Skip to content

Commit db7cd95

Browse files
committed
Add element_size function for Dataset elements
1 parent 0c588d7 commit db7cd95

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/svs/core/data/simple.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ class SimpleData {
292292
/// Return the number of dimensions for each entry in the dataset.
293293
size_t dimensions() const { return getsize<1>(data_); }
294294

295+
/// Return The size in bytes of one vector: sizeof(element_type) * dimensions()
296+
size_t element_size() const { return sizeof(element_type) * dimensions(); }
297+
295298
///
296299
/// @brief Return a constant handle to vector stored as position ``i``.
297300
///
@@ -720,6 +723,8 @@ class SimpleData<T, Extent, Blocked<Alloc>> {
720723
}
721724
}
722725

726+
size_t element_size() const { return sizeof(element_type) * dimensions(); }
727+
723728
const_value_type get_datum(size_t i) const {
724729
auto [block_id, data_id] = resolve(i);
725730
return getindex(blocks_, block_id).slice(data_id);

include/svs/quantization/scalar/scalar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ class SQDataset {
390390

391391
size_t size() const { return data_.size(); }
392392
size_t dimensions() const { return data_.dimensions(); }
393+
size_t element_size() const { return sizeof(element_type) * dimensions(); }
393394

394395
float get_scale() const { return scale_; }
395396
float get_bias() const { return bias_; }

tests/svs/core/data.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,20 @@ CATCH_TEST_CASE("Data Loading/Saving", "[core][data]") {
8888
CATCH_REQUIRE(w == z);
8989
}
9090
}
91+
92+
CATCH_TEST_CASE("Element Size", "[core][data]") {
93+
CATCH_SECTION("Check element_size()") {
94+
// Test with float, dynamic dimensions
95+
auto float_data = svs::data::SimpleData<float, svs::Dynamic>(5, 10);
96+
CATCH_REQUIRE(float_data.element_size() == sizeof(float) * 10);
97+
98+
// Test fixed dimensions with blocked storage
99+
auto blocked_fixed = svs::data::BlockedData<int32_t, 64>(25, 64);
100+
CATCH_REQUIRE(blocked_fixed.element_size() == sizeof(int32_t) * 64);
101+
102+
// Test element_size consistency across different instances
103+
auto data1 = svs::data::SimpleData<float, svs::Dynamic>(10, 20);
104+
auto data2 = svs::data::SimpleData<float, svs::Dynamic>(50, 20); // Different size, same dims
105+
CATCH_REQUIRE(data1.element_size() == data2.element_size());
106+
}
107+
}

0 commit comments

Comments
 (0)