Skip to content

Commit

Permalink
Merge pull request #2 from franzpoeschel/julia-bindings-review
Browse files Browse the repository at this point in the history
Review for Julia bindings PR
  • Loading branch information
eschnett authored Aug 2, 2023
2 parents 8dc4076 + b381ad8 commit db180de
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 282 deletions.
21 changes: 16 additions & 5 deletions src/binding/julia/Attributable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@

#include "defs.hpp"

namespace
{
struct UseType
{
template <typename T>
static void call(jlcxx::TypeWrapper<Attributable> type)
{
type.method(
"cxx_set_attribute_" + datatypeToString(determineDatatype<T>()) +
"!",
&Attributable::setAttribute<T>);
}
};
} // namespace

void define_julia_Attributable(jlcxx::Module &mod)
{
auto type = mod.add_type<Attributable>("CXX_Attributable");

#define USE_TYPE(NAME, ENUM, TYPE) \
type.method( \
"cxx_set_attribute_" NAME "!", &Attributable::setAttribute<TYPE>);
{FORALL_OPENPMD_TYPES(USE_TYPE)}
#undef USE_TYPE
forallJuliaTypes<UseType>(type);

type.method("cxx_get_attribute", &Attributable::getAttribute);
type.method("cxx_delete_attribute!", &Attributable::deleteAttribute);
Expand Down
21 changes: 15 additions & 6 deletions src/binding/julia/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@

#include "defs.hpp"

namespace
{
struct UseType
{
template <typename T>
static void call(jlcxx::TypeWrapper<Attribute> type)
{
type.method(
"cxx_get_" + datatypeToString(determineDatatype<T>()),
&Attribute::get<T>);
}
};
} // namespace

void define_julia_Attribute(jlcxx::Module &mod)
{
auto type = mod.add_type<Attribute>("CXX_Attribute");

type.method("cxx_dtype", [](const Attribute &attr) { return attr.dtype; });

#define USE_TYPE(NAME, ENUM, TYPE) \
type.method("cxx_get_" NAME, &Attribute::get<TYPE>);
{
FORALL_OPENPMD_TYPES(USE_TYPE)
}
#undef USE_TYPE
forallJuliaTypes<UseType>(type);
}
2 changes: 1 addition & 1 deletion src/binding/julia/BaseRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace jlcxx
template <>
struct SuperType<BaseRecordComponent>
{
typedef Attributable type;
using type = Attributable;
};
} // namespace jlcxx

Expand Down
2 changes: 1 addition & 1 deletion src/binding/julia/ChunkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace jlcxx
template <>
struct SuperType<WrittenChunkInfo>
{
typedef ChunkInfo type;
using type = ChunkInfo;
};
} // namespace jlcxx

Expand Down
12 changes: 4 additions & 8 deletions src/binding/julia/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ namespace jlcxx
template <typename T, typename K>
struct SuperType<Container<T, K>>
{
typedef Attributable type;
using type = Attributable;
};
} // namespace jlcxx

using julia_Container_type_t =
jlcxx::TypeWrapper<jlcxx::Parametric<jlcxx::TypeVar<1>, jlcxx::TypeVar<2>>>;
// TODO: use std::optional instead of std::unique_ptr
typedef jlcxx::TypeWrapper<
jlcxx::Parametric<jlcxx::TypeVar<1>, jlcxx::TypeVar<2>>>
julia_Container_type_t;
extern std::unique_ptr<julia_Container_type_t> julia_Container_type;

template <typename Eltype, typename Keytype>
Expand All @@ -43,7 +42,6 @@ void define_julia_Container(jlcxx::Module &mod)
using ContainerT = typename decltype(type)::type;
using key_type = typename ContainerT::key_type;
using mapped_type = typename ContainerT::mapped_type;
using size_type = typename ContainerT::size_type;
static_assert(std::is_same_v<Eltype, mapped_type>);
static_assert(std::is_same_v<Keytype, key_type>);

