File: size.R

package info (click to toggle)
r-cran-matlab 1.0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: sh: 13; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
###
### $Id: size.R 22 2022-05-30 18:03:47Z proebuck $
###


##-----------------------------------------------------------------------------
test.size <- function(input, expected) {
    output <- do.call(getFromNamespace("size", "matlab"), input)
    identical(as.integer(output), expected)
}

X.vec <- 2:9
size.expected.X.vec <- c(1, length(X.vec))

test.size(list(X = X.vec), size.expected.X.vec)
test.size(list(X = X.vec, 1), as.integer(1))
test.size(list(X = X.vec, 2), length(X.vec))


X.mat <- matrix(X.vec, 4, 2)
size.expected.X.mat <- dim(X.mat)

test.size(list(X = X.mat), size.expected.X.mat)
test.size(list(X = X.mat, 1), size.expected.X.mat[1])
test.size(list(X = X.mat, 2), size.expected.X.mat[2])
test.size(list(X = X.mat, 3), as.integer(1))	# singleton dimension

X.arr <- array(2:25, c(4, 3, 2))
size.expected.X.arr <- dim(X.arr)

test.size(list(X = X.arr), size.expected.X.arr)
test.size(list(X = X.arr, 1), size.expected.X.arr[1])
test.size(list(X = X.arr, 2), size.expected.X.arr[2])
test.size(list(X = X.arr, 3), size.expected.X.arr[3])