forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conversion helpers between map- and array representations
- Loading branch information
1 parent
227cb94
commit 00a014a
Showing
7 changed files
with
118 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "openPMD/UnitDimension.hpp" | ||
#include <algorithm> | ||
#include <iterator> | ||
|
||
namespace openPMD | ||
{ | ||
namespace auxiliary | ||
{ | ||
void fromMapOfUnitDimension( | ||
double *cursor, std::map<UnitDimension, double> const &udim) | ||
{ | ||
for (auto [unit, exponent] : udim) | ||
{ | ||
cursor[static_cast<uint8_t>(unit)] = exponent; | ||
} | ||
} | ||
} // namespace auxiliary | ||
|
||
namespace unit_representations | ||
{ | ||
auto asArray(AsMap const &udim) -> AsArray | ||
{ | ||
AsArray res; | ||
auxiliary::fromMapOfUnitDimension(res.begin(), udim); | ||
return res; | ||
} | ||
auto asMap(AsArray const &array) -> AsMap | ||
{ | ||
AsMap udim; | ||
for (size_t i = 0; i < array.size(); ++i) | ||
{ | ||
if (array[i] != 0) | ||
{ | ||
udim[static_cast<UnitDimension>(i)] = array[i]; | ||
} | ||
} | ||
return udim; | ||
} | ||
|
||
auto asArrays(AsMaps const &vec) -> AsArrays | ||
{ | ||
AsArrays res; | ||
std::transform( | ||
vec.begin(), | ||
vec.end(), | ||
std::back_inserter(res), | ||
[](auto const &map) { return asArray(map); }); | ||
return res; | ||
} | ||
auto asMaps(AsArrays const &vec) -> AsMaps | ||
{ | ||
AsMaps res; | ||
std::transform( | ||
vec.begin(), | ||
vec.end(), | ||
std::back_inserter(res), | ||
[](auto const &array) { return asMap(array); }); | ||
return res; | ||
} | ||
} // namespace unit_representations | ||
} // namespace openPMD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters