Nektar++
Public Member Functions | Static Public Member Functions | List of all members
pybind11::detail::standard_nekmatrix_caster< Type, T > Struct Template Reference

#include <NekMatrix.hpp>

Public Member Functions

 PYBIND11_TYPE_CASTER (Type, const_name("NekMatrix<T>"))
 
bool load (handle src, bool)
 

Static Public Member Functions

static handle cast (const Nektar::NekMatrix< T, Nektar::StandardMatrixTag > &src, return_value_policy, handle)
 

Detailed Description

template<typename Type, typename T>
struct pybind11::detail::standard_nekmatrix_caster< Type, T >

Definition at line 46 of file Python/LinearAlgebra/NekMatrix.hpp.

Member Function Documentation

◆ cast()

template<typename Type , typename T >
static handle pybind11::detail::standard_nekmatrix_caster< Type, T >::cast ( const Nektar::NekMatrix< T, Nektar::StandardMatrixTag > &  src,
return_value_policy  ,
handle   
)
inlinestatic

Definition at line 82 of file Python/LinearAlgebra/NekMatrix.hpp.

85 {
87
88 // Construct a new wrapper matrix to hold onto the data. Assign a
89 // destructor so that the wrapper is cleaned up when the Python object
90 // is deallocated.
91 capsule c(new NMat(src.GetRows(), src.GetColumns(), src.GetPtr(),
93 [](void *ptr) {
94 NMat *mat = (NMat *)ptr;
95 delete mat;
96 });
97
98 // Create the NumPy array, passing the capsule. When we go out of scope,
99 // c's reference count will have been reduced by 1, but array increases
100 // the reference count when it assigns the base to the array.
101 array a({src.GetRows(), src.GetColumns()},
102 {sizeof(T), src.GetRows() * sizeof(T)}, src.GetRawPtr(), c);
103
104 // This causes the array to be released without decreasing its reference
105 // count, which we do since if we just returned a, then the array would
106 // be deallocated immediately when this function returns.
107 return a.release();
108 }

References Nektar::eWrapper.

◆ load()

template<typename Type , typename T >
bool pybind11::detail::standard_nekmatrix_caster< Type, T >::load ( handle  src,
bool   
)
inline

Definition at line 51 of file Python/LinearAlgebra/NekMatrix.hpp.

52 {
53 // Perform some checks: the source should be an ndarray.
54 if (!array_t<T>::check_(src))
55 {
56 return false;
57 }
58
59 // The array should be a c-style, contiguous array of type T.
60 auto buf = array_t<T, array::c_style | array::forcecast>::ensure(src);
61 if (!buf)
62 {
63 return false;
64 }
65
66 // There should be two dimensions.
67 auto dims = buf.ndim();
68 if (dims != 2)
69 {
70 return false;
71 }
72
73 // Copy data across from the Python array to C++.
74 std::vector<size_t> shape = {buf.shape()[0], buf.shape()[1]};
76 shape[0], shape[1], buf.data(), Nektar::eFULL, buf.data());
77
78 return true;
79 }

References Nektar::eFULL.

◆ PYBIND11_TYPE_CASTER()

template<typename Type , typename T >
pybind11::detail::standard_nekmatrix_caster< Type, T >::PYBIND11_TYPE_CASTER ( Type  ,
const_name("NekMatrix<T>")   
)