vtkmodules.numpy_interface.vtk_strided_array#

VTKStridedArray — numpy-compatible mixin for vtkStridedArray.

This module provides the VTKStridedArray mixin class and registers overrides for all vtkStridedArray instantiations so that strided arrays coming from VTK automatically have numpy-compatible operations.

A vtkStridedArray provides a strided view on a raw buffer: value[tupleIdx][compIdx] = buffer[stride * tupleIdx + offset + compIdx]. Used in InSitu/Catalyst (vtkConduitArrayUtilities) for zero-copy access to external memory with interleaved data layouts.

When the underlying buffer is accessible (via GetBufferSource() or a stored numpy reference), __array__ returns a zero-copy strided numpy view — no data is copied. When the buffer is not accessible (raw-pointer construction from C++), a DeepCopy fallback is used.

模組目次#

類別#

VTKStridedArray

A numpy-compatible mixin for strided implicit arrays.

Functions#

API#

class vtkmodules.numpy_interface.vtk_strided_array.VTKStridedArray(buffer=None, stride=1, offset=0, **kwargs)#

基底類別:vtkmodules.numpy_interface._vtk_array_mixin.VTKDataArrayMixin

A numpy-compatible mixin for strided implicit arrays.

vtkStridedArray stores a strided view on a buffer, presenting buffer[stride * tupleIdx + offset + compIdx] as a virtual array. This Python mixin adds numpy integration: arithmetic, reductions, indexing, and to_numpy().

初始化

Create a strided array.

Can be called as::

vtkStridedArray['float32']()                         # empty
vtkStridedArray['float32'](data, 2)                  # 1D, stride=2
vtkStridedArray['float32'](data_2d, 3)               # 2D, ncomps from shape[1]
vtkStridedArray['float32'](data, 3, offset=1)        # with offset

buffer is any array-like (list, numpy array, etc.). A 1D buffer gives a single-component array; a 2D buffer with shape (N, M) gives an M-component array (the buffer is flattened internally).

The data is converted to a VTK buffer via numpy_to_vtk (zero-copy when the dtype already matches) and ConstructBackend is called.

ConstructBackend(buffer, stride, components=None, offset=None)#

Set strided backend parameters.

buffer is a vtkAbstractBuffer (e.g. obtained via array.GetBuffer()). The C++ side stores the buffer with reference counting so the vtkBuffer object stays alive.

If the buffer was created by numpy_to_vtk (zero-copy), the underlying numpy array reference is also preserved here so that the raw memory remains valid.

_get_buffer_numpy()#

Return the underlying buffer as a flat numpy array (zero-copy).

Returns None if no buffer is accessible (raw-pointer construction).

property stride#

Return the stride of the strided backend.

property offset#

Return the offset of the strided backend.

property dtype#
property nbytes#
to_numpy(dtype=None)#

Return the array as a numpy ndarray (zero-copy when possible).

__array__(dtype=None, copy=None)#

Return a numpy view using strides (zero-copy when possible).

When the underlying buffer is accessible, creates a strided numpy view that maps directly to the buffer memory. Falls back to DeepCopy only when the buffer is not accessible from Python.

__buffer__(flags)#

Override C-level buffer protocol to return strided view.

__array_ufunc__(ufunc, method, *inputs, **kwargs)#

Handle numpy ufuncs by materializing.

__array_function__(func, types, args, kwargs)#

Dispatch numpy functions via override registry.

__getitem__(key)#

Index into the strided array.

Scalar index: direct lookup via GetComponent/GetTuple. Everything else: delegates to the numpy strided view.

__setitem__(key, value)#
__add__(other)#
__radd__(other)#
__sub__(other)#
__rsub__(other)#
__mul__(other)#
__rmul__(other)#
__truediv__(other)#
__rtruediv__(other)#
__floordiv__(other)#
__rfloordiv__(other)#
__pow__(other)#
__rpow__(other)#
__mod__(other)#
__rmod__(other)#
__lt__(other)#
__le__(other)#
__eq__(other)#
__ne__(other)#
__ge__(other)#
__gt__(other)#
__neg__()#
__pos__()#
__abs__()#
sum(axis=None, **kwargs)#
min(axis=None, **kwargs)#
max(axis=None, **kwargs)#
mean(axis=None, **kwargs)#
std(axis=None, **kwargs)#
var(axis=None, **kwargs)#
any(axis=None, **kwargs)#
all(axis=None, **kwargs)#
prod(axis=None, **kwargs)#
__iter__()#
__repr__()#
__str__()#
vtkmodules.numpy_interface.vtk_strided_array._strided_sum(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_mean(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_min(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_max(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_std(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_var(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_any(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_all(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_prod(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._strided_concatenate(arrays, axis=0, **kwargs)#
vtkmodules.numpy_interface.vtk_strided_array._register_strided_overrides()#

Register VTKStridedArray mixin as override for all vtkStridedArray template types.