Skip to content

vtl #

VTL tensor network logo

The V Tensor Library

[![Mentioned in Awesome V][awesomevbadge]][awesomevurl] [![CI][workflowbadge]][workflowurl] [![Docs][docsbadge]][docsurl] [![Full ML][fullmlbadge]][fullmlurl] [![Benchmarks][benchmarksbadge]][benchmarksurl] [![License: MIT][licensebadge]][licenseurl] ![VSL Backed][vslbackedbadge] ![CUDA Optional][cudaoptionalbadge] ![Vulkan f32][vulkanbadge]

VTL is a pure-V tensor library for numerical computing and machine learning — n-dimensional arrays, autograd, linear algebra via VSL, and a full neural network module.

Train small neural networks, experiment with autograd, and use VSL-backed CPU, CUDA, and Vulkan compute paths from one V-native API.

vlang.io | Docs | Tutorials | Histograms | PyTorch parity | Burn comparison | ML Roadmap | Contributing | VSL

<imgsrc="static/vtl-feature-banner.svg"alt="VTL tensors, autograd, numerical computing, and CPU and GPU training paths"width="100%"

VTL and VSL architecture

VTL tensor, VSL kernel, and compute backend architecture

View SVG source · PNG

import vtl
t := vtl.from_array([1.0, 2, 3, 4], [2, 2])!
t.get([1, 1])
// 4.0

Features

  • Tensors — create, slice, indexed take/take_nd/take_flat/put, choose/select, round_decimals, nan_to_num, compress, indices, pad, set membership, reshape, transpose, move/roll axes, N-D diagonal views, NumPy-style Kronecker products, broadcast, map/reduce, einsum, and complex128 storage with elementwise and matrix products
  • Autograd — reverse-mode AD; arbitrary computational graphs
  • Neural networks — Sequential API; Linear, Conv2D, LSTM, Attention, …
  • Losses & optimizers — MSE, MAE, BCE, Hinge, Focal, CrossEntropy, Huber; Adam, AdamW, NAdam, RAdam, SGD, …
  • Linear algebra — VSL-backed real matmul and general eigensolvers, pure-V complex128 matmul, solve, QR, LU, Cholesky, SVD, pinv
  • Hardware — zero-copy Tensor.data for C libs; optional CUDA and Vulkan training paths

ML Release Highlights

The ML beta scope is the high-level VTL API: tensors, autograd, layers, losses, optimizers, datasets, and CPU training. CUDA and Vulkan paths are available for opt-in validation and early adopters, but remain experimental backend accelerators rather than stable user contracts.

Area Status
f32 training Sequential + MSE + Adam smoke tests
CUDA Experimental opt-in Linear/Conv2D forward; f64 Linear/Conv2D/Dropout backward; activation chain and Adam slots
Vulkan Experimental opt-in f32 Linear, Conv2D same-padding, ReLU/Sigmoid/Softplus/SELU/HardSwish, fused Adam shader
Datasets MNIST, IMDB, CIFAR-10 loaders plus CI-safe synthetic examples
Benchmarks VTL vs NumPy/PyTorch scripts and PR benchmark workflow

For memory-safe local commands, see DEV_LIGHTWEIGHT.md.

Quick start

import vtl
import vtl.autograd
import vtl.nn.layers
import vtl.nn.models
import vtl.nn.optimizers

mut ctx := autograd.ctx[f32]()
mut model := models.sequential_from_ctx[f32](ctx)
model.input([784])
model.linear(256)
model.linear(10)
model.mse_loss()

input_tensor := vtl.zeros[f32]([64, 784])
mut x := ctx.variable(input_tensor)
y_pred := model.forward(x)!

target := vtl.zeros[f32]([64, 10])
mut loss_val := model.loss(y_pred, target)!
loss_val.backprop()!

mut opt := optimizers.adam_optimizer[f32](optimizers.AdamOptimizerConfig{
    learning_rate: 0.001
})
opt.build_params(model.info.layers)
opt.update()!

Module overview

Module Purpose Guide
vtl Tensor creation, slicing, broadcasting, reductions First steps
Complex tensors math.complex.Complex storage and elementwise arithmetic Complex tensors
vtl.fft Real and complex FFTs via VSL PocketFFT FFT
vtl.csv Numeric CSV tensor input and output NumPy I/O
vtl.npy / vtl.npz Typed NumPy array and archive I/O NumPy I/O
vtl.autograd Differentiable operations and backpropagation Autograd
vtl.autograd_cuda Optional CUDA autograd Device memory
vtl.la VSL-backed linear algebra Linear algebra
vtl.nn Layers, losses, optimizers, and training Neural networks
vtl.nn.models Model construction, training, serialization Neural networks
vtl.nn.layers Dense, convolutional, recurrent, and attention layers Neural networks
vtl.nn.loss Regression and classification losses Neural networks
vtl.nn.optimizers Optimizers and learning-rate schedulers Optimizers
vtl.nn.data Neural-network data loaders Examples
vtl.nn.internal Internal tensor and activation operations Source
vtl.nn.gates Neural-network autograd gates Autograd
vtl.datasets MNIST, CIFAR-10, and IMDB loaders Datasets
vtl.stats Averages, descriptive statistics, and summaries Reductions
Core lookup Unique values, indexing, and set operations Indexing
vtl.ml.metrics Machine-learning metrics and evaluation Source
vtl.storage CPU, CUDA, VCL, and Vulkan storage Device memory

Installation

VTL uses VSL for linear algebra. The core vtl module works without optional system BLAS/LAPACK, but LA features need VSL.

Follow VSL install instructions, then:

v install vtl

Testing

# Run the full scoped suite from ~/.vmodules; compiler parallelism is disabled
# to keep the local memory ceiling predictable.
cd ~/.vmodules
systemd-run --user --scope --property=MemoryMax=4G --property=MemorySwapMax=0 \
    env VJOBS=2 VTL_NO_PARALLEL=1 ./vtl/bin/test

See DEV_LIGHTWEIGHT.md for memory-safe subsets in CI.

Documentation

Start Here

Goal Read
Learn tensors First steps
Learn autograd Autograd tutorial
Build neural networks Neural networks
Pick optimizers Optimizers
Run examples Examples catalog
Use datasets Datasets
Exchange NumPy .npy arrays .npy input/output
Quantize tensors for INT8 inference Quantization API, example
Load numeric CSV data CSV and NumPy I/O
Use GPU paths safely DEV_LIGHTWEIGHT.md, DEVICE_MEMORY.md
Tutorial Topic
TUTORIAL_FIRST_STEPS.md Tensor creation, indexing, slicing
TUTORIAL_MATH_UFUNCS.md NumPy-style elementwise math and binary decomposition
TUTORIAL_MAP_REDUCE.md map / nmap and reductions
TUTORIAL_AUTOGRAD.md Variable, gates, backprop
TUTORIAL_REDUCTIONS.md argmax / argmin / cumsum
TUTORIAL_NEURAL_NETWORKS.md Layers, losses, Sequential
TUTORIAL_OPTIMIZERS.md Adam, AdamW, RMSProp, schedulers
TUTORIAL_LINEAR_ALGEBRA.md LA basics via VSL
TUTORIAL_FFT.md One-dimensional real Fourier transforms via PocketFFT
TUTORIAL_ADVANCED_LA.md QR, LU, Cholesky, pinv
TUTORIAL_BROADCASTING.md Broadcasting rules
TUTORIAL_SLICING.md Slicing and views

Full index: docs/README.md.

Contributors

VTL's early development was inspired by vnum, part of the Vlang Num group, and the work of Christopher Zimmerman. The core was reimplemented while keeping that lineage and inspiration. The original vnum work carried a BSD 3-Clause license with attribution to vlang-num contributors; the historical license text is preserved in the VTL repository history. This acknowledgment records that history and does not change VTL's current license, shown below.

VTL contributors

Made with contributors-img.

License

MIT

[awesomevbadge]: https://awesome.re/mentioned-badge.svg [workflowbadge]: https://github.com/vlang/vtl/actions/workflows/ci.yml/badge.svg [docsbadge]: https://github.com/vlang/vtl/actions/workflows/deploy-docs.yml/badge.svg [fullmlbadge]: https://github.com/vlang/vtl/actions/workflows/ci-full-ml.yml/badge.svg [benchmarksbadge]: https://github.com/vlang/vtl/actions/workflows/benchmark-pr-comment.yml/badge.svg [licensebadge]: https://img.shields.io/badge/License-MIT-blue.svg [vslbackedbadge]: https://img.shields.io/badge/VSL-backed-027d9c?logo=v [cudaoptionalbadge]: https://img.shields.io/badge/CUDA-optional-76b900?logo=nvidia [vulkanbadge]: https://img.shields.io/badge/Vulkan-f32-ac162c?logo=vulkan [awesomevurl]: https://github.com/vlang/awesome-v/blob/master/README.md#scientific-computing [workflowurl]: https://github.com/vlang/vtl/actions/workflows/ci.yml [docsurl]: https://github.com/vlang/vtl/actions/workflows/deploy-docs.yml [fullmlurl]: https://github.com/vlang/vtl/actions/workflows/ci-full-ml.yml [benchmarksurl]: https://github.com/vlang/vtl/actions/workflows/benchmark-pr-comment.yml [licenseurl]: https://github.com/vlang/vtl/blob/main/LICENSE

fn abs #

fn abs(input &Tensor[complex.Complex]) !&Tensor[f64]

abs is the NumPy-style alias for absolute.

fn absolute #

fn absolute(input &Tensor[complex.Complex]) !&Tensor[f64]

absolute returns the magnitude of every complex element as a float64 tensor. math.hypot scales its inputs to avoid unnecessary overflow and underflow.

fn add_promoted #

fn add_promoted[R, T, U](a &Tensor[T], b &Tensor[U]) !&Tensor[R]

add_promoted adds real numeric tensors after converting both operands to the explicitly selected NumPy-style promoted dtype. The output type R must match promote_types(dtype_ofT, dtype_ofU).

fn advanced_index #

fn advanced_index[T](t &Tensor[T], indices []&Tensor[int]) !&Tensor[T]

advanced_index selects values using one integer coordinate tensor per input axis. Coordinate tensors are broadcast together, and each output element is read from the matching coordinate tuple. The result is an independent row-major copy. This API handles full coordinate tuples; mixing coordinate tensors with slices or scalar indices is not supported here.

fn arange #

fn arange[T](start f64, stop f64, step f64, params TensorData) !&Tensor[T]

arange returns evenly spaced values in the half-open interval [start, stop). The direction of step determines whether the result is ascending or descending.

fn arccos #

