thresholded_relu#

ivy.thresholded_relu(x, /, *, threshold=0, out=None)[source]#

Apply the rectified linear unit function with custom threshold.

Parameters:
  • x (Union[Array, NativeArray]) – input array

  • threshold (Union[int, float], default: 0) – threshold value above which the activation is linear. Default: 0.

  • 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 containing the rectified linear unit activation of each element in x. with custom threshold.

Examples

With ivy.Array input:

>>> x = ivy.array([-1., 0., 1.])
>>> y = ivy.thresholded_relu(x, threshold=0.5)
>>> print(y)
ivy.array([0.,  0. ,  1.])
>>> x = ivy.array([1.5, 0.7, -2.4])
>>> y = ivy.zeros(3)
>>> ivy.thresholded_relu(x, threshold=1, out = y)
>>> print(y)
ivy.array([ 1.5,  0., 0.])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.2, 0.6]))
>>> x = ivy.thresholded_relu(x, threshold=0.5)
>>> print(x)
{
    a: ivy.array([1., 0.]),
    b: ivy.array([0., 0.6])
}
Array.thresholded_relu(self, /, *, threshold=0, out=None)[source]#

ivy.Array instance method variant of ivy.thresholded_relu. This method simply wraps the function, and so the docstring for ivy.thresholded_relu also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array.

  • threshold (Union[int, float], default: 0) – threshold value above which the activation is linear. Default: 0.

  • 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 relu activation function applied element-wise with custom threshold.

Examples

>>> x = ivy.array([-1., .2, 1.])
>>> y = x.thresholded_relu(threshold=0.5)
>>> print(y)
ivy.array([0., 0., 1.])
Container.thresholded_relu(self, /, *, threshold=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.thresholded_relu. This method simply wraps the function, and so the docstring for ivy.thresholded_relu also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container.

  • threshold (Union[int, float, Container], default: 0) – threshold value above which the activation is linear. Default: 0.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • 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 rectified linear activation unit function applied element-wise with custom threshold.

Examples

>>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.4, -0.2]))
>>> y = x.thresholded_relu(threshold=0.5)
>>> print(y)
{
    a: ivy.array([1., 0.]),
    b: ivy.array([0., 0.])
}