rray_dim: Find common dimensions

Description Usage Arguments Details Value See Also Examples

View source: R/dim.R

Description

Usage

1
2
3

Arguments

x

An object.

...

Objects to find common dimensions for.

Details

rray_dim_common() first finds the common dimensionality, makes any implicit dimensions explicit, then recycles the size of each dimension to a common size.

As an example, the common dimensions of (4, 5) and (4, 1, 2) are:

1
2
3
4
(4, 5, 1) <- implicit 1 is made to be explicit, then recycled to 2
(4, 1, 2) <- the 1 in the second dimension here is recycled to 5
---------
(4, 5, 2) <- resulting common dim

The resulting dimensions from rray_dim_common() are the dimensions that are used in broadcasted operations.

Value

An integer vector containing the common dimensions.

See Also

rray_dim_n()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
x_1_by_4 <- rray(c(1, 2, 3, 4), c(1, 4))
x_5_by_1 <- rray(1:5, c(5, 1))

rray_dim(x_1_by_4)

# recycle rows: 1 VS 5 = 5
# recycle cols: 4 VS 1 = 4
rray_dim_common(x_1_by_4, x_5_by_1)

x_5_by_1_by_3 <- rray(1, c(5, 1, 3))

# recycle rows:    5 VS 1 = 5
# recycle cols:    4 VS 1 = 4
# recycle 3rd dim: 1 VS 3 = 3
# (here, 3rd dim of 1 for the matrix is implicit)
rray_dim_common(x_1_by_4, x_5_by_1_by_3)

# The dimensions of NULL are 0
rray_dim(NULL)

rray documentation built on July 23, 2019, 5:04 p.m.