fn arccos(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

arccos applies the principal inverse complex cosine to every element.

fn arccosh #

fn arccosh(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

arccosh applies the principal inverse complex hyperbolic cosine to every element.

fn arcsin #

fn arcsin(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

arcsin applies the principal inverse complex sine to every element.

fn arcsinh #

fn arcsinh(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

arcsinh applies the principal inverse complex hyperbolic sine to every element.

fn arctan #

fn arctan(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

arctan applies the principal inverse complex tangent to every element.

fn arctanh #

fn arctanh(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

arctanh applies the principal inverse complex hyperbolic tangent to every element.

fn argpartition #

fn argpartition[T](t &Tensor[T], kth int) !&Tensor[int]

argpartition returns local indices that place kth at its sorted position along the last axis. The order of the other indices is unspecified.

fn argpartition_axis #

fn argpartition_axis[T](t &Tensor[T], kths []int, axis int) !&Tensor[int]

argpartition_axis partially orders local indices along axis. The returned tensor has the same shape as t and supports multiple kth positions.

fn argsort #

fn argsort[T](t &Tensor[T]) !&Tensor[int]

argsort returns stable ascending sort indices along the last axis.

fn argsort_axis #

fn argsort_axis[T](t &Tensor[T], axis int) !&Tensor[int]

argsort_axis returns the stable ascending sort indices along axis. Returned indices are local to that axis; floating-point NaNs sort to the end.

fn argwhere #

fn argwhere[T](t &Tensor[T]) !&Tensor[int]

argwhere returns the coordinates of non-zero elements as a row-major tensor with shape [number of matches, input rank].

fn array_index #

fn array_index(indices &Tensor[int]) TensorIndex

array_index selects positions using an integer coordinate tensor. All coordinate tensors in a mixed_index call are broadcast together.

fn bernoulli #

fn bernoulli[T](prob f64, shape []int, params TensorData) &Tensor[T]

bernoulli returns a tensor of bernoulli random variables.

fn beta #

fn beta(alpha f64, beta f64, shape []int, params TensorData) !&Tensor[f64]

beta returns samples from the Beta distribution using VTL's global stream.

fn binomial #

fn binomial[T](n int, prob f64, shape []int, params TensorData) !&Tensor[T]

binomial returns a tensor of binomial random variables.

fn boolean_index #

fn boolean_index[T](t &Tensor[T], mask &Tensor[bool]) !&Tensor[T]

boolean_index selects values where mask is true. The mask shape must match the leading tensor dimensions; any remaining tensor dimensions are retained after the selected-element axis. The result is an independent row-major copy, matching NumPy's a[mask] behavior.

fn broadcast2 #

@[inline]
fn broadcast2[T](a &Tensor[T], b &Tensor[T]) !(&Tensor[T], &Tensor[T])

broadcast2 exposes this operation as part of the public API.

fn broadcast3 #

@[inline]
fn broadcast3[T](a &Tensor[T], b &Tensor[T], c &Tensor[T]) !(&Tensor[T], &Tensor[T], &Tensor[T])

broadcast3 exposes this operation as part of the public API.

fn broadcast_n #

@[inline]
fn broadcast_n[T](ts []&Tensor[T]) ![]&Tensor[T]

broadcast_n exposes this operation as part of the public API.

fn cast #

fn cast[T](x TensorDataType) T

cast exposes this operation as part of the public API.

fn cauchy #

fn cauchy(location f64, scale f64, shape []int, params TensorData) !&Tensor[f64]

cauchy returns samples from a Cauchy distribution using VTL's global stream.

fn chi_square #

fn chi_square(degrees_of_freedom f64, shape []int, params TensorData) !&Tensor[f64]

chi_square returns samples from a chi-square distribution using VTL's global random stream.

fn choose #

fn choose[T](indices &Tensor[int], choices []&Tensor[T]) !&Tensor[T]

choose selects values from choices using integer indices. Choices broadcast to one common shape, and indices broadcast to that shape. Each index must be in the range [0, choices.len).

fn clip_tensor #

fn clip_tensor[T](t &Tensor[T], lower &Tensor[T], upper &Tensor[T]) !&Tensor[T]

clip_tensor clamps values using broadcastable lower and upper bounds. It computes the result in one pass so callers do not need separate maximum and minimum tensors or intermediate results. Stride-based offsets avoid creating per-element coordinate arrays, including when an input is a view.

fn column_stack #

fn column_stack[T](ts []&Tensor[T]) !&Tensor[T]

column_stack stacks 1-D arrays as columns into a 2-D array.

fn complex_angle #

fn complex_angle(input &Tensor[complex.Complex], degrees bool) !&Tensor[f64]

complex_angle returns the phase of each value in radians, or degrees when requested. The result range follows atan2 and is [-pi, pi].

fn complex_is_finite #

fn complex_is_finite(input &Tensor[complex.Complex]) !&Tensor[bool]

complex_is_finite reports whether both components of each value are finite.

fn complex_is_inf #

fn complex_is_inf(input &Tensor[complex.Complex]) !&Tensor[bool]

complex_is_inf reports whether either component of each value is infinite.

fn complex_is_nan #

fn complex_is_nan(input &Tensor[complex.Complex]) !&Tensor[bool]

complex_is_nan reports whether either component of each value is NaN.

fn compress #

fn compress[T](condition &Tensor[bool], t &Tensor[T]) !&Tensor[T]

compress selects flattened values at positions where condition is true. As in NumPy, a condition shorter than the input stops selection at its length; extra condition values are ignored.

fn compress_axis #

fn compress_axis[T](condition &Tensor[bool], t &Tensor[T], axis int) !&Tensor[T]

compress_axis selects slices along axis using a one-dimensional condition. If condition is shorter than the axis, the remaining slices are omitted.

fn concatenate #

fn concatenate[T](ts []&Tensor[T], data AxisData) !&Tensor[T]

concatenate concatenates two Tensors together

fn conj #

fn conj(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

conj returns the complex conjugate of every element in a complex tensor.

fn copysign #

fn copysign[T](magnitude &Tensor[T], sign &Tensor[T]) !&Tensor[T]

copysign returns the magnitude of magnitude with the sign bit of sign. Both f32 and f64 inputs broadcast to a common output shape.

fn cos #

fn cos(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

cos applies the complex cosine to every element.

fn cosh #

fn cosh(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

cosh applies the complex hyperbolic cosine to every element.

fn count_nonzero #

@[direct_array_access]
fn count_nonzero[T](t &Tensor[T]) int

count_nonzero counts non-zero values across every tensor dimension.

fn count_nonzero_axes #

fn count_nonzero_axes[T](t &Tensor[T], axes []int, keepdims bool) !&Tensor[int]

count_nonzero_axes counts non-zero values along multiple axes. Negative axes are supported, axes must be unique, and an empty axis list preserves the input shape while converting each value to zero or one.

fn count_nonzero_axis #

fn count_nonzero_axis[T](t &Tensor[T], axis int, keepdims bool) !&Tensor[int]

count_nonzero_axis counts non-zero values along one axis. By default the reduced axis is removed; set keepdims to retain it with length one.

fn diagonal #

fn diagonal[T](input &Tensor[T], params DiagonalData) !&Tensor[T]

diagonal returns a view along the diagonal of two axes of an N-D tensor. The selected axes are removed and the diagonal axis is appended to the result, following NumPy's shape convention. The view shares input storage. VTL tensors remain mutable, so writes through the result update the input.

fn diff #

fn diff[T](t &Tensor[T], n int, axis int) !&Tensor[T]

diff computes the n-th discrete difference along an axis. Negative axes count from the end, and n=0 returns a row-major copy of the input.

fn digitize #

fn digitize[T](values &Tensor[T], bins &Tensor[T], right bool) !&Tensor[int]

digitize assigns values to monotonic bins. Increasing and decreasing edge arrays are supported; right selects which interval owns an edge value.

fn dirichlet #

fn dirichlet[T](alpha &Tensor[T], sample_shape []int, params TensorData) !&Tensor[f64]

dirichlet returns normalized Gamma samples. The final output axis contains categories and sample_shape defines the preceding axes.

fn divide_promoted #

fn divide_promoted[R, T, U](a &Tensor[T], b &Tensor[U]) !&Tensor[R]

divide_promoted performs NumPy-style true division for real numeric tensors and booleans. The output dtype is float32 only when the promoted input dtype is float32; otherwise it is float64. Inputs are broadcast before division.

fn dstack #

fn dstack[T](ts []&Tensor[T]) !&Tensor[T]

dstack stacks arrays in sequence depth wise (along third axis)

fn dtype_of #

fn dtype_of[T]() DType

dtype_of returns the VTL dtype corresponding to the compile-time type T.

fn einsum #

fn einsum[T](subscripts string, operands ...&Tensor[T]) !&Tensor[T]

einsum evaluates an Einstein summation expression over one or more tensors. It supports alphabetic axis labels, explicit or implicit output labels, repeated labels for diagonals, broadcasting of size-one axes, and any number of operands. Ellipses expand to the leading axes and are right-aligned across operands, enabling batched expressions such as ...ij,...jk->...ik.

When the output is omitted, labels that occur exactly once are returned in alphabetical order, following NumPy's implicit-output convention.

fn ellipsis_index #

fn ellipsis_index() TensorIndex

ellipsis_index expands to enough full axes to cover the unindexed dimensions. At most one ellipsis is allowed in a mixed_index call.

fn empty #

@[inline]
fn empty[T](shape []int, params TensorData) &Tensor[T]

empty exposes this operation as part of the public API.

fn empty_like #

@[inline]
fn empty_like[T](t &Tensor[T]) &Tensor[T]

empty_like exposes this operation as part of the public API.

fn exp #

fn exp(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

exp applies the complex exponential to every complex tensor element.

fn exponential #

fn exponential[T](lambda f64, shape []int, params TensorData) &Tensor[T]

exponential returns a tensor of exponential random variables.

fn eye #

fn eye[T](m int, n int, k int, params TensorData) &Tensor[T]

eye returns a 2D array with ones on the diagonal and zeros elsewhere

fn f_distribution #

fn f_distribution(numerator_df f64, denominator_df f64, shape []int, params TensorData) !&Tensor[f64]

f_distribution returns samples from the F distribution using VTL's global random stream.

fn from_1d #

fn from_1d[T](arr []T, params TensorData) !&Tensor[T]

from_1d takes a one dimensional array of floating point values and returns a one dimensional Tensor if possible

fn from_2d #

@[direct_array_access]
fn from_2d[T](a [][]T, params TensorData) !&Tensor[T]

from_2d exposes this operation as part of the public API.

fn from_array #

fn from_array[T](arr []T, shape []int, params TensorData) !&Tensor[T]

from_varray takes a one dimensional array of T values and coerces it into an arbitrary shaped Tensor if possible. Panics if the shape provided does not hold the provided array

fn full #

@[inline]
fn full[T](shape []int, val T, params TensorData) &Tensor[T]

full exposes this operation as part of the public API.

fn full_index #

fn full_index() TensorIndex

full_index selects every position on one axis.

fn full_like #

fn full_like[T](t &Tensor[T], val T) &Tensor[T]

full_like returns a new tensor of the same shape and type as a given Tensor filled with a given val

fn gamma #

fn gamma(alpha f64, scale f64, shape []int, params TensorData) !&Tensor[f64]

gamma returns samples from a Gamma distribution on VTL's global random stream. alpha is the shape and scale is the scale parameter.

fn geometric #

fn geometric(probability f64, shape []int, params TensorData) !&Tensor[int]

geometric returns the number of Bernoulli trials needed for the first success, sampled from V's global random stream. Results start at 1.

fn gumbel #

fn gumbel(location f64, scale f64, shape []int, params TensorData) !&Tensor[f64]

gumbel returns samples from a Gumbel distribution using VTL's global stream.

fn hstack #

fn hstack[T](ts []&Tensor[T]) !&Tensor[T]

hstack stacks arrays in sequence horizontally (column wise)

fn hypergeometric #

fn hypergeometric(ngood int, nbad int, nsample int, shape []int, params TensorData) !&Tensor[int]

hypergeometric returns the number of good items in draws made without replacement from a population containing ngood good and nbad bad items.

fn identity #

@[inline]
fn identity[T](n int, params TensorData) &Tensor[T]

identity exposes this operation as part of the public API.

fn imag #

fn imag(input &Tensor[complex.Complex]) !&Tensor[f64]

imag returns the imaginary components of a complex tensor as a float64 tensor.

fn indices #

fn indices(dimensions []int) !&Tensor[int]

indices returns a dense coordinate tensor with shape [dimensions.len, ...dimensions], matching numpy.indices for integer arrays. Each leading-axis plane contains the coordinates for one input dimension.

fn indices_sparse #

fn indices_sparse(dimensions []int) ![]&Tensor[int]

indices_sparse returns one broadcastable coordinate tensor per dimension. Each result has rank dimensions.len and only its own axis has non-unit length, matching numpy.indices(..., sparse: true) without allocating the dense coordinate stack.

fn integer_index #

fn integer_index(index int) TensorIndex

integer_index selects one position and removes its axis from the result.

fn isin #

fn isin[T](elements &Tensor[T], test_elements &Tensor[T]) &Tensor[bool]

isin returns a boolean tensor indicating whether each element occurs in test_elements. It preserves the shape and logical iteration order of the input, including for non-contiguous views.

fn kron #

fn kron[T](a &Tensor[T], b &Tensor[T]) !&Tensor[T]

kron returns the Kronecker product of two tensors. The lower-rank input is left-padded with singleton dimensions, matching NumPy's rank semantics.

fn laplace #

fn laplace(location f64, scale f64, shape []int, params TensorData) !&Tensor[f64]

laplace returns samples from a Laplace distribution using VTL's global stream.

fn ldexp #

fn ldexp[T](mantissa &Tensor[T], exponent &Tensor[int]) !&Tensor[T]

ldexp scales each floating-point mantissa by 2 raised to the corresponding integer exponent. The operands broadcast to a common shape.

fn linspace #

fn linspace[T](start f64, stop f64, num int, params LinspaceData) !&Tensor[T]

linspace returns num evenly spaced values between start and stop. The endpoint is included by default; set endpoint: false to exclude stop.

fn log #

fn log(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

log applies the principal complex natural logarithm to every element.

fn logaddexp #

fn logaddexp[T](a &Tensor[T], b &Tensor[T]) !&Tensor[T]

logaddexp computes log(exp(a) + exp(b)) elementwise using a stable form. The f32/f64 operands broadcast to a common output shape.

fn logaddexp2 #

fn logaddexp2[T](a &Tensor[T], b &Tensor[T]) !&Tensor[T]

logaddexp2 computes log2(2^a + 2^b) elementwise using a stable form. The f32/f64 operands broadcast to a common output shape.

fn logistic #

fn logistic(location f64, scale f64, shape []int, params TensorData) !&Tensor[f64]

logistic returns samples from a Logistic distribution using VTL's global stream.

fn lognormal #

fn lognormal(mean f64, sigma f64, shape []int, params TensorData) !&Tensor[f64]

lognormal returns samples whose natural logarithm follows a normal distribution using VTL's global random stream.

fn logspace #

fn logspace[T](start f64, stop f64, num int, params LogspaceData) !&Tensor[T]

logspace returns num values spaced evenly on a logarithmic scale between base^start and base^stop. The endpoint is included by default.

fn masked_array #

fn masked_array[T](values &Tensor[T], mask &Tensor[bool]) !MaskedArray[T]

masked_array creates a masked tensor. The mask broadcasts against values; the returned values and mask are views with the common broadcast shape.

fn meshgrid #

fn meshgrid[T](x &Tensor[T], y &Tensor[T]) !(&Tensor[T], &Tensor[T])

meshgrid builds dense two-dimensional XY coordinate grids from two vectors. The output shape is [len(y), len(x)], matching NumPy's default indexing="xy".

fn meshgrid_n #

fn meshgrid_n[T](vectors []&Tensor[T], indexing MeshgridIndexing) ![]&Tensor[T]

meshgrid_n builds one dense coordinate tensor for each one-dimensional input. With xy, the first two dimensions are swapped, matching NumPy's default indexing convention. ij preserves the input axis order.

fn mixed_index #

fn mixed_index[T](t &Tensor[T], indices []TensorIndex) !&Tensor[T]

mixed_index combines full slices, ranges, scalar integers, broadcasted coordinate tensors, ellipsis, and inserted size-one axes. Omitted trailing axes select the full axis. If every index is basic, the result is a view; if any coordinate tensor is used, the result is an independent row-major copy.

fn multiply_promoted #

fn multiply_promoted[R, T, U](a &Tensor[T], b &Tensor[U]) !&Tensor[R]

multiply_promoted multiplies real numeric tensors after converting both operands to the explicitly selected NumPy-style promoted dtype. The output type R must match promote_types(dtype_ofT, dtype_ofU).

fn multivariate_normal #

fn multivariate_normal(mean &Tensor[f64], covariance &Tensor[f64], sample_shape []int, params TensorData) !&Tensor[f64]

multivariate_normal draws samples with the requested mean and covariance using VTL's global random stream.

fn negative_binomial #

fn negative_binomial(n f64, probability f64, shape []int, params TensorData) !&Tensor[int]

negative_binomial counts failures before n successes on VTL's global random stream. n may be any finite positive real value.

fn new_random_generator #

fn new_random_generator(seed int) RandomGenerator

new_random_generator creates an independent generator initialized from seed.

fn newaxis_index #

fn newaxis_index() TensorIndex

newaxis_index inserts a size-one axis at this position without consuming an input axis. Basic indexing with a new axis remains a view.

fn nonzero #

fn nonzero[T](t &Tensor[T]) ![]&Tensor[int]

nonzero returns one index tensor per input axis, matching NumPy's tuple of coordinate arrays. A nonzero scalar is treated as a one-dimensional value with index zero, following NumPy's scalar promotion behavior.

fn normal #

fn normal[T](shape []int, params NormalTensorData) &Tensor[T]

normal returns a tensor of normal random variables.

fn one_hot #

fn one_hot(indices &Tensor[int], num_classes int) !&Tensor[int]

one_hot encodes integer class indices as rows of a one-hot matrix. The output shape is indices.shape followed by num_classes; every index must be in [0, num_classes). An empty index tensor returns an empty tensor with the corresponding trailing class dimension.

fn ones #

@[inline]
fn ones[T](shape []int, params TensorData) &Tensor[T]

ones exposes this operation as part of the public API.

fn ones_like #

@[inline]
fn ones_like[T](t &Tensor[T]) &Tensor[T]

ones_like exposes this operation as part of the public API.

fn pad #

fn pad[T](t &Tensor[T], pad_width [][]int, mode PadMode, constant_value T) !&Tensor[T]

pad adds a before/after width to every dimension. pad_width contains one [before, after] pair per axis. Reflect excludes the edge value; symmetric includes it. constant_value is used only with .constant.

fn pareto #

fn pareto(shape_parameter f64, shape []int, params TensorData) !&Tensor[f64]

pareto returns standard Pareto samples (minimum zero) using VTL's global stream.

fn partition #

fn partition[T](t &Tensor[T], kth int) !&Tensor[T]

partition returns a copy with the value at kth in its sorted position and every preceding value less than or equal to it. Remaining values are unspecified, matching NumPy's default last-axis behavior.

fn partition_axis #

fn partition_axis[T](t &Tensor[T], kths []int, axis int) !&Tensor[T]

partition_axis partially sorts each one-dimensional slice along axis. kth positions are local to each slice; multiple positions can be requested in one pass without fully sorting the data.

fn poisson #

fn poisson(lambda f64, shape []int, params TensorData) !&Tensor[int]

poisson returns integer event counts from VTL's global random stream.

fn promote_types #

fn promote_types(a DType, b DType) !DType

promote_types returns the common dtype for two array dtypes. Its numeric rules are modeled on NumPy, using the integer and floating-point types VTL currently supports. If VTL has no signed integer width that can represent both inputs, it promotes to float64. Mixing strings with other dtypes is rejected; scalar-value weak promotion is not part of this dtype-only API.

fn random #

fn random[T](min T, max T, shape []int, params TensorData) &Tensor[T]

random returns a new Tensor of given shape and type, initialized with random numbers between a given min and max value

fn random_seed #

fn random_seed(i int)

random_seed resets VTL's global random generator for reproducible results. The seed affects random tensor constructors and model parameter initialization that use V's default random generator.

fn range #

fn range[T](from int, to int, params TensorData) &Tensor[T]

range returns a Tensor containing values ranging from [from, to)

fn ravel_multi_index #

@[direct_array_access]
fn ravel_multi_index(coordinates []&Tensor[int], dimensions []int,
	options MultiIndexOptions) !&Tensor[int]

ravel_multi_index converts one integer coordinate tensor per dimension to flat indices. Coordinate tensors broadcast together. The result shape is their broadcast shape. mode applies raise, wrap, or clip bounds handling to every axis; axis_modes may instead specify one mode per axis. Order selects C (row-major) or F (column-major) flattening.

fn rayleigh #

fn rayleigh(scale f64, shape []int, params TensorData) !&Tensor[f64]

rayleigh returns samples from a Rayleigh distribution using VTL's global stream.

fn real #

fn real(input &Tensor[complex.Complex]) !&Tensor[f64]

real returns the real components of a complex tensor as a float64 tensor.

fn remainder_promoted #

fn remainder_promoted[R, T, U](a &Tensor[T], b &Tensor[U]) !&Tensor[R]

remainder_promoted returns the element-wise NumPy remainder of real numeric tensors after dtype promotion and broadcasting. Integer zero divisors produce zero; floating-point zero divisors produce NaN.

fn repeat #

fn repeat[T](t &Tensor[T], repeats int) !&Tensor[T]

repeat returns a copy with each value repeated the requested number of times. If axis is omitted the tensor is flattened first, matching NumPy.

fn repeat_axis #

fn repeat_axis[T](t &Tensor[T], repeats int, axis int) !&Tensor[T]

repeat_axis repeats each value along axis and preserves the other dimensions.

fn roll #

fn roll[T](t &Tensor[T], shift int, axes ...int) !&Tensor[T]

roll shifts values along the flattened tensor when axes is omitted. When axes are provided, the same shift is applied independently to each axis. Negative axes and shifts are accepted. The result is always a copy.

fn roll_axes #

fn roll_axes[T](t &Tensor[T], shift int, axes []int) !&Tensor[T]

roll_axes applies one scalar shift to each selected axis. Repeated axes accumulate their shifts, and an empty axis list leaves the tensor unchanged.

fn roll_flat #

fn roll_flat[T](t &Tensor[T], shift int) !&Tensor[T]

roll_flat circularly shifts the row-major logical values and preserves the original shape.

fn roll_shifts #

fn roll_shifts[T](t &Tensor[T], shifts []int, axes []int) !&Tensor[T]

roll_shifts applies paired shifts and axes, accumulating repeated axes.

fn rot90 #

fn rot90[T](t &Tensor[T]) !&Tensor[T]

rot90 rotates a tensor counterclockwise by k quarter-turns in its first two dimensions, matching NumPy's default axes=(0, 1).

fn rot90_axes #

fn rot90_axes[T](t &Tensor[T], k int, axes []int) !&Tensor[T]

rot90_axes rotates counterclockwise in the plane defined by two distinct axes.

fn rot90_k #

fn rot90_k[T](t &Tensor[T], k int) !&Tensor[T]

rot90_k rotates in the first two dimensions by k counterclockwise quarter-turns.

fn searchsorted #

fn searchsorted[T](sorted &Tensor[T], values &Tensor[T], side SearchSide) !&Tensor[int]

searchsorted returns insertion positions for values in an ascending 1-D tensor. The input is assumed to be sorted; each query uses binary search.

fn searchsorted_descending #

fn searchsorted_descending[T](sorted &Tensor[T], values &Tensor[T], side SearchSide) !&Tensor[int]

searchsorted_descending returns insertion positions for values in a descending 1-D tensor. The input is assumed to be sorted; each query uses binary search. The output has the same shape as values.

fn select #

fn select[T](conditions []&Tensor[bool], choices []&Tensor[T], default T) !&Tensor[T]

select picks the value from the first choice whose condition is true at each output position. Conditions and choices broadcast to a common shape; default is used where no condition is true.

fn seq #

@[inline]
fn seq[T](n int, params TensorData) &Tensor[T]

seq exposes this operation as part of the public API.

fn sin #

fn sin(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

sin applies the complex sine to every element.

fn sinh #

fn sinh(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

sinh applies the complex hyperbolic sine to every element.

fn slice_all #

fn slice_all(step int) !TensorIndex

slice_all selects the whole axis, optionally traversing it in reverse.

fn slice_from #

fn slice_from(start int, step int) !TensorIndex

slice_from selects from start through the end of the axis in step increments. A negative step traverses toward the beginning.

fn slice_index #

fn slice_index(start int, stop int, step int) !TensorIndex

slice_index selects an explicit Python-style [start:stop:step] range. Negative boundaries count from the end; a zero step is rejected.

fn slice_to #

fn slice_to(stop int, step int) !TensorIndex

slice_to selects from the beginning of the axis through stop in step increments.

fn sort #

fn sort[T](t &Tensor[T]) !&Tensor[T]

sort returns a copy sorted along the last axis, matching NumPy's default.

fn sort_axis #

fn sort_axis[T](t &Tensor[T], axis int) !&Tensor[T]

sort_axis returns a copy sorted in ascending order along axis. Floating-point NaNs sort after all non-NaN values, and equal values keep their input order.

fn sqrt #

fn sqrt(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

sqrt applies the principal complex square root to every element.

fn stack #

fn stack[T](ts []&Tensor[T], data AxisData) !&Tensor[T]

stack join a sequence of arrays along a new axis.

fn student_t #

fn student_t(degrees_of_freedom f64, shape []int, params TensorData) !&Tensor[f64]

student_t returns samples from the standard Student's t distribution using VTL's global random stream.

fn subtract_promoted #

fn subtract_promoted[R, T, U](a &Tensor[T], b &Tensor[U]) !&Tensor[R]

subtract_promoted subtracts real numeric tensors after converting both operands to the explicitly selected NumPy-style promoted dtype. The output type R must match promote_types(dtype_ofT, dtype_ofU).

fn tan #

fn tan(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

tan applies the complex tangent to every element.

fn tanh #

fn tanh(input &Tensor[complex.Complex]) !&Tensor[complex.Complex]

tanh applies the complex hyperbolic tangent to every element.

fn td #

fn td[T](x T) TensorDataType

td exposes this operation as part of the public API.

fn tensor #

fn tensor[T](init T, shape []int, params TensorData) &Tensor[T]

tensor allocates a Tensor onto specified device with a given data

fn tensor_like #

fn tensor_like[T](t &Tensor[T]) &Tensor[T]

tensor_like returns a new tensor created with similar storage properties as the Tensor t

fn tensor_like_with_shape #

fn tensor_like_with_shape[T](t &Tensor[T], shape []int) &Tensor[T]

tensor_like_with_shape returns a new tensor created with similar storage properties as the Tensor t with a given shape

fn tile #

fn tile[T](t &Tensor[T], reps []int) !&Tensor[T]

tile repeats t as a block according to reps. Repetition dimensions align from the right; shorter reps are padded with ones on the left, as in NumPy.

fn triangular #

fn triangular(left f64, mode f64, right f64, shape []int, params TensorData) !&Tensor[f64]

triangular returns samples from a triangular distribution using VTL's global stream.

fn tril #

fn tril[T](input &Tensor[T], options TriangularOptions) !&Tensor[T]

tril returns a copy with entries above the k-th diagonal of each trailing matrix set to zero. Inputs must have at least two dimensions.

fn triu #

fn triu[T](input &Tensor[T], options TriangularOptions) !&Tensor[T]

triu returns a copy with entries below the k-th diagonal of each trailing matrix set to zero. Inputs must have at least two dimensions.

fn unique #

fn unique[T](t &Tensor[T]) !&Tensor[T]

unique returns the sorted unique values in a flattened copy of the tensor. Floating-point NaNs are treated as one value and sort after other values.

fn unique_axis #

fn unique_axis[T](t &Tensor[T], axis int) !&Tensor[T]

unique_axis returns lexicographically sorted unique slices along axis.

fn unique_axis_result #

fn unique_axis_result[T](t &Tensor[T], axis int) !UniqueAxisResult[T]

unique_axis_result returns unique slices, occurrence counts, first source axis positions, and inverse indices aligned to the input axis.

fn unique_counts #

fn unique_counts[T](t &Tensor[T]) !UniqueCounts[T]

unique_counts returns sorted unique values and the number of occurrences of each value in the flattened input tensor.

fn unique_first_indices #

fn unique_first_indices[T](t &Tensor[T]) !&Tensor[int]

unique_first_indices returns the first flattened input index for each sorted unique value.

fn unique_inverse #

fn unique_inverse[T](t &Tensor[T]) !&Tensor[int]

unique_inverse returns the unique-value index for each flattened input element. Apply it to unique(t) to reconstruct the input values.

fn unravel_index #

@[direct_array_access]
fn unravel_index(indices &Tensor[int], dimensions []int, options UnravelIndexOptions) ![]&Tensor[int]

unravel_index converts flat indices into one coordinate tensor per axis. Each returned tensor has the same shape as indices. Order selects C (row-major) or F (column-major) decoding.

fn vander #

@[direct_array_access]
fn vander[T](input &Tensor[T], params VandermondeData) !&Tensor[T]

vander returns a Vandermonde matrix built from a one-dimensional input. The default column count is input.size; powers descend by default and increase when requested, matching NumPy's vander convention. T must be a numeric element type.

fn vstack #

fn vstack[T](ts []&Tensor[T]) !&Tensor[T]

vstack stack arrays in sequence vertically (row wise)

fn wald #

fn wald(mean f64, scale f64, shape []int, params TensorData) !&Tensor[f64]

wald returns samples from a Wald (inverse Gaussian) distribution using VTL's global stream.

fn weibull #

fn weibull(shape_parameter f64, shape []int, params TensorData) !&Tensor[f64]

weibull returns samples from the unit-scale Weibull distribution using VTL's global random stream.

fn where #

fn where[T](condition &Tensor[bool], x &Tensor[T], y &Tensor[T]) !&Tensor[T]

where selects elements from x or y according to condition, broadcasting all three tensors to their common shape. True condition elements select x.

fn zeros #

@[inline]
fn zeros[T](shape []int, params TensorData) &Tensor[T]

zeros exposes this operation as part of the public API.

fn zeros_like #

@[inline]
fn zeros_like[T](t &Tensor[T]) &Tensor[T]

zeros_like exposes this operation as part of the public API.

interface AnyTensor #

interface AnyTensor[T] {
	shape   []int
	strides []int
	cpu() &Tensor[T]
	vcl() !&Tensor[T]
	str() string
	rank() int
	size() int
	is_matrix() bool
	is_square_matrix() bool
	is_vector() bool
	is_row_major() bool
	is_col_major() bool
	is_row_major_contiguous() bool
	is_col_major_contiguous() bool
	is_contiguous() bool
mut:
	memory MemoryFormat
}

AnyTensor is an interface that allows for any tensor to be used in the vtl library

fn (MaskedArray[T]) filled #

fn (array &MaskedArray[T]) filled[T](fill_value T) &Tensor[T]

filled returns a row-major copy with masked entries replaced by fill_value.

fn (MaskedArray[T]) compressed #

fn (array &MaskedArray[T]) compressed[T]() !&Tensor[T]

compressed returns all unmasked values as a one-dimensional copy in row-major logical order.

fn (MaskedArray[T]) mixed_index #

fn (array &MaskedArray[T]) mixed_index[T](indices []TensorIndex) !MaskedArray[T]

mixed_index applies NumPy-style mixed basic and advanced indexing to both values and mask, preserving their alignment and view/copy behavior.

fn (MaskedArray[T]) take_along_axis #

fn (array &MaskedArray[T]) take_along_axis[T](indices &Tensor[int], axis int) !MaskedArray[T]

take_along_axis gathers matching values and mask entries using the same broadcastable index tensor.

fn (MaskedArray[T]) put_along_axis #

fn (array &MaskedArray[T]) put_along_axis[T](indices &Tensor[int], updates &MaskedArray[T], axis int) !MaskedArray[T]

put_along_axis returns a copy with masked-array updates written along axis. Update values and masks must match the index shape and are broadcast under the same shape rules as Tensor.put_along_axis.

fn (MaskedArray[T]) count #

fn (array &MaskedArray[T]) count[T]() int

count returns the number of unmasked values.

fn (MaskedArray[T]) cumsum #

fn (array &MaskedArray[T]) cumsum[T]() !MaskedArray[T]

cumsum returns the flattened cumulative sum of valid values. Masked entries stay masked in the result and do not change the running total.

fn (MaskedArray[T]) cumsum_along_axis #

fn (array &MaskedArray[T]) cumsum_along_axis[T](axis int) !MaskedArray[T]

cumsum_along_axis returns prefix sums along one axis. Masked entries remain masked and are skipped by the running total.

fn (MaskedArray[T]) cumsum_as #

fn (array &MaskedArray[T]) cumsum_as[U]() !MaskedArray[U]

cumsum_as returns the flattened cumulative sum using an explicit output accumulator type. Masked positions remain masked and are skipped.

fn (MaskedArray[T]) cumsum_along_axis_as #

fn (array &MaskedArray[T]) cumsum_along_axis_as[U](axis int) !MaskedArray[U]

cumsum_along_axis_as returns cumulative sums along one axis using an explicit output accumulator type.

fn (MaskedArray[T]) cumprod #

fn (array &MaskedArray[T]) cumprod[T]() !MaskedArray[T]

cumprod returns the flattened cumulative product of valid values. Masked entries stay masked in the result and do not change the running product.

fn (MaskedArray[T]) cumprod_along_axis #

fn (array &MaskedArray[T]) cumprod_along_axis[T](axis int) !MaskedArray[T]

cumprod_along_axis returns prefix products along one axis. Masked entries remain masked and are skipped by the running product.

fn (MaskedArray[T]) cumprod_as #

fn (array &MaskedArray[T]) cumprod_as[U]() !MaskedArray[U]

cumprod_as returns the flattened cumulative product using an explicit output accumulator type. Masked positions remain masked and are skipped.

fn (MaskedArray[T]) cumprod_along_axis_as #

fn (array &MaskedArray[T]) cumprod_along_axis_as[U](axis int) !MaskedArray[U]

cumprod_along_axis_as returns cumulative products along one axis using an explicit output accumulator type.

fn (MaskedArray[T]) add #

fn (array &MaskedArray[T]) add[T](other &MaskedArray[T]) !MaskedArray[T]

add adds two masked arrays with broadcasting and combines their masks.

fn (MaskedArray[T]) subtract #

fn (array &MaskedArray[T]) subtract[T](other &MaskedArray[T]) !MaskedArray[T]

subtract subtracts another masked array with broadcasting.

fn (MaskedArray[T]) multiply #

fn (array &MaskedArray[T]) multiply[T](other &MaskedArray[T]) !MaskedArray[T]

multiply multiplies two masked arrays with broadcasting.

fn (MaskedArray[T]) divide #

fn (array &MaskedArray[T]) divide[T](other &MaskedArray[T]) !MaskedArray[T]

divide divides by another masked array with broadcasting.

fn (MaskedArray[T]) equal #

fn (array &MaskedArray[T]) equal[T](other &MaskedArray[T]) !MaskedArray[bool]

equal performs a broadcasted equality comparison and masks invalid pairs.

fn (MaskedArray[T]) not_equal #

fn (array &MaskedArray[T]) not_equal[T](other &MaskedArray[T]) !MaskedArray[bool]

not_equal performs a broadcasted inequality comparison and masks invalid pairs.

fn (MaskedArray[T]) less_than #

fn (array &MaskedArray[T]) less_than[T](other &MaskedArray[T]) !MaskedArray[bool]

less_than compares values with < and masks invalid pairs.

fn (MaskedArray[T]) less_equal #

fn (array &MaskedArray[T]) less_equal[T](other &MaskedArray[T]) !MaskedArray[bool]

less_equal compares values with <= and masks invalid pairs.

fn (MaskedArray[T]) greater_than #

fn (array &MaskedArray[T]) greater_than[T](other &MaskedArray[T]) !MaskedArray[bool]

greater_than compares values with > and masks invalid pairs.

fn (MaskedArray[T]) greater_equal #

fn (array &MaskedArray[T]) greater_equal[T](other &MaskedArray[T]) !MaskedArray[bool]

greater_equal compares values with >= and masks invalid pairs.

fn (MaskedArray[T]) add_scalar #

fn (array &MaskedArray[T]) add_scalar[T](scalar T) !MaskedArray[T]

add_scalar adds a valid scalar to every value and preserves the mask.

fn (MaskedArray[T]) subtract_scalar #

fn (array &MaskedArray[T]) subtract_scalar[T](scalar T) !MaskedArray[T]

subtract_scalar subtracts a valid scalar from every value and preserves the mask.

fn (MaskedArray[T]) multiply_scalar #

fn (array &MaskedArray[T]) multiply_scalar[T](scalar T) !MaskedArray[T]

multiply_scalar multiplies every value by a valid scalar and preserves the mask.

fn (MaskedArray[T]) divide_scalar #

fn (array &MaskedArray[T]) divide_scalar[T](scalar T) !MaskedArray[T]

divide_scalar divides every value by a valid scalar and preserves the mask.

fn (MaskedArray[T]) sum #

fn (array &MaskedArray[T]) sum[T]() MaskedValue[T]

sum reduces all unmasked values. An entirely masked array returns a masked additive identity with value zero.

fn (MaskedArray[T]) prod #

fn (array &MaskedArray[T]) prod[T]() MaskedValue[T]

prod reduces all unmasked values. An entirely masked array returns a masked multiplicative identity with value one.

fn (MaskedArray[T]) min #

fn (array &MaskedArray[T]) min[T]() MaskedValue[T]

min returns the smallest unmasked value. An entirely masked array returns a masked result whose value is zero and must be ignored.

fn (MaskedArray[T]) max #

fn (array &MaskedArray[T]) max[T]() MaskedValue[T]

max returns the largest unmasked value. An entirely masked array returns a masked result whose value is zero and must be ignored.

fn (MaskedArray[T]) argmin #

fn (array &MaskedArray[T]) argmin[T]() MaskedValue[int]

argmin returns the flat logical index of the first smallest unmasked value. An entirely masked array returns a masked result with index zero.

fn (MaskedArray[T]) argmax #

fn (array &MaskedArray[T]) argmax[T]() MaskedValue[int]

argmax returns the flat logical index of the first largest unmasked value. An entirely masked array returns a masked result with index zero.

fn (MaskedArray[T]) argmin_along_axis #

fn (array &MaskedArray[T]) argmin_along_axis[T](axis int, keepdims bool) !MaskedArray[int]

argmin_along_axis returns the first minimum index in each axis slice. Slices with no unmasked values are marked in the output mask.

fn (MaskedArray[T]) argmax_along_axis #

fn (array &MaskedArray[T]) argmax_along_axis[T](axis int, keepdims bool) !MaskedArray[int]

argmax_along_axis returns the first maximum index in each axis slice. Slices with no unmasked values are marked in the output mask.

fn (MaskedArray[T]) mean #

fn (array &MaskedArray[T]) mean[T]() MaskedValue[f64]

mean reduces all unmasked values. An entirely masked array returns a masked NaN result.

fn (MaskedArray[T]) variance #

fn (array &MaskedArray[T]) variance[T](ddof int) !MaskedValue[f64]

variance computes population or sample variance over unmasked values. ddof is subtracted from the valid count; insufficient data returns a masked NaN.

fn (MaskedArray[T]) std #

fn (array &MaskedArray[T]) std[T](ddof int) !MaskedValue[f64]

std computes population or sample standard deviation over unmasked values.

fn (MaskedArray[T]) quantile #

fn (array &MaskedArray[T]) quantile[T](q f64) !MaskedValue[f64]

quantile computes NumPy's default linearly interpolated quantile over all unmasked values. An entirely masked or empty array returns a masked NaN.

fn (MaskedArray[T]) quantile_with_method #

fn (array &MaskedArray[T]) quantile_with_method[T](q f64, method QuantileMethod) !MaskedValue[f64]

quantile_with_method computes a selected NumPy-compatible quantile over all unmasked values. An entirely masked or empty array returns a masked NaN.

fn (MaskedArray[T]) median #

fn (array &MaskedArray[T]) median[T]() MaskedValue[f64]

median computes the median of all unmasked values.

fn (MaskedArray[T]) percentile #

fn (array &MaskedArray[T]) percentile[T](percentile f64) !MaskedValue[f64]

percentile computes a linearly interpolated percentile over unmasked values.

fn (MaskedArray[T]) percentile_with_method #

fn (array &MaskedArray[T]) percentile_with_method[T](percentile f64, method QuantileMethod) !MaskedValue[f64]

percentile_with_method computes a selected percentile over unmasked values.

fn (MaskedArray[T]) quantile_along_axis #

fn (array &MaskedArray[T]) quantile_along_axis[T](axis int, q f64, keepdims bool) !MaskedArray[f64]

quantile_along_axis computes one quantile per slice, optionally retaining the reduced axis with length one.

fn (MaskedArray[T]) quantile_along_axis_with_method #

fn (array &MaskedArray[T]) quantile_along_axis_with_method[T](axis int, q f64, method QuantileMethod, keepdims bool) !MaskedArray[f64]

quantile_along_axis_with_method computes one selected quantile per slice.

fn (MaskedArray[T]) percentile_along_axis #

fn (array &MaskedArray[T]) percentile_along_axis[T](axis int, percentile f64, keepdims bool) !MaskedArray[f64]

percentile_along_axis computes one percentile per axis slice.

fn (MaskedArray[T]) percentile_along_axis_with_method #

fn (array &MaskedArray[T]) percentile_along_axis_with_method[T](axis int, percentile f64, method QuantileMethod, keepdims bool) !MaskedArray[f64]

percentile_along_axis_with_method computes a selected percentile per slice.

fn (MaskedArray[T]) quantile_along_axes #

fn (array &MaskedArray[T]) quantile_along_axes[T](axes []int, q f64, keepdims bool) !MaskedArray[f64]

quantile_along_axes computes one quantile per slice over several axes. Slices with no valid values have a NaN payload and a true output mask.

fn (MaskedArray[T]) quantile_along_axes_with_method #

fn (array &MaskedArray[T]) quantile_along_axes_with_method[T](axes []int, q f64, method QuantileMethod, keepdims bool) !MaskedArray[f64]

quantile_along_axes_with_method reduces multiple axes with a selected estimator. Slices with no valid values have a NaN payload and true mask.

fn (MaskedArray[T]) percentile_along_axes #

fn (array &MaskedArray[T]) percentile_along_axes[T](axes []int, percentile f64, keepdims bool) !MaskedArray[f64]

percentile_along_axes computes one percentile per slice over several axes.

fn (MaskedArray[T]) percentile_along_axes_with_method #

fn (array &MaskedArray[T]) percentile_along_axes_with_method[T](axes []int, percentile f64, method QuantileMethod, keepdims bool) !MaskedArray[f64]

percentile_along_axes_with_method reduces several axes with a selected estimator on the 0..100 percentile scale.

fn (MaskedArray[T]) median_along_axis #

fn (array &MaskedArray[T]) median_along_axis[T](axis int, keepdims bool) !MaskedArray[f64]

median_along_axis computes the median of each unmasked axis slice.

fn (MaskedArray[T]) median_along_axes #

fn (array &MaskedArray[T]) median_along_axes[T](axes []int, keepdims bool) !MaskedArray[f64]

median_along_axes computes medians over several axes.

fn (MaskedArray[T]) sum_along_axis #

fn (array &MaskedArray[T]) sum_along_axis[T](axis int, keepdims bool) !MaskedArray[T]

sum_along_axis reduces unmasked values along one axis. Output mask entries are true for slices containing no unmasked values.

fn (MaskedArray[T]) sum_along_axes #

fn (array &MaskedArray[T]) sum_along_axes[T](axes []int, keepdims bool) !MaskedArray[T]

sum_along_axes reduces unmasked values over several axes. Negative axes are supported; duplicate axes are rejected. An empty axes list preserves data.

fn (MaskedArray[T]) prod_along_axis #

fn (array &MaskedArray[T]) prod_along_axis[T](axis int, keepdims bool) !MaskedArray[T]

prod_along_axis multiplies unmasked values along one axis.

fn (MaskedArray[T]) prod_along_axes #

fn (array &MaskedArray[T]) prod_along_axes[T](axes []int, keepdims bool) !MaskedArray[T]

prod_along_axes multiplies unmasked values over several axes. Negative axes are supported; duplicate axes are rejected. An empty axes list preserves data.

fn (MaskedArray[T]) min_along_axis #

fn (array &MaskedArray[T]) min_along_axis[T](axis int, keepdims bool) !MaskedArray[T]

min_along_axis finds the smallest unmasked value in each axis slice.

fn (MaskedArray[T]) min_along_axes #

fn (array &MaskedArray[T]) min_along_axes[T](axes []int, keepdims bool) !MaskedArray[T]

min_along_axes finds minima across several axes. Empty slices are masked.

fn (MaskedArray[T]) max_along_axis #

fn (array &MaskedArray[T]) max_along_axis[T](axis int, keepdims bool) !MaskedArray[T]

max_along_axis finds the largest unmasked value in each axis slice.

fn (MaskedArray[T]) max_along_axes #

fn (array &MaskedArray[T]) max_along_axes[T](axes []int, keepdims bool) !MaskedArray[T]

max_along_axes finds maxima across several axes. Empty slices are masked.

fn (MaskedArray[T]) variance_along_axis #

fn (array &MaskedArray[T]) variance_along_axis[T](axis int, ddof int, keepdims bool) !MaskedArray[f64]

variance_along_axis computes variance along one axis, marking slices with insufficient valid values as masked NaN results.

fn (MaskedArray[T]) variance_along_axes #

fn (array &MaskedArray[T]) variance_along_axes[T](axes []int, ddof int, keepdims bool) !MaskedArray[f64]

variance_along_axes computes population or sample variance over several axes. Empty axes compute elementwise zero variance for valid values.

fn (MaskedArray[T]) std_along_axis #

fn (array &MaskedArray[T]) std_along_axis[T](axis int, ddof int, keepdims bool) !MaskedArray[f64]

std_along_axis computes standard deviation along one axis.

fn (MaskedArray[T]) std_along_axes #

fn (array &MaskedArray[T]) std_along_axes[T](axes []int, ddof int, keepdims bool) !MaskedArray[f64]

std_along_axes computes standard deviation over several axes.

fn (MaskedArray[T]) mean_along_axis #

fn (array &MaskedArray[T]) mean_along_axis[T](axis int, keepdims bool) !MaskedArray[f64]

mean_along_axis computes the mean of unmasked values per axis slice. Slices with no unmasked values carry a masked NaN result.

fn (MaskedArray[T]) mean_along_axes #

fn (array &MaskedArray[T]) mean_along_axes[T](axes []int, keepdims bool) !MaskedArray[f64]

mean_along_axes computes means over several axes. Negative axes are supported; duplicate axes are rejected. An empty axes list converts each unmasked value to f64 and preserves the mask.

fn (MaskedArray[T]) weighted_average #

fn (array &MaskedArray[T]) weighted_average[T, W](weights &Tensor[W]) !MaskedValue[f64]

weighted_average computes a weighted mean over valid values. Weights must broadcast to the values shape; masked observations do not contribute either their value or their weight. An entirely masked array returns masked NaN.

fn (MaskedArray[T]) weighted_average_along_axis #

fn (array &MaskedArray[T]) weighted_average_along_axis[T, W](weights &Tensor[W], axis int, keepdims bool) !MaskedArray[f64]

weighted_average_along_axis computes weighted means per slice. Weights may broadcast to the values shape or be a vector matching the selected axis.

fn (MaskedArray[T]) weighted_average_along_axes #

fn (array &MaskedArray[T]) weighted_average_along_axes[T, W](weights &Tensor[W], axes []int, keepdims bool) !MaskedArray[f64]

weighted_average_along_axes reduces several dimensions. Weights must broadcast to the values shape; empty slices are masked and zero-sum valid weights return an error.

fn (TensorAxisIterator[T]) next #

@[inline]
fn (mut s TensorAxisIterator[T]) next[T]() ?(T, []int)

next exposes this operation as part of the public API.

type TensorDataType #

type TensorDataType = bool
	| f32
	| f64
	| i16
	| i32
	| i64
	| i8
	| int
	| string
	| u16
	| u32
	| u64
	| u8

TensorDataType is a sum type that lists the possible types to be used to define storage

fn (TensorDataType) string #

fn (v TensorDataType) string() string

string returns TensorDataType as a string.

fn (TensorDataType) int #

fn (v TensorDataType) int() int

int converts a numeric TensorDataType value to int.

fn (TensorDataType) i64 #

fn (v TensorDataType) i64() i64

i64 converts a numeric TensorDataType value to i64.

fn (TensorDataType) i32 #

fn (v TensorDataType) i32() i32

i32 converts a numeric TensorDataType value to i32.

fn (TensorDataType) i8 #

fn (v TensorDataType) i8() i8

i8 converts a numeric TensorDataType value to i8.

fn (TensorDataType) i16 #

fn (v TensorDataType) i16() i16

i16 converts a numeric TensorDataType value to i16.

fn (TensorDataType) u8 #

fn (v TensorDataType) u8() u8

u8 converts a numeric TensorDataType value to u8.

fn (TensorDataType) u16 #

fn (v TensorDataType) u16() u16

u16 converts a numeric TensorDataType value to u16.

fn (TensorDataType) u32 #

fn (v TensorDataType) u32() u32

u32 converts a numeric TensorDataType value to u32.

fn (TensorDataType) u64 #

fn (v TensorDataType) u64() u64

u64 converts a numeric TensorDataType value to u64.

fn (TensorDataType) f32 #

fn (v TensorDataType) f32() f32

f32 converts a numeric TensorDataType value to f32.

fn (TensorDataType) f64 #

fn (v TensorDataType) f64() f64

f64 converts a numeric TensorDataType value to f64.

fn (TensorDataType) bool #

fn (v TensorDataType) bool() bool

bool uses TensorDataType as a bool

fn (TensorIterator[T]) next #

@[inline]
fn (mut s TensorIterator[T]) next[T]() ?(T, []int)

next exposes this operation as part of the public API.

fn (Tensor[T]) cpu #

@[inline]
fn (t &Tensor[T]) cpu() !&Tensor[T]

cpu exposes this operation as part of the public API.

fn (Tensor[T]) str #

@[inline]
fn (t &Tensor[T]) str() string

str exposes this operation as part of the public API.

fn (Tensor[T]) rank #

fn (t &Tensor[T]) rank() int

rank returns the number of dimensions of a given Tensor

fn (Tensor[T]) size #

fn (t &Tensor[T]) size() int

size returns the number of allocated elements for a given tensor

fn (Tensor[T]) is_matrix #

@[inline]
fn (t &Tensor[T]) is_matrix() bool

is_matrix exposes this operation as part of the public API.

fn (Tensor[T]) is_square_matrix #

@[inline]
fn (t &Tensor[T]) is_square_matrix() bool

is_square_matrix exposes this operation as part of the public API.

fn (Tensor[T]) is_vector #

@[inline]
fn (t &Tensor[T]) is_vector() bool

is_vector exposes this operation as part of the public API.

fn (Tensor[T]) is_row_major #

@[inline]
fn (t &Tensor[T]) is_row_major() bool

is_row_major exposes this operation as part of the public API.

fn (Tensor[T]) is_col_major #

@[inline]
fn (t &Tensor[T]) is_col_major() bool

is_col_major exposes this operation as part of the public API.

fn (Tensor[T]) is_row_major_contiguous #

@[inline]
fn (t &Tensor[T]) is_row_major_contiguous() bool

is_row_major_contiguous exposes this operation as part of the public API.

fn (Tensor[T]) is_col_major_contiguous #

@[inline]
fn (t &Tensor[T]) is_col_major_contiguous() bool

is_col_major_contiguous exposes this operation as part of the public API.

fn (Tensor[T]) is_contiguous #

@[inline]
fn (t &Tensor[T]) is_contiguous() bool

is_contiguous exposes this operation as part of the public API.

fn (Tensor[T]) to_array #

fn (t &Tensor[T]) to_array() []T

to_array returns the flatten representation of a tensor in a v array storing elements of type T

fn (Tensor[T]) copy #

@[inline]
fn (t &Tensor[T]) copy(memory MemoryFormat) &Tensor[T]

copy exposes this operation as part of the public API.

fn (Tensor[T]) view #

@[inline]
fn (t &Tensor[T]) view() &Tensor[T]

view exposes this operation as part of the public API.

fn (Tensor[T]) set #

@[inline]
fn (mut t Tensor[T]) set[T](index []int, val T)

set exposes this operation as part of the public API.

fn (Tensor[T]) set_nth #

@[inline]
fn (mut t Tensor[T]) set_nth[T](n int, val T)

set_nth exposes this operation as part of the public API.

fn (Tensor[T]) fill #

@[inline]
fn (mut t Tensor[T]) fill[T](val T) &Tensor[T]

fill exposes this operation as part of the public API.

fn (Tensor[T]) assign #

fn (mut t Tensor[T]) assign[T](other &Tensor[T]) !&Tensor[T]

assign sets the values of an Tensor equal to the values of another Tensor of the same shape

fn (Tensor[T]) put #

fn (mut t Tensor[T]) put[T](indices &Tensor[int], values &Tensor[T]) !

put replaces values at row-major logical flat indices. Values repeat when there are fewer values than indices. Negative indices count from the end. Invalid indices return an error without changing the tensor.

fn (Tensor[T]) putmask #

@[direct_array_access]
fn (mut t Tensor[T]) putmask[T](mask &Tensor[bool], values &Tensor[T]) !

putmask replaces values where mask is true, in row-major logical order. Update values repeat cyclically by row-major flat position, matching NumPy's putmask semantics. The mask must match the tensor shape exactly.

fn (Tensor[T]) put_with_mode #

fn (mut t Tensor[T]) put_with_mode[T](indices &Tensor[int], values &Tensor[T], mode PutMode) !

put_with_mode replaces values at row-major logical flat indices, using mode to handle indices outside the flattened tensor's range. Repeated indices follow row-major write order, so the last value wins. All indices are validated before any writes are made.

fn (Tensor[T]) put_along_axis #

fn (mut t Tensor[T]) put_along_axis[T](indices &Tensor[int], values &Tensor[T], axis int) !

put_along_axis writes values at indices along axis. Indices and values must have the same rank as the target and values must match the index shape. The index dimensions outside axis may be smaller than the target dimensions. Negative indices count from the end. When an index is repeated, the last value in row-major iteration order wins.

fn (Tensor[T]) scatter_add #

fn (mut t Tensor[T]) scatter_add[T](indices &Tensor[int], values &Tensor[T], axis int) !

scatter_add adds values at indices along axis. Duplicate indices accumulate in row-major iteration order; negative indices count from the end.

fn (Tensor[T]) bitwise_and #

fn (a &Tensor[T]) bitwise_and[T](b &Tensor[T]) !&Tensor[T]

bitwise_and computes the elementwise bitwise AND with tensor broadcasting.

fn (Tensor[T]) bitwise_or #

fn (a &Tensor[T]) bitwise_or[T](b &Tensor[T]) !&Tensor[T]

bitwise_or computes the elementwise bitwise OR with tensor broadcasting.

fn (Tensor[T]) bitwise_xor #

fn (a &Tensor[T]) bitwise_xor[T](b &Tensor[T]) !&Tensor[T]

bitwise_xor computes the elementwise bitwise XOR with tensor broadcasting.

fn (Tensor[T]) bitwise_invert #

fn (t &Tensor[T]) bitwise_invert[T]() &Tensor[T]

bitwise_invert computes the elementwise one's complement.

fn (Tensor[T]) left_shift #

fn (t &Tensor[T]) left_shift[T](shift int) !&Tensor[T]

left_shift shifts every integer value left by a scalar number of bits.

fn (Tensor[T]) right_shift #

fn (t &Tensor[T]) right_shift[T](shift int) !&Tensor[T]

right_shift shifts every integer value right by a scalar number of bits.

fn (Tensor[T]) broadcastable #

fn (a &Tensor[T]) broadcastable[T](b &Tensor[T]) ![]int

broadcastable takes two Tensors and either returns a valid broadcastable shape or an error

fn (Tensor[T]) broadcast_to #

fn (t &Tensor[T]) broadcast_to[T](shape []int) !&Tensor[T]

broadcast_to broadcasts a Tensor to a compatible shape with no data copy

fn (Tensor[T]) as_bool #

@[inline]
fn (t &Tensor[T]) as_bool[T]() &Tensor[bool]

as_bool exposes this operation as part of the public API.

fn (Tensor[T]) as_f32 #

@[inline]
fn (t &Tensor[T]) as_f32[T]() &Tensor[f32]

as_f32 exposes this operation as part of the public API.

fn (Tensor[T]) as_f64 #

@[inline]
fn (t &Tensor[T]) as_f64[T]() &Tensor[f64]

as_f64 exposes this operation as part of the public API.

fn (Tensor[T]) as_i64 #

fn (t &Tensor[T]) as_i64[T]() &Tensor[i64]

as_i64 casts each tensor value to i64 while preserving its logical shape.

fn (Tensor[T]) as_i32 #

fn (t &Tensor[T]) as_i32[T]() &Tensor[i32]

as_i32 casts each tensor value to i32 while preserving its logical shape.

fn (Tensor[T]) as_i16 #

@[inline]
fn (t &Tensor[T]) as_i16[T]() &Tensor[i16]

as_i16 exposes this operation as part of the public API.

fn (Tensor[T]) as_i8 #

@[inline]
fn (t &Tensor[T]) as_i8[T]() &Tensor[i8]

as_i8 exposes this operation as part of the public API.

fn (Tensor[T]) as_int #

@[inline]
fn (t &Tensor[T]) as_int[T]() &Tensor[int]

as_int exposes this operation as part of the public API.

fn (Tensor[T]) as_string #

@[inline]
fn (t &Tensor[T]) as_string[T]() &Tensor[string]

as_string exposes this operation as part of the public API.

fn (Tensor[T]) as_u8 #

@[inline]
fn (t &Tensor[T]) as_u8[T]() &Tensor[u8]

as_u8 exposes this operation as part of the public API.

fn (Tensor[T]) as_u16 #

fn (t &Tensor[T]) as_u16[T]() &Tensor[u16]

as_u16 casts each tensor value to u16 while preserving its logical shape.

fn (Tensor[T]) as_u32 #

fn (t &Tensor[T]) as_u32[T]() &Tensor[u32]

as_u32 casts each tensor value to u32 while preserving its logical shape.

fn (Tensor[T]) as_u64 #

fn (t &Tensor[T]) as_u64[T]() &Tensor[u64]

as_u64 casts each tensor value to u64 while preserving its logical shape.

fn (Tensor[T]) dtype #

fn (t &Tensor[T]) dtype[T]() DType

dtype returns the element dtype of the receiver tensor.

fn (Tensor[T]) apply #

fn (mut t Tensor[T]) apply[T](f fn (x T, i []int) T)

apply applies a function to each element of a given Tensor

fn (Tensor[T]) map #

fn (t &Tensor[T]) map[T](f fn (x T, i []int) T) &Tensor[T]

map maps a function to a given Tensor retuning a new Tensor with same shape

fn (Tensor[T]) map_values #

@[direct_array_access]
fn (t &Tensor[T]) map_values[T](f fn (x T) T) &Tensor[T]

map_values applies a value-only function to each element, without passing its multidimensional index. It uses direct linear access for contiguous row-major storage and falls back to map for views and non-contiguous tensors.

fn (Tensor[T]) map_pair_values #

@[direct_array_access]
fn (a &Tensor[T]) map_pair_values[T](b &Tensor[T], f fn (x T, y T) T) !&Tensor[T]

map_pair_values applies a value-only binary function with standard tensor broadcasting. Equal-shaped contiguous row-major tensors use direct linear access; broadcasting and non-contiguous inputs use nmap.

fn (Tensor[T]) reduce #

fn (t &Tensor[T]) reduce[T](init T, f fn (acc T, x T, i []int) T) T

reduce reduces a function to a given Tensor retuning a new aggregated value

fn (Tensor[T]) napply #

fn (mut t Tensor[T]) napply[T](ts []&Tensor[T], f fn (xs []T, i []int) T) !

napply applies a function to each element of a given Tensor with params

fn (Tensor[T]) nmap #

fn (t &Tensor[T]) nmap[T](ts []&Tensor[T], f fn (xs []T, i []int) T) !&Tensor[T]

nmap maps a function to a given list of Tensor retuning a new Tensor with same shape

fn (Tensor[T]) nreduce #

fn (t &Tensor[T]) nreduce[T](ts []&Tensor[T], init T, f fn (acc T, xs []T, i []int) T) !T

nreduce reduces a function to a given list of Tensor retuning a new aggregated value

fn (Tensor[T]) with_dims #

fn (t &Tensor[T]) with_dims[T](n int) !&Tensor[T]

with_dims returns a new Tensor adding dimensions so that it has at least n dimensions

fn (Tensor[T]) with_broadcast #

fn (t &Tensor[T]) with_broadcast[T](n int) !&Tensor[T]

with_broadcast expands a Tensors dimensions n times by broadcasting the shape and strides

fn (Tensor[T]) diagonal #

fn (t &Tensor[T]) diagonal[T]() &Tensor[T]

diagonal returns a view of the diagonal entries of a two dimensional tensor

fn (Tensor[T]) ravel #

@[inline]
fn (t &Tensor[T]) ravel[T]() !&Tensor[T]

ravel returns a one-dimensional tensor in row-major logical order. It shares storage for row-major contiguous tensors and copies non-contiguous tensors.

fn (Tensor[T]) flatten #

fn (t &Tensor[T]) flatten[T]() !&Tensor[T]

flatten returns a one-dimensional copy of a tensor in row-major logical order, even when the input is already contiguous.

fn (Tensor[T]) reshape #

fn (t &Tensor[T]) reshape[T](shape []int) !&Tensor[T]

reshape returns a Tensor with a new shape in row-major logical order. Row-major contiguous tensors share storage; other layouts are copied.

fn (Tensor[T]) as_strided #

fn (t &Tensor[T]) as_strided[T](shape []int, strides []int) !&Tensor[T]

as_strided returns a view of the Tensor with new shape and strides

fn (Tensor[T]) transpose #

@[direct_array_access]
fn (t &Tensor[T]) transpose[T](order []int) !&Tensor[T]

transpose exposes this operation as part of the public API.

fn (Tensor[T]) t #

fn (t &Tensor[T]) t[T]() !&Tensor[T]

t returns a full transpose of a tensor, with the axes reversed

fn (Tensor[T]) swapaxes #

fn (t &Tensor[T]) swapaxes[T](a1 int, a2 int) !&Tensor[T]

swapaxes returns a view of an tensor with two axes swapped

fn (Tensor[T]) moveaxis #

fn (t &Tensor[T]) moveaxis[T](source []int, destination []int) !&Tensor[T]

moveaxis returns a view with the axes in source moved to destination. Axis positions may be negative, and the remaining axes keep their order.

fn (Tensor[T]) rollaxis #

fn (t &Tensor[T]) rollaxis[T](axis int, start int) !&Tensor[T]

rollaxis moves axis backwards until it lies before start and returns a view. Negative axis positions are counted from the end of the tensor.

fn (Tensor[T]) slice #

@[direct_array_access]
fn (t &Tensor[T]) slice[T](idx ...[]int) !&Tensor[T]

slice exposes this operation as part of the public API.

fn (Tensor[T]) slice_hilo #

@[direct_array_access]
fn (t &Tensor[T]) slice_hilo[T](idx1 []int, idx2 []int) !&Tensor[T]

slice_hilo exposes this operation as part of the public API.

fn (Tensor[T]) all #

@[direct_array_access]
fn (t &Tensor[T]) all[T]() bool

all returns whether all array elements evaluate to true.

fn (Tensor[T]) any #

@[direct_array_access]
fn (t &Tensor[T]) any[T]() bool

any returns whether any array elements evaluate to true.

fn (Tensor[T]) logical_and #

fn (a &Tensor[T]) logical_and[T](b &Tensor[T]) !&Tensor[bool]

logical_and evaluates element truth values with standard tensor broadcasting.

fn (Tensor[T]) logical_or #

fn (a &Tensor[T]) logical_or[T](b &Tensor[T]) !&Tensor[bool]

logical_or evaluates element truth values with standard tensor broadcasting.

fn (Tensor[T]) logical_xor #

fn (a &Tensor[T]) logical_xor[T](b &Tensor[T]) !&Tensor[bool]

logical_xor evaluates element truth values with standard tensor broadcasting.

fn (Tensor[T]) logical_not #

fn (t &Tensor[T]) logical_not[T]() &Tensor[bool]

logical_not negates the truth value of each tensor element.

fn (Tensor[T]) all_axis #

fn (t &Tensor[T]) all_axis[T](axis int, keepdims bool) !&Tensor[bool]

all_axis reduces one axis with logical AND. The reduced dimension is removed unless keepdims is true. Empty reductions follow NumPy's identity: true.

fn (Tensor[T]) any_axis #

fn (t &Tensor[T]) any_axis[T](axis int, keepdims bool) !&Tensor[bool]

any_axis reduces one axis with logical OR. The reduced dimension is removed unless keepdims is true. Empty reductions follow NumPy's identity: false.

fn (Tensor[T]) all_axes #

fn (t &Tensor[T]) all_axes[T](axes []int, keepdims bool) !&Tensor[bool]

all_axes reduces multiple axes with logical AND. Axes may be negative and must be unique. An empty axes list converts values to bool without reducing.

fn (Tensor[T]) any_axes #

fn (t &Tensor[T]) any_axes[T](axes []int, keepdims bool) !&Tensor[bool]

any_axes reduces multiple axes with logical OR. Axes may be negative and must be unique. An empty axes list converts values to bool without reducing.

fn (Tensor[T]) is_finite #

fn (t &Tensor[T]) is_finite[T]() &Tensor[bool]

is_finite returns true where x is not positive infinity, negative infinity, or NaN; false otherwise.

fn (Tensor[T]) is_inf #

fn (t &Tensor[T]) is_inf[T](sign int) &Tensor[bool]

is_inf reports whether t is an infinity, according to sign. If sign > 0, is_inf reports whether t is positive infinity. If sign < 0, is_inf reports whether t is negative infinity. If sign == 0, is_inf reports whether t is either infinity.

fn (Tensor[T]) is_nan #

fn (t &Tensor[T]) is_nan[T]() &Tensor[bool]

is_nan returns true for NaN values and false for finite values and infinities.

fn (Tensor[T]) array_equal #

fn (t &Tensor[T]) array_equal[T](other &Tensor[T]) bool

array_equal returns true if input arrays have the same shape and all elements compare exactly equal. Floating-point NaNs compare unequal; use isclose for approximate comparisons.

fn (Tensor[T]) array_equiv #

fn (t &Tensor[T]) array_equiv[T](other &Tensor[T]) bool

array_equiv returns true if input arrays are shape consistent and all elements equal. Shape consistent means they are either the same shape, or one input array can be broadcasted to create the same shape as the other one.

fn (Tensor[T]) equal #

@[direct_array_access]
fn (t &Tensor[T]) equal[T](other &Tensor[T]) !&Tensor[bool]

equal exposes this operation as part of the public API.

fn (Tensor[T]) not_equal #

@[direct_array_access]
fn (t &Tensor[T]) not_equal[T](other &Tensor[T]) !&Tensor[bool]

not_equal exposes this operation as part of the public API.

fn (Tensor[T]) tolerance #

@[inline]
fn (t &Tensor[T]) tolerance[T](other &Tensor[T], tol T) !&Tensor[bool]

fn (Tensor[T]) close #

@[inline]
fn (t &Tensor[T]) close[T](other &Tensor[T]) !&Tensor[bool]

close exposes this operation as part of the public API.

fn (Tensor[T]) veryclose #

@[inline]
fn (t &Tensor[T]) veryclose[T](other &Tensor[T]) !&Tensor[bool]

veryclose exposes this operation as part of the public API.

fn (Tensor[T]) alike #

@[inline]
fn (t &Tensor[T]) alike[T](other &Tensor[T]) !&Tensor[bool]

alike exposes this operation as part of the public API.

fn (Tensor[T]) isclose #

@[direct_array_access]
fn (t &Tensor[T]) isclose[T](other &Tensor[T], params IsCloseData) !&Tensor[bool]

fn (Tensor[T]) allclose #

@[direct_array_access]
fn (t &Tensor[T]) allclose[T](other &Tensor[T], params IsCloseData) !bool

allclose returns true if all broadcasted elements satisfy isclose.

fn (Tensor[T]) iterator #

fn (t &Tensor[T]) iterator[T]() &TensorIterator[T]

iterator creates an iterator through a Tensor

fn (Tensor[T]) custom_iterator #

fn (t &Tensor[T]) custom_iterator[T](data IteratorBuildData[T]) &TensorIterator[T]

iterator creates an iterator through a Tensor with custom data

fn (Tensor[T]) iterators #

fn (t &Tensor[T]) iterators[T](ts []&Tensor[T]) !(&TensorsIterator[T], []int)

iterators creates an array of iterators through a list of tensors

fn (Tensor[T]) axis_iterator #

fn (t &Tensor[T]) axis_iterator[T](axis int) &TensorAxisIterator[T]

axis_iterator returns an iterator over the axis of a Tensor, commonly used for reduction operations along an axis.

fn (Tensor[T]) axis_with_dims_iterator #

fn (t &Tensor[T]) axis_with_dims_iterator[T](axis int) &TensorAxisIterator[T]

axis returns an iterator over the axis of a Tensor, commonly used for reduction operations along an axis. This iterator keeps the axis dimension as size 1 instead of removing it

fn (Tensor[T]) take #

fn (t &Tensor[T]) take[T](indices []int, axis int) !&Tensor[T]

take returns a copy of the tensor with the values at indices selected along axis. Negative axes and negative indices count from the end. The indices are a one-dimensional list; use slice for range-based views.

fn (Tensor[T]) take_with_mode #

fn (t &Tensor[T]) take_with_mode[T](indices []int, axis int, mode TakeMode) !&Tensor[T]

take_with_mode selects values along axis, handling out-of-range indices with the requested mode. In .clip mode, negative values clip to zero, matching NumPy's take behavior.

fn (Tensor[T]) take_nd #

fn (t &Tensor[T]) take_nd[T](indices &Tensor[int], axis int) !&Tensor[T]

take_nd gathers values along one axis using an index tensor. The index tensor's dimensions replace the selected axis in the output shape.

fn (Tensor[T]) take_nd_with_mode #

fn (t &Tensor[T]) take_nd_with_mode[T](indices &Tensor[int], axis int, mode TakeMode) !&Tensor[T]

take_nd_with_mode gathers with an index tensor and applies mode to every index. The index tensor's dimensions replace the selected axis.

fn (Tensor[T]) take_flat #

fn (t &Tensor[T]) take_flat[T](indices &Tensor[int]) !&Tensor[T]

take_flat gathers from the row-major logical flattening of a tensor and preserves the shape of the index tensor.

fn (Tensor[T]) take_flat_with_mode #

fn (t &Tensor[T]) take_flat_with_mode[T](indices &Tensor[int], mode TakeMode) !&Tensor[T]

take_flat_with_mode gathers from row-major logical order and applies mode to indices outside the flattened tensor's range.

fn (Tensor[T]) take_along_axis #

fn (t &Tensor[T]) take_along_axis[T](indices &Tensor[int], axis int) !&Tensor[T]

take_along_axis gathers values using an index tensor with the same rank as the receiver. Non-axis dimensions broadcast; the result's axis length is taken from the index tensor. Negative indices count from the end.

fn (Tensor[T]) get #

@[inline]
fn (t &Tensor[T]) get[T](index []int) T

get exposes this operation as part of the public API.

fn (Tensor[T]) get_nth #

@[inline]
fn (t &Tensor[T]) get_nth[T](n int) T

get_nth exposes this operation as part of the public API.

fn (Tensor[T]) offset_index #

@[inline]
fn (t &Tensor[T]) offset_index[T](index []int) int

offset_index exposes this operation as part of the public API.

fn (Tensor[T]) nth_index #

fn (t &Tensor[T]) nth_index[T](n int) []int

nth_index returns the nth index of a Tensor's shape for n == 2 and a shape of [2, 2] the nth index is [1, 0] and for a shape of [2, 3] and n == 3 the nth index is [0, 1, 1] in sorted order.

fn (Tensor[T]) flip #

fn (t &Tensor[T]) flip[T](axes ...int) !&Tensor[T]

flip returns a copy of t with the selected axes reversed. With no axes, all axes are reversed, matching NumPy's flip default. Negative axes are accepted.

fn (Tensor[T]) masked_select #

fn (t &Tensor[T]) masked_select[T](mask &Tensor[bool]) !&Tensor[T]

masked_select returns the values whose corresponding mask entries are true. The mask must be broadcastable to the tensor shape; values are returned in row-major logical order, including for non-contiguous views.

fn (Tensor[T]) masked_fill #

fn (t &Tensor[T]) masked_fill[T](mask &Tensor[bool], value T) !&Tensor[T]

masked_fill returns a tensor with mask-selected values replaced by value. The mask must be broadcastable to the tensor shape.

fn (Tensor[T]) masked_scatter #

fn (t &Tensor[T]) masked_scatter[T](mask &Tensor[bool], source &Tensor[T]) !&Tensor[T]

masked_scatter copies source values, in row-major order, into the true positions selected by a broadcastable mask. The source must contain at least as many values as the mask selects; extra source values are ignored.

fn (Tensor[T]) diag #

fn (t &Tensor[T]) diag[T]() !&Tensor[T]

diag constructs a diagonal array. input must be one dimensional and will be placed along the resulting diagonal

fn (Tensor[T]) diag_flat #

fn (t &Tensor[T]) diag_flat[T]() !&Tensor[T]

diag_flat constructs a diagonal array. the flattened input is placed along the diagonal of the resulting matrix

fn (Tensor[T]) tril #

fn (t &Tensor[T]) tril[T]() &Tensor[T]

tril computes the lower triangle of an array. returns a copy of an array with elements above the diagonal zeroed

fn (Tensor[T]) tril_offset #

fn (t &Tensor[T]) tril_offset[T](offset int) &Tensor[T]

tril_inplace computes the lower triangle of an array. returns a copy of an array with elements above the kth diagonal zeroed

fn (Tensor[T]) tril_inplace #

fn (mut t Tensor[T]) tril_inplace[T]() &Tensor[T]

tril_inplace computes the lower triangle of an array. modifies an array inplace with elements above the diagonal zeroed.

fn (Tensor[T]) tril_inpl_offset #

fn (mut t Tensor[T]) tril_inpl_offset[T](offset int) &Tensor[T]

tril_inpl_offset computes the lower triangle of an array. modifies an array inplace with elements above the k-th diagonal zeroed.

fn (Tensor[T]) triu #

fn (t &Tensor[T]) triu[T]() &Tensor[T]

triu computes the Upper triangle of an array. returns a copy of an array with elements below the diagonal zeroed

fn (Tensor[T]) triu_offset #

fn (t &Tensor[T]) triu_offset[T](offset int) &Tensor[T]

triu_offset computes the upper triangle of an array. returns a copy of an array with elements below the kth diagonal zeroed

fn (Tensor[T]) triu_inplace #

fn (mut t Tensor[T]) triu_inplace[T]() &Tensor[T]

triu_inplace computes the upper triangle of an array. modifies an array inplace with elements below the diagonal zeroed.

fn (Tensor[T]) nan_to_num #

fn (t &Tensor[T]) nan_to_num[T](params NanToNumConfig) &Tensor[T]

nan_to_num replaces NaN and positive or negative infinity in floating-point tensors. Complex values are handled component-wise; other types are copied.

fn (Tensor[T]) sign #

fn (t &Tensor[T]) sign[T]() &Tensor[T]

sign returns the elementwise sign of each value: -1, 0, or 1. Floating-point NaNs remain NaN, matching NumPy's sign behavior.

fn (Tensor[T]) heaviside #

fn (t &Tensor[T]) heaviside[T](x1 T) &Tensor[T]

heaviside returns 0 for negative values, 1 for positive values, and x1 for zero values. Floating-point NaNs remain NaN.

fn (Tensor[T]) clip #

fn (t &Tensor[T]) clip[T](min_value T, max_value T) !&Tensor[T]

clip limits tensor values to the inclusive scalar interval [min_value, max_value]. The tensor element type is preserved; NaN values remain NaN.

fn (Tensor[T]) abs #

@[inline]
fn (t &Tensor[T]) abs[T]() &Tensor[T]

abs exposes this operation as part of the public API.

fn (Tensor[T]) acos #

@[inline]
fn (t &Tensor[T]) acos[T]() &Tensor[T]

acos exposes this operation as part of the public API.

fn (Tensor[T]) acosh #

@[inline]
fn (t &Tensor[T]) acosh[T]() &Tensor[T]

acosh exposes this operation as part of the public API.

fn (Tensor[T]) asin #

@[inline]
fn (t &Tensor[T]) asin[T]() &Tensor[T]

asin exposes this operation as part of the public API.

fn (Tensor[T]) asinh #

@[inline]
fn (t &Tensor[T]) asinh[T]() &Tensor[T]

asinh exposes this operation as part of the public API.

fn (Tensor[T]) atan #

@[inline]
fn (t &Tensor[T]) atan[T]() &Tensor[T]

atan exposes this operation as part of the public API.

fn (Tensor[T]) atan2 #

@[inline]
fn (a &Tensor[T]) atan2[T](b &Tensor[T]) !&Tensor[T]

atan2 exposes this operation as part of the public API.

fn (Tensor[T]) atanh #

@[inline]
fn (t &Tensor[T]) atanh[T]() &Tensor[T]

atanh exposes this operation as part of the public API.

fn (Tensor[T]) cbrt #

@[inline]
fn (t &Tensor[T]) cbrt[T]() &Tensor[T]

cbrt exposes this operation as part of the public API.

fn (Tensor[T]) ceil #

@[inline]
fn (t &Tensor[T]) ceil[T]() &Tensor[T]

ceil exposes this operation as part of the public API.

fn (Tensor[T]) cos #

@[inline]
fn (t &Tensor[T]) cos[T]() &Tensor[T]

cos exposes this operation as part of the public API.

fn (Tensor[T]) cosh #

@[inline]
fn (t &Tensor[T]) cosh[T]() &Tensor[T]

cosh exposes this operation as part of the public API.

fn (Tensor[T]) cot #

@[inline]
fn (t &Tensor[T]) cot[T]() &Tensor[T]

cot exposes this operation as part of the public API.

fn (Tensor[T]) degrees #

@[inline]
fn (t &Tensor[T]) degrees[T]() &Tensor[T]

degrees exposes this operation as part of the public API.

fn (Tensor[T]) erf #

@[inline]
fn (t &Tensor[T]) erf[T]() &Tensor[T]

erf exposes this operation as part of the public API.

fn (Tensor[T]) erfc #

@[inline]
fn (t &Tensor[T]) erfc[T]() &Tensor[T]

erfc exposes this operation as part of the public API.

fn (Tensor[T]) exp #

@[inline]
fn (t &Tensor[T]) exp[T]() &Tensor[T]

exp exposes this operation as part of the public API.

fn (Tensor[T]) exp2 #

@[inline]
fn (t &Tensor[T]) exp2[T]() &Tensor[T]

exp2 exposes this operation as part of the public API.

fn (Tensor[T]) expm1 #

@[inline]
fn (t &Tensor[T]) expm1[T]() &Tensor[T]

expm1 exposes this operation as part of the public API.

fn (Tensor[T]) f32_bits #

@[inline]
fn (t &Tensor[T]) f32_bits[T]() &Tensor[T]

f32_bits exposes this operation as part of the public API.

fn (Tensor[T]) f32_from_bits #

@[inline]
fn (t &Tensor[T]) f32_from_bits[T]() &Tensor[T]

f32_from_bits exposes this operation as part of the public API.

fn (Tensor[T]) f64_bits #

@[inline]
fn (t &Tensor[T]) f64_bits[T]() &Tensor[T]

f64_bits exposes this operation as part of the public API.

fn (Tensor[T]) f64_from_bits #

@[inline]
fn (t &Tensor[T]) f64_from_bits[T]() &Tensor[T]

f64_from_bits exposes this operation as part of the public API.

fn (Tensor[T]) factorial #

@[inline]
fn (t &Tensor[T]) factorial[T]() &Tensor[T]

factorial exposes this operation as part of the public API.

fn (Tensor[T]) floor #

@[inline]
fn (t &Tensor[T]) floor[T]() &Tensor[T]

floor exposes this operation as part of the public API.

fn (Tensor[T]) fmod #

@[inline]
fn (a &Tensor[T]) fmod[T](b &Tensor[T]) !&Tensor[T]

fmod exposes this operation as part of the public API.

fn (Tensor[T]) gamma #

@[inline]
fn (t &Tensor[T]) gamma[T]() &Tensor[T]

gamma exposes this operation as part of the public API.

fn (Tensor[T]) gcd #

@[inline]
fn (a &Tensor[T]) gcd[T](b &Tensor[T]) !&Tensor[T]

gcd exposes this operation as part of the public API.

fn (Tensor[T]) hypot #

@[inline]
fn (a &Tensor[T]) hypot[T](b &Tensor[T]) !&Tensor[T]

hypot exposes this operation as part of the public API.

fn (Tensor[T]) lcm #

@[inline]
fn (a &Tensor[T]) lcm[T](b &Tensor[T]) !&Tensor[T]

lcm exposes this operation as part of the public API.

fn (Tensor[T]) log #

@[inline]
fn (t &Tensor[T]) log[T]() &Tensor[T]

log exposes this operation as part of the public API.

fn (Tensor[T]) log10 #

@[inline]
fn (t &Tensor[T]) log10[T]() &Tensor[T]

log10 exposes this operation as part of the public API.

fn (Tensor[T]) log1p #

@[inline]
fn (t &Tensor[T]) log1p[T]() &Tensor[T]

log1p exposes this operation as part of the public API.

fn (Tensor[T]) log2 #

@[inline]
fn (t &Tensor[T]) log2[T]() &Tensor[T]

log2 exposes this operation as part of the public API.

fn (Tensor[T]) log_factorial #

@[inline]
fn (t &Tensor[T]) log_factorial[T]() &Tensor[T]

log_factorial exposes this operation as part of the public API.

fn (Tensor[T]) log_gamma #

@[inline]
fn (t &Tensor[T]) log_gamma[T]() &Tensor[T]

log_gamma exposes this operation as part of the public API.

fn (Tensor[T]) log_n #

@[inline]
fn (a &Tensor[T]) log_n[T](b &Tensor[T]) !&Tensor[T]

log_n exposes this operation as part of the public API.

fn (Tensor[T]) max #

@[inline]
fn (a &Tensor[T]) max[T](b &Tensor[T]) !&Tensor[T]

max returns the elementwise maximum and propagates NaNs, like numpy.maximum.

fn (Tensor[T]) min #

@[inline]
fn (a &Tensor[T]) min[T](b &Tensor[T]) !&Tensor[T]

min returns the elementwise minimum and propagates NaNs, like numpy.minimum.

fn (Tensor[T]) fmax #

@[inline]
fn (a &Tensor[T]) fmax[T](b &Tensor[T]) !&Tensor[T]

fmax returns the elementwise maximum, ignoring a single NaN operand, like numpy.fmax. If both operands are NaN, the left operand is returned.

fn (Tensor[T]) fmin #

@[inline]
fn (a &Tensor[T]) fmin[T](b &Tensor[T]) !&Tensor[T]

fmin returns the elementwise minimum, ignoring a single NaN operand, like numpy.fmin. If both operands are NaN, the left operand is returned.

fn (Tensor[T]) nextafter #

@[inline]
fn (a &Tensor[T]) nextafter[T](b &Tensor[T]) !&Tensor[T]

nextafter exposes this operation as part of the public API.

fn (Tensor[T]) nextafter32 #

@[inline]
fn (a &Tensor[T]) nextafter32[T](b &Tensor[T]) !&Tensor[T]

nextafter32 exposes this operation as part of the public API.

fn (Tensor[T]) pow #

@[inline]
fn (a &Tensor[T]) pow[T](b &Tensor[T]) !&Tensor[T]

pow exposes this operation as part of the public API.

fn (Tensor[T]) pow10 #

@[inline]
fn (t &Tensor[T]) pow10[T]() &Tensor[T]

pow10 exposes this operation as part of the public API.

fn (Tensor[T]) radians #

@[inline]
fn (t &Tensor[T]) radians[T]() &Tensor[T]

radians exposes this operation as part of the public API.

fn (Tensor[T]) round #

@[inline]
fn (t &Tensor[T]) round[T]() &Tensor[T]

round exposes this operation as part of the public API.

fn (Tensor[T]) round_to_even #

@[inline]
fn (t &Tensor[T]) round_to_even[T]() &Tensor[T]

round_to_even exposes this operation as part of the public API.

fn (Tensor[T]) round_decimals #

fn (t &Tensor[T]) round_decimals[T](decimals int) &Tensor[T]

round_decimals rounds real floating-point elements to a decimal position, following NumPy's ties-to-even rule. Negative decimals round to tens, hundreds, and larger place values. Integer tensors are copied unchanged.

fn (Tensor[T]) sin #

@[inline]
fn (t &Tensor[T]) sin[T]() &Tensor[T]

sin exposes this operation as part of the public API.

fn (Tensor[T]) sinh #

@[inline]
fn (t &Tensor[T]) sinh[T]() &Tensor[T]

sinh exposes this operation as part of the public API.

fn (Tensor[T]) sqrt #

@[inline]
fn (t &Tensor[T]) sqrt[T]() &Tensor[T]

sqrt exposes this operation as part of the public API.

fn (Tensor[T]) tan #

@[inline]
fn (t &Tensor[T]) tan[T]() &Tensor[T]

tan exposes this operation as part of the public API.

fn (Tensor[T]) tanh #

@[inline]
fn (t &Tensor[T]) tanh[T]() &Tensor[T]

tanh exposes this operation as part of the public API.

fn (Tensor[T]) trunc #

@[inline]
fn (t &Tensor[T]) trunc[T]() &Tensor[T]

trunc exposes this operation as part of the public API.

fn (Tensor[T]) modf #

fn (t &Tensor[T]) modf[T]() !(&Tensor[T], &Tensor[T])

modf returns fractional and integral parts, in that order, matching NumPy. Only f32 and f64 tensors are supported.

fn (Tensor[T]) frexp #

fn (t &Tensor[T]) frexp[T]() !(&Tensor[T], &Tensor[int])

frexp decomposes each f32/f64 value into a mantissa and base-2 exponent. The mantissa preserves the input floating-point type; exponents use int.

fn (Tensor[T]) signbit #

fn (t &Tensor[T]) signbit[T]() !&Tensor[bool]

signbit returns true for values with a negative sign bit, including -0 and negative NaNs. Signed integers are true when negative; unsigned and boolean values are always false.

fn (Tensor[T]) add #

@[inline]
fn (a &Tensor[T]) add[T](b &Tensor[T]) !&Tensor[T]

add exposes this operation as part of the public API.

fn (Tensor[T]) add_scalar #

@[inline]
fn (a &Tensor[T]) add_scalar[T](scalar T) !&Tensor[T]

add_scalar exposes this operation as part of the public API.

fn (Tensor[T]) subtract #

@[inline]
fn (a &Tensor[T]) subtract[T](b &Tensor[T]) !&Tensor[T]

subtract exposes this operation as part of the public API.

fn (Tensor[T]) subtract_scalar #

@[inline]
fn (a &Tensor[T]) subtract_scalar[T](scalar T) !&Tensor[T]

subtract_scalar exposes this operation as part of the public API.

fn (Tensor[T]) divide #

@[inline]
fn (a &Tensor[T]) divide[T](b &Tensor[T]) !&Tensor[T]

divide exposes this operation as part of the public API.

fn (Tensor[T]) divide_scalar #

@[inline]
fn (a &Tensor[T]) divide_scalar[T](scalar T) !&Tensor[T]

divide_scalar exposes this operation as part of the public API.

fn (Tensor[T]) multiply #

@[inline]
fn (a &Tensor[T]) multiply[T](b &Tensor[T]) !&Tensor[T]

multiply exposes this operation as part of the public API.

fn (Tensor[T]) multiply_scalar #

@[inline]
fn (a &Tensor[T]) multiply_scalar[T](scalar T) !&Tensor[T]

multiply_scalar exposes this operation as part of the public API.

fn (Tensor[T]) + #

@[inline]
fn (a &Tensor[T]) + (b &Tensor[T]) &Tensor[T]
  • adds two tensors elementwise. It panics when their shapes are not broadcastable; use add when shape errors need to be handled explicitly.

fn (Tensor[T]) - #

@[inline]
fn (a &Tensor[T]) - (b &Tensor[T]) &Tensor[T]
  • subtracts two tensors elementwise, following broadcasting rules. It panics when their shapes are not broadcastable; use subtract when shape errors need to be handled explicitly.

fn (Tensor[T]) * #

@[inline]
fn (a &Tensor[T]) * (b &Tensor[T]) &Tensor[T]
  • multiplies two tensors elementwise, following broadcasting rules. It panics when their shapes are not broadcastable; use multiply when shape errors need to be handled explicitly.

fn (Tensor[T]) / #

@[inline]
fn (a &Tensor[T]) / (b &Tensor[T]) &Tensor[T]

/ divides two tensors elementwise, following broadcasting rules. It panics when their shapes are not broadcastable; use divide when shape errors need to be handled explicitly.

fn (Tensor[T]) argmax_axis #

@[inline]
fn (t &Tensor[T]) argmax_axis[T](axis int) !&Tensor[int]

argmax_axis exposes this operation as part of the public API.

fn (Tensor[T]) argmin_axis #

@[inline]
fn (t &Tensor[T]) argmin_axis[T](axis int) !&Tensor[int]

argmin_axis exposes this operation as part of the public API.

fn (Tensor[T]) max_axis #

@[inline]
fn (t &Tensor[T]) max_axis[T](axis int) !&Tensor[T]

max_axis exposes this operation as part of the public API.

fn (Tensor[T]) min_axis #

@[inline]
fn (t &Tensor[T]) min_axis[T](axis int) !&Tensor[T]

min_axis exposes this operation as part of the public API.

fn (Tensor[T]) max_axis_squeeze #

fn (t &Tensor[T]) max_axis_squeeze[T](axis int) !&Tensor[T]

max_axis_squeeze returns maximum values with the reduced axis removed, matching NumPy's default keepdims=false shape behavior.

fn (Tensor[T]) min_axis_squeeze #

fn (t &Tensor[T]) min_axis_squeeze[T](axis int) !&Tensor[T]

min_axis_squeeze returns minimum values with the reduced axis removed, matching NumPy's default keepdims=false shape behavior.

fn (Tensor[T]) max_axes #

fn (t &Tensor[T]) max_axes[T](axes []int, keepdims bool) !&Tensor[T]

max_axes reduces several axes by maximum. Negative axes are supported; duplicate axes return an error. An empty axes list returns a copy.

fn (Tensor[T]) min_axes #

fn (t &Tensor[T]) min_axes[T](axes []int, keepdims bool) !&Tensor[T]

min_axes reduces several axes by minimum. Negative axes are supported; duplicate axes return an error. An empty axes list returns a copy.

fn (Tensor[T]) argmax_axis_squeeze #

fn (t &Tensor[T]) argmax_axis_squeeze[T](axis int) !&Tensor[int]

argmax_axis_squeeze returns the maximum indices with the reduced axis removed, matching NumPy's default keepdims=false behavior.

fn (Tensor[T]) argmin_axis_squeeze #

fn (t &Tensor[T]) argmin_axis_squeeze[T](axis int) !&Tensor[int]

argmin_axis_squeeze returns the minimum indices with the reduced axis removed, matching NumPy's default keepdims=false behavior.

fn (Tensor[T]) argmax #

@[inline]
fn (t &Tensor[T]) argmax[T](axis int) !&Tensor[int]

argmax exposes this operation as part of the public API.

fn (Tensor[T]) argmin #

@[inline]
fn (t &Tensor[T]) argmin[T](axis int) !&Tensor[int]

argmin exposes this operation as part of the public API.

fn (Tensor[T]) argmax_flat #

fn (t &Tensor[T]) argmax_flat[T]() !int

argmax_flat returns the flattened index of the first largest value. A NaN value is returned immediately, matching NumPy's argmax behavior.

fn (Tensor[T]) argmin_flat #

fn (t &Tensor[T]) argmin_flat[T]() !int

argmin_flat returns the flattened index of the first smallest value. A NaN value is returned immediately, matching NumPy's argmin behavior.

fn (Tensor[T]) nanargmax #

fn (t &Tensor[T]) nanargmax[T]() !int

nanargmax returns the flattened index of the largest non-NaN value. The first index wins ties, matching NumPy. Empty and all-NaN tensors return an error.

fn (Tensor[T]) nanargmin #

fn (t &Tensor[T]) nanargmin[T]() !int

nanargmin returns the flattened index of the smallest non-NaN value. The first index wins ties, matching NumPy. Empty and all-NaN tensors return an error.

fn (Tensor[T]) nanargmax_axis #

fn (t &Tensor[T]) nanargmax_axis[T](axis int, keepdims bool) !&Tensor[int]

nanargmax_axis returns the index of the largest non-NaN value on axis. Set keepdims to retain the reduced axis as a length-one dimension.

fn (Tensor[T]) nanargmin_axis #

fn (t &Tensor[T]) nanargmin_axis[T](axis int, keepdims bool) !&Tensor[int]

nanargmin_axis returns the index of the smallest non-NaN value on axis. Set keepdims to retain the reduced axis as a length-one dimension.

fn (Tensor[T]) cumsum #

@[direct_array_access; inline]
fn (t &Tensor[T]) cumsum[T](axis int) !&Tensor[T]

cumsum exposes this operation as part of the public API. Axis normalization and shape-derived loop bounds keep the direct array accesses below within the input and output buffers for valid tensors.

fn (Tensor[T]) cumprod #

@[direct_array_access; inline]
fn (t &Tensor[T]) cumprod[T](axis int) !&Tensor[T]

cumprod exposes this operation as part of the public API. Axis normalization and shape-derived loop bounds keep the direct array accesses below within the input and output buffers for valid tensors.

fn (Tensor[T]) cumsum_as #

fn (t &Tensor[T]) cumsum_as[U](axis int) !&Tensor[U]

cumsum_as computes a cumulative sum using an explicitly selected output accumulator type. This is useful when the input type has insufficient precision or range for the running total.

fn (Tensor[T]) cumprod_as #

fn (t &Tensor[T]) cumprod_as[U](axis int) !&Tensor[U]

cumprod_as computes a cumulative product using an explicitly selected output accumulator type.

fn (Tensor[T]) cumsum_flat #

fn (t &Tensor[T]) cumsum_flat[T]() !&Tensor[T]

cumsum_flat computes a cumulative sum over the tensor's logical row-major order and returns a one-dimensional tensor. This is the flattened form of NumPy's cumsum with axis=None.

fn (Tensor[T]) cumsum_flat_as #

fn (t &Tensor[T]) cumsum_flat_as[U]() !&Tensor[U]

cumsum_flat_as computes a flattened cumulative sum with an explicit output accumulator type.

fn (Tensor[T]) cumprod_flat #

fn (t &Tensor[T]) cumprod_flat[T]() !&Tensor[T]

cumprod_flat computes a cumulative product over the tensor's logical row-major order and returns a one-dimensional tensor. This is the flattened form of NumPy's cumprod with axis=None.

fn (Tensor[T]) cumprod_flat_as #

fn (t &Tensor[T]) cumprod_flat_as[U]() !&Tensor[U]

cumprod_flat_as computes a flattened cumulative product with an explicit output accumulator type.

fn (Tensor[T]) array_split #

@[direct_array_access]
fn (t &Tensor[T]) array_split[T](ind int, axis int) ![]&Tensor[T]

array_split exposes this operation as part of the public API.

fn (Tensor[T]) array_split_expl #

fn (t &Tensor[T]) array_split_expl[T](ind []int, axis int) ![]&Tensor[T]

array_split_expl splits an array into multiple sub-arrays. Please refer to the split documentation. The only difference between these functions is that array_split allows indices_or_sections to be an integer that does not equally divide the axis. For an array of length l that should be split into n sections, it returns l % n sub-arrays of size l//n + 1 and the rest of size l//n.

fn (Tensor[T]) split #

fn (t &Tensor[T]) split[T](ind int, axis int) ![]&Tensor[T]

split splits an array into multiple sub-arrays. The array will be divided into N equal arrays along axis. If such a split is not possible, panic

fn (Tensor[T]) split_expl #

fn (t &Tensor[T]) split_expl[T](ind []int, axis int) ![]&Tensor[T]

split_expl splits an array into multiple sub-arrays. The array will be divided into The entries of ind indicate where along axis the array is split. For example, [2, 3] would, for axis=0, result in: ary[:2] ary[2:3] ary[3:]

fn (Tensor[T]) hsplit #

fn (t &Tensor[T]) hsplit[T](ind int) ![]&Tensor[T]

hsplit splits an array into multiple sub-arrays horizontally (column-wise). Please refer to the split documentation. hsplit is equivalent to split with axis=1, the array is always split along the second axis regardless of the array dimension.

fn (Tensor[T]) hsplit_expl #

fn (t &Tensor[T]) hsplit_expl[T](ind []int) ![]&Tensor[T]

hsplit_expl splits an array into multiple sub-arrays horizontally (column-wise) Please refer to the split documentation. hsplit is equivalent to split with axis=1, the array is always split along the second axis regardless of the array dimension.

fn (Tensor[T]) vsplit #

fn (t &Tensor[T]) vsplit[T](ind int) ![]&Tensor[T]

vsplit splits an array into multiple sub-arrays vertically (row-wise). Please refer to the split documentation. vsplit is equivalent to split with axis=0 (default), the array is always split along the first axis regardless of the array dimension.

fn (Tensor[T]) vsplit_expl #

fn (t &Tensor[T]) vsplit_expl[T](ind []int) ![]&Tensor[T]

vsplit_expl splits an array into multiple sub-arrays vertically (row-wise). Please refer to the split documentation. vsplit is equivalent to split with axis=0 (default), the array is always split along the first axis regardless of the array dimension.

fn (Tensor[T]) dsplit #

fn (t &Tensor[T]) dsplit[T](ind int) ![]&Tensor[T]

dsplit splits array into multiple sub-arrays along the 3rd axis (depth). Please refer to the split documentation. dsplit is equivalent to split with axis=2, the array is always split along the third axis provided the array dimension is greater than or equal to 3.

fn (Tensor[T]) dsplit_expl #

fn (t &Tensor[T]) dsplit_expl[T](ind []int) ![]&Tensor[T]

dsplit_expl splits array into multiple sub-arrays along the 3rd axis (depth). Please refer to the split documentation. dsplit is equivalent to split with axis=2, the array is always split along the third axis provided the array dimension is greater than or equal to 3.

fn (Tensor[T]) unsqueeze #

fn (t &Tensor[T]) unsqueeze[T](data AxisData) !&Tensor[T]

unsqueeze adds a dimension of size one to a Tensor

fn (Tensor[T]) squeeze #

fn (t &Tensor[T]) squeeze[T](data AxisData) !&Tensor[T]

squeeze removes dimensions of size one from a Tensor. If dim is provided, only that dimension is removed (must be size 1). If no dim is provided, all size-1 dimensions are removed.

fn (Tensor[T]) expand_dims #

fn (t &Tensor[T]) expand_dims[T](data AxisData) !&Tensor[T]

expand_dims adds an axis to a Tensor in order to support broadcasting operations

fn (Tensor[T]) cuda #

fn (t &Tensor[T]) cuda(params CudaParams) !&Tensor[T]

cuda returns an error when CUDA is not enabled at compile time

fn (Tensor[T]) vcl #

fn (t &Tensor[T]) vcl(params VclParams) !&Tensor[T]

vcl returns a VclTensor from a Tensor

fn (Tensor[T]) vulkan #

fn (t &Tensor[T]) vulkan(params storage.VulkanParams) !&Tensor[T]

vulkan exposes this operation as part of the public API.

fn (Tensor[T]) assert_square_matrix #

@[inline]
fn (t &Tensor[T]) assert_square_matrix[T]() !

assert_square_matrix exposes this operation as part of the public API.

fn (Tensor[T]) assert_matrix #

@[inline]
fn (t &Tensor[T]) assert_matrix[T]() !

assert_matrix exposes this operation as part of the public API.

fn (Tensor[T]) ensure_memory #

@[inline]
fn (mut t Tensor[T]) ensure_memory[T]()

ensure_memory exposes this operation as part of the public API.

fn (TensorsIterator[T]) next #

@[inline]
fn (mut its TensorsIterator[T]) next[T]() ?([]T, []int)

next exposes this operation as part of the public API.

enum DType #

enum DType {
	boolean
	int8
	int16
	int32
	int64
	native_int
	uint8
	uint16
	uint32
	uint64
	float32
	float64
	string
	complex128
}

DType describes the element types currently supported by VTL tensors.

enum IndexKind #

enum IndexKind {
	full
	slice
	integer
	array
	ellipsis
	newaxis
}

IndexKind describes one axis operation used by mixed_index.

enum IteratorStrategy #

enum IteratorStrategy {
	flatten_iteration
	strided_iteration
}

IteratorStrategy defines a function to use in order to mutate iteration position

enum MemoryFormat #

enum MemoryFormat {
	row_major
	col_major
}

MemoryFormat is a sum type that lists the possible memory layouts

enum MeshgridIndexing #

enum MeshgridIndexing {
	xy
	ij
}

MeshgridIndexing controls the dimension order used by meshgrid_n.

enum MultiIndexOrder #

enum MultiIndexOrder {
	c
	f
}

MultiIndexOrder selects row-major or column-major flattening order.

enum PadMode #

enum PadMode {
	constant
	edge
	wrap
	reflect
	symmetric
}

PadMode selects how values outside a tensor's bounds are generated.

enum PutMode #

enum PutMode {
	raise
	wrap
	clip
}

PutMode controls how flat indices outside a tensor's range are handled.

enum QuantileMethod #

enum QuantileMethod {
	inverted_cdf
	averaged_inverted_cdf
	closest_observation
	interpolated_inverted_cdf
	hazen
	weibull
	linear
	median_unbiased
	normal_unbiased
	lower
	higher
	midpoint
	nearest
}

QuantileMethod selects one of NumPy's thirteen sample-quantile estimators.

enum SearchSide #

enum SearchSide {
	left
	right
}

SearchSide selects which side of equal values receives an insertion index.

enum TakeMode #

enum TakeMode {
	raise
	wrap
	clip
}

TakeMode controls how indices outside a gathered axis are handled.

struct AxisData #

@[params]
struct AxisData {
pub:
	axis int
}

AxisData defines a public data structure for this module.

struct CudaParams #

@[params]
struct CudaParams {}

CudaParams defines a public data structure for this module.

struct DiagonalData #

@[params]
struct DiagonalData {
pub:
	offset int
	axis1  int
	axis2  int = 1
}

DiagonalData configures the offset and axes used by diagonal.

struct IsCloseData #

@[params]
struct IsCloseData {
pub:
	rtol      f64 = 1e-5
	atol      f64 = 1e-8
	equal_nan bool
}

IsCloseData configures relative and absolute tolerances and NaN comparison.

struct IteratorBuildData #

struct IteratorBuildData[T] {
	next_handler IteratorStrategy
	start        int
}

IteratorBuildData defines a public data structure for this module.

struct LinspaceData #

@[params]
struct LinspaceData {
pub:
	endpoint bool         = true
	memory   MemoryFormat = .row_major
}

LinspaceData configures linspace's endpoint and output memory layout.

struct LogspaceData #

@[params]
struct LogspaceData {
pub:
	endpoint bool         = true
	base     f64          = 10.0
	memory   MemoryFormat = .row_major
}

LogspaceData configures logspace's endpoint, base, and output memory layout.

struct MaskedArray #

struct MaskedArray[T] {
pub:
	values &Tensor[T]
	mask   &Tensor[bool]
}

MaskedArray pairs tensor values with a boolean missing-data mask. A true mask entry marks the corresponding value as missing, following NumPy's numpy.ma convention.

struct MaskedValue #

struct MaskedValue[T] {
pub:
	value     T
	is_masked bool
}

MaskedValue carries a reduction result and indicates whether it is masked.

struct MultiIndexOptions #

@[params]
struct MultiIndexOptions {
pub:
	mode       TakeMode = .raise
	axis_modes []TakeMode
	order      MultiIndexOrder = .c
}

MultiIndexOptions configures ravel_multi_index. Set axis_modes to provide a different bounds mode for each coordinate axis; otherwise mode applies to every axis.

struct NanToNumConfig #

@[params]
struct NanToNumConfig {
pub:
	nan    f64
	posinf ?f64
	neginf ?f64
}

NanToNumConfig contains replacement values for non-finite floating-point tensor elements. Missing infinity replacements use the type's finite limits.

struct NormalTensorData #

@[params]
struct NormalTensorData {
	TensorData
	config.NormalConfigStruct
}

NormalTensorData defines a public data structure for this module.

struct RandomGenerator #

struct RandomGenerator {
mut:
	rng &rand.PRNG
}

RandomGenerator owns an independent pseudorandom stream for reproducible experiments that must not modify or depend on V's global random state.

fn (RandomGenerator) free #

fn (mut generator RandomGenerator) free()

free releases the generator's underlying pseudorandom engine.

fn (RandomGenerator) uniform #

fn (mut generator RandomGenerator) uniform(minimum f64, maximum f64, shape []int) !&Tensor[f64]

uniform returns f64 values in the [minimum, maximum) range.

fn (RandomGenerator) integers #

fn (mut generator RandomGenerator) integers(low int, high int, shape []int) !&Tensor[int]

integers returns seeded int samples from [low, high).

fn (RandomGenerator) integers_with_endpoint #

fn (mut generator RandomGenerator) integers_with_endpoint(low int, high int, shape []int, endpoint bool) !&Tensor[int]

integers_with_endpoint returns seeded int samples from [low, high) or [low, high] when endpoint is true.

fn (RandomGenerator) normal #

fn (mut generator RandomGenerator) normal(shape []int, params NormalTensorData) !&Tensor[f64]

normal returns f64 values from a normal distribution with the given parameters.

fn (RandomGenerator) multivariate_normal #

fn (mut generator RandomGenerator) multivariate_normal(mean &Tensor[f64], covariance &Tensor[f64], sample_shape []int) !&Tensor[f64]

multivariate_normal draws samples with the requested mean and covariance. sample_shape describes the leading sample dimensions; the final output axis contains the variables. Positive-semidefinite covariance matrices are supported, including singular matrices.

fn (RandomGenerator) lognormal #

fn (mut generator RandomGenerator) lognormal(mean f64, sigma f64, shape []int) !&Tensor[f64]

lognormal returns samples whose natural logarithm follows a normal distribution with the given mean and standard deviation.

fn (RandomGenerator) bernoulli #

fn (mut generator RandomGenerator) bernoulli(probability f64, shape []int) !&Tensor[bool]

bernoulli returns bool values sampled with the given probability of true.

fn (RandomGenerator) binomial #

fn (mut generator RandomGenerator) binomial(trials int, probability f64, shape []int) !&Tensor[int]

binomial returns the number of successful trials in each sample using this generator's independent stream.

fn (RandomGenerator) negative_binomial #

fn (mut generator RandomGenerator) negative_binomial(n f64, probability f64, shape []int) !&Tensor[int]

negative_binomial counts failures before n successes using this generator's independent stream. n is the positive real-valued success threshold and p is the success probability for each trial.

fn (RandomGenerator) hypergeometric #

fn (mut generator RandomGenerator) hypergeometric(ngood int, nbad int, nsample int, shape []int) !&Tensor[int]

hypergeometric samples the number of good items in draws made without replacement from a population containing ngood good and nbad bad items.

fn (RandomGenerator) multinomial #

fn (mut generator RandomGenerator) multinomial(trials int, probabilities &Tensor[f64], sample_shape []int) !&Tensor[int]

multinomial returns category counts for repeated samples from one categorical distribution. The final output axis contains the categories.

fn (RandomGenerator) exponential #

fn (mut generator RandomGenerator) exponential(lambda f64, shape []int) !&Tensor[f64]

exponential returns f64 samples from an exponential distribution with the given positive finite rate using this generator's independent stream.

fn (RandomGenerator) gumbel #

fn (mut generator RandomGenerator) gumbel(location f64, scale f64, shape []int) !&Tensor[f64]

gumbel returns samples from a Gumbel distribution with the given location and non-negative scale using this generator's independent stream.

fn (RandomGenerator) laplace #

fn (mut generator RandomGenerator) laplace(location f64, scale f64, shape []int) !&Tensor[f64]

laplace returns samples from a Laplace distribution with the given location and non-negative scale using this generator's independent stream.

fn (RandomGenerator) cauchy #

fn (mut generator RandomGenerator) cauchy(location f64, scale f64, shape []int) !&Tensor[f64]

cauchy returns samples from a Cauchy distribution with the given location and positive scale using this generator's independent stream.

fn (RandomGenerator) wald #

fn (mut generator RandomGenerator) wald(mean f64, scale f64, shape []int) !&Tensor[f64]

wald returns samples from a Wald (inverse Gaussian) distribution with the given positive mean and positive scale using this generator's stream.

fn (RandomGenerator) logistic #

fn (mut generator RandomGenerator) logistic(location f64, scale f64, shape []int) !&Tensor[f64]

logistic returns samples from a Logistic distribution with the given location and non-negative scale using this generator's independent stream.

fn (RandomGenerator) pareto #

fn (mut generator RandomGenerator) pareto(shape_parameter f64, shape []int) !&Tensor[f64]

pareto returns samples from the standard Pareto distribution (minimum zero) with the given positive shape parameter and this generator's stream.

fn (RandomGenerator) rayleigh #

fn (mut generator RandomGenerator) rayleigh(scale f64, shape []int) !&Tensor[f64]

rayleigh returns samples from a Rayleigh distribution with non-negative scale and this generator's independent stream.

fn (RandomGenerator) triangular #

fn (mut generator RandomGenerator) triangular(left f64, mode f64, right f64, shape []int) !&Tensor[f64]

triangular returns samples from a triangular distribution defined by its left endpoint, mode, right endpoint, and this generator's independent stream.

fn (RandomGenerator) geometric #

fn (mut generator RandomGenerator) geometric(probability f64, shape []int) !&Tensor[int]

geometric returns the number of Bernoulli trials needed for the first success, independently sampled from this generator. Results start at 1.

fn (RandomGenerator) poisson #

fn (mut generator RandomGenerator) poisson(lambda f64, shape []int) !&Tensor[int]

poisson returns integer event counts with the given finite, non-negative expected rate using this generator's independent stream.

fn (RandomGenerator) weibull #

fn (mut generator RandomGenerator) weibull(shape_parameter f64, shape []int) !&Tensor[f64]

weibull returns samples from the unit-scale Weibull distribution. The positive shape parameter controls the distribution's tail and hazard rate.

fn (RandomGenerator) chi_square #

fn (mut generator RandomGenerator) chi_square(degrees_of_freedom f64, shape []int) !&Tensor[f64]

chi_square returns samples from a chi-square distribution with the given positive degrees of freedom.

fn (RandomGenerator) student_t #

fn (mut generator RandomGenerator) student_t(degrees_of_freedom f64, shape []int) !&Tensor[f64]

student_t returns samples from the standard Student's t distribution.

fn (RandomGenerator) f_distribution #

fn (mut generator RandomGenerator) f_distribution(numerator_df f64, denominator_df f64, shape []int) !&Tensor[f64]

f_distribution returns samples from an F distribution with the specified numerator and denominator degrees of freedom.

fn (RandomGenerator) choice #

fn (mut generator RandomGenerator) choice[T](population &Tensor[T], size int, replace bool) !&Tensor[T]

choice samples values from a tensor's flattened logical order. Without replacement, selected positions are unique; the same value may still occur more than once in the population.

fn (RandomGenerator) choice_weighted #

fn (mut generator RandomGenerator) choice_weighted[T](population &Tensor[T], weights &Tensor[f64], size int, replace bool) !&Tensor[T]

choice_weighted samples values from a tensor's flattened logical order in proportion to non-negative weights. Without replacement, each selected position is removed from the remaining weight distribution.

fn (RandomGenerator) choice_axis #

fn (mut generator RandomGenerator) choice_axis[T](population &Tensor[T], size int, axis int, replace bool) !&Tensor[T]

choice_axis samples complete slices along axis and replaces that axis by size.

fn (RandomGenerator) choice_weighted_axis #

fn (mut generator RandomGenerator) choice_weighted_axis[T](population &Tensor[T], weights &Tensor[f64], size int, axis int, replace bool) !&Tensor[T]

choice_weighted_axis samples complete slices in proportion to non-negative axis weights and replaces that axis by size.

fn (RandomGenerator) permutation #

fn (mut generator RandomGenerator) permutation(size int) !&Tensor[int]

permutation returns the integers in [0, size) in a seeded random order.

fn (RandomGenerator) permutation_tensor #

fn (mut generator RandomGenerator) permutation_tensor[T](input &Tensor[T]) !&Tensor[T]

permutation_tensor returns a copy with rows shuffled along the first axis, matching NumPy's permutation behavior for an N-dimensional array.

fn (RandomGenerator) permutation_axis #

fn (mut generator RandomGenerator) permutation_axis[T](input &Tensor[T], axis int) !&Tensor[T]

permutation_axis returns a copy with slices shuffled along the selected axis. Negative axes are accepted, matching Tensor.take and NumPy's axis convention.

fn (RandomGenerator) gamma #

fn (mut generator RandomGenerator) gamma(alpha f64, scale f64, shape []int) !&Tensor[f64]

gamma returns samples from a Gamma distribution using this generator's independent stream. alpha is the shape and scale is the scale parameter.

fn (RandomGenerator) beta #

fn (mut generator RandomGenerator) beta(alpha f64, beta f64, shape []int) !&Tensor[f64]

beta returns samples from a Beta distribution using this generator's independent stream. alpha and beta are the two positive shape parameters.

fn (RandomGenerator) dirichlet #

fn (mut generator RandomGenerator) dirichlet[T](alpha &Tensor[T], sample_shape []int) !&Tensor[f64]

dirichlet returns samples from a Dirichlet distribution. The final output axes match the concentration tensor's shape; sample_shape is prepended.

struct Tensor #

@[heap]
struct Tensor[T] {
pub mut:
	data    &storage.CpuStorage[T] = unsafe { nil }
	memory  MemoryFormat
	size    int
	shape   []int
	strides []int
}

Tensor defines a public data structure for this module.

struct TensorAxisIterator #

@[heap]
struct TensorAxisIterator[T] {
pub:
	tensor &Tensor[T] = unsafe { nil }
pub mut:
	shape     []int
	strides   []int
	axis      int
	inc       int
	iteration int
	pos       int
}

TensorAxisIterator defines a public data structure for this module.

struct TensorData #

@[params]
struct TensorData {
pub:
	memory MemoryFormat = .row_major
}

TensorData defines a public data structure for this module.

struct TensorIndex #

struct TensorIndex {
pub:
	kind      IndexKind
	integer   int
	start     int
	stop      int
	has_start bool
	has_stop  bool
	step      int
	indices   &Tensor[int]
}

TensorIndex describes one axis of a mixed basic and advanced indexing operation. Use the constructors below to create valid values.

struct TensorIterator #

@[heap]
struct TensorIterator[T] {
pub:
	tensor       &Tensor[T] = unsafe { nil }
	next_handler IteratorStrategy
pub mut:
	iteration int
}

TensorIterator defines a public data structure for this module.

struct TensorsIterator #

struct TensorsIterator[T] {
mut:
	iters []&TensorIterator[T]
}

TensorsIterator defines a public data structure for this module.

struct TriangularOptions #

@[params]
struct TriangularOptions {
pub:
	k int
}

TriangularOptions selects the diagonal offset for triangular matrix helpers.

struct UniqueAxisResult #

struct UniqueAxisResult[T] {
pub:
	values        &Tensor[T]
	counts        &Tensor[int]
	first_indices &Tensor[int]
	inverse       &Tensor[int]
}

UniqueAxisResult contains unique axis slices and their source metadata.

struct UniqueCounts #

struct UniqueCounts[T] {
pub:
	values &Tensor[T]
	counts &Tensor[int]
}

UniqueCounts contains sorted unique values and their occurrence counts.

struct UnravelIndexOptions #

@[params]
struct UnravelIndexOptions {
pub:
	order MultiIndexOrder = .c
}

UnravelIndexOptions selects the order used by unravel_index. The default is C (row-major) order, matching NumPy.

struct VandermondeData #

@[params]
struct VandermondeData {
pub:
	n          int = -1
	increasing bool
}

VandermondeData configures the column count and power order used by vander.

struct VclParams #

@[params]
struct VclParams {}

VclParams defines a public data structure for this module.