Expand All @@ -69,9 +67,7 @@ void define_julia_Container(jlcxx::Module &mod)
type.method("cxx_count", &ContainerT::count);
type.method("cxx_contains", &ContainerT::contains);
type.method(
"cxx_delete!",
static_cast<size_type (ContainerT::*)(const key_type &)>(
&ContainerT::erase));
"cxx_delete!", overload_cast<const key_type &>(&ContainerT::erase));
type.method("cxx_keys", [](const ContainerT &cont) {
std::vector<key_type> res;
res.reserve(cont.size());
Expand Down
18 changes: 15 additions & 3 deletions src/binding/julia/Datatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@

#include "defs.hpp"

namespace
{
struct UseType
{
template <typename T>
static void call(jlcxx::Module &mod)
{
Datatype const dt = determineDatatype<T>();
mod.set_const(datatypeToString(dt), dt);
}
};
} // namespace

void define_julia_Datatype(jlcxx::Module &mod)
{
mod.add_bits<Datatype>("Datatype", jlcxx::julia_type("CppEnum"));
jlcxx::stl::apply_stl<Datatype>(mod);

#define USE_TYPE(NAME, ENUM, TYPE) mod.set_const(NAME, ENUM);
{FORALL_OPENPMD_TYPES(USE_TYPE)}
#undef USE_TYPE
forallJuliaTypes<UseType>(mod);

mod.set_const("UNDEFINED", Datatype::UNDEFINED);

mod.set_const("openPMD_datatypes", openPMD_Datatypes);
Expand Down
6 changes: 2 additions & 4 deletions src/binding/julia/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace jlcxx
template <>
struct SuperType<Iteration>
{
typedef Attributable type;
using type = Attributable;
};
} // namespace jlcxx

Expand All @@ -29,9 +29,7 @@ void define_julia_Iteration(jlcxx::Module &mod)
type.method("cxx_set_dt!", &Iteration::setDt<double>);
type.method("cxx_time_unit_SI", &Iteration::timeUnitSI);
type.method("cxx_set_time_unit_SI!", &Iteration::setTimeUnitSI);
type.method(
"cxx_close",
static_cast<Iteration &(Iteration::*)(bool)>(&Iteration::close));
type.method("cxx_close", overload_cast<bool>(&Iteration::close));
type.method("cxx_open", &Iteration::open);
type.method("cxx_closed", &Iteration::closed);
type.method("cxx_meshes", [](Iteration &iter) -> Container<Mesh> & {
Expand Down
5 changes: 2 additions & 3 deletions src/binding/julia/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace jlcxx
template <>
struct SuperType<Mesh>
{
typedef Container<MeshRecordComponent> type;
using type = Container<MeshRecordComponent>;
};
} // namespace jlcxx

Expand Down Expand Up @@ -50,8 +50,7 @@ void define_julia_Mesh(jlcxx::Module &mod)

type.method("cxx_geometry", &Mesh::geometry);
type.method(
"cxx_set_geometry!",
static_cast<Mesh &(Mesh::*)(Mesh::Geometry g)>(&Mesh::setGeometry));
"cxx_set_geometry!", overload_cast<Mesh::Geometry>(&Mesh::setGeometry));
type.method("cxx_geometry_parameters", &Mesh::geometryParameters);
type.method("cxx_set_geometry_parameters!", &Mesh::setGeometryParameters);
type.method("cxx_data_order", &Mesh::dataOrder);
Expand Down
24 changes: 16 additions & 8 deletions src/binding/julia/MeshRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ namespace jlcxx
template <>
struct SuperType<MeshRecordComponent>
{
typedef RecordComponent type;
using type = RecordComponent;
};
} // namespace jlcxx

namespace
{
struct UseType
{
template <typename T>
static void call(jlcxx::TypeWrapper<MeshRecordComponent> type)
{
type.method(
"cxx_make_constant_" + datatypeToString(determineDatatype<T>()),
&MeshRecordComponent::makeConstant<T>);
}
};
} // namespace

void define_julia_MeshRecordComponent(jlcxx::Module &mod)
{
auto type = mod.add_type<MeshRecordComponent>(
"CXX_MeshRecordComponent", jlcxx::julia_base_type<RecordComponent>());

type.method("cxx_position", &MeshRecordComponent::position<double>);
type.method("cxx_set_position!", &MeshRecordComponent::setPosition<double>);
#define USE_TYPE(NAME, ENUM, TYPE) \
type.method( \
"cxx_make_constant_" NAME, &MeshRecordComponent::makeConstant<TYPE>);
{
FORALL_OPENPMD_TYPES(USE_TYPE)
}
#undef USE_TYPE
forallJuliaTypes<UseType>(type);
}
2 changes: 1 addition & 1 deletion src/binding/julia/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace jlcxx
template <>
struct SuperType<RecordComponent>
{
typedef BaseRecordComponent type;
using type = BaseRecordComponent;
};
} // namespace jlcxx

Expand Down
26 changes: 16 additions & 10 deletions src/binding/julia/RecordComponent_load_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

#include "defs.hpp"

void define_julia_RecordComponent_load_chunk(
jlcxx::Module & /*mod*/, jlcxx::TypeWrapper<RecordComponent> &type)
namespace
{
#define USE_TYPE(NAME, ENUM, TYPE) \
type.method( \
"cxx_load_chunk_" NAME, \
static_cast<void (RecordComponent::*)( \
std::shared_ptr<TYPE>, Offset, Extent)>( \
&RecordComponent::loadChunk<TYPE>));
struct UseType
{
template <typename T>
static void call(jlcxx::TypeWrapper<RecordComponent> &type)
{
FORALL_SCALAR_OPENPMD_TYPES(USE_TYPE)
type.method(
"cxx_load_" + datatypeToString(determineDatatype<T>()),
overload_cast<std::shared_ptr<T>, Offset, Extent>(
&RecordComponent::loadChunk<T>));
}
#undef USE_TYPE
};
} // namespace

