Fork me on GitHub
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood

Module init_cpu

Procs

proc newTensorUninit[T](shape: varargs[int]): Tensor[T] {.
noSideEffect, noInit, inline
.}
Creates a new Tensor on Cpu backend
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A Tensor of the proper shape with NO initialization
Warning ⚠
Tensor data is uninitialized and contains garbage.
  Source Edit
proc newTensorUninit[T](shape: MetadataArray): Tensor[T] {.
noSideEffect, noInit, inline
.}
Creates a new Tensor on Cpu backend
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A Tensor of the proper shape with NO initialization
Warning ⚠
Tensor data is uninitialized and contains garbage.
  Source Edit
proc newTensor[T](shape: varargs[int]): Tensor[T] {.
noSideEffect, noInit, inline
.}
Creates a new Tensor on Cpu backend
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A Tensor of the proper shape initialized with the default type value (0 for numeric types) on Cpu backend
  Source Edit
proc newTensorWith[T](shape: varargs[int]; value: T): Tensor[T] {.
noInit, noSideEffect
.}
Creates a new Tensor filled with the given value
Input:
  • Shape of the Tensor
  • Type of its elements
  • Value to initialize its elements
Result:
  • A Tensor of the proper shape initialized with the given value
  Source Edit
proc newTensorWith[T](shape: MetadataArray; value: T): Tensor[T] {.
noInit, noSideEffect
.}
Creates a new Tensor filled with the given value
Input:
  • Shape of the Tensor
  • Type of its elements
  • Value to initialize its elements
Result:
  • A Tensor of the proper shape initialized with the given value
  Source Edit
proc toTensor(s: openArray; dummy_bugfix: static[int] = 0): auto {.
noSideEffect
.}
Convert an openarray to a Tensor
Input:
  • An array or a seq (can be nested)
Result:
  • A Tensor of the same shape

Note: dummy_bugfix param is unused and is a workaround a Nim bug.

  Source Edit
proc toTensor(s: string): auto {.
noSideEffect, raises: [IndexError], tags: []
.}

Convert a string to a Tensor

This proc handles string specifically as otherwise they are interpreted as a sequence of char

  Source Edit
proc zeros[T: SomeNumber](shape: varargs[int]): Tensor[T] {.
noInit, noSideEffect, inline
.}
Creates a new Tensor filled with 0
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A zero-ed Tensor of the input shape on backend Cpu
  Source Edit
proc zeros[T: SomeNumber](shape: MetadataArray): Tensor[T] {.
noInit, noSideEffect, inline
.}
Creates a new Tensor filled with 0
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A zero-ed Tensor of the input shape on backend Cpu
  Source Edit
proc zeros_like[T: SomeNumber](t: Tensor[T]): Tensor[T] {.
noInit, noSideEffect, inline
.}
Creates a new Tensor filled with 0 with the same shape as the input
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A zero-ed Tensor of the same shape
  Source Edit
proc ones[T: SomeNumber](shape: varargs[int]): Tensor[T] {.
noInit, inline, noSideEffect
.}
Creates a new Tensor filled with 1
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A one-ed Tensor of the same shape
  Source Edit
proc ones[T: SomeNumber](shape: MetadataArray): Tensor[T] {.
noInit, inline, noSideEffect
.}
Creates a new Tensor filled with 1
Input:
  • Shape of the Tensor
  • Type of its elements
Result:
  • A one-ed Tensor of the same shape
  Source Edit
proc ones_like[T: SomeNumber](t: Tensor[T]): Tensor[T] {.
noInit, inline, noSideEffect
.}
Creates a new Tensor filled with 1 with the same shape as the input and filled with 1
Input:
  • Tensor
Result:
  • A one-ed Tensor of the same shape
  Source Edit
proc randomTensor[T: SomeReal](shape: varargs[int]; max: T): Tensor[T] {.
noInit
.}

Creates a new float Tensor filled with values between 0 and max.

Random seed can be set by importing random and randomize(seed)

Input:
  • a shape
  • the max value possible (float)
  • a tensor backend
Result:
  • A tensor of the input shape filled with random value between 0 and max input value
  Source Edit
proc randomTensor(shape: varargs[int]; max: int): Tensor[int] {.
noInit, raises: [], tags: []
.}

Creates a new int Tensor filled with values between 0 and max.

Random seed can be set by importing random and randomize(seed)

Input:
  • a shape
  • the max value possible (integer, inclusive)
  • a tensor backend
Result:
  • A tensor of the input shape filled with random value between 0 and max input value (excluded)
  Source Edit
proc randomTensor[T](shape: varargs[int]; slice: Slice[T]): Tensor[T] {.
noInit
.}

Creates a new int Tensor filled with values in the Slice range.

Random seed can be set by importing random and randomize(seed)

Input:
  • a shape
  • a range/slice
  • a tensor backend
Result:
  • A tensor of the input shape filled with random value in the slice range
  Source Edit
proc randomNormalTensor[T: SomeReal](shape: varargs[int]; mean: T = 0; std: T = 1): Tensor[T] {.
noInit
.}

Creates a new Tensor filled with values in the normal distribution

Random seed can be set by importing random and randomize(seed)

Input:
  • a shape
  • the mean (default 0)
  • the standard deviation (default 1)
Result:
  • A tensor of the input shape filled with random values in the normal distribution
  Source Edit