Commit 8394d019 authored by Sebastian Wolf's avatar Sebastian Wolf

Fixed missing explicit instantiations

parent f2cd1a1d
Pipeline #1098 passed with stages
in 17 minutes and 20 seconds
......@@ -51,7 +51,7 @@ namespace xerus {
MeasurementSet& operator=(const MeasurementSet& _other) = default;
MeasurementSet& operator=( MeasurementSet&& _other) = default;
virtual ~MeasurementSet() = 0;
virtual ~MeasurementSet() = default;
///@brief Returns the number of measuremts.
......@@ -98,7 +98,7 @@ namespace xerus {
virtual void check_consitency() = 0;
protected:
virtual void create_random_positions(const size_t _numMeasurements, const std::vector<size_t>& _dimensions);
virtual void create_random_positions(const size_t _numMeasurements, const std::vector<size_t>& _dimensions) = 0;
virtual void check_position(const std::vector<PositionType>& _position) = 0;
......@@ -144,7 +144,9 @@ namespace xerus {
virtual void get_values(std::vector<value_t>& _values, std::function<value_t(const std::vector<size_t>&)> _callback) const override;
};
/**
* @brief Class used to represent a set of rank-one measurments.
*/
class RankOneMeasurementSet : public MeasurementSet<Tensor> {
public:
RankOneMeasurementSet() = default;
......
......@@ -200,6 +200,10 @@ namespace xerus {
return relative_weighted_l2_difference(measuredValues, testValues, weights);
}
// Explicit instantiation of the two template parameters that will be implemented in the xerus library
template class MeasurementSet<size_t>;
template class MeasurementSet<Tensor>;
// --------------------- SinglePointMeasurementSet -----------------
......@@ -245,35 +249,42 @@ namespace xerus {
);
}
struct vec_compare final {
bool operator() (const std::vector<size_t>& _lhs, const std::vector<size_t>& _rhs) const {
REQUIRE(_lhs.size() == _rhs.size(), "Inconsistent degrees in measurment positions.");
for (size_t i = 0; i < _lhs.size(); ++i) {
if (_lhs[i] < _rhs[i]) { return true; }
if (_lhs[i] > _rhs[i]) { return false; }
}
return false; // equality
}
};
void SinglePointMeasurementSet::create_random_positions(const size_t _numMeasurements, const std::vector<size_t>& _dimensions) {
XERUS_REQUIRE(misc::product(_dimensions) >= _numMeasurements, "It's impossible to perform as many measurements as requested. " << _numMeasurements << " > " << _dimensions);
// Create distributions
std::vector<std::uniform_int_distribution<size_t>> indexDist;
for (size_t i = 0; i < _dimensions.size(); ++i) {
indexDist.emplace_back(0, _dimensions[i]-1);
}
std::set<std::vector<size_t>, vec_compare> measuredPositions;
std::vector<size_t> multIdx(_dimensions.size());
for (size_t i = 0; i < _numMeasurements; ++i) {
for (size_t k = 0; k < _dimensions.size(); ++k) {
multIdx[k] = indexDist[k](misc::randomEngine);
while (measuredPositions.size() < _numMeasurements) {
for (size_t i = 0; i < _dimensions.size(); ++i) {
multIdx[i] = indexDist[i](misc::randomEngine);
}
positions.push_back(multIdx);
measuredPositions.insert(multIdx);
}
for(const auto& pos : measuredPositions) {
positions.push_back(pos);
}
std::sort(positions.begin(), positions.end(), [](const std::vector<size_t>& _lhs, const std::vector<size_t>& _rhs) {
REQUIRE(_lhs.size() == _rhs.size(), "Inconsistent degrees in measurment positions.");
for (size_t i = 0; i < _lhs.size(); ++i) {
const auto res = internal::compare(_lhs[i], _rhs[i]);
if(res == -1) { return true; }
if(res == 1) { return false; }
}
return false; // equality
});
measuredValues.resize(_numMeasurements, 0.0);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment