Skip to content

Commit

Permalink
made tests conform to WRE, added coo test
Browse files Browse the repository at this point in the history
  • Loading branch information
wrathematics committed Oct 29, 2015
1 parent c61f611 commit 1a556af
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 25 deletions.
25 changes: 25 additions & 0 deletions tests/coo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if(require(slam))
{
library(slam)
library(fastcosim)

set.seed(1234)

m <- 30
n <- 10
x <- matrix(0, m, n)
x[sample(m*n, size=25)] <- 10

coo <- as.simple_triplet_matrix(x)

t1 <- cosine(x)
t2 <- cosine(coo)


stopifnot(all.equal(t1, t2))

#t1[which(is.nan(t1))] <- 0
#t2[which(is.nan(t2))] <- 0
#stopifnot(all.equal(t1, t2))
}

43 changes: 24 additions & 19 deletions tests/matrix.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
x <- matrix(rnorm(30), 10)
if (require(lsa))
{
x <- matrix(rnorm(30), 10)

t1 <- lsa::cosine(x)
t2 <- fastcosim::cosine(x)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))



x <- t(x)

t1 <- lsa::cosine(x)
t2 <- fastcosim::cosine(x)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))



x <- tcrossprod(x)

t1 <- lsa::cosine(x)
t2 <- fastcosim::cosine(x)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))
}

t1 <- lsa::cosine(x)
t2 <- fastcosim::cosine(x)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))



x <- t(x)

t1 <- lsa::cosine(x)
t2 <- fastcosim::cosine(x)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))



x <- tcrossprod(x)

t1 <- lsa::cosine(x)
t2 <- fastcosim::cosine(x)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))
15 changes: 9 additions & 6 deletions tests/vecvec.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
x <- rnorm(30)
y <- rnorm(30)

t1 <- as.vector(lsa::cosine(x, y))
t2 <- fastcosim::cosine(x, y)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))
if (require(lsa))
{
x <- rnorm(30)
y <- rnorm(30)

t1 <- as.vector(lsa::cosine(x, y))
t2 <- fastcosim::cosine(x, y)
stopifnot(all.equal(t1, t2, check.attributes=FALSE))
}

0 comments on commit 1a556af

Please sign in to comment.