fn
from_numpy
→Tensorfrom_numpy(arr: np.ndarray)Create a CPU tensor from a NumPy ndarray with shared storage.
The returned tensor wraps the array's existing buffer — no data is
copied — and inherits the array's dtype according to the canonical
NumPy → Lucid mapping (np.float32 → lucid.float32,
np.int64 → lucid.int64, etc.). Because storage is shared,
mutations in the array are visible in the tensor and vice versa.
Parameters
arrnumpy.ndarraySource array. Must reside in CPU memory. Any layout (C / Fortran /
strided) is accepted; the resulting tensor preserves the array's
strides where possible.
Returns
TensorA CPU tensor sharing storage with arr.
Raises
TypeErrorIf
arr is not a NumPy ndarray.ValueErrorIf
arr's dtype has no corresponding Lucid dtype
(e.g. np.float128 on some platforms).Notes
This is one of the documented H4 bridge boundaries — the only places
where Lucid is allowed to take a NumPy array as input. To move the
result onto a Metal device, chain Tensor.to::
t = lucid.from_numpy(arr).to("metal")
Examples
>>> import lucid, numpy as np
>>> arr = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
>>> t = lucid.from_numpy(arr)
>>> t.dtype
float32
>>> arr[0, 0] = 99.0 # mutate the source
>>> t[0, 0].item() # change visible in the tensor
99.0