Skip to content

Casting routine from files/header#49

Open
frheault wants to merge 4 commits into
tee-ar-ex:mainfrom
frheault:fixes_for_benchmark
Open

Casting routine from files/header#49
frheault wants to merge 4 commits into
tee-ar-ex:mainfrom
frheault:fixes_for_benchmark

Conversation

@frheault

Copy link
Copy Markdown
Contributor

(Similar description to trx-rs PR)

Proposed modifications to allow fair comparison for benchmarking across languages, the biggest modification is to up/down-cast to uint32 offsets since it is not completely illegal. Some of the benchmark files add offsets as uint64. I believe this is mostly to smooth operations between languages, I personally think that virtually no one will create a tractogram with 40M streamlines with 100 points each, but it is possible.

I apologize for the formatting, I believe my VScode did some automatic formatting, @mattcieslak if you could tell me what standard/linter/tool to use (or maybe I should manually revert the identical lines?).

I believe some unit testing is needed to verify if everything is alright, but I tested single language round-trip (load/save) and between language compatibility. Then I benchmarked on big files: https://github.com/tee-ar-ex/trx-manuscript-2026-benchmark

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates AnyTrxFile::_create_from_pointer()’s handling of groups/ entries to allow loading group membership arrays stored in additional integer dtypes by converting them into the internal uint32 representation, enabling more consistent cross-language benchmarking/interoperability.

Changes:

  • Allow groups/ arrays with integer dtypes beyond uint32 (e.g., uint64, int64, int32, uint16, etc.) by casting to uint32.
  • Add a guard intended to prevent unsafe downcasting when NB_STREAMLINES exceeds 32-bit capacity.
  • Materialize group arrays to owned memory before storing in trx.groups.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/trx.cpp Outdated
Comment on lines +537 to +558
if (ext == "int64") {
const int64_t* src = reinterpret_cast<const int64_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
} else if (ext == "uint64") {
const uint64_t* src = reinterpret_cast<const uint64_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
} else if (ext == "uint8") {
const uint8_t* src = reinterpret_cast<const uint8_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
} else if (ext == "int8") {
const int8_t* src = reinterpret_cast<const int8_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
} else if (ext == "uint16") {
const uint16_t* src = reinterpret_cast<const uint16_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
} else if (ext == "int16") {
const int16_t* src = reinterpret_cast<const int16_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
} else if (ext == "int32") {
const int32_t* src = reinterpret_cast<const int32_t*>(tmp_arr.owned.data());
for (size_t i = 0; i < size; ++i) dst[i] = static_cast<uint32_t>(src[i]);
}
Comment thread src/trx.cpp Outdated
Comment on lines +523 to +528
if (ext == "int64" || ext == "uint64") {
uint64_t num_strs = static_cast<uint64_t>(header["NB_STREAMLINES"].number_value());
if (num_strs > 4294967295ULL) {
throw TrxFormatError("downcasting is unsafe because the number of streamlines exceeds the 32-bit limit");
}
}
Comment thread src/trx.cpp Outdated
Comment on lines +519 to +523
} else if (ext == "int64" || ext == "uint64" || ext == "int32" || ext == "uint8" || ext == "int8" || ext == "uint16" || ext == "int16") {
if (ext == "int32" || ext == "uint8" || ext == "int8" || ext == "uint16" || ext == "int16") {
std::cerr << "Warning: Upcasting group from " << ext << " to uint32\n";
}
if (ext == "int64" || ext == "uint64") {
@36000 36000 mentioned this pull request Jun 23, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 13.23308% with 577 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.67%. Comparing base (3921412) to head (8c1fa19).

Files with missing lines Patch % Lines
src/legacy_io.cpp 0.00% 568 Missing ⚠️
src/trx.cpp 82.22% 8 Missing ⚠️
tests/test_trx_anytrxfile.cpp 98.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
- Coverage   88.64%   82.67%   -5.97%     
==========================================
  Files          15       16       +1     
  Lines        7749     8416     +667     
  Branches     1043     1181     +138     
==========================================
+ Hits         6869     6958      +89     
- Misses        880     1458     +578     
Flag Coverage Δ
linux 81.62% <13.35%> (-6.22%) ⬇️
macos 82.52% <13.33%> (-5.96%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants