Skip to content

vtl #

The V Tensor Library

vlang.io | Docs | Tutorials | Changelog | Contributing

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

VTL Provides

  • An n-dimensional Tensor data structure
  • Sophisticated reduction, elementwise, and accumulation operations
  • Data Structures that can easily be passed to C libraries
  • Powerful linear algebra routines backed by VSL that uses LAPACKE and OpenBLAS.

In the docs you can find more information about this module

Installation

Install dependencies (optional)

We use VSL as backend for some functionalities. VTL requires VSL's linear algebra module. If you wish you to use vtl without these, the vtl module will still function as normal.

Follow this install instructions at VSL docs in order to install VSL with all needed dependencies.

Install VTL

v install vtl

Done. Installation completed.

Testing

To test the module, just type the following command:

v test .

License

MIT

Contributors

This work was originally based on the work done by > Christopher (christopherzimmerman).

The development of this library continues its course after having reimplemented its core > and a large part of its interface. In the same way, we do not want to stop recognizing > the work and inspiration that the library done by Christopher has given.

Made with contributors-img.

fn bernoulli #

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

bernoulli returns a tensor of bernoulli random variables.

fn binomial #

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

binomial returns a tensor of binomial random variables.

fn broadcast2 #

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

broadcast2 broadcasts two Tensors against each other

fn broadcast3 #

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

broadcast3 broadcasts three Tensors against each other

fn broadcast_n #

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

broadcast_n broadcasts N Tensors against each other

fn cast #

fn cast[T](x TensorDataType) T

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 concatenate #

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

concatenate concatenates two Tensors together

fn dstack #

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

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

fn empty #

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

empty returns a new Tensor of given shape and type, without initializing entries

fn empty_like #

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

empty_like returns a new Tensor of given shape and type as a given Tensor

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 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 #

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

from_2d takes a two dimensional array of floating point values and returns a two-dimensional Tensor if possible

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 #

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

full returns a new tensor of a given shape and type, filled with the given value

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 hstack #

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

hstack stacks arrays in sequence horizontally (column wise)

fn identity #

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

identity returns an array is a square array with ones on the main diagonal

fn normal #

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

normal returns a tensor of normal random variables.

fn ones #

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

ones returns a new tensor of a given shape and type, filled with ones

fn ones_like #

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

ones_like returns a new tensor of a given shape and type, filled with ones

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)

fn range #

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

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

fn seq #

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

seq returns a Tensor containing values ranging from [0, to)

fn stack #

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

stack join a sequence of arrays along a new axis.

fn td #

fn td[T](x T) TensorDataType

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 vstack #

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

vstack stack arrays in sequence vertically (row wise)

fn zeros #

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

zeros returns a new tensor of a given shape and type, filled with zeros

fn zeros_like #

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

zeros_like returns a new Tensor of given shape and type as a given Tensor, filled with zeros

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 (TensorAxisIterator[T]) next #

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

next calls the iteration type for a given iterator which is either flat or strided and returns a Num containing the current value

type TensorDataType #

type TensorDataType = bool | f32 | f64 | i16 | 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 uses TensorDataType as an integer.

fn (TensorDataType) i64 #

fn (v TensorDataType) i64() i64

i64 uses TensorDataType as a 64-bit integer.

fn (TensorDataType) i8 #

fn (v TensorDataType) i8() i8

i8 uses TensorDataType as a 8-bit unsigned integer.

fn (TensorDataType) i16 #

fn (v TensorDataType) i16() i16

i16 uses TensorDataType as a 16-bit unsigned integer.

fn (TensorDataType) u8 #

fn (v TensorDataType) u8() u8

u8 uses TensorDataType as a 8-bit unsigned integer.

fn (TensorDataType) u16 #

fn (v TensorDataType) u16() u16

u16 uses TensorDataType as a 16-bit unsigned integer.

fn (TensorDataType) u32 #

fn (v TensorDataType) u32() u32

u32 uses TensorDataType as a 32-bit unsigned integer.

fn (TensorDataType) u64 #

fn (v TensorDataType) u64() u64

u64 uses TensorDataType as a 64-bit unsigned integer.

fn (TensorDataType) f32 #

fn (v TensorDataType) f32() f32

f32 uses TensorDataType as a 32-bit float.

