Types
ConvolveMode = enum full, same, valid
- Source Edit
Procs
proc abs(t: Tensor[Complex[float32]]): Tensor[float32] {.noinit, ...raises: [], tags: [], forbids: [].}
- Return a Tensor with absolute values of all elements Source Edit
proc almostEqual[T: SomeFloat | Complex32 | Complex64](t1, t2: Tensor[T]; unitsInLastPlace: Natural = 4): Tensor[bool] {.noinit.}
-
Element-wise almostEqual function
Checks whether pairs of elements of two tensors are almost equal, using the machine epsilon.
For more details check the section covering the almostEqual procedure in nim's standard library documentation.
Inputs:
- t1, t2: Input (floating point or complex) tensors of the same shape.
- unitsInLastPlace: The max number of units in the last place difference tolerated when comparing two numbers. The larger the value, the more error is allowed. A 0 value means that two numbers must be exactly the same to be considered equal.
Result:
- A new boolean tensor of the same shape as the inputs, in which elements are true if the two values in the same position on the two input tensors are almost equal (and false if they are not).
Note:
- You can combine this function with all to check if two real tensors are almost equal.
proc classify[T: SomeFloat](t: Tensor[T]): Tensor[FloatClass] {.noinit.}
-
Element-wise classify function (returns a tensor with the float class of each element).
Returns: A FloatClass tensor where each value is one of the following:
- fcNormal: value is an ordinary nonzero floating point value
- fcSubnormal: value is a subnormal (a very small) floating point value
- fcZero: value is zero
- fcNegZero: value is the negative zero
- fcNan: value is Not a Number (NaN)
- fcInf: value is positive infinity
- fcNegInf: value is negative infinity
proc convolve[T: SomeNumber | Complex32 | Complex64](t1, t2: Tensor[T]; mode = ConvolveMode.full): Tensor[T] {.noinit.}
-
Returns the discrete, linear convolution of two one-dimensional tensors.
The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal (Wikipedia, “Convolution”, https://en.wikipedia.org/wiki/Convolution).
The convolution is defined as the integral of the product of the two tensors after one is reflected about the y-axis and shifted n positions, for all values of n in which the tensors overlap (since the integral will be zero outside of that window).
Inputs:
- t1, t2: Input tensors of size N and M respectively.
- mode: Convolution mode (full, same, valid):
- full: This is the default mode. It returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen.
- same: Returns an output of length max(M, N). Boundary effects are still visible.
- valid: Returns output of length max(M, N) - min(M, N) + 1. The convolution is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.
Output:
- Convolution tensor of same type as the inputs and size according to the mode.
Notes:
- The API of this function is the same as the one of numpy.convolve.
proc copySign[T: SomeFloat](t1, t2: Tensor[T]): Tensor[T] {.noinit.}
-
Element-wise copySign function (combines 2 tensors, taking the magnitudes from t1 and the signs from t2)
This uses nim's copySign under the hood, and thus has the same properties. That is, it works for values which are NaN, infinity or zero (all of which can carry a sign) but does not work for integers.
Source Edit proc correlate[T: Complex32 | Complex64](t1, t2: Tensor[T]; mode = CorrelateMode.valid): Tensor[T] {.noinit.}
-
Returns the cross-correlation of two one-dimensional complex tensors.
The correlation is defined as the integral of the product of the two tensors after the second one is conjugated and shifted n positions, for all values of n in which the tensors overlap (since the integral will be zero outside of that window).
Inputs:
- t1, t2: Input tensors of size N and M respectively.
- mode: Correlation mode (full, same, valid):
- full: It returns the correlation at each point of overlap, with an output shape of (N+M-1,). At the end-points of the correlation, the signals do not overlap completely, and boundary effects may be seen.
- same: Returns an output of length max(M, N). Boundary effects are still visible.
- valid: This is the default mode. Returns output of length max(M, N) - min(M, N) + 1. The correlation is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.
Output:
- Correlation tensor of same type as the inputs and size according to the mode.
Notes:
- The API of this function is the same as the one of numpy.correlate.
- Note that (as with np.correlate) the default correlation mode is valid, which is different than the default convolution mode (full).
proc correlate[T: SomeNumber](t1, t2: Tensor[T]; mode = CorrelateMode.valid): Tensor[ T] {.noinit.}
-
Returns the cross-correlation of two one-dimensional real tensors.
The correlation is defined as the integral of the product of the two tensors after the second one is shifted n positions, for all values of n in which the tensors overlap (since the integral will be zero outside of that window).
Inputs:
- t1, t2: Input tensors of size N and M respectively.
- mode: Correlation mode (full, same, valid):
- full: It returns the correlation at each point of overlap, with an output shape of (N+M-1,). At the end-points of the correlation, the signals do not overlap completely, and boundary effects may be seen.
- same: Returns an output of length max(M, N). Boundary effects are still visible.
- valid: This is the default mode. Returns output of length max(M, N) - min(M, N) + 1. The correlation is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.
Output:
- Correlation tensor of same type as the inputs and size according to the mode.
Notes:
- The API of this function is the same as the one of numpy.correlate.
- Note that (as with np.correlate) the default correlation mode is valid, which is different than the default convolution mode (full).
proc elwise_div[T: SomeFloat](a, b: Tensor[T]): Tensor[T] {.noinit.}
- Element-wise division Source Edit
proc elwise_div[T: SomeInteger](a, b: Tensor[T]): Tensor[T] {.noinit.}
- Element-wise division Source Edit
proc elwise_mul[T](a, b: Tensor[T]): Tensor[T] {.noinit.}
- Element-wise multiply Source Edit
proc floorMod[T: SomeNumber](t1, t2: Tensor[T]): Tensor[T] {.noinit.}
- Broadcasted floorMod operation: floorMod(tensor, tensor). Source Edit
proc mcopySign[T: SomeFloat](t1: var Tensor[T]; t2: Tensor[T])
-
In-place element-wise copySign function (changes the signs of the elements of t1 to match those of t2)
This uses nim's copySign under the hood, and thus has the same properties. That is, it works for values which are NaN, infinity or zero (all of which can carry a sign) but does not work for integers.
Source Edit proc melwise_div[T: SomeFloat](a: var Tensor[T]; b: Tensor[T])
- Element-wise division (in-place) Source Edit
proc melwise_div[T: SomeInteger](a: var Tensor[T]; b: Tensor[T])
- Element-wise division (in-place) Source Edit
proc melwise_mul[T](a: var Tensor[T]; b: Tensor[T])
- Element-wise multiply Source Edit
proc mreciprocal[T: Complex[float32] or Complex[float64]](t: var Tensor[T])
- Apply the reciprocal 1/x in-place to all elements of the Tensor Source Edit
proc mreciprocal[T: SomeFloat](t: var Tensor[T])
- Apply the reciprocal 1/x in-place to all elements of the Tensor Source Edit
proc reciprocal[T: Complex[float32] or Complex[float64]](t: Tensor[T]): Tensor[T] {. noinit.}
- Return a tensor with the reciprocal 1/x of all elements Source Edit
proc reciprocal[T: SomeFloat](t: Tensor[T]): Tensor[T] {.noinit.}
- Return a tensor with the reciprocal 1/x of all elements Source Edit
proc sinc[T: SomeFloat](t: Tensor[T]; normalized: static bool = true): Tensor[T] {. noinit.}
-
Return the normalized or non-normalized sinc function of a Tensor
For values other than 0, the normalized sinc function is equal to sin(PI * x) / (PI * x), while the non-normalized sync function is equal to sin(x) / x. sinc(0) takes the limit value 1 in both cases, making sinc not only everywhere continuous but also infinitely differentiable.
Inputs:
- t: Input real tensor.
- normalized: Select whether to return the normalized or non-normalized sync. This argument is static so it must be set at compile time. The default is true (i.e. to return the normalized sync).
Result:
- New tensor with the sinc values of all the input tensor elements.
proc sinc[T: SomeFloat](x: T; normalized: static bool = true): T {.inline.}
-
Return the normalized or non-normalized sinc function.
For values other than 0, the normalized sinc function is equal to sin(PI * x) / (PI * x), while the non-normalized sync function is equal to sin(x) / x. sinc(0) takes the limit value 1 in both cases, making sinc not only everywhere continuous but also infinitely differentiable.
Inputs:
- t: Real input value.
- normalized: Select whether to return the normalized or non-normalized sync. This argument is static so it must be set at compile time. The default is true (i.e. to return the normalized sync).
Result:
- Calculated sinc value