Skip to content

Commit

Permalink
Added getters for Variable rank
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMichell committed Oct 10, 2024
1 parent 7ea1434 commit 7c6b97d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit 7c6b97d

Please sign in to comment.