int test_sigbits(char sigbits) {
    scil_user_hints_t hints;
    scil_user_hints_initialize(&hints);
    hints.significant_bits = sigbits;
    hints.force_compression_methods = "3";
    printf("#Testing sigbit algorithm with hint 'number of sigbits' = %d\n", sigbits);

    scil_context_t* context;
    int ret = scil_context_create(&context, SCIL_TYPE_DOUBLE, 0, NULL, &hints);

    if(ret != SCIL_NO_ERR){
      return -2;
    }

    scil_dims_t dims;
    scil_dims_initialize_1d(&dims, count);

    size_t uncompressed_size = scil_dims_get_size(&dims, SCIL_TYPE_DOUBLE);
    size_t compressed_size   = scil_get_compressed_data_size_limit(&dims, SCIL_TYPE_DOUBLE);

    double* buffer_in  = (double*)malloc(uncompressed_size);
    byte* buffer_out   = (byte*)malloc(compressed_size);
    byte* buffer_tmp   = (byte*)malloc(compressed_size / 2);
    double* buffer_end = (double*)malloc(uncompressed_size);

    for(size_t i = 0; i < count; ++i){
        buffer_in[i] = input_values[i];
    }

    size_t out_size;
    ret = scil_compress(buffer_out, compressed_size, buffer_in, &dims, &out_size, context);
    scil_decompress(SCIL_TYPE_DOUBLE, buffer_end, &dims, buffer_out, out_size, buffer_tmp);

    if(ret != SCIL_NO_ERR){
      return -1;
    }

    int errors = 0;
    printf("#Input value,Expected value,Value after comp-decomp,Status\n");
    for (size_t i = 0; i < count; ++i) {
        double expected = expected_value(sigbits, i);
        printf("%12.4e,%12.4e,%12.4e", buffer_in[i], expected, buffer_end[i]);
        if (same_value(expected, buffer_end[i])) {
            printf(",Ok\n");
        }
        else {
            printf(",Error\n");
            errors++;
        }
    }

    free(buffer_in);
    free(buffer_out);
    free(buffer_tmp);
    free(buffer_end);

    //scil_destroy_context(context);

    return errors;
}
Exemplo n.º 2
0
int playExpected2048(Game g, int depth) {
    int size;
    while(!is2048(g->board)) {
        Move* moves = effectual_moves(g->board, &size);
        // Test end conditions
        if (moves == NULL)
            break;
        if (size == 0) {
            free(moves);
            break;
        }
        int i;
        Move bestMove = moves[0];
        double bestE = 0;
        for (i = 0; i < size; i++) {
            double E = expected_value(g, moves[i], depth);
            if (E > bestE) {
                bestMove = moves[i];
                bestE = E;
            }
        }
        make_move(g, bestMove);
        free(moves);
    }
    return g->score;
}
Exemplo n.º 3
0
	void exceptionBufferIsTrimmedCorrectly_assignStringOfOneGreaterThanExceptionBufferCanContain_memberLenEqualsBufferSizeMinusTwo()
	{
		char buffer[OOLUA::ERROR::size+2];
		memset(buffer, 1, OOLUA::ERROR::size);
		buffer[OOLUA::ERROR::size+1]='\0';
		OOLUA::Exception e(buffer);
		size_t expected_value(OOLUA::ERROR::size-2);
		CPPUNIT_ASSERT_EQUAL(expected_value, e.m_len);
	}
Exemplo n.º 4
0
int main()
{
  // Disable deprecation warning for getenv call.
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4996)
#endif

  const char *usepath = getenv("CHAI_USE_PATH");
  const char *modulepath = getenv("CHAI_MODULE_PATH");

#ifdef BOOST_MSVC
#pragma warning(pop)
#endif

  std::vector<std::string> usepaths;
  usepaths.push_back("");
  if (usepath)
  {
    usepaths.push_back(usepath);
  }

  std::vector<std::string> modulepaths;
  modulepaths.push_back("");
  if (modulepath)
  {
    modulepaths.push_back(modulepath);
  }

  chaiscript::ChaiScript chai(modulepaths,usepaths);

  boost::thread_group threads;

  // Ensure at least two, but say only 7 on an 8 core processor
  int num_threads = std::max<unsigned int>(boost::thread::hardware_concurrency() - 1, 2u);

  for (int i = 0; i < num_threads; ++i)
  {
    threads.create_thread(boost::bind(&do_work, boost::ref(chai), i));
  }

  threads.join_all();


  for (int i = 0; i < num_threads; ++i)
  {
    std::stringstream ss;
    ss << i;
    if (chai.eval<int>("getvalue(" + ss.str() + ")") != expected_value(4000))
    {
      return EXIT_FAILURE;
    }

    if (chai.eval<int>("getid(" + ss.str() + ")") != i)
    {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}
Exemplo n.º 5
0
	void exception_assignStringOfLengthOnePlusNull_bufferLenIsOne()
	{
		OOLUA::Exception e("f");
		size_t expected_value(1);
		CPPUNIT_ASSERT_EQUAL(expected_value, e.m_len);
	}
int main()
{
  // Disable deprecation warning for getenv call.
#ifdef CHAISCRIPT_MSVC
#ifdef max // Why Microsoft? why?
#undef max
#endif
#pragma warning(push)
#pragma warning(disable : 4996)
#endif

  const char *usepath = getenv("CHAI_USE_PATH");
  const char *modulepath = getenv("CHAI_MODULE_PATH");

#ifdef CHAISCRIPT_MSVC
#pragma warning(pop)
#endif

  std::vector<std::string> usepaths;
  usepaths.push_back("");
  if (usepath)
  {
    usepaths.push_back(usepath);
  }

  std::vector<std::string> modulepaths;
  modulepaths.push_back("");
  if (modulepath)
  {
    modulepaths.push_back(modulepath);
  }

  chaiscript::ChaiScript chai(modulepaths,usepaths);

  std::vector<std::shared_ptr<std::thread> > threads;

  // Ensure at least two, but say only 7 on an 8 core processor
  int num_threads = std::max(std::thread::hardware_concurrency() - 1, 2u);

  for (int i = 0; i < num_threads; ++i)
  {
    threads.push_back(std::shared_ptr<std::thread>(new std::thread(do_work, std::ref(chai), i)));
  }

  for (int i = 0; i < num_threads; ++i)
  {
    threads[i]->join();
  }



  for (int i = 0; i < num_threads; ++i)
  {
    std::stringstream ss;
    ss << i;
    if (chai.eval<int>("getvalue(" + ss.str() + ")") != expected_value(4000))
    {
      return EXIT_FAILURE;
    }

    if (chai.eval<int>("getid(" + ss.str() + ")") != i)
    {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}