Skip to content

Commit 2becd7a

Browse files
authored
Merge pull request #163 from thiago-carneiro/main
fix missing inlines in various headers and incorrect pointers in 'from_variable'
2 parents ba18d0f + 62ec3ce commit 2becd7a

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

mdio/dataset.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace internal {
5353
* @return An `mdio::Result` containing the .zarray JSON metadata on success, or
5454
* an error on failure.
5555
*/
56-
Result<nlohmann::json> get_zarray(const ::nlohmann::json metadata) {
56+
inline Result<nlohmann::json> get_zarray(const ::nlohmann::json metadata) {
5757
// derive .zarray json metadata (without reading it).
5858
auto json =
5959
metadata; // Why am I doing this? It's an extra copy that does nothing!
@@ -125,7 +125,7 @@ Result<nlohmann::json> get_zarray(const ::nlohmann::json metadata) {
125125
* @param json_variables The JSON variables.
126126
* @return An `mdio::Future<void>` representing the asynchronous write.
127127
*/
128-
Future<void> write_zmetadata(
128+
inline Future<void> write_zmetadata(
129129
const ::nlohmann::json& dataset_metadata,
130130
const std::vector<::nlohmann::json>& json_variables) {
131131
// header material at the root of the dataset ...
@@ -252,7 +252,7 @@ Future<void> write_zmetadata(
252252
* It will default to the "file" driver if no prefix is found.
253253
* @param dataset_path The path to the dataset.
254254
*/
255-
Future<tensorstore::KvStore> dataset_kvs_store(
255+
inline Future<tensorstore::KvStore> dataset_kvs_store(
256256
const std::string& dataset_path) {
257257
// the tensorstore driver needs a bucket field
258258
::nlohmann::json kvstore;
@@ -298,7 +298,7 @@ Future<tensorstore::KvStore> dataset_kvs_store(
298298
* @return An `mdio::Future` containing the .zmetadata JSON on success, or an
299299
* error on failure.
300300
*/
301-
Future<std::tuple<::nlohmann::json, std::vector<::nlohmann::json>>>
301+
inline Future<std::tuple<::nlohmann::json, std::vector<::nlohmann::json>>>
302302
from_zmetadata(const std::string& dataset_path) {
303303
// e.g. dataset_path = "zarrs/acceptance/";
304304
// FIXME - enable async

mdio/dataset_factory.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @param raw A string to be encoded
3737
* @return A string encoded in base64
3838
*/
39-
std::string encode_base64(const std::string raw) {
39+
inline std::string encode_base64(const std::string raw) {
4040
std::string encoded = absl::Base64Escape(raw);
4141
return encoded;
4242
}
@@ -50,7 +50,7 @@ std::string encode_base64(const std::string raw) {
5050
* @return A string representing the dtype in numpy format limited to the dtypes
5151
* supported by MDIO Dataset
5252
*/
53-
tensorstore::Result<std::string> to_zarr_dtype(const std::string dtype) {
53+
inline tensorstore::Result<std::string> to_zarr_dtype(const std::string dtype) {
5454
// Convert the input dtype to Zarr dtype
5555
if (dtype == "int8") {
5656
return "<i1";
@@ -93,8 +93,8 @@ tensorstore::Result<std::string> to_zarr_dtype(const std::string dtype) {
9393
* @return OkStatus if successful, InvalidArgumentError if dtype is not
9494
* supported
9595
*/
96-
absl::Status transform_dtype(nlohmann::json& input /*NOLINT*/,
97-
nlohmann::json& variable /*NOLINT*/) {
96+
inline absl::Status transform_dtype(nlohmann::json& input /*NOLINT*/,
97+
nlohmann::json& variable /*NOLINT*/) {
9898
if (input["dataType"].contains("fields")) {
9999
nlohmann::json dtypeFields = nlohmann::json::array();
100100
for (const auto& field : input["dataType"]["fields"]) {
@@ -124,8 +124,8 @@ absl::Status transform_dtype(nlohmann::json& input /*NOLINT*/,
124124
* @return OkStatus if successful, InvalidArgumentError if compressor is invalid
125125
* for MDIO
126126
*/
127-
absl::Status transform_compressor(nlohmann::json& input /*NOLINT*/,
128-
nlohmann::json& variable /*NOLINT*/) {
127+
inline absl::Status transform_compressor(nlohmann::json& input /*NOLINT*/,
128+
nlohmann::json& variable /*NOLINT*/) {
129129
if (input.contains("compressor")) {
130130
if (input["compressor"].contains("name")) {
131131
if (input["compressor"]["name"] != "blosc") {
@@ -182,7 +182,7 @@ absl::Status transform_compressor(nlohmann::json& input /*NOLINT*/,
182182
* before this step This presumes that the user does not attempt to use these
183183
* functions directly
184184
*/
185-
void transform_shape(
185+
inline void transform_shape(
186186
nlohmann::json& input /*NOLINT*/, nlohmann::json& variable /*NOLINT*/,
187187
std::unordered_map<std::string, uint64_t>& dimensionMap /*NOLINT*/) {
188188
if (input["dimensions"][0].is_object()) {
@@ -208,8 +208,8 @@ void transform_shape(
208208
* @param variable A Variable stub (Will be modified)
209209
* @return OkStatus if successful, InvalidArgumentError if the path is invalid
210210
*/
211-
absl::Status transform_metadata(const std::string& path,
212-
nlohmann::json& variable /*NOLINT*/) {
211+
inline absl::Status transform_metadata(const std::string& path,
212+
nlohmann::json& variable /*NOLINT*/) {
213213
std::string bucket =
214214
"NULL"; // Default value, if is NULL don't add a bucket field
215215
std::string driver = "file";
@@ -261,7 +261,7 @@ absl::Status transform_metadata(const std::string& path,
261261
* @param dimensionMap A map of dimension names to sizes
262262
* @return A Variable spec or an error if the Variable spec is invalid
263263
*/
264-
tensorstore::Result<nlohmann::json> from_json_to_spec(
264+
inline tensorstore::Result<nlohmann::json> from_json_to_spec(
265265
nlohmann::json& json /*NOLINT*/,
266266
std::unordered_map<std::string, uint64_t>& dimensionMap /*NOLINT*/,
267267
const std::string& path) {
@@ -404,8 +404,8 @@ tensorstore::Result<nlohmann::json> from_json_to_spec(
404404
* @return A map of dimension names to sizes or error if the dimensions are not
405405
* consistently sized
406406
*/
407-
tensorstore::Result<std::unordered_map<std::string, uint64_t>> get_dimensions(
408-
nlohmann::json& spec /*NOLINT*/) {
407+
inline tensorstore::Result<std::unordered_map<std::string, uint64_t>>
408+
get_dimensions(nlohmann::json& spec /*NOLINT*/) {
409409
std::unordered_map<std::string, uint64_t> dimensions;
410410
for (auto& variable : spec["variables"]) {
411411
if (variable["dimensions"][0].is_object()) {
@@ -438,7 +438,8 @@ tensorstore::Result<std::unordered_map<std::string, uint64_t>> get_dimensions(
438438
* @param spec A Dataset spec
439439
* @return A vector of Variable specs or an error if the Dataset spec is invalid
440440
*/
441-
tensorstore::Result<std::tuple<nlohmann::json, std::vector<nlohmann::json>>>
441+
inline tensorstore::Result<
442+
std::tuple<nlohmann::json, std::vector<nlohmann::json>>>
442443
Construct(nlohmann::json& spec /*NOLINT*/, const std::string& path) {
443444
// Validation should only return status codes. If it returns data then it
444445
// should be a "constructor"

mdio/dataset_validator.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
* @brief Checks if a key exists in a map
3131
* Specific for our case of {coordinate: index} mapping
3232
*/
33-
bool contains(const std::unordered_set<std::string>& set,
34-
const std::string key) {
33+
inline bool contains(const std::unordered_set<std::string>& set,
34+
const std::string key) {
3535
return set.count(key);
3636
}
3737

@@ -42,7 +42,7 @@ bool contains(const std::unordered_set<std::string>& set,
4242
* @return OkStatus if valid, NotFoundError if schema file load fails,
4343
* InvalidArgumentError if validation fails for any reason
4444
*/
45-
absl::Status validate_schema(nlohmann::json& spec /*NOLINT*/) {
45+
inline absl::Status validate_schema(nlohmann::json& spec /*NOLINT*/) {
4646
nlohmann::json targetSchema =
4747
nlohmann::json::parse(kDatasetSchema, nullptr, false);
4848
if (targetSchema.is_discarded()) {
@@ -72,7 +72,7 @@ absl::Status validate_schema(nlohmann::json& spec /*NOLINT*/) {
7272
* @return OkStatus if valid, InvalidArgumentError if a coordinate does not have
7373
* a matching Variable.
7474
*/
75-
absl::Status validate_coordinates_present(const nlohmann::json& spec) {
75+
inline absl::Status validate_coordinates_present(const nlohmann::json& spec) {
7676
// Build a mapping of all the dimension coordinates
7777
std::unordered_set<std::string>
7878
dimension; // name of all 1-d Variables who's name matches the dimension
@@ -145,7 +145,7 @@ absl::Status validate_coordinates_present(const nlohmann::json& spec) {
145145
* reason
146146
147147
*/
148-
absl::Status validate_dataset(nlohmann::json& spec /*NOLINT*/) {
148+
inline absl::Status validate_dataset(nlohmann::json& spec /*NOLINT*/) {
149149
absl::Status schemaStatus = validate_schema(spec);
150150
if (!schemaStatus.ok()) {
151151
return schemaStatus;

mdio/utils/delete.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace utils {
3434
* @return OK result if the dataset was valid and deleted successfully,
3535
* otherwise an error result
3636
*/
37-
Result<void> DeleteDataset(const std::string dataset_path) {
37+
inline Result<void> DeleteDataset(const std::string dataset_path) {
3838
// Open the dataset
3939
// This is to ensure that what is getting deleted by MDIO is a valid MDIO
4040
// dataset itself.

mdio/variable.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ namespace internal {
214214
* @return A driver specific message if the status is a missing driver message,
215215
* otherwise the original status.
216216
*/
217-
absl::Status CheckMissingDriverStatus(const absl::Status& status) {
217+
inline absl::Status CheckMissingDriverStatus(const absl::Status& status) {
218218
std::string error(status.message());
219219
if (error.find("Error parsing object member \"driver\"") !=
220220
std::string::npos) {
@@ -1837,10 +1837,12 @@ Result<VariableData<T, R, OriginKind>> from_variable(
18371837
size_t element_size = variable.dtype().size();
18381838

18391839
if (variable.dtype() == constants::kFloat32) {
1840-
auto* data = reinterpret_cast<float*>(_array.data());
1840+
auto* data =
1841+
reinterpret_cast<float*>(_array.byte_strided_origin_pointer().get());
18411842
std::fill_n(data, num_elements, std::numeric_limits<float>::quiet_NaN());
18421843
} else { // double
1843-
auto* data = reinterpret_cast<double*>(_array.data());
1844+
auto* data =
1845+
reinterpret_cast<double*>(_array.byte_strided_origin_pointer().get());
18441846
std::fill_n(data, num_elements, std::numeric_limits<double>::quiet_NaN());
18451847
}
18461848
}

0 commit comments

Comments
 (0)