Skip to contents

Returns a boolean matrix that is TRUE on and above the given diagonal, mirroring base R's upper.tri(). Use nv_triu() to zero out the other triangle of an existing array instead.

Usage

nv_upper_tri(shape, diagonal = 1L, device = NULL)

nv_upper_tri_like(like, diagonal = 1L, shape = NULL, device = NULL)

Arguments

shape

(integer())
Shape.

diagonal

(integer(1))
Diagonal offset, with the same meaning as in nv_triu(). The default 1 excludes the main diagonal, matching upper.tri(); use 0 to include it, matching upper.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, or

  • a device object as returned by nv_device(): a PJRTDevice for the "pjrt" backend or a quickr_device for the "quickr" backend. Because a device object is backend-specific, it also determines the backend.

The default (NULL) uses default_device(): the CPU, or the platform named by the PJRT_PLATFORM environment variable on the "pjrt" backend.

like

(AnvlArray)
Existing array whose attributes are used as defaults (only for nv_upper_tri_like()).

Value

arrayish
Has the given shape and dtype bool.

See also

nv_lower_tri(), nv_triu(), prim_iota() for the underlying primitive.

Examples

nv_upper_tri(c(3, 3))
#> AnvlArray
#>  0 1 1
#>  0 0 1
#>  0 0 0
#> [ CPUbool{3,3} ] 
nv_upper_tri(c(3, 3), diagonal = 0L)
#> AnvlArray
#>  1 1 1
#>  0 1 1
#>  0 0 1
#> [ CPUbool{3,3} ] 
x <- nv_fill(0, shape = c(3, 3))
nv_upper_tri_like(x)
#> AnvlArray
#>  0 1 1
#>  0 0 1
#>  0 0 0
#> [ CPUbool{3,3} ]