fn (TensorDataType) f64 #

fn (v TensorDataType) f64() f64

f64 uses TensorDataType as a float.

fn (TensorDataType) bool #

fn (v TensorDataType) bool() bool

bool uses TensorDataType as a bool

fn (TensorIterator[T]) next #

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

next calls the iteration type for a given iterator which is either flat or strided and returns a Num containing the current value

fn (Tensor[T]) abs #

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

abs returns the elementwise abs of an tensor

fn (Tensor[T]) acos #

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

acos returns the elementwise acos of an tensor

fn (Tensor[T]) acosh #

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

acosh returns the elementwise acosh of an tensor

fn (Tensor[T]) add #

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

add adds two tensors elementwise

fn (Tensor[T]) add_scalar #

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

add adds a scalar to a tensor elementwise

fn (Tensor[T]) alike #

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

alike compares two tensors elementwise

fn (Tensor[T]) all #

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

all returns whether all array elements evaluate to true.

fn (Tensor[T]) any #

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

any returns whether any array elements evaluate to true.

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]) 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 equal.

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]) array_split #

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

array_split 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]) 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]) as_bool #

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

as_bool casts the Tensor to a Tensor of bools. If the original Tensor is not a Tensor of bools, then each value is cast to a bool, otherwise the original Tensor is returned.

fn (Tensor[T]) as_f32 #

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

as_f32 casts the Tensor to a Tensor of f32s. If the original Tensor is not a Tensor of f32s, then each value is cast to a f32, otherwise the original Tensor is returned.

fn (Tensor[T]) as_f64 #

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

as_f64 casts the Tensor to a Tensor of f64s. If the original Tensor is not a Tensor of f64s, then each value is cast to a f64, otherwise the original Tensor is returned.

fn (Tensor[T]) as_i16 #

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

as_i16 casts the Tensor to a Tensor of i16 values. If the original Tensor is not a Tensor of i16s, then each value is cast to a i16, otherwise the original Tensor is returned.

fn (Tensor[T]) as_i8 #

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

as_i8 casts the Tensor to a Tensor of i8 values. If the original Tensor is not a Tensor of i8s, then each value is cast to a i8, otherwise the original Tensor is returned.

fn (Tensor[T]) as_int #

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

as_int casts the Tensor to a Tensor of ints. If the original Tensor is not a Tensor of ints, then each value is cast to a int, otherwise the original Tensor is returned.

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]) as_string #

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

as_string casts the Tensor to a Tensor of string values. If the original Tensor is not a Tensor of strings, then each value is cast to a string, otherwise the original Tensor is returned.

fn (Tensor[T]) as_u8 #

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

as_u8 casts the Tensor to a Tensor of u8 values. If the original Tensor is not a Tensor of u8s, then each value is cast to a u8, otherwise the original Tensor is returned.

fn (Tensor[T]) asin #

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

asin returns the elementwise asin of an tensor

fn (Tensor[T]) asinh #

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

asinh returns the elementwise asinh of an tensor

fn (Tensor[T]) assert_matrix #

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

assert_square_matrix panics if the given tensor is not a matrix

fn (Tensor[T]) assert_square_matrix #

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

assert_square_matrix panics if the given tensor is not a square matrix

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]) atan #

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

atan returns the elementwise atan of an tensor

fn (Tensor[T]) atan2 #

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

atan2 returns the atan2 elementwise of two tensors

fn (Tensor[T]) atanh #

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

atanh returns the elementwise atanh of an tensor

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]) 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]) 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]) cbrt #

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

cbrt returns the elementwise cbrt of an tensor

fn (Tensor[T]) ceil #

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

ceil returns the elementwise ceil of an tensor

fn (Tensor[T]) close #

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

close compares two tensors elementwise

fn (Tensor[T]) copy #

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

copy returns a copy of a Tensor with a particular memory layout, either row_major-contiguous or col_major-contiguous

fn (Tensor[T]) cos #

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

cos returns the elementwise cos of an tensor

fn (Tensor[T]) cosh #

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

cosh returns the elementwise cosh of an tensor

fn (Tensor[T]) cot #

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

cot returns the elementwise cot of an tensor

fn (Tensor[T]) cpu #

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

cpu returns a Tensor from 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]) degrees #

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

