Skip to content

Commit 080b8ed

Browse files
committed
add rep()
1 parent 5222a71 commit 080b8ed

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

R/rep.r

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#' rep
2+
#'
3+
#' Replicate elements of a float vector/matrix.
4+
#'
5+
#' @param x
6+
#' A float matrix.
7+
#' @param ...
8+
#' Additional arguments (passed to \code{base::rep}).
9+
#'
10+
#' @return
11+
#' A float vector.
12+
#'
13+
#' @examples
14+
#' library(float)
15+
#' x = fl(matrix(1:6, 3, 2))
16+
#'
17+
#' rep(x, 5)
18+
#'
19+
#' @name rep
20+
#' @rdname rep
21+
NULL
22+
23+
24+
25+
#' @rdname rep
26+
#' @export
27+
rep.float32 = function(x, ...)
28+
{
29+
x_rep = rep(DATA(x), ...)
30+
float32(x_rep)
31+
}

man/rep.Rd

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/rep.r

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
suppressPackageStartupMessages(library(float))
2+
3+
tol = 1e-6
4+
5+
x = matrix(1:6, 3, 2)
6+
s = fl(x)
7+
8+
test = dbl(rep(s, 5))
9+
truth = rep(x, 5)
10+
stopifnot(all.equal(test, truth, tol=tol))

0 commit comments

Comments
 (0)