From 49b52f9546a681f1fb8a8ab536508b2a68166b1e Mon Sep 17 00:00:00 2001 From: Maria Markova Date: Sat, 20 Sep 2025 22:40:41 +0200 Subject: [PATCH] Add element_size function for Dataset elements --- include/svs/core/data/simple.h | 5 +++++ include/svs/quantization/scalar/scalar.h | 1 + tests/svs/core/data.cpp | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/svs/core/data/simple.h b/include/svs/core/data/simple.h index 3ceb8126a..d14141d1f 100644 --- a/include/svs/core/data/simple.h +++ b/include/svs/core/data/simple.h @@ -292,6 +292,9 @@ class SimpleData { /// Return the number of dimensions for each entry in the dataset. size_t dimensions() const { return getsize<1>(data_); } + /// Return The size in bytes of one vector: sizeof(element_type) * dimensions() + size_t element_size() const { return sizeof(element_type) * dimensions(); } + /// /// @brief Return a constant handle to vector stored as position ``i``. /// @@ -720,6 +723,8 @@ class SimpleData> { } } + size_t element_size() const { return sizeof(element_type) * dimensions(); } + const_value_type get_datum(size_t i) const { auto [block_id, data_id] = resolve(i); return getindex(blocks_, block_id).slice(data_id); diff --git a/include/svs/quantization/scalar/scalar.h b/include/svs/quantization/scalar/scalar.h index e55bf5d2c..7ddf1cb9d 100644 --- a/include/svs/quantization/scalar/scalar.h +++ b/include/svs/quantization/scalar/scalar.h @@ -390,6 +390,7 @@ class SQDataset { size_t size() const { return data_.size(); } size_t dimensions() const { return data_.dimensions(); } + size_t element_size() const { return sizeof(element_type) * dimensions(); } float get_scale() const { return scale_; } float get_bias() const { return bias_; } diff --git a/tests/svs/core/data.cpp b/tests/svs/core/data.cpp index ee7896ce2..2b7f56c0c 100644 --- a/tests/svs/core/data.cpp +++ b/tests/svs/core/data.cpp @@ -88,3 +88,21 @@ CATCH_TEST_CASE("Data Loading/Saving", "[core][data]") { CATCH_REQUIRE(w == z); } } + +CATCH_TEST_CASE("Element Size", "[core][data]") { + CATCH_SECTION("Check element_size()") { + // Test with float, dynamic dimensions + auto float_data = svs::data::SimpleData(5, 10); + CATCH_REQUIRE(float_data.element_size() == sizeof(float) * 10); + + // Test fixed dimensions with blocked storage + auto blocked_fixed = svs::data::BlockedData(25, 64); + CATCH_REQUIRE(blocked_fixed.element_size() == sizeof(int32_t) * 64); + + // Test element_size consistency across different instances + auto data1 = svs::data::SimpleData(10, 20); + auto data2 = + svs::data::SimpleData(50, 20); // Different size, same dims + CATCH_REQUIRE(data1.element_size() == data2.element_size()); + } +}