Commit 342e78a9 authored by Sebastian Wolf's avatar Sebastian Wolf

Fixed 32/64Bit issus in fileIO

parent 9534f71f
Pipeline #642 failed with stages
in 3 minutes and 42 seconds
......@@ -59,7 +59,7 @@ namespace xerus { namespace misc {
template<class T>
void stream_writer(std::ostream& _stream, const std::vector<T> &_value, FileFormat _format) {
write_to_stream<uint64>(_stream, _value.size(), _format);
write_to_stream<size_t>(_stream, _value.size(), _format);
for (size_t i = 0; i < _value.size(); ++i) {
write_to_stream<T>(_stream, _value[i], _format);
}
......@@ -90,7 +90,7 @@ namespace xerus { namespace misc {
template<class T>
void stream_reader(std::istream& _stream, std::vector<T> &_obj, const FileFormat _format) {
_obj.resize(read_from_stream<uint64>(_stream, _format));
_obj.resize(read_from_stream<size_t>(_stream, _format));
for (size_t i = 0; i < _obj.size(); ++i) {
read_from_stream<T>(_stream, _obj[i], _format);
}
......
......@@ -1698,20 +1698,20 @@ namespace xerus {
}
// storage version number
write_to_stream<uint64>(_stream, 1, _format);
write_to_stream<size_t>(_stream, 1, _format);
write_to_stream(_stream, _obj.dimensions, _format);
if (_obj.representation == Tensor::Representation::Dense) {
write_to_stream<uint64>(_stream, 1, _format);
write_to_stream<size_t>(_stream, 1, _format);
for (size_t i = 0; i < _obj.size; ++i) {
write_to_stream<value_t>(_stream, _obj[i], _format);
}
} else {
write_to_stream<uint64>(_stream, 2, _format);
write_to_stream<uint64>(_stream, _obj.get_unsanitized_sparse_data().size(), _format);
write_to_stream<size_t>(_stream, 2, _format);
write_to_stream<size_t>(_stream, _obj.get_unsanitized_sparse_data().size(), _format);
for (const auto &d : _obj.get_unsanitized_sparse_data()) {
write_to_stream<uint64>(_stream, d.first, _format);
write_to_stream<size_t>(_stream, d.first, _format);
write_to_stream<value_t>(_stream, _obj.factor*d.second, _format);
}
}
......@@ -1719,7 +1719,7 @@ namespace xerus {
void stream_reader(std::istream& _stream, Tensor &_obj, const FileFormat _format) {
IF_CHECK(uint64 ver = )read_from_stream<uint64>(_stream, _format);
IF_CHECK(size_t ver = )read_from_stream<size_t>(_stream, _format);
REQUIRE(ver == 1, "Unknown stream version to open (" << ver << ")");
// Load dimensions
......@@ -1727,7 +1727,7 @@ namespace xerus {
read_from_stream(_stream, dims, _format);
// Load representation
const uint64 rep = read_from_stream<uint64>(_stream, _format);
const size_t rep = read_from_stream<size_t>(_stream, _format);
// Load data
if (rep == 1) { // Dense
......@@ -1744,13 +1744,13 @@ namespace xerus {
REQUIRE(rep == 2, "Unknown tensor representation " << rep << " in stream");
_obj.reset(std::move(dims), Tensor::Representation::Sparse);
const uint64 num = read_from_stream<uint64>(_stream, _format);
const uint64 num = read_from_stream<size_t>(_stream, _format);
REQUIRE(num < std::numeric_limits<size_t>::max(), "The stored Tensor is to large to be loaded using 32 Bit xerus.");
for (size_t i = 0; i < num; ++i) {
REQUIRE(_stream, "Unexpected end of stream in reading sparse Tensor.");
// NOTE inline function calls can be called in any order by the compiler, so we have to cache the results to ensure correct order
uint64 pos = read_from_stream<uint64>(_stream, _format);
uint64 pos = read_from_stream<size_t>(_stream, _format);
value_t val = read_from_stream<value_t>(_stream, _format);
_obj.get_unsanitized_sparse_data().emplace(pos, val);
}
......
......@@ -1431,7 +1431,7 @@ namespace xerus {
_stream << std::setprecision(std::numeric_limits<value_t>::digits10 + 1);
}
// storage version number
write_to_stream<uint64>(_stream, 1, _format);
write_to_stream<size_t>(_stream, 1, _format);
// Save dimensions
write_to_stream(_stream, _obj.dimensions, _format);
......@@ -1439,22 +1439,22 @@ namespace xerus {
// save external links
for(const TensorNetwork::Link& el : _obj.externalLinks) {
write_to_stream<uint64>(_stream, el.other, _format);
write_to_stream<uint64>(_stream, el.indexPosition, _format);
write_to_stream<uint64>(_stream, el.dimension, _format);
write_to_stream<size_t>(_stream, el.other, _format);
write_to_stream<size_t>(_stream, el.indexPosition, _format);
write_to_stream<size_t>(_stream, el.dimension, _format);
}
if(_format == FileFormat::TSV) { _stream << "\n\n"; }
// Save nodes with their links
write_to_stream<uint64>(_stream, _obj.nodes.size(), _format);
write_to_stream<size_t>(_stream, _obj.nodes.size(), _format);
if(_format == FileFormat::TSV) { _stream << '\n'; }
for(const TensorNetwork::TensorNode& node : _obj.nodes) {
write_to_stream<uint64>(_stream, node.neighbors.size(), _format);
write_to_stream<size_t>(_stream, node.neighbors.size(), _format);
for(const TensorNetwork::Link& link : node.neighbors) {
write_to_stream<bool>(_stream, link.external, _format);
write_to_stream<uint64>(_stream, link.other, _format);
write_to_stream<uint64>(_stream, link.indexPosition, _format);
write_to_stream<uint64>(_stream, link.dimension, _format);
write_to_stream<size_t>(_stream, link.other, _format);
write_to_stream<size_t>(_stream, link.indexPosition, _format);
write_to_stream<size_t>(_stream, link.dimension, _format);
}
}
if(_format == FileFormat::TSV) { _stream << '\n'; }
......@@ -1467,7 +1467,7 @@ namespace xerus {
}
void stream_reader(std::istream& _stream, TensorNetwork &_obj, const FileFormat _format) {
IF_CHECK( uint64 ver = ) read_from_stream<uint64>(_stream, _format);
IF_CHECK( size_t ver = ) read_from_stream<size_t>(_stream, _format);
REQUIRE(ver == 1, "Unknown stream version to open (" << ver << ")");
// Load dimensions
......@@ -1477,21 +1477,21 @@ namespace xerus {
_obj.externalLinks.resize(_obj.dimensions.size());
for(TensorNetwork::Link& el : _obj.externalLinks) {
el.external = false;
el.other = read_from_stream<uint64>(_stream, _format);
el.indexPosition = read_from_stream<uint64>(_stream, _format);
el.dimension = read_from_stream<uint64>(_stream, _format);
el.other = read_from_stream<size_t>(_stream, _format);
el.indexPosition = read_from_stream<size_t>(_stream, _format);
el.dimension = read_from_stream<size_t>(_stream, _format);
}
// Load nodes with their links
_obj.nodes.resize(read_from_stream<uint64>(_stream, _format));
_obj.nodes.resize(read_from_stream<size_t>(_stream, _format));
for(TensorNetwork::TensorNode& node : _obj.nodes) {
node.neighbors.resize(read_from_stream<uint64>(_stream, _format));
node.neighbors.resize(read_from_stream<size_t>(_stream, _format));
node.erased = false;
for(TensorNetwork::Link& link : node.neighbors) {
link.external = read_from_stream<bool>(_stream, _format);
link.other = read_from_stream<uint64>(_stream, _format);
link.indexPosition = read_from_stream<uint64>(_stream, _format);
link.dimension = read_from_stream<uint64>(_stream, _format);
link.other = read_from_stream<size_t>(_stream, _format);
link.indexPosition = read_from_stream<size_t>(_stream, _format);
link.dimension = read_from_stream<size_t>(_stream, _format);
}
}
......
......@@ -1450,11 +1450,11 @@ namespace xerus {
_stream << std::setprecision(std::numeric_limits<value_t>::digits10 + 1);
}
// storage version number
write_to_stream<uint64>(_stream, 1, _format);
write_to_stream<size_t>(_stream, 1, _format);
// store TN specific data
write_to_stream<bool>(_stream, _obj.cannonicalized, _format);
write_to_stream<uint64>(_stream, _obj.corePosition, _format);
write_to_stream<size_t>(_stream, _obj.corePosition, _format);
// save rest of TN
write_to_stream<TensorNetwork>(_stream, _obj, _format);
......@@ -1465,12 +1465,12 @@ namespace xerus {
template<bool isOperator>
void stream_reader(std::istream& _stream, TTNetwork<isOperator> &_obj, const misc::FileFormat _format) {
IF_CHECK( uint64 ver = ) read_from_stream<uint64>(_stream, _format);
IF_CHECK( size_t ver = ) read_from_stream<size_t>(_stream, _format);
REQUIRE(ver == 1, "Unknown stream version to open (" << ver << ")");
// load TN specific data
read_from_stream<bool>(_stream, _obj.cannonicalized, _format);
read_from_stream<uint64>(_stream, _obj.corePosition, _format);
read_from_stream<size_t>(_stream, _obj.corePosition, _format);
// load rest of TN
read_from_stream<TensorNetwork>(_stream, _obj, _format);
......
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