void define_julia_RecordComponent_load_chunk(
jlcxx::Module & /*mod*/, jlcxx::TypeWrapper<RecordComponent> &type)
{
forallScalarJuliaTypes<UseType>(type);
}
22 changes: 15 additions & 7 deletions src/binding/julia/RecordComponent_make_constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@

#include "defs.hpp"

void define_julia_RecordComponent_make_constant(
jlcxx::Module & /*mod*/, jlcxx::TypeWrapper<RecordComponent> &type)
namespace
{
#define USE_TYPE(NAME, ENUM, TYPE) \
type.method( \
"cxx_make_constant_" NAME, &RecordComponent::makeConstant<TYPE>);
struct UseType
{
template <typename T>
static void call(jlcxx::TypeWrapper<RecordComponent> &type)
{
FORALL_SCALAR_OPENPMD_TYPES(USE_TYPE)
type.method(
"cxx_make_constant_" + datatypeToString(determineDatatype<T>()),
&RecordComponent::makeConstant<T>);
}
#undef USE_TYPE
};
} // namespace

void define_julia_RecordComponent_make_constant(
jlcxx::Module & /*mod*/, jlcxx::TypeWrapper<RecordComponent> &type)
{
forallScalarJuliaTypes<UseType>(type);
}
26 changes: 16 additions & 10 deletions src/binding/julia/RecordComponent_store_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

#include "defs.hpp"

void define_julia_RecordComponent_store_chunk(
jlcxx::Module & /*mod*/, jlcxx::TypeWrapper<RecordComponent> &type)
namespace
{
#define USE_TYPE(NAME, ENUM, TYPE) \
type.method( \
"cxx_store_chunk_" NAME, \
static_cast<void (RecordComponent::*)( \
std::shared_ptr<TYPE>, Offset, Extent)>( \
&RecordComponent::storeChunk<TYPE>));
struct UseType
{
template <typename T>
static void call(jlcxx::TypeWrapper<RecordComponent> &type)
{
FORALL_SCALAR_OPENPMD_TYPES(USE_TYPE)
type.method(
"cxx_store_chunk_" + datatypeToString(determineDatatype<T>()),
overload_cast<std::shared_ptr<T>, Offset, Extent>(
&RecordComponent::storeChunk<T>));
}
#undef USE_TYPE
};
} // namespace

void define_julia_RecordComponent_store_chunk(
jlcxx::Module & /*mod*/, jlcxx::TypeWrapper<RecordComponent> &type)
{
forallScalarJuliaTypes<UseType>(type);
}
9 changes: 4 additions & 5 deletions src/binding/julia/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace jlcxx
template <>
struct SuperType<Series>
{
typedef Attributable type;
using type = Attributable;
};
} // namespace jlcxx

Expand All @@ -45,7 +45,7 @@ void define_julia_Series(jlcxx::Module &mod)
sized_uint_t<sizeof(MPI_Comm)> ucomm,
const std::string &options) {
MPI_Comm comm;
static_assert(sizeof ucomm == sizeof comm, "");
static_assert(sizeof ucomm == sizeof comm);
memcpy(&comm, &ucomm, sizeof comm);
return Series(filepath, at, comm, options);
});
Expand All @@ -55,7 +55,7 @@ void define_julia_Series(jlcxx::Module &mod)
Access at,
sized_uint_t<sizeof(MPI_Comm)> ucomm) {
MPI_Comm comm;
static_assert(sizeof ucomm == sizeof comm, "");
static_assert(sizeof ucomm == sizeof comm);
memcpy(&comm, &ucomm, sizeof comm);
return Series(filepath, at, comm);
});
Expand All @@ -81,8 +81,7 @@ void define_julia_Series(jlcxx::Module &mod)
type.method("cxx_software", &Series::software);
type.method(
"cxx_set_software!",
static_cast<Series &(Series::*)(const std::string &,
const std::string &)>(
overload_cast<const std::string &, const std::string &>(
&Series::setSoftware));
type.method(
"cxx_set_software!",
Expand Down
3 changes: 1 addition & 2 deletions src/binding/julia/WriteIterations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

void define_julia_WriteIterations(jlcxx::Module &mod)
{
using iterations_t = Container<Iteration, uint64_t>;
using key_type = typename iterations_t::key_type;
using key_type = Series::IterationIndex_t;
// using mapped_type = typename iterations_t::mapped_type;

auto type = mod.add_type<WriteIterations>("WriteIterations");
Expand Down
Loading

0 comments on commit db180de

Please sign in to comment.