hardtanh#
- ivy.hardtanh(x, /, *, max_val=1, min_val=-1, out=None)[source]#
Apply the hardtanh unit function element-wise.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array.min_val (
float
, default:-1
) – minimum value of the linear region range. Default: -1.max_val (
float
, default:1
) – maximum value of the linear region range. Default: 1.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – The input array with elu applied element-wise.
Examples
With
ivy.Array
input: >>> x = ivy.array([0.39, -0.85]) >>> y = ivy.hardtanh(x) >>> print(y) ivy.array([ 0.39, -0.85]) >>> x = ivy.array([1.5, 0.7, -2.4]) >>> y = ivy.zeros(3) >>> ivy.hardtanh(x, out=y) >>> print(y) ivy.array([ 1., 0.7, -1.]) >>> x = ivy.array([[1.1, 2.2, 3.3],[-0.4, 0.5, -6.6]]) >>> ivy.hardtanh(x, out=x) >>> print(x) ivy.array([[ 1., 1., 1.],[-0.4, 0.5, -1.]])With
ivy.Container
input: >>> x = ivy.Container(a=ivy.array([0.0, -1.2]), b=ivy.array([0.4, -0.2])) >>> x = ivy.hardtanh(x, out=x) >>> print(x) {a: ivy.array([0., -1.]), b: ivy.array([0.4, -0.2])
}
- Array.hardtanh(self, /, *, max_val=1, min_val=-1, out=None)[source]#
ivy.Array instance method variant of ivy.hardtanh. This method simply wraps the function, and so the docstring for ivy.hardtanh also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.min_val (
float
, default:-1
) – minimum value of the linear region range. Default: -1.max_val (
float
, default:1
) – maximum value of the linear region range. Default: 1.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – an array with the hardtanh activation function applied element-wise with custom linear region range.
Examples
>>> x = ivy.array([-1., .2, 1.]) >>> y = x.hardtanh() >>> print(y) ivy.array([-1. , 0.2, 1. ])
- Container.hardtanh(self, /, *, min_val=-1.0, max_val=1.0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.hardtanh.This method simply wraps the function, so the docstring for ivy.elu also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.min_val (
Container
, default:-1.0
) – minimum value of the linear region range. Default: -1.max_val (
Container
, default:1.0
) – maximum value of the linear region range. Default: 1.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container with the hardtanh unit function applied element-wise.
Examples
>>> x = ivy.Container(a=ivy.array([0.39, -2.0]), b=ivy.array([2., -0.2])) >>> y = ivy.Container.hardtanh(x) >>> print(y) { a: ivy.array([0.389999, -1.]), b: ivy.array([1., -0.2]) }