Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/svs/core/data/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Return The size in bytes of one vector: sizeof(element_type) * dimensions()
/// 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``.
///
Expand Down Expand Up @@ -720,6 +723,8 @@ class SimpleData<T, Extent, Blocked<Alloc>> {
}
}

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);
Expand Down
1 change: 1 addition & 0 deletions include/svs/quantization/scalar/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down
18 changes: 18 additions & 0 deletions tests/svs/core/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, svs::Dynamic>(5, 10);
CATCH_REQUIRE(float_data.element_size() == sizeof(float) * 10);

// Test fixed dimensions with blocked storage
auto blocked_fixed = svs::data::BlockedData<int32_t, 64>(25, 64);
CATCH_REQUIRE(blocked_fixed.element_size() == sizeof(int32_t) * 64);

// Test element_size consistency across different instances
auto data1 = svs::data::SimpleData<float, svs::Dynamic>(10, 20);
auto data2 =
svs::data::SimpleData<float, svs::Dynamic>(50, 20); // Different size, same dims
Comment on lines +104 to +105
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
auto data2 =
svs::data::SimpleData<float, svs::Dynamic>(50, 20); // Different size, same dims
// Different size, same dims
auto data2 =
svs::data::SimpleData<float, svs::Dynamic>(50, 20);

CATCH_REQUIRE(data1.element_size() == data2.element_size());
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This test looks good. Maybe we can add a similar test for SQDataset here
Also would be great to add a few more supported datatypes to ensure there is not discrepancy.

Loading