ArrayBuffer#

class fields.buffers.core.ArrayBuffer(array: ndarray)[source]#

A lightweight buffer wrapper around a plain NumPy array.

This class provides a minimal, unitless backend for storing field data using standard numpy.ndarray objects. It is designed for general-purpose use cases where unit handling or advanced I/O (e.g., HDF5) is not required.

Because it does not attach physical units, this class is best suited for purely numerical workflows or as a baseline buffer in performance-sensitive tasks.

Examples

Create a buffer from a 2D list:

>>> buf = ArrayBuffer.from_array([[1, 2], [3, 4]])
>>> buf
ArrayBuffer(shape=(2, 2), dtype=int64)

Create a zero-initialized buffer with shape (3, 3):

>>> ArrayBuffer.zeros((3, 3)).as_array()
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]])

See also

UnytArrayBuffer

A unit-aware buffer backend.

HDF5Buffer

HDF5 backed buffer.

BufferBase

Abstract interface for all buffer backends.

Methods

__init__(array)

Initialize the buffer with a NumPy array.

as_array()

Return the buffer as a NumPy array.

as_core()

Return the raw backend array object stored in this buffer.

as_repr()

Return a NumPy-compatible array for use in NumPy operations.

as_unyt_array()

Convert the buffer contents into a unyt_array with attached units.

astype(dtype, *args, **kwargs)

Return a copy of this buffer with a different data type.

broadcast_to(shape, *args, **kwargs)

Broadcast an array to a new shape.

can_handle(obj)

Return True if obj can be wrapped by this buffer class.

can_handle_list()

Return a list of type names that this buffer can wrap.

convert_to_base([unit_system, equivalence])

Convert this buffer in-place to base units for the given unit system.

convert_to_units(units[, equivalence])

Convert this buffer's data to the specified physical units (in-place).

copy(*args, **kwargs)

Return a deep copy of this buffer.

empty(shape, *args, **kwargs)

Return a new buffer of given shape and type, without initializing entries.

empty_like(other, *args, **kwargs)

Create a new buffer allocation matching the shape of another buffer.

expand_dims(axis, *args, **kwargs)

Expand the shape of an array.

flatten(*args[, order])

Return a flattened 1D view of this buffer.

from_array(obj, *args[, dtype])

Construct a new ArrayBuffer from an arbitrary array-like input.

full(shape, *args[, fill_value])

Create a buffer filled with a constant value.

full_like(other[, fill_value])

Create a new buffer filled with a constant value and matching the shape of another buffer.

in_units(units, *args[, equivalence, ...])

Return a new copy of this buffer cast to the specified physical units.

ones(shape, *args, **kwargs)

Create a buffer initialized with ones.

ones_like(other, *args, **kwargs)

Create a new buffer filled with ones and matching the shape of another buffer.

reshape(shape, *args, **kwargs)

Return a reshaped copy of this buffer.

resolve(array_like, *args[, buffer_registry])

Resolve and instantiate a buffer subclass for an arbitrary array-like input.

squeeze(*args[, axis])

Remove axes of length one from self.

to(units, *args[, equivalence, ...])

Return a new buffer (or array) with values cast to the specified units.

to_value(units[, equivalence])

Return a NumPy array of values converted to the specified physical units.

transpose([axes])

Return this buffer with axes transposed.

zeros(shape, *args, **kwargs)

Create a buffer initialized with zeros.

zeros_like(other, *args, **kwargs)

Create a new buffer filled with zeros and matching the shape of another buffer.

Attributes

c

Shorthand for as_core().

d

Shorthand for as_array().

dtype

Data type of the array.

has_units

Whether the buffer carries unit metadata.

ndim

Number of dimensions.

shape

Shape of the underlying array.

size

Total number of elements.

units

Physical units attached to the buffer data.

v

Shorthand for as_unyt_array().