Skip to content

Commit

Permalink
Simplified namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
odlomax committed Aug 13, 2024
1 parent cb50361 commit 43954ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
7 changes: 2 additions & 5 deletions src/atlas/util/PackVectorFields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ void copyFieldData(ComponentField& componentField, VectorField& vectorField,

} // namespace

namespace pack_vector_fields {

FieldSet pack(const FieldSet& fields, FieldSet packedFields) {
FieldSet pack_vector_fields(const FieldSet& fields, FieldSet packedFields) {
// Get the number of variables for each vector field.
auto vectorSizeMap = std::map<std::string, idx_t>{};
for (const auto& field : fields) {
Expand Down Expand Up @@ -186,7 +184,7 @@ FieldSet pack(const FieldSet& fields, FieldSet packedFields) {
return packedFields;
}

FieldSet unpack(const FieldSet& fields, FieldSet unpackedFields) {
FieldSet unpack_vector_fields(const FieldSet& fields, FieldSet unpackedFields) {
for (const auto& field : fields) {
auto componentFieldMetadataVector = std::vector<LocalConfiguration>{};
if (!field.metadata().get("component field metadata",
Expand Down Expand Up @@ -227,6 +225,5 @@ FieldSet unpack(const FieldSet& fields, FieldSet unpackedFields) {
return unpackedFields;
}

} // namespace pack_vector_fields
} // namespace util
} // namespace atlas
9 changes: 4 additions & 5 deletions src/atlas/util/PackVectorFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class LocalConfiguration;
namespace atlas {
namespace util {

namespace pack_vector_fields {

/// @brief Packs vector field components into vector fields
///
/// @details Iterates through @param fields and creates vector fields from any
Expand All @@ -26,16 +24,17 @@ namespace pack_vector_fields {
/// field set.
/// Note, a mutable @param packedFields field set can be supplied if
/// one needs to guarantee the order of the packed fields
FieldSet pack(const FieldSet& fields, FieldSet packedFields = FieldSet{});
FieldSet pack_vector_fields(const FieldSet& fields,
FieldSet packedFields = FieldSet{});

/// @brief Unpacks vector field into vector field components.
///
/// @details Undoes "pack" operation when a set of packed fields are supplied
/// as @param fields. A mutable @param unpackedFields field set can be
/// supplied if one needs to guarantee the order of the unpacked
/// fields.
FieldSet unpack(const FieldSet& fields, FieldSet unpackedFields = FieldSet{});
}; // namespace pack_vector_fields
FieldSet unpack_vector_fields(const FieldSet& fields,
FieldSet unpackedFields = FieldSet{});

} // namespace util
} // namespace atlas
16 changes: 8 additions & 8 deletions src/tests/util/test_pack_vector_fields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ void checkTestFields(const FieldSet& fields) {
CASE("Basic pack and unpack") {
const auto fields = createOrderedTestFields();

const auto packedFields = util::pack_vector_fields::pack(fields);
const auto packedFields = util::pack_vector_fields(fields);

EXPECT(!packedFields.has("vector component 0"));
EXPECT(!packedFields.has("vector component 1"));
EXPECT(packedFields.has("vector"));
EXPECT(packedFields.has("scalar"));

const auto unpackedFields = util::pack_vector_fields::unpack(packedFields);
const auto unpackedFields = util::unpack_vector_fields(packedFields);

EXPECT(unpackedFields.has("vector component 0"));
EXPECT(unpackedFields.has("vector component 1"));
Expand All @@ -198,7 +198,7 @@ CASE("Basic pack and unpack") {
CASE("unpack into existing field set") {
auto fields = createUnorderedTestFields();

const auto packedFields = util::pack_vector_fields::pack(fields);
const auto packedFields = util::pack_vector_fields(fields);

EXPECT(!packedFields.has("vector component 0"));
EXPECT(!packedFields.has("vector component 1"));
Expand All @@ -208,7 +208,7 @@ CASE("unpack into existing field set") {
// Need to unpack into existing field to guarantee field order is preserved.
array::make_view<float, 1>(fields["vector component 0"]).assign(0.);
array::make_view<float, 1>(fields["vector component 1"]).assign(0.);
util::pack_vector_fields::unpack(packedFields, fields);
util::unpack_vector_fields(packedFields, fields);

EXPECT(fields.has("vector component 0"));
EXPECT(fields.has("vector component 1"));
Expand All @@ -220,13 +220,13 @@ CASE("unpack into existing field set") {

CASE("check that bad inputs throw") {
// Try to apply pack to inconsistent field sets.
EXPECT_THROWS(util::pack_vector_fields::pack(createInconsistentRankFields()));
EXPECT_THROWS(util::pack_vector_fields(createInconsistentRankFields()));
EXPECT_THROWS(
util::pack_vector_fields::pack(createInconsistentDatatypeFields()));
util::pack_vector_fields(createInconsistentDatatypeFields()));
EXPECT_THROWS(
util::pack_vector_fields::pack(createInconsistentLevelsFields()));
util::pack_vector_fields(createInconsistentLevelsFields()));
EXPECT_THROWS(
util::pack_vector_fields::pack(createInconsistentVariablesFields()));
util::pack_vector_fields(createInconsistentVariablesFields()));
}

} // namespace test
Expand Down

0 comments on commit 43954ef

Please sign in to comment.