Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added getters for Variable rank #129

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
12 changes: 12 additions & 0 deletions mdio/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,12 @@ class Variable {
*/
IndexDomainView<R> dimensions() const { return store.domain(); }

/**
* @brief Gets the rank of the variable.
* @return std::size_t The rank of the variable.
*/
std::size_t rank() const { return store.rank(); }

/**
* @brief Returns the number of samples in the variable.
* @return Index The number of samples in the variable.
Expand Down Expand Up @@ -1687,6 +1693,12 @@ struct VariableData {
*/
IndexDomainView<R> dimensions() const { return data.domain; }

/**
* @brief Gets the rank of the VariableData
* @return std::size_t The rank of the VariableData
*/
std::size_t rank() const { return data.data.rank(); }

/**
* @brief Returns the number of samples in the variable.
* @return Index The number of samples in the variable.
Expand Down
22 changes: 22 additions & 0 deletions mdio/variable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ TEST(Variable, open) {
std::filesystem::remove_all("name");
}

TEST(Variable, rank) {
auto variable =
mdio::Variable<>::Open(json_good, mdio::constants::kCreateClean);
ASSERT_TRUE(variable.status().ok()) << variable.status();
auto rank = variable.value().rank();
EXPECT_EQ(rank, 2);
std::filesystem::remove_all("name");
}

TEST(Variable, openMetadata) {
auto json = json_good["metadata"];

Expand Down Expand Up @@ -1050,6 +1059,19 @@ TEST(VariableData, testConstruction) {
std::filesystem::remove_all("name");
}

TEST(VariableData, rank) {
auto variableFuture =
mdio::Variable<>::Open(json_good, mdio::constants::kCreateClean);
ASSERT_TRUE(variableFuture.status().ok()) << variableFuture.status();
auto variableObject = variableFuture.value();
auto variableDataFuture = variableObject.Read();
ASSERT_TRUE(variableDataFuture.status().ok()) << variableDataFuture.status();
auto variableDataObject = variableDataFuture.result();
EXPECT_EQ(variableDataObject.value().rank(), 2);

std::filesystem::remove_all("name");
}

TEST(VariableData, writeChunkedData) {
auto result =
mdio::Variable<>::Open(json_good, mdio::constants::kCreateClean).result();
Expand Down
Loading