Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dtype property to FiniteElement #763

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/basix/finite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ def dof_ordering(self) -> typing.List[int]:
"""DOF layout."""
return self._e.dof_ordering

@property
def dtype(self) -> npt.DTypeLike:
"""Element float type."""
return _np.dtype(self._e.dtype)


def create_element(family_name: ElementFamily, cell_name: CellType, degree: int,
lvariant: LagrangeVariant = LagrangeVariant.unset,
Expand Down
13 changes: 12 additions & 1 deletion python/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <nanobind/stl/vector.h>
#include <span>
#include <string>
#include <type_traits>
#include <variant>
#include <vector>

Expand Down Expand Up @@ -318,7 +319,17 @@ void declare_float(nb::module_& m, std::string type)
&FiniteElement<T>::has_tensor_product_factorisation)
.def_prop_ro("interpolation_nderivs",
&FiniteElement<T>::interpolation_nderivs)
.def_prop_ro("dof_ordering", &FiniteElement<T>::dof_ordering);
.def_prop_ro("dof_ordering", &FiniteElement<T>::dof_ordering)
.def_prop_ro("dtype",
[](const FiniteElement<T>&) -> char
{
static_assert(std::is_same_v<T, float>
or std::is_same_v<T, double>);
if constexpr (std::is_same_v<T, float>)
return 'f';
else if constexpr (std::is_same_v<T, double>)
return 'd';
});

// Create FiniteElement
m.def(
Expand Down
Loading