dtorch.functionnal

Description

This module contain all the methods that can be used on jtensors. All of them support the autograd and are often used in ML.

Functions

transpose(tensor: dtorch.jtensors.JTensors, axis: Tuple[int, int] | None = (1, 0)) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to transpose

  • axis – the axis to transpose

Returns:

the transposed tensor

This function transpose the tensor along the given axes.

split(tensor: dtorch.jtensors.JTensors, value: int | list[int]) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to split

  • value – the value to split the tensor

Returns:

the splitted tensor

This function split the tensor along the given axis.

norm(tensor) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to normalize

Returns:

the normalized tensor

This function return a 1 element tensor containing the norm of the tensor.

sqrt(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to sqrt

Returns:

the sqrted tensor

This function return a tensor containing the square root of the tensor.

logsumexp(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to logsumexp

Returns:

the logsumexped tensor

This function return a tensor containing the logsumexp of the tensor. Mathematically, it is defined as \(log(sum(exp(tensor)))\).

sigmoid(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to sigmoid

Returns:

the sigmoided tensor

This function return a tensor containing the sigmoid of the tensor. Mathematically, it is defined as \(1 / (1 + exp(-tensor))\).

from_list(data: list[dtorch.jtensors.JTensors]) dtorch.jtensors.JTensors
Parameters:

data – the list of tensors to concatenate

Returns:

the concatenated tensor

This function return a tensor containing the concatenation of the given tensors.

to_list(tensor: dtorch.jtensors.JTensors) list[dtorch.jtensors.JTensors]
Parameters:

tensor – the tensor to split

Returns:

the splitted tensor

This function return a list of tensors containing the split of the given tensor.

as_strided(tensor: dtorch.jtensors.JTensors, shape: Tuple[int, int], strides: Tuple[int, int]) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to transform

  • shape – the shape of the new tensor

  • strides – the strides of the new tensor

Returns:

the strided tensor

This function return a tensor with the new stride and shape. To know more about strides, see this.

conv1d(input: dtorch.jtensors.JTensors, weight: dtorch.jtensors.JTensors, bias: dtorch.jtensors.JTensors | None = None, stride: int | None = 1) dtorch.jtensors.JTensors
Parameters:
  • input – 1d tensor (batch_size, in_channel, width) or (in_channel, width)

  • weight – (out_channel, in_channel, kernel_width) or (in_channel, kernel_width)

  • bias – (out_channel). Defaults to None.

  • stridemovement speed of the kernel. Defaults to 1.

Returns:

the convoluted tensor

This function return a tensor containing the convolution of the input tensor with the weight tensor. If the bias is not None, it will be added to the result.

conv2d(input: dtorch.jtensors.JTensors, weight: dtorch.jtensors.JTensors, bias: dtorch.jtensors.JTensors | None = None, stride: int = 1) dtorch.jtensors.JTensors
Parameters:
  • input – 2d tensor (batch_size, in_channel, height, width) or (in_channel, height, width)

  • weight – (out_channel, in_channel, kernel_height, kernel_width) or (in_channel, kernel_height, kernel_width)

  • bias – (out_channel). Defaults to None.

  • stridemovement speed of the kernel. Defaults to 1.

Returns:

the convoluted tensor

This function return a tensor containing the convolution of the input tensor with the weight tensor. If the bias is not None, it will be added to the result.

dropout(tensor: dtorch.jtensors.JTensors, p: float = 0.5)
Parameters:
  • tensor – the tensor to dropout

  • p – the probability of dropout. Defaults to 0.5.

Returns:

the dropouted tensor

This function return a tensor containing the dropouted tensor. The dropout is a technique used to prevent overfitting. It randomly set some values to 0.

softmax(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to softmax

Returns:

the softmaxed tensor

This function return a tensor containing the softmax of the tensor. Mathematically, it is defined as \(exp(tensor) / sum(exp(tensor))\).

max(tensor: dtorch.jtensors.JTensors, value: int | float) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to max

  • value – the value to max the tensor

Returns:

the maxed tensor

This function return a tensor containing the max between the tensor and each value.

exp(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to exp

Returns:

the exped tensor

This function return a tensor containing the exp of the tensor.

log(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to log

Returns:

the loged tensor

This function return a tensor containing the log of the tensor.

matmul(left: dtorch.jtensors.JTensors, right: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:
  • left – the left tensor

  • right – the right tensor

Returns:

the multiplied tensor

This function return a tensor containing the multiplication of the left tensor with the right tensor.

sum(tensor: dtorch.jtensors.JTensors, axis: Tuple[int] | None = None, keepdims: bool = False) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to sum

  • axis – the axis to sum. Defaults to None.

  • keepdims – whether to keep the dimensions. Defaults to False.

Returns:

the summed tensor

This function return a tensor containing the sum of the tensor. If the axis is not None, it will sum the tensor along the given axis. If the keepdims is True, it will keep the dimensions of the tensor.

squeeze(tensor: dtorch.jtensors.JTensors, axis: int) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to squeeze

  • axis – the axis to squeeze

Returns:

the squeezed tensor

This function return a tensor containing the squeezed tensor. It will remove the dimension of the tensor along the given axis.

unsqueeze(tensor: dtorch.jtensors.JTensors, axis: int) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to unsqueeze

  • axis – the axis to unsqueeze

Returns:

the unsqueezed tensor

This function return a tensor containing the unsqueezed tensor. It will add a dimension of the tensor along the given axis.

reshape(tensor: dtorch.jtensors.JTensors, shape: Tuple[int]) dtorch.jtensors.JTensors
Parameters:
  • tensor – the tensor to reshape

  • shape – the new shape of the tensor

Returns:

the reshaped tensor

This function return a tensor containing the reshaped tensor. It will reshape the tensor to the given shape.

arange(start: int, end: int, step: int = 1) dtorch.jtensors.JTensors
Parameters:
  • start – the start of the range

  • end – the end of the range

  • step – the step of the range. Defaults to 1.

Returns:

the ranged tensor

This function return a tensor containing the ranged tensor. It will create a tensor containing the values from start to end with the given step.

tensor(list: list | np.ndarray, require_grads: bool = False, dtype: type | np.dtype = np.float64) dtorch.jtensors.JTensors
Parameters:
  • list – the list to convert to tensor

  • require_grads – whether the tensor require gradients. Defaults to False.

  • dtype – the type of the tensor. Defaults to np.float64.

Returns:

the converted tensor

This function return a tensor containing the converted tensor. It will convert the list to a tensor.

random(*shape: int) dtorch.jtensors.JTensors
Parameters:

shape – the shape of the random tensor

Returns:

the random tensor

This function return a tensor containing the random tensor. It will create a tensor containing random values.

ones(*shape: int, requires_grad: bool = False) dtorch.jtensors.JTensors
Parameters:
  • shape – the shape of the ones tensor

  • requires_grad – whether the tensor require gradients. Defaults to False.

Returns:

the ones tensor

This function return a tensor containing ones of the given shape.

zeros(*shape: int, requires_grad: bool = False) dtorch.jtensors.JTensors
Parameters:
  • shape – the shape of the zeros tensor

  • requires_grad – whether the tensor require gradients. Defaults to False.

Returns:

the zeros tensor

This function return a tensor containing zeros of the given shape.

xavier(nb_feat: int, size: int, require_grads: bool | None = False) dtorch.jtensors.JTensors
Parameters:
  • nb_feat – the number of features

  • size – the size of the tensor

  • require_grads – whether the tensor require gradients. Defaults to False.

Returns:

the xavier tensor

It will create a tensor containing random values following the xavier initialization.

zeros_like(tensor: dtorch.jtensors.JTensors) dtorch.jtensors.JTensors
Parameters:

tensor – the tensor to zeros like

Returns:

the zeros like tensor

This function return a tensor containing zeros like the given tensor.

uniform_(_from: float | int, _to: float | int, size: int, require_grads: bool = False)
Parameters:
  • _from – the start of the range

  • _to – the end of the range

  • size – the size of the tensor

  • require_grads – whether the tensor require gradients. Defaults to False.

Returns:

the uniform tensor

It will create a tensor containing random values following the uniform initialization.