This document is relevant for: Trn1, Trn2, Trn3
nki.language.trunc#
- nki.language.trunc(x, dtype=None)[source]#
Truncated value of the input, element-wise.
((Similar to numpy.trunc))
Warning
This API is experimental and may change in future releases.
The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the fractional part of the signed number x is discarded.
- Parameters:
x – a tile.
dtype – (optional) data type to cast the output type to (see Supported Data Types for more information); if not specified, it will default to be the same as the data type of the input tile.
- Returns:
a tile that has truncated values of
x.
Examples:
import nki.language as nl # nki.language.trunc -- truncates 3.7 toward zero to 3.0 a = nl.full((128, 512), 3.7, dtype=nl.float32, buffer=nl.sbuf) c = nl.trunc(a) expected = nl.full((128, 512), 3.0, dtype=nl.float32, buffer=nl.sbuf) assert nl.equal(c, expected) # nki.language.trunc -- truncates -3.7 toward zero to -3.0 a = nl.full((128, 512), -3.7, dtype=nl.float32, buffer=nl.sbuf) c = nl.trunc(a) expected = nl.full((128, 512), -3.0, dtype=nl.float32, buffer=nl.sbuf) assert nl.equal(c, expected)
This document is relevant for: Trn1, Trn2, Trn3