Skip to content

Commit

Permalink
Add complex dtype support
Browse files Browse the repository at this point in the history
  • Loading branch information
calgray committed Sep 26, 2024
1 parent c77f42e commit e9da3d0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/z5/filesystem/factory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace filesystem {
ptr.reset(new Dataset<float>(dataset, metadata)); break;
case types::float64:
ptr.reset(new Dataset<double>(dataset, metadata)); break;
case types::complex64:
ptr.reset(new Dataset<std::complex<float>>(dataset, metadata)); break;
case types::complex128:
ptr.reset(new Dataset<std::complex<double>>(dataset, metadata)); break;
}
return ptr;
}
Expand Down
2 changes: 2 additions & 0 deletions include/z5/metadata.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ namespace z5 {
} else {
throw std::runtime_error("Invalid string value for fillValue");
}
} else if(fillValJson.type() == nlohmann::json::value_t::null) {
fillValue = std::numeric_limits<double>::quiet_NaN();
} else {
fillValue = static_cast<double>(fillValJson);
}
Expand Down
9 changes: 6 additions & 3 deletions include/z5/types/types.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace types {
enum Datatype {
int8, int16, int32, int64,
uint8, uint16, uint32, uint64,
float32, float64
float32, float64,
complex64, complex128
};

struct Datatypes {
Expand All @@ -38,15 +39,17 @@ namespace types {
static DtypeMap & zarrToDtype() {
static DtypeMap dtypeMap({{{"|i1", int8}, {"<i2", int16}, {"<i4", int32}, {"<i8", int64},
{"|u1", uint8}, {"<u2", uint16}, {"<u4", uint32}, {"<u8", uint64},
{"<f4", float32}, {"<f8", float64}}});
{"<f4", float32}, {"<f8", float64},
{"<c8", complex64}, {"<c16", complex128}}});
return dtypeMap;
}

static InverseDtypeMap & dtypeToZarr() {

static InverseDtypeMap dtypeMap({{{int8 , "|i1"}, {int16, "<i2"}, {int32, "<i4"}, {int64, "<i8"},
{uint8 , "|u1"}, {uint16, "<u2"}, {uint32, "<u4"},{uint64,"<u8"},
{float32, "<f4"}, {float64,"<f8"}}});
{float32, "<f4"}, {float64,"<f8"},
{complex64, "<c8"}, {complex128, "<c16"}}});
return dtypeMap;
}

Expand Down
11 changes: 11 additions & 0 deletions src/python/lib/dataset.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ namespace z5 {
// float types
exportIoT<float>(module, "float32");
exportIoT<double>(module, "float64");
// complex types
exportIoT<std::complex<float>>(module, "complex64");
exportIoT<std::complex<double>>(module, "complex128");

// export writing scalars
// The overloads cannot be properly resolved,
Expand Down Expand Up @@ -281,6 +284,14 @@ namespace z5 {
static_cast<double>(val),
numberOfThreads);
break;
case types::Datatype::complex64 : writePyScalar<std::complex<float>>(ds, roiBegin, roiShape,
static_cast<std::complex<float>>(val),
numberOfThreads);
break;
case types::Datatype::complex128 : writePyScalar<std::complex<double>>(ds, roiBegin, roiShape,
static_cast<std::complex<double>>(val),
numberOfThreads);
break;
default: throw(std::runtime_error("Invalid datatype"));

}
Expand Down

0 comments on commit e9da3d0

Please sign in to comment.