tests/testthat/test-dense-convert.r

context("dense-convert")

# test data
dims <- c(2,2,2)
arr <- array(c(1,0,0,0,1,0,0,0), dims)
X <- sptensor(subs = matrix(c(1,1,1, 1,1,2), nrow = length(dims)),
              vals = c(1,1),
              dims = dims)
Z <- dtensor(arr)

test_that("sparse tensor converts to dense tensor", {
  expect_equal(as_dtensor(X), Z)
})

test_that("array converts to dense tensor", {
  expect_equal(as_dtensor(arr), Z)
})

test_that("as.vector works", {
  expect_equal(as.vector(Z), c(1,0,0,0,1,0,0,0))
})

Try the tensorr package in your browser

Any scripts or data that you put into this service are public.

tensorr documentation built on May 2, 2019, 3:26 a.m.