Support larger TRX files - #55
Open
36000 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates TRX reading/writing and in-memory handling to support tractograms with large vertex/streamline counts (and 64-bit offsets), addressing crashes when counts/offsets exceed 32-bit limits (issue #50).
Changes:
- Switch many count/shape variables from
inttoint64_tacross TRX loading, saving, resizing, and mmap shapes. - Introduce
_json_int64()and replace severalint_value()reads to avoid 32-bit truncation when consuming header counts. - Update mmap/remap helpers and shard-merge header writing to better accommodate large datasets.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/trx.cpp |
Widened header parsing/counts and mmap shape handling; updated shard merge header counts to avoid 32-bit truncation. |
include/trx/trx.tpp |
Propagated 64-bit counts/shapes through TrxFile construction, loading, resizing, saving, and subset operations. |
include/trx/trx.h |
Added _json_int64() and widened several public/internal count fields and APIs to int64_t. |
include/trx/detail/dtype_helpers.h |
Updated remap and length-computation helpers to accept 64-bit dimensions/counts. |
Suppressed comments (1)
src/trx.cpp:916
- _create_memmap computes
filesizevia unchecked multiplication and, when the file is missing, calls allocate_file() which writes astd::string(filesize, '\0'). For large TRX datasets this can overflow size_t (producing a too-small mapping) and/or try to allocate enormous RAM just to preallocate the file, defeating the goal of supporting large files. Consider adding overflow/negative-shape checks and preallocating with filesystem resize (or seek+write) instead of materializing the full file in memory.
mio::shared_mmap_sink _create_memmap(std::string filename,
const std::tuple<int64_t, int64_t> &shape,
const std::string &mode,
const std::string &dtype,
long long offset) {
static_cast<void>(mode);
const std::size_t filesize = static_cast<std::size_t>(std::get<0>(shape)) *
static_cast<std::size_t>(std::get<1>(shape)) *
static_cast<std::size_t>(trx::detail::_sizeof_dtype(dtype));
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+82
to
+84
| inline int64_t _json_int64(const json &value) { | ||
| return static_cast<int64_t>(value.number_value()); | ||
| } |
Comment on lines
+1694
to
+1695
| merged_header = _json_set(merged_header, "NB_VERTICES", static_cast<double>(total_vertices)); | ||
| merged_header = _json_set(merged_header, "NB_STREAMLINES", static_cast<double>(total_streamlines)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I updated the code to handle tractograms with large numbers of vertices, fixing #50