From 6a97e6c9e78a226abf4342d9b72bf1cc0235d775 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Nov 2019 18:02:40 +0100 Subject: endian conversion for binary read --- ripser.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 1ae62e1..59bd8ac 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -830,10 +830,15 @@ enum file_format { BINARY }; +static const uint16_t endian_check(0xff00); +static const bool is_big_endian = *reinterpret_cast(&endian_check); + template T read(std::istream& input_stream) { T result; - input_stream.read(reinterpret_cast(&result), sizeof(T)); - return result; // on little endian: boost::endian::little_to_native(result); + char* p = reinterpret_cast(&result); + input_stream.read(p, sizeof(T)); + if (is_big_endian) std::reverse(p, p + sizeof(T)); + return result; } compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) { -- cgit v1.2.3 From 47458eed67680f0beba78335b21748c1bfebeb76 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Tue, 10 Dec 2019 17:17:11 +0100 Subject: fix to read, properly handling premature end of file --- ripser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ripser.cpp b/ripser.cpp index 59bd8ac..5bc62bc 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -836,7 +836,7 @@ static const bool is_big_endian = *reinterpret_cast(&endian_chec template T read(std::istream& input_stream) { T result; char* p = reinterpret_cast(&result); - input_stream.read(p, sizeof(T)); + if (input_stream.read(p, sizeof(T)) != sizeof(T) return T(); if (is_big_endian) std::reverse(p, p + sizeof(T)); return result; } -- cgit v1.2.3 From 67cfa5f488dede857f73059e737cdaea0dedd9b5 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 10 Jan 2020 08:32:06 +0100 Subject: fixed compile error pointed out by adamConnerSax --- ripser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ripser.cpp b/ripser.cpp index 5bc62bc..cd546e8 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -836,7 +836,7 @@ static const bool is_big_endian = *reinterpret_cast(&endian_chec template T read(std::istream& input_stream) { T result; char* p = reinterpret_cast(&result); - if (input_stream.read(p, sizeof(T)) != sizeof(T) return T(); + if (input_stream.read(p, sizeof(T)).gcount() != sizeof(T)) return T(); if (is_big_endian) std::reverse(p, p + sizeof(T)); return result; } -- cgit v1.2.3 From 286d3696796a707eecd0f71e6377880f60c936da Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Mon, 27 Jan 2020 15:16:43 +0100 Subject: fixed documentation: the binary format for distance values is 32 bit, not 64 bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ce826f..51029bf 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ The input is given either in a file whose name is passed as an argument, or thro - `distance`: full distance matrix; similar to the above, but for all entries of the distance matrix. One line per row of the matrix; only the part below the diagonal is actually read. - `dipha`: DIPHA distance matrix as described on the [DIPHA] website. - `point-cloud`: point cloud; a comma (or whitespace, or other non-numerical character) separated list of coordinates of the points in some Euclidean space, one point per line. - - `binary`: lower distance matrix in binary file format; a sequence of the distance matrix entries below the diagonal in 64 bit double format (IEEE 754, little endian). + - `binary`: lower distance matrix in binary file format; a sequence of the distance matrix entries below the diagonal in 32 bit double format (IEEE 754, little endian). - `sparse`: sparse triplet format; a whitespace separated list of entries of a sparse distance matrix, one entry per line, each of the form *i j d(i,j)* specifying the distance between points *i* and *j*. Each pair of points should appear in the file at most once. - `--dim k`: compute persistent homology up to dimension *k*. - `--threshold t`: compute Rips complexes up to diameter *t*. -- cgit v1.2.3