degrees returns the elementwise degrees of an tensor

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]) 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]) divide #

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

divide divides two tensors elementwise

fn (Tensor[T]) divide_scalar #

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

divide divides a scalar to a tensor elementwise

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]) ensure_memory #

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

ensure_memory sets a correct memory layout to a given tensor

fn (Tensor[T]) equal #

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

equal compares two tensors elementwise

fn (Tensor[T]) erf #

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

erf returns the elementwise erf of an tensor

fn (Tensor[T]) erfc #

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

erfc returns the elementwise erfc of an tensor

fn (Tensor[T]) exp #

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

exp returns the elementwise exp of an tensor

fn (Tensor[T]) exp2 #

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

exp2 returns the elementwise exp2 of an tensor

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]) expm1 #

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

expm1 returns the elementwise expm1 of an tensor

fn (Tensor[T]) f32_bits #

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

f32_bits returns the elementwise f32_bits of an tensor

fn (Tensor[T]) f32_from_bits #

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

f32_from_bits returns the elementwise f32_from_bits of an tensor

fn (Tensor[T]) f64_bits #

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

f64_bits returns the elementwise f64_bits of an tensor

fn (Tensor[T]) f64_from_bits #

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

f64_from_bits returns the elementwise f64_from_bits of an tensor

fn (Tensor[T]) factorial #

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

factorial returns the elementwise factorial of an tensor

fn (Tensor[T]) fill #

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

fill fills an entire Tensor with a given value

fn (Tensor[T]) floor #

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

floor returns the elementwise floor of an tensor

fn (Tensor[T]) fmod #

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

fmod returns the fmod elementwise of two tensors

fn (Tensor[T]) gamma #

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

gamma returns the elementwise gamma of an tensor

fn (Tensor[T]) gcd #

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

gcd returns the gcd elementwise of two tensors

fn (Tensor[T]) get #

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

get returns a scalar value from a Tensor at the provided index

fn (Tensor[T]) get_nth #

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

get_nth returns a scalar value from a Tensor at the provided index

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]) hypot #

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

hypot returns the hypot elementwise of two tensors

fn (Tensor[T]) is_col_major #

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

is_col_major returns if a Tensor is supposed to store its data in Col-Major order

fn (Tensor[T]) is_col_major_contiguous #

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

is_col_major verifies if a Tensor stores its data in Col-Major order

fn (Tensor[T]) is_contiguous #

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

is_contiguous verifies that a Tensor is contiguous independent of memory layout

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_matrix #

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

is_matrix returns if a Tensor is a nxm matrix or not

fn (Tensor[T]) is_nan #

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

is_nan reports whether f is an IEEE 754 ``not-a-number'' value.

fn (Tensor[T]) is_row_major #

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

is_row_major returns if a Tensor is supposed to store its data in Row-Major order

fn (Tensor[T]) is_row_major_contiguous #

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

is_row_major verifies if a Tensor stores its data in Row-Major order

fn (Tensor[T]) is_square_matrix #

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

is_matrix returns if a Tensor is a square matrix or not

fn (Tensor[T]) is_vector #

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

is_matrix returns if a Tensor is a square 1D vector or not

fn (Tensor[T]) iterator #

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

iterator creates an iterator through a Tensor

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]) lcm #

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

lcm returns the lcm elementwise of two tensors

fn (Tensor[T]) log #

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

log returns the elementwise log of an tensor

fn (Tensor[T]) log10 #

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

log10 returns the elementwise log10 of an tensor

fn (Tensor[T]) log1p #

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

log1p returns the elementwise log1p of an tensor

fn (Tensor[T]) log2 #

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

log2 returns the elementwise log2 of an tensor

fn (Tensor[T]) log_factorial #

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

log_factorial returns the elementwise log_factorial of an tensor

fn (Tensor[T]) log_gamma #

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

log_gamma returns the elementwise log_gamma of an tensor

fn (Tensor[T]) log_n #

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

log_n returns the log_n elementwise of two tensors

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]) max #

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

max returns the max elementwise of two tensors

fn (Tensor[T]) min #

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

min returns the min elementwise of two tensors

fn (Tensor[T]) multiply #

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

multiply multiplies two tensors elementwise

fn (Tensor[T]) multiply_scalar #

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

