summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGard Spreemann <gspr@nonempty.org>2020-02-06 11:15:40 +0100
committerGard Spreemann <gspr@nonempty.org>2020-02-06 11:15:40 +0100
commita6a42128c65a4ad78d17a3198fb8b12f0b1ec914 (patch)
tree31ec00d9c2e82dc02245a5c1c946bd904afde259
parent74048b53e8eaa5c11071e376ffcd711506bc6445 (diff)
parent286d3696796a707eecd0f71e6377880f60c936da (diff)
Merge branch 'upstream/latest' into debian/sid
-rw-r--r--README.md2
-rw-r--r--ripser.cpp9
2 files changed, 8 insertions, 3 deletions
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*.
diff --git a/ripser.cpp b/ripser.cpp
index 1ae62e1..cd546e8 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<const uint8_t*>(&endian_check);
+
template <typename T> T read(std::istream& input_stream) {
T result;
- input_stream.read(reinterpret_cast<char*>(&result), sizeof(T));
- return result; // on little endian: boost::endian::little_to_native(result);
+ char* p = reinterpret_cast<char*>(&result);
+ if (input_stream.read(p, sizeof(T)).gcount() != sizeof(T)) return T();
+ if (is_big_endian) std::reverse(p, p + sizeof(T));
+ return result;
}
compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) {