void IntegrationTest::occurrenceCompare(const std::string& keyword, int occurrence) const {
    ecl_kw_type* ecl_kw1 = nullptr;
    ecl_kw_type* ecl_kw2 = nullptr;
    const unsigned int numCells = getEclKeywordData(ecl_kw1, ecl_kw2, keyword, occurrence, occurrence);
    std::vector<double> values1(numCells), values2(numCells);
    ecl_kw_get_data_as_double(ecl_kw1, values1.data());
    ecl_kw_get_data_as_double(ecl_kw2, values2.data());

    // This variable sums up the difference between the keyword value for the first case and the keyword value for the second case, for each cell. The sum is weighted with respect to the cell volume of each cell.
    double weightedDifference = 0;
    // This variable sums up the difference between the keyword value for the occurrence and the initial keyword value for each cell. The sum is weighted with respect to the cell volume of each cell.
    double relativeWeightedTotal = 0;

    for (size_t cell = 0; cell < values1.size(); ++cell) {
        relativeWeightedTotal += std::abs(values1[cell] - initialCellValues[cell])*cellVolumes[cell];
        weightedDifference += std::abs(values1[cell] - values2[cell])*cellVolumes[cell];
    }

    if (relativeWeightedTotal != 0) {
        double ratioValue = weightedDifference/relativeWeightedTotal;
        if ((ratioValue) > getRelTolerance()) {
            OPM_THROW(std::runtime_error, "\nFor keyword " << keyword << " and occurrence " << occurrence << ":"
                    << "\nThe ratio of the deviation and the total value is " << ratioValue
                    << ", which exceeds the relative tolerance of " << getRelTolerance() << "."
                    << "\nSee the docs for more information about how the ratio is computed.");
        }
    }
}
Beispiel #2
0
  /// FIXME - this could be faster by a factor of 2 - we are sorting TWICE!
  pair<double,double> confidence_interval(const valarray<double>& values,double P) 
  {
    vector<double> values2(values.size());
    for(int i=0;i<values.size();i++)
      values2[i] = values[i];

    return confidence_interval(values2,P);
  }
Beispiel #3
0
 void compare_pairs(X1 const& x1, X2 const& x2, T*)
 {
     test::list<T> values1(x1.first, x1.second);
     test::list<T> values2(x2.first, x2.second);
     values1.sort();
     values2.sort();
     BOOST_TEST(values1.size() == values2.size() &&
             std::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent));
 }
Beispiel #4
0
 void compare_range(X1 const& x1, X2 const& x2)
 {
     typedef test::list<BOOST_DEDUCED_TYPENAME X1::value_type> value_list;
     value_list values1(x1.begin(), x1.end());
     value_list values2(x2.begin(), x2.end());
     values1.sort();
     values2.sort();
     BOOST_TEST(values1.size() == values2.size() &&
             std::equal(values1.begin(), values1.end(), values2.begin(),
                 test::equivalent));
 }
void RegressionTest::doubleComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2) {
    ecl_kw_type* ecl_kw1 = nullptr;
    ecl_kw_type* ecl_kw2 = nullptr;
    const unsigned int numCells = getEclKeywordData(ecl_kw1, ecl_kw2, keyword, occurrence1, occurrence2);
    std::vector<double> values1(numCells), values2(numCells);
    ecl_kw_get_data_as_double(ecl_kw1, values1.data());
    ecl_kw_get_data_as_double(ecl_kw2, values2.data());

    auto it = std::find(keywordDisallowNegatives.begin(), keywordDisallowNegatives.end(), keyword);
    for (size_t cell = 0; cell < values1.size(); cell++) {
        deviationsForCell(values1[cell], values2[cell], keyword, occurrence1, occurrence2, cell, it == keywordDisallowNegatives.end());
    }
}
void RegressionTest::intComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2) const {
    ecl_kw_type* ecl_kw1 = nullptr;
    ecl_kw_type* ecl_kw2 = nullptr;
    const unsigned int numCells = getEclKeywordData(ecl_kw1, ecl_kw2, keyword, occurrence1, occurrence2);
    std::vector<int> values1(numCells), values2(numCells);
    ecl_kw_get_memcpy_int_data(ecl_kw1, values1.data());
    ecl_kw_get_memcpy_int_data(ecl_kw2, values2.data());
    for (size_t cell = 0; cell < values1.size(); cell++) {
        if (values1[cell] != values2[cell]) {
            printValuesForCell(keyword, occurrence1, occurrence2, cell, values1[cell], values2[cell]);
            OPM_THROW(std::runtime_error, "Values of int type differ.");
        }
    }
}
Beispiel #7
0
  double quantile(const valarray<double>& values, double Q)
  {
    assert(0 <= Q and Q <= 1.0);
    assert(values.size() > 0);

    if (values.size() == 1)
      return values[0];

    // sort values
    vector<double> values2(values.size());
    for(int i=0;i<values.size();i++)
      values2[i] = values[i];

    return quantile(values2,Q);
  }
