Returns a boolean matrix that is TRUE on and below the given diagonal,
mirroring base R's lower.tri(). Use nv_tril() to zero out the other
triangle of an existing array instead.
Usage
nv_lower_tri(shape, diagonal = -1L, device = NULL)
nv_lower_tri_like(like, diagonal = -1L, shape = NULL, device = NULL)Arguments
- shape
(
integer())
Shape of the result: exactly two axis sizes, since the result is a matrix.- diagonal
(
integer(1))
Diagonal offset, with the same meaning as innv_tril(). The default-1excludes the main diagonal, matchinglower.tri(); use0to include it, matchinglower.tri(diag = TRUE).- device
(
NULL|character(1)| device)
The device the data lives on, given either as:a device string naming the platform (e.g.
"cpu","cuda","cuda:<n>"), which is resolved against the backend in use, ora device object as returned by
nv_device(): aPJRTDevicefor the"pjrt"backend or aquickr_devicefor the"quickr"backend. Because a device object is backend-specific, it also determines the backend.
The default (
NULL) usesdefault_device().- like
(
AnvlArray)
Existing array whose attributes are used as defaults (only fornv_lower_tri_like()).
Value
(arrayish)
Has the given shape and boolean data type. It is a mask over positions,
so no array data enters it – pass it to nv_ifelse() or multiply by it
to use it.
See also
nv_upper_tri(), nv_tril(), prim_iota() for the underlying primitive.
Examples
# a boolean mask, whatever the array it is later used with
nv_lower_tri(c(3, 3))
#> AnvlArray
#> 0 0 0
#> 1 0 0
#> 1 1 0
#> [ CPUbool{3,3} ]
nv_lower_tri(c(3, 3), diagonal = 0L)
#> AnvlArray
#> 1 0 0
#> 1 1 0
#> 1 1 1
#> [ CPUbool{3,3} ]
x <- nv_fill(0, shape = c(3, 3))
nv_lower_tri_like(x)
#> AnvlArray
#> 0 0 0
#> 1 0 0
#> 1 1 0
#> [ CPUbool{3,3} ]