ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [08/11] ignite git commit: IGNITE-6949: Cleanup OLS code. This closes #3063.
Date Fri, 24 Nov 2017 08:31:05 GMT
IGNITE-6949: Cleanup OLS code. This closes #3063.

Signed-off-by: nikolay_tikhonov <ntikhonov@gridgain.com>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/34955be3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/34955be3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/34955be3

Branch: refs/heads/ignite-zk
Commit: 34955be37cc2d9f889d182890f2a85d147877ead
Parents: 5a4c6e0
Author: zaleslaw <zaleslaw.sin@gmail.com>
Authored: Thu Nov 23 17:25:07 2017 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Thu Nov 23 17:25:51 2017 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/ml/FileExporter.java |  13 +-
 .../main/java/org/apache/ignite/ml/Trainer.java |   7 +
 .../clustering/KMeansDistributedClusterer.java  |   9 +-
 .../ignite/ml/clustering/KMeansModel.java       |   1 -
 .../java/org/apache/ignite/ml/math/Blas.java    |  28 +-
 .../java/org/apache/ignite/ml/math/Matrix.java  |   1 +
 .../apache/ignite/ml/math/MatrixStorage.java    |   2 -
 .../java/org/apache/ignite/ml/math/Vector.java  |   1 +
 .../ignite/ml/math/distributed/CacheUtils.java  | 266 ++++---
 .../math/distributed/keys/RowColMatrixKey.java  |   2 +-
 .../distributed/keys/impl/MatrixBlockKey.java   |  32 +-
 .../distributed/keys/impl/SparseMatrixKey.java  |  15 +-
 .../distributed/keys/impl/VectorBlockKey.java   |  31 +-
 .../ignite/ml/math/functions/Functions.java     |   6 +-
 .../math/functions/IgniteToDoubleFunction.java  |   1 +
 .../ml/math/functions/IgniteTriFunction.java    |   5 +-
 .../ml/math/impls/matrix/AbstractMatrix.java    |  28 +-
 .../matrix/SparseBlockDistributedMatrix.java    |  21 +-
 .../impls/matrix/SparseDistributedMatrix.java   |  31 +-
 .../storage/matrix/BlockMatrixStorage.java      |  58 +-
 .../storage/matrix/BlockVectorStorage.java      |  62 +-
 .../impls/storage/matrix/MapWrapperStorage.java |   7 +-
 .../matrix/SparseDistributedMatrixStorage.java  |  22 +-
 .../matrix/SparseLocalOnHeapMatrixStorage.java  |   3 +-
 .../vector/SparseDistributedVectorStorage.java  | 100 +--
 .../vector/SparseLocalOnHeapVectorStorage.java  |   2 +-
 .../ml/math/impls/vector/MapWrapperVector.java  |   1 -
 .../vector/SparseBlockDistributedVector.java    |  18 +-
 .../impls/vector/SparseDistributedVector.java   |  46 +-
 .../ml/math/impls/vector/VectorBlockEntry.java  |   2 -
 .../apache/ignite/ml/math/util/MatrixUtil.java  |   6 +-
 .../columnbased/caches/ProjectionsCache.java    |   8 +-
 .../org/apache/ignite/ml/util/MnistUtils.java   |  20 +-
 .../java/org/apache/ignite/ml/util/Utils.java   |   9 +-
 .../org/apache/ignite/ml/LocalModelsTest.java   |   4 +-
 ...KMeansDistributedClustererTestMultiNode.java |  13 +-
 .../org/apache/ignite/ml/math/BlasTest.java     |  11 +-
 .../ml/math/MathImplDistributedTestSuite.java   |  16 +-
 .../impls/matrix/MatrixImplementationsTest.java |   6 +-
 .../SparseDistributedBlockMatrixTest.java       |  85 ++-
 .../matrix/SparseDistributedMatrixTest.java     |  22 +-
 .../SparseDistributedVectorStorageTest.java     |  12 +-
 .../SparseBlockDistributedVectorTest.java       |  31 +-
 .../vector/SparseDistributedVectorTest.java     |  49 +-
 ...tedBlockOLSMultipleLinearRegressionTest.java | 733 +++++++++----------
 ...tributedOLSMultipleLinearRegressionTest.java |  57 +-
 .../OLSMultipleLinearRegressionTest.java        |   1 -
 .../trees/columntrees.manualrun.properties      |   3 +-
 48 files changed, 969 insertions(+), 938 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/FileExporter.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/FileExporter.java b/modules/ml/src/main/java/org/apache/ignite/ml/FileExporter.java
