Added Vector.eachNonZero method and implementations (issue #57) #76

Merged
merged 4 commits into from Aug 3, 2013

Projects

None yet

2 participants

@SamoylovMD
Contributor

No description provided.

@vkostyukov vkostyukov commented on the diff Aug 3, 2013
...ain/java/org/la4j/vector/sparse/CompressedVector.java
@@ -235,6 +235,13 @@ public void each(VectorProcedure procedure) {
}
@Override
+ public void eachNonZero(VectorProcedure procedure) {
@vkostyukov
vkostyukov Aug 3, 2013 Owner

It is not necessary to check value in compressed vector on zero. It is guaranteed that only non-zero values are store. Which means, that we only need to rename each to eachNonZero in CompressedVector class. Please also make sure that MatrixMarketStream uses the proper iteration method. TIP: It should be eachNonZero.

@vkostyukov vkostyukov commented on an outdated diff Aug 3, 2013
src/main/java/org/la4j/vector/AbstractVector.java
@@ -428,6 +428,13 @@ public void each(VectorProcedure procedure) {
}
@Override
+ public void eachNonZero(VectorProcedure procedure) {
+ for (int i = 0; i < length; i++) {
+ if (Math.abs(get(i))>Vectors.EPS) procedure.apply(i, get(i));
@vkostyukov
vkostyukov Aug 3, 2013 Owner

Please, add spaces between get(i) > Vectors.EPS. And having a {} arround procedure is also a good practice.

@vkostyukov vkostyukov commented on an outdated diff Aug 3, 2013
src/main/java/org/la4j/vector/AbstractSafeVector.java
@@ -276,6 +276,11 @@ public void each(VectorProcedure procedure) {
}
@Override
+ public void eachNonZero(VectorProcedure procedure) {
+ self.each(procedure);
@vkostyukov
vkostyukov Aug 3, 2013 Owner

Should be each.nonZero(procedure).

@vkostyukov
Owner

Looks good! Just one thing's left (see my comments below).

@vkostyukov
Owner

Nice job Maxim @SamoylovMD!

@vkostyukov vkostyukov merged commit f2294b5 into vkostyukov:master Aug 3, 2013

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment