Arrays

The escape.core.array module provides array classes for efficient numerical computation in C++. The module includes:

Classes

double_array_obj

Array class for double-precision floating point values. Wraps C++ array_t<double>.

mask_array_obj

Array class for boolean mask values. Wraps C++ array_t<bool>.

Features

  • Create views or deep copies of numpy arrays

  • Direct memory access to underlying C++ arrays

  • Efficient array operations in C++

  • Seamless conversion between numpy and C++ arrays

  • Support for multi-dimensional arrays

  • Memory-efficient array views

Examples

Creating array views: >>> import escape as esc >>> import numpy as np >>> a = np.arange(10, dtype=float) >>> # Create view of numpy array >>> view = esc.double_array_obj.convert(a) >>> view array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> # Modifying original array affects view >>> a[0] = 100 >>> view array([100., 1., 2., 3., 4., 5., 6., 7., 8., 9.])

Creating deep copies: >>> # Create independent copy >>> copy = esc.double_array_obj.convert(a, copy=True) >>> a[1] = 200 >>> copy # Copy remains unchanged array([100., 1., 2., 3., 4., 5., 6., 7., 8., 9.])

Converting back to numpy: >>> import numpy as np >>> np.asarray(view) array([100., 200., 2., 3., 4., 5., 6., 7., 8., 9.])

escape.core.array.double_array(src: Union[ndarray[Any, dtype[_ScalarType_co]], List], copy: bool = False) double_array_obj

Returns an instance of double_array_obj - array of double values, which holds either a copy of source or wraps its data pointer.

Args:

src: Array to be wrapped. copy: If True the source data will be always copied.

If False and source owns its data, i.e. source is not an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of double_array_obj

escape.core.array.mask_array(src: Union[ndarray[Any, dtype[_ScalarType_co]], List], copy: bool = False) mask_array_obj

Returns an instance of bool_array_obj - array of boolean values, which holds either a copy of source or wraps its data pointer.

Args:

src: Array to be wrapped. copy: If True the source data will be always copied.

If False and source doesn’t own its data, i.e. source is an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of bool_array_obj

class escape.core.array.double_array_obj
static convert(input: Union[ndarray[Any, dtype[float64]], List[float]], copy: bool = False) double_array_obj

Static method to create a wrapper of a numpy array or python list with double elements.

Args:

input: Array to be wrapped copy: If True the source data will be always copied.

If False and source doesn’t own its data, i.e. source is an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of double_array_obj

Raises:

ValueError: If input has more than 2 dimensions TypeError: If input cannot be converted to float array

shape

Returns shape of ESCAPE array as a tuple (nrows, ncols)

class escape.core.array.mask_array_obj
static convert(input: Union[ndarray[Any, dtype[bool]], List[bool]], copy: bool = False) mask_array_obj

Static method to create a wrapper of a numpy array or python list with boolean elements.

Args:

input: Array to be wrapped copy: If True the source data will be always copied.

If False and source owns its data, i.e. source is not an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of mask_array_obj

Raises:

ValueError: If input has more than 2 dimensions TypeError: If input cannot be converted to boolean array

shape

Returns shape of ESCAPE array as a tuple (nrows, ncols)