Commit 81952ee5 authored by Philipp Trunschke's avatar Philipp Trunschke

improve error messages

parent 8cddbe6e
......@@ -106,17 +106,17 @@ namespace xerus { namespace uq { namespace impl_uqRaAdf {
static std::vector<std::vector<Tensor>> transpose_positions(const TTTensor& _x, const std::vector<std::vector<Tensor>>& _positions, const std::vector<Tensor>& _solutions) {
REQUIRE(_positions.size() == _solutions.size(), "Incompatible positions and solutions vector");
REQUIRE(_positions.size() == _solutions.size(), "Incompatible positions and solutions vector: " << _positions.size() << " vs " << _solutions.size());
for(size_t sample=0; sample < _positions.size(); ++sample) {
REQUIRE(_positions[sample].size() == _x.order()-1, "Invalid measurement");
REQUIRE(_positions[sample].size() == _x.order()-1, "Invalid measurement: " << _positions[sample].size() << " vs " << _x.order()-1 << " (at sample " << sample << ")");
}
std::vector<std::vector<Tensor>> positions(_x.order());
for(size_t corePosition=1; corePosition < _x.order(); ++corePosition) {
positions[corePosition].reserve(_positions.size());
for(size_t sample=0; sample < _positions.size(); ++sample) {
REQUIRE(_positions[sample][corePosition-1].dimensions.size() == 1, "Invalid measurement component");
REQUIRE(_positions[sample][corePosition-1].size == _x.dimensions[corePosition], "Invalid measurement component");
REQUIRE(_positions[sample][corePosition-1].dimensions.size() == 1, "Invalid measurement component: len(" << _positions[sample][corePosition-1].dimensions << ") != 1 (at sample " << sample << " & position " << corePosition << ")");
REQUIRE(_positions[sample][corePosition-1].size == _x.dimensions[corePosition], "Invalid measurement component"); // << _positions[sample][corePosition-1].size == _x.dimensions[corePosition]);
positions[corePosition].push_back(_positions[sample][corePosition-1]);
}
}
......
......@@ -64,7 +64,9 @@ void expose_tensor(module& m) {
throw std::runtime_error("Incompatible format: expected a double array!");
}
if (info.itemsize != sizeof(value_t)) {
throw std::runtime_error("Incompatible size");
std::ostringstream msg;
msg << "Incompatible size: " << info.itemsize << " (got) vs " << sizeof(value_t) << " (expected)";
throw std::runtime_error(msg.str());
}
if (info.shape.size() == 1 and info.shape[0] == 0) {
return Tensor({}, Tensor::Representation::Dense, Tensor::Initialisation::None);
......@@ -73,8 +75,9 @@ void expose_tensor(module& m) {
std::vector<size_t> dims(info.shape.begin(), info.shape.end());
std::vector<size_t> strides(info.strides.begin(), info.strides.end());
if (strides != strides_from_dimensions_and_item_size(dims, info.itemsize)) {
/* std::cerr << "Incompatible strides: " << strides << " (got) vs " << strides_from_dimensions_and_item_size(dims, info.itemsize) << " (expected)" << std::endl; */
throw std::runtime_error("Incompatible strides");
std::ostringstream msg;
msg << "Incompatible strides: " << strides << " (got) vs " << strides_from_dimensions_and_item_size(dims, info.itemsize) << " (expected). Make sure your buffer is C contiguous." << std::endl;
throw std::runtime_error(msg.str());
}
Tensor result(dims, Tensor::Representation::Dense, Tensor::Initialisation::None);
......
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