28 #include "../Array.hpp" 29 #include "../Macros.hpp" 30 #include "../limits.hpp" 31 #include "../output.hpp" 71 virtual void setAccessLevel(
int const accessLevel,
int const memorySpace ) = 0;
77 virtual std::string
repr()
const = 0;
84 virtual int ndim()
const = 0;
105 virtual void resize(
long long const newSize ) = 0;
112 virtual void resize(
long long const *
const newSizes ) = 0;
121 virtual PyObject *
toNumPy()
const = 0;
127 virtual std::type_index
valueType()
const = 0;
132 int m_accessLevel =
static_cast< int >( LvArray::python::PyModify::READ_ONLY );
146 template<
typename T,
150 template<
typename >
class BUFFER_TYPE >
168 virtual std::string
repr() const final
override 169 {
return system::demangleType< Array< T, NDIM, PERM, INDEX_TYPE, BUFFER_TYPE > >(); }
172 virtual int ndim() const final
override 177 {
return m_array.getSingleParameterResizeIndex(); }
181 { m_array.setSingleParameterResizeIndex( dim ); }
184 virtual void resize(
long long const newSize )
final override 185 { m_array.resize( integerConversion< INDEX_TYPE >( newSize ) ); }
188 virtual void resize(
long long const *
const newSizes )
final override 190 INDEX_TYPE dims[ NDIM ];
192 for(
int i = 0; i < NDIM; ++i )
193 { dims[ i ] = integerConversion< INDEX_TYPE >( newSizes[ i ] ); }
195 m_array.resize( NDIM, dims );
202 if( accessLevel >= static_cast< int >( LvArray::python::PyModify::RESIZEABLE ) )
210 virtual PyObject *
toNumPy() const final
override 212 m_array.move( MemorySpace::host,
m_accessLevel != static_cast< int >(PyModify::READ_ONLY) );
213 return toNumPyImpl();
217 virtual std::type_index
valueType() const final
override 219 if( std::is_same< T, std::string >::value && NDIM == 1 )
220 {
return std::type_index(
typeid( PyObject * ) ); }
221 return std::type_index(
typeid( T ) );
230 template<
typename _T=T >
231 std::enable_if_t< !std::is_same< _T, std::string >::value, PyObject * >
235 m_accessLevel >=
static_cast< int >( LvArray::python::PyModify::MODIFIABLE ),
246 template<
typename _T=T >
247 std::enable_if_t< std::is_same< _T, std::string >::value && NDIM == 1, PyObject * >
249 {
return createPyListOfStrings( m_array.data(), integerConversion< long long >( m_array.size() ) ); }
260 PyObject *
create( std::unique_ptr< internal::PyArrayWrapperBase > && array );
276 template<
typename T,
280 template<
typename >
class BUFFER_TYPE >
281 std::enable_if_t< internal::canExportToNumpy< T > || ( std::is_same< T, std::string >::value && NDIM == 1 ), PyObject * >
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:79
std::enable_if_t< internal::canExportToNumpy< T >, PyObject *> create(T &value)
Create a NumPy 1D array of length 1 containing the scalar value.
Definition: numpyHelpers.hpp:147
PyObject * createPyListOfStrings(std::string const *const strptr, long long const size)
Create and return a Python list of strings from an array of std::strings. The Python strings will be ...
Definition: pythonHelpers.cpp:85
virtual std::type_index valueType() const final override
Return the type of the values stored in the Array.
Definition: PyArray.hpp:217
virtual int getSingleParameterResizeIndex() const final override
Return the single parameter resize index of the Array.
Definition: PyArray.hpp:176
PyArrayWrapper(Array< T, NDIM, PERM, INDEX_TYPE, BUFFER_TYPE > &array)
Constructor.
Definition: PyArray.hpp:159
virtual int ndim() const =0
Return the number of dimensions in the Array.
virtual void resize(long long const newSize) final override
Resize the default dimension of the Array.
Definition: PyArray.hpp:184
virtual void resize(long long const *const newSizes) final override
Resize all the dimensions of the Array.
Definition: PyArray.hpp:188
virtual std::string repr() const =0
Return a string representing to the underlying Array type.
virtual void setAccessLevel(int const accessLevel, int const memorySpace)=0
Set the access level for the Array.
Provides A virtual Python wrapper around an Array.
Definition: PyArray.hpp:50
Array< T, NDIM, PERM, INDEX_TYPE, BUFFER_TYPE > & m_array
The wrapped Array.
Definition: PyArray.hpp:252
An implements the PyArrayWrapperBase interface for a particular Array type.
Definition: PyArray.hpp:151
virtual std::string repr() const final override
Return a string representing to the underlying Array type.
Definition: PyArray.hpp:168
virtual void resize(long long const newSize)=0
Resize the default dimension of the Array.
virtual PyObject * toNumPy() const final override
Return a NumPy ndarray wrapping the Array.
Definition: PyArray.hpp:210
virtual int ndim() const final override
Return the number of dimensions in the Array.
Definition: PyArray.hpp:172
virtual int getAccessLevel() const
Return the access level for the Array.
Definition: PyArray.hpp:63
virtual std::type_index valueType() const =0
Return the type of the values stored in the Array.
std::enable_if_t< !std::is_same< _T, std::string >::value, PyObject *> toNumPyImpl() const
Create a NumPy ndarray for an Array that doesn't contain std::strings.
Definition: PyArray.hpp:232
Forward declarations of Python Objects.
virtual PyObject * toNumPy() const =0
Return a NumPy ndarray wrapping the Array.
The top level namespace.
Definition: Array.hpp:24
virtual int getSingleParameterResizeIndex() const =0
Return the single parameter resize index of the Array.
virtual void setSingleParameterResizeIndex(int const dim) const =0
Set the single parameter resize index of the Array.
Contains methods to help with conversion to python objects.
virtual ~PyArrayWrapperBase()=default
Default destructor.
PyTypeObject * getPyArrayType()
Return the Python type for the Array.
std::enable_if_t< internal::canExportToNumpy< T >||(std::is_same< T, std::string >::value &&NDIM==1), PyObject *> create(Array< T, NDIM, PERM, INDEX_TYPE, BUFFER_TYPE > &array)
Create a Python object corresponding to array.
Definition: PyArray.hpp:282
std::enable_if_t< std::is_same< _T, std::string >::value &&NDIM==1, PyObject *> toNumPyImpl() const
Create Python list of strings from a 1D Array of strings.
Definition: PyArray.hpp:248
virtual void setSingleParameterResizeIndex(int const dim) const final override
Set the single parameter resize index of the Array.
Definition: PyArray.hpp:180
virtual void setAccessLevel(int accessLevel, int memorySpace) final override
Set the access level for the Array.
Definition: PyArray.hpp:199
int m_accessLevel
If the array can be modified.
Definition: PyArray.hpp:132
std::enable_if_t< internal::canExportToNumpy< T >, PyObject *> createNumPyArray(T *const data, bool const modify, int const ndim, INDEX_TYPE const *const dimsPtr, INDEX_TYPE const *const stridesPtr)
Return a NumPy ndarray view of data.
Definition: numpyHelpers.hpp:107