Skip to content

Commit

Permalink
Add test for sparse breeze by vector builder
Browse files Browse the repository at this point in the history
  • Loading branch information
funes committed May 7, 2014
1 parent 64e7198 commit d129a66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ object Vectors {
case v: BSV[Double] =>
if (v.index.length == v.used) {
new SparseVector(v.length, v.index, v.data)
}
else {
} else {
new SparseVector(v.length, v.index.slice(0, v.used), v.data.slice(0, v.used))
}
case v: BV[_] =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.mllib.linalg

import org.scalatest.FunSuite

import breeze.linalg.{DenseVector => BDV, SparseVector => BSV}
import breeze.linalg.{DenseVector => BDV, SparseVector => BSV, VectorBuilder => BVB}

/**
* Test Breeze vector conversions.
Expand Down Expand Up @@ -55,4 +55,16 @@ class BreezeVectorConversionSuite extends FunSuite {
assert(vec.indices.eq(indices), "should not copy data")
assert(vec.values.eq(values), "should not copy data")
}

test("sparse breeze by vector builder to vector") {
val builder = new BVB[Double](n)
for (i <- 0 until indices.length) {
builder.add(indices(i), values(i))
}
val breeze = builder.toSparseVector
val vec = Vectors.fromBreeze(breeze).asInstanceOf[SparseVector]
assert(vec.size === n)
assert(vec.indices === indices)
assert(vec.values === values)
}
}

0 comments on commit d129a66

Please sign in to comment.