pyncarray
pyncarray
Section titled “pyncarray”Functions
Section titled “Functions”| Return | Name | Description |
|---|---|---|
NCA_PYNCARRAY_API void |
set_eager |
|
NCA_PYNCARRAY_API bool |
is_eager |
|
bool |
is_nc_array inline |
|
bool |
needs_device_vm inline |
|
void |
_build_node_helper |
|
py::object |
eval_python_expr |
|
void |
register_expr_class |
|
void |
register_common_array_methods |
Helper function to attach common methods to a Python binding for an array specialization. |
auto |
host_dispatch inline |
This is a duplicate dispatch to that in ncarry/array_impl.hh but host only. The original needs to be host/device, so we get a lot of spurious warnings. |
ncarray::DType |
pydtype_to_dtype inline |
Cast a pybind11 array dtype to a ncarray::DType. |
auto |
pyarray_to_view inline |
Construct a view over a NumPy array. |
ncarray::ArrayImpl< LayoutT, RefT > |
pyarray_to_ref inline |
Construct a reference type array from an array of arrays. |
ncarray::ArrayImpl< LayoutT, RefT > |
pylist_to_ref inline |
Construct a reference type array from a list of arrays. |
py::array |
ncarr_to_numpy inline |
Construct a NumPy array from an input nc/soarray type object. |
ncarray::Slice |
pyslice_to_slice inline |
|
std::vector< ncarray::IndexItem > |
pytuple_to_indices inline |
set_eager
Section titled “set_eager”NCA_PYNCARRAY_API void set_eager(bool eager)is_eager
Section titled “is_eager”NCA_PYNCARRAY_API bool is_eager()is_nc_array
Section titled “is_nc_array”inline
template<class LPolicy, class MemType> inline bool is_nc_array(const py::handle & val)needs_device_vm
Section titled “needs_device_vm”inline
inline bool needs_device_vm(const py::handle & node)_build_node_helper
Section titled “_build_node_helper”template<typename MemType> void _build_node_helper(ncarray::ExprMVNode< MemType > & self, py::object other)eval_python_expr
Section titled “eval_python_expr”template<typename MemType> py::object eval_python_expr(const py::object & pyexpr)register_expr_class
Section titled “register_expr_class”template<typename MemType> void register_expr_class(py::module_ & m, const std::string & name)register_common_array_methods
Section titled “register_common_array_methods”template<typename ArrayT> void register_common_array_methods(py::classh< ArrayT > & arr_cl)Helper function to attach common methods to a Python binding for an array specialization.
All array specializations generally have the same functions in C++ and in their Python bindings (plus/minus some speciality features). This function just attaches those all.
Parameters
Section titled “Parameters”ArrayTThe kind of array being used. This is a full array specifier, including storage+layout specifier.
Parameters
Section titled “Parameters”arr_clThe class of the Python binding.
host_dispatch
Section titled “host_dispatch”inline
template<typename Visitor> inline auto host_dispatch(ncarray::DType type, Visitor && visitor)This is a duplicate dispatch to that in ncarry/array_impl.hh but host only. The original needs to be host/device, so we get a lot of spurious warnings.
We do NOT want to just silence the warning (e.g. pragma diag_suppress 20014) for nvcc as we want to catch other instances of host/device called from host.
pydtype_to_dtype
Section titled “pydtype_to_dtype”inline
inline ncarray::DType pydtype_to_dtype(py::dtype dtype)Cast a pybind11 array dtype to a ncarray::DType.
Parameters
Section titled “Parameters”dtypeThe pybind11 datatype.
Returns
Section titled “Returns”The ncarray datatype.
pyarray_to_view
Section titled “pyarray_to_view”inline
template<class ViewType> inline auto pyarray_to_view(const py::array & arr, ssize_t target_ndim = -1)Construct a view over a NumPy array.
Parameters
Section titled “Parameters”ViewTypeThe kind of view to construct. E.g. NCArrayView, SOArrayView.
Parameters
Section titled “Parameters”-
arrAn input NumPy array to convert. -
target_ndimThe target dimensionality of the output with padding. TODO: This mostly serves as a hack until broadcasting is suppported. Because of the implicit dimensionality mismatch between NCArrays* and NumPy….
Returns
Section titled “Returns”A view of ViewType over the data from the NumPy array.
pyarray_to_ref
Section titled “pyarray_to_ref”inline
template<class LayoutT, class RefT = ncarray::RefPolicy> inline ncarray::ArrayImpl< LayoutT, RefT > pyarray_to_ref(const py::array & arr, const bool read_only_ = false)Construct a reference type array from an array of arrays.
NOTE: This function assumes the arrays in the array all have the same shape and strides.
Parameters
Section titled “Parameters”-
LayoutTThe layout specifier for the returned reference type. E.g., NCOffsetsPolicy or SOArrayPolicy (PEP3118). -
RefTThe reference storage specifier. E.g. RefPolicy or DevRefPolicy.
Parameters
Section titled “Parameters”-
arrThe input array of arrays. -
read_only_Whether this reference should be read only.
Returns
Section titled “Returns”The constructed reference type.
pylist_to_ref
Section titled “pylist_to_ref”inline
template<class LayoutT, class RefT = ncarray::RefPolicy> inline ncarray::ArrayImpl< LayoutT, RefT > pylist_to_ref(const py::list & list, const bool read_only_ = false)Construct a reference type array from a list of arrays.
NOTE: This function assumes the arrays in the list all have the same shape and strides.
Parameters
Section titled “Parameters”-
LayoutTThe layout specifier for the returned reference type. E.g., NCOffsetsPolicy or SOArrayPolicy (PEP3118). -
RefTThe reference storage specifier. E.g. RefPolicy or DevRefPolicy.
Parameters
Section titled “Parameters”-
listThe input list of arrays. -
read_only_Whether this reference should be read only.
Returns
Section titled “Returns”The constructed reference type.
ncarr_to_numpy
Section titled “ncarr_to_numpy”inline
template<class ArrayT> inline py::array ncarr_to_numpy(const ArrayT & ncarr, std::optional< ncarray::DType > dtype = std::nullopt)Construct a NumPy array from an input nc/soarray type object.
Parameters
Section titled “Parameters”ArrayTThe kind of array being used. This is a full array specifier, including storage+layout specifier.
Parameters
Section titled “Parameters”-
ncarrThe input array to convert. -
dtypeThe datatype for the converted NumPy array. I.e., if provided a cast will be performed. Otherwise, the input array dtype will be used.
Returns
Section titled “Returns”A NumPy array of specified dtype over the input data.
pyslice_to_slice
Section titled “pyslice_to_slice”inline
inline ncarray::Slice pyslice_to_slice(ssize_t axis_shape, py::slice slice)pytuple_to_indices
Section titled “pytuple_to_indices”inline
template<class ArrayT> inline std::vector< ncarray::IndexItem > pytuple_to_indices(const ArrayT & self, py::tuple tup)Variables
Section titled “Variables”| Return | Name | Description |
|---|---|---|
NCA_PYNCARRAY_API bool |
g_eager_eval |
Global toggle for whether Python will eagerly convert Expr objects to arrays. |
g_eager_eval
Section titled “g_eager_eval”NCA_PYNCARRAY_API bool g_eager_eval = trueGlobal toggle for whether Python will eagerly convert Expr objects to arrays.