Skip to content

Commit

Permalink
Add complex256 dtype support
Browse files Browse the repository at this point in the history
  • Loading branch information
calgray committed Oct 17, 2024
1 parent ea80fe2 commit f0bc751
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions include/z5/filesystem/factory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace filesystem {
ptr.reset(new Dataset<std::complex<float>>(dataset, metadata)); break;
case types::complex128:
ptr.reset(new Dataset<std::complex<double>>(dataset, metadata)); break;
case types::complex256:
ptr.reset(new Dataset<std::complex<long double>>(dataset, metadata)); break;
}
return ptr;
}
Expand Down Expand Up @@ -86,6 +88,8 @@ namespace filesystem {
ptr.reset(new Dataset<std::complex<float>>(dataset, metadata)); break;
case types::complex128:
ptr.reset(new Dataset<std::complex<double>>(dataset, metadata)); break;
case types::complex256:
ptr.reset(new Dataset<std::complex<long double>>(dataset, metadata)); break;
}
return ptr;
}
Expand Down
7 changes: 4 additions & 3 deletions include/z5/types/types.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <map>
#include <variant>
#include <complex>

#include "nlohmann/json.hpp"

Expand All @@ -29,7 +30,7 @@ namespace types {
int8, int16, int32, int64,
uint8, uint16, uint32, uint64,
float32, float64,
complex64, complex128
complex64, complex128, complex256
};

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

Expand All @@ -49,7 +50,7 @@ namespace types {
static InverseDtypeMap dtypeMap({{{int8 , "|i1"}, {int16, "<i2"}, {int32, "<i4"}, {int64, "<i8"},
{uint8 , "|u1"}, {uint16, "<u2"}, {uint32, "<u4"},{uint64,"<u8"},
{float32, "<f4"}, {float64,"<f8"},
{complex64, "<c8"}, {complex128, "<c16"}}});
{complex64, "<c8"}, {complex128, "<c16"}, {complex256, "<c32"}}});
return dtypeMap;
}

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

// export writing scalars
// The overloads cannot be properly resolved,
Expand Down Expand Up @@ -289,8 +290,12 @@ namespace z5 {
numberOfThreads);
break;
case types::Datatype::complex128 : writePyScalar<std::complex<double>>(ds, roiBegin, roiShape,
static_cast<std::complex<double>>(val),
numberOfThreads);
static_cast<std::complex<double>>(val),
numberOfThreads);
break;
case types::Datatype::complex256 : writePyScalar<std::complex<long double>>(ds, roiBegin, roiShape,
static_cast<std::complex<long double>>(val),
numberOfThreads);
break;
default: throw(std::runtime_error("Invalid datatype"));

Expand Down

0 comments on commit f0bc751

Please sign in to comment.