View Source Nx.Constants (Nx v0.2.1)

Common constants used in computations.

Link to this section Summary

Functions

Returns the imaginary constant.

Returns infinity in f32.

Returns infinity.

Returns a scalar tensor with the maximum finite value for the given type.

Returns a scalar tensor with the minimum finite value for the given type.

Returns infinity in f32.

Returns NaN (Not a Number).

Returns infinity in f32.

Returns negative infinity.

Link to this section Functions

Returns the imaginary constant.

Accepts the same options as Nx.tensor/2

examples

Examples

iex> Nx.Constants.i()
#Nx.Tensor<
  c64
  0.0+1.0i
>

iex> Nx.Constants.i(type: {:c, 128})
#Nx.Tensor<
  c128
  0.0+1.0i
>

error-cases

Error cases

iex> Nx.Constants.i(type: {:f, 32})
** (ArgumentError) invalid type for complex number. Expected {:c, 64} or {:c, 128}, got: {:f, 32}

Returns infinity in f32.

Link to this function

infinity(type, opts \\ [])

View Source

Returns infinity.

options

Options

  • :backend - a backend to allocate the tensor on.

examples

Examples

iex> Nx.Constants.infinity({:bf, 16})
#Nx.Tensor<
  bf16
  Inf
>

iex> Nx.Constants.infinity({:f, 16})
#Nx.Tensor<
  f16
  Inf
>

iex> Nx.Constants.infinity({:f, 32})
#Nx.Tensor<
  f32
  Inf
>

iex> Nx.Constants.infinity({:f, 64})
#Nx.Tensor<
  f64
  Inf
>
Link to this function

max_finite(type, opts \\ [])

View Source

Returns a scalar tensor with the maximum finite value for the given type.

options

Options

  • :backend - a backend to allocate the tensor on.

examples

Examples

iex> Nx.Constants.max_finite({:u, 8})
#Nx.Tensor<
  u8
  255
>

iex> Nx.Constants.max_finite({:s, 16})
#Nx.Tensor<
  s16
  32677
>

iex> Nx.Constants.max_finite({:f, 32})
#Nx.Tensor<
  f32
  3.4028234663852886e38
>
Link to this function

min_finite(type, opts \\ [])

View Source

Returns a scalar tensor with the minimum finite value for the given type.

options

Options

  • :backend - a backend to allocate the tensor on.

examples

Examples

iex> Nx.Constants.min_finite({:u, 8})
#Nx.Tensor<
  u8
  0
>

iex> Nx.Constants.min_finite({:s, 16})
#Nx.Tensor<
  s16
  -32678
>

iex> Nx.Constants.min_finite({:f, 32})
#Nx.Tensor<
  f32
  -3.4028234663852886e38
>

Returns infinity in f32.

Returns NaN (Not a Number).

options

Options

  • :backend - a backend to allocate the tensor on.

examples

Examples

iex> Nx.Constants.nan({:bf, 16})
#Nx.Tensor<
  bf16
  NaN
>

iex> Nx.Constants.nan({:f, 16})
#Nx.Tensor<
  f16
  NaN
>

iex> Nx.Constants.nan({:f, 32})
#Nx.Tensor<
  f32
  NaN
>

iex> Nx.Constants.nan({:f, 64})
#Nx.Tensor<
  f64
  NaN
>

Returns infinity in f32.

Link to this function

neg_infinity(type, opts \\ [])

View Source

Returns negative infinity.

options

Options

  • :backend - a backend to allocate the tensor on.

examples

Examples

iex> Nx.Constants.neg_infinity({:bf, 16})
#Nx.Tensor<
  bf16
  -Inf
>

iex> Nx.Constants.neg_infinity({:f, 16})
#Nx.Tensor<
  f16
  -Inf
>

iex> Nx.Constants.neg_infinity({:f, 32})
#Nx.Tensor<
  f32
  -Inf
>

iex> Nx.Constants.neg_infinity({:f, 64})
#Nx.Tensor<
  f64
  -Inf
>