fourier_encode#
- ivy.fourier_encode(x, max_freq, /, *, num_bands=4, linear=False, concat=True, flatten=False)[source]#
Pad an array with fourier encodings.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array to encode.max_freq (
Union
[float
,Array
,NativeArray
]) – The maximum frequency of the encoding.num_bands (
int
) – The number of frequency bands for the encoding. (default:4
) Default is 4.linear (
bool
) – Whether to space the frequency bands linearly as opposed to geometrically. (default:False
) Default isFalse
.concat (
bool
) – Whether to concatenate the position, sin and cos values, or return seperately. (default:True
) Default isTrue
.flatten (
bool
) – Whether to flatten the position dimension into the batch dimension. (default:False
) Default is False.
- Return type:
Union
[Array
,NativeArray
,Tuple
]- Returns:
ret – New array with the final dimension expanded, and the encodings stored in this channel.
Examples
>>> x = ivy.array([1,2,3]) >>> y = 1.5 >>> z = ivy.fourier_encode(x,y) >>> print(z) ivy.array([[ 1.0000000e+00, 1.2246468e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00], [ 2.0000000e+00, -2.4492936e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00], [ 3.0000000e+00, 3.6739404e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]])
>>> x = ivy.array([3,10]) >>> y = 2.5 >>> z = ivy.fourier_encode(x, y, num_bands=3) >>> print(z) ivy.array([[ 3.0000000e+00, 3.6739404e-16, 3.6739404e-16, 3.6739404e-16, -1.0000000e+00, -1.0000000e+00, -1.0000000e+00], [ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]])
- Array.fourier_encode(self, max_freq, /, *, num_bands=4, linear=False, concat=True, flatten=False)#
ivy.Array instance method variant of ivy.fourier_encode. This method simply wraps the function, and so the docstring for ivy.fourier_encode also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array to encodemax_freq (
Union
[float
,Array
,NativeArray
]) – The maximum frequency of the encoding.num_bands (
int
) – The number of frequency bands for the encoding. Default is 4. (default:4
)linear (
bool
) – Whether to space the frequency bands linearly as opposed to geometrically. (default:False
) Default isFalse
.concat (
bool
) – Whether to concatenate the position, sin and cos values, or return (default:True
) seperately. Default isTrue
.flatten (
bool
) – Whether to flatten the position dimension into the batch dimension. (default:False
) Default isFalse
.
- Return type:
Union
[Array
,NativeArray
,Tuple
]- Returns:
ret – New array with the final dimension expanded, and the encodings stored in this channel.
Examples
>>> x = ivy.array([1, 2, 3]) >>> y = 1.5 >>> z = x.fourier_encode(y) >>> print(z) ivy.array([[ 1.0000000e+00, 1.2246468e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00], [ 2.0000000e+00, -2.4492936e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00], [ 3.0000000e+00, 3.6739404e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]])
>>> x = ivy.array([3, 10]) >>> y = 2.5 >>> z = x.fourier_encode(y, num_bands=3) >>> print(z) ivy.array([[ 3.0000000e+00, 3.6739404e-16, 3.6739404e-16, 3.6739404e-16, -1.0000000e+00, -1.0000000e+00, -1.0000000e+00], [ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]])
- Container.fourier_encode(self, max_freq, /, *, num_bands=4, linear=False, flatten=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)#
ivy.Container instance method variant of ivy.fourier_encode. This method simply wraps the function, and so the docstring for ivy.fourier_encode also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input container to apply fourier_encode at leaves.max_freq (
Union
[float
,Array
,NativeArray
]) – The maximum frequency of the encoding.num_bands (
int
) – The number of frequency bands for the encoding. Default is 4. (default:4
)linear (
bool
) – Whether to space the frequency bands linearly as opposed to geometrically. (default:False
) Default isFalse
.flatten (
bool
) – Whether to flatten the position dimension into the batch dimension. (default:False
) Default isFalse
.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.dtype – Data type of the returned array. Default is
None
.out – Optional output container. Default is
None
.
- Return type:
Container
- Returns:
ret – New container with the final dimension expanded of arrays at its leaves, and the encodings stored in this channel.
Examples
>>> x = ivy.Container(a = ivy.array([1,2]), ... b = ivy.array([3,4])) >>> y = 1.5 >>> z = x.fourier_encode(y) >>> print(z) { a: (<classivy.array.array.Array>shape=[2,9]), b: (<classivy.array.array.Array>shape=[2,9]) }
>>> x = ivy.Container(a = ivy.array([3,10]), ... b = ivy.array([4,8])) >>> y = 2.5 >>> z = x.fourier_encode(y,num_bands=3) >>> print(z) { a: ivy.array([[ 3.0000000e+00, 3.6739404e-16, 3.6739404e-16, 3.6739404e-16,-1.0000000e+00, -1.0000000e+00, -1.0000000e+00], [ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]]), b: ivy.array([[4.00000000e+00, -4.89858720e-16, -4.89858720e-16, -4.89858720e-16, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00], [ 8.00000000e+00, -9.79717439e-16, -9.79717439e-16, -9.79717439e-16, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]) }