Skip to content

Commit 16e570e

Browse files
authored
Merge pull request #114 from TGSAI/106_flattened_warning
Resolve warning regarding sizeof(void)
2 parents f671a5b + 1d00713 commit 16e570e

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

mdio/variable.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,18 +1726,16 @@ struct VariableData {
17261726
* @endcode
17271727
*/
17281728
ptrdiff_t get_flattened_offset() {
1729-
// TODO(BrianMichell): Implement unit test
17301729
auto accessor = get_data_accessor();
1731-
auto origin_ptr =
1732-
accessor.data(); // The raw pointer to the data. May not start at 0.
1733-
auto offset_ptr =
1734-
accessor.byte_strided_origin_pointer(); // The raw pointer to the first
1735-
// element of the data.
1730+
// The raw pointer to the data. May not start at 0.
1731+
auto origin_ptr = accessor.data();
1732+
// The raw pointer to the first element of the data.
1733+
auto offset_ptr = accessor.byte_strided_origin_pointer();
17361734
char* origin_addr = reinterpret_cast<char*>(origin_ptr);
1737-
char* offset_addr = reinterpret_cast<char*>(
1738-
offset_ptr.get()); // We have to get the raw pointer
1735+
// We have to get the raw pointer
1736+
char* offset_addr = reinterpret_cast<char*>(offset_ptr.get());
17391737
ptrdiff_t byte_diff = offset_addr - origin_addr;
1740-
return byte_diff / sizeof(T);
1738+
return byte_diff / dtype().size();
17411739
}
17421740

17431741
// An identifier for the variable.

mdio/variable_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,25 @@ TEST(VariableData, writeChunkedData) {
10541054
std::filesystem::remove_all("name");
10551055
}
10561056

1057+
TEST(VariableData, flattenedOffset) {
1058+
auto json = PopulateStore(json_good).value();
1059+
auto variableObject = mdio::Variable<>::Open(json).result();
1060+
EXPECT_TRUE(variableObject.ok());
1061+
1062+
mdio::RangeDescriptor<mdio::Index> desc1 = {"x", 50, 100, 1};
1063+
mdio::RangeDescriptor<mdio::Index> desc2 = {"y", 0, 100, 1};
1064+
variableObject = variableObject.value().slice(desc1, desc2);
1065+
1066+
auto variableDataFuture = variableObject->Read();
1067+
1068+
auto variableDataObject = variableDataFuture.result();
1069+
EXPECT_TRUE(variableDataObject.ok());
1070+
1071+
auto varData = variableDataObject.value();
1072+
1073+
EXPECT_EQ(varData.get_flattened_offset(), 5000);
1074+
}
1075+
10571076
TEST(VariableData, inMemoryEdits) {
10581077
auto json = PopulateStore(json_good).value();
10591078
auto variableObject = mdio::Variable<>::Open(json).result();

0 commit comments

Comments
 (0)