Skip to content

Commit

Permalink
Merge pull request #114 from TGSAI/106_flattened_warning
Browse files Browse the repository at this point in the history
Resolve warning regarding sizeof(void)
  • Loading branch information
blasscoc authored Sep 13, 2024
2 parents f671a5b + 1d00713 commit 16e570e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
16 changes: 7 additions & 9 deletions mdio/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -1726,18 +1726,16 @@ struct VariableData {
* @endcode
*/
ptrdiff_t get_flattened_offset() {
// TODO(BrianMichell): Implement unit test
auto accessor = get_data_accessor();
auto origin_ptr =
accessor.data(); // The raw pointer to the data. May not start at 0.
auto offset_ptr =
accessor.byte_strided_origin_pointer(); // The raw pointer to the first
// element of the data.
// The raw pointer to the data. May not start at 0.
auto origin_ptr = accessor.data();
// The raw pointer to the first element of the data.
auto offset_ptr = accessor.byte_strided_origin_pointer();
char* origin_addr = reinterpret_cast<char*>(origin_ptr);
char* offset_addr = reinterpret_cast<char*>(
offset_ptr.get()); // We have to get the raw pointer
// We have to get the raw pointer
char* offset_addr = reinterpret_cast<char*>(offset_ptr.get());
ptrdiff_t byte_diff = offset_addr - origin_addr;
return byte_diff / sizeof(T);
return byte_diff / dtype().size();
}

// An identifier for the variable.
Expand Down
19 changes: 19 additions & 0 deletions mdio/variable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,25 @@ TEST(VariableData, writeChunkedData) {
std::filesystem::remove_all("name");
}

TEST(VariableData, flattenedOffset) {
auto json = PopulateStore(json_good).value();
auto variableObject = mdio::Variable<>::Open(json).result();
EXPECT_TRUE(variableObject.ok());

mdio::RangeDescriptor<mdio::Index> desc1 = {"x", 50, 100, 1};
mdio::RangeDescriptor<mdio::Index> desc2 = {"y", 0, 100, 1};
variableObject = variableObject.value().slice(desc1, desc2);

auto variableDataFuture = variableObject->Read();

auto variableDataObject = variableDataFuture.result();
EXPECT_TRUE(variableDataObject.ok());

auto varData = variableDataObject.value();

EXPECT_EQ(varData.get_flattened_offset(), 5000);
}

TEST(VariableData, inMemoryEdits) {
auto json = PopulateStore(json_good).value();
auto variableObject = mdio::Variable<>::Open(json).result();
Expand Down

0 comments on commit 16e570e

Please sign in to comment.