Layers#
- ivy.adaptive_avg_pool1d(input, output_size)[source]#
Apply a 1D adaptive average pooling over an input signal composed of several input planes.
- Parameters:
input (
Union
[Array
,NativeArray
]) – Input array. Must have shape (N, C, L_in) or (C, L_in) where N is the batch dimension, C is the feature dimension, and L_in is the spatial dimension.output_size (
int
) – Spatial output size.
- Return type:
- Returns:
The result of the pooling operation. Will have shape (N, C, L_out) or
(C, L_out), where L_out = output_size
- ivy.adaptive_avg_pool2d(input, output_size)[source]#
Apply a 2D adaptive average pooling over an input signal composed of several input planes.
- Parameters:
input (
Union
[Array
,NativeArray
]) – Input array. Must have shape (N, C, H_in, W_in) or (C, H_in, W_in) where N is the batch dimension, C is the feature dimension, and H_in and W_in are the 2 spatial dimensions.output_size (
Union
[Sequence
[int
],int
]) – Spatial output size.
- Return type:
- Returns:
The result of the pooling operation. Will have shape (N, C, S_0, S_1) or
(C, S_0, S_1), where S = output_size
- ivy.avg_pool1d(x, kernel, strides, padding, /, *, data_format='NWC', count_include_pad=False, ceil_mode=False, division_override=None, out=None)[source]#
Compute a 1-D avg pool given 3-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input image [batch_size, w, d_in].kernel (
Union
[int
,Tuple
[int
]]) – Size of the kernel i.e., the sliding window for each dimension of input. [w].strides (
Union
[int
,Tuple
[int
]]) – The stride of the sliding window for each dimension of input.padding (
str
) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.data_format (
str
) – NWC” or “NCW”. Defaults to “NWC”. (default:'NWC'
)count_include_pad (
bool
) – Whether to include padding in the averaging calculation. (default:False
)ceil_mode (
bool
) – Whether to use ceil or floor for creating the output shape. (default:False
)division_override (
Optional
[int
]) – If specified, it will be used as the divisor, (default:None
) otherwise kernel_size will be used.out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
)
- Return type:
- Returns:
ret – The result of the pooling operation.
Both the description and the type hints above assumes an array input
for simplicity, but this function is *nestable, and therefore*
also accepts
ivy.Container
instances in place of any ofthe arguments.
Examples
>>> x = ivy.arange(0, 24.).reshape((2, 3, 4)) >>> print(ivy.avg_pool1d(x, 2, 2, 'SAME')) ivy.array([[[ 2., 3., 4., 5.], [ 8., 9., 10., 11.]],
- [[14., 15., 16., 17.],
[20., 21., 22., 23.]]])
>>> x = ivy.arange(0, 24.).reshape((2, 3, 4)) >>> print(ivy.avg_pool1d(x, 2, 2, 'VALID')) ivy.array([[[ 2., 3., 4., 5.]],
[[14., 15., 16., 17.]]])
- ivy.avg_pool2d(x, kernel, strides, padding, /, *, data_format='NHWC', count_include_pad=False, ceil_mode=False, out=None)[source]#
Compute a 2-D average pool given 4-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input image [batch_size,h,w,d_in].kernel (
Union
[int
,Tuple
[int
],Tuple
[int
,int
]]) – Size of the kernel i.e., the sliding window for each dimension of input. [h,w].strides (
Union
[int
,Tuple
[int
],Tuple
[int
,int
]]) – The stride of the sliding window for each dimension of input.padding (
str
) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimensio paddings.data_format (
str
) – NHWC” or “NCHW”. Defaults to “NHWC”. (default:'NHWC'
)count_include_pad (
bool
) – Whether to include padding in the averaging calculation. (default:False
)ceil_mode (
bool
) – Whether to use ceil or floor for creating the output shape. (default:False
)out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
)
- Return type:
- Returns:
ret – The result of the pooling operation.
Both the description and the type hints above assumes an array input
for simplicity, but this function is *nestable, and therefore*
also accepts
ivy.Container
instances in place of any ofthe arguments.
Examples
>>> x = ivy.arange(12.).reshape((2, 1, 3, 2)) >>> print(ivy.avg_pool2d(x, (2, 2), (1, 1), 'SAME')) ivy.array([[[[ 1., 2.], [ 3., 4.], [ 4., 5.]]],
- [[[ 7., 8.],
[ 9., 10.], [10., 11.]]]])
>>> x = ivy.arange(48.).reshape((2, 4, 3, 2)) >>> print(ivy.avg_pool2d(x, 3, 1, 'VALID')) ivy.array([[[[ 8., 9.]],
[[14., 15.]]],
[[[32., 33.]],
[[38., 39.]]]])
- ivy.avg_pool3d(x, kernel, strides, padding, /, *, data_format='NDHWC', count_include_pad=False, ceil_mode=False, divisor_override=None, out=None)[source]#
Compute a 3-D avg pool given 5-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input volume [batch_size,d,h,w,d_in].kernel (
Union
[int
,Tuple
[int
],Tuple
[int
,int
,int
]]) – Convolution filters [d,h,w].strides (
Union
[int
,Tuple
[int
],Tuple
[int
,int
,int
]]) – The stride of the sliding window for each dimension of input.padding (
str
) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.data_format (
str
) – NDHWC” or “NCDHW”. Defaults to “NDHWC”. (default:'NDHWC'
)count_include_pad (
bool
) – Whether to include padding in the averaging calculation. (default:False
)ceil_mode (
bool
) – Whether to use ceil or floor for creating the output shape. (default:False
)divisor_override (
Optional
[int
]) – If specified, it will be used as divisor, otherwise kernel_size will be used. (default:None
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – The result of the pooling operation.
Both the description and the type hints above assumes an array input
for simplicity, but this function is *nestable, and therefore*
also accepts
ivy.Container
instances in place of any ofthe arguments.
Examples
>>> x = ivy.arange(48.).reshape((2, 3, 2, 2, 2)) >>> print(ivy.avg_pool3d(x,2,2,'VALID')) ivy.array([[[[[ 7., 8.]]]],
[[[[31., 32.]]]]])
>>> print(ivy.avg_pool3d(x,2,2,'SAME')) ivy.array([[[[[ 7., 8.]]],
[[[19., 20.]]]],
[[[[31., 32.]]],
[[[43., 44.]]]]])
- ivy.dct(x, /, *, type=2, n=None, axis=-1, norm=None, out=None)[source]#
Compute the 1D Discrete Cosine Tranformation of a given signal.
- Parameters:
x (
Union
[Array
,NativeArray
]) – The input signal.type (
Literal
[1, 2, 3, 4]) – The type of the dct. Must be 1, 2, 3 or 4. (default:2
)n (
Optional
[int
]) – The lenght of the transform. If n is less than the input signal lenght, (default:None
) then x is truncated, if n is larger then x is zero-padded.axis (
int
) – The axis to compute the DCT along. (default:-1
)norm (
Optional
[Literal
[‘ortho’]]) – The type of normalization to be applied. Must be either None or “ortho”. (default:None
)out (
Optional
[Union
[Array
,NativeArray
]]) – optional output array, for writing the result to. (default:None
)
- Return type:
Union
[Array
,NativeArray
]- Returns:
ret – Array containing the transformed input.
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
Examples
With
ivy.Array
input:>>> x = ivy.array([8, 16, 24, 32, 40, 48, 56, 64]) >>> ivy.dct(x, type=2, n=None, norm='ortho') ivy.array([102., -51.5, 0., -5.39, 0., -1.61, 0., -0.406])
>>> x = ivy.array([[[8, 16, 24, 32], [40, 48, 56, 64]], ... [[1, 2, 3, 4], [ 5, 6, 7, 8]]]) >>> ivy.dct(x, type=1, n=None, axis=0, norm=None) ivy.array([[[ 9., 18., 27., 36.], [45., 54., 63., 72.]], [[ 7., 14., 21., 28.], [35., 42., 49., 56.]]])
>>> x = ivy.array([[ 8.1, 16.2, 24.3, 32.4], ... [40.5, 48.6, 56.7, 64.8]]) >>> y = ivy.zeros((2, 4), dtype=ivy.float32) >>> ivy.dct(x, type=1, n=None, norm=None, out=y) >>> print(y) ivy.array([[ 1.22e+02, -3.24e+01, 1.91e-06, -8.10e+00], [ 3.16e+02, -3.24e+01, 3.81e-06, -8.10e+00]])
>>> x = ivy.array([8., 16., 24., 32., 40., 48., 56., 64.]) >>> ivy.dct(x, type=4, n=None, norm=None, out=x) >>> print(x) ivy.array([ 279. , -280. , 128. , -115. , 83.7, -79.5, 69.8, -68.7])
With one
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8])) >>> ivy.dct(x, type=3, n=None, norm='ortho') { a: ivy.array([79.5, -70.4, 30., -23.6, 13.9, -10.1, 5.2, -1.95]), b: ivy.array([9.94, -8.8, 3.75, -2.95, 1.74, -1.26, 0.65, -0.244]) }
With multiple
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8])) >>> container_n = ivy.Container(a=9, b=4) >>> container_type = ivy.Container(a=2, b=1) >>> container_norm = ivy.Container(a="ortho", b=None) >>> ivy.dct(x, type=container_type, n=container_n, norm=container_norm) { a: ivy.array([96., -28.2, -31.9, 22.9, -26., 19.8, -17., 10.9, -5.89]), b: ivy.array([15., -4., 0., -1.]) }
- ivy.dft(x, /, *, axis=1, inverse=False, onesided=False, dft_length=None, norm='backward', out=None)[source]#
Compute the discrete Fourier transform of input.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT.axis (
int
) – The axis on which to perform the DFT. By default this (default:1
) value is set to 1, which corresponds to the first dimension after the batch index.inverse (
bool
) – Whether to perform the inverse discrete fourier transform. (default:False
) By default this value is set to False.onesided (
bool
) – If onesided is True, only values for w in [0, 1, 2, …, floor(n_fft/2) + 1] (default:False
) are returned because the real-to-complex Fourier transform satisfies the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]*. Note if the input or window tensors are complex, then onesided output is not possible. Enabling onesided with real inputs performs a Real-valued fast Fourier transform (RFFT). When invoked with real or complex valued input, the default value is False. Values can be True or False.dft_length (
Optional
[Union
[int
,Tuple
[int
]]]) – The length of the signal.If greater than the axis dimension, (default:None
) the signal will be zero-padded up to dft_length. If less than the axis dimension, only the first dft_length values will be used as the signal. It’s an optional value.norm (
str
) – Optional argument, “backward”, “ortho” or “forward”. Defaults to be (default:'backward'
) “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.out (
Optional
[Array
]) – Optional output array, for writing the result to. It must (default:None
) have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – The Fourier Transform of the input vector.If onesided is False, the following shape is expected: [batch_idx][signal_dim1][signal_dim2] …[signal_dimN][2]. If axis=0 and onesided is True, the following shape is expected: [batch_idx][floor(signal_dim1/2)+1][signal_dim2]…[signal_dimN][2]. If axis=1 and onesided is True, the following shape is expected: [batch_idx][signal_dim1][floor(signal_dim2/2)+1]…[signal_dimN][2]. If axis=N-1 and onesided is True, the following shape is expected: [batch_idx][signal_dim1][signal_dim2]…[floor(signal_dimN/2)+1][2]. The signal_dim at the specified axis is equal to the dft_length.
- ivy.dropout1d(x, prob, /, *, training=True, data_format='NWC', out=None)[source]#
Randomly zero out entire channels with probability prob using samples from a Bernoulli distribution and the remaining channels are scaled by (1/1-prob). In this case, dropout1d performs a channel-wise dropout but assumes a channel is a 1D feature map.
- Parameters:
x (
Union
[Array
,NativeArray
]) – a 2D or 3D input array. Should have a floating-point data type.prob (
float
) – probability of a channel to be zero-ed.training (
bool
) – controls whether dropout1d is performed during training or ignored (default:True
) during testing.data_format (
str
) – “NWC” or “NCW”. Defaults to “NWC”. (default:'NWC'
)out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
) It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret –
- an array with some channels zero-ed and the rest of channels are
scaled by (1/1-prob).
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
Examples
With
ivy.Array
input:>>> x = ivy.array([1, 1, 1]).reshape([1, 1, 3]) >>> y = ivy.dropout1d(x, 0.5) >>> print(y) ivy.array([[[2., 0, 2.]]])
>>> x = ivy.array([1, 1, 1]).reshape([1, 1, 3]) >>> y = ivy.dropout1d(x, 1, training=False, data_format="NCW") >>> print(y) ivy.array([[[1, 1, 1]]])
With one
ivy.Container
input: >>> x = ivy.Container(a=ivy.array([100, 200, 300]).reshape([1, 1, 3]), … b=ivy.array([400, 500, 600]).reshape([1, 1, 3])) >>> y = ivy.dropout1d(x, 0.5) >>> print(y) { a: ivy.array([[[200., 400., 0.]]]), b: ivy.array([[[0., 0., 0.]]]) }
- ivy.dropout3d(x, prob, /, *, training=True, data_format='NDHWC', out=None)[source]#
Randomly zero out entire channels with probability prob using samples from a Bernoulli distribution and the remaining channels are scaled by (1/1-prob). In this case, dropout3d performs a channel-wise dropout but assumes a channel is a 1D feature map.
- Parameters:
x (
Union
[Array
,NativeArray
]) – a 4D or 5D input array. Should have a floating-point data type.prob (
float
) – probability of a channel to be zero-ed.training (
bool
) – controls whether dropout3d is performed during training or ignored (default:True
) during testing.data_format (
str
) – “NDHWC” or “NCDHW”. Defaults to “NDHWC”. (default:'NDHWC'
)out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
) It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret –
- an array with some channels zero-ed and the rest of channels are
scaled by (1/1-prob).
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
- ivy.embedding(weights, indices, /, *, max_norm=None, out=None)[source]#
Embeds a given tensor of indices using a given tensor of weights.
- Parameters:
weights (
Union
[Array
,NativeArray
]) – The weights tensor.indices (
Union
[Array
,NativeArray
]) – The indices tensor.max_norm (
Optional
[int
]) – The maximum norm of the embeddings. (default:None
)out (
Optional
[Array
]) – Optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – The result of the embedding operation.
Examples
>>> weights = ivy.array([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]) >>> indices = ivy.array([0, 2]) >>> print(ivy.embedding(weights, indices, max_norm=5)) ivy.array([[1., 2., 3.], [7., 8., 9.]])
- ivy.fft(x, dim, /, *, norm='backward', n=None, out=None)[source]#
Compute the one dimensional discrete Fourier transform given input at least 1-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT.dim (
int
) – The dimension along which to take the one dimensional FFT.norm (
str
) – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. (default:'backward'
) “backward” indicates no normalization. “ortho” indicates normalization by $frac{1}{sqrt{n}}$. “forward” indicates normalization by $frac{1}{n}$.n (
Optional
[Union
[int
,Tuple
[int
]]]) – Optional argument indicating the sequence length, if given, the input would be (default:None
) padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1.out (
Optional
[Array
]) – Optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – The result of the FFT operation.
Examples
>>> ivy.fft(np.exp(2j * np.pi * np.arange(8) / 8), 0) ivy.array([-3.44509285e-16+1.14423775e-17j, 8.00000000e+00-8.11483250e-16j, 2.33486982e-16+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j, 9.95799250e-17+2.33486982e-16j, 0.00000000e+00+7.66951701e-17j, 1.14423775e-17+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j]) >>> ivy.fft(np.exp(2j * np.pi * np.arange(8) / 8), 0, n=16) ivy.array([-3.44509285e-16+1.14423775e-17j, 1.00000000e+00+5.02733949e+00j, 8.00000000e+00-8.11483250e-16j, 1.00000000e+00-5.02733949e+00j, 2.33486982e-16+1.22464680e-16j, 1.00000000e+00-1.49660576e+00j, 0.00000000e+00+1.22464680e-16j, 1.00000000e+00-6.68178638e-01j, 9.95799250e-17+2.33486982e-16j, 1.00000000e+00-1.98912367e-01j, 0.00000000e+00+7.66951701e-17j, 1.00000000e+00+1.98912367e-01j, 1.14423775e-17+1.22464680e-16j, 1.00000000e+00+6.68178638e-01j, 0.00000000e+00+1.22464680e-16j, 1.00000000e+00+1.49660576e+00j]) >>> ivy.fft(np.exp(2j * np.pi * np.arange(8) / 8), 0, norm="ortho") ivy.array([-1.21802426e-16+4.04549134e-18j, 2.82842712e+00-2.86902654e-16j, 8.25501143e-17+4.32978028e-17j, 0.00000000e+00+4.32978028e-17j, 3.52068201e-17+8.25501143e-17j, 0.00000000e+00+2.71158374e-17j, 4.04549134e-18+4.32978028e-17j, 0.00000000e+00+4.32978028e-17j])
- ivy.idct(x, /, *, type=2, n=None, axis=-1, norm=None, out=None)[source]#
Compute the 1D Inverse Discrete Cosine Tranformation of a given signal.
- Parameters:
x (
Union
[Array
,NativeArray
]) – The input signal.type (
Literal
[1, 2, 3, 4]) – The type of the idct. Must be 1, 2, 3 or 4. (default:2
)n (
Optional
[int
]) – The length of the transform. If n is less than the input signal length, (default:None
) then x is truncated, if n is larger then x is zero-padded.axis (
int
) – The axis to compute the IDCT along. (default:-1
)norm (
Optional
[Literal
[‘ortho’]]) – The type of normalization to be applied. Must be either None or “ortho”. (default:None
)out (
Optional
[Union
[Array
,NativeArray
]]) – optional output array, for writing the result to. (default:None
)
- Return type:
Union
[Array
,NativeArray
]- Returns:
ret – Array containing the transformed input.
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
Examples
With
ivy.Array
input:>>> x = ivy.array([8, 16, 24, 32, 40, 48, 56, 64]) >>> ivy.idct(x, type=2, n=None, norm='ortho') ivy.array([ 79.49862671, -70.37691498, 30.00390816, -23.58938599, 13.92713165, -10.078475 , 5.19664812, -1.95411837])
>>> x = ivy.array([[[8, 16, 24, 32], [40, 48, 56, 64]], ... [[1, 2, 3, 4], [ 5, 6, 7, 8]]]) >>> ivy.idct(x, type=1, n=None, axis=0, norm=None) ivy.array([[[ 9., 18., 27., 36.], [45., 54., 63., 72.]], [[ 7., 14., 21., 28.], [35., 42., 49., 56.]]])
>>> x = ivy.array([[ 8.1, 16.2, 24.3, 32.4], ... [40.5, 48.6, 56.7, 64.8]]) >>> y = ivy.zeros((2, 4), dtype=ivy.float32) >>> ivy.idct(x, type=1, n=None, norm=None, out=y) >>> print(y) ivy.array([[ 1.21500000e+02, -3.24000015e+01, 1.90734863e-06, -8.10000420e+00], [ 3.15899994e+02, -3.24000053e+01, 3.81469727e-06, -8.09999847e+00]])
>>> x = ivy.array([8., 16., 24., 32., 40., 48., 56., 64.]) >>> ivy.idct(x, type=4, n=None, norm=None, out=x) >>> print(x) ivy.array([ 279.4135742 , -279.6779785 , 128.3770599 , -114.8719864 , 83.72109985, -79.52869415, 69.79182434, -68.72489166])
With one
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8])) >>> ivy.idct(x, type=3, n=None, norm='ortho') { a: ivy.array([1.01823372e+02, -5.15385818e+01, 1.36371455e-06, -5.38763905e+00, 0., -1.60722279e+00, -8.80319249e-08, -4.05617893e-01]), b: ivy.array([1.27279215e+01, -6.44232273e+00, 1.70464318e-07, -6.73454881e-01, 0., -2.00902849e-01, -1.10039906e-08, -5.07022366e-02]) }
With multiple
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8])) >>> container_n = ivy.Container(a=9, b=4) >>> container_type = ivy.Container(a=2, b=1) >>> container_norm = ivy.Container(a="ortho", b=None) >>> ivy.idct(x, type=container_type, n=container_n, norm=container_norm) { a: ivy.array([86.29723358, -66.6950531, 9.93914509, 2.88008738, -16.18951225, 18.06697273, -17.57439804, 11.68861485, -4.41308832]), b: ivy.array([15., -4., -2.22044605e-16, -1.]) }
- ivy.ifft(x, dim, *, norm='backward', n=None, out=None)[source]#
Compute the one dimensional discrete Fourier transform given input at least 1-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input volume […,d_in,…], where d_in indicates the dimension that needs IFFT.dim (
int
) – The dimension along which to take the one dimensional IFFT.norm (
str
) – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. (default:'backward'
) “backward” indicates no normalization. “ortho” indicates normalization by $frac{1}{sqrt{n}}$. “forward” indicates normalization by $frac{1}{n}$.n (
Optional
[Union
[int
,Tuple
[int
]]]) – Optional argument indicating the sequence length, if given, the input would be (default:None
) padded with zero or truncated to length n before performing IFFT. Should be a integer greater than 1.out (
Optional
[Array
]) – Optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – The result of the IFFT operation.
Examples
>>> ivy.ifft(np.exp(2j * np.pi * np.arange(8) / 8), 0) ivy.array([-4.30636606e-17+1.43029718e-18j, 0.00000000e+00+1.53080850e-17j, 1.43029718e-18+1.53080850e-17j, 0.00000000e+00+9.58689626e-18j, 1.24474906e-17+2.91858728e-17j, 0.00000000e+00+1.53080850e-17j, 2.91858728e-17+1.53080850e-17j, 1.00000000e+00-1.01435406e-16j]) >>> ivy.ifft(np.exp(2j * np.pi * np.arange(8) / 8), 0, n=16) ivy.array([-2.15318303e-17+7.15148591e-19j, 6.25000000e-02+9.35378602e-02j, 0.00000000e+00+7.65404249e-18j, 6.25000000e-02+4.17611649e-02j, 7.15148591e-19+7.65404249e-18j, 6.25000000e-02+1.24320230e-02j, 0.00000000e+00+4.79344813e-18j, 6.25000000e-02-1.24320230e-02j, 6.22374531e-18+1.45929364e-17j, 6.25000000e-02-4.17611649e-02j, 0.00000000e+00+7.65404249e-18j, 6.25000000e-02-9.35378602e-02j, 1.45929364e-17+7.65404249e-18j, 6.25000000e-02-3.14208718e-01j, 5.00000000e-01-5.07177031e-17j, 6.25000000e-02+3.14208718e-01j]) >>> ivy.ifft(np.exp(2j * np.pi * np.arange(8) / 8), 0, norm="ortho") ivy.array([-1.21802426e-16+4.04549134e-18j, 0.00000000e+00+4.32978028e-17j, 4.04549134e-18+4.32978028e-17j, 0.00000000e+00+2.71158374e-17j, 3.52068201e-17+8.25501143e-17j, 0.00000000e+00+4.32978028e-17j, 8.25501143e-17+4.32978028e-17j, 2.82842712e+00-2.86902654e-16j])
- ivy.interpolate(x, size, /, *, mode='linear', scale_factor=None, recompute_scale_factor=None, align_corners=None, antialias=False, out=None)[source]#
Down/up samples the input to the given size. The algorithm used for interpolation is determined by mode.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array, Must have the shape [batch x channels x [optional depth] x [optional height] x width].size (
Union
[Sequence
[int
],int
]) – Output size.mode (
Literal
[‘linear’, ‘bilinear’, ‘trilinear’, ‘nearest’, ‘area’, ‘nearest_exact’, ‘tf_area’, ‘bicubic_tensorflow’, ‘bicubic’, ‘mitchellcubic’, ‘lanczos3’, ‘lanczos5’, ‘gaussian’]) – Interpolation mode. Can be one of the following: (default:'linear'
) - linear - bilinear - trilinear - nearest - nearest-exact - area - tf_area - bicubic - mitchellcubic - lanczos3 - lanczos5 - gaussianscale_factor (
Optional
[Union
[int
,Sequence
[int
]]]) – Multiplier for spatial size that defines the output size (overwriting size). (default:None
)align_corners (
Optional
[bool
]) – If True, the corner pixels of the input and output tensors are aligned, (default:None
) and thus preserving the values at the corner pixels. If False, the corner pixels are not aligned, and the interpolation uses edge value padding for out-of-boundary values. only has an effect when mode is ‘linear’, ‘bilinear’, ‘bicubic’ or ‘trilinear’. Default: Falseantialias (
bool
) – If True, antialiasing is applied when downsampling an image. (default:False
) Supported modes: ‘bilinear’, ‘bicubic’.out (
Optional
[Array
]) – Optional output array, for writing the result to. It must (default:None
) have a shape that the inputs broadcast to.
- Return type:
- Returns:
resized array
- ivy.max_pool1d(x, kernel, strides, padding, /, *, data_format='NWC', out=None)[source]#
Compute a 1-D max pool given 3-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input image [batch_size, w, d_in].kernel (
Union
[int
,Tuple
[int
]]) – Size of the kernel i.e., the sliding window for each dimension of input. [w].strides (
Union
[int
,Tuple
[int
]]) – The stride of the sliding window for each dimension of input.padding (
str
) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.data_format (
str
) – NWC” or “NCW”. Defaults to “NWC”. (default:'NWC'
)out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
)
- Return type:
- Returns:
ret – The result of the pooling operation.
Both the description and the type hints above assumes an array input
for simplicity, but this function is *nestable, and therefore*
also accepts
ivy.Container
instances in place of any ofthe arguments.
Examples
>>> x = ivy.arange(0, 24.).reshape((2, 3, 4)) >>> print(ivy.max_pool1d(x, 2, 2, 'SAME')) ivy.array([[[ 4., 5., 6., 7.], [ 8., 9., 10., 11.]],
- [[16., 17., 18., 19.],
[20., 21., 22., 23.]]])
>>> x = ivy.arange(0, 24.).reshape((2, 3, 4)) >>> print(ivy.max_pool1d(x, 2, 2, 'VALID')) ivy.array([[[ 4., 5., 6., 7.]],
[[16., 17., 18., 19.]]])
- ivy.max_pool2d(x, kernel, strides, padding, /, *, data_format='NHWC', dilation=1, ceil_mode=False, out=None)[source]#
Compute a 2-D max pool given 4-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input image [batch_size,h,w,d_in].kernel (
Union
[int
,Tuple
[int
],Tuple
[int
,int
]]) – Size of the kernel i.e., the sliding window for each dimension of input. [h,w].strides (
Union
[int
,Tuple
[int
],Tuple
[int
,int
]]) – The stride of the sliding window for each dimension of input.padding (
Union
[str
,int
,Tuple
[int
],Tuple
[int
,int
]]) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.data_format (
str
) – NHWC” or “NCHW”. Defaults to “NHWC”. (default:'NHWC'
)out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
)
- Return type:
- Returns:
ret – The result of the pooling operation.
Both the description and the type hints above assumes an array input
for simplicity, but this function is *nestable, and therefore*
also accepts
ivy.Container
instances in place of any ofthe arguments.
Examples
>>> x = ivy.arange(12.).reshape((2, 1, 3, 2)) >>> print(ivy.max_pool2d(x, (2, 2), (1, 1), 'SAME')) ivy.array([[[[ 2, 3], [ 4, 5], [ 4, 5]]],
- [[[ 8, 9],
[10, 11], [10, 11]]]])
>>> x = ivy.arange(48.).reshape((2, 4, 3, 2)) >>> print(ivy.max_pool2d(x, 3, 1, 'VALID')) ivy.array([[[[16, 17]],
[[22, 23]]],
[[[40, 41]],
[[46, 47]]]])
- ivy.max_pool3d(x, kernel, strides, padding, /, *, data_format='NDHWC', out=None)[source]#
Compute a 3-D max pool given 5-D input x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input volume [batch_size,d,h,w,d_in].kernel (
Union
[int
,Tuple
[int
],Tuple
[int
,int
,int
]]) – Convolution filters [d,h,w].strides (
Union
[int
,Tuple
[int
],Tuple
[int
,int
,int
]]) – The stride of the sliding window for each dimension of input.padding (
str
) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.data_format (
str
) – NDHWC” or “NCDHW”. Defaults to “NDHWC”. (default:'NDHWC'
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – The result of the pooling operation.
Both the description and the type hints above assumes an array input
for simplicity, but this function is *nestable, and therefore*
also accepts
ivy.Container
instances in place of any ofthe arguments.
Examples
>>> x = ivy.arange(48.).reshape((2, 3, 2, 2, 2)) >>> print(ivy.max_pool3d(x, 2, 2, 'VALID')) ivy.array([[[[[14., 15.]]]],
[[[[38., 39.]]]]])
>>> print(ivy.max_pool3d(x, 2, 2, 'SAME')) ivy.array([[[[[14., 15.]]],
[[[22., 23.]]]],
[[[[38., 39.]]],
[[[46., 47.]]]]])
- ivy.reduce_window(operand, init_value, computation, window_dimensions, /, *, window_strides=1, padding='VALID', base_dilation=1, window_dilation=1)[source]#
Apply a reduction function to all elements in each window of an array.
- Parameters:
operand (
Union
[Array
,NativeArray
]) – An array representing the base area on which the window is going to slide over.init_value (
Union
[int
,float
]) – The starting value for the reduction.computation (
Callable
) – The reduction function to apply to elements in each window.window_dimensions (
Union
[int
,Sequence
[int
]]) – A sequence containing the window dimensions.window_strides (
Union
[int
,Sequence
[int
]]) – A sequence containing the window strides. (default:1
)padding (
Union
[str
,int
,Sequence
[Tuple
[int
,int
]]]) – Either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no (default:'VALID'
) padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.base_dilation (
Union
[int
,Sequence
[int
]]) – A sequence containing the base dilation values. (default:1
)window_dilation (
Union
[int
,Sequence
[int
]]) – A sequence containing the window dilation values. (default:1
)
- Return type:
- Returns:
ret – The result of the pooling-like operation.
Examples
>>> x = ivy.array([[1, 2, 3, 4], >>> [5, 6, 7, 8], >>> [9, 10, 11, 12]]) >>> ivy.reduce_window(x, 0, ivy.sum, (2, 2)) ivy.array([[32.]])