-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-dvector.r
40 lines (28 loc) · 970 Bytes
/
test-dvector.r
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
36
37
38
39
library(testthat)
library(Matrix)
# Load the data representation.
source("disk-part.r")
# We'll use doSEQ as a parallel execution engine.
library(foreach)
registerDoSEQ()
# Test the distributed vector.
source("dvector.r")
# Initialize disk parting.
init_disk_part()
# Create the vector.
dv <- dvector_from_vectors(list(rnorm(10), rnorm(20), rnorm(15)))
class(dv)
dv_sparse <- dvector_from_vectors(list(rnorm(10),
sparseVector(1:2, 4:5, 15), rnorm(20)))
# Sample a few element positions.
inds <- sample.int(length(dv), 10, replace=TRUE)
# Emerge the vector at the specified indices and see if it's
# the same same as emerging the entire vector and then
# subsetting by indices.
expect_equal(dv[inds], dv[][inds])
# Add one to each element of the vector.
dv2 <- dv + 1
# Make sure it's the same as emerging dv and then adding 1.
expect_equal(dv2[], (dv+1)[])
dv_index <- dvector_from_vectors(list(inds, inds))
expect_equal(dv[dv_index][], dv[][dv_index[]])