multiply multiplies a scalar to a tensor elementwise

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]) nextafter #

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

nextafter returns the nextafter elementwise of two tensors

fn (Tensor[T]) nextafter32 #

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

nextafter32 returns the nextafter32 elementwise of two tensors

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]) not_equal #

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

not_equal compares two tensors elementwise

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]) 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]) offset_index #

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

offset_index returns the index to a Tensor's data at a given index

fn (Tensor[T]) pow #

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

pow returns the pow elementwise of two tensors

fn (Tensor[T]) pow10 #

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

pow10 returns the elementwise pow10 of an tensor

fn (Tensor[T]) radians #

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

radians returns the elementwise deg2rad of an tensor

fn (Tensor[T]) rank #

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

rank returns the number of dimensions of a given Tensor

fn (Tensor[T]) ravel #

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

ravel returns a flattened view of an Tensor if possible, otherwise a flattened copy

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]) reshape #

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

reshape returns an Tensor with a new shape

fn (Tensor[T]) round #

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

round rounds elements of an tensor elementwise

fn (Tensor[T]) round_to_even #

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

round_to_even round_to_evens elements of an tensor elementwise

fn (Tensor[T]) set #

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

set copies a scalar value into a Tensor at the provided index

fn (Tensor[T]) set_nth #

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

set_nth copies a scalar value into a Tensor at the provided offset

fn (Tensor[T]) sin #

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

sin returns the elementwise sin of an tensor

fn (Tensor[T]) sinh #

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

sinh returns the elementwise sinh of an 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]) slice #

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

slice returns a tensor from a variadic list of indexing operations

fn (Tensor[T]) slice_hilo #

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

slice_hilo returns a view of an array from a list of starting indices and a list of closing indices.

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]) sqrt #

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

sqrt returns the elementwise square root of an tensor

fn (Tensor[T]) str #

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

str returns the string representation of a Tensor

fn (Tensor[T]) subtract #

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

subtract subtracts two tensors elementwise

fn (Tensor[T]) subtract_scalar #

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

subtract subtracts a scalar to a tensor elementwise

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]) t #

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

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

fn (Tensor[T]) tan #

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

tan returns the elementwise tan of an tensor

fn (Tensor[T]) tanh #

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

tanh returns the elementwise tanh of an tensor

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]) tolerance #

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

tolerance compares two tensors elementwise with a given tolerance

fn (Tensor[T]) transpose #

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

transpose permutes the axes of an tensor in a specified order and returns a view of the data

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_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]) 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_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]) 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_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]) 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]) trunc #

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

trunc returns the elementwise trunc of an tensor

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]) vcl #

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

vcl returns a VclTensor from a Tensor

fn (Tensor[T]) veryclose #

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

veryclose compares two tensors elementwise

fn (Tensor[T]) view #

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

view returns a view of a Tensor, identical to the parent but not owning its own data

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]) 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]) 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 (TensorsIterator[T]) next #

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

next calls the iteration type for a given list of iterators which is either flat or strided and returns a list of Nums containing the current values

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

struct AxisData #

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

struct IteratorBuildData #

struct IteratorBuildData[T] {
	next_handler IteratorStrategy
	start        int
}

struct NormalTensorData #

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

NormalTensorData is the data for a normal distribution.

struct Tensor #

@[heap]
struct Tensor[T] {
pub mut:
	data    &storage.CpuStorage[T] = unsafe { nil }
	memory  MemoryFormat
	size    int
	shape   []int
	strides []int
}

Tensor is the main structure defined by VTL to manage N Dimensional data

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 is the core iterator for axis-wise operations. Stores a copy of the shape and strides reduced along a given axis

struct TensorData #

@[params]
struct TensorData {
pub:
	memory MemoryFormat = .row_major
}

struct TensorIterator #

@[heap]
struct TensorIterator[T] {
pub:
	tensor       &Tensor[T] = unsafe { nil }
	next_handler IteratorStrategy
pub mut:
	iteration int
}

TensorIterator is a struct to hold a Tensors iteration state while iterating through a Tensor

struct TensorsIterator #

struct TensorsIterator[T] {
mut:
	iters []&TensorIterator[T]
}

struct VclParams #

@[params]
struct VclParams {}