WeichenXu123 commented on a change in pull request #30009:
URL: https://github.com/apache/spark/pull/30009#discussion_r506021907
##########
File path: mllib/src/test/scala/org/apache/spark/ml/feature/InstanceSuite.scala
##########
@@ -74,4 +74,36 @@ class InstanceSuite extends SparkFunSuite{
}
}
+ test("InstanceBlock: blokify with max memory usage") {
+ val instance1 = Instance(19.0, 2.0, Vectors.dense(1.0, 7.0))
+ val instance2 = Instance(17.0, 1.0, Vectors.dense(0.0, 5.0).toSparse)
+ val instances = Seq(instance1, instance2)
+
+ val blocks = InstanceBlock
+ .blokifyWithMaxMemUsage(Iterator.apply(instance1, instance2),
128).toArray
+ require(blocks.length == 1)
+ val block = blocks.head
+ assert(block.size === 2)
+ assert(block.numFeatures === 2)
+ block.instanceIterator.zipWithIndex.foreach {
+ case (instance, i) =>
+ assert(instance.label === instances(i).label)
+ assert(instance.weight === instances(i).weight)
+ assert(instance.features.toArray === instances(i).features.toArray)
+ }
+ Seq(0, 1).foreach { i =>
+ val nzIter = block.getNonZeroIter(i)
+ val vec = Vectors.sparse(2, nzIter.toSeq)
+ assert(vec.toArray === instances(i).features.toArray)
+ }
+
+ // instances larger than maxMemUsage
+ val bigInstance = Instance(-1.0, 2.0,
Vectors.dense(Array.fill(10000)(1.0)))
+ InstanceBlock.blokifyWithMaxMemUsage(Iterator.fill(10)(bigInstance),
64).size
+
+ // different numFeatures
+ intercept[IllegalArgumentException] {
+ InstanceBlock.blokifyWithMaxMemUsage(Iterator.apply(instance1,
bigInstance), 64).size
+ }
+ }
Review comment:
add test:
* Generate a sparse and dense instance mixed list (a list which some segment
is dense but others are very sparse), verify each block size won't exceed the
blockMem limit too much. (Such as: (actual block mem size)/confg <= 1.1 ?)
##########
File path: mllib/src/test/scala/org/apache/spark/ml/feature/InstanceSuite.scala
##########
@@ -74,4 +74,36 @@ class InstanceSuite extends SparkFunSuite{
}
}
+ test("InstanceBlock: blokify with max memory usage") {
+ val instance1 = Instance(19.0, 2.0, Vectors.dense(1.0, 7.0))
+ val instance2 = Instance(17.0, 1.0, Vectors.dense(0.0, 5.0).toSparse)
+ val instances = Seq(instance1, instance2)
+
+ val blocks = InstanceBlock
+ .blokifyWithMaxMemUsage(Iterator.apply(instance1, instance2),
128).toArray
+ require(blocks.length == 1)
+ val block = blocks.head
+ assert(block.size === 2)
+ assert(block.numFeatures === 2)
+ block.instanceIterator.zipWithIndex.foreach {
+ case (instance, i) =>
+ assert(instance.label === instances(i).label)
+ assert(instance.weight === instances(i).weight)
+ assert(instance.features.toArray === instances(i).features.toArray)
+ }
+ Seq(0, 1).foreach { i =>
+ val nzIter = block.getNonZeroIter(i)
+ val vec = Vectors.sparse(2, nzIter.toSeq)
+ assert(vec.toArray === instances(i).features.toArray)
+ }
+
+ // instances larger than maxMemUsage
+ val bigInstance = Instance(-1.0, 2.0,
Vectors.dense(Array.fill(10000)(1.0)))
+ InstanceBlock.blokifyWithMaxMemUsage(Iterator.fill(10)(bigInstance),
64).size
Review comment:
Verify block contains 1 row.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]