index 79bb71c..2fb73c0 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/FileExporter.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/FileExporter.java
@@ -42,11 +42,12 @@ public class FileExporter<D> implements Exporter<D, String> {
 
     /** {@inheritDoc} */
     @Override public void save(D d, String path) {
-        try (FileOutputStream fos = new FileOutputStream(path)){
-            try (ObjectOutputStream outStream = new ObjectOutputStream(fos)){
+        try (FileOutputStream fos = new FileOutputStream(path)) {
+            try (ObjectOutputStream outStream = new ObjectOutputStream(fos)) {
                 outStream.writeObject(d);
             }
-        } catch (IOException e) {
+        }
+        catch (IOException e) {
             if (log != null)
                 log.error("Error opening file.", e);
         }
@@ -56,13 +57,13 @@ public class FileExporter<D> implements Exporter<D, String> {
     @Override public D load(String path) {
         D mdl = null;
 
-        try (FileInputStream fis = new FileInputStream(path)){
+        try (FileInputStream fis = new FileInputStream(path)) {
             try (ObjectInputStream inputStream = new ObjectInputStream(fis)) {
                 mdl = (D)inputStream.readObject();
             }
             catch (ClassNotFoundException e) {
-            if (log != null)
-                log.error("Object creation failed.", e);
+                if (log != null)
+                    log.error("Object creation failed.", e);
             }
         }
         catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/Trainer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/Trainer.java b/modules/ml/src/main/java/org/apache/ignite/ml/Trainer.java
index 795e218..a95a1cc 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/Trainer.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/Trainer.java
@@ -22,9 +22,16 @@ import org.apache.ignite.ml.trees.trainers.columnbased.ColumnDecisionTreeTrainer
 /**
  * Interface for Trainers. Trainer is just a function which produces model from the data.
  * See for example {@link ColumnDecisionTreeTrainer}.
+ *
  * @param <M> Type of produced model.
  * @param <T> Type of data needed for model producing.
  */
 public interface Trainer<M extends Model, T> {
+    /**
+     * Returns model based on data
+     *
+     * @param data data to build model
+     * @return model
+     */
     M train(T data);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansDistributedClusterer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansDistributedClusterer.java b/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansDistributedClusterer.java
index 4286f42..24938bc 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansDistributedClusterer.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansDistributedClusterer.java
@@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import javax.cache.Cache;
 import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.ml.math.DistanceMeasure;
 import org.apache.ignite.ml.math.Vector;
 import org.apache.ignite.ml.math.VectorUtils;
@@ -205,7 +204,8 @@ public class KMeansDistributedClusterer extends BaseKMeansClusterer<SparseDistri
     }
 
     /** */
-    private ConcurrentHashMap<Integer, Double> getNewCosts(SparseDistributedMatrix points, List<Vector> newCenters, String cacheName) {
+    private ConcurrentHashMap<Integer, Double> getNewCosts(SparseDistributedMatrix points, List<Vector> newCenters,
+        String cacheName) {
         return distributedFold(cacheName,
             (IgniteBiFunction<Cache.Entry<SparseMatrixKey, ConcurrentHashMap<Integer, Double>>,
                 ConcurrentHashMap<Integer, Double>,
@@ -223,7 +223,8 @@ public class KMeansDistributedClusterer extends BaseKMeansClusterer<SparseDistri
     }
 
     /** */
-    private ConcurrentHashMap<Integer, Integer> weightCenters(UUID uid, List<Vector> distinctCenters, String cacheName) {
+    private ConcurrentHashMap<Integer, Integer> weightCenters(UUID uid, List<Vector> distinctCenters,
+        String cacheName) {
         return distributedFold(cacheName,
             (IgniteBiFunction<Cache.Entry<SparseMatrixKey, Map<Integer, Double>>,
                 ConcurrentHashMap<Integer, Integer>,
@@ -249,7 +250,7 @@ public class KMeansDistributedClusterer extends BaseKMeansClusterer<SparseDistri
             key -> key.dataStructureId().equals(uid),
             (map1, map2) -> MapUtil.mergeMaps(map1, map2, (integer, integer2) -> integer2 + integer,
                 ConcurrentHashMap::new),
-                ConcurrentHashMap::new);
+            ConcurrentHashMap::new);
     }
 
     /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansModel.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansModel.java b/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansModel.java
index 7f6f877..c449b8b 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansModel.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/clustering/KMeansModel.java
@@ -110,5 +110,4 @@ public class KMeansModel implements ClusterizationModel<Vector, Integer>, Export
         return distance.equals(that.distance) && Arrays.deepEquals(centers, that.centers);
     }
 
-
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java
index 4b83ede..9929725 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java
@@ -43,7 +43,8 @@ public class Blas {
     /** F2J implementation of BLAS. */
     transient static private BLAS f2jBlas = new F2jBLAS();
 
-    /** Native implementation of BLAS. F2J implementation will be used as fallback if no native implementation is found
+    /**
+     * Native implementation of BLAS. F2J implementation will be used as fallback if no native implementation is found.
      */
     transient static private BLAS nativeBlas = BLAS.getInstance();
 
@@ -64,7 +65,7 @@ public class Blas {
             axpy(a, (SparseLocalVector)x, y.getStorage().data());
         else
             throw new MathIllegalArgumentException("Operation 'axpy' doesn't support this combination of parameters [x="
-                + x.getClass().getName() + ", y="+y.getClass().getName()+"].");
+                + x.getClass().getName() + ", y=" + y.getClass().getName() + "].");
     }
 
     /** */
@@ -83,7 +84,8 @@ public class Blas {
                 y[k] += x.getX(k);
                 k++;
             }
-        } else {
+        }
+        else {
             int k = 0;
 
             while (k < xSize) {
@@ -127,11 +129,11 @@ public class Blas {
                         yData[i] = x.getX(i);
                 }
             }
-        } else
+        }
+        else
             throw new IllegalArgumentException("Vector y must be array based in copy.");
     }
 
-
     /**
      * Performs in-place multiplication of vector x by a real scalar a. (x = a * x)
      *
@@ -146,7 +148,8 @@ public class Blas {
 
             for (Integer i : indexes)
                 x.compute(i, (ind, v) -> v * a);
-        } else
+        }
+        else
             throw new IllegalArgumentException();
     }
 
@@ -179,7 +182,8 @@ public class Blas {
     }
 
     /**
-     * A := alpha * x * x^T + A
+     * A := alpha * x * x^T + A.
+     *
      * @param alpha a real scalar that will be multiplied to x * x^T^.
      * @param x the vector x that contains the n elements.
      * @param a the symmetric matrix A. Size of n x n.
@@ -266,20 +270,20 @@ public class Blas {
     /**
      * Currently we support only local onheap matrices for BLAS.
      */
-    private static void checkMatrixType(Matrix a, String op){
+    private static void checkMatrixType(Matrix a, String op) {
         if (a instanceof DenseLocalOffHeapMatrix || a instanceof SparseDistributedMatrix
             || a instanceof SparseBlockDistributedMatrix)
             throw new IllegalArgumentException("Operation doesn't support for matrix [class="
-                + a.getClass().getName() + ", operation="+op+"].");
+                + a.getClass().getName() + ", operation=" + op + "].");
     }
 
     /**
      * Currently we support only local onheap vectors for BLAS.
      */
-    private static void checkVectorType(Vector a, String op){
+    private static void checkVectorType(Vector a, String op) {
         if (a instanceof DenseLocalOffHeapVector || a instanceof SparseLocalOffHeapVector || a instanceof CacheVector)
             throw new IllegalArgumentException("Operation doesn't support for vector [class="
-                + a.getClass().getName() + ", operation="+op+"].");
+                + a.getClass().getName() + ", operation=" + op + "].");
     }
 
     /**
@@ -321,6 +325,7 @@ public class Blas {
 
     /**
      * M := alpha * M.
+     *
      * @param m Matrix M.
      * @param alpha Alpha.
      */
@@ -333,6 +338,7 @@ public class Blas {
 
     /**
      * v := alpha * v.
+     *
      * @param v Vector v.
      * @param alpha Aplha.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java
index 8c171a6..9d1ece4 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java
@@ -557,6 +557,7 @@ public interface Matrix extends MetaAttributes, Externalizable, StorageOpsMetric
 
     /**
      * Replace matrix entry with value oldVal at (row, col) with result of computing f(row, col, oldVal).
+     *
      * @param row Row.
      * @param col Column.
      * @param f Function used for replacing.

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixStorage.java
index e4f9e40..9738857 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixStorage.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixStorage.java
@@ -49,14 +49,12 @@ public interface MatrixStorage extends Externalizable, StorageOpsMetrics, Destro
 
     /**
      * @return Matrix elements storage mode.
-     *
      * @see StorageConstants
      */
     public int storageMode();
 
     /**
      * @return Matrix access mode.
-     *
      * @see StorageConstants
      */
     public int accessMode();

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/Vector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Vector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Vector.java
index 5fd39af..391c5fe 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Vector.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Vector.java
@@ -500,6 +500,7 @@ public interface Vector extends MetaAttributes, Externalizable, StorageOpsMetric
 
     /**
      * Replace vector entry with value oldVal at i with result of computing f(i, oldVal).
+     *
      * @param i Position.
      * @param f Function used for replacing.
      **/

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/CacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/CacheUtils.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/CacheUtils.java
index 37384b8..6baa865 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/CacheUtils.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/CacheUtils.java
@@ -17,6 +17,16 @@
 
 package org.apache.ignite.ml.math.distributed;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.BinaryOperator;
+import java.util.stream.Stream;
+import javax.cache.Cache;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
@@ -36,16 +46,16 @@ import org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey;
 import org.apache.ignite.ml.math.distributed.keys.impl.MatrixBlockKey;
 import org.apache.ignite.ml.math.distributed.keys.impl.VectorBlockKey;
 import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.ml.math.functions.*;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteBinaryOperator;
+import org.apache.ignite.ml.math.functions.IgniteConsumer;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IgniteSupplier;
+import org.apache.ignite.ml.math.functions.IgniteTriFunction;
 import org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry;
 import org.apache.ignite.ml.math.impls.vector.VectorBlockEntry;
 
-import javax.cache.Cache;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.BinaryOperator;
-import java.util.stream.Stream;
-
 /**
  * Distribution-related misc. support.
  *
@@ -97,8 +107,8 @@ public class CacheUtils {
 
     /**
      * @param cacheName Cache name.
-     * @param k         Key into the cache.
-     * @param <K>       Key type.
+     * @param k Key into the cache.
+     * @param <K> Key type.
      * @return Cluster group for given key.
      */
     protected static <K> ClusterGroup getClusterGroupForGivenKey(String cacheName, K k) {
@@ -109,8 +119,8 @@ public class CacheUtils {
      * @param cacheName Cache name.
      * @param keyMapper {@link KeyMapper} to validate cache key.
      * @param valMapper {@link ValueMapper} to obtain double value for given cache key.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      * @return Sum of the values obtained for valid keys.
      */
     public static <K, V> double sum(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
@@ -119,7 +129,8 @@ public class CacheUtils {
                 double v = valMapper.toDouble(ce.entry().getValue());
 
                 return acc == null ? v : acc + v;
-            } else
+            }
+            else
                 return acc;
         });
 
@@ -141,14 +152,16 @@ public class CacheUtils {
             double sum;
 
             if (v instanceof Map) {
-                Map<Integer, Double> map = (Map<Integer, Double>) v;
+                Map<Integer, Double> map = (Map<Integer, Double>)v;
 
                 sum = sum(map.values());
-            } else if (v instanceof MatrixBlockEntry) {
-                MatrixBlockEntry be = (MatrixBlockEntry) v;
+            }
+            else if (v instanceof MatrixBlockEntry) {
+                MatrixBlockEntry be = (MatrixBlockEntry)v;
 
                 sum = be.sum();
-            } else
+            }
+            else
                 throw new UnsupportedOperationException();
 
             return acc == null ? sum : acc + sum;
@@ -170,8 +183,8 @@ public class CacheUtils {
      * @param cacheName Cache name.
      * @param keyMapper {@link KeyMapper} to validate cache key.
      * @param valMapper {@link ValueMapper} to obtain double value for given cache key.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      * @return Minimum value for valid keys.
      */
     public static <K, V> double min(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
@@ -183,7 +196,8 @@ public class CacheUtils {
                     return v;
                 else
                     return Math.min(acc, v);
-            } else
+            }
+            else
                 return acc;
         });
 
@@ -205,14 +219,16 @@ public class CacheUtils {
             double min;
 
             if (v instanceof Map) {
-                Map<Integer, Double> map = (Map<Integer, Double>) v;
+                Map<Integer, Double> map = (Map<Integer, Double>)v;
 
                 min = Collections.min(map.values());
-            } else if (v instanceof MatrixBlockEntry) {
-                MatrixBlockEntry be = (MatrixBlockEntry) v;
+            }
+            else if (v instanceof MatrixBlockEntry) {
+                MatrixBlockEntry be = (MatrixBlockEntry)v;
 
                 min = be.minValue();
-            } else
+            }
+            else
                 throw new UnsupportedOperationException();
 
             if (acc == null)
@@ -240,14 +256,16 @@ public class CacheUtils {
             double max;
 
             if (v instanceof Map) {
-                Map<Integer, Double> map = (Map<Integer, Double>) v;
+                Map<Integer, Double> map = (Map<Integer, Double>)v;
 
                 max = Collections.max(map.values());
-            } else if (v instanceof MatrixBlockEntry) {
-                MatrixBlockEntry be = (MatrixBlockEntry) v;
+            }
+            else if (v instanceof MatrixBlockEntry) {
+                MatrixBlockEntry be = (MatrixBlockEntry)v;
 
                 max = be.maxValue();
-            } else
+            }
+            else
                 throw new UnsupportedOperationException();
 
             if (acc == null)
@@ -264,8 +282,8 @@ public class CacheUtils {
      * @param cacheName Cache name.
      * @param keyMapper {@link KeyMapper} to validate cache key.
      * @param valMapper {@link ValueMapper} to obtain double value for given cache key.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      * @return Maximum value for valid keys.
      */
     public static <K, V> double max(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
@@ -277,7 +295,8 @@ public class CacheUtils {
                     return v;
                 else
                     return Math.max(acc, v);
-            } else
+            }
+            else
                 return acc;
         });
 
@@ -288,12 +307,12 @@ public class CacheUtils {
      * @param cacheName Cache name.
      * @param keyMapper {@link KeyMapper} to validate cache key.
      * @param valMapper {@link ValueMapper} to obtain double value for given cache key.
-     * @param mapper    Mapping {@link IgniteFunction}.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param mapper Mapping {@link IgniteFunction}.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      */
     public static <K, V> void map(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper,
-                                  IgniteFunction<Double, Double> mapper) {
+        IgniteFunction<Double, Double> mapper) {
         foreach(cacheName, (CacheEntry<K, V> ce) -> {
             K k = ce.entry().getKey();
 
@@ -305,7 +324,7 @@ public class CacheUtils {
 
     /**
      * @param matrixUuid Matrix UUID.
-     * @param mapper     Mapping {@link IgniteFunction}.
+     * @param mapper Mapping {@link IgniteFunction}.
      */
     @SuppressWarnings("unchecked")
     public static <K, V> void sparseMap(UUID matrixUuid, IgniteDoubleFunction<Double> mapper, String cacheName) {
@@ -319,16 +338,18 @@ public class CacheUtils {
             V v = ce.entry().getValue();
 
             if (v instanceof Map) {
-                Map<Integer, Double> map = (Map<Integer, Double>) v;
+                Map<Integer, Double> map = (Map<Integer, Double>)v;
 
                 for (Map.Entry<Integer, Double> e : (map.entrySet()))
                     e.setValue(mapper.apply(e.getValue()));
 
-            } else if (v instanceof MatrixBlockEntry) {
-                MatrixBlockEntry be = (MatrixBlockEntry) v;
+            }
+            else if (v instanceof MatrixBlockEntry) {
+                MatrixBlockEntry be = (MatrixBlockEntry)v;
 
                 be.map(mapper);
-            } else
+            }
+            else
                 throw new UnsupportedOperationException();
 
             ce.cache().put(k, v);
@@ -343,15 +364,15 @@ public class CacheUtils {
     private static <K> IgnitePredicate<K> sparseKeyFilter(UUID matrixUuid) {
         return key -> {
             if (key instanceof DataStructureCacheKey)
-                return ((DataStructureCacheKey) key).dataStructureId().equals(matrixUuid);
+                return ((DataStructureCacheKey)key).dataStructureId().equals(matrixUuid);
             else if (key instanceof IgniteBiTuple)
-                return ((IgniteBiTuple<Integer, UUID>) key).get2().equals(matrixUuid);
+                return ((IgniteBiTuple<Integer, UUID>)key).get2().equals(matrixUuid);
             else if (key instanceof MatrixBlockKey)
-                return ((MatrixBlockKey) key).dataStructureId().equals(matrixUuid);
+                return ((MatrixBlockKey)key).dataStructureId().equals(matrixUuid);
             else if (key instanceof RowColMatrixKey)
-                return ((RowColMatrixKey) key).dataStructureId().equals(matrixUuid);
+                return ((RowColMatrixKey)key).dataStructureId().equals(matrixUuid);
             else if (key instanceof VectorBlockKey)
-                return ((VectorBlockKey) key).dataStructureId().equals(matrixUuid);
+                return ((VectorBlockKey)key).dataStructureId().equals(matrixUuid);
             else
                 throw new UnsupportedOperationException(); // TODO: handle my poor doubles
         };
@@ -359,9 +380,9 @@ public class CacheUtils {
 
     /**
      * @param cacheName Cache name.
-     * @param fun       An operation that accepts a cache entry and processes it.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param fun An operation that accepts a cache entry and processes it.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      */
     private static <K, V> void foreach(String cacheName, IgniteConsumer<CacheEntry<K, V>> fun) {
         foreach(cacheName, fun, null);
@@ -369,13 +390,13 @@ public class CacheUtils {
 
     /**
      * @param cacheName Cache name.
-     * @param fun       An operation that accepts a cache entry and processes it.
+     * @param fun An operation that accepts a cache entry and processes it.
      * @param keyFilter Cache keys filter.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      */
     protected static <K, V> void foreach(String cacheName, IgniteConsumer<CacheEntry<K, V>> fun,
-                                         IgnitePredicate<K> keyFilter) {
+        IgnitePredicate<K> keyFilter) {
         bcast(cacheName, () -> {
             Ignite ignite = Ignition.localIgnite();
             IgniteCache<K, V> cache = ignite.getOrCreateCache(cacheName);
@@ -393,7 +414,7 @@ public class CacheUtils {
                 // Iterate over given partition.
                 // Query returns an empty cursor if this partition is not stored on this node.
                 for (Cache.Entry<K, V> entry : cache.query(new ScanQuery<K, V>(part,
-                        (k, v) -> affinity.mapPartitionToNode(p) == locNode && (keyFilter == null || keyFilter.apply(k)))))
+                    (k, v) -> affinity.mapPartitionToNode(p) == locNode && (keyFilter == null || keyFilter.apply(k)))))
                     fun.accept(new CacheEntry<>(entry, cache));
             }
         });
@@ -401,14 +422,14 @@ public class CacheUtils {
 
     /**
      * @param cacheName Cache name.
-     * @param fun       An operation that accepts a cache entry and processes it.
-     * @param ignite    Ignite.
-     * @param keysGen   Keys generator.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param fun An operation that accepts a cache entry and processes it.
+     * @param ignite Ignite.
+     * @param keysGen Keys generator.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      */
     public static <K, V> void update(String cacheName, Ignite ignite,
-                                     IgniteBiFunction<Ignite, Cache.Entry<K, V>, Stream<Cache.Entry<K, V>>> fun, IgniteSupplier<Set<K>> keysGen) {
+        IgniteBiFunction<Ignite, Cache.Entry<K, V>, Stream<Cache.Entry<K, V>>> fun, IgniteSupplier<Set<K>> keysGen) {
         bcast(cacheName, ignite, () -> {
             Ignite ig = Ignition.localIgnite();
             IgniteCache<K, V> cache = ig.getOrCreateCache(cacheName);
@@ -435,14 +456,14 @@ public class CacheUtils {
 
     /**
      * @param cacheName Cache name.
-     * @param fun       An operation that accepts a cache entry and processes it.
-     * @param ignite    Ignite.
-     * @param keysGen   Keys generator.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
+     * @param fun An operation that accepts a cache entry and processes it.
+     * @param ignite Ignite.
+     * @param keysGen Keys generator.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
      */
     public static <K, V> void update(String cacheName, Ignite ignite, IgniteConsumer<Cache.Entry<K, V>> fun,
-                                     IgniteSupplier<Set<K>> keysGen) {
+        IgniteSupplier<Set<K>> keysGen) {
         bcast(cacheName, ignite, () -> {
             Ignite ig = Ignition.localIgnite();
             IgniteCache<K, V> cache = ig.getOrCreateCache(cacheName);
@@ -473,10 +494,10 @@ public class CacheUtils {
      * <b>Currently fold supports only commutative operations.<b/>
      *
      * @param cacheName Cache name.
-     * @param folder    Fold function operating over cache entries.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
-     * @param <A>       Fold result type.
+     * @param folder Fold function operating over cache entries.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
+     * @param <A> Fold result type.
      * @return Fold operation result.
      */
     public static <K, V, A> Collection<A> fold(String cacheName, IgniteBiFunction<CacheEntry<K, V>, A, A> folder) {
@@ -487,14 +508,14 @@ public class CacheUtils {
      * <b>Currently fold supports only commutative operations.<b/>
      *
      * @param cacheName Cache name.
-     * @param folder    Fold function operating over cache entries.
-     * @param <K>       Cache key object type.
-     * @param <V>       Cache value object type.
-     * @param <A>       Fold result type.
+     * @param folder Fold function operating over cache entries.
+     * @param <K> Cache key object type.
+     * @param <V> Cache value object type.
+     * @param <A> Fold result type.
      * @return Fold operation result.
      */
     public static <K, V, A> Collection<A> fold(String cacheName, IgniteBiFunction<CacheEntry<K, V>, A, A> folder,
-                                               IgnitePredicate<K> keyFilter) {
+        IgnitePredicate<K> keyFilter) {
         return bcast(cacheName, () -> {
             Ignite ignite = Ignition.localIgnite();
             IgniteCache<K, V> cache = ignite.getOrCreateCache(cacheName);
@@ -514,7 +535,7 @@ public class CacheUtils {
                 // Iterate over given partition.
                 // Query returns an empty cursor if this partition is not stored on this node.
                 for (Cache.Entry<K, V> entry : cache.query(new ScanQuery<K, V>(part,
-                        (k, v) -> affinity.mapPartitionToNode(p) == locNode && (keyFilter == null || keyFilter.apply(k)))))
+                    (k, v) -> affinity.mapPartitionToNode(p) == locNode && (keyFilter == null || keyFilter.apply(k)))))
                     a = folder.apply(new CacheEntry<>(entry, cache), a);
             }
 
@@ -525,34 +546,34 @@ public class CacheUtils {
     /**
      * Distributed version of fold operation.
      *
-     * @param cacheName   Cache name.
-     * @param folder      Folder.
-     * @param keyFilter   Key filter.
+     * @param cacheName Cache name.
+     * @param folder Folder.
+     * @param keyFilter Key filter.
      * @param accumulator Accumulator.
      * @param zeroValSupp Zero value supplier.
      */
     public static <K, V, A> A distributedFold(String cacheName, IgniteBiFunction<Cache.Entry<K, V>, A, A> folder,
-                                              IgnitePredicate<K> keyFilter, BinaryOperator<A> accumulator, IgniteSupplier<A> zeroValSupp) {
+        IgnitePredicate<K> keyFilter, BinaryOperator<A> accumulator, IgniteSupplier<A> zeroValSupp) {
         return sparseFold(cacheName, folder, keyFilter, accumulator, zeroValSupp, null, null, 0,
-                false);
+            false);
     }
 
     /**
      * Sparse version of fold. This method also applicable to sparse zeroes.
      *
-     * @param cacheName   Cache name.
-     * @param folder      Folder.
-     * @param keyFilter   Key filter.
+     * @param cacheName Cache name.
+     * @param folder Folder.
+     * @param keyFilter Key filter.
      * @param accumulator Accumulator.
      * @param zeroValSupp Zero value supplier.
-     * @param defVal      Default value.
-     * @param defKey      Default key.
-     * @param defValCnt   Def value count.
+     * @param defVal Default value.
+     * @param defKey Default key.
+     * @param defValCnt Def value count.
      * @param isNilpotent Is nilpotent.
      */
     private static <K, V, A> A sparseFold(String cacheName, IgniteBiFunction<Cache.Entry<K, V>, A, A> folder,
-                                          IgnitePredicate<K> keyFilter, BinaryOperator<A> accumulator, IgniteSupplier<A> zeroValSupp, V defVal, K defKey,
-                                          long defValCnt, boolean isNilpotent) {
+        IgnitePredicate<K> keyFilter, BinaryOperator<A> accumulator, IgniteSupplier<A> zeroValSupp, V defVal, K defKey,
+        long defValCnt, boolean isNilpotent) {
 
         A defRes = zeroValSupp.get();
 
@@ -579,7 +600,7 @@ public class CacheUtils {
                 // Iterate over given partition.
                 // Query returns an empty cursor if this partition is not stored on this node.
                 for (Cache.Entry<K, V> entry : cache.query(new ScanQuery<K, V>(part,
-                        (k, v) -> affinity.mapPartitionToNode(p) == locNode && (keyFilter == null || keyFilter.apply(k)))))
+                    (k, v) -> affinity.mapPartitionToNode(p) == locNode && (keyFilter == null || keyFilter.apply(k)))))
                     a = folder.apply(entry, a);
             }
 
@@ -588,11 +609,23 @@ public class CacheUtils {
         return totalRes.stream().reduce(defRes, accumulator);
     }
 
+    /**
+     * Distributed version of fold operation. This method also applicable to sparse zeroes.
+     *
+     * @param cacheName Cache name.
+     * @param ignite ignite
+     * @param acc Accumulator
+     * @param supp supplier
+     * @param entriesGen entries generator
+     * @param comb combiner
+     * @param zeroValSupp Zero value supplier.
+     * @return aggregated result
+     */
     public static <K, V, A, W> A reduce(String cacheName, Ignite ignite,
-                                        IgniteTriFunction<W, Cache.Entry<K, V>, A, A> acc,
-                                        IgniteSupplier<W> supp,
-                                        IgniteSupplier<Iterable<Cache.Entry<K, V>>> entriesGen, IgniteBinaryOperator<A> comb,
-                                        IgniteSupplier<A> zeroValSupp) {
+        IgniteTriFunction<W, Cache.Entry<K, V>, A, A> acc,
+        IgniteSupplier<W> supp,
+        IgniteSupplier<Iterable<Cache.Entry<K, V>>> entriesGen, IgniteBinaryOperator<A> comb,
+        IgniteSupplier<A> zeroValSupp) {
 
         A defRes = zeroValSupp.get();
 
@@ -611,16 +644,29 @@ public class CacheUtils {
         return totalRes.stream().reduce(defRes, comb);
     }
 
-    public static <K, V, A, W> A reduce(String cacheName, IgniteTriFunction<W, Cache.Entry<K, V>, A, A> acc,
-                                        IgniteSupplier<W> supp,
-                                        IgniteSupplier<Iterable<Cache.Entry<K, V>>> entriesGen, IgniteBinaryOperator<A> comb,
-                                        IgniteSupplier<A> zeroValSupp) {
+    /**
+     * Distributed version of fold operation.
+     *
+     * @param cacheName Cache name.
+     * @param acc Accumulator
+     * @param supp supplier
+     * @param entriesGen entries generator
+     * @param comb combiner
+     * @param zeroValSupp Zero value supplier
+     * @return aggregated result
+     */
+    public static <K, V, A, W> A reduce(String cacheName,
+        IgniteTriFunction<W, Cache.Entry<K, V>, A, A> acc,
+        IgniteSupplier<W> supp,
+        IgniteSupplier<Iterable<Cache.Entry<K, V>>> entriesGen,
+        IgniteBinaryOperator<A> comb,
+        IgniteSupplier<A> zeroValSupp) {
         return reduce(cacheName, Ignition.localIgnite(), acc, supp, entriesGen, comb, zeroValSupp);
     }
 
     /**
      * @param cacheName Cache name.
-     * @param run       {@link Runnable} to broadcast to cache nodes for given cache name.
+     * @param run {@link Runnable} to broadcast to cache nodes for given cache name.
      */
     public static void bcast(String cacheName, Ignite ignite, IgniteRunnable run) {
         ignite.compute(ignite.cluster().forDataNodes(cacheName)).broadcast(run);
@@ -630,7 +676,7 @@ public class CacheUtils {
      * Broadcast runnable to data nodes of given cache.
      *
      * @param cacheName Cache name.
-     * @param run       Runnable.
+     * @param run Runnable.
      */
     public static void bcast(String cacheName, IgniteRunnable run) {
         bcast(cacheName, ignite(), run);
@@ -638,8 +684,8 @@ public class CacheUtils {
 
     /**
      * @param cacheName Cache name.
-     * @param call      {@link IgniteCallable} to broadcast to cache nodes for given cache name.
-     * @param <A>       Type returned by the callable.
+     * @param call {@link IgniteCallable} to broadcast to cache nodes for given cache name.
+     * @param <A> Type returned by the callable.
      */
     public static <A> Collection<A> bcast(String cacheName, IgniteCallable<A> call) {
         return bcast(cacheName, ignite(), call);
@@ -649,9 +695,9 @@ public class CacheUtils {
      * Broadcast callable to data nodes of given cache.
      *
      * @param cacheName Cache name.
-     * @param ignite    Ignite instance.
-     * @param call      Callable to broadcast.
-     * @param <A>       Type of callable result.
+     * @param ignite Ignite instance.
+     * @param call Callable to broadcast.
+     * @param <A> Type of callable result.
      * @return Results of callable from each node.
      */
     public static <A> Collection<A> bcast(String cacheName, Ignite ignite, IgniteCallable<A> call) {
@@ -660,7 +706,7 @@ public class CacheUtils {
 
     /**
      * @param vectorUuid Matrix UUID.
-     * @param mapper     Mapping {@link IgniteFunction}.
+     * @param mapper Mapping {@link IgniteFunction}.
      */
     @SuppressWarnings("unchecked")
     public static <K, V> void sparseMapForVector(UUID vectorUuid, IgniteDoubleFunction<V> mapper, String cacheName) {
@@ -674,13 +720,15 @@ public class CacheUtils {
             V v = ce.entry().getValue();
 
             if (v instanceof VectorBlockEntry) {
-                VectorBlockEntry entry = (VectorBlockEntry) v;
+                VectorBlockEntry entry = (VectorBlockEntry)v;
 
-                for (int i = 0; i < entry.size(); i++) entry.set(i, (Double) mapper.apply(entry.get(i)));
+                for (int i = 0; i < entry.size(); i++)
+                    entry.set(i, (Double)mapper.apply(entry.get(i)));
 
-                ce.cache().put(k, (V) entry);
-            } else {
-                V mappingRes = mapper.apply((Double) v);
+                ce.cache().put(k, (V)entry);
+            }
+            else {
+                V mappingRes = mapper.apply((Double)v);
                 ce.cache().put(k, mappingRes);
             }
         }, sparseKeyFilter(vectorUuid));

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/RowColMatrixKey.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/RowColMatrixKey.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/RowColMatrixKey.java
index 78af2e8..05d8027 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/RowColMatrixKey.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/RowColMatrixKey.java
@@ -24,7 +24,7 @@ import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
  */
 public interface RowColMatrixKey extends DataStructureCacheKey {
     /**
-     *  Return index value(blockId, Row/Col index, etc.)
+     * Return index value(blockId, Row/Col index, etc.)
      */
     public int index();
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/MatrixBlockKey.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/MatrixBlockKey.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/MatrixBlockKey.java
index 9e8d81e..6e09499 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/MatrixBlockKey.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/MatrixBlockKey.java
@@ -17,34 +17,40 @@
 
 package org.apache.ignite.ml.math.distributed.keys.impl;
 
-import org.apache.ignite.binary.*;
-import org.apache.ignite.internal.binary.BinaryUtils;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry;
-import org.apache.ignite.ml.math.impls.matrix.SparseBlockDistributedMatrix;
-import org.jetbrains.annotations.Nullable;
-
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.UUID;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry;
+import org.apache.ignite.ml.math.impls.matrix.SparseBlockDistributedMatrix;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Key implementation for {@link MatrixBlockEntry} using for {@link SparseBlockDistributedMatrix}.
  */
-public class MatrixBlockKey implements org.apache.ignite.ml.math.distributed.keys.MatrixBlockKey, Externalizable, Binarylizable {
+public class MatrixBlockKey implements org.apache.ignite.ml.math.distributed.keys.MatrixBlockKey,
+    Externalizable, Binarylizable {
     /** */
     private static final long serialVersionUID = 0L;
+
     /** Block row ID */
     private long blockIdRow;
+
     /** Block col ID */
     private long blockIdCol;
+
     /** Matrix ID */
     private UUID matrixUuid;
+
     /** Block affinity key. */
     private UUID affinityKey;
 
@@ -150,13 +156,11 @@ public class MatrixBlockKey implements org.apache.ignite.ml.math.distributed.key
         MatrixBlockKey that = (MatrixBlockKey)obj;
 
         return blockIdRow == that.blockIdRow && blockIdCol == that.blockIdCol && matrixUuid.equals(that.matrixUuid)
-                && F.eq(affinityKey, that.affinityKey);
+            && F.eq(affinityKey, that.affinityKey);
     }
 
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(MatrixBlockKey.class, this);
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/SparseMatrixKey.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/SparseMatrixKey.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/SparseMatrixKey.java
index 980d433..cbd5208 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/SparseMatrixKey.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/SparseMatrixKey.java
@@ -17,17 +17,16 @@
 
 package org.apache.ignite.ml.math.distributed.keys.impl;
 
-import org.apache.ignite.cache.affinity.AffinityKeyMapped;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey;
-import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
-
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.UUID;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey;
+import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
 
 /**
  * Key implementation for {@link SparseDistributedMatrix}.
@@ -35,8 +34,10 @@ import java.util.UUID;
 public class SparseMatrixKey implements RowColMatrixKey, Externalizable {
     /** */
     private int idx;
+
     /** */
     private UUID matrixId;
+
     /** */
     @AffinityKeyMapped
     private Object affinityKey;
@@ -44,7 +45,7 @@ public class SparseMatrixKey implements RowColMatrixKey, Externalizable {
     /**
      * Default constructor (required by Externalizable).
      */
-    public SparseMatrixKey(){
+    public SparseMatrixKey() {
 
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/VectorBlockKey.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/VectorBlockKey.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/VectorBlockKey.java
index 6052010..718897f 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/VectorBlockKey.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/distributed/keys/impl/VectorBlockKey.java
@@ -17,21 +17,22 @@
 
 package org.apache.ignite.ml.math.distributed.keys.impl;
 
-import org.apache.ignite.binary.*;
-import org.apache.ignite.internal.binary.BinaryUtils;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.ml.math.impls.vector.SparseBlockDistributedVector;
-import org.apache.ignite.ml.math.impls.vector.VectorBlockEntry;
-import org.jetbrains.annotations.Nullable;
-
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.UUID;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.ml.math.impls.vector.SparseBlockDistributedVector;
+import org.apache.ignite.ml.math.impls.vector.VectorBlockEntry;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Key implementation for {@link VectorBlockEntry} using for {@link SparseBlockDistributedVector}.
@@ -39,10 +40,13 @@ import java.util.UUID;
 public class VectorBlockKey implements org.apache.ignite.ml.math.distributed.keys.VectorBlockKey, Externalizable, Binarylizable {
     /** */
     private static final long serialVersionUID = 0L;
+
     /** Block row ID */
     private long blockId;
+
     /** Vector ID */
     private UUID vectorUuid;
+
     /** Block affinity key. */
     private UUID affinityKey;
 
@@ -73,7 +77,6 @@ public class VectorBlockKey implements org.apache.ignite.ml.math.distributed.key
         return blockId;
     }
 
-
     /** {@inheritDoc} */
     @Override public UUID dataStructureId() {
         return vectorUuid;
@@ -138,7 +141,7 @@ public class VectorBlockKey implements org.apache.ignite.ml.math.distributed.key
 
         VectorBlockKey that = (VectorBlockKey)obj;
 
-        return blockId == that.blockId  && vectorUuid.equals(that.vectorUuid)
+        return blockId == that.blockId && vectorUuid.equals(that.vectorUuid)
             && F.eq(affinityKey, that.affinityKey);
     }
 
@@ -146,6 +149,4 @@ public class VectorBlockKey implements org.apache.ignite.ml.math.distributed.key
     @Override public String toString() {
         return S.toString(VectorBlockKey.class, this);
     }
-
-
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/Functions.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/Functions.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/Functions.java
index ce534bd..fa7ee76 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/Functions.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/Functions.java
@@ -17,11 +17,10 @@
 
 package org.apache.ignite.ml.math.functions;
 
-import org.apache.ignite.lang.IgniteBiTuple;
-
 import java.util.Comparator;
 import java.util.List;
 import java.util.function.BiFunction;
+import org.apache.ignite.lang.IgniteBiTuple;
 
 /**
  * Compatibility with Apache Mahout.
@@ -80,6 +79,7 @@ public final class Functions {
 
     /**
      * Generic 'max' function.
+     *
      * @param a First object to compare.
      * @param b Second object to compare.
      * @param f Comparator.
@@ -92,6 +92,7 @@ public final class Functions {
 
     /**
      * Generic 'min' function.
+     *
      * @param a First object to compare.
      * @param b Second object to compare.
      * @param f Comparator.
@@ -215,6 +216,7 @@ public final class Functions {
 
     /**
      * Curry bifunction.
+     *
      * @param f Bifunction to curry.
      * @param <A> Type of first argument of {@code f}.
      * @param <B> Type of second argument of {@code f}.

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteToDoubleFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteToDoubleFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteToDoubleFunction.java
index 59a8bf3..7fcb455 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteToDoubleFunction.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteToDoubleFunction.java
@@ -20,6 +20,7 @@ package org.apache.ignite.ml.math.functions;
 import java.io.Serializable;
 import java.util.function.ToDoubleFunction;
 
+/** */
 @FunctionalInterface
 public interface IgniteToDoubleFunction<T> extends ToDoubleFunction<T>, Serializable {
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteTriFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteTriFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteTriFunction.java
index 3284a00..4d8fd20 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteTriFunction.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteTriFunction.java
@@ -23,13 +23,14 @@ import java.util.function.Function;
 
 /** Serializable TriFunction (A, B, C) -> R. */
 @FunctionalInterface
-public interface IgniteTriFunction<A,B,C,R> extends Serializable {
+public interface IgniteTriFunction<A, B, C, R> extends Serializable {
     /** */
     R apply(A a, B b, C c);
 
     /** */
     default <V> IgniteTriFunction<A, B, C, V> andThen(Function<? super R, ? extends V> after) {
         Objects.requireNonNull(after);
+
         return (A a, B b, C c) -> after.apply(apply(a, b, c));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/AbstractMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/AbstractMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/AbstractMatrix.java
index 89f567e..ef6bc05 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/AbstractMatrix.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/AbstractMatrix.java
@@ -332,7 +332,7 @@ public abstract class AbstractMatrix implements Matrix {
     /** {@inheritDoc} */
     @Override public Matrix assign(double val) {
         if (sto.isArrayBased())
-                Arrays.fill(sto.data(), val);
+            Arrays.fill(sto.data(), val);
         else {
             int rows = rowSize();
             int cols = columnSize();
@@ -717,7 +717,7 @@ public abstract class AbstractMatrix implements Matrix {
         Vector res = new DenseLocalOnHeapVector(columnSize());
 
         for (int i = 0; i < columnSize(); i++)
-            res.setX(i, getX(row,i));
+            res.setX(i, getX(row, i));
 
         return res;
     }
@@ -740,9 +740,13 @@ public abstract class AbstractMatrix implements Matrix {
     /** {@inheritDoc} */
     @Override public Vector getCol(int col) {
         checkColumnIndex(col);
+
         Vector res;
-        if (isDistributed()) res = MatrixUtil.likeVector(this, rowSize());
-        else res = new DenseLocalOnHeapVector(rowSize());
+
+        if (isDistributed())
+            res = MatrixUtil.likeVector(this, rowSize());
+        else
+            res = new DenseLocalOnHeapVector(rowSize());
 
         for (int i = 0; i < rowSize(); i++)
             res.setX(i, getX(i, col));
@@ -797,7 +801,7 @@ public abstract class AbstractMatrix implements Matrix {
 
         Vector res = likeVector(rows);
 
-        Blas.gemv(1,this,vec,0,res);
+        Blas.gemv(1, this, vec, 0, res);
 
         return res;
     }
@@ -977,13 +981,19 @@ public abstract class AbstractMatrix implements Matrix {
         setX(row, col, f.apply(row, col, getX(row, col)));
     }
 
-
+    /**
+     * Return max amount of columns in 2d array.
+     *
+     * TODO: why this in this class, mb some util class?
+     *
+     * @param data Data.
+     */
     protected int getMaxAmountOfColumns(double[][] data) {
-        int maxAmountOfColumns = 0;
+        int maxAmountOfCols = 0;
 
         for (int i = 0; i < data.length; i++)
-            maxAmountOfColumns = Math.max(maxAmountOfColumns, data[i].length);
+            maxAmountOfCols = Math.max(maxAmountOfCols, data[i].length);
 
-        return maxAmountOfColumns;
+        return maxAmountOfCols;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseBlockDistributedMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseBlockDistributedMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseBlockDistributedMatrix.java
index ea9fb8c..2d822d2 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseBlockDistributedMatrix.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseBlockDistributedMatrix.java
@@ -17,6 +17,10 @@
 
 package org.apache.ignite.ml.math.impls.matrix;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
@@ -37,11 +41,6 @@ import org.apache.ignite.ml.math.impls.vector.SparseBlockDistributedVector;
 import org.apache.ignite.ml.math.impls.vector.SparseDistributedVector;
 import org.apache.ignite.ml.math.impls.vector.VectorBlockEntry;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
 /**
  * Sparse block distributed matrix. This matrix represented by blocks 32x32 {@link MatrixBlockEntry}.
  *
@@ -71,6 +70,7 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
      */
     public SparseBlockDistributedMatrix(double[][] data) {
         assert data.length > 0;
+
         setStorage(new BlockMatrixStorage(data.length, getMaxAmountOfColumns(data)));
 
         for (int i = 0; i < data.length; i++)
@@ -117,7 +117,7 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
             throw new CardinalityException(columnSize(), mtx.rowSize());
 
         SparseBlockDistributedMatrix matrixA = this;
-        SparseBlockDistributedMatrix matrixB = (SparseBlockDistributedMatrix) mtx;
+        SparseBlockDistributedMatrix matrixB = (SparseBlockDistributedMatrix)mtx;
 
         String cacheName = this.storage().cacheName();
         SparseBlockDistributedMatrix matrixC = new SparseBlockDistributedMatrix(matrixA.rowSize(), matrixB.columnSize());
@@ -166,7 +166,6 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
         return matrixC;
     }
 
-
     /**
      * {@inheritDoc}
      */
@@ -179,8 +178,7 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
             throw new CardinalityException(columnSize(), vec.size());
 
         SparseBlockDistributedMatrix matrixA = this;
-        SparseBlockDistributedVector vectorB = (SparseBlockDistributedVector) vec;
-
+        SparseBlockDistributedVector vectorB = (SparseBlockDistributedVector)vec;
 
         String cacheName = this.storage().cacheName();
         SparseBlockDistributedVector vectorC = new SparseBlockDistributedVector(matrixA.rowSize());
@@ -205,7 +203,6 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
             locKeys.forEach(key -> {
                 long newBlockId = key.blockId();
 
-
                 IgnitePair<Long> newBlockIdForMtx = new IgnitePair<>(newBlockId, 0L);
 
                 VectorBlockEntry blockC = null;
@@ -296,7 +293,7 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
 
     /** */
     private UUID getUUID() {
-        return ((BlockMatrixStorage) getStorage()).getUUID();
+        return ((BlockMatrixStorage)getStorage()).getUUID();
     }
 
     /**
@@ -313,6 +310,6 @@ public class SparseBlockDistributedMatrix extends AbstractMatrix implements Stor
      *
      */
     private BlockMatrixStorage storage() {
-        return (BlockMatrixStorage) getStorage();
+        return (BlockMatrixStorage)getStorage();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
index 497241d..3288724 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
@@ -17,6 +17,9 @@
 
 package org.apache.ignite.ml.math.impls.matrix;
 
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.affinity.Affinity;
@@ -32,10 +35,6 @@ import org.apache.ignite.ml.math.impls.storage.matrix.SparseDistributedMatrixSto
 import org.apache.ignite.ml.math.impls.storage.vector.SparseDistributedVectorStorage;
 import org.apache.ignite.ml.math.impls.vector.SparseDistributedVector;
 
-import java.util.Collection;
-import java.util.Map;
-import java.util.UUID;
-
 /**
  * Sparse distributed matrix implementation based on data grid.
  * <p>
@@ -76,14 +75,13 @@ public class SparseDistributedMatrix extends AbstractMatrix implements StorageCo
      */
     public SparseDistributedMatrix(double[][] data) {
         assert data.length > 0;
-        setStorage(new SparseDistributedMatrixStorage(data.length, getMaxAmountOfColumns(data),  StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE));
+        setStorage(new SparseDistributedMatrixStorage(data.length, getMaxAmountOfColumns(data), StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE));
 
         for (int i = 0; i < data.length; i++)
             for (int j = 0; j < data[i].length; j++)
-                storage().set(i,j,data[i][j]);
+                storage().set(i, j, data[i][j]);
     }
 
-
     /**
      * @param rows Amount of rows in the matrix.
      * @param cols Amount of columns in the matrix.
@@ -124,7 +122,6 @@ public class SparseDistributedMatrix extends AbstractMatrix implements StorageCo
         return mapOverValues(v -> v * x);
     }
 
-
     /** {@inheritDoc} */
     @Override public Matrix times(Matrix mtx) {
         if (mtx == null)
@@ -160,15 +157,16 @@ public class SparseDistributedMatrix extends AbstractMatrix implements StorageCo
             // TODO: IGNITE:5114, exec in parallel
             locKeys.forEach(key -> {
                 int idx = key.index();
-                
-                if (isRowMode){
+
+                if (isRowMode) {
                     Vector Aik = matrixA.getRow(idx);
 
                     for (int i = 0; i < matrixB.columnSize(); i++) {
                         Vector Bkj = matrixB.getCol(i);
                         matrixC.set(idx, i, Aik.times(Bkj).sum());
                     }
-                } else {
+                }
+                else {
                     Vector Bkj = matrixB.getCol(idx);
 
                     for (int i = 0; i < matrixA.rowSize(); i++) {
@@ -182,7 +180,6 @@ public class SparseDistributedMatrix extends AbstractMatrix implements StorageCo
         return matrixC;
     }
 
-
     /** {@inheritDoc} */
     @Override public Vector times(Vector vec) {
         if (vec == null)
@@ -192,12 +189,12 @@ public class SparseDistributedMatrix extends AbstractMatrix implements StorageCo
             throw new CardinalityException(columnSize(), vec.size());
 
         SparseDistributedMatrix matrixA = this;
-        SparseDistributedVector vectorB = (SparseDistributedVector) vec;
+        SparseDistributedVector vectorB = (SparseDistributedVector)vec;
 
         String cacheName = storage().cacheName();
         int rows = this.rowSize();
 
-        SparseDistributedVector vectorC = (SparseDistributedVector) likeVector(rows);
+        SparseDistributedVector vectorC = (SparseDistributedVector)likeVector(rows);
 
         CacheUtils.bcast(cacheName, () -> {
             Ignite ignite = Ignition.localIgnite();
@@ -271,8 +268,10 @@ public class SparseDistributedMatrix extends AbstractMatrix implements StorageCo
 
     /** {@inheritDoc} */
     @Override public Matrix like(int rows, int cols) {
-        if(storage()==null) return new SparseDistributedMatrix(rows, cols);
-        else return new SparseDistributedMatrix(rows, cols, storage().storageMode(), storage().accessMode());
+        if (storage() == null)
+            return new SparseDistributedMatrix(rows, cols);
+        else
+            return new SparseDistributedMatrix(rows, cols, storage().storageMode(), storage().accessMode());
 
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockMatrixStorage.java
index 411b038..e73ef22 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockMatrixStorage.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockMatrixStorage.java
@@ -17,6 +17,14 @@
 
 package org.apache.ignite.ml.math.impls.storage.matrix;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.CacheAtomicityMode;
@@ -25,7 +33,6 @@ import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.util.lang.IgnitePair;
-import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.ml.math.MatrixStorage;
 import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.distributed.CacheUtils;
@@ -34,12 +41,6 @@ import org.apache.ignite.ml.math.distributed.keys.impl.MatrixBlockKey;
 import org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry;
 import org.apache.ignite.ml.math.impls.matrix.SparseBlockDistributedMatrix;
 
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.*;
-
 import static org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry.MAX_BLOCK_SIZE;
 
 /**
@@ -48,28 +49,32 @@ import static org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry.MAX_BLOCK_
 public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, StorageConstants, DistributedStorage<MatrixBlockKey> {
     /** Cache name used for all instances of {@link BlockMatrixStorage}. */
     private static final String CACHE_NAME = "ML_BLOCK_SPARSE_MATRICES_CONTAINER";
+
     /** */
     private int blocksInCol;
+
     /** */
     private int blocksInRow;
+
     /** Amount of rows in the matrix. */
     private int rows;
+
     /** Amount of columns in the matrix. */
     private int cols;
+
     /** Matrix uuid. */
     private UUID uuid;
+
     /** Block size about 8 KB of data. */
     private int maxBlockEdge = MAX_BLOCK_SIZE;
 
     /** Actual distributed storage. */
     private IgniteCache<
-            MatrixBlockKey /* Matrix block number with uuid. */,
-            MatrixBlockEntry /* Block of matrix, local sparse matrix. */
+        MatrixBlockKey /* Matrix block number with uuid. */,
+        MatrixBlockEntry /* Block of matrix, local sparse matrix. */
         > cache = null;
 
-    /**
-     *
-     */
+    /** */
     public BlockMatrixStorage() {
         // No-op.
     }
@@ -93,9 +98,7 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
         uuid = UUID.randomUUID();
     }
 
-    /**
-     *
-     */
+    /** */
     public IgniteCache<MatrixBlockKey, MatrixBlockEntry> cache() {
         return cache;
     }
@@ -215,9 +218,9 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
 
         Set<MatrixBlockKey> keyset = new HashSet<>();
 
-        for(int i = 0; i <= maxBlockId.get1(); i++)
-            for(int j = 0; j <= maxBlockId.get2(); j++)
-                keyset.add(getCacheKey(i,j));
+        for (int i = 0; i <= maxBlockId.get1(); i++)
+            for (int j = 0; j <= maxBlockId.get2(); j++)
+                keyset.add(getCacheKey(i, j));
 
         return keyset;
     }
@@ -237,8 +240,7 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
         List<MatrixBlockEntry> res = new LinkedList<>();
 
         for (int i = 0; i < blocksInCol; i++)
-            res.add(getEntryById(new IgnitePair<>(blockId.get1(), (long) i)));
-
+            res.add(getEntryById(new IgnitePair<>(blockId.get1(), (long)i)));
 
         return res;
     }
@@ -253,7 +255,7 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
         List<MatrixBlockEntry> res = new LinkedList<>();
 
         for (int i = 0; i < blocksInRow; i++)
-            res.add(getEntryById(new IgnitePair<>((long) i, blockId.get2())));
+            res.add(getEntryById(new IgnitePair<>((long)i, blockId.get2())));
 
         return res;
     }
@@ -288,7 +290,8 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
     }
 
     /**
-     * Returns cached or new BlockEntry by given blockId
+     * Returns cached or new BlockEntry by given blockId.
+     *
      * @param blockId blockId
      * @return BlockEntry
      */
@@ -305,7 +308,8 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
     }
 
     /**
-     * Builds empty BlockEntry with sizes based on blockId and BlockMatrixStorage fields' values
+     * Builds empty BlockEntry with sizes based on blockId and BlockMatrixStorage fields' values.
+     *
      * @param blockId blockId
      * @return Empty BlockEntry
      */
@@ -316,15 +320,14 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
 
         int rowSize;
 
-        if(rowMod == 0)
+        if (rowMod == 0)
             rowSize = maxBlockEdge;
         else
             rowSize = blockId.get1() != (blocksInRow - 1) ? maxBlockEdge : rowMod;
 
-
         int colSize;
 
-        if(colMod == 0)
+        if (colMod == 0)
             colSize = maxBlockEdge;
         else
             colSize = blockId.get2() != (blocksInCol - 1) ? maxBlockEdge : colMod;
@@ -368,7 +371,8 @@ public class BlockMatrixStorage extends CacheUtils implements MatrixStorage, Sto
     }
 
     /**
-     * Calculates blockId for given cell's coordinates
+     * Calculates blockId for given cell's coordinates.
+     *
      * @param x x1 attribute in (x1,x2) coordinates
      * @param y x2 attribute in (x1, x2) coordinates
      * @return blockId as an IgnitePair

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockVectorStorage.java
index a44ed8e..6400b4d 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockVectorStorage.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/BlockVectorStorage.java
@@ -17,6 +17,14 @@
 
 package org.apache.ignite.ml.math.impls.storage.matrix;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.CacheAtomicityMode;
@@ -24,9 +32,6 @@ import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.util.lang.IgnitePair;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.VectorStorage;
 import org.apache.ignite.ml.math.distributed.CacheUtils;
@@ -36,11 +41,6 @@ import org.apache.ignite.ml.math.impls.vector.SparseBlockDistributedVector;
 import org.apache.ignite.ml.math.impls.vector.VectorBlockEntry;
 import org.jetbrains.annotations.NotNull;
 
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.*;
-
 import static org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry.MAX_BLOCK_SIZE;
 
 /**
@@ -49,20 +49,24 @@ import static org.apache.ignite.ml.math.impls.matrix.MatrixBlockEntry.MAX_BLOCK_
 public class BlockVectorStorage extends CacheUtils implements VectorStorage, StorageConstants, DistributedStorage<VectorBlockKey> {
     /** Cache name used for all instances of {@link BlockVectorStorage}. */
     private static final String CACHE_NAME = "ML_BLOCK_SPARSE_MATRICES_CONTAINER";
+
     /** */
     private int blocks;
+
     /** Amount of columns in the vector. */
     private int size;
+
     /** Matrix uuid. */
     private UUID uuid;
+
     /** Block size about 8 KB of data. */
     private int maxBlockEdge = MAX_BLOCK_SIZE;
 
     /** Actual distributed storage. */
     private IgniteCache<
-            VectorBlockKey /* Matrix block number with uuid. */,
-            VectorBlockEntry /* Block of matrix, local sparse matrix. */
-            > cache = null;
+        VectorBlockKey /* Matrix block number with uuid. */,
+        VectorBlockEntry /* Block of matrix, local sparse matrix. */
+        > cache = null;
 
     /**
      *
@@ -79,17 +83,13 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
         assert size > 0;
 
         this.size = size;
-
         this.blocks = size % maxBlockEdge == 0 ? size / maxBlockEdge : size / maxBlockEdge + 1;
 
         cache = newCache();
-
         uuid = UUID.randomUUID();
     }
 
-    /**
-     *
-     */
+    /** */
     public IgniteCache<VectorBlockKey, VectorBlockEntry> cache() {
         return cache;
     }
@@ -109,14 +109,6 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
         return size;
     }
 
-
-    /**
-     * @return Blocks in row.
-     */
-    public int blocksInRow() {
-        return blocks;
-    }
-
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
         out.writeInt(size);
@@ -129,7 +121,7 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         size = in.readInt();
         blocks = in.readInt();
-        uuid = (UUID) in.readObject();
+        uuid = (UUID)in.readObject();
 
         cache = ignite().getOrCreateCache(in.readUTF());
     }
@@ -182,11 +174,10 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
         return new VectorBlockKey(blockId, uuid, getAffinityKey(blockId));
     }
 
-
     /** {@inheritDoc} */
     @Override public Set<VectorBlockKey> getAllKeys() {
-        int maxIndex = size - 1;
-        long maxBlockId = getBlockId(maxIndex);
+        int maxIdx = size - 1;
+        long maxBlockId = getBlockId(maxIdx);
 
         Set<VectorBlockKey> keyset = new HashSet<>();
 
@@ -201,7 +192,6 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
         return CACHE_NAME;
     }
 
-
     /**
      * Get column for current block.
      *
@@ -236,10 +226,10 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
         if (obj == null || getClass() != obj.getClass())
             return false;
 
-        BlockVectorStorage that = (BlockVectorStorage) obj;
+        BlockVectorStorage that = (BlockVectorStorage)obj;
 
         return size == that.size && uuid.equals(that.uuid)
-                && (cache != null ? cache.equals(that.cache) : that.cache == null);
+            && (cache != null ? cache.equals(that.cache) : that.cache == null);
     }
 
     /**
@@ -257,6 +247,9 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
         return entry;
     }
 
+    /**
+     * Get empty block entry by the given block id.
+     */
     @NotNull
     private VectorBlockEntry getEmptyBlockEntry(long blockId) {
         VectorBlockEntry entry;
@@ -286,7 +279,7 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
      * Distributed matrix set.
      *
      * @param idx Row or column index.
-     * @param v   New value to set.
+     * @param v New value to set.
      */
     private void matrixSet(int idx, double v) {
         long blockId = getBlockId(idx);
@@ -308,7 +301,7 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
 
     /** */
     private long getBlockId(int x) {
-        return (long) x / maxBlockEdge;
+        return (long)x / maxBlockEdge;
     }
 
     /**
@@ -368,7 +361,8 @@ public class BlockVectorStorage extends CacheUtils implements VectorStorage, Sto
      */
     @Override public double[] data() {
         double[] res = new double[this.size];
-        for (int i = 0; i < this.size; i++) res[i] = this.get(i);
+        for (int i = 0; i < this.size; i++)
+            res[i] = this.get(i);
         return res;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MapWrapperStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MapWrapperStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MapWrapperStorage.java
index 91db30e..3a02e44 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MapWrapperStorage.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MapWrapperStorage.java
@@ -17,14 +17,13 @@
 
 package org.apache.ignite.ml.math.impls.storage.matrix;
 
-import org.apache.ignite.internal.util.GridArgumentCheck;
-import org.apache.ignite.ml.math.VectorStorage;
-
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Map;
 import java.util.Set;
+import org.apache.ignite.internal.util.GridArgumentCheck;
+import org.apache.ignite.ml.math.VectorStorage;
 
 /**
  * Storage for wrapping given map.
@@ -53,7 +52,7 @@ public class MapWrapperStorage implements VectorStorage {
 
         assert min >= 0;
 
-        size =  (max - min) + 1;
+        size = (max - min) + 1;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
index e976899..9b4a189 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
@@ -19,6 +19,14 @@ package org.apache.ignite.ml.math.impls.storage.matrix;
 
 import it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap;
 import it.unimi.dsi.fastutil.ints.Int2DoubleRBTreeMap;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.CacheAtomicityMode;
@@ -34,29 +42,25 @@ import org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey;
 import org.apache.ignite.ml.math.distributed.keys.impl.SparseMatrixKey;
 import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
 
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
 /**
  * {@link MatrixStorage} implementation for {@link SparseDistributedMatrix}.
  */
 public class SparseDistributedMatrixStorage extends CacheUtils implements MatrixStorage, StorageConstants, DistributedStorage<RowColMatrixKey> {
     /** Cache name used for all instances of {@link SparseDistributedMatrixStorage}. */
     private static final String CACHE_NAME = "ML_SPARSE_MATRICES_CONTAINER";
+
     /** Amount of rows in the matrix. */
     private int rows;
+
     /** Amount of columns in the matrix. */
     private int cols;
+
     /** Row or column based storage mode. */
     private int stoMode;
+
     /** Random or sequential access mode. */
     private int acsMode;
+
     /** Matrix uuid. */
     private UUID uuid;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/34955be3/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
index 5e68b6c..5b3c9c8 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
@@ -201,6 +201,7 @@ public class SparseLocalOnHeapMatrixStorage implements MatrixStorage, StorageCon
     }
 
     // TODO: IGNITE-5777, optimize this
+
     /** {@inheritDoc} */
     @Override public double[] data() {
         double[] res = new double[rows * cols];
@@ -214,7 +215,7 @@ public class SparseLocalOnHeapMatrixStorage implements MatrixStorage, StorageCon
                 else
                     res[fstIdx * cols + sndIdx] = val;
 
-        }));
+            }));
 
         return res;
     }


Mime
View raw message