void ECLFilesComparator::deviationsForOccurence(const std::string& keyword, int occurence) {
    ecl_kw_type* ecl_kw1         = ecl_file_iget_named_kw(ecl_file1, keyword.c_str(), occurence);
    ecl_kw_type* ecl_kw2         = ecl_file_iget_named_kw(ecl_file2, keyword.c_str(), occurence);
    const unsigned int numCells1 = ecl_kw_get_size(ecl_kw1);
    const unsigned int numCells2 = ecl_kw_get_size(ecl_kw2);
    if (numCells1 != numCells2) {
        std::cout << "For keyword " << keyword << " and occurence " << occurence << ":\n";
        OPM_THROW(std::runtime_error, "Number of active cells are different.");
    }
    std::vector<double> values1(numCells1), values2(numCells2);
    ecl_kw_get_data_as_double(ecl_kw1, values1.data());
    ecl_kw_get_data_as_double(ecl_kw2, values2.data());

    auto it = std::find(keywordWhitelist.begin(), keywordWhitelist.end(), keyword);
    for (unsigned int cell = 0; cell < values1.size(); cell++) {
        deviationsForCell(values1[cell], values2[cell], keyword, occurence, cell, it == keywordWhitelist.end());
    }
}
Beispiel #9
0
void handle_values_tests_distributed_access(hpx::vector<T>& v)
{
    fill_vector (v, T(42));

    std::vector<std::size_t> positions(5);
    fill_vector(positions, 0, 2);
    std::vector<std::size_t> positions2(5);
    fill_vector(positions2, 1, 2);

    std::vector<T> values(positions.size());
    fill_vector(values, T(48), T(3));
    std::vector<T> values2(positions2.size());
    fill_vector(values2, T(42), T(0));

    v.set_values(positions, values);
    std::vector<T> result  = v.get_values_sync(positions );
    std::vector<T> result2 = v.get_values_sync(positions2);

    compare_vectors(values , result);
    compare_vectors(values2, result2);
}
Beispiel #10
0
 void Database::swap(const std::vector<std::string>& keys1, const std::vector<std::string>& keys2)
 {
   CHECK_EQ(keys1.size(), keys2.size());
   uint size = keys1.size();
   leveldb::WriteBatch batch;
   std::vector<std::string> values1(size);
   std::vector<std::string> values2(size);
   for (uint i = 0; i < keys1.size(); i++)
   {
     std::string value1;
     std::string value2;
     leveldb::Status s1 = db_->Get(readOptions_, keys1[i], &value1);
     leveldb::Status s2 = db_->Get(readOptions_, keys2[i], &value2);
     CHECK(s1.ok() && s2.ok()) << s1.ToString() << " " << s2.ToString();
     values1[i] = value2;
     values2[i] = value1;
     batch.Put(keys1[i], values1[i]);
     batch.Put(keys2[i], values2[i]);
   }
   db_->Write(writeOptions_, &batch);
 }
