Skip to content

Global functions

Complete reference for namespaced functions that proxy to NDArray instance methods and static factories. They mirror the behavior documented on the rest of this API reference.

For full parameter lists, edge cases, and examples, follow the links to the corresponding class methods.


Overview

  • Each function delegates to NDArray; there is no second implementation in PHP.
  • Binary-style operations take the receiver array as the first argument: add($a, $b) is the same as $a->add($b).
  • Canonical list and signatures always match the current src/Functions.php in the repository.

The catalogue is split into base, linear algebra, FFT / DCT, and windows sections.


Importing

Import only what you need with use function:

php
<?php

use function PhpMlKit\NDArray\nd_array;
use function PhpMlKit\NDArray\add;
use function PhpMlKit\NDArray\Linalg\matmul;

$a = nd_array([[1, 2], [3, 4]]);
$b = add($a, $a);
$c = matmul($a, $a);

You can combine imports from the base namespace and sub-namespaces in one use function block if you prefer.


Base namespace

Array creation and factories

FunctionMaps toSee
nd_arrayNDArray::fromArray()Array Creation — fromArray
zerosNDArray::zeros()Array Creation — zeros
onesNDArray::ones()Array Creation — ones
fullNDArray::full()Array Creation — full
from_bufferNDArray::fromBuffer()Array Creation — fromBuffer
from_bytesNDArray::fromBytes()Array Creation — fromBytes
from_scalarNDArray::fromScalar()Array Creation — fromScalar
zeros_likeNDArray::zerosLike()Array Creation
ones_likeNDArray::onesLike()Array Creation
full_likeNDArray::fullLike()Array Creation
eyeNDArray::eye()Array Creation — eye
arangeNDArray::arange()Array Creation — arange
linspaceNDArray::linspace()Array Creation — linspace
logspaceNDArray::logspace()Array Creation - logspace
geomspaceNDArray::geomspace()Array Creation - geomspace
meshgridNDArray::meshgrid()Array Creation - meshgrid
randomNDArray::random()Array Creation - random
random_intNDArray::randomInt()Array Creation
randnNDArray::randn()Array Creation
normalNDArray::normal()Array Creation - normal
uniformNDArray::uniform()Array Creation - uniform
tileNDArray::tile()Array Manipulation - tile
repeatNDArray::repeat()Array Manipulation - repeat
copy$a->copy()Array Manipulation
astype$a->astype()Array Manipulation
cast$a->cast()Array Manipulation

Element-wise math and arithmetic

FunctionMaps toSee
add$a->add()Mathematical Functions – add
subtract$a->subtract()Mathematical Functions – subtract
multiply$a->multiply()Mathematical Functions – multiply
divide$a->divide()Mathematical Functions – divide
rem$a->rem()Mathematical Functions – rem
mod$a->mod()Mathematical Functions – mod
abs$a->abs()Mathematical Functions – abs
negative$a->negative()Mathematical Functions – negative
real$a->real()Mathematical Functions – real
imag$a->imag()Mathematical Functions – imag
conjugate$a->conjugate()Mathematical Functions – conjugate
conj$a->conj()Mathematical Functions – conj
iscomplex$a->iscomplex()Mathematical Functions – iscomplex
isreal$a->isreal()Mathematical Functions – isreal
angle$a->angle()Mathematical Functions – angle
sqrt$a->sqrt()Mathematical Functions – sqrt
exp$a->exp()Mathematical Functions – exp
log$a->log()Mathematical Functions – log
ln$a->ln()Mathematical Functions – ln
sin$a->sin()Mathematical Functions – sin
cos$a->cos()Mathematical Functions – cos
tan$a->tan()Mathematical Functions – tan
sinh$a->sinh()Mathematical Functions – sinh
cosh$a->cosh()Mathematical Functions – cosh
tanh$a->tanh()Mathematical Functions – tanh
asin$a->asin()Mathematical Functions – asin
acos$a->acos()Mathematical Functions – acos
atan$a->atan()Mathematical Functions – atan
cbrt$a->cbrt()Mathematical Functions – cbrt
ceil$a->ceil()Mathematical Functions – ceil
exp2$a->exp2()Mathematical Functions – exp2
floor$a->floor()Mathematical Functions – floor
log2$a->log2()Mathematical Functions – log2
log10$a->log10()Mathematical Functions – log10
pow2$a->pow2()Mathematical Functions – pow2
round$a->round()Mathematical Functions – round
signum$a->signum()Mathematical Functions – signum
recip$a->recip()Mathematical Functions – recip
ln1p$a->ln1p()Mathematical Functions – ln1p
to_degrees$a->toDegrees()Mathematical Functions – toDegrees
to_radians$a->toRadians()Mathematical Functions – toRadians
powi$a->powi()Mathematical Functions – powi
powf$a->powf()Mathematical Functions – powf
hypot$a->hypot()Mathematical Functions – hypot

