Tessero\NDArray
AI assistant
Build this with Claude Code, Cursor or Copilot
Copy a Tessero-tuned prompt for Tessero\NDArray, grounded in 16 real API signatures , into your IDE's AI. No chatbot, just exact context.
__construct
__construct(Tessero\Native\Buffer $buffer, Tessero\DType $dtype, array $shape, ?array $strides = null, int $offset = 0)
empty
static
empty(array|int $shape, Tessero\DType|string $dtype = …): self
zeros
static
zeros(array|int $shape, Tessero\DType|string $dtype = …): self
ones
static
ones(array|int $shape, Tessero\DType|string $dtype = …): self
full
static
full(array|int $shape, int|float|bool $value, Tessero\DType|string|null $dtype = null): self
arange
static
arange(int|float $start, int|float|null $stop = null, int|float $step = 1, Tessero\DType|string|null $dtype = null): self
linspace
static
linspace(float $start, float $stop, int $num = 50, bool $endpoint = true): self
eye
static
eye(int $n, ?int $m = null, int $k = 0, Tessero\DType|string $dtype = …): self
array
static
array(mixed $data, Tessero\DType|string|null $dtype = null): self
Build an array from PHP data: a scalar, a (nested) list, or another NDArray (copied). Passing $dtype skips type inference, which is the faster path for big inputs.
fromFlat
static
fromFlat(array $flat, array $shape, Tessero\DType|string $dtype = …): self
complex
static
complex(mixed $real, mixed $imag = null): self
Complex array from real and imaginary parts (arrays or nested lists of equal shape).
fromBytes
static
fromBytes(string $bytes, Tessero\DType|string $dtype, ?array $shape = null): self
Wrap raw little-endian bytes (copied).
asArray
static
asArray(mixed $value, Tessero\DType|string|null $dtype = null): self
memmap
static
memmap(string $filename, string $mode = 'r+', ?array $shape = null, Tessero\DType|string $dtype = …, int $offset = 0): self
An array backed by a memory-mapped file (numpy.memmap): nothing is read up front; the OS pages data in on access. Modes: 'r' read-only, 'r+' read/write (extends a short file), 'w+' create or truncate, 'c' copy-on-write. Without $shape the file (after $offset) is one 1-D array. Views share the mapping; results of computations are ordinary arrays. Same arguments and errors as ext-tessero.
openMemmap
static
openMemmap(string $path, string $mode = 'r+', ?array $shape = null, Tessero\DType|string $dtype = …, bool $fortranOrder = false): self
A memory-mapped .npy file (numpy.lib.format.open_memmap): 'w+' creates it with a header for $shape and $dtype; 'r', 'r+' and 'c' read shape and dtype from the file.
load
static
load(string $path, ?string $mmapMode = null): self
Read a .npy file (numpy.load); with $mmapMode ('r', 'r+', 'c') the data is memory-mapped instead of read.
save
save(string $path): void
Write this array to a .npy file (numpy.save), C order.
flush
flush(bool $sync = false): self
Write a memory map's dirty pages back to its file: scheduled (default) or synchronous with $sync. No-op for other arrays.
isMemmap
isMemmap(): bool
True for memory-mapped arrays and views of them.
isReadonly
isReadonly(): bool
True for arrays over read-only memory (memmap mode 'r').
filename
filename(): ?string
The mapped file's resolved path, or null.
shape
shape(): array
strides
strides(): array
dtype
dtype(): Tessero\DType
ndim
ndim(): int
size
size(): int
nbytes
nbytes(): int
buffer
buffer(): Tessero\Native\Buffer
The native block this array (or view) reads; shared by all views of it. Advanced use only.
ptr
ptr(): FFI\CData
char* to the first element, for passing to C in the same statement.
isContiguous
isContiguous(): bool
isFortranContiguous
isFortranContiguous(): bool
count
count(): int
toArray
toArray(): mixed
Nested PHP array (scalar for 0-d). Complex elements become [re, im] pairs.
toList
toList(): array
Flat C-order list of values (complex: interleaved re, im).
toBytes
toBytes(): string
Raw little-endian bytes in C order.
item
item(int ...$index): array|int|float|bool
One element as a PHP scalar ([re, im] for complex).
toJson
toJson(): string
JSON text written directly by libtessero from the strided memory (no PHP arrays in between): about 10x faster than json_encode($a->toArray()) on large arrays. Floats use the shortest round-trip form; NaN/Inf become null.
meta
meta(): FFI\CData
C-side metadata (tsr_array) describing this view, for kernels that take whole arrays. Like ptr(), the embedded data pointer is valid only while this array is alive.
sliceNative
sliceNative(string $spec): self
Basic indexing with the spec parsed by libtessero (same grammar as offsetGet): one call into C, no PHP string handling. Returns a view.
jsonSerialize
jsonSerialize(): mixed
copy
copy(): self
contiguous
contiguous(): self
This array if already C-contiguous, else a contiguous copy.
astype
astype(Tessero\DType|string $dtype, bool $copy = false): self
view
view(Tessero\DType|string $dtype): self
Reinterpret the same bytes as another dtype of equal itemsize (bool <-> uint8).
isWritable
isWritable(): bool
False for arrays over read-only memory (a memory map opened with mode 'r').
assign
assign(mixed $src): self
Copy (and cast) the values of $src, broadcast to this array's shape, into this array (which may be a view).
reshape
reshape(array|int ...$shape): self
ravel
ravel(): self
flatten
flatten(): self
transpose
transpose(?array $axes = null): self
t
t(): self
Matrix transpose (reverses all axes).
swapAxes
swapAxes(int $a, int $b): self
moveAxis
moveAxis(int $source, int $destination): self
expandDims
expandDims(int $axis): self
squeeze
squeeze(?int $axis = null): self
broadcastTo
broadcastTo(array $shape): self
slice
slice(string|int|null ...$specs): self
Basic indexing, one spec per axis: int select (drops the axis; negative counts from the end) 'a:b:c' slice, any part optional ('::-1' reverses, ':' keeps) '...' fill the remaining axes with ':' null insert a new axis of length 1 (numpy.newaxis) Always returns a view.
get
get(int ...$index): mixed
Element or sub-array at integer indices (scalar when all axes are indexed).
take
take(mixed $indices, ?int $axis = null): self
Gather along an axis (numpy.take). Indices may be negative. With $axis null the array is flattened first.
put
put(mixed $indices, mixed $values, ?int $axis = null): self
Scatter values along an axis in place (numpy.put_along_axis for whole slices).
filter
filter(self $mask): self
Elements where $mask is true, as a 1-D array (a[mask]).
setWhere
setWhere(self $mask, mixed $values): self
a[mask] = values (a scalar, or one value per true element).
flatNonzero
flatNonzero(): self
Flat indices of non-zero elements (numpy.flatnonzero).
getIterator
getIterator(): Traversable
add
add(mixed $b, ?self $out = null): self
sub
sub(mixed $b, ?self $out = null): self
mul
mul(mixed $b, ?self $out = null): self
div
div(mixed $b, ?self $out = null): self
pow
pow(mixed $b, ?self $out = null): self
mod
mod(mixed $b, ?self $out = null): self
floorDiv
floorDiv(mixed $b, ?self $out = null): self
maximum
maximum(mixed $b, ?self $out = null): self
minimum
minimum(mixed $b, ?self $out = null): self
atan2
atan2(mixed $b, ?self $out = null): self
hypot
hypot(mixed $b, ?self $out = null): self
eq
eq(mixed $b): self
ne
ne(mixed $b): self
lt
lt(mixed $b): self
le
le(mixed $b): self
gt
gt(mixed $b): self
ge
ge(mixed $b): self
logicalAnd
logicalAnd(mixed $b): self
logicalOr
logicalOr(mixed $b): self
logicalXor
logicalXor(mixed $b): self
rsub
rsub(mixed $a): self
Reflected forms for scalar - array expressions.
rdiv
rdiv(mixed $a): self
rpow
rpow(mixed $a): self
neg
neg(?self $out = null): self
abs
abs(?self $out = null): self
square
square(?self $out = null): self
sign
sign(?self $out = null): self
sqrt
sqrt(?self $out = null): self
exp
exp(?self $out = null): self
log
log(?self $out = null): self
log10
log10(?self $out = null): self
log2
log2(?self $out = null): self
expm1
expm1(?self $out = null): self
log1p
log1p(?self $out = null): self
sin
sin(?self $out = null): self
cos
cos(?self $out = null): self
tan
tan(?self $out = null): self
arcsin
arcsin(?self $out = null): self
arccos
arccos(?self $out = null): self
arctan
arctan(?self $out = null): self
sinh
sinh(?self $out = null): self
cosh
cosh(?self $out = null): self
tanh
tanh(?self $out = null): self
floor
floor(?self $out = null): self
ceil
ceil(?self $out = null): self
rint
rint(?self $out = null): self
reciprocal
reciprocal(?self $out = null): self
isnan
isnan(): self
isfinite
isfinite(): self
isinf
isinf(): self
invert
invert(): self
Bitwise NOT for integers, logical NOT for bool (numpy.invert).
logicalNot
logicalNot(): self
real
real(): self
imag
imag(): self
conj
conj(): self
angle
angle(): self
round
round(int $decimals = 0): self
clip
clip(int|float|null $min = null, int|float|null $max = null): self
sum
sum(array|int|null $axis = null, bool $keepdims = false): mixed
prod
prod(array|int|null $axis = null, bool $keepdims = false): mixed
min
min(array|int|null $axis = null, bool $keepdims = false): mixed
max
max(array|int|null $axis = null, bool $keepdims = false): mixed
any
any(array|int|null $axis = null, bool $keepdims = false): mixed
all
all(array|int|null $axis = null, bool $keepdims = false): mixed
argmin
argmin(?int $axis = null, bool $keepdims = false): mixed
argmax
argmax(?int $axis = null, bool $keepdims = false): mixed
mean
mean(array|int|null $axis = null, bool $keepdims = false): mixed
var
var(array|int|null $axis = null, int $ddof = 0, bool $keepdims = false): mixed
std
std(array|int|null $axis = null, int $ddof = 0, bool $keepdims = false): mixed
cumsum
cumsum(?int $axis = null): self
cumprod
cumprod(?int $axis = null): self
diff
diff(int $n = 1, int $axis = -1): self
n-th discrete difference along an axis (numpy.diff).
sort
sort(int $axis = -1): self
nonzero
nonzero(): mixed
Indices of the non-zero elements (numpy.ndarray.nonzero).
mT
mT(): mixed
Matrix transpose: swap the last two axes (numpy.ndarray.mT).
trace
trace(int $offset = 0, int $axis1 = 0, int $axis2 = 1): mixed
Sum along a diagonal (numpy.ndarray.trace).
diagonal
diagonal(int $offset = 0, int $axis1 = 0, int $axis2 = 1): mixed
A diagonal of the matrix (numpy.ndarray.diagonal).
repeat
repeat(mixed $repeats, ?int $axis = null): mixed
Repeat elements (numpy.ndarray.repeat).
compress
compress(mixed $condition, ?int $axis = null): mixed
Select elements where a boolean condition is true (numpy.ndarray.compress).
choose
choose(mixed $choices, mixed $mode = 'raise'): mixed
Choose from a set of arrays by index (numpy.ndarray.choose).
fill
fill(mixed $value): self
Fill the array with a scalar value (numpy.ndarray.fill); returns a new same-shape array.
byteswap
byteswap(bool $inplace = false): self
A copy with each element's bytes reversed (numpy.ndarray.byteswap).
resize
resize(array|int $shape): self
Return a copy resized to the given shape (numpy.ndarray.resize): flattened, zero-padded or truncated.
searchsorted
searchsorted(mixed $v, string $side = 'left'): mixed
Indices where elements of v keep this sorted if inserted (numpy.ndarray.searchsorted).
partition
partition(mixed $kth, int $axis = -1): mixed
A partial sort: a copy with the kth element in final sorted position (numpy.ndarray.partition).
argpartition
argpartition(mixed $kth, int $axis = -1): mixed
Indices that would partition the array about the kth element (numpy.ndarray.argpartition).
argsort
argsort(int $axis = -1): self
matmul
matmul(self|array $other): mixed
Matrix product with NumPy's matmul rules: 1-D operands are promoted to row/column vectors, >2-D operands are stacks of matrices with broadcast batch dimensions. float64/float32 use BLAS when one is available.
dot
dot(self|array $other): mixed
numpy.dot for 1-D/2-D operands (alias of matmul there).
where
static
where(mixed $cond, mixed $a, mixed $b): self
Element-wise selection: cond ? a : b, with broadcasting.
concatenate
static
concatenate(array $arrays, int $axis = 0): self
stack
static
stack(array $arrays, int $axis = 0): self
allclose
static
allclose(mixed $a, mixed $b, float $rtol = 1.0E-5, float $atol = 1.0E-8, bool $equalNan = false): bool
isclose
static
isclose(mixed $a, mixed $b, float $rtol = 1.0E-5, float $atol = 1.0E-8, bool $equalNan = false): self
broadcastShapes
static
broadcastShapes(array ...$shapes): array
cStrides
static
cStrides(array $shape, int $itemsize): array
normAxis
static
normAxis(int $axis, int $ndim): int