Pads an array with a given padding value.
Arguments
- x
(
arrayish)
The array to pad. Can be any data type.xandpadding_valuemust have the same data type. An R value among them assumes the data type of the others when it is in its data type category, and its default data type when none of them has one.- padding_value
(
arrayish)
Scalar value to use for padding. Sharesx's data type.- edge_padding_low
(
integer())
Amount of padding to add at the start of each axis.- edge_padding_high
(
integer())
Amount of padding to add at the end of each axis.- interior_padding
(
integer())
Amount of padding to add between elements in each axis.
Value
(arrayish)
Has the data type the operands agreed on. Each axis grows by
edge_padding_low + edge_padding_high, plus interior_padding between
every pair of elements; negative edge padding trims (see hlo_pad()).
Examples
x <- nv_array(1:3)
# one element before, two after
prim_pad(x, 0L, edge_padding_low = 1L, edge_padding_high = 2L, interior_padding = 0L)
#> AnvlArray
#> 0
#> 1
#> 2
#> 3
#> 0
#> 0
#> [ CPUi32{6} ]
# interior padding goes between the elements
prim_pad(x, 0L, 0L, 0L, 1L)
#> AnvlArray
#> 1
#> 0
#> 2
#> 0
#> 3
#> [ CPUi32{5} ]
# negative edge padding trims instead
prim_pad(x, 0L, -1L, 0L, 0L)
#> AnvlArray
#> 2
#> 3
#> [ CPUi32{2} ]
# one padding amount per axis
prim_pad(nv_matrix(1:4, nrow = 2), 0L, c(1L, 0L), c(0L, 1L), c(0L, 0L))
#> AnvlArray
#> 0 0 0
#> 1 3 0
#> 2 4 0
#> [ CPUi32{3,3} ]
# the R padding value is built at x's data type
prim_pad(nv_array(c(1.5, 2.5), dtype = "f64"), 0, 1L, 1L, 0L)
#> AnvlArray
#> 0.0000
#> 1.5000
#> 2.5000
#> 0.0000
#> [ CPUf64{4} ]