Bitwise and shifts

FunctionMaps toSee
bitand$a->bitand()Bitwise Operations – bitand
bitor$a->bitor()Bitwise Operations – bitor
bitxor$a->bitxor()Bitwise Operations – bitxor
left_shift$a->leftShift()Bitwise Operations – left_shift
right_shift$a->rightShift()Bitwise Operations – right_shift

Clipping and extrema

FunctionMaps toSee
clamp$a->clamp()Mathematical Functions – clamp
clip$a->clip()Mathematical Functions – clip
minimum$a->minimum()Mathematical Functions – minimum
maximum$a->maximum()Mathematical Functions – maximum
sigmoid$a->sigmoid()Mathematical Functions – sigmoid
softmax$a->softmax()Mathematical Functions – softmax

Comparisons

FunctionMaps toSee
eq$a->eq()Logic Functions – eq
ne$a->ne()Logic Functions – ne
gt$a->gt()Logic Functions – gt
gte$a->gte()Logic Functions – gte
lt$a->lt()Logic Functions – lt
lte$a->lte()Logic Functions – lte

Logical (boolean element-wise)

FunctionMaps toSee
and$a->and()Logic Functions – and
or$a->or()Logic Functions – or
not$a->not()Logic Functions – not
xor$a->xor()Logic Functions – xor

Statistics and reductions

FunctionMaps toSee
sum$a->sum()Statistics – sum
mean$a->mean()Statistics – mean
amin$a->min()Statistics – min
amax$a->max()Statistics – max
argmin$a->argmin()Sorting & Searching – argmin
argmax$a->argmax()Sorting & Searching – argmax
sort$a->sort()Sorting & Searching – sort
argsort$a->argsort()Sorting & Searching – argsort
topk$a->topk()Sorting & Searching – topk
product$a->product()Statistics – product
cumsum$a->cumsum()Statistics – cumsum
cumprod$a->cumprod()Statistics – cumprod
var$a->var()Statistics – var
std$a->std()Statistics – std
bincount$a->bincount()Statistics – bincount

Shape, padding, tiling

FunctionMaps toSee
pad$a->pad()Array Manipulation – pad
reshape$a->reshape()Array Manipulation – reshape
transpose$a->transpose()Array Manipulation – transpose
swapaxes$a->swapaxes()Array Manipulation – swapaxes
permute$a->permute()Array Manipulation – permute
mergeaxes$a->mergeaxes()Array Manipulation – mergeaxes
flip$a->flip()Array Manipulation – flip
insertaxis$a->insertaxis()Array Manipulation – insertaxis
flatten$a->flatten()Array Manipulation – flatten
ravel$a->ravel()Array Manipulation – ravel
squeeze$a->squeeze()Array Manipulation – squeeze
expand_dims$a->expandDims()Array Manipulation – expandDims
tile$a->tile()Array Manipulation – tile
repeat$a->repeat()Array Manipulation – repeat

Stacking and splitting

FunctionMaps toSee
concatenateNDArray::concatenate()Array Manipulation – concatenate
stackNDArray::stack()Array Manipulation – stack
vstackNDArray::vstack()Array Manipulation – vstack
hstackNDArray::hstack()Array Manipulation – hstack
split$a->split()Array Manipulation – split
vsplit$a->vsplit()Array Manipulation – vsplit
hsplit$a->hsplit()Array Manipulation – hsplit

