py21cmfast.wrapper.arrays.Array

class py21cmfast.wrapper.arrays.Array

A flexible array management class providing state tracking and initialization capabilities.

The Array class supports dynamic array creation, caching, and state management with immutable semantics.The class allows for creating arrays with configurable shape, data type, initialization function, and optional caching backend. It provides methods for initializing, setting values, removing values, writing to disk, and loading from disk while maintaining a consistent state.

Variables:
  • shape – Dimensions of the array.

  • dtype – Data type of the array (default is float).

  • state – Current state of the array.

  • initfunc – Function used for array initialization (default is np.zeros).

  • value – Actual array data.

  • cache_backend – Optional backend for disk caching.

Examples

# Create an array with specific shape and initialize arr = Array(shape=(10, 10)) initialized_arr = arr.initialize()

# Set a value and write to disk arr = arr.set_value(np.random.rand(10, 10)) arr = arr.written_to_disk(backend)

computed()

Set the array to a given value and return a new Array.

Return type:

Self

initialize()

Initialize the array to its initial/default allocated state.

loaded_from_disk(backend=None)

Load values for the array from a cache backend, and return a new instance.

Parameters:

backend (CacheBackend | None)

Return type:

Self

purged_to_disk(backend)

Move the array data to disk and return a new object with correct state.

Parameters:

backend (CacheBackend | None)

Return type:

Self

with_value(val)

Set the array to a given value and return a new Array.

Parameters:

val (numpy.ndarray)

Return type:

Self

without_value()

Remove the allocated data from the array.

Return type:

Self

written_to_disk(backend)

Write the array to disk and return a new object with correct state.

Parameters:

backend (CacheBackend | None)

Return type:

Self

cache_backend
dtype
initfunc
shape
state
value