Beispiel #11
0
int main(int /*argc*/, char* /*argv*/[])
{
    static const auto valueSize = 512ull * 512ull * 512ull * 8ull; // 4GB of consecutive data

    cppassist::vector<float> values1(valueSize);
    cppassist::vector<float> values2(valueSize);
    std::fill(values1.valueBegin(), values1.valueEnd(), 2.0f);
    std::fill(values2.valueBegin(), values2.valueEnd(), 4.0f);

    std::cout << "Start measuring" << std::endl;

    const auto start = std::chrono::high_resolution_clock::now();

    cppassist::traverse_mt([](const cppassist::vector<float>::value_type & chunk1, cppassist::vector<float>::value_type & chunk2)
    {
        chunk2 = sqrt((sqrt(chunk1) * sqrt(chunk2) + 12.0f) * 0.125f + 5.0f);
    }, values1, values2);

    const auto end = std::chrono::high_resolution_clock::now();

    std::cout << "  End measuring: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;

    return 0;
}
Beispiel #12
0
void basic_test()
{
    using value_type = std::pair<int, int>;
    const size_t value_size = sizeof(value_type);

    const size_t n_values = 6000;
    const size_t n_tests = 3000;

    // make sure all changes will be buffered (*)
    const size_t buffer_size = n_values * (value_size + sizeof(int*));

    const size_t mem_to_sort = 32 * 1024 * 1024;

    const size_t subblock_raw_size = 4 * 1024;
    const size_t block_size = 4;
    using unordered_map = stxxl::unordered_map<int, int, hash_int, cmp,
                                               subblock_raw_size, block_size>;
    using iterator = unordered_map::iterator;
    using const_iterator = unordered_map::const_iterator;

    foxxll::stats_data stats_begin;

    unordered_map map;
    map.max_buffer_size(buffer_size);
    const unordered_map& cmap = map;

    // generate random values

    std::vector<value_type> values1(n_values);
    std::vector<value_type> values2(n_values);
    std::vector<value_type> values3(n_values / 2);

    {
        auto broadcast = [](uint64_t x) -> value_type {
                             return {
                                        x, x
                             };
                         };
        random_fill_vector(values1, broadcast);
        random_fill_vector(values2, broadcast);
        random_fill_vector(values3, broadcast);
    }

    // --- initial import
    std::cout << "Initial import...";
    stats_begin = *foxxll::stats::get_instance();

    die_unless(map.begin() == map.end());
    map.insert(values1.begin(), values1.end(), mem_to_sort);
    die_unless(map.begin() != map.end());
    die_unless(map.size() == n_values);

    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    // (*) all these values are stored in external memory; the remaining
    // changes will be buffered in internal memory

    // --- insert: new (from values2) and existing (from values1) values, with
    // --- and without checking
    std::cout << "Insert...";
    stats_begin = *foxxll::stats::get_instance();

    for (size_t i = 0; i < n_values / 2; i++) {
        // new without checking
        map.insert_oblivious(values2[2 * i]);
        // new with checking
        std::pair<iterator, bool> res = map.insert(values2[2 * i + 1]);
        die_unless(res.second && (*(res.first)).first == values2[2 * i + 1].first);
        // existing without checking
        map.insert_oblivious(values1[2 * i]);
        // exiting with checking
        res = map.insert(values1[2 * i + 1]);
        die_unless(!res.second && (*(res.first)).first == values1[2 * i + 1].first);
    }

    die_unless(map.size() == 2 * n_values);
    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    // "old" values are stored in external memory, "new" values are stored in
    // internal memory

    // --- find: existing (from external and internal memory) and non-existing
    // --- values
    std::cout << "Find...";
    stats_begin = *foxxll::stats::get_instance();

    std::random_shuffle(values1.begin(), values1.end());
    std::random_shuffle(values2.begin(), values2.end());
    for (size_t i = 0; i < n_tests; i++) {
        die_unless(cmap.find(values1[i].first) != cmap.end());
        die_unless(cmap.find(values2[i].first) != cmap.end());
        die_unless(cmap.find(values3[i].first) == cmap.end());
    }
    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    // --- insert with overwriting
    std::cout << "Insert with overwriting...";
    stats_begin = *foxxll::stats::get_instance();

    std::random_shuffle(values1.begin(), values1.end());
    std::random_shuffle(values2.begin(), values2.end());
    for (size_t i = 0; i < n_tests; i++) {
        value_type value1 = values1[i];         // in external memory
        value1.second++;
        map.insert_oblivious(value1);

        value_type value2 = values2[i];         // in internal memory
        value2.second++;
        map.insert_oblivious(value2);
    }
    // now check
    die_unless(map.size() == 2 * n_values);         // nothing added, nothing removed
    for (size_t i = 0; i < n_tests; i++) {
        const_iterator it1 = cmap.find(values1[i].first);
        const_iterator it2 = cmap.find(values2[i].first);

        die_unless((*it1).second == values1[i].second + 1);
        die_unless((*it2).second == values2[i].second + 1);
    }
    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    // --- erase: existing and non-existing values, with and without checking
    std::cout << "Erase...";
    stats_begin = *foxxll::stats::get_instance();

    std::random_shuffle(values1.begin(), values1.end());
    std::random_shuffle(values2.begin(), values2.end());
    std::random_shuffle(values3.begin(), values3.end());
    for (size_t i = 0; i < n_tests / 2; i++) {        // external
        // existing without checking
        map.erase_oblivious(values1[2 * i].first);
        // existing with checking
        die_unless(map.erase(values1[2 * i + 1].first) == 1);
    }
    for (size_t i = 0; i < n_tests / 2; i++) {        // internal
        // existing without checking
        map.erase_oblivious(values2[2 * i].first);
        // existing with checking
        die_unless(map.erase(values2[2 * i + 1].first) == 1);
        // non-existing without checking
        map.erase_oblivious(values3[i].first);
        // non-existing with checking
    }
    die_unless(map.size() == 2 * n_values - 2 * n_tests);
    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    map.clear();
    die_unless(map.size() == 0);

    // --- find and manipulate values by []-operator

    // make sure there are some values in our unordered_map: externally
    // [0..n/2) and internally [n/2..n) from values1
    std::cout << "[ ]-operator...";
    stats_begin = *foxxll::stats::get_instance();

    map.insert(values1.begin(), values1.begin() + n_values / 2, mem_to_sort);
    for (size_t i = n_values / 2; i < n_values; i++) {
        map.insert_oblivious(values1[i]);
    }
    // lookup of existing values
    die_unless(map[values1[5].first] == values1[5].second);                               // external
    die_unless(map[values1[n_values / 2 + 5].first] == values1[n_values / 2 + 5].second); // internal
    // manipulate existing values
    ++(map[values1[7].first]);
    ++(map[values1[n_values / 2 + 7].first]);
    {
        const_iterator cit1 = cmap.find(values1[7].first);
        die_unless((*cit1).second == (*cit1).first + 1);
        const_iterator cit2 = cmap.find(values1[n_values / 2 + 7].first);
        die_unless((*cit2).second == (*cit2).first + 1);
    }
    // lookup of non-existing values
    die_unless(map[values2[5].first] == unordered_map::mapped_type());
    // assignment of non-existing values
    map[values2[7].first] = values2[7].second;
    {
        const_iterator cit = cmap.find(values2[7].first);
        die_unless((*cit).first == values2[7].second);
    }
    die_unless(map.size() == n_values + 2);
    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    map.clear();
    die_unless(map.size() == 0);

    // --- additional bulk insert test
    std::cout << "additional bulk-insert...";
    stats_begin = *foxxll::stats::get_instance();

    map.insert(values1.begin(), values1.begin() + n_values / 2, mem_to_sort);
    map.insert(values1.begin() + n_values / 2, values1.end(), mem_to_sort);
    die_unless(map.size() == n_values);
    // lookup some random values
    std::random_shuffle(values1.begin(), values1.end());
    for (size_t i = 0; i < n_tests; i++)
        die_unless(cmap.find(values1[i].first) != cmap.end());
    std::cout << "passed" << std::endl;
    LOG1 << foxxll::stats_data(*foxxll::stats::get_instance()) - stats_begin;

    // --- test equality predicate
    unordered_map::key_equal key_eq = map.key_eq();
    die_unless(key_eq(42, 42));
    die_unless(!key_eq(42, 6 * 9));

    std::cout << "\nAll tests passed" << std::endl;

    map.buffer_size();
}
Beispiel #13
0
int main (int argc, char const* argv[])
{
	numa::HashTable<std::string, int, 5> table(numa::NodeList::allNodes());
	
	int count = 100000;
	
	// fill
	for (int i = 0; i < count; i++) {
		table[generate(i)] = i;

		assert(!table.begin().is_end());
		assert(table.end().is_end());
	}
	
	// check for content
	for (int i = 0; i < count; i++) {
		if (table[generate(i)] != i) {
			printf("Not in table: (%s,%d)\n", generate(i).c_str(), i);
		}
	}

	std::vector<bool> values1(count, false);
	std::vector<bool> values2(count, false);

	// iterate 1...
	for (auto it = table.begin(); !it.is_end(); it.next()) {
		int n;
		assert(sscanf(it->first.c_str(), "_%d_", &n) > 0);
		assert(n == it->second);
		assert(n >= 0 && n < count);
		assert(!values1[n]);
		values1[n] = true;
	}

	// iterate 2...
	for (numa::Node node : table.nodes()) {
		numa::HashTable<std::string, int, 5>::ParallelIteration iter(table, node, 10);
		numa::HashTable<std::string, int, 5>::ParallelIteration::Iterator it;

		numa::MemSource ms;

		while (iter.get(it, ms)) {
			numa::PlaceGuard guard(ms);
			for (; !it.is_end(); it.next()) {
				int n;
				assert(sscanf(it->first.c_str(), "_%d_", &n) > 0);
				assert(n == it->second);
				assert(n >= 0 && n < count);
				assert(!values2[n]);
				values2[n] = true;
			}
		}
	}

	// check for values
	for (int i = 0; i < count; i++) {
		assert(values1[i]);
		assert(values2[i]);
	}
	
	return 0;
}
int main()
{
	// --added for timing code-- //
	timekeeper myTimer;
	unsigned precomputationRealTime, precomputationClockTime;
	unsigned sumOfInterpolationRealTimes = 0;
	unsigned sumOfInterpolationClockTimes = 0;

	int W=50;

	std::vector<Vector<2,double> > samplesPos(W*W);
	std::vector<double> values1(W*W, 0.);
	std::vector<double> values2(W*W, 0.);
	std::vector<double> valuesR(W*W, 0.);

	for (int i=0; i<W; i++)
	{
		for (int j=0; j<W; j++)
		{
			samplesPos[i*W+j] = Vector<2,double>(i/(double)W,j/(double)W); // the data lie on the unit grid
			values1[i*W+j] = 0.;
			values2[i*W+j] = 0.;
	
			// generate a square
			if (i>5 && i<45 && j>5 && j<45)
				values1[i*W+j] = 1;
			else
				values1[i*W+j] = 0;

			// generate a disk
			if ((i-25)*(i-25)+(j-25)*(j-25)<509)
				values2[i*W+j] = 1;
			else
				values2[i*W+j] = 0;
		}
	}

	Interpolator<2,double> interp(samplesPos, values1,  // source distribution, in R^2 
		samplesPos, values2,							// target distribution
		sqrDistLinear, rbfFuncLinear, interpolateBinsLinear, // how to represent and move the particles
		2,												// particle spread : distance to 2nd nearest neighbor at each sample point
		1);											   // 1 frequency band (standard displacement interpolation)

	// --added for timing code-- //
	myTimer.start();

	interp.precompute();

	// --added for timing code-- //
	myTimer.stop();
	precomputationRealTime = myTimer.getElapsedRealMS();
	precomputationClockTime = myTimer.getElapsedClockMS();
	myTimer.clear();

	int N = 50; // we get 50 intermediate steps
	for (int p=0; p<N; p++)
	{
		double alpha = p/((double)N-1.);

		// --added for timing code-- //
		myTimer.start();

		interp.interpolate(alpha, samplesPos, valuesR);

		// --added for timing code-- //
		myTimer.stop();
		sumOfInterpolationRealTimes += myTimer.getElapsedRealMS();
		sumOfInterpolationClockTimes += myTimer.getElapsedClockMS();
		myTimer.clear();

		saveFile(p, valuesR);
	}

	// --added for timing code-- //
	FILE* timingRecord = fopen("timing", "a");
	fprintf(timingRecord, "entry start\n");
	fprintf(timingRecord, "precomputation (ms): %u\n", precomputationRealTime);
	fprintf(timingRecord, "precomputation (clock ms): %u\n", precomputationClockTime);
	fprintf(timingRecord, "total interpolation (ms): %u\n", sumOfInterpolationRealTimes);
	fprintf(timingRecord, "total interpolation (clock ms): %u\n", sumOfInterpolationClockTimes);
	fprintf(timingRecord, "interpolation count: %d\n", N);
	fprintf(timingRecord, "\n");

	return 0;
}