Indexing, take/put, selection

FunctionMaps toSee
get$a->get()Indexing Routines – get
set$a->set()Indexing Routines – set
set_at$a->setAt()Indexing Routines – setAt
get_at$a->getAt()Indexing Routines – getAt
take$a->take()Indexing Routines – take
take_along_axis$a->takeAlongAxis()Indexing Routines – takeAlongAxis
put$a->put()Indexing Routines – put
put_along_axis$a->putAlongAxis()Indexing Routines – putAlongAxis
scatter_add$a->scatterAdd()Indexing Routines – scatterAdd
whereNDArray::where()Indexing Routines – where

Slicing and assignment

FunctionMaps toSee
slice$a->slice()Indexing Routines – slice
assign$a->assign()Indexing Routines – assign

Linear algebra namespace

Import with:

php
use function PhpMlKit\NDArray\Linalg\norm;
use function PhpMlKit\NDArray\Linalg\matmul;
FunctionMaps toSee
norm$a->norm()Linear Algebra – norm
dot$a->dot()Linear Algebra – dot
matmul$a->matmul()Linear Algebra – matmul
einsum$a->einsum()Linear Algebra – einsum
diagonal$a->diagonal()Linear Algebra – diagonal
diag$a->diag()Linear Algebra – diag
trace$a->trace()Linear Algebra – trace
solve$a->solve()Linear Algebra – solve
inv$a->inv()Linear Algebra – inv
det$a->det()Linear Algebra – det
svd$a->svd()Linear Algebra – svd
qr$a->qr()Linear Algebra – qr
eig$a->eig()Linear Algebra – eig
eigvals$a->eigvals()Linear Algebra – eigvals
eigh$a->eigh()Linear Algebra – eigh
eigvalsh$a->eigvalsh()Linear Algebra – eigvalsh
cholesky$a->cholesky()Linear Algebra – cholesky
lstsq$a->lstsq()Linear Algebra – lstsq
least_squares$a->leastSquares()Linear Algebra – leastSquares
pinv$a->pinv()Linear Algebra – pinv
cond$a->cond()Linear Algebra – cond
rank$a->rank()Linear Algebra – rank

FFT and DCT namespace

Import with:

php
use function PhpMlKit\NDArray\Fft\fft;
use function PhpMlKit\NDArray\Fft\ifft;
FunctionMaps toSee
fft$a->fft()Signal Processing – fft
ifft$a->ifft()Signal Processing – ifft
fftn$a->fftn()Signal Processing – fftn
ifftn$a->ifftn()Signal Processing – ifftn
rfft$a->rfft()Signal Processing – rfft
irfft$a->irfft()Signal Processing – irfft
fft2$a->fft2()Signal Processing – fft2
ifft2$a->ifft2()Signal Processing – ifft2
dct$a->dct()Signal Processing – dct
idct$a->idct()Signal Processing – idct
dctn$a->dctn()Signal Processing – dctn
idctn$a->idctn()Signal Processing – idctn
dct2$a->dct2()Signal Processing – dct2
idct2$a->idct2()Signal Processing – idct2

Window functions namespace

Import with:

php
use function PhpMlKit\NDArray\Windows\hanning;

Each function wraps the matching static method on NDArray and returns a Float64 vector of length $m.

FunctionMaps toSee
bartlettNDArray::bartlett()Window Functions – bartlett
blackmanNDArray::blackman()Window Functions – blackman
bohmanNDArray::bohman()Window Functions – bohman
boxcarNDArray::boxcar()Window Functions – boxcar
hammingNDArray::hamming()Window Functions – hamming
hanningNDArray::hanning()Window Functions – hanning
hannNDArray::hann()Window Functions – hann
kaiserNDArray::kaiser()Window Functions – kaiser
lanczosNDArray::lanczos()Window Functions – lanczos
triangNDArray::triang()Window Functions – triang

See also

Released under the MIT License.