Maths
Last updated
Last updated
Helper module for mathematical processing.
These functions and classes are only used internally, meaning an end-user shouldn’t need to access anything here.
static
⇒ Float32Array
⇒ Array.<number>
⇒ Float32Array
⇒ void
⇒ void
⇒ void
⇒ void
⇒ void
⇒ void
⇒ void
⇒ *
⇒ Array.<number>
⇒ any
⇒ number
⇒ Array
⇒ number
⇒ number
⇒ Array.<number>
⇒ Array.<number>
⇒ Array.<number>
⇒ number
inner
: Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
Throws:
Error
FFT size must be a power of two and bigger than 1.
size
number
The size of the input array. Must be a power of two and bigger than 1.
Create a complex number array with size 2 * size
Converts a complex number representation stored in a Float32Array to an array of real numbers.
complex
Float32Array
The complex number representation to be converted.
[storage]
Array.<number>
An optional array to store the result in.
Convert a real-valued input array to a complex-valued output array.
input
Float32Array
The real-valued input array.
[storage]
Float32Array
Optional buffer to store the output array.
Completes the spectrum by adding its mirrored negative frequency components.
spectrum
Float32Array
The input spectrum.
Performs a Fast Fourier Transform (FFT) on the given input data and stores the result in the output buffer.
Error
Input and output buffers must be different.
out
Float32Array
The output buffer to store the result.
data
Float32Array
The input data to transform.
Performs a real-valued forward FFT on the given input buffer and stores the result in the given output buffer. The input buffer must contain real values only, while the output buffer will contain complex values. The input and output buffers must be different.
Error
If the input and output buffers are the same.
out
Float32Array
The output buffer.
data
Float32Array
The input buffer containing real values.
Performs an inverse FFT transformation on the given data
array, and stores the result in out
. The out
array must be a different buffer than the data
array. The out
array will contain the result of the transformation. The data
array will not be modified.
Error
If `out` and `data` refer to the same buffer.
out
Float32Array
The output buffer for the transformed data.
data
Float32Array
The input data to transform.
Performs a radix-4 implementation of a discrete Fourier transform on a given set of data.
out
Float32Array
The output buffer for the transformed data.
data
Float32Array
The input buffer of data to be transformed.
inv
number
A scaling factor to apply to the transform.
Performs a radix-2 implementation of a discrete Fourier transform on a given set of data.
data
Float32Array
The input buffer of data to be transformed.
out
Float32Array
The output buffer for the transformed data.
outOff
number
The offset at which to write the output data.
off
number
The offset at which to begin reading the input data.
step
number
The step size for indexing the input data.
Performs radix-4 transformation on input data of length 8
data
Float32Array
Input data array of length 8
out
Float32Array
Output data array of length 8
outOff
number
Index of output array to start writing from
off
number
Index of input array to start reading from
step
number
Step size between elements in input array
inv
number
Scaling factor for inverse transform
Real input radix-4 implementation
out
Float32Array
Output array for the transformed data
data
Float32Array
Input array of real data to be transformed
inv
number
The scale factor used to normalize the inverse transform
Performs a single real input radix-2 transformation on the provided data
data
Float32Array
The input data array
out
Float32Array
The output data array
outOff
number
The output offset
off
number
The input offset
step
number
The step
Computes a single real-valued transform using radix-4 algorithm. This method is only called for len=8.
data
Float32Array
The input data array.
out
Float32Array
The output data array.
outOff
number
The offset into the output array.
off
number
The offset into the input array.
step
number
The step size for the input array.
inv
number
The value of inverse.
input
TypedArray
Helper method to transpose a AnyTypedArray
directly
array
T
dims
Array.<number>
axes
Array.<number>
Compute the softmax of an array of numbers.
arr
Array.<number>
The array of numbers to compute the softmax of.
Calculates the logarithm of the softmax function for the input array.
arr
Array.<number>
The input array to calculate the log_softmax function for.
Calculates the dot product of two arrays.
arr1
Array.<number>
The first array.
arr2
Array.<number>
The second array.
Get the top k items from an iterable, sorted by descending order
items
Array
The items to be sorted
[top_k]
number
0
The number of top items to return (default: 0 = return all)
Computes the cosine similarity between two arrays.
arr1
Array.<number>
The first array.
arr2
Array.<number>
The second array.
Calculates the magnitude of a given array.
arr
Array.<number>
The array to calculate the magnitude of.
Returns the value and index of the minimum element in an array.
Error
If array is empty.
arr
Array.<number>
array of numbers.
Returns the value and index of the maximum element in an array.
Error
If array is empty.
arr
Array.<number>
array of numbers.
Return the Discrete Fourier Transform sample frequencies.
TypeError
If n is not an integer.
n
number
Window length
[d]
number
1.0
Sample spacing (inverse of the sampling rate). Defaults to 1.
Example
Copied
Performs median filter on the provided data. Padding is done by mirroring the data.
data
AnyTypedArray
The input array
windowSize
number
The window size
Helper function to round a number to a given number of decimals
num
number
The number to round
decimals
number
The number of decimals
FFT class provides functionality for performing Fast Fourier Transform on arrays Code adapted from
Kind: static class of
⇒ Float32Array
⇒ Array.<number>
⇒ Float32Array
⇒ void
⇒ void
⇒ void
⇒ void
⇒ void
⇒ void
⇒ void
Kind: instance method of
Returns: Float32Array
- A complex number array with size 2 * size
Kind: instance method of
Returns: Array.<number>
- An array of real numbers representing the input complex number representation.
Kind: instance method of
Returns: Float32Array
- The complex-valued output array.
Kind: instance method of
Kind: instance method of Throws:
Kind: instance method of Throws:
Kind: instance method of Throws:
Kind: instance method of
Kind: instance method of
Kind: instance method of
Kind: instance method of
Kind: instance method of
Kind: instance method of
Kind: static method of
Kind: static method of
Returns: *
- The transposed array and the new shape.
Kind: static method of
Returns: Array.<number>
- The softmax array.
Kind: static method of
Returns: any
- The resulting log_softmax array.
Kind: static method of
Returns: number
- The dot product of arr1 and arr2.
Kind: static method of
Returns: Array
- The top k items, sorted by descending order
Kind: static method of
Returns: number
- The cosine similarity between the two arrays.
Kind: static method of
Returns: number
- The magnitude of the array.
Kind: static method of
Returns: Array.<number>
- the value and index of the minimum element, of the form: [valueOfMin, indexOfMin]
Throws:
Kind: static method of
Returns: Array.<number>
- the value and index of the maximum element, of the form: [valueOfMax, indexOfMax]
Throws:
Code adapted from Original Python doc:
Kind: static method of
Returns: Array.<number>
- Array of length Math.floor(n / 2) + 1;
containing the sample frequencies.
Throws:
Kind: static method of
Kind: static method of
Returns: number
- The rounded number
Kind: inner typedef of