This document is relevant for: Trn2, Trn3

nki.language.maximum#

nki.language.maximum(x, y, dtype=None)[source]#

Maximum of the inputs, element-wise.

((Similar to numpy.maximum))

Warning

This API is experimental and may change in future releases.

Parameters:
  • x – a tile or a scalar value.

  • y – a tile or a scalar value.

  • dtype – (optional) data type to cast the output type to (see Supported Data Types for more information);

Returns:

a tile that has the maximum of each element from x and y.

Examples:

import nki.language as nl

# nki.language.maximum -- max(3.0, 5.0) = 5.0
a = nl.full((128, 512), 3.0, dtype=nl.float32, buffer=nl.sbuf)
b = nl.full((128, 512), 5.0, dtype=nl.float32, buffer=nl.sbuf)
c = nl.maximum(a, b)
expected = nl.full((128, 512), 5.0, dtype=nl.float32, buffer=nl.sbuf)
assert nl.equal(c, expected)

# nki.language.maximum -- with a scalar operand
a = nl.full((128, 512), 3.0, dtype=nl.float32, buffer=nl.sbuf)
c = nl.maximum(a, 5.0)
expected = nl.full((128, 512), 5.0, dtype=nl.float32, buffer=nl.sbuf)
assert nl.equal(c, expected)

This document is relevant for: Trn2, Trn3