You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/04/19 14:47:22 UTC

[01/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Repository: ignite
Updated Branches:
  refs/heads/ignite-1561 db84aad94 -> 78601cb18


http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorIterableTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorIterableTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorIterableTest.java
new file mode 100644
index 0000000..16c2571
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorIterableTest.java
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Spliterator;
+import java.util.function.BiConsumer;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Test;
+
+import static java.util.Spliterator.ORDERED;
+import static java.util.Spliterator.SIZED;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/** */
+public class VectorIterableTest {
+    /** */
+    @Test
+    public void allTest() {
+        consumeSampleVectors(
+            (v, desc) -> {
+                int expIdx = 0;
+
+                for (Vector.Element e : v.all()) {
+                    int actualIdx = e.index();
+
+                    assertEquals("Unexpected index for " + desc,
+                        expIdx, actualIdx);
+
+                    expIdx++;
+                }
+
+                assertEquals("Unexpected amount of elements for " + desc,
+                    expIdx, v.size());
+            }
+        );
+    }
+
+    /** */
+    @Test
+    public void allTestBound() {
+        consumeSampleVectors(
+            (v, desc) -> iteratorTestBound(v.all().iterator(), desc)
+        );
+    }
+
+    /** */
+    @Test
+    public void nonZeroesTestBasic() {
+        final int size = 5;
+
+        final double[] nonZeroesOddData = new double[size], nonZeroesEvenData = new double[size];
+
+        for (int idx = 0; idx < size; idx++) {
+            final boolean odd = (idx & 1) == 1;
+
+            nonZeroesOddData[idx] = odd ? 1 : 0;
+
+            nonZeroesEvenData[idx] = odd ? 0 : 1;
+        }
+
+        assertTrue("Arrays failed to initialize.",
+            !isZero(nonZeroesEvenData[0])
+                && isZero(nonZeroesEvenData[1])
+                && isZero(nonZeroesOddData[0])
+                && !isZero(nonZeroesOddData[1]));
+
+        final Vector nonZeroesEvenVec = new DenseLocalOnHeapVector(nonZeroesEvenData),
+            nonZeroesOddVec = new DenseLocalOnHeapVector(nonZeroesOddData);
+
+        assertTrue("Vectors failed to initialize.",
+            !isZero(nonZeroesEvenVec.getElement(0).get())
+                && isZero(nonZeroesEvenVec.getElement(1).get())
+                && isZero(nonZeroesOddVec.getElement(0).get())
+                && !isZero(nonZeroesOddVec.getElement(1).get()));
+
+        assertTrue("Iterator(s) failed to start.",
+            nonZeroesEvenVec.nonZeroes().iterator().next() != null
+                && nonZeroesOddVec.nonZeroes().iterator().next() != null);
+
+        int nonZeroesActual = 0;
+
+        for (Vector.Element e : nonZeroesEvenVec.nonZeroes()) {
+            final int idx = e.index();
+
+            final boolean odd = (idx & 1) == 1;
+
+            final double val = e.get();
+
+            assertTrue("Not an even index " + idx + ", for value " + val, !odd);
+
+            assertTrue("Zero value " + val + " at even index " + idx, !isZero(val));
+
+            nonZeroesActual++;
+        }
+
+        final int nonZeroesOddExp = (size + 1) / 2;
+
+        assertEquals("Unexpected num of iterated odd non-zeroes.", nonZeroesOddExp, nonZeroesActual);
+
+        assertEquals("Unexpected nonZeroElements of odd.", nonZeroesOddExp, nonZeroesEvenVec.nonZeroElements());
+
+        nonZeroesActual = 0;
+
+        for (Vector.Element e : nonZeroesOddVec.nonZeroes()) {
+            final int idx = e.index();
+
+            final boolean odd = (idx & 1) == 1;
+
+            final double val = e.get();
+
+            assertTrue("Not an odd index " + idx + ", for value " + val, odd);
+
+            assertTrue("Zero value " + val + " at even index " + idx, !isZero(val));
+
+            nonZeroesActual++;
+        }
+
+        final int nonZeroesEvenExp = size / 2;
+
+        assertEquals("Unexpected num of iterated even non-zeroes", nonZeroesEvenExp, nonZeroesActual);
+
+        assertEquals("Unexpected nonZeroElements of even", nonZeroesEvenExp, nonZeroesOddVec.nonZeroElements());
+    }
+
+    /** */
+    @Test
+    public void nonZeroesTest() {
+        // todo make RandomVector constructor that accepts a function and use it here
+        //  in order to *reliably* test non-zeroes in there
+        consumeSampleVectors(
+            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
+                -> {
+                int numZeroesActual = vec.size();
+
+                for (Vector.Element e : vec.nonZeroes()) {
+                    numZeroesActual--;
+
+                    assertTrue("Unexpected zero at " + desc + ", index " + e.index(), !isZero(e.get()));
+                }
+
+                assertEquals("Unexpected num zeroes at " + desc, (int)numZeroes, numZeroesActual);
+            }));
+    }
+
+    /** */
+    @Test
+    public void nonZeroesTestBound() {
+        consumeSampleVectors(
+            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
+                -> iteratorTestBound(vec.nonZeroes().iterator(), desc)));
+    }
+
+    /** */
+    @Test
+    public void nonZeroElementsTest() {
+        consumeSampleVectors(
+            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
+                -> assertEquals("Unexpected num zeroes at " + desc,
+                (int)numZeroes, vec.size() - vec.nonZeroElements())));
+    }
+
+    /** */
+    @Test
+    public void allSpliteratorTest() {
+        consumeSampleVectors(
+            (v, desc) -> {
+                final String desc1 = " " + desc;
+
+                Spliterator<Double> spliterator = v.allSpliterator();
+
+                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
+
+                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, spliterator.trySplit());
+
+                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
+
+                if (!readOnly(v))
+                    fillWithNonZeroes(v);
+
+                spliterator = v.allSpliterator();
+
+                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
+
+                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.estimateSize(), v.size());
+
+                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.getExactSizeIfKnown(), v.size());
+
+                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
+
+                Spliterator<Double> secondHalf = spliterator.trySplit();
+
+                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, secondHalf);
+
+                spliterator.tryAdvance(x -> {
+                });
+            }
+        );
+    }
+
+    /** */
+    @Test
+    public void nonZeroSpliteratorTest() {
+        consumeSampleVectors(
+            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
+                -> {
+                final String desc1 = " Num zeroes " + numZeroes + " " + desc;
+
+                Spliterator<Double> spliterator = vec.nonZeroSpliterator();
+
+                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
+
+                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, spliterator.trySplit());
+
+                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
+
+                spliterator = vec.nonZeroSpliterator();
+
+                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
+
+                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.estimateSize(), vec.size() - numZeroes);
+
+                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.getExactSizeIfKnown(), vec.size() - numZeroes);
+
+                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
+
+                Spliterator<Double> secondHalf = spliterator.trySplit();
+
+                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, secondHalf);
+
+                double[] data = new double[vec.size()];
+
+                for (Vector.Element e : vec.all())
+                    data[e.index()] = e.get();
+
+                spliterator = vec.nonZeroSpliterator();
+
+                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
+
+                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.estimateSize(),
+                    Arrays.stream(data).filter(x -> x != 0d).count());
+
+                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.getExactSizeIfKnown(),
+                    Arrays.stream(data).filter(x -> x != 0d).count());
+
+                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
+
+                secondHalf = spliterator.trySplit();
+
+                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, secondHalf);
+
+                if (!spliterator.tryAdvance(x -> {
+                }))
+                    fail(MathTestConstants.NO_NEXT_ELEMENT + desc1);
+            }));
+    }
+
+    /** */
+    private void iteratorTestBound(Iterator<Vector.Element> it, String desc) {
+        while (it.hasNext())
+            assertNotNull(it.next());
+
+        boolean expECaught = false;
+
+        try {
+            it.next();
+        }
+        catch (NoSuchElementException e) {
+            expECaught = true;
+        }
+
+        assertTrue("Expected exception missed for " + desc,
+            expECaught);
+    }
+
+    /** */
+    private void consumeSampleVectorsWithZeroes(Vector sample,
+        BiConsumer<Vector, Integer> consumer) {
+        if (readOnly(sample)) {
+            int numZeroes = 0;
+
+            for (Vector.Element e : sample.all())
+                if (isZero(e.get()))
+                    numZeroes++;
+
+            consumer.accept(sample, numZeroes);
+
+            return;
+        }
+
+        fillWithNonZeroes(sample);
+
+        consumer.accept(sample, 0);
+
+        final int sampleSize = sample.size();
+
+        if (sampleSize == 0)
+            return;
+
+        for (Vector.Element e : sample.all())
+            e.set(0);
+
+        consumer.accept(sample, sampleSize);
+
+        fillWithNonZeroes(sample);
+
+        for (int testIdx : new int[] {0, sampleSize / 2, sampleSize - 1}) {
+            final Vector.Element e = sample.getElement(testIdx);
+
+            final double backup = e.get();
+
+            e.set(0);
+
+            consumer.accept(sample, 1);
+
+            e.set(backup);
+        }
+
+        if (sampleSize < 3)
+            return;
+
+        sample.getElement(sampleSize / 3).set(0);
+
+        sample.getElement((2 * sampleSize) / 3).set(0);
+
+        consumer.accept(sample, 2);
+    }
+
+    /** */
+    private void fillWithNonZeroes(Vector sample) {
+        int idx = 0;
+
+        for (Vector.Element e : sample.all())
+            e.set(1 + idx++);
+
+        assertEquals("Not all filled with non-zeroes", idx, sample.size());
+    }
+
+    /** */
+    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
+        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
+    }
+
+    /** */
+    private boolean isZero(double val) {
+        return val == 0.0;
+    }
+
+    /** */
+    private boolean readOnly(Vector v) {
+        return v instanceof RandomVector || v instanceof ConstantVector;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorNormTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorNormTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorNormTest.java
new file mode 100644
index 0000000..4e4f212
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorNormTest.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import org.apache.ignite.ml.math.Vector;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class VectorNormTest {
+    /** */
+    @Test
+    public void normalizeTest() {
+        normalizeTest(2, (val, len) -> val / len, Vector::normalize);
+    }
+
+    /** */
+    @Test
+    public void normalizePowerTest() {
+        for (double pow : new double[] {0, 0.5, 1, 2, 2.5, Double.POSITIVE_INFINITY})
+            normalizeTest(pow, (val, norm) -> val / norm, (v) -> v.normalize(pow));
+    }
+
+    /** */
+    @Test
+    public void logNormalizeTest() {
+        normalizeTest(2, (val, len) -> Math.log1p(val) / (len * Math.log(2)), Vector::logNormalize);
+    }
+
+    /** */
+    @Test
+    public void logNormalizePowerTest() {
+        for (double pow : new double[] {1.1, 2, 2.5})
+            normalizeTest(pow, (val, norm) -> Math.log1p(val) / (norm * Math.log(pow)), (v) -> v.logNormalize(pow));
+    }
+
+    /** */
+    @Test
+    public void kNormTest() {
+        for (double pow : new double[] {0, 0.5, 1, 2, 2.5, Double.POSITIVE_INFINITY})
+            toDoubleTest(pow, ref -> new Norm(ref, pow).calculate(), v -> v.kNorm(pow));
+    }
+
+    /** */
+    @Test
+    public void getLengthSquaredTest() {
+        toDoubleTest(2.0, ref -> new Norm(ref, 2).sumPowers(), Vector::getLengthSquared);
+    }
+
+    /** */
+    @Test
+    public void getDistanceSquaredTest() {
+        consumeSampleVectors((v, desc) -> {
+            new VectorImplementationsTest.ElementsChecker(v, desc); // IMPL NOTE this initialises vector
+
+            final int size = v.size();
+            final Vector vOnHeap = new DenseLocalOnHeapVector(size);
+            final Vector vOffHeap = new DenseLocalOffHeapVector(size);
+
+            invertValues(v, vOnHeap);
+            invertValues(v, vOffHeap);
+
+            for (int idx = 0; idx < size; idx++) {
+                final double exp = v.get(idx);
+                final int idxMirror = size - 1 - idx;
+
+                assertTrue("On heap vector difference at " + desc + ", idx " + idx,
+                    exp - vOnHeap.get(idxMirror) == 0);
+                assertTrue("Off heap vector difference at " + desc + ", idx " + idx,
+                    exp - vOffHeap.get(idxMirror) == 0);
+            }
+
+            final double exp = vOnHeap.minus(v).getLengthSquared(); // IMPL NOTE this won't mutate vOnHeap
+            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOnHeap));
+
+            assertTrue("On heap vector not close enough at " + desc + ", " + metric,
+                metric.closeEnough());
+
+            final VectorImplementationsTest.Metric metric1 = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOffHeap));
+
+            assertTrue("Off heap vector not close enough at " + desc + ", " + metric1,
+                metric1.closeEnough());
+        });
+    }
+
+    /** */
+    @Test
+    public void dotTest() {
+        consumeSampleVectors((v, desc) -> {
+            new VectorImplementationsTest.ElementsChecker(v, desc); // IMPL NOTE this initialises vector
+
+            final int size = v.size();
+            final Vector v1 = new DenseLocalOnHeapVector(size);
+
+            invertValues(v, v1);
+
+            final double actual = v.dot(v1);
+
+            double exp = 0;
+
+            for (Vector.Element e : v.all())
+                exp += e.get() * v1.get(e.index());
+
+            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, actual);
+
+            assertTrue("Dot product not close enough at " + desc + ", " + metric,
+                metric.closeEnough());
+        });
+    }
+
+    /** */
+    private void invertValues(Vector src, Vector dst) {
+        final int size = src.size();
+
+        for (Vector.Element e : src.all()) {
+            final int idx = size - 1 - e.index();
+            final double val = e.get();
+
+            dst.set(idx, val);
+        }
+    }
+
+    /** */
+    private void toDoubleTest(Double val, Function<double[], Double> calcRef, Function<Vector, Double> calcVec) {
+        consumeSampleVectors((v, desc) -> {
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            new VectorImplementationsTest.ElementsChecker(v, ref, desc); // IMPL NOTE this initialises vector and reference array
+
+            final double exp = calcRef.apply(ref);
+            final double obtained = calcVec.apply(v);
+            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, obtained);
+
+            assertTrue("Not close enough at " + desc
+                + (val == null ? "" : ", value " + val) + ", " + metric, metric.closeEnough());
+        });
+    }
+
+    /** */
+    private void normalizeTest(double pow, BiFunction<Double, Double, Double> operation,
+        Function<Vector, Vector> vecOperation) {
+        consumeSampleVectors((v, desc) -> {
+            final int size = v.size();
+            final double[] ref = new double[size];
+            final boolean nonNegative = pow != (int)pow;
+
+            final VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc + ", pow = " + pow, nonNegative);
+            final double norm = new Norm(ref, pow).calculate();
+
+            for (int idx = 0; idx < size; idx++)
+                ref[idx] = operation.apply(ref[idx], norm);
+
+            checker.assertCloseEnough(vecOperation.apply(v), ref);
+        });
+    }
+
+    /** */
+    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
+        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
+    }
+
+    /** */
+    private static class Norm {
+        /** */
+        private final double[] arr;
+
+        /** */
+        private final Double pow;
+
+        /** */
+        Norm(double[] arr, double pow) {
+            this.arr = arr;
+            this.pow = pow;
+        }
+
+        /** */
+        double calculate() {
+            if (pow.equals(0.0))
+                return countNonZeroes(); // IMPL NOTE this is beautiful if you think of it
+
+            if (pow.equals(Double.POSITIVE_INFINITY))
+                return maxAbs();
+
+            return Math.pow(sumPowers(), 1 / pow);
+        }
+
+        /** */
+        double sumPowers() {
+            if (pow.equals(0.0))
+                return countNonZeroes();
+
+            double norm = 0;
+
+            for (double val : arr)
+                norm += pow == 1 ? Math.abs(val) : Math.pow(val, pow);
+
+            return norm;
+        }
+
+        /** */
+        private int countNonZeroes() {
+            int cnt = 0;
+
+            final Double zero = 0.0;
+
+            for (double val : arr)
+                if (!zero.equals(val))
+                    cnt++;
+
+            return cnt;
+        }
+
+        /** */
+        private double maxAbs() {
+            double res = 0;
+
+            for (double val : arr) {
+                final double abs = Math.abs(val);
+
+                if (abs > res)
+                    res = abs;
+            }
+
+            return res;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorToMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorToMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorToMatrixTest.java
new file mode 100644
index 0000000..4d5bc56
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorToMatrixTest.java
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.RandomMatrix;
+import org.apache.ignite.ml.math.impls.matrix.SparseLocalOnHeapMatrix;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/** Tests for methods of Vector that involve Matrix. */
+public class VectorToMatrixTest {
+    /** */
+    private static final Map<Class<? extends Vector>, Class<? extends Matrix>> typesMap = typesMap();
+
+    /** */
+    private static final List<Class<? extends Vector>> likeMatrixUnsupported = Arrays.asList(FunctionVector.class,
+        SingleElementVector.class, SingleElementVectorView.class, ConstantVector.class);
+
+    /** */
+    @Test
+    public void testHaveLikeMatrix() throws InstantiationException, IllegalAccessException {
+        for (Class<? extends Vector> key : typesMap.keySet()) {
+            Class<? extends Matrix> val = typesMap.get(key);
+
+            if (val == null && likeMatrixSupported(key))
+                System.out.println("Missing test for implementation of likeMatrix for " + key.getSimpleName());
+        }
+    }
+
+    /** */
+    @Test
+    public void testLikeMatrixUnsupported() throws Exception {
+        consumeSampleVectors((v, desc) -> {
+            if (likeMatrixSupported(v.getClass()))
+                return;
+
+            boolean expECaught = false;
+
+            try {
+                assertNull("Null view instead of exception in " + desc, v.likeMatrix(1, 1));
+            }
+            catch (UnsupportedOperationException uoe) {
+                expECaught = true;
+            }
+
+            assertTrue("Expected exception was not caught in " + desc, expECaught);
+        });
+    }
+
+    /** */
+    @Test
+    public void testLikeMatrix() {
+        consumeSampleVectors((v, desc) -> {
+            if (!availableForTesting(v))
+                return;
+
+            final Matrix matrix = v.likeMatrix(1, 1);
+
+            Class<? extends Vector> key = v.getClass();
+
+            Class<? extends Matrix> expMatrixType = typesMap.get(key);
+
+            assertNotNull("Expect non-null matrix for " + key.getSimpleName() + " in " + desc, matrix);
+
+            Class<? extends Matrix> actualMatrixType = matrix.getClass();
+
+            assertTrue("Expected matrix type " + expMatrixType.getSimpleName()
+                    + " should be assignable from actual type " + actualMatrixType.getSimpleName() + " in " + desc,
+                expMatrixType.isAssignableFrom(actualMatrixType));
+
+            for (int rows : new int[] {1, 2})
+                for (int cols : new int[] {1, 2}) {
+                    final Matrix actualMatrix = v.likeMatrix(rows, cols);
+
+                    String details = "rows " + rows + " cols " + cols;
+
+                    assertNotNull("Expect non-null matrix for " + details + " in " + desc,
+                        actualMatrix);
+
+                    assertEquals("Unexpected number of rows in " + desc, rows, actualMatrix.rowSize());
+
+                    assertEquals("Unexpected number of cols in " + desc, cols, actualMatrix.columnSize());
+                }
+        });
+    }
+
+    /** */
+    @Test
+    public void testToMatrix() {
+        consumeSampleVectors((v, desc) -> {
+            if (!availableForTesting(v))
+                return;
+
+            fillWithNonZeroes(v);
+
+            final Matrix matrixRow = v.toMatrix(true);
+
+            final Matrix matrixCol = v.toMatrix(false);
+
+            for (Vector.Element e : v.all())
+                assertToMatrixValue(desc, matrixRow, matrixCol, e.get(), e.index());
+        });
+    }
+
+    /** */
+    @Test
+    public void testToMatrixPlusOne() {
+        consumeSampleVectors((v, desc) -> {
+            if (!availableForTesting(v))
+                return;
+
+            fillWithNonZeroes(v);
+
+            for (double zeroVal : new double[] {-1, 0, 1, 2}) {
+                final Matrix matrixRow = v.toMatrixPlusOne(true, zeroVal);
+
+                final Matrix matrixCol = v.toMatrixPlusOne(false, zeroVal);
+
+                final Metric metricRow0 = new Metric(zeroVal, matrixRow.get(0, 0));
+
+                assertTrue("Not close enough row like " + metricRow0 + " at index 0 in " + desc,
+                    metricRow0.closeEnough());
+
+                final Metric metricCol0 = new Metric(zeroVal, matrixCol.get(0, 0));
+
+                assertTrue("Not close enough cols like " + metricCol0 + " at index 0 in " + desc,
+                    metricCol0.closeEnough());
+
+                for (Vector.Element e : v.all())
+                    assertToMatrixValue(desc, matrixRow, matrixCol, e.get(), e.index() + 1);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testCross() {
+        consumeSampleVectors((v, desc) -> {
+            if (!availableForTesting(v))
+                return;
+
+            fillWithNonZeroes(v);
+
+            for (int delta : new int[] {-1, 0, 1}) {
+                final int size2 = v.size() + delta;
+
+                if (size2 < 1)
+                    return;
+
+                final Vector v2 = new DenseLocalOnHeapVector(size2);
+
+                for (Vector.Element e : v2.all())
+                    e.set(size2 - e.index());
+
+                assertCross(v, v2, desc);
+            }
+        });
+    }
+
+    /** */
+    private void assertCross(Vector v1, Vector v2, String desc) {
+        assertNotNull(v1);
+        assertNotNull(v2);
+
+        final Matrix res = v1.cross(v2);
+
+        assertNotNull("Cross matrix is expected to be not null in " + desc, res);
+
+        assertEquals("Unexpected number of rows in cross Matrix in " + desc, v1.size(), res.rowSize());
+
+        assertEquals("Unexpected number of cols in cross Matrix in " + desc, v2.size(), res.columnSize());
+
+        for (int row = 0; row < v1.size(); row++)
+            for (int col = 0; col < v2.size(); col++) {
+                final Metric metric = new Metric(v1.get(row) * v2.get(col), res.get(row, col));
+
+                assertTrue("Not close enough cross " + metric + " at row " + row + " at col " + col
+                    + " in " + desc, metric.closeEnough());
+            }
+    }
+
+    /** */
+    private void assertToMatrixValue(String desc, Matrix matrixRow, Matrix matrixCol, double exp, int idx) {
+        final Metric metricRow = new Metric(exp, matrixRow.get(0, idx));
+
+        assertTrue("Not close enough row like " + metricRow + " at index " + idx + " in " + desc,
+            metricRow.closeEnough());
+
+        final Metric metricCol = new Metric(exp, matrixCol.get(idx, 0));
+
+        assertTrue("Not close enough cols like " + matrixCol + " at index " + idx + " in " + desc,
+            metricCol.closeEnough());
+    }
+
+    /** */
+    private void fillWithNonZeroes(Vector sample) {
+        if (sample instanceof RandomVector)
+            return;
+
+        for (Vector.Element e : sample.all())
+            e.set(1 + e.index());
+    }
+
+    /** */
+    private boolean availableForTesting(Vector v) {
+        assertNotNull("Error in test: vector is null", v);
+
+        if (!likeMatrixSupported(v.getClass()))
+            return false;
+
+        final boolean availableForTesting = typesMap.get(v.getClass()) != null;
+
+        final Matrix actualLikeMatrix = v.likeMatrix(1, 1);
+
+        assertTrue("Need to enable matrix testing for vector type " + v.getClass().getSimpleName(),
+            availableForTesting || actualLikeMatrix == null);
+
+        return availableForTesting;
+    }
+
+    /** Ignore test for given vector type. */
+    private boolean likeMatrixSupported(Class<? extends Vector> clazz) {
+        for (Class<? extends Vector> ignoredClass : likeMatrixUnsupported)
+            if (ignoredClass.isAssignableFrom(clazz))
+                return false;
+
+        return true;
+    }
+
+    /** */
+    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
+        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
+    }
+
+    /** */
+    private static Map<Class<? extends Vector>, Class<? extends Matrix>> typesMap() {
+        return new LinkedHashMap<Class<? extends Vector>, Class<? extends Matrix>>() {{
+            put(DenseLocalOnHeapVector.class, DenseLocalOnHeapMatrix.class);
+            put(DenseLocalOffHeapVector.class, DenseLocalOffHeapMatrix.class);
+            put(RandomVector.class, RandomMatrix.class);
+            put(SparseLocalVector.class, SparseLocalOnHeapMatrix.class);
+            put(SingleElementVector.class, null); // todo find out if we need SingleElementMatrix to match, or skip it
+            put(ConstantVector.class, null);
+            put(FunctionVector.class, null);
+            put(PivotedVectorView.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
+            put(SingleElementVectorView.class, null);
+            put(MatrixVectorView.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
+            put(DelegatingVector.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
+            // IMPL NOTE check for presence of all implementations here will be done in testHaveLikeMatrix via Fixture
+        }};
+    }
+
+    /** */
+    private static class Metric { // todo consider if softer tolerance (like say 0.1 or 0.01) would make sense here
+        /** */
+        private final double exp;
+
+        /** */
+        private final double obtained;
+
+        /** **/
+        Metric(double exp, double obtained) {
+            this.exp = exp;
+            this.obtained = obtained;
+        }
+
+        /** */
+        boolean closeEnough() {
+            return new Double(exp).equals(obtained);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Metric{" + "expected=" + exp +
+                ", obtained=" + obtained +
+                '}';
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorViewTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorViewTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorViewTest.java
new file mode 100644
index 0000000..ad2bc3f
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorViewTest.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.function.BiConsumer;
+import java.util.stream.IntStream;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Unit tests for {@link VectorView}.
+ */
+public class VectorViewTest {
+    /** */
+    private static final int OFFSET = 10;
+
+    /** */
+    private static final int VIEW_LENGTH = 80;
+
+    /** */
+    private static final String EXTERNALIZE_TEST_FILE_NAME = "externalizeTest";
+
+    /** */
+    private VectorView testVector;
+
+    /** */
+    private DenseLocalOnHeapVector parentVector;
+
+    /** */
+    private double[] parentData;
+
+    /** */
+    @Before
+    public void setup() {
+        parentVector = new DenseLocalOnHeapVector(MathTestConstants.STORAGE_SIZE);
+
+        IntStream.range(0, MathTestConstants.STORAGE_SIZE).forEach(idx -> parentVector.set(idx, Math.random()));
+
+        parentData = parentVector.getStorage().data().clone();
+
+        testVector = new VectorView(parentVector, OFFSET, VIEW_LENGTH);
+    }
+
+    /** */
+    @AfterClass
+    public static void cleanup() throws IOException {
+        Files.deleteIfExists(Paths.get(EXTERNALIZE_TEST_FILE_NAME));
+    }
+
+    /** */
+    @Test
+    public void testCopy() throws Exception {
+        Vector cp = testVector.copy();
+
+        assertTrue(MathTestConstants.VAL_NOT_EQUALS, cp.equals(testVector));
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testLike() throws Exception {
+        for (int card : new int[] {1, 2, 4, 8, 16, 32, 64, 128})
+            consumeSampleVectors((v, desc) -> {
+                Vector vLike = new VectorView(v, 0, 1).like(card);
+
+                Class<? extends Vector> expType = v.getClass();
+
+                assertNotNull("Expect non-null like vector for " + expType.getSimpleName() + " in " + desc, vLike);
+
+                assertEquals("Expect size equal to cardinality at " + desc, card, vLike.size());
+
+                Class<? extends Vector> actualType = vLike.getClass();
+
+                assertTrue("Expected matrix type " + expType.getSimpleName()
+                        + " should be assignable from actual type " + actualType.getSimpleName() + " in " + desc,
+                    expType.isAssignableFrom(actualType));
+
+            });
+    }
+
+    /** See also {@link VectorToMatrixTest#testLikeMatrix()}. */
+    @Test
+    public void testLikeMatrix() {
+        consumeSampleVectors((v, desc) -> {
+            boolean expECaught = false;
+
+            try {
+                assertNull("Null view instead of exception in " + desc, new VectorView(v, 0, 1).likeMatrix(1, 1));
+            }
+            catch (UnsupportedOperationException uoe) {
+                expECaught = true;
+            }
+
+            assertTrue("Expected exception was not caught in " + desc, expECaught);
+        });
+    }
+
+    /** */
+    @Test
+    public void testWriteReadExternal() throws Exception {
+        assertNotNull("Unexpected null parent data", parentData);
+
+        File f = new File(EXTERNALIZE_TEST_FILE_NAME);
+
+        try {
+            ObjectOutputStream objOutputStream = new ObjectOutputStream(new FileOutputStream(f));
+
+            objOutputStream.writeObject(testVector);
+
+            objOutputStream.close();
+
+            ObjectInputStream objInputStream = new ObjectInputStream(new FileInputStream(f));
+
+            VectorView readVector = (VectorView)objInputStream.readObject();
+
+            objInputStream.close();
+
+            assertTrue(MathTestConstants.VAL_NOT_EQUALS, testVector.equals(readVector));
+        }
+        catch (ClassNotFoundException | IOException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    /** */
+    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
+        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
+    }
+
+}


[03/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
new file mode 100644
index 0000000..7c2d415
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Tests for {@link SparseDistributedMatrixStorage}.
+ */
+@GridCommonTest(group = "Distributed Models")
+public class SparseDistributedMatrixStorageTest extends GridCommonAbstractTest {
+    /** Number of nodes in grid */
+    private static final int NODE_COUNT = 3;
+    /** Cache name. */
+    private static final String CACHE_NAME = "test-cache";
+    /** */
+    private static final String UNEXPECTED_ATTRIBUTE_VALUE = "Unexpected attribute value.";
+    /** Grid instance. */
+    private Ignite ignite;
+
+    /**
+     * Default constructor.
+     */
+    public SparseDistributedMatrixStorageTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        for (int i = 1; i <= NODE_COUNT; i++)
+            startGrid(i);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override protected void beforeTest() throws Exception {
+        ignite = grid(NODE_COUNT);
+
+        ignite.configuration().setPeerClassLoadingEnabled(true);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ignite.destroyCache(CACHE_NAME);
+    }
+
+    /** */
+    public void testCacheCreation() throws Exception {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        final int rows = MathTestConstants.STORAGE_SIZE;
+        final int cols = MathTestConstants.STORAGE_SIZE;
+
+        SparseDistributedMatrixStorage storage = new SparseDistributedMatrixStorage(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        assertNotNull("SparseDistributedMatrixStorage cache is null.", storage.cache());
+    }
+
+    /** */
+    public void testSetGet() throws Exception {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        final int rows = MathTestConstants.STORAGE_SIZE;
+        final int cols = MathTestConstants.STORAGE_SIZE;
+
+        SparseDistributedMatrixStorage storage = new SparseDistributedMatrixStorage(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < cols; j++) {
+                double v = Math.random();
+                storage.set(i, j, v);
+
+                assert Double.compare(v, storage.get(i, j)) == 0;
+                assert Double.compare(v, storage.get(i, j)) == 0;
+            }
+        }
+    }
+
+    /** */
+    public void testAttributes() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        final int rows = MathTestConstants.STORAGE_SIZE;
+        final int cols = MathTestConstants.STORAGE_SIZE;
+
+        SparseDistributedMatrixStorage storage = new SparseDistributedMatrixStorage(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.rowSize(), rows);
+        assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.columnSize(), cols);
+
+        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, storage.isArrayBased());
+        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, storage.isDense());
+        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, storage.isDistributed());
+
+        assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.isRandomAccess(), !storage.isSequentialAccess());
+        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, storage.isRandomAccess());
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
new file mode 100644
index 0000000..6578e14
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Unit tests for {@link SparseLocalOnHeapVectorStorage}.
+ */
+public class RandomAccessSparseVectorStorageTest extends VectorBaseStorageTest<SparseLocalOnHeapVectorStorage> {
+    /** */
+    @Override public void setUp() {
+        storage = new SparseLocalOnHeapVectorStorage(MathTestConstants.STORAGE_SIZE, StorageConstants.RANDOM_ACCESS_MODE);
+    }
+
+    /** */
+    @Test
+    public void data() throws Exception {
+        assertNull(MathTestConstants.NULL_VAL, storage.data());
+    }
+
+    /** */
+    @Test
+    public void isSequentialAccess() throws Exception {
+        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isSequentialAccess());
+    }
+
+    /** */
+    @Test
+    public void isDense() throws Exception {
+        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isDense());
+    }
+
+    /** */
+    @Test
+    public void isArrayBased() throws Exception {
+        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isArrayBased());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
new file mode 100644
index 0000000..7e5fc48
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.apache.ignite.ml.math.impls.MathTestConstants.STORAGE_SIZE;
+import static org.apache.ignite.ml.math.impls.MathTestConstants.UNEXPECTED_VAL;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link SparseLocalOffHeapVectorStorage}.
+ */
+public class SparseLocalOffHeapVectorStorageTest extends ExternalizeTest<SparseLocalOffHeapVectorStorage> {
+    /** */ private SparseLocalOffHeapVectorStorage testVectorStorage;
+
+    /** */
+    @Before
+    public void setup() {
+        testVectorStorage = new SparseLocalOffHeapVectorStorage(STORAGE_SIZE);
+    }
+
+    /** */
+    @After
+    public void teardown() {
+        testVectorStorage.destroy();
+        testVectorStorage = null;
+    }
+
+    /** */
+    @Test
+    public void testBasic() {
+        for (int i = 0; i < STORAGE_SIZE; i++) {
+            double testVal = Math.random();
+            testVectorStorage.set(i, testVal);
+            assertEquals(UNEXPECTED_VAL, testVal, testVectorStorage.get(i), 0d);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Test(expected = UnsupportedOperationException.class)
+    @Override public void externalizeTest() {
+        super.externalizeTest(new SparseLocalOffHeapVectorStorage(STORAGE_SIZE));
+    }
+
+    /** */
+    @Test
+    public void testAttributes() {
+        SparseLocalOffHeapVectorStorage testVectorStorage = new SparseLocalOffHeapVectorStorage(STORAGE_SIZE);
+
+        assertTrue(UNEXPECTED_VAL, testVectorStorage.isRandomAccess());
+        assertFalse(UNEXPECTED_VAL, testVectorStorage.isSequentialAccess());
+        assertFalse(UNEXPECTED_VAL, testVectorStorage.isDense());
+        assertFalse(UNEXPECTED_VAL, testVectorStorage.isArrayBased());
+        assertFalse(UNEXPECTED_VAL, testVectorStorage.isDistributed());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorArrayStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorArrayStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorArrayStorageTest.java
new file mode 100644
index 0000000..ce62b3e
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorArrayStorageTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.util.Arrays;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit test for {@link ArrayVectorStorage}.
+ */
+public class VectorArrayStorageTest extends VectorBaseStorageTest<ArrayVectorStorage> {
+    /** */
+    @Override public void setUp() {
+        storage = new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void isArrayBased() throws Exception {
+        assertTrue(MathTestConstants.WRONG_ATTRIBUTE_VAL, storage.isArrayBased());
+
+        assertTrue(MathTestConstants.WRONG_ATTRIBUTE_VAL, new ArrayVectorStorage().isArrayBased());
+    }
+
+    /** */
+    @Test
+    public void data() throws Exception {
+        assertNotNull(MathTestConstants.NULL_DATA_STORAGE, storage.data());
+
+        assertEquals(MathTestConstants.WRONG_DATA_SIZE, storage.data().length, MathTestConstants.STORAGE_SIZE);
+
+        assertTrue(MathTestConstants.UNEXPECTED_DATA_VAL, Arrays.equals(storage.data(), new double[MathTestConstants.STORAGE_SIZE]));
+
+        assertNull(MathTestConstants.UNEXPECTED_DATA_VAL, new ArrayVectorStorage().data());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorBaseStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorBaseStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorBaseStorageTest.java
new file mode 100644
index 0000000..206fe85
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorBaseStorageTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Abstract class with base tests for each vector storage.
+ */
+public abstract class VectorBaseStorageTest<T extends VectorStorage> extends ExternalizeTest<T> {
+    /** */
+    protected T storage;
+
+    /** */
+    @Before
+    public abstract void setUp();
+
+    /** */
+    @After
+    public void tearDown() throws Exception {
+        storage.destroy();
+    }
+
+    /** */
+    @Test
+    public void getSet() throws Exception {
+        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++) {
+            double random = Math.random();
+
+            storage.set(i, random);
+
+            assertEquals(MathTestConstants.WRONG_DATA_ELEMENT, storage.get(i), random, MathTestConstants.NIL_DELTA);
+        }
+    }
+
+    /** */
+    @Test
+    public void size() {
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.size() == MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Override public void externalizeTest() {
+        super.externalizeTest(storage);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorOffheapStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorOffheapStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorOffheapStorageTest.java
new file mode 100644
index 0000000..6b719d0
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/VectorOffheapStorageTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link DenseLocalOffHeapVectorStorage}.
+ */
+public class VectorOffheapStorageTest extends VectorBaseStorageTest<DenseLocalOffHeapVectorStorage> {
+    /** */
+    @Before
+    public void setUp() {
+        storage = new DenseLocalOffHeapVectorStorage(MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void isArrayBased() throws Exception {
+        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isArrayBased());
+    }
+
+    /** */
+    @Test
+    public void data() throws Exception {
+        assertNull(MathTestConstants.NULL_VAL, storage.data());
+    }
+
+    /** */
+    @Test
+    public void isSequentialAccess() throws Exception {
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isSequentialAccess());
+    }
+
+    /** */
+    @Test
+    public void isDense() throws Exception {
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isDense());
+    }
+
+    /** */
+    @Test
+    public void equalsTest() {
+        //noinspection EqualsWithItself
+        assertTrue(MathTestConstants.VAL_NOT_EQUALS, storage.equals(storage));
+
+        //noinspection EqualsBetweenInconvertibleTypes
+        assertFalse(MathTestConstants.VALUES_SHOULD_BE_NOT_EQUALS,
+            storage.equals(new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE)));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/AbstractVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/AbstractVectorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/AbstractVectorTest.java
new file mode 100644
index 0000000..fa66769
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/AbstractVectorTest.java
@@ -0,0 +1,543 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Arrays;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.ml.math.impls.storage.vector.ArrayVectorStorage;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit test for {@link AbstractVector}.
+ */
+public class AbstractVectorTest {
+    /** */
+    private AbstractVector testVector;
+
+    /** */
+    @Before
+    public void setUp() {
+        testVector = getAbstractVector();
+    }
+
+    /** */
+    @Test
+    public void setStorage() {
+        testVector.setStorage(createStorage());
+
+        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void size() {
+        testVector.setStorage(createStorage());
+        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE);
+
+        testVector.setStorage(new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE + MathTestConstants.STORAGE_SIZE));
+        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE + MathTestConstants.STORAGE_SIZE);
+
+        testVector = getAbstractVector(createStorage());
+        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void getPositive() {
+        testVector = getAbstractVector(createStorage());
+
+        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
+            assertNotNull(MathTestConstants.NULL_VALUES, testVector.get(i));
+
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void getNegative0() {
+        testVector.get(0);
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void getNegative1() {
+        testVector.setStorage(createStorage());
+
+        testVector.get(-1);
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void getNegative2() {
+        testVector.setStorage(createStorage());
+
+        testVector.get(testVector.size() + 1);
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void getXNegative0() {
+        testVector.getX(0);
+    }
+
+    /** */
+    @Test(expected = ArrayIndexOutOfBoundsException.class)
+    public void getXNegative1() {
+        testVector.setStorage(createStorage());
+
+        testVector.getX(-1);
+    }
+
+    /** */
+    @Test(expected = ArrayIndexOutOfBoundsException.class)
+    public void getXNegative2() {
+        testVector.setStorage(createStorage());
+
+        testVector.getX(MathTestConstants.STORAGE_SIZE + 1);
+    }
+
+    /** */
+    @Test
+    public void set() {
+        double[] data = initVector();
+
+        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
+            testVector.set(i, Math.exp(data[i]));
+
+        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
+            assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.get(i), Math.exp(data[i]), MathTestConstants.NIL_DELTA);
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void setNegative0() {
+        testVector.set(-1, -1);
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void setNegative1() {
+        initVector();
+
+        testVector.set(-1, -1);
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void setNegative2() {
+        initVector();
+
+        testVector.set(MathTestConstants.STORAGE_SIZE + 1, -1);
+    }
+
+    /** */
+    @Test(expected = IndexOutOfBoundsException.class)
+    public void setXNegative0() {
+        initVector();
+
+        testVector.setX(-1, -1);
+    }
+
+    /** */
+    @Test(expected = IndexOutOfBoundsException.class)
+    public void setXNegative1() {
+        initVector();
+
+        testVector.setX(MathTestConstants.STORAGE_SIZE + 1, -1);
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void setXNegative2() {
+        testVector.setX(-1, -1);
+    }
+
+    /** */
+    @Test
+    public void isZero() {
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, testVector.isZero(0d));
+
+        assertFalse(MathTestConstants.UNEXPECTED_VAL, testVector.isZero(1d));
+    }
+
+    /** */
+    @Test
+    public void guid() {
+        assertNotNull(MathTestConstants.NULL_GUID, testVector.guid());
+
+        assertEquals(MathTestConstants.UNEXPECTED_GUID_VAL, testVector.guid(), testVector.guid());
+
+        assertFalse(MathTestConstants.EMPTY_GUID, testVector.guid().toString().isEmpty());
+
+        testVector = getAbstractVector(createStorage());
+
+        assertNotNull(MathTestConstants.NULL_GUID, testVector.guid());
+
+        assertEquals(MathTestConstants.UNEXPECTED_GUID_VAL, testVector.guid(), testVector.guid());
+
+        assertFalse(MathTestConstants.EMPTY_GUID, testVector.guid().toString().isEmpty());
+    }
+
+    /** */
+    @Test
+    public void equalsTest() {
+        VectorStorage storage = createStorage();
+
+        AbstractVector testVector1 = getAbstractVector();
+
+        testVector1.setStorage(storage);
+
+        AbstractVector testVector2 = getAbstractVector();
+
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector, testVector);
+
+        testVector2.setStorage(storage);
+
+        assertTrue(MathTestConstants.VAL_NOT_EQUALS, testVector1.equals(testVector2));
+
+        assertFalse(MathTestConstants.VALUES_SHOULD_BE_NOT_EQUALS, testVector1.equals(testVector));
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void all() {
+        assertNotNull(MathTestConstants.NULL_VAL, testVector.all());
+
+        assertNotNull(MathTestConstants.NULL_VAL, getAbstractVector(createStorage()).all());
+
+        getAbstractVector().all().iterator().next();
+    }
+
+    /** */
+    @Test
+    public void nonZeroElements() {
+        VectorStorage storage = createStorage();
+
+        double[] data = storage.data();
+
+        testVector = getAbstractVector(storage);
+
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.nonZeroElements(), Arrays.stream(data).filter(x -> x != 0d).count());
+
+        addNilValues(data);
+
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.nonZeroElements(), Arrays.stream(data).filter(x -> x != 0d).count());
+    }
+
+    /** */
+    @Test
+    public void foldMapWithSecondVector() {
+        double[] data0 = initVector();
+
+        VectorStorage storage1 = createStorage();
+
+        double[] data1 = storage1.data().clone();
+
+        AbstractVector testVector1 = getAbstractVector(storage1);
+
+        String testVal = "";
+
+        for (int i = 0; i < data0.length; i++)
+            testVal += data0[i] + data1[i];
+
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.foldMap(testVector1, (string, xi) -> string.concat(xi.toString()), Functions.PLUS, ""), testVal);
+    }
+
+    /** */
+    @Test
+    public void nonZeroes() {
+        assertNotNull(MathTestConstants.NULL_VAL, testVector.nonZeroes());
+
+        double[] data = initVector();
+
+        assertNotNull(MathTestConstants.NULL_VAL, testVector.nonZeroes());
+
+        Assert.assertEquals(MathTestConstants.VAL_NOT_EQUALS, StreamSupport.stream(testVector.nonZeroes().spliterator(), false).count(), Arrays.stream(data).filter(x -> x != 0d).count());
+
+        addNilValues(data);
+
+        Assert.assertEquals(MathTestConstants.VAL_NOT_EQUALS, StreamSupport.stream(testVector.nonZeroes().spliterator(), false).count(), Arrays.stream(data).filter(x -> x != 0d).count());
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void nonZeroesEmpty() {
+        testVector.nonZeroes().iterator().next();
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void assign() {
+        testVector.assign(MathTestConstants.TEST_VAL);
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void assignArr() {
+        testVector.assign(new double[1]);
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void assignArrEmpty() {
+        testVector.assign(new double[0]);
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void dotNegative() {
+        testVector.dot(getAbstractVector(createEmptyStorage()));
+    }
+
+    /** */
+    @Test
+    public void dotSelf() {
+        double[] data = initVector();
+
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.dotSelf(), Arrays.stream(data).reduce(0, (x, y) -> x + y * y), MathTestConstants.NIL_DELTA);
+    }
+
+    /** */
+    @Test
+    public void getStorage() {
+        assertNotNull(MathTestConstants.NULL_VAL, getAbstractVector(createEmptyStorage()));
+        assertNotNull(MathTestConstants.NULL_VAL, getAbstractVector(createStorage()));
+        testVector.setStorage(createStorage());
+        assertNotNull(MathTestConstants.NULL_VAL, testVector.getStorage());
+    }
+
+    /** */
+    @Test
+    public void getElement() {
+        double[] data = initVector();
+
+        for (int i = 0; i < data.length; i++) {
+            assertNotNull(MathTestConstants.NULL_VAL, testVector.getElement(i));
+
+            assertEquals(MathTestConstants.UNEXPECTED_VAL, testVector.getElement(i).get(), data[i], MathTestConstants.NIL_DELTA);
+
+            testVector.getElement(i).set(++data[i]);
+
+            assertEquals(MathTestConstants.UNEXPECTED_VAL, testVector.getElement(i).get(), data[i], MathTestConstants.NIL_DELTA);
+        }
+    }
+
+    /**
+     * Create {@link AbstractVector} with storage for tests.
+     *
+     * @param storage {@link VectorStorage}
+     * @return AbstractVector.
+     */
+    private AbstractVector getAbstractVector(VectorStorage storage) {
+        return new AbstractVector(storage) { // TODO: find out how to fix warning about missing constructor
+            /** */
+            @Override public boolean isDense() {
+                return false;
+            }
+
+            /** */
+            @Override public boolean isSequentialAccess() {
+                return false;
+            }
+
+            /** */
+            @Override public Matrix likeMatrix(int rows, int cols) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector copy() {
+                return getAbstractVector(this.getStorage());
+            }
+
+            /** */
+            @Override public Vector like(int crd) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector normalize() {
+                return null;
+            }
+
+            /** */
+            @Override public Vector normalize(double power) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector logNormalize() {
+                return null;
+            }
+
+            /** */
+            @Override public Vector logNormalize(double power) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector viewPart(int off, int len) {
+                return null;
+            }
+
+            /** {@inheritDoc} */
+            @Override public boolean isRandomAccess() {
+                return true;
+            }
+
+            /** {@inheritDoc} */
+            @Override public boolean isDistributed() {
+                return false;
+            }
+        };
+    }
+
+    /**
+     * Create empty {@link AbstractVector} for tests.
+     *
+     * @return AbstractVector.
+     */
+    private AbstractVector getAbstractVector() {
+        return new AbstractVector() { // TODO: find out how to fix warning about missing constructor
+            /** */
+            @Override public boolean isDense() {
+                return false;
+            }
+
+            /** */
+            @Override public Matrix likeMatrix(int rows, int cols) {
+                return null;
+            }
+
+            /** */
+            @Override public boolean isSequentialAccess() {
+                return false;
+            }
+
+            /** */
+            @Override public Vector copy() {
+                return getAbstractVector(this.getStorage());
+            }
+
+            /** */
+            @Override public Vector like(int crd) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector normalize() {
+                return null;
+            }
+
+            /** */
+            @Override public Vector normalize(double power) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector logNormalize() {
+                return null;
+            }
+
+            /** */
+            @Override public Vector logNormalize(double power) {
+                return null;
+            }
+
+            /** */
+            @Override public Vector viewPart(int off, int len) {
+                return null;
+            }
+
+            /** {@inheritDoc} */
+            @Override public boolean isRandomAccess() {
+                return true;
+            }
+
+            /** {@inheritDoc} */
+            @Override public boolean isDistributed() {
+                return false;
+            }
+        };
+    }
+
+    /**
+     * Create {@link VectorStorage} for tests.
+     *
+     * @return VectorStorage
+     */
+    private VectorStorage createEmptyStorage() {
+        return new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE);
+    }
+
+    /**
+     * Create filled {@link VectorStorage} for tests.
+     *
+     * @return VectorStorage.
+     */
+    private VectorStorage createStorage() {
+        ArrayVectorStorage storage = new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE);
+
+        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
+            storage.set(i, Math.random());
+
+        return storage;
+    }
+
+    /**
+     * Init vector and return initialized values.
+     *
+     * @return Initial values.
+     */
+    private double[] initVector() {
+        VectorStorage storage = createStorage();
+        double[] data = storage.data().clone();
+
+        testVector = getAbstractVector(storage);
+        return data;
+    }
+
+    /**
+     * Add some zeroes to vector elements.
+     */
+    private void addNilValues() {
+        testVector.set(10, 0);
+        testVector.set(50, 0);
+    }
+
+    /**
+     * Add some zeroes to vector elements. Also set zeroes to the same elements in reference array data
+     */
+    private void addNilValues(double[] testRef) {
+        addNilValues();
+        testRef[10] = 0;
+        testRef[50] = 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/CacheVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/CacheVectorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/CacheVectorTest.java
new file mode 100644
index 0000000..0026e2b
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/CacheVectorTest.java
@@ -0,0 +1,434 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.stream.IntStream;
+import junit.framework.TestCase;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.ml.math.IdentityValueMapper;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorKeyMapper;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Tests for {@link CacheVector}.
+ */
+@GridCommonTest(group = "Distributed Models")
+public class CacheVectorTest extends GridCommonAbstractTest {
+    /** Number of nodes in grid */
+    private static final int NODE_COUNT = 3;
+    /** Cache name. */
+    private static final String CACHE_NAME = "test-cache";
+    /** Cache size. */
+    private static final int size = MathTestConstants.STORAGE_SIZE;
+    /** Grid instance. */
+    private Ignite ignite;
+    /** Default key mapper. */
+    private VectorKeyMapper<Integer> keyMapper = new TestKeyMapper();
+
+    /**
+     * Default constructor.
+     */
+    public CacheVectorTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        for (int i = 1; i <= NODE_COUNT; i++)
+            startGrid(i);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        ignite = grid(NODE_COUNT);
+
+        ignite.configuration().setPeerClassLoadingEnabled(true);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ignite.destroyCache(CACHE_NAME);
+    }
+
+    /** */
+    public void testGetSet() throws Exception {
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        for (int i = 0; i < size; i++) {
+            double random = Math.random();
+            cacheVector.set(i, random);
+            assertEquals("Unexpected value.", random, cacheVector.get(i), 0d);
+        }
+    }
+
+    /** */
+    public void testMap() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+
+        cacheVector.map(value -> 110d);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), 110d, 0d);
+    }
+
+    /** */
+    public void testMapBiFunc() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+
+        cacheVector.map(Functions.PLUS, 1d);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), 1d, 0d);
+    }
+
+    /** */
+    public void testSum() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+
+        assertEquals("Unexpected value.", cacheVector.sum(), 0d, 0d);
+
+        cacheVector.assign(1d);
+
+        assertEquals("Unexpected value.", cacheVector.sum(), size, 0d);
+    }
+
+    /** */
+    public void testSumNegative() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        try {
+            double d = cacheVector.sum();
+            fail();
+        }
+        catch (NullPointerException e) {
+            // No-op.
+        }
+    }
+
+    /** */
+    public void testAssign() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+
+        cacheVector.assign(1d);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), 1d, 0d);
+    }
+
+    /** */
+    public void testAssignRange() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        cacheVector.assign(IntStream.range(0, size).asDoubleStream().toArray());
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), i, 0d);
+    }
+
+    /** */
+    public void testAssignVector() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
+
+        cacheVector.assign(testVec);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), testVec.get(i), 0d);
+    }
+
+    /** */
+    public void testAssignFunc() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        cacheVector.assign(idx -> idx);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), i, 0d);
+    }
+
+    /** */
+    public void testPlus() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+
+        cacheVector.plus(1d);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), 1d, 0d);
+    }
+
+    /** */
+    public void testPlusVec() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
+
+        try {
+            cacheVector.plus(testVec);
+            TestCase.fail();
+        }
+        catch (UnsupportedOperationException ignored) {
+
+        }
+    }
+
+    /** */
+    public void testDivide() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        final int size = MathTestConstants.STORAGE_SIZE;
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+        cacheVector.assign(1d);
+
+        cacheVector.divide(2d);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), 1d / 2d, 0d);
+    }
+
+    /** */
+    public void testTimes() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        final int size = MathTestConstants.STORAGE_SIZE;
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        initVector(cacheVector);
+        cacheVector.assign(1d);
+
+        cacheVector.times(2d);
+
+        for (int i = 0; i < size; i++)
+            assertEquals("Unexpected value.", cacheVector.get(i), 2d, 0d);
+    }
+
+    /** */
+    public void testTimesVector() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        cacheVector.assign(1d);
+        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
+
+        try {
+            cacheVector.times(testVec);
+            TestCase.fail();
+        }
+        catch (UnsupportedOperationException ignored) {
+
+        }
+
+    }
+
+    /** */
+    public void testMin() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
+
+        cacheVector.assign(testVec);
+
+        assertEquals("Unexpected value.", cacheVector.minValue(), 0d, 0d);
+    }
+
+    /** */
+    public void testMax() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
+
+        cacheVector.assign(testVec);
+
+        assertEquals("Unexpected value.", cacheVector.maxValue(), testVec.get(size - 1), 0d);
+    }
+
+    /** */
+    public void testLike() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        try {
+            cacheVector.like(size);
+            TestCase.fail("Unsupported case");
+        }
+        catch (UnsupportedOperationException ignored) {
+
+        }
+    }
+
+    /** */
+    public void testLikeMatrix() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        try {
+            cacheVector.likeMatrix(size, size);
+            TestCase.fail("Unsupported case");
+        }
+        catch (UnsupportedOperationException ignored) {
+
+        }
+    }
+
+    /** */
+    public void testCopy() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        try {
+            cacheVector.copy();
+            TestCase.fail("Unsupported case");
+        }
+        catch (UnsupportedOperationException ignored) {
+
+        }
+    }
+
+    /** */
+    public void testExternalize() throws IOException, ClassNotFoundException {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        IdentityValueMapper valMapper = new IdentityValueMapper();
+        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
+
+        cacheVector.set(1, 1.0);
+
+        ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
+        ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
+
+        objOutputStream.writeObject(cacheVector);
+
+        ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
+        ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
+
+        CacheVector objRestored = (CacheVector)objInputStream.readObject();
+
+        assertTrue(MathTestConstants.VAL_NOT_EQUALS, cacheVector.equals(objRestored));
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, objRestored.get(1), 1.0, 0.0);
+    }
+
+    /** */
+    private void initVector(CacheVector cacheVector) {
+        for (int i = 0; i < cacheVector.size(); i++)
+            cacheVector.set(i, 0d);
+    }
+
+    /** */
+    private IgniteCache<Integer, Double> getCache() {
+        assert ignite != null;
+
+        CacheConfiguration cfg = new CacheConfiguration();
+        cfg.setName(CACHE_NAME);
+
+        IgniteCache<Integer, Double> cache = ignite.getOrCreateCache(CACHE_NAME);
+
+        assert cache != null;
+        return cache;
+    }
+
+    /** */ private static class TestKeyMapper implements VectorKeyMapper<Integer> {
+        /** {@inheritDoc} */
+        @Override public Integer apply(int i) {
+            return i;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isValid(Integer i) {
+            return i < size;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/ConstantVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/ConstantVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/ConstantVectorConstructorTest.java
new file mode 100644
index 0000000..c5c0bbd
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/ConstantVectorConstructorTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class ConstantVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new ConstantVector(-1, 1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void zeroSizeTest() {
+        assertEquals("Zero size.", IMPOSSIBLE_SIZE,
+            new ConstantVector(0, 1).size());
+    }
+
+    /** */
+    @Test
+    public void primitiveTest() {
+        assertEquals("1 size.", 1,
+            new ConstantVector(1, 1).size());
+
+        assertEquals("2 size.", 2,
+            new ConstantVector(2, 1).size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DelegatingVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DelegatingVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DelegatingVectorConstructorTest.java
new file mode 100644
index 0000000..1a9884f
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DelegatingVectorConstructorTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Vector;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class DelegatingVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test
+    public void basicTest() {
+        final Vector parent = new DenseLocalOnHeapVector(new double[] {0, 1});
+
+        final Vector delegate = new DelegatingVector(parent);
+
+        final int size = parent.size();
+
+        assertEquals("Delegate size differs from expected.", size, delegate.size());
+
+        for (int idx = 0; idx < size; idx++)
+            assertDelegate(parent, delegate, idx);
+    }
+
+    /** */
+    private void assertDelegate(Vector parent, Vector delegate, int idx) {
+        assertValue(parent, delegate, idx);
+
+        parent.set(idx, parent.get(idx) + 1);
+
+        assertValue(parent, delegate, idx);
+
+        delegate.set(idx, delegate.get(idx) + 2);
+
+        assertValue(parent, delegate, idx);
+    }
+
+    /** */
+    private void assertValue(Vector parent, Vector delegate, int idx) {
+        assertEquals("Unexpected value at index " + idx, parent.get(idx), delegate.get(idx), 0d);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java
new file mode 100644
index 0000000..1a979bd
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class DenseLocalOffHeapVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new DenseLocalOffHeapVector(-1).size());
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void nullArrayTest() {
+        assertEquals("Null array.", IMPOSSIBLE_SIZE,
+            new DenseLocalOffHeapVector(null).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void zeroSizeTest() {
+        assertEquals("0 size.", IMPOSSIBLE_SIZE,
+            new DenseLocalOffHeapVector(new double[0]).size());
+    }
+
+    /** */
+    @Test
+    public void primitiveTest() {
+        assertEquals("1 size.", 1,
+            new DenseLocalOffHeapVector(new double[1]).size());
+
+        assertEquals("2 size.", 2,
+            new DenseLocalOffHeapVector(new double[2]).size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java
new file mode 100644
index 0000000..df504f3
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class DenseLocalOnHeapVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapInvalidArgsTest() {
+        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
+                put("invalid", 99);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapMissingArgsTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("arr", new double[0]);
+            put("shallowCopyMissing", "whatever");
+        }};
+
+        assertEquals("Expect exception due to missing args.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(test).size());
+    }
+
+    /** */
+    @Test(expected = ClassCastException.class)
+    public void mapInvalidArrTypeTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("size", "whatever");
+        }};
+
+        assertEquals("Expect exception due to invalid arr type.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(test).size());
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapInvalidCopyTypeTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("arr", new double[0]);
+            put("shallowCopy", 0);
+        }};
+
+        assertEquals("Expect exception due to invalid copy type.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(test).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void mapNullTest() {
+        //noinspection ConstantConditions
+        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector((Map<String, Object>)null).size());
+    }
+
+    /** */
+    @Test
+    public void mapTest() {
+        assertEquals("Size from args.", 99,
+            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
+                put("size", 99);
+            }}).size());
+
+        final double[] test = new double[99];
+
+        assertEquals("Size from array in args.", test.length,
+            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
+                put("arr", test);
+                put("copy", false);
+            }}).size());
+
+        assertEquals("Size from array in args, shallow copy.", test.length,
+            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
+                put("arr", test);
+                put("copy", true);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(-1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullCopyTest() {
+        assertEquals("Null array to non-shallow copy.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(null, false).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullDefaultCopyTest() {
+        assertEquals("Null array default copy.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector((double[])null).size());
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void defaultConstructorTest() {
+        assertEquals("Default constructor.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector().size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullArrShallowCopyTest() {
+        assertEquals("Null array shallow copy.", IMPOSSIBLE_SIZE,
+            new DenseLocalOnHeapVector(null, true).size());
+    }
+
+    /** */
+    @Test
+    public void primitiveTest() {
+        assertEquals("0 size shallow copy.", 0,
+            new DenseLocalOnHeapVector(new double[0], true).size());
+
+        assertEquals("0 size.", 0,
+            new DenseLocalOnHeapVector(new double[0], false).size());
+
+        assertEquals("1 size shallow copy.", 1,
+            new DenseLocalOnHeapVector(new double[1], true).size());
+
+        assertEquals("1 size.", 1,
+            new DenseLocalOnHeapVector(new double[1], false).size());
+
+        assertEquals("0 size default copy.", 0,
+            new DenseLocalOnHeapVector(new double[0]).size());
+
+        assertEquals("1 size default copy.", 1,
+            new DenseLocalOnHeapVector(new double[1]).size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/FunctionVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/FunctionVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/FunctionVectorConstructorTest.java
new file mode 100644
index 0000000..1e99f7e
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/FunctionVectorConstructorTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.IntToDoubleFunction;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IntDoubleToVoidFunction;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class FunctionVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapInvalidArgsTest() {
+        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
+            new FunctionVector(new HashMap<String, Object>() {{
+                put("invalid", 99);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapMissingArgsTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("size", 1);
+            put("paramMissing", "whatever");
+        }};
+
+        assertEquals("Expect exception due to missing args.",
+            -1, new FunctionVector(test).size());
+    }
+
+    /** */
+    @Test(expected = ClassCastException.class)
+    public void mapInvalidParamTypeTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("size", "whatever");
+
+            put("getFunc", (IntToDoubleFunction)i -> i);
+        }};
+
+        assertEquals("Expect exception due to invalid param type.", IMPOSSIBLE_SIZE,
+            new FunctionVector(test).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void mapNullTest() {
+        //noinspection ConstantConditions
+        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
+            new FunctionVector(null).size());
+    }
+
+    /** */
+    @Test
+    public void mapTest() {
+        assertEquals("Size from args.", 99,
+            new FunctionVector(new HashMap<String, Object>() {{
+                put("size", 99);
+
+                put("getFunc", (IgniteFunction<Integer, Double>)i -> (double)i);
+            }}).size());
+
+        assertEquals("Size from args with setFunc.", 99,
+            new FunctionVector(new HashMap<String, Object>() {{
+                put("size", 99);
+
+                put("getFunc", (IgniteFunction<Integer, Double>)i -> (double)i);
+
+                put("setFunc", (IntDoubleToVoidFunction)(integer, aDouble) -> {
+                });
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new FunctionVector(-1, (i) -> (double)i).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void zeroSizeTest() {
+        assertEquals("0 size.", IMPOSSIBLE_SIZE,
+            new FunctionVector(0, (i) -> (double)i).size());
+    }
+
+    /** */
+    @Test
+    public void primitiveTest() {
+        assertEquals("1 size.", 1,
+            new FunctionVector(1, (i) -> (double)i).size());
+
+        assertEquals("2 size.", 2,
+            new FunctionVector(2, (i) -> (double)i).size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorViewTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorViewTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorViewTest.java
new file mode 100644
index 0000000..c861a0e
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorViewTest.java
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link MatrixVectorView}.
+ */
+public class MatrixVectorViewTest {
+    /** */
+    private static final String UNEXPECTED_VALUE = "Unexpected value";
+    /** */
+    private static final int SMALL_SIZE = 3;
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    private Matrix parent;
+
+    /** */
+    @Before
+    public void setup() {
+        parent = newMatrix(SMALL_SIZE, SMALL_SIZE);
+    }
+
+    /** */
+    @Test
+    public void testDiagonal() {
+        Vector vector = parent.viewDiagonal();
+
+        for (int i = 0; i < SMALL_SIZE; i++)
+            assertView(i, i, vector, i);
+    }
+
+    /** */
+    @Test
+    public void testRow() {
+        for (int i = 0; i < SMALL_SIZE; i++) {
+            Vector viewRow = parent.viewRow(i);
+
+            for (int j = 0; j < SMALL_SIZE; j++)
+                assertView(i, j, viewRow, j);
+        }
+    }
+
+    /** */
+    @Test
+    public void testCols() {
+        for (int i = 0; i < SMALL_SIZE; i++) {
+            Vector viewCol = parent.viewColumn(i);
+
+            for (int j = 0; j < SMALL_SIZE; j++)
+                assertView(j, i, viewCol, j);
+        }
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        for (int rowSize : new int[] {1, 2, 3, 4})
+            for (int colSize : new int[] {1, 2, 3, 4})
+                for (int row = 0; row < rowSize; row++)
+                    for (int col = 0; col < colSize; col++)
+                        for (int rowStride = 0; rowStride < rowSize; rowStride++)
+                            for (int colStride = 0; colStride < colSize; colStride++)
+                                if (rowStride != 0 || colStride != 0)
+                                    assertMatrixVectorView(newMatrix(rowSize, colSize), row, col, rowStride, colStride);
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void parentNullTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(null, 1, 1, 1, 1).size());
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void rowNegativeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, -1, 1, 1, 1).size());
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void colNegativeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, -1, 1, 1).size());
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void rowTooLargeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, parent.rowSize() + 1, 1, 1, 1).size());
+    }
+
+    /** */
+    @Test(expected = IndexException.class)
+    public void colTooLargeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, parent.columnSize() + 1, 1, 1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void rowStrideNegativeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, 1, -1, 1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void colStrideNegativeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, 1, 1, -1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void rowStrideTooLargeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, 1, parent.rowSize() + 1, 1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void colStrideTooLargeTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, 1, 1, parent.columnSize() + 1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void bothStridesZeroTest() {
+        //noinspection ConstantConditions
+        assertEquals(IMPOSSIBLE_SIZE,
+            new MatrixVectorView(parent, 1, 1, 0, 0).size());
+    }
+
+    /** */
+    private void assertMatrixVectorView(Matrix parent, int row, int col, int rowStride, int colStride) {
+        MatrixVectorView view = new MatrixVectorView(parent, row, col, rowStride, colStride);
+
+        String desc = "parent [" + parent.rowSize() + "x" + parent.columnSize() + "], view ["
+            + row + "x" + col + "], strides [" + rowStride + ", " + colStride + "]";
+
+        final int size = view.size();
+
+        final int sizeByRows = rowStride == 0 ? IMPOSSIBLE_SIZE : (parent.rowSize() - row) / rowStride;
+        final int sizeByCols = colStride == 0 ? IMPOSSIBLE_SIZE : (parent.columnSize() - col) / colStride;
+
+        assertTrue("Size " + size + " differs from expected for " + desc,
+            size == sizeByRows || size == sizeByCols);
+
+        for (int idx = 0; idx < size; idx++) {
+            final int rowIdx = row + idx * rowStride;
+            final int colIdx = col + idx * colStride;
+
+            assertEquals(UNEXPECTED_VALUE + " at view index " + idx + desc,
+                parent.get(rowIdx, colIdx), view.get(idx), 0d);
+        }
+    }
+
+    /** */
+    private Matrix newMatrix(int rowSize, int colSize) {
+        Matrix res = new DenseLocalOnHeapMatrix(rowSize, colSize);
+
+        for (int i = 0; i < res.rowSize(); i++)
+            for (int j = 0; j < res.columnSize(); j++)
+                res.set(i, j, i * res.rowSize() + j);
+
+        return res;
+    }
+
+    /** */
+    private void assertView(int row, int col, Vector view, int viewIdx) {
+        assertValue(row, col, view, viewIdx);
+
+        parent.set(row, col, parent.get(row, col) + 1);
+
+        assertValue(row, col, view, viewIdx);
+
+        view.set(viewIdx, view.get(viewIdx) + 2);
+
+        assertValue(row, col, view, viewIdx);
+    }
+
+    /** */
+    private void assertValue(int row, int col, Vector view, int viewIdx) {
+        assertEquals(UNEXPECTED_VALUE + " at row " + row + " col " + col, parent.get(row, col), view.get(viewIdx), 0d);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorViewConstructorTest.java
new file mode 100644
index 0000000..72be324
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorViewConstructorTest.java
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class PivotedVectorViewConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    private static final SampleParams sampleParams = new SampleParams();
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void nullVecParamTest() {
+        assertEquals("Expect exception due to null vector param.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(null, sampleParams.pivot).size());
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void nullVecParam2Test() {
+        assertEquals("Expect exception due to null vector param, with unpivot.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(null, sampleParams.pivot, sampleParams.unpivot).size());
+    }
+
+    /** */
+    @Test(expected = NullPointerException.class)
+    public void nullPivotParamTest() {
+        assertEquals("Expect exception due to null pivot param.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, null).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullPivotParam2Test() {
+        assertEquals("Expect exception due to null pivot param, with unpivot.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, null, sampleParams.unpivot).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullUnpivotParam2Test() {
+        assertEquals("Expect exception due to null unpivot param.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, sampleParams.pivot, null).size());
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void emptyPivotTest() {
+        assertEquals("Expect exception due to empty pivot param.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, new int[] {}).size());
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void emptyPivot2Test() {
+        assertEquals("Expect exception due to empty pivot param, with unpivot.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, new int[] {}, sampleParams.unpivot).size());
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void wrongPivotTest() {
+        assertEquals("Expect exception due to wrong pivot param.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, new int[] {0}).size());
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void wrongPivot2Test() {
+        assertEquals("Expect exception due to wrong pivot param, with unpivot.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, new int[] {0}, sampleParams.unpivot).size());
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void emptyUnpivotTest() {
+        assertEquals("Expect exception due to empty unpivot param.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, sampleParams.pivot, new int[] {}).size());
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void wrongUnpivotTest() {
+        assertEquals("Expect exception due to wrong unpivot param, with unpivot.", IMPOSSIBLE_SIZE,
+            new PivotedVectorView(sampleParams.vec, sampleParams.pivot, new int[] {0}).size());
+    }
+
+    /** */
+    @Test
+    public void basicPivotTest() {
+        final PivotedVectorView pvv = new PivotedVectorView(sampleParams.vec, sampleParams.pivot);
+
+        final int size = sampleParams.vec.size();
+
+        assertEquals("View size differs from expected.", size, pvv.size());
+
+        assertSame("Base vector differs from expected.", sampleParams.vec, pvv.getBaseVector());
+
+        for (int idx = 0; idx < size; idx++) {
+            assertEquals("Sample pivot and unpivot differ from expected",
+                idx, sampleParams.unpivot[sampleParams.pivot[idx]]);
+
+            assertEquals("Pivot differs from expected at index " + idx,
+                sampleParams.pivot[idx], pvv.pivot(idx));
+
+            assertEquals("Default unpivot differs from expected at index " + idx,
+                sampleParams.unpivot[idx], pvv.unpivot(idx));
+
+            final Metric metric = new Metric(sampleParams.vec.get(idx), pvv.get(pvv.pivot(idx)));
+
+            assertTrue("Not close enough at index " + idx + ", " + metric, metric.closeEnough());
+        }
+
+        for (int idx = 0; idx < size; idx++) {
+            sampleParams.vec.set(idx, sampleParams.vec.get(idx) + idx + 1);
+
+            final Metric metric = new Metric(sampleParams.vec.get(idx), pvv.get(pvv.pivot(idx)));
+
+            assertTrue("Modified value not close enough at index " + idx + ", " + metric, metric.closeEnough());
+        }
+    }
+
+    /** */
+    @Test
+    public void basicUnpivotTest() {
+        final PivotedVectorView pvv = new PivotedVectorView(sampleParams.vec, sampleParams.pivot, sampleParams.unpivot);
+
+        final int size = sampleParams.vec.size();
+
+        assertEquals("View size differs from expected.", size, pvv.size());
+
+        for (int idx = 0; idx < size; idx++) {
+            assertEquals("Unpivot differs from expected at index " + idx,
+                sampleParams.unpivot[idx], pvv.unpivot(idx));
+
+            final Metric metric = new Metric(sampleParams.vec.get(idx), pvv.get(pvv.unpivot(idx)));
+
+            assertTrue("Not close enough at index " + idx + ", " + metric, metric.closeEnough());
+        }
+    }
+
+    /** */
+    private static class SampleParams {
+        /** */
+        final double[] data = new double[] {0, 1};
+        /** */
+        final Vector vec = new DenseLocalOnHeapVector(data);
+        /** */
+        final int[] pivot = new int[] {1, 0};
+        /** */
+        final int[] unpivot = new int[] {1, 0};
+    }
+
+    /** */
+    private static class Metric { // todo consider if softer tolerance (like say 0.1 or 0.01) would make sense here
+        /** */
+        private final double exp;
+
+        /** */
+        private final double obtained;
+
+        /** **/
+        Metric(double exp, double obtained) {
+            this.exp = exp;
+            this.obtained = obtained;
+        }
+
+        /** */
+        boolean closeEnough() {
+            return new Double(exp).equals(obtained) || closeEnoughToZero();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Metric{" + "expected=" + exp +
+                ", obtained=" + obtained +
+                '}';
+        }
+
+        /** */
+        private boolean closeEnoughToZero() {
+            return (new Double(exp).equals(0.0) && new Double(obtained).equals(-0.0))
+                || (new Double(exp).equals(-0.0) && new Double(obtained).equals(0.0));
+        }
+    }
+}


[21/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/Functions.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/Functions.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/Functions.java
deleted file mode 100644
index 7100908..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/Functions.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-/**
- * Compatibility with Apache Mahout.
- */
-public final class Functions {
-    /** Function that returns {@code Math.abs(a)}. */
-    public static final IgniteDoubleFunction<Double> ABS = Math::abs;
-
-    /** Function that returns its argument. */
-    public static final IgniteDoubleFunction<Double> IDENTITY = (a) -> a;
-
-    /** Function that returns {@code Math.log(a) / Math.log(2)}. */
-    public static final IgniteDoubleFunction<Double> LOG2 = (a) -> Math.log(a) * 1.4426950408889634;
-
-    /** Function that returns {@code -a}. */
-    public static final IgniteDoubleFunction<Double> NEGATE = (a) -> -a;
-
-    /** Function that returns {@code  a < 0 ? -1 : a > 0 ? 1 : 0 }. */
-    public static final IgniteDoubleFunction<Double> SIGN = (a) -> a < 0.0 ? -1.0 : a > 0.0 ? 1.0 : 0.0;
-
-    /** Function that returns {@code a * a}. */
-    public static final IgniteDoubleFunction<Double> SQUARE = (a) -> a * a;
-
-    /** Function that returns {@code  1 / (1 + exp(-a) } */
-    public static final IgniteDoubleFunction<Double> SIGMOID = (a) -> 1.0 / (1.0 + Math.exp(-a));
-
-    /** Function that returns {@code  1 / a } */
-    public static final IgniteDoubleFunction<Double> INV = (a) -> 1.0 / a;
-
-    /** Function that returns {@code  a * (1-a) } */
-    public static final IgniteDoubleFunction<Double> SIGMOIDGRADIENT = (a) -> a * (1.0 - a);
-
-    /** Function that returns {@code a % b}. */
-    public static final IgniteBiFunction<Double, Double, Double> MOD = (a, b) -> a % b;
-
-    /** Function that returns {@code a * b}. */
-    public static final IgniteBiFunction<Double, Double, Double> MULT = (a, b) -> a * b;
-
-    /** Function that returns {@code Math.log(a) / Math.log(b)}. */
-    public static final IgniteBiFunction<Double, Double, Double> LG = (a, b) -> Math.log(a) / Math.log(b);
-
-    /** Function that returns {@code a + b}. */
-    public static final IgniteBiFunction<Double, Double, Double> PLUS = (a, b) -> a + b;
-
-    /** Function that returns {@code a - b}. */
-    public static final IgniteBiFunction<Double, Double, Double> MINUS = (a, b) -> a - b;
-
-    /** Function that returns {@code abs(a - b)}. */
-    public static final IgniteBiFunction<Double, Double, Double> MINUS_ABS = (a, b) -> Math.abs(a - b);
-
-    /** Function that returns {@code max(abs(a), abs(b))}. */
-    public static final IgniteBiFunction<Double, Double, Double> MAX_ABS = (a, b) -> Math.max(Math.abs(a), Math.abs(b));
-
-    /** Function that returns {@code min(abs(a), abs(b))}. */
-    public static final IgniteBiFunction<Double, Double, Double> MIN_ABS = (a, b) -> Math.min(Math.abs(a), Math.abs(b));
-
-    /** Function that returns {@code Math.abs(a) + Math.abs(b)}. */
-    public static final IgniteBiFunction<Double, Double, Double> PLUS_ABS = (a, b) -> Math.abs(a) + Math.abs(b);
-
-    /** Function that returns {@code (a - b) * (a - b)} */
-    public static final IgniteBiFunction<Double, Double, Double> MINUS_SQUARED = (a, b) -> (a - b) * (a - b);
-
-    /**
-     * Function that returns {@code a &lt; b ? -1 : a &gt; b ? 1 : 0}.
-     */
-    public static final IgniteBiFunction<Double, Double, Double> COMPARE = (a, b) -> a < b ? -1.0 : a > b ? 1.0 : 0.0;
-
-    /**
-     * Function that returns {@code a + b}. {@code a} is a variable, {@code b} is fixed.
-     *
-     * @param b
-     */
-    public static IgniteDoubleFunction<Double> plus(final double b) {
-        return (a) -> a + b;
-    }
-
-    /**
-     * Function that returns {@code a * b}. {@code a} is a variable, {@code b} is fixed.
-     *
-     * @param b
-     */
-    public static IgniteDoubleFunction<Double> mult(final double b) {
-        return (a) -> a * b;
-    }
-
-    /** Function that returns {@code a / b}. {@code a} is a variable, {@code b} is fixed. */
-    public static IgniteDoubleFunction<Double> div(double b) {
-        return mult(1 / b);
-    }
-
-    /**
-     * Function that returns {@code a + b*constant}. {@code a} and {@code b} are variables,
-     * {@code constant} is fixed.
-     */
-    public static IgniteBiFunction<Double, Double, Double> plusMult(double constant) {
-        return (a, b) -> a + b * constant;
-    }
-
-    /**
-     * Function that returns {@code a - b*constant}. {@code a} and {@code b} are variables,
-     * {@code constant} is fixed.
-     */
-    public static IgniteBiFunction<Double, Double, Double> minusMult(double constant) {
-        return (a, b) -> a - b * constant;
-    }
-
-    /**
-     * @param b
-     */
-    public static IgniteDoubleFunction<Double> pow(final double b) {
-        return (a) -> {
-            if (b == 2)
-                return a * a;
-            else
-                return Math.pow(a, b);
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiConsumer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiConsumer.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiConsumer.java
deleted file mode 100644
index 22e8274..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiConsumer.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.apache.ignite.math.functions;
-
-import java.io.Serializable;
-import java.util.function.BiConsumer;
-
-/**
- * Serializable binary consumer.
- *
- * @see java.util.function.BiConsumer
- */
-public interface IgniteBiConsumer<T, U> extends BiConsumer<T, U>, Serializable {
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiFunction.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiFunction.java
deleted file mode 100644
index 9d9c147..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteBiFunction.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-import java.io.Serializable;
-import java.util.function.BiFunction;
-
-/**
- * Serializable binary function.
- *
- * @see java.util.function.BiFunction
- */
-public interface IgniteBiFunction<A, B, T> extends BiFunction<A, B, T>, Serializable {
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteConsumer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteConsumer.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteConsumer.java
deleted file mode 100644
index 1f7ca07..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteConsumer.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-import java.io.Serializable;
-import java.util.function.Consumer;
-
-/**
- * Serializable consumer.
- *
- * @see java.util.function.Consumer
- */
-public interface IgniteConsumer<T> extends Consumer<T>, Serializable {
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteDoubleFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteDoubleFunction.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteDoubleFunction.java
deleted file mode 100644
index 7a23d50..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteDoubleFunction.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-import java.io.Serializable;
-import java.util.function.DoubleFunction;
-
-/**
- * Serializable double function.
- *
- * @see java.util.function.DoubleFunction
- */
-public interface IgniteDoubleFunction<Double> extends DoubleFunction<Double>, Serializable {
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteFunction.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteFunction.java
deleted file mode 100644
index cfe89a4..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IgniteFunction.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-import java.io.Serializable;
-import java.util.function.Function;
-
-/**
- * Serializable function.
- *
- * @see java.util.function.Function
- */
-public interface IgniteFunction<T, R> extends Function<T, R>, Serializable {
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntDoubleToVoidFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntDoubleToVoidFunction.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IntDoubleToVoidFunction.java
deleted file mode 100644
index e5d69c7..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntDoubleToVoidFunction.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-/**
- * Setter function for the vector.
- */
-public interface IntDoubleToVoidFunction extends IgniteBiConsumer<Integer, Double> {
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntDoubleToVoidFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntDoubleToVoidFunction.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntDoubleToVoidFunction.java
deleted file mode 100644
index cad8c3c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntDoubleToVoidFunction.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-import java.io.Serializable;
-
-/**
- * Setter function for matrices.
- */
-public interface IntIntDoubleToVoidFunction extends Serializable {
-    /** */
-    public void apply(int x, int y, double v);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntToDoubleFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntToDoubleFunction.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntToDoubleFunction.java
deleted file mode 100644
index b31d9f9..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/IntIntToDoubleFunction.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.functions;
-
-/**
- * Getters functions for matrices.
- */
-public interface IntIntToDoubleFunction extends IgniteBiFunction<Integer, Integer, Double> {
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/functions/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/functions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/functions/package-info.java
deleted file mode 100644
index 133e62c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/functions/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains serializable functions for distributed code algebra.
- */
-package org.apache.ignite.math.functions;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/CacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/CacheUtils.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/CacheUtils.java
deleted file mode 100644
index df33895..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/CacheUtils.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import javax.cache.Cache;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.cache.query.ScanQuery;
-import org.apache.ignite.cluster.ClusterGroup;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.lang.IgniteRunnable;
-import org.apache.ignite.math.KeyMapper;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteConsumer;
-import org.apache.ignite.math.functions.IgniteFunction;
-
-/**
- * Distribution-related misc. support.
- */
-public class CacheUtils {
-    /**
-     * Cache entry support.
-     *
-     * @param <K>
-     * @param <V>
-     */
-    public static class CacheEntry<K, V> {
-        /** */
-        private Cache.Entry<K, V> entry;
-        /** */
-        private IgniteCache<K, V> cache;
-
-        /**
-         * @param entry Original cache entry.
-         * @param cache Cache instance.
-         */
-        CacheEntry(Cache.Entry<K, V> entry, IgniteCache<K, V> cache) {
-            this.entry = entry;
-            this.cache = cache;
-        }
-
-        /**
-         *
-         *
-         */
-        public Cache.Entry<K, V> entry() {
-            return entry;
-        }
-
-        /**
-         *
-         *
-         */
-        public IgniteCache<K, V> cache() {
-            return cache;
-        }
-    }
-
-    /**
-     * Gets local Ignite instance.
-     */
-    public static Ignite ignite() {
-        return Ignition.localIgnite();
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @param k Key into the cache.
-     * @param <K> Key type.
-     * @return Cluster group for given key.
-     */
-    public static <K> ClusterGroup groupForKey(String cacheName, K k) {
-        return ignite().cluster().forNode(ignite().affinity(cacheName).mapKeyToNode(k));
-    }
-
-    /**
-     * @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.
-     * @return Sum of the values obtained for valid keys.
-     */
-    public static <K, V> double sum(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
-        Collection<Double> subSums = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
-            if (keyMapper.isValid(ce.entry().getKey())) {
-                double v = valMapper.toDouble(ce.entry().getValue());
-
-                return acc == null ? v : acc + v;
-            }
-            else
-                return acc;
-        });
-
-        return sum(subSums);
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @return Sum obtained using sparse logic.
-     */
-    public static <K, V> double sparseSum(String cacheName) {
-        Collection<Double> subSums = fold(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce, Double acc) -> {
-            Map<Integer, Double> map = ce.entry().getValue();
-
-            double sum = sum(map.values());
-
-            return acc == null ? sum : acc + sum;
-        });
-
-        return sum(subSums);
-    }
-
-    /**
-     * @param c {@link Collection} of double values to sum.
-     * @return Sum of the values.
-     */
-    private static double sum(Collection<Double> c) {
-        double sum = 0.0;
-
-        for (double d : c)
-            sum += d;
-
-        return sum;
-    }
-
-    /**
-     * @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.
-     * @return Minimum value for valid keys.
-     */
-    public static <K, V> double min(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
-        Collection<Double> mins = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
-            if (keyMapper.isValid(ce.entry().getKey())) {
-                double v = valMapper.toDouble(ce.entry().getValue());
-
-                if (acc == null)
-                    return v;
-                else
-                    return Math.min(acc, v);
-            }
-            else
-                return acc;
-        });
-
-        return Collections.min(mins);
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @return Minimum value obtained using sparse logic.
-     */
-    public static <K, V> double sparseMin(String cacheName) {
-        Collection<Double> mins = fold(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce, Double acc) -> {
-            Map<Integer, Double> map = ce.entry().getValue();
-
-            double min = Collections.min(map.values());
-
-            if (acc == null)
-                return min;
-            else
-                return Math.min(acc, min);
-        });
-
-        return Collections.min(mins);
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @return Maximum value obtained using sparse logic.
-     */
-    public static <K, V> double sparseMax(String cacheName) {
-        Collection<Double> maxes = fold(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce, Double acc) -> {
-            Map<Integer, Double> map = ce.entry().getValue();
-
-            double max = Collections.max(map.values());
-
-            if (acc == null)
-                return max;
-            else
-                return Math.max(acc, max);
-        });
-
-        return Collections.max(maxes);
-    }
-
-    /**
-     * @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.
-     * @return Maximum value for valid keys.
-     */
-    public static <K, V> double max(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
-        Collection<Double> maxes = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
-            if (keyMapper.isValid(ce.entry().getKey())) {
-                double v = valMapper.toDouble(ce.entry().getValue());
-
-                if (acc == null)
-                    return v;
-                else
-                    return Math.max(acc, v);
-            }
-            else
-                return acc;
-        });
-
-        return Collections.max(maxes);
-    }
-
-    /**
-     * @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.
-     */
-    public static <K, V> void map(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper,
-        IgniteFunction<Double, Double> mapper) {
-        foreach(cacheName, (CacheEntry<K, V> ce) -> {
-            K k = ce.entry().getKey();
-
-            if (keyMapper.isValid(k))
-                // Actual assignment.
-                ce.cache().put(k, valMapper.fromDouble(mapper.apply(valMapper.toDouble(ce.entry().getValue()))));
-        });
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @param mapper Mapping {@link IgniteFunction}.
-     */
-    public static <K, V> void sparseMap(String cacheName, IgniteFunction<Double, Double> mapper) {
-        foreach(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce) -> {
-            Integer k = ce.entry().getKey();
-            Map<Integer, Double> v = ce.entry().getValue();
-
-            for (Map.Entry<Integer, Double> e : v.entrySet())
-                e.setValue(mapper.apply(e.getValue()));
-
-            ce.cache().put(k, v);
-        });
-    }
-
-    /**
-     * @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.
-     */
-    public static <K, V> void foreach(String cacheName, IgniteConsumer<CacheEntry<K, V>> fun) {
-        bcast(cacheName, () -> {
-            Ignite ignite = Ignition.localIgnite();
-            IgniteCache<K, V> cache = ignite.getOrCreateCache(cacheName);
-
-            int partsCnt = ignite.affinity(cacheName).partitions();
-
-            // Use affinity in filter for scan query. Otherwise we accept consumer in each node which is wrong.
-            Affinity affinity = ignite.affinity(cacheName);
-            ClusterNode locNode = ignite.cluster().localNode();
-
-            // Iterate over all partitions. Some of them will be stored on that local node.
-            for (int part = 0; part < partsCnt; part++) {
-                int p = part;
-
-                // 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)))
-                    fun.accept(new CacheEntry<>(entry, cache));
-            }
-        });
-    }
-
-    /**
-     * <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.
-     * @return Fold operation result.
-     */
-    public static <K, V, A> Collection<A> fold(String cacheName, IgniteBiFunction<CacheEntry<K, V>, A, A> folder) {
-        return bcast(cacheName, () -> {
-            Ignite ignite = Ignition.localIgnite();
-            IgniteCache<K, V> cache = ignite.getOrCreateCache(cacheName);
-
-            int partsCnt = ignite.affinity(cacheName).partitions();
-
-            // Use affinity in filter for ScanQuery. Otherwise we accept consumer in each node which is wrong.
-            Affinity affinity = ignite.affinity(cacheName);
-            ClusterNode locNode = ignite.cluster().localNode();
-
-            A a = null;
-
-            // Iterate over all partitions. Some of them will be stored on that local node.
-            for (int part = 0; part < partsCnt; part++) {
-                int p = part;
-
-                // 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)))
-                    a = folder.apply(new CacheEntry<>(entry, cache), a);
-            }
-
-            return a;
-        });
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @param run {@link Runnable} to broadcast to cache nodes for given cache name.
-     */
-    public static void bcast(String cacheName, IgniteRunnable run) {
-        ignite().compute(ignite().cluster().forCacheNodes(cacheName)).broadcast(run);
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @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 ignite().compute(ignite().cluster().forCacheNodes(cacheName)).broadcast(call);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/AbstractMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/AbstractMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/AbstractMatrix.java
deleted file mode 100644
index ca11e81..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/AbstractMatrix.java
+++ /dev/null
@@ -1,880 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.decompositions.LUDecomposition;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.ColumnIndexException;
-import org.apache.ignite.math.exceptions.RowIndexException;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.functions.IntIntToDoubleFunction;
-import org.apache.ignite.math.impls.vector.MatrixVectorView;
-
-/**
- * This class provides a helper implementation of the {@link Matrix}
- * interface to minimize the effort required to implement it.
- * Subclasses may override some of the implemented methods if a more
- * specific or optimized implementation is desirable.
- *
- * TODO: add row/column optimization.
- */
-public abstract class AbstractMatrix implements Matrix {
-    // Stochastic sparsity analysis.
-    /** */
-    private static final double Z95 = 1.959964;
-    /** */
-    private static final double Z80 = 1.281552;
-    /** */
-    private static final int MAX_SAMPLES = 500;
-    /** */
-    private static final int MIN_SAMPLES = 15;
-
-    /** Cached minimum element. */
-    private Element minElm;
-    /** Cached maximum element. */
-    private Element maxElm = null;
-
-    /** Matrix storage implementation. */
-    private MatrixStorage sto;
-
-    /** Meta attributes storage. */
-    private Map<String, Object> meta = new HashMap<>();
-
-    /** Matrix's GUID. */
-    private IgniteUuid guid = IgniteUuid.randomUuid();
-
-    /**
-     * @param sto Backing {@link MatrixStorage}.
-     */
-    public AbstractMatrix(MatrixStorage sto) {
-        this.sto = sto;
-    }
-
-    /**
-     *
-     */
-    public AbstractMatrix() {
-        // No-op.
-    }
-
-    /**
-     * @param sto Backing {@link MatrixStorage}.
-     */
-    protected void setStorage(MatrixStorage sto) {
-        assert sto != null;
-
-        this.sto = sto;
-    }
-
-    /**
-     * @param row Row index in the matrix.
-     * @param col Column index in the matrix.
-     * @param v Value to set.
-     */
-    protected void storageSet(int row, int col, double v) {
-        sto.set(row, col, v);
-
-        // Reset cached values.
-        minElm = maxElm = null;
-    }
-
-    /**
-     * @param row Row index in the matrix.
-     * @param col Column index in the matrix.
-     */
-    protected double storageGet(int row, int col) {
-        return sto.get(row, col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element maxElement() {
-        if (maxElm == null) {
-            double max = Double.NEGATIVE_INFINITY;
-            int row = 0, col = 0;
-
-            int rows = rowSize();
-            int cols = columnSize();
-
-            for (int x = 0; x < rows; x++)
-                for (int y = 0; y < cols; y++) {
-                    double d = storageGet(x, y);
-
-                    if (d > max) {
-                        max = d;
-                        row = x;
-                        col = y;
-                    }
-                }
-
-            maxElm = mkElement(row, col);
-        }
-
-        return maxElm;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element minElement() {
-        if (minElm == null) {
-            double min = Double.MAX_VALUE;
-            int row = 0, col = 0;
-
-            int rows = rowSize();
-            int cols = columnSize();
-
-            for (int x = 0; x < rows; x++)
-                for (int y = 0; y < cols; y++) {
-                    double d = storageGet(x, y);
-
-                    if (d < min) {
-                        min = d;
-                        row = x;
-                        col = y;
-                    }
-                }
-
-            minElm = mkElement(row, col);
-        }
-
-        return minElm;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxValue() {
-        return maxElement().get();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double minValue() {
-        return minElement().get();
-    }
-
-    /**
-     * @param row Row index in the matrix.
-     * @param col Column index in the matrix.
-     */
-    private Element mkElement(int row, int col) {
-        return new Element() {
-            /** {@inheritDoc} */
-            @Override public double get() {
-                return storageGet(row, col);
-            }
-
-            /** {@inheritDoc} */
-            @Override public int row() {
-                return row;
-            }
-
-            /** {@inheritDoc} */
-            @Override public int column() {
-                return col;
-            }
-
-            /** {@inheritDoc} */
-            @Override public void set(double d) {
-                storageSet(row, col, d);
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element getElement(int row, int col) {
-        return mkElement(row, col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix swapRows(int row1, int row2) {
-        checkRowIndex(row1);
-        checkRowIndex(row2);
-
-        int cols = columnSize();
-
-        for (int y = 0; y < cols; y++) {
-            double v = getX(row1, y);
-
-            setX(row1, y, getX(row2, y));
-            setX(row2, y, v);
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix swapColumns(int col1, int col2) {
-        checkColumnIndex(col1);
-        checkColumnIndex(col2);
-
-        int rows = rowSize();
-
-        for (int x = 0; x < rows; x++) {
-            double v = getX(x, col1);
-
-            setX(x, col1, getX(x, col2));
-            setX(x, col2, v);
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public MatrixStorage getStorage() {
-        return sto;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return sto.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return sto.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return sto.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return sto.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return sto.isArrayBased();
-    }
-
-    /**
-     * Check row index bounds.
-     *
-     * @param row Row index.
-     */
-    private void checkRowIndex(int row) {
-        if (row < 0 || row >= rowSize())
-            throw new RowIndexException(row);
-    }
-
-    /**
-     * Check column index bounds.
-     *
-     * @param col Column index.
-     */
-    private void checkColumnIndex(int col) {
-        if (col < 0 || col >= columnSize())
-            throw new ColumnIndexException(col);
-    }
-
-    /**
-     * Check column and row index bounds.
-     *
-     * @param row Row index.
-     * @param col Column index.
-     */
-    protected void checkIndex(int row, int col) {
-        checkRowIndex(row);
-        checkColumnIndex(col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sto);
-        out.writeObject(meta);
-        out.writeObject(guid);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map<String, Object> getMetaStorage() {
-        return meta;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sto = (MatrixStorage)in.readObject();
-        meta = (Map<String, Object>)in.readObject();
-        guid = (IgniteUuid)in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assign(double val) {
-        if (sto.isArrayBased())
-            for (double[] column : sto.data())
-                Arrays.fill(column, val);
-        else {
-            int rows = rowSize();
-            int cols = columnSize();
-
-            for (int x = 0; x < rows; x++)
-                for (int y = 0; y < cols; y++)
-                    storageSet(x, y, val);
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assign(IntIntToDoubleFunction fun) {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                storageSet(x, y, fun.apply(x, y));
-
-        return this;
-    }
-
-    /** */
-    private void checkCardinality(Matrix mtx) {
-        checkCardinality(mtx.rowSize(), mtx.columnSize());
-    }
-
-    /** */
-    private void checkCardinality(int rows, int cols) {
-        if (rows != rowSize())
-            throw new CardinalityException(rowSize(), rows);
-
-        if (cols != columnSize())
-            throw new CardinalityException(columnSize(), cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assign(double[][] vals) {
-        checkCardinality(vals.length, vals[0].length);
-
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                storageSet(x, y, vals[x][y]);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assign(Matrix mtx) {
-        checkCardinality(mtx);
-
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                storageSet(x, y, mtx.getX(x, y));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix map(IgniteDoubleFunction<Double> fun) {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                storageSet(x, y, fun.apply(storageGet(x, y)));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix map(Matrix mtx, IgniteBiFunction<Double, Double, Double> fun) {
-        checkCardinality(mtx);
-
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                storageSet(x, y, fun.apply(storageGet(x, y), mtx.getX(x, y)));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assignColumn(int col, org.apache.ignite.math.Vector vec) {
-        checkColumnIndex(col);
-
-        int rows = rowSize();
-
-        for (int x = 0; x < rows; x++)
-            storageSet(x, col, vec.getX(x));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assignRow(int row, Vector vec) {
-        checkRowIndex(row);
-
-        int cols = columnSize();
-
-        if (cols != vec.size())
-            throw new CardinalityException(cols, vec.size());
-
-        if (sto.isArrayBased() && vec.getStorage().isArrayBased())
-            System.arraycopy(vec.getStorage().data(), 0, sto.data()[row], 0, cols);
-        else
-            for (int y = 0; y < cols; y++)
-                storageSet(row, y, vec.getX(y));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector foldRows(IgniteFunction<Vector, Double> fun) {
-        int rows = rowSize();
-
-        Vector vec = likeVector(rows);
-
-        for (int i = 0; i < rows; i++)
-            vec.setX(i, fun.apply(viewRow(i)));
-
-        return vec;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector foldColumns(IgniteFunction<Vector, Double> fun) {
-        int cols = columnSize();
-
-        Vector vec = likeVector(cols);
-
-        for (int i = 0; i < cols; i++)
-            vec.setX(i, fun.apply(viewColumn(i)));
-
-        return vec;
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun,
-        T zeroVal) {
-        T res = zeroVal;
-
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                res = foldFun.apply(res, mapFun.apply(storageGet(x, y)));
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return sto.columnSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return sto.rowSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double determinant() {
-        //TODO: This decomposition should be cached
-        LUDecomposition dec = new LUDecomposition(this);
-        double res = dec.determinant();
-        dec.destroy();
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix inverse() {
-        if (rowSize() != columnSize())
-            throw new CardinalityException(rowSize(), columnSize());
-
-        //TODO: This decomposition should be cached
-        LUDecomposition dec = new LUDecomposition(this);
-
-        Matrix res = dec.solve(likeIdentity());
-        dec.destroy();
-
-        return res;
-    }
-
-    /** */
-    protected Matrix likeIdentity() {
-        int n = rowSize();
-        Matrix res = like(n, n);
-
-        for (int i = 0; i < n; i++)
-            res.setX(i, i, 1.0);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix divide(double d) {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                setX(x, y, getX(x, y) / d);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int row, int col) {
-        checkIndex(row, col);
-
-        return storageGet(row, col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getX(int row, int col) {
-        return storageGet(row, col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix minus(Matrix mtx) {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        checkCardinality(rows, cols);
-
-        Matrix res = like(rows, cols);
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                res.setX(x, y, getX(x, y) - mtx.getX(x, y));
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix plus(double x) {
-        Matrix cp = copy();
-
-        cp.map(Functions.plus(x));
-
-        return cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix plus(Matrix mtx) {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        checkCardinality(rows, cols);
-
-        Matrix res = like(rows, cols);
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                res.setX(x, y, getX(x, y) + mtx.getX(x, y));
-
-        return res;
-
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteUuid guid() {
-        return guid;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix set(int row, int col, double val) {
-        checkIndex(row, col);
-
-        storageSet(row, col, val);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix setRow(int row, double[] data) {
-        checkRowIndex(row);
-
-        int cols = columnSize();
-
-        if (cols != data.length)
-            throw new CardinalityException(cols, data.length);
-
-        if (sto.isArrayBased())
-            System.arraycopy(data, 0, sto.data()[row], 0, cols);
-        else
-            for (int y = 0; y < cols; y++)
-                setX(row, y, data[y]);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix setColumn(int col, double[] data) {
-        checkColumnIndex(col);
-
-        int rows = rowSize();
-
-        if (rows != data.length)
-            throw new CardinalityException(rows, data.length);
-
-        for (int x = 0; x < rows; x++)
-            setX(x, col, data[x]);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix setX(int row, int col, double val) {
-        storageSet(row, col, val);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix times(double x) {
-        Matrix cp = copy();
-
-        cp.map(Functions.mult(x));
-
-        return cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxAbsRowSumNorm() {
-        double max = 0.0;
-
-        int rows = rowSize();
-        int cols = columnSize();
-
-        for (int x = 0; x < rows; x++) {
-            double sum = 0;
-
-            for (int y = 0; y < cols; y++)
-                sum += Math.abs(getX(x, y));
-
-            if (sum > max)
-                max = sum;
-        }
-
-        return max;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(Vector vec) {
-        int cols = columnSize();
-
-        if (cols != vec.size())
-            throw new CardinalityException(cols, vec.size());
-
-        int rows = rowSize();
-
-        Vector res = likeVector(rows);
-
-        for (int x = 0; x < rows; x++)
-            res.setX(x, vec.dot(viewRow(x)));
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix times(Matrix mtx) {
-        int cols = columnSize();
-
-        if (cols != mtx.rowSize())
-            throw new CardinalityException(cols, mtx.rowSize());
-
-        int rows = rowSize();
-
-        int mtxCols = mtx.columnSize();
-
-        Matrix res = like(rows, mtxCols);
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < mtxCols; y++) {
-                double sum = 0.0;
-
-                for (int k = 0; k < cols; k++)
-                    sum += getX(x, k) * mtx.getX(k, y);
-
-                res.setX(x, y, sum);
-            }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        double sum = 0.0;
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                sum += getX(x, y);
-
-        return sum;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix transpose() {
-        int rows = rowSize();
-        int cols = columnSize();
-
-        Matrix mtx = like(cols, rows);
-
-        for (int x = 0; x < rows; x++)
-            for (int y = 0; y < cols; y++)
-                mtx.setX(y, x, getX(x, y));
-
-        return mtx;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean density(double threshold) {
-        assert threshold >= 0.0 && threshold <= 1.0;
-
-        int n = MIN_SAMPLES;
-        int rows = rowSize();
-        int cols = columnSize();
-
-        double mean = 0.0;
-        double pq = threshold * (1 - threshold);
-
-        Random rnd = new Random();
-
-        for (int i = 0; i < MIN_SAMPLES; i++)
-            if (getX(rnd.nextInt(rows), rnd.nextInt(cols)) != 0.0)
-                mean++;
-
-        mean /= MIN_SAMPLES;
-
-        double iv = Z80 * Math.sqrt(pq / n);
-
-        if (mean < threshold - iv)
-            return false; // Sparse.
-        else if (mean > threshold + iv)
-            return true; // Dense.
-
-        while (n < MAX_SAMPLES) {
-            // Determine upper bound we may need for 'n' to likely relinquish the uncertainty.
-            // Here, we use confidence interval formula but solved for 'n'.
-            double ivX = Math.max(Math.abs(threshold - mean), 1e-11);
-
-            double stdErr = ivX / Z80;
-            double nX = Math.min(Math.max((int)Math.ceil(pq / (stdErr * stdErr)), n), MAX_SAMPLES) - n;
-
-            if (nX < 1.0) // IMPL NOTE this can happen with threshold 1.0
-                nX = 1.0;
-
-            double meanNext = 0.0;
-
-            for (int i = 0; i < nX; i++)
-                if (getX(rnd.nextInt(rows), rnd.nextInt(cols)) != 0.0)
-                    meanNext++;
-
-            mean = (n * mean + meanNext) / (n + nX);
-
-            n += nX;
-
-            // Are we good now?
-            iv = Z80 * Math.sqrt(pq / n);
-
-            if (mean < threshold - iv)
-                return false; // Sparse.
-            else if (mean > threshold + iv)
-                return true; // Dense.
-        }
-
-        return mean > threshold; // Dense if mean > threshold.
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix viewPart(int[] off, int[] size) {
-        return new MatrixView(this, off[0], off[1], size[0], size[1]);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix viewPart(int rowOff, int rows, int colOff, int cols) {
-        return viewPart(new int[] {rowOff, colOff}, new int[] {rows, cols});
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewRow(int row) {
-        return new MatrixVectorView(this, row, 0, 0, 1);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewColumn(int col) {
-        return new MatrixVectorView(this, 0, col, 1, 0);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewDiagonal() {
-        return new MatrixVectorView(this, 0, 0, 1, 1);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        Matrix cp = like(rowSize(), columnSize());
-
-        cp.assign(this);
-
-        return cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + guid.hashCode();
-        res = res * 37 + sto.hashCode();
-        res = res * 37 + meta.hashCode();
-
-        return res;
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * We ignore guid's for comparisons.
-     */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        AbstractMatrix that = (AbstractMatrix)o;
-
-        MatrixStorage sto = getStorage();
-
-        return (sto != null ? sto.equals(that.getStorage()) : that.getStorage() == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/CacheMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/CacheMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/CacheMatrix.java
deleted file mode 100644
index 8ce1192..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/CacheMatrix.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixKeyMapper;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.impls.CacheUtils;
-import org.apache.ignite.math.impls.storage.matrix.CacheMatrixStorage;
-
-/**
- * Matrix based on existing cache and key and value mapping functions.
- */
-public class CacheMatrix<K, V> extends AbstractMatrix {
-    /**
-     *
-     */
-    public CacheMatrix() {
-        // No-op.
-    }
-
-    /**
-     * Creates new matrix over existing cache.
-     *
-     * @param rows
-     * @param cols
-     * @param cache
-     * @param keyMapper
-     * @param valMapper
-     */
-    public CacheMatrix(
-        int rows,
-        int cols,
-        IgniteCache<K, V> cache,
-        MatrixKeyMapper<K> keyMapper,
-        ValueMapper<V> valMapper) {
-        assert rows > 0;
-        assert cols > 0;
-        assert cache != null;
-        assert keyMapper != null;
-        assert valMapper != null;
-
-        setStorage(new CacheMatrixStorage<>(rows, cols, cache, keyMapper, valMapper));
-    }
-
-    /**
-     *
-     *
-     */
-    @SuppressWarnings({"unchecked"})
-    private CacheMatrixStorage<K, V> storage() {
-        return (CacheMatrixStorage<K, V>)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Return the same matrix with updates values (broken contract).
-     *
-     * @param d
-     */
-    @Override public Matrix divide(double d) {
-        return mapOverValues((Double v) -> v / d);
-    }
-
-    /**
-     * Return the same matrix with updates values (broken contract).
-     *
-     * @param x
-     */
-    @Override public Matrix plus(double x) {
-        return mapOverValues((Double v) -> v + x);
-    }
-
-    /**
-     * Return the same matrix with updates values (broken contract).
-     *
-     * @param x
-     */
-    @Override public Matrix times(double x) {
-        return mapOverValues((Double v) -> v * x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assign(double val) {
-        return mapOverValues((Double v) -> val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix map(IgniteDoubleFunction<Double> fun) {
-        return mapOverValues(fun::apply);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        CacheMatrixStorage<K, V> sto = storage();
-
-        return CacheUtils.sum(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxValue() {
-        CacheMatrixStorage<K, V> sto = storage();
-
-        return CacheUtils.max(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double minValue() {
-        CacheMatrixStorage<K, V> sto = storage();
-
-        return CacheUtils.min(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
-    }
-
-    /**
-     * @param mapper
-     */
-    private Matrix mapOverValues(IgniteFunction<Double, Double> mapper) {
-        CacheMatrixStorage<K, V> sto = storage();
-
-        CacheUtils.map(sto.cache().getName(), sto.keyMapper(), sto.valueMapper(), mapper);
-
-        return this;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrix.java
deleted file mode 100644
index d5f8eca..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrix.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.storage.matrix.DenseOffHeapMatrixStorage;
-import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVector;
-
-/**
- * Dense local off-heap implementation of the {@link Matrix} interface.
- */
-public class DenseLocalOffHeapMatrix extends AbstractMatrix {
-    /** */
-    public DenseLocalOffHeapMatrix() {
-        // No-op.
-    }
-
-    /**
-     * @param data Backing data array.
-     */
-    public DenseLocalOffHeapMatrix(double[][] data) {
-        assert data != null;
-
-        setStorage(new DenseOffHeapMatrixStorage(data));
-    }
-
-    /**
-     * @param rows Amount of rows in matrix.
-     * @param cols Amount of columns in matrix.
-     */
-    public DenseLocalOffHeapMatrix(int rows, int cols) {
-        assert rows > 0;
-        assert cols > 0;
-
-        setStorage(new DenseOffHeapMatrixStorage(rows, cols));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        DenseLocalOffHeapMatrix cp = new DenseLocalOffHeapMatrix(getStorage().rowSize(), getStorage().columnSize());
-
-        cp.assign(this);
-
-        return cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        return new DenseLocalOffHeapMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        return new DenseLocalOffHeapVector(crd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        getStorage().destroy();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Matrix likeIdentity() {
-        int n = rowSize();
-        Matrix res = like(n, n);
-
-        // IMPL NOTE as opposed to on-heap matrices this one isn't initialized with zeroes
-        for (int i = 0; i < n; i++)
-            for (int j = 0; j < n; j++)
-                res.setX(i, j, i == j ? 1.0 : 0.0);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrix.java
deleted file mode 100644
index 3cc3e4f..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrix.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.storage.matrix.ArrayMatrixStorage;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-
-/**
- * Basic implementation for matrix.
- *
- * This is a trivial implementation for matrix assuming dense logic, local on-heap JVM storage
- * based on <code>double[][]</code> array. It is only suitable for data sets where
- * local, non-distributed execution is satisfactory and on-heap JVM storage is enough
- * to keep the entire data set.
- */
-public class DenseLocalOnHeapMatrix extends AbstractMatrix {
-    /**
-     *
-     */
-    public DenseLocalOnHeapMatrix() {
-        // No-op.
-    }
-
-    /**
-     * @param rows Amount of rows in matrix.
-     * @param cols Amount of columns in matrix.
-     */
-    public DenseLocalOnHeapMatrix(int rows, int cols) {
-        assert rows > 0;
-        assert cols > 0;
-
-        setStorage(new ArrayMatrixStorage(rows, cols));
-    }
-
-    /**
-     * @param mtx Backing data array.
-     */
-    public DenseLocalOnHeapMatrix(double[][] mtx) {
-        assert mtx != null;
-
-        setStorage(new ArrayMatrixStorage(mtx));
-    }
-
-    /**
-     * @param orig Original matrix.
-     */
-    private DenseLocalOnHeapMatrix(DenseLocalOnHeapMatrix orig) {
-        assert orig != null;
-
-        setStorage(new ArrayMatrixStorage(orig.rowSize(), orig.columnSize()));
-
-        assign(orig);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        return new DenseLocalOnHeapMatrix(this);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        return new DenseLocalOnHeapMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        return new DenseLocalOnHeapVector(crd);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DiagonalMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DiagonalMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DiagonalMatrix.java
deleted file mode 100644
index 0b1f97e..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/DiagonalMatrix.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.storage.matrix.DiagonalMatrixStorage;
-import org.apache.ignite.math.impls.vector.ConstantVector;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.apache.ignite.math.impls.vector.SingleElementVectorView;
-
-/**
- * Implementation of diagonal view of the {@link Matrix}.
- *
- * <p>See also: <a href="https://en.wikipedia.org/wiki/Diagonal_matrix">Wikipedia article</a>.</p>
- */
-public class DiagonalMatrix extends AbstractMatrix {
-    /**
-     *
-     */
-    public DiagonalMatrix() {
-        // No-op.
-    }
-
-    /**
-     * @param diagonal Backing {@link Vector}.
-     */
-    public DiagonalMatrix(Vector diagonal) {
-        super(new DiagonalMatrixStorage(diagonal));
-    }
-
-    /**
-     * @param mtx Backing {@link Matrix}.
-     */
-    public DiagonalMatrix(Matrix mtx) {
-        super(new DiagonalMatrixStorage(mtx == null ? null : mtx.viewDiagonal()));
-    }
-
-    /**
-     * @param vals Backing array of values at diagonal.
-     */
-    public DiagonalMatrix(double[] vals) {
-        super(new DiagonalMatrixStorage(new DenseLocalOnHeapVector(vals)));
-    }
-
-    /**
-     *
-     *
-     */
-    private DiagonalMatrixStorage storage() {
-        return (DiagonalMatrixStorage)getStorage();
-    }
-
-    /**
-     * @param size Size of diagonal.
-     * @param val Constant value at diagonal.
-     */
-    public DiagonalMatrix(int size, double val) {
-        super(new DiagonalMatrixStorage(new ConstantVector(size, val)));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewRow(int row) {
-        return new SingleElementVectorView(storage().diagonal(), row);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewColumn(int col) {
-        return new SingleElementVectorView(storage().diagonal(), col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        return new DiagonalMatrix(storage().diagonal());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        return storage().diagonal().likeMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        return storage().diagonal().like(crd);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/FunctionMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/FunctionMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/FunctionMatrix.java
deleted file mode 100644
index b180b5b..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/FunctionMatrix.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IntIntDoubleToVoidFunction;
-import org.apache.ignite.math.functions.IntIntToDoubleFunction;
-import org.apache.ignite.math.impls.storage.matrix.FunctionMatrixStorage;
-
-/**
- * Implementation of {@link Matrix} that maps row and column index to {@link java.util.function} interfaces.
- */
-public class FunctionMatrix extends AbstractMatrix {
-    /**
-     *
-     */
-    public FunctionMatrix() {
-        // No-op.
-    }
-
-    /**
-     * Creates read-write or read-only function matrix.
-     *
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param getFunc Function that returns value corresponding to given row and column index.
-     * @param setFunc Set function. If {@code null} - this will be a read-only matrix.
-     */
-    public FunctionMatrix(int rows, int cols, IntIntToDoubleFunction getFunc, IntIntDoubleToVoidFunction setFunc) {
-        assert rows > 0;
-        assert cols > 0;
-        assert getFunc != null;
-
-        setStorage(new FunctionMatrixStorage(rows, cols, getFunc, setFunc));
-    }
-
-    /**
-     * Creates read-only function matrix.
-     *
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param getFunc Function that returns value corresponding to given row and column index.
-     */
-    public FunctionMatrix(int rows, int cols, IntIntToDoubleFunction getFunc) {
-        assert rows > 0;
-        assert cols > 0;
-        assert getFunc != null;
-
-        setStorage(new FunctionMatrixStorage(rows, cols, getFunc));
-    }
-
-    /**
-     *
-     *
-     */
-    private FunctionMatrixStorage storage() {
-        return (FunctionMatrixStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        FunctionMatrixStorage sto = storage();
-
-        return new FunctionMatrix(sto.rowSize(), sto.columnSize(), sto.getFunction(), sto.setFunction());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        FunctionMatrixStorage sto = storage();
-
-        return new FunctionMatrix(rows, cols, sto.getFunction(), sto.setFunction());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/MatrixView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/MatrixView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/MatrixView.java
deleted file mode 100644
index 7b04dde..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/MatrixView.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.io.Externalizable;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.storage.matrix.MatrixDelegateStorage;
-
-/**
- * Implements the rectangular view into the parent {@link Matrix}.
- */
-public class MatrixView extends AbstractMatrix {
-    /**
-     * Constructor for {@link Externalizable} interface.
-     */
-    public MatrixView() {
-        // No-op.
-    }
-
-    /**
-     * @param parent Backing parent {@link Matrix}.
-     * @param rowOff Row offset to parent matrix.
-     * @param colOff Column offset to parent matrix.
-     * @param rows Amount of rows in the view.
-     * @param cols Amount of columns in the view.
-     */
-    public MatrixView(Matrix parent, int rowOff, int colOff, int rows, int cols) {
-        this(parent == null ? null : parent.getStorage(), rowOff, colOff, rows, cols);
-    }
-
-    /**
-     * @param sto Backing parent {@link MatrixStorage}.
-     * @param rowOff Row offset to parent storage.
-     * @param colOff Column offset to parent storage.
-     * @param rows Amount of rows in the view.
-     * @param cols Amount of columns in the view.
-     */
-    public MatrixView(MatrixStorage sto, int rowOff, int colOff, int rows, int cols) {
-        super(new MatrixDelegateStorage(sto, rowOff, colOff, rows, cols));
-    }
-
-    /**
-     *
-     *
-     */
-    private MatrixDelegateStorage storage() {
-        return (MatrixDelegateStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        MatrixDelegateStorage sto = storage();
-
-        return new MatrixView(sto.delegate(), sto.rowOffset(), sto.columnOffset(), sto.rowSize(), sto.columnSize());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/PivotedMatrixView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/PivotedMatrixView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/PivotedMatrixView.java
deleted file mode 100644
index 1f7b008..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/PivotedMatrixView.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.storage.matrix.PivotedMatrixStorage;
-import org.apache.ignite.math.impls.vector.PivotedVectorView;
-
-/**
- * Pivoted (index mapped) view over another matrix implementation.
- */
-public class PivotedMatrixView extends AbstractMatrix {
-    /** Pivoted matrix. */
-    private Matrix mtx;
-
-    /**
-     *
-     */
-    public PivotedMatrixView() {
-        // No-op.
-    }
-
-    /**
-     * @param mtx
-     * @param rowPivot
-     * @param colPivot
-     */
-    public PivotedMatrixView(Matrix mtx, int[] rowPivot, int[] colPivot) {
-        super(new PivotedMatrixStorage(mtx == null ? null : mtx.getStorage(), rowPivot, colPivot));
-
-        this.mtx = mtx;
-    }
-
-    /**
-     * @param mtx
-     */
-    public PivotedMatrixView(Matrix mtx) {
-        super(new PivotedMatrixStorage(mtx == null ? null : mtx.getStorage()));
-
-        this.mtx = mtx;
-    }
-
-    /**
-     * @param mtx
-     * @param pivot
-     */
-    public PivotedMatrixView(Matrix mtx, int[] pivot) {
-        super(new PivotedMatrixStorage(mtx == null ? null : mtx.getStorage(), pivot));
-
-        this.mtx = mtx;
-    }
-
-    /**
-     * Swaps indexes {@code i} and {@code j} for both both row and column.
-     *
-     * @param i First index to swap.
-     * @param j Second index to swap.
-     */
-    public Matrix swap(int i, int j) {
-        swapRows(i, j);
-        swapColumns(i, j);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix swapRows(int i, int j) {
-        if (i < 0 || i >= storage().rowPivot().length)
-            throw new IndexException(i);
-        if (j < 0 || j >= storage().rowPivot().length)
-            throw new IndexException(j);
-
-        storage().swapRows(i, j);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix swapColumns(int i, int j) {
-        if (i < 0 || i >= storage().columnPivot().length)
-            throw new IndexException(i);
-        if (j < 0 || j >= storage().columnPivot().length)
-            throw new IndexException(j);
-
-        storage().swapColumns(i, j);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewRow(int row) {
-        return new PivotedVectorView(
-            mtx.viewRow(storage().rowPivot()[row]),
-            storage().columnPivot(),
-            storage().columnUnpivot()
-        );
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewColumn(int col) {
-        return new PivotedVectorView(
-            mtx.viewColumn(storage().columnPivot()[col]),
-            storage().rowPivot(),
-            storage().rowUnpivot()
-        );
-    }
-
-    /**
-     *
-     *
-     */
-    public Matrix getBaseMatrix() {
-        return mtx;
-    }
-
-    /**
-     *
-     *
-     */
-    public int[] rowPivot() {
-        return storage().rowPivot();
-    }
-
-    /**
-     *
-     *
-     */
-    public int[] columnPivot() {
-        return storage().columnPivot();
-    }
-
-    /**
-     * @param i
-     */
-    public int rowPivot(int i) {
-        return storage().rowPivot()[i];
-    }
-
-    /**
-     * @param i
-     */
-    public int columnPivot(int i) {
-        return storage().columnPivot()[i];
-    }
-
-    /**
-     * @param i
-     */
-    public int rowUnpivot(int i) {
-        return storage().rowUnpivot()[i];
-    }
-
-    /**
-     * @param i
-     */
-    public int columnUnpivot(int i) {
-        return storage().columnUnpivot()[i];
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        super.writeExternal(out);
-
-        out.writeObject(mtx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        super.readExternal(in);
-
-        mtx = (Matrix)in.readObject();
-    }
-
-    /**
-     *
-     *
-     */
-    private PivotedMatrixStorage storage() {
-        return (PivotedMatrixStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        return new PivotedMatrixView(mtx, storage().rowPivot(), storage().columnPivot());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + mtx.hashCode();
-        res = res * 37 + getStorage().hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        PivotedMatrixView that = (PivotedMatrixView)o;
-
-        MatrixStorage sto = storage();
-
-        return mtx.equals(that.mtx) && sto.equals(that.storage());
-    }
-}


[02/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/RandomVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/RandomVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/RandomVectorConstructorTest.java
new file mode 100644
index 0000000..49e1a50
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/RandomVectorConstructorTest.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class RandomVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapInvalidArgsTest() {
+        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
+            new RandomVector(new HashMap<String, Object>() {{
+                put("invalid", 99);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapMissingArgsTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("paramMissing", "whatever");
+        }};
+
+        assertEquals("Expect exception due to missing args.",
+            -1, new RandomVector(test).size());
+    }
+
+    /** */
+    @Test(expected = ClassCastException.class)
+    public void mapInvalidParamTypeTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("size", "whatever");
+            put("fastHash", true);
+        }};
+
+        assertEquals("Expect exception due to invalid param type.", IMPOSSIBLE_SIZE,
+            new RandomVector(test).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void mapNullTest() {
+        //noinspection ConstantConditions
+        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
+            new RandomVector(null).size());
+    }
+
+    /** */
+    @Test
+    public void mapTest() {
+        assertEquals("Size from args.", 99,
+            new RandomVector(new HashMap<String, Object>() {{
+                put("size", 99);
+            }}).size());
+
+        final int test = 99;
+
+        assertEquals("Size from args with fastHash false.", test,
+            new RandomVector(new HashMap<String, Object>() {{
+                put("size", test);
+                put("fastHash", false);
+            }}).size());
+
+        assertEquals("Size from args with fastHash true.", test,
+            new RandomVector(new HashMap<String, Object>() {{
+                put("size", test);
+                put("fastHash", true);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new RandomVector(-1).size());
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        final int basicSize = 3;
+
+        Vector v1 = new RandomVector(basicSize);
+
+        //noinspection EqualsWithItself
+        assertTrue("Expect vector to be equal to self", v1.equals(v1));
+
+        //noinspection ObjectEqualsNull
+        assertFalse("Expect vector to be not equal to null", v1.equals(null));
+
+        assertEquals("Size differs from expected", basicSize, v1.size());
+
+        verifyValues(v1);
+
+        Vector v2 = new RandomVector(basicSize, true);
+
+        assertEquals("Size differs from expected", basicSize, v2.size());
+
+        verifyValues(v2);
+
+        Vector v3 = new RandomVector(basicSize, false);
+
+        assertEquals("Size differs from expected", basicSize, v3.size());
+
+        verifyValues(v3);
+    }
+
+    /** */
+    private void verifyValues(Vector v) {
+        for (Vector.Element e : v.all()) {
+            double val = e.get();
+
+            assertTrue("Value too small: " + val + " at index " + e.index(), -1d <= val);
+
+            assertTrue("Value too large: " + val + " at index " + e.index(), val <= 1d);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorConstructorTest.java
new file mode 100644
index 0000000..db4d5de
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorConstructorTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class SingleElementVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapInvalidArgsTest() {
+        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
+            new SingleElementVector(new HashMap<String, Object>() {{
+                put("invalid", 99);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void mapMissingArgsTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("size", 1);
+
+            put("paramMissing", "whatever");
+        }};
+
+        assertEquals("Expect exception due to missing args.",
+            -1, new SingleElementVector(test).size());
+    }
+
+    /** */
+    @Test(expected = ClassCastException.class)
+    public void mapInvalidParamTypeTest() {
+        final Map<String, Object> test = new HashMap<String, Object>() {{
+            put("size", "whatever");
+
+            put("index", 0);
+            put("value", 1.0);
+        }};
+
+        assertEquals("Expect exception due to invalid param type.", IMPOSSIBLE_SIZE,
+            new SingleElementVector(test).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void mapNullTest() {
+        //noinspection ConstantConditions
+        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
+            new SingleElementVector(null).size());
+    }
+
+    /** */
+    @Test
+    public void mapTest() {
+        assertEquals("Size from array in args.", 99,
+            new SingleElementVector(new HashMap<String, Object>() {{
+                put("size", 99);
+                put("index", 0);
+                put("value", 1.0);
+            }}).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new SingleElementVector(-1, 0, 1.0).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void zeroSizeTest() {
+        assertEquals("Zero size.", IMPOSSIBLE_SIZE,
+            new SingleElementVector(0, 0, 1.0).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void wrongIndexTest() {
+        //noinspection ConstantConditions
+        assertEquals("Wrong index.", IMPOSSIBLE_SIZE,
+            new SingleElementVector(1, 2, 1.0).size());
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        final int[] sizes = new int[] {1, 4, 8};
+
+        for (int size : sizes)
+            for (int idx = 0; idx < size; idx++)
+                basicTest(size, idx);
+    }
+
+    /** */
+    private void basicTest(int size, int idx) {
+        final Double expVal = (double)(size - idx);
+
+        Vector v = new SingleElementVector(size, idx, expVal);
+
+        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
+            expVal.equals(v.get(idx)));
+
+        final double delta = 1.0;
+
+        v.set(idx, expVal - delta);
+
+        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
+            expVal.equals(v.get(idx) + delta));
+
+        final Double zero = 0.0;
+
+        for (int i = 0; i < size; i++) {
+            if (i == idx)
+                continue;
+
+            assertTrue("Expect zero at index " + i + " for size " + size,
+                zero.equals(v.get(i)));
+
+            boolean eCaught = false;
+
+            try {
+                v.set(i, 1.0);
+            }
+            catch (UnsupportedOperationException uoe) {
+                eCaught = true;
+            }
+
+            assertTrue("Expect " + java.lang.UnsupportedOperationException.class.getSimpleName()
+                + " at index " + i + " for size " + size, eCaught);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorViewConstructorTest.java
new file mode 100644
index 0000000..a693319
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorViewConstructorTest.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class SingleElementVectorViewConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    private static final SampleHelper helper = new SampleHelper();
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullVecParamTest() {
+        assertEquals("Expect exception due to null vector param.", IMPOSSIBLE_SIZE,
+            new SingleElementVectorView(null, helper.idx).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeIdxParamTest() {
+        assertEquals("Expect exception due to negative index param.", IMPOSSIBLE_SIZE,
+            new SingleElementVectorView(helper.vec, -1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void tooLargeIdxParamTest() {
+        assertEquals("Expect exception due to too large index param.", IMPOSSIBLE_SIZE,
+            new SingleElementVectorView(helper.vec, helper.vec.size()).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void emptyVecParamTest() {
+        assertEquals("Expect exception due to empty vector param.", IMPOSSIBLE_SIZE,
+            new SingleElementVectorView(helper.vecEmpty, 0).size());
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        final int[] sizes = new int[] {1, 4, 8};
+
+        for (int size : sizes)
+            for (int idx = 0; idx < size; idx++)
+                basicTest(size, idx);
+    }
+
+    /** */
+    private void basicTest(int size, int idx) {
+        final Double expVal = (double)(size - idx);
+
+        Vector orig = helper.newSample(size, idx, expVal);
+
+        SingleElementVectorView svv = new SingleElementVectorView(orig, idx);
+
+        assertEquals("Size differs from expected", size, svv.size());
+
+        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
+            expVal.equals(svv.get(idx)));
+
+        final double delta = 1.0;
+
+        svv.set(idx, expVal - delta);
+
+        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
+            expVal.equals(orig.get(idx) + delta));
+
+        final Double zero = 0.0;
+
+        for (int i = 0; i < size; i++) {
+            if (i == idx)
+                continue;
+
+            assertTrue("Expect zero at index " + i + " for size " + size,
+                zero.equals(svv.get(i)));
+
+            boolean eCaught = false;
+
+            try {
+                svv.set(i, 1.0);
+            }
+            catch (UnsupportedOperationException uoe) {
+                eCaught = true;
+            }
+
+            assertTrue("Expect " + UnsupportedOperationException.class.getSimpleName()
+                + " at index " + i + " for size " + size, eCaught);
+        }
+    }
+
+    /** */
+    private static class SampleHelper {
+        /** */
+        final double[] data = new double[] {0, 1};
+        /** */
+        final Vector vec = new DenseLocalOnHeapVector(data);
+        /** */
+        final Vector vecEmpty = new DenseLocalOnHeapVector(new double[] {});
+        /** */
+        final int idx = 0;
+
+        /** */
+        Vector newSample(int size, int idx, double expVal) {
+            final Vector v = new DenseLocalOnHeapVector(size);
+
+            for (int i = 0; i < size; i++)
+                v.set(i, i == idx ? expVal : i);
+
+            return v;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVectorConstructorTest.java
new file mode 100644
index 0000000..912168e
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVectorConstructorTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.StorageConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class SparseLocalVectorConstructorTest {
+    /** */
+    private static final int IMPOSSIBLE_SIZE = -1;
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void negativeSizeTest() {
+        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
+            new SparseLocalVector(-1, 1).size());
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void zeroSizeTest() {
+        assertEquals("0 size.", IMPOSSIBLE_SIZE,
+            new SparseLocalVector(0, 1).size());
+    }
+
+    /** */
+    @Test
+    public void primitiveTest() {
+        assertEquals("1 size, random access.", 1,
+            new SparseLocalVector(1, StorageConstants.RANDOM_ACCESS_MODE).size());
+
+        assertEquals("1 size, sequential access.", 1,
+            new SparseLocalVector(1, StorageConstants.SEQUENTIAL_ACCESS_MODE).size());
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorAttributesTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorAttributesTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorAttributesTest.java
new file mode 100644
index 0000000..e2f6a40
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorAttributesTest.java
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class VectorAttributesTest {
+    /** */
+    private final List<AttrCfg> attrCfgs = Arrays.asList(
+        new AttrCfg("isDense", Vector::isDense,
+            DenseLocalOnHeapVector.class, DenseLocalOffHeapVector.class, RandomVector.class, ConstantVector.class,
+            SingleElementVector.class),
+        new AttrCfg("isArrayBased", Vector::isArrayBased,
+            DenseLocalOnHeapVector.class),
+        new AttrCfg("isSequentialAccess", Vector::isSequentialAccess,
+            DenseLocalOnHeapVector.class, DenseLocalOffHeapVector.class, SparseLocalVectorSequentialAccess.class,
+            RandomVector.class, ConstantVector.class, SingleElementVector.class),
+        new AttrCfg("guidNotNull", v -> v.guid() == null), // IMPL NOTE this is somewhat artificial
+        new AttrCfg("isRandomAccess", Vector::isRandomAccess,
+            DenseLocalOnHeapVector.class, DenseLocalOffHeapVector.class, RandomVector.class, ConstantVector.class,
+            SingleElementVector.class, SparseLocalVectorSequentialAccess.class, SparseLocalVectorRandomAccess.class),
+        new AttrCfg("isDistributed", Vector::isDistributed));
+
+    /** */
+    private final List<Specification> specFixture = Arrays.asList(
+        new Specification(new DenseLocalOnHeapVector(1)),
+        new Specification(new DenseLocalOffHeapVector(1)),
+        new Specification(new DelegatingVector(new DenseLocalOnHeapVector(1)),
+            DenseLocalOnHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
+            "isRandomAccess", "isDistributed"),
+        new Specification(new DelegatingVector(new DenseLocalOffHeapVector(1)),
+            DenseLocalOffHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
+            "isRandomAccess", "isDistributed"),
+        new Specification(new SparseLocalVectorSequentialAccess(1)),
+        new Specification(new SparseLocalVectorRandomAccess(1)),
+        new Specification(new RandomVector(1)),
+        new Specification(new ConstantVector(1, 1.0)),
+        new Specification(new FunctionVector(1, idx -> (double)idx)),
+        new Specification(new SingleElementVector(1, 0, 1.0)),
+        new Specification(new PivotedVectorView(new DenseLocalOnHeapVector(1), new int[] {0}),
+            DenseLocalOnHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
+            "isRandomAccess", "isDistributed"),
+        new Specification(new PivotedVectorView(new DenseLocalOffHeapVector(1), new int[] {0}),
+            DenseLocalOffHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
+            "isRandomAccess", "isDistributed"),
+        new Specification(new SingleElementVectorView(new DenseLocalOnHeapVector(1), 0),
+            DenseLocalOnHeapVector.class, "isDense", "isSequentialAccess",
+            "isRandomAccess", "isDistributed"),
+        new Specification(new SingleElementVectorView(new DenseLocalOffHeapVector(1), 0),
+            DenseLocalOffHeapVector.class, "isDense", "isSequentialAccess",
+            "isRandomAccess", "isDistributed"),
+        new Specification(new MatrixVectorView(new DenseLocalOnHeapMatrix(1, 1), 0, 0, 1, 1),
+            DenseLocalOnHeapVector.class, "isDense",
+            "isRandomAccess", "isDistributed"), // todo find out why "isSequentialAccess" fails here
+        new Specification(new MatrixVectorView(new DenseLocalOffHeapMatrix(1, 1), 0, 0, 1, 1),
+            DenseLocalOffHeapVector.class, "isDense",
+            "isRandomAccess", "isDistributed"));
+
+    /** */
+    @Test
+    public void isDenseTest() {
+        assertAttribute("isDense");
+    }
+
+    /** */
+    @Test
+    public void isArrayBasedTest() {
+        assertAttribute("isArrayBased");
+    }
+
+    /** */
+    @Test
+    public void isSequentialAccessTest() {
+        assertAttribute("isSequentialAccess");
+    }
+
+    /** */
+    @Test
+    public void guidTest() {
+        assertAttribute("guidNotNull");
+    }
+
+    /** */
+    @Test
+    public void isRandomAccessTest() {
+        assertAttribute("isRandomAccess");
+    }
+
+    /** */
+    @Test
+    public void isDistributedTest() {
+        assertAttribute("isDistributed");
+    }
+
+    /** */
+    private void assertAttribute(String name) {
+        final AttrCfg attr = attrCfg(name);
+
+        for (Specification spec : specFixture)
+            spec.verify(attr);
+    }
+
+    /** */
+    private AttrCfg attrCfg(String name) {
+        for (AttrCfg attr : attrCfgs)
+            if (attr.name.equals(name))
+                return attr;
+
+        throw new IllegalArgumentException("Undefined attribute " + name);
+    }
+
+    /** See http://en.wikipedia.org/wiki/Specification_pattern */
+    private static class Specification {
+        /** */
+        private final Vector v;
+        /** */
+        private final Class<? extends Vector> underlyingType;
+        /** */
+        private final List<String> attrsFromUnderlying;
+        /** */
+        final String desc;
+
+        /** */
+        Specification(Vector v, Class<? extends Vector> underlyingType, String... attrsFromUnderlying) {
+            this.v = v;
+            this.underlyingType = underlyingType;
+            this.attrsFromUnderlying = Arrays.asList(attrsFromUnderlying);
+            final Class<? extends Vector> clazz = v.getClass();
+            desc = clazz.getSimpleName() + (clazz.equals(underlyingType)
+                ? "" : " (underlying type " + underlyingType.getSimpleName() + ")");
+        }
+
+        /** */
+        Specification(Vector v) {
+            this(v, v.getClass());
+        }
+
+        /** */
+        void verify(AttrCfg attr) {
+            final boolean obtained = attr.obtain.apply(v);
+
+            final Class<? extends Vector> typeToCheck
+                = attrsFromUnderlying.contains(attr.name) ? underlyingType : v.getClass();
+
+            final boolean exp = attr.trueInTypes.contains(typeToCheck);
+
+            assertEquals("Unexpected " + attr.name + " value for " + desc, exp, obtained);
+        }
+    }
+
+    /** */
+    private static class AttrCfg {
+        /** */
+        final String name;
+        /** */
+        final Function<Vector, Boolean> obtain;
+        /** */
+        final List<Class> trueInTypes;
+
+        /** */
+        AttrCfg(String name, Function<Vector, Boolean> obtain, Class... trueInTypes) {
+            this.name = name;
+            this.obtain = obtain;
+            this.trueInTypes = Arrays.asList(trueInTypes);
+        }
+    }
+
+    /** */
+    private static class SparseLocalVectorSequentialAccess extends SparseLocalVector {
+        /** */
+        public SparseLocalVectorSequentialAccess() {
+            // No-op.
+        }
+
+        /** */
+        SparseLocalVectorSequentialAccess(int size) {
+            super(size, SEQUENTIAL_ACCESS_MODE);
+        }
+    }
+
+    /** */
+    private static class SparseLocalVectorRandomAccess extends SparseLocalVector {
+        /** */
+        public SparseLocalVectorRandomAccess() {
+            // No-op.
+        }
+
+        /** */
+        SparseLocalVectorRandomAccess(int size) {
+            super(size, RANDOM_ACCESS_MODE);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorFoldMapTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorFoldMapTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorFoldMapTest.java
new file mode 100644
index 0000000..676bb17
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorFoldMapTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Arrays;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.junit.Test;
+
+import static java.util.function.DoubleUnaryOperator.identity;
+import static org.junit.Assert.assertTrue;
+
+/** See also: {@link AbstractVectorTest} and {@link VectorToMatrixTest}. */
+public class VectorFoldMapTest {
+    /** */
+    @Test
+    public void mapVectorTest() {
+        operationVectorTest((operand1, operand2) -> operand1 + operand2, (Vector v1, Vector v2) -> v1.map(v2, Functions.PLUS));
+    }
+
+    /** */
+    @Test
+    public void mapDoubleFunctionTest() {
+        consumeSampleVectors((v, desc) -> operatorTest(v, desc,
+            (vec) -> vec.map(Functions.INV), (val) -> 1.0 / val));
+    }
+
+    /** */
+    @Test
+    public void mapBiFunctionTest() {
+        consumeSampleVectors((v, desc) -> operatorTest(v, desc,
+            (vec) -> vec.map(Functions.PLUS, 1.0), (val) -> 1.0 + val));
+    }
+
+    /** */
+    @Test
+    public void foldMapTest() {
+        toDoubleTest(
+            ref -> Arrays.stream(ref).map(identity()).sum(),
+            (v) -> v.foldMap(Functions.PLUS, Functions.IDENTITY, 0.0));
+    }
+
+    /** */
+    @Test
+    public void foldMapVectorTest() {
+        toDoubleTest(
+            ref -> 2.0 * Arrays.stream(ref).sum(),
+            (v) -> v.foldMap(v, Functions.PLUS, Functions.PLUS, 0.0));
+
+    }
+
+    /** */
+    private void operatorTest(Vector v, String desc, Function<Vector, Vector> op, Function<Double, Double> refOp) {
+        final int size = v.size();
+        final double[] ref = new double[size];
+
+        VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
+
+        Vector actual = op.apply(v);
+
+        for (int idx = 0; idx < size; idx++)
+            ref[idx] = refOp.apply(ref[idx]);
+
+        checker.assertCloseEnough(actual, ref);
+    }
+
+    /** */
+    private void toDoubleTest(Function<double[], Double> calcRef, Function<Vector, Double> calcVec) {
+        consumeSampleVectors((v, desc) -> {
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            new VectorImplementationsTest.ElementsChecker(v, ref, desc); // IMPL NOTE this initialises vector and reference array
+
+            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(calcRef.apply(ref), calcVec.apply(v));
+
+            assertTrue("Not close enough at " + desc
+                + ", " + metric, metric.closeEnough());
+        });
+    }
+
+    /** */
+    private void operationVectorTest(BiFunction<Double, Double, Double> operation,
+        BiFunction<Vector, Vector, Vector> vecOperation) {
+        consumeSampleVectors((v, desc) -> {
+            // TODO find out if more elaborate testing scenario is needed or it's okay as is.
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            final VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
+            final Vector operand = v.copy();
+
+            for (int idx = 0; idx < size; idx++)
+                ref[idx] = operation.apply(ref[idx], ref[idx]);
+
+            checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
+        });
+    }
+
+    /** */
+    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
+        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsFixtures.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsFixtures.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsFixtures.java
new file mode 100644
index 0000000..be3bb22
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsFixtures.java
@@ -0,0 +1,655 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.storage.vector.FunctionVectorStorage;
+import org.jetbrains.annotations.NotNull;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/** */
+class VectorImplementationsFixtures {
+    /** */
+    private static final List<Supplier<Iterable<Vector>>> suppliers = Arrays.asList(
+        (Supplier<Iterable<Vector>>)DenseLocalOnHeapVectorFixture::new,
+        (Supplier<Iterable<Vector>>)DenseLocalOffHeapVectorFixture::new,
+        (Supplier<Iterable<Vector>>)SparseLocalVectorFixture::new,
+        (Supplier<Iterable<Vector>>)RandomVectorFixture::new,
+        (Supplier<Iterable<Vector>>)ConstantVectorFixture::new,
+        (Supplier<Iterable<Vector>>)DelegatingVectorFixture::new,
+        (Supplier<Iterable<Vector>>)FunctionVectorFixture::new,
+        (Supplier<Iterable<Vector>>)SingleElementVectorFixture::new,
+        (Supplier<Iterable<Vector>>)PivotedVectorViewFixture::new,
+        (Supplier<Iterable<Vector>>)SingleElementVectorViewFixture::new,
+        (Supplier<Iterable<Vector>>)MatrixVectorViewFixture::new,
+        (Supplier<Iterable<Vector>>)SparseLocalOffHeapVectorFixture::new
+    );
+
+    /** */
+    void consumeSampleVectors(Consumer<Integer> paramsConsumer, BiConsumer<Vector, String> consumer) {
+        for (Supplier<Iterable<Vector>> fixtureSupplier : VectorImplementationsFixtures.suppliers) {
+            final Iterable<Vector> fixture = fixtureSupplier.get();
+
+            for (Vector v : fixture) {
+                if (paramsConsumer != null)
+                    paramsConsumer.accept(v.size());
+
+                consumer.accept(v, fixture.toString());
+            }
+        }
+    }
+
+    /** */
+    void selfTest() {
+        new VectorSizesExtraIterator<>("VectorSizesExtraIterator test",
+            (size, shallowCp) -> new DenseLocalOnHeapVector(new double[size], shallowCp),
+            null, "shallow copy", new Boolean[] {false, true, null}).selfTest();
+
+        new VectorSizesIterator("VectorSizesIterator test", DenseLocalOffHeapVector::new, null).selfTest();
+    }
+
+    /** */
+    private static class DenseLocalOnHeapVectorFixture extends VectorSizesExtraFixture<Boolean> {
+        /** */
+        DenseLocalOnHeapVectorFixture() {
+            super("DenseLocalOnHeapVector",
+                (size, shallowCp) -> new DenseLocalOnHeapVector(new double[size], shallowCp),
+                "shallow copy", new Boolean[] {false, true, null});
+        }
+    }
+
+    /** */
+    private static class DenseLocalOffHeapVectorFixture extends VectorSizesFixture {
+        /** */
+        DenseLocalOffHeapVectorFixture() {
+            super("DenseLocalOffHeapVector", DenseLocalOffHeapVector::new);
+        }
+    }
+
+    /** */
+    private static class SparseLocalVectorFixture extends VectorSizesExtraFixture<Integer> {
+        /** */
+        SparseLocalVectorFixture() {
+            super("SparseLocalVector", SparseLocalVector::new, "access mode",
+                new Integer[] {StorageConstants.SEQUENTIAL_ACCESS_MODE, StorageConstants.RANDOM_ACCESS_MODE, null});
+        }
+    }
+
+    /** */
+    private static class RandomVectorFixture extends VectorSizesFixture {
+        /** */
+        RandomVectorFixture() {
+            super("RandomVector", RandomVector::new);
+        }
+    }
+
+    /** */
+    private static class ConstantVectorFixture extends VectorSizesExtraFixture<Double> {
+        /** */
+        ConstantVectorFixture() {
+            super("ConstantVector", ConstantVector::new,
+                "value", new Double[] {-1.0, 0.0, 0.5, 1.0, 2.0, null});
+        }
+    }
+
+    /** */
+    private static class FunctionVectorFixture extends VectorSizesExtraFixture<Double> {
+        /** */
+        FunctionVectorFixture() {
+            super("FunctionVector",
+                (size, scale) -> new FunctionVectorForTest(new double[size], scale),
+                "scale", new Double[] {0.5, 1.0, 2.0, null});
+        }
+    }
+
+    /** */
+    private static class SingleElementVectorFixture implements Iterable<Vector> {
+        /** */
+        private final Supplier<TwoParamsIterator<Integer, Double>> iter;
+
+        /** */
+        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
+
+        /** */
+        SingleElementVectorFixture() {
+            iter = () -> new TwoParamsIterator<Integer, Double>("SingleElementVector",
+                null, ctxDescrHolder::set,
+                "size", new Integer[] {1, null},
+                "value", new Double[] {-1.0, 0.0, 0.5, 1.0, 2.0, null}) {
+
+                /** {@inheritDoc} */
+                @Override BiFunction<Integer, Double, Vector> ctor() {
+                    return (size, value) -> new SingleElementVector(size, 0, value);
+                }
+            };
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Vector> iterator() {
+            return iter.get();//(
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return ctxDescrHolder.get();
+        }
+    }
+
+    /** */
+    private static class PivotedVectorViewFixture extends VectorSizesFixture {
+        /** */
+        PivotedVectorViewFixture() {
+            super("PivotedVectorView", PivotedVectorViewFixture::pivotedVectorView);
+        }
+
+        /** */
+        private static PivotedVectorView pivotedVectorView(int size) {
+            final DenseLocalOnHeapVector vec = new DenseLocalOnHeapVector(size);
+
+            final int[] pivot = new int[size];
+
+            for (int idx = 0; idx < size; idx++)
+                pivot[idx] = size - 1 - idx;
+
+            PivotedVectorView tmp = new PivotedVectorView(vec, pivot);
+
+            final int[] unpivot = new int[size];
+
+            for (int idx = 0; idx < size; idx++)
+                unpivot[idx] = tmp.unpivot(idx);
+
+            final int[] idxRecovery = new int[size];
+
+            for (int idx = 0; idx < size; idx++)
+                idxRecovery[idx] = idx;
+
+            return new PivotedVectorView(new PivotedVectorView(tmp, unpivot), idxRecovery);
+        }
+    }
+
+    /** */
+    private static class SingleElementVectorViewFixture implements Iterable<Vector> {
+        /** */
+        private final Supplier<TwoParamsIterator<Integer, Double>> iter;
+
+        /** */
+        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
+
+        /** */
+        SingleElementVectorViewFixture() {
+            iter = () -> new TwoParamsIterator<Integer, Double>("SingleElementVectorView",
+                null, ctxDescrHolder::set,
+                "size", new Integer[] {1, null},
+                "value", new Double[] {-1.0, 0.0, 0.5, 1.0, 2.0, null}) {
+
+                /** {@inheritDoc} */
+                @Override BiFunction<Integer, Double, Vector> ctor() {
+                    return (size, value) -> new SingleElementVectorView(new SingleElementVector(size, 0, value), 0);
+                }
+            };
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Vector> iterator() {
+            return iter.get();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return ctxDescrHolder.get();
+        }
+    }
+
+    /** */
+    private static class MatrixVectorViewFixture extends VectorSizesExtraFixture<Integer> {
+        /** */
+        MatrixVectorViewFixture() {
+            super("MatrixVectorView",
+                MatrixVectorViewFixture::newView,
+                "stride kind", new Integer[] {0, 1, 2, null});
+        }
+
+        /** */
+        private static Vector newView(int size, int strideKind) {
+            final Matrix parent = new DenseLocalOnHeapMatrix(size, size);
+
+            return new MatrixVectorView(parent, 0, 0, strideKind != 1 ? 1 : 0, strideKind != 0 ? 1 : 0);
+        }
+    }
+
+    /** */
+    private static class VectorSizesExtraFixture<T> implements Iterable<Vector> {
+        /** */
+        private final Supplier<VectorSizesExtraIterator<T>> iter;
+
+        /** */
+        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
+
+        /** */
+        VectorSizesExtraFixture(String vectorKind, BiFunction<Integer, T, Vector> ctor, String extraParamName,
+            T[] extras) {
+            iter = () -> new VectorSizesExtraIterator<>(vectorKind, ctor, ctxDescrHolder::set, extraParamName, extras);
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Vector> iterator() {
+            return iter.get();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return ctxDescrHolder.get();
+        }
+    }
+
+    /** */
+    private static abstract class VectorSizesFixture implements Iterable<Vector> {
+        /** */
+        private final Supplier<VectorSizesIterator> iter;
+
+        /** */
+        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
+
+        /** */
+        VectorSizesFixture(String vectorKind, Function<Integer, Vector> ctor) {
+            iter = () -> new VectorSizesIterator(vectorKind, ctor, ctxDescrHolder::set);
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Vector> iterator() {
+            return iter.get();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return ctxDescrHolder.get();
+        }
+    }
+
+    /** */
+    private static class VectorSizesExtraIterator<T> extends VectorSizesIterator {
+        /** */
+        private final T[] extras;
+        /** */
+        private int extraIdx = 0;
+        /** */
+        private final BiFunction<Integer, T, Vector> ctor;
+        /** */
+        private final String extraParamName;
+
+        /**
+         * @param vectorKind Descriptive name to use for context logging.
+         * @param ctor Constructor for objects to iterate over.
+         * @param ctxDescrConsumer Context logging consumer.
+         * @param extraParamName Name of extra parameter to iterate over.
+         * @param extras Array of extra parameter values to iterate over.
+         */
+        VectorSizesExtraIterator(String vectorKind, BiFunction<Integer, T, Vector> ctor,
+            Consumer<String> ctxDescrConsumer, String extraParamName, T[] extras) {
+            super(vectorKind, null, ctxDescrConsumer);
+
+            this.ctor = ctor;
+            this.extraParamName = extraParamName;
+            this.extras = extras;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            return super.hasNext() && hasNextExtra(extraIdx);
+        }
+
+        /** {@inheritDoc} */
+        @Override void nextIdx() {
+            assert extras[extraIdx] != null
+                : "Index(es) out of bound at " + VectorSizesExtraIterator.this;
+
+            if (hasNextExtra(extraIdx + 1)) {
+                extraIdx++;
+
+                return;
+            }
+
+            extraIdx = 0;
+
+            super.nextIdx();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return "{" + super.toString() +
+                ", " + extraParamName + "=" + extras[extraIdx] +
+                '}';
+        }
+
+        /** {@inheritDoc} */
+        @Override BiFunction<Integer, Integer, Vector> ctor() {
+            return (size, delta) -> ctor.apply(size + delta, extras[extraIdx]);
+        }
+
+        /** */
+        void selfTest() {
+            final Set<Integer> extraIdxs = new HashSet<>();
+
+            int cnt = 0;
+
+            while (hasNext()) {
+                assertNotNull("Expect not null vector at " + this, next());
+
+                if (extras[extraIdx] != null)
+                    extraIdxs.add(extraIdx);
+
+                cnt++;
+            }
+
+            assertEquals("Extra param tested", extraIdxs.size(), extras.length - 1);
+
+            assertEquals("Combinations tested mismatch.",
+                7 * 3 * (extras.length - 1), cnt);
+        }
+
+        /** */
+        private boolean hasNextExtra(int idx) {
+            return extras[idx] != null;
+        }
+    }
+
+    /** */
+    private static class VectorSizesIterator extends TwoParamsIterator<Integer, Integer> {
+        /** */
+        private final Function<Integer, Vector> ctor;
+
+        /** */
+        VectorSizesIterator(String vectorKind, Function<Integer, Vector> ctor, Consumer<String> ctxDescrConsumer) {
+            super(vectorKind, null, ctxDescrConsumer,
+                "size", new Integer[] {2, 4, 8, 16, 32, 64, 128, null},
+                "size delta", new Integer[] {-1, 0, 1, null});
+
+            this.ctor = ctor;
+        }
+
+        /** {@inheritDoc} */
+        @Override BiFunction<Integer, Integer, Vector> ctor() {
+            return (size, delta) -> ctor.apply(size + delta);
+        }
+    }
+
+    /** */
+    private static class TwoParamsIterator<T, U> implements Iterator<Vector> {
+        /** */
+        private final T params1[];
+
+        /** */
+        private final U params2[];
+
+        /** */
+        private final String vectorKind;
+
+        /** */
+        private final String param1Name;
+
+        /** */
+        private final String param2Name;
+
+        /** */
+        private final BiFunction<T, U, Vector> ctor;
+
+        /** */
+        private final Consumer<String> ctxDescrConsumer;
+
+        /** */
+        private int param1Idx = 0;
+
+        /** */
+        private int param2Idx = 0;
+
+        /** */
+        TwoParamsIterator(String vectorKind, BiFunction<T, U, Vector> ctor,
+            Consumer<String> ctxDescrConsumer, String param1Name, T[] params1, String param2Name, U[] params2) {
+            this.param1Name = param1Name;
+            this.params1 = params1;
+
+            this.param2Name = param2Name;
+            this.params2 = params2;
+
+            this.vectorKind = vectorKind;
+
+            this.ctor = ctor;
+
+            this.ctxDescrConsumer = ctxDescrConsumer;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            return hasNextParam1(param1Idx) && hasNextParam2(param2Idx);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Vector next() {
+            if (!hasNext())
+                throw new NoSuchElementException(TwoParamsIterator.this.toString());
+
+            if (ctxDescrConsumer != null)
+                ctxDescrConsumer.accept(toString());
+
+            Vector res = ctor().apply(params1[param1Idx], params2[param2Idx]);
+
+            nextIdx();
+
+            return res;
+        }
+
+        /** */
+        void selfTest() {
+            final Set<Integer> sizeIdxs = new HashSet<>(), deltaIdxs = new HashSet<>();
+
+            int cnt = 0;
+
+            while (hasNext()) {
+                assertNotNull("Expect not null vector at " + this, next());
+
+                if (params1[param1Idx] != null)
+                    sizeIdxs.add(param1Idx);
+
+                if (params2[param2Idx] != null)
+                    deltaIdxs.add(param2Idx);
+
+                cnt++;
+            }
+
+            assertEquals("Sizes tested mismatch.", sizeIdxs.size(), params1.length - 1);
+
+            assertEquals("Deltas tested", deltaIdxs.size(), params2.length - 1);
+
+            assertEquals("Combinations tested mismatch.",
+                (params1.length - 1) * (params2.length - 1), cnt);
+        }
+
+        /** IMPL NOTE override in subclasses if needed */
+        void nextIdx() {
+            assert params1[param1Idx] != null && params2[param2Idx] != null
+                : "Index(es) out of bound at " + TwoParamsIterator.this;
+
+            if (hasNextParam2(param2Idx + 1)) {
+                param2Idx++;
+
+                return;
+            }
+
+            param2Idx = 0;
+
+            param1Idx++;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return vectorKind + "{" + param1Name + "=" + params1[param1Idx] +
+                ", " + param2Name + "=" + params2[param2Idx] +
+                '}';
+        }
+
+        /** IMPL NOTE override in subclasses if needed */
+        BiFunction<T, U, Vector> ctor() {
+            return ctor;
+        }
+
+        /** */
+        private boolean hasNextParam1(int idx) {
+            return params1[idx] != null;
+        }
+
+        /** */
+        private boolean hasNextParam2(int idx) {
+            return params2[idx] != null;
+        }
+    }
+
+    /** Delegating vector with dense local onheap vector */
+    private static class DelegatingVectorFixture implements Iterable<Vector> {
+
+        /** */
+        private final Supplier<VectorSizesExtraIterator<Boolean>> iter;
+
+        /** */
+        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
+
+        /** */
+        DelegatingVectorFixture() {
+            iter = () -> new VectorSizesExtraIterator<>("DelegatingVector with DenseLocalOnHeapVector",
+                (size, shallowCp) -> new DelegatingVector(new DenseLocalOnHeapVector(new double[size], shallowCp)),
+                ctxDescrHolder::set, "shallow copy", new Boolean[] {false, true, null});
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Vector> iterator() {
+            return iter.get();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
+            return ctxDescrHolder.get();
+        }
+    }
+
+    /** Subclass tweaked for serialization */
+    private static class FunctionVectorForTest extends FunctionVector {
+        /** */
+        double[] arr;
+
+        /** */
+        double scale;
+
+        /** */
+        public FunctionVectorForTest() {
+            // No-op.
+        }
+
+        /** */
+        FunctionVectorForTest(double[] arr, double scale) {
+            super(arr.length, idx -> arr[idx] * scale, (idx, value) -> arr[idx] = value / scale);
+
+            this.arr = arr;
+
+            this.scale = scale;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            super.writeExternal(out);
+
+            out.writeObject(arr);
+
+            out.writeDouble(scale);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            super.readExternal(in);
+
+            arr = (double[])in.readObject();
+
+            scale = in.readDouble();
+
+            setStorage(new FunctionVectorStorage(arr.length, idx -> arr[idx] * scale, (idx, value) -> arr[idx] = value / scale));
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = 1;
+
+            res = res * 37 + Double.hashCode(scale);
+            res = res * 37 + Integer.hashCode(getStorage().size());
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            FunctionVectorForTest that = (FunctionVectorForTest)o;
+
+            return new Double(scale).equals(that.scale)
+                && (arr != null ? Arrays.equals(arr, that.arr) : that.arr == null);
+        }
+    }
+
+    /** */
+    private static class SparseLocalOffHeapVectorFixture extends VectorSizesFixture {
+
+        /** */
+        SparseLocalOffHeapVectorFixture() {
+            super("SparseLocalOffHeapVector", SparseLocalOffHeapVector::new);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsTest.java
new file mode 100644
index 0000000..48dcc36
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/VectorImplementationsTest.java
@@ -0,0 +1,861 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/** See also: {@link AbstractVectorTest} and {@link VectorToMatrixTest}. */
+public class VectorImplementationsTest { // todo split this to smaller cohesive test classes
+    /** */
+    @Test
+    public void vectorImplementationsFixturesTest() {
+        new VectorImplementationsFixtures().selfTest();
+    }
+
+    /** */
+    @Test
+    public void setGetTest() {
+        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
+            vec.set(idx, val);
+
+            return val;
+        }));
+    }
+
+    /** */
+    @Test
+    public void setXTest() {
+        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
+            vec.setX(idx, val);
+
+            return val;
+        }));
+    }
+
+    /** */
+    @Test
+    public void incrementTest() {
+        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
+            double old = vec.get(idx);
+
+            vec.increment(idx, val);
+
+            return old + val;
+        }));
+    }
+
+    /** */
+    @Test
+    public void incrementXTest() {
+        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
+            double old = vec.getX(idx);
+
+            vec.incrementX(idx, val);
+
+            return old + val;
+        }));
+    }
+
+    /** */
+    @Test
+    public void operateXOutOfBoundsTest() {
+        consumeSampleVectors((v, desc) -> {
+            if (v instanceof DenseLocalOffHeapVector || v instanceof SparseLocalVector || v instanceof SparseLocalOffHeapVector)
+                return; // todo find out if it's OK to skip by instances here
+
+            boolean expECaught = false;
+
+            try {
+                v.getX(-1);
+            }
+            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
+                expECaught = true;
+            }
+
+            if (!getXOutOfBoundsOK(v))
+                assertTrue("Expect exception at negative index getX in " + desc, expECaught);
+
+            expECaught = false;
+
+            try {
+                v.setX(-1, 0);
+            }
+            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
+                expECaught = true;
+            }
+
+            assertTrue("Expect exception at negative index setX in " + desc, expECaught);
+
+            expECaught = false;
+
+            try {
+                v.incrementX(-1, 1);
+            }
+            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
+                expECaught = true;
+            }
+
+            assertTrue("Expect exception at negative index incrementX in " + desc, expECaught);
+
+            expECaught = false;
+
+            try {
+                v.getX(v.size());
+            }
+            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
+                expECaught = true;
+            }
+
+            if (!getXOutOfBoundsOK(v))
+                assertTrue("Expect exception at too large index getX in " + desc, expECaught);
+
+            expECaught = false;
+
+            try {
+                v.setX(v.size(), 1);
+            }
+            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
+                expECaught = true;
+            }
+
+            assertTrue("Expect exception at too large index setX in " + desc, expECaught);
+
+            expECaught = false;
+
+            try {
+                v.incrementX(v.size(), 1);
+            }
+            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
+                expECaught = true;
+            }
+
+            assertTrue("Expect exception at too large index incrementX in " + desc, expECaught);
+        });
+    }
+
+    /** */
+    @Test
+    public void sizeTest() {
+        final AtomicReference<Integer> expSize = new AtomicReference<>(0);
+
+        consumeSampleVectors(
+            expSize::set,
+            (v, desc) -> Assert.assertEquals("Expected size for " + desc,
+                (int)expSize.get(), v.size())
+        );
+    }
+
+    /** */
+    @Test
+    public void getElementTest() {
+        consumeSampleVectors((v, desc) -> new ElementsChecker(v, desc).assertCloseEnough(v));
+    }
+
+    /** */
+    @Test
+    public void copyTest() {
+        consumeSampleVectors((v, desc) -> new ElementsChecker(v, desc).assertCloseEnough(v.copy()));
+    }
+
+    /** */
+    @Test
+    public void divideTest() {
+        operationTest((val, operand) -> val / operand, Vector::divide);
+    }
+
+    /** */
+    @Test
+    public void likeTest() {
+        for (int card : new int[] {1, 2, 4, 8, 16, 32, 64, 128})
+            consumeSampleVectors((v, desc) -> {
+                Class<? extends Vector> expType = expLikeType(v);
+
+                if (expType == null) {
+                    try {
+                        v.like(card);
+                    }
+                    catch (UnsupportedOperationException uoe) {
+                        return;
+                    }
+
+                    fail("Expected exception wasn't caught for " + desc);
+
+                    return;
+                }
+
+                Vector vLike = v.like(card);
+
+                assertNotNull("Expect non-null like vector for " + expType.getSimpleName() + " in " + desc, vLike);
+                assertEquals("Expect size equal to cardinality at " + desc, card, vLike.size());
+
+                Class<? extends Vector> actualType = vLike.getClass();
+
+                assertTrue("Actual vector type " + actualType.getSimpleName()
+                        + " should be assignable from expected type " + expType.getSimpleName() + " in " + desc,
+                    actualType.isAssignableFrom(expType));
+            });
+    }
+
+    /** */
+    @Test
+    public void minusTest() {
+        operationVectorTest((operand1, operand2) -> operand1 - operand2, Vector::minus);
+    }
+
+    /** */
+    @Test
+    public void plusVectorTest() {
+        operationVectorTest((operand1, operand2) -> operand1 + operand2, Vector::plus);
+    }
+
+    /** */
+    @Test
+    public void plusDoubleTest() {
+        operationTest((val, operand) -> val + operand, Vector::plus);
+    }
+
+    /** */
+    @Test
+    public void timesVectorTest() {
+        operationVectorTest((operand1, operand2) -> operand1 * operand2, Vector::times);
+    }
+
+    /** */
+    @Test
+    public void timesDoubleTest() {
+        operationTest((val, operand) -> val * operand, Vector::times);
+    }
+
+    /** */
+    @Test
+    public void viewPartTest() {
+        consumeSampleVectors((v, desc) -> {
+            final int size = v.size();
+            final double[] ref = new double[size];
+            final int delta = size > 32 ? 3 : 1; // IMPL NOTE this is for faster test execution
+
+            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
+
+            for (int off = 0; off < size; off += delta)
+                for (int len = 1; len < size - off; len += delta)
+                    checker.assertCloseEnough(v.viewPart(off, len), Arrays.copyOfRange(ref, off, off + len));
+        });
+    }
+
+    /** */
+    @Test
+    public void sumTest() {
+        toDoubleTest(
+            ref -> Arrays.stream(ref).sum(),
+            Vector::sum);
+    }
+
+    /** */
+    @Test
+    public void minValueTest() {
+        toDoubleTest(
+            ref -> Arrays.stream(ref).min().getAsDouble(),
+            Vector::minValue);
+    }
+
+    /** */
+    @Test
+    public void maxValueTest() {
+        toDoubleTest(
+            ref -> Arrays.stream(ref).max().getAsDouble(),
+            Vector::maxValue);
+    }
+
+    /** */
+    @Test
+    public void sortTest() {
+        consumeSampleVectors((v, desc) -> {
+            if (readOnly(v) || !v.isArrayBased()) {
+                boolean expECaught = false;
+
+                try {
+                    v.sort();
+                }
+                catch (UnsupportedOperationException uoe) {
+                    expECaught = true;
+                }
+
+                assertTrue("Expected exception was not caught for sort in " + desc, expECaught);
+
+                return;
+            }
+
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            new ElementsChecker(v, ref, desc).assertCloseEnough(v.sort(), Arrays.stream(ref).sorted().toArray());
+        });
+    }
+
+    /** */
+    @Test
+    public void metaAttributesTest() {
+        consumeSampleVectors((v, desc) -> {
+            assertNotNull("Null meta storage in " + desc, v.getMetaStorage());
+
+            final String key = "test key";
+            final String val = "test value";
+            final String details = "key [" + key + "] for " + desc;
+
+            v.setAttribute(key, val);
+            assertTrue("Expect to have meta attribute for " + details, v.hasAttribute(key));
+            assertEquals("Unexpected meta attribute value for " + details, val, v.getAttribute(key));
+
+            v.removeAttribute(key);
+            assertFalse("Expect not to have meta attribute for " + details, v.hasAttribute(key));
+            assertNull("Unexpected meta attribute value for " + details, v.getAttribute(key));
+        });
+    }
+
+    /** */
+    @Test
+    public void assignDoubleTest() {
+        consumeSampleVectors((v, desc) -> {
+            if (readOnly(v))
+                return;
+
+            for (double val : new double[] {0, -1, 0, 1}) {
+                v.assign(val);
+
+                for (int idx = 0; idx < v.size(); idx++) {
+                    final Metric metric = new Metric(val, v.get(idx));
+
+                    assertTrue("Not close enough at index " + idx + ", val " + val + ", " + metric
+                        + ", " + desc, metric.closeEnough());
+                }
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void assignDoubleArrTest() {
+        consumeSampleVectors((v, desc) -> {
+            if (readOnly(v))
+                return;
+
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
+
+            for (int idx = 0; idx < size; idx++)
+                ref[idx] = -ref[idx];
+
+            v.assign(ref);
+
+            checker.assertCloseEnough(v, ref);
+
+            assignDoubleArrWrongCardinality(v, desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void assignVectorTest() {
+        consumeSampleVectors((v, desc) -> {
+            if (readOnly(v))
+                return;
+
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
+
+            for (int idx = 0; idx < size; idx++)
+                ref[idx] = -ref[idx];
+
+            v.assign(new DenseLocalOnHeapVector(ref));
+
+            checker.assertCloseEnough(v, ref);
+
+            assignVectorWrongCardinality(v, desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void assignFunctionTest() {
+        consumeSampleVectors((v, desc) -> {
+            if (readOnly(v))
+                return;
+
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
+
+            for (int idx = 0; idx < size; idx++)
+                ref[idx] = -ref[idx];
+
+            v.assign((idx) -> ref[idx]);
+
+            checker.assertCloseEnough(v, ref);
+        });
+    }
+
+    /** */
+    @Test
+    public void minElementTest() {
+        consumeSampleVectors((v, desc) -> {
+            final ElementsChecker checker = new ElementsChecker(v, desc);
+
+            final Vector.Element minE = v.minElement();
+
+            final int minEIdx = minE.index();
+
+            assertTrue("Unexpected index from minElement " + minEIdx + ", " + desc,
+                minEIdx >= 0 && minEIdx < v.size());
+
+            final Metric metric = new Metric(minE.get(), v.minValue());
+
+            assertTrue("Not close enough minElement at index " + minEIdx + ", " + metric
+                + ", " + desc, metric.closeEnough());
+
+            checker.assertNewMinElement(v);
+        });
+    }
+
+    /** */
+    @Test
+    public void maxElementTest() {
+        consumeSampleVectors((v, desc) -> {
+            final ElementsChecker checker = new ElementsChecker(v, desc);
+
+            final Vector.Element maxE = v.maxElement();
+
+            final int minEIdx = maxE.index();
+
+            assertTrue("Unexpected index from minElement " + minEIdx + ", " + desc,
+                minEIdx >= 0 && minEIdx < v.size());
+
+            final Metric metric = new Metric(maxE.get(), v.maxValue());
+
+            assertTrue("Not close enough maxElement at index " + minEIdx + ", " + metric
+                + ", " + desc, metric.closeEnough());
+
+            checker.assertNewMaxElement(v);
+        });
+    }
+
+    /** */
+    @Test
+    public void externalizeTest() {
+        (new ExternalizeTest<Vector>() {
+            /** {@inheritDoc} */
+            @Override public void externalizeTest() {
+                consumeSampleVectors((v, desc) -> {
+                    if (v instanceof SparseLocalOffHeapVector)
+                        return; //TODO: wait till SparseLocalOffHeapVector externalization support.
+
+                    externalizeTest(v);
+                });
+            }
+        }).externalizeTest();
+    }
+
+    /** */
+    @Test
+    public void hashCodeTest() {
+        consumeSampleVectors((v, desc) -> assertTrue("Zero hash code for " + desc, v.hashCode() != 0));
+    }
+
+    /** */
+    private boolean getXOutOfBoundsOK(Vector v) {
+        // todo find out if this is indeed OK
+        return v instanceof RandomVector || v instanceof ConstantVector
+            || v instanceof SingleElementVector || v instanceof SingleElementVectorView;
+    }
+
+    /** */
+    private void mutateAtIdxTest(Vector v, String desc, MutateAtIdx operation) {
+        if (readOnly(v)) {
+            if (v.size() < 1)
+                return;
+
+            boolean expECaught = false;
+
+            try {
+                operation.apply(v, 0, 1);
+            }
+            catch (UnsupportedOperationException uoe) {
+                expECaught = true;
+            }
+
+            assertTrue("Expect exception at attempt to mutate element in " + desc, expECaught);
+
+            return;
+        }
+
+        for (double val : new double[] {0, -1, 0, 1})
+            for (int idx = 0; idx < v.size(); idx++) {
+                double exp = operation.apply(v, idx, val);
+
+                final Metric metric = new Metric(exp, v.get(idx));
+
+                assertTrue("Not close enough at index " + idx + ", val " + val + ", " + metric
+                    + ", " + desc, metric.closeEnough());
+            }
+    }
+
+    /** */
+    private Class<? extends Vector> expLikeType(Vector v) {
+        Class<? extends Vector> clazz = v.getClass();
+
+        if (clazz.isAssignableFrom(PivotedVectorView.class) || clazz.isAssignableFrom(SingleElementVectorView.class))
+            return null;
+
+        if (clazz.isAssignableFrom(MatrixVectorView.class) || clazz.isAssignableFrom(DelegatingVector.class))
+            return DenseLocalOnHeapVector.class; // IMPL NOTE per fixture
+
+        return clazz;
+    }
+
+    /** */
+    private void toDoubleTest(Function<double[], Double> calcRef, Function<Vector, Double> calcVec) {
+        consumeSampleVectors((v, desc) -> {
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            new ElementsChecker(v, ref, desc); // IMPL NOTE this initialises vector and reference array
+
+            final Metric metric = new Metric(calcRef.apply(ref), calcVec.apply(v));
+
+            assertTrue("Not close enough at " + desc
+                + ", " + metric, metric.closeEnough());
+        });
+    }
+
+    /** */
+    private void operationVectorTest(BiFunction<Double, Double, Double> operation,
+        BiFunction<Vector, Vector, Vector> vecOperation) {
+        consumeSampleVectors((v, desc) -> {
+            // TODO find out if more elaborate testing scenario is needed or it's okay as is.
+            final int size = v.size();
+            final double[] ref = new double[size];
+
+            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
+            final Vector operand = v.copy();
+
+            for (int idx = 0; idx < size; idx++)
+                ref[idx] = operation.apply(ref[idx], ref[idx]);
+
+            checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
+
+            assertWrongCardinality(v, desc, vecOperation);
+        });
+    }
+
+    /** */
+    private void assignDoubleArrWrongCardinality(Vector v, String desc) {
+        boolean expECaught = false;
+
+        try {
+            v.assign(new double[v.size() + 1]);
+        }
+        catch (CardinalityException ce) {
+            expECaught = true;
+        }
+
+        assertTrue("Expect exception at too large size in " + desc, expECaught);
+
+        if (v.size() < 2)
+            return;
+
+        expECaught = false;
+
+        try {
+            v.assign(new double[v.size() - 1]);
+        }
+        catch (CardinalityException ce) {
+            expECaught = true;
+        }
+
+        assertTrue("Expect exception at too small size in " + desc, expECaught);
+    }
+
+    /** */
+    private void assignVectorWrongCardinality(Vector v, String desc) {
+        boolean expECaught = false;
+
+        try {
+            v.assign(new DenseLocalOnHeapVector(v.size() + 1));
+        }
+        catch (CardinalityException ce) {
+            expECaught = true;
+        }
+
+        assertTrue("Expect exception at too large size in " + desc, expECaught);
+
+        if (v.size() < 2)
+            return;
+
+        expECaught = false;
+
+        try {
+            v.assign(new DenseLocalOnHeapVector(v.size() - 1));
+        }
+        catch (CardinalityException ce) {
+            expECaught = true;
+        }
+
+        assertTrue("Expect exception at too small size in " + desc, expECaught);
+    }
+
+    /** */
+    private void assertWrongCardinality(
+        Vector v, String desc, BiFunction<Vector, Vector, Vector> vecOperation) {
+        boolean expECaught = false;
+
+        try {
+            vecOperation.apply(v, new DenseLocalOnHeapVector(v.size() + 1));
+        }
+        catch (CardinalityException ce) {
+            expECaught = true;
+        }
+
+        assertTrue("Expect exception at too large size in " + desc, expECaught);
+
+        if (v.size() < 2)
+            return;
+
+        expECaught = false;
+
+        try {
+            vecOperation.apply(v, new DenseLocalOnHeapVector(v.size() - 1));
+        }
+        catch (CardinalityException ce) {
+            expECaught = true;
+        }
+
+        assertTrue("Expect exception at too small size in " + desc, expECaught);
+    }
+
+    /** */
+    private void operationTest(BiFunction<Double, Double, Double> operation,
+        BiFunction<Vector, Double, Vector> vecOperation) {
+        for (double val : new double[] {0, 0.1, 1, 2, 10})
+            consumeSampleVectors((v, desc) -> {
+                final int size = v.size();
+                final double[] ref = new double[size];
+
+                final ElementsChecker checker = new ElementsChecker(v, ref, "val " + val + ", " + desc);
+
+                for (int idx = 0; idx < size; idx++)
+                    ref[idx] = operation.apply(ref[idx], val);
+
+                checker.assertCloseEnough(vecOperation.apply(v, val), ref);
+            });
+    }
+
+    /** */
+    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
+        consumeSampleVectors(null, consumer);
+    }
+
+    /** */
+    private void consumeSampleVectors(Consumer<Integer> paramsConsumer, BiConsumer<Vector, String> consumer) {
+        new VectorImplementationsFixtures().consumeSampleVectors(paramsConsumer, consumer);
+    }
+
+    /** */
+    private static boolean readOnly(Vector v) {
+        return v instanceof RandomVector || v instanceof ConstantVector;
+    }
+
+    /** */
+    private interface MutateAtIdx {
+        /** */
+        double apply(Vector v, int idx, double val);
+    }
+
+    /** */
+    static class ElementsChecker {
+        /** */
+        private final String fixtureDesc;
+
+        /** */
+        private final double[] refReadOnly;
+
+        /** */
+        private final boolean nonNegative;
+
+        /** */
+        ElementsChecker(Vector v, double[] ref, String fixtureDesc, boolean nonNegative) {
+            this.fixtureDesc = fixtureDesc;
+
+            this.nonNegative = nonNegative;
+
+            refReadOnly = readOnly(v) && ref == null ? new double[v.size()] : null;
+
+            init(v, ref);
+        }
+
+        /** */
+        ElementsChecker(Vector v, double[] ref, String fixtureDesc) {
+            this(v, ref, fixtureDesc, false);
+        }
+
+        /** */
+        ElementsChecker(Vector v, String fixtureDesc) {
+            this(v, null, fixtureDesc);
+        }
+
+        /** */
+        void assertCloseEnough(Vector obtained, double[] exp) {
+            final int size = obtained.size();
+
+            for (int i = 0; i < size; i++) {
+                final Vector.Element e = obtained.getElement(i);
+
+                if (refReadOnly != null && exp == null)
+                    exp = refReadOnly;
+
+                final Metric metric = new Metric(exp == null ? generated(i) : exp[i], e.get());
+
+                assertEquals("Unexpected vector index at " + fixtureDesc, i, e.index());
+                assertTrue("Not close enough at index " + i + ", size " + size + ", " + metric
+                    + ", " + fixtureDesc, metric.closeEnough());
+            }
+        }
+
+        /** */
+        void assertCloseEnough(Vector obtained) {
+            assertCloseEnough(obtained, null);
+        }
+
+        /** */
+        void assertNewMinElement(Vector v) {
+            if (readOnly(v))
+                return;
+
+            int exp = v.size() / 2;
+
+            v.set(exp, -(v.size() * 2 + 1));
+
+            assertEquals("Unexpected minElement index at " + fixtureDesc, exp, v.minElement().index());
+        }
+
+        /** */
+        void assertNewMaxElement(Vector v) {
+            if (readOnly(v))
+                return;
+
+            int exp = v.size() / 2;
+
+            v.set(exp, v.size() * 2 + 1);
+
+            assertEquals("Unexpected minElement index at " + fixtureDesc, exp, v.maxElement().index());
+        }
+
+        /** */
+        private void init(Vector v, double[] ref) {
+            if (readOnly(v)) {
+                initReadonly(v, ref);
+
+                return;
+            }
+
+            for (Vector.Element e : v.all()) {
+                int idx = e.index();
+
+                // IMPL NOTE introduce negative values because their absence
+                //    blocked catching an ugly bug in AbstractVector#kNorm
+                int val = generated(idx);
+
+                e.set(val);
+
+                if (ref != null)
+                    ref[idx] = val;
+            }
+        }
+
+        /** */
+        private void initReadonly(Vector v, double[] ref) {
+            if (refReadOnly != null)
+                for (Vector.Element e : v.all())
+                    refReadOnly[e.index()] = e.get();
+
+            if (ref != null)
+                for (Vector.Element e : v.all())
+                    ref[e.index()] = e.get();
+        }
+
+        /** */
+        private int generated(int idx) {
+            return nonNegative || (idx & 1) == 0 ? idx : -idx;
+        }
+    }
+
+    /** */
+    static class Metric { // todo consider if softer tolerance (like say 0.1 or 0.01) would make sense here
+        /** */
+        private final double exp;
+
+        /** */
+        private final double obtained;
+
+        /** **/
+        Metric(double exp, double obtained) {
+            this.exp = exp;
+            this.obtained = obtained;
+        }
+
+        /** */
+        boolean closeEnough() {
+            return new Double(exp).equals(obtained) || closeEnoughToZero();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Metric{" + "expected=" + exp +
+                ", obtained=" + obtained +
+                '}';
+        }
+
+        /** */
+        private boolean closeEnoughToZero() {
+            return (new Double(exp).equals(0.0) && new Double(obtained).equals(-0.0))
+                || (new Double(exp).equals(-0.0) && new Double(obtained).equals(0.0));
+        }
+    }
+}


[38/50] [abbrv] ignite git commit: master - Mute test with a correct link

Posted by sb...@apache.org.
master - Mute test with a correct link


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

Branch: refs/heads/ignite-1561
Commit: 9b21c85d6ec0cdbba8cbf2382559a8ef5a82e15c
Parents: 2edb935
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Tue Apr 18 18:40:27 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Tue Apr 18 18:43:21 2017 +0300

----------------------------------------------------------------------
 .../cache/IgniteCacheJoinPartitionedAndReplicatedTest.java         | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9b21c85d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
index d4772c1..37b21c9 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
@@ -161,6 +161,8 @@ public class IgniteCacheJoinPartitionedAndReplicatedTest extends GridCommonAbstr
      * @throws Exception If failed.
      */
     public void testJoin() throws Exception {
+        fail("https://issues.apache.org/jira/browse/IGNITE-5016");
+
         Ignite client = grid(2);
 
         IgniteCache<Object, Object> personCache = client.cache(PERSON_CACHE);


[46/50] [abbrv] ignite git commit: Fixed service deployment tests.

Posted by sb...@apache.org.
Fixed service deployment tests.


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

Branch: refs/heads/ignite-1561
Commit: 15359bc0b048c1a6a4093ea8998b343374667d43
Parents: b47f29d
Author: Andrey V. Mashenkov <an...@gmail.com>
Authored: Wed Apr 19 06:30:30 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Apr 19 14:03:12 2017 +0300

----------------------------------------------------------------------
 .../GridServiceProcessorAbstractSelfTest.java   |  17 +++
 ...ServiceProcessorMultiNodeConfigSelfTest.java |  40 +++----
 .../GridServiceProcessorMultiNodeSelfTest.java  | 113 ++++++++++---------
 3 files changed, 95 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/15359bc0/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
index b9076b9..fafd24e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
@@ -30,7 +30,9 @@ import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
+import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
 import org.apache.ignite.internal.util.typedef.CA;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.lang.IgniteFuture;
@@ -783,6 +785,21 @@ public abstract class GridServiceProcessorAbstractSelfTest extends GridCommonAbs
     }
 
     /**
+     * @param srvcName Service name
+     * @param expectedDeps Expected number of service deployments
+     *
+     */
+    protected boolean waitForDeployment(final String srvcName, final int expectedDeps) throws IgniteInterruptedCheckedException {
+        final Ignite g = randomGrid();
+
+        return GridTestUtils.waitForCondition(new GridAbsPredicateX() {
+            @Override public boolean applyx() {
+                return actualCount(srvcName, g.services().serviceDescriptors())  == expectedDeps;
+            }
+        }, 1500);
+    }
+
+    /**
      * Counter service.
      */
     protected interface CounterService {

http://git-wip-us.apache.org/repos/asf/ignite/blob/15359bc0/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
index 9da62c0..16e5e30 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
@@ -22,7 +22,6 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
 import org.apache.ignite.services.ServiceConfiguration;
 import org.apache.ignite.testframework.GridTestUtils;
@@ -213,32 +212,20 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
         try {
             latch.await();
 
+            waitForDeployment(name, nodeCount() + 1);
+
             checkCount(name, g.services().serviceDescriptors(), nodeCount() + 1);
         }
         finally {
             stopExtraNodes(extraNodes);
         }
 
-        assertEquals(name, 1, DummyService.cancelled(name));
-
         waitForDeployment(name, nodeCount());
 
-        checkCount(name, g.services().serviceDescriptors(), nodeCount());
-    }
-
-    /**
-     * @param srvcName Service name
-     * @param expectedDeps Expected number of service deployments
-     *
-     */
-    private boolean waitForDeployment(final String srvcName, final int expectedDeps) throws IgniteInterruptedCheckedException {
-        final Ignite g = randomGrid();
+        // Service can be redeployed when nodes is stopping one-by-one.
+        assertEquals(0, DummyService.started(name) - DummyService.cancelled(name));
 
-        return GridTestUtils.waitForCondition(new GridAbsPredicateX() {
-            @Override public boolean applyx() {
-                return actualCount(srvcName, g.services().serviceDescriptors())  == expectedDeps;
-            }
-        }, 1500);
+        checkCount(name, g.services().serviceDescriptors(), nodeCount());
     }
 
     /**
@@ -281,8 +268,12 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
         try {
             latch.await();
 
-            assertEquals(name, newNodes, DummyService.started(name));
-            assertEquals(name, 0, DummyService.cancelled(name));
+            waitForDeployment(name, nodeCount() + newNodes);
+
+            assertEquals(name, newNodes,  DummyService.started(name) - DummyService.cancelled(name));
+// Next may fails. Server can be restarted on unstable topology.
+//            assertEquals(name, newNodes, DummyService.started(name));
+//            assertEquals(name, 0, DummyService.cancelled(name));
 
             checkCount(name, g.services().serviceDescriptors(), nodeCount() + newNodes);
         }
@@ -314,8 +305,13 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
         try {
             latch.await();
 
-            assertEquals(name, servers, DummyService.started(name));
-            assertEquals(name, 0, DummyService.cancelled(name));
+            waitForDeployment(name, nodeCount() + servers);
+
+            assertEquals(name, servers,  DummyService.started(name) - DummyService.cancelled(name));
+// Next may fails. Server can be restarted on unstable topology.
+//            assertEquals(name, servers, DummyService.started(name));
+//            assertEquals(name, 0, DummyService.cancelled(name));
+
 
             checkCount(name, g.services().serviceDescriptors(), nodeCount() + servers);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/15359bc0/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
index 50f5999..32d1462 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
@@ -90,7 +90,7 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
         // Store a cache key.
         g.cache(CACHE_NAME).put(affKey, affKey.toString());
 
-        String name = "serviceAffinityUpdateTopology";
+        final String name = "serviceAffinityUpdateTopology";
 
         IgniteServices svcs = g.services();
 
@@ -125,9 +125,7 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
         Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
 
         try {
-            final int prestartedNodes = nodeCount() + 1;
-
-            String name = "serviceOnEachNodeButClientUpdateTopology";
+            final String name = "serviceOnEachNodeButClientUpdateTopology";
 
             Ignite g = randomGrid();
 
@@ -135,9 +133,9 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
 
             DummyService.exeLatch(name, latch);
 
-        IgniteServices svcs = g.services();
+            IgniteServices svcs = g.services();
 
-        IgniteFuture<?> fut = svcs.deployNodeSingletonAsync(name, new DummyService());
+            IgniteFuture<?> fut = svcs.deployNodeSingletonAsync(name, new DummyService());
 
             info("Deployed service: " + name);
 
@@ -150,8 +148,8 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
             // Ensure service is deployed
             assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
 
-            TestCase.assertEquals(name, nodeCount(), DummyService.started(name));
-            TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+            assertEquals(name, nodeCount(), DummyService.started(name));
+            assertEquals(name, 0, DummyService.cancelled(name));
 
             int servers = 2;
             int clients = 2;
@@ -165,12 +163,13 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
             try {
                 latch.await();
 
-                // Ensure service is deployed
-                assertNotNull(grid(prestartedNodes + servers - 1)
-                    .services().serviceProxy(name, Service.class, false, 2000));
+                waitForDeployment(name, servers);
+
+                assertEquals(name, nodeCount() + servers,  DummyService.started(name) - DummyService.cancelled(name));
 
-                TestCase.assertEquals(name, nodeCount() + servers, DummyService.started(name));
-                TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+//                 Next may fails. Server can be restarted on unstable topology.
+//                assertEquals(name, nodeCount() + servers, DummyService.started(name));
+//                assertEquals(name, 0, DummyService.cancelled(name));
 
                 checkCount(name, g.services().serviceDescriptors(), nodeCount() + servers);
             }
@@ -191,7 +190,7 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
         Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
 
         try {
-            String name = "serviceOnEachNodeUpdateTopology";
+            final String name = "serviceOnEachNodeUpdateTopology";
 
             Ignite g = randomGrid();
 
@@ -223,8 +222,8 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
             // Ensure service is deployed
             assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
 
-            TestCase.assertEquals(name, prestartedNodes, DummyService.started(name));
-            TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+            assertEquals(name, prestartedNodes, DummyService.started(name));
+            assertEquals(name, 0, DummyService.cancelled(name));
 
             int servers = 2;
             int clients = 2;
@@ -240,11 +239,14 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
             try {
                 latch.await();
 
-                // Ensure service is deployed
-                assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
+                waitForDeployment(name, prestartedNodes + extraNodes);
+
+                assertEquals(name, prestartedNodes + extraNodes,
+                    DummyService.started(name) - DummyService.cancelled(name));
 
-                TestCase.assertEquals(name, prestartedNodes + extraNodes, DummyService.started(name));
-                TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+//                 Next may fails. Server can be restarted on unstable topology.
+//                assertEquals(name, prestartedNodes + extraNodes, DummyService.started(name));
+//                assertEquals(name, 0, DummyService.cancelled(name));
 
                 checkCount(name, g.services().serviceDescriptors(), prestartedNodes + extraNodes);
             }
@@ -261,60 +263,65 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
      * @throws Exception If failed.
      */
     public void testDeployLimits() throws Exception {
-            String name = "serviceWithLimitsUpdateTopology";
+        final String name = "serviceWithLimitsUpdateTopology";
 
-            Ignite g = randomGrid();
+        Ignite g = randomGrid();
 
-            final int totalInstances = nodeCount() + 1;
+        final int totalInstances = nodeCount() + 1;
 
-            CountDownLatch latch = new CountDownLatch(nodeCount());
+        CountDownLatch latch = new CountDownLatch(nodeCount());
 
-            DummyService.exeLatch(name, latch);
+        DummyService.exeLatch(name, latch);
 
-            ServiceConfiguration srvcCfg = new ServiceConfiguration();
+        ServiceConfiguration srvcCfg = new ServiceConfiguration();
 
-            srvcCfg.setName(name);
-            srvcCfg.setMaxPerNodeCount(1);
-            srvcCfg.setTotalCount(totalInstances);
-            srvcCfg.setService(new DummyService());
+        srvcCfg.setName(name);
+        srvcCfg.setMaxPerNodeCount(1);
+        srvcCfg.setTotalCount(totalInstances);
+        srvcCfg.setService(new DummyService());
 
-            IgniteServices svcs = g.services().withAsync();
+        IgniteServices svcs = g.services().withAsync();
 
-            svcs.deploy(srvcCfg);
+        svcs.deploy(srvcCfg);
 
-            IgniteFuture<?> fut = svcs.future();
+        IgniteFuture<?> fut = svcs.future();
 
-            info("Deployed service: " + name);
+        info("Deployed service: " + name);
 
-            fut.get();
+        fut.get();
 
-            info("Finished waiting for service future: " + name);
+        info("Finished waiting for service future: " + name);
 
-            latch.await();
+        latch.await();
 
-            TestCase.assertEquals(name, nodeCount(), DummyService.started(name));
-            TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+        assertEquals(name, nodeCount(), DummyService.started(name));
+        assertEquals(name, 0, DummyService.cancelled(name));
 
-            checkCount(name, g.services().serviceDescriptors(), nodeCount());
+        checkCount(name, g.services().serviceDescriptors(), nodeCount());
 
-            int extraNodes = 2;
+        int extraNodes = 2;
 
-            latch = new CountDownLatch(1);
+        latch = new CountDownLatch(1);
 
-            DummyService.exeLatch(name, latch);
+        DummyService.exeLatch(name, latch);
 
-            startExtraNodes(2);
+        startExtraNodes(2);
 
-            try {
-                latch.await();
+        try {
+            latch.await();
 
-                TestCase.assertEquals(name, totalInstances, DummyService.started(name));
-                TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+            waitForDeployment(name, totalInstances);
 
-                checkCount(name, g.services().serviceDescriptors(), totalInstances);
-            }
-            finally {
-                stopExtraNodes(extraNodes);
-            }
+            assertEquals(name, totalInstances,  DummyService.started(name) - DummyService.cancelled(name));
+
+//            Next may fails. Server can be restarted on unstable topology.
+//            assertEquals(name, totalInstances, DummyService.started(name));
+//            assertEquals(name, 0, DummyService.cancelled(name));
+
+            checkCount(name, g.services().serviceDescriptors(), totalInstances);
+        }
+        finally {
+            stopExtraNodes(extraNodes);
+        }
     }
 }
\ No newline at end of file


[11/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html b/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html
deleted file mode 100644
index 19a907a..0000000
--- a/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html
+++ /dev/null
@@ -1,128 +0,0 @@
-<!DOCTYPE html>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements.  See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<meta charset="utf-8">
-<title>IgniteML</title>
-<style>
-    body {
-        margin: 0 15px;
-    }
-
-    p {
-        margin: 10px 0 !important;
-    }
-
-    .name {
-        font-size: 20px;
-        font-weight: 400;
-        font-family: monospace;
-    }
-
-    .swatch {
-        display: inline-block;
-        width: 25px;
-        height: 25px;
-        margin-left: 5px;
-        vertical-align: bottom;
-    }
-</style>
-<body>
-<img style="margin-top: 15px" width="100px" src="https://ignite.apache.org/images/logo3.png">
-<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js"></script>
-<script>
-    /*@DATA@*/
-    var data = [[{d: 2.256, r: 198, g: 128, b: 128}, {d: 0.123, r: 218, g: 228, b: 18}], [{
-        d: 2.256,
-        r: 108,
-        g: 28,
-        b: 108
-    }, {d: 0.123, r: 228, g: 228, b: 228}]];
-    /*@MAX@*/
-    var max = {d: 2.256, r: 128, g: 128, b: 128};
-    /*@MIN@*/
-    var min = {d: 0.123, r: 228, g: 228, b: 228};
-    /*@NAME@*/
-    var name = "Matrix";
-
-    var rows = data.length;
-    var cols = data[0].length;
-
-    var range = max.d - min.d;
-
-    var rw, rh;
-    var W, H;
-
-    if (cols > W) {
-        rw = 1;
-        W = cols;
-    }
-    else {
-        W = 1000;
-        rw = Math.min(Math.round(W / cols), 10);
-    }
-
-    if (rows > H) {
-        rh = 1;
-        H = rows;
-    }
-    else {
-        H = 1000;
-        rh = Math.min(Math.round(H / rows), 10);
-    }
-
-    d3.selectAll("body")
-        .append("p")
-        .text(name + " (" + rows + "x" + cols + ")")
-        .attr("class", "name");
-
-    d3.selectAll("body")
-        .append("p")
-        .attr("class", "name")
-        .text("Max: " + max.d)
-        .append("span")
-        .attr("class", "swatch")
-        .attr("style", "background-color: rgb(" + max.r + ", " + max.g + ", " + max.b + ")");
-
-    d3.selectAll("body")
-        .append("p")
-        .attr("class", "name")
-        .text("Min: " + min.d)
-        .append("span")
-        .attr("class", "swatch")
-        .attr("style", "background-color: rgb(" + min.r + ", " + min.g + ", " + min.b + ")");
-
-    var svg = d3.select("body").append("svg")
-        .attr("width", W)
-        .attr("height", H);
-
-    var y = 0;
-
-    for (var row = 0; row < rows; row++)
-        svg.selectAll("div")
-            .data(data[row])
-            .enter()
-            .append("rect")
-            .attr("x", function (d, i) {
-                return i * rw
-            })
-            .attr("y", rh * row)
-            .attr("fill", function (d) {
-                return "rgb(" + d.r + ", " + d.g + ", " + d.b + ")";
-            })
-            .attr("width", rw)
-            .attr("height", rh);
-</script>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html b/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html
deleted file mode 100644
index 7644481..0000000
--- a/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE html>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements.  See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<meta charset="utf-8">
-<title>IgniteML</title>
-<style>
-    body {
-        margin: 0 15px;
-    }
-
-    p {
-        margin: 10px 0 !important;
-    }
-
-    .name {
-        font-size: 20px;
-        font-weight: 400;
-        font-family: monospace;
-    }
-
-    .swatch {
-        display: inline-block;
-        width: 25px;
-        height: 25px;
-        margin-left: 5px;
-        vertical-align: bottom;
-    }
-</style>
-<body>
-<img style="margin-top: 15px" width="100px" src="https://ignite.apache.org/images/logo3.png">
-<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js"></script>
-<script>
-    /*@DATA@*/
-    var data = [{d: 2.256, r: 128, g: 128, b: 128}, {d: 0.123, r: 228, g: 228, b: 228}];
-    /*@MAX@*/
-    var max = {d: 2.256, r: 128, g: 128, b: 128};
-    /*@MIN@*/
-    var min = {d: 0.123, r: 228, g: 228, b: 228};
-    /*@NAME@*/
-    var name = "Vector";
-
-    var W, H = 1000;
-
-    var range = max.d - min.d;
-
-    var rh = 20; // Constant.
-
-    var rw;
-
-    if (data.length > W) {
-        rw = 1;
-        W = data.length;
-    }
-    else {
-        W = 1000;
-        rw = Math.min(Math.round(W / data.length), 5);
-    }
-
-    d3.selectAll("body")
-        .append("p")
-        .text(name + " (size: " + data.length + ")")
-        .attr("class", "name");
-
-    d3.selectAll("body")
-        .append("p")
-        .attr("class", "name")
-        .text("Max: " + max.d)
-        .append("span")
-        .attr("class", "swatch")
-        .attr("style", "background-color: rgb(" + max.r + ", " + max.g + ", " + max.b + ")");
-
-    d3.selectAll("body")
-        .append("p")
-        .attr("class", "name")
-        .text("Min: " + min.d)
-        .append("span")
-        .attr("class", "swatch")
-        .attr("style", "background-color: rgb(" + min.r + ", " + min.g + ", " + min.b + ")");
-
-    var svg = d3.select("body").append("svg")
-        .attr("width", W)
-        .attr("height", H);
-
-    svg.selectAll("rect")
-        .data(data)
-        .enter()
-        .append("rect")
-        .attr("x", function (d, i) {
-            return i * rw
-        })
-        .attr("y", 10)
-        .attr("fill", function (d) {
-            return "rgb(" + d.r + ", " + d.g + ", " + d.b + ")";
-        })
-        .attr("width", rw)
-        .attr("height", rh);
-</script>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html
new file mode 100644
index 0000000..19a907a
--- /dev/null
+++ b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<meta charset="utf-8">
+<title>IgniteML</title>
+<style>
+    body {
+        margin: 0 15px;
+    }
+
+    p {
+        margin: 10px 0 !important;
+    }
+
+    .name {
+        font-size: 20px;
+        font-weight: 400;
+        font-family: monospace;
+    }
+
+    .swatch {
+        display: inline-block;
+        width: 25px;
+        height: 25px;
+        margin-left: 5px;
+        vertical-align: bottom;
+    }
+</style>
+<body>
+<img style="margin-top: 15px" width="100px" src="https://ignite.apache.org/images/logo3.png">
+<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js"></script>
+<script>
+    /*@DATA@*/
+    var data = [[{d: 2.256, r: 198, g: 128, b: 128}, {d: 0.123, r: 218, g: 228, b: 18}], [{
+        d: 2.256,
+        r: 108,
+        g: 28,
+        b: 108
+    }, {d: 0.123, r: 228, g: 228, b: 228}]];
+    /*@MAX@*/
+    var max = {d: 2.256, r: 128, g: 128, b: 128};
+    /*@MIN@*/
+    var min = {d: 0.123, r: 228, g: 228, b: 228};
+    /*@NAME@*/
+    var name = "Matrix";
+
+    var rows = data.length;
+    var cols = data[0].length;
+
+    var range = max.d - min.d;
+
+    var rw, rh;
+    var W, H;
+
+    if (cols > W) {
+        rw = 1;
+        W = cols;
+    }
+    else {
+        W = 1000;
+        rw = Math.min(Math.round(W / cols), 10);
+    }
+
+    if (rows > H) {
+        rh = 1;
+        H = rows;
+    }
+    else {
+        H = 1000;
+        rh = Math.min(Math.round(H / rows), 10);
+    }
+
+    d3.selectAll("body")
+        .append("p")
+        .text(name + " (" + rows + "x" + cols + ")")
+        .attr("class", "name");
+
+    d3.selectAll("body")
+        .append("p")
+        .attr("class", "name")
+        .text("Max: " + max.d)
+        .append("span")
+        .attr("class", "swatch")
+        .attr("style", "background-color: rgb(" + max.r + ", " + max.g + ", " + max.b + ")");
+
+    d3.selectAll("body")
+        .append("p")
+        .attr("class", "name")
+        .text("Min: " + min.d)
+        .append("span")
+        .attr("class", "swatch")
+        .attr("style", "background-color: rgb(" + min.r + ", " + min.g + ", " + min.b + ")");
+
+    var svg = d3.select("body").append("svg")
+        .attr("width", W)
+        .attr("height", H);
+
+    var y = 0;
+
+    for (var row = 0; row < rows; row++)
+        svg.selectAll("div")
+            .data(data[row])
+            .enter()
+            .append("rect")
+            .attr("x", function (d, i) {
+                return i * rw
+            })
+            .attr("y", rh * row)
+            .attr("fill", function (d) {
+                return "rgb(" + d.r + ", " + d.g + ", " + d.b + ")";
+            })
+            .attr("width", rw)
+            .attr("height", rh);
+</script>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html
new file mode 100644
index 0000000..7644481
--- /dev/null
+++ b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html
@@ -0,0 +1,111 @@
+<!DOCTYPE html>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<meta charset="utf-8">
+<title>IgniteML</title>
+<style>
+    body {
+        margin: 0 15px;
+    }
+
+    p {
+        margin: 10px 0 !important;
+    }
+
+    .name {
+        font-size: 20px;
+        font-weight: 400;
+        font-family: monospace;
+    }
+
+    .swatch {
+        display: inline-block;
+        width: 25px;
+        height: 25px;
+        margin-left: 5px;
+        vertical-align: bottom;
+    }
+</style>
+<body>
+<img style="margin-top: 15px" width="100px" src="https://ignite.apache.org/images/logo3.png">
+<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js"></script>
+<script>
+    /*@DATA@*/
+    var data = [{d: 2.256, r: 128, g: 128, b: 128}, {d: 0.123, r: 228, g: 228, b: 228}];
+    /*@MAX@*/
+    var max = {d: 2.256, r: 128, g: 128, b: 128};
+    /*@MIN@*/
+    var min = {d: 0.123, r: 228, g: 228, b: 228};
+    /*@NAME@*/
+    var name = "Vector";
+
+    var W, H = 1000;
+
+    var range = max.d - min.d;
+
+    var rh = 20; // Constant.
+
+    var rw;
+
+    if (data.length > W) {
+        rw = 1;
+        W = data.length;
+    }
+    else {
+        W = 1000;
+        rw = Math.min(Math.round(W / data.length), 5);
+    }
+
+    d3.selectAll("body")
+        .append("p")
+        .text(name + " (size: " + data.length + ")")
+        .attr("class", "name");
+
+    d3.selectAll("body")
+        .append("p")
+        .attr("class", "name")
+        .text("Max: " + max.d)
+        .append("span")
+        .attr("class", "swatch")
+        .attr("style", "background-color: rgb(" + max.r + ", " + max.g + ", " + max.b + ")");
+
+    d3.selectAll("body")
+        .append("p")
+        .attr("class", "name")
+        .text("Min: " + min.d)
+        .append("span")
+        .attr("class", "swatch")
+        .attr("style", "background-color: rgb(" + min.r + ", " + min.g + ", " + min.b + ")");
+
+    var svg = d3.select("body").append("svg")
+        .attr("width", W)
+        .attr("height", H);
+
+    svg.selectAll("rect")
+        .data(data)
+        .enter()
+        .append("rect")
+        .attr("x", function (d, i) {
+            return i * rw
+        })
+        .attr("y", 10)
+        .attr("fill", function (d) {
+            return "rgb(" + d.r + ", " + d.g + ", " + d.b + ")";
+        })
+        .attr("width", rw)
+        .attr("height", rh);
+</script>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java b/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java
deleted file mode 100644
index 218b7ff..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Common test for externalization.
- */
-public abstract class ExternalizeTest<T extends Externalizable & Destroyable> {
-    /** */
-    protected void externalizeTest(T initObj) {
-        T objRestored = null;
-
-        try {
-            ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
-            ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
-
-            objOutputStream.writeObject(initObj);
-
-            ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
-            ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
-
-            objRestored = (T)objInputStream.readObject();
-
-            assertTrue(MathTestConstants.VAL_NOT_EQUALS, initObj.equals(objRestored));
-            assertTrue(MathTestConstants.VAL_NOT_EQUALS, Integer.compare(initObj.hashCode(), objRestored.hashCode()) == 0);
-        }
-        catch (ClassNotFoundException | IOException e) {
-            fail(e + " [" + e.getMessage() + "]");
-        }
-        finally {
-            if (objRestored != null)
-                objRestored.destroy();
-        }
-    }
-
-    /** */
-    @Test
-    public abstract void externalizeTest();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java
deleted file mode 100644
index 318ea95..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import org.apache.ignite.math.impls.matrix.CacheMatrixTest;
-import org.apache.ignite.math.impls.matrix.SparseDistributedMatrixTest;
-import org.apache.ignite.math.impls.storage.matrix.SparseDistributedMatrixStorageTest;
-import org.apache.ignite.math.impls.vector.CacheVectorTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for all distributed tests located in org.apache.ignite.math.impls.* package.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-    CacheVectorTest.class,
-    CacheMatrixTest.class,
-    SparseDistributedMatrixStorageTest.class,
-    SparseDistributedMatrixTest.class,
-})
-public class MathImplDistributedTestSuite {
-    // No-op.
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java
deleted file mode 100644
index a652e7f..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import org.apache.ignite.math.decompositions.CholeskyDecompositionTest;
-import org.apache.ignite.math.decompositions.EigenDecompositionTest;
-import org.apache.ignite.math.decompositions.LUDecompositionTest;
-import org.apache.ignite.math.decompositions.QRDecompositionTest;
-import org.apache.ignite.math.decompositions.SingularValueDecompositionTest;
-import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrixConstructorTest;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrixConstructorTest;
-import org.apache.ignite.math.impls.matrix.DiagonalMatrixTest;
-import org.apache.ignite.math.impls.matrix.FunctionMatrixConstructorTest;
-import org.apache.ignite.math.impls.matrix.MatrixAttributeTest;
-import org.apache.ignite.math.impls.matrix.MatrixImplementationsTest;
-import org.apache.ignite.math.impls.matrix.MatrixViewConstructorTest;
-import org.apache.ignite.math.impls.matrix.PivotedMatrixViewConstructorTest;
-import org.apache.ignite.math.impls.matrix.RandomMatrixConstructorTest;
-import org.apache.ignite.math.impls.matrix.SparseLocalOnHeapMatrixConstructorTest;
-import org.apache.ignite.math.impls.matrix.TransposedMatrixViewTest;
-import org.apache.ignite.math.impls.storage.matrix.MatrixArrayStorageTest;
-import org.apache.ignite.math.impls.storage.matrix.MatrixOffHeapStorageTest;
-import org.apache.ignite.math.impls.storage.matrix.MatrixStorageImplementationTest;
-import org.apache.ignite.math.impls.storage.vector.RandomAccessSparseVectorStorageTest;
-import org.apache.ignite.math.impls.storage.vector.SparseLocalOffHeapVectorStorageTest;
-import org.apache.ignite.math.impls.storage.vector.VectorArrayStorageTest;
-import org.apache.ignite.math.impls.storage.vector.VectorOffheapStorageTest;
-import org.apache.ignite.math.impls.vector.AbstractVectorTest;
-import org.apache.ignite.math.impls.vector.ConstantVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.DelegatingVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.FunctionVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.MatrixVectorViewTest;
-import org.apache.ignite.math.impls.vector.PivotedVectorViewConstructorTest;
-import org.apache.ignite.math.impls.vector.RandomVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.SingleElementVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.SingleElementVectorViewConstructorTest;
-import org.apache.ignite.math.impls.vector.SparseLocalVectorConstructorTest;
-import org.apache.ignite.math.impls.vector.VectorAttributesTest;
-import org.apache.ignite.math.impls.vector.VectorFoldMapTest;
-import org.apache.ignite.math.impls.vector.VectorImplementationsTest;
-import org.apache.ignite.math.impls.vector.VectorIterableTest;
-import org.apache.ignite.math.impls.vector.VectorNormTest;
-import org.apache.ignite.math.impls.vector.VectorToMatrixTest;
-import org.apache.ignite.math.impls.vector.VectorViewTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for all local tests located in org.apache.ignite.math.impls.* package.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-    // Vector constructors tests.
-    DenseLocalOnHeapVectorConstructorTest.class,
-    DenseLocalOffHeapVectorConstructorTest.class,
-    SparseLocalVectorConstructorTest.class,
-    RandomVectorConstructorTest.class,
-    ConstantVectorConstructorTest.class,
-    FunctionVectorConstructorTest.class,
-    SingleElementVectorConstructorTest.class,
-    PivotedVectorViewConstructorTest.class,
-    SingleElementVectorViewConstructorTest.class,
-    DelegatingVectorConstructorTest.class,
-    // Various vectors tests.
-    AbstractVectorTest.class,
-    VectorImplementationsTest.class,
-    VectorViewTest.class,
-    MatrixVectorViewTest.class,
-    // Vector particular features tests.
-    VectorIterableTest.class,
-    VectorAttributesTest.class,
-    VectorToMatrixTest.class,
-    VectorNormTest.class,
-    VectorFoldMapTest.class,
-    // Vector storage tests
-    VectorArrayStorageTest.class,
-    VectorOffheapStorageTest.class,
-    RandomAccessSparseVectorStorageTest.class,
-    SparseLocalOffHeapVectorStorageTest.class,
-    // Matrix storage tests.
-    MatrixStorageImplementationTest.class,
-    MatrixOffHeapStorageTest.class,
-    MatrixArrayStorageTest.class,
-    // Matrix constructors tests.
-    DenseLocalOnHeapMatrixConstructorTest.class,
-    DenseLocalOffHeapMatrixConstructorTest.class,
-    RandomMatrixConstructorTest.class,
-    FunctionMatrixConstructorTest.class,
-    MatrixViewConstructorTest.class,
-    PivotedMatrixViewConstructorTest.class,
-    SparseLocalOnHeapMatrixConstructorTest.class,
-    // Matrix tests.
-    MatrixImplementationsTest.class,
-    DiagonalMatrixTest.class,
-    MatrixAttributeTest.class,
-    TransposedMatrixViewTest.class,
-    // Decomposes
-    LUDecompositionTest.class,
-    EigenDecompositionTest.class,
-    CholeskyDecompositionTest.class,
-    QRDecompositionTest.class,
-    SingularValueDecompositionTest.class
-})
-public class MathImplLocalTestSuite {
-    // No-op.
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java
deleted file mode 100644
index 44fa8e6..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for local and distributed tests
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-    MathImplLocalTestSuite.class,
-    MathImplDistributedTestSuite.class
-})
-public class MathImplMainTestSuite {
-    // No-op.
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java b/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java
deleted file mode 100644
index 35d2f60..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.awt.Color;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Optional;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.junit.Test;
-
-import static java.nio.file.Files.createTempFile;
-import static org.junit.Assert.assertEquals;
-
-/**
- * Tests for {@link Tracer}.
- */
-public class TracerTest {
-    /** */ private static final String DEFAULT_FORMAT = "%.10f";
-    /** */ private static final double DEFAULT_DELTA = 0.000000001d;
-
-    /**
-     * Color mapper that maps [0, 1] range into three distinct RGB segments.
-     */
-    private static final Tracer.ColorMapper COLOR_MAPPER = new Tracer.ColorMapper() {
-        /** {@inheritDoc} */
-        @Override public Color apply(Double d) {
-            if (d <= 0.33)
-                return Color.RED;
-            else if (d <= 0.66)
-                return Color.GREEN;
-            else
-                return Color.BLUE;
-        }
-    };
-
-    /**
-     * @param size Vector size.
-     */
-    private Vector makeRandomVector(int size) {
-        DenseLocalOnHeapVector vec = new DenseLocalOnHeapVector(size);
-
-        vec.assign((idx) -> Math.random());
-
-        return vec;
-    }
-
-    /**
-     * @param rows Amount of rows in matrix.
-     * @param cols Amount of columns in matrix.
-     */
-    private Matrix makeRandomMatrix(int rows, int cols) {
-        DenseLocalOnHeapMatrix mtx = new DenseLocalOnHeapMatrix(rows, cols);
-
-        // Missing assign(f)?
-        mtx.map((d) -> Math.random());
-
-        return mtx;
-    }
-
-    /**
-     *
-     */
-    @Test
-    public void testAsciiVectorTracer() {
-        Vector vec = makeRandomVector(20);
-
-        Tracer.showAscii(vec);
-        Tracer.showAscii(vec, "%2f");
-        Tracer.showAscii(vec, "%.3g");
-    }
-
-    /**
-     *
-     */
-    @Test
-    public void testAsciiMatrixTracer() {
-        Matrix mtx = makeRandomMatrix(10, 10);
-
-        Tracer.showAscii(mtx);
-        Tracer.showAscii(mtx, "%2f");
-        Tracer.showAscii(mtx, "%.3g");
-    }
-
-    /**
-     *
-     */
-    @Test
-    public void testHtmlVectorTracer() throws IOException {
-        Vector vec1 = makeRandomVector(1000);
-
-        // Default color mapping.
-        Tracer.showHtml(vec1);
-
-        // Custom color mapping.
-        Tracer.showHtml(vec1, COLOR_MAPPER);
-
-        // Default color mapping with sorted vector.
-        Tracer.showHtml(vec1.sort());
-    }
-
-    /**
-     *
-     */
-    @Test
-    public void testHtmlMatrixTracer() throws IOException {
-        Matrix mtx1 = makeRandomMatrix(100, 100);
-
-        // Custom color mapping.
-        Tracer.showHtml(mtx1, COLOR_MAPPER);
-
-        Matrix mtx2 = new DenseLocalOnHeapMatrix(100, 100);
-
-        double MAX = (double)(mtx2.rowSize() * mtx2.columnSize());
-
-        mtx2.assign((x, y) -> (double)(x * y) / MAX);
-
-        Tracer.showHtml(mtx2);
-    }
-
-    /** */
-    @Test
-    public void testWriteVectorToCSVFile() throws IOException {
-        DenseLocalOnHeapVector vector = new DenseLocalOnHeapVector(MathTestConstants.STORAGE_SIZE);
-
-        for (int i = 0; i < vector.size(); i++)
-            vector.set(i, Math.random());
-
-        Path file = createTempFile("vector", ".csv");
-
-        Tracer.saveAsCsv(vector, DEFAULT_FORMAT, file.toString());
-
-        System.out.println("Vector exported: " + file.getFileName());
-
-        List<String> strings = Files.readAllLines(file);
-        Optional<String> reduce = strings.stream().reduce((s1, s2) -> s1 + s2);
-        String[] csvVals = reduce.get().split(",");
-
-        for (int i = 0; i < vector.size(); i++) {
-            Double csvVal = Double.valueOf(csvVals[i]);
-
-            assertEquals("Unexpected value.", csvVal, vector.get(i), DEFAULT_DELTA);
-        }
-
-        Files.deleteIfExists(file);
-    }
-
-    /** */
-    @Test
-    public void testWriteMatrixToCSVFile() throws IOException {
-        DenseLocalOnHeapMatrix matrix = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
-
-        for (int i = 0; i < matrix.rowSize(); i++)
-            for (int j = 0; j < matrix.columnSize(); j++)
-                matrix.set(i, j, Math.random());
-
-        Path file = createTempFile("matrix", ".csv");
-
-        Tracer.saveAsCsv(matrix, DEFAULT_FORMAT, file.toString());
-
-        System.out.println("Matrix exported: " + file.getFileName());
-
-        List<String> strings = Files.readAllLines(file);
-        Optional<String> reduce = strings.stream().reduce((s1, s2) -> s1 + s2);
-        String[] csvVals = reduce.get().split(",");
-
-        for (int i = 0; i < matrix.rowSize(); i++)
-            for (int j = 0; j < matrix.columnSize(); j++) {
-                Double csvVal = Double.valueOf(csvVals[i * matrix.rowSize() + j]);
-
-                assertEquals("Unexpected value.", csvVal, matrix.get(i, j), DEFAULT_DELTA);
-            }
-
-        Files.deleteIfExists(file);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java
deleted file mode 100644
index 4c3718a..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.benchmark;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/** Refer {@link MathBenchmarkSelfTest} for usage examples. */
-class MathBenchmark {
-    /** */
-    private final boolean outputToConsole;
-
-    /** */
-    private final String benchmarkName;
-
-    /** */
-    private final int measurementTimes;
-
-    /** */
-    private final int warmUpTimes;
-
-    /** */
-    private final String tag;
-
-    /** */
-    private final String comments;
-
-    /** Constructor strictly for use within this class. */
-    private MathBenchmark(String benchmarkName, boolean outputToConsole, int measurementTimes, int warmUpTimes,
-        String tag, String comments) {
-        this.benchmarkName = benchmarkName;
-        this.outputToConsole = outputToConsole;
-        this.measurementTimes = measurementTimes;
-        this.warmUpTimes = warmUpTimes;
-        this.tag = tag;
-        this.comments = comments;
-        validate();
-    }
-
-    /**
-     * Benchmark with specified name and default parameters, in particular, default output file.
-     *
-     * @param benchmarkName name
-     */
-    MathBenchmark(String benchmarkName) {
-        this(benchmarkName, false, 100, 1, "", "");
-    }
-
-    /**
-     * Executes the code using config of this benchmark.
-     *
-     * @param code code to execute
-     * @throws Exception if something goes wrong
-     */
-    void execute(BenchmarkCode code) throws Exception {
-        System.out.println("Started benchmark [" + benchmarkName + "].");
-
-        for (int cnt = 0; cnt < warmUpTimes; cnt++)
-            code.call();
-
-        final long start = System.currentTimeMillis();
-
-        for (int cnt = 0; cnt < measurementTimes; cnt++)
-            code.call();
-
-        final long end = System.currentTimeMillis();
-
-        writeResults(formatResults(start, end));
-
-        System.out.println("Finished benchmark [" + benchmarkName + "].");
-    }
-
-    /**
-     * Set optional output mode for using stdout.
-     *
-     * @return configured benchmark
-     */
-    MathBenchmark outputToConsole() {
-        return new MathBenchmark(benchmarkName, true, measurementTimes, warmUpTimes, tag, comments);
-    }
-
-    /**
-     * Set optional measurement times.
-     *
-     * @param param times
-     * @return configured benchmark
-     */
-    MathBenchmark measurementTimes(int param) {
-        return new MathBenchmark(benchmarkName, outputToConsole, param, warmUpTimes, tag, comments);
-    }
-
-    /**
-     * Set optional warm-up times.
-     *
-     * @param param times
-     * @return configured benchmark
-     */
-    MathBenchmark warmUpTimes(int param) {
-        return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, param, tag, comments);
-    }
-
-    /**
-     * Set optional tag to help filtering specific kind of benchmark results.
-     *
-     * @param param name
-     * @return configured benchmark
-     */
-    MathBenchmark tag(String param) {
-        return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, warmUpTimes, param, comments);
-    }
-
-    /**
-     * Set optional comments.
-     *
-     * @param param name
-     * @return configured benchmark
-     */
-    MathBenchmark comments(String param) {
-        return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, warmUpTimes, tag, param);
-    }
-
-    /** */
-    private void writeResults(String results) throws Exception {
-        if (outputToConsole) {
-            System.out.println(results);
-
-            return;
-        }
-
-        new ResultsWriter().append(results);
-    }
-
-    /** */
-    private String formatResults(long start, long end) {
-        final String delim = ",";
-
-        assert !formatDouble(1000_000_001.1).contains(delim) : "Formatted results contain [" + delim + "].";
-
-        final String ts = formatTs(start);
-
-        assert !ts.contains(delim) : "Formatted timestamp contains [" + delim + "].";
-
-        return benchmarkName +
-            delim +
-            ts + // IMPL NOTE timestamp
-            delim +
-            formatDouble((double)(end - start) / measurementTimes) +
-            delim +
-            measurementTimes +
-            delim +
-            warmUpTimes +
-            delim +
-            tag +
-            delim +
-            comments;
-    }
-
-    /** */
-    private String formatDouble(double val) {
-        return String.format(Locale.US, "%f", val);
-    }
-
-    /** */
-    private String formatTs(long ts) {
-        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
-
-        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
-
-        return sdf.format(new Date(ts));
-    }
-
-    /** */
-    private void validate() {
-        if (benchmarkName == null || benchmarkName.isEmpty())
-            throw new IllegalArgumentException("Invalid benchmark name: [" + benchmarkName + "].");
-
-        if (measurementTimes < 1)
-            throw new IllegalArgumentException("Invalid measurement times: [" + measurementTimes + "].");
-    }
-
-    /** */
-    interface BenchmarkCode {
-        // todo find out why Callable<Void> failed to work here
-
-        /** */
-        void call() throws Exception;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java
deleted file mode 100644
index 7a86461..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.benchmark;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class MathBenchmarkSelfTest {
-    /** */
-    @Test
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void demoTest() throws Exception {
-        for (int i = 0; i < 2; i++)
-            new MathBenchmark("demo test")
-                .outputToConsole() // IMPL NOTE this is to write output into console instead of a file
-                .tag(null) // IMPL NOTE try null for tag, expect it to be formatted reasonably
-                .comments(null) // IMPL NOTE try null for comments, expect it to be formatted reasonably
-                .execute(() -> {
-                    double seed = 1.1;
-
-                    for (int cnt = 0; cnt < 1000; cnt++) {
-                        seed = Math.pow(seed, 2);
-
-                        assertTrue(seed > 0);
-                    }
-                });
-    }
-
-    /** */
-    @Test
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void configTest() throws Exception {
-        new MathBenchmark("demo config test")
-            .outputToConsole()
-            .measurementTimes(2)
-            .warmUpTimes(0)
-            .tag("demo tag")
-            .comments("demo comments")
-            .execute(() -> System.out.println("config test"));
-    }
-
-    /** */
-    @Test(expected = IllegalArgumentException.class)
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void emptyNameTest() throws Exception {
-        new MathBenchmark("")
-            .outputToConsole()
-            .measurementTimes(1)
-            .warmUpTimes(1)
-            .tag("empty name test tag")
-            .comments("empty name test comments")
-            .execute(() -> System.out.println("empty name test"));
-    }
-
-    /** */
-    @Test(expected = IllegalArgumentException.class)
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void nullDropboxPathTest() throws Exception {
-        new ResultsWriter(null, "whatever", "whatever");
-    }
-
-    /** */
-    @Test(expected = IllegalArgumentException.class)
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void nullDropboxUrlTest() throws Exception {
-        new ResultsWriter("whatever", null, "whatever");
-    }
-
-    /** */
-    @Test(expected = IllegalArgumentException.class)
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void nullDropboxTokenTest() throws Exception {
-        new ResultsWriter("whatever", "whatever", null);
-    }
-
-    /** */
-    @Test(expected = IllegalArgumentException.class)
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void nullResultsTest() throws Exception {
-        new ResultsWriter("whatever", "whatever", "whatever").append(null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java
deleted file mode 100644
index aeec156..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.benchmark;
-
-import com.dropbox.core.DbxException;
-import com.dropbox.core.DbxRequestConfig;
-import com.dropbox.core.v2.DbxClientV2;
-import com.dropbox.core.v2.files.WriteMode;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.UUID;
-
-/** */
-class ResultsWriter {
-    /** */
-    private static final String DROPBOX_PATH
-        = "/benchmarks/math.benchmark.results.csv";
-
-    /** */
-    private static final String DROPBOX_URL
-        = "https://www.dropbox.com/s/r7tcle31r7gaty8/math.benchmark.results.csv";
-
-    /** */
-    private static final String ACCESS_TOKEN
-        = "1MMmQjEyzGAAAAAAAAAAfDFrQ6oBPPi4NX-iU_VrgmXB2JDXqRHGa125cTkkEQ0V";
-
-    /** */
-    private final String dropboxPath;
-    /** */
-    private final String dropboxUrl;
-    /** */
-    private final String accessTok;
-
-    /** */
-    ResultsWriter(String dropboxPath, String dropboxUrl, String accessTok) {
-        this.dropboxPath = dropboxPath;
-        this.dropboxUrl = dropboxUrl;
-        this.accessTok = accessTok;
-
-        if (dropboxPath == null || dropboxUrl == null || accessTok == null)
-            throw new IllegalArgumentException("Neither of dropbox path, URL, access token can be null.");
-    }
-
-    /** **/
-    ResultsWriter() {
-        this(DROPBOX_PATH, DROPBOX_URL, ACCESS_TOKEN);
-    }
-
-    /** */
-    void append(String res) throws DbxException, IOException {
-        if (res == null)
-            throw new IllegalArgumentException("benchmark result is null");
-
-        if (dropboxPath == null) {
-            System.out.println(res);
-
-            return;
-        }
-
-        append(res, client());
-    }
-
-    /** */
-    private void append(String res, DbxClientV2 client) throws DbxException, IOException {
-        File tmp = createTmpFile();
-
-        try (FileOutputStream out = new FileOutputStream(tmp)) {
-            client.files().download(dropboxPath).download(out);
-        }
-
-        writeResults(res, tmp);
-
-        try (FileInputStream in = new FileInputStream(tmp)) {
-            client.files().uploadBuilder(dropboxPath).withMode(WriteMode.OVERWRITE).uploadAndFinish(in);
-        }
-
-        if (!tmp.delete())
-            System.out.println("Failed to delete " + tmp.getAbsolutePath());
-
-        System.out.println("Uploaded benchmark results to: " + dropboxUrl);
-    }
-
-    /** */
-    private void writeResults(String res, File tmp) throws IOException {
-        final String unixLineSeparator = "\n";
-
-        try (final PrintWriter writer = new PrintWriter(Files.newBufferedWriter(Paths.get(tmp.toURI()),
-            StandardOpenOption.APPEND, StandardOpenOption.CREATE))) {
-            writer.write(res + unixLineSeparator);
-        }
-    }
-
-    /** */
-    private File createTmpFile() throws IOException {
-        File tmp = File.createTempFile(UUID.randomUUID().toString(), ".csv");
-
-        tmp.deleteOnExit();
-
-        return tmp;
-    }
-
-    /** */
-    private DbxClientV2 client() {
-        return new DbxClientV2(DbxRequestConfig.newBuilder("dropbox/MathBenchmark").build(), accessTok);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java
deleted file mode 100644
index 1f7b204..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.benchmark;
-
-import java.util.function.BiConsumer;
-import java.util.function.Function;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVector;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-/** */
-public class VectorBenchmarkTest {
-    // todo add benchmarks for other methods in Vector and for other types of Vector and Matrix
-
-    /** */
-    @Test
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void testDenseLocalOnHeapVector() throws Exception {
-        benchmark("DenseLocalOnHeapVector basic mix", DenseLocalOnHeapVector::new, this::basicMix);
-
-        benchmark("DenseLocalOnHeapVector fold map", DenseLocalOnHeapVector::new, this::foldMapMix);
-    }
-
-    /** */
-    @Test
-    @Ignore("Benchmark tests are intended only for manual execution")
-    public void testDenseLocalOffHeapVector() throws Exception {
-        benchmark("DenseLocalOffHeapVector basic mix", DenseLocalOffHeapVector::new, this::basicMix);
-
-        benchmark("DenseLocalOffHeapVector fold map", DenseLocalOffHeapVector::new, this::foldMapMix);
-    }
-
-    /** */
-    private void benchmark(String namePrefix, Function<Integer, Vector> constructor,
-        BiConsumer<Integer, Function<Integer, Vector>> consumer) throws Exception {
-        assertNotNull(namePrefix);
-
-        new MathBenchmark(namePrefix + " small sizes").execute(() -> {
-            for (int size : new int[] {2, 3, 4, 5, 6, 7})
-                consumer.accept(size, constructor);
-        });
-
-        new MathBenchmark(namePrefix + " sizes powers of 2").execute(() -> {
-            for (int power : new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14})
-                consumer.accept(1 << power, constructor);
-        });
-
-        new MathBenchmark(namePrefix + " large sizes").execute(() -> {
-            for (int power : new int[] {10, 12, 14, 16})
-                for (int delta : new int[] {-1, 0, 1})
-                    consumer.accept((1 << power) + delta, constructor);
-        });
-
-        new MathBenchmark(namePrefix + " extra large sizes")
-            .measurementTimes(10)
-            .execute(() -> { // IMPL NOTE trying below with power 22 almost killed my IDEA and laptop
-                for (int power : new int[] {17, 18, 19, 20, 21})
-                    for (int delta : new int[] {-1, 0}) // IMPL NOTE delta +1 is not intended for use here
-                        consumer.accept((1 << power) + delta, constructor);
-            });
-    }
-
-    /** */
-    private void basicMix(int size, Function<Integer, Vector> constructor) {
-        final Vector v1 = constructor.apply(size), v2 = constructor.apply(size);
-
-        for (int idx = 0; idx < size; idx++) {
-            v1.set(idx, idx);
-
-            v2.set(idx, size - idx);
-        }
-
-        assertNotNull(v1.sum());
-
-        assertNotNull(v1.copy());
-
-        assertFalse(v1.getLengthSquared() < 0);
-
-        assertNotNull(v1.normalize());
-
-        assertNotNull(v1.logNormalize());
-
-        assertFalse(v1.getDistanceSquared(v2) < 0);
-
-        assertNotNull(v1.divide(2));
-
-        assertNotNull(v1.minus(v2));
-
-        assertNotNull(v1.plus(v2));
-
-        assertNotNull(v1.dot(v2));
-
-        assertNotNull(v1.assign(v2));
-
-        assertNotNull(v1.assign(1)); // IMPL NOTE this would better be last test for it sets all values the same
-    }
-
-    /** */
-    private void foldMapMix(int size, Function<Integer, Vector> constructor) {
-        final Vector v1 = constructor.apply(size), v2 = constructor.apply(size);
-
-        for (int idx = 0; idx < size; idx++) {
-            v1.set(idx, idx);
-
-            v2.set(idx, size - idx);
-        }
-
-        assertNotNull(v1.map((val) -> (val + 1)));
-
-        assertNotNull(v1.map(v2, (one, other) -> one + other / 2.0));
-
-        assertNotNull(v1.map((val, val1) -> (val + val1), 2.0));
-
-        assertNotNull(v1.foldMap((sum, val) -> (val + sum), (val) -> val, 0.0));
-
-        assertNotNull(v1.foldMap(v2, (sum, val) -> (val + sum), (val1, val2) -> val1 + val2, 0.0));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java
deleted file mode 100644
index cbf5d36..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.benchmark;

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java
deleted file mode 100644
index fa311e0..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.NonPositiveDefiniteMatrixException;
-import org.apache.ignite.math.exceptions.NonSymmetricMatrixException;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.matrix.PivotedMatrixView;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/** */
-public class CholeskyDecompositionTest {
-    /** */
-    @Test
-    public void basicTest() {
-        basicTest(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        }));
-    }
-
-    /**
-     * Test for {@link DecompositionSupport} features.
-     */
-    @Test
-    public void decompositionSupportTest() {
-        basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        })));
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullMatrixTest() {
-        new CholeskyDecomposition(null);
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void wrongMatrixSizeTest() {
-        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(2, 3));
-    }
-
-    /** */
-    @Test(expected = NonSymmetricMatrixException.class)
-    public void nonSymmetricMatrixTest() {
-        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 10.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {-10.0d, -1.0d, 2.0d}
-        }));
-    }
-
-    /** */
-    @Test(expected = NonPositiveDefiniteMatrixException.class)
-    public void nonAbsPositiveMatrixTest() {
-        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 0.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        }));
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void solveWrongVectorSizeTest() {
-        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        })).solve(new DenseLocalOnHeapVector(2));
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void solveWrongMatrixSizeTest() {
-        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        })).solve(new DenseLocalOnHeapMatrix(2, 3));
-    }
-
-    /** */
-    private void basicTest(Matrix m) {
-        // This decomposition is useful when dealing with systems of linear equations of the form
-        // m x = b where m is a Hermitian matrix.
-        // For such systems Cholesky decomposition provides
-        // more effective method of solving compared to LU decomposition.
-        // Suppose we want to solve system
-        // m x = b for various bs. Then after we computed Cholesky decomposition, we can feed various bs
-        // as a matrix of the form
-        // (b1, b2, ..., bm)
-        // to the method Cholesky::solve which returns solutions in the form
-        // (sol1, sol2, ..., solm)
-        CholeskyDecomposition dec = new CholeskyDecomposition(m);
-        assertEquals("Unexpected value for decomposition determinant.",
-            4d, dec.getDeterminant(), 0d);
-
-        Matrix l = dec.getL();
-        Matrix lt = dec.getLT();
-
-        assertNotNull("Matrix l is expected to be not null.", l);
-        assertNotNull("Matrix lt is expected to be not null.", lt);
-
-        for (int row = 0; row < l.rowSize(); row++)
-            for (int col = 0; col < l.columnSize(); col++)
-                assertEquals("Unexpected value transposed matrix at (" + row + "," + col + ").",
-                    l.get(row, col), lt.get(col, row), 0d);
-
-        Matrix bs = new DenseLocalOnHeapMatrix(new double[][] {
-            {4.0, -6.0, 7.0},
-            {1.0, 1.0, 1.0}
-        }).transpose();
-        Matrix sol = dec.solve(bs);
-
-        assertNotNull("Solution matrix is expected to be not null.", sol);
-        assertEquals("Solution rows are not as expected.", bs.rowSize(), sol.rowSize());
-        assertEquals("Solution columns are not as expected.", bs.columnSize(), sol.columnSize());
-
-        for (int i = 0; i < sol.columnSize(); i++)
-            assertNotNull("Solution matrix column is expected to be not null at index " + i, sol.viewColumn(i));
-
-        Vector b = new DenseLocalOnHeapVector(new double[] {4.0, -6.0, 7.0});
-        Vector solVec = dec.solve(b);
-
-        for (int idx = 0; idx < b.size(); idx++)
-            assertEquals("Unexpected value solution vector at " + idx,
-                b.get(idx), solVec.get(idx), 0d);
-
-        dec.destroy();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java
deleted file mode 100644
index e4e7b15..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for {@link EigenDecomposition}
- */
-public class EigenDecompositionTest {
-    /** */
-    private static final double EPSILON = 1e-11;
-
-    /** */
-    @Test
-    public void testMatrixWithRealEigenvalues() {
-        test(new double[][] {
-                {1.0d, 0.0d, 0.0d, 0.0d},
-                {0.0d, 1.0d, 0.0d, 0.0d},
-                {0.0d, 0.0d, 2.0d, 0.0d},
-                {1.0d, 1.0d, 0.0d, 2.0d}},
-            new double[] {1, 2, 2, 1});
-    }
-
-    /** */
-    @Test
-    public void testSymmetricMatrix() {
-        EigenDecomposition decomposition = new EigenDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {1.0d, 0.0d, 0.0d, 1.0d},
-            {0.0d, 1.0d, 0.0d, 1.0d},
-            {0.0d, 0.0d, 2.0d, 0.0d},
-            {1.0d, 1.0d, 0.0d, 2.0d}}));
-
-        Matrix d = decomposition.getD();
-        Matrix v = decomposition.getV();
-
-        assertNotNull("Matrix d is expected to be not null.", d);
-        assertNotNull("Matrix v is expected to be not null.", v);
-
-        assertEquals("Unexpected rows in d matrix.", 4, d.rowSize());
-        assertEquals("Unexpected cols in d matrix.", 4, d.columnSize());
-
-        assertEquals("Unexpected rows in v matrix.", 4, v.rowSize());
-        assertEquals("Unexpected cols in v matrix.", 4, v.columnSize());
-
-        assertIsDiagonalNonZero(d);
-
-        decomposition.destroy();
-    }
-
-    /** */
-    @Test
-    public void testNonSquareMatrix() {
-        EigenDecomposition decomposition = new EigenDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {1.0d, 0.0d, 0.0d},
-            {0.0d, 1.0d, 0.0d},
-            {0.0d, 0.0d, 2.0d},
-            {1.0d, 1.0d, 0.0d}}));
-        // todo find out why decomposition of 3X4 matrix throws row index exception
-
-        Matrix d = decomposition.getD();
-        Matrix v = decomposition.getV();
-
-        assertNotNull("Matrix d is expected to be not null.", d);
-        assertNotNull("Matrix v is expected to be not null.", v);
-
-        assertEquals("Unexpected rows in d matrix.", 4, d.rowSize());
-        assertEquals("Unexpected cols in d matrix.", 4, d.columnSize());
-
-        assertEquals("Unexpected rows in v matrix.", 4, v.rowSize());
-        assertEquals("Unexpected cols in v matrix.", 3, v.columnSize());
-
-        assertIsDiagonal(d, true);
-
-        decomposition.destroy();
-    }
-
-    /** */
-    private void test(double[][] mRaw, double[] expRealEigenValues) {
-        DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(mRaw);
-        EigenDecomposition decomposition = new EigenDecomposition(m);
-
-        Matrix d = decomposition.getD();
-        Matrix v = decomposition.getV();
-
-        assertIsDiagonalNonZero(d);
-
-        // check that d's diagonal consists of eigenvalues of m.
-        assertDiagonalConsistsOfEigenvalues(m, d, v);
-
-        // m = v d v^{-1} is equivalent to
-        // m v = v d
-        assertMatricesAreEqual(m.times(v), v.times(d));
-
-        assertEigenvalues(decomposition, expRealEigenValues);
-
-        decomposition.destroy();
-    }
-
-    /** */
-    private void assertEigenvalues(EigenDecomposition decomposition, double[] expRealEigenValues) {
-        Vector real = decomposition.getRealEigenValues();
-        Vector imag = decomposition.getImagEigenvalues();
-
-        assertEquals("Real values size differs from expected.", expRealEigenValues.length, real.size());
-        assertEquals("Imag values size differs from expected.", expRealEigenValues.length, imag.size());
-
-        for (int idx = 0; idx < expRealEigenValues.length; idx++) {
-            assertEquals("Real eigen value differs from expected at " + idx,
-                expRealEigenValues[idx], real.get(idx), 0d);
-
-            assertEquals("Imag eigen value differs from expected at " + idx,
-                0d, imag.get(idx), 0d);
-        }
-
-    }
-
-    /** */
-    private void assertDiagonalConsistsOfEigenvalues(DenseLocalOnHeapMatrix m, Matrix d, Matrix v) {
-        int n = m.columnSize();
-        for (int i = 0; i < n; i++) {
-            Vector eigenVector = v.viewColumn(i);
-            double eigenVal = d.getX(i, i);
-            assertVectorsAreEqual(m.times(eigenVector), eigenVector.times(eigenVal));
-        }
-
-    }
-
-    /** */
-    private void assertMatricesAreEqual(Matrix exp, Matrix actual) {
-        assertTrue("The row sizes of matrices are not equal", exp.rowSize() == actual.rowSize());
-        assertTrue("The col sizes of matrices are not equal", exp.columnSize() == actual.columnSize());
-
-        // Since matrix is square, we need only one dimension
-        int n = exp.columnSize();
-
-        for (int i = 0; i < n; i++)
-            for (int j = 0; j < n; j++)
-                assertEquals("Values should be equal", exp.getX(i, j), actual.getX(i, j), EPSILON);
-    }
-
-    /** */
-    private void assertVectorsAreEqual(Vector exp, Vector actual) {
-        assertTrue("Vectors sizes are not equal", exp.size() == actual.size());
-
-        // Since matrix is square, we need only one dimension
-        int n = exp.size();
-
-        for (int i = 0; i < n; i++)
-            assertEquals("Values should be equal", exp.getX(i), actual.getX(i), EPSILON);
-    }
-
-    /** */
-    private void assertIsDiagonalNonZero(Matrix m) {
-        assertIsDiagonal(m, false);
-    }
-
-    /** */
-    private void assertIsDiagonal(Matrix m, boolean zeroesAllowed) {
-        // Since matrix is square, we need only one dimension
-        int n = m.columnSize();
-
-        assertEquals("Diagonal matrix is not square", n, m.rowSize());
-
-        for (int i = 0; i < n; i++)
-            for (int j = 0; j < n; j++)
-                assertTrue("Matrix is not diagonal, violation at (" + i + "," + j + ")",
-                    ((i == j) && (zeroesAllowed || m.getX(i, j) != 0))
-                        || ((i != j) && m.getX(i, j) == 0));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java
deleted file mode 100644
index 0feb48f..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.SingularMatrixException;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.matrix.PivotedMatrixView;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Tests for {@link LUDecomposition}.
- */
-public class LUDecompositionTest {
-    /** */
-    private Matrix testL;
-    /** */
-    private Matrix testU;
-    /** */
-    private Matrix testP;
-    /** */
-    private Matrix testMatrix;
-    /** */
-    private int[] rawPivot;
-
-    /** */
-    @Before
-    public void setUp() {
-        double[][] rawMatrix = new double[][] {
-            {2.0d, 1.0d, 1.0d, 0.0d},
-            {4.0d, 3.0d, 3.0d, 1.0d},
-            {8.0d, 7.0d, 9.0d, 5.0d},
-            {6.0d, 7.0d, 9.0d, 8.0d}};
-        double[][] rawL = {
-            {1.0d, 0.0d, 0.0d, 0.0d},
-            {3.0d / 4.0d, 1.0d, 0.0d, 0.0d},
-            {1.0d / 2.0d, -2.0d / 7.0d, 1.0d, 0.0d},
-            {1.0d / 4.0d, -3.0d / 7.0d, 1.0d / 3.0d, 1.0d}};
-        double[][] rawU = {
-            {8.0d, 7.0d, 9.0d, 5.0d},
-            {0.0d, 7.0d / 4.0d, 9.0d / 4.0d, 17.0d / 4.0d},
-            {0.0d, 0.0d, -6.0d / 7.0d, -2.0d / 7.0d},
-            {0.0d, 0.0d, 0.0d, 2.0d / 3.0d}};
-        double[][] rawP = new double[][] {
-            {0, 0, 1.0d, 0},
-            {0, 0, 0, 1.0d},
-            {0, 1.0d, 0, 0},
-            {1.0d, 0, 0, 0}};
-
-        rawPivot = new int[] {3, 4, 2, 1};
-
-        testMatrix = new DenseLocalOnHeapMatrix(rawMatrix);
-        testL = new DenseLocalOnHeapMatrix(rawL);
-        testU = new DenseLocalOnHeapMatrix(rawU);
-        testP = new DenseLocalOnHeapMatrix(rawP);
-    }
-
-    /** */
-    @Test
-    public void getL() throws Exception {
-        Matrix luDecompositionL = new LUDecomposition(testMatrix).getL();
-
-        assertEquals("Unexpected row size.", testL.rowSize(), luDecompositionL.rowSize());
-        assertEquals("Unexpected column size.", testL.columnSize(), luDecompositionL.columnSize());
-
-        for (int i = 0; i < testL.rowSize(); i++)
-            for (int j = 0; j < testL.columnSize(); j++)
-                assertEquals("Unexpected value at (" + i + "," + j + ").",
-                    testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d);
-
-        luDecompositionL.destroy();
-    }
-
-    /** */
-    @Test
-    public void getU() throws Exception {
-        Matrix luDecompositionU = new LUDecomposition(testMatrix).getU();
-
-        assertEquals("Unexpected row size.", testU.rowSize(), luDecompositionU.rowSize());
-        assertEquals("Unexpected column size.", testU.columnSize(), luDecompositionU.columnSize());
-
-        for (int i = 0; i < testU.rowSize(); i++)
-            for (int j = 0; j < testU.columnSize(); j++)
-                assertEquals("Unexpected value at (" + i + "," + j + ").",
-                    testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d);
-
-        luDecompositionU.destroy();
-    }
-
-    /** */
-    @Test
-    public void getP() throws Exception {
-        Matrix luDecompositionP = new LUDecomposition(testMatrix).getP();
-
-        assertEquals("Unexpected row size.", testP.rowSize(), luDecompositionP.rowSize());
-        assertEquals("Unexpected column size.", testP.columnSize(), luDecompositionP.columnSize());
-
-        for (int i = 0; i < testP.rowSize(); i++)
-            for (int j = 0; j < testP.columnSize(); j++)
-                assertEquals("Unexpected value at (" + i + "," + j + ").",
-                    testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d);
-
-        luDecompositionP.destroy();
-    }
-
-    /** */
-    @Test
-    public void getPivot() throws Exception {
-        Vector pivot = new LUDecomposition(testMatrix).getPivot();
-
-        assertEquals("Unexpected pivot size.", rawPivot.length, pivot.size());
-
-        for (int i = 0; i < testU.rowSize(); i++)
-            assertEquals("Unexpected value at " + i, rawPivot[i], (int)pivot.get(i) + 1);
-    }
-
-    /**
-     * Test for {@link DecompositionSupport} features.
-     */
-    @Test
-    public void decompositionSupportTest() {
-        LUDecomposition dec = new LUDecomposition(new PivotedMatrixView(testMatrix));
-        Matrix luDecompositionL = dec.getL();
-
-        assertEquals("Unexpected L row size.", testL.rowSize(), luDecompositionL.rowSize());
-        assertEquals("Unexpected L column size.", testL.columnSize(), luDecompositionL.columnSize());
-
-        for (int i = 0; i < testL.rowSize(); i++)
-            for (int j = 0; j < testL.columnSize(); j++)
-                assertEquals("Unexpected L value at (" + i + "," + j + ").",
-                    testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d);
-
-        Matrix luDecompositionU = dec.getU();
-
-        assertEquals("Unexpected U row size.", testU.rowSize(), luDecompositionU.rowSize());
-        assertEquals("Unexpected U column size.", testU.columnSize(), luDecompositionU.columnSize());
-
-        for (int i = 0; i < testU.rowSize(); i++)
-            for (int j = 0; j < testU.columnSize(); j++)
-                assertEquals("Unexpected U value at (" + i + "," + j + ").",
-                    testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d);
-
-        Matrix luDecompositionP = dec.getP();
-
-        assertEquals("Unexpected P row size.", testP.rowSize(), luDecompositionP.rowSize());
-        assertEquals("Unexpected P column size.", testP.columnSize(), luDecompositionP.columnSize());
-
-        for (int i = 0; i < testP.rowSize(); i++)
-            for (int j = 0; j < testP.columnSize(); j++)
-                assertEquals("Unexpected P value at (" + i + "," + j + ").",
-                    testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d);
-
-        dec.destroy();
-    }
-
-    /** */
-    @Test
-    public void singularDeterminant() throws Exception {
-        assertEquals("Unexpected determinant for singular matrix decomposition.",
-            0d, new LUDecomposition(new DenseLocalOnHeapMatrix(2, 2)).determinant(), 0d);
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void solveVecWrongSize() throws Exception {
-        new LUDecomposition(testMatrix).solve(new DenseLocalOnHeapVector(testMatrix.rowSize() + 1));
-    }
-
-    /** */
-    @Test(expected = SingularMatrixException.class)
-    public void solveVecSingularMatrix() throws Exception {
-        new LUDecomposition(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()))
-            .solve(new DenseLocalOnHeapVector(testMatrix.rowSize()));
-    }
-
-    /** */
-    @Test
-    public void solveVec() throws Exception {
-        Vector sol = new LUDecomposition(new PivotedMatrixView(testMatrix))
-            .solve(new DenseLocalOnHeapVector(testMatrix.rowSize()));
-
-        assertEquals("Wrong solution vector size.", testMatrix.rowSize(), sol.size());
-
-        for (int i = 0; i < sol.size(); i++)
-            assertEquals("Unexpected value at index " + i, 0d, sol.getX(i), 0.0000001d);
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void solveMtxWrongSize() throws Exception {
-        new LUDecomposition(testMatrix).solve(
-            new DenseLocalOnHeapMatrix(testMatrix.rowSize() + 1, testMatrix.rowSize()));
-    }
-
-    /** */
-    @Test(expected = SingularMatrixException.class)
-    public void solveMtxSingularMatrix() throws Exception {
-        new LUDecomposition(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()))
-            .solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()));
-    }
-
-    /** */
-    @Test
-    public void solveMtx() throws Exception {
-        Matrix sol = new LUDecomposition(new PivotedMatrixView(testMatrix))
-            .solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()));
-
-        assertEquals("Wrong solution matrix row size.", testMatrix.rowSize(), sol.rowSize());
-
-        assertEquals("Wrong solution matrix column size.", testMatrix.rowSize(), sol.columnSize());
-
-        for (int row = 0; row < sol.rowSize(); row++)
-            for (int col = 0; col < sol.columnSize(); col++)
-                assertEquals("Unexpected P value at (" + row + "," + col + ").",
-                    0d, sol.getX(row, col), 0.0000001d);
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullMatrixTest() {
-        new LUDecomposition(null);
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void nonSquareMatrixTest() {
-        new LUDecomposition(new DenseLocalOnHeapMatrix(2, 3));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java
deleted file mode 100644
index 3bb92d1..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.matrix.PivotedMatrixView;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class QRDecompositionTest {
-    /** */
-    @Test
-    public void basicTest() {
-        basicTest(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        }));
-    }
-
-    /**
-     * Test for {@link DecompositionSupport} features.
-     */
-    @Test
-    public void decompositionSupportTest() {
-        basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        })));
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullMatrixTest() {
-        new QRDecomposition(null);
-    }
-
-    /** */
-    @Test(expected = IllegalArgumentException.class)
-    public void solveWrongMatrixSizeTest() {
-        new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        })).solve(new DenseLocalOnHeapMatrix(2, 3));
-    }
-
-    /** */
-    private void basicTest(Matrix m) {
-        QRDecomposition dec = new QRDecomposition(m);
-        assertTrue("Unexpected value for full rank in decomposition " + dec, dec.hasFullRank());
-
-        Matrix q = dec.getQ();
-        Matrix r = dec.getR();
-
-        assertNotNull("Matrix q is expected to be not null.", q);
-        assertNotNull("Matrix r is expected to be not null.", r);
-
-        Matrix qSafeCp = safeCopy(q);
-
-        Matrix expIdentity = qSafeCp.times(qSafeCp.transpose());
-
-        final double delta = 0.0001;
-
-        for (int row = 0; row < expIdentity.rowSize(); row++)
-            for (int col = 0; col < expIdentity.columnSize(); col++)
-                assertEquals("Unexpected identity matrix value at (" + row + "," + col + ").",
-                    row == col ? 1d : 0d, expIdentity.get(col, row), delta);
-
-        for (int row = 0; row < r.rowSize(); row++)
-            for (int col = 0; col < row - 1; col++)
-                assertEquals("Unexpected upper triangular matrix value at (" + row + "," + col + ").",
-                    0d, r.get(row, col), delta);
-
-        Matrix recomposed = qSafeCp.times(r);
-
-        for (int row = 0; row < m.rowSize(); row++)
-            for (int col = 0; col < m.columnSize(); col++)
-                assertEquals("Unexpected recomposed matrix value at (" + row + "," + col + ").",
-                    m.get(row, col), recomposed.get(row, col), delta);
-
-        Matrix sol = dec.solve(new DenseLocalOnHeapMatrix(3, 10));
-        assertEquals("Unexpected rows in solution matrix.", 3, sol.rowSize());
-        assertEquals("Unexpected cols in solution matrix.", 10, sol.columnSize());
-
-        for (int row = 0; row < sol.rowSize(); row++)
-            for (int col = 0; col < sol.columnSize(); col++)
-                assertEquals("Unexpected solution matrix value at (" + row + "," + col + ").",
-                    0d, sol.get(row, col), delta);
-
-        dec.destroy();
-
-        QRDecomposition dec1 = new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d},
-            {-1.0d, 2.0d},
-            {0.0d, -1.0d}
-        }));
-
-        assertTrue("Unexpected value for full rank in decomposition " + dec1, dec1.hasFullRank());
-
-        dec1.destroy();
-
-        QRDecomposition dec2 = new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d, 0.0d},
-            {0.0d, -1.0d, 2.0d, 0.0d}
-        }));
-
-        assertTrue("Unexpected value for full rank in decomposition " + dec2, dec2.hasFullRank());
-
-        dec2.destroy();
-    }
-
-    /** */
-    private Matrix safeCopy(Matrix orig) {
-        return new DenseLocalOnHeapMatrix(orig.rowSize(), orig.columnSize()).assign(orig);
-    }
-}


[04/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationsTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationsTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationsTest.java
new file mode 100644
index 0000000..c827037
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationsTest.java
@@ -0,0 +1,1113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.ColumnIndexException;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.exceptions.RowIndexException;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.apache.ignite.ml.math.impls.vector.RandomVector;
+import org.apache.ignite.ml.math.impls.vector.SparseLocalVector;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@link Matrix} implementations.
+ */
+public class MatrixImplementationsTest extends ExternalizeTest<Matrix> {
+    /** */
+    private static final double DEFAULT_DELTA = 0.000000001d;
+
+    /** */
+    private void consumeSampleMatrix(BiConsumer<Matrix, String> consumer) {
+        new MatrixImplementationFixtures().consumeSampleMatrix(consumer);
+    }
+
+    /** */
+    @Test
+    public void externalizeTest() {
+        consumeSampleMatrix((m, desc) -> externalizeTest(m));
+    }
+
+    /** */
+    @Test
+    public void testLike() {
+        consumeSampleMatrix((m, desc) -> {
+            Class<? extends Matrix> cls = likeMatrixType(m);
+
+            if (cls != null) {
+                Matrix like = m.like(m.rowSize(), m.columnSize());
+
+                assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected rows.", like.rowSize(), m.rowSize());
+                assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected columns.", like.columnSize(), m.columnSize());
+
+                assertEquals("Wrong \"like\" matrix for " + desc
+                        + "; Unexpected class: " + like.getClass().toString(),
+                    cls,
+                    like.getClass());
+
+                return;
+            }
+
+            boolean expECaught = false;
+
+            try {
+                m.like(1, 1);
+            }
+            catch (UnsupportedOperationException uoe) {
+                expECaught = true;
+            }
+
+            assertTrue("Expected exception was not caught for " + desc, expECaught);
+        });
+    }
+
+    /** */
+    @Test
+    public void testCopy() {
+        consumeSampleMatrix((m, desc) -> {
+            Matrix cp = m.copy();
+            assertTrue("Incorrect copy for empty matrix " + desc, cp.equals(m));
+
+            if (!readOnly(m))
+                fillMatrix(m);
+
+            cp = m.copy();
+
+            assertTrue("Incorrect copy for matrix " + desc, cp.equals(m));
+        });
+    }
+
+    /** */
+    @Test
+    public void testHaveLikeVector() throws InstantiationException, IllegalAccessException {
+        for (Class<? extends Matrix> key : likeVectorTypesMap().keySet()) {
+            Class<? extends Vector> val = likeVectorTypesMap().get(key);
+
+            if (val == null && !ignore(key))
+                System.out.println("Missing test for implementation of likeMatrix for " + key.getSimpleName());
+        }
+    }
+
+    /** */
+    @Test
+    public void testLikeVector() {
+        consumeSampleMatrix((m, desc) -> {
+            if (likeVectorTypesMap().containsKey(m.getClass())) {
+                Vector likeVector = m.likeVector(m.columnSize());
+
+                assertNotNull(likeVector);
+                assertEquals("Unexpected value for " + desc, likeVector.size(), m.columnSize());
+
+                return;
+            }
+
+            boolean expECaught = false;
+
+            try {
+                m.likeVector(1);
+            }
+            catch (UnsupportedOperationException uoe) {
+                expECaught = true;
+            }
+
+            assertTrue("Expected exception was not caught for " + desc, expECaught);
+        });
+    }
+
+    /** */
+    @Test
+    public void testAssignSingleElement() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            final double assignVal = Math.random();
+
+            m.assign(assignVal);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        assignVal, m.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testAssignArray() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] data = new double[m.rowSize()][m.columnSize()];
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    data[i][j] = Math.random();
+
+            m.assign(data);
+
+            for (int i = 0; i < m.rowSize(); i++) {
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        data[i][j], m.get(i, j), 0d);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testAssignFunction() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            m.assign((i, j) -> (double)(i * m.columnSize() + j));
+
+            for (int i = 0; i < m.rowSize(); i++) {
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        (double)(i * m.columnSize() + j), m.get(i, j), 0d);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testPlus() {
+        consumeSampleMatrix((m, desc) -> {
+            if (readOnly(m))
+                return;
+
+            double[][] data = fillAndReturn(m);
+
+            double plusVal = Math.random();
+
+            Matrix plus = m.plus(plusVal);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        data[i][j] + plusVal, plus.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testPlusMatrix() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] data = fillAndReturn(m);
+
+            Matrix plus = m.plus(m);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        data[i][j] * 2.0, plus.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testMinusMatrix() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            Matrix minus = m.minus(m);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        0.0, minus.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testTimes() {
+        consumeSampleMatrix((m, desc) -> {
+            if (readOnly(m))
+                return;
+
+            double[][] data = fillAndReturn(m);
+
+            double timeVal = Math.random();
+            Matrix times = m.times(timeVal);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        data[i][j] * timeVal, times.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testTimesVector() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] data = fillAndReturn(m);
+
+            double[] arr = fillArray(m.columnSize());
+
+            Vector times = m.times(new DenseLocalOnHeapVector(arr));
+
+            assertEquals("Unexpected vector size for " + desc, times.size(), m.rowSize());
+
+            for (int i = 0; i < m.rowSize(); i++) {
+                double exp = 0.0;
+
+                for (int j = 0; j < m.columnSize(); j++)
+                    exp += arr[j] * data[i][j];
+
+                assertEquals("Unexpected value for " + desc + " at " + i,
+                    times.get(i), exp, 0d);
+            }
+
+            testInvalidCardinality(() -> m.times(new DenseLocalOnHeapVector(m.columnSize() + 1)), desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void testTimesMatrix() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] data = fillAndReturn(m);
+
+            double[] arr = fillArray(m.columnSize());
+
+            Matrix mult = new DenseLocalOnHeapMatrix(m.columnSize(), 1);
+
+            mult.setColumn(0, arr);
+
+            Matrix times = m.times(mult);
+
+            assertEquals("Unexpected rows for " + desc, times.rowSize(), m.rowSize());
+
+            assertEquals("Unexpected cols for " + desc, times.columnSize(), 1);
+
+            for (int i = 0; i < m.rowSize(); i++) {
+                double exp = 0.0;
+
+                for (int j = 0; j < m.columnSize(); j++)
+                    exp += arr[j] * data[i][j];
+
+                assertEquals("Unexpected value for " + desc + " at " + i,
+                    exp, times.get(i, 0), 0d);
+            }
+
+            testInvalidCardinality(() -> m.times(new DenseLocalOnHeapMatrix(m.columnSize() + 1, 1)), desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void testDivide() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] data = fillAndReturn(m);
+
+            double divVal = Math.random();
+
+            Matrix divide = m.divide(divVal);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        data[i][j] / divVal, divide.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testTranspose() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            Matrix transpose = m.transpose();
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        m.get(i, j), transpose.get(j, i), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testDeterminant() {
+        consumeSampleMatrix((m, desc) -> {
+            if (m.rowSize() != m.columnSize())
+                return;
+
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] doubles = fillIntAndReturn(m);
+
+            if (m.rowSize() == 1) {
+                assertEquals("Unexpected value " + desc, m.determinant(), doubles[0][0], 0d);
+
+                return;
+            }
+
+            if (m.rowSize() == 2) {
+                double det = doubles[0][0] * doubles[1][1] - doubles[0][1] * doubles[1][0];
+                assertEquals("Unexpected value " + desc, m.determinant(), det, 0d);
+
+                return;
+            }
+
+            if (m.rowSize() > 512)
+                return; // IMPL NOTE if row size >= 30000 it takes unacceptably long for normal test run.
+
+            Matrix diagMtx = m.like(m.rowSize(), m.columnSize());
+
+            diagMtx.assign(0);
+            for (int i = 0; i < m.rowSize(); i++)
+                diagMtx.set(i, i, m.get(i, i));
+
+            double det = 1;
+
+            for (int i = 0; i < diagMtx.rowSize(); i++)
+                det *= diagMtx.get(i, i);
+
+            try {
+                assertEquals("Unexpected value " + desc, det, diagMtx.determinant(), DEFAULT_DELTA);
+            }
+            catch (Exception e) {
+                System.out.println(desc);
+                throw e;
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testInverse() {
+        consumeSampleMatrix((m, desc) -> {
+            if (m.rowSize() != m.columnSize())
+                return;
+
+            if (ignore(m.getClass()))
+                return;
+
+            if (m.rowSize() > 256)
+                return; // IMPL NOTE this is for quicker test run.
+
+            fillNonSingularMatrix(m);
+
+            assertTrue("Unexpected zero determinant " + desc, Math.abs(m.determinant()) > 0d);
+
+            Matrix inverse = m.inverse();
+
+            Matrix mult = m.times(inverse);
+
+            final double delta = 0.001d;
+
+            assertEquals("Unexpected determinant " + desc, 1d, mult.determinant(), delta);
+
+            assertEquals("Unexpected top left value " + desc, 1d, mult.get(0, 0), delta);
+
+            if (m.rowSize() == 1)
+                return;
+
+            assertEquals("Unexpected center value " + desc,
+                1d, mult.get(m.rowSize() / 2, m.rowSize() / 2), delta);
+
+            assertEquals("Unexpected bottom right value " + desc,
+                1d, mult.get(m.rowSize() - 1, m.rowSize() - 1), delta);
+
+            assertEquals("Unexpected top right value " + desc,
+                0d, mult.get(0, m.rowSize() - 1), delta);
+
+            assertEquals("Unexpected bottom left value " + desc,
+                0d, mult.get(m.rowSize() - 1, 0), delta);
+        });
+    }
+
+    /** */
+    @Test
+    public void testMap() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            m.map(x -> 10d);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        10d, m.get(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testMapMatrix() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            double[][] doubles = fillAndReturn(m);
+
+            testMapMatrixWrongCardinality(m, desc);
+
+            Matrix cp = m.copy();
+
+            m.map(cp, (m1, m2) -> m1 + m2);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        m.get(i, j), doubles[i][j] * 2, 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testViewRow() {
+        consumeSampleMatrix((m, desc) -> {
+            if (!readOnly(m))
+                fillMatrix(m);
+
+            for (int i = 0; i < m.rowSize(); i++) {
+                Vector vector = m.viewRow(i);
+                assert vector != null;
+
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        m.get(i, j), vector.get(j), 0d);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testViewCol() {
+        consumeSampleMatrix((m, desc) -> {
+            if (!readOnly(m))
+                fillMatrix(m);
+
+            for (int i = 0; i < m.columnSize(); i++) {
+                Vector vector = m.viewColumn(i);
+                assert vector != null;
+
+                for (int j = 0; j < m.rowSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
+                        m.get(j, i), vector.get(j), 0d);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testFoldRow() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            Vector foldRows = m.foldRows(Vector::sum);
+
+            for (int i = 0; i < m.rowSize(); i++) {
+                Double locSum = 0d;
+
+                for (int j = 0; j < m.columnSize(); j++)
+                    locSum += m.get(i, j);
+
+                assertEquals("Unexpected value for " + desc + " at " + i,
+                    foldRows.get(i), locSum, 0d);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testFoldCol() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            Vector foldCols = m.foldColumns(Vector::sum);
+
+            for (int j = 0; j < m.columnSize(); j++) {
+                Double locSum = 0d;
+
+                for (int i = 0; i < m.rowSize(); i++)
+                    locSum += m.get(i, j);
+
+                assertEquals("Unexpected value for " + desc + " at " + j,
+                    foldCols.get(j), locSum, 0d);
+            }
+        });
+    }
+
+    /** */
+    @Test
+    public void testSum() {
+        consumeSampleMatrix((m, desc) -> {
+            double[][] data = fillAndReturn(m);
+
+            double sum = m.sum();
+
+            double rawSum = 0;
+            for (double[] anArr : data)
+                for (int j = 0; j < data[0].length; j++)
+                    rawSum += anArr[j];
+
+            assertEquals("Unexpected value for " + desc,
+                rawSum, sum, 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testMax() {
+        consumeSampleMatrix((m, desc) -> {
+            double[][] doubles = fillAndReturn(m);
+            double max = Double.NEGATIVE_INFINITY;
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    max = max < doubles[i][j] ? doubles[i][j] : max;
+
+            assertEquals("Unexpected value for " + desc, m.maxValue(), max, 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testMin() {
+        consumeSampleMatrix((m, desc) -> {
+            double[][] doubles = fillAndReturn(m);
+            double min = Double.MAX_VALUE;
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    min = min > doubles[i][j] ? doubles[i][j] : min;
+
+            assertEquals("Unexpected value for " + desc, m.minValue(), min, 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testGetElement() {
+        consumeSampleMatrix((m, desc) -> {
+            if (!(readOnly(m)))
+                fillMatrix(m);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++) {
+                    final Matrix.Element e = m.getElement(i, j);
+
+                    final String details = desc + " at [" + i + "," + j + "]";
+
+                    assertEquals("Unexpected element row " + details, i, e.row());
+                    assertEquals("Unexpected element col " + details, j, e.column());
+
+                    final double val = m.get(i, j);
+
+                    assertEquals("Unexpected value for " + details, val, e.get(), 0d);
+
+                    boolean expECaught = false;
+
+                    final double newVal = val * 2.0;
+
+                    try {
+                        e.set(newVal);
+                    }
+                    catch (UnsupportedOperationException uoe) {
+                        if (!(readOnly(m)))
+                            throw uoe;
+
+                        expECaught = true;
+                    }
+
+                    if (readOnly(m)) {
+                        if (!expECaught)
+                            fail("Expected exception was not caught for " + details);
+
+                        continue;
+                    }
+
+                    assertEquals("Unexpected value set for " + details, newVal, m.get(i, j), 0d);
+                }
+        });
+    }
+
+    /** */
+    @Test
+    public void testGetX() {
+        consumeSampleMatrix((m, desc) -> {
+            if (!(readOnly(m)))
+                fillMatrix(m);
+
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    assertEquals("Unexpected value for " + desc + " at [" + i + "," + j + "]",
+                        m.get(i, j), m.getX(i, j), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testGetMetaStorage() {
+        consumeSampleMatrix((m, desc) -> assertNotNull("Null meta storage in " + desc, m.getMetaStorage()));
+    }
+
+    /** */
+    @Test
+    public void testGuid() {
+        consumeSampleMatrix((m, desc) -> assertNotNull("Null guid in " + desc, m.guid()));
+    }
+
+    /** */
+    @Test
+    public void testSwapRows() {
+        consumeSampleMatrix((m, desc) -> {
+            if (readOnly(m))
+                return;
+
+            double[][] doubles = fillAndReturn(m);
+
+            final int swap_i = m.rowSize() == 1 ? 0 : 1;
+            final int swap_j = 0;
+
+            Matrix swap = m.swapRows(swap_i, swap_j);
+
+            for (int col = 0; col < m.columnSize(); col++) {
+                assertEquals("Unexpected value for " + desc + " at col " + col + ", swap_i " + swap_i,
+                    swap.get(swap_i, col), doubles[swap_j][col], 0d);
+
+                assertEquals("Unexpected value for " + desc + " at col " + col + ", swap_j " + swap_j,
+                    swap.get(swap_j, col), doubles[swap_i][col], 0d);
+            }
+
+            testInvalidRowIndex(() -> m.swapRows(-1, 0), desc + " negative first swap index");
+            testInvalidRowIndex(() -> m.swapRows(0, -1), desc + " negative second swap index");
+            testInvalidRowIndex(() -> m.swapRows(m.rowSize(), 0), desc + " too large first swap index");
+            testInvalidRowIndex(() -> m.swapRows(0, m.rowSize()), desc + " too large second swap index");
+        });
+    }
+
+    /** */
+    @Test
+    public void testSwapColumns() {
+        consumeSampleMatrix((m, desc) -> {
+            if (readOnly(m))
+                return;
+
+            double[][] doubles = fillAndReturn(m);
+
+            final int swap_i = m.columnSize() == 1 ? 0 : 1;
+            final int swap_j = 0;
+
+            Matrix swap = m.swapColumns(swap_i, swap_j);
+
+            for (int row = 0; row < m.rowSize(); row++) {
+                assertEquals("Unexpected value for " + desc + " at row " + row + ", swap_i " + swap_i,
+                    swap.get(row, swap_i), doubles[row][swap_j], 0d);
+
+                assertEquals("Unexpected value for " + desc + " at row " + row + ", swap_j " + swap_j,
+                    swap.get(row, swap_j), doubles[row][swap_i], 0d);
+            }
+
+            testInvalidColIndex(() -> m.swapColumns(-1, 0), desc + " negative first swap index");
+            testInvalidColIndex(() -> m.swapColumns(0, -1), desc + " negative second swap index");
+            testInvalidColIndex(() -> m.swapColumns(m.columnSize(), 0), desc + " too large first swap index");
+            testInvalidColIndex(() -> m.swapColumns(0, m.columnSize()), desc + " too large second swap index");
+        });
+    }
+
+    /** */
+    @Test
+    public void testSetRow() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            int rowIdx = m.rowSize() / 2;
+
+            double[] newValues = fillArray(m.columnSize());
+
+            m.setRow(rowIdx, newValues);
+
+            for (int col = 0; col < m.columnSize(); col++)
+                assertEquals("Unexpected value for " + desc + " at " + col,
+                    newValues[col], m.get(rowIdx, col), 0d);
+
+            testInvalidCardinality(() -> m.setRow(rowIdx, new double[m.columnSize() + 1]), desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void testSetColumn() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            int colIdx = m.columnSize() / 2;
+
+            double[] newValues = fillArray(m.rowSize());
+
+            m.setColumn(colIdx, newValues);
+
+            for (int row = 0; row < m.rowSize(); row++)
+                assertEquals("Unexpected value for " + desc + " at " + row,
+                    newValues[row], m.get(row, colIdx), 0d);
+
+            testInvalidCardinality(() -> m.setColumn(colIdx, new double[m.rowSize() + 1]), desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void testViewPart() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            int rowOff = m.rowSize() < 3 ? 0 : 1;
+            int rows = m.rowSize() < 3 ? 1 : m.rowSize() - 2;
+            int colOff = m.columnSize() < 3 ? 0 : 1;
+            int cols = m.columnSize() < 3 ? 1 : m.columnSize() - 2;
+
+            Matrix view1 = m.viewPart(rowOff, rows, colOff, cols);
+            Matrix view2 = m.viewPart(new int[] {rowOff, colOff}, new int[] {rows, cols});
+
+            String details = desc + " view [" + rowOff + ", " + rows + ", " + colOff + ", " + cols + "]";
+
+            for (int i = 0; i < rows; i++)
+                for (int j = 0; j < cols; j++) {
+                    assertEquals("Unexpected view1 value for " + details + " at (" + i + "," + j + ")",
+                        m.get(i + rowOff, j + colOff), view1.get(i, j), 0d);
+
+                    assertEquals("Unexpected view2 value for " + details + " at (" + i + "," + j + ")",
+                        m.get(i + rowOff, j + colOff), view2.get(i, j), 0d);
+                }
+        });
+    }
+
+    /** */
+    @Test
+    public void testDensity() {
+        consumeSampleMatrix((m, desc) -> {
+            if (!readOnly(m))
+                fillMatrix(m);
+
+            assertTrue("Unexpected density with threshold 0 for " + desc, m.density(0.0));
+
+            assertFalse("Unexpected density with threshold 1 for " + desc, m.density(1.0));
+        });
+    }
+
+    /** */
+    @Test
+    public void testMaxAbsRowSumNorm() {
+        consumeSampleMatrix((m, desc) -> {
+            if (!readOnly(m))
+                fillMatrix(m);
+
+            assertEquals("Unexpected value for " + desc,
+                maxAbsRowSumNorm(m), m.maxAbsRowSumNorm(), 0d);
+        });
+    }
+
+    /** */
+    @Test
+    public void testAssignRow() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            int rowIdx = m.rowSize() / 2;
+
+            double[] newValues = fillArray(m.columnSize());
+
+            m.assignRow(rowIdx, new DenseLocalOnHeapVector(newValues));
+
+            for (int col = 0; col < m.columnSize(); col++)
+                assertEquals("Unexpected value for " + desc + " at " + col,
+                    newValues[col], m.get(rowIdx, col), 0d);
+
+            testInvalidCardinality(() -> m.assignRow(rowIdx, new DenseLocalOnHeapVector(m.columnSize() + 1)), desc);
+        });
+    }
+
+    /** */
+    @Test
+    public void testAssignColumn() {
+        consumeSampleMatrix((m, desc) -> {
+            if (ignore(m.getClass()))
+                return;
+
+            fillMatrix(m);
+
+            int colIdx = m.columnSize() / 2;
+
+            double[] newValues = fillArray(m.rowSize());
+
+            m.assignColumn(colIdx, new DenseLocalOnHeapVector(newValues));
+
+            for (int row = 0; row < m.rowSize(); row++)
+                assertEquals("Unexpected value for " + desc + " at " + row,
+                    newValues[row], m.get(row, colIdx), 0d);
+        });
+    }
+
+    /** */
+    private double[] fillArray(int len) {
+        double[] newValues = new double[len];
+
+        for (int i = 0; i < newValues.length; i++)
+            newValues[i] = newValues.length - i;
+        return newValues;
+    }
+
+    /** */
+    private double maxAbsRowSumNorm(Matrix m) {
+        double max = 0.0;
+
+        for (int x = 0; x < m.rowSize(); x++) {
+            double sum = 0;
+
+            for (int y = 0; y < m.columnSize(); y++)
+                sum += Math.abs(m.getX(x, y));
+
+            if (sum > max)
+                max = sum;
+        }
+
+        return max;
+    }
+
+    /** */
+    private void testInvalidRowIndex(Supplier<Matrix> supplier, String desc) {
+        try {
+            supplier.get();
+        }
+        catch (RowIndexException | IndexException ie) {
+            return;
+        }
+
+        fail("Expected exception was not caught for " + desc);
+    }
+
+    /** */
+    private void testInvalidColIndex(Supplier<Matrix> supplier, String desc) {
+        try {
+            supplier.get();
+        }
+        catch (ColumnIndexException | IndexException ie) {
+            return;
+        }
+
+        fail("Expected exception was not caught for " + desc);
+    }
+
+    /** */
+    private void testMapMatrixWrongCardinality(Matrix m, String desc) {
+        for (int rowDelta : new int[] {-1, 0, 1})
+            for (int colDelta : new int[] {-1, 0, 1}) {
+                if (rowDelta == 0 && colDelta == 0)
+                    continue;
+
+                int rowNew = m.rowSize() + rowDelta;
+                int colNew = m.columnSize() + colDelta;
+
+                if (rowNew < 1 || colNew < 1)
+                    continue;
+
+                testInvalidCardinality(() -> m.map(new DenseLocalOnHeapMatrix(rowNew, colNew), (m1, m2) -> m1 + m2),
+                    desc + " wrong cardinality when mapping to size " + rowNew + "x" + colNew);
+            }
+    }
+
+    /** */
+    private void testInvalidCardinality(Supplier<Object> supplier, String desc) {
+        try {
+            supplier.get();
+        }
+        catch (CardinalityException ce) {
+            return;
+        }
+
+        fail("Expected exception was not caught for " + desc);
+    }
+
+    /** */
+    private boolean readOnly(Matrix m) {
+        return m instanceof RandomMatrix;
+    }
+
+    /** */
+    private double[][] fillIntAndReturn(Matrix m) {
+        double[][] data = new double[m.rowSize()][m.columnSize()];
+
+        if (readOnly(m)) {
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    data[i][j] = m.get(i, j);
+
+        }
+        else {
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    data[i][j] = i * m.rowSize() + j + 1;
+
+            m.assign(data);
+        }
+        return data;
+    }
+
+    /** */
+    private double[][] fillAndReturn(Matrix m) {
+        double[][] data = new double[m.rowSize()][m.columnSize()];
+
+        if (readOnly(m)) {
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    data[i][j] = m.get(i, j);
+
+        }
+        else {
+            for (int i = 0; i < m.rowSize(); i++)
+                for (int j = 0; j < m.columnSize(); j++)
+                    data[i][j] = -0.5d + Math.random();
+
+            m.assign(data);
+        }
+        return data;
+    }
+
+    /** */
+    private void fillNonSingularMatrix(Matrix m) {
+        for (int i = 0; i < m.rowSize(); i++) {
+            m.set(i, i, 10);
+
+            for (int j = 0; j < m.columnSize(); j++)
+                if (j != i)
+                    m.set(i, j, 0.01d);
+        }
+    }
+
+    /** */
+    private void fillMatrix(Matrix m) {
+        for (int i = 0; i < m.rowSize(); i++)
+            for (int j = 0; j < m.columnSize(); j++)
+                m.set(i, j, Math.random());
+    }
+
+    /** Ignore test for given matrix type. */
+    private boolean ignore(Class<? extends Matrix> clazz) {
+        List<Class<? extends Matrix>> ignoredClasses = Arrays.asList(RandomMatrix.class, PivotedMatrixView.class,
+            MatrixView.class, FunctionMatrix.class, TransposedMatrixView.class);
+
+        for (Class<? extends Matrix> ignoredClass : ignoredClasses)
+            if (ignoredClass.isAssignableFrom(clazz))
+                return true;
+
+        return false;
+    }
+
+    /** */
+    private Class<? extends Matrix> likeMatrixType(Matrix m) {
+        for (Class<? extends Matrix> clazz : likeTypesMap().keySet())
+            if (clazz.isAssignableFrom(m.getClass()))
+                return likeTypesMap().get(clazz);
+
+        return null;
+    }
+
+    /** */
+    private static Map<Class<? extends Matrix>, Class<? extends Vector>> likeVectorTypesMap() {
+        return new LinkedHashMap<Class<? extends Matrix>, Class<? extends Vector>>() {{
+            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapVector.class);
+            put(DenseLocalOffHeapMatrix.class, DenseLocalOffHeapVector.class);
+            put(RandomMatrix.class, RandomVector.class);
+            put(SparseLocalOnHeapMatrix.class, SparseLocalVector.class);
+            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapVector.class);
+            put(DiagonalMatrix.class, DenseLocalOnHeapVector.class); // IMPL NOTE per fixture
+            // IMPL NOTE check for presence of all implementations here will be done in testHaveLikeMatrix via Fixture
+        }};
+    }
+
+    /** */
+    private static Map<Class<? extends Matrix>, Class<? extends Matrix>> likeTypesMap() {
+        return new LinkedHashMap<Class<? extends Matrix>, Class<? extends Matrix>>() {{
+            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapMatrix.class);
+            put(DenseLocalOffHeapMatrix.class, DenseLocalOffHeapMatrix.class);
+            put(RandomMatrix.class, RandomMatrix.class);
+            put(SparseLocalOnHeapMatrix.class, SparseLocalOnHeapMatrix.class);
+            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapMatrix.class);
+            put(DiagonalMatrix.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
+            put(FunctionMatrix.class, FunctionMatrix.class);
+            // IMPL NOTE check for presence of all implementations here will be done in testHaveLikeMatrix via Fixture
+        }};
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixKeyMapperForTests.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixKeyMapperForTests.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixKeyMapperForTests.java
new file mode 100644
index 0000000..bc628c9
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixKeyMapperForTests.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.MatrixKeyMapper;
+
+/** */
+public class MatrixKeyMapperForTests implements MatrixKeyMapper<Integer> {
+    /** */ private int rows;
+    /** */ private int cols;
+
+    /** */
+    public MatrixKeyMapperForTests() {
+        // No-op.
+    }
+
+    /** */
+    public MatrixKeyMapperForTests(int rows, int cols) {
+        this.rows = rows;
+        this.cols = cols;
+    }
+
+    /** */
+    @Override public Integer apply(int x, int y) {
+        return x * cols + y;
+    }
+
+    /** */
+    @Override public boolean isValid(Integer integer) {
+        return (rows * cols) > integer;
+    }
+
+    /** */
+    @Override public int hashCode() {
+        int hash = 1;
+
+        hash += hash * 31 + rows;
+        hash += hash * 31 + cols;
+
+        return hash;
+    }
+
+    /** */
+    @Override public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        MatrixKeyMapperForTests that = (MatrixKeyMapperForTests)obj;
+
+        return rows == that.rows && cols == that.cols;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixViewConstructorTest.java
new file mode 100644
index 0000000..82564cb
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixViewConstructorTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.storage.matrix.MatrixDelegateStorage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class MatrixViewConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        Matrix m = new DenseLocalOnHeapMatrix(1, 1);
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView((Matrix)null, 0, 0, 1, 1),
+            "Null parent matrix.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, -1, 0, 1, 1),
+            "Invalid row offset.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, 0, -1, 1, 1),
+            "Invalid col offset.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, 0, 0, 0, 1),
+            "Invalid rows.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, 0, 0, 1, 0),
+            "Invalid cols.");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        for (Matrix m : new Matrix[] {
+            new DenseLocalOnHeapMatrix(3, 3),
+            new DenseLocalOnHeapMatrix(3, 4), new DenseLocalOnHeapMatrix(4, 3)})
+            for (int rowOff : new int[] {0, 1})
+                for (int colOff : new int[] {0, 1})
+                    for (int rows : new int[] {1, 2})
+                        for (int cols : new int[] {1, 2})
+                            basicTest(m, rowOff, colOff, rows, cols);
+    }
+
+    /** */
+    private void basicTest(Matrix parent, int rowOff, int colOff, int rows, int cols) {
+        for (int row = 0; row < parent.rowSize(); row++)
+            for (int col = 0; col < parent.columnSize(); col++)
+                parent.set(row, col, row * parent.columnSize() + col + 1);
+
+        Matrix view = new MatrixView(parent, rowOff, colOff, rows, cols);
+
+        assertEquals("Rows in view.", rows, view.rowSize());
+        assertEquals("Cols in view.", cols, view.columnSize());
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++)
+                assertEquals("Unexpected value at " + row + "x" + col,
+                    parent.get(row + rowOff, col + colOff), view.get(row, col), 0d);
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++)
+                view.set(row, col, 0d);
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++)
+                assertEquals("Unexpected value set at " + row + "x" + col,
+                    0d, parent.get(row + rowOff, col + colOff), 0d);
+    }
+
+    /** */
+    @Test
+    public void attributeTest() {
+        for (Matrix m : new Matrix[] {
+            new DenseLocalOnHeapMatrix(3, 3),
+            new DenseLocalOnHeapMatrix(3, 4), new DenseLocalOnHeapMatrix(4, 3)}) {
+            MatrixView matrixView = new MatrixView(m, 0, 0, m.rowSize(), m.columnSize());
+
+            MatrixDelegateStorage delegateStorage = (MatrixDelegateStorage)matrixView.getStorage();
+
+            assertEquals(m.rowSize(), matrixView.rowSize());
+            assertEquals(m.columnSize(), matrixView.columnSize());
+
+            assertEquals(m.rowSize(), (delegateStorage).rowsLength());
+            assertEquals(m.columnSize(), (delegateStorage).columnsLength());
+
+            assertEquals(m.isSequentialAccess(), delegateStorage.isSequentialAccess());
+            assertEquals(m.isRandomAccess(), delegateStorage.isRandomAccess());
+            assertEquals(m.isDistributed(), delegateStorage.isDistributed());
+            assertEquals(m.isDense(), delegateStorage.isDense());
+            assertEquals(m.isArrayBased(), delegateStorage.isArrayBased());
+
+            assertArrayEquals(m.getStorage().data(), delegateStorage.data());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixViewConstructorTest.java
new file mode 100644
index 0000000..87bf3ad
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixViewConstructorTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.util.Arrays;
+import org.apache.ignite.ml.math.Matrix;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class PivotedMatrixViewConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        Matrix m = new DenseLocalOnHeapMatrix(1, 1);
+
+        int[] pivot = new int[] {0};
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(null),
+            "Null parent matrix.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(null, pivot),
+            "Null parent matrix, with pivot.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(m, null),
+            "Null pivot.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(m, null, pivot),
+            "Null row pivot.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(m, pivot, null),
+            "Null col pivot.");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        Matrix m = new DenseLocalOnHeapMatrix(2, 2);
+
+        int[] pivot = new int[] {0, 1};
+
+        PivotedMatrixView view = new PivotedMatrixView(m, pivot);
+
+        assertEquals("Rows in view.", m.rowSize(), view.rowSize());
+        assertEquals("Cols in view.", m.columnSize(), view.columnSize());
+
+        assertTrue("Row pivot array in view.", Arrays.equals(pivot, view.rowPivot()));
+        assertTrue("Col pivot array in view.", Arrays.equals(pivot, view.columnPivot()));
+
+        Assert.assertEquals("Base matrix in view.", m, view.getBaseMatrix());
+
+        assertEquals("Row pivot value in view.", 0, view.rowPivot(0));
+        assertEquals("Col pivot value in view.", 0, view.columnPivot(0));
+
+        assertEquals("Row unpivot value in view.", 0, view.rowUnpivot(0));
+        assertEquals("Col unpivot value in view.", 0, view.columnUnpivot(0));
+
+        Matrix swap = view.swap(1, 1);
+
+        for (int row = 0; row < view.rowSize(); row++)
+            for (int col = 0; col < view.columnSize(); col++)
+                assertEquals("Unexpected swap value set at (" + row + "," + col + ").",
+                    view.get(row, col), swap.get(row, col), 0d);
+
+        //noinspection EqualsWithItself
+        assertTrue("View is expected to be equal to self.", view.equals(view));
+        //noinspection ObjectEqualsNull
+        assertFalse("View is expected to be not equal to null.", view.equals(null));
+    }
+
+    /** */
+    @Test
+    public void pivotTest() {
+        int[] pivot = new int[] {2, 1, 0, 3};
+
+        for (Matrix m : new Matrix[] {
+            new DenseLocalOnHeapMatrix(3, 3),
+            new DenseLocalOnHeapMatrix(3, 4), new DenseLocalOnHeapMatrix(4, 3)})
+            pivotTest(m, pivot);
+    }
+
+    /** */
+    private void pivotTest(Matrix parent, int[] pivot) {
+        for (int row = 0; row < parent.rowSize(); row++)
+            for (int col = 0; col < parent.columnSize(); col++)
+                parent.set(row, col, row * parent.columnSize() + col + 1);
+
+        Matrix view = new PivotedMatrixView(parent, pivot);
+
+        int rows = parent.rowSize();
+        int cols = parent.columnSize();
+
+        assertEquals("Rows in view.", rows, view.rowSize());
+        assertEquals("Cols in view.", cols, view.columnSize());
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++)
+                assertEquals("Unexpected value at " + row + "x" + col,
+                    parent.get(pivot[row], pivot[col]), view.get(row, col), 0d);
+
+        int min = rows < cols ? rows : cols;
+
+        for (int idx = 0; idx < min; idx++)
+            view.set(idx, idx, 0d);
+
+        for (int idx = 0; idx < min; idx++)
+            assertEquals("Unexpected value set at " + idx,
+                0d, parent.get(pivot[idx], pivot[idx]), 0d);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrixConstructorTest.java
new file mode 100644
index 0000000..558e4d8
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrixConstructorTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class RandomMatrixConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(0, 1), "invalid row parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(1, 0), "invalid col parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(0, 1, true), "invalid row parameter, fastHash true");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(1, 0, true), "invalid col parameter, fastHash true");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(0, 1, false), "invalid row parameter, fastHash false");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(1, 0, false), "invalid col parameter, fastHash false");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        assertEquals("Expected number of rows, int parameters.", 1,
+            new RandomMatrix(1, 2).rowSize());
+
+        assertEquals("Expected number of cols, int parameters.", 1,
+            new RandomMatrix(2, 1).columnSize());
+
+        assertEquals("Expected number of rows, int parameters, fastHash true.", 1,
+            new RandomMatrix(1, 2, true).rowSize());
+
+        assertEquals("Expected number of cols, int parameters, fastHash true.", 1,
+            new RandomMatrix(2, 1, true).columnSize());
+
+        assertEquals("Expected number of rows, int parameters, fastHash false.", 1,
+            new RandomMatrix(1, 2, false).rowSize());
+
+        assertEquals("Expected number of cols, int parameters, fastHash false.", 1,
+            new RandomMatrix(2, 1, false).columnSize());
+
+        RandomMatrix m = new RandomMatrix(1, 1);
+        //noinspection EqualsWithItself
+        assertTrue("Matrix is expected to be equal to self.", m.equals(m));
+        //noinspection ObjectEqualsNull
+        assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrixTest.java
new file mode 100644
index 0000000..8985806
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrixTest.java
@@ -0,0 +1,265 @@
+// @java.file.header
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+import static org.apache.ignite.ml.math.impls.MathTestConstants.UNEXPECTED_VAL;
+
+/**
+ * Tests for {@link SparseDistributedMatrix}.
+ */
+@GridCommonTest(group = "Distributed Models")
+public class SparseDistributedMatrixTest extends GridCommonAbstractTest {
+    /** Number of nodes in grid */
+    private static final int NODE_COUNT = 3;
+    /** Cache name. */
+    private static final String CACHE_NAME = "test-cache";
+    /** Precision. */
+    private static final double PRECISION = 0.0;
+    /** Grid instance. */
+    private Ignite ignite;
+    /** Matrix rows */
+    private final int rows = MathTestConstants.STORAGE_SIZE;
+    /** Matrix cols */
+    private final int cols = MathTestConstants.STORAGE_SIZE;
+    /** Matrix for tests */
+    private SparseDistributedMatrix cacheMatrix;
+
+    /**
+     * Default constructor.
+     */
+    public SparseDistributedMatrixTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        for (int i = 1; i <= NODE_COUNT; i++)
+            startGrid(i);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override protected void beforeTest() throws Exception {
+        ignite = grid(NODE_COUNT);
+
+        ignite.configuration().setPeerClassLoadingEnabled(true);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ignite.destroyCache(CACHE_NAME);
+
+        if (cacheMatrix != null) {
+            cacheMatrix.destroy();
+            cacheMatrix = null;
+        }
+    }
+
+    /** */
+    public void testGetSet() throws Exception {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < cols; j++) {
+                double v = Math.random();
+                cacheMatrix.set(i, j, v);
+
+                assert Double.compare(v, cacheMatrix.get(i, j)) == 0;
+            }
+        }
+    }
+
+    /** */
+    public void testExternalize() throws IOException, ClassNotFoundException {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        cacheMatrix.set(1, 1, 1.0);
+
+        ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
+        ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
+
+        objOutputStream.writeObject(cacheMatrix);
+
+        ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
+        ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
+
+        SparseDistributedMatrix objRestored = (SparseDistributedMatrix)objInputStream.readObject();
+
+        assertTrue(MathTestConstants.VAL_NOT_EQUALS, cacheMatrix.equals(objRestored));
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, objRestored.get(1, 1), 1.0, 0.0);
+    }
+
+    /** Test simple math. */
+    public void testMath() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+        initMtx(cacheMatrix);
+
+        cacheMatrix.assign(2.0);
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                assertEquals(UNEXPECTED_VAL, 2.0, cacheMatrix.get(i, j), PRECISION);
+
+        cacheMatrix.plus(3.0);
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                assertEquals(UNEXPECTED_VAL, 5.0, cacheMatrix.get(i, j), PRECISION);
+
+        cacheMatrix.times(2.0);
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                assertEquals(UNEXPECTED_VAL, 10.0, cacheMatrix.get(i, j), PRECISION);
+
+        cacheMatrix.divide(10.0);
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                assertEquals(UNEXPECTED_VAL, 1.0, cacheMatrix.get(i, j), PRECISION);
+
+        assertEquals(UNEXPECTED_VAL, cacheMatrix.rowSize() * cacheMatrix.columnSize(), cacheMatrix.sum(), PRECISION);
+    }
+
+    /** */
+    public void testMinMax() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                cacheMatrix.set(i, j, i * cols + j + 1);
+
+        assertEquals(UNEXPECTED_VAL, 1.0, cacheMatrix.minValue(), PRECISION);
+        assertEquals(UNEXPECTED_VAL, rows * cols, cacheMatrix.maxValue(), PRECISION);
+
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                cacheMatrix.set(i, j, -1.0 * (i * cols + j + 1));
+
+        assertEquals(UNEXPECTED_VAL, -rows * cols, cacheMatrix.minValue(), PRECISION);
+        assertEquals(UNEXPECTED_VAL, -1.0, cacheMatrix.maxValue(), PRECISION);
+
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                cacheMatrix.set(i, j, i * cols + j);
+
+        assertEquals(UNEXPECTED_VAL, 1.0, cacheMatrix.minValue(), PRECISION);
+        assertEquals(UNEXPECTED_VAL, rows * cols - 1.0, cacheMatrix.maxValue(), PRECISION);
+    }
+
+    /** */
+    public void testMap() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+        initMtx(cacheMatrix);
+
+        cacheMatrix.map(i -> 100.0);
+        for (int i = 0; i < cacheMatrix.rowSize(); i++)
+            for (int j = 0; j < cacheMatrix.columnSize(); j++)
+                assertEquals(UNEXPECTED_VAL, 100.0, cacheMatrix.get(i, j), PRECISION);
+    }
+
+    /** */
+    public void testCopy() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        try {
+            cacheMatrix.copy();
+            fail("UnsupportedOperationException expected.");
+        }
+        catch (UnsupportedOperationException e) {
+            return;
+        }
+        fail("UnsupportedOperationException expected.");
+    }
+
+    /** */
+    public void testLike() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        try {
+            cacheMatrix.like(1, 1);
+            fail("UnsupportedOperationException expected.");
+        }
+        catch (UnsupportedOperationException e) {
+            return;
+        }
+        fail("UnsupportedOperationException expected.");
+    }
+
+    /** */
+    public void testLikeVector() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+        try {
+            cacheMatrix.likeVector(1);
+            fail("UnsupportedOperationException expected.");
+        }
+        catch (UnsupportedOperationException e) {
+            return;
+        }
+        fail("UnsupportedOperationException expected.");
+    }
+
+    /** */
+    private void initMtx(Matrix m) {
+        for (int i = 0; i < m.rowSize(); i++)
+            for (int j = 0; j < m.columnSize(); j++)
+                m.set(i, j, 1.0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
new file mode 100644
index 0000000..bc05eb7
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class SparseLocalOnHeapMatrixConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new SparseLocalOnHeapMatrix(0, 1),
+            "invalid row parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new SparseLocalOnHeapMatrix(1, 0),
+            "invalid col parameter");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        assertEquals("Expected number of rows.", 1,
+            new SparseLocalOnHeapMatrix(1, 2).rowSize());
+
+        assertEquals("Expected number of cols, int parameters.", 1,
+            new SparseLocalOnHeapMatrix(2, 1).columnSize());
+
+        SparseLocalOnHeapMatrix m = new SparseLocalOnHeapMatrix(1, 1);
+        //noinspection EqualsWithItself
+        assertTrue("Matrix is expected to be equal to self.", m.equals(m));
+        //noinspection ObjectEqualsNull
+        assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixViewTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixViewTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixViewTest.java
new file mode 100644
index 0000000..22ec7cc
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixViewTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link TransposedMatrixView}.
+ */
+public class TransposedMatrixViewTest extends ExternalizeTest<TransposedMatrixView> {
+    /** */
+    private static final String UNEXPECTED_VALUE = "Unexpected value";
+    /** */
+    private TransposedMatrixView testMatrix;
+    /** */
+    private DenseLocalOnHeapMatrix parent;
+
+    /** */
+    @Before
+    public void setup() {
+        parent = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
+        fillMatrix(parent);
+        testMatrix = new TransposedMatrixView(parent);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void externalizeTest() {
+        externalizeTest(testMatrix);
+    }
+
+    /** */
+    @Test
+    public void testView() {
+        assertEquals(UNEXPECTED_VALUE, parent.rowSize(), testMatrix.columnSize());
+        assertEquals(UNEXPECTED_VALUE, parent.columnSize(), testMatrix.rowSize());
+
+        for (int i = 0; i < parent.rowSize(); i++)
+            for (int j = 0; j < parent.columnSize(); j++)
+                assertEquals(UNEXPECTED_VALUE, parent.get(i, j), testMatrix.get(j, i), 0d);
+    }
+
+    /** */
+    @Test
+    public void testNullParams() {
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new TransposedMatrixView(null), "Null Matrix parameter");
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testLike() {
+        testMatrix.like(0, 0);
+    }
+
+    /** */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testLikeVector() {
+        testMatrix.likeVector(0);
+    }
+
+    /** */
+    private void fillMatrix(DenseLocalOnHeapMatrix mtx) {
+        for (int i = 0; i < mtx.rowSize(); i++)
+            for (int j = 0; j < mtx.columnSize(); j++)
+                mtx.setX(i, j, i * mtx.rowSize() + j);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixArrayStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixArrayStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixArrayStorageTest.java
new file mode 100644
index 0000000..569ed57
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixArrayStorageTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link ArrayMatrixStorage}.
+ */
+public class MatrixArrayStorageTest extends MatrixBaseStorageTest<ArrayMatrixStorage> {
+    /** {@inheritDoc} */
+    @Override public void setUp() {
+        storage = new ArrayMatrixStorage(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void isSequentialAccess() throws Exception {
+        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isSequentialAccess());
+    }
+
+    /** */
+    @Test
+    public void isDense() throws Exception {
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isDense());
+    }
+
+    /** */
+    @Test
+    public void isArrayBased() throws Exception {
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isArrayBased());
+    }
+
+    /** */
+    @Test
+    public void data() throws Exception {
+        double[][] data = storage.data();
+        assertNotNull(MathTestConstants.NULL_VAL, data);
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, data.length == MathTestConstants.STORAGE_SIZE);
+        assertTrue(MathTestConstants.UNEXPECTED_VAL, data[0].length == MathTestConstants.STORAGE_SIZE);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixBaseStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixBaseStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixBaseStorageTest.java
new file mode 100644
index 0000000..94e87c2
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixBaseStorageTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Abstract class with base tests for each matrix storage.
+ */
+public abstract class MatrixBaseStorageTest<T extends MatrixStorage> extends ExternalizeTest<T> {
+    /** */
+    protected T storage;
+
+    /** */
+    @Before
+    public abstract void setUp();
+
+    /** */
+    @After
+    public void tearDown() throws Exception {
+        storage.destroy();
+    }
+
+    /** */
+    @Test
+    public void getSet() throws Exception {
+        int rows = MathTestConstants.STORAGE_SIZE;
+        int cols = MathTestConstants.STORAGE_SIZE;
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < cols; j++) {
+                double data = Math.random();
+
+                storage.set(i, j, data);
+
+                Assert.assertEquals(MathTestConstants.VAL_NOT_EQUALS, storage.get(i, j), data, MathTestConstants.NIL_DELTA);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void columnSize() throws Exception {
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, storage.columnSize(), MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void rowSize() throws Exception {
+        assertEquals(MathTestConstants.VAL_NOT_EQUALS, storage.rowSize(), MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Override public void externalizeTest() {
+        fillMatrix();
+        super.externalizeTest(storage);
+    }
+
+    /** */
+    protected void fillMatrix() {
+        for (int i = 0; i < storage.rowSize(); i++) {
+            for (int j = 0; j < storage.columnSize(); j++)
+                storage.set(i, j, Math.random());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixOffHeapStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
new file mode 100644
index 0000000..52d57fd
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNull;
+
+/**
+ * Unit tests for {@link DenseOffHeapMatrixStorage}.
+ */
+public class MatrixOffHeapStorageTest extends MatrixBaseStorageTest<DenseOffHeapMatrixStorage> {
+    /** {@inheritDoc} */
+    @Override public void setUp() {
+        storage = new DenseOffHeapMatrixStorage(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
+    }
+
+    /** */
+    @Test
+    public void data() throws Exception {
+        assertNull(MathTestConstants.UNEXPECTED_VAL, storage.data());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageFixtures.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageFixtures.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageFixtures.java
new file mode 100644
index 0000000..03473cf
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageFixtures.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ *
+ */
+class MatrixStorageFixtures {
+    /** */
+    private static final List<Supplier<Iterable<MatrixStorage>>> suppliers = Collections.singletonList(
+        (Supplier<Iterable<MatrixStorage>>) SparseLocalMatrixStorageFixture::new
+    );
+
+    /** */
+    void consumeSampleStorages(BiConsumer<Integer, Integer> paramsConsumer,
+        BiConsumer<MatrixStorage, String> consumer) {
+        for (Supplier<Iterable<MatrixStorage>> fixtureSupplier : suppliers) {
+            final Iterable<MatrixStorage> fixture = fixtureSupplier.get();
+
+            for (MatrixStorage matrixStorage : fixture) {
+                if (paramsConsumer != null)
+                    paramsConsumer.accept(matrixStorage.rowSize(), matrixStorage.columnSize());
+
+                consumer.accept(matrixStorage, fixture.toString());
+            }
+        }
+    }
+
+    /** */
+    private static class SparseLocalMatrixStorageFixture implements Iterable<MatrixStorage> {
+        /** */
+        private final Integer[] rows = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 1024, null};
+        /** */
+        private final Integer[] cols = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1024, 512, null};
+        /** */
+        private final Integer[] randomAccess = new Integer[] {StorageConstants.SEQUENTIAL_ACCESS_MODE, StorageConstants.RANDOM_ACCESS_MODE, null};
+        /** */
+        private final Integer[] rowStorage = new Integer[] {StorageConstants.ROW_STORAGE_MODE, StorageConstants.COLUMN_STORAGE_MODE, null};
+        /** */
+        private int sizeIdx = 0;
+        /** */
+        private int acsModeIdx = 0;
+        /** */
+        private int stoModeIdx = 0;
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<MatrixStorage> iterator() {
+            return new Iterator<MatrixStorage>() {
+                /** {@inheritDoc} */
+                @Override public boolean hasNext() {
+                    return hasNextCol(sizeIdx) && hasNextRow(sizeIdx)
+                        && hasNextAcsMode(acsModeIdx) && hasNextStoMode(stoModeIdx);
+                }
+
+                /** {@inheritDoc} */
+                @Override public MatrixStorage next() {
+                    if (!hasNext())
+                        throw new NoSuchElementException(SparseLocalMatrixStorageFixture.this.toString());
+
+                    MatrixStorage storage = new SparseLocalOnHeapMatrixStorage(
+                        rows[sizeIdx], cols[sizeIdx], randomAccess[acsModeIdx], rowStorage[stoModeIdx]);
+
+                    nextIdx();
+
+                    return storage;
+                }
+
+                private void nextIdx() {
+                    if (hasNextStoMode(stoModeIdx + 1)) {
+                        stoModeIdx++;
+
+                        return;
+                    }
+
+                    stoModeIdx = 0;
+
+                    if (hasNextAcsMode(acsModeIdx + 1)) {
+                        acsModeIdx++;
+
+                        return;
+                    }
+
+                    acsModeIdx = 0;
+                    sizeIdx++;
+                }
+            };
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "SparseLocalMatrixStorageFixture{ " + "rows=" + rows[sizeIdx] + ", cols=" + cols[sizeIdx] +
+                ", access mode=" + randomAccess[acsModeIdx] + ", storage mode=" + rowStorage[stoModeIdx] + "}";
+        }
+
+        /** */ private boolean hasNextRow(int idx) {
+            return rows[idx] != null;
+        }
+
+        /** */ private boolean hasNextCol(int idx) {
+            return cols[idx] != null;
+        }
+
+        /** */ private boolean hasNextAcsMode(int idx) {
+            return randomAccess[idx] != null;
+        }
+
+        /** */ private boolean hasNextStoMode(int idx) {
+            return rowStorage[idx] != null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageImplementationTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageImplementationTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageImplementationTest.java
new file mode 100644
index 0000000..72daeca
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixStorageImplementationTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link MatrixStorage} implementations.
+ *
+ * TODO: add attribute tests.
+ */
+public class MatrixStorageImplementationTest extends ExternalizeTest<MatrixStorage> {
+    /**
+     * The columnSize() and the rowSize() test.
+     */
+    @Test
+    public void sizeTest() {
+        final AtomicReference<Integer> expRowSize = new AtomicReference<>(0);
+        final AtomicReference<Integer> expColSize = new AtomicReference<>(0);
+
+        consumeSampleStorages((x, y) -> {
+                expRowSize.set(x);
+                expColSize.set(y);
+            },
+            (ms, desc) -> assertTrue("Expected size for " + desc, expColSize.get().equals(ms.columnSize()) && expRowSize.get().equals(ms.rowSize())));
+    }
+
+    /** */
+    @Test
+    public void getSetTest() {
+        consumeSampleStorages(null, (ms, desc) -> {
+            for (int i = 0; i < ms.rowSize(); i++) {
+                for (int j = 0; j < ms.columnSize(); j++) {
+                    double random = Math.random();
+                    ms.set(i, j, random);
+                    assertTrue("Unexpected value for " + desc + " x:" + i + ", y:" + j, Double.compare(random, ms.get(i, j)) == 0);
+                }
+            }
+        });
+    }
+
+    /** */
+    @Override public void externalizeTest() {
+        consumeSampleStorages(null, (ms, desc) -> externalizeTest(ms));
+    }
+
+    /** */
+    private void consumeSampleStorages(BiConsumer<Integer, Integer> paramsConsumer,
+        BiConsumer<MatrixStorage, String> consumer) {
+        new MatrixStorageFixtures().consumeSampleStorages(paramsConsumer, consumer);
+    }
+}


[24/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
IGNITE-5000 Rename Ignite Math module to Ignite ML module
      added missed licenses
      renamed packages
      fixed wrong ml profile activation


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

Branch: refs/heads/ignite-1561
Commit: d78e071a7de1129838652e9f377ff73d3a84495d
Parents: 7038af4
Author: Yury Babak <yb...@gridgain.com>
Authored: Tue Apr 18 16:47:15 2017 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Tue Apr 18 16:47:17 2017 +0300

----------------------------------------------------------------------
 examples/pom-standalone.xml                     |    4 -
 examples/pom.xml                                |    4 -
 .../CholeskyDecompositionExample.java           |    8 +-
 .../EigenDecompositionExample.java              |    8 +-
 .../decompositions/LUDecompositionExample.java  |    8 +-
 .../SingularValueDecompositionExample.java      |    6 +-
 .../ml/math/matrix/CacheMatrixExample.java      |   10 +-
 .../ml/math/matrix/ExampleMatrixStorage.java    |    4 +-
 .../math/matrix/MatrixCustomStorageExample.java |   12 +-
 .../examples/ml/math/matrix/MatrixExample.java  |    4 +-
 .../ml/math/matrix/MatrixExampleUtil.java       |    4 +-
 .../ml/math/matrix/OffHeapMatrixExample.java    |    4 +-
 .../matrix/SparseDistributedMatrixExample.java  |    5 +-
 .../ml/math/matrix/SparseMatrixExample.java     |    4 +-
 .../examples/ml/math/tracer/TracerExample.java  |    4 +-
 .../ml/math/vector/CacheVectorExample.java      |    8 +-
 .../ml/math/vector/ExampleVectorStorage.java    |    4 +-
 .../ml/math/vector/OffHeapVectorExample.java    |    4 +-
 .../ml/math/vector/SparseVectorExample.java     |    6 +-
 .../math/vector/VectorCustomStorageExample.java |   14 +-
 .../examples/ml/math/vector/VectorExample.java  |    4 +-
 modules/ml/pom.xml                              |    6 -
 .../java/org/apache/ignite/math/Algebra.java    |  571 ---------
 .../java/org/apache/ignite/math/Constants.java  |   42 -
 .../org/apache/ignite/math/Destroyable.java     |   30 -
 .../apache/ignite/math/IdentityValueMapper.java |   53 -
 .../java/org/apache/ignite/math/KeyMapper.java  |   33 -
 .../java/org/apache/ignite/math/Matrix.java     |  518 --------
 .../org/apache/ignite/math/MatrixKeyMapper.java |   30 -
 .../org/apache/ignite/math/MatrixStorage.java   |   58 -
 .../org/apache/ignite/math/MetaAttributes.java  |   76 --
 .../java/org/apache/ignite/math/MurmurHash.java |  246 ----
 .../apache/ignite/math/StorageConstants.java    |   49 -
 .../apache/ignite/math/StorageOpsMetrics.java   |   49 -
 .../java/org/apache/ignite/math/Tracer.java     |  456 -------
 .../org/apache/ignite/math/ValueMapper.java     |   27 -
 .../java/org/apache/ignite/math/Vector.java     |  498 --------
 .../org/apache/ignite/math/VectorKeyMapper.java |   29 -
 .../org/apache/ignite/math/VectorStorage.java   |   53 -
 .../decompositions/CholeskyDecomposition.java   |  306 -----
 .../decompositions/DecompositionSupport.java    |  105 --
 .../math/decompositions/EigenDecomposition.java |  923 ---------------
 .../math/decompositions/LUDecomposition.java    |  366 ------
 .../math/decompositions/QRDecomposition.java    |  186 ---
 .../SingularValueDecomposition.java             |  620 ----------
 .../math/decompositions/package-info.java       |   22 -
 .../math/exceptions/CardinalityException.java   |   38 -
 .../math/exceptions/ColumnIndexException.java   |   35 -
 .../ignite/math/exceptions/IndexException.java  |   35 -
 .../NonPositiveDefiniteMatrixException.java     |   20 -
 .../exceptions/NonSymmetricMatrixException.java |   18 -
 .../math/exceptions/RowIndexException.java      |   35 -
 .../exceptions/SingularMatrixException.java     |   30 -
 .../exceptions/UnknownProviderException.java    |   35 -
 .../UnsupportedOperationException.java          |   44 -
 .../ignite/math/exceptions/package-info.java    |   22 -
 .../apache/ignite/math/functions/Functions.java |  136 ---
 .../ignite/math/functions/IgniteBiConsumer.java |   12 -
 .../ignite/math/functions/IgniteBiFunction.java |   29 -
 .../ignite/math/functions/IgniteConsumer.java   |   29 -
 .../math/functions/IgniteDoubleFunction.java    |   29 -
 .../ignite/math/functions/IgniteFunction.java   |   30 -
 .../math/functions/IntDoubleToVoidFunction.java |   25 -
 .../functions/IntIntDoubleToVoidFunction.java   |   28 -
 .../math/functions/IntIntToDoubleFunction.java  |   24 -
 .../ignite/math/functions/package-info.java     |   22 -
 .../apache/ignite/math/impls/CacheUtils.java    |  356 ------
 .../math/impls/matrix/AbstractMatrix.java       |  880 --------------
 .../ignite/math/impls/matrix/CacheMatrix.java   |  158 ---
 .../impls/matrix/DenseLocalOffHeapMatrix.java   |   90 --
 .../impls/matrix/DenseLocalOnHeapMatrix.java    |   86 --
 .../math/impls/matrix/DiagonalMatrix.java       |  101 --
 .../math/impls/matrix/FunctionMatrix.java       |   95 --
 .../ignite/math/impls/matrix/MatrixView.java    |   84 --
 .../math/impls/matrix/PivotedMatrixView.java    |  243 ----
 .../ignite/math/impls/matrix/RandomMatrix.java  |   97 --
 .../impls/matrix/SparseDistributedMatrix.java   |  155 ---
 .../impls/matrix/SparseLocalOnHeapMatrix.java   |   72 --
 .../math/impls/matrix/TransposedMatrixView.java |   84 --
 .../ignite/math/impls/matrix/package-info.java  |   22 -
 .../apache/ignite/math/impls/package-info.java  |   22 -
 .../storage/matrix/ArrayMatrixStorage.java      |  161 ---
 .../storage/matrix/CacheMatrixStorage.java      |  180 ---
 .../matrix/DenseOffHeapMatrixStorage.java       |  197 ----
 .../storage/matrix/DiagonalMatrixStorage.java   |  136 ---
 .../storage/matrix/FunctionMatrixStorage.java   |  175 ---
 .../storage/matrix/MatrixDelegateStorage.java   |  205 ----
 .../storage/matrix/PivotedMatrixStorage.java    |  256 ----
 .../storage/matrix/RandomMatrixStorage.java     |  176 ---
 .../matrix/SparseDistributedMatrixStorage.java  |  281 -----
 .../matrix/SparseLocalOnHeapMatrixStorage.java  |  226 ----
 .../math/impls/storage/matrix/package-info.java |   22 -
 .../storage/vector/ArrayVectorStorage.java      |  135 ---
 .../storage/vector/CacheVectorStorage.java      |  175 ---
 .../storage/vector/ConstantVectorStorage.java   |  133 ---
 .../storage/vector/DelegateVectorStorage.java   |  157 ---
 .../vector/DenseLocalOffHeapVectorStorage.java  |  172 ---
 .../storage/vector/FunctionVectorStorage.java   |  141 ---
 .../storage/vector/MatrixVectorStorage.java     |  185 ---
 .../storage/vector/PivotedVectorStorage.java    |  175 ---
 .../storage/vector/RandomVectorStorage.java     |  152 ---
 .../SingleElementVectorDelegateStorage.java     |  145 ---
 .../vector/SingleElementVectorStorage.java      |  143 ---
 .../vector/SparseLocalOffHeapVectorStorage.java |  148 ---
 .../vector/SparseLocalOnHeapVectorStorage.java  |  152 ---
 .../math/impls/storage/vector/package-info.java |   22 -
 .../impls/vector/AbstractReadOnlyVector.java    |  108 --
 .../math/impls/vector/AbstractVector.java       |  903 --------------
 .../ignite/math/impls/vector/CacheVector.java   |  140 ---
 .../math/impls/vector/ConstantVector.java       |   84 --
 .../math/impls/vector/DelegatingVector.java     |  391 ------
 .../impls/vector/DenseLocalOffHeapVector.java   |   89 --
 .../impls/vector/DenseLocalOnHeapVector.java    |  104 --
 .../math/impls/vector/FunctionVector.java       |  112 --
 .../math/impls/vector/MatrixVectorView.java     |  139 ---
 .../math/impls/vector/PivotedVectorView.java    |  163 ---
 .../ignite/math/impls/vector/RandomVector.java  |  128 --
 .../math/impls/vector/SingleElementVector.java  |  102 --
 .../impls/vector/SingleElementVectorView.java   |   97 --
 .../impls/vector/SparseLocalOffHeapVector.java  |   47 -
 .../math/impls/vector/SparseLocalVector.java    |   71 --
 .../ignite/math/impls/vector/VectorView.java    |   85 --
 .../ignite/math/impls/vector/package-info.java  |   22 -
 .../org/apache/ignite/math/package-info.java    |   22 -
 .../java/org/apache/ignite/ml/math/Algebra.java |  571 +++++++++
 .../org/apache/ignite/ml/math/Constants.java    |   42 +
 .../org/apache/ignite/ml/math/Destroyable.java  |   30 +
 .../ignite/ml/math/IdentityValueMapper.java     |   53 +
 .../org/apache/ignite/ml/math/KeyMapper.java    |   33 +
 .../java/org/apache/ignite/ml/math/Matrix.java  |  518 ++++++++
 .../apache/ignite/ml/math/MatrixKeyMapper.java  |   30 +
 .../apache/ignite/ml/math/MatrixStorage.java    |   58 +
 .../apache/ignite/ml/math/MetaAttributes.java   |   76 ++
 .../org/apache/ignite/ml/math/MurmurHash.java   |  246 ++++
 .../apache/ignite/ml/math/StorageConstants.java |   49 +
 .../ignite/ml/math/StorageOpsMetrics.java       |   49 +
 .../java/org/apache/ignite/ml/math/Tracer.java  |  456 +++++++
 .../org/apache/ignite/ml/math/ValueMapper.java  |   35 +
 .../java/org/apache/ignite/ml/math/Vector.java  |  498 ++++++++
 .../apache/ignite/ml/math/VectorKeyMapper.java  |   29 +
 .../apache/ignite/ml/math/VectorStorage.java    |   53 +
 .../decompositions/CholeskyDecomposition.java   |  306 +++++
 .../decompositions/DecompositionSupport.java    |  105 ++
 .../math/decompositions/EigenDecomposition.java |  923 +++++++++++++++
 .../ml/math/decompositions/LUDecomposition.java |  366 ++++++
 .../ml/math/decompositions/QRDecomposition.java |  186 +++
 .../SingularValueDecomposition.java             |  620 ++++++++++
 .../ml/math/decompositions/package-info.java    |   22 +
 .../math/exceptions/CardinalityException.java   |   38 +
 .../math/exceptions/ColumnIndexException.java   |   35 +
 .../ml/math/exceptions/IndexException.java      |   35 +
 .../NonPositiveDefiniteMatrixException.java     |   37 +
 .../exceptions/NonSymmetricMatrixException.java |   35 +
 .../ml/math/exceptions/RowIndexException.java   |   35 +
 .../exceptions/SingularMatrixException.java     |   30 +
 .../exceptions/UnknownProviderException.java    |   35 +
 .../UnsupportedOperationException.java          |   44 +
 .../ignite/ml/math/exceptions/package-info.java |   22 +
 .../ignite/ml/math/functions/Functions.java     |  136 +++
 .../ml/math/functions/IgniteBiConsumer.java     |   29 +
 .../ml/math/functions/IgniteBiFunction.java     |   29 +
 .../ml/math/functions/IgniteConsumer.java       |   29 +
 .../ml/math/functions/IgniteDoubleFunction.java |   29 +
 .../ml/math/functions/IgniteFunction.java       |   30 +
 .../math/functions/IntDoubleToVoidFunction.java |   25 +
 .../functions/IntIntDoubleToVoidFunction.java   |   28 +
 .../math/functions/IntIntToDoubleFunction.java  |   24 +
 .../ignite/ml/math/functions/package-info.java  |   22 +
 .../apache/ignite/ml/math/impls/CacheUtils.java |  356 ++++++
 .../ml/math/impls/matrix/AbstractMatrix.java    |  880 ++++++++++++++
 .../ml/math/impls/matrix/CacheMatrix.java       |  158 +++
 .../impls/matrix/DenseLocalOffHeapMatrix.java   |   90 ++
 .../impls/matrix/DenseLocalOnHeapMatrix.java    |   86 ++
 .../ml/math/impls/matrix/DiagonalMatrix.java    |  101 ++
 .../ml/math/impls/matrix/FunctionMatrix.java    |   95 ++
 .../ignite/ml/math/impls/matrix/MatrixView.java |   84 ++
 .../ml/math/impls/matrix/PivotedMatrixView.java |  243 ++++
 .../ml/math/impls/matrix/RandomMatrix.java      |   97 ++
 .../impls/matrix/SparseDistributedMatrix.java   |  155 +++
 .../impls/matrix/SparseLocalOnHeapMatrix.java   |   72 ++
 .../math/impls/matrix/TransposedMatrixView.java |   84 ++
 .../ml/math/impls/matrix/package-info.java      |   22 +
 .../ignite/ml/math/impls/package-info.java      |   22 +
 .../storage/matrix/ArrayMatrixStorage.java      |  161 +++
 .../storage/matrix/CacheMatrixStorage.java      |  180 +++
 .../matrix/DenseOffHeapMatrixStorage.java       |  197 ++++
 .../storage/matrix/DiagonalMatrixStorage.java   |  136 +++
 .../storage/matrix/FunctionMatrixStorage.java   |  175 +++
 .../storage/matrix/MatrixDelegateStorage.java   |  205 ++++
 .../storage/matrix/PivotedMatrixStorage.java    |  256 ++++
 .../storage/matrix/RandomMatrixStorage.java     |  176 +++
 .../matrix/SparseDistributedMatrixStorage.java  |  290 +++++
 .../matrix/SparseLocalOnHeapMatrixStorage.java  |  226 ++++
 .../math/impls/storage/matrix/package-info.java |   22 +
 .../storage/vector/ArrayVectorStorage.java      |  135 +++
 .../storage/vector/CacheVectorStorage.java      |  175 +++
 .../storage/vector/ConstantVectorStorage.java   |  133 +++
 .../storage/vector/DelegateVectorStorage.java   |  157 +++
 .../vector/DenseLocalOffHeapVectorStorage.java  |  172 +++
 .../storage/vector/FunctionVectorStorage.java   |  141 +++
 .../storage/vector/MatrixVectorStorage.java     |  185 +++
 .../storage/vector/PivotedVectorStorage.java    |  175 +++
 .../storage/vector/RandomVectorStorage.java     |  152 +++
 .../SingleElementVectorDelegateStorage.java     |  145 +++
 .../vector/SingleElementVectorStorage.java      |  143 +++
 .../vector/SparseLocalOffHeapVectorStorage.java |  149 +++
 .../vector/SparseLocalOnHeapVectorStorage.java  |  152 +++
 .../math/impls/storage/vector/package-info.java |   22 +
 .../impls/vector/AbstractReadOnlyVector.java    |  125 ++
 .../ml/math/impls/vector/AbstractVector.java    |  903 ++++++++++++++
 .../ml/math/impls/vector/CacheVector.java       |  140 +++
 .../ml/math/impls/vector/ConstantVector.java    |   84 ++
 .../ml/math/impls/vector/DelegatingVector.java  |  391 ++++++
 .../impls/vector/DenseLocalOffHeapVector.java   |   89 ++
 .../impls/vector/DenseLocalOnHeapVector.java    |  104 ++
 .../ml/math/impls/vector/FunctionVector.java    |  112 ++
 .../ml/math/impls/vector/MatrixVectorView.java  |  139 +++
 .../ml/math/impls/vector/PivotedVectorView.java |  163 +++
 .../ml/math/impls/vector/RandomVector.java      |  129 ++
 .../math/impls/vector/SingleElementVector.java  |  102 ++
 .../impls/vector/SingleElementVectorView.java   |   97 ++
 .../impls/vector/SparseLocalOffHeapVector.java  |   47 +
 .../ml/math/impls/vector/SparseLocalVector.java |   71 ++
 .../ignite/ml/math/impls/vector/VectorView.java |   85 ++
 .../ml/math/impls/vector/package-info.java      |   22 +
 .../org/apache/ignite/ml/math/package-info.java |   22 +
 .../apache/ignite/math/d3-matrix-template.html  |  128 --
 .../apache/ignite/math/d3-vector-template.html  |  111 --
 .../ignite/ml/math/d3-matrix-template.html      |  128 ++
 .../ignite/ml/math/d3-vector-template.html      |  111 ++
 .../org/apache/ignite/math/ExternalizeTest.java |   66 --
 .../math/MathImplDistributedTestSuite.java      |   39 -
 .../ignite/math/MathImplLocalTestSuite.java     |  123 --
 .../ignite/math/MathImplMainTestSuite.java      |   33 -
 .../java/org/apache/ignite/math/TracerTest.java |  195 ---
 .../ignite/math/benchmark/MathBenchmark.java    |  205 ----
 .../math/benchmark/MathBenchmarkSelfTest.java   |  100 --
 .../ignite/math/benchmark/ResultsWriter.java    |  127 --
 .../math/benchmark/VectorBenchmarkTest.java     |  138 ---
 .../ignite/math/benchmark/package-info.java     |   18 -
 .../CholeskyDecompositionTest.java              |  158 ---
 .../decompositions/EigenDecompositionTest.java  |  193 ---
 .../decompositions/LUDecompositionTest.java     |  250 ----
 .../decompositions/QRDecompositionTest.java     |  139 ---
 .../SingularValueDecompositionTest.java         |  120 --
 .../ignite/math/impls/MathTestConstants.java    |   88 --
 .../math/impls/matrix/CacheMatrixTest.java      |  369 ------
 .../DenseLocalOffHeapMatrixConstructorTest.java |   65 -
 .../DenseLocalOnHeapMatrixConstructorTest.java  |   71 --
 .../math/impls/matrix/DiagonalMatrixTest.java   |  209 ----
 .../matrix/FunctionMatrixConstructorTest.java   |  113 --
 .../math/impls/matrix/MatrixAttributeTest.java  |  156 ---
 .../matrix/MatrixImplementationFixtures.java    |  381 ------
 .../impls/matrix/MatrixImplementationsTest.java | 1113 ------------------
 .../impls/matrix/MatrixKeyMapperForTests.java   |   69 --
 .../impls/matrix/MatrixViewConstructorTest.java |  114 --
 .../PivotedMatrixViewConstructorTest.java       |  128 --
 .../matrix/RandomMatrixConstructorTest.java     |   71 --
 .../matrix/SparseDistributedMatrixTest.java     |  265 -----
 .../SparseLocalOnHeapMatrixConstructorTest.java |   53 -
 .../impls/matrix/TransposedMatrixViewTest.java  |   87 --
 .../storage/matrix/MatrixArrayStorageTest.java  |   63 -
 .../storage/matrix/MatrixBaseStorageTest.java   |   89 --
 .../matrix/MatrixOffHeapStorageTest.java        |   39 -
 .../storage/matrix/MatrixStorageFixtures.java   |  141 ---
 .../matrix/MatrixStorageImplementationTest.java |   73 --
 .../SparseDistributedMatrixStorageTest.java     |  126 --
 .../RandomAccessSparseVectorStorageTest.java    |   60 -
 .../SparseLocalOffHeapVectorStorageTest.java    |   78 --
 .../storage/vector/VectorArrayStorageTest.java  |   58 -
 .../storage/vector/VectorBaseStorageTest.java   |   69 --
 .../vector/VectorOffheapStorageTest.java        |   73 --
 .../math/impls/vector/AbstractVectorTest.java   |  543 ---------
 .../math/impls/vector/CacheVectorTest.java      |  417 -------
 .../vector/ConstantVectorConstructorTest.java   |   52 -
 .../vector/DelegatingVectorConstructorTest.java |   62 -
 .../DenseLocalOffHeapVectorConstructorTest.java |   59 -
 .../DenseLocalOnHeapVectorConstructorTest.java  |  163 ---
 .../vector/FunctionVectorConstructorTest.java   |  121 --
 .../math/impls/vector/MatrixVectorViewTest.java |  209 ----
 .../PivotedVectorViewConstructorTest.java       |  211 ----
 .../vector/RandomVectorConstructorTest.java     |  145 ---
 .../SingleElementVectorConstructorTest.java     |  159 ---
 .../SingleElementVectorViewConstructorTest.java |  137 ---
 .../SparseLocalVectorConstructorTest.java       |   54 -
 .../math/impls/vector/VectorAttributesTest.java |  217 ----
 .../math/impls/vector/VectorFoldMapTest.java    |  122 --
 .../vector/VectorImplementationsFixtures.java   |  655 -----------
 .../impls/vector/VectorImplementationsTest.java |  860 --------------
 .../math/impls/vector/VectorIterableTest.java   |  376 ------
 .../math/impls/vector/VectorNormTest.java       |  247 ----
 .../math/impls/vector/VectorToMatrixTest.java   |  291 -----
 .../math/impls/vector/VectorViewTest.java       |  162 ---
 .../apache/ignite/ml/math/ExternalizeTest.java  |   66 ++
 .../ml/math/MathImplDistributedTestSuite.java   |   39 +
 .../ignite/ml/math/MathImplLocalTestSuite.java  |  123 ++
 .../ignite/ml/math/MathImplMainTestSuite.java   |   33 +
 .../org/apache/ignite/ml/math/TracerTest.java   |  195 +++
 .../ignite/ml/math/benchmark/MathBenchmark.java |  205 ++++
 .../math/benchmark/MathBenchmarkSelfTest.java   |  100 ++
 .../ignite/ml/math/benchmark/ResultsWriter.java |  127 ++
 .../ml/math/benchmark/VectorBenchmarkTest.java  |  138 +++
 .../ignite/ml/math/benchmark/package-info.java  |   18 +
 .../CholeskyDecompositionTest.java              |  158 +++
 .../decompositions/EigenDecompositionTest.java  |  193 +++
 .../decompositions/LUDecompositionTest.java     |  250 ++++
 .../decompositions/QRDecompositionTest.java     |  139 +++
 .../SingularValueDecompositionTest.java         |  120 ++
 .../ignite/ml/math/impls/MathTestConstants.java |   88 ++
 .../ml/math/impls/matrix/CacheMatrixTest.java   |  369 ++++++
 .../DenseLocalOffHeapMatrixConstructorTest.java |   65 +
 .../DenseLocalOnHeapMatrixConstructorTest.java  |   71 ++
 .../math/impls/matrix/DiagonalMatrixTest.java   |  209 ++++
 .../matrix/FunctionMatrixConstructorTest.java   |  113 ++
 .../math/impls/matrix/MatrixAttributeTest.java  |  156 +++
 .../matrix/MatrixImplementationFixtures.java    |  381 ++++++
 .../impls/matrix/MatrixImplementationsTest.java | 1113 ++++++++++++++++++
 .../impls/matrix/MatrixKeyMapperForTests.java   |   69 ++
 .../impls/matrix/MatrixViewConstructorTest.java |  114 ++
 .../PivotedMatrixViewConstructorTest.java       |  129 ++
 .../matrix/RandomMatrixConstructorTest.java     |   71 ++
 .../matrix/SparseDistributedMatrixTest.java     |  265 +++++
 .../SparseLocalOnHeapMatrixConstructorTest.java |   53 +
 .../impls/matrix/TransposedMatrixViewTest.java  |   87 ++
 .../storage/matrix/MatrixArrayStorageTest.java  |   63 +
 .../storage/matrix/MatrixBaseStorageTest.java   |   89 ++
 .../matrix/MatrixOffHeapStorageTest.java        |   39 +
 .../storage/matrix/MatrixStorageFixtures.java   |  137 +++
 .../matrix/MatrixStorageImplementationTest.java |   73 ++
 .../SparseDistributedMatrixStorageTest.java     |  126 ++
 .../RandomAccessSparseVectorStorageTest.java    |   60 +
 .../SparseLocalOffHeapVectorStorageTest.java    |   78 ++
 .../storage/vector/VectorArrayStorageTest.java  |   58 +
 .../storage/vector/VectorBaseStorageTest.java   |   69 ++
 .../vector/VectorOffheapStorageTest.java        |   73 ++
 .../math/impls/vector/AbstractVectorTest.java   |  543 +++++++++
 .../ml/math/impls/vector/CacheVectorTest.java   |  434 +++++++
 .../vector/ConstantVectorConstructorTest.java   |   52 +
 .../vector/DelegatingVectorConstructorTest.java |   62 +
 .../DenseLocalOffHeapVectorConstructorTest.java |   59 +
 .../DenseLocalOnHeapVectorConstructorTest.java  |  163 +++
 .../vector/FunctionVectorConstructorTest.java   |  121 ++
 .../math/impls/vector/MatrixVectorViewTest.java |  226 ++++
 .../PivotedVectorViewConstructorTest.java       |  211 ++++
 .../vector/RandomVectorConstructorTest.java     |  145 +++
 .../SingleElementVectorConstructorTest.java     |  159 +++
 .../SingleElementVectorViewConstructorTest.java |  137 +++
 .../SparseLocalVectorConstructorTest.java       |   54 +
 .../math/impls/vector/VectorAttributesTest.java |  217 ++++
 .../ml/math/impls/vector/VectorFoldMapTest.java |  122 ++
 .../vector/VectorImplementationsFixtures.java   |  655 +++++++++++
 .../impls/vector/VectorImplementationsTest.java |  861 ++++++++++++++
 .../math/impls/vector/VectorIterableTest.java   |  376 ++++++
 .../ml/math/impls/vector/VectorNormTest.java    |  247 ++++
 .../math/impls/vector/VectorToMatrixTest.java   |  308 +++++
 .../ml/math/impls/vector/VectorViewTest.java    |  162 +++
 356 files changed, 27247 insertions(+), 27124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/pom-standalone.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone.xml b/examples/pom-standalone.xml
index 64b4301..0183563 100644
--- a/examples/pom-standalone.xml
+++ b/examples/pom-standalone.xml
@@ -113,10 +113,6 @@
                 <java.ver>1.8</java.ver>
             </properties>
 
-            <activation>
-                <jdk>[1.8,)</jdk>
-            </activation>
-
             <dependencies>
                 <dependency>
                     <groupId>org.apache.ignite</groupId>

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index b933385..895519b 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -260,10 +260,6 @@
                 <ml.folder>src/main/ml</ml.folder>
             </properties>
 
-            <activation>
-                <jdk>[1.8,)</jdk>
-            </activation>
-
             <build>
                 <plugins>
                     <plugin>

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
index 07308f5..ebac2b1 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
@@ -17,10 +17,10 @@
 
 package org.apache.ignite.examples.ml.math.decompositions;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Tracer;
-import org.apache.ignite.math.decompositions.CholeskyDecomposition;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.decompositions.CholeskyDecomposition;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
 
 /**
  * Example of using {@link CholeskyDecomposition}.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
index 16e692b..cda37f4 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
@@ -17,10 +17,10 @@
 
 package org.apache.ignite.examples.ml.math.decompositions;
 
-import org.apache.ignite.math.Tracer;
-import org.apache.ignite.math.decompositions.EigenDecomposition;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.decompositions.EigenDecomposition;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
 
 /**
  * Example of using {@link EigenDecomposition}.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
index c670eab..a815047 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
@@ -17,10 +17,10 @@
 
 package org.apache.ignite.examples.ml.math.decompositions;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Tracer;
-import org.apache.ignite.math.decompositions.LUDecomposition;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.decompositions.LUDecomposition;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
 
 /**
  * Example of using {@link LUDecomposition}.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
index 281fbc4..81406ae 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
@@ -17,9 +17,9 @@
 
 package org.apache.ignite.examples.ml.math.decompositions;
 
-import org.apache.ignite.math.Tracer;
-import org.apache.ignite.math.decompositions.SingularValueDecomposition;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.decompositions.SingularValueDecomposition;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
 
 /**
  * Example of using {@link SingularValueDecomposition}.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
index 80f861f..ec414e5 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
@@ -21,11 +21,11 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.math.IdentityValueMapper;
-import org.apache.ignite.math.MatrixKeyMapper;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.impls.matrix.CacheMatrix;
+import org.apache.ignite.ml.math.IdentityValueMapper;
+import org.apache.ignite.ml.math.MatrixKeyMapper;
+import org.apache.ignite.ml.math.ValueMapper;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.impls.matrix.CacheMatrix;
 
 /** */
 public class CacheMatrixExample {

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
index d0c8604..5fb06d7 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
@@ -22,10 +22,10 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Arrays;
 
-import org.apache.ignite.math.MatrixStorage;
+import org.apache.ignite.ml.math.MatrixStorage;
 
 /**
- * Example matrix storage, modeled after {@link org.apache.ignite.math.impls.storage.matrix.ArrayMatrixStorage}.
+ * Example matrix storage, modeled after {@link org.apache.ignite.ml.math.impls.storage.matrix.ArrayMatrixStorage}.
  */
 class ExampleMatrixStorage implements MatrixStorage {
     /** Backing data array. */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
index b3df9f1..76716cc 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
@@ -17,11 +17,11 @@
 
 package org.apache.ignite.examples.ml.math.matrix;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.AbstractMatrix;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.AbstractMatrix;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
 
 /**
  * This example shows how to use {@link Matrix} API based on custom {@link MatrixStorage}.
@@ -82,7 +82,7 @@ public final class MatrixCustomStorageExample {
 
     /**
      * Example of vector with custom storage, modeled after
-     * {@link org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix}.
+     * {@link org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix}.
      */
     static class MatrixCustomStorage extends AbstractMatrix {
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
index 66f50d5..66db374 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.examples.ml.math.matrix;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
 
 /**
  * This example shows how to use {@link Matrix} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
index bf406a8..af12e15 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.examples.ml.math.matrix;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Tracer;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Tracer;
 
 /**
  * Utility functions for {@link Matrix} API examples.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
index 71dc2b8..f743bd9 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.examples.ml.math.matrix;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrix;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix;
 
 /**
  * This example shows how to use off-heap {@link Matrix} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
index ffbd9af..1e5f099 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
@@ -14,12 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.ignite.examples.ml.math.matrix;
 
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.impls.matrix.SparseDistributedMatrix;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
 import org.apache.ignite.thread.IgniteThread;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
index d63d985..d3715ea 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.examples.ml.math.matrix;
 
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.matrix.SparseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.matrix.SparseLocalOnHeapMatrix;
 
 /**
  * This example shows how to use sparse {@link Matrix} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
index 0bf7743..085153c 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
@@ -19,8 +19,8 @@ package org.apache.ignite.examples.ml.math.tracer;
 
 import java.awt.Color;
 import java.io.IOException;
-import org.apache.ignite.math.Tracer;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
 
 /**
  * Example of using {@link Tracer} utility API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
index 3e83ef5..789248c 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
@@ -21,10 +21,10 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.math.IdentityValueMapper;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.VectorKeyMapper;
-import org.apache.ignite.math.impls.vector.CacheVector;
+import org.apache.ignite.ml.math.IdentityValueMapper;
+import org.apache.ignite.ml.math.ValueMapper;
+import org.apache.ignite.ml.math.VectorKeyMapper;
+import org.apache.ignite.ml.math.impls.vector.CacheVector;
 
 /**
  * This example shows how to use {@link CacheVector} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
index b382c46..bc46b63 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
@@ -22,10 +22,10 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Arrays;
 
-import org.apache.ignite.math.VectorStorage;
+import org.apache.ignite.ml.math.VectorStorage;
 
 /**
- * Example vector storage, modeled after {@link org.apache.ignite.math.impls.storage.vector.ArrayVectorStorage}.
+ * Example vector storage, modeled after {@link org.apache.ignite.ml.math.impls.storage.vector.ArrayVectorStorage}.
  */
 class ExampleVectorStorage implements VectorStorage {
     /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
index 031843b..f470aef 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
@@ -18,8 +18,8 @@
 package org.apache.ignite.examples.ml.math.vector;
 
 import java.util.Arrays;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVector;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector;
 
 /**
  * This example shows how to use off-heap {@link Vector} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
index f5678f6..8ace55b 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
@@ -18,10 +18,10 @@
 package org.apache.ignite.examples.ml.math.vector;
 
 import java.util.Arrays;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.SparseLocalVector;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.vector.SparseLocalVector;
 
-import static org.apache.ignite.math.StorageConstants.RANDOM_ACCESS_MODE;
+import static org.apache.ignite.ml.math.StorageConstants.RANDOM_ACCESS_MODE;
 
 /**
  * This example shows how to use sparse {@link Vector} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
index 2d549ae..a7204ad 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
@@ -18,11 +18,11 @@
 package org.apache.ignite.examples.ml.math.vector;
 
 import java.util.Arrays;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.vector.AbstractVector;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.vector.AbstractVector;
 
 /**
  * This example shows how to use {@link Vector} based on custom {@link VectorStorage}.
@@ -78,7 +78,7 @@ public final class VectorCustomStorageExample {
 
     /**
      * Example of vector with custom storage, modeled after
-     * {@link org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector}.
+     * {@link org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector}.
      */
     static class VectorCustomStorage extends AbstractVector {
         /**
@@ -118,7 +118,7 @@ public final class VectorCustomStorageExample {
 
         /** {@inheritDoc */
         @Override public Vector like(int crd) {
-            return new org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector(crd);
+            return new org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector(crd);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
index d6971a7..3390de5 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
@@ -18,8 +18,8 @@
 package org.apache.ignite.examples.ml.math.vector;
 
 import java.util.Arrays;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
 
 /**
  * This example shows how to use {@link Vector} API.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/pom.xml
----------------------------------------------------------------------
diff --git a/modules/ml/pom.xml b/modules/ml/pom.xml
index 4755a2c..e6f5acb 100644
--- a/modules/ml/pom.xml
+++ b/modules/ml/pom.xml
@@ -100,10 +100,4 @@
             </plugin>
         </plugins>
     </build>
-
-    <profiles>
-        <profile>
-            <id>math</id>
-        </profile>
-    </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/Algebra.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/Algebra.java b/modules/ml/src/main/java/org/apache/ignite/math/Algebra.java
deleted file mode 100644
index 6bfd608..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/Algebra.java
+++ /dev/null
@@ -1,571 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
-Copyright 1999 CERN - European Organization for Nuclear Research.
-Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
-is hereby granted without fee, provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear in supporting documentation.
-CERN makes no representations about the suitability of this software for any purpose.
-It is provided "as is" without expressed or implied warranty.
-*/
-
-package org.apache.ignite.math;
-
-/**
- * Miscellaneous arithmetic and algebra functions.
- * Lifted from Apache Mahout.
- */
-public class Algebra extends Constants {
-    /** */ private static final double[] STIRLING_CORRECTION = {
-        0.0,
-        8.106146679532726e-02, 4.134069595540929e-02,
-        2.767792568499834e-02, 2.079067210376509e-02,
-        1.664469118982119e-02, 1.387612882307075e-02,
-        1.189670994589177e-02, 1.041126526197209e-02,
-        9.255462182712733e-03, 8.330563433362871e-03,
-        7.573675487951841e-03, 6.942840107209530e-03,
-        6.408994188004207e-03, 5.951370112758848e-03,
-        5.554733551962801e-03, 5.207655919609640e-03,
-        4.901395948434738e-03, 4.629153749334029e-03,
-        4.385560249232324e-03, 4.166319691996922e-03,
-        3.967954218640860e-03, 3.787618068444430e-03,
-        3.622960224683090e-03, 3.472021382978770e-03,
-        3.333155636728090e-03, 3.204970228055040e-03,
-        3.086278682608780e-03, 2.976063983550410e-03,
-        2.873449362352470e-03, 2.777674929752690e-03,
-    };
-
-    /** */ private static final double[] LOG_FACTORIALS = {
-        0.00000000000000000, 0.00000000000000000, 0.69314718055994531,
-        1.79175946922805500, 3.17805383034794562, 4.78749174278204599,
-        6.57925121201010100, 8.52516136106541430, 10.60460290274525023,
-        12.80182748008146961, 15.10441257307551530, 17.50230784587388584,
-        19.98721449566188615, 22.55216385312342289, 25.19122118273868150,
-        27.89927138384089157, 30.67186010608067280, 33.50507345013688888,
-        36.39544520803305358, 39.33988418719949404, 42.33561646075348503,
-        45.38013889847690803, 48.47118135183522388, 51.60667556776437357,
-        54.78472939811231919, 58.00360522298051994, 61.26170176100200198,
-        64.55753862700633106, 67.88974313718153498, 71.25703896716800901
-    };
-
-    /** */ private static final long[] LONG_FACTORIALS = {
-        1L,
-        1L,
-        2L,
-        6L,
-        24L,
-        120L,
-        720L,
-        5040L,
-        40320L,
-        362880L,
-        3628800L,
-        39916800L,
-        479001600L,
-        6227020800L,
-        87178291200L,
-        1307674368000L,
-        20922789888000L,
-        355687428096000L,
-        6402373705728000L,
-        121645100408832000L,
-        2432902008176640000L
-    };
-
-    /** */ private static final double[] DOUBLE_FACTORIALS = {
-        5.109094217170944E19,
-        1.1240007277776077E21,
-        2.585201673888498E22,
-        6.204484017332394E23,
-        1.5511210043330984E25,
-        4.032914611266057E26,
-        1.0888869450418352E28,
-        3.048883446117138E29,
-        8.841761993739701E30,
-        2.652528598121911E32,
-        8.222838654177924E33,
-        2.6313083693369355E35,
-        8.68331761881189E36,
-        2.952327990396041E38,
-        1.0333147966386144E40,
-        3.719933267899013E41,
-        1.3763753091226346E43,
-        5.23022617466601E44,
-        2.0397882081197447E46,
-        8.15915283247898E47,
-        3.34525266131638E49,
-        1.4050061177528801E51,
-        6.041526306337384E52,
-        2.6582715747884495E54,
-        1.196222208654802E56,
-        5.502622159812089E57,
-        2.5862324151116827E59,
-        1.2413915592536068E61,
-        6.082818640342679E62,
-        3.0414093201713376E64,
-        1.5511187532873816E66,
-        8.06581751709439E67,
-        4.274883284060024E69,
-        2.308436973392413E71,
-        1.2696403353658264E73,
-        7.109985878048632E74,
-        4.052691950487723E76,
-        2.350561331282879E78,
-        1.386831185456898E80,
-        8.32098711274139E81,
-        5.075802138772246E83,
-        3.146997326038794E85,
-        1.9826083154044396E87,
-        1.2688693218588414E89,
-        8.247650592082472E90,
-        5.443449390774432E92,
-        3.6471110918188705E94,
-        2.48003554243683E96,
-        1.7112245242814127E98,
-        1.1978571669969892E100,
-        8.504785885678624E101,
-        6.123445837688612E103,
-        4.470115461512686E105,
-        3.307885441519387E107,
-        2.4809140811395404E109,
-        1.8854947016660506E111,
-        1.451830920282859E113,
-        1.1324281178206295E115,
-        8.94618213078298E116,
-        7.15694570462638E118,
-        5.797126020747369E120,
-        4.7536433370128435E122,
-        3.94552396972066E124,
-        3.314240134565354E126,
-        2.8171041143805494E128,
-        2.4227095383672744E130,
-        2.107757298379527E132,
-        1.854826422573984E134,
-        1.6507955160908465E136,
-        1.4857159644817605E138,
-        1.3520015276784033E140,
-        1.2438414054641305E142,
-        1.156772507081641E144,
-        1.0873661566567426E146,
-        1.0329978488239061E148,
-        9.916779348709491E149,
-        9.619275968248216E151,
-        9.426890448883248E153,
-        9.332621544394415E155,
-        9.332621544394418E157,
-        9.42594775983836E159,
-        9.614466715035125E161,
-        9.902900716486178E163,
-        1.0299016745145631E166,
-        1.0813967582402912E168,
-        1.1462805637347086E170,
-        1.2265202031961373E172,
-        1.324641819451829E174,
-        1.4438595832024942E176,
-        1.5882455415227423E178,
-        1.7629525510902457E180,
-        1.974506857221075E182,
-        2.2311927486598138E184,
-        2.543559733472186E186,
-        2.925093693493014E188,
-        3.393108684451899E190,
-        3.96993716080872E192,
-        4.6845258497542896E194,
-        5.574585761207606E196,
-        6.689502913449135E198,
-        8.094298525273444E200,
-        9.875044200833601E202,
-        1.2146304367025332E205,
-        1.506141741511141E207,
-        1.882677176888926E209,
-        2.3721732428800483E211,
-        3.0126600184576624E213,
-        3.856204823625808E215,
-        4.974504222477287E217,
-        6.466855489220473E219,
-        8.471580690878813E221,
-        1.1182486511960037E224,
-        1.4872707060906847E226,
-        1.99294274616152E228,
-        2.690472707318049E230,
-        3.6590428819525483E232,
-        5.0128887482749884E234,
-        6.917786472619482E236,
-        9.615723196941089E238,
-        1.3462012475717523E241,
-        1.8981437590761713E243,
-        2.6953641378881633E245,
-        3.8543707171800694E247,
-        5.550293832739308E249,
-        8.047926057471989E251,
-        1.1749972043909107E254,
-        1.72724589045464E256,
-        2.5563239178728637E258,
-        3.8089226376305687E260,
-        5.7133839564458575E262,
-        8.627209774233244E264,
-        1.3113358856834527E267,
-        2.0063439050956838E269,
-        3.0897696138473515E271,
-        4.789142901463393E273,
-        7.471062926282892E275,
-        1.1729568794264134E278,
-        1.8532718694937346E280,
-        2.946702272495036E282,
-        4.714723635992061E284,
-        7.590705053947223E286,
-        1.2296942187394494E289,
-        2.0044015765453032E291,
-        3.287218585534299E293,
-        5.423910666131583E295,
-        9.003691705778434E297,
-        1.5036165148649983E300,
-        2.5260757449731988E302,
-        4.2690680090047056E304,
-        7.257415615308004E306
-    };
-
-    /**
-     * Efficiently returns the binomial coefficient, often also referred to as
-     * "n over k" or "n choose k". The binomial coefficient is defined as
-     * {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )}.
-     * <ul> <li>{@code k&lt;0}: {@code 0}.</li>
-     * <li>{@code k==0}: {@code 1}.</li>
-     * <li>{@code k==1}: {@code n}.</li>
-     * <li>else: {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k)}.</li>
-     * </ul>
-     *
-     * @param n
-     * @param k
-     * @return Binomial coefficient.
-     */
-    public static double binomial(double n, long k) {
-        if (k < 0)
-            return 0;
-
-        if (k == 0)
-            return 1;
-
-        if (k == 1)
-            return n;
-
-        // binomial(n,k) = (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )
-        double a = n - k + 1;
-        double b = 1;
-        double binomial = 1;
-
-        for (long i = k; i-- > 0; )
-            binomial *= (a++) / (b++);
-
-        return binomial;
-    }
-
-    /**
-     * Efficiently returns the binomial coefficient, often also referred to as "n over k" or "n choose k".
-     * The binomial coefficient is defined as
-     * <ul> <li>{@code k&lt;0}: {@code 0}. <li>{@code k==0 || k==n}: {@code 1}. <li>{@code k==1 || k==n-1}:
-     * {@code n}. <li>else: {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )}. </ul>
-     *
-     * @param n
-     * @param k
-     * @return Binomial coefficient.
-     */
-    public static double binomial(long n, long k) {
-        if (k < 0)
-            return 0;
-
-        if (k == 0 || k == n)
-            return 1;
-
-        if (k == 1 || k == n - 1)
-            return n;
-
-        if (n > k) {
-            int max = LONG_FACTORIALS.length + DOUBLE_FACTORIALS.length;
-
-            if (n < max) {
-                double nFac = factorial((int)n);
-                double kFac = factorial((int)k);
-                double nMinusKFac = factorial((int)(n - k));
-                double nk = nMinusKFac * kFac;
-
-                if (nk != Double.POSITIVE_INFINITY) // No numeric overflow?
-                    return nFac / nk;
-            }
-
-            if (k > n / 2)
-                k = n - k;
-        }
-
-        // binomial(n,k) = (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )
-        long a = n - k + 1;
-        long b = 1;
-        double binomial = 1;
-
-        for (long i = k; i-- > 0; )
-            binomial *= (double)a++ / (b++);
-
-        return binomial;
-    }
-
-    /**
-     * Returns the smallest <code>long &gt;= value</code>.
-     * <dl><dt>Examples: {@code 1.0 -> 1, 1.2 -> 2, 1.9 -> 2}. This
-     * method is safer than using (long) Math.ceil(value), because of possible rounding error.</dt></dl>
-     *
-     * @param val
-     */
-    public static long ceil(double val) {
-        return Math.round(Math.ceil(val));
-    }
-
-    /**
-     * Evaluates the series of Chebyshev polynomials Ti at argument x/2. The series is given by
-     * <pre>
-     *        N-1
-     *         - '
-     *  y  =   &gt;   coef[i] T (x/2)
-     *         -            i
-     *        i=0
-     * </pre>
-     * Coefficients are stored in reverse order, i.e. the zero order term is last in the array.  Note N is the number of
-     * coefficients, not the order. <p> If coefficients are for the interval a to b, x must have been transformed to x
-     * -&lt; 2(2x - b - a)/(b-a) before entering the routine.  This maps x from (a, b) to (-1, 1), over which the
-     * Chebyshev polynomials are defined. <p> If the coefficients are for the inverted interval, in which (a, b) is
-     * mapped to (1/b, 1/a), the transformation required is {@code x -> 2(2ab/x - b - a)/(b-a)}.  If b is infinity, this
-     * becomes {@code x -> 4a/x - 1}. <p> SPEED: <p> Taking advantage of the recurrence properties of the Chebyshev
-     * polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same
-     * degree.
-     *
-     * @param x Argument to the polynomial.
-     * @param coef Coefficients of the polynomial.
-     * @param N Number of coefficients.
-     */
-    public static double chbevl(double x, double[] coef, int N) {
-        int p = 0;
-
-        double b0 = coef[p++];
-        double b1 = 0.0;
-        int i = N - 1;
-
-        double b2;
-
-        do {
-            b2 = b1;
-            b1 = b0;
-            b0 = x * b1 - b2 + coef[p++];
-        }
-        while (--i > 0);
-
-        return 0.5 * (b0 - b2);
-    }
-
-    /**
-     * Instantly returns the factorial {@code k!}.
-     *
-     * @param k must hold {@code k &gt;= 0}.
-     */
-    private static double factorial(int k) {
-        if (k < 0)
-            throw new IllegalArgumentException();
-
-        int len1 = LONG_FACTORIALS.length;
-
-        if (k < len1)
-            return LONG_FACTORIALS[k];
-
-        int len2 = DOUBLE_FACTORIALS.length;
-
-        return (k < len1 + len2) ? DOUBLE_FACTORIALS[k - len1] : Double.POSITIVE_INFINITY;
-    }
-
-    /**
-     * Returns the largest <code>long &lt;= value</code>.
-     * <dl><dt>Examples: {@code 1.0 -> 1, 1.2 -> 1, 1.9 -> 1 <dt> 2.0 -> 2, 2.2 -> 2, 2.9 -> 2}</dt></dl>
-     * This method is safer than using (long) Math.floor(value), because of possible rounding error.
-     */
-    public static long floor(double val) {
-        return Math.round(Math.floor(val));
-    }
-
-    /**
-     * Returns {@code log<sub>base</sub>value}.
-     */
-    public static double log(double base, double val) {
-        return Math.log(val) / Math.log(base);
-    }
-
-    /**
-     * Returns {@code log<sub>10</sub>value}.
-     */
-    public static double log10(double val) {
-        // 1.0 / Math.log(10) == 0.43429448190325176
-        return Math.log(val) * 0.43429448190325176;
-    }
-
-    /**
-     * Returns {@code log<sub>2</sub>value}.
-     */
-    public static double log2(double val) {
-        // 1.0 / Math.log(2) == 1.4426950408889634
-        return Math.log(val) * 1.4426950408889634;
-    }
-
-    /**
-     * Returns {@code log(k!)}. Tries to avoid overflows. For {@code k&lt;30} simply looks up a table in O(1).
-     * For {@code k&gt;=30} uses stirlings approximation.
-     *
-     * @param k must hold {@code k &gt;= 0}.
-     */
-    public static double logFactorial(int k) {
-        if (k >= 30) {
-            double r = 1.0 / k;
-            double rr = r * r;
-            double C7 = -5.95238095238095238e-04;
-            double C5 = 7.93650793650793651e-04;
-            double C3 = -2.77777777777777778e-03;
-            double C1 = 8.33333333333333333e-02;
-            double C0 = 9.18938533204672742e-01;
-
-            return (k + 0.5) * Math.log(k) - k + C0 + r * (C1 + rr * (C3 + rr * (C5 + rr * C7)));
-        }
-        else
-            return LOG_FACTORIALS[k];
-    }
-
-    /**
-     * Instantly returns the factorial {@code k!}.
-     *
-     * @param k must hold {@code k >= 0 && k < 21}
-     */
-    public static long longFactorial(int k) {
-        if (k < 0)
-            throw new IllegalArgumentException("Negative k");
-
-        if (k < LONG_FACTORIALS.length)
-            return LONG_FACTORIALS[k];
-
-        throw new IllegalArgumentException("Overflow");
-    }
-
-    /**
-     * Returns the StirlingCorrection.
-     *
-     * Correction term of the Stirling approximation for {@code log(k!)} (series in
-     * 1/k, or table values for small k) with int parameter k. </p> {@code  log k! = (k + 1/2)log(k + 1) - (k + 1) +
-     * (1/2)log(2Pi) + STIRLING_CORRECTION(k + 1) log k! = (k + 1/2)log(k)     -  k      + (1/2)log(2Pi) +
-     * STIRLING_CORRECTION(k) }
-     */
-    public static double stirlingCorrection(int k) {
-        if (k > 30) {
-            double r = 1.0 / k;
-            double rr = r * r;
-            double C7 = -5.95238095238095238e-04;
-            double C5 = 7.93650793650793651e-04;
-            double C3 = -2.77777777777777778e-03;
-            double C1 = 8.33333333333333333e-02;
-
-            return r * (C1 + rr * (C3 + rr * (C5 + rr * C7)));
-        }
-        else
-            return STIRLING_CORRECTION[k];
-    }
-
-    /**
-     * Evaluates the given polynomial of degree {@code N} at {@code x}, assuming coefficient of N is 1.0. Otherwise same
-     * as {@link #evalPoly(double, double[], int)}.
-     * <pre>
-     *                     2          N
-     * y  =  C  + C x + C x  +...+ C x
-     *        0    1     2          N
-     *
-     * where C  = 1 and hence is omitted from the array.
-     *        N
-     *
-     * Coefficients are stored in reverse order:
-     *
-     * coef[0] = C  , ..., coef[N-1] = C  .
-     *            N-1                   0
-     *
-     * Calling arguments are otherwise the same as {@link #evalPoly(double, double[], int)}.
-     * </pre>
-     * In the interest of speed, there are no checks for out of bounds arithmetic.
-     *
-     * @param x Argument to the polynomial.
-     * @param coef Coefficients of the polynomial.
-     * @param n Degree of the polynomial.
-     */
-    public static double evalPoly1(double x, double[] coef, int n) {
-        double res = x + coef[0];
-
-        for (int i = 1; i < n; i++)
-            res = res * x + coef[i];
-
-        return res;
-    }
-
-    /**
-     * Evaluates the given polynomial of degree {@code N} at {@code x}.
-     * <pre>
-     *                     2          N
-     * y  =  C  + C x + C x  +...+ C x
-     *        0    1     2          N
-     *
-     * Coefficients are stored in reverse order:
-     *
-     * coef[0] = C  , ..., coef[N] = C  .
-     *            N                   0
-     * </pre>
-     * In the interest of speed, there are no checks for out of bounds arithmetic.
-     *
-     * @param x Argument to the polynomial.
-     * @param coef Coefficients of the polynomial.
-     * @param n Degree of the polynomial.
-     */
-    public static double evalPoly(double x, double[] coef, int n) {
-        double res = coef[0];
-
-        for (int i = 1; i <= n; i++)
-            res = res * x + coef[i];
-
-        return res;
-    }
-
-    /**
-     * Gets <code>sqrt(a^2 + b^2)</code> without under/overflow.
-     *
-     * @param a
-     * @param b
-     */
-    public static double hypot(double a, double b) {
-        double r;
-
-        if (Math.abs(a) > Math.abs(b)) {
-            r = b / a;
-            r = Math.abs(a) * Math.sqrt(1 + r * r);
-        }
-        else if (b != 0) {
-            r = a / b;
-            r = Math.abs(b) * Math.sqrt(1 + r * r);
-        }
-        else
-            r = 0.0;
-
-        return r;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/Constants.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/Constants.java b/modules/ml/src/main/java/org/apache/ignite/math/Constants.java
deleted file mode 100644
index 02756b6..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/Constants.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
-Copyright 1999 CERN - European Organization for Nuclear Research.
-Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
-is hereby granted without fee, provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear in supporting documentation.
-CERN makes no representations about the suitability of this software for any purpose.
-It is provided "as is" without expressed or implied warranty.
-*/
-
-package org.apache.ignite.math;
-
-/**
- * Math constants. Lifted from Apache Mahout.
- */
-public class Constants {
-    /** */ public static final double MACHEP = 1.11022302462515654042E-16;
-    /** */ public static final double MAXLOG = 7.09782712893383996732E2;
-    /** */ public static final double MINLOG = -7.451332191019412076235E2;
-    /** */ public static final double MAXGAM = 171.624376956302725;
-    /** */ public static final double SQTPI = 2.50662827463100050242E0;
-    /** */ public static final double SQRTH = 7.07106781186547524401E-1;
-    /** */ public static final double LOGPI = 1.14472988584940017414;
-    /** */ public static final double BIG = 4.503599627370496e15;
-    /** */ public static final double BIGINV = 2.22044604925031308085e-16;
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/Destroyable.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/Destroyable.java b/modules/ml/src/main/java/org/apache/ignite/math/Destroyable.java
deleted file mode 100644
index f3b467c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/Destroyable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-/**
- * Support for destroying objects that are managed outside of JVM.
- */
-public interface Destroyable {
-    /**
-     * Destroys object if managed outside of JVM. It's a no-op in all other cases.
-     */
-    public default void destroy() {
-        // No-op.
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/IdentityValueMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/IdentityValueMapper.java b/modules/ml/src/main/java/org/apache/ignite/math/IdentityValueMapper.java
deleted file mode 100644
index 65c7024..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/IdentityValueMapper.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-/**
- * Identity value mapper.
- */
-public class IdentityValueMapper implements ValueMapper<Double> {
-    /** */ private static final long serialVersionUID = -8010078306142216389L;
-
-    /** {@inheritDoc} */
-    @Override public Double fromDouble(double v) {
-        return v;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double toDouble(Double v) {
-        assert v != null;
-
-        return v;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return Long.hashCode(serialVersionUID);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/KeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/KeyMapper.java b/modules/ml/src/main/java/org/apache/ignite/math/KeyMapper.java
deleted file mode 100644
index f4f9a39..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/KeyMapper.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.io.Serializable;
-
-/**
- * Maps key objects to index in {@link Vector} or {@link Matrix}.
- */
-public interface KeyMapper<K> extends Serializable {
-    /**
-     * Checks given cache key corresponds to a valid index in vector or matrix.
-     *
-     * @param k Key to check.
-     * @return {@code true} if there is a valid index, {@code false} otherwise.
-     */
-    public boolean isValid(K k);
-}


[19/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/CacheVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/CacheVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/CacheVectorStorage.java
deleted file mode 100644
index 670deef..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/CacheVectorStorage.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.VectorKeyMapper;
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * Vector storage based on existing cache and index and value mapping functions.
- */
-public class CacheVectorStorage<K, V> implements VectorStorage {
-    /** Storage size. */
-    private int size;
-    /** Key mapper. */
-    private VectorKeyMapper<K> keyMapper;
-    /** Value mapper. */
-    private ValueMapper<V> valMapper;
-    /** Underlying ignite cache. */
-    private IgniteCache<K, V> cache;
-
-    /**
-     *
-     */
-    public CacheVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size
-     * @param cache
-     * @param keyMapper
-     * @param valMapper
-     */
-    public CacheVectorStorage(int size, IgniteCache<K, V> cache, VectorKeyMapper<K> keyMapper,
-        ValueMapper<V> valMapper) {
-        assert size > 0;
-        assert cache != null;
-        assert keyMapper != null;
-        assert valMapper != null;
-
-        this.size = size;
-        this.cache = cache;
-        this.keyMapper = keyMapper;
-        this.valMapper = valMapper;
-    }
-
-    /**
-     *
-     *
-     */
-    public IgniteCache<K, V> cache() {
-        return cache;
-    }
-
-    /**
-     *
-     *
-     */
-    public VectorKeyMapper<K> keyMapper() {
-        return keyMapper;
-    }
-
-    /**
-     *
-     *
-     */
-    public ValueMapper<V> valueMapper() {
-        return valMapper;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return valMapper.toDouble(cache.get(keyMapper.apply(i)));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        cache.put(keyMapper.apply(i), valMapper.fromDouble(v));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(size);
-        out.writeObject(keyMapper);
-        out.writeObject(valMapper);
-        out.writeUTF(cache.getName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        size = in.readInt();
-        keyMapper = (VectorKeyMapper<K>)in.readObject();
-        valMapper = (ValueMapper<V>)in.readObject();
-        cache = Ignition.localIgnite().getOrCreateCache(in.readUTF());
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + size();
-        res = res * 37 + keyMapper.hashCode();
-        res = res * 37 + valMapper.hashCode();
-        res = res * 37 + cache.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-
-        if (obj == null || getClass() != obj.getClass())
-            return false;
-
-        CacheVectorStorage that = (CacheVectorStorage)obj;
-
-        return size == that.size
-            && (keyMapper != null ? keyMapper.getClass().equals(that.keyMapper.getClass()) : that.keyMapper == null)
-            && (valMapper != null ? valMapper.getClass().equals(that.valMapper.getClass()) : that.valMapper == null)
-            && (cache != null ? cache.equals(that.cache) : that.cache == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ConstantVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ConstantVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ConstantVectorStorage.java
deleted file mode 100644
index ff5ab26..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ConstantVectorStorage.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * Constant read-only vector storage.
- */
-public class ConstantVectorStorage implements VectorStorage {
-    /** */ private int size;
-    /** */ private double val;
-
-    /**
-     *
-     */
-    public ConstantVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size Vector size.
-     * @param val Value to set for vector elements.
-     */
-    public ConstantVectorStorage(int size, double val) {
-        assert size > 0;
-
-        this.size = size;
-        this.val = val;
-    }
-
-    /**
-     *
-     *
-     */
-    public double constant() {
-        return val;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return val;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        throw new UnsupportedOperationException("Can't set value into constant vector.");
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(size);
-        out.writeDouble(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        size = in.readInt();
-        val = in.readDouble();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + size;
-        res = res * 37 + Double.hashCode(val);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        ConstantVectorStorage that = (ConstantVectorStorage)o;
-
-        return size == that.size && val == that.val;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DelegateVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DelegateVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DelegateVectorStorage.java
deleted file mode 100644
index aa6018c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DelegateVectorStorage.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * {@link VectorStorage} implementation that delegates to parent matrix.
- */
-public class DelegateVectorStorage implements VectorStorage {
-    /** Parent vector storage. */
-    private VectorStorage sto;
-
-    /** Offset in the parent vector. */
-    private int off;
-
-    /** Size of the vector. */
-    private int len;
-
-    /**
-     *
-     */
-    public DelegateVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param sto Vector storage to delegate to.
-     * @param off Offset in the parent vector.
-     * @param len Size of the vector.
-     */
-    public DelegateVectorStorage(VectorStorage sto, int off, int len) {
-        assert sto != null;
-        assert off >= 0;
-        assert len > 0;
-
-        this.sto = sto;
-        this.off = off;
-        this.len = len;
-    }
-
-    /** */
-    public VectorStorage delegate() {
-        return sto;
-    }
-
-    /** */
-    public int offset() {
-        return off;
-    }
-
-    /** */
-    public int length() {
-        return len;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return len;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return sto.get(off + i);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        sto.set(off + i, v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[] data() {
-        return sto.data();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return sto.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return sto.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return sto.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return sto.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return sto.isArrayBased();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sto);
-        out.writeInt(off);
-        out.writeInt(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sto = (VectorStorage)in.readObject();
-        off = in.readInt();
-        len = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        DelegateVectorStorage that = (DelegateVectorStorage)o;
-
-        return len == that.len && off == that.off && (sto != null ? sto.equals(that.sto) : that.sto == null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + off;
-        res = res * 37 + len;
-        res = res * 37 + sto.hashCode();
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java
deleted file mode 100644
index 2e7cdc9..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.stream.IntStream;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * Local, dense off-heap vector storage.
- */
-public class DenseLocalOffHeapVectorStorage implements VectorStorage {
-    /** Vector size. */
-    private int size;
-
-    /** */
-    private transient long ptr;
-    //TODO: temp solution.
-    /** */
-    private int ptrInitHash;
-
-    /**
-     *
-     */
-    public DenseLocalOffHeapVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size Vector size.
-     */
-    public DenseLocalOffHeapVectorStorage(int size) {
-        assert size > 0;
-
-        this.size = size;
-
-        allocateMemory(size);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return GridUnsafe.getDouble(pointerOffset(i));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        GridUnsafe.putDouble(pointerOffset(i), v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[] data() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(size);
-        out.writeInt(ptrInitHash);
-
-        for (int i = 0; i < size; i++)
-            out.writeDouble(get(i));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        size = in.readInt();
-
-        allocateMemory(size);
-
-        ptrInitHash = in.readInt();
-
-        for (int i = 0; i < size; i++)
-            set(i, in.readDouble());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        GridUnsafe.freeMemory(ptr);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + size;
-        res = res * 37 + ptrInitHash;
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        DenseLocalOffHeapVectorStorage that = (DenseLocalOffHeapVectorStorage)o;
-
-        return size == that.size && isMemoryEquals(that);
-    }
-
-    /** */
-    private boolean isMemoryEquals(DenseLocalOffHeapVectorStorage otherStorage) {
-        return IntStream.range(0, size).parallel().noneMatch(idx -> Double.compare(get(idx), otherStorage.get(idx)) != 0);
-    }
-
-    /**
-     * Pointer offset for specific index.
-     *
-     * @param i Offset index.
-     */
-    private long pointerOffset(int i) {
-        return ptr + i * Double.BYTES;
-    }
-
-    /** */
-    private void allocateMemory(int size) {
-        ptr = GridUnsafe.allocateMemory(size * Double.BYTES);
-
-        ptrInitHash = Long.hashCode(ptr);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/FunctionVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/FunctionVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/FunctionVectorStorage.java
deleted file mode 100644
index df8fa12..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/FunctionVectorStorage.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.functions.IntDoubleToVoidFunction;
-
-/**
- * Read-only or read-write function-based vector storage.
- */
-public class FunctionVectorStorage implements VectorStorage {
-    /** */ private IgniteFunction<Integer, Double> getFunc;
-    /** */ private IntDoubleToVoidFunction setFunc;
-    /** */ private int size;
-
-    /**
-     *
-     */
-    public FunctionVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * Creates read-only or read-write storage.
-     *
-     * @param size Cardinality of this vector storage.
-     * @param getFunc Get function.
-     * @param setFunc Optional set function ({@code null} for read-only storage).
-     */
-    public FunctionVectorStorage(int size, IgniteFunction<Integer, Double> getFunc, IntDoubleToVoidFunction setFunc) {
-        assert size > 0;
-        assert getFunc != null; // At least get function is required.
-
-        this.size = size;
-        this.getFunc = getFunc;
-        this.setFunc = setFunc;
-    }
-
-    /**
-     *
-     *
-     */
-    public IgniteFunction<Integer, Double> getFunction() {
-        return getFunc;
-    }
-
-    /**
-     *
-     *
-     */
-    public IntDoubleToVoidFunction setFunction() {
-        return setFunc;
-    }
-
-    /**
-     * Creates read-only storage.
-     *
-     * @param size Cardinality of this vector storage.
-     * @param getFunc Get function.
-     */
-    public FunctionVectorStorage(int size, IgniteFunction<Integer, Double> getFunc) {
-        this(size, getFunc, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return getFunc.apply(i);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        if (setFunc != null)
-            setFunc.accept(i, v);
-        else
-            throw new UnsupportedOperationException("Cannot set into read-only vector.");
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(setFunc);
-        out.writeObject(getFunc);
-        out.writeInt(size);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        setFunc = (IntDoubleToVoidFunction)in.readObject();
-        getFunc = (IgniteFunction<Integer, Double>)in.readObject();
-        size = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/MatrixVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/MatrixVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/MatrixVectorStorage.java
deleted file mode 100644
index ece0003..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/MatrixVectorStorage.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.IndexException;
-
-/**
- * Row, column or diagonal vector-based view of the matrix
- */
-public class MatrixVectorStorage implements VectorStorage {
-    /** */ private Matrix parent;
-
-    /** */ private int row;
-    /** */ private int col;
-
-    /** */ private int rowStride;
-    /** */  private int colStride;
-
-    /** */ private int size;
-
-    /**
-     *
-     */
-    public MatrixVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param parent
-     * @param row
-     * @param col
-     * @param rowStride
-     * @param colStride
-     */
-    public MatrixVectorStorage(Matrix parent, int row, int col, int rowStride, int colStride) {
-        assert parent != null;
-        assert rowStride >= 0;
-        assert colStride >= 0;
-        assert rowStride > 0 || colStride > 0;
-
-        if (row < 0 || row >= parent.rowSize())
-            throw new IndexException(row);
-        if (col < 0 || col >= parent.columnSize())
-            throw new IndexException(col);
-
-        this.parent = parent;
-
-        this.row = row;
-        this.col = col;
-
-        this.rowStride = rowStride;
-        this.colStride = colStride;
-
-        this.size = getSize();
-    }
-
-    /**
-     *
-     *
-     */
-    int row() {
-        return row;
-    }
-
-    /**
-     *
-     *
-     */
-    int column() {
-        return col;
-    }
-
-    /**
-     *
-     *
-     */
-    int rowStride() {
-        return rowStride;
-    }
-
-    /**
-     *
-     *
-     */
-    int columnStride() {
-        return colStride;
-    }
-
-    /**
-     *
-     *
-     */
-    private int getSize() {
-        if (rowStride != 0 && colStride != 0) {
-            int n1 = (parent.rowSize() - row) / rowStride;
-            int n2 = (parent.columnSize() - col) / colStride;
-
-            return Math.min(n1, n2);
-        }
-        else if (rowStride > 0)
-            return (parent.rowSize() - row) / rowStride;
-        else
-            return (parent.columnSize() - col) / colStride;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return parent.get(row + i * rowStride, col + i * colStride);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        parent.set(row + i * rowStride, col + i * colStride, v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return parent.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return parent.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return parent.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return parent.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(parent);
-        out.writeInt(row);
-        out.writeInt(col);
-        out.writeInt(rowStride);
-        out.writeInt(colStride);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        parent = (Matrix)in.readObject();
-        row = in.readInt();
-        col = in.readInt();
-        rowStride = in.readInt();
-        colStride = in.readInt();
-
-        size = getSize();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/PivotedVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/PivotedVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/PivotedVectorStorage.java
deleted file mode 100644
index f69e959..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/PivotedVectorStorage.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * Pivoted (index mapped) view over another vector storage implementation.
- */
-public class PivotedVectorStorage implements VectorStorage {
-    /** */ private VectorStorage sto;
-
-    /** */ private int[] pivot;
-    /** */ private int[] unpivot;
-
-    /**
-     * @param pivot Pivot array.
-     */
-    private static int[] reverse(int[] pivot) {
-        int[] res = new int[pivot.length];
-
-        for (int i = 0; i < pivot.length; i++)
-            res[pivot[i]] = i;
-
-        return res;
-    }
-
-    /**
-     *
-     *
-     */
-    public int[] pivot() {
-        return pivot;
-    }
-
-    /**
-     *
-     *
-     */
-    public int[] unpivot() {
-        return unpivot;
-    }
-
-    /**
-     * @param sto Backing vector storage.
-     * @param pivot Mapping from external index to internal.
-     * @param unpivot Mapping from internal index to external.
-     */
-    public PivotedVectorStorage(VectorStorage sto, int[] pivot, int[] unpivot) {
-        assert sto != null;
-        assert pivot != null;
-        assert unpivot != null;
-
-        this.sto = sto;
-        this.pivot = pivot;
-        this.unpivot = unpivot;
-    }
-
-    /**
-     * @param sto Backing vector storage.
-     * @param pivot Mapping from external index to internal.
-     */
-    public PivotedVectorStorage(VectorStorage sto, int[] pivot) {
-        this(sto, pivot, reverse(pivot));
-    }
-
-    /**
-     *
-     */
-    public PivotedVectorStorage() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return sto.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return sto.get(pivot[i]);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        sto.set(pivot[i], v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sto);
-        out.writeObject(pivot);
-        out.writeObject(unpivot);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sto = (VectorStorage)in.readObject();
-        pivot = (int[])in.readObject();
-        unpivot = (int[])in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return sto.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return sto.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return sto.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return sto.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return sto.isArrayBased();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[] data() {
-        return isArrayBased() ? sto.data() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        PivotedVectorStorage that = (PivotedVectorStorage)o;
-
-        return (sto != null ? sto.equals(that.sto) : that.sto == null) && Arrays.equals(pivot, that.pivot)
-            && Arrays.equals(unpivot, that.unpivot);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = sto != null ? sto.hashCode() : 0;
-
-        res = 31 * res + Arrays.hashCode(pivot);
-        res = 31 * res + Arrays.hashCode(unpivot);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/RandomVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/RandomVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/RandomVectorStorage.java
deleted file mode 100644
index 58f0fb4..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/RandomVectorStorage.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.nio.ByteBuffer;
-import java.util.Random;
-import org.apache.ignite.math.MurmurHash;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * {@link VectorStorage} implementation with random values in the vector elements.
- */
-public class RandomVectorStorage implements VectorStorage {
-    /** */
-    private static final long SCALE = 1L << 32;
-    /** */
-    private static final int PRIME = 104047;
-
-    /** Random generation seed. */
-    private int seed;
-
-    /** Vector size. */
-    private int size;
-
-    /** Whether fast hash is used, in {@link #get(int)}. */
-    private boolean fastHash;
-
-    /** */
-    public RandomVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size Size of the storage.
-     * @param fastHash Whether or not to use fast hashing or Murmur hashing.
-     */
-    public RandomVectorStorage(int size, boolean fastHash) {
-        assert size > 0;
-
-        this.size = size;
-        this.fastHash = fastHash;
-
-        seed = new Random().nextInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        if (!fastHash) {
-            ByteBuffer buf = ByteBuffer.allocate(4);
-
-            buf.putInt(i);
-            buf.flip();
-
-            return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / (double)SCALE;
-        }
-        else
-            // This isn't a fantastic random number generator, but it is just fine for random projections.
-            return (((i * PRIME) & 8) * 0.25) - 1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        throw new UnsupportedOperationException("Random vector storage is a read-only storage.");
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(size);
-        out.writeInt(seed);
-        out.writeBoolean(fastHash);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        size = in.readInt();
-        seed = in.readInt();
-        fastHash = in.readBoolean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + Boolean.hashCode(fastHash);
-        res = res * 37 + seed;
-        res = res * 37 + size;
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        RandomVectorStorage that = (RandomVectorStorage)o;
-
-        return size == that.size && seed == that.seed && fastHash == that.fastHash;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorDelegateStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorDelegateStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorDelegateStorage.java
deleted file mode 100644
index c5a4350..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorDelegateStorage.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * Single value view storage over another vector.
- */
-public class SingleElementVectorDelegateStorage implements VectorStorage {
-    /** */ private int idx;
-    /** */ private Vector vec;
-
-    /**
-     *
-     */
-    public SingleElementVectorDelegateStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param vec Parent vector.
-     * @param idx Element index.
-     */
-    public SingleElementVectorDelegateStorage(Vector vec, int idx) {
-        assert vec != null;
-        assert idx >= 0;
-
-        this.vec = vec;
-        this.idx = idx;
-    }
-
-    /**
-     *
-     *
-     */
-    public int index() {
-        return idx;
-    }
-
-    /**
-     *
-     *
-     */
-    public Vector delegate() {
-        return vec;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return vec.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return i == idx ? vec.get(i) : 0.0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        if (i == idx)
-            vec.set(i, v);
-        else
-            throw new UnsupportedOperationException("Can't set element outside of index: " + idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(vec);
-        out.writeInt(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        vec = (Vector)in.readObject();
-        idx = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        SingleElementVectorDelegateStorage that = (SingleElementVectorDelegateStorage)o;
-
-        return idx == that.idx && (vec != null ? vec.equals(that.vec) : that.vec == null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = idx;
-
-        res = 31 * res + (vec != null ? vec.hashCode() : 0);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorStorage.java
deleted file mode 100644
index 3378817..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SingleElementVectorStorage.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * Vector storage holding a single non-zero value at some index.
- */
-public class SingleElementVectorStorage implements VectorStorage {
-    /** */ private int idx;
-    /** */ private double val;
-    /** */ private int size;
-
-    /**
-     *
-     */
-    public SingleElementVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size Parent vector size.
-     * @param idx Element index in the parent vector.
-     * @param val Value of the element.
-     */
-    public SingleElementVectorStorage(int size, int idx, double val) {
-        assert size > 0;
-        assert idx >= 0;
-
-        this.size = size;
-        this.idx = idx;
-        this.val = val;
-    }
-
-    /**
-     *
-     * @return Index of the element in the parent vector.
-     */
-    public int index() {
-        return idx;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return i == idx ? val : 0.0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        if (i == idx)
-            val = v;
-        else
-            throw new UnsupportedOperationException("Can't set element outside of index: " + idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(size);
-        out.writeInt(idx);
-        out.writeDouble(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        size = in.readInt();
-        idx = in.readInt();
-        val = in.readDouble();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        SingleElementVectorStorage that = (SingleElementVectorStorage)o;
-
-        return idx == that.idx && Double.compare(that.val, val) == 0 && size == that.size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = idx;
-        long temp = Double.doubleToLongBits(val);
-
-        res = 31 * res + (int)(temp ^ (temp >>> 32));
-        res = 31 * res + size;
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java
deleted file mode 100644
index 9b912cb..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.nio.ByteBuffer;
-import org.apache.ignite.internal.util.offheap.GridOffHeapMap;
-import org.apache.ignite.internal.util.offheap.GridOffHeapMapFactory;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * {@link VectorStorage} implementation for {@link org.apache.ignite.math.impls.vector.SparseLocalOffHeapVector}.
- */
-public class SparseLocalOffHeapVectorStorage implements VectorStorage {
-    /** Assume 10% density. */
-    private static final int INIT_DENSITY = 10;
-    /** Storage capacity. */
-    private int size;
-    /** Local off heap map. */
-    private GridOffHeapMap gridOffHeapMap;
-
-    /** */
-    public SparseLocalOffHeapVectorStorage() {
-        //No-op.
-    }
-
-    /** */
-    public SparseLocalOffHeapVectorStorage(int cap) {
-        assert cap > 0;
-
-        gridOffHeapMap = GridOffHeapMapFactory.unsafeMap(cap / INIT_DENSITY);
-        size = cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        byte[] bytes = gridOffHeapMap.get(hash(i), intToByteArray(i));
-        return bytes == null ? 0 : ByteBuffer.wrap(bytes).getDouble();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        if (v != 0.0)
-            gridOffHeapMap.put(hash(i), intToByteArray(i), doubleToByteArray(v));
-        else if (gridOffHeapMap.contains(hash(i), intToByteArray(i)))
-            gridOffHeapMap.remove(hash(i), intToByteArray(i));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        throw new UnsupportedOperationException(); // TODO: add externalization support.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        gridOffHeapMap.destruct();
-    }
-
-    /** */
-    private int hash(int h) {
-        // Apply base step of MurmurHash; see http://code.google.com/p/smhasher/
-        // Despite two multiplies, this is often faster than others
-        // with comparable bit-spread properties.
-        h ^= h >>> 16;
-        h *= 0x85ebca6b;
-        h ^= h >>> 13;
-        h *= 0xc2b2ae35;
-
-        return (h >>> 16) ^ h;
-    }
-
-    /** */
-    private byte[] intToByteArray(int val) {
-        return new byte[] {
-            (byte)(val >>> 24),
-            (byte)(val >>> 16),
-            (byte)(val >>> 8),
-            (byte)val};
-    }
-
-    /** */
-    private byte[] doubleToByteArray(double val) {
-        long l = Double.doubleToRawLongBits(val);
-        return new byte[] {
-            (byte)((l >> 56) & 0xff),
-            (byte)((l >> 48) & 0xff),
-            (byte)((l >> 40) & 0xff),
-            (byte)((l >> 32) & 0xff),
-            (byte)((l >> 24) & 0xff),
-            (byte)((l >> 16) & 0xff),
-            (byte)((l >> 8) & 0xff),
-            (byte)((l) & 0xff),
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java
deleted file mode 100644
index b3a8a3c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-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 org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * Sparse, local, on-heap vector storage.
- */
-public class SparseLocalOnHeapVectorStorage implements VectorStorage, StorageConstants {
-    /** */ private int size;
-    /** */ private int acsMode;
-
-    /** Actual map storage. */
-    private Map<Integer, Double> sto;
-
-    /**
-     *
-     */
-    public SparseLocalOnHeapVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size Vector size.
-     * @param acsMode Access mode.
-     */
-    public SparseLocalOnHeapVectorStorage(int size, int acsMode) {
-        assert size > 0;
-        assertAccessMode(acsMode);
-
-        this.size = size;
-        this.acsMode = acsMode;
-
-        if (acsMode == SEQUENTIAL_ACCESS_MODE)
-            sto = new Int2DoubleRBTreeMap();
-        else
-            sto = new Int2DoubleOpenHashMap();
-    }
-
-    /**
-     *
-     *
-     */
-    public int getAccessMode() {
-        return acsMode;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return size;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return sto.getOrDefault(i, 0.0);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        if (v != 0.0)
-            sto.put(i, v);
-        else if (sto.containsKey(i))
-            sto.remove(i);
-
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(size);
-        out.writeInt(acsMode);
-        out.writeObject(sto);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked"})
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        size = in.readInt();
-        acsMode = in.readInt();
-        sto = (Map<Integer, Double>)in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return acsMode == SEQUENTIAL_ACCESS_MODE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        SparseLocalOnHeapVectorStorage that = (SparseLocalOnHeapVectorStorage)o;
-
-        return size == that.size && acsMode == that.acsMode && (sto != null ? sto.equals(that.sto) : that.sto == null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = size;
-
-        res = 31 * res + acsMode;
-        res = 31 * res + (sto != null ? sto.hashCode() : 0);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/package-info.java
deleted file mode 100644
index a716e6a..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains specific implementations for vector storage models.
- */
-package org.apache.ignite.math.impls.storage.vector;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractReadOnlyVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractReadOnlyVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractReadOnlyVector.java
deleted file mode 100644
index 58c583a..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractReadOnlyVector.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.impls.matrix.FunctionMatrix;
-
-/**
- * This class provides a helper implementation of the read-only implementation of {@link Vector}
- * interface to minimize the effort required to implement it.
- * Subclasses may override some of the implemented methods if a more
- * specific or optimized implementation is desirable.
- */
-public abstract class AbstractReadOnlyVector extends AbstractVector {
-    /** */
-    public AbstractReadOnlyVector() {
-        // No-op.
-    }
-
-    /**
-     * @param sto Storage.
-     */
-    public AbstractReadOnlyVector(VectorStorage sto) {
-        super(true, sto);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix cross(Vector vec) {
-        return new FunctionMatrix(size(), vec.size(),
-            (row, col) -> vec.get(col) * get(row));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix toMatrix(boolean rowLike) {
-        return new FunctionMatrix(rowLike ? 1 : size(), rowLike ? size() : 1,
-            (row, col) -> rowLike ? get(col) : get(row));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
-        return new FunctionMatrix(rowLike ? 1 : size() + 1, rowLike ? size() + 1 : 1, (row, col) -> {
-            if (row == 0 && col == 0)
-                return zeroVal;
-
-            return rowLike ? get(col - 1) : get(row - 1);
-        });
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        return this; // This exploits read-only feature of this type vector.
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector logNormalize() {
-        return logNormalize(2.0, Math.sqrt(getLengthSquared()));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector logNormalize(double power) {
-        return logNormalize(power, kNorm(power));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
-        return new FunctionVector(size(), (i) -> fun.apply(get(i)));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun) {
-        checkCardinality(vec);
-
-        return new FunctionVector(size(), (i) -> fun.apply(get(i), vec.get(i)));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
-        return new FunctionVector(size(), (i) -> fun.apply(get(i), y));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector divide(double x) {
-        if (x == 1.0)
-            return this;
-
-        return new FunctionVector(size(), (i) -> get(i) / x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        return x == 0 ? new ConstantVector(size(), 0) : new FunctionVector(size(), (i) -> get(i) * x);
-    }
-
-    /**
-     * @param power Power.
-     * @param normLen Normalized length.
-     * @return logNormalized value.
-     */
-    private Vector logNormalize(double power, double normLen) {
-        assert !(Double.isInfinite(power) || power <= 1.0);
-
-        double denominator = normLen * Math.log(power);
-
-        return new FunctionVector(size(), (idx) -> Math.log1p(get(idx)) / denominator);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractVector.java
deleted file mode 100644
index d84c0f3..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/AbstractVector.java
+++ /dev/null
@@ -1,903 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Spliterator;
-import java.util.function.Consumer;
-import java.util.function.IntToDoubleFunction;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.impls.matrix.MatrixView;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * This class provides a helper implementation of the {@link Vector}
- * interface to minimize the effort required to implement it.
- * Subclasses may override some of the implemented methods if a more
- * specific or optimized implementation is desirable.
- */
-public abstract class AbstractVector implements Vector {
-    /** Vector storage implementation. */
-    private VectorStorage sto;
-
-    /** Meta attribute storage. */
-    private Map<String, Object> meta = new HashMap<>();
-
-    /** Vector's GUID. */
-    private IgniteUuid guid = IgniteUuid.randomUuid();
-
-    /** Cached value for length squared. */
-    private double lenSq = 0.0;
-
-    /** Maximum cached element. */
-    private Element maxElm = null;
-    /** Minimum cached element. */
-    private Element minElm = null;
-
-    /** Readonly flag (false by default). */
-    private boolean readOnly = false;
-
-    /** Read-only error message. */
-    private static final String RO_MSG = "Vector is read-only.";
-
-    /**
-     *
-     */
-    private void ensureReadOnly() {
-        if (readOnly)
-            throw new UnsupportedOperationException(RO_MSG);
-    }
-
-    /**
-     * @param sto Storage.
-     */
-    public AbstractVector(VectorStorage sto) {
-        this(false, sto);
-    }
-
-    /**
-     * @param readOnly Is read only.
-     * @param sto Storage.
-     */
-    public AbstractVector(boolean readOnly, VectorStorage sto) {
-        assert sto != null;
-
-        this.readOnly = readOnly;
-        this.sto = sto;
-    }
-
-    /**
-     *
-     */
-    public AbstractVector() {
-        // No-op.
-    }
-
-    /**
-     * Set storage.
-     *
-     * @param sto Storage.
-     */
-    protected void setStorage(VectorStorage sto) {
-        this.sto = sto;
-    }
-
-    /**
-     * @param i Index.
-     * @param v Value.
-     */
-    protected void storageSet(int i, double v) {
-        ensureReadOnly();
-
-        sto.set(i, v);
-
-        // Reset cached values.
-        lenSq = 0.0;
-        maxElm = minElm = null;
-    }
-
-    /**
-     * @param i Index.
-     * @return Value.
-     */
-    protected double storageGet(int i) {
-        return sto.get(i);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return sto.size();
-    }
-
-    /**
-     * Check index bounds.
-     *
-     * @param idx Index to check.
-     */
-    protected void checkIndex(int idx) {
-        if (idx < 0 || idx >= sto.size())
-            throw new IndexException(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int idx) {
-        checkIndex(idx);
-
-        return storageGet(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getX(int idx) {
-        return storageGet(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return sto.isArrayBased();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector sort() {
-        if (isArrayBased())
-            Arrays.parallelSort(sto.data());
-        else
-            throw new UnsupportedOperationException();
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
-        if (sto.isArrayBased()) {
-            double[] data = sto.data();
-
-            Arrays.setAll(data, (idx) -> fun.apply(data[idx]));
-        }
-        else {
-            int len = size();
-
-            for (int i = 0; i < len; i++)
-                storageSet(i, fun.apply(storageGet(i)));
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun) {
-        checkCardinality(vec);
-
-        int len = size();
-
-        for (int i = 0; i < len; i++)
-            storageSet(i, fun.apply(storageGet(i), vec.get(i)));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
-        int len = size();
-
-        for (int i = 0; i < len; i++)
-            storageSet(i, fun.apply(storageGet(i), y));
-
-        return this;
-    }
-
-    /**
-     * @param idx Index.
-     * @return Value.
-     */
-    protected Element makeElement(int idx) {
-        checkIndex(idx);
-
-        return new Element() {
-            /** {@inheritDoc} */
-            @Override public double get() {
-                return storageGet(idx);
-            }
-
-            /** {@inheritDoc} */
-            @Override public int index() {
-                return idx;
-            }
-
-            /** {@inheritDoc} */
-            @Override public void set(double val) {
-                storageSet(idx, val);
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element minElement() {
-        if (minElm == null) {
-            int minIdx = 0;
-            int len = size();
-
-            for (int i = 0; i < len; i++)
-                if (storageGet(i) < storageGet(minIdx))
-                    minIdx = i;
-
-            minElm = makeElement(minIdx);
-        }
-
-        return minElm;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element maxElement() {
-        if (maxElm == null) {
-            int maxIdx = 0;
-            int len = size();
-
-            for (int i = 0; i < len; i++)
-                if (storageGet(i) > storageGet(maxIdx))
-                    maxIdx = i;
-
-            maxElm = makeElement(maxIdx);
-        }
-
-        return maxElm;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double minValue() {
-        return minElement().get();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxValue() {
-        return maxElement().get();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector set(int idx, double val) {
-        checkIndex(idx);
-
-        storageSet(idx, val);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector setX(int idx, double val) {
-        storageSet(idx, val);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector increment(int idx, double val) {
-        checkIndex(idx);
-
-        storageSet(idx, storageGet(idx) + val);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector incrementX(int idx, double val) {
-        storageSet(idx, storageGet(idx) + val);
-
-        return this;
-    }
-
-    /**
-     * Tests if given value is considered a zero value.
-     *
-     * @param val Value to check.
-     */
-    protected boolean isZero(double val) {
-        return val == 0.0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        double sum = 0;
-        int len = size();
-
-        for (int i = 0; i < len; i++)
-            sum += storageGet(i);
-
-        return sum;
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteUuid guid() {
-        return guid;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable<Element> all() {
-        return new Iterable<Element>() {
-            private int idx = 0;
-
-            /** {@inheritDoc} */
-            @NotNull
-            @Override public Iterator<Element> iterator() {
-                return new Iterator<Element>() {
-                    /** {@inheritDoc} */
-                    @Override public boolean hasNext() {
-                        return size() > 0 && idx < size();
-                    }
-
-                    /** {@inheritDoc} */
-                    @Override public Element next() {
-                        if (hasNext())
-                            return getElement(idx++);
-
-                        throw new NoSuchElementException();
-                    }
-                };
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nonZeroElements() {
-        int cnt = 0;
-
-        for (Element ignored : nonZeroes())
-            cnt++;
-
-        return cnt;
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun,
-        T zeroVal) {
-        T res = zeroVal;
-        int len = size();
-
-        for (int i = 0; i < len; i++)
-            res = foldFun.apply(res, mapFun.apply(storageGet(i)));
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T foldMap(Vector vec, IgniteBiFunction<T, Double, T> foldFun,
-        IgniteBiFunction<Double, Double, Double> combFun, T zeroVal) {
-        checkCardinality(vec);
-
-        T res = zeroVal;
-        int len = size();
-
-        for (int i = 0; i < len; i++)
-            res = foldFun.apply(res, combFun.apply(storageGet(i), vec.getX(i)));
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable<Element> nonZeroes() {
-        return new Iterable<Element>() {
-            private int idx = 0;
-            private int idxNext = -1;
-
-            /** {@inheritDoc} */
-            @NotNull
-            @Override public Iterator<Element> iterator() {
-                return new Iterator<Element>() {
-                    @Override public boolean hasNext() {
-                        findNext();
-
-                        return !over();
-                    }
-
-                    @Override public Element next() {
-                        if (hasNext()) {
-                            idx = idxNext;
-
-                            return getElement(idxNext);
-                        }
-
-                        throw new NoSuchElementException();
-                    }
-
-                    private void findNext() {
-                        if (over())
-                            return;
-
-                        if (idxNextInitialized() && idx != idxNext)
-                            return;
-
-                        if (idxNextInitialized())
-                            idx = idxNext + 1;
-
-                        while (idx < size() && isZero(get(idx)))
-                            idx++;
-
-                        idxNext = idx++;
-                    }
-
-                    private boolean over() {
-                        return idxNext >= size();
-                    }
-
-                    private boolean idxNextInitialized() {
-                        return idxNext != -1;
-                    }
-                };
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map<String, Object> getMetaStorage() {
-        return meta;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(double val) {
-        if (sto.isArrayBased()) {
-            ensureReadOnly();
-
-            Arrays.fill(sto.data(), val);
-        }
-        else {
-            int len = size();
-
-            for (int i = 0; i < len; i++)
-                storageSet(i, val);
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(double[] vals) {
-        checkCardinality(vals);
-
-        if (sto.isArrayBased()) {
-            ensureReadOnly();
-
-            System.arraycopy(vals, 0, sto.data(), 0, vals.length);
-
-            lenSq = 0.0;
-        }
-        else {
-            int len = size();
-
-            for (int i = 0; i < len; i++)
-                storageSet(i, vals[i]);
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(Vector vec) {
-        checkCardinality(vec);
-
-        for (Vector.Element x : vec.all())
-            storageSet(x.index(), x.get());
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(IntToDoubleFunction fun) {
-        assert fun != null;
-
-        if (sto.isArrayBased()) {
-            ensureReadOnly();
-
-            Arrays.setAll(sto.data(), fun);
-        }
-        else {
-            int len = size();
-
-            for (int i = 0; i < len; i++)
-                storageSet(i, fun.applyAsDouble(i));
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Spliterator<Double> allSpliterator() {
-        return new Spliterator<Double>() {
-            /** {@inheritDoc} */
-            @Override public boolean tryAdvance(Consumer<? super Double> act) {
-                int len = size();
-
-                for (int i = 0; i < len; i++)
-                    act.accept(storageGet(i));
-
-                return true;
-            }
-
-            /** {@inheritDoc} */
-            @Override public Spliterator<Double> trySplit() {
-                return null; // No Splitting.
-            }
-
-            /** {@inheritDoc} */
-            @Override public long estimateSize() {
-                return size();
-            }
-
-            /** {@inheritDoc} */
-            @Override public int characteristics() {
-                return ORDERED | SIZED;
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Spliterator<Double> nonZeroSpliterator() {
-        return new Spliterator<Double>() {
-            /** {@inheritDoc} */
-            @Override public boolean tryAdvance(Consumer<? super Double> act) {
-                int len = size();
-
-                for (int i = 0; i < len; i++) {
-                    double val = storageGet(i);
-
-                    if (!isZero(val))
-                        act.accept(val);
-                }
-
-                return true;
-            }
-
-            /** {@inheritDoc} */
-            @Override public Spliterator<Double> trySplit() {
-                return null; // No Splitting.
-            }
-
-            /** {@inheritDoc} */
-            @Override public long estimateSize() {
-                return nonZeroElements();
-            }
-
-            /** {@inheritDoc} */
-            @Override public int characteristics() {
-                return ORDERED | SIZED;
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public double dot(Vector vec) {
-        checkCardinality(vec);
-
-        double sum = 0.0;
-        int len = size();
-
-        for (int i = 0; i < len; i++)
-            sum += storageGet(i) * vec.getX(i);
-
-        return sum;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getLengthSquared() {
-        if (lenSq == 0.0)
-            lenSq = dotSelf();
-
-        return lenSq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return sto.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return sto.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return sto.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return sto.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public VectorStorage getStorage() {
-        return sto;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewPart(int off, int len) {
-        return new VectorView(this, off, len);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix cross(Vector vec) {
-        Matrix res = likeMatrix(size(), vec.size());
-
-        if (res == null)
-            return null;
-
-        for (Element e : nonZeroes()) {
-            int row = e.index();
-
-            res.assignRow(row, vec.times(getX(row)));
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix toMatrix(boolean rowLike) {
-        Matrix res = likeMatrix(rowLike ? 1 : size(), rowLike ? size() : 1);
-
-        if (res == null)
-            return null;
-
-        if (rowLike)
-            res.assignRow(0, this);
-        else
-            res.assignColumn(0, this);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
-        Matrix res = likeMatrix(rowLike ? 1 : size() + 1, rowLike ? size() + 1 : 1);
-
-        if (res == null)
-            return null;
-
-        res.set(0, 0, zeroVal);
-
-        if (rowLike)
-            new MatrixView(res, 0, 1, 1, size()).assignRow(0, this);
-        else
-            new MatrixView(res, 1, 0, size(), 1).assignColumn(0, this);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getDistanceSquared(Vector vec) {
-        checkCardinality(vec);
-
-        double thisLenSq = getLengthSquared();
-        double thatLenSq = vec.getLengthSquared();
-        double dot = dot(vec);
-        double distEst = thisLenSq + thatLenSq - 2 * dot;
-
-        if (distEst > 1.0e-3 * (thisLenSq + thatLenSq))
-            // The vectors are far enough from each other that the formula is accurate.
-            return Math.max(distEst, 0);
-        else
-            return foldMap(vec, Functions.PLUS, Functions.MINUS_SQUARED, 0d);
-    }
-
-    /** */
-    protected void checkCardinality(Vector vec) {
-        if (vec.size() != size())
-            throw new CardinalityException(size(), vec.size());
-    }
-
-    /** */
-    protected void checkCardinality(double[] vec) {
-        if (vec.length != size())
-            throw new CardinalityException(size(), vec.length);
-    }
-
-    /** */
-    protected void checkCardinality(int[] arr) {
-        if (arr.length != size())
-            throw new CardinalityException(size(), arr.length);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector minus(Vector vec) {
-        checkCardinality(vec);
-
-        Vector cp = copy();
-
-        return cp.map(vec, Functions.MINUS);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector plus(double x) {
-        Vector cp = copy();
-
-        return x != 0.0 ? cp.map(Functions.plus(x)) : cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector divide(double x) {
-        Vector cp = copy();
-
-        if (x != 1.0)
-            for (Element element : cp.all())
-                element.set(element.get() / x);
-
-        return cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        if (x == 0.0)
-            return like(size());
-        else
-            return copy().map(Functions.mult(x));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(Vector vec) {
-        checkCardinality(vec);
-
-        return copy().map(vec, Functions.MULT);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector plus(Vector vec) {
-        checkCardinality(vec);
-
-        Vector cp = copy();
-
-        return cp.map(vec, Functions.PLUS);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector logNormalize() {
-        return logNormalize(2.0, Math.sqrt(getLengthSquared()));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector logNormalize(double power) {
-        return logNormalize(power, kNorm(power));
-    }
-
-    /**
-     * @param power Power.
-     * @param normLen Normalized length.
-     * @return logNormalized value.
-     */
-    private Vector logNormalize(double power, double normLen) {
-        assert !(Double.isInfinite(power) || power <= 1.0);
-
-        double denominator = normLen * Math.log(power);
-
-        Vector cp = copy();
-
-        for (Element element : cp.all())
-            element.set(Math.log1p(element.get()) / denominator);
-
-        return cp;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double kNorm(double power) {
-        assert power >= 0.0;
-
-        // Special cases.
-        if (Double.isInfinite(power))
-            return foldMap(Math::max, Math::abs, 0d);
-        else if (power == 2.0)
-            return Math.sqrt(getLengthSquared());
-        else if (power == 1.0)
-            return foldMap(Functions.PLUS, Math::abs, 0d);
-        else if (power == 0.0)
-            return nonZeroElements();
-        else
-            // Default case.
-            return Math.pow(foldMap(Functions.PLUS, Functions.pow(power), 0d), 1.0 / power);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector normalize() {
-        return divide(Math.sqrt(getLengthSquared()));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector normalize(double power) {
-        return divide(kNorm(power));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        return like(size()).assign(this);
-    }
-
-    /**
-     * @return Result of dot with self.
-     */
-    protected double dotSelf() {
-        double sum = 0.0;
-        int len = size();
-
-        for (int i = 0; i < len; i++) {
-            double v = storageGet(i);
-
-            sum += v * v;
-        }
-
-        return sum;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element getElement(int idx) {
-        return makeElement(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sto);
-        out.writeObject(meta);
-        out.writeObject(guid);
-        out.writeBoolean(readOnly);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sto = (VectorStorage)in.readObject();
-        meta = (Map<String, Object>)in.readObject();
-        guid = (IgniteUuid)in.readObject();
-        readOnly = in.readBoolean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        sto.destroy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-        res += res * 37 + guid.hashCode();
-        res += sto == null ? 0 : res * 37 + sto.hashCode();
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-
-        if (obj == null || getClass() != obj.getClass())
-            return false;
-
-        AbstractVector that = (AbstractVector)obj;
-
-        return (sto != null ? sto.equals(that.sto) : that.sto == null);
-    }
-}


[06/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorIterableTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorIterableTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorIterableTest.java
deleted file mode 100644
index 7a64c85..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorIterableTest.java
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.Spliterator;
-import java.util.function.BiConsumer;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Test;
-
-import static java.util.Spliterator.ORDERED;
-import static java.util.Spliterator.SIZED;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/** */
-public class VectorIterableTest {
-    /** */
-    @Test
-    public void allTest() {
-        consumeSampleVectors(
-            (v, desc) -> {
-                int expIdx = 0;
-
-                for (Vector.Element e : v.all()) {
-                    int actualIdx = e.index();
-
-                    assertEquals("Unexpected index for " + desc,
-                        expIdx, actualIdx);
-
-                    expIdx++;
-                }
-
-                assertEquals("Unexpected amount of elements for " + desc,
-                    expIdx, v.size());
-            }
-        );
-    }
-
-    /** */
-    @Test
-    public void allTestBound() {
-        consumeSampleVectors(
-            (v, desc) -> iteratorTestBound(v.all().iterator(), desc)
-        );
-    }
-
-    /** */
-    @Test
-    public void nonZeroesTestBasic() {
-        final int size = 5;
-
-        final double[] nonZeroesOddData = new double[size], nonZeroesEvenData = new double[size];
-
-        for (int idx = 0; idx < size; idx++) {
-            final boolean odd = (idx & 1) == 1;
-
-            nonZeroesOddData[idx] = odd ? 1 : 0;
-
-            nonZeroesEvenData[idx] = odd ? 0 : 1;
-        }
-
-        assertTrue("Arrays failed to initialize.",
-            !isZero(nonZeroesEvenData[0])
-                && isZero(nonZeroesEvenData[1])
-                && isZero(nonZeroesOddData[0])
-                && !isZero(nonZeroesOddData[1]));
-
-        final Vector nonZeroesEvenVec = new DenseLocalOnHeapVector(nonZeroesEvenData),
-            nonZeroesOddVec = new DenseLocalOnHeapVector(nonZeroesOddData);
-
-        assertTrue("Vectors failed to initialize.",
-            !isZero(nonZeroesEvenVec.getElement(0).get())
-                && isZero(nonZeroesEvenVec.getElement(1).get())
-                && isZero(nonZeroesOddVec.getElement(0).get())
-                && !isZero(nonZeroesOddVec.getElement(1).get()));
-
-        assertTrue("Iterator(s) failed to start.",
-            nonZeroesEvenVec.nonZeroes().iterator().next() != null
-                && nonZeroesOddVec.nonZeroes().iterator().next() != null);
-
-        int nonZeroesActual = 0;
-
-        for (Vector.Element e : nonZeroesEvenVec.nonZeroes()) {
-            final int idx = e.index();
-
-            final boolean odd = (idx & 1) == 1;
-
-            final double val = e.get();
-
-            assertTrue("Not an even index " + idx + ", for value " + val, !odd);
-
-            assertTrue("Zero value " + val + " at even index " + idx, !isZero(val));
-
-            nonZeroesActual++;
-        }
-
-        final int nonZeroesOddExp = (size + 1) / 2;
-
-        assertEquals("Unexpected num of iterated odd non-zeroes.", nonZeroesOddExp, nonZeroesActual);
-
-        assertEquals("Unexpected nonZeroElements of odd.", nonZeroesOddExp, nonZeroesEvenVec.nonZeroElements());
-
-        nonZeroesActual = 0;
-
-        for (Vector.Element e : nonZeroesOddVec.nonZeroes()) {
-            final int idx = e.index();
-
-            final boolean odd = (idx & 1) == 1;
-
-            final double val = e.get();
-
-            assertTrue("Not an odd index " + idx + ", for value " + val, odd);
-
-            assertTrue("Zero value " + val + " at even index " + idx, !isZero(val));
-
-            nonZeroesActual++;
-        }
-
-        final int nonZeroesEvenExp = size / 2;
-
-        assertEquals("Unexpected num of iterated even non-zeroes", nonZeroesEvenExp, nonZeroesActual);
-
-        assertEquals("Unexpected nonZeroElements of even", nonZeroesEvenExp, nonZeroesOddVec.nonZeroElements());
-    }
-
-    /** */
-    @Test
-    public void nonZeroesTest() {
-        // todo make RandomVector constructor that accepts a function and use it here
-        //  in order to *reliably* test non-zeroes in there
-        consumeSampleVectors(
-            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
-                -> {
-                int numZeroesActual = vec.size();
-
-                for (Vector.Element e : vec.nonZeroes()) {
-                    numZeroesActual--;
-
-                    assertTrue("Unexpected zero at " + desc + ", index " + e.index(), !isZero(e.get()));
-                }
-
-                assertEquals("Unexpected num zeroes at " + desc, (int)numZeroes, numZeroesActual);
-            }));
-    }
-
-    /** */
-    @Test
-    public void nonZeroesTestBound() {
-        consumeSampleVectors(
-            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
-                -> iteratorTestBound(vec.nonZeroes().iterator(), desc)));
-    }
-
-    /** */
-    @Test
-    public void nonZeroElementsTest() {
-        consumeSampleVectors(
-            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
-                -> assertEquals("Unexpected num zeroes at " + desc,
-                (int)numZeroes, vec.size() - vec.nonZeroElements())));
-    }
-
-    /** */
-    @Test
-    public void allSpliteratorTest() {
-        consumeSampleVectors(
-            (v, desc) -> {
-                final String desc1 = " " + desc;
-
-                Spliterator<Double> spliterator = v.allSpliterator();
-
-                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
-
-                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, spliterator.trySplit());
-
-                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
-
-                if (!readOnly(v))
-                    fillWithNonZeroes(v);
-
-                spliterator = v.allSpliterator();
-
-                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
-
-                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.estimateSize(), v.size());
-
-                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.getExactSizeIfKnown(), v.size());
-
-                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
-
-                Spliterator<Double> secondHalf = spliterator.trySplit();
-
-                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, secondHalf);
-
-                spliterator.tryAdvance(x -> {
-                });
-            }
-        );
-    }
-
-    /** */
-    @Test
-    public void nonZeroSpliteratorTest() {
-        consumeSampleVectors(
-            (v, desc) -> consumeSampleVectorsWithZeroes(v, (vec, numZeroes)
-                -> {
-                final String desc1 = " Num zeroes " + numZeroes + " " + desc;
-
-                Spliterator<Double> spliterator = vec.nonZeroSpliterator();
-
-                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
-
-                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, spliterator.trySplit());
-
-                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
-
-                spliterator = vec.nonZeroSpliterator();
-
-                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
-
-                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.estimateSize(), vec.size() - numZeroes);
-
-                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.getExactSizeIfKnown(), vec.size() - numZeroes);
-
-                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
-
-                Spliterator<Double> secondHalf = spliterator.trySplit();
-
-                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, secondHalf);
-
-                double[] data = new double[vec.size()];
-
-                for (Vector.Element e : vec.all())
-                    data[e.index()] = e.get();
-
-                spliterator = vec.nonZeroSpliterator();
-
-                assertNotNull(MathTestConstants.NULL_VAL + desc1, spliterator);
-
-                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.estimateSize(),
-                    Arrays.stream(data).filter(x -> x != 0d).count());
-
-                assertEquals(MathTestConstants.VAL_NOT_EQUALS + desc1, spliterator.getExactSizeIfKnown(),
-                    Arrays.stream(data).filter(x -> x != 0d).count());
-
-                assertTrue(MathTestConstants.UNEXPECTED_VAL + desc1, spliterator.hasCharacteristics(ORDERED | SIZED));
-
-                secondHalf = spliterator.trySplit();
-
-                assertNull(MathTestConstants.NOT_NULL_VAL + desc1, secondHalf);
-
-                if (!spliterator.tryAdvance(x -> {
-                }))
-                    fail(MathTestConstants.NO_NEXT_ELEMENT + desc1);
-            }));
-    }
-
-    /** */
-    private void iteratorTestBound(Iterator<Vector.Element> it, String desc) {
-        while (it.hasNext())
-            assertNotNull(it.next());
-
-        boolean expECaught = false;
-
-        try {
-            it.next();
-        }
-        catch (NoSuchElementException e) {
-            expECaught = true;
-        }
-
-        assertTrue("Expected exception missed for " + desc,
-            expECaught);
-    }
-
-    /** */
-    private void consumeSampleVectorsWithZeroes(Vector sample,
-        BiConsumer<Vector, Integer> consumer) {
-        if (readOnly(sample)) {
-            int numZeroes = 0;
-
-            for (Vector.Element e : sample.all())
-                if (isZero(e.get()))
-                    numZeroes++;
-
-            consumer.accept(sample, numZeroes);
-
-            return;
-        }
-
-        fillWithNonZeroes(sample);
-
-        consumer.accept(sample, 0);
-
-        final int sampleSize = sample.size();
-
-        if (sampleSize == 0)
-            return;
-
-        for (Vector.Element e : sample.all())
-            e.set(0);
-
-        consumer.accept(sample, sampleSize);
-
-        fillWithNonZeroes(sample);
-
-        for (int testIdx : new int[] {0, sampleSize / 2, sampleSize - 1}) {
-            final Vector.Element e = sample.getElement(testIdx);
-
-            final double backup = e.get();
-
-            e.set(0);
-
-            consumer.accept(sample, 1);
-
-            e.set(backup);
-        }
-
-        if (sampleSize < 3)
-            return;
-
-        sample.getElement(sampleSize / 3).set(0);
-
-        sample.getElement((2 * sampleSize) / 3).set(0);
-
-        consumer.accept(sample, 2);
-    }
-
-    /** */
-    private void fillWithNonZeroes(Vector sample) {
-        int idx = 0;
-
-        for (Vector.Element e : sample.all())
-            e.set(1 + idx++);
-
-        assertEquals("Not all filled with non-zeroes", idx, sample.size());
-    }
-
-    /** */
-    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
-        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
-    }
-
-    /** */
-    private boolean isZero(double val) {
-        return val == 0.0;
-    }
-
-    /** */
-    private boolean readOnly(Vector v) {
-        return v instanceof RandomVector || v instanceof ConstantVector;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorNormTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorNormTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorNormTest.java
deleted file mode 100644
index f1c2928..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorNormTest.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import org.apache.ignite.math.Vector;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class VectorNormTest {
-    /** */
-    @Test
-    public void normalizeTest() {
-        normalizeTest(2, (val, len) -> val / len, Vector::normalize);
-    }
-
-    /** */
-    @Test
-    public void normalizePowerTest() {
-        for (double pow : new double[] {0, 0.5, 1, 2, 2.5, Double.POSITIVE_INFINITY})
-            normalizeTest(pow, (val, norm) -> val / norm, (v) -> v.normalize(pow));
-    }
-
-    /** */
-    @Test
-    public void logNormalizeTest() {
-        normalizeTest(2, (val, len) -> Math.log1p(val) / (len * Math.log(2)), Vector::logNormalize);
-    }
-
-    /** */
-    @Test
-    public void logNormalizePowerTest() {
-        for (double pow : new double[] {1.1, 2, 2.5})
-            normalizeTest(pow, (val, norm) -> Math.log1p(val) / (norm * Math.log(pow)), (v) -> v.logNormalize(pow));
-    }
-
-    /** */
-    @Test
-    public void kNormTest() {
-        for (double pow : new double[] {0, 0.5, 1, 2, 2.5, Double.POSITIVE_INFINITY})
-            toDoubleTest(pow, ref -> new Norm(ref, pow).calculate(), v -> v.kNorm(pow));
-    }
-
-    /** */
-    @Test
-    public void getLengthSquaredTest() {
-        toDoubleTest(2.0, ref -> new Norm(ref, 2).sumPowers(), Vector::getLengthSquared);
-    }
-
-    /** */
-    @Test
-    public void getDistanceSquaredTest() {
-        consumeSampleVectors((v, desc) -> {
-            new VectorImplementationsTest.ElementsChecker(v, desc); // IMPL NOTE this initialises vector
-
-            final int size = v.size();
-            final Vector vOnHeap = new DenseLocalOnHeapVector(size);
-            final Vector vOffHeap = new DenseLocalOffHeapVector(size);
-
-            invertValues(v, vOnHeap);
-            invertValues(v, vOffHeap);
-
-            for (int idx = 0; idx < size; idx++) {
-                final double exp = v.get(idx);
-                final int idxMirror = size - 1 - idx;
-
-                assertTrue("On heap vector difference at " + desc + ", idx " + idx,
-                    exp - vOnHeap.get(idxMirror) == 0);
-                assertTrue("Off heap vector difference at " + desc + ", idx " + idx,
-                    exp - vOffHeap.get(idxMirror) == 0);
-            }
-
-            final double exp = vOnHeap.minus(v).getLengthSquared(); // IMPL NOTE this won't mutate vOnHeap
-            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOnHeap));
-
-            assertTrue("On heap vector not close enough at " + desc + ", " + metric,
-                metric.closeEnough());
-
-            final VectorImplementationsTest.Metric metric1 = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOffHeap));
-
-            assertTrue("Off heap vector not close enough at " + desc + ", " + metric1,
-                metric1.closeEnough());
-        });
-    }
-
-    /** */
-    @Test
-    public void dotTest() {
-        consumeSampleVectors((v, desc) -> {
-            new VectorImplementationsTest.ElementsChecker(v, desc); // IMPL NOTE this initialises vector
-
-            final int size = v.size();
-            final Vector v1 = new DenseLocalOnHeapVector(size);
-
-            invertValues(v, v1);
-
-            final double actual = v.dot(v1);
-
-            double exp = 0;
-
-            for (Vector.Element e : v.all())
-                exp += e.get() * v1.get(e.index());
-
-            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, actual);
-
-            assertTrue("Dot product not close enough at " + desc + ", " + metric,
-                metric.closeEnough());
-        });
-    }
-
-    /** */
-    private void invertValues(Vector src, Vector dst) {
-        final int size = src.size();
-
-        for (Vector.Element e : src.all()) {
-            final int idx = size - 1 - e.index();
-            final double val = e.get();
-
-            dst.set(idx, val);
-        }
-    }
-
-    /** */
-    private void toDoubleTest(Double val, Function<double[], Double> calcRef, Function<Vector, Double> calcVec) {
-        consumeSampleVectors((v, desc) -> {
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            new VectorImplementationsTest.ElementsChecker(v, ref, desc); // IMPL NOTE this initialises vector and reference array
-
-            final double exp = calcRef.apply(ref);
-            final double obtained = calcVec.apply(v);
-            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, obtained);
-
-            assertTrue("Not close enough at " + desc
-                + (val == null ? "" : ", value " + val) + ", " + metric, metric.closeEnough());
-        });
-    }
-
-    /** */
-    private void normalizeTest(double pow, BiFunction<Double, Double, Double> operation,
-        Function<Vector, Vector> vecOperation) {
-        consumeSampleVectors((v, desc) -> {
-            final int size = v.size();
-            final double[] ref = new double[size];
-            final boolean nonNegative = pow != (int)pow;
-
-            final VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc + ", pow = " + pow, nonNegative);
-            final double norm = new Norm(ref, pow).calculate();
-
-            for (int idx = 0; idx < size; idx++)
-                ref[idx] = operation.apply(ref[idx], norm);
-
-            checker.assertCloseEnough(vecOperation.apply(v), ref);
-        });
-    }
-
-    /** */
-    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
-        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
-    }
-
-    /** */
-    private static class Norm {
-        /** */
-        private final double[] arr;
-
-        /** */
-        private final Double pow;
-
-        /** */
-        Norm(double[] arr, double pow) {
-            this.arr = arr;
-            this.pow = pow;
-        }
-
-        /** */
-        double calculate() {
-            if (pow.equals(0.0))
-                return countNonZeroes(); // IMPL NOTE this is beautiful if you think of it
-
-            if (pow.equals(Double.POSITIVE_INFINITY))
-                return maxAbs();
-
-            return Math.pow(sumPowers(), 1 / pow);
-        }
-
-        /** */
-        double sumPowers() {
-            if (pow.equals(0.0))
-                return countNonZeroes();
-
-            double norm = 0;
-
-            for (double val : arr)
-                norm += pow == 1 ? Math.abs(val) : Math.pow(val, pow);
-
-            return norm;
-        }
-
-        /** */
-        private int countNonZeroes() {
-            int cnt = 0;
-
-            final Double zero = 0.0;
-
-            for (double val : arr)
-                if (!zero.equals(val))
-                    cnt++;
-
-            return cnt;
-        }
-
-        /** */
-        private double maxAbs() {
-            double res = 0;
-
-            for (double val : arr) {
-                final double abs = Math.abs(val);
-
-                if (abs > res)
-                    res = abs;
-            }
-
-            return res;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorToMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorToMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorToMatrixTest.java
deleted file mode 100644
index adcb2cc..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorToMatrixTest.java
+++ /dev/null
@@ -1,291 +0,0 @@
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.BiConsumer;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.matrix.RandomMatrix;
-import org.apache.ignite.math.impls.matrix.SparseLocalOnHeapMatrix;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/** Tests for methods of Vector that involve Matrix. */
-public class VectorToMatrixTest {
-    /** */
-    private static final Map<Class<? extends Vector>, Class<? extends Matrix>> typesMap = typesMap();
-
-    /** */
-    private static final List<Class<? extends Vector>> likeMatrixUnsupported = Arrays.asList(FunctionVector.class,
-        SingleElementVector.class, SingleElementVectorView.class, ConstantVector.class);
-
-    /** */
-    @Test
-    public void testHaveLikeMatrix() throws InstantiationException, IllegalAccessException {
-        for (Class<? extends Vector> key : typesMap.keySet()) {
-            Class<? extends Matrix> val = typesMap.get(key);
-
-            if (val == null && likeMatrixSupported(key))
-                System.out.println("Missing test for implementation of likeMatrix for " + key.getSimpleName());
-        }
-    }
-
-    /** */
-    @Test
-    public void testLikeMatrixUnsupported() throws Exception {
-        consumeSampleVectors((v, desc) -> {
-            if (likeMatrixSupported(v.getClass()))
-                return;
-
-            boolean expECaught = false;
-
-            try {
-                assertNull("Null view instead of exception in " + desc, v.likeMatrix(1, 1));
-            }
-            catch (UnsupportedOperationException uoe) {
-                expECaught = true;
-            }
-
-            assertTrue("Expected exception was not caught in " + desc, expECaught);
-        });
-    }
-
-    /** */
-    @Test
-    public void testLikeMatrix() {
-        consumeSampleVectors((v, desc) -> {
-            if (!availableForTesting(v))
-                return;
-
-            final Matrix matrix = v.likeMatrix(1, 1);
-
-            Class<? extends Vector> key = v.getClass();
-
-            Class<? extends Matrix> expMatrixType = typesMap.get(key);
-
-            assertNotNull("Expect non-null matrix for " + key.getSimpleName() + " in " + desc, matrix);
-
-            Class<? extends Matrix> actualMatrixType = matrix.getClass();
-
-            assertTrue("Expected matrix type " + expMatrixType.getSimpleName()
-                    + " should be assignable from actual type " + actualMatrixType.getSimpleName() + " in " + desc,
-                expMatrixType.isAssignableFrom(actualMatrixType));
-
-            for (int rows : new int[] {1, 2})
-                for (int cols : new int[] {1, 2}) {
-                    final Matrix actualMatrix = v.likeMatrix(rows, cols);
-
-                    String details = "rows " + rows + " cols " + cols;
-
-                    assertNotNull("Expect non-null matrix for " + details + " in " + desc,
-                        actualMatrix);
-
-                    assertEquals("Unexpected number of rows in " + desc, rows, actualMatrix.rowSize());
-
-                    assertEquals("Unexpected number of cols in " + desc, cols, actualMatrix.columnSize());
-                }
-        });
-    }
-
-    /** */
-    @Test
-    public void testToMatrix() {
-        consumeSampleVectors((v, desc) -> {
-            if (!availableForTesting(v))
-                return;
-
-            fillWithNonZeroes(v);
-
-            final Matrix matrixRow = v.toMatrix(true);
-
-            final Matrix matrixCol = v.toMatrix(false);
-
-            for (Vector.Element e : v.all())
-                assertToMatrixValue(desc, matrixRow, matrixCol, e.get(), e.index());
-        });
-    }
-
-    /** */
-    @Test
-    public void testToMatrixPlusOne() {
-        consumeSampleVectors((v, desc) -> {
-            if (!availableForTesting(v))
-                return;
-
-            fillWithNonZeroes(v);
-
-            for (double zeroVal : new double[] {-1, 0, 1, 2}) {
-                final Matrix matrixRow = v.toMatrixPlusOne(true, zeroVal);
-
-                final Matrix matrixCol = v.toMatrixPlusOne(false, zeroVal);
-
-                final Metric metricRow0 = new Metric(zeroVal, matrixRow.get(0, 0));
-
-                assertTrue("Not close enough row like " + metricRow0 + " at index 0 in " + desc,
-                    metricRow0.closeEnough());
-
-                final Metric metricCol0 = new Metric(zeroVal, matrixCol.get(0, 0));
-
-                assertTrue("Not close enough cols like " + metricCol0 + " at index 0 in " + desc,
-                    metricCol0.closeEnough());
-
-                for (Vector.Element e : v.all())
-                    assertToMatrixValue(desc, matrixRow, matrixCol, e.get(), e.index() + 1);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testCross() {
-        consumeSampleVectors((v, desc) -> {
-            if (!availableForTesting(v))
-                return;
-
-            fillWithNonZeroes(v);
-
-            for (int delta : new int[] {-1, 0, 1}) {
-                final int size2 = v.size() + delta;
-
-                if (size2 < 1)
-                    return;
-
-                final Vector v2 = new DenseLocalOnHeapVector(size2);
-
-                for (Vector.Element e : v2.all())
-                    e.set(size2 - e.index());
-
-                assertCross(v, v2, desc);
-            }
-        });
-    }
-
-    /** */
-    private void assertCross(Vector v1, Vector v2, String desc) {
-        assertNotNull(v1);
-        assertNotNull(v2);
-
-        final Matrix res = v1.cross(v2);
-
-        assertNotNull("Cross matrix is expected to be not null in " + desc, res);
-
-        assertEquals("Unexpected number of rows in cross Matrix in " + desc, v1.size(), res.rowSize());
-
-        assertEquals("Unexpected number of cols in cross Matrix in " + desc, v2.size(), res.columnSize());
-
-        for (int row = 0; row < v1.size(); row++)
-            for (int col = 0; col < v2.size(); col++) {
-                final Metric metric = new Metric(v1.get(row) * v2.get(col), res.get(row, col));
-
-                assertTrue("Not close enough cross " + metric + " at row " + row + " at col " + col
-                    + " in " + desc, metric.closeEnough());
-            }
-    }
-
-    /** */
-    private void assertToMatrixValue(String desc, Matrix matrixRow, Matrix matrixCol, double exp, int idx) {
-        final Metric metricRow = new Metric(exp, matrixRow.get(0, idx));
-
-        assertTrue("Not close enough row like " + metricRow + " at index " + idx + " in " + desc,
-            metricRow.closeEnough());
-
-        final Metric metricCol = new Metric(exp, matrixCol.get(idx, 0));
-
-        assertTrue("Not close enough cols like " + matrixCol + " at index " + idx + " in " + desc,
-            metricCol.closeEnough());
-    }
-
-    /** */
-    private void fillWithNonZeroes(Vector sample) {
-        if (sample instanceof RandomVector)
-            return;
-
-        for (Vector.Element e : sample.all())
-            e.set(1 + e.index());
-    }
-
-    /** */
-    private boolean availableForTesting(Vector v) {
-        assertNotNull("Error in test: vector is null", v);
-
-        if (!likeMatrixSupported(v.getClass()))
-            return false;
-
-        final boolean availableForTesting = typesMap.get(v.getClass()) != null;
-
-        final Matrix actualLikeMatrix = v.likeMatrix(1, 1);
-
-        assertTrue("Need to enable matrix testing for vector type " + v.getClass().getSimpleName(),
-            availableForTesting || actualLikeMatrix == null);
-
-        return availableForTesting;
-    }
-
-    /** Ignore test for given vector type. */
-    private boolean likeMatrixSupported(Class<? extends Vector> clazz) {
-        for (Class<? extends Vector> ignoredClass : likeMatrixUnsupported)
-            if (ignoredClass.isAssignableFrom(clazz))
-                return false;
-
-        return true;
-    }
-
-    /** */
-    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
-        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
-    }
-
-    /** */
-    private static Map<Class<? extends Vector>, Class<? extends Matrix>> typesMap() {
-        return new LinkedHashMap<Class<? extends Vector>, Class<? extends Matrix>>() {{
-            put(DenseLocalOnHeapVector.class, DenseLocalOnHeapMatrix.class);
-            put(DenseLocalOffHeapVector.class, DenseLocalOffHeapMatrix.class);
-            put(RandomVector.class, RandomMatrix.class);
-            put(SparseLocalVector.class, SparseLocalOnHeapMatrix.class);
-            put(SingleElementVector.class, null); // todo find out if we need SingleElementMatrix to match, or skip it
-            put(ConstantVector.class, null);
-            put(FunctionVector.class, null);
-            put(PivotedVectorView.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
-            put(SingleElementVectorView.class, null);
-            put(MatrixVectorView.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
-            put(DelegatingVector.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
-            // IMPL NOTE check for presence of all implementations here will be done in testHaveLikeMatrix via Fixture
-        }};
-    }
-
-    /** */
-    private static class Metric { // todo consider if softer tolerance (like say 0.1 or 0.01) would make sense here
-        /** */
-        private final double exp;
-
-        /** */
-        private final double obtained;
-
-        /** **/
-        Metric(double exp, double obtained) {
-            this.exp = exp;
-            this.obtained = obtained;
-        }
-
-        /** */
-        boolean closeEnough() {
-            return new Double(exp).equals(obtained);
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Metric{" + "expected=" + exp +
-                ", obtained=" + obtained +
-                '}';
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorViewTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorViewTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorViewTest.java
deleted file mode 100644
index 55893d0..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorViewTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.function.BiConsumer;
-import java.util.stream.IntStream;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Unit tests for {@link VectorView}.
- */
-public class VectorViewTest {
-    /** */
-    private static final int OFFSET = 10;
-
-    /** */
-    private static final int VIEW_LENGTH = 80;
-
-    /** */
-    private static final String EXTERNALIZE_TEST_FILE_NAME = "externalizeTest";
-
-    /** */
-    private VectorView testVector;
-
-    /** */
-    private DenseLocalOnHeapVector parentVector;
-
-    /** */
-    private double[] parentData;
-
-    /** */
-    @Before
-    public void setup() {
-        parentVector = new DenseLocalOnHeapVector(MathTestConstants.STORAGE_SIZE);
-
-        IntStream.range(0, MathTestConstants.STORAGE_SIZE).forEach(idx -> parentVector.set(idx, Math.random()));
-
-        parentData = parentVector.getStorage().data().clone();
-
-        testVector = new VectorView(parentVector, OFFSET, VIEW_LENGTH);
-    }
-
-    /** */
-    @AfterClass
-    public static void cleanup() throws IOException {
-        Files.deleteIfExists(Paths.get(EXTERNALIZE_TEST_FILE_NAME));
-    }
-
-    /** */
-    @Test
-    public void testCopy() throws Exception {
-        Vector cp = testVector.copy();
-
-        assertTrue(MathTestConstants.VAL_NOT_EQUALS, cp.equals(testVector));
-    }
-
-    /** */
-    @Test(expected = org.apache.ignite.math.exceptions.UnsupportedOperationException.class)
-    public void testLike() throws Exception {
-        for (int card : new int[] {1, 2, 4, 8, 16, 32, 64, 128})
-            consumeSampleVectors((v, desc) -> {
-                Vector vLike = new VectorView(v, 0, 1).like(card);
-
-                Class<? extends Vector> expType = v.getClass();
-
-                assertNotNull("Expect non-null like vector for " + expType.getSimpleName() + " in " + desc, vLike);
-
-                assertEquals("Expect size equal to cardinality at " + desc, card, vLike.size());
-
-                Class<? extends Vector> actualType = vLike.getClass();
-
-                assertTrue("Expected matrix type " + expType.getSimpleName()
-                        + " should be assignable from actual type " + actualType.getSimpleName() + " in " + desc,
-                    expType.isAssignableFrom(actualType));
-
-            });
-    }
-
-    /** See also {@link VectorToMatrixTest#testLikeMatrix()}. */
-    @Test
-    public void testLikeMatrix() {
-        consumeSampleVectors((v, desc) -> {
-            boolean expECaught = false;
-
-            try {
-                assertNull("Null view instead of exception in " + desc, new VectorView(v, 0, 1).likeMatrix(1, 1));
-            }
-            catch (UnsupportedOperationException uoe) {
-                expECaught = true;
-            }
-
-            assertTrue("Expected exception was not caught in " + desc, expECaught);
-        });
-    }
-
-    /** */
-    @Test
-    public void testWriteReadExternal() throws Exception {
-        assertNotNull("Unexpected null parent data", parentData);
-
-        File f = new File(EXTERNALIZE_TEST_FILE_NAME);
-
-        try {
-            ObjectOutputStream objOutputStream = new ObjectOutputStream(new FileOutputStream(f));
-
-            objOutputStream.writeObject(testVector);
-
-            objOutputStream.close();
-
-            ObjectInputStream objInputStream = new ObjectInputStream(new FileInputStream(f));
-
-            VectorView readVector = (VectorView)objInputStream.readObject();
-
-            objInputStream.close();
-
-            assertTrue(MathTestConstants.VAL_NOT_EQUALS, testVector.equals(readVector));
-        }
-        catch (ClassNotFoundException | IOException e) {
-            fail(e.getMessage());
-        }
-    }
-
-    /** */
-    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
-        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/ExternalizeTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/ExternalizeTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/ExternalizeTest.java
new file mode 100644
index 0000000..32a8ec1
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/ExternalizeTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Common test for externalization.
+ */
+public abstract class ExternalizeTest<T extends Externalizable & Destroyable> {
+    /** */
+    protected void externalizeTest(T initObj) {
+        T objRestored = null;
+
+        try {
+            ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
+            ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
+
+            objOutputStream.writeObject(initObj);
+
+            ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
+            ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
+
+            objRestored = (T)objInputStream.readObject();
+
+            assertTrue(MathTestConstants.VAL_NOT_EQUALS, initObj.equals(objRestored));
+            assertTrue(MathTestConstants.VAL_NOT_EQUALS, Integer.compare(initObj.hashCode(), objRestored.hashCode()) == 0);
+        }
+        catch (ClassNotFoundException | IOException e) {
+            fail(e + " [" + e.getMessage() + "]");
+        }
+        finally {
+            if (objRestored != null)
+                objRestored.destroy();
+        }
+    }
+
+    /** */
+    @Test
+    public abstract void externalizeTest();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplDistributedTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplDistributedTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplDistributedTestSuite.java
new file mode 100644
index 0000000..720a090
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplDistributedTestSuite.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import org.apache.ignite.ml.math.impls.matrix.CacheMatrixTest;
+import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrixTest;
+import org.apache.ignite.ml.math.impls.storage.matrix.SparseDistributedMatrixStorageTest;
+import org.apache.ignite.ml.math.impls.vector.CacheVectorTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for all distributed tests located in org.apache.ignite.math.impls.* package.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    CacheVectorTest.class,
+    CacheMatrixTest.class,
+    SparseDistributedMatrixStorageTest.class,
+    SparseDistributedMatrixTest.class,
+})
+public class MathImplDistributedTestSuite {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplLocalTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplLocalTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplLocalTestSuite.java
new file mode 100644
index 0000000..be9c33a
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplLocalTestSuite.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import org.apache.ignite.ml.math.decompositions.CholeskyDecompositionTest;
+import org.apache.ignite.ml.math.decompositions.EigenDecompositionTest;
+import org.apache.ignite.ml.math.decompositions.LUDecompositionTest;
+import org.apache.ignite.ml.math.decompositions.QRDecompositionTest;
+import org.apache.ignite.ml.math.decompositions.SingularValueDecompositionTest;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrixConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrixConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.DiagonalMatrixTest;
+import org.apache.ignite.ml.math.impls.matrix.FunctionMatrixConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.MatrixAttributeTest;
+import org.apache.ignite.ml.math.impls.matrix.MatrixImplementationsTest;
+import org.apache.ignite.ml.math.impls.matrix.MatrixViewConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixViewConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.RandomMatrixConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.SparseLocalOnHeapMatrixConstructorTest;
+import org.apache.ignite.ml.math.impls.matrix.TransposedMatrixViewTest;
+import org.apache.ignite.ml.math.impls.storage.matrix.MatrixArrayStorageTest;
+import org.apache.ignite.ml.math.impls.storage.matrix.MatrixOffHeapStorageTest;
+import org.apache.ignite.ml.math.impls.storage.matrix.MatrixStorageImplementationTest;
+import org.apache.ignite.ml.math.impls.storage.vector.RandomAccessSparseVectorStorageTest;
+import org.apache.ignite.ml.math.impls.storage.vector.SparseLocalOffHeapVectorStorageTest;
+import org.apache.ignite.ml.math.impls.storage.vector.VectorArrayStorageTest;
+import org.apache.ignite.ml.math.impls.storage.vector.VectorOffheapStorageTest;
+import org.apache.ignite.ml.math.impls.vector.AbstractVectorTest;
+import org.apache.ignite.ml.math.impls.vector.ConstantVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.DelegatingVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.FunctionVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.MatrixVectorViewTest;
+import org.apache.ignite.ml.math.impls.vector.PivotedVectorViewConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.RandomVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.SingleElementVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.SingleElementVectorViewConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.SparseLocalVectorConstructorTest;
+import org.apache.ignite.ml.math.impls.vector.VectorAttributesTest;
+import org.apache.ignite.ml.math.impls.vector.VectorFoldMapTest;
+import org.apache.ignite.ml.math.impls.vector.VectorImplementationsTest;
+import org.apache.ignite.ml.math.impls.vector.VectorIterableTest;
+import org.apache.ignite.ml.math.impls.vector.VectorNormTest;
+import org.apache.ignite.ml.math.impls.vector.VectorToMatrixTest;
+import org.apache.ignite.ml.math.impls.vector.VectorViewTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for all local tests located in org.apache.ignite.math.impls.* package.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    // Vector constructors tests.
+    DenseLocalOnHeapVectorConstructorTest.class,
+    DenseLocalOffHeapVectorConstructorTest.class,
+    SparseLocalVectorConstructorTest.class,
+    RandomVectorConstructorTest.class,
+    ConstantVectorConstructorTest.class,
+    FunctionVectorConstructorTest.class,
+    SingleElementVectorConstructorTest.class,
+    PivotedVectorViewConstructorTest.class,
+    SingleElementVectorViewConstructorTest.class,
+    DelegatingVectorConstructorTest.class,
+    // Various vectors tests.
+    AbstractVectorTest.class,
+    VectorImplementationsTest.class,
+    VectorViewTest.class,
+    MatrixVectorViewTest.class,
+    // Vector particular features tests.
+    VectorIterableTest.class,
+    VectorAttributesTest.class,
+    VectorToMatrixTest.class,
+    VectorNormTest.class,
+    VectorFoldMapTest.class,
+    // Vector storage tests
+    VectorArrayStorageTest.class,
+    VectorOffheapStorageTest.class,
+    RandomAccessSparseVectorStorageTest.class,
+    SparseLocalOffHeapVectorStorageTest.class,
+    // Matrix storage tests.
+    MatrixStorageImplementationTest.class,
+    MatrixOffHeapStorageTest.class,
+    MatrixArrayStorageTest.class,
+    // Matrix constructors tests.
+    DenseLocalOnHeapMatrixConstructorTest.class,
+    DenseLocalOffHeapMatrixConstructorTest.class,
+    RandomMatrixConstructorTest.class,
+    FunctionMatrixConstructorTest.class,
+    MatrixViewConstructorTest.class,
+    PivotedMatrixViewConstructorTest.class,
+    SparseLocalOnHeapMatrixConstructorTest.class,
+    // Matrix tests.
+    MatrixImplementationsTest.class,
+    DiagonalMatrixTest.class,
+    MatrixAttributeTest.class,
+    TransposedMatrixViewTest.class,
+    // Decomposes
+    LUDecompositionTest.class,
+    EigenDecompositionTest.class,
+    CholeskyDecompositionTest.class,
+    QRDecompositionTest.class,
+    SingularValueDecompositionTest.class
+})
+public class MathImplLocalTestSuite {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplMainTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplMainTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplMainTestSuite.java
new file mode 100644
index 0000000..5f41583
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplMainTestSuite.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for local and distributed tests
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    MathImplLocalTestSuite.class,
+    MathImplDistributedTestSuite.class
+})
+public class MathImplMainTestSuite {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/TracerTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/TracerTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/TracerTest.java
new file mode 100644
index 0000000..d7c746d
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/TracerTest.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.junit.Test;
+
+import static java.nio.file.Files.createTempFile;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link Tracer}.
+ */
+public class TracerTest {
+    /** */ private static final String DEFAULT_FORMAT = "%.10f";
+    /** */ private static final double DEFAULT_DELTA = 0.000000001d;
+
+    /**
+     * Color mapper that maps [0, 1] range into three distinct RGB segments.
+     */
+    private static final Tracer.ColorMapper COLOR_MAPPER = new Tracer.ColorMapper() {
+        /** {@inheritDoc} */
+        @Override public Color apply(Double d) {
+            if (d <= 0.33)
+                return Color.RED;
+            else if (d <= 0.66)
+                return Color.GREEN;
+            else
+                return Color.BLUE;
+        }
+    };
+
+    /**
+     * @param size Vector size.
+     */
+    private Vector makeRandomVector(int size) {
+        DenseLocalOnHeapVector vec = new DenseLocalOnHeapVector(size);
+
+        vec.assign((idx) -> Math.random());
+
+        return vec;
+    }
+
+    /**
+     * @param rows Amount of rows in matrix.
+     * @param cols Amount of columns in matrix.
+     */
+    private Matrix makeRandomMatrix(int rows, int cols) {
+        DenseLocalOnHeapMatrix mtx = new DenseLocalOnHeapMatrix(rows, cols);
+
+        // Missing assign(f)?
+        mtx.map((d) -> Math.random());
+
+        return mtx;
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testAsciiVectorTracer() {
+        Vector vec = makeRandomVector(20);
+
+        Tracer.showAscii(vec);
+        Tracer.showAscii(vec, "%2f");
+        Tracer.showAscii(vec, "%.3g");
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testAsciiMatrixTracer() {
+        Matrix mtx = makeRandomMatrix(10, 10);
+
+        Tracer.showAscii(mtx);
+        Tracer.showAscii(mtx, "%2f");
+        Tracer.showAscii(mtx, "%.3g");
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testHtmlVectorTracer() throws IOException {
+        Vector vec1 = makeRandomVector(1000);
+
+        // Default color mapping.
+        Tracer.showHtml(vec1);
+
+        // Custom color mapping.
+        Tracer.showHtml(vec1, COLOR_MAPPER);
+
+        // Default color mapping with sorted vector.
+        Tracer.showHtml(vec1.sort());
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testHtmlMatrixTracer() throws IOException {
+        Matrix mtx1 = makeRandomMatrix(100, 100);
+
+        // Custom color mapping.
+        Tracer.showHtml(mtx1, COLOR_MAPPER);
+
+        Matrix mtx2 = new DenseLocalOnHeapMatrix(100, 100);
+
+        double MAX = (double)(mtx2.rowSize() * mtx2.columnSize());
+
+        mtx2.assign((x, y) -> (double)(x * y) / MAX);
+
+        Tracer.showHtml(mtx2);
+    }
+
+    /** */
+    @Test
+    public void testWriteVectorToCSVFile() throws IOException {
+        DenseLocalOnHeapVector vector = new DenseLocalOnHeapVector(MathTestConstants.STORAGE_SIZE);
+
+        for (int i = 0; i < vector.size(); i++)
+            vector.set(i, Math.random());
+
+        Path file = createTempFile("vector", ".csv");
+
+        Tracer.saveAsCsv(vector, DEFAULT_FORMAT, file.toString());
+
+        System.out.println("Vector exported: " + file.getFileName());
+
+        List<String> strings = Files.readAllLines(file);
+        Optional<String> reduce = strings.stream().reduce((s1, s2) -> s1 + s2);
+        String[] csvVals = reduce.get().split(",");
+
+        for (int i = 0; i < vector.size(); i++) {
+            Double csvVal = Double.valueOf(csvVals[i]);
+
+            assertEquals("Unexpected value.", csvVal, vector.get(i), DEFAULT_DELTA);
+        }
+
+        Files.deleteIfExists(file);
+    }
+
+    /** */
+    @Test
+    public void testWriteMatrixToCSVFile() throws IOException {
+        DenseLocalOnHeapMatrix matrix = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
+
+        for (int i = 0; i < matrix.rowSize(); i++)
+            for (int j = 0; j < matrix.columnSize(); j++)
+                matrix.set(i, j, Math.random());
+
+        Path file = createTempFile("matrix", ".csv");
+
+        Tracer.saveAsCsv(matrix, DEFAULT_FORMAT, file.toString());
+
+        System.out.println("Matrix exported: " + file.getFileName());
+
+        List<String> strings = Files.readAllLines(file);
+        Optional<String> reduce = strings.stream().reduce((s1, s2) -> s1 + s2);
+        String[] csvVals = reduce.get().split(",");
+
+        for (int i = 0; i < matrix.rowSize(); i++)
+            for (int j = 0; j < matrix.columnSize(); j++) {
+                Double csvVal = Double.valueOf(csvVals[i * matrix.rowSize() + j]);
+
+                assertEquals("Unexpected value.", csvVal, matrix.get(i, j), DEFAULT_DELTA);
+            }
+
+        Files.deleteIfExists(file);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmark.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmark.java
new file mode 100644
index 0000000..33ccfc9
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmark.java
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.benchmark;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/** Refer {@link MathBenchmarkSelfTest} for usage examples. */
+class MathBenchmark {
+    /** */
+    private final boolean outputToConsole;
+
+    /** */
+    private final String benchmarkName;
+
+    /** */
+    private final int measurementTimes;
+
+    /** */
+    private final int warmUpTimes;
+
+    /** */
+    private final String tag;
+
+    /** */
+    private final String comments;
+
+    /** Constructor strictly for use within this class. */
+    private MathBenchmark(String benchmarkName, boolean outputToConsole, int measurementTimes, int warmUpTimes,
+        String tag, String comments) {
+        this.benchmarkName = benchmarkName;
+        this.outputToConsole = outputToConsole;
+        this.measurementTimes = measurementTimes;
+        this.warmUpTimes = warmUpTimes;
+        this.tag = tag;
+        this.comments = comments;
+        validate();
+    }
+
+    /**
+     * Benchmark with specified name and default parameters, in particular, default output file.
+     *
+     * @param benchmarkName name
+     */
+    MathBenchmark(String benchmarkName) {
+        this(benchmarkName, false, 100, 1, "", "");
+    }
+
+    /**
+     * Executes the code using config of this benchmark.
+     *
+     * @param code code to execute
+     * @throws Exception if something goes wrong
+     */
+    void execute(BenchmarkCode code) throws Exception {
+        System.out.println("Started benchmark [" + benchmarkName + "].");
+
+        for (int cnt = 0; cnt < warmUpTimes; cnt++)
+            code.call();
+
+        final long start = System.currentTimeMillis();
+
+        for (int cnt = 0; cnt < measurementTimes; cnt++)
+            code.call();
+
+        final long end = System.currentTimeMillis();
+
+        writeResults(formatResults(start, end));
+
+        System.out.println("Finished benchmark [" + benchmarkName + "].");
+    }
+
+    /**
+     * Set optional output mode for using stdout.
+     *
+     * @return configured benchmark
+     */
+    MathBenchmark outputToConsole() {
+        return new MathBenchmark(benchmarkName, true, measurementTimes, warmUpTimes, tag, comments);
+    }
+
+    /**
+     * Set optional measurement times.
+     *
+     * @param param times
+     * @return configured benchmark
+     */
+    MathBenchmark measurementTimes(int param) {
+        return new MathBenchmark(benchmarkName, outputToConsole, param, warmUpTimes, tag, comments);
+    }
+
+    /**
+     * Set optional warm-up times.
+     *
+     * @param param times
+     * @return configured benchmark
+     */
+    MathBenchmark warmUpTimes(int param) {
+        return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, param, tag, comments);
+    }
+
+    /**
+     * Set optional tag to help filtering specific kind of benchmark results.
+     *
+     * @param param name
+     * @return configured benchmark
+     */
+    MathBenchmark tag(String param) {
+        return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, warmUpTimes, param, comments);
+    }
+
+    /**
+     * Set optional comments.
+     *
+     * @param param name
+     * @return configured benchmark
+     */
+    MathBenchmark comments(String param) {
+        return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, warmUpTimes, tag, param);
+    }
+
+    /** */
+    private void writeResults(String results) throws Exception {
+        if (outputToConsole) {
+            System.out.println(results);
+
+            return;
+        }
+
+        new ResultsWriter().append(results);
+    }
+
+    /** */
+    private String formatResults(long start, long end) {
+        final String delim = ",";
+
+        assert !formatDouble(1000_000_001.1).contains(delim) : "Formatted results contain [" + delim + "].";
+
+        final String ts = formatTs(start);
+
+        assert !ts.contains(delim) : "Formatted timestamp contains [" + delim + "].";
+
+        return benchmarkName +
+            delim +
+            ts + // IMPL NOTE timestamp
+            delim +
+            formatDouble((double)(end - start) / measurementTimes) +
+            delim +
+            measurementTimes +
+            delim +
+            warmUpTimes +
+            delim +
+            tag +
+            delim +
+            comments;
+    }
+
+    /** */
+    private String formatDouble(double val) {
+        return String.format(Locale.US, "%f", val);
+    }
+
+    /** */
+    private String formatTs(long ts) {
+        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+
+        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+        return sdf.format(new Date(ts));
+    }
+
+    /** */
+    private void validate() {
+        if (benchmarkName == null || benchmarkName.isEmpty())
+            throw new IllegalArgumentException("Invalid benchmark name: [" + benchmarkName + "].");
+
+        if (measurementTimes < 1)
+            throw new IllegalArgumentException("Invalid measurement times: [" + measurementTimes + "].");
+    }
+
+    /** */
+    interface BenchmarkCode {
+        // todo find out why Callable<Void> failed to work here
+
+        /** */
+        void call() throws Exception;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmarkSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmarkSelfTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmarkSelfTest.java
new file mode 100644
index 0000000..86b29db
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/MathBenchmarkSelfTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.benchmark;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class MathBenchmarkSelfTest {
+    /** */
+    @Test
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void demoTest() throws Exception {
+        for (int i = 0; i < 2; i++)
+            new MathBenchmark("demo test")
+                .outputToConsole() // IMPL NOTE this is to write output into console instead of a file
+                .tag(null) // IMPL NOTE try null for tag, expect it to be formatted reasonably
+                .comments(null) // IMPL NOTE try null for comments, expect it to be formatted reasonably
+                .execute(() -> {
+                    double seed = 1.1;
+
+                    for (int cnt = 0; cnt < 1000; cnt++) {
+                        seed = Math.pow(seed, 2);
+
+                        assertTrue(seed > 0);
+                    }
+                });
+    }
+
+    /** */
+    @Test
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void configTest() throws Exception {
+        new MathBenchmark("demo config test")
+            .outputToConsole()
+            .measurementTimes(2)
+            .warmUpTimes(0)
+            .tag("demo tag")
+            .comments("demo comments")
+            .execute(() -> System.out.println("config test"));
+    }
+
+    /** */
+    @Test(expected = IllegalArgumentException.class)
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void emptyNameTest() throws Exception {
+        new MathBenchmark("")
+            .outputToConsole()
+            .measurementTimes(1)
+            .warmUpTimes(1)
+            .tag("empty name test tag")
+            .comments("empty name test comments")
+            .execute(() -> System.out.println("empty name test"));
+    }
+
+    /** */
+    @Test(expected = IllegalArgumentException.class)
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void nullDropboxPathTest() throws Exception {
+        new ResultsWriter(null, "whatever", "whatever");
+    }
+
+    /** */
+    @Test(expected = IllegalArgumentException.class)
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void nullDropboxUrlTest() throws Exception {
+        new ResultsWriter("whatever", null, "whatever");
+    }
+
+    /** */
+    @Test(expected = IllegalArgumentException.class)
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void nullDropboxTokenTest() throws Exception {
+        new ResultsWriter("whatever", "whatever", null);
+    }
+
+    /** */
+    @Test(expected = IllegalArgumentException.class)
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void nullResultsTest() throws Exception {
+        new ResultsWriter("whatever", "whatever", "whatever").append(null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/ResultsWriter.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/ResultsWriter.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/ResultsWriter.java
new file mode 100644
index 0000000..2c37bff
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/ResultsWriter.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.benchmark;
+
+import com.dropbox.core.DbxException;
+import com.dropbox.core.DbxRequestConfig;
+import com.dropbox.core.v2.DbxClientV2;
+import com.dropbox.core.v2.files.WriteMode;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.UUID;
+
+/** */
+class ResultsWriter {
+    /** */
+    private static final String DROPBOX_PATH
+        = "/benchmarks/math.benchmark.results.csv";
+
+    /** */
+    private static final String DROPBOX_URL
+        = "https://www.dropbox.com/s/r7tcle31r7gaty8/math.benchmark.results.csv";
+
+    /** */
+    private static final String ACCESS_TOKEN
+        = "1MMmQjEyzGAAAAAAAAAAfDFrQ6oBPPi4NX-iU_VrgmXB2JDXqRHGa125cTkkEQ0V";
+
+    /** */
+    private final String dropboxPath;
+    /** */
+    private final String dropboxUrl;
+    /** */
+    private final String accessTok;
+
+    /** */
+    ResultsWriter(String dropboxPath, String dropboxUrl, String accessTok) {
+        this.dropboxPath = dropboxPath;
+        this.dropboxUrl = dropboxUrl;
+        this.accessTok = accessTok;
+
+        if (dropboxPath == null || dropboxUrl == null || accessTok == null)
+            throw new IllegalArgumentException("Neither of dropbox path, URL, access token can be null.");
+    }
+
+    /** **/
+    ResultsWriter() {
+        this(DROPBOX_PATH, DROPBOX_URL, ACCESS_TOKEN);
+    }
+
+    /** */
+    void append(String res) throws DbxException, IOException {
+        if (res == null)
+            throw new IllegalArgumentException("benchmark result is null");
+
+        if (dropboxPath == null) {
+            System.out.println(res);
+
+            return;
+        }
+
+        append(res, client());
+    }
+
+    /** */
+    private void append(String res, DbxClientV2 client) throws DbxException, IOException {
+        File tmp = createTmpFile();
+
+        try (FileOutputStream out = new FileOutputStream(tmp)) {
+            client.files().download(dropboxPath).download(out);
+        }
+
+        writeResults(res, tmp);
+
+        try (FileInputStream in = new FileInputStream(tmp)) {
+            client.files().uploadBuilder(dropboxPath).withMode(WriteMode.OVERWRITE).uploadAndFinish(in);
+        }
+
+        if (!tmp.delete())
+            System.out.println("Failed to delete " + tmp.getAbsolutePath());
+
+        System.out.println("Uploaded benchmark results to: " + dropboxUrl);
+    }
+
+    /** */
+    private void writeResults(String res, File tmp) throws IOException {
+        final String unixLineSeparator = "\n";
+
+        try (final PrintWriter writer = new PrintWriter(Files.newBufferedWriter(Paths.get(tmp.toURI()),
+            StandardOpenOption.APPEND, StandardOpenOption.CREATE))) {
+            writer.write(res + unixLineSeparator);
+        }
+    }
+
+    /** */
+    private File createTmpFile() throws IOException {
+        File tmp = File.createTempFile(UUID.randomUUID().toString(), ".csv");
+
+        tmp.deleteOnExit();
+
+        return tmp;
+    }
+
+    /** */
+    private DbxClientV2 client() {
+        return new DbxClientV2(DbxRequestConfig.newBuilder("dropbox/MathBenchmark").build(), accessTok);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/VectorBenchmarkTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/VectorBenchmarkTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/VectorBenchmarkTest.java
new file mode 100644
index 0000000..fd98382
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/VectorBenchmarkTest.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.benchmark;
+
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+/** */
+public class VectorBenchmarkTest {
+    // todo add benchmarks for other methods in Vector and for other types of Vector and Matrix
+
+    /** */
+    @Test
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void testDenseLocalOnHeapVector() throws Exception {
+        benchmark("DenseLocalOnHeapVector basic mix", DenseLocalOnHeapVector::new, this::basicMix);
+
+        benchmark("DenseLocalOnHeapVector fold map", DenseLocalOnHeapVector::new, this::foldMapMix);
+    }
+
+    /** */
+    @Test
+    @Ignore("Benchmark tests are intended only for manual execution")
+    public void testDenseLocalOffHeapVector() throws Exception {
+        benchmark("DenseLocalOffHeapVector basic mix", DenseLocalOffHeapVector::new, this::basicMix);
+
+        benchmark("DenseLocalOffHeapVector fold map", DenseLocalOffHeapVector::new, this::foldMapMix);
+    }
+
+    /** */
+    private void benchmark(String namePrefix, Function<Integer, Vector> constructor,
+        BiConsumer<Integer, Function<Integer, Vector>> consumer) throws Exception {
+        assertNotNull(namePrefix);
+
+        new MathBenchmark(namePrefix + " small sizes").execute(() -> {
+            for (int size : new int[] {2, 3, 4, 5, 6, 7})
+                consumer.accept(size, constructor);
+        });
+
+        new MathBenchmark(namePrefix + " sizes powers of 2").execute(() -> {
+            for (int power : new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14})
+                consumer.accept(1 << power, constructor);
+        });
+
+        new MathBenchmark(namePrefix + " large sizes").execute(() -> {
+            for (int power : new int[] {10, 12, 14, 16})
+                for (int delta : new int[] {-1, 0, 1})
+                    consumer.accept((1 << power) + delta, constructor);
+        });
+
+        new MathBenchmark(namePrefix + " extra large sizes")
+            .measurementTimes(10)
+            .execute(() -> { // IMPL NOTE trying below with power 22 almost killed my IDEA and laptop
+                for (int power : new int[] {17, 18, 19, 20, 21})
+                    for (int delta : new int[] {-1, 0}) // IMPL NOTE delta +1 is not intended for use here
+                        consumer.accept((1 << power) + delta, constructor);
+            });
+    }
+
+    /** */
+    private void basicMix(int size, Function<Integer, Vector> constructor) {
+        final Vector v1 = constructor.apply(size), v2 = constructor.apply(size);
+
+        for (int idx = 0; idx < size; idx++) {
+            v1.set(idx, idx);
+
+            v2.set(idx, size - idx);
+        }
+
+        assertNotNull(v1.sum());
+
+        assertNotNull(v1.copy());
+
+        assertFalse(v1.getLengthSquared() < 0);
+
+        assertNotNull(v1.normalize());
+
+        assertNotNull(v1.logNormalize());
+
+        assertFalse(v1.getDistanceSquared(v2) < 0);
+
+        assertNotNull(v1.divide(2));
+
+        assertNotNull(v1.minus(v2));
+
+        assertNotNull(v1.plus(v2));
+
+        assertNotNull(v1.dot(v2));
+
+        assertNotNull(v1.assign(v2));
+
+        assertNotNull(v1.assign(1)); // IMPL NOTE this would better be last test for it sets all values the same
+    }
+
+    /** */
+    private void foldMapMix(int size, Function<Integer, Vector> constructor) {
+        final Vector v1 = constructor.apply(size), v2 = constructor.apply(size);
+
+        for (int idx = 0; idx < size; idx++) {
+            v1.set(idx, idx);
+
+            v2.set(idx, size - idx);
+        }
+
+        assertNotNull(v1.map((val) -> (val + 1)));
+
+        assertNotNull(v1.map(v2, (one, other) -> one + other / 2.0));
+
+        assertNotNull(v1.map((val, val1) -> (val + val1), 2.0));
+
+        assertNotNull(v1.foldMap((sum, val) -> (val + sum), (val) -> val, 0.0));
+
+        assertNotNull(v1.foldMap(v2, (sum, val) -> (val + sum), (val1, val2) -> val1 + val2, 0.0));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/package-info.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/package-info.java
new file mode 100644
index 0000000..f77e6e32
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/benchmark/package-info.java
@@ -0,0 +1,18 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.benchmark;

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/CholeskyDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/CholeskyDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/CholeskyDecompositionTest.java
new file mode 100644
index 0000000..be03cb1
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/CholeskyDecompositionTest.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.NonPositiveDefiniteMatrixException;
+import org.apache.ignite.ml.math.exceptions.NonSymmetricMatrixException;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/** */
+public class CholeskyDecompositionTest {
+    /** */
+    @Test
+    public void basicTest() {
+        basicTest(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        }));
+    }
+
+    /**
+     * Test for {@link DecompositionSupport} features.
+     */
+    @Test
+    public void decompositionSupportTest() {
+        basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        })));
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullMatrixTest() {
+        new CholeskyDecomposition(null);
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void wrongMatrixSizeTest() {
+        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(2, 3));
+    }
+
+    /** */
+    @Test(expected = NonSymmetricMatrixException.class)
+    public void nonSymmetricMatrixTest() {
+        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 10.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {-10.0d, -1.0d, 2.0d}
+        }));
+    }
+
+    /** */
+    @Test(expected = NonPositiveDefiniteMatrixException.class)
+    public void nonAbsPositiveMatrixTest() {
+        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 0.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        }));
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void solveWrongVectorSizeTest() {
+        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        })).solve(new DenseLocalOnHeapVector(2));
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void solveWrongMatrixSizeTest() {
+        new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        })).solve(new DenseLocalOnHeapMatrix(2, 3));
+    }
+
+    /** */
+    private void basicTest(Matrix m) {
+        // This decomposition is useful when dealing with systems of linear equations of the form
+        // m x = b where m is a Hermitian matrix.
+        // For such systems Cholesky decomposition provides
+        // more effective method of solving compared to LU decomposition.
+        // Suppose we want to solve system
+        // m x = b for various bs. Then after we computed Cholesky decomposition, we can feed various bs
+        // as a matrix of the form
+        // (b1, b2, ..., bm)
+        // to the method Cholesky::solve which returns solutions in the form
+        // (sol1, sol2, ..., solm)
+        CholeskyDecomposition dec = new CholeskyDecomposition(m);
+        assertEquals("Unexpected value for decomposition determinant.",
+            4d, dec.getDeterminant(), 0d);
+
+        Matrix l = dec.getL();
+        Matrix lt = dec.getLT();
+
+        assertNotNull("Matrix l is expected to be not null.", l);
+        assertNotNull("Matrix lt is expected to be not null.", lt);
+
+        for (int row = 0; row < l.rowSize(); row++)
+            for (int col = 0; col < l.columnSize(); col++)
+                assertEquals("Unexpected value transposed matrix at (" + row + "," + col + ").",
+                    l.get(row, col), lt.get(col, row), 0d);
+
+        Matrix bs = new DenseLocalOnHeapMatrix(new double[][] {
+            {4.0, -6.0, 7.0},
+            {1.0, 1.0, 1.0}
+        }).transpose();
+        Matrix sol = dec.solve(bs);
+
+        assertNotNull("Solution matrix is expected to be not null.", sol);
+        assertEquals("Solution rows are not as expected.", bs.rowSize(), sol.rowSize());
+        assertEquals("Solution columns are not as expected.", bs.columnSize(), sol.columnSize());
+
+        for (int i = 0; i < sol.columnSize(); i++)
+            assertNotNull("Solution matrix column is expected to be not null at index " + i, sol.viewColumn(i));
+
+        Vector b = new DenseLocalOnHeapVector(new double[] {4.0, -6.0, 7.0});
+        Vector solVec = dec.solve(b);
+
+        for (int idx = 0; idx < b.size(); idx++)
+            assertEquals("Unexpected value solution vector at " + idx,
+                b.get(idx), solVec.get(idx), 0d);
+
+        dec.destroy();
+    }
+}


[37/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.


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

Branch: refs/heads/ignite-1561
Commit: 2edb935cbf87198993c403724e26efc655710c25
Parents: 9e7421f
Author: devozerov <vo...@gridgain.com>
Authored: Tue Apr 18 17:11:34 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Tue Apr 18 17:11:36 2017 +0300

----------------------------------------------------------------------
 .../jdbc2/JdbcAbstractDmlStatementSelfTest.java |   92 +-
 ...BinaryMarshallerInsertStatementSelfTest.java |    9 +-
 ...cBinaryMarshallerMergeStatementSelfTest.java |    9 +-
 .../jdbc2/JdbcDynamicIndexAbstractSelfTest.java |  367 ++++
 ...namicIndexAtomicPartitionedNearSelfTest.java |   26 +
 ...bcDynamicIndexAtomicPartitionedSelfTest.java |   39 +
 ...dbcDynamicIndexAtomicReplicatedSelfTest.java |   39 +
 ...dexTransactionalPartitionedNearSelfTest.java |   26 +
 ...icIndexTransactionalPartitionedSelfTest.java |   39 +
 ...micIndexTransactionalReplicatedSelfTest.java |   39 +
 .../jdbc2/JdbcInsertStatementSelfTest.java      |    4 +-
 .../jdbc/suite/IgniteJdbcDriverTestSuite.java   |    8 +
 .../apache/ignite/IgniteSystemProperties.java   |    8 +
 .../org/apache/ignite/cache/QueryEntity.java    |   82 +-
 .../org/apache/ignite/cache/QueryIndex.java     |    9 +
 .../configuration/CacheConfiguration.java       |    7 +-
 .../apache/ignite/internal/GridComponent.java   |    5 +-
 .../ignite/internal/GridKernalContext.java      |    7 +
 .../ignite/internal/GridKernalContextImpl.java  |   13 +-
 .../org/apache/ignite/internal/GridTopic.java   |    5 +-
 .../apache/ignite/internal/IgniteKernal.java    |   27 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |   18 +
 .../managers/communication/GridIoManager.java   |    2 +
 .../communication/GridIoMessageFactory.java     |    6 +
 .../managers/communication/GridIoPolicy.java    |    3 +
 .../cache/CacheAffinitySharedManager.java       |    3 +-
 .../cache/CachePartitionExchangeWorkerTask.java |    6 +-
 .../cache/DynamicCacheChangeRequest.java        |   23 +-
 .../cache/DynamicCacheDescriptor.java           |   50 +-
 .../processors/cache/GridCacheEntryEx.java      |   13 +-
 .../processors/cache/GridCacheMapEntry.java     |   17 +
 .../GridCachePartitionExchangeManager.java      |   36 +-
 .../processors/cache/GridCacheProcessor.java    |  135 +-
 .../cache/GridCacheSharedContext.java           |    2 +
 .../GridDhtPartitionsExchangeFuture.java        |    5 -
 .../cache/query/GridCacheQueryManager.java      |    7 +-
 .../cache/query/IgniteQueryErrorCode.java       |   27 +-
 .../internal/processors/pool/PoolProcessor.java |    5 +
 .../query/GridQueryIndexDescriptor.java         |    5 +
 .../processors/query/GridQueryIndexing.java     |   43 +-
 .../processors/query/GridQueryProcessor.java    | 1707 ++++++++++++++++--
 .../query/GridQueryTypeDescriptor.java          |    7 +
 .../processors/query/IgniteSQLException.java    |    7 +
 .../query/QueryIndexDescriptorImpl.java         |   42 +-
 .../processors/query/QueryIndexKey.java         |   85 +
 .../internal/processors/query/QuerySchema.java  |  168 ++
 .../query/QueryTypeDescriptorImpl.java          |  150 +-
 .../internal/processors/query/QueryUtils.java   |  219 ++-
 .../query/schema/SchemaExchangeWorkerTask.java  |   53 +
 .../query/schema/SchemaIndexCacheVisitor.java   |   33 +
 .../schema/SchemaIndexCacheVisitorClosure.java  |   42 +
 .../schema/SchemaIndexCacheVisitorImpl.java     |  197 ++
 .../SchemaIndexOperationCancellationToken.java  |   53 +
 .../processors/query/schema/SchemaKey.java      |   59 +
 .../SchemaNodeLeaveExchangeWorkerTask.java      |   53 +
 .../schema/SchemaOperationClientFuture.java     |   52 +
 .../query/schema/SchemaOperationException.java  |  138 ++
 .../query/schema/SchemaOperationManager.java    |  292 +++
 .../query/schema/SchemaOperationWorker.java     |  205 +++
 .../message/SchemaAbstractDiscoveryMessage.java |   70 +
 .../message/SchemaFinishDiscoveryMessage.java   |   98 +
 .../message/SchemaOperationStatusMessage.java   |  168 ++
 .../message/SchemaProposeDiscoveryMessage.java  |  133 ++
 .../operation/SchemaAbstractOperation.java      |   67 +
 .../operation/SchemaIndexAbstractOperation.java |   40 +
 .../operation/SchemaIndexCreateOperation.java   |   91 +
 .../operation/SchemaIndexDropOperation.java     |   68 +
 .../processors/cache/GridCacheTestEntryEx.java  |    7 +
 .../junits/GridTestKernalContext.java           |    1 +
 .../query/h2/GridH2IndexingGeoSelfTest.java     |    4 +-
 .../query/h2/DmlStatementsProcessor.java        |   49 +-
 .../processors/query/h2/IgniteH2Indexing.java   |  678 +++++--
 .../query/h2/ddl/DdlStatementsProcessor.java    |  208 +++
 .../query/h2/opt/GridH2IndexBase.java           |    2 +-
 .../query/h2/opt/GridH2PrimaryScanIndex.java    |   87 +
 .../query/h2/opt/GridH2SystemIndexFactory.java  |   38 +
 .../processors/query/h2/opt/GridH2Table.java    |  382 ++--
 .../query/h2/opt/GridLuceneIndex.java           |   10 +-
 .../query/h2/sql/GridSqlCreateIndex.java        |  121 ++
 .../query/h2/sql/GridSqlDropIndex.java          |   82 +
 .../query/h2/sql/GridSqlQueryParser.java        |  123 ++
 .../cache/index/AbstractSchemaSelfTest.java     |  512 ++++++
 .../DynamicIndexAbstractBasicSelfTest.java      |  950 ++++++++++
 .../DynamicIndexAbstractConcurrentSelfTest.java |  921 ++++++++++
 .../index/DynamicIndexAbstractSelfTest.java     |  467 +++++
 .../index/DynamicIndexClientBasicSelfTest.java  |   28 +
 ...ndexPartitionedAtomicConcurrentSelfTest.java |   33 +
 ...titionedTransactionalConcurrentSelfTest.java |   33 +
 ...IndexReplicatedAtomicConcurrentSelfTest.java |   33 +
 ...plicatedTransactionalConcurrentSelfTest.java |   33 +
 .../index/DynamicIndexServerBasicSelfTest.java  |   28 +
 ...amicIndexServerCoordinatorBasicSelfTest.java |   28 +
 ...namicIndexServerNodeFIlterBasicSelfTest.java |   28 +
 ...erverNodeFilterCoordinatorBasicSelfTest.java |   30 +
 .../index/H2DynamicIndexAbstractSelfTest.java   |  400 ++++
 ...namicIndexAtomicPartitionedNearSelfTest.java |   26 +
 ...H2DynamicIndexAtomicPartitionedSelfTest.java |   39 +
 .../H2DynamicIndexAtomicReplicatedSelfTest.java |   39 +
 ...dexTransactionalPartitionedNearSelfTest.java |   26 +
 ...icIndexTransactionalPartitionedSelfTest.java |   39 +
 ...micIndexTransactionalReplicatedSelfTest.java |   39 +
 .../cache/index/SchemaExchangeSelfTest.java     |  589 ++++++
 .../local/IgniteCacheLocalQuerySelfTest.java    |    2 +-
 .../query/IgniteQueryDedicatedPoolTest.java     |    1 -
 .../query/IgniteSqlSplitterSelfTest.java        |    2 +-
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  109 +-
 .../query/h2/IgniteSqlQueryMinMaxTest.java      |   16 +-
 .../query/h2/opt/GridH2TableSelfTest.java       |  171 +-
 .../query/h2/sql/GridQueryParsingTest.java      |  212 ++-
 .../IgniteCacheQuerySelfTestSuite.java          |   37 +-
 .../IgniteCacheQuerySelfTestSuite2.java         |   11 +
 111 files changed, 11221 insertions(+), 1016 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java
index 440f6d0..f23dde7 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java
@@ -21,17 +21,10 @@ import java.io.Serializable;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.util.Collections;
-import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.ConnectorConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 
 import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX;
@@ -42,9 +35,6 @@ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
  * Statement test.
  */
 public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstractTest {
-    /** IP finder. */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
     /** JDBC URL. */
     private static final String BASE_URL = CFG_URL_PREFIX + "modules/clients/src/test/config/jdbc-config.xml";
 
@@ -58,18 +48,28 @@ public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstrac
     protected Connection conn;
 
     /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        return getConfiguration0(igniteInstanceName);
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(3);
+
+        Class.forName("org.apache.ignite.IgniteJdbcDriver");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        conn = DriverManager.getConnection(getCfgUrl());
+
+        ignite(0).getOrCreateCache(cacheConfig());
     }
 
     /**
-     * @param igniteInstanceName Ignite instance name.
-     * @return Grid configuration used for starting the grid.
-     * @throws Exception If failed.
+     * @return Cache configuration for non binary marshaller tests.
      */
-    private IgniteConfiguration getConfiguration0(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
+    private CacheConfiguration nonBinCacheConfig() {
         CacheConfiguration<?,?> cache = defaultCacheConfiguration();
 
         cache.setCacheMode(PARTITIONED);
@@ -79,32 +79,18 @@ public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstrac
             String.class, Person.class
         );
 
-        cfg.setCacheConfiguration(cache);
-
-        TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
-        disco.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(disco);
-
-        cfg.setConnectorConfiguration(new ConnectorConfiguration());
-
-        return cfg;
+        return cache;
     }
 
     /**
-     * @param igniteInstanceName Ignite instance name.
-     * @return Grid configuration used for starting the grid ready for manipulating binary objects.
-     * @throws Exception If failed.
+     * @return Cache configuration for binary marshaller tests.
      */
-    IgniteConfiguration getBinaryConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = getConfiguration0(igniteInstanceName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration ccfg = cfg.getCacheConfiguration()[0];
+    final CacheConfiguration binaryCacheConfig() {
+        CacheConfiguration<?,?> cache = defaultCacheConfiguration();
 
-        ccfg.getQueryEntities().clear();
+        cache.setCacheMode(PARTITIONED);
+        cache.setBackups(1);
+        cache.setWriteSynchronizationMode(FULL_SYNC);
 
         QueryEntity e = new QueryEntity();
 
@@ -116,26 +102,16 @@ public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstrac
         e.addQueryField("firstName", String.class.getName(), null);
         e.addQueryField("lastName", String.class.getName(), null);
 
-        ccfg.setQueryEntities(Collections.singletonList(e));
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(3);
+        cache.setQueryEntities(Collections.singletonList(e));
 
-        Class.forName("org.apache.ignite.IgniteJdbcDriver");
+        return cache;
     }
 
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        conn = DriverManager.getConnection(getCfgUrl());
+    /**
+     * @return Configuration of cache to create.
+     */
+    CacheConfiguration cacheConfig() {
+        return nonBinCacheConfig();
     }
 
     /**
@@ -147,9 +123,7 @@ public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstrac
 
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
-        grid(0).cache(null).clear();
-
-        assertEquals(0, grid(0).cache(null).size(CachePeekMode.ALL));
+        grid(0).destroyCache(null);
 
         conn.close();
         assertTrue(conn.isClosed());

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerInsertStatementSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerInsertStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerInsertStatementSelfTest.java
index e8a09d9..878e4de 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerInsertStatementSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerInsertStatementSelfTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.ignite.internal.jdbc2;
 
+import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 
 /**
  * JDBC test of INSERT statement w/binary marshaller - no nodes know about classes.
@@ -30,6 +32,11 @@ public class JdbcBinaryMarshallerInsertStatementSelfTest extends JdbcInsertState
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        return getBinaryConfiguration(igniteInstanceName);
+        return super.getConfiguration(igniteInstanceName).setMarshaller(new BinaryMarshaller());
+    }
+
+    /** {@inheritDoc} */
+    @Override CacheConfiguration cacheConfig() {
+        return binaryCacheConfig();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerMergeStatementSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerMergeStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerMergeStatementSelfTest.java
index 5e4b559..8b4d3c7 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerMergeStatementSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcBinaryMarshallerMergeStatementSelfTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.ignite.internal.jdbc2;
 
+import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 
 /**
  * JDBC test of MERGE statement w/binary marshaller - no nodes know about classes.
@@ -30,6 +32,11 @@ public class JdbcBinaryMarshallerMergeStatementSelfTest extends JdbcMergeStateme
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        return getBinaryConfiguration(igniteInstanceName);
+        return super.getConfiguration(igniteInstanceName).setMarshaller(new BinaryMarshaller());
+    }
+
+    /** {@inheritDoc} */
+    @Override CacheConfiguration cacheConfig() {
+        return binaryCacheConfig();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAbstractSelfTest.java
new file mode 100644
index 0000000..84ffc28
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAbstractSelfTest.java
@@ -0,0 +1,367 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.List;
+import javax.cache.CacheException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.F;
+
+/**
+ * Test that checks indexes handling with JDBC.
+ */
+public abstract class JdbcDynamicIndexAbstractSelfTest extends JdbcAbstractDmlStatementSelfTest {
+    /** */
+    private final static String CREATE_INDEX = "create index idx on Person (id desc)";
+
+    /** */
+    private final static String DROP_INDEX = "drop index idx";
+
+    /** */
+    private final static String CREATE_INDEX_IF_NOT_EXISTS = "create index if not exists idx on Person (id desc)";
+
+    /** */
+    private final static String DROP_INDEX_IF_EXISTS = "drop index idx if exists";
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        try (PreparedStatement ps =
+            conn.prepareStatement("INSERT INTO Person (_key, id, age, firstName, lastName) values (?, ?, ?, ?, ?)")) {
+
+            ps.setString(1, "j");
+            ps.setInt(2, 1);
+            ps.setInt(3, 10);
+            ps.setString(4, "John");
+            ps.setString(5, "Smith");
+            ps.executeUpdate();
+
+            ps.setString(1, "m");
+            ps.setInt(2, 2);
+            ps.setInt(3, 20);
+            ps.setString(4, "Mark");
+            ps.setString(5, "Stone");
+            ps.executeUpdate();
+
+            ps.setString(1, "s");
+            ps.setInt(2, 3);
+            ps.setInt(3, 30);
+            ps.setString(4, "Sarah");
+            ps.setString(5, "Pazzi");
+            ps.executeUpdate();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override CacheConfiguration cacheConfig() {
+        CacheConfiguration ccfg = super.cacheConfig();
+
+        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+
+        ccfg.setCacheMode(cacheMode());
+        ccfg.setAtomicityMode(atomicityMode());
+
+        if (nearCache())
+            ccfg.setNearConfiguration(new NearCacheConfiguration());
+
+        return ccfg;
+    }
+
+    /**
+     * @return Cache mode to use.
+     */
+    protected abstract CacheMode cacheMode();
+
+    /**
+     * @return Cache atomicity mode to use.
+     */
+    protected abstract CacheAtomicityMode atomicityMode();
+
+    /**
+     * @return Whether to use near cache.
+     */
+    protected abstract boolean nearCache();
+
+    /**
+     * Execute given SQL statement.
+     * @param sql Statement.
+     * @throws SQLException if failed.
+     */
+    private void jdbcRun(String sql) throws SQLException {
+        try (Statement stmt = conn.createStatement()) {
+            stmt.execute(sql);
+        }
+    }
+
+    /** */
+    private Object getSingleValue(ResultSet rs) throws SQLException {
+        assertEquals(1, rs.getMetaData().getColumnCount());
+
+        assertTrue(rs.next());
+
+        Object res = rs.getObject(1);
+
+        assertTrue(rs.isLast());
+
+        return res;
+    }
+
+    /**
+     * Test that after index creation index is used by queries.
+     */
+    public void testCreateIndex() throws SQLException {
+        assertSize(3);
+
+        assertColumnValues(30, 20, 10);
+
+        jdbcRun(CREATE_INDEX);
+
+        // Test that local queries on all server nodes use new index.
+        for (int i = 0 ; i < 3; i++) {
+            List<List<?>> locRes = ignite(i).cache(null).query(new SqlFieldsQuery("explain select id from " +
+                "Person where id = 5").setLocal(true)).getAll();
+
+            assertEquals(F.asList(
+                Collections.singletonList("SELECT\n" +
+                    "    ID\n" +
+                    "FROM \"\".PERSON\n" +
+                    "    /* \"\".IDX: ID = 5 */\n" +
+                    "WHERE ID = 5")
+            ), locRes);
+        }
+
+        assertSize(3);
+
+        assertColumnValues(30, 20, 10);
+    }
+
+    /**
+     * Test that creating an index with duplicate name yields an error.
+     */
+    public void testCreateIndexWithDuplicateName() throws SQLException {
+        jdbcRun(CREATE_INDEX);
+
+        assertSqlException(new RunnableX() {
+            /** {@inheritDoc} */
+            @Override public void run() throws Exception {
+                jdbcRun(CREATE_INDEX);
+            }
+        }, IgniteQueryErrorCode.INDEX_ALREADY_EXISTS);
+    }
+
+    /**
+     * Test that creating an index with duplicate name does not yield an error with {@code IF NOT EXISTS}.
+     */
+    public void testCreateIndexIfNotExists() throws SQLException {
+        jdbcRun(CREATE_INDEX);
+
+        // Despite duplicate name, this does not yield an error.
+        jdbcRun(CREATE_INDEX_IF_NOT_EXISTS);
+    }
+
+    /**
+     * Test that after index drop there are no attempts to use it, and data state remains intact.
+     */
+    public void testDropIndex() throws SQLException {
+        assertSize(3);
+
+        jdbcRun(CREATE_INDEX);
+
+        assertSize(3);
+
+        jdbcRun(DROP_INDEX);
+
+        // Test that no local queries on server nodes use new index.
+        for (int i = 0 ; i < 3; i++) {
+            List<List<?>> locRes = ignite(i).cache(null).query(new SqlFieldsQuery("explain select id from " +
+                "Person where id = 5").setLocal(true)).getAll();
+
+            assertEquals(F.asList(
+                Collections.singletonList("SELECT\n" +
+                    "    ID\n" +
+                    "FROM \"\".PERSON\n" +
+                    "    /* \"\".PERSON.__SCAN_ */\n" +
+                    "WHERE ID = 5")
+            ), locRes);
+        }
+
+        assertSize(3);
+    }
+
+    /**
+     * Test that dropping a non-existent index yields an error.
+     */
+    public void testDropMissingIndex() {
+        assertSqlException(new RunnableX() {
+            /** {@inheritDoc} */
+            @Override public void run() throws Exception {
+                jdbcRun(DROP_INDEX);
+            }
+        }, IgniteQueryErrorCode.INDEX_NOT_FOUND);
+    }
+
+    /**
+     * Test that dropping a non-existent index does not yield an error with {@code IF EXISTS}.
+     */
+    public void testDropMissingIndexIfExists() throws SQLException {
+        // Despite index missing, this does not yield an error.
+        jdbcRun(DROP_INDEX_IF_EXISTS);
+    }
+
+    /**
+     * Test that changes in cache affect index, and vice versa.
+     */
+    public void testIndexState() throws SQLException {
+        IgniteCache<String, Person> cache = cache();
+
+        assertSize(3);
+
+        assertColumnValues(30, 20, 10);
+
+        jdbcRun(CREATE_INDEX);
+
+        assertSize(3);
+
+        assertColumnValues(30, 20, 10);
+
+        cache.remove("m");
+
+        assertColumnValues(30, 10);
+
+        cache.put("a", new Person(4, "someVal", "a", 5));
+
+        assertColumnValues(5, 30, 10);
+
+        jdbcRun(DROP_INDEX);
+
+        assertColumnValues(5, 30, 10);
+    }
+
+    /**
+     * Check that values of {@code field1} match what we expect.
+     * @param vals Expected values.
+     */
+    private void assertColumnValues(int... vals) throws SQLException {
+        try (Statement stmt = conn.createStatement()) {
+            try (ResultSet rs = stmt.executeQuery("SELECT age FROM Person ORDER BY id desc")) {
+                assertEquals(1, rs.getMetaData().getColumnCount());
+
+                for (int i = 0; i < vals.length; i++) {
+                    assertTrue("Result set must have " + vals.length + " rows, got " + i, rs.next());
+
+                    assertEquals(vals[i], rs.getInt(1));
+                }
+
+                assertFalse("Result set must have exactly " + vals.length + " rows", rs.next());
+            }
+        }
+    }
+
+    /**
+     * Do a {@code SELECT COUNT(*)} query to check index state correctness.
+     * @param expSize Expected number of items in table.
+     */
+    private void assertSize(long expSize) throws SQLException {
+        assertEquals(expSize, cache().size());
+
+        try (Statement stmt = conn.createStatement()) {
+            try (ResultSet rs = stmt.executeQuery("SELECT COUNT(*) from Person")) {
+                assertEquals(expSize, getSingleValue(rs));
+            }
+        }
+    }
+
+    /**
+     * @return Cache.
+     */
+    private IgniteCache<String, Person> cache() {
+        return grid(0).cache(null);
+    }
+
+    /**
+     * Ensure that SQL exception is thrown.
+     *
+     * @param r Runnable.
+     * @param expCode Error code.
+     */
+    private static void assertSqlException(RunnableX r, int expCode) {
+        // We expect IgniteSQLException with given code inside CacheException inside JDBC SQLException.
+
+        try {
+            r.run();
+        }
+        catch (SQLException ex) {
+            if (ex.getCause() != null) {
+                try {
+                    throw ex.getCause();
+                }
+                catch (CacheException ex1) {
+                    if (ex1.getCause() != null) {
+                        try {
+                            throw ex1.getCause();
+                        }
+                        catch (IgniteSQLException e) {
+                            assertEquals("Unexpected error code [expected=" + expCode + ", actual=" + e.statusCode() + ']',
+                                expCode, e.statusCode());
+
+                            return;
+                        }
+                        catch (Throwable t) {
+                            fail("Unexpected exception: " + t);
+                        }
+                    }
+                }
+                catch (Throwable t) {
+                    fail("Unexpected exception: " + t);
+                }
+            }
+        }
+        catch (Exception e) {
+            fail("Unexpected exception: " + e);
+        }
+
+        fail(IgniteSQLException.class.getSimpleName() +  " is not thrown.");
+    }
+
+    /**
+     * Runnable which can throw checked exceptions.
+     */
+    private interface RunnableX {
+        /**
+         * Do run.
+         *
+         * @throws Exception If failed.
+         */
+        public void run() throws Exception;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedNearSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedNearSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedNearSelfTest.java
new file mode 100644
index 0000000..c2b5011
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedNearSelfTest.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+/** */
+public class JdbcDynamicIndexAtomicPartitionedNearSelfTest extends JdbcDynamicIndexAtomicPartitionedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedSelfTest.java
new file mode 100644
index 0000000..41e07e7
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicPartitionedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class JdbcDynamicIndexAtomicPartitionedSelfTest extends JdbcDynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicReplicatedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicReplicatedSelfTest.java
new file mode 100644
index 0000000..7a5b015
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexAtomicReplicatedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class JdbcDynamicIndexAtomicReplicatedSelfTest extends JdbcDynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedNearSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedNearSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedNearSelfTest.java
new file mode 100644
index 0000000..2815dff
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedNearSelfTest.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+/** */
+public class JdbcDynamicIndexTransactionalPartitionedNearSelfTest extends JdbcDynamicIndexTransactionalPartitionedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedSelfTest.java
new file mode 100644
index 0000000..47b257f
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalPartitionedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class JdbcDynamicIndexTransactionalPartitionedSelfTest extends JdbcDynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalReplicatedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalReplicatedSelfTest.java
new file mode 100644
index 0000000..9b135d8
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcDynamicIndexTransactionalReplicatedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class JdbcDynamicIndexTransactionalReplicatedSelfTest extends JdbcDynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcInsertStatementSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcInsertStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcInsertStatementSelfTest.java
index 1bd6d34..9e01bc7 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcInsertStatementSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcInsertStatementSelfTest.java
@@ -24,8 +24,8 @@ import java.sql.Statement;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.concurrent.Callable;
-import org.apache.ignite.IgniteException;
 import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
 import org.apache.ignite.testframework.GridTestUtils;
 
 /**
@@ -164,7 +164,7 @@ public class JdbcInsertStatementSelfTest extends JdbcAbstractDmlStatementSelfTes
 
         assertNotNull(reason);
 
-        assertEquals(IgniteException.class, reason.getClass());
+        assertEquals(IgniteSQLException.class, reason.getClass());
 
         assertEquals("Failed to INSERT some keys because they are already in cache [keys=[p2]]", reason.getMessage());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
index 2489de9..75671de 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
@@ -73,6 +73,14 @@ public class IgniteJdbcDriverTestSuite extends TestSuite {
         suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDeleteStatementSelfTest.class));
         suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcStreamingSelfTest.class));
 
+        // DDL tests.
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDynamicIndexAtomicPartitionedNearSelfTest.class));
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDynamicIndexAtomicPartitionedSelfTest.class));
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDynamicIndexAtomicReplicatedSelfTest.class));
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDynamicIndexTransactionalPartitionedNearSelfTest.class));
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDynamicIndexTransactionalPartitionedSelfTest.class));
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcDynamicIndexTransactionalReplicatedSelfTest.class));
+
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index 1216db8..37e8c6b 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -575,6 +575,14 @@ public final class IgniteSystemProperties {
      */
     public static final String IGNITE_MAX_INDEX_PAYLOAD_SIZE = "IGNITE_MAX_INDEX_PAYLOAD_SIZE";
 
+    /**
+     * Indexing discovery history size. Protects from duplicate messages maintaining the list of IDs of recently
+     * arrived discovery messages.
+     * <p>
+     * Defaults to {@code 1000}.
+     */
+    public static final String IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE = "IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE";
+
     /** Returns true for system properties only avoiding sending sensitive information. */
     private static final IgnitePredicate<Map.Entry<String, String>> PROPS_FILTER = new IgnitePredicate<Map.Entry<String, String>>() {
         @Override public boolean apply(final Map.Entry<String, String> entry) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index 9f4313e..31fe264 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -20,9 +20,12 @@ package org.apache.ignite.cache;
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
+
+import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.A;
 
@@ -63,6 +66,24 @@ public class QueryEntity implements Serializable {
     }
 
     /**
+     * Copy constructor.
+     *
+     * @param other Other entity.
+     */
+    public QueryEntity(QueryEntity other) {
+        keyType = other.keyType;
+        valType = other.valType;
+
+        fields = new LinkedHashMap<>(other.fields);
+        keyFields = other.keyFields != null ? new HashSet<>(other.keyFields) : null;
+
+        aliases = new HashMap<>(other.aliases);
+        idxs = new HashMap<>(other.idxs);
+
+        tableName = other.tableName;
+    }
+
+    /**
      * Creates a query entity with the given key and value types.
      *
      * @param keyType Key type.
@@ -204,7 +225,7 @@ public class QueryEntity implements Serializable {
         for (QueryIndex idx : idxs) {
             if (!F.isEmpty(idx.getFields())) {
                 if (idx.getName() == null)
-                    idx.setName(defaultIndexName(idx));
+                    idx.setName(QueryUtils.indexName(this, idx));
 
                 if (idx.getIndexType() == null)
                     throw new IllegalArgumentException("Index type is not set " + idx.getName());
@@ -220,6 +241,13 @@ public class QueryEntity implements Serializable {
     }
 
     /**
+     * Clear indexes.
+     */
+    public void clearIndexes() {
+        this.idxs.clear();
+    }
+
+    /**
      * Gets table name for this query entity.
      *
      * @return table name
@@ -254,56 +282,4 @@ public class QueryEntity implements Serializable {
 
         return this;
     }
-
-    /**
-     * Ensures that index with the given name exists.
-     *
-     * @param idxName Index name.
-     * @param idxType Index type.
-     */
-    public void ensureIndex(String idxName, QueryIndexType idxType) {
-        QueryIndex idx = idxs.get(idxName);
-
-        if (idx == null) {
-            idx = new QueryIndex();
-
-            idx.setName(idxName);
-            idx.setIndexType(idxType);
-
-            idxs.put(idxName, idx);
-        }
-        else
-            throw new IllegalArgumentException("An index with the same name and of a different type already exists " +
-                "[idxName=" + idxName + ", existingIdxType=" + idx.getIndexType() + ", newIdxType=" + idxType + ']');
-    }
-
-    /**
-     * Generates default index name by concatenating all index field names.
-     *
-     * @param idx Index to build name for.
-     * @return Index name.
-     */
-    public static String defaultIndexName(QueryIndex idx) {
-        StringBuilder idxName = new StringBuilder();
-
-        for (Map.Entry<String, Boolean> field : idx.getFields().entrySet()) {
-            idxName.append(field.getKey());
-
-            idxName.append('_');
-            idxName.append(field.getValue() ? "asc_" : "desc_");
-        }
-
-        for (int i = 0; i < idxName.length(); i++) {
-            char ch = idxName.charAt(i);
-
-            if (Character.isWhitespace(ch))
-                idxName.setCharAt(i, '_');
-            else
-                idxName.setCharAt(i, Character.toLowerCase(ch));
-        }
-
-        idxName.append("idx");
-
-        return idxName.toString();
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
index 750d3e1..555a006 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
@@ -16,6 +16,9 @@
  */
 package org.apache.ignite.cache;
 
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Collection;
@@ -38,6 +41,7 @@ public class QueryIndex implements Serializable {
     private String name;
 
     /** */
+    @GridToStringInclude
     private LinkedHashMap<String, Boolean> fields;
 
     /** */
@@ -260,4 +264,9 @@ public class QueryIndex implements Serializable {
     public void setInlineSize(int inlineSize) {
         this.inlineSize = inlineSize;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryIndex.class, this);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 2308a10..a2f7cc8 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -2096,7 +2096,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
         @Nullable ClassProperty parent) {
         if (U.isJdk(cls) || QueryUtils.isGeometryClass(cls)) {
             if (parent == null && !key && QueryUtils.isSqlType(cls)) { // We have to index primitive _val.
-                String idxName = QueryUtils._VAL + "_idx";
+                String idxName = cls.getSimpleName() + "_" + QueryUtils._VAL + "_idx";
 
                 type.addIndex(idxName, QueryUtils.isGeometryClass(cls) ?
                     QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);
@@ -2527,6 +2527,11 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
         }
 
         /** {@inheritDoc} */
+        @Override public String name() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
         @Override public Collection<String> fields() {
             Collection<String> res = new ArrayList<>(fields.size());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java b/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java
index be9a1d6..98edf0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java
@@ -58,7 +58,10 @@ public interface GridComponent {
         MARSHALLER_PROC,
 
         /** */
-        BINARY_PROC
+        BINARY_PROC,
+
+        /** Query processor. */
+        QUERY_PROC
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
index 6fefb68..8462e5f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
@@ -564,6 +564,13 @@ public interface GridKernalContext extends Iterable<GridComponent> {
     public ExecutorService getQueryExecutorService();
 
     /**
+     * Executor service that is in charge of processing schema change messages.
+     *
+     * @return Executor service that is in charge of processing schema change messages.
+     */
+    public ExecutorService getSchemaExecutorService();
+
+    /**
      * Gets exception registry.
      *
      * @return Exception registry.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 664e47c..213cf86 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -340,6 +340,10 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
 
     /** */
     @GridToStringExclude
+    protected ExecutorService schemaExecSvc;
+
+    /** */
+    @GridToStringExclude
     private Map<String, Object> attrs = new HashMap<>();
 
     /** */
@@ -396,8 +400,8 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
      * @param idxExecSvc Indexing executor service.
      * @param callbackExecSvc Callback executor service.
      * @param qryExecSvc Query executor service.
+     * @param schemaExecSvc Schema executor service.
      * @param plugins Plugin providers.
-     * @throws IgniteCheckedException In case of error.
      */
     @SuppressWarnings("TypeMayBeWeakened")
     protected GridKernalContextImpl(
@@ -419,6 +423,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
         @Nullable ExecutorService idxExecSvc,
         IgniteStripedThreadPoolExecutor callbackExecSvc,
         ExecutorService qryExecSvc,
+        ExecutorService schemaExecSvc,
         List<PluginProvider> plugins
     ) {
         assert grid != null;
@@ -442,6 +447,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
         this.idxExecSvc = idxExecSvc;
         this.callbackExecSvc = callbackExecSvc;
         this.qryExecSvc = qryExecSvc;
+        this.schemaExecSvc = schemaExecSvc;
 
         marshCtx = new MarshallerContextImpl(plugins);
 
@@ -987,6 +993,11 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
     }
 
     /** {@inheritDoc} */
+    @Override public ExecutorService getSchemaExecutorService() {
+        return schemaExecSvc;
+    }
+
+    /** {@inheritDoc} */
     @Override public IgniteExceptionRegistry exceptionRegistry() {
         return IgniteExceptionRegistry.get();
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java b/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java
index 7acc070..c382999 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java
@@ -108,7 +108,10 @@ public enum GridTopic {
     TOPIC_HADOOP_MSG,
 
     /** */
-    TOPIC_METADATA_REQ;
+    TOPIC_METADATA_REQ,
+
+    /** */
+    TOPIC_SCHEMA;
 
     /** Enum values. */
     private static final GridTopic[] VALS = values();

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 9b41b58..922dd55 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -311,6 +311,10 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
 
     /** */
     @GridToStringExclude
+    private ObjectName schemaExecSvcMBean;
+
+    /** */
+    @GridToStringExclude
     private ObjectName stripedExecSvcMBean;
 
     /** Kernal start timestamp. */
@@ -694,6 +698,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
      * @param idxExecSvc Indexing executor service.
      * @param callbackExecSvc Callback executor service.
      * @param qryExecSvc Query executor service.
+     * @param schemaExecSvc Schema executor service.
      * @param errHnd Error handler to use for notification about startup problems.
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
@@ -714,6 +719,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         @Nullable ExecutorService idxExecSvc,
         IgniteStripedThreadPoolExecutor callbackExecSvc,
         ExecutorService qryExecSvc,
+        ExecutorService schemaExecSvc,
         GridAbsClosure errHnd
     )
         throws IgniteCheckedException
@@ -828,6 +834,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
                 idxExecSvc,
                 callbackExecSvc,
                 qryExecSvc,
+                schemaExecSvc,
                 plugins
             );
 
@@ -1019,7 +1026,9 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
             // Register MBeans.
             registerKernalMBean();
             registerLocalNodeMBean();
-            registerExecutorMBeans(execSvc, sysExecSvc, p2pExecSvc, mgmtExecSvc, restExecSvc, qryExecSvc);
+            registerExecutorMBeans(execSvc, sysExecSvc, p2pExecSvc, mgmtExecSvc, restExecSvc, qryExecSvc,
+                schemaExecSvc);
+
             registerStripedExecutorMBean(stripedExecSvc);
 
             // Lifecycle bean notifications.
@@ -1611,11 +1620,12 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
     }
 
     /**
-     * @param execSvc
-     * @param sysExecSvc
-     * @param p2pExecSvc
-     * @param mgmtExecSvc
-     * @param restExecSvc
+     * @param execSvc Public executor service.
+     * @param sysExecSvc System executor service.
+     * @param p2pExecSvc P2P executor service.
+     * @param mgmtExecSvc Management executor service.
+     * @param restExecSvc Query executor service.
+     * @param schemaExecSvc Schema executor service.
      * @throws IgniteCheckedException If failed.
      */
     private void registerExecutorMBeans(ExecutorService execSvc,
@@ -1623,12 +1633,14 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         ExecutorService p2pExecSvc,
         ExecutorService mgmtExecSvc,
         ExecutorService restExecSvc,
-        ExecutorService qryExecSvc) throws IgniteCheckedException {
+        ExecutorService qryExecSvc,
+        ExecutorService schemaExecSvc) throws IgniteCheckedException {
         pubExecSvcMBean = registerExecutorMBean(execSvc, "GridExecutionExecutor");
         sysExecSvcMBean = registerExecutorMBean(sysExecSvc, "GridSystemExecutor");
         mgmtExecSvcMBean = registerExecutorMBean(mgmtExecSvc, "GridManagementExecutor");
         p2PExecSvcMBean = registerExecutorMBean(p2pExecSvc, "GridClassLoadingExecutor");
         qryExecSvcMBean = registerExecutorMBean(qryExecSvc, "GridQueryExecutor");
+        schemaExecSvcMBean = registerExecutorMBean(schemaExecSvc, "GridSchemaExecutor");
 
         ConnectorConfiguration clientCfg = cfg.getConnectorConfiguration();
 
@@ -2151,6 +2163,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
                     unregisterMBean(locNodeMBean) &
                     unregisterMBean(restExecSvcMBean) &
                     unregisterMBean(qryExecSvcMBean) &
+                    unregisterMBean(schemaExecSvcMBean) &
                     unregisterMBean(stripedExecSvcMBean)
             ))
                 errOnStop = false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 61e93cf..2eda01c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -1527,6 +1527,9 @@ public class IgnitionEx {
         /** Query executor service. */
         private ThreadPoolExecutor qryExecSvc;
 
+        /** Query executor service. */
+        private ThreadPoolExecutor schemaExecSvc;
+
         /** Grid state. */
         private volatile IgniteState state = STOPPED;
 
@@ -1845,6 +1848,16 @@ public class IgnitionEx {
 
             qryExecSvc.allowCoreThreadTimeOut(true);
 
+            schemaExecSvc = new IgniteThreadPoolExecutor(
+                "schema",
+                cfg.getIgniteInstanceName(),
+                2,
+                2,
+                DFLT_THREAD_KEEP_ALIVE_TIME,
+                new LinkedBlockingQueue<Runnable>());
+
+            schemaExecSvc.allowCoreThreadTimeOut(true);
+
             // Register Ignite MBean for current grid instance.
             registerFactoryMbean(myCfg.getMBeanServer());
 
@@ -1872,6 +1885,7 @@ public class IgnitionEx {
                     idxExecSvc,
                     callbackExecSvc,
                     qryExecSvc,
+                    schemaExecSvc,
                     new CA() {
                         @Override public void apply() {
                             startLatch.countDown();
@@ -2464,6 +2478,10 @@ public class IgnitionEx {
 
             qryExecSvc = null;
 
+            U.shutdownNow(getClass(), schemaExecSvc, log);
+
+            schemaExecSvc = null;
+
             U.shutdownNow(getClass(), stripedExecSvc, log);
 
             stripedExecSvc = null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
index b615c35..83fc3b5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
@@ -97,6 +97,7 @@ import static org.apache.ignite.internal.managers.communication.GridIoPolicy.IGF
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.MANAGEMENT_POOL;
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.P2P_POOL;
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.PUBLIC_POOL;
+import static org.apache.ignite.internal.managers.communication.GridIoPolicy.SCHEMA_POOL;
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.SERVICE_POOL;
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL;
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.UTILITY_CACHE_POOL;
@@ -700,6 +701,7 @@ public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializa
                 case IGFS_POOL:
                 case DATA_STREAMER_POOL:
                 case QUERY_POOL:
+                case SCHEMA_POOL:
                 case SERVICE_POOL:
                 {
                     if (msg.isOrdered())

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index b972a31..17e4a01 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -137,6 +137,7 @@ import org.apache.ignite.internal.processors.igfs.IgfsFragmentizerResponse;
 import org.apache.ignite.internal.processors.igfs.IgfsSyncMessage;
 import org.apache.ignite.internal.processors.marshaller.MissingMappingRequestMessage;
 import org.apache.ignite.internal.processors.marshaller.MissingMappingResponseMessage;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaOperationStatusMessage;
 import org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryCancelRequest;
 import org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryFailResponse;
 import org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageRequest;
@@ -177,6 +178,11 @@ public class GridIoMessageFactory implements MessageFactory {
         Message msg = null;
 
         switch (type) {
+            case -53:
+                msg = new SchemaOperationStatusMessage();
+
+                break;
+
             case -52:
                 msg = new GridIntList();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoPolicy.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoPolicy.java
index e848633..13bc4c4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoPolicy.java
@@ -55,6 +55,9 @@ public class GridIoPolicy {
     /** Pool for service proxy executions. */
     public static final byte SERVICE_POOL = 11;
 
+    /** Schema pool.  */
+    public static final byte SCHEMA_POOL = 12;
+
     /**
      * Defines the range of reserved pools that are not available for plugins.
      * @param key The key.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
index 77e832e..0958208 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
@@ -346,7 +346,8 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
                     req.startCacheConfiguration(),
                     req.cacheType(),
                     false,
-                    req.deploymentId());
+                    req.deploymentId(),
+                    req.schema());
 
                 DynamicCacheDescriptor old = registeredCaches.put(cacheId, desc);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
index ca99511..ad0dcc9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
@@ -21,9 +21,5 @@ package org.apache.ignite.internal.processors.cache;
  * Cache partition exchange worker task marker interface.
  */
 public interface CachePartitionExchangeWorkerTask {
-    /**
-     * @return {@code True} if task denotes standard exchange task, {@code false} if this is a custom task which
-     * must be executed from within exchange thread.
-     */
-    boolean isExchange();
+    // No-op.
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
index 1e5ab88..9d2563d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
@@ -17,16 +17,18 @@
 
 package org.apache.ignite.internal.processors.cache;
 
-import java.io.Serializable;
-import java.util.UUID;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.query.QuerySchema;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.lang.IgniteUuid;
 import org.jetbrains.annotations.Nullable;
 
+import java.io.Serializable;
+import java.util.UUID;
+
 /**
  * Cache start/stop request.
  */
@@ -83,6 +85,9 @@ public class DynamicCacheChangeRequest implements Serializable {
     /** Reset lost partitions flag. */
     private boolean resetLostPartitions;
 
+    /** Dynamic schema. */
+    private QuerySchema schema;
+
     /** */
     private transient boolean exchangeNeeded;
 
@@ -353,6 +358,20 @@ public class DynamicCacheChangeRequest implements Serializable {
         return rcvdFrom;
     }
 
+    /**
+     * @return Dynamic schema.
+     */
+    public QuerySchema schema() {
+        return schema;
+    }
+
+    /**
+     * @param schema Dynamic schema.
+     */
+    public void schema(QuerySchema schema) {
+        this.schema = schema != null ? schema.copy() : null;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(DynamicCacheChangeRequest.class, this, "cacheName", cacheName());

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
index 5938785..92a7af3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
@@ -24,6 +24,8 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.plugin.CachePluginManager;
+import org.apache.ignite.internal.processors.query.QuerySchema;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaFinishDiscoveryMessage;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -84,6 +86,12 @@ public class DynamicCacheDescriptor {
     /** */
     private transient AffinityTopologyVersion clientCacheStartVer;
 
+    /** Mutex to control schema. */
+    private final Object schemaMux = new Object();
+
+    /** Current schema. */
+    private QuerySchema schema;
+
     /**
      * @param ctx Context.
      * @param cacheCfg Cache configuration.
@@ -91,12 +99,15 @@ public class DynamicCacheDescriptor {
      * @param template {@code True} if this is template configuration.
      * @param deploymentId Deployment ID.
      */
+    @SuppressWarnings("unchecked")
     public DynamicCacheDescriptor(GridKernalContext ctx,
         CacheConfiguration cacheCfg,
         CacheType cacheType,
         boolean template,
-        IgniteUuid deploymentId) {
+        IgniteUuid deploymentId,
+        QuerySchema schema) {
         assert cacheCfg != null;
+        assert schema != null;
 
         this.cacheCfg = cacheCfg;
         this.cacheType = cacheType;
@@ -106,6 +117,10 @@ public class DynamicCacheDescriptor {
         pluginMgr = new CachePluginManager(ctx, cacheCfg);
 
         cacheId = CU.cacheId(cacheCfg.getName());
+
+        synchronized (schemaMux) {
+            this.schema = schema.copy();
+        }
     }
 
     /**
@@ -319,6 +334,39 @@ public class DynamicCacheDescriptor {
         this.clientCacheStartVer = clientCacheStartVer;
     }
 
+    /**
+     * @return Schema.
+     */
+    public QuerySchema schema() {
+        synchronized (schemaMux) {
+            return schema.copy();
+        }
+    }
+
+    /**
+     * Set schema
+     *
+     * @param schema Schema.
+     */
+    public void schema(QuerySchema schema) {
+        assert schema != null;
+
+        synchronized (schemaMux) {
+            this.schema = schema.copy();
+        }
+    }
+
+    /**
+     * Try applying finish message.
+     *
+     * @param msg Message.
+     */
+    public void schemaChangeFinish(SchemaFinishDiscoveryMessage msg) {
+        synchronized (schemaMux) {
+            schema.finish(msg);
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(DynamicCacheDescriptor.class, this, "cacheName", U.maskName(cacheCfg.getName()));

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
index 2066342..1eab04e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
@@ -33,8 +33,8 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersionedEntryEx;
 import org.apache.ignite.internal.processors.dr.GridDrType;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure;
 import org.apache.ignite.internal.util.lang.GridTuple3;
-import org.apache.ignite.internal.util.typedef.T2;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -902,6 +902,17 @@ public interface GridCacheEntryEx {
         throws IgniteCheckedException, GridCacheEntryRemovedException;
 
     /**
+     * Update index from within entry lock, passing key, value, and expiration time to provided closure.
+     *
+     * @param clo Closure to apply to key, value, and expiration time.
+     * @param link Link.
+     * @throws IgniteCheckedException If failed.
+     * @throws GridCacheEntryRemovedException If entry was removed.
+     */
+    public void updateIndex(SchemaIndexCacheVisitorClosure clo, long link) throws IgniteCheckedException,
+        GridCacheEntryRemovedException;
+
+    /**
      * @return Expire time, without accounting for transactions or removals.
      */
     public long rawExpireTime();

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index f4d4258..ddec684 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -63,6 +63,7 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersionedEntryEx;
 import org.apache.ignite.internal.processors.dr.GridDrType;
 import org.apache.ignite.internal.util.IgniteTree;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure;
 import org.apache.ignite.internal.util.lang.GridClosureException;
 import org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter;
 import org.apache.ignite.internal.util.lang.GridTuple;
@@ -3374,6 +3375,22 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
     }
 
     /** {@inheritDoc} */
+    @Override public void updateIndex(SchemaIndexCacheVisitorClosure clo, long link) throws IgniteCheckedException,
+        GridCacheEntryRemovedException {
+        synchronized (this) {
+            if (isInternal())
+                return;
+
+            checkObsolete();
+
+            unswap(false);
+
+            if (val != null)
+                clo.apply(key, partition(), val, ver, expireTimeUnlocked(), link);
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public <K, V> EvictableEntry<K, V> wrapEviction() {
         return new CacheEvictableEntryImpl<>(this);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index 2775aa7..4775ea1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@ -78,6 +78,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.Gri
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.query.schema.SchemaNodeLeaveExchangeWorkerTask;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
 import org.apache.ignite.internal.util.GridListSet;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -309,6 +310,10 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
                     if (log.isDebugEnabled())
                         log.debug("Do not start exchange for discovery event: " + evt);
                 }
+
+                // Notify indexing engine about node leave so that we can re-map coordinator accordingly.
+                if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED)
+                    exchWorker.addCustomTask(new SchemaNodeLeaveExchangeWorkerTask(evt.eventNode()));
             }
             finally {
                 leaveBusy();
@@ -752,17 +757,6 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
-     * Add custom task.
-     *
-     * @param task Task.
-     */
-    public void addCustomTask(CachePartitionExchangeWorkerTask task) {
-        assert !task.isExchange();
-
-        exchWorker.addCustomTask(task);
-    }
-
-    /**
      * @param evt Discovery event.
      * @return Affinity topology version.
      */
@@ -1536,6 +1530,16 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
+     * Check if provided task from exchange queue is exchange task.
+     *
+     * @param task Task.
+     * @return {@code True} if this is exchange task.
+     */
+    private static boolean isExchangeTask(CachePartitionExchangeWorkerTask task) {
+        return task instanceof GridDhtPartitionsExchangeFuture;
+    }
+
+    /**
      * @param exchTopVer Exchange topology version.
      */
     private void dumpPendingObjects(@Nullable AffinityTopologyVersion exchTopVer) {
@@ -1682,7 +1686,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
         void addCustomTask(CachePartitionExchangeWorkerTask task) {
             assert task != null;
 
-            assert !task.isExchange();
+            assert !isExchangeTask(task);
 
             futQ.offer(task);
         }
@@ -1693,6 +1697,8 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
          * @param task Task.
          */
         void processCustomTask(CachePartitionExchangeWorkerTask task) {
+            assert !isExchangeTask(task);
+
             try {
                 cctx.cache().processCustomExchangeTask(task);
             }
@@ -1707,7 +1713,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
         boolean hasPendingExchange() {
             if (!futQ.isEmpty()) {
                 for (CachePartitionExchangeWorkerTask task : futQ) {
-                    if (task.isExchange())
+                    if (isExchangeTask(task))
                         return true;
                 }
             }
@@ -1722,7 +1728,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
             U.warn(log, "Pending exchange futures:");
 
             for (CachePartitionExchangeWorkerTask task: futQ) {
-                if (task.isExchange())
+                if (isExchangeTask(task))
                     U.warn(log, ">>> " + task);
             }
         }
@@ -1773,7 +1779,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
                     if (task == null)
                         continue; // Main while loop.
 
-                    if (!task.isExchange()) {
+                    if (!isExchangeTask(task)) {
                         processCustomTask(task);
 
                         continue;


[05/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/EigenDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/EigenDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/EigenDecompositionTest.java
new file mode 100644
index 0000000..d283ce7
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/EigenDecompositionTest.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link EigenDecomposition}
+ */
+public class EigenDecompositionTest {
+    /** */
+    private static final double EPSILON = 1e-11;
+
+    /** */
+    @Test
+    public void testMatrixWithRealEigenvalues() {
+        test(new double[][] {
+                {1.0d, 0.0d, 0.0d, 0.0d},
+                {0.0d, 1.0d, 0.0d, 0.0d},
+                {0.0d, 0.0d, 2.0d, 0.0d},
+                {1.0d, 1.0d, 0.0d, 2.0d}},
+            new double[] {1, 2, 2, 1});
+    }
+
+    /** */
+    @Test
+    public void testSymmetricMatrix() {
+        EigenDecomposition decomposition = new EigenDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {1.0d, 0.0d, 0.0d, 1.0d},
+            {0.0d, 1.0d, 0.0d, 1.0d},
+            {0.0d, 0.0d, 2.0d, 0.0d},
+            {1.0d, 1.0d, 0.0d, 2.0d}}));
+
+        Matrix d = decomposition.getD();
+        Matrix v = decomposition.getV();
+
+        assertNotNull("Matrix d is expected to be not null.", d);
+        assertNotNull("Matrix v is expected to be not null.", v);
+
+        assertEquals("Unexpected rows in d matrix.", 4, d.rowSize());
+        assertEquals("Unexpected cols in d matrix.", 4, d.columnSize());
+
+        assertEquals("Unexpected rows in v matrix.", 4, v.rowSize());
+        assertEquals("Unexpected cols in v matrix.", 4, v.columnSize());
+
+        assertIsDiagonalNonZero(d);
+
+        decomposition.destroy();
+    }
+
+    /** */
+    @Test
+    public void testNonSquareMatrix() {
+        EigenDecomposition decomposition = new EigenDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {1.0d, 0.0d, 0.0d},
+            {0.0d, 1.0d, 0.0d},
+            {0.0d, 0.0d, 2.0d},
+            {1.0d, 1.0d, 0.0d}}));
+        // todo find out why decomposition of 3X4 matrix throws row index exception
+
+        Matrix d = decomposition.getD();
+        Matrix v = decomposition.getV();
+
+        assertNotNull("Matrix d is expected to be not null.", d);
+        assertNotNull("Matrix v is expected to be not null.", v);
+
+        assertEquals("Unexpected rows in d matrix.", 4, d.rowSize());
+        assertEquals("Unexpected cols in d matrix.", 4, d.columnSize());
+
+        assertEquals("Unexpected rows in v matrix.", 4, v.rowSize());
+        assertEquals("Unexpected cols in v matrix.", 3, v.columnSize());
+
+        assertIsDiagonal(d, true);
+
+        decomposition.destroy();
+    }
+
+    /** */
+    private void test(double[][] mRaw, double[] expRealEigenValues) {
+        DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(mRaw);
+        EigenDecomposition decomposition = new EigenDecomposition(m);
+
+        Matrix d = decomposition.getD();
+        Matrix v = decomposition.getV();
+
+        assertIsDiagonalNonZero(d);
+
+        // check that d's diagonal consists of eigenvalues of m.
+        assertDiagonalConsistsOfEigenvalues(m, d, v);
+
+        // m = v d v^{-1} is equivalent to
+        // m v = v d
+        assertMatricesAreEqual(m.times(v), v.times(d));
+
+        assertEigenvalues(decomposition, expRealEigenValues);
+
+        decomposition.destroy();
+    }
+
+    /** */
+    private void assertEigenvalues(EigenDecomposition decomposition, double[] expRealEigenValues) {
+        Vector real = decomposition.getRealEigenValues();
+        Vector imag = decomposition.getImagEigenvalues();
+
+        assertEquals("Real values size differs from expected.", expRealEigenValues.length, real.size());
+        assertEquals("Imag values size differs from expected.", expRealEigenValues.length, imag.size());
+
+        for (int idx = 0; idx < expRealEigenValues.length; idx++) {
+            assertEquals("Real eigen value differs from expected at " + idx,
+                expRealEigenValues[idx], real.get(idx), 0d);
+
+            assertEquals("Imag eigen value differs from expected at " + idx,
+                0d, imag.get(idx), 0d);
+        }
+
+    }
+
+    /** */
+    private void assertDiagonalConsistsOfEigenvalues(DenseLocalOnHeapMatrix m, Matrix d, Matrix v) {
+        int n = m.columnSize();
+        for (int i = 0; i < n; i++) {
+            Vector eigenVector = v.viewColumn(i);
+            double eigenVal = d.getX(i, i);
+            assertVectorsAreEqual(m.times(eigenVector), eigenVector.times(eigenVal));
+        }
+
+    }
+
+    /** */
+    private void assertMatricesAreEqual(Matrix exp, Matrix actual) {
+        assertTrue("The row sizes of matrices are not equal", exp.rowSize() == actual.rowSize());
+        assertTrue("The col sizes of matrices are not equal", exp.columnSize() == actual.columnSize());
+
+        // Since matrix is square, we need only one dimension
+        int n = exp.columnSize();
+
+        for (int i = 0; i < n; i++)
+            for (int j = 0; j < n; j++)
+                assertEquals("Values should be equal", exp.getX(i, j), actual.getX(i, j), EPSILON);
+    }
+
+    /** */
+    private void assertVectorsAreEqual(Vector exp, Vector actual) {
+        assertTrue("Vectors sizes are not equal", exp.size() == actual.size());
+
+        // Since matrix is square, we need only one dimension
+        int n = exp.size();
+
+        for (int i = 0; i < n; i++)
+            assertEquals("Values should be equal", exp.getX(i), actual.getX(i), EPSILON);
+    }
+
+    /** */
+    private void assertIsDiagonalNonZero(Matrix m) {
+        assertIsDiagonal(m, false);
+    }
+
+    /** */
+    private void assertIsDiagonal(Matrix m, boolean zeroesAllowed) {
+        // Since matrix is square, we need only one dimension
+        int n = m.columnSize();
+
+        assertEquals("Diagonal matrix is not square", n, m.rowSize());
+
+        for (int i = 0; i < n; i++)
+            for (int j = 0; j < n; j++)
+                assertTrue("Matrix is not diagonal, violation at (" + i + "," + j + ")",
+                    ((i == j) && (zeroesAllowed || m.getX(i, j) != 0))
+                        || ((i != j) && m.getX(i, j) == 0));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/LUDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/LUDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/LUDecompositionTest.java
new file mode 100644
index 0000000..fc76c39
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/LUDecompositionTest.java
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.SingularMatrixException;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link LUDecomposition}.
+ */
+public class LUDecompositionTest {
+    /** */
+    private Matrix testL;
+    /** */
+    private Matrix testU;
+    /** */
+    private Matrix testP;
+    /** */
+    private Matrix testMatrix;
+    /** */
+    private int[] rawPivot;
+
+    /** */
+    @Before
+    public void setUp() {
+        double[][] rawMatrix = new double[][] {
+            {2.0d, 1.0d, 1.0d, 0.0d},
+            {4.0d, 3.0d, 3.0d, 1.0d},
+            {8.0d, 7.0d, 9.0d, 5.0d},
+            {6.0d, 7.0d, 9.0d, 8.0d}};
+        double[][] rawL = {
+            {1.0d, 0.0d, 0.0d, 0.0d},
+            {3.0d / 4.0d, 1.0d, 0.0d, 0.0d},
+            {1.0d / 2.0d, -2.0d / 7.0d, 1.0d, 0.0d},
+            {1.0d / 4.0d, -3.0d / 7.0d, 1.0d / 3.0d, 1.0d}};
+        double[][] rawU = {
+            {8.0d, 7.0d, 9.0d, 5.0d},
+            {0.0d, 7.0d / 4.0d, 9.0d / 4.0d, 17.0d / 4.0d},
+            {0.0d, 0.0d, -6.0d / 7.0d, -2.0d / 7.0d},
+            {0.0d, 0.0d, 0.0d, 2.0d / 3.0d}};
+        double[][] rawP = new double[][] {
+            {0, 0, 1.0d, 0},
+            {0, 0, 0, 1.0d},
+            {0, 1.0d, 0, 0},
+            {1.0d, 0, 0, 0}};
+
+        rawPivot = new int[] {3, 4, 2, 1};
+
+        testMatrix = new DenseLocalOnHeapMatrix(rawMatrix);
+        testL = new DenseLocalOnHeapMatrix(rawL);
+        testU = new DenseLocalOnHeapMatrix(rawU);
+        testP = new DenseLocalOnHeapMatrix(rawP);
+    }
+
+    /** */
+    @Test
+    public void getL() throws Exception {
+        Matrix luDecompositionL = new LUDecomposition(testMatrix).getL();
+
+        assertEquals("Unexpected row size.", testL.rowSize(), luDecompositionL.rowSize());
+        assertEquals("Unexpected column size.", testL.columnSize(), luDecompositionL.columnSize());
+
+        for (int i = 0; i < testL.rowSize(); i++)
+            for (int j = 0; j < testL.columnSize(); j++)
+                assertEquals("Unexpected value at (" + i + "," + j + ").",
+                    testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d);
+
+        luDecompositionL.destroy();
+    }
+
+    /** */
+    @Test
+    public void getU() throws Exception {
+        Matrix luDecompositionU = new LUDecomposition(testMatrix).getU();
+
+        assertEquals("Unexpected row size.", testU.rowSize(), luDecompositionU.rowSize());
+        assertEquals("Unexpected column size.", testU.columnSize(), luDecompositionU.columnSize());
+
+        for (int i = 0; i < testU.rowSize(); i++)
+            for (int j = 0; j < testU.columnSize(); j++)
+                assertEquals("Unexpected value at (" + i + "," + j + ").",
+                    testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d);
+
+        luDecompositionU.destroy();
+    }
+
+    /** */
+    @Test
+    public void getP() throws Exception {
+        Matrix luDecompositionP = new LUDecomposition(testMatrix).getP();
+
+        assertEquals("Unexpected row size.", testP.rowSize(), luDecompositionP.rowSize());
+        assertEquals("Unexpected column size.", testP.columnSize(), luDecompositionP.columnSize());
+
+        for (int i = 0; i < testP.rowSize(); i++)
+            for (int j = 0; j < testP.columnSize(); j++)
+                assertEquals("Unexpected value at (" + i + "," + j + ").",
+                    testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d);
+
+        luDecompositionP.destroy();
+    }
+
+    /** */
+    @Test
+    public void getPivot() throws Exception {
+        Vector pivot = new LUDecomposition(testMatrix).getPivot();
+
+        assertEquals("Unexpected pivot size.", rawPivot.length, pivot.size());
+
+        for (int i = 0; i < testU.rowSize(); i++)
+            assertEquals("Unexpected value at " + i, rawPivot[i], (int)pivot.get(i) + 1);
+    }
+
+    /**
+     * Test for {@link DecompositionSupport} features.
+     */
+    @Test
+    public void decompositionSupportTest() {
+        LUDecomposition dec = new LUDecomposition(new PivotedMatrixView(testMatrix));
+        Matrix luDecompositionL = dec.getL();
+
+        assertEquals("Unexpected L row size.", testL.rowSize(), luDecompositionL.rowSize());
+        assertEquals("Unexpected L column size.", testL.columnSize(), luDecompositionL.columnSize());
+
+        for (int i = 0; i < testL.rowSize(); i++)
+            for (int j = 0; j < testL.columnSize(); j++)
+                assertEquals("Unexpected L value at (" + i + "," + j + ").",
+                    testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d);
+
+        Matrix luDecompositionU = dec.getU();
+
+        assertEquals("Unexpected U row size.", testU.rowSize(), luDecompositionU.rowSize());
+        assertEquals("Unexpected U column size.", testU.columnSize(), luDecompositionU.columnSize());
+
+        for (int i = 0; i < testU.rowSize(); i++)
+            for (int j = 0; j < testU.columnSize(); j++)
+                assertEquals("Unexpected U value at (" + i + "," + j + ").",
+                    testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d);
+
+        Matrix luDecompositionP = dec.getP();
+
+        assertEquals("Unexpected P row size.", testP.rowSize(), luDecompositionP.rowSize());
+        assertEquals("Unexpected P column size.", testP.columnSize(), luDecompositionP.columnSize());
+
+        for (int i = 0; i < testP.rowSize(); i++)
+            for (int j = 0; j < testP.columnSize(); j++)
+                assertEquals("Unexpected P value at (" + i + "," + j + ").",
+                    testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d);
+
+        dec.destroy();
+    }
+
+    /** */
+    @Test
+    public void singularDeterminant() throws Exception {
+        assertEquals("Unexpected determinant for singular matrix decomposition.",
+            0d, new LUDecomposition(new DenseLocalOnHeapMatrix(2, 2)).determinant(), 0d);
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void solveVecWrongSize() throws Exception {
+        new LUDecomposition(testMatrix).solve(new DenseLocalOnHeapVector(testMatrix.rowSize() + 1));
+    }
+
+    /** */
+    @Test(expected = SingularMatrixException.class)
+    public void solveVecSingularMatrix() throws Exception {
+        new LUDecomposition(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()))
+            .solve(new DenseLocalOnHeapVector(testMatrix.rowSize()));
+    }
+
+    /** */
+    @Test
+    public void solveVec() throws Exception {
+        Vector sol = new LUDecomposition(new PivotedMatrixView(testMatrix))
+            .solve(new DenseLocalOnHeapVector(testMatrix.rowSize()));
+
+        assertEquals("Wrong solution vector size.", testMatrix.rowSize(), sol.size());
+
+        for (int i = 0; i < sol.size(); i++)
+            assertEquals("Unexpected value at index " + i, 0d, sol.getX(i), 0.0000001d);
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void solveMtxWrongSize() throws Exception {
+        new LUDecomposition(testMatrix).solve(
+            new DenseLocalOnHeapMatrix(testMatrix.rowSize() + 1, testMatrix.rowSize()));
+    }
+
+    /** */
+    @Test(expected = SingularMatrixException.class)
+    public void solveMtxSingularMatrix() throws Exception {
+        new LUDecomposition(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()))
+            .solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()));
+    }
+
+    /** */
+    @Test
+    public void solveMtx() throws Exception {
+        Matrix sol = new LUDecomposition(new PivotedMatrixView(testMatrix))
+            .solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()));
+
+        assertEquals("Wrong solution matrix row size.", testMatrix.rowSize(), sol.rowSize());
+
+        assertEquals("Wrong solution matrix column size.", testMatrix.rowSize(), sol.columnSize());
+
+        for (int row = 0; row < sol.rowSize(); row++)
+            for (int col = 0; col < sol.columnSize(); col++)
+                assertEquals("Unexpected P value at (" + row + "," + col + ").",
+                    0d, sol.getX(row, col), 0.0000001d);
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullMatrixTest() {
+        new LUDecomposition(null);
+    }
+
+    /** */
+    @Test(expected = CardinalityException.class)
+    public void nonSquareMatrixTest() {
+        new LUDecomposition(new DenseLocalOnHeapMatrix(2, 3));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/QRDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/QRDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/QRDecompositionTest.java
new file mode 100644
index 0000000..589d5d1
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/QRDecompositionTest.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class QRDecompositionTest {
+    /** */
+    @Test
+    public void basicTest() {
+        basicTest(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        }));
+    }
+
+    /**
+     * Test for {@link DecompositionSupport} features.
+     */
+    @Test
+    public void decompositionSupportTest() {
+        basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        })));
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullMatrixTest() {
+        new QRDecomposition(null);
+    }
+
+    /** */
+    @Test(expected = IllegalArgumentException.class)
+    public void solveWrongMatrixSizeTest() {
+        new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        })).solve(new DenseLocalOnHeapMatrix(2, 3));
+    }
+
+    /** */
+    private void basicTest(Matrix m) {
+        QRDecomposition dec = new QRDecomposition(m);
+        assertTrue("Unexpected value for full rank in decomposition " + dec, dec.hasFullRank());
+
+        Matrix q = dec.getQ();
+        Matrix r = dec.getR();
+
+        assertNotNull("Matrix q is expected to be not null.", q);
+        assertNotNull("Matrix r is expected to be not null.", r);
+
+        Matrix qSafeCp = safeCopy(q);
+
+        Matrix expIdentity = qSafeCp.times(qSafeCp.transpose());
+
+        final double delta = 0.0001;
+
+        for (int row = 0; row < expIdentity.rowSize(); row++)
+            for (int col = 0; col < expIdentity.columnSize(); col++)
+                assertEquals("Unexpected identity matrix value at (" + row + "," + col + ").",
+                    row == col ? 1d : 0d, expIdentity.get(col, row), delta);
+
+        for (int row = 0; row < r.rowSize(); row++)
+            for (int col = 0; col < row - 1; col++)
+                assertEquals("Unexpected upper triangular matrix value at (" + row + "," + col + ").",
+                    0d, r.get(row, col), delta);
+
+        Matrix recomposed = qSafeCp.times(r);
+
+        for (int row = 0; row < m.rowSize(); row++)
+            for (int col = 0; col < m.columnSize(); col++)
+                assertEquals("Unexpected recomposed matrix value at (" + row + "," + col + ").",
+                    m.get(row, col), recomposed.get(row, col), delta);
+
+        Matrix sol = dec.solve(new DenseLocalOnHeapMatrix(3, 10));
+        assertEquals("Unexpected rows in solution matrix.", 3, sol.rowSize());
+        assertEquals("Unexpected cols in solution matrix.", 10, sol.columnSize());
+
+        for (int row = 0; row < sol.rowSize(); row++)
+            for (int col = 0; col < sol.columnSize(); col++)
+                assertEquals("Unexpected solution matrix value at (" + row + "," + col + ").",
+                    0d, sol.get(row, col), delta);
+
+        dec.destroy();
+
+        QRDecomposition dec1 = new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d},
+            {-1.0d, 2.0d},
+            {0.0d, -1.0d}
+        }));
+
+        assertTrue("Unexpected value for full rank in decomposition " + dec1, dec1.hasFullRank());
+
+        dec1.destroy();
+
+        QRDecomposition dec2 = new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d, 0.0d},
+            {0.0d, -1.0d, 2.0d, 0.0d}
+        }));
+
+        assertTrue("Unexpected value for full rank in decomposition " + dec2, dec2.hasFullRank());
+
+        dec2.destroy();
+    }
+
+    /** */
+    private Matrix safeCopy(Matrix orig) {
+        return new DenseLocalOnHeapMatrix(orig.rowSize(), orig.columnSize()).assign(orig);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/SingularValueDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/SingularValueDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/SingularValueDecompositionTest.java
new file mode 100644
index 0000000..f9843ae
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/decompositions/SingularValueDecompositionTest.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class SingularValueDecompositionTest {
+    /** */
+    @Test
+    public void basicTest() {
+        basicTest(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        }));
+    }
+
+    /**
+     * Test for {@link DecompositionSupport} features.
+     */
+    @Test
+    public void decompositionSupportTest() {
+        basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d},
+            {0.0d, -1.0d, 2.0d}
+        })));
+    }
+
+    /** */
+    @Test
+    public void rowsLessThanColumnsTest() {
+        DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
+            {2.0d, -1.0d, 0.0d},
+            {-1.0d, 2.0d, -1.0d}
+        });
+
+        SingularValueDecomposition dec = new SingularValueDecomposition(m);
+        assertEquals("Unexpected value for singular values size.",
+            2, dec.getSingularValues().length);
+
+        Matrix s = dec.getS();
+        Matrix u = dec.getU();
+        Matrix v = dec.getV();
+        Matrix covariance = dec.getCovariance(0.5);
+
+        assertNotNull("Matrix s is expected to be not null.", s);
+        assertNotNull("Matrix u is expected to be not null.", u);
+        assertNotNull("Matrix v is expected to be not null.", v);
+        assertNotNull("Covariance matrix is expected to be not null.", covariance);
+
+        dec.destroy();
+    }
+
+    /** */
+    @Test(expected = AssertionError.class)
+    public void nullMatrixTest() {
+        new SingularValueDecomposition(null);
+    }
+
+    /** */
+    private void basicTest(Matrix m) {
+        SingularValueDecomposition dec = new SingularValueDecomposition(m);
+        assertEquals("Unexpected value for singular values size.",
+            3, dec.getSingularValues().length);
+
+        Matrix s = dec.getS();
+        Matrix u = dec.getU();
+        Matrix v = dec.getV();
+        Matrix covariance = dec.getCovariance(0.5);
+
+        assertNotNull("Matrix s is expected to be not null.", s);
+        assertNotNull("Matrix u is expected to be not null.", u);
+        assertNotNull("Matrix v is expected to be not null.", v);
+        assertNotNull("Covariance matrix is expected to be not null.", covariance);
+
+        assertTrue("Decomposition cond is expected to be positive.", dec.cond() > 0);
+        assertTrue("Decomposition norm2 is expected to be positive.", dec.norm2() > 0);
+        assertEquals("Decomposition rank differs from expected.", 3, dec.rank());
+        assertEquals("Decomposition singular values size differs from expected.",
+            3, dec.getSingularValues().length);
+
+        Matrix recomposed = (u.times(s).times(v.transpose()));
+
+        for (int row = 0; row < m.rowSize(); row++)
+            for (int col = 0; col < m.columnSize(); col++)
+                assertEquals("Unexpected recomposed matrix value at (" + row + "," + col + ").",
+                    m.get(row, col), recomposed.get(row, col), 0.001);
+
+        for (int row = 0; row < covariance.rowSize(); row++)
+            for (int col = row + 1; col < covariance.columnSize(); col++)
+                assertEquals("Unexpected covariance matrix value at (" + row + "," + col + ").",
+                    covariance.get(row, col), covariance.get(col, row), 0.001);
+
+        dec.destroy();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/MathTestConstants.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/MathTestConstants.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/MathTestConstants.java
new file mode 100644
index 0000000..d26733e
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/MathTestConstants.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls;
+
+/**
+ * Collect constants for org.apache.ignite.math tests
+ */
+public interface MathTestConstants {
+    /** */
+    public double SECOND_ARG = 1d;
+
+    /**
+     * We assume that we will check calculation precision in other tests.
+     */
+    public double EXP_DELTA = 0.1d;
+
+    /** */
+    public String UNEXPECTED_VAL = "Unexpected value.";
+
+    /** */
+    public String NULL_GUID = "Null GUID.";
+
+    /** */
+    public String UNEXPECTED_GUID_VAL = "Unexpected GUID value.";
+
+    /** */
+    public String EMPTY_GUID = "Empty GUID.";
+
+    /** */
+    public String VALUES_SHOULD_BE_NOT_EQUALS = "Values should be not equals.";
+
+    /** */
+    public String NULL_VAL = "Null value.";
+
+    /** */
+    public String NULL_VALUES = "Null values.";
+
+    /** */
+    public String NOT_NULL_VAL = "Not null value.";
+
+    /** */
+    public double TEST_VAL = 1d;
+
+    /** */
+    public String VAL_NOT_EQUALS = "Values not equals.";
+
+    /** */
+    public String NO_NEXT_ELEMENT = "No next element.";
+
+    /** */
+    public int STORAGE_SIZE = 100;
+
+    /** */
+    public String WRONG_ATTRIBUTE_VAL = "Wrong attribute value.";
+
+    /** */
+    public String NULL_DATA_ELEMENT = "Null data element.";
+
+    /** */
+    public String WRONG_DATA_ELEMENT = "Wrong data element.";
+
+    /** */
+    public double NIL_DELTA = 0d;
+
+    /** */
+    public String NULL_DATA_STORAGE = "Null data storage.";
+
+    /** */
+    public String WRONG_DATA_SIZE = "Wrong data size.";
+
+    /** */
+    public String UNEXPECTED_DATA_VAL = "Unexpected data value.";
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrixTest.java
new file mode 100644
index 0000000..3d4d05e
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrixTest.java
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.IdentityValueMapper;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixKeyMapper;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Tests for {@link CacheMatrix}.
+ */
+@GridCommonTest(group = "Distributed Models")
+public class CacheMatrixTest extends GridCommonAbstractTest {
+    /** Number of nodes in grid */
+    private static final int NODE_COUNT = 3;
+    /** Cache name. */
+    private static final String CACHE_NAME = "test-cache";
+    /** */
+    private static final String UNEXPECTED_ATTRIBUTE_VALUE = "Unexpected attribute value.";
+    /** Grid instance. */
+    private Ignite ignite;
+    /** Matrix rows */
+    private final int rows = MathTestConstants.STORAGE_SIZE;
+    /** Matrix cols */
+    private final int cols = MathTestConstants.STORAGE_SIZE;
+
+    /**
+     * Default constructor.
+     */
+    public CacheMatrixTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        for (int i = 1; i <= NODE_COUNT; i++)
+            startGrid(i);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override protected void beforeTest() throws Exception {
+        ignite = grid(NODE_COUNT);
+
+        ignite.configuration().setPeerClassLoadingEnabled(true);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ignite.destroyCache(CACHE_NAME);
+    }
+
+    /** */
+    public void testGetSet() throws Exception {
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < cols; j++) {
+                double v = Math.random();
+                cacheMatrix.set(i, j, v);
+
+                assert Double.compare(v, cacheMatrix.get(i, j)) == 0;
+                assert Double.compare(v, cache.get(keyMapper.apply(i, j))) == 0;
+            }
+        }
+    }
+
+    /** */
+    public void testCopy() throws Exception {
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        fillMatrix(cacheMatrix);
+
+        try {
+            cacheMatrix.copy();
+
+            fail("UnsupportedOperationException expected");
+        }
+        catch (UnsupportedOperationException e) {
+            // No-op.
+        }
+    }
+
+    /** */
+    public void testLike() throws Exception {
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        try {
+            cacheMatrix.like(rows, cols);
+
+            fail("UnsupportedOperationException expected");
+        }
+        catch (UnsupportedOperationException e) {
+            // No-op.
+        }
+    }
+
+    /** */
+    public void testLikeVector() throws Exception {
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        try {
+            cacheMatrix.likeVector(cols);
+
+            fail("UnsupportedOperationException expected");
+        }
+        catch (UnsupportedOperationException e) {
+            // No-op.
+        }
+    }
+
+    /** */
+    public void testPlus() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        double plusVal = 2;
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        initMatrix(cacheMatrix);
+
+        cacheMatrix.plus(plusVal);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                assertEquals(plusVal, cacheMatrix.get(i, j));
+    }
+
+    /** */
+    public void testDivide() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        double initVal = 1;
+        double divVal = 2;
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        initMatrix(cacheMatrix);
+        cacheMatrix.assign(initVal);
+        cacheMatrix.divide(divVal);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                assertTrue(Double.compare(cacheMatrix.get(i, j), initVal / divVal) == 0);
+    }
+
+    /** */
+    public void testTimes() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        double initVal = 1;
+        double timVal = 2;
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        initMatrix(cacheMatrix);
+        cacheMatrix.assign(initVal);
+        cacheMatrix.times(timVal);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                assertTrue(Double.compare(cacheMatrix.get(i, j), initVal * timVal) == 0);
+    }
+
+    /** */
+    public void testSum() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        double initVal = 1;
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        double sum = 0;
+
+        initMatrix(cacheMatrix);
+        sum = cacheMatrix.sum();
+
+        assertTrue(Double.compare(sum, 0d) == 0);
+
+        cacheMatrix.assign(1d);
+        sum = cacheMatrix.sum();
+
+        assertTrue(Double.compare(sum, rows * cols) == 0);
+    }
+
+    /** */
+    public void testAssignSingleValue() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        double initVal = 1;
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        initMatrix(cacheMatrix);
+
+        cacheMatrix.assign(initVal);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                assertEquals(initVal, cacheMatrix.get(i, j));
+    }
+
+    /** */
+    public void testAssignArray() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        double[][] initVal = new double[rows][cols];
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                initVal[i][j] = Math.random();
+
+        cacheMatrix.assign(initVal);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                assertEquals(initVal[i][j], cacheMatrix.get(i, j));
+    }
+
+    /** */
+    public void testAttributes() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isSequentialAccess());
+        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isDense());
+        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isArrayBased());
+        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isRandomAccess());
+        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isDistributed());
+    }
+
+    /** */
+    public void testExternalization() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        ExternalizeTest<CacheMatrix<Integer, Double>> externalizeTest = new ExternalizeTest<CacheMatrix<Integer, Double>>() {
+
+            @Override public void externalizeTest() {
+                super.externalizeTest(cacheMatrix);
+            }
+        };
+
+        externalizeTest.externalizeTest();
+    }
+
+    /** */
+    public void testMinMax() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                cacheMatrix.set(i, j, i * rows + j);
+
+        assertEquals(0.0, cacheMatrix.minValue(), 0.0);
+        assertEquals(rows * cols - 1, cacheMatrix.maxValue(), 0.0);
+    }
+
+    /** */
+    public void testMap() {
+        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
+        IgniteCache<Integer, Double> cache = getCache();
+        final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
+
+        initMatrix(cacheMatrix);
+
+        cacheMatrix.map(value -> value + 10);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                assertEquals(10.0, cacheMatrix.getX(i, j), 0.0);
+    }
+
+    /** */
+    private IgniteCache<Integer, Double> getCache() {
+        assert ignite != null;
+
+        CacheConfiguration cfg = new CacheConfiguration();
+        cfg.setName(CACHE_NAME);
+
+        IgniteCache<Integer, Double> cache = ignite.getOrCreateCache(CACHE_NAME);
+
+        assert cache != null;
+        return cache;
+    }
+
+    /** */
+    private MatrixKeyMapper<Integer> getKeyMapper(final int rows, final int cols) {
+        return new MatrixKeyMapperForTests(rows, cols);
+    }
+
+    /** Init the given matrix by random values. */
+    private void fillMatrix(Matrix m) {
+        for (int i = 0; i < m.rowSize(); i++)
+            for (int j = 0; j < m.columnSize(); j++)
+                m.set(i, j, Math.random());
+    }
+
+    /** Init the given matrix by zeros. */
+    private void initMatrix(Matrix m) {
+        for (int i = 0; i < m.rowSize(); i++)
+            for (int j = 0; j < m.columnSize(); j++)
+                m.set(i, j, 0d);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java
new file mode 100644
index 0000000..88bf8d0
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class DenseLocalOffHeapMatrixConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(0, 1), "invalid row parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(1, 0), "invalid col parameter");
+
+        //noinspection ConstantConditions
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(null), "null matrix parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(new double[][] {null, new double[1]}),
+            "null row in matrix");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        assertEquals("Expected number of rows, int parameters.", 1,
+            new DenseLocalOffHeapMatrix(1, 2).rowSize());
+
+        assertEquals("Expected number of rows, double[][] parameter.", 1,
+            new DenseLocalOffHeapMatrix(new double[][] {new double[2]}).rowSize());
+
+        assertEquals("Expected number of cols, int parameters.", 1,
+            new DenseLocalOffHeapMatrix(2, 1).columnSize());
+
+        assertEquals("Expected number of cols, double[][] parameter.", 1,
+            new DenseLocalOffHeapMatrix(new double[][] {new double[1], new double[1]}).columnSize());
+
+        double[][] data1 = new double[][] {{1, 2}, {3, 4}}, data2 = new double[][] {{1, 2}, {3, 5}};
+
+        assertTrue("Matrices with same values are expected to be equal",
+            new DenseLocalOffHeapMatrix(data1).equals(new DenseLocalOffHeapMatrix(data1)));
+
+        assertFalse("Matrices with same values are expected to be equal",
+            new DenseLocalOffHeapMatrix(data1).equals(new DenseLocalOffHeapMatrix(data2)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java
new file mode 100644
index 0000000..1cf6464
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.util.function.Supplier;
+import org.apache.ignite.ml.math.Matrix;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/** */
+public class DenseLocalOnHeapMatrixConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(0, 1), "invalid row parameter");
+
+        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(1, 0), "invalid col parameter");
+
+        //noinspection ConstantConditions
+        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(null), "null matrix parameter");
+
+        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(new double[][] {null, new double[1]}),
+            "null row in matrix");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        assertEquals("Expected number of rows, int parameters.", 1,
+            new DenseLocalOnHeapMatrix(1, 2).rowSize());
+
+        assertEquals("Expected number of rows, double[][] parameter.", 1,
+            new DenseLocalOnHeapMatrix(new double[][] {new double[2]}).rowSize());
+
+        assertEquals("Expected number of cols, int parameters.", 1,
+            new DenseLocalOnHeapMatrix(2, 1).columnSize());
+
+        assertEquals("Expected number of cols, double[][] parameter.", 1,
+            new DenseLocalOnHeapMatrix(new double[][] {new double[1], new double[1]}).columnSize());
+    }
+
+    /** */
+    static void verifyAssertionError(Supplier<Matrix> ctor, String desc) {
+        try {
+            assertNotNull("Unexpected null matrix in " + desc, ctor.get());
+        }
+        catch (AssertionError ae) {
+            return;
+        }
+
+        fail("Expected error not caught in " + desc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrixTest.java
new file mode 100644
index 0000000..a00403f
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrixTest.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.ExternalizeTest;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.MathTestConstants;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@link DiagonalMatrix}.
+ */
+public class DiagonalMatrixTest extends ExternalizeTest<DiagonalMatrix> {
+    /** */
+    public static final String UNEXPECTED_VALUE = "Unexpected value";
+
+    /** */
+    private DiagonalMatrix testMatrix;
+
+    /** */
+    @Before
+    public void setup() {
+        DenseLocalOnHeapMatrix parent = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
+        fillMatrix(parent);
+        testMatrix = new DiagonalMatrix(parent);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void externalizeTest() {
+        externalizeTest(testMatrix);
+    }
+
+    /** */
+    @Test
+    public void testSetGetBasic() {
+        double testVal = 42;
+        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++) {
+            testMatrix.set(i, i, testVal);
+
+            assertEquals(UNEXPECTED_VALUE + " at (" + i + "," + i + ")", testMatrix.get(i, i), testVal, 0d);
+        }
+
+        //noinspection EqualsWithItself
+        assertTrue("Matrix is expected to be equal to self.", testMatrix.equals(testMatrix));
+        //noinspection ObjectEqualsNull
+        assertFalse("Matrix is expected to be not equal to null.", testMatrix.equals(null));
+    }
+
+    /** */
+    @Test
+    public void testSetGet() {
+        verifyDiagonal(testMatrix);
+
+        final int size = MathTestConstants.STORAGE_SIZE;
+
+        for (Matrix m : new Matrix[] {
+            new DenseLocalOnHeapMatrix(size + 1, size),
+            new DenseLocalOnHeapMatrix(size, size + 1)}) {
+            fillMatrix(m);
+
+            verifyDiagonal(new DiagonalMatrix(m));
+        }
+
+        final double[] data = new double[size];
+
+        for (int i = 0; i < size; i++)
+            data[i] = 1 + i;
+
+        final Matrix m = new DiagonalMatrix(new DenseLocalOnHeapVector(data));
+
+        assertEquals("Rows in matrix constructed from vector", size, m.rowSize());
+        assertEquals("Cols in matrix constructed from vector", size, m.columnSize());
+
+        for (int i = 0; i < size; i++)
+            assertEquals(UNEXPECTED_VALUE + " at vector index " + i, data[i], m.get(i, i), 0d);
+
+        verifyDiagonal(m);
+
+        final Matrix m1 = new DiagonalMatrix(data);
+
+        assertEquals("Rows in matrix constructed from array", size, m1.rowSize());
+        assertEquals("Cols in matrix constructed from array", size, m1.columnSize());
+
+        for (int i = 0; i < size; i++)
+            assertEquals(UNEXPECTED_VALUE + " at array index " + i, data[i], m1.get(i, i), 0d);
+
+        verifyDiagonal(m1);
+    }
+
+    /** */
+    @Test
+    public void testConstant() {
+        final int size = MathTestConstants.STORAGE_SIZE;
+
+        for (double val : new double[] {-1.0, 0.0, 1.0}) {
+            Matrix m = new DiagonalMatrix(size, val);
+
+            assertEquals("Rows in matrix", size, m.rowSize());
+            assertEquals("Cols in matrix", size, m.columnSize());
+
+            for (int i = 0; i < size; i++)
+                assertEquals(UNEXPECTED_VALUE + " at index " + i, val, m.get(i, i), 0d);
+
+            verifyDiagonal(m, true);
+        }
+    }
+
+    /** */
+    @Test
+    public void testAttributes() {
+        assertTrue(UNEXPECTED_VALUE, testMatrix.rowSize() == MathTestConstants.STORAGE_SIZE);
+        assertTrue(UNEXPECTED_VALUE, testMatrix.columnSize() == MathTestConstants.STORAGE_SIZE);
+
+        assertFalse(UNEXPECTED_VALUE, testMatrix.isArrayBased());
+        assertTrue(UNEXPECTED_VALUE, testMatrix.isDense());
+        assertFalse(UNEXPECTED_VALUE, testMatrix.isDistributed());
+
+        assertEquals(UNEXPECTED_VALUE, testMatrix.isRandomAccess(), !testMatrix.isSequentialAccess());
+        assertTrue(UNEXPECTED_VALUE, testMatrix.isRandomAccess());
+    }
+
+    /** */
+    @Test
+    public void testNullParams() {
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DiagonalMatrix((Matrix)null), "Null Matrix parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DiagonalMatrix((Vector)null), "Null Vector parameter");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DiagonalMatrix((double[])null), "Null double[] parameter");
+    }
+
+    /** */
+    private void verifyDiagonal(Matrix m, boolean readonly) {
+        final int rows = m.rowSize(), cols = m.columnSize();
+
+        final String sizeDetails = "rows" + "X" + "cols " + rows + "X" + cols;
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++) {
+                final String details = " at (" + i + "," + j + "), " + sizeDetails;
+
+                final boolean diagonal = i == j;
+
+                final double old = m.get(i, j);
+
+                if (!diagonal)
+                    assertEquals(UNEXPECTED_VALUE + details, 0, old, 0d);
+
+                final double exp = diagonal && !readonly ? old + 1 : old;
+
+                boolean expECaught = false;
+
+                try {
+                    m.set(i, j, exp);
+                }
+                catch (UnsupportedOperationException uoe) {
+                    if (diagonal && !readonly)
+                        throw uoe;
+
+                    expECaught = true;
+                }
+
+                if ((!diagonal || readonly) && !expECaught)
+                    fail("Expected exception was not caught " + details);
+
+                assertEquals(UNEXPECTED_VALUE + details, exp, m.get(i, j), 0d);
+            }
+    }
+
+    /** */
+    private void verifyDiagonal(Matrix m) {
+        verifyDiagonal(m, false);
+    }
+
+    /** */
+    private void fillMatrix(Matrix m) {
+        final int rows = m.rowSize(), cols = m.columnSize();
+
+        boolean negative = false;
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                m.set(i, j, (negative = !negative) ? -(i * cols + j + 1) : i * cols + j + 1);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrixConstructorTest.java
new file mode 100644
index 0000000..25de7d3
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrixConstructorTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** */
+public class FunctionMatrixConstructorTest {
+    /** */
+    @Test
+    public void invalidArgsTest() {
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(0, 1, (i, j) -> 0.0),
+            "Invalid row parameter.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 0, (i, j) -> 0.0),
+            "Invalid col parameter.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 1, null),
+            "Invalid func parameter.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(0, 1, (i, j) -> 0.0, null),
+            "Invalid row parameter, with setter func.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 0, (i, j) -> 0.0, null),
+            "Invalid col parameter, with setter func.");
+
+        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 1, null, null),
+            "Invalid func parameter, with setter func.");
+    }
+
+    /** */
+    @Test
+    public void basicTest() {
+        for (int rows : new int[] {1, 2, 3})
+            for (int cols : new int[] {1, 2, 3})
+                basicTest(rows, cols);
+
+        Matrix m = new FunctionMatrix(1, 1, (i, j) -> 1d);
+        //noinspection EqualsWithItself
+        assertTrue("Matrix is expected to be equal to self.", m.equals(m));
+        //noinspection ObjectEqualsNull
+        assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
+    }
+
+    /** */
+    private void basicTest(int rows, int cols) {
+        double[][] data = new double[rows][cols];
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++)
+                data[row][col] = row * cols + row;
+
+        Matrix mReadOnly = new FunctionMatrix(rows, cols, (i, j) -> data[i][j]);
+
+        assertEquals("Rows in matrix.", rows, mReadOnly.rowSize());
+        assertEquals("Cols in matrix.", cols, mReadOnly.columnSize());
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++) {
+                assertEquals("Unexpected value at " + row + "x" + col, data[row][col], mReadOnly.get(row, col), 0d);
+
+                boolean expECaught = false;
+
+                try {
+                    mReadOnly.set(row, col, 0.0);
+                }
+                catch (UnsupportedOperationException uoe) {
+                    expECaught = true;
+                }
+
+                assertTrue("Expected exception wasn't thrown at " + row + "x" + col, expECaught);
+            }
+
+        Matrix m = new FunctionMatrix(rows, cols, (i, j) -> data[i][j], (i, j, val) -> data[i][j] = val);
+
+        assertEquals("Rows in matrix, with setter function.", rows, m.rowSize());
+        assertEquals("Cols in matrix, with setter function.", cols, m.columnSize());
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++) {
+                assertEquals("Unexpected value at " + row + "x" + col, data[row][col], m.get(row, col), 0d);
+
+                m.set(row, col, -data[row][col]);
+            }
+
+        for (int row = 0; row < rows; row++)
+            for (int col = 0; col < cols; col++)
+                assertEquals("Unexpected value set at " + row + "x" + col, -(row * cols + row), m.get(row, col), 0d);
+
+        assertTrue("Incorrect copy for empty matrix.", m.copy().equals(m));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixAttributeTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixAttributeTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixAttributeTest.java
new file mode 100644
index 0000000..79cb13a
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixAttributeTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import org.apache.ignite.ml.math.Matrix;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Attribute tests for matrices.
+ *
+ * TODO: WIP
+ */
+public class MatrixAttributeTest {
+    /** */
+    private final List<MatrixAttributeTest.AttrCfg> attrCfgs = Arrays.asList(
+        new AttrCfg("isDense", Matrix::isDense,
+            DenseLocalOnHeapMatrix.class, DenseLocalOffHeapMatrix.class, RandomMatrix.class, DiagonalMatrix.class),
+        new AttrCfg("isArrayBased", Matrix::isArrayBased, DenseLocalOnHeapMatrix.class),
+        new AttrCfg("isDistributed", Matrix::isDistributed),
+        new AttrCfg("isRandomAccess", Matrix::isRandomAccess, DenseLocalOnHeapMatrix.class, DenseLocalOffHeapMatrix.class, RandomMatrix.class, DiagonalMatrix.class, SparseLocalOnHeapMatrix.class),
+        new AttrCfg("isSequentialAccess", Matrix::isSequentialAccess, DiagonalMatrix.class)
+    );
+
+    /** */
+    private final List<MatrixAttributeTest.Specification> specFixture = Arrays.asList(
+        new Specification(new DenseLocalOnHeapMatrix(1, 1)),
+        new Specification(new DenseLocalOffHeapMatrix(1, 1)),
+        new Specification(new RandomMatrix(1, 1)),
+        new Specification(new DiagonalMatrix(new double[] {1.0})),
+        new Specification(new FunctionMatrix(1, 1, (x, y) -> 1.0)),
+        new Specification(new SparseLocalOnHeapMatrix(1, 1))
+    );
+
+    /** */
+    @Test
+    public void isDenseTest() {
+        assertAttribute("isDense");
+    }
+
+    /** */
+    @Test
+    public void isArrayBasedTest() {
+        assertAttribute("isArrayBased");
+    }
+
+    /** */
+    @Test
+    public void isSequentialAccessTest() {
+        assertAttribute("isSequentialAccess");
+    }
+
+    /** */
+    @Test
+    public void isRandomAccessTest() {
+        assertAttribute("isRandomAccess");
+    }
+
+    /** */
+    @Test
+    public void isDistributedTest() {
+        assertAttribute("isDistributed");
+    }
+
+    /** */
+    private void assertAttribute(String name) {
+        final MatrixAttributeTest.AttrCfg attr = attrCfg(name);
+
+        for (MatrixAttributeTest.Specification spec : specFixture)
+            spec.verify(attr);
+    }
+
+    /** */
+    private MatrixAttributeTest.AttrCfg attrCfg(String name) {
+        for (MatrixAttributeTest.AttrCfg attr : attrCfgs)
+            if (attr.name.equals(name))
+                return attr;
+
+        throw new IllegalArgumentException("Undefined attribute " + name);
+    }
+
+    /** See http://en.wikipedia.org/wiki/Specification_pattern */
+    private static class Specification {
+        /** */
+        private final Matrix m;
+        /** */
+        private final Class<? extends Matrix> underlyingType;
+        /** */
+        private final List<String> attrsFromUnderlying;
+        /** */
+        final String desc;
+
+        /** */
+        Specification(Matrix m, Class<? extends Matrix> underlyingType, String... attrsFromUnderlying) {
+            this.m = m;
+            this.underlyingType = underlyingType;
+            this.attrsFromUnderlying = Arrays.asList(attrsFromUnderlying);
+            final Class<? extends Matrix> clazz = m.getClass();
+            desc = clazz.getSimpleName() + (clazz.equals(underlyingType)
+                ? "" : " (underlying type " + underlyingType.getSimpleName() + ")");
+        }
+
+        /** */
+        Specification(Matrix m) {
+            this(m, m.getClass());
+        }
+
+        /** */
+        void verify(MatrixAttributeTest.AttrCfg attr) {
+            final boolean obtained = attr.obtain.apply(m);
+
+            final Class<? extends Matrix> typeToCheck
+                = attrsFromUnderlying.contains(attr.name) ? underlyingType : m.getClass();
+
+            final boolean exp = attr.trueInTypes.contains(typeToCheck);
+
+            assertEquals("Unexpected " + attr.name + " value for " + desc, exp, obtained);
+        }
+    }
+
+    /** */
+    private static class AttrCfg {
+        /** */
+        final String name;
+        /** */
+        final Function<Matrix, Boolean> obtain;
+        /** */
+        final List<Class> trueInTypes;
+
+        /** */
+        AttrCfg(String name, Function<Matrix, Boolean> obtain, Class... trueInTypes) {
+            this.name = name;
+            this.obtain = obtain;
+            this.trueInTypes = Arrays.asList(trueInTypes);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationFixtures.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationFixtures.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationFixtures.java
new file mode 100644
index 0000000..52a0077
--- /dev/null
+++ b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/MatrixImplementationFixtures.java
@@ -0,0 +1,381 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.impls.storage.matrix.FunctionMatrixStorage;
+import org.jetbrains.annotations.NotNull;
+
+/** */
+class MatrixImplementationFixtures {
+    /** */
+    private static final List<Supplier<Iterable<Matrix>>> suppliers = Arrays.asList(
+        (Supplier<Iterable<Matrix>>)DenseLocalOnHeapMatrixFixture::new,
+        (Supplier<Iterable<Matrix>>)DenseLocalOffHeapMatrixFixture::new,
+        (Supplier<Iterable<Matrix>>)RandomMatrixFixture::new,
+        (Supplier<Iterable<Matrix>>)SparseLocalOnHeapMatrixFixture::new,
+        (Supplier<Iterable<Matrix>>)PivotedMatrixViewFixture::new,
+        (Supplier<Iterable<Matrix>>)MatrixViewFixture::new,
+        (Supplier<Iterable<Matrix>>)FunctionMatrixFixture::new,
+        (Supplier<Iterable<Matrix>>)DiagonalMatrixFixture::new,
+        (Supplier<Iterable<Matrix>>)TransposedMatrixViewFixture::new
+    );
+
+    /** */
+    void consumeSampleMatrix(BiConsumer<Matrix, String> consumer) {
+        for (Supplier<Iterable<Matrix>> fixtureSupplier : suppliers) {
+            final Iterable<Matrix> fixture = fixtureSupplier.get();
+
+            for (Matrix matrix : fixture) {
+                consumer.accept(matrix, fixture.toString());
+
+                matrix.destroy();
+            }
+        }
+    }
+
+    /** */
+    private static class DenseLocalOnHeapMatrixFixture extends MatrixSizeIterator {
+        /** */
+        DenseLocalOnHeapMatrixFixture() {
+            super(DenseLocalOnHeapMatrix::new, "DenseLocalOnHeapMatrix");
+        }
+    }
+
+    /** */
+    private static class DenseLocalOffHeapMatrixFixture extends MatrixSizeIterator {
+        /** */
+        DenseLocalOffHeapMatrixFixture() {
+            super(DenseLocalOffHeapMatrix::new, "DenseLocalOffHeapMatrix");
+        }
+    }
+
+    /** */
+    private static class RandomMatrixFixture extends MatrixSizeIterator {
+        /** */
+        RandomMatrixFixture() {
+            super(RandomMatrix::new, "RandomMatrix");
+        }
+    }
+
+    /** */
+    private static class SparseLocalOnHeapMatrixFixture extends MatrixSizeIterator {
+        /** */
+        SparseLocalOnHeapMatrixFixture() {
+            super(SparseLocalOnHeapMatrix::new, "SparseLocalOnHeapMatrix");
+        }
+    }
+
+    /** */
+    private static class PivotedMatrixViewFixture extends WrapperMatrixIterator {
+        /** */
+        PivotedMatrixViewFixture() {
+            super(PivotedMatrixView::new, "PivotedMatrixView over DenseLocalOnHeapMatrix");
+        }
+    }
+
+    /** */
+    private static class MatrixViewFixture extends WrapperMatrixIterator {
+        /** */
+        MatrixViewFixture() {
+            super((matrix) -> new MatrixView(matrix, 0, 0, matrix.rowSize(), matrix.columnSize()),
+                "MatrixView over DenseLocalOnHeapMatrix");
+        }
+    }
+
+    /** */
+    private static class FunctionMatrixFixture extends WrapperMatrixIterator {
+        /** */
+        FunctionMatrixFixture() {
+            super(FunctionMatrixForTest::new, "FunctionMatrix wrapping DenseLocalOnHeapMatrix");
+        }
+    }
+
+    /** */
+    private static class DiagonalMatrixFixture extends DiagonalIterator {
+        /** */
+        DiagonalMatrixFixture() {
+            super(DenseLocalOnHeapMatrix::new, "DiagonalMatrix over DenseLocalOnHeapMatrix");
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Matrix> iterator() {
+            return new Iterator<Matrix>() {
+                /** {@inheritDoc} */
+                @Override public boolean hasNext() {
+                    return hasNextSize(getSizeIdx());
+                }
+
+                /** {@inheritDoc} */
+                @Override public Matrix next() {
+                    assert getSize(getSizeIdx()) == 1 : "Only size 1 allowed for diagonal matrix fixture.";
+
+                    Matrix matrix = getConstructor().apply(getSize(getSizeIdx()), getSize(getSizeIdx()));
+
+                    nextIdx();
+
+                    return new DiagonalMatrix(matrix);
+                }
+            };
+        }
+    }
+
+    /** */
+    private static class TransposedMatrixViewFixture extends WrapperMatrixIterator {
+        /** */
+        TransposedMatrixViewFixture() {
+            super(TransposedMatrixView::new, "TransposedMatrixView over DenseLocalOnHeapMatrix");
+        }
+    }
+
+    /** */
+    private static abstract class DiagonalIterator implements Iterable<Matrix> {
+        /** */
+        private final Integer[] sizes = new Integer[] {1, null};
+        /** */
+        private int sizeIdx = 0;
+
+        /** */
+        private BiFunction<Integer, Integer, ? extends Matrix> constructor;
+        /** */
+        private String desc;
+
+        /** */
+        DiagonalIterator(BiFunction<Integer, Integer, ? extends Matrix> constructor, String desc) {
+            this.constructor = constructor;
+            this.desc = desc;
+        }
+
+        /** */
+        public BiFunction<Integer, Integer, ? extends Matrix> getConstructor() {
+            return constructor;
+        }
+
+        /** */
+        int getSizeIdx() {
+            return sizeIdx;
+        }
+
+        /** */
+        @Override public String toString() {
+            return desc + "{rows=" + sizes[sizeIdx] + ", cols=" + sizes[sizeIdx] + "}";
+        }
+
+        /** */
+        boolean hasNextSize(int idx) {
+            return sizes[idx] != null;
+        }
+
+        /** */
+        Integer getSize(int idx) {
+            return sizes[idx];
+        }
+
+        /** */
+        void nextIdx() {
+            sizeIdx++;
+        }
+    }
+
+    /** */
+    private static class WrapperMatrixIterator extends MatrixSizeIterator {
+        /** */
+        private final Function<Matrix, Matrix> wrapperCtor;
+
+        /** */
+        WrapperMatrixIterator(Function<Matrix, Matrix> wrapperCtor, String desc) {
+            super(DenseLocalOnHeapMatrix::new, desc);
+
+            this.wrapperCtor = wrapperCtor;
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Matrix> iterator() {
+            return new Iterator<Matrix>() {
+                /** {@inheritDoc} */
+                @Override public boolean hasNext() {
+                    return hasNextCol(getSizeIdx()) && hasNextRow(getSizeIdx());
+                }
+
+                /** {@inheritDoc} */
+                @Override public Matrix next() {
+                    Matrix matrix = getConstructor().apply(getRow(getSizeIdx()), getCol(getSizeIdx()));
+
+                    nextIdx();
+
+                    return wrapperCtor.apply(matrix);
+                }
+            };
+        }
+    }
+
+    /** */
+    private static class MatrixSizeIterator implements Iterable<Matrix> {
+        /** */
+        private final Integer[] rows = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 1024, null};
+        /** */
+        private final Integer[] cols = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1024, 512, null};
+        /** */
+        private int sizeIdx = 0;
+
+        /** */
+        private BiFunction<Integer, Integer, ? extends Matrix> constructor;
+        /** */
+        private String desc;
+
+        /** */
+        MatrixSizeIterator(BiFunction<Integer, Integer, ? extends Matrix> constructor, String desc) {
+            this.constructor = constructor;
+            this.desc = desc;
+        }
+
+        /** */
+        public BiFunction<Integer, Integer, ? extends Matrix> getConstructor() {
+            return constructor;
+        }
+
+        /** */
+        int getSizeIdx() {
+            return sizeIdx;
+        }
+
+        /** */
+        @Override public String toString() {
+            return desc + "{rows=" + rows[sizeIdx] + ", cols=" + cols[sizeIdx] + "}";
+        }
+
+        /** */
+        boolean hasNextRow(int idx) {
+            return rows[idx] != null;
+        }
+
+        /** */
+        boolean hasNextCol(int idx) {
+            return cols[idx] != null;
+        }
+
+        /** */
+        Integer getRow(int idx) {
+            return rows[idx];
+        }
+
+        /** */
+        int getCol(int idx) {
+            return cols[idx];
+        }
+
+        /** {@inheritDoc} */
+        @NotNull
+        @Override public Iterator<Matrix> iterator() {
+            return new Iterator<Matrix>() {
+                /** {@inheritDoc} */
+                @Override public boolean hasNext() {
+                    return hasNextCol(sizeIdx) && hasNextRow(sizeIdx);
+                }
+
+                /** {@inheritDoc} */
+                @Override public Matrix next() {
+                    Matrix matrix = constructor.apply(rows[sizeIdx], cols[sizeIdx]);
+
+                    nextIdx();
+
+                    return matrix;
+                }
+            };
+        }
+
+        /** */
+        void nextIdx() {
+            sizeIdx++;
+        }
+    }
+
+    /** Subclass tweaked for serialization */
+    private static class FunctionMatrixForTest extends FunctionMatrix {
+        /** */
+        Matrix underlying;
+
+        /** */
+        public FunctionMatrixForTest() {
+            // No-op.
+        }
+
+        /** */
+        FunctionMatrixForTest(Matrix underlying) {
+            super(underlying.rowSize(), underlying.columnSize(), underlying::get, underlying::set);
+
+            this.underlying = underlying;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Matrix copy() {
+            return new FunctionMatrixForTest(underlying);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            super.writeExternal(out);
+
+            out.writeObject(underlying);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            super.readExternal(in);
+
+            underlying = (Matrix)in.readObject();
+
+            setStorage(new FunctionMatrixStorage(underlying.rowSize(), underlying.columnSize(),
+                underlying::get, underlying::set));
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = 1;
+
+            res = res * 37 + underlying.hashCode();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            FunctionMatrixForTest that = (FunctionMatrixForTest)o;
+
+            return underlying != null ? underlying.equals(that.underlying) : that.underlying == null;
+        }
+    }
+}


[22/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/EigenDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/EigenDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/EigenDecomposition.java
deleted file mode 100644
index 66fe13c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/EigenDecomposition.java
+++ /dev/null
@@ -1,923 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.functions.Functions;
-
-/**
- * This class provides EigenDecomposition of given matrix. The class is based on
- * class with similar name from <a href="http://mahout.apache.org/">Apache Mahout</a> library.
- *
- * @see <a href=http://mathworld.wolfram.com/EigenDecomposition.html>MathWorld</a>
- */
-public class EigenDecomposition extends DecompositionSupport {
-    /** Row and column dimension (square matrix). */
-    private final int n;
-
-    /** Array for internal storage of eigen vectors. */
-    private final Matrix v;
-
-    /** Array for internal storage of eigenvalues. */
-    private final Vector d;
-    /** Array for internal storage of eigenvalues. */
-    private final Vector e;
-
-    /** */
-    public EigenDecomposition(Matrix matrix) {
-        this(matrix, isSymmetric(matrix));
-    }
-
-    /** */
-    public EigenDecomposition(Matrix matrix, boolean isSymmetric) {
-        n = matrix.columnSize();
-
-        d = likeVector(matrix);
-        e = likeVector(matrix);
-        v = like(matrix);
-
-        if (isSymmetric) {
-            v.assign(matrix);
-
-            // Tridiagonalize.
-            tred2();
-
-            // Diagonalize.
-            tql2();
-
-        }
-        else
-            // Reduce to Hessenberg form.
-            // Reduce Hessenberg to real Schur form.
-            hqr2(orthes(matrix));
-    }
-
-    /**
-     * Return the eigen vector matrix
-     *
-     * @return V
-     */
-    public Matrix getV() {
-        return like(v).assign(v);
-    }
-
-    /**
-     * Return the real parts of the eigenvalues
-     */
-    public Vector getRealEigenValues() {
-        return d;
-    }
-
-    /**
-     * Return the imaginary parts of the eigenvalues
-     */
-    public Vector getImagEigenvalues() {
-        return e;
-    }
-
-    /**
-     * Return the block diagonal eigenvalue matrix
-     *
-     * @return D
-     */
-    public Matrix getD() {
-        Matrix res = like(v, d.size(), d.size());
-        res.assign(0);
-        res.viewDiagonal().assign(d);
-        for (int i = 0; i < n; i++) {
-            double v = e.getX(i);
-            if (v > 0)
-                res.setX(i, i + 1, v);
-            else if (v < 0)
-                res.setX(i, i - 1, v);
-        }
-        return res;
-    }
-
-    /**
-     * Destroys decomposition components and other internal components of decomposition.
-     */
-    @Override public void destroy() {
-        e.destroy();
-        v.destroy();
-        d.destroy();
-    }
-
-    /** */
-    private void tred2() {
-        //  This is derived from the Algol procedures tred2 by
-        //  Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
-        //  Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
-        //  Fortran subroutine in EISPACK.
-
-        d.assign(v.viewColumn(n - 1));
-
-        // Householder reduction to tridiagonal form.
-
-        for (int i = n - 1; i > 0; i--) {
-
-            // Scale to avoid under/overflow.
-            double scale = d.viewPart(0, i).kNorm(1);
-            double h = 0.0;
-
-            if (scale == 0.0) {
-                e.setX(i, d.getX(i - 1));
-                for (int j = 0; j < i; j++) {
-                    d.setX(j, v.getX(i - 1, j));
-                    v.setX(i, j, 0.0);
-                    v.setX(j, i, 0.0);
-                }
-            }
-            else {
-
-                // Generate Householder vector.
-
-                for (int k = 0; k < i; k++) {
-                    d.setX(k, d.getX(k) / scale);
-                    h += d.getX(k) * d.getX(k);
-                }
-
-                double f = d.getX(i - 1);
-                double g = Math.sqrt(h);
-
-                if (f > 0)
-                    g = -g;
-
-                e.setX(i, scale * g);
-                h -= f * g;
-                d.setX(i - 1, f - g);
-
-                for (int j = 0; j < i; j++)
-                    e.setX(j, 0.0);
-
-                // Apply similarity transformation to remaining columns.
-
-                for (int j = 0; j < i; j++) {
-                    f = d.getX(j);
-                    v.setX(j, i, f);
-                    g = e.getX(j) + v.getX(j, j) * f;
-
-                    for (int k = j + 1; k <= i - 1; k++) {
-                        g += v.getX(k, j) * d.getX(k);
-                        e.setX(k, e.getX(k) + v.getX(k, j) * f);
-                    }
-
-                    e.setX(j, g);
-                }
-
-                f = 0.0;
-
-                for (int j = 0; j < i; j++) {
-                    e.setX(j, e.getX(j) / h);
-                    f += e.getX(j) * d.getX(j);
-                }
-
-                double hh = f / (h + h);
-
-                for (int j = 0; j < i; j++)
-                    e.setX(j, e.getX(j) - hh * d.getX(j));
-
-                for (int j = 0; j < i; j++) {
-                    f = d.getX(j);
-                    g = e.getX(j);
-
-                    for (int k = j; k <= i - 1; k++)
-                        v.setX(k, j, v.getX(k, j) - (f * e.getX(k) + g * d.getX(k)));
-
-                    d.setX(j, v.getX(i - 1, j));
-                    v.setX(i, j, 0.0);
-                }
-            }
-
-            d.setX(i, h);
-        }
-    }
-
-    /** */
-    private Matrix orthes(Matrix matrix) {
-        // Working storage for nonsymmetric algorithm.
-        Vector ort = likeVector(matrix);
-        Matrix hessenBerg = like(matrix).assign(matrix);
-
-        //  This is derived from the Algol procedures orthes and ortran,
-        //  by Martin and Wilkinson, Handbook for Auto. Comp.,
-        //  Vol.ii-Linear Algebra, and the corresponding
-        //  Fortran subroutines in EISPACK.
-
-        int low = 0;
-        int high = n - 1;
-
-        for (int m = low + 1; m <= high - 1; m++) {
-
-            // Scale column.
-
-            Vector hCol = hessenBerg.viewColumn(m - 1).viewPart(m, high - m + 1);
-            double scale = hCol.kNorm(1);
-
-            if (scale != 0.0) {
-                // Compute Householder transformation.
-                ort.viewPart(m, high - m + 1).map(hCol, Functions.plusMult(1 / scale));
-                double h = ort.viewPart(m, high - m + 1).getLengthSquared();
-
-                double g = Math.sqrt(h);
-
-                if (ort.getX(m) > 0)
-                    g = -g;
-
-                h -= ort.getX(m) * g;
-                ort.setX(m, ort.getX(m) - g);
-
-                // Apply Householder similarity transformation
-                // H = (I-u*u'/h)*H*(I-u*u')/h)
-
-                Vector ortPiece = ort.viewPart(m, high - m + 1);
-
-                for (int j = m; j < n; j++) {
-                    double f = ortPiece.dot(hessenBerg.viewColumn(j).viewPart(m, high - m + 1)) / h;
-                    hessenBerg.viewColumn(j).viewPart(m, high - m + 1).map(ortPiece, Functions.plusMult(-f));
-                }
-
-                for (int i = 0; i <= high; i++) {
-                    double f = ortPiece.dot(hessenBerg.viewRow(i).viewPart(m, high - m + 1)) / h;
-                    hessenBerg.viewRow(i).viewPart(m, high - m + 1).map(ortPiece, Functions.plusMult(-f));
-                }
-
-                ort.setX(m, scale * ort.getX(m));
-                hessenBerg.setX(m, m - 1, scale * g);
-            }
-        }
-
-        // Accumulate transformations (Algol's ortran).
-
-        v.assign(0);
-        v.viewDiagonal().assign(1);
-
-        for (int m = high - 1; m >= low + 1; m--) {
-            if (hessenBerg.getX(m, m - 1) != 0.0) {
-                ort.viewPart(m + 1, high - m).assign(hessenBerg.viewColumn(m - 1).viewPart(m + 1, high - m));
-
-                for (int j = m; j <= high; j++) {
-                    double g = ort.viewPart(m, high - m + 1).dot(v.viewColumn(j).viewPart(m, high - m + 1));
-
-                    // Double division avoids possible underflow
-                    g = g / ort.getX(m) / hessenBerg.getX(m, m - 1);
-                    v.viewColumn(j).viewPart(m, high - m + 1).map(ort.viewPart(m, high - m + 1), Functions.plusMult(g));
-                }
-            }
-        }
-
-        return hessenBerg;
-    }
-
-    /** Symmetric tridiagonal QL algorithm. */
-    private void tql2() {
-        //  This is derived from the Algol procedures tql2, by
-        //  Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
-        //  Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
-        //  Fortran subroutine in EISPACK.
-
-        e.viewPart(0, n - 1).assign(e.viewPart(1, n - 1));
-        e.setX(n - 1, 0.0);
-
-        double f = 0.0;
-        double tst1 = 0.0;
-        double eps = Math.pow(2.0, -52.0);
-
-        for (int l = 0; l < n; l++) {
-            // Find small subdiagonal element.
-
-            tst1 = Math.max(tst1, Math.abs(d.getX(l)) + Math.abs(e.getX(l)));
-            int m = l;
-
-            while (m < n) {
-                if (Math.abs(e.getX(m)) <= eps * tst1)
-                    break;
-
-                m++;
-            }
-
-            // If m == l, d.getX(l) is an eigenvalue,
-            // otherwise, iterate.
-
-            if (m > l) {
-                do {
-                    // Compute implicit shift
-
-                    double g = d.getX(l);
-                    double p = (d.getX(l + 1) - g) / (2.0 * e.getX(l));
-                    double r = Math.hypot(p, 1.0);
-
-                    if (p < 0)
-                        r = -r;
-
-                    d.setX(l, e.getX(l) / (p + r));
-                    d.setX(l + 1, e.getX(l) * (p + r));
-                    double dl1 = d.getX(l + 1);
-                    double h = g - d.getX(l);
-
-                    for (int i = l + 2; i < n; i++)
-                        d.setX(i, d.getX(i) - h);
-
-                    f += h;
-
-                    // Implicit QL transformation.
-
-                    p = d.getX(m);
-                    double c = 1.0;
-                    double c2 = c;
-                    double c3 = c;
-                    double el1 = e.getX(l + 1);
-                    double s = 0.0;
-                    double s2 = 0.0;
-
-                    for (int i = m - 1; i >= l; i--) {
-                        c3 = c2;
-                        c2 = c;
-                        s2 = s;
-                        g = c * e.getX(i);
-                        h = c * p;
-                        r = Math.hypot(p, e.getX(i));
-                        e.setX(i + 1, s * r);
-                        s = e.getX(i) / r;
-                        c = p / r;
-                        p = c * d.getX(i) - s * g;
-                        d.setX(i + 1, h + s * (c * g + s * d.getX(i)));
-
-                        // Accumulate transformation.
-
-                        for (int k = 0; k < n; k++) {
-                            h = v.getX(k, i + 1);
-                            v.setX(k, i + 1, s * v.getX(k, i) + c * h);
-                            v.setX(k, i, c * v.getX(k, i) - s * h);
-                        }
-                    }
-
-                    p = -s * s2 * c3 * el1 * e.getX(l) / dl1;
-                    e.setX(l, s * p);
-                    d.setX(l, c * p);
-
-                    // Check for convergence.
-
-                }
-                while (Math.abs(e.getX(l)) > eps * tst1);
-            }
-
-            d.setX(l, d.getX(l) + f);
-            e.setX(l, 0.0);
-        }
-
-        // Sort eigenvalues and corresponding vectors.
-
-        for (int i = 0; i < n - 1; i++) {
-            int k = i;
-            double p = d.getX(i);
-
-            for (int j = i + 1; j < n; j++)
-                if (d.getX(j) > p) {
-                    k = j;
-                    p = d.getX(j);
-                }
-
-            if (k != i) {
-                d.setX(k, d.getX(i));
-                d.setX(i, p);
-
-                for (int j = 0; j < n; j++) {
-                    p = v.getX(j, i);
-                    v.setX(j, i, v.getX(j, k));
-                    v.setX(j, k, p);
-                }
-            }
-        }
-    }
-
-    /** */
-    private void hqr2(Matrix h) {
-        //  This is derived from the Algol procedure hqr2,
-        //  by Martin and Wilkinson, Handbook for Auto. Comp.,
-        //  Vol.ii-Linear Algebra, and the corresponding
-        //  Fortran subroutine in EISPACK.
-
-        // Initialize
-
-        int nn = this.n;
-        int n = nn - 1;
-        int low = 0;
-        int high = nn - 1;
-        double eps = Math.pow(2.0, -52.0);
-        double exshift = 0.0;
-        double p = 0;
-        double q = 0;
-        double r = 0;
-        double s = 0;
-        double z = 0;
-        double w;
-        double x;
-        double y;
-
-        // Store roots isolated by balanc and compute matrix norm
-
-        double norm = h.foldMap(Functions.PLUS, Functions.ABS, 0.0);
-
-        // Outer loop over eigenvalue index
-
-        int iter = 0;
-        while (n >= low) {
-            // Look for single small sub-diagonal element
-            int l = n;
-
-            while (l > low) {
-                s = Math.abs(h.getX(l - 1, l - 1)) + Math.abs(h.getX(l, l));
-
-                if (s == 0.0)
-                    s = norm;
-
-                if (Math.abs(h.getX(l, l - 1)) < eps * s)
-                    break;
-
-                l--;
-            }
-
-            // Check for convergence
-
-            if (l == n) {
-                // One root found
-                h.setX(n, n, h.getX(n, n) + exshift);
-                d.setX(n, h.getX(n, n));
-                e.setX(n, 0.0);
-                n--;
-                iter = 0;
-            }
-            else if (l == n - 1) {
-                // Two roots found
-                w = h.getX(n, n - 1) * h.getX(n - 1, n);
-                p = (h.getX(n - 1, n - 1) - h.getX(n, n)) / 2.0;
-                q = p * p + w;
-                z = Math.sqrt(Math.abs(q));
-                h.setX(n, n, h.getX(n, n) + exshift);
-                h.setX(n - 1, n - 1, h.getX(n - 1, n - 1) + exshift);
-                x = h.getX(n, n);
-
-                // Real pair
-                if (q >= 0) {
-                    if (p >= 0)
-                        z = p + z;
-                    else
-                        z = p - z;
-
-                    d.setX(n - 1, x + z);
-                    d.setX(n, d.getX(n - 1));
-
-                    if (z != 0.0)
-                        d.setX(n, x - w / z);
-
-                    e.setX(n - 1, 0.0);
-                    e.setX(n, 0.0);
-                    x = h.getX(n, n - 1);
-                    s = Math.abs(x) + Math.abs(z);
-                    p = x / s;
-                    q = z / s;
-                    r = Math.sqrt(p * p + q * q);
-                    p /= r;
-                    q /= r;
-
-                    // Row modification
-
-                    for (int j = n - 1; j < nn; j++) {
-                        z = h.getX(n - 1, j);
-                        h.setX(n - 1, j, q * z + p * h.getX(n, j));
-                        h.setX(n, j, q * h.getX(n, j) - p * z);
-                    }
-
-                    // Column modification
-
-                    for (int i = 0; i <= n; i++) {
-                        z = h.getX(i, n - 1);
-                        h.setX(i, n - 1, q * z + p * h.getX(i, n));
-                        h.setX(i, n, q * h.getX(i, n) - p * z);
-                    }
-
-                    // Accumulate transformations
-
-                    for (int i = low; i <= high; i++) {
-                        z = v.getX(i, n - 1);
-                        v.setX(i, n - 1, q * z + p * v.getX(i, n));
-                        v.setX(i, n, q * v.getX(i, n) - p * z);
-                    }
-
-                    // Complex pair
-
-                }
-                else {
-                    d.setX(n - 1, x + p);
-                    d.setX(n, x + p);
-                    e.setX(n - 1, z);
-                    e.setX(n, -z);
-                }
-
-                n -= 2;
-                iter = 0;
-
-                // No convergence yet
-
-            }
-            else {
-                // Form shift
-                x = h.getX(n, n);
-                y = 0.0;
-                w = 0.0;
-
-                if (l < n) {
-                    y = h.getX(n - 1, n - 1);
-                    w = h.getX(n, n - 1) * h.getX(n - 1, n);
-                }
-
-                // Wilkinson's original ad hoc shift
-
-                if (iter == 10) {
-                    exshift += x;
-
-                    for (int i = low; i <= n; i++)
-                        h.setX(i, i, x);
-
-                    s = Math.abs(h.getX(n, n - 1)) + Math.abs(h.getX(n - 1, n - 2));
-                    x = y = 0.75 * s;
-                    w = -0.4375 * s * s;
-                }
-
-                // MATLAB's new ad hoc shift
-
-                if (iter == 30) {
-                    s = (y - x) / 2.0;
-                    s = s * s + w;
-
-                    if (s > 0) {
-                        s = Math.sqrt(s);
-
-                        if (y < x)
-                            s = -s;
-
-                        s = x - w / ((y - x) / 2.0 + s);
-
-                        for (int i = low; i <= n; i++)
-                            h.setX(i, i, h.getX(i, i) - s);
-
-                        exshift += s;
-                        x = y = w = 0.964;
-                    }
-                }
-
-                iter++;   // (Could check iteration count here.)
-
-                // Look for two consecutive small sub-diagonal elements
-
-                int m = n - 2;
-
-                while (m >= l) {
-                    z = h.getX(m, m);
-                    r = x - z;
-                    s = y - z;
-                    p = (r * s - w) / h.getX(m + 1, m) + h.getX(m, m + 1);
-                    q = h.getX(m + 1, m + 1) - z - r - s;
-                    r = h.getX(m + 2, m + 1);
-                    s = Math.abs(p) + Math.abs(q) + Math.abs(r);
-                    p /= s;
-                    q /= s;
-                    r /= s;
-
-                    if (m == l)
-                        break;
-
-                    double hmag = Math.abs(h.getX(m - 1, m - 1)) + Math.abs(h.getX(m + 1, m + 1));
-                    double threshold = eps * Math.abs(p) * (Math.abs(z) + hmag);
-
-                    if (Math.abs(h.getX(m, m - 1)) * (Math.abs(q) + Math.abs(r)) < threshold)
-                        break;
-
-                    m--;
-                }
-
-                for (int i = m + 2; i <= n; i++) {
-                    h.setX(i, i - 2, 0.0);
-
-                    if (i > m + 2)
-                        h.setX(i, i - 3, 0.0);
-                }
-
-                // Double QR step involving rows l:n and columns m:n
-
-                for (int k = m; k <= n - 1; k++) {
-                    boolean notlast = k != n - 1;
-
-                    if (k != m) {
-                        p = h.getX(k, k - 1);
-                        q = h.getX(k + 1, k - 1);
-                        r = notlast ? h.getX(k + 2, k - 1) : 0.0;
-                        x = Math.abs(p) + Math.abs(q) + Math.abs(r);
-                        if (x != 0.0) {
-                            p /= x;
-                            q /= x;
-                            r /= x;
-                        }
-                    }
-
-                    if (x == 0.0)
-                        break;
-
-                    s = Math.sqrt(p * p + q * q + r * r);
-
-                    if (p < 0)
-                        s = -s;
-
-                    if (s != 0) {
-                        if (k != m)
-                            h.setX(k, k - 1, -s * x);
-                        else if (l != m)
-                            h.setX(k, k - 1, -h.getX(k, k - 1));
-
-                        p += s;
-                        x = p / s;
-                        y = q / s;
-                        z = r / s;
-                        q /= p;
-                        r /= p;
-
-                        // Row modification
-
-                        for (int j = k; j < nn; j++) {
-                            p = h.getX(k, j) + q * h.getX(k + 1, j);
-
-                            if (notlast) {
-                                p += r * h.getX(k + 2, j);
-                                h.setX(k + 2, j, h.getX(k + 2, j) - p * z);
-                            }
-
-                            h.setX(k, j, h.getX(k, j) - p * x);
-                            h.setX(k + 1, j, h.getX(k + 1, j) - p * y);
-                        }
-
-                        // Column modification
-
-                        for (int i = 0; i <= Math.min(n, k + 3); i++) {
-                            p = x * h.getX(i, k) + y * h.getX(i, k + 1);
-
-                            if (notlast) {
-                                p += z * h.getX(i, k + 2);
-                                h.setX(i, k + 2, h.getX(i, k + 2) - p * r);
-                            }
-
-                            h.setX(i, k, h.getX(i, k) - p);
-                            h.setX(i, k + 1, h.getX(i, k + 1) - p * q);
-                        }
-
-                        // Accumulate transformations
-
-                        for (int i = low; i <= high; i++) {
-                            p = x * v.getX(i, k) + y * v.getX(i, k + 1);
-
-                            if (notlast) {
-                                p += z * v.getX(i, k + 2);
-                                v.setX(i, k + 2, v.getX(i, k + 2) - p * r);
-                            }
-
-                            v.setX(i, k, v.getX(i, k) - p);
-                            v.setX(i, k + 1, v.getX(i, k + 1) - p * q);
-                        }
-                    }  // (s != 0)
-                }  // k loop
-            }  // check convergence
-        }  // while (n >= low)
-
-        // Back substitute to find vectors of upper triangular form
-
-        if (norm == 0.0)
-            return;
-
-        for (n = nn - 1; n >= 0; n--) {
-            p = d.getX(n);
-            q = e.getX(n);
-
-            // Real vector
-
-            double t;
-
-            if (q == 0) {
-                int l = n;
-                h.setX(n, n, 1.0);
-
-                for (int i = n - 1; i >= 0; i--) {
-                    w = h.getX(i, i) - p;
-                    r = 0.0;
-
-                    for (int j = l; j <= n; j++)
-                        r += h.getX(i, j) * h.getX(j, n);
-
-                    if (e.getX(i) < 0.0) {
-                        z = w;
-                        s = r;
-                    }
-                    else {
-                        l = i;
-
-                        if (e.getX(i) == 0.0) {
-                            if (w == 0.0)
-                                h.setX(i, n, -r / (eps * norm));
-                            else
-                                h.setX(i, n, -r / w);
-
-                            // Solve real equations
-
-                        }
-                        else {
-                            x = h.getX(i, i + 1);
-                            y = h.getX(i + 1, i);
-                            q = (d.getX(i) - p) * (d.getX(i) - p) + e.getX(i) * e.getX(i);
-                            t = (x * s - z * r) / q;
-                            h.setX(i, n, t);
-
-                            if (Math.abs(x) > Math.abs(z))
-                                h.setX(i + 1, n, (-r - w * t) / x);
-                            else
-                                h.setX(i + 1, n, (-s - y * t) / z);
-                        }
-
-                        // Overflow control
-
-                        t = Math.abs(h.getX(i, n));
-
-                        if (eps * t * t > 1) {
-                            for (int j = i; j <= n; j++)
-                                h.setX(j, n, h.getX(j, n) / t);
-                        }
-                    }
-                }
-
-                // Complex vector
-
-            }
-            else if (q < 0) {
-                int l = n - 1;
-
-                // Last vector component imaginary so matrix is triangular
-
-                if (Math.abs(h.getX(n, n - 1)) > Math.abs(h.getX(n - 1, n))) {
-                    h.setX(n - 1, n - 1, q / h.getX(n, n - 1));
-                    h.setX(n - 1, n, -(h.getX(n, n) - p) / h.getX(n, n - 1));
-                }
-                else {
-                    cdiv(0.0, -h.getX(n - 1, n), h.getX(n - 1, n - 1) - p, q);
-                    h.setX(n - 1, n - 1, cdivr);
-                    h.setX(n - 1, n, cdivi);
-                }
-
-                h.setX(n, n - 1, 0.0);
-                h.setX(n, n, 1.0);
-
-                for (int i = n - 2; i >= 0; i--) {
-                    double ra = 0.0;
-                    double sa = 0.0;
-
-                    for (int j = l; j <= n; j++) {
-                        ra += h.getX(i, j) * h.getX(j, n - 1);
-                        sa += h.getX(i, j) * h.getX(j, n);
-                    }
-
-                    w = h.getX(i, i) - p;
-
-                    if (e.getX(i) < 0.0) {
-                        z = w;
-                        r = ra;
-                        s = sa;
-                    }
-                    else {
-                        l = i;
-
-                        if (e.getX(i) == 0) {
-                            cdiv(-ra, -sa, w, q);
-                            h.setX(i, n - 1, cdivr);
-                            h.setX(i, n, cdivi);
-                        }
-                        else {
-
-                            // Solve complex equations
-
-                            x = h.getX(i, i + 1);
-                            y = h.getX(i + 1, i);
-
-                            double vr = (d.getX(i) - p) * (d.getX(i) - p) + e.getX(i) * e.getX(i) - q * q;
-                            double vi = (d.getX(i) - p) * 2.0 * q;
-
-                            if (vr == 0.0 && vi == 0.0) {
-                                double hmag = Math.abs(x) + Math.abs(y);
-                                vr = eps * norm * (Math.abs(w) + Math.abs(q) + hmag + Math.abs(z));
-                            }
-
-                            cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi);
-
-                            h.setX(i, n - 1, cdivr);
-                            h.setX(i, n, cdivi);
-
-                            if (Math.abs(x) > (Math.abs(z) + Math.abs(q))) {
-                                h.setX(i + 1, n - 1, (-ra - w * h.getX(i, n - 1) + q * h.getX(i, n)) / x);
-                                h.setX(i + 1, n, (-sa - w * h.getX(i, n) - q * h.getX(i, n - 1)) / x);
-                            }
-                            else {
-                                cdiv(-r - y * h.getX(i, n - 1), -s - y * h.getX(i, n), z, q);
-
-                                h.setX(i + 1, n - 1, cdivr);
-                                h.setX(i + 1, n, cdivi);
-                            }
-                        }
-
-                        // Overflow control
-
-                        t = Math.max(Math.abs(h.getX(i, n - 1)), Math.abs(h.getX(i, n)));
-
-                        if (eps * t * t > 1)
-                            for (int j = i; j <= n; j++) {
-                                h.setX(j, n - 1, h.getX(j, n - 1) / t);
-                                h.setX(j, n, h.getX(j, n) / t);
-                            }
-                    }
-                }
-            }
-        }
-
-        // Vectors of isolated roots
-
-        for (int i = 0; i < nn; i++)
-            if (i < low || i > high) {
-                for (int j = i; j < nn; j++)
-                    v.setX(i, j, h.getX(i, j));
-            }
-
-        // Back transformation to get eigen vectors of original matrix
-
-        for (int j = nn - 1; j >= low; j--)
-            for (int i = low; i <= high; i++) {
-                z = 0.0;
-
-                for (int k = low; k <= Math.min(j, high); k++)
-                    z += v.getX(i, k) * h.getX(k, j);
-
-                v.setX(i, j, z);
-            }
-    }
-
-    /** */
-    private static boolean isSymmetric(Matrix matrix) {
-        int cols = matrix.columnSize();
-        int rows = matrix.rowSize();
-
-        if (cols != rows)
-            return false;
-
-        for (int i = 0; i < cols; i++)
-            for (int j = 0; j < rows; j++) {
-                if (matrix.getX(i, j) != matrix.get(j, i))
-                    return false;
-            }
-
-        return true;
-    }
-
-    /** Complex scalar division - real part. */
-    private double cdivr;
-    /** Complex scalar division - imaginary part. */
-    private double cdivi;
-
-    /** */
-    private void cdiv(double xr, double xi, double yr, double yi) {
-        double r;
-        double d;
-
-        if (Math.abs(yr) > Math.abs(yi)) {
-            r = yi / yr;
-            d = yr + r * yi;
-            cdivr = (xr + r * xi) / d;
-            cdivi = (xi - r * xr) / d;
-        }
-        else {
-            r = yr / yi;
-            d = yi + r * yr;
-            cdivr = (r * xr + xi) / d;
-            cdivi = (r * xi - xr) / d;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/LUDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/LUDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/LUDecomposition.java
deleted file mode 100644
index 82c90ec..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/LUDecomposition.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.SingularMatrixException;
-
-/**
- * Calculates the LU-decomposition of a square matrix.
- *
- * This class inspired by class from Apache Common Math with similar name.
- *
- * @see <a href="http://mathworld.wolfram.com/LUDecomposition.html">MathWorld</a>
- * @see <a href="http://en.wikipedia.org/wiki/LU_decomposition">Wikipedia</a>
- */
-public class LUDecomposition extends DecompositionSupport {
-    /** Default bound to determine effective singularity in LU decomposition. */
-    private static final double DEFAULT_TOO_SMALL = 1e-11;
-
-    /** Pivot permutation associated with LU decomposition. */
-    private final Vector pivot;
-    /** Parity of the permutation associated with the LU decomposition. */
-    private boolean even;
-    /** Singularity indicator. */
-    private boolean singular;
-    /** Cached value of L. */
-    private Matrix cachedL;
-    /** Cached value of U. */
-    private Matrix cachedU;
-    /** Cached value of P. */
-    private Matrix cachedP;
-    /** Original matrix. */
-    private Matrix matrix;
-    /** Entries of LU decomposition. */
-    private Matrix lu;
-
-    /**
-     * Calculates the LU-decomposition of the given matrix.
-     * This constructor uses 1e-11 as default value for the singularity
-     * threshold.
-     *
-     * @param matrix Matrix to decompose.
-     * @throws CardinalityException if matrix is not square.
-     */
-    public LUDecomposition(Matrix matrix) {
-        this(matrix, DEFAULT_TOO_SMALL);
-    }
-
-    /**
-     * Calculates the LUP-decomposition of the given matrix.
-     *
-     * @param matrix Matrix to decompose.
-     * @param singularityThreshold threshold (based on partial row norm).
-     * @throws CardinalityException if matrix is not square.
-     */
-    public LUDecomposition(Matrix matrix, double singularityThreshold) {
-        assert matrix != null;
-
-        int rows = matrix.rowSize();
-        int cols = matrix.columnSize();
-
-        if (rows != cols)
-            throw new CardinalityException(rows, cols);
-
-        this.matrix = matrix;
-
-        lu = copy(matrix);
-
-        pivot = likeVector(matrix);
-
-        for (int i = 0; i < pivot.size(); i++)
-            pivot.setX(i, i);
-
-        even = true;
-        singular = false;
-
-        cachedL = null;
-        cachedU = null;
-        cachedP = null;
-
-        for (int col = 0; col < cols; col++) {
-
-            //upper
-            for (int row = 0; row < col; row++) {
-                Vector luRow = lu.viewRow(row);
-                double sum = luRow.get(col);
-
-                for (int i = 0; i < row; i++)
-                    sum -= luRow.getX(i) * lu.getX(i, col);
-
-                luRow.setX(col, sum);
-            }
-
-            // permutation row
-            int max = col;
-
-            double largest = Double.NEGATIVE_INFINITY;
-
-            // lower
-            for (int row = col; row < rows; row++) {
-                Vector luRow = lu.viewRow(row);
-                double sum = luRow.getX(col);
-
-                for (int i = 0; i < col; i++)
-                    sum -= luRow.getX(i) * lu.getX(i, col);
-
-                luRow.setX(col, sum);
-
-                if (Math.abs(sum) > largest) {
-                    largest = Math.abs(sum);
-                    max = row;
-                }
-            }
-
-            // Singularity check
-            if (Math.abs(lu.getX(max, col)) < singularityThreshold) {
-                singular = true;
-                return;
-            }
-
-            // Pivot if necessary
-            if (max != col) {
-                double tmp;
-                Vector luMax = lu.viewRow(max);
-                Vector luCol = lu.viewRow(col);
-
-                for (int i = 0; i < cols; i++) {
-                    tmp = luMax.getX(i);
-                    luMax.setX(i, luCol.getX(i));
-                    luCol.setX(i, tmp);
-                }
-
-                int temp = (int)pivot.getX(max);
-                pivot.setX(max, pivot.getX(col));
-                pivot.setX(col, temp);
-
-                even = !even;
-            }
-
-            // Divide the lower elements by the "winning" diagonal elt.
-            final double luDiag = lu.getX(col, col);
-
-            for (int row = col + 1; row < cols; row++) {
-                double val = lu.getX(row, col) / luDiag;
-                lu.setX(row, col, val);
-            }
-        }
-    }
-
-    /**
-     * Destroys decomposition components and other internal components of decomposition.
-     */
-    @Override public void destroy() {
-        if (cachedL != null)
-            cachedL.destroy();
-        if (cachedU != null)
-            cachedU.destroy();
-        if (cachedP != null)
-            cachedP.destroy();
-        lu.destroy();
-    }
-
-    /**
-     * Returns the matrix L of the decomposition.
-     * <p>L is a lower-triangular matrix</p>
-     *
-     * @return the L matrix (or null if decomposed matrix is singular).
-     */
-    public Matrix getL() {
-        if ((cachedL == null) && !singular) {
-            final int m = pivot.size();
-
-            cachedL = like(matrix);
-            cachedL.assign(0.0);
-
-            for (int i = 0; i < m; ++i) {
-                for (int j = 0; j < i; ++j)
-                    cachedL.setX(i, j, lu.getX(i, j));
-
-                cachedL.setX(i, i, 1.0);
-            }
-        }
-
-        return cachedL;
-    }
-
-    /**
-     * Returns the matrix U of the decomposition.
-     * <p>U is an upper-triangular matrix</p>
-     *
-     * @return the U matrix (or null if decomposed matrix is singular).
-     */
-    public Matrix getU() {
-        if ((cachedU == null) && !singular) {
-            final int m = pivot.size();
-
-            cachedU = like(matrix);
-            cachedU.assign(0.0);
-
-            for (int i = 0; i < m; ++i)
-                for (int j = i; j < m; ++j)
-                    cachedU.setX(i, j, lu.getX(i, j));
-        }
-
-        return cachedU;
-    }
-
-    /**
-     * Returns the P rows permutation matrix.
-     * <p>P is a sparse matrix with exactly one element set to 1.0 in
-     * each row and each column, all other elements being set to 0.0.</p>
-     * <p>The positions of the 1 elements are given by the {@link #getPivot()
-     * pivot permutation vector}.</p>
-     *
-     * @return the P rows permutation matrix (or null if decomposed matrix is singular).
-     * @see #getPivot()
-     */
-    public Matrix getP() {
-        if ((cachedP == null) && !singular) {
-            final int m = pivot.size();
-
-            cachedP = like(matrix);
-            cachedP.assign(0.0);
-
-            for (int i = 0; i < m; ++i)
-                cachedP.setX(i, (int)pivot.get(i), 1.0);
-        }
-
-        return cachedP;
-    }
-
-    /**
-     * Returns the pivot permutation vector.
-     *
-     * @return the pivot permutation vector.
-     * @see #getP()
-     */
-    public Vector getPivot() {
-        return pivot.copy();
-    }
-
-    /**
-     * Return the determinant of the matrix.
-     *
-     * @return determinant of the matrix.
-     */
-    public double determinant() {
-        if (singular)
-            return 0;
-
-        final int m = pivot.size();
-        double determinant = even ? 1 : -1;
-
-        for (int i = 0; i < m; i++)
-            determinant *= lu.getX(i, i);
-
-        return determinant;
-    }
-
-    /** */
-    public Vector solve(Vector b) {
-        final int m = pivot.size();
-
-        if (b.size() != m)
-            throw new CardinalityException(b.size(), m);
-
-        if (singular)
-            throw new SingularMatrixException();
-
-        final double[] bp = new double[m];
-
-        // Apply permutations to b
-        for (int row = 0; row < m; row++)
-            bp[row] = b.get((int)pivot.get(row));
-
-        // Solve LY = b
-        for (int col = 0; col < m; col++) {
-            final double bpCol = bp[col];
-
-            for (int i = col + 1; i < m; i++)
-                bp[i] -= bpCol * lu.get(i, col);
-        }
-
-        // Solve UX = Y
-        for (int col = m - 1; col >= 0; col--) {
-            bp[col] /= lu.get(col, col);
-            final double bpCol = bp[col];
-
-            for (int i = 0; i < col; i++)
-                bp[i] -= bpCol * lu.get(i, col);
-        }
-
-        return b.like(m).assign(bp);
-    }
-
-    /** */
-    public Matrix solve(Matrix b) {
-        final int m = pivot.size();
-
-        if (b.rowSize() != m)
-            throw new CardinalityException(b.rowSize(), m);
-
-        if (singular)
-            throw new SingularMatrixException();
-
-        final int nColB = b.columnSize();
-
-        // Apply permutations to b
-        final double[][] bp = new double[m][nColB];
-        for (int row = 0; row < m; row++) {
-            final double[] bpRow = bp[row];
-            final int pRow = (int)pivot.get(row);
-
-            for (int col = 0; col < nColB; col++)
-                bpRow[col] = b.get(pRow, col);
-        }
-
-        // Solve LY = b
-        for (int col = 0; col < m; col++) {
-            final double[] bpCol = bp[col];
-            for (int i = col + 1; i < m; i++) {
-                final double[] bpI = bp[i];
-                final double luICol = lu.get(i, col);
-
-                for (int j = 0; j < nColB; j++)
-                    bpI[j] -= bpCol[j] * luICol;
-            }
-        }
-
-        // Solve UX = Y
-        for (int col = m - 1; col >= 0; col--) {
-            final double[] bpCol = bp[col];
-            final double luDiag = lu.getX(col, col);
-
-            for (int j = 0; j < nColB; j++)
-                bpCol[j] /= luDiag;
-
-            for (int i = 0; i < col; i++) {
-                final double[] bpI = bp[i];
-                final double luICol = lu.get(i, col);
-
-                for (int j = 0; j < nColB; j++)
-                    bpI[j] -= bpCol[j] * luICol;
-            }
-        }
-
-        return b.like(b.rowSize(), b.columnSize()).assign(bp);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/QRDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/QRDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/QRDecomposition.java
deleted file mode 100644
index 9608ed5..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/QRDecomposition.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.functions.Functions;
-
-/**
- * For an {@code m x n} matrix {@code A} with {@code m >= n}, the QR decomposition
- * is an {@code m x n} orthogonal matrix {@code Q} and an {@code n x n} upper
- * triangular matrix {@code R} so that {@code A = Q*R}.
- */
-public class QRDecomposition extends DecompositionSupport {
-    /** */
-    private final Matrix q;
-    /** */
-    private final Matrix r;
-
-    /** */
-    private final Matrix mType;
-    /** */
-    private final boolean fullRank;
-
-    /** */
-    private final int rows;
-    /** */
-    private final int cols;
-
-    /**
-     * @param v Value to be checked for being an ordinary double.
-     */
-    private void checkDouble(double v) {
-        if (Double.isInfinite(v) || Double.isNaN(v))
-            throw new ArithmeticException("Invalid intermediate result");
-    }
-
-    /**
-     * Constructs a new QR decomposition object computed by Householder reflections.
-     *
-     * @param mtx A rectangular matrix.
-     */
-    public QRDecomposition(Matrix mtx) {
-        assert mtx != null;
-
-        rows = mtx.rowSize();
-
-        int min = Math.min(mtx.rowSize(), mtx.columnSize());
-
-        cols = mtx.columnSize();
-
-        mType = like(mtx, 1, 1);
-
-        Matrix qTmp = copy(mtx);
-
-        boolean fullRank = true;
-
-        r = like(mtx, min, cols);
-
-        for (int i = 0; i < min; i++) {
-            Vector qi = qTmp.viewColumn(i);
-
-            double alpha = qi.kNorm(2);
-
-            if (Math.abs(alpha) > Double.MIN_VALUE)
-                qi.map(Functions.div(alpha));
-            else {
-                checkDouble(alpha);
-
-                fullRank = false;
-            }
-
-            r.set(i, i, alpha);
-
-            for (int j = i + 1; j < cols; j++) {
-                Vector qj = qTmp.viewColumn(j);
-
-                double norm = qj.kNorm(2);
-
-                if (Math.abs(norm) > Double.MIN_VALUE) {
-                    double beta = qi.dot(qj);
-
-                    r.set(i, j, beta);
-
-                    if (j < min)
-                        qj.map(qi, Functions.plusMult(-beta));
-                }
-                else
-                    checkDouble(norm);
-            }
-        }
-
-        if (cols > min)
-            q = qTmp.viewPart(0, rows, 0, min).copy();
-        else
-            q = qTmp;
-
-        this.fullRank = fullRank;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        q.destroy();
-        r.destroy();
-        mType.destroy();
-    }
-
-    /**
-     * Gets orthogonal factor {@code Q}.
-     */
-    public Matrix getQ() {
-        return q;
-    }
-
-    /**
-     * Gets triangular factor {@code R}.
-     */
-    public Matrix getR() {
-        return r;
-    }
-
-    /**
-     * Returns whether the matrix {@code A} has full rank.
-     *
-     * @return true if {@code R}, and hence {@code A} , has full rank.
-     */
-    public boolean hasFullRank() {
-        return fullRank;
-    }
-
-    /**
-     * Least squares solution of {@code A*X = B}; {@code returns X}.
-     *
-     * @param mtx A matrix with as many rows as {@code A} and any number of cols.
-     * @return {@code X<} that minimizes the two norm of {@code Q*R*X - B}.
-     * @throws IllegalArgumentException if {@code B.rows() != A.rows()}.
-     */
-    public Matrix solve(Matrix mtx) {
-        if (mtx.rowSize() != rows)
-            throw new IllegalArgumentException("Matrix row dimensions must agree.");
-
-        int cols = mtx.columnSize();
-
-        Matrix x = like(mType, this.cols, cols);
-
-        Matrix qt = getQ().transpose();
-        Matrix y = qt.times(mtx);
-
-        Matrix r = getR();
-
-        for (int k = Math.min(this.cols, rows) - 1; k > 0; k--) {
-            // X[k,] = Y[k,] / R[k,k], note that X[k,] starts with 0 so += is same as =
-            x.viewRow(k).map(y.viewRow(k), Functions.plusMult(1 / r.get(k, k)));
-
-            // Y[0:(k-1),] -= R[0:(k-1),k] * X[k,]
-            Vector rCol = r.viewColumn(k).viewPart(0, k);
-
-            for (int c = 0; c < cols; c++)
-                y.viewColumn(c).viewPart(0, k).map(rCol, Functions.plusMult(-x.get(k, c)));
-        }
-
-        return x;
-    }
-
-    /**
-     * Returns a rough string rendition of a QR.
-     */
-    @Override public String toString() {
-        return String.format("QR(%d x %d, fullRank=%s)", rows, cols, hasFullRank());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/SingularValueDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/SingularValueDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/SingularValueDecomposition.java
deleted file mode 100644
index 75eb206..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/SingularValueDecomposition.java
+++ /dev/null
@@ -1,620 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Algebra;
-import org.apache.ignite.math.Matrix;
-
-/**
- * Compute a singular value decomposition (SVD) of {@code (l x k)} matrix {@code m}.
- * <p>This decomposition can be thought
- * as an extension of {@link EigenDecomposition} to rectangular matrices. The factorization we get is following:</p>
- * <p>{@code m = u * s * v^{*}}, where</p>
- * <ul><li>{@code u} is a real or complex unitary matrix.</li>
- * <li>{@code s} is a rectangular diagonal matrix with non-negative real numbers on diagonal
- * (these numbers are singular values of {@code m}).</li>
- * <li>{@code v} is a real or complex unitary matrix.</li></ul>
- * <p>If {@code m} is real then {@code u} and {@code v} are also real.</p>
- * <p>See also: <a href="https://en.wikipedia.org/wiki/Singular_value_decomposition">Wikipedia article on SVD</a>.</p>
- * <p>Note: complex case is currently not supported.</p>
- */
-public class SingularValueDecomposition extends DecompositionSupport {
-    // U and V.
-    /** */
-    private final double[][] u;
-    /** */
-    private final double[][] v;
-
-    /** Singular values. */
-    private final double[] s;
-
-    /** Row dimension. */
-    private final int m;
-    /** Column dimension. */
-    private final int n;
-
-    /** */
-    private Matrix arg;
-
-    /** */
-    private boolean transpositionNeeded;
-
-    /**
-     * Singular value decomposition object.
-     *
-     * @param arg A rectangular matrix.
-     */
-    public SingularValueDecomposition(Matrix arg) {
-        assert arg != null;
-
-        this.arg = arg;
-
-        if (arg.rowSize() < arg.columnSize())
-            transpositionNeeded = true;
-
-        double[][] a;
-
-        if (transpositionNeeded) {
-            // Use the transpose matrix.
-            m = arg.columnSize();
-            n = arg.rowSize();
-
-            a = new double[m][n];
-
-            for (int i = 0; i < m; i++)
-                for (int j = 0; j < n; j++)
-                    a[i][j] = arg.get(j, i);
-        }
-        else {
-            m = arg.rowSize();
-            n = arg.columnSize();
-
-            a = new double[m][n];
-
-            for (int i = 0; i < m; i++)
-                for (int j = 0; j < n; j++)
-                    a[i][j] = arg.get(i, j);
-        }
-
-        int nu = Math.min(m, n);
-
-        s = new double[Math.min(m + 1, n)];
-        u = new double[m][nu];
-        v = new double[n][n];
-
-        double[] e = new double[n];
-        double[] work = new double[m];
-
-        int nct = Math.min(m - 1, n);
-        int nrt = Math.max(0, Math.min(n - 2, m));
-
-        for (int k = 0; k < Math.max(nct, nrt); k++) {
-            if (k < nct) {
-                // Compute the transformation for the k-th column and
-                // place the k-th diagonal in s[k]. Compute 2-norm of k-th
-                // column without under/overflow.
-                s[k] = 0;
-
-                for (int i = k; i < m; i++)
-                    s[k] = Algebra.hypot(s[k], a[i][k]);
-
-                if (s[k] != 0.0) {
-                    if (a[k][k] < 0.0)
-                        s[k] = -s[k];
-
-                    for (int i = k; i < m; i++)
-                        a[i][k] /= s[k];
-
-                    a[k][k] += 1.0;
-                }
-
-                s[k] = -s[k];
-            }
-
-            for (int j = k + 1; j < n; j++) {
-                if (k < nct && s[k] != 0.0) {
-                    // Apply the transformation.
-                    double t = 0;
-
-                    for (int i = k; i < m; i++)
-                        t += a[i][k] * a[i][j];
-
-                    t = -t / a[k][k];
-
-                    for (int i = k; i < m; i++)
-                        a[i][j] += t * a[i][k];
-                }
-
-                // Place the k-th row of A into e for the
-                // subsequent calculation of the row transformation.
-                e[j] = a[k][j];
-            }
-
-            if (k < nct)
-                // Place the transformation in U for subsequent back
-                // multiplication.
-                for (int i = k; i < m; i++)
-                    u[i][k] = a[i][k];
-
-            if (k < nrt) {
-                // Compute the k-th row transformation and place the
-                // k-th super-diagonal in e[k].
-                // Compute 2-norm without under/overflow.
-                e[k] = 0;
-
-                for (int i = k + 1; i < n; i++)
-                    e[k] = Algebra.hypot(e[k], e[i]);
-
-                if (e[k] != 0.0) {
-                    if (e[k + 1] < 0.0)
-                        e[k] = -e[k];
-
-                    for (int i = k + 1; i < n; i++)
-                        e[i] /= e[k];
-
-                    e[k + 1] += 1.0;
-                }
-
-                e[k] = -e[k];
-
-                if (k + 1 < m && e[k] != 0.0) {
-                    // Apply the transformation.
-                    for (int i = k + 1; i < m; i++)
-                        work[i] = 0.0;
-
-                    for (int j = k + 1; j < n; j++)
-                        for (int i = k + 1; i < m; i++)
-                            work[i] += e[j] * a[i][j];
-
-                    for (int j = k + 1; j < n; j++) {
-                        double t = -e[j] / e[k + 1];
-
-                        for (int i = k + 1; i < m; i++)
-                            a[i][j] += t * work[i];
-                    }
-                }
-
-                // Place the transformation in V for subsequent
-                // back multiplication.
-                for (int i = k + 1; i < n; i++)
-                    v[i][k] = e[i];
-            }
-        }
-
-        // Set up the final bi-diagonal matrix or order p.
-        int p = Math.min(n, m + 1);
-
-        if (nct < n)
-            s[nct] = a[nct][nct];
-
-        if (m < p)
-            s[p - 1] = 0.0;
-
-        if (nrt + 1 < p)
-            e[nrt] = a[nrt][p - 1];
-
-        e[p - 1] = 0.0;
-
-        // Generate U.
-        for (int j = nct; j < nu; j++) {
-            for (int i = 0; i < m; i++)
-                u[i][j] = 0.0;
-
-            u[j][j] = 1.0;
-        }
-
-        for (int k = nct - 1; k >= 0; k--) {
-            if (s[k] != 0.0) {
-                for (int j = k + 1; j < nu; j++) {
-                    double t = 0;
-
-                    for (int i = k; i < m; i++)
-                        t += u[i][k] * u[i][j];
-
-                    t = -t / u[k][k];
-
-                    for (int i = k; i < m; i++)
-                        u[i][j] += t * u[i][k];
-                }
-
-                for (int i = k; i < m; i++)
-                    u[i][k] = -u[i][k];
-
-                u[k][k] = 1.0 + u[k][k];
-
-                for (int i = 0; i < k - 1; i++)
-                    u[i][k] = 0.0;
-            }
-            else {
-                for (int i = 0; i < m; i++)
-                    u[i][k] = 0.0;
-
-                u[k][k] = 1.0;
-            }
-        }
-
-        // Generate V.
-        for (int k = n - 1; k >= 0; k--) {
-            if (k < nrt && e[k] != 0.0) {
-                for (int j = k + 1; j < nu; j++) {
-                    double t = 0;
-
-                    for (int i = k + 1; i < n; i++)
-                        t += v[i][k] * v[i][j];
-
-                    t = -t / v[k + 1][k];
-
-                    for (int i = k + 1; i < n; i++)
-                        v[i][j] += t * v[i][k];
-                }
-            }
-
-            for (int i = 0; i < n; i++)
-                v[i][k] = 0.0;
-
-            v[k][k] = 1.0;
-        }
-
-        // Main iteration loop for the singular values.
-        int pp = p - 1;
-        int iter = 0;
-
-        double eps = Math.pow(2.0, -52.0);
-        double tiny = Math.pow(2.0, -966.0);
-
-        while (p > 0) {
-            int k;
-
-            for (k = p - 2; k >= -1; k--) {
-                if (k == -1)
-                    break;
-
-                if (Math.abs(e[k]) <= tiny + eps * (Math.abs(s[k]) + Math.abs(s[k + 1]))) {
-                    e[k] = 0.0;
-
-                    break;
-                }
-            }
-
-            int kase;
-
-            if (k == p - 2)
-                kase = 4;
-            else {
-                int ks;
-
-                for (ks = p - 1; ks >= k; ks--) {
-                    if (ks == k)
-                        break;
-
-                    double t =
-                        (ks != p ? Math.abs(e[ks]) : 0.) +
-                            (ks != k + 1 ? Math.abs(e[ks - 1]) : 0.);
-
-                    if (Math.abs(s[ks]) <= tiny + eps * t) {
-                        s[ks] = 0.0;
-
-                        break;
-                    }
-                }
-
-                if (ks == k)
-                    kase = 3;
-                else if (ks == p - 1)
-                    kase = 1;
-                else {
-                    kase = 2;
-
-                    k = ks;
-                }
-            }
-
-            k++;
-
-            // Perform the task indicated by kase.
-            switch (kase) {
-                // Deflate negligible s(p).
-                case 1: {
-                    double f = e[p - 2];
-
-                    e[p - 2] = 0.0;
-
-                    for (int j = p - 2; j >= k; j--) {
-                        double t = Algebra.hypot(s[j], f);
-                        double cs = s[j] / t;
-                        double sn = f / t;
-
-                        s[j] = t;
-
-                        if (j != k) {
-                            f = -sn * e[j - 1];
-                            e[j - 1] = cs * e[j - 1];
-                        }
-
-                        for (int i = 0; i < n; i++) {
-                            t = cs * v[i][j] + sn * v[i][p - 1];
-
-                            v[i][p - 1] = -sn * v[i][j] + cs * v[i][p - 1];
-                            v[i][j] = t;
-                        }
-                    }
-                }
-
-                break;
-
-                // Split at negligible s(k).
-                case 2: {
-                    double f = e[k - 1];
-                    e[k - 1] = 0.0;
-
-                    for (int j = k; j < p; j++) {
-                        double t = Algebra.hypot(s[j], f);
-                        double cs = s[j] / t;
-                        double sn = f / t;
-
-                        s[j] = t;
-                        f = -sn * e[j];
-                        e[j] = cs * e[j];
-
-                        for (int i = 0; i < m; i++) {
-                            t = cs * u[i][j] + sn * u[i][k - 1];
-
-                            u[i][k - 1] = -sn * u[i][j] + cs * u[i][k - 1];
-                            u[i][j] = t;
-                        }
-                    }
-                }
-
-                break;
-
-                // Perform one qr step.
-                case 3: {
-                    // Calculate the shift.
-                    double scale = Math.max(Math.max(Math.max(Math.max(
-                        Math.abs(s[p - 1]), Math.abs(s[p - 2])), Math.abs(e[p - 2])),
-                        Math.abs(s[k])), Math.abs(e[k]));
-
-                    double sp = s[p - 1] / scale;
-                    double spm1 = s[p - 2] / scale;
-                    double epm1 = e[p - 2] / scale;
-                    double sk = s[k] / scale;
-                    double ek = e[k] / scale;
-                    double b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0;
-                    double c = sp * epm1 * sp * epm1;
-                    double shift = 0.0;
-
-                    if (b != 0.0 || c != 0.0) {
-                        shift = Math.sqrt(b * b + c);
-
-                        if (b < 0.0)
-                            shift = -shift;
-
-                        shift = c / (b + shift);
-                    }
-
-                    double f = (sk + sp) * (sk - sp) + shift;
-                    double g = sk * ek;
-
-                    // Chase zeros.
-                    for (int j = k; j < p - 1; j++) {
-                        double t = Algebra.hypot(f, g);
-                        double cs = f / t;
-                        double sn = g / t;
-
-                        if (j != k)
-                            e[j - 1] = t;
-
-                        f = cs * s[j] + sn * e[j];
-                        e[j] = cs * e[j] - sn * s[j];
-                        g = sn * s[j + 1];
-                        s[j + 1] = cs * s[j + 1];
-
-                        for (int i = 0; i < n; i++) {
-                            t = cs * v[i][j] + sn * v[i][j + 1];
-
-                            v[i][j + 1] = -sn * v[i][j] + cs * v[i][j + 1];
-                            v[i][j] = t;
-                        }
-
-                        t = Algebra.hypot(f, g);
-                        cs = f / t;
-                        sn = g / t;
-                        s[j] = t;
-                        f = cs * e[j] + sn * s[j + 1];
-                        s[j + 1] = -sn * e[j] + cs * s[j + 1];
-                        g = sn * e[j + 1];
-                        e[j + 1] = cs * e[j + 1];
-
-                        if (j < m - 1)
-                            for (int i = 0; i < m; i++) {
-                                t = cs * u[i][j] + sn * u[i][j + 1];
-
-                                u[i][j + 1] = -sn * u[i][j] + cs * u[i][j + 1];
-                                u[i][j] = t;
-                            }
-                    }
-
-                    e[p - 2] = f;
-                    iter = iter + 1;
-                }
-
-                break;
-
-                // Convergence.
-                case 4: {
-                    // Make the singular values positive.
-                    if (s[k] <= 0.0) {
-                        s[k] = s[k] < 0.0 ? -s[k] : 0.0;
-
-                        for (int i = 0; i <= pp; i++)
-                            v[i][k] = -v[i][k];
-                    }
-
-                    // Order the singular values.
-                    while (k < pp) {
-                        if (s[k] >= s[k + 1])
-                            break;
-
-                        double t = s[k];
-
-                        s[k] = s[k + 1];
-                        s[k + 1] = t;
-
-                        if (k < n - 1)
-                            for (int i = 0; i < n; i++) {
-                                t = v[i][k + 1];
-
-                                v[i][k + 1] = v[i][k];
-                                v[i][k] = t;
-                            }
-
-                        if (k < m - 1)
-                            for (int i = 0; i < m; i++) {
-                                t = u[i][k + 1];
-
-                                u[i][k + 1] = u[i][k];
-                                u[i][k] = t;
-                            }
-
-                        k++;
-                    }
-
-                    iter = 0;
-                    p--;
-                }
-
-                break;
-
-                default:
-                    throw new IllegalStateException();
-            }
-        }
-    }
-
-    /**
-     * Gets the two norm condition number, which is {@code max(S) / min(S)} .
-     */
-    public double cond() {
-        return s[0] / s[Math.min(m, n) - 1];
-    }
-
-    /**
-     * @return the diagonal matrix of singular values.
-     */
-    public Matrix getS() {
-        double[][] s = new double[n][n];
-
-        for (int i = 0; i < n; i++) {
-            for (int j = 0; j < n; j++)
-                s[i][j] = 0.0;
-
-            s[i][i] = this.s[i];
-        }
-
-        return like(arg, n, n).assign(s);
-    }
-
-    /**
-     * Gets the diagonal of {@code S}, which is a one-dimensional array of
-     * singular values.
-     *
-     * @return diagonal of {@code S}.
-     */
-    public double[] getSingularValues() {
-        return s;
-    }
-
-    /**
-     * Gets the left singular vectors {@code U}.
-     *
-     * @return {@code U}
-     */
-    public Matrix getU() {
-        if (transpositionNeeded)
-            return like(arg, v.length, v.length).assign(v);
-        else {
-            int numCols = Math.min(m + 1, n);
-
-            Matrix r = like(arg, m, numCols);
-
-            for (int i = 0; i < m; i++)
-                for (int j = 0; j < numCols; j++)
-                    r.set(i, j, u[i][j]);
-
-            return r;
-        }
-    }
-
-    /**
-     * Gets the right singular vectors {@code V}.
-     *
-     * @return {@code V}
-     */
-    public Matrix getV() {
-        if (transpositionNeeded) {
-            int numCols = Math.min(m + 1, n);
-
-            Matrix r = like(arg, m, numCols);
-
-            for (int i = 0; i < m; i++)
-                for (int j = 0; j < numCols; j++)
-                    r.set(i, j, u[i][j]);
-
-            return r;
-        }
-        else
-            return like(arg, v.length, v.length).assign(v);
-    }
-
-    /**
-     * Gets the two norm, which is {@code max(S)}.
-     */
-    public double norm2() {
-        return s[0];
-    }
-
-    /**
-     * Gets effective numerical matrix rank.
-     */
-    public int rank() {
-        double eps = Math.pow(2.0, -52.0);
-        double tol = Math.max(m, n) * s[0] * eps;
-        int r = 0;
-
-        for (double value : s)
-            if (value > tol)
-                r++;
-
-        return r;
-    }
-
-    /**
-     * Gets [n � n] covariance matrix.
-     *
-     * @param minSingularVal Value below which singular values are ignored.
-     */
-    Matrix getCovariance(double minSingularVal) {
-        Matrix j = like(arg, s.length, s.length);
-        Matrix vMat = like(arg, v.length, v.length).assign(v);
-
-        for (int i = 0; i < s.length; i++)
-            j.set(i, i, s[i] >= minSingularVal ? 1 / (s[i] * s[i]) : 0.0);
-
-        return vMat.times(j).times(vMat.transpose());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/package-info.java
deleted file mode 100644
index dcfa0f8..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains matrix decompositions for distributed code algebra.
- */
-package org.apache.ignite.math.decompositions;

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/CardinalityException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/CardinalityException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/CardinalityException.java
deleted file mode 100644
index fc87a27..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/CardinalityException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * Indicates a cardinality mismatch in matrix or vector operations.
- */
-public class CardinalityException extends IgniteException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * Creates new cardinality violation exception.
-     *
-     * @param exp Expected cardinality.
-     * @param act Actual cardinality.
-     */
-    public CardinalityException(int exp, int act) {
-        super("Cardinality violation [expected=" + exp + ", actual=" + act + "]");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/ColumnIndexException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/ColumnIndexException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/ColumnIndexException.java
deleted file mode 100644
index 7670caf..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/ColumnIndexException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * This exception is used to indicate any error condition accessing matrix elements by invalid column index.
- */
-public class ColumnIndexException extends IgniteException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * @param idx Index value that caused this exception.
-     */
-    public ColumnIndexException(int idx) {
-        super("Invalid (out of bound) column index: " + idx);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/IndexException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/IndexException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/IndexException.java
deleted file mode 100644
index 9ada706..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/IndexException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * Indicates an invalid, i.e. out of bound, index on matrix or vector operations.
- */
-public class IndexException extends IgniteException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * @param idx Index value that caused this exception.
-     */
-    public IndexException(int idx) {
-        super("Invalid (out of bound) index: " + idx);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonPositiveDefiniteMatrixException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonPositiveDefiniteMatrixException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonPositiveDefiniteMatrixException.java
deleted file mode 100644
index b6017c2..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonPositiveDefiniteMatrixException.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * This exception is used to indicate error condition of matrix elements failing the positivity check.
- */
-public class NonPositiveDefiniteMatrixException extends IgniteException {
-    /**
-     * Construct an exception.
-     *
-     * @param wrong Value that fails the positivity check.
-     * @param idx Row (and column) index.
-     * @param threshold Absolute positivity threshold.
-     */
-    public NonPositiveDefiniteMatrixException(double wrong, int idx, double threshold) {
-        super("Matrix must be positive, wrong element located on diagonal with index "
-            + idx + " and has value " + wrong + " with this threshold " + threshold);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonSymmetricMatrixException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonSymmetricMatrixException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonSymmetricMatrixException.java
deleted file mode 100644
index 8b4cbdb..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/NonSymmetricMatrixException.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * This exception is used to indicate error condition of matrix failing the symmetry check.
- */
-public class NonSymmetricMatrixException extends IgniteException {
-    /**
-     * @param row Row.
-     * @param col Column.
-     * @param threshold Threshold.
-     */
-    public NonSymmetricMatrixException(int row, int col, double threshold) {
-        super("Symmetric matrix expected, the symmetry is broken on row "
-            + row + " and col " + col + " with this threshold " + threshold);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/RowIndexException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/RowIndexException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/RowIndexException.java
deleted file mode 100644
index f74ae2c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/RowIndexException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * This exception is used to indicate any error condition accessing matrix elements by invalid row index.
- */
-public class RowIndexException extends IgniteException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * @param idx Index value that caused this exception.
-     */
-    public RowIndexException(int idx) {
-        super("Invalid (out of bound) row index: " + idx);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/SingularMatrixException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/SingularMatrixException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/SingularMatrixException.java
deleted file mode 100644
index 4ed3410..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/SingularMatrixException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * Exception to be thrown when a non-singular matrix is expected.
- */
-public class SingularMatrixException extends IgniteException {
-    /** */
-    public SingularMatrixException() {
-        super("Regular (or non-singular) matrix expected.");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnknownProviderException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnknownProviderException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnknownProviderException.java
deleted file mode 100644
index 3e6498a..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnknownProviderException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * Indicates that no provider has been found for a given vector or matrix flavor.
- */
-public class UnknownProviderException extends IgniteException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * @param flv Flavor (a.k.a. operation performance hints) that has no registered provider for.
-     */
-    public UnknownProviderException(String flv) {
-        super("No provider has been found for the flavor: " + flv);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnsupportedOperationException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnsupportedOperationException.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnsupportedOperationException.java
deleted file mode 100644
index be5264c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/UnsupportedOperationException.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.exceptions;
-
-import org.apache.ignite.IgniteException;
-
-/**
- * Indicate that a specific operation is not supported by the underlying implementation.
- * In some cases, an operation may be unsupported only in certain cases where, for example,
- * it could not be deterministically completed in polynomial time.
- */
-public class UnsupportedOperationException extends IgniteException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * @param errMsg Error message.
-     */
-    public UnsupportedOperationException(String errMsg) {
-        super(errMsg);
-    }
-
-    /**
-     *
-     */
-    public UnsupportedOperationException() {
-        this("Unsupported operation.");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/exceptions/package-info.java
deleted file mode 100644
index 83f3fa4..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/exceptions/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains exceptions for distributed code algebra.
- */
-package org.apache.ignite.math.exceptions;
\ No newline at end of file


[28/50] [abbrv] ignite git commit: IGNITE-4954 - Configurable expiration timeout for Cassandra session. This closes #1785.

Posted by sb...@apache.org.
IGNITE-4954 - Configurable expiration timeout for Cassandra session. This closes #1785.


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

Branch: refs/heads/ignite-1561
Commit: 735ce60da02ebadc43aaa29cc97d331b8056df36
Parents: 36a6cd0
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Thu Apr 13 11:29:30 2017 +0300
Committer: Andrey V. Mashenkov <an...@gmail.com>
Committed: Tue Apr 18 16:59:50 2017 +0300

----------------------------------------------------------------------
 .../store/cassandra/datasource/DataSource.java  | 50 ++++++++++++++------
 .../cassandra/session/CassandraSessionImpl.java | 23 +++++----
 .../cassandra/session/pool/SessionPool.java     |  6 +--
 .../cassandra/session/pool/SessionWrapper.java  | 15 +++---
 4 files changed, 62 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/735ce60d/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/datasource/DataSource.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/datasource/DataSource.java b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/datasource/DataSource.java
index 1ba3c7d..754d902 100644
--- a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/datasource/DataSource.java
+++ b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/datasource/DataSource.java
@@ -17,6 +17,16 @@
 
 package org.apache.ignite.cache.store.cassandra.datasource;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
 import com.datastax.driver.core.AuthProvider;
 import com.datastax.driver.core.Cluster;
 import com.datastax.driver.core.ConsistencyLevel;
@@ -31,25 +41,13 @@ import com.datastax.driver.core.policies.LoadBalancingPolicy;
 import com.datastax.driver.core.policies.ReconnectionPolicy;
 import com.datastax.driver.core.policies.RetryPolicy;
 import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.UUID;
-
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.store.cassandra.session.CassandraSession;
 import org.apache.ignite.cache.store.cassandra.session.CassandraSessionImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
  * Data source abstraction to specify configuration of the Cassandra session to be used.
@@ -64,6 +62,9 @@ public class DataSource implements Externalizable {
      */
     private static final UUID NULL_OBJECT = UUID.fromString("45ffae47-3193-5910-84a2-048fe65735d9");
 
+    /** Default expiration timeout for Cassandra driver session. */
+    public static final long DFLT_SESSION_EXPIRATION_TIMEOUT = 300000; // 5 minutes.
+
     /** Number of rows to immediately fetch in CQL statement execution. */
     private Integer fetchSize;
 
@@ -141,6 +142,9 @@ public class DataSource implements Externalizable {
     /** Netty options to use for connection. */
     private NettyOptions nettyOptions;
 
+    /** Expiration timeout for Cassandra driver session. */
+    private long sessionExpirationTimeout = DFLT_SESSION_EXPIRATION_TIMEOUT;
+
     /** Cassandra session wrapper instance. */
     private volatile CassandraSession ses;
 
@@ -460,6 +464,23 @@ public class DataSource implements Externalizable {
     }
 
     /**
+     * Sets expiration timeout for Cassandra driver session. Idle sessions that are not
+     * used during this timeout value will be automatically closed and recreated later
+     * on demand.
+     * <p>
+     * If set to {@code 0}, timeout is disabled.
+     * <p>
+     * Default value is {@link #DFLT_SESSION_EXPIRATION_TIMEOUT}.
+     *
+     * @param sessionExpirationTimeout Expiration timeout for Cassandra driver session.
+     */
+    public void setSessionExpirationTimeout(long sessionExpirationTimeout) {
+        this.sessionExpirationTimeout = sessionExpirationTimeout;
+
+        invalidate();
+    }
+
+    /**
      * Creates Cassandra session wrapper if it wasn't created yet and returns it
      *
      * @param log logger
@@ -541,7 +562,8 @@ public class DataSource implements Externalizable {
         if (nettyOptions != null)
             builder = builder.withNettyOptions(nettyOptions);
 
-        return ses = new CassandraSessionImpl(builder, fetchSize, readConsistency, writeConsistency, log);
+        return ses = new CassandraSessionImpl(
+            builder, fetchSize, readConsistency, writeConsistency, sessionExpirationTimeout, log);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/735ce60d/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/CassandraSessionImpl.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/CassandraSessionImpl.java b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/CassandraSessionImpl.java
index ac11686..19b88c9 100644
--- a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/CassandraSessionImpl.java
+++ b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/CassandraSessionImpl.java
@@ -17,6 +17,13 @@
 
 package org.apache.ignite.cache.store.cassandra.session;
 
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.Cache;
 import com.datastax.driver.core.BatchStatement;
 import com.datastax.driver.core.BoundStatement;
 import com.datastax.driver.core.Cluster;
@@ -30,13 +37,6 @@ import com.datastax.driver.core.Statement;
 import com.datastax.driver.core.exceptions.AlreadyExistsException;
 import com.datastax.driver.core.exceptions.InvalidQueryException;
 import com.datastax.driver.core.querybuilder.Batch;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import javax.cache.Cache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.store.cassandra.common.CassandraHelper;
@@ -83,6 +83,9 @@ public class CassandraSessionImpl implements CassandraSession {
     /** Consistency level for Cassandra WRITE operations (insert/update/delete). */
     private ConsistencyLevel writeConsistency;
 
+    /** Expiration timeout. */
+    private long expirationTimeout;
+
     /** Logger. */
     private IgniteLogger log;
 
@@ -102,11 +105,12 @@ public class CassandraSessionImpl implements CassandraSession {
      * @param log Logger.
      */
     public CassandraSessionImpl(Cluster.Builder builder, Integer fetchSize, ConsistencyLevel readConsistency,
-        ConsistencyLevel writeConsistency, IgniteLogger log) {
+        ConsistencyLevel writeConsistency, long expirationTimeout, IgniteLogger log) {
         this.builder = builder;
         this.fetchSize = fetchSize;
         this.readConsistency = readConsistency;
         this.writeConsistency = writeConsistency;
+        this.expirationTimeout = expirationTimeout;
         this.log = log;
     }
 
@@ -504,7 +508,8 @@ public class CassandraSessionImpl implements CassandraSession {
     /** {@inheritDoc} */
     @Override public synchronized void close() throws IOException {
         if (decrementSessionRefs() == 0 && ses != null) {
-            SessionPool.put(this, ses);
+            SessionPool.put(this, ses, expirationTimeout);
+
             ses = null;
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/735ce60d/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionPool.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionPool.java b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionPool.java
index 95938bd..4de8516 100644
--- a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionPool.java
+++ b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionPool.java
@@ -17,13 +17,13 @@
 
 package org.apache.ignite.cache.store.cassandra.session.pool;
 
-import com.datastax.driver.core.Session;
 import java.lang.Thread.State;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import com.datastax.driver.core.Session;
 import org.apache.ignite.cache.store.cassandra.session.CassandraSessionImpl;
 
 /**
@@ -98,14 +98,14 @@ public class SessionPool {
      * @param cassandraSes Session wrapper.
      * @param driverSes Driver session.
      */
-    public static void put(CassandraSessionImpl cassandraSes, Session driverSes) {
+    public static void put(CassandraSessionImpl cassandraSes, Session driverSes, long expirationTimeout) {
         if (cassandraSes == null || driverSes == null)
             return;
 
         SessionWrapper old;
 
         synchronized (sessions) {
-            old = sessions.put(cassandraSes, new SessionWrapper(driverSes));
+            old = sessions.put(cassandraSes, new SessionWrapper(driverSes, expirationTimeout));
 
             if (monitorSingleton == null || State.TERMINATED.equals(monitorSingleton.getState())) {
                 monitorSingleton = new SessionMonitor();

http://git-wip-us.apache.org/repos/asf/ignite/blob/735ce60d/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionWrapper.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionWrapper.java b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionWrapper.java
index 7c5722b..68b9dd4 100644
--- a/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionWrapper.java
+++ b/modules/cassandra/store/src/main/java/org/apache/ignite/cache/store/cassandra/session/pool/SessionWrapper.java
@@ -24,12 +24,12 @@ import org.apache.ignite.cache.store.cassandra.common.CassandraHelper;
  * Wrapper for Cassandra driver session, responsible for monitoring session expiration and its closing.
  */
 public class SessionWrapper {
-    /** Expiration timeout for Cassandra driver session. */
-    public static final long DFLT_EXPIRATION_TIMEOUT = 300000;  // 5 minutes.
-
     /** Cassandra driver session. */
     private Session ses;
 
+    /** Expiration timeout. */
+    private long expirationTimeout;
+
     /** Wrapper creation time.  */
     private long time;
 
@@ -38,9 +38,11 @@ public class SessionWrapper {
      *
      * @param ses Cassandra driver session.
      */
-    public SessionWrapper(Session ses) {
+    public SessionWrapper(Session ses, long expirationTimeout) {
         this.ses = ses;
-        this.time = System.currentTimeMillis();
+        this.expirationTimeout = expirationTimeout;
+
+        time = System.currentTimeMillis();
     }
 
     /**
@@ -49,7 +51,7 @@ public class SessionWrapper {
      * @return true if session expired.
      */
     public boolean expired() {
-        return System.currentTimeMillis() - time > DFLT_EXPIRATION_TIMEOUT;
+        return expirationTimeout > 0 && System.currentTimeMillis() - time > expirationTimeout;
     }
 
     /**
@@ -66,6 +68,7 @@ public class SessionWrapper {
      */
     public void release() {
         CassandraHelper.closeSession(ses);
+
         ses = null;
     }
 }


[08/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
deleted file mode 100644
index 66fe9b4..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * Tests for {@link SparseDistributedMatrixStorage}.
- */
-@GridCommonTest(group = "Distributed Models")
-public class SparseDistributedMatrixStorageTest extends GridCommonAbstractTest {
-    /** Number of nodes in grid */
-    private static final int NODE_COUNT = 3;
-    /** Cache name. */
-    private static final String CACHE_NAME = "test-cache";
-    /** */
-    private static final String UNEXPECTED_ATTRIBUTE_VALUE = "Unexpected attribute value.";
-    /** Grid instance. */
-    private Ignite ignite;
-
-    /**
-     * Default constructor.
-     */
-    public SparseDistributedMatrixStorageTest() {
-        super(false);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        for (int i = 1; i <= NODE_COUNT; i++)
-            startGrid(i);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override protected void beforeTest() throws Exception {
-        ignite = grid(NODE_COUNT);
-
-        ignite.configuration().setPeerClassLoadingEnabled(true);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        ignite.destroyCache(CACHE_NAME);
-    }
-
-    /** */
-    public void testCacheCreation() throws Exception {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        final int rows = MathTestConstants.STORAGE_SIZE;
-        final int cols = MathTestConstants.STORAGE_SIZE;
-
-        SparseDistributedMatrixStorage storage = new SparseDistributedMatrixStorage(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        assertNotNull("SparseDistributedMatrixStorage cache is null.", storage.cache());
-    }
-
-    /** */
-    public void testSetGet() throws Exception {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        final int rows = MathTestConstants.STORAGE_SIZE;
-        final int cols = MathTestConstants.STORAGE_SIZE;
-
-        SparseDistributedMatrixStorage storage = new SparseDistributedMatrixStorage(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        for (int i = 0; i < rows; i++) {
-            for (int j = 0; j < cols; j++) {
-                double v = Math.random();
-                storage.set(i, j, v);
-
-                assert Double.compare(v, storage.get(i, j)) == 0;
-                assert Double.compare(v, storage.get(i, j)) == 0;
-            }
-        }
-    }
-
-    /** */
-    public void testAttributes() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        final int rows = MathTestConstants.STORAGE_SIZE;
-        final int cols = MathTestConstants.STORAGE_SIZE;
-
-        SparseDistributedMatrixStorage storage = new SparseDistributedMatrixStorage(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.rowSize(), rows);
-        assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.columnSize(), cols);
-
-        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, storage.isArrayBased());
-        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, storage.isDense());
-        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, storage.isDistributed());
-
-        assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.isRandomAccess(), !storage.isSequentialAccess());
-        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, storage.isRandomAccess());
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
deleted file mode 100644
index 8a223fc..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-
-/**
- * Unit tests for {@link SparseLocalOnHeapVectorStorage}.
- */
-public class RandomAccessSparseVectorStorageTest extends VectorBaseStorageTest<SparseLocalOnHeapVectorStorage> {
-    /** */
-    @Override public void setUp() {
-        storage = new SparseLocalOnHeapVectorStorage(MathTestConstants.STORAGE_SIZE, StorageConstants.RANDOM_ACCESS_MODE);
-    }
-
-    /** */
-    @Test
-    public void data() throws Exception {
-        assertNull(MathTestConstants.NULL_VAL, storage.data());
-    }
-
-    /** */
-    @Test
-    public void isSequentialAccess() throws Exception {
-        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isSequentialAccess());
-    }
-
-    /** */
-    @Test
-    public void isDense() throws Exception {
-        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isDense());
-    }
-
-    /** */
-    @Test
-    public void isArrayBased() throws Exception {
-        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isArrayBased());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
deleted file mode 100644
index a7751d8..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.apache.ignite.math.impls.MathTestConstants.STORAGE_SIZE;
-import static org.apache.ignite.math.impls.MathTestConstants.UNEXPECTED_VAL;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for {@link SparseLocalOffHeapVectorStorage}.
- */
-public class SparseLocalOffHeapVectorStorageTest extends ExternalizeTest<SparseLocalOffHeapVectorStorage> {
-    /** */ private SparseLocalOffHeapVectorStorage testVectorStorage;
-
-    /** */
-    @Before
-    public void setup() {
-        testVectorStorage = new SparseLocalOffHeapVectorStorage(STORAGE_SIZE);
-    }
-
-    /** */
-    @After
-    public void teardown() {
-        testVectorStorage.destroy();
-        testVectorStorage = null;
-    }
-
-    /** */
-    @Test
-    public void testBasic() {
-        for (int i = 0; i < STORAGE_SIZE; i++) {
-            double testVal = Math.random();
-            testVectorStorage.set(i, testVal);
-            assertEquals(UNEXPECTED_VAL, testVal, testVectorStorage.get(i), 0d);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Test(expected = UnsupportedOperationException.class)
-    @Override public void externalizeTest() {
-        super.externalizeTest(new SparseLocalOffHeapVectorStorage(STORAGE_SIZE));
-    }
-
-    /** */
-    @Test
-    public void testAttributes() {
-        SparseLocalOffHeapVectorStorage testVectorStorage = new SparseLocalOffHeapVectorStorage(STORAGE_SIZE);
-
-        assertTrue(UNEXPECTED_VAL, testVectorStorage.isRandomAccess());
-        assertFalse(UNEXPECTED_VAL, testVectorStorage.isSequentialAccess());
-        assertFalse(UNEXPECTED_VAL, testVectorStorage.isDense());
-        assertFalse(UNEXPECTED_VAL, testVectorStorage.isArrayBased());
-        assertFalse(UNEXPECTED_VAL, testVectorStorage.isDistributed());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java
deleted file mode 100644
index 2afc97b..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.util.Arrays;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit test for {@link ArrayVectorStorage}.
- */
-public class VectorArrayStorageTest extends VectorBaseStorageTest<ArrayVectorStorage> {
-    /** */
-    @Override public void setUp() {
-        storage = new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void isArrayBased() throws Exception {
-        assertTrue(MathTestConstants.WRONG_ATTRIBUTE_VAL, storage.isArrayBased());
-
-        assertTrue(MathTestConstants.WRONG_ATTRIBUTE_VAL, new ArrayVectorStorage().isArrayBased());
-    }
-
-    /** */
-    @Test
-    public void data() throws Exception {
-        assertNotNull(MathTestConstants.NULL_DATA_STORAGE, storage.data());
-
-        assertEquals(MathTestConstants.WRONG_DATA_SIZE, storage.data().length, MathTestConstants.STORAGE_SIZE);
-
-        assertTrue(MathTestConstants.UNEXPECTED_DATA_VAL, Arrays.equals(storage.data(), new double[MathTestConstants.STORAGE_SIZE]));
-
-        assertNull(MathTestConstants.UNEXPECTED_DATA_VAL, new ArrayVectorStorage().data());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java
deleted file mode 100644
index 988f8c3..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Abstract class with base tests for each vector storage.
- */
-public abstract class VectorBaseStorageTest<T extends VectorStorage> extends ExternalizeTest<T> {
-    /** */
-    protected T storage;
-
-    /** */
-    @Before
-    public abstract void setUp();
-
-    /** */
-    @After
-    public void tearDown() throws Exception {
-        storage.destroy();
-    }
-
-    /** */
-    @Test
-    public void getSet() throws Exception {
-        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++) {
-            double random = Math.random();
-
-            storage.set(i, random);
-
-            assertEquals(MathTestConstants.WRONG_DATA_ELEMENT, storage.get(i), random, MathTestConstants.NIL_DELTA);
-        }
-    }
-
-    /** */
-    @Test
-    public void size() {
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.size() == MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Override public void externalizeTest() {
-        super.externalizeTest(storage);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java
deleted file mode 100644
index 2645926..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit tests for {@link DenseLocalOffHeapVectorStorage}.
- */
-public class VectorOffheapStorageTest extends VectorBaseStorageTest<DenseLocalOffHeapVectorStorage> {
-    /** */
-    @Before
-    public void setUp() {
-        storage = new DenseLocalOffHeapVectorStorage(MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void isArrayBased() throws Exception {
-        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isArrayBased());
-    }
-
-    /** */
-    @Test
-    public void data() throws Exception {
-        assertNull(MathTestConstants.NULL_VAL, storage.data());
-    }
-
-    /** */
-    @Test
-    public void isSequentialAccess() throws Exception {
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isSequentialAccess());
-    }
-
-    /** */
-    @Test
-    public void isDense() throws Exception {
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isDense());
-    }
-
-    /** */
-    @Test
-    public void equalsTest() {
-        //noinspection EqualsWithItself
-        assertTrue(MathTestConstants.VAL_NOT_EQUALS, storage.equals(storage));
-
-        //noinspection EqualsBetweenInconvertibleTypes
-        assertFalse(MathTestConstants.VALUES_SHOULD_BE_NOT_EQUALS,
-            storage.equals(new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE)));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java
deleted file mode 100644
index c7927a5..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Arrays;
-import java.util.stream.StreamSupport;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.math.impls.storage.vector.ArrayVectorStorage;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit test for {@link AbstractVector}.
- */
-public class AbstractVectorTest {
-    /** */
-    private AbstractVector testVector;
-
-    /** */
-    @Before
-    public void setUp() {
-        testVector = getAbstractVector();
-    }
-
-    /** */
-    @Test
-    public void setStorage() {
-        testVector.setStorage(createStorage());
-
-        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void size() {
-        testVector.setStorage(createStorage());
-        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE);
-
-        testVector.setStorage(new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE + MathTestConstants.STORAGE_SIZE));
-        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE + MathTestConstants.STORAGE_SIZE);
-
-        testVector = getAbstractVector(createStorage());
-        assertTrue(testVector.size() == MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void getPositive() {
-        testVector = getAbstractVector(createStorage());
-
-        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
-            assertNotNull(MathTestConstants.NULL_VALUES, testVector.get(i));
-
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void getNegative0() {
-        testVector.get(0);
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void getNegative1() {
-        testVector.setStorage(createStorage());
-
-        testVector.get(-1);
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void getNegative2() {
-        testVector.setStorage(createStorage());
-
-        testVector.get(testVector.size() + 1);
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void getXNegative0() {
-        testVector.getX(0);
-    }
-
-    /** */
-    @Test(expected = ArrayIndexOutOfBoundsException.class)
-    public void getXNegative1() {
-        testVector.setStorage(createStorage());
-
-        testVector.getX(-1);
-    }
-
-    /** */
-    @Test(expected = ArrayIndexOutOfBoundsException.class)
-    public void getXNegative2() {
-        testVector.setStorage(createStorage());
-
-        testVector.getX(MathTestConstants.STORAGE_SIZE + 1);
-    }
-
-    /** */
-    @Test
-    public void set() {
-        double[] data = initVector();
-
-        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
-            testVector.set(i, Math.exp(data[i]));
-
-        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
-            assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.get(i), Math.exp(data[i]), MathTestConstants.NIL_DELTA);
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void setNegative0() {
-        testVector.set(-1, -1);
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void setNegative1() {
-        initVector();
-
-        testVector.set(-1, -1);
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void setNegative2() {
-        initVector();
-
-        testVector.set(MathTestConstants.STORAGE_SIZE + 1, -1);
-    }
-
-    /** */
-    @Test(expected = IndexOutOfBoundsException.class)
-    public void setXNegative0() {
-        initVector();
-
-        testVector.setX(-1, -1);
-    }
-
-    /** */
-    @Test(expected = IndexOutOfBoundsException.class)
-    public void setXNegative1() {
-        initVector();
-
-        testVector.setX(MathTestConstants.STORAGE_SIZE + 1, -1);
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void setXNegative2() {
-        testVector.setX(-1, -1);
-    }
-
-    /** */
-    @Test
-    public void isZero() {
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, testVector.isZero(0d));
-
-        assertFalse(MathTestConstants.UNEXPECTED_VAL, testVector.isZero(1d));
-    }
-
-    /** */
-    @Test
-    public void guid() {
-        assertNotNull(MathTestConstants.NULL_GUID, testVector.guid());
-
-        assertEquals(MathTestConstants.UNEXPECTED_GUID_VAL, testVector.guid(), testVector.guid());
-
-        assertFalse(MathTestConstants.EMPTY_GUID, testVector.guid().toString().isEmpty());
-
-        testVector = getAbstractVector(createStorage());
-
-        assertNotNull(MathTestConstants.NULL_GUID, testVector.guid());
-
-        assertEquals(MathTestConstants.UNEXPECTED_GUID_VAL, testVector.guid(), testVector.guid());
-
-        assertFalse(MathTestConstants.EMPTY_GUID, testVector.guid().toString().isEmpty());
-    }
-
-    /** */
-    @Test
-    public void equalsTest() {
-        VectorStorage storage = createStorage();
-
-        AbstractVector testVector1 = getAbstractVector();
-
-        testVector1.setStorage(storage);
-
-        AbstractVector testVector2 = getAbstractVector();
-
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector, testVector);
-
-        testVector2.setStorage(storage);
-
-        assertTrue(MathTestConstants.VAL_NOT_EQUALS, testVector1.equals(testVector2));
-
-        assertFalse(MathTestConstants.VALUES_SHOULD_BE_NOT_EQUALS, testVector1.equals(testVector));
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void all() {
-        assertNotNull(MathTestConstants.NULL_VAL, testVector.all());
-
-        assertNotNull(MathTestConstants.NULL_VAL, getAbstractVector(createStorage()).all());
-
-        getAbstractVector().all().iterator().next();
-    }
-
-    /** */
-    @Test
-    public void nonZeroElements() {
-        VectorStorage storage = createStorage();
-
-        double[] data = storage.data();
-
-        testVector = getAbstractVector(storage);
-
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.nonZeroElements(), Arrays.stream(data).filter(x -> x != 0d).count());
-
-        addNilValues(data);
-
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.nonZeroElements(), Arrays.stream(data).filter(x -> x != 0d).count());
-    }
-
-    /** */
-    @Test
-    public void foldMapWithSecondVector() {
-        double[] data0 = initVector();
-
-        VectorStorage storage1 = createStorage();
-
-        double[] data1 = storage1.data().clone();
-
-        AbstractVector testVector1 = getAbstractVector(storage1);
-
-        String testVal = "";
-
-        for (int i = 0; i < data0.length; i++)
-            testVal += data0[i] + data1[i];
-
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.foldMap(testVector1, (string, xi) -> string.concat(xi.toString()), Functions.PLUS, ""), testVal);
-    }
-
-    /** */
-    @Test
-    public void nonZeroes() {
-        assertNotNull(MathTestConstants.NULL_VAL, testVector.nonZeroes());
-
-        double[] data = initVector();
-
-        assertNotNull(MathTestConstants.NULL_VAL, testVector.nonZeroes());
-
-        Assert.assertEquals(MathTestConstants.VAL_NOT_EQUALS, StreamSupport.stream(testVector.nonZeroes().spliterator(), false).count(), Arrays.stream(data).filter(x -> x != 0d).count());
-
-        addNilValues(data);
-
-        Assert.assertEquals(MathTestConstants.VAL_NOT_EQUALS, StreamSupport.stream(testVector.nonZeroes().spliterator(), false).count(), Arrays.stream(data).filter(x -> x != 0d).count());
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void nonZeroesEmpty() {
-        testVector.nonZeroes().iterator().next();
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void assign() {
-        testVector.assign(MathTestConstants.TEST_VAL);
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void assignArr() {
-        testVector.assign(new double[1]);
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void assignArrEmpty() {
-        testVector.assign(new double[0]);
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void dotNegative() {
-        testVector.dot(getAbstractVector(createEmptyStorage()));
-    }
-
-    /** */
-    @Test
-    public void dotSelf() {
-        double[] data = initVector();
-
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, testVector.dotSelf(), Arrays.stream(data).reduce(0, (x, y) -> x + y * y), MathTestConstants.NIL_DELTA);
-    }
-
-    /** */
-    @Test
-    public void getStorage() {
-        assertNotNull(MathTestConstants.NULL_VAL, getAbstractVector(createEmptyStorage()));
-        assertNotNull(MathTestConstants.NULL_VAL, getAbstractVector(createStorage()));
-        testVector.setStorage(createStorage());
-        assertNotNull(MathTestConstants.NULL_VAL, testVector.getStorage());
-    }
-
-    /** */
-    @Test
-    public void getElement() {
-        double[] data = initVector();
-
-        for (int i = 0; i < data.length; i++) {
-            assertNotNull(MathTestConstants.NULL_VAL, testVector.getElement(i));
-
-            assertEquals(MathTestConstants.UNEXPECTED_VAL, testVector.getElement(i).get(), data[i], MathTestConstants.NIL_DELTA);
-
-            testVector.getElement(i).set(++data[i]);
-
-            assertEquals(MathTestConstants.UNEXPECTED_VAL, testVector.getElement(i).get(), data[i], MathTestConstants.NIL_DELTA);
-        }
-    }
-
-    /**
-     * Create {@link AbstractVector} with storage for tests.
-     *
-     * @param storage {@link VectorStorage}
-     * @return AbstractVector.
-     */
-    private AbstractVector getAbstractVector(VectorStorage storage) {
-        return new AbstractVector(storage) { // TODO: find out how to fix warning about missing constructor
-            /** */
-            @Override public boolean isDense() {
-                return false;
-            }
-
-            /** */
-            @Override public boolean isSequentialAccess() {
-                return false;
-            }
-
-            /** */
-            @Override public Matrix likeMatrix(int rows, int cols) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector copy() {
-                return getAbstractVector(this.getStorage());
-            }
-
-            /** */
-            @Override public Vector like(int crd) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector normalize() {
-                return null;
-            }
-
-            /** */
-            @Override public Vector normalize(double power) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector logNormalize() {
-                return null;
-            }
-
-            /** */
-            @Override public Vector logNormalize(double power) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector viewPart(int off, int len) {
-                return null;
-            }
-
-            /** {@inheritDoc} */
-            @Override public boolean isRandomAccess() {
-                return true;
-            }
-
-            /** {@inheritDoc} */
-            @Override public boolean isDistributed() {
-                return false;
-            }
-        };
-    }
-
-    /**
-     * Create empty {@link AbstractVector} for tests.
-     *
-     * @return AbstractVector.
-     */
-    private AbstractVector getAbstractVector() {
-        return new AbstractVector() { // TODO: find out how to fix warning about missing constructor
-            /** */
-            @Override public boolean isDense() {
-                return false;
-            }
-
-            /** */
-            @Override public Matrix likeMatrix(int rows, int cols) {
-                return null;
-            }
-
-            /** */
-            @Override public boolean isSequentialAccess() {
-                return false;
-            }
-
-            /** */
-            @Override public Vector copy() {
-                return getAbstractVector(this.getStorage());
-            }
-
-            /** */
-            @Override public Vector like(int crd) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector normalize() {
-                return null;
-            }
-
-            /** */
-            @Override public Vector normalize(double power) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector logNormalize() {
-                return null;
-            }
-
-            /** */
-            @Override public Vector logNormalize(double power) {
-                return null;
-            }
-
-            /** */
-            @Override public Vector viewPart(int off, int len) {
-                return null;
-            }
-
-            /** {@inheritDoc} */
-            @Override public boolean isRandomAccess() {
-                return true;
-            }
-
-            /** {@inheritDoc} */
-            @Override public boolean isDistributed() {
-                return false;
-            }
-        };
-    }
-
-    /**
-     * Create {@link VectorStorage} for tests.
-     *
-     * @return VectorStorage
-     */
-    private VectorStorage createEmptyStorage() {
-        return new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE);
-    }
-
-    /**
-     * Create filled {@link VectorStorage} for tests.
-     *
-     * @return VectorStorage.
-     */
-    private VectorStorage createStorage() {
-        ArrayVectorStorage storage = new ArrayVectorStorage(MathTestConstants.STORAGE_SIZE);
-
-        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++)
-            storage.set(i, Math.random());
-
-        return storage;
-    }
-
-    /**
-     * Init vector and return initialized values.
-     *
-     * @return Initial values.
-     */
-    private double[] initVector() {
-        VectorStorage storage = createStorage();
-        double[] data = storage.data().clone();
-
-        testVector = getAbstractVector(storage);
-        return data;
-    }
-
-    /**
-     * Add some zeroes to vector elements.
-     */
-    private void addNilValues() {
-        testVector.set(10, 0);
-        testVector.set(50, 0);
-    }
-
-    /**
-     * Add some zeroes to vector elements. Also set zeroes to the same elements in reference array data
-     */
-    private void addNilValues(double[] testRef) {
-        addNilValues();
-        testRef[10] = 0;
-        testRef[50] = 0;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java
deleted file mode 100644
index f276820..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java
+++ /dev/null
@@ -1,417 +0,0 @@
-package org.apache.ignite.math.impls.vector;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.stream.IntStream;
-import junit.framework.TestCase;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.math.IdentityValueMapper;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorKeyMapper;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * Tests for {@link CacheVector}.
- */
-@GridCommonTest(group = "Distributed Models")
-public class CacheVectorTest extends GridCommonAbstractTest {
-    /** Number of nodes in grid */
-    private static final int NODE_COUNT = 3;
-    /** Cache name. */
-    private static final String CACHE_NAME = "test-cache";
-    /** Cache size. */
-    private static final int size = MathTestConstants.STORAGE_SIZE;
-    /** Grid instance. */
-    private Ignite ignite;
-    /** Default key mapper. */
-    private VectorKeyMapper<Integer> keyMapper = new TestKeyMapper();
-
-    /**
-     * Default constructor.
-     */
-    public CacheVectorTest() {
-        super(false);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        for (int i = 1; i <= NODE_COUNT; i++)
-            startGrid(i);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        ignite = grid(NODE_COUNT);
-
-        ignite.configuration().setPeerClassLoadingEnabled(true);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        ignite.destroyCache(CACHE_NAME);
-    }
-
-    /** */
-    public void testGetSet() throws Exception {
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        for (int i = 0; i < size; i++) {
-            double random = Math.random();
-            cacheVector.set(i, random);
-            assertEquals("Unexpected value.", random, cacheVector.get(i), 0d);
-        }
-    }
-
-    /** */
-    public void testMap() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-
-        cacheVector.map(value -> 110d);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), 110d, 0d);
-    }
-
-    /** */
-    public void testMapBiFunc() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-
-        cacheVector.map(Functions.PLUS, 1d);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), 1d, 0d);
-    }
-
-    /** */
-    public void testSum() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-
-        assertEquals("Unexpected value.", cacheVector.sum(), 0d, 0d);
-
-        cacheVector.assign(1d);
-
-        assertEquals("Unexpected value.", cacheVector.sum(), size, 0d);
-    }
-
-    /** */
-    public void testSumNegative() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        try {
-            double d = cacheVector.sum();
-            fail();
-        }
-        catch (NullPointerException e) {
-            // No-op.
-        }
-    }
-
-    /** */
-    public void testAssign() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-
-        cacheVector.assign(1d);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), 1d, 0d);
-    }
-
-    /** */
-    public void testAssignRange() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        cacheVector.assign(IntStream.range(0, size).asDoubleStream().toArray());
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), i, 0d);
-    }
-
-    /** */
-    public void testAssignVector() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
-
-        cacheVector.assign(testVec);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), testVec.get(i), 0d);
-    }
-
-    /** */
-    public void testAssignFunc() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        cacheVector.assign(idx -> idx);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), i, 0d);
-    }
-
-    /** */
-    public void testPlus() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-
-        cacheVector.plus(1d);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), 1d, 0d);
-    }
-
-    /** */
-    public void testPlusVec() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
-
-        try {
-            cacheVector.plus(testVec);
-            TestCase.fail();
-        }
-        catch (UnsupportedOperationException ignored) {
-
-        }
-    }
-
-    /** */
-    public void testDivide() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        final int size = MathTestConstants.STORAGE_SIZE;
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-        cacheVector.assign(1d);
-
-        cacheVector.divide(2d);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), 1d / 2d, 0d);
-    }
-
-    /** */
-    public void testTimes() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        final int size = MathTestConstants.STORAGE_SIZE;
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        initVector(cacheVector);
-        cacheVector.assign(1d);
-
-        cacheVector.times(2d);
-
-        for (int i = 0; i < size; i++)
-            assertEquals("Unexpected value.", cacheVector.get(i), 2d, 0d);
-    }
-
-    /** */
-    public void testTimesVector() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        cacheVector.assign(1d);
-        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
-
-        try {
-            cacheVector.times(testVec);
-            TestCase.fail();
-        }
-        catch (UnsupportedOperationException ignored) {
-
-        }
-
-    }
-
-    /** */
-    public void testMin() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
-
-        cacheVector.assign(testVec);
-
-        assertEquals("Unexpected value.", cacheVector.minValue(), 0d, 0d);
-    }
-
-    /** */
-    public void testMax() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
-
-        cacheVector.assign(testVec);
-
-        assertEquals("Unexpected value.", cacheVector.maxValue(), testVec.get(size - 1), 0d);
-    }
-
-    /** */
-    public void testLike() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        try {
-            cacheVector.like(size);
-            TestCase.fail("Unsupported case");
-        }
-        catch (UnsupportedOperationException ignored) {
-
-        }
-    }
-
-    /** */
-    public void testLikeMatrix() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        try {
-            cacheVector.likeMatrix(size, size);
-            TestCase.fail("Unsupported case");
-        }
-        catch (UnsupportedOperationException ignored) {
-
-        }
-    }
-
-    /** */
-    public void testCopy() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        try {
-            cacheVector.copy();
-            TestCase.fail("Unsupported case");
-        }
-        catch (UnsupportedOperationException ignored) {
-
-        }
-    }
-
-    /** */
-    public void testExternalize() throws IOException, ClassNotFoundException {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        IdentityValueMapper valMapper = new IdentityValueMapper();
-        CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
-        cacheVector.set(1, 1.0);
-
-        ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
-        ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
-
-        objOutputStream.writeObject(cacheVector);
-
-        ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
-        ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
-
-        CacheVector objRestored = (CacheVector)objInputStream.readObject();
-
-        assertTrue(MathTestConstants.VAL_NOT_EQUALS, cacheVector.equals(objRestored));
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, objRestored.get(1), 1.0, 0.0);
-    }
-
-    /** */
-    private void initVector(CacheVector cacheVector) {
-        for (int i = 0; i < cacheVector.size(); i++)
-            cacheVector.set(i, 0d);
-    }
-
-    /** */
-    private IgniteCache<Integer, Double> getCache() {
-        assert ignite != null;
-
-        CacheConfiguration cfg = new CacheConfiguration();
-        cfg.setName(CACHE_NAME);
-
-        IgniteCache<Integer, Double> cache = ignite.getOrCreateCache(CACHE_NAME);
-
-        assert cache != null;
-        return cache;
-    }
-
-    /** */ private static class TestKeyMapper implements VectorKeyMapper<Integer> {
-        /** {@inheritDoc} */
-        @Override public Integer apply(int i) {
-            return i;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean isValid(Integer i) {
-            return i < size;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/ConstantVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/ConstantVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/ConstantVectorConstructorTest.java
deleted file mode 100644
index 2ed42bc..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/ConstantVectorConstructorTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class ConstantVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new ConstantVector(-1, 1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void zeroSizeTest() {
-        assertEquals("Zero size.", IMPOSSIBLE_SIZE,
-            new ConstantVector(0, 1).size());
-    }
-
-    /** */
-    @Test
-    public void primitiveTest() {
-        assertEquals("1 size.", 1,
-            new ConstantVector(1, 1).size());
-
-        assertEquals("2 size.", 2,
-            new ConstantVector(2, 1).size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DelegatingVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DelegatingVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DelegatingVectorConstructorTest.java
deleted file mode 100644
index 82e4e0b..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DelegatingVectorConstructorTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Vector;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class DelegatingVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test
-    public void basicTest() {
-        final Vector parent = new DenseLocalOnHeapVector(new double[] {0, 1});
-
-        final Vector delegate = new DelegatingVector(parent);
-
-        final int size = parent.size();
-
-        assertEquals("Delegate size differs from expected.", size, delegate.size());
-
-        for (int idx = 0; idx < size; idx++)
-            assertDelegate(parent, delegate, idx);
-    }
-
-    /** */
-    private void assertDelegate(Vector parent, Vector delegate, int idx) {
-        assertValue(parent, delegate, idx);
-
-        parent.set(idx, parent.get(idx) + 1);
-
-        assertValue(parent, delegate, idx);
-
-        delegate.set(idx, delegate.get(idx) + 2);
-
-        assertValue(parent, delegate, idx);
-    }
-
-    /** */
-    private void assertValue(Vector parent, Vector delegate, int idx) {
-        assertEquals("Unexpected value at index " + idx, parent.get(idx), delegate.get(idx), 0d);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java
deleted file mode 100644
index d62f35f..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVectorConstructorTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class DenseLocalOffHeapVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new DenseLocalOffHeapVector(-1).size());
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void nullArrayTest() {
-        assertEquals("Null array.", IMPOSSIBLE_SIZE,
-            new DenseLocalOffHeapVector(null).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void zeroSizeTest() {
-        assertEquals("0 size.", IMPOSSIBLE_SIZE,
-            new DenseLocalOffHeapVector(new double[0]).size());
-    }
-
-    /** */
-    @Test
-    public void primitiveTest() {
-        assertEquals("1 size.", 1,
-            new DenseLocalOffHeapVector(new double[1]).size());
-
-        assertEquals("2 size.", 2,
-            new DenseLocalOffHeapVector(new double[2]).size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java
deleted file mode 100644
index c10778e..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVectorConstructorTest.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class DenseLocalOnHeapVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = org.apache.ignite.math.exceptions.UnsupportedOperationException.class)
-    public void mapInvalidArgsTest() {
-        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
-                put("invalid", 99);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void mapMissingArgsTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("arr", new double[0]);
-            put("shallowCopyMissing", "whatever");
-        }};
-
-        assertEquals("Expect exception due to missing args.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(test).size());
-    }
-
-    /** */
-    @Test(expected = ClassCastException.class)
-    public void mapInvalidArrTypeTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("size", "whatever");
-        }};
-
-        assertEquals("Expect exception due to invalid arr type.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(test).size());
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void mapInvalidCopyTypeTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("arr", new double[0]);
-            put("shallowCopy", 0);
-        }};
-
-        assertEquals("Expect exception due to invalid copy type.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(test).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void mapNullTest() {
-        //noinspection ConstantConditions
-        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector((Map<String, Object>)null).size());
-    }
-
-    /** */
-    @Test
-    public void mapTest() {
-        assertEquals("Size from args.", 99,
-            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
-                put("size", 99);
-            }}).size());
-
-        final double[] test = new double[99];
-
-        assertEquals("Size from array in args.", test.length,
-            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
-                put("arr", test);
-                put("copy", false);
-            }}).size());
-
-        assertEquals("Size from array in args, shallow copy.", test.length,
-            new DenseLocalOnHeapVector(new HashMap<String, Object>() {{
-                put("arr", test);
-                put("copy", true);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(-1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullCopyTest() {
-        assertEquals("Null array to non-shallow copy.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(null, false).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullDefaultCopyTest() {
-        assertEquals("Null array default copy.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector((double[])null).size());
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void defaultConstructorTest() {
-        assertEquals("Default constructor.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector().size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullArrShallowCopyTest() {
-        assertEquals("Null array shallow copy.", IMPOSSIBLE_SIZE,
-            new DenseLocalOnHeapVector(null, true).size());
-    }
-
-    /** */
-    @Test
-    public void primitiveTest() {
-        assertEquals("0 size shallow copy.", 0,
-            new DenseLocalOnHeapVector(new double[0], true).size());
-
-        assertEquals("0 size.", 0,
-            new DenseLocalOnHeapVector(new double[0], false).size());
-
-        assertEquals("1 size shallow copy.", 1,
-            new DenseLocalOnHeapVector(new double[1], true).size());
-
-        assertEquals("1 size.", 1,
-            new DenseLocalOnHeapVector(new double[1], false).size());
-
-        assertEquals("0 size default copy.", 0,
-            new DenseLocalOnHeapVector(new double[0]).size());
-
-        assertEquals("1 size default copy.", 1,
-            new DenseLocalOnHeapVector(new double[1]).size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/FunctionVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/FunctionVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/FunctionVectorConstructorTest.java
deleted file mode 100644
index 57c96d1..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/FunctionVectorConstructorTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.IntToDoubleFunction;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.functions.IntDoubleToVoidFunction;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class FunctionVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = org.apache.ignite.math.exceptions.UnsupportedOperationException.class)
-    public void mapInvalidArgsTest() {
-        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
-            new FunctionVector(new HashMap<String, Object>() {{
-                put("invalid", 99);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void mapMissingArgsTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("size", 1);
-            put("paramMissing", "whatever");
-        }};
-
-        assertEquals("Expect exception due to missing args.",
-            -1, new FunctionVector(test).size());
-    }
-
-    /** */
-    @Test(expected = ClassCastException.class)
-    public void mapInvalidParamTypeTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("size", "whatever");
-
-            put("getFunc", (IntToDoubleFunction)i -> i);
-        }};
-
-        assertEquals("Expect exception due to invalid param type.", IMPOSSIBLE_SIZE,
-            new FunctionVector(test).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void mapNullTest() {
-        //noinspection ConstantConditions
-        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
-            new FunctionVector(null).size());
-    }
-
-    /** */
-    @Test
-    public void mapTest() {
-        assertEquals("Size from args.", 99,
-            new FunctionVector(new HashMap<String, Object>() {{
-                put("size", 99);
-
-                put("getFunc", (IgniteFunction<Integer, Double>)i -> (double)i);
-            }}).size());
-
-        assertEquals("Size from args with setFunc.", 99,
-            new FunctionVector(new HashMap<String, Object>() {{
-                put("size", 99);
-
-                put("getFunc", (IgniteFunction<Integer, Double>)i -> (double)i);
-
-                put("setFunc", (IntDoubleToVoidFunction)(integer, aDouble) -> {
-                });
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new FunctionVector(-1, (i) -> (double)i).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void zeroSizeTest() {
-        assertEquals("0 size.", IMPOSSIBLE_SIZE,
-            new FunctionVector(0, (i) -> (double)i).size());
-    }
-
-    /** */
-    @Test
-    public void primitiveTest() {
-        assertEquals("1 size.", 1,
-            new FunctionVector(1, (i) -> (double)i).size());
-
-        assertEquals("2 size.", 2,
-            new FunctionVector(2, (i) -> (double)i).size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/MatrixVectorViewTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/MatrixVectorViewTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/MatrixVectorViewTest.java
deleted file mode 100644
index b7e390e..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/MatrixVectorViewTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for {@link MatrixVectorView}.
- */
-public class MatrixVectorViewTest {
-    /** */
-    private static final String UNEXPECTED_VALUE = "Unexpected value";
-    /** */
-    private static final int SMALL_SIZE = 3;
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    private Matrix parent;
-
-    /** */
-    @Before
-    public void setup() {
-        parent = newMatrix(SMALL_SIZE, SMALL_SIZE);
-    }
-
-    /** */
-    @Test
-    public void testDiagonal() {
-        Vector vector = parent.viewDiagonal();
-
-        for (int i = 0; i < SMALL_SIZE; i++)
-            assertView(i, i, vector, i);
-    }
-
-    /** */
-    @Test
-    public void testRow() {
-        for (int i = 0; i < SMALL_SIZE; i++) {
-            Vector viewRow = parent.viewRow(i);
-
-            for (int j = 0; j < SMALL_SIZE; j++)
-                assertView(i, j, viewRow, j);
-        }
-    }
-
-    /** */
-    @Test
-    public void testCols() {
-        for (int i = 0; i < SMALL_SIZE; i++) {
-            Vector viewCol = parent.viewColumn(i);
-
-            for (int j = 0; j < SMALL_SIZE; j++)
-                assertView(j, i, viewCol, j);
-        }
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        for (int rowSize : new int[] {1, 2, 3, 4})
-            for (int colSize : new int[] {1, 2, 3, 4})
-                for (int row = 0; row < rowSize; row++)
-                    for (int col = 0; col < colSize; col++)
-                        for (int rowStride = 0; rowStride < rowSize; rowStride++)
-                            for (int colStride = 0; colStride < colSize; colStride++)
-                                if (rowStride != 0 || colStride != 0)
-                                    assertMatrixVectorView(newMatrix(rowSize, colSize), row, col, rowStride, colStride);
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void parentNullTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(null, 1, 1, 1, 1).size());
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void rowNegativeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, -1, 1, 1, 1).size());
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void colNegativeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, -1, 1, 1).size());
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void rowTooLargeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, parent.rowSize() + 1, 1, 1, 1).size());
-    }
-
-    /** */
-    @Test(expected = IndexException.class)
-    public void colTooLargeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, parent.columnSize() + 1, 1, 1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void rowStrideNegativeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, 1, -1, 1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void colStrideNegativeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, 1, 1, -1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void rowStrideTooLargeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, 1, parent.rowSize() + 1, 1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void colStrideTooLargeTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, 1, 1, parent.columnSize() + 1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void bothStridesZeroTest() {
-        //noinspection ConstantConditions
-        assertEquals(IMPOSSIBLE_SIZE,
-            new MatrixVectorView(parent, 1, 1, 0, 0).size());
-    }
-
-    /** */
-    private void assertMatrixVectorView(Matrix parent, int row, int col, int rowStride, int colStride) {
-        MatrixVectorView view = new MatrixVectorView(parent, row, col, rowStride, colStride);
-
-        String desc = "parent [" + parent.rowSize() + "x" + parent.columnSize() + "], view ["
-            + row + "x" + col + "], strides [" + rowStride + ", " + colStride + "]";
-
-        final int size = view.size();
-
-        final int sizeByRows = rowStride == 0 ? IMPOSSIBLE_SIZE : (parent.rowSize() - row) / rowStride;
-        final int sizeByCols = colStride == 0 ? IMPOSSIBLE_SIZE : (parent.columnSize() - col) / colStride;
-
-        assertTrue("Size " + size + " differs from expected for " + desc,
-            size == sizeByRows || size == sizeByCols);
-
-        for (int idx = 0; idx < size; idx++) {
-            final int rowIdx = row + idx * rowStride;
-            final int colIdx = col + idx * colStride;
-
-            assertEquals(UNEXPECTED_VALUE + " at view index " + idx + desc,
-                parent.get(rowIdx, colIdx), view.get(idx), 0d);
-        }
-    }
-
-    /** */
-    private Matrix newMatrix(int rowSize, int colSize) {
-        Matrix res = new DenseLocalOnHeapMatrix(rowSize, colSize);
-
-        for (int i = 0; i < res.rowSize(); i++)
-            for (int j = 0; j < res.columnSize(); j++)
-                res.set(i, j, i * res.rowSize() + j);
-
-        return res;
-    }
-
-    /** */
-    private void assertView(int row, int col, Vector view, int viewIdx) {
-        assertValue(row, col, view, viewIdx);
-
-        parent.set(row, col, parent.get(row, col) + 1);
-
-        assertValue(row, col, view, viewIdx);
-
-        view.set(viewIdx, view.get(viewIdx) + 2);
-
-        assertValue(row, col, view, viewIdx);
-    }
-
-    /** */
-    private void assertValue(int row, int col, Vector view, int viewIdx) {
-        assertEquals(UNEXPECTED_VALUE + " at row " + row + " col " + col, parent.get(row, col), view.get(viewIdx), 0d);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/PivotedVectorViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/PivotedVectorViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/PivotedVectorViewConstructorTest.java
deleted file mode 100644
index 91650dc..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/PivotedVectorViewConstructorTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class PivotedVectorViewConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    private static final SampleParams sampleParams = new SampleParams();
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void nullVecParamTest() {
-        assertEquals("Expect exception due to null vector param.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(null, sampleParams.pivot).size());
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void nullVecParam2Test() {
-        assertEquals("Expect exception due to null vector param, with unpivot.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(null, sampleParams.pivot, sampleParams.unpivot).size());
-    }
-
-    /** */
-    @Test(expected = NullPointerException.class)
-    public void nullPivotParamTest() {
-        assertEquals("Expect exception due to null pivot param.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, null).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullPivotParam2Test() {
-        assertEquals("Expect exception due to null pivot param, with unpivot.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, null, sampleParams.unpivot).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullUnpivotParam2Test() {
-        assertEquals("Expect exception due to null unpivot param.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, sampleParams.pivot, null).size());
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void emptyPivotTest() {
-        assertEquals("Expect exception due to empty pivot param.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, new int[] {}).size());
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void emptyPivot2Test() {
-        assertEquals("Expect exception due to empty pivot param, with unpivot.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, new int[] {}, sampleParams.unpivot).size());
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void wrongPivotTest() {
-        assertEquals("Expect exception due to wrong pivot param.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, new int[] {0}).size());
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void wrongPivot2Test() {
-        assertEquals("Expect exception due to wrong pivot param, with unpivot.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, new int[] {0}, sampleParams.unpivot).size());
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void emptyUnpivotTest() {
-        assertEquals("Expect exception due to empty unpivot param.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, sampleParams.pivot, new int[] {}).size());
-    }
-
-    /** */
-    @Test(expected = CardinalityException.class)
-    public void wrongUnpivotTest() {
-        assertEquals("Expect exception due to wrong unpivot param, with unpivot.", IMPOSSIBLE_SIZE,
-            new PivotedVectorView(sampleParams.vec, sampleParams.pivot, new int[] {0}).size());
-    }
-
-    /** */
-    @Test
-    public void basicPivotTest() {
-        final PivotedVectorView pvv = new PivotedVectorView(sampleParams.vec, sampleParams.pivot);
-
-        final int size = sampleParams.vec.size();
-
-        assertEquals("View size differs from expected.", size, pvv.size());
-
-        assertSame("Base vector differs from expected.", sampleParams.vec, pvv.getBaseVector());
-
-        for (int idx = 0; idx < size; idx++) {
-            assertEquals("Sample pivot and unpivot differ from expected",
-                idx, sampleParams.unpivot[sampleParams.pivot[idx]]);
-
-            assertEquals("Pivot differs from expected at index " + idx,
-                sampleParams.pivot[idx], pvv.pivot(idx));
-
-            assertEquals("Default unpivot differs from expected at index " + idx,
-                sampleParams.unpivot[idx], pvv.unpivot(idx));
-
-            final Metric metric = new Metric(sampleParams.vec.get(idx), pvv.get(pvv.pivot(idx)));
-
-            assertTrue("Not close enough at index " + idx + ", " + metric, metric.closeEnough());
-        }
-
-        for (int idx = 0; idx < size; idx++) {
-            sampleParams.vec.set(idx, sampleParams.vec.get(idx) + idx + 1);
-
-            final Metric metric = new Metric(sampleParams.vec.get(idx), pvv.get(pvv.pivot(idx)));
-
-            assertTrue("Modified value not close enough at index " + idx + ", " + metric, metric.closeEnough());
-        }
-    }
-
-    /** */
-    @Test
-    public void basicUnpivotTest() {
-        final PivotedVectorView pvv = new PivotedVectorView(sampleParams.vec, sampleParams.pivot, sampleParams.unpivot);
-
-        final int size = sampleParams.vec.size();
-
-        assertEquals("View size differs from expected.", size, pvv.size());
-
-        for (int idx = 0; idx < size; idx++) {
-            assertEquals("Unpivot differs from expected at index " + idx,
-                sampleParams.unpivot[idx], pvv.unpivot(idx));
-
-            final Metric metric = new Metric(sampleParams.vec.get(idx), pvv.get(pvv.unpivot(idx)));
-
-            assertTrue("Not close enough at index " + idx + ", " + metric, metric.closeEnough());
-        }
-    }
-
-    /** */
-    private static class SampleParams {
-        /** */
-        final double[] data = new double[] {0, 1};
-        /** */
-        final Vector vec = new DenseLocalOnHeapVector(data);
-        /** */
-        final int[] pivot = new int[] {1, 0};
-        /** */
-        final int[] unpivot = new int[] {1, 0};
-    }
-
-    /** */
-    private static class Metric { // todo consider if softer tolerance (like say 0.1 or 0.01) would make sense here
-        /** */
-        private final double exp;
-
-        /** */
-        private final double obtained;
-
-        /** **/
-        Metric(double exp, double obtained) {
-            this.exp = exp;
-            this.obtained = obtained;
-        }
-
-        /** */
-        boolean closeEnough() {
-            return new Double(exp).equals(obtained) || closeEnoughToZero();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Metric{" + "expected=" + exp +
-                ", obtained=" + obtained +
-                '}';
-        }
-
-        /** */
-        private boolean closeEnoughToZero() {
-            return (new Double(exp).equals(0.0) && new Double(obtained).equals(-0.0))
-                || (new Double(exp).equals(-0.0) && new Double(obtained).equals(0.0));
-        }
-    }
-}


[09/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationsTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationsTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationsTest.java
deleted file mode 100644
index 28abab7..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationsTest.java
+++ /dev/null
@@ -1,1113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.BiConsumer;
-import java.util.function.Supplier;
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.ColumnIndexException;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.exceptions.RowIndexException;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVector;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.apache.ignite.math.impls.vector.RandomVector;
-import org.apache.ignite.math.impls.vector.SparseLocalVector;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Tests for {@link Matrix} implementations.
- */
-public class MatrixImplementationsTest extends ExternalizeTest<Matrix> {
-    /** */
-    private static final double DEFAULT_DELTA = 0.000000001d;
-
-    /** */
-    private void consumeSampleMatrix(BiConsumer<Matrix, String> consumer) {
-        new MatrixImplementationFixtures().consumeSampleMatrix(consumer);
-    }
-
-    /** */
-    @Test
-    public void externalizeTest() {
-        consumeSampleMatrix((m, desc) -> externalizeTest(m));
-    }
-
-    /** */
-    @Test
-    public void testLike() {
-        consumeSampleMatrix((m, desc) -> {
-            Class<? extends Matrix> cls = likeMatrixType(m);
-
-            if (cls != null) {
-                Matrix like = m.like(m.rowSize(), m.columnSize());
-
-                assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected rows.", like.rowSize(), m.rowSize());
-                assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected columns.", like.columnSize(), m.columnSize());
-
-                assertEquals("Wrong \"like\" matrix for " + desc
-                        + "; Unexpected class: " + like.getClass().toString(),
-                    cls,
-                    like.getClass());
-
-                return;
-            }
-
-            boolean expECaught = false;
-
-            try {
-                m.like(1, 1);
-            }
-            catch (UnsupportedOperationException uoe) {
-                expECaught = true;
-            }
-
-            assertTrue("Expected exception was not caught for " + desc, expECaught);
-        });
-    }
-
-    /** */
-    @Test
-    public void testCopy() {
-        consumeSampleMatrix((m, desc) -> {
-            Matrix cp = m.copy();
-            assertTrue("Incorrect copy for empty matrix " + desc, cp.equals(m));
-
-            if (!readOnly(m))
-                fillMatrix(m);
-
-            cp = m.copy();
-
-            assertTrue("Incorrect copy for matrix " + desc, cp.equals(m));
-        });
-    }
-
-    /** */
-    @Test
-    public void testHaveLikeVector() throws InstantiationException, IllegalAccessException {
-        for (Class<? extends Matrix> key : likeVectorTypesMap().keySet()) {
-            Class<? extends Vector> val = likeVectorTypesMap().get(key);
-
-            if (val == null && !ignore(key))
-                System.out.println("Missing test for implementation of likeMatrix for " + key.getSimpleName());
-        }
-    }
-
-    /** */
-    @Test
-    public void testLikeVector() {
-        consumeSampleMatrix((m, desc) -> {
-            if (likeVectorTypesMap().containsKey(m.getClass())) {
-                Vector likeVector = m.likeVector(m.columnSize());
-
-                assertNotNull(likeVector);
-                assertEquals("Unexpected value for " + desc, likeVector.size(), m.columnSize());
-
-                return;
-            }
-
-            boolean expECaught = false;
-
-            try {
-                m.likeVector(1);
-            }
-            catch (UnsupportedOperationException uoe) {
-                expECaught = true;
-            }
-
-            assertTrue("Expected exception was not caught for " + desc, expECaught);
-        });
-    }
-
-    /** */
-    @Test
-    public void testAssignSingleElement() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            final double assignVal = Math.random();
-
-            m.assign(assignVal);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        assignVal, m.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testAssignArray() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] data = new double[m.rowSize()][m.columnSize()];
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    data[i][j] = Math.random();
-
-            m.assign(data);
-
-            for (int i = 0; i < m.rowSize(); i++) {
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        data[i][j], m.get(i, j), 0d);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testAssignFunction() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            m.assign((i, j) -> (double)(i * m.columnSize() + j));
-
-            for (int i = 0; i < m.rowSize(); i++) {
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        (double)(i * m.columnSize() + j), m.get(i, j), 0d);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testPlus() {
-        consumeSampleMatrix((m, desc) -> {
-            if (readOnly(m))
-                return;
-
-            double[][] data = fillAndReturn(m);
-
-            double plusVal = Math.random();
-
-            Matrix plus = m.plus(plusVal);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        data[i][j] + plusVal, plus.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testPlusMatrix() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] data = fillAndReturn(m);
-
-            Matrix plus = m.plus(m);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        data[i][j] * 2.0, plus.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testMinusMatrix() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            Matrix minus = m.minus(m);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        0.0, minus.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testTimes() {
-        consumeSampleMatrix((m, desc) -> {
-            if (readOnly(m))
-                return;
-
-            double[][] data = fillAndReturn(m);
-
-            double timeVal = Math.random();
-            Matrix times = m.times(timeVal);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        data[i][j] * timeVal, times.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testTimesVector() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] data = fillAndReturn(m);
-
-            double[] arr = fillArray(m.columnSize());
-
-            Vector times = m.times(new DenseLocalOnHeapVector(arr));
-
-            assertEquals("Unexpected vector size for " + desc, times.size(), m.rowSize());
-
-            for (int i = 0; i < m.rowSize(); i++) {
-                double exp = 0.0;
-
-                for (int j = 0; j < m.columnSize(); j++)
-                    exp += arr[j] * data[i][j];
-
-                assertEquals("Unexpected value for " + desc + " at " + i,
-                    times.get(i), exp, 0d);
-            }
-
-            testInvalidCardinality(() -> m.times(new DenseLocalOnHeapVector(m.columnSize() + 1)), desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void testTimesMatrix() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] data = fillAndReturn(m);
-
-            double[] arr = fillArray(m.columnSize());
-
-            Matrix mult = new DenseLocalOnHeapMatrix(m.columnSize(), 1);
-
-            mult.setColumn(0, arr);
-
-            Matrix times = m.times(mult);
-
-            assertEquals("Unexpected rows for " + desc, times.rowSize(), m.rowSize());
-
-            assertEquals("Unexpected cols for " + desc, times.columnSize(), 1);
-
-            for (int i = 0; i < m.rowSize(); i++) {
-                double exp = 0.0;
-
-                for (int j = 0; j < m.columnSize(); j++)
-                    exp += arr[j] * data[i][j];
-
-                assertEquals("Unexpected value for " + desc + " at " + i,
-                    exp, times.get(i, 0), 0d);
-            }
-
-            testInvalidCardinality(() -> m.times(new DenseLocalOnHeapMatrix(m.columnSize() + 1, 1)), desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void testDivide() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] data = fillAndReturn(m);
-
-            double divVal = Math.random();
-
-            Matrix divide = m.divide(divVal);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        data[i][j] / divVal, divide.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testTranspose() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            Matrix transpose = m.transpose();
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        m.get(i, j), transpose.get(j, i), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testDeterminant() {
-        consumeSampleMatrix((m, desc) -> {
-            if (m.rowSize() != m.columnSize())
-                return;
-
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] doubles = fillIntAndReturn(m);
-
-            if (m.rowSize() == 1) {
-                assertEquals("Unexpected value " + desc, m.determinant(), doubles[0][0], 0d);
-
-                return;
-            }
-
-            if (m.rowSize() == 2) {
-                double det = doubles[0][0] * doubles[1][1] - doubles[0][1] * doubles[1][0];
-                assertEquals("Unexpected value " + desc, m.determinant(), det, 0d);
-
-                return;
-            }
-
-            if (m.rowSize() > 512)
-                return; // IMPL NOTE if row size >= 30000 it takes unacceptably long for normal test run.
-
-            Matrix diagMtx = m.like(m.rowSize(), m.columnSize());
-
-            diagMtx.assign(0);
-            for (int i = 0; i < m.rowSize(); i++)
-                diagMtx.set(i, i, m.get(i, i));
-
-            double det = 1;
-
-            for (int i = 0; i < diagMtx.rowSize(); i++)
-                det *= diagMtx.get(i, i);
-
-            try {
-                assertEquals("Unexpected value " + desc, det, diagMtx.determinant(), DEFAULT_DELTA);
-            }
-            catch (Exception e) {
-                System.out.println(desc);
-                throw e;
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testInverse() {
-        consumeSampleMatrix((m, desc) -> {
-            if (m.rowSize() != m.columnSize())
-                return;
-
-            if (ignore(m.getClass()))
-                return;
-
-            if (m.rowSize() > 256)
-                return; // IMPL NOTE this is for quicker test run.
-
-            fillNonSingularMatrix(m);
-
-            assertTrue("Unexpected zero determinant " + desc, Math.abs(m.determinant()) > 0d);
-
-            Matrix inverse = m.inverse();
-
-            Matrix mult = m.times(inverse);
-
-            final double delta = 0.001d;
-
-            assertEquals("Unexpected determinant " + desc, 1d, mult.determinant(), delta);
-
-            assertEquals("Unexpected top left value " + desc, 1d, mult.get(0, 0), delta);
-
-            if (m.rowSize() == 1)
-                return;
-
-            assertEquals("Unexpected center value " + desc,
-                1d, mult.get(m.rowSize() / 2, m.rowSize() / 2), delta);
-
-            assertEquals("Unexpected bottom right value " + desc,
-                1d, mult.get(m.rowSize() - 1, m.rowSize() - 1), delta);
-
-            assertEquals("Unexpected top right value " + desc,
-                0d, mult.get(0, m.rowSize() - 1), delta);
-
-            assertEquals("Unexpected bottom left value " + desc,
-                0d, mult.get(m.rowSize() - 1, 0), delta);
-        });
-    }
-
-    /** */
-    @Test
-    public void testMap() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            m.map(x -> 10d);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        10d, m.get(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testMapMatrix() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            double[][] doubles = fillAndReturn(m);
-
-            testMapMatrixWrongCardinality(m, desc);
-
-            Matrix cp = m.copy();
-
-            m.map(cp, (m1, m2) -> m1 + m2);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        m.get(i, j), doubles[i][j] * 2, 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testViewRow() {
-        consumeSampleMatrix((m, desc) -> {
-            if (!readOnly(m))
-                fillMatrix(m);
-
-            for (int i = 0; i < m.rowSize(); i++) {
-                Vector vector = m.viewRow(i);
-                assert vector != null;
-
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        m.get(i, j), vector.get(j), 0d);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testViewCol() {
-        consumeSampleMatrix((m, desc) -> {
-            if (!readOnly(m))
-                fillMatrix(m);
-
-            for (int i = 0; i < m.columnSize(); i++) {
-                Vector vector = m.viewColumn(i);
-                assert vector != null;
-
-                for (int j = 0; j < m.rowSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")",
-                        m.get(j, i), vector.get(j), 0d);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testFoldRow() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            Vector foldRows = m.foldRows(Vector::sum);
-
-            for (int i = 0; i < m.rowSize(); i++) {
-                Double locSum = 0d;
-
-                for (int j = 0; j < m.columnSize(); j++)
-                    locSum += m.get(i, j);
-
-                assertEquals("Unexpected value for " + desc + " at " + i,
-                    foldRows.get(i), locSum, 0d);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testFoldCol() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            Vector foldCols = m.foldColumns(Vector::sum);
-
-            for (int j = 0; j < m.columnSize(); j++) {
-                Double locSum = 0d;
-
-                for (int i = 0; i < m.rowSize(); i++)
-                    locSum += m.get(i, j);
-
-                assertEquals("Unexpected value for " + desc + " at " + j,
-                    foldCols.get(j), locSum, 0d);
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void testSum() {
-        consumeSampleMatrix((m, desc) -> {
-            double[][] data = fillAndReturn(m);
-
-            double sum = m.sum();
-
-            double rawSum = 0;
-            for (double[] anArr : data)
-                for (int j = 0; j < data[0].length; j++)
-                    rawSum += anArr[j];
-
-            assertEquals("Unexpected value for " + desc,
-                rawSum, sum, 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testMax() {
-        consumeSampleMatrix((m, desc) -> {
-            double[][] doubles = fillAndReturn(m);
-            double max = Double.NEGATIVE_INFINITY;
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    max = max < doubles[i][j] ? doubles[i][j] : max;
-
-            assertEquals("Unexpected value for " + desc, m.maxValue(), max, 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testMin() {
-        consumeSampleMatrix((m, desc) -> {
-            double[][] doubles = fillAndReturn(m);
-            double min = Double.MAX_VALUE;
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    min = min > doubles[i][j] ? doubles[i][j] : min;
-
-            assertEquals("Unexpected value for " + desc, m.minValue(), min, 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testGetElement() {
-        consumeSampleMatrix((m, desc) -> {
-            if (!(readOnly(m)))
-                fillMatrix(m);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++) {
-                    final Matrix.Element e = m.getElement(i, j);
-
-                    final String details = desc + " at [" + i + "," + j + "]";
-
-                    assertEquals("Unexpected element row " + details, i, e.row());
-                    assertEquals("Unexpected element col " + details, j, e.column());
-
-                    final double val = m.get(i, j);
-
-                    assertEquals("Unexpected value for " + details, val, e.get(), 0d);
-
-                    boolean expECaught = false;
-
-                    final double newVal = val * 2.0;
-
-                    try {
-                        e.set(newVal);
-                    }
-                    catch (UnsupportedOperationException uoe) {
-                        if (!(readOnly(m)))
-                            throw uoe;
-
-                        expECaught = true;
-                    }
-
-                    if (readOnly(m)) {
-                        if (!expECaught)
-                            fail("Expected exception was not caught for " + details);
-
-                        continue;
-                    }
-
-                    assertEquals("Unexpected value set for " + details, newVal, m.get(i, j), 0d);
-                }
-        });
-    }
-
-    /** */
-    @Test
-    public void testGetX() {
-        consumeSampleMatrix((m, desc) -> {
-            if (!(readOnly(m)))
-                fillMatrix(m);
-
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    assertEquals("Unexpected value for " + desc + " at [" + i + "," + j + "]",
-                        m.get(i, j), m.getX(i, j), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testGetMetaStorage() {
-        consumeSampleMatrix((m, desc) -> assertNotNull("Null meta storage in " + desc, m.getMetaStorage()));
-    }
-
-    /** */
-    @Test
-    public void testGuid() {
-        consumeSampleMatrix((m, desc) -> assertNotNull("Null guid in " + desc, m.guid()));
-    }
-
-    /** */
-    @Test
-    public void testSwapRows() {
-        consumeSampleMatrix((m, desc) -> {
-            if (readOnly(m))
-                return;
-
-            double[][] doubles = fillAndReturn(m);
-
-            final int swap_i = m.rowSize() == 1 ? 0 : 1;
-            final int swap_j = 0;
-
-            Matrix swap = m.swapRows(swap_i, swap_j);
-
-            for (int col = 0; col < m.columnSize(); col++) {
-                assertEquals("Unexpected value for " + desc + " at col " + col + ", swap_i " + swap_i,
-                    swap.get(swap_i, col), doubles[swap_j][col], 0d);
-
-                assertEquals("Unexpected value for " + desc + " at col " + col + ", swap_j " + swap_j,
-                    swap.get(swap_j, col), doubles[swap_i][col], 0d);
-            }
-
-            testInvalidRowIndex(() -> m.swapRows(-1, 0), desc + " negative first swap index");
-            testInvalidRowIndex(() -> m.swapRows(0, -1), desc + " negative second swap index");
-            testInvalidRowIndex(() -> m.swapRows(m.rowSize(), 0), desc + " too large first swap index");
-            testInvalidRowIndex(() -> m.swapRows(0, m.rowSize()), desc + " too large second swap index");
-        });
-    }
-
-    /** */
-    @Test
-    public void testSwapColumns() {
-        consumeSampleMatrix((m, desc) -> {
-            if (readOnly(m))
-                return;
-
-            double[][] doubles = fillAndReturn(m);
-
-            final int swap_i = m.columnSize() == 1 ? 0 : 1;
-            final int swap_j = 0;
-
-            Matrix swap = m.swapColumns(swap_i, swap_j);
-
-            for (int row = 0; row < m.rowSize(); row++) {
-                assertEquals("Unexpected value for " + desc + " at row " + row + ", swap_i " + swap_i,
-                    swap.get(row, swap_i), doubles[row][swap_j], 0d);
-
-                assertEquals("Unexpected value for " + desc + " at row " + row + ", swap_j " + swap_j,
-                    swap.get(row, swap_j), doubles[row][swap_i], 0d);
-            }
-
-            testInvalidColIndex(() -> m.swapColumns(-1, 0), desc + " negative first swap index");
-            testInvalidColIndex(() -> m.swapColumns(0, -1), desc + " negative second swap index");
-            testInvalidColIndex(() -> m.swapColumns(m.columnSize(), 0), desc + " too large first swap index");
-            testInvalidColIndex(() -> m.swapColumns(0, m.columnSize()), desc + " too large second swap index");
-        });
-    }
-
-    /** */
-    @Test
-    public void testSetRow() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            int rowIdx = m.rowSize() / 2;
-
-            double[] newValues = fillArray(m.columnSize());
-
-            m.setRow(rowIdx, newValues);
-
-            for (int col = 0; col < m.columnSize(); col++)
-                assertEquals("Unexpected value for " + desc + " at " + col,
-                    newValues[col], m.get(rowIdx, col), 0d);
-
-            testInvalidCardinality(() -> m.setRow(rowIdx, new double[m.columnSize() + 1]), desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void testSetColumn() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            int colIdx = m.columnSize() / 2;
-
-            double[] newValues = fillArray(m.rowSize());
-
-            m.setColumn(colIdx, newValues);
-
-            for (int row = 0; row < m.rowSize(); row++)
-                assertEquals("Unexpected value for " + desc + " at " + row,
-                    newValues[row], m.get(row, colIdx), 0d);
-
-            testInvalidCardinality(() -> m.setColumn(colIdx, new double[m.rowSize() + 1]), desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void testViewPart() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            int rowOff = m.rowSize() < 3 ? 0 : 1;
-            int rows = m.rowSize() < 3 ? 1 : m.rowSize() - 2;
-            int colOff = m.columnSize() < 3 ? 0 : 1;
-            int cols = m.columnSize() < 3 ? 1 : m.columnSize() - 2;
-
-            Matrix view1 = m.viewPart(rowOff, rows, colOff, cols);
-            Matrix view2 = m.viewPart(new int[] {rowOff, colOff}, new int[] {rows, cols});
-
-            String details = desc + " view [" + rowOff + ", " + rows + ", " + colOff + ", " + cols + "]";
-
-            for (int i = 0; i < rows; i++)
-                for (int j = 0; j < cols; j++) {
-                    assertEquals("Unexpected view1 value for " + details + " at (" + i + "," + j + ")",
-                        m.get(i + rowOff, j + colOff), view1.get(i, j), 0d);
-
-                    assertEquals("Unexpected view2 value for " + details + " at (" + i + "," + j + ")",
-                        m.get(i + rowOff, j + colOff), view2.get(i, j), 0d);
-                }
-        });
-    }
-
-    /** */
-    @Test
-    public void testDensity() {
-        consumeSampleMatrix((m, desc) -> {
-            if (!readOnly(m))
-                fillMatrix(m);
-
-            assertTrue("Unexpected density with threshold 0 for " + desc, m.density(0.0));
-
-            assertFalse("Unexpected density with threshold 1 for " + desc, m.density(1.0));
-        });
-    }
-
-    /** */
-    @Test
-    public void testMaxAbsRowSumNorm() {
-        consumeSampleMatrix((m, desc) -> {
-            if (!readOnly(m))
-                fillMatrix(m);
-
-            assertEquals("Unexpected value for " + desc,
-                maxAbsRowSumNorm(m), m.maxAbsRowSumNorm(), 0d);
-        });
-    }
-
-    /** */
-    @Test
-    public void testAssignRow() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            int rowIdx = m.rowSize() / 2;
-
-            double[] newValues = fillArray(m.columnSize());
-
-            m.assignRow(rowIdx, new DenseLocalOnHeapVector(newValues));
-
-            for (int col = 0; col < m.columnSize(); col++)
-                assertEquals("Unexpected value for " + desc + " at " + col,
-                    newValues[col], m.get(rowIdx, col), 0d);
-
-            testInvalidCardinality(() -> m.assignRow(rowIdx, new DenseLocalOnHeapVector(m.columnSize() + 1)), desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void testAssignColumn() {
-        consumeSampleMatrix((m, desc) -> {
-            if (ignore(m.getClass()))
-                return;
-
-            fillMatrix(m);
-
-            int colIdx = m.columnSize() / 2;
-
-            double[] newValues = fillArray(m.rowSize());
-
-            m.assignColumn(colIdx, new DenseLocalOnHeapVector(newValues));
-
-            for (int row = 0; row < m.rowSize(); row++)
-                assertEquals("Unexpected value for " + desc + " at " + row,
-                    newValues[row], m.get(row, colIdx), 0d);
-        });
-    }
-
-    /** */
-    private double[] fillArray(int len) {
-        double[] newValues = new double[len];
-
-        for (int i = 0; i < newValues.length; i++)
-            newValues[i] = newValues.length - i;
-        return newValues;
-    }
-
-    /** */
-    private double maxAbsRowSumNorm(Matrix m) {
-        double max = 0.0;
-
-        for (int x = 0; x < m.rowSize(); x++) {
-            double sum = 0;
-
-            for (int y = 0; y < m.columnSize(); y++)
-                sum += Math.abs(m.getX(x, y));
-
-            if (sum > max)
-                max = sum;
-        }
-
-        return max;
-    }
-
-    /** */
-    private void testInvalidRowIndex(Supplier<Matrix> supplier, String desc) {
-        try {
-            supplier.get();
-        }
-        catch (RowIndexException | IndexException ie) {
-            return;
-        }
-
-        fail("Expected exception was not caught for " + desc);
-    }
-
-    /** */
-    private void testInvalidColIndex(Supplier<Matrix> supplier, String desc) {
-        try {
-            supplier.get();
-        }
-        catch (ColumnIndexException | IndexException ie) {
-            return;
-        }
-
-        fail("Expected exception was not caught for " + desc);
-    }
-
-    /** */
-    private void testMapMatrixWrongCardinality(Matrix m, String desc) {
-        for (int rowDelta : new int[] {-1, 0, 1})
-            for (int colDelta : new int[] {-1, 0, 1}) {
-                if (rowDelta == 0 && colDelta == 0)
-                    continue;
-
-                int rowNew = m.rowSize() + rowDelta;
-                int colNew = m.columnSize() + colDelta;
-
-                if (rowNew < 1 || colNew < 1)
-                    continue;
-
-                testInvalidCardinality(() -> m.map(new DenseLocalOnHeapMatrix(rowNew, colNew), (m1, m2) -> m1 + m2),
-                    desc + " wrong cardinality when mapping to size " + rowNew + "x" + colNew);
-            }
-    }
-
-    /** */
-    private void testInvalidCardinality(Supplier<Object> supplier, String desc) {
-        try {
-            supplier.get();
-        }
-        catch (CardinalityException ce) {
-            return;
-        }
-
-        fail("Expected exception was not caught for " + desc);
-    }
-
-    /** */
-    private boolean readOnly(Matrix m) {
-        return m instanceof RandomMatrix;
-    }
-
-    /** */
-    private double[][] fillIntAndReturn(Matrix m) {
-        double[][] data = new double[m.rowSize()][m.columnSize()];
-
-        if (readOnly(m)) {
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    data[i][j] = m.get(i, j);
-
-        }
-        else {
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    data[i][j] = i * m.rowSize() + j + 1;
-
-            m.assign(data);
-        }
-        return data;
-    }
-
-    /** */
-    private double[][] fillAndReturn(Matrix m) {
-        double[][] data = new double[m.rowSize()][m.columnSize()];
-
-        if (readOnly(m)) {
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    data[i][j] = m.get(i, j);
-
-        }
-        else {
-            for (int i = 0; i < m.rowSize(); i++)
-                for (int j = 0; j < m.columnSize(); j++)
-                    data[i][j] = -0.5d + Math.random();
-
-            m.assign(data);
-        }
-        return data;
-    }
-
-    /** */
-    private void fillNonSingularMatrix(Matrix m) {
-        for (int i = 0; i < m.rowSize(); i++) {
-            m.set(i, i, 10);
-
-            for (int j = 0; j < m.columnSize(); j++)
-                if (j != i)
-                    m.set(i, j, 0.01d);
-        }
-    }
-
-    /** */
-    private void fillMatrix(Matrix m) {
-        for (int i = 0; i < m.rowSize(); i++)
-            for (int j = 0; j < m.columnSize(); j++)
-                m.set(i, j, Math.random());
-    }
-
-    /** Ignore test for given matrix type. */
-    private boolean ignore(Class<? extends Matrix> clazz) {
-        List<Class<? extends Matrix>> ignoredClasses = Arrays.asList(RandomMatrix.class, PivotedMatrixView.class,
-            MatrixView.class, FunctionMatrix.class, TransposedMatrixView.class);
-
-        for (Class<? extends Matrix> ignoredClass : ignoredClasses)
-            if (ignoredClass.isAssignableFrom(clazz))
-                return true;
-
-        return false;
-    }
-
-    /** */
-    private Class<? extends Matrix> likeMatrixType(Matrix m) {
-        for (Class<? extends Matrix> clazz : likeTypesMap().keySet())
-            if (clazz.isAssignableFrom(m.getClass()))
-                return likeTypesMap().get(clazz);
-
-        return null;
-    }
-
-    /** */
-    private static Map<Class<? extends Matrix>, Class<? extends Vector>> likeVectorTypesMap() {
-        return new LinkedHashMap<Class<? extends Matrix>, Class<? extends Vector>>() {{
-            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapVector.class);
-            put(DenseLocalOffHeapMatrix.class, DenseLocalOffHeapVector.class);
-            put(RandomMatrix.class, RandomVector.class);
-            put(SparseLocalOnHeapMatrix.class, SparseLocalVector.class);
-            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapVector.class);
-            put(DiagonalMatrix.class, DenseLocalOnHeapVector.class); // IMPL NOTE per fixture
-            // IMPL NOTE check for presence of all implementations here will be done in testHaveLikeMatrix via Fixture
-        }};
-    }
-
-    /** */
-    private static Map<Class<? extends Matrix>, Class<? extends Matrix>> likeTypesMap() {
-        return new LinkedHashMap<Class<? extends Matrix>, Class<? extends Matrix>>() {{
-            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapMatrix.class);
-            put(DenseLocalOffHeapMatrix.class, DenseLocalOffHeapMatrix.class);
-            put(RandomMatrix.class, RandomMatrix.class);
-            put(SparseLocalOnHeapMatrix.class, SparseLocalOnHeapMatrix.class);
-            put(DenseLocalOnHeapMatrix.class, DenseLocalOnHeapMatrix.class);
-            put(DiagonalMatrix.class, DenseLocalOnHeapMatrix.class); // IMPL NOTE per fixture
-            put(FunctionMatrix.class, FunctionMatrix.class);
-            // IMPL NOTE check for presence of all implementations here will be done in testHaveLikeMatrix via Fixture
-        }};
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixKeyMapperForTests.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixKeyMapperForTests.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixKeyMapperForTests.java
deleted file mode 100644
index 90fbec4..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixKeyMapperForTests.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.MatrixKeyMapper;
-
-/** */
-public class MatrixKeyMapperForTests implements MatrixKeyMapper<Integer> {
-    /** */ private int rows;
-    /** */ private int cols;
-
-    /** */
-    public MatrixKeyMapperForTests() {
-        // No-op.
-    }
-
-    /** */
-    public MatrixKeyMapperForTests(int rows, int cols) {
-        this.rows = rows;
-        this.cols = cols;
-    }
-
-    /** */
-    @Override public Integer apply(int x, int y) {
-        return x * cols + y;
-    }
-
-    /** */
-    @Override public boolean isValid(Integer integer) {
-        return (rows * cols) > integer;
-    }
-
-    /** */
-    @Override public int hashCode() {
-        int hash = 1;
-
-        hash += hash * 31 + rows;
-        hash += hash * 31 + cols;
-
-        return hash;
-    }
-
-    /** */
-    @Override public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-
-        if (obj == null || getClass() != obj.getClass())
-            return false;
-
-        MatrixKeyMapperForTests that = (MatrixKeyMapperForTests)obj;
-
-        return rows == that.rows && cols == that.cols;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixViewConstructorTest.java
deleted file mode 100644
index 01278da..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixViewConstructorTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.storage.matrix.MatrixDelegateStorage;
-import org.junit.Test;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class MatrixViewConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        Matrix m = new DenseLocalOnHeapMatrix(1, 1);
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView((Matrix)null, 0, 0, 1, 1),
-            "Null parent matrix.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, -1, 0, 1, 1),
-            "Invalid row offset.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, 0, -1, 1, 1),
-            "Invalid col offset.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, 0, 0, 0, 1),
-            "Invalid rows.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new MatrixView(m, 0, 0, 1, 0),
-            "Invalid cols.");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        for (Matrix m : new Matrix[] {
-            new DenseLocalOnHeapMatrix(3, 3),
-            new DenseLocalOnHeapMatrix(3, 4), new DenseLocalOnHeapMatrix(4, 3)})
-            for (int rowOff : new int[] {0, 1})
-                for (int colOff : new int[] {0, 1})
-                    for (int rows : new int[] {1, 2})
-                        for (int cols : new int[] {1, 2})
-                            basicTest(m, rowOff, colOff, rows, cols);
-    }
-
-    /** */
-    private void basicTest(Matrix parent, int rowOff, int colOff, int rows, int cols) {
-        for (int row = 0; row < parent.rowSize(); row++)
-            for (int col = 0; col < parent.columnSize(); col++)
-                parent.set(row, col, row * parent.columnSize() + col + 1);
-
-        Matrix view = new MatrixView(parent, rowOff, colOff, rows, cols);
-
-        assertEquals("Rows in view.", rows, view.rowSize());
-        assertEquals("Cols in view.", cols, view.columnSize());
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++)
-                assertEquals("Unexpected value at " + row + "x" + col,
-                    parent.get(row + rowOff, col + colOff), view.get(row, col), 0d);
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++)
-                view.set(row, col, 0d);
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++)
-                assertEquals("Unexpected value set at " + row + "x" + col,
-                    0d, parent.get(row + rowOff, col + colOff), 0d);
-    }
-
-    /** */
-    @Test
-    public void attributeTest() {
-        for (Matrix m : new Matrix[] {
-            new DenseLocalOnHeapMatrix(3, 3),
-            new DenseLocalOnHeapMatrix(3, 4), new DenseLocalOnHeapMatrix(4, 3)}) {
-            MatrixView matrixView = new MatrixView(m, 0, 0, m.rowSize(), m.columnSize());
-
-            MatrixDelegateStorage delegateStorage = (MatrixDelegateStorage)matrixView.getStorage();
-
-            assertEquals(m.rowSize(), matrixView.rowSize());
-            assertEquals(m.columnSize(), matrixView.columnSize());
-
-            assertEquals(m.rowSize(), (delegateStorage).rowsLength());
-            assertEquals(m.columnSize(), (delegateStorage).columnsLength());
-
-            assertEquals(m.isSequentialAccess(), delegateStorage.isSequentialAccess());
-            assertEquals(m.isRandomAccess(), delegateStorage.isRandomAccess());
-            assertEquals(m.isDistributed(), delegateStorage.isDistributed());
-            assertEquals(m.isDense(), delegateStorage.isDense());
-            assertEquals(m.isArrayBased(), delegateStorage.isArrayBased());
-
-            assertArrayEquals(m.getStorage().data(), delegateStorage.data());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/PivotedMatrixViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/PivotedMatrixViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/PivotedMatrixViewConstructorTest.java
deleted file mode 100644
index a495745..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/PivotedMatrixViewConstructorTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.util.Arrays;
-import org.apache.ignite.math.Matrix;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class PivotedMatrixViewConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        Matrix m = new DenseLocalOnHeapMatrix(1, 1);
-
-        int[] pivot = new int[] {0};
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(null),
-            "Null parent matrix.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(null, pivot),
-            "Null parent matrix, with pivot.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(m, null),
-            "Null pivot.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(m, null, pivot),
-            "Null row pivot.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new PivotedMatrixView(m, pivot, null),
-            "Null col pivot.");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        Matrix m = new DenseLocalOnHeapMatrix(2, 2);
-
-        int[] pivot = new int[] {0, 1};
-
-        PivotedMatrixView view = new PivotedMatrixView(m, pivot);
-
-        assertEquals("Rows in view.", m.rowSize(), view.rowSize());
-        assertEquals("Cols in view.", m.columnSize(), view.columnSize());
-
-        assertTrue("Row pivot array in view.", Arrays.equals(pivot, view.rowPivot()));
-        assertTrue("Col pivot array in view.", Arrays.equals(pivot, view.columnPivot()));
-
-        assertEquals("Base matrix in view.", m, view.getBaseMatrix());
-
-        assertEquals("Row pivot value in view.", 0, view.rowPivot(0));
-        assertEquals("Col pivot value in view.", 0, view.columnPivot(0));
-
-        assertEquals("Row unpivot value in view.", 0, view.rowUnpivot(0));
-        assertEquals("Col unpivot value in view.", 0, view.columnUnpivot(0));
-
-        Matrix swap = view.swap(1, 1);
-
-        for (int row = 0; row < view.rowSize(); row++)
-            for (int col = 0; col < view.columnSize(); col++)
-                assertEquals("Unexpected swap value set at (" + row + "," + col + ").",
-                    view.get(row, col), swap.get(row, col), 0d);
-
-        //noinspection EqualsWithItself
-        assertTrue("View is expected to be equal to self.", view.equals(view));
-        //noinspection ObjectEqualsNull
-        assertFalse("View is expected to be not equal to null.", view.equals(null));
-    }
-
-    /** */
-    @Test
-    public void pivotTest() {
-        int[] pivot = new int[] {2, 1, 0, 3};
-
-        for (Matrix m : new Matrix[] {
-            new DenseLocalOnHeapMatrix(3, 3),
-            new DenseLocalOnHeapMatrix(3, 4), new DenseLocalOnHeapMatrix(4, 3)})
-            pivotTest(m, pivot);
-    }
-
-    /** */
-    private void pivotTest(Matrix parent, int[] pivot) {
-        for (int row = 0; row < parent.rowSize(); row++)
-            for (int col = 0; col < parent.columnSize(); col++)
-                parent.set(row, col, row * parent.columnSize() + col + 1);
-
-        Matrix view = new PivotedMatrixView(parent, pivot);
-
-        int rows = parent.rowSize();
-        int cols = parent.columnSize();
-
-        assertEquals("Rows in view.", rows, view.rowSize());
-        assertEquals("Cols in view.", cols, view.columnSize());
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++)
-                assertEquals("Unexpected value at " + row + "x" + col,
-                    parent.get(pivot[row], pivot[col]), view.get(row, col), 0d);
-
-        int min = rows < cols ? rows : cols;
-
-        for (int idx = 0; idx < min; idx++)
-            view.set(idx, idx, 0d);
-
-        for (int idx = 0; idx < min; idx++)
-            assertEquals("Unexpected value set at " + idx,
-                0d, parent.get(pivot[idx], pivot[idx]), 0d);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/RandomMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/RandomMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/RandomMatrixConstructorTest.java
deleted file mode 100644
index e19cfa3..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/RandomMatrixConstructorTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class RandomMatrixConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(0, 1), "invalid row parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(1, 0), "invalid col parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(0, 1, true), "invalid row parameter, fastHash true");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(1, 0, true), "invalid col parameter, fastHash true");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(0, 1, false), "invalid row parameter, fastHash false");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new RandomMatrix(1, 0, false), "invalid col parameter, fastHash false");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        assertEquals("Expected number of rows, int parameters.", 1,
-            new RandomMatrix(1, 2).rowSize());
-
-        assertEquals("Expected number of cols, int parameters.", 1,
-            new RandomMatrix(2, 1).columnSize());
-
-        assertEquals("Expected number of rows, int parameters, fastHash true.", 1,
-            new RandomMatrix(1, 2, true).rowSize());
-
-        assertEquals("Expected number of cols, int parameters, fastHash true.", 1,
-            new RandomMatrix(2, 1, true).columnSize());
-
-        assertEquals("Expected number of rows, int parameters, fastHash false.", 1,
-            new RandomMatrix(1, 2, false).rowSize());
-
-        assertEquals("Expected number of cols, int parameters, fastHash false.", 1,
-            new RandomMatrix(2, 1, false).columnSize());
-
-        RandomMatrix m = new RandomMatrix(1, 1);
-        //noinspection EqualsWithItself
-        assertTrue("Matrix is expected to be equal to self.", m.equals(m));
-        //noinspection ObjectEqualsNull
-        assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java
deleted file mode 100644
index 8218a12..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java
+++ /dev/null
@@ -1,265 +0,0 @@
-// @java.file.header
-
-/*  _________        _____ __________________        _____
- *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
- *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
- *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
- *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
- */
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-import static org.apache.ignite.math.impls.MathTestConstants.UNEXPECTED_VAL;
-
-/**
- * Tests for {@link SparseDistributedMatrix}.
- */
-@GridCommonTest(group = "Distributed Models")
-public class SparseDistributedMatrixTest extends GridCommonAbstractTest {
-    /** Number of nodes in grid */
-    private static final int NODE_COUNT = 3;
-    /** Cache name. */
-    private static final String CACHE_NAME = "test-cache";
-    /** Precision. */
-    private static final double PRECISION = 0.0;
-    /** Grid instance. */
-    private Ignite ignite;
-    /** Matrix rows */
-    private final int rows = MathTestConstants.STORAGE_SIZE;
-    /** Matrix cols */
-    private final int cols = MathTestConstants.STORAGE_SIZE;
-    /** Matrix for tests */
-    private SparseDistributedMatrix cacheMatrix;
-
-    /**
-     * Default constructor.
-     */
-    public SparseDistributedMatrixTest() {
-        super(false);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        for (int i = 1; i <= NODE_COUNT; i++)
-            startGrid(i);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override protected void beforeTest() throws Exception {
-        ignite = grid(NODE_COUNT);
-
-        ignite.configuration().setPeerClassLoadingEnabled(true);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        ignite.destroyCache(CACHE_NAME);
-
-        if (cacheMatrix != null) {
-            cacheMatrix.destroy();
-            cacheMatrix = null;
-        }
-    }
-
-    /** */
-    public void testGetSet() throws Exception {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        for (int i = 0; i < rows; i++) {
-            for (int j = 0; j < cols; j++) {
-                double v = Math.random();
-                cacheMatrix.set(i, j, v);
-
-                assert Double.compare(v, cacheMatrix.get(i, j)) == 0;
-            }
-        }
-    }
-
-    /** */
-    public void testExternalize() throws IOException, ClassNotFoundException {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        cacheMatrix.set(1, 1, 1.0);
-
-        ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
-        ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
-
-        objOutputStream.writeObject(cacheMatrix);
-
-        ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
-        ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
-
-        SparseDistributedMatrix objRestored = (SparseDistributedMatrix)objInputStream.readObject();
-
-        assertTrue(MathTestConstants.VAL_NOT_EQUALS, cacheMatrix.equals(objRestored));
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, objRestored.get(1, 1), 1.0, 0.0);
-    }
-
-    /** Test simple math. */
-    public void testMath() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-        initMtx(cacheMatrix);
-
-        cacheMatrix.assign(2.0);
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                assertEquals(UNEXPECTED_VAL, 2.0, cacheMatrix.get(i, j), PRECISION);
-
-        cacheMatrix.plus(3.0);
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                assertEquals(UNEXPECTED_VAL, 5.0, cacheMatrix.get(i, j), PRECISION);
-
-        cacheMatrix.times(2.0);
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                assertEquals(UNEXPECTED_VAL, 10.0, cacheMatrix.get(i, j), PRECISION);
-
-        cacheMatrix.divide(10.0);
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                assertEquals(UNEXPECTED_VAL, 1.0, cacheMatrix.get(i, j), PRECISION);
-
-        assertEquals(UNEXPECTED_VAL, cacheMatrix.rowSize() * cacheMatrix.columnSize(), cacheMatrix.sum(), PRECISION);
-    }
-
-    /** */
-    public void testMinMax() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                cacheMatrix.set(i, j, i * cols + j + 1);
-
-        assertEquals(UNEXPECTED_VAL, 1.0, cacheMatrix.minValue(), PRECISION);
-        assertEquals(UNEXPECTED_VAL, rows * cols, cacheMatrix.maxValue(), PRECISION);
-
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                cacheMatrix.set(i, j, -1.0 * (i * cols + j + 1));
-
-        assertEquals(UNEXPECTED_VAL, -rows * cols, cacheMatrix.minValue(), PRECISION);
-        assertEquals(UNEXPECTED_VAL, -1.0, cacheMatrix.maxValue(), PRECISION);
-
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                cacheMatrix.set(i, j, i * cols + j);
-
-        assertEquals(UNEXPECTED_VAL, 1.0, cacheMatrix.minValue(), PRECISION);
-        assertEquals(UNEXPECTED_VAL, rows * cols - 1.0, cacheMatrix.maxValue(), PRECISION);
-    }
-
-    /** */
-    public void testMap() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-        initMtx(cacheMatrix);
-
-        cacheMatrix.map(i -> 100.0);
-        for (int i = 0; i < cacheMatrix.rowSize(); i++)
-            for (int j = 0; j < cacheMatrix.columnSize(); j++)
-                assertEquals(UNEXPECTED_VAL, 100.0, cacheMatrix.get(i, j), PRECISION);
-    }
-
-    /** */
-    public void testCopy() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        try {
-            cacheMatrix.copy();
-            fail("UnsupportedOperationException expected.");
-        }
-        catch (UnsupportedOperationException e) {
-            return;
-        }
-        fail("UnsupportedOperationException expected.");
-    }
-
-    /** */
-    public void testLike() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        try {
-            cacheMatrix.like(1, 1);
-            fail("UnsupportedOperationException expected.");
-        }
-        catch (UnsupportedOperationException e) {
-            return;
-        }
-        fail("UnsupportedOperationException expected.");
-    }
-
-    /** */
-    public void testLikeVector() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
-        try {
-            cacheMatrix.likeVector(1);
-            fail("UnsupportedOperationException expected.");
-        }
-        catch (UnsupportedOperationException e) {
-            return;
-        }
-        fail("UnsupportedOperationException expected.");
-    }
-
-    /** */
-    private void initMtx(Matrix m) {
-        for (int i = 0; i < m.rowSize(); i++)
-            for (int j = 0; j < m.columnSize(); j++)
-                m.set(i, j, 1.0);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
deleted file mode 100644
index fc675c1..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class SparseLocalOnHeapMatrixConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new SparseLocalOnHeapMatrix(0, 1),
-            "invalid row parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new SparseLocalOnHeapMatrix(1, 0),
-            "invalid col parameter");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        assertEquals("Expected number of rows.", 1,
-            new SparseLocalOnHeapMatrix(1, 2).rowSize());
-
-        assertEquals("Expected number of cols, int parameters.", 1,
-            new SparseLocalOnHeapMatrix(2, 1).columnSize());
-
-        SparseLocalOnHeapMatrix m = new SparseLocalOnHeapMatrix(1, 1);
-        //noinspection EqualsWithItself
-        assertTrue("Matrix is expected to be equal to self.", m.equals(m));
-        //noinspection ObjectEqualsNull
-        assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java
deleted file mode 100644
index 5eacfea..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Tests for {@link TransposedMatrixView}.
- */
-public class TransposedMatrixViewTest extends ExternalizeTest<TransposedMatrixView> {
-    /** */
-    private static final String UNEXPECTED_VALUE = "Unexpected value";
-    /** */
-    private TransposedMatrixView testMatrix;
-    /** */
-    private DenseLocalOnHeapMatrix parent;
-
-    /** */
-    @Before
-    public void setup() {
-        parent = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
-        fillMatrix(parent);
-        testMatrix = new TransposedMatrixView(parent);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void externalizeTest() {
-        externalizeTest(testMatrix);
-    }
-
-    /** */
-    @Test
-    public void testView() {
-        assertEquals(UNEXPECTED_VALUE, parent.rowSize(), testMatrix.columnSize());
-        assertEquals(UNEXPECTED_VALUE, parent.columnSize(), testMatrix.rowSize());
-
-        for (int i = 0; i < parent.rowSize(); i++)
-            for (int j = 0; j < parent.columnSize(); j++)
-                assertEquals(UNEXPECTED_VALUE, parent.get(i, j), testMatrix.get(j, i), 0d);
-    }
-
-    /** */
-    @Test
-    public void testNullParams() {
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new TransposedMatrixView(null), "Null Matrix parameter");
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void testLike() {
-        testMatrix.like(0, 0);
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void testLikeVector() {
-        testMatrix.likeVector(0);
-    }
-
-    /** */
-    private void fillMatrix(DenseLocalOnHeapMatrix mtx) {
-        for (int i = 0; i < mtx.rowSize(); i++)
-            for (int j = 0; j < mtx.columnSize(); j++)
-                mtx.setX(i, j, i * mtx.rowSize() + j);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java
deleted file mode 100644
index 817dd49..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit tests for {@link ArrayMatrixStorage}.
- */
-public class MatrixArrayStorageTest extends MatrixBaseStorageTest<ArrayMatrixStorage> {
-    /** {@inheritDoc} */
-    @Override public void setUp() {
-        storage = new ArrayMatrixStorage(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void isSequentialAccess() throws Exception {
-        assertFalse(MathTestConstants.UNEXPECTED_VAL, storage.isSequentialAccess());
-    }
-
-    /** */
-    @Test
-    public void isDense() throws Exception {
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isDense());
-    }
-
-    /** */
-    @Test
-    public void isArrayBased() throws Exception {
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, storage.isArrayBased());
-    }
-
-    /** */
-    @Test
-    public void data() throws Exception {
-        double[][] data = storage.data();
-        assertNotNull(MathTestConstants.NULL_VAL, data);
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, data.length == MathTestConstants.STORAGE_SIZE);
-        assertTrue(MathTestConstants.UNEXPECTED_VAL, data[0].length == MathTestConstants.STORAGE_SIZE);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java
deleted file mode 100644
index 8df19e4..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Abstract class with base tests for each matrix storage.
- */
-public abstract class MatrixBaseStorageTest<T extends MatrixStorage> extends ExternalizeTest<T> {
-    /** */
-    protected T storage;
-
-    /** */
-    @Before
-    public abstract void setUp();
-
-    /** */
-    @After
-    public void tearDown() throws Exception {
-        storage.destroy();
-    }
-
-    /** */
-    @Test
-    public void getSet() throws Exception {
-        int rows = MathTestConstants.STORAGE_SIZE;
-        int cols = MathTestConstants.STORAGE_SIZE;
-
-        for (int i = 0; i < rows; i++) {
-            for (int j = 0; j < cols; j++) {
-                double data = Math.random();
-
-                storage.set(i, j, data);
-
-                Assert.assertEquals(MathTestConstants.VAL_NOT_EQUALS, storage.get(i, j), data, MathTestConstants.NIL_DELTA);
-            }
-        }
-    }
-
-    /** */
-    @Test
-    public void columnSize() throws Exception {
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, storage.columnSize(), MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void rowSize() throws Exception {
-        assertEquals(MathTestConstants.VAL_NOT_EQUALS, storage.rowSize(), MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Override public void externalizeTest() {
-        fillMatrix();
-        super.externalizeTest(storage);
-    }
-
-    /** */
-    protected void fillMatrix() {
-        for (int i = 0; i < storage.rowSize(); i++) {
-            for (int j = 0; j < storage.columnSize(); j++)
-                storage.set(i, j, Math.random());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
deleted file mode 100644
index a3b21bb..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNull;
-
-/**
- * Unit tests for {@link DenseOffHeapMatrixStorage}.
- */
-public class MatrixOffHeapStorageTest extends MatrixBaseStorageTest<DenseOffHeapMatrixStorage> {
-    /** {@inheritDoc} */
-    @Override public void setUp() {
-        storage = new DenseOffHeapMatrixStorage(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
-    }
-
-    /** */
-    @Test
-    public void data() throws Exception {
-        assertNull(MathTestConstants.UNEXPECTED_VAL, storage.data());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java
deleted file mode 100644
index 6353c38..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.function.BiConsumer;
-import java.util.function.Supplier;
-import org.apache.ignite.math.MatrixStorage;
-import org.jetbrains.annotations.NotNull;
-
-import static org.apache.ignite.math.StorageConstants.COLUMN_STORAGE_MODE;
-import static org.apache.ignite.math.StorageConstants.RANDOM_ACCESS_MODE;
-import static org.apache.ignite.math.StorageConstants.ROW_STORAGE_MODE;
-import static org.apache.ignite.math.StorageConstants.SEQUENTIAL_ACCESS_MODE;
-
-/**
- *
- */
-class MatrixStorageFixtures {
-    /** */
-    private static final List<Supplier<Iterable<MatrixStorage>>> suppliers = Collections.singletonList(
-        (Supplier<Iterable<MatrixStorage>>) SparseLocalMatrixStorageFixture::new
-    );
-
-    /** */
-    void consumeSampleStorages(BiConsumer<Integer, Integer> paramsConsumer,
-        BiConsumer<MatrixStorage, String> consumer) {
-        for (Supplier<Iterable<MatrixStorage>> fixtureSupplier : suppliers) {
-            final Iterable<MatrixStorage> fixture = fixtureSupplier.get();
-
-            for (MatrixStorage matrixStorage : fixture) {
-                if (paramsConsumer != null)
-                    paramsConsumer.accept(matrixStorage.rowSize(), matrixStorage.columnSize());
-
-                consumer.accept(matrixStorage, fixture.toString());
-            }
-        }
-    }
-
-    /** */
-    private static class SparseLocalMatrixStorageFixture implements Iterable<MatrixStorage> {
-        /** */
-        private final Integer[] rows = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 1024, null};
-        /** */
-        private final Integer[] cols = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1024, 512, null};
-        /** */
-        private final Integer[] randomAccess = new Integer[] {SEQUENTIAL_ACCESS_MODE, RANDOM_ACCESS_MODE, null};
-        /** */
-        private final Integer[] rowStorage = new Integer[] {ROW_STORAGE_MODE, COLUMN_STORAGE_MODE, null};
-        /** */
-        private int sizeIdx = 0;
-        /** */
-        private int acsModeIdx = 0;
-        /** */
-        private int stoModeIdx = 0;
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<MatrixStorage> iterator() {
-            return new Iterator<MatrixStorage>() {
-                /** {@inheritDoc} */
-                @Override public boolean hasNext() {
-                    return hasNextCol(sizeIdx) && hasNextRow(sizeIdx)
-                        && hasNextAcsMode(acsModeIdx) && hasNextStoMode(stoModeIdx);
-                }
-
-                /** {@inheritDoc} */
-                @Override public MatrixStorage next() {
-                    if (!hasNext())
-                        throw new NoSuchElementException(SparseLocalMatrixStorageFixture.this.toString());
-
-                    MatrixStorage storage = new SparseLocalOnHeapMatrixStorage(
-                        rows[sizeIdx], cols[sizeIdx], randomAccess[acsModeIdx], rowStorage[stoModeIdx]);
-
-                    nextIdx();
-
-                    return storage;
-                }
-
-                private void nextIdx() {
-                    if (hasNextStoMode(stoModeIdx + 1)) {
-                        stoModeIdx++;
-
-                        return;
-                    }
-
-                    stoModeIdx = 0;
-
-                    if (hasNextAcsMode(acsModeIdx + 1)) {
-                        acsModeIdx++;
-
-                        return;
-                    }
-
-                    acsModeIdx = 0;
-                    sizeIdx++;
-                }
-            };
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "SparseLocalMatrixStorageFixture{ " + "rows=" + rows[sizeIdx] + ", cols=" + cols[sizeIdx] +
-                ", access mode=" + randomAccess[acsModeIdx] + ", storage mode=" + rowStorage[stoModeIdx] + "}";
-        }
-
-        /** */ private boolean hasNextRow(int idx) {
-            return rows[idx] != null;
-        }
-
-        /** */ private boolean hasNextCol(int idx) {
-            return cols[idx] != null;
-        }
-
-        /** */ private boolean hasNextAcsMode(int idx) {
-            return randomAccess[idx] != null;
-        }
-
-        /** */ private boolean hasNextStoMode(int idx) {
-            return rowStorage[idx] != null;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java
deleted file mode 100644
index 6ec09bd..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.BiConsumer;
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.MatrixStorage;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit tests for {@link MatrixStorage} implementations.
- *
- * TODO: add attribute tests.
- */
-public class MatrixStorageImplementationTest extends ExternalizeTest<MatrixStorage> {
-    /**
-     * The columnSize() and the rowSize() test.
-     */
-    @Test
-    public void sizeTest() {
-        final AtomicReference<Integer> expRowSize = new AtomicReference<>(0);
-        final AtomicReference<Integer> expColSize = new AtomicReference<>(0);
-
-        consumeSampleStorages((x, y) -> {
-                expRowSize.set(x);
-                expColSize.set(y);
-            },
-            (ms, desc) -> assertTrue("Expected size for " + desc, expColSize.get().equals(ms.columnSize()) && expRowSize.get().equals(ms.rowSize())));
-    }
-
-    /** */
-    @Test
-    public void getSetTest() {
-        consumeSampleStorages(null, (ms, desc) -> {
-            for (int i = 0; i < ms.rowSize(); i++) {
-                for (int j = 0; j < ms.columnSize(); j++) {
-                    double random = Math.random();
-                    ms.set(i, j, random);
-                    assertTrue("Unexpected value for " + desc + " x:" + i + ", y:" + j, Double.compare(random, ms.get(i, j)) == 0);
-                }
-            }
-        });
-    }
-
-    /** */
-    @Override public void externalizeTest() {
-        consumeSampleStorages(null, (ms, desc) -> externalizeTest(ms));
-    }
-
-    /** */
-    private void consumeSampleStorages(BiConsumer<Integer, Integer> paramsConsumer,
-        BiConsumer<MatrixStorage, String> consumer) {
-        new MatrixStorageFixtures().consumeSampleStorages(paramsConsumer, consumer);
-    }
-}


[41/50] [abbrv] ignite git commit: Attempt to fix awaitPartitionMapExchange: wait for last exchange completion to avoid races with cache destroy.

Posted by sb...@apache.org.
Attempt to fix awaitPartitionMapExchange: wait for last exchange completion to avoid races with cache destroy.


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

Branch: refs/heads/ignite-1561
Commit: d38348432a2b8b66999c6410ec4f5c1ef050191d
Parents: 36e7e19
Author: sboikov <sb...@gridgain.com>
Authored: Wed Apr 19 12:46:31 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Apr 19 12:46:31 2017 +0300

----------------------------------------------------------------------
 .../junits/common/GridCommonAbstractTest.java   | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d3834843/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index 81f5caf..cef35e5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
@@ -544,6 +544,27 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
 
         Set<String> names = new HashSet<>();
 
+        Ignite crd = null;
+
+        for (Ignite g : G.allGrids()) {
+            ClusterNode node = g.cluster().localNode();
+
+            if (crd == null || node.order() < crd.cluster().localNode().order()) {
+                crd = g;
+
+                if (node.order() == 1)
+                    break;
+            }
+        }
+
+        if (crd == null)
+            return;
+
+        AffinityTopologyVersion waitTopVer = ((IgniteKernal)crd).context().discovery().topologyVersionEx();
+
+        if (waitTopVer.topologyVersion() <= 0)
+            waitTopVer = new AffinityTopologyVersion(1, 0);
+
         for (Ignite g : G.allGrids()) {
             if (nodes != null && !nodes.contains(g.cluster().localNode()))
                 continue;
@@ -560,6 +581,19 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
             else
                 startTime = g0.context().discovery().gridStartTime();
 
+            IgniteInternalFuture<?> exchFut =
+                g0.context().cache().context().exchange().affinityReadyFuture(waitTopVer);
+
+            if (exchFut != null && !exchFut.isDone()) {
+                try {
+                    exchFut.get(timeout);
+                }
+                catch (IgniteCheckedException e) {
+                    log.error("Failed to wait for exchange [topVer=" + waitTopVer +
+                        ", node=" + g0.name() + ']', e);
+                }
+            }
+
             for (IgniteCacheProxy<?, ?> c : g0.context().cache().jcaches()) {
                 CacheConfiguration cfg = c.context().config();
 


[30/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalReplicatedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalReplicatedSelfTest.java
new file mode 100644
index 0000000..85a8837
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalReplicatedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class H2DynamicIndexTransactionalReplicatedSelfTest extends H2DynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
new file mode 100644
index 0000000..95ad2f1
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
@@ -0,0 +1,589 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.IgniteClientDisconnectedException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.GridTestUtils;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Tests for schema exchange between nodes.
+ */
+public class SchemaExchangeSelfTest extends AbstractSchemaSelfTest {
+    /** Node on which filter should be applied (if any). */
+    private static String filterNodeName;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        filterNodeName = null;
+
+        super.afterTest();
+    }
+
+    /**
+     * Test propagation of empty query schema for static cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testEmptyStatic() throws Exception {
+        checkEmpty(false);
+    }
+
+    /**
+     * Test propagation of empty query schema for dynamic cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testEmptyDynamic() throws Exception {
+        checkEmpty(true);
+    }
+
+    /**
+     * Check empty metadata propagation.
+     *
+     * @param dynamic Dynamic start flag.
+     * @throws Exception If failed.
+     */
+    private void checkEmpty(boolean dynamic) throws Exception {
+        IgniteEx node1;
+
+        if (dynamic) {
+            node1 = startNoCache(1);
+
+            node1.getOrCreateCache(cacheConfiguration());
+        }
+        else
+            node1 = start(1);
+
+        assertTypes(node1);
+
+        IgniteEx node2 = start(2, KeyClass.class, ValueClass.class);
+
+        assertTypes(node1);
+        assertTypes(node2);
+
+        IgniteEx node3 = start(3, KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
+
+        assertTypes(node1);
+        assertTypes(node2);
+        assertTypes(node3);
+    }
+
+    /**
+     * Test propagation of non-empty query schema for static cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNonEmptyStatic() throws Exception {
+        checkNonEmpty(false);
+    }
+
+    /**
+     * Test propagation of non-empty query schema for dynamic cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNonEmptyDynamic() throws Exception {
+        checkNonEmpty(true);
+    }
+
+    /**
+     * Check \u0442\u0449\u0442-empty metadata propagation.
+     *
+     * @param dynamic Dynamic start flag.
+     * @throws Exception If failed.
+     */
+    private void checkNonEmpty(boolean dynamic) throws Exception {
+        IgniteEx node1;
+
+        if (dynamic) {
+            node1 = startNoCache(1);
+
+            node1.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class));
+        }
+        else
+            node1 = start(1, KeyClass.class, ValueClass.class);
+
+        assertTypes(node1, ValueClass.class);
+
+        IgniteEx node2 = start(2);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+
+        IgniteEx node3 = start(3, KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+        assertTypes(node3, ValueClass.class);
+    }
+
+    /**
+     * Make sure that new metadata can be propagated after destroy.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDynamicRestarts() throws Exception {
+        IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
+        IgniteEx node2 = startNoCache(2);
+        IgniteEx node3 = startClientNoCache(3);
+        IgniteEx node4 = startClientNoCache(4);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+
+        assertTypes(node3);
+
+        node3.cache(CACHE_NAME);
+        assertTypes(node3, ValueClass.class);
+
+        // Check restarts from the first node.
+        node1.destroyCache(CACHE_NAME);
+
+        node1.getOrCreateCache(cacheConfiguration());
+
+        assertTypes(node1);
+        assertTypes(node2);
+        assertTypes(node3);
+
+        node1.destroyCache(CACHE_NAME);
+
+        node1.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class,
+            KeyClass2.class, ValueClass2.class));
+
+        assertTypes(node1, ValueClass.class, ValueClass2.class);
+        assertTypes(node2, ValueClass.class, ValueClass2.class);
+
+        assertTypes(node3);
+
+        node3.cache(CACHE_NAME);
+        assertTypes(node3, ValueClass.class, ValueClass2.class);
+
+        // Check restarts from the second node.
+        node2.destroyCache(CACHE_NAME);
+
+        node2.getOrCreateCache(cacheConfiguration());
+
+        assertTypes(node1);
+        assertTypes(node2);
+        assertTypes(node3);
+
+        node2.destroyCache(CACHE_NAME);
+
+        node2.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class,
+            KeyClass2.class, ValueClass2.class));
+
+        assertTypes(node1, ValueClass.class, ValueClass2.class);
+        assertTypes(node2, ValueClass.class, ValueClass2.class);
+
+        assertTypes(node3);
+
+        node3.cache(CACHE_NAME);
+        assertTypes(node3, ValueClass.class, ValueClass2.class);
+
+        assertTypes(node4);
+
+        node4.cache(CACHE_NAME);
+        assertTypes(node4, ValueClass.class, ValueClass2.class);
+
+        // Make sure that joining node observes correct state.
+        assertTypes(start(5), ValueClass.class, ValueClass2.class);
+        assertTypes(startNoCache(6), ValueClass.class, ValueClass2.class);
+
+        assertTypes(startClient(7), ValueClass.class, ValueClass2.class);
+
+        IgniteEx node8 = startClientNoCache(8);
+
+        assertTypes(node8);
+
+        node8.cache(CACHE_NAME);
+        assertTypes(node8, ValueClass.class, ValueClass2.class);
+    }
+
+    /**
+     * Test client join for static cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testClientJoinStatic() throws Exception {
+        checkClientJoin(false);
+    }
+
+    /**
+     * Test client join for dynamic cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testClientJoinDynamic() throws Exception {
+        checkClientJoin(true);
+    }
+
+    /**
+     * Check client join.
+     *
+     * @throws Exception If failed.
+     */
+    private void checkClientJoin(boolean dynamic) throws Exception {
+        IgniteEx node1;
+
+        if (dynamic) {
+            node1 = startNoCache(1);
+
+            node1.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class));
+        }
+        else
+            node1 = start(1, KeyClass.class, ValueClass.class);
+
+        IgniteEx node2 = startClient(2);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+
+        IgniteEx node3 = startClient(3, KeyClass.class, ValueClass.class,
+            KeyClass2.class, ValueClass2.class);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+        assertTypes(node3, ValueClass.class);
+
+        IgniteEx node4 = startClientNoCache(4);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+        assertTypes(node3, ValueClass.class);
+
+        assertTypes(node4);
+
+        node4.cache(CACHE_NAME);
+        assertTypes(node4, ValueClass.class);
+    }
+
+    /**
+     * Test client cache start (static).
+     *
+     * @throws Exception If failed.
+     */
+    public void testClientCacheStartStatic() throws Exception {
+        checkClientCacheStart(false);
+    }
+
+    /**
+     * Test client cache start (dynamic).
+     *
+     * @throws Exception If failed.
+     */
+    public void testClientCacheStartDynamic() throws Exception {
+        checkClientCacheStart(true);
+    }
+
+    /**
+     * Check client cache start.
+     *
+     * @throws Exception If failed.
+     */
+    private void checkClientCacheStart(boolean dynamic) throws Exception {
+        IgniteEx node1 = startNoCache(1);
+
+        IgniteEx node2;
+
+        if (dynamic) {
+            node2 = startClientNoCache(2);
+
+            node2.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class));
+        }
+        else
+            node2 = startClient(2, KeyClass.class, ValueClass.class);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+
+        IgniteEx node3 = start(3);
+        IgniteEx node4 = start(4,  KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
+        IgniteEx node5 = startNoCache(5);
+
+        IgniteEx node6 = startClient(6);
+        IgniteEx node7 = startClient(7,  KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
+        IgniteEx node8 = startClientNoCache(8);
+
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+        assertTypes(node3, ValueClass.class);
+        assertTypes(node4, ValueClass.class);
+        assertTypes(node5, ValueClass.class);
+        assertTypes(node6, ValueClass.class);
+        assertTypes(node7, ValueClass.class);
+
+        assertTypes(node8);
+        node8.cache(CACHE_NAME);
+        assertTypes(node8, ValueClass.class);
+
+        node2.destroyCache(CACHE_NAME);
+        node2.getOrCreateCache(
+            cacheConfiguration(KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class));
+
+        assertTypes(node1, ValueClass.class, ValueClass2.class);
+        assertTypes(node2, ValueClass.class, ValueClass2.class);
+        assertTypes(node3, ValueClass.class, ValueClass2.class);
+        assertTypes(node4, ValueClass.class, ValueClass2.class);
+        assertTypes(node5, ValueClass.class, ValueClass2.class);
+
+        assertTypes(node6);
+        assertTypes(node7);
+        assertTypes(node8);
+
+        node6.cache(CACHE_NAME);
+        node7.cache(CACHE_NAME);
+        node8.cache(CACHE_NAME);
+
+        assertTypes(node6, ValueClass.class, ValueClass2.class);
+        assertTypes(node7, ValueClass.class, ValueClass2.class);
+        assertTypes(node8, ValueClass.class, ValueClass2.class);
+    }
+
+    /**
+     * Test behavior when node filter is set.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNodeFilter() throws Exception {
+        filterNodeName = getTestIgniteInstanceName(1);
+
+        IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
+        assertTypes(node1, ValueClass.class);
+
+        IgniteEx node2 = start(2, KeyClass.class, ValueClass.class);
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+
+        IgniteEx node3 = startNoCache(3);
+        assertTypes(node1, ValueClass.class);
+        assertTypes(node2, ValueClass.class);
+
+        assertTypes(node3);
+
+        node3.cache(CACHE_NAME);
+        assertTypes(node3, ValueClass.class);
+    }
+
+    /**
+     * Test client reconnect.
+     *
+     * @throws Exception If failed.
+     */
+    public void testClientReconnect() throws Exception {
+        IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
+        assertTypes(node1, ValueClass.class);
+
+        IgniteEx node2 = startClientNoCache(2);
+        assertTypes(node2);
+
+        node2.cache(CACHE_NAME);
+        assertTypes(node2, ValueClass.class);
+
+        stopGrid(1);
+
+        assert GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                return grid(2).context().clientDisconnected();
+            }
+        }, 10_000L);
+
+        IgniteFuture reconnFut = null;
+
+        try {   
+            node2.cache(CACHE_NAME);
+
+            fail();
+        }
+        catch (IgniteClientDisconnectedException e) {
+            reconnFut = e.reconnectFuture();
+        }
+
+        node1 = start(1, KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
+        assertTypes(node1, ValueClass.class, ValueClass2.class);
+
+        reconnFut.get();
+
+        assertTypes(node2);
+
+        node2.cache(CACHE_NAME);
+        assertTypes(node2, ValueClass.class, ValueClass2.class);
+    }
+
+    /**
+     * Ensure that only provided types exists for the given cache.
+     *
+     * @param node Node.
+     * @param clss Classes.
+     */
+    private static void assertTypes(IgniteEx node, Class... clss) {
+        Map<String, QueryTypeDescriptorImpl> types = types(node, CACHE_NAME);
+
+        if (clss == null || clss.length == 0)
+            assert types.isEmpty();
+        else {
+            assertEquals(clss.length, types.size());
+
+            for (Class cls : clss) {
+                String tblName = tableName(cls);
+
+                assert types.containsKey(tblName);
+            }
+        }
+    }
+
+    /**
+     * Start node with the given cache configuration.
+     *
+     * @param clss Key-value classes.
+     * @return Node.
+     */
+    private IgniteEx start(int idx, Class... clss) throws Exception {
+        return start(idx, false, clss);
+    }
+
+    /**
+     * Start client node with the given cache configuration.
+     *
+     * @param clss Key-value classes.
+     * @return Node.
+     */
+    private IgniteEx startClient(int idx, Class... clss) throws Exception {
+        return start(idx, true, clss);
+    }
+
+    /**
+     * Start node with the given cache configuration.
+     *
+     * @param idx Index.
+     * @param client Client flag.
+     * @param clss Key-value classes.
+     * @return Node.
+     */
+    private IgniteEx start(int idx, boolean client, Class... clss) throws Exception {
+        String name = getTestIgniteInstanceName(idx);
+
+        IgniteConfiguration cfg = getConfiguration(name);
+
+        cfg.setClientMode(client);
+        cfg.setLocalHost("127.0.0.1");
+        cfg.setCacheConfiguration(cacheConfiguration(clss));
+
+        if (filterNodeName != null && F.eq(name, filterNodeName))
+            cfg.setUserAttributes(Collections.singletonMap("AFF_NODE", true));
+
+        return (IgniteEx)Ignition.start(cfg);
+    }
+
+    /**
+     * Start node without cache.
+     *
+     * @param idx Index.
+     * @return Node.
+     * @throws Exception If failed.
+     */
+    private IgniteEx startNoCache(int idx) throws Exception {
+        return startNoCache(idx, false);
+    }
+
+    /**
+     * Start client node without cache.
+     *
+     * @param idx Index.
+     * @return Node.
+     * @throws Exception If failed.
+     */
+    private IgniteEx startClientNoCache(int idx) throws Exception {
+        return startNoCache(idx, true);
+    }
+
+    /**
+     * Start node without cache.
+     *
+     * @param idx Index.
+     * @param client Client mode flag.
+     * @return Node.
+     * @throws Exception If failed.
+     */
+    private IgniteEx startNoCache(int idx, boolean client) throws Exception {
+        String name = getTestIgniteInstanceName(idx);
+
+        IgniteConfiguration cfg = getConfiguration(name);
+
+        cfg.setClientMode(client);
+        cfg.setLocalHost("127.0.0.1");
+
+        return (IgniteEx)Ignition.start(cfg);
+    }
+
+    /**
+     * Get cache configuration.
+     *
+     * @param clss QUery classes.
+     * @return Configuration.
+     */
+    @SuppressWarnings("unchecked")
+    private static CacheConfiguration cacheConfiguration(Class... clss) {
+        CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME).setIndexedTypes(clss);
+
+        if (filterNodeName != null) {
+            ccfg.setNodeFilter(new IgnitePredicate<ClusterNode>() {
+                @Override public boolean apply(ClusterNode node) {
+                    return node.attribute("AFF_NODE") != null;
+                }
+            });
+        }
+
+        return ccfg;
+    }
+
+    // TODO: Start/stop many nodes with static configs and dynamic start/stop.
+
+    /**
+     * Key class 2.
+     */
+    @SuppressWarnings("unused")
+    private static class KeyClass2 {
+        @QuerySqlField
+        private String keyField2;
+    }
+
+    /**
+     * Value class 2.
+     */
+    @SuppressWarnings("unused")
+    private static class ValueClass2 {
+        @QuerySqlField
+        private String valField2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
index 6013b80..e0c6396 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
@@ -85,6 +85,6 @@ public class IgniteCacheLocalQuerySelfTest extends IgniteCacheAbstractQuerySelfT
         List<List<?>> res = cache.query(new SqlFieldsQuery(
             "explain select _key from String where _val > 'value1'").setLocal(true)).getAll();
 
-        assertTrue("__ explain: \n" + res, ((String)res.get(0).get(0)).contains("_val_idx"));
+        assertTrue("__ explain: \n" + res, ((String)res.get(0).get(0)).toLowerCase().contains("_val_idx"));
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteQueryDedicatedPoolTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteQueryDedicatedPoolTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteQueryDedicatedPoolTest.java
index 711db2f..fe966f9 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteQueryDedicatedPoolTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteQueryDedicatedPoolTest.java
@@ -83,7 +83,6 @@ public class IgniteQueryDedicatedPoolTest extends GridCommonAbstractTest {
         if ("client".equals(gridName))
             cfg.setClientMode(true);
 
-
         cfg.setIndexingSpi(new TestIndexingSpi());
 
         return cfg;

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
index b180eba..2a03796 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
@@ -413,7 +413,7 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest {
 
             info("Plan: " + plan);
 
-            assertTrue(plan.contains("grpIdx"));
+            assertTrue("_explain: " + plan, plan.toLowerCase().contains("grpidx"));
 
             // Sorted list
             List<GroupIndexTestValue> list = F.asList(

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 1c30412..e62199a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -87,7 +87,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         return cfg;
     }
 
-    /**
+    /*
      * Fields initialization.
      */
     static {
@@ -246,22 +246,22 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
     public void testSpi() throws Exception {
         IgniteH2Indexing spi = getIndexing();
 
-        assertEquals(-1, spi.size(typeAA.space(), typeAA));
-        assertEquals(-1, spi.size(typeAB.space(), typeAB));
-        assertEquals(-1, spi.size(typeBA.space(), typeBA));
+        assertEquals(-1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(-1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(-1, spi.size(typeBA.space(), typeBA.name()));
 
         IgniteCache<Integer, BinaryObject> cacheA = ignite0.createCache(cacheACfg());
 
-        assertEquals(0, spi.size(typeAA.space(), typeAA));
-        assertEquals(0, spi.size(typeAB.space(), typeAB));
-        assertEquals(-1, spi.size(typeBA.space(), typeBA));
+        assertEquals(0, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(0, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(-1, spi.size(typeBA.space(), typeBA.name()));
 
         IgniteCache<Integer, BinaryObject> cacheB = ignite0.createCache(cacheBCfg());
 
         // Initially all is empty.
-        assertEquals(0, spi.size(typeAA.space(), typeAA));
-        assertEquals(0, spi.size(typeAB.space(), typeAB));
-        assertEquals(0, spi.size(typeBA.space(), typeBA));
+        assertEquals(0, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(0, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(0, spi.size(typeBA.space(), typeBA.name()));
 
         assertFalse(spi.queryLocalSql(typeAA.space(), "select * from A.A", null, Collections.emptySet(), typeAA.name(), null, null).hasNext());
         assertFalse(spi.queryLocalSql(typeAB.space(), "select * from A.B", null, Collections.emptySet(), typeAB.name(), null, null).hasNext());
@@ -288,48 +288,48 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         cacheA.put(1, aa("A", 1, "Vasya", 10).build());
 
-        assertEquals(1, spi.size(typeAA.space(), typeAA));
-        assertEquals(0, spi.size(typeAB.space(), typeAB));
-        assertEquals(0, spi.size(typeBA.space(), typeBA));
+        assertEquals(1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(0, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(0, spi.size(typeBA.space(), typeBA.name()));
 
         cacheA.put(1, ab(1, "Vasya", 20, "Some text about Vasya goes here.").build());
 
         // In one space all keys must be unique.
-        assertEquals(0, spi.size(typeAA.space(), typeAA));
-        assertEquals(1, spi.size(typeAB.space(), typeAB));
-        assertEquals(0, spi.size(typeBA.space(), typeBA));
+        assertEquals(0, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(0, spi.size(typeBA.space(), typeBA.name()));
 
         cacheB.put(1, ba(2, "Petya", 25, true).build());
 
         // No replacement because of different space.
-        assertEquals(0, spi.size(typeAA.space(), typeAA));
-        assertEquals(1, spi.size(typeAB.space(), typeAB));
-        assertEquals(1, spi.size(typeBA.space(), typeBA));
+        assertEquals(0, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(1, spi.size(typeBA.space(), typeBA.name()));
 
         cacheB.put(1, ba(2, "Kolya", 25, true).build());
 
         // Replacement in the same table.
-        assertEquals(0, spi.size(typeAA.space(), typeAA));
-        assertEquals(1, spi.size(typeAB.space(), typeAB));
-        assertEquals(1, spi.size(typeBA.space(), typeBA));
+        assertEquals(0, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(1, spi.size(typeBA.space(), typeBA.name()));
 
         cacheA.put(2, aa("A", 2, "Valera", 19).build());
 
-        assertEquals(1, spi.size(typeAA.space(), typeAA));
-        assertEquals(1, spi.size(typeAB.space(), typeAB));
-        assertEquals(1, spi.size(typeBA.space(), typeBA));
+        assertEquals(1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(1, spi.size(typeBA.space(), typeBA.name()));
 
         cacheA.put(3, aa("A", 3, "Borya", 18).build());
 
-        assertEquals(2, spi.size(typeAA.space(), typeAA));
-        assertEquals(1, spi.size(typeAB.space(), typeAB));
-        assertEquals(1, spi.size(typeBA.space(), typeBA));
+        assertEquals(2, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(1, spi.size(typeBA.space(), typeBA.name()));
 
         cacheA.put(4, ab(4, "Vitalya", 20, "Very Good guy").build());
 
-        assertEquals(2, spi.size(typeAA.space(), typeAA));
-        assertEquals(2, spi.size(typeAB.space(), typeAB));
-        assertEquals(1, spi.size(typeBA.space(), typeBA));
+        assertEquals(2, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(2, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(1, spi.size(typeBA.space(), typeBA.name()));
 
         // Query data.
         Iterator<IgniteBiTuple<Integer, BinaryObjectImpl>> res =
@@ -376,7 +376,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         // Text queries
         Iterator<IgniteBiTuple<Integer, BinaryObjectImpl>> txtRes = spi.queryLocalText(typeAB.space(), "good",
-            typeAB, null);
+            typeAB.name(), null);
 
         assertTrue(txtRes.hasNext());
         assertEquals(ab(4, "Vitalya", 20, "Very Good guy").build(), value(txtRes.next()));
@@ -410,32 +410,32 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         // Remove
         cacheA.remove(2);
 
-        assertEquals(1, spi.size(typeAA.space(), typeAA));
-        assertEquals(2, spi.size(typeAB.space(), typeAB));
-        assertEquals(1, spi.size(typeBA.space(), typeBA));
+        assertEquals(1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(2, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(1, spi.size(typeBA.space(), typeBA.name()));
 
         cacheB.remove(1);
 
-        assertEquals(1, spi.size(typeAA.space(), typeAA));
-        assertEquals(2, spi.size(typeAB.space(), typeAB));
-        assertEquals(0, spi.size(typeBA.space(), typeBA));
+        assertEquals(1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(2, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(0, spi.size(typeBA.space(), typeBA.name()));
 
         // Unregister.
-        spi.unregisterType(typeAA.space(), typeAA);
+        spi.unregisterType(typeAA.space(), typeAA.name());
 
-        assertEquals(-1, spi.size(typeAA.space(), typeAA));
-        assertEquals(2, spi.size(typeAB.space(), typeAB));
-        assertEquals(0, spi.size(typeBA.space(), typeBA));
+        assertEquals(-1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(2, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(0, spi.size(typeBA.space(), typeBA.name()));
 
-        spi.unregisterType(typeAB.space(), typeAB);
+        spi.unregisterType(typeAB.space(), typeAB.name());
 
-        assertEquals(-1, spi.size(typeAA.space(), typeAA));
-        assertEquals(-1, spi.size(typeAB.space(), typeAB));
-        assertEquals(0, spi.size(typeBA.space(), typeBA));
+        assertEquals(-1, spi.size(typeAA.space(), typeAA.name()));
+        assertEquals(-1, spi.size(typeAB.space(), typeAB.name()));
+        assertEquals(0, spi.size(typeBA.space(), typeBA.name()));
 
-        spi.unregisterType(typeBA.space(), typeBA);
+        spi.unregisterType(typeBA.space(), typeBA.name());
 
-        assertEquals(-1, spi.size(typeAA.space(), typeAA));
+        assertEquals(-1, spi.size(typeAA.space(), typeAA.name()));
     }
 
     /**
@@ -500,6 +500,11 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         }
 
         /** {@inheritDoc} */
+        @Override public String name() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
         @Override public Collection<String> fields() {
             return fields;
         }
@@ -640,8 +645,12 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         /** */
         @Override public Map<String, GridQueryIndexDescriptor> indexes() {
-            return textIdx == null ? Collections.<String, GridQueryIndexDescriptor>emptyMap() :
-                Collections.singletonMap("index", textIdx);
+            return Collections.emptyMap();
+        }
+
+        /** */
+        @Override public GridQueryIndexDescriptor textIndex() {
+            return textIdx;
         }
 
         /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlQueryMinMaxTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlQueryMinMaxTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlQueryMinMaxTest.java
index 0f50d7e..e78b695 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlQueryMinMaxTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlQueryMinMaxTest.java
@@ -142,8 +142,8 @@ public class IgniteSqlQueryMinMaxTest extends GridCommonAbstractTest {
             QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_key), max(_key) from ValueObj"));
             List<List<?>> result = cursor.getAll();
             assertEquals(2, result.size());
-            assertTrue(((String) result.get(0).get(0)).contains("_key_PK"));
-            assertTrue(((String) result.get(0).get(0)).contains("direct lookup"));
+            assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_key_pk"));
+            assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
         }
     }
 
@@ -158,8 +158,8 @@ public class IgniteSqlQueryMinMaxTest extends GridCommonAbstractTest {
             QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(idxVal), max(idxVal) from ValueObj"));
             List<List<?>> result = cursor.getAll();
             assertEquals(2, result.size());
-            assertTrue(((String)result.get(0).get(0)).contains("idxVal_idx"));
-            assertTrue(((String)result.get(0).get(0)).contains("direct lookup"));
+            assertTrue(((String)result.get(0).get(0)).toLowerCase().contains("idxval_idx"));
+            assertTrue(((String)result.get(0).get(0)).toLowerCase().contains("direct lookup"));
         }
     }
 
@@ -174,8 +174,8 @@ public class IgniteSqlQueryMinMaxTest extends GridCommonAbstractTest {
             QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_key), max(_key) from Integer"));
             List<List<?>> result = cursor.getAll();
             assertEquals(2, result.size());
-            assertTrue(((String)result.get(0).get(0)).contains("_key_PK"));
-            assertTrue(((String)result.get(0).get(0)).contains("direct lookup"));
+            assertTrue(((String)result.get(0).get(0)).toLowerCase().contains("_key_pk"));
+            assertTrue(((String)result.get(0).get(0)).toLowerCase().contains("direct lookup"));
         }
     }
 
@@ -190,8 +190,8 @@ public class IgniteSqlQueryMinMaxTest extends GridCommonAbstractTest {
             QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_val), max(_val) from Integer"));
             List<List<?>> result = cursor.getAll();
             assertEquals(2, result.size());
-            assertTrue(((String)result.get(0).get(0)).contains("_val_idx"));
-            assertTrue(((String)result.get(0).get(0)).contains("direct lookup"));
+            assertTrue(((String)result.get(0).get(0)).toLowerCase().contains("_val_idx"));
+            assertTrue(((String)result.get(0).get(0)).toLowerCase().contains("direct lookup"));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java
index 4bd9302..88ff61e 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java
@@ -79,7 +79,7 @@ public class GridH2TableSelfTest extends GridCommonAbstractTest {
     private static final String NON_UNIQUE_IDX_NAME = "__GG_IDX_";
 
     /** */
-    private static final String SCAN_IDX_NAME = GridH2Table.ScanIndex.SCAN_INDEX_NAME_SUFFIX;
+    private static final String SCAN_IDX_NAME = GridH2PrimaryScanIndex.SCAN_INDEX_NAME_SUFFIX;
 
     /** */
     private Connection conn;
@@ -89,31 +89,36 @@ public class GridH2TableSelfTest extends GridCommonAbstractTest {
 
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
-        Driver.load();
-
-        conn = DriverManager.getConnection(DB_URL);
-
-        tbl = GridH2Table.Engine.createTable(conn, CREATE_TABLE_SQL, null, new GridH2Table.IndexesFactory() {
-            @Override public H2RowFactory createRowFactory(GridH2Table tbl) {
-                return null;
-            }
-
-            @Override public ArrayList<Index> createIndexes(GridH2Table tbl) {
-                ArrayList<Index> idxs = new ArrayList<>();
-
-                IndexColumn id = tbl.indexColumn(0, SortOrder.ASCENDING);
-                IndexColumn t = tbl.indexColumn(1, SortOrder.ASCENDING);
-                IndexColumn str = tbl.indexColumn(2, SortOrder.DESCENDING);
-                IndexColumn x = tbl.indexColumn(3, SortOrder.DESCENDING);
-
-                idxs.add(new H2PkHashIndex(null, tbl, HASH, F.asList(id)));
-                idxs.add(new GridH2TreeIndex(PK_NAME, tbl, true, F.asList(id)));
-                idxs.add(new GridH2TreeIndex(NON_UNIQUE_IDX_NAME, tbl, false, F.asList(x, t, id)));
-                idxs.add(new GridH2TreeIndex(STR_IDX_NAME, tbl, false, F.asList(str, id)));
-
-                return idxs;
-            }
-        }, null);
+        // TODO: IGNITE-4994: Restore mock.
+//        Driver.load();
+//
+//        conn = DriverManager.getConnection(DB_URL);
+//
+//        tbl = GridH2Table.Engine.createTable(conn, CREATE_TABLE_SQL, null, new GridH2Table.IndexesFactory() {
+//            @Override public void onTableCreated(GridH2Table tbl) {
+//                // No-op.
+//            }
+//
+//            @Override public H2RowFactory createRowFactory(GridH2Table tbl) {
+//                return null;
+//            }
+//
+//            @Override public ArrayList<Index> createIndexes(GridH2Table tbl) {
+//                ArrayList<Index> idxs = new ArrayList<>();
+//
+//                IndexColumn id = tbl.indexColumn(0, SortOrder.ASCENDING);
+//                IndexColumn t = tbl.indexColumn(1, SortOrder.ASCENDING);
+//                IndexColumn str = tbl.indexColumn(2, SortOrder.DESCENDING);
+//                IndexColumn x = tbl.indexColumn(3, SortOrder.DESCENDING);
+//
+//                idxs.add(new H2PkHashIndex(null, tbl, HASH, F.asList(id)));
+//                idxs.add(new GridH2TreeIndex(PK_NAME, tbl, true, F.asList(id)));
+//                idxs.add(new GridH2TreeIndex(NON_UNIQUE_IDX_NAME, tbl, false, F.asList(x, t, id)));
+//                idxs.add(new GridH2TreeIndex(STR_IDX_NAME, tbl, false, F.asList(str, id)));
+//
+//                return idxs;
+//            }
+//        }, null);
     }
 
     /** {@inheritDoc} */
@@ -285,120 +290,6 @@ public class GridH2TableSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Multithreaded indexes consistency test.
-     *
-     * @throws Exception If failed.
-     */
-    public void testIndexesMultiThreadedConsistency() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-3484");
-
-        final int threads = 19;
-        final int iterations = 1500;
-
-        multithreaded(new Callable<Void>() {
-            @Override public Void call() throws Exception {
-                Random rnd = new Random();
-
-                PreparedStatement ps1 = null;
-
-                for (int i = 0; i < iterations; i++) {
-                    UUID id = UUID.randomUUID();
-
-                    int x = rnd.nextInt(50);
-
-                    long t = System.currentTimeMillis();
-
-                    GridH2Row row = row(id, t, rnd.nextBoolean() ? id.toString() : UUID.randomUUID().toString(), x);
-
-                    assertTrue(tbl.doUpdate(row, false));
-
-                    if (rnd.nextInt(100) == 0) {
-                        tbl.lock(null, false, false);
-
-                        long cnt = 0;
-
-                        try {
-                            ArrayList<Index> idxs = tbl.getIndexes();
-
-                            // Consistency check.
-                            Set<Row> rowSet = checkIndexesConsistent(idxs, null);
-
-                            // Order check.
-                            checkOrdered(idxs);
-
-                            checkIndexesConsistent(idxs, rowSet);
-
-                            cnt = idxs.get(0).getRowCount(null);
-                        }
-                        finally {
-                            tbl.unlock(null);
-                        }
-
-                        // Row count is valid.
-                        ResultSet rs = conn.createStatement().executeQuery("select count(*) from t");
-
-                        assertTrue(rs.next());
-
-                        int cnt2 = rs.getInt(1);
-
-                        rs.close();
-
-                        assertTrue(cnt2 + " must be >= " + cnt, cnt2 >= cnt);
-                        assertTrue(cnt2 <= threads * iterations);
-
-                        // Search by ID.
-                        rs = conn.createStatement().executeQuery("select * from t where id = '" + id.toString() + "'");
-
-                        assertTrue(rs.next());
-                        assertFalse(rs.next());
-
-                        rs.close();
-
-                        // Scan search.
-                        if (ps1 == null)
-                            ps1 = conn.prepareStatement("select id from t where x = ? order by t desc");
-
-                        ps1.setInt(1, x);
-
-                        rs = ps1.executeQuery();
-
-                        for (;;) {
-                            assertTrue(rs.next());
-
-                            if (rs.getObject(1).equals(id))
-                                break;
-                        }
-
-                        rs.close();
-                    }
-                }
-                return null;
-            }
-        }, threads);
-    }
-
-    /**
-     * Run test in endless loop.
-     *
-     * @param args Arguments.
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("InfiniteLoopStatement")
-    public static void main(String ... args) throws Exception {
-        for (int i = 0;;) {
-            GridH2TableSelfTest t = new GridH2TableSelfTest();
-
-            t.beforeTest();
-
-            t.testDataLoss();
-
-            t.afterTest();
-
-            System.out.println("..." + ++i);
-        }
-    }
-
-    /**
       * @throws Exception If failed.
      */
     public void testRangeQuery() throws Exception {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
index 1d8893e..631adeb 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
@@ -22,9 +22,15 @@ import java.sql.Connection;
 import java.sql.Date;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.Callable;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -32,15 +38,19 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
 import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.h2.command.Prepared;
 import org.h2.engine.Session;
 import org.h2.jdbc.JdbcConnection;
+import org.h2.message.DbException;
 
 import static org.apache.ignite.cache.CacheRebalanceMode.SYNC;
 import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
@@ -453,6 +463,206 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
     /**
      *
      */
+    public void testParseCreateIndex() throws Exception {
+        assertCreateIndexEquals(
+            buildCreateIndex(null, "Person", "sch1", false, QueryIndexType.SORTED, "name", true),
+            "create index on Person (name)");
+
+        assertCreateIndexEquals(
+            buildCreateIndex("idx", "Person", "sch1", false, QueryIndexType.SORTED, "name", true),
+            "create index idx on Person (name ASC)");
+
+        assertCreateIndexEquals(
+            buildCreateIndex("idx", "Person", "sch1", false, QueryIndexType.GEOSPATIAL, "name", true),
+            "create spatial index sch1.idx on sch1.Person (name ASC)");
+
+        assertCreateIndexEquals(
+            buildCreateIndex("idx", "Person", "sch1", true, QueryIndexType.SORTED, "name", true),
+            "create index if not exists sch1.idx on sch1.Person (name)");
+
+        // When we specify schema for the table and don't specify it for the index, resulting schema is table's
+        assertCreateIndexEquals(
+            buildCreateIndex("idx", "Person", "sch1", true, QueryIndexType.SORTED, "name", false),
+            "create index if not exists idx on sch1.Person (name dEsC)");
+
+        assertCreateIndexEquals(
+            buildCreateIndex("idx", "Person", "sch1", true, QueryIndexType.GEOSPATIAL, "old", true, "name", false),
+            "create spatial index if not exists idx on Person (old, name desc)");
+
+        // Schemas for index and table must match
+        assertParseThrows("create index if not exists sch2.idx on sch1.Person (name)",
+            DbException.class, "Schema name must match [90080-191]");
+
+        assertParseThrows("create hash index if not exists idx on Person (name)",
+            IgniteSQLException.class, "Only SPATIAL modifier is supported for CREATE INDEX");
+
+        assertParseThrows("create unique index if not exists idx on Person (name)",
+            IgniteSQLException.class, "Only SPATIAL modifier is supported for CREATE INDEX");
+
+        assertParseThrows("create primary key on Person (name)",
+            IgniteSQLException.class, "Only SPATIAL modifier is supported for CREATE INDEX");
+
+        assertParseThrows("create primary key hash on Person (name)",
+            IgniteSQLException.class, "Only SPATIAL modifier is supported for CREATE INDEX");
+
+        assertParseThrows("create index on Person (name nulls first)",
+            IgniteSQLException.class, "NULLS FIRST and NULLS LAST modifiers are not supported for index columns");
+
+        assertParseThrows("create index on Person (name desc nulls last)",
+            IgniteSQLException.class, "NULLS FIRST and NULLS LAST modifiers are not supported for index columns");
+    }
+
+    /**
+     *
+     */
+    public void testParseDropIndex() throws Exception {
+        // Schema that is not set defaults to default schema of connection which is empty string
+        assertDropIndexEquals(buildDropIndex("idx", "sch1", false), "drop index idx");
+        assertDropIndexEquals(buildDropIndex("idx", "sch1", true), "drop index if exists idx");
+        assertDropIndexEquals(buildDropIndex("idx", "sch1", true), "drop index if exists sch1.idx");
+        assertDropIndexEquals(buildDropIndex("idx", "sch1", false), "drop index sch1.idx");
+
+        // Message is null as long as it may differ from system to system, so we just check for exceptions
+        assertParseThrows("drop index schema2.", DbException.class, null);
+        assertParseThrows("drop index", DbException.class, null);
+        assertParseThrows("drop index if exists", DbException.class, null);
+        assertParseThrows("drop index if exists schema2.", DbException.class, null);
+    }
+
+    /**
+     * @param sql Statement.
+     * @param exCls Exception class.
+     * @param msg Expected message.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    private void assertParseThrows(final String sql, Class<? extends Exception> exCls, String msg) {
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                Prepared p = parse(sql);
+
+                return new GridSqlQueryParser(false).parse(p);
+            }
+        }, exCls, msg);
+    }
+
+    /**
+     * Parse SQL and compare it to expected instance.
+     */
+    private void assertCreateIndexEquals(GridSqlCreateIndex exp, String sql) throws Exception {
+        Prepared prepared = parse(sql);
+
+        GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
+
+        assertTrue(stmt instanceof GridSqlCreateIndex);
+
+        assertCreateIndexEquals(exp, (GridSqlCreateIndex) stmt);
+    }
+
+    /**
+     * Parse SQL and compare it to expected instance of DROP INDEX.
+     */
+    private void assertDropIndexEquals(GridSqlDropIndex exp, String sql) throws Exception {
+        Prepared prepared = parse(sql);
+
+        GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
+
+        assertTrue(stmt instanceof GridSqlDropIndex);
+
+        assertDropIndexEquals(exp, (GridSqlDropIndex) stmt);
+    }
+
+    /**
+     * Test two instances of {@link GridSqlDropIndex} for equality.
+     */
+    private static void assertDropIndexEquals(GridSqlDropIndex exp, GridSqlDropIndex actual) {
+        assertEqualsIgnoreCase(exp.name(), actual.name());
+        assertEqualsIgnoreCase(exp.schemaName(), actual.schemaName());
+        assertEquals(exp.ifExists(), actual.ifExists());
+    }
+
+    /**
+     *
+     */
+    private static GridSqlDropIndex buildDropIndex(String name, String schema, boolean ifExists) {
+        GridSqlDropIndex res = new GridSqlDropIndex();
+
+        res.name(name);
+        res.schemaName(schema);
+        res.ifExists(ifExists);
+
+        return res;
+    }
+
+    /**
+     * Test two instances of {@link GridSqlCreateIndex} for equality.
+     */
+    private static void assertCreateIndexEquals(GridSqlCreateIndex exp, GridSqlCreateIndex actual) {
+        assertEquals(exp.ifNotExists(), actual.ifNotExists());
+        assertEqualsIgnoreCase(exp.schemaName(), actual.schemaName());
+        assertEqualsIgnoreCase(exp.tableName(), actual.tableName());
+
+        assertEqualsIgnoreCase(exp.index().getName(), actual.index().getName());
+
+        Iterator<Map.Entry<String, Boolean>> expFldsIt = exp.index().getFields().entrySet().iterator();
+        Iterator<Map.Entry<String, Boolean>> actualFldsIt = actual.index().getFields().entrySet().iterator();
+
+        while (expFldsIt.hasNext()) {
+            assertTrue(actualFldsIt.hasNext());
+
+            Map.Entry<String, Boolean> expEntry = expFldsIt.next();
+            Map.Entry<String, Boolean> actualEntry = actualFldsIt.next();
+
+            assertEqualsIgnoreCase(expEntry.getKey(), actualEntry.getKey());
+            assertEquals(expEntry.getValue(), actualEntry.getValue());
+        }
+
+        assertFalse(actualFldsIt.hasNext());
+
+        assertEquals(exp.index().getIndexType(), actual.index().getIndexType());
+    }
+
+    /**
+     *
+     */
+    private static void assertEqualsIgnoreCase(String exp, String actual) {
+        assertEquals((exp == null), (actual == null));
+
+        if (exp != null)
+            assertTrue(exp.equalsIgnoreCase(actual));
+    }
+
+    /**
+     *
+     */
+    private static GridSqlCreateIndex buildCreateIndex(String name, String tblName, String schemaName, boolean ifNotExists,
+        QueryIndexType type, Object... flds) {
+        QueryIndex idx = new QueryIndex();
+
+        idx.setName(name);
+
+        assert !F.isEmpty(flds) && flds.length % 2 == 0;
+
+        LinkedHashMap<String, Boolean> trueFlds = new LinkedHashMap<>();
+
+        for (int i = 0; i < flds.length / 2; i++)
+            trueFlds.put((String)flds[i * 2], (Boolean)flds[i * 2 + 1]);
+
+        idx.setFields(trueFlds);
+        idx.setIndexType(type);
+
+        GridSqlCreateIndex res = new GridSqlCreateIndex();
+
+        res.schemaName(schemaName);
+        res.tableName(tblName);
+        res.ifNotExists(ifNotExists);
+        res.index(idx);
+
+        return res;
+    }
+
+    /**
+     *
+     */
     private JdbcConnection connection() throws Exception {
         GridKernalContext ctx = ((IgniteEx)ignite).context();
 
@@ -508,7 +718,7 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
 
         System.out.println(normalizeSql(res));
 
-        assertSqlEquals(prepared.getPlanSQL(), res);
+        assertSqlEquals(U.firstNotNull(prepared.getPlanSQL(), prepared.getSQL()), res);
     }
 
     @QuerySqlFunction

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
index de341d0..b61affe 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
@@ -81,6 +81,18 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.Ignite
 import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedFieldsQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQueryP2PDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest;
+import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicPartitionedNearSelfTest;
+import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexTransactionalPartitionedNearSelfTest;
+import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexTransactionalPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexTransactionalReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexClientBasicSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerCoordinatorBasicSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerNodeFIlterBasicSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerNodeFilterCoordinatorBasicSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerBasicSelfTest;
+import org.apache.ignite.internal.processors.cache.index.SchemaExchangeSelfTest;
 import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalAtomicQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalFieldsQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalQueryCancelOrTimeoutSelfTest;
@@ -98,7 +110,6 @@ import org.apache.ignite.internal.processors.query.IgniteSqlSplitterSelfTest;
 import org.apache.ignite.internal.processors.query.h2.GridH2IndexingInMemSelfTest;
 import org.apache.ignite.internal.processors.query.h2.GridH2IndexingOffheapSelfTest;
 import org.apache.ignite.internal.processors.query.h2.IgniteSqlQueryMinMaxTest;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2TableSelfTest;
 import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
 import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
 import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryDistributedJoinsTest;
@@ -117,8 +128,20 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
     public static TestSuite suite() throws Exception {
         IgniteTestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test Suite");
 
+        // Dynamic index create/drop tests.
+        suite.addTest(new TestSuite(SchemaExchangeSelfTest.class));
+
+        suite.addTest(new TestSuite(DynamicIndexServerCoordinatorBasicSelfTest.class));
+        suite.addTest(new TestSuite(DynamicIndexServerBasicSelfTest.class));
+        suite.addTest(new TestSuite(DynamicIndexServerNodeFilterCoordinatorBasicSelfTest.class));
+        suite.addTest(new TestSuite(DynamicIndexServerNodeFIlterBasicSelfTest.class));
+        suite.addTest(new TestSuite(DynamicIndexClientBasicSelfTest.class));
+
         // H2 tests.
-        suite.addTest(new TestSuite(GridH2TableSelfTest.class));
+
+        // TODO: IGNITE-4994: Restore mock.
+        // suite.addTest(new TestSuite(GridH2TableSelfTest.class));
+
         suite.addTest(new TestSuite(GridH2IndexingInMemSelfTest.class));
         suite.addTest(new TestSuite(GridH2IndexingOffheapSelfTest.class));
 
@@ -171,6 +194,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
 
         suite.addTestSuite(IgniteCacheMultipleIndexedTypesTest.class);
 
+        // DML.
         suite.addTestSuite(IgniteCacheMergeSqlQuerySelfTest.class);
         suite.addTestSuite(IgniteCacheInsertSqlQuerySelfTest.class);
         suite.addTestSuite(IgniteCacheUpdateSqlQuerySelfTest.class);
@@ -185,6 +209,14 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheMultipleIndexedTypesTest.class);
         suite.addTestSuite(IgniteSqlQueryMinMaxTest.class);
 
+        // DDL.
+        suite.addTestSuite(H2DynamicIndexTransactionalReplicatedSelfTest.class);
+        suite.addTestSuite(H2DynamicIndexTransactionalPartitionedSelfTest.class);
+        suite.addTestSuite(H2DynamicIndexTransactionalPartitionedNearSelfTest.class);
+        suite.addTestSuite(H2DynamicIndexAtomicReplicatedSelfTest.class);
+        suite.addTestSuite(H2DynamicIndexAtomicPartitionedSelfTest.class);
+        suite.addTestSuite(H2DynamicIndexAtomicPartitionedNearSelfTest.class);
+
         // Fields queries.
         suite.addTestSuite(SqlFieldsQuerySelfTest.class);
         suite.addTestSuite(IgniteCacheLocalFieldsQuerySelfTest.class);
@@ -227,7 +259,6 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheNoClassQuerySelfTest.class);
 
         // Cancellation.
-
         suite.addTestSuite(IgniteCacheDistributedQueryCancelSelfTest.class);
         suite.addTestSuite(IgniteCacheLocalQueryCancelOrTimeoutSelfTest.class);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
index 416f150..5085cd5 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
@@ -30,6 +30,10 @@ import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheD
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeFailTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeRestartSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeRestartSelfTest2;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexPartitionedAtomicConcurrentSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexPartitionedTransactionalConcurrentSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexReplicatedAtomicConcurrentSelfTest;
+import org.apache.ignite.internal.processors.cache.index.DynamicIndexReplicatedTransactionalConcurrentSelfTest;
 import org.apache.ignite.testframework.IgniteTestSuite;
 
 /**
@@ -43,6 +47,13 @@ public class IgniteCacheQuerySelfTestSuite2 extends TestSuite {
     public static TestSuite suite() throws Exception {
         TestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test Suite 2");
 
+        // Dynamic index create/drop tests.
+        suite.addTestSuite(DynamicIndexPartitionedAtomicConcurrentSelfTest.class);
+        suite.addTestSuite(DynamicIndexPartitionedTransactionalConcurrentSelfTest.class);
+        suite.addTestSuite(DynamicIndexReplicatedAtomicConcurrentSelfTest.class);
+        suite.addTestSuite(DynamicIndexReplicatedTransactionalConcurrentSelfTest.class);
+
+        // Other tests.
         suite.addTestSuite(IgniteCacheQueryMultiThreadedSelfTest.class);
 
         suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class);


[10/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/SingularValueDecompositionTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/SingularValueDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/SingularValueDecompositionTest.java
deleted file mode 100644
index d0b89f8..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/SingularValueDecompositionTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.matrix.PivotedMatrixView;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class SingularValueDecompositionTest {
-    /** */
-    @Test
-    public void basicTest() {
-        basicTest(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        }));
-    }
-
-    /**
-     * Test for {@link DecompositionSupport} features.
-     */
-    @Test
-    public void decompositionSupportTest() {
-        basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d},
-            {0.0d, -1.0d, 2.0d}
-        })));
-    }
-
-    /** */
-    @Test
-    public void rowsLessThanColumnsTest() {
-        DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
-            {2.0d, -1.0d, 0.0d},
-            {-1.0d, 2.0d, -1.0d}
-        });
-
-        SingularValueDecomposition dec = new SingularValueDecomposition(m);
-        assertEquals("Unexpected value for singular values size.",
-            2, dec.getSingularValues().length);
-
-        Matrix s = dec.getS();
-        Matrix u = dec.getU();
-        Matrix v = dec.getV();
-        Matrix covariance = dec.getCovariance(0.5);
-
-        assertNotNull("Matrix s is expected to be not null.", s);
-        assertNotNull("Matrix u is expected to be not null.", u);
-        assertNotNull("Matrix v is expected to be not null.", v);
-        assertNotNull("Covariance matrix is expected to be not null.", covariance);
-
-        dec.destroy();
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullMatrixTest() {
-        new SingularValueDecomposition(null);
-    }
-
-    /** */
-    private void basicTest(Matrix m) {
-        SingularValueDecomposition dec = new SingularValueDecomposition(m);
-        assertEquals("Unexpected value for singular values size.",
-            3, dec.getSingularValues().length);
-
-        Matrix s = dec.getS();
-        Matrix u = dec.getU();
-        Matrix v = dec.getV();
-        Matrix covariance = dec.getCovariance(0.5);
-
-        assertNotNull("Matrix s is expected to be not null.", s);
-        assertNotNull("Matrix u is expected to be not null.", u);
-        assertNotNull("Matrix v is expected to be not null.", v);
-        assertNotNull("Covariance matrix is expected to be not null.", covariance);
-
-        assertTrue("Decomposition cond is expected to be positive.", dec.cond() > 0);
-        assertTrue("Decomposition norm2 is expected to be positive.", dec.norm2() > 0);
-        assertEquals("Decomposition rank differs from expected.", 3, dec.rank());
-        assertEquals("Decomposition singular values size differs from expected.",
-            3, dec.getSingularValues().length);
-
-        Matrix recomposed = (u.times(s).times(v.transpose()));
-
-        for (int row = 0; row < m.rowSize(); row++)
-            for (int col = 0; col < m.columnSize(); col++)
-                assertEquals("Unexpected recomposed matrix value at (" + row + "," + col + ").",
-                    m.get(row, col), recomposed.get(row, col), 0.001);
-
-        for (int row = 0; row < covariance.rowSize(); row++)
-            for (int col = row + 1; col < covariance.columnSize(); col++)
-                assertEquals("Unexpected covariance matrix value at (" + row + "," + col + ").",
-                    covariance.get(row, col), covariance.get(col, row), 0.001);
-
-        dec.destroy();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/MathTestConstants.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/MathTestConstants.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/MathTestConstants.java
deleted file mode 100644
index 122c62e..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/MathTestConstants.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls;
-
-/**
- * Collect constants for org.apache.ignite.math tests
- */
-public interface MathTestConstants {
-    /** */
-    public double SECOND_ARG = 1d;
-
-    /**
-     * We assume that we will check calculation precision in other tests.
-     */
-    public double EXP_DELTA = 0.1d;
-
-    /** */
-    public String UNEXPECTED_VAL = "Unexpected value.";
-
-    /** */
-    public String NULL_GUID = "Null GUID.";
-
-    /** */
-    public String UNEXPECTED_GUID_VAL = "Unexpected GUID value.";
-
-    /** */
-    public String EMPTY_GUID = "Empty GUID.";
-
-    /** */
-    public String VALUES_SHOULD_BE_NOT_EQUALS = "Values should be not equals.";
-
-    /** */
-    public String NULL_VAL = "Null value.";
-
-    /** */
-    public String NULL_VALUES = "Null values.";
-
-    /** */
-    public String NOT_NULL_VAL = "Not null value.";
-
-    /** */
-    public double TEST_VAL = 1d;
-
-    /** */
-    public String VAL_NOT_EQUALS = "Values not equals.";
-
-    /** */
-    public String NO_NEXT_ELEMENT = "No next element.";
-
-    /** */
-    public int STORAGE_SIZE = 100;
-
-    /** */
-    public String WRONG_ATTRIBUTE_VAL = "Wrong attribute value.";
-
-    /** */
-    public String NULL_DATA_ELEMENT = "Null data element.";
-
-    /** */
-    public String WRONG_DATA_ELEMENT = "Wrong data element.";
-
-    /** */
-    public double NIL_DELTA = 0d;
-
-    /** */
-    public String NULL_DATA_STORAGE = "Null data storage.";
-
-    /** */
-    public String WRONG_DATA_SIZE = "Wrong data size.";
-
-    /** */
-    public String UNEXPECTED_DATA_VAL = "Unexpected data value.";
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/CacheMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/CacheMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/CacheMatrixTest.java
deleted file mode 100644
index 8a6d077..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/CacheMatrixTest.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.IdentityValueMapper;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixKeyMapper;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * Tests for {@link CacheMatrix}.
- */
-@GridCommonTest(group = "Distributed Models")
-public class CacheMatrixTest extends GridCommonAbstractTest {
-    /** Number of nodes in grid */
-    private static final int NODE_COUNT = 3;
-    /** Cache name. */
-    private static final String CACHE_NAME = "test-cache";
-    /** */
-    private static final String UNEXPECTED_ATTRIBUTE_VALUE = "Unexpected attribute value.";
-    /** Grid instance. */
-    private Ignite ignite;
-    /** Matrix rows */
-    private final int rows = MathTestConstants.STORAGE_SIZE;
-    /** Matrix cols */
-    private final int cols = MathTestConstants.STORAGE_SIZE;
-
-    /**
-     * Default constructor.
-     */
-    public CacheMatrixTest() {
-        super(false);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        for (int i = 1; i <= NODE_COUNT; i++)
-            startGrid(i);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override protected void beforeTest() throws Exception {
-        ignite = grid(NODE_COUNT);
-
-        ignite.configuration().setPeerClassLoadingEnabled(true);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        ignite.destroyCache(CACHE_NAME);
-    }
-
-    /** */
-    public void testGetSet() throws Exception {
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        for (int i = 0; i < rows; i++) {
-            for (int j = 0; j < cols; j++) {
-                double v = Math.random();
-                cacheMatrix.set(i, j, v);
-
-                assert Double.compare(v, cacheMatrix.get(i, j)) == 0;
-                assert Double.compare(v, cache.get(keyMapper.apply(i, j))) == 0;
-            }
-        }
-    }
-
-    /** */
-    public void testCopy() throws Exception {
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        fillMatrix(cacheMatrix);
-
-        try {
-            cacheMatrix.copy();
-
-            fail("UnsupportedOperationException expected");
-        }
-        catch (UnsupportedOperationException e) {
-            // No-op.
-        }
-    }
-
-    /** */
-    public void testLike() throws Exception {
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        try {
-            cacheMatrix.like(rows, cols);
-
-            fail("UnsupportedOperationException expected");
-        }
-        catch (UnsupportedOperationException e) {
-            // No-op.
-        }
-    }
-
-    /** */
-    public void testLikeVector() throws Exception {
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        try {
-            cacheMatrix.likeVector(cols);
-
-            fail("UnsupportedOperationException expected");
-        }
-        catch (UnsupportedOperationException e) {
-            // No-op.
-        }
-    }
-
-    /** */
-    public void testPlus() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        double plusVal = 2;
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        initMatrix(cacheMatrix);
-
-        cacheMatrix.plus(plusVal);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                assertEquals(plusVal, cacheMatrix.get(i, j));
-    }
-
-    /** */
-    public void testDivide() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        double initVal = 1;
-        double divVal = 2;
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        initMatrix(cacheMatrix);
-        cacheMatrix.assign(initVal);
-        cacheMatrix.divide(divVal);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                assertTrue(Double.compare(cacheMatrix.get(i, j), initVal / divVal) == 0);
-    }
-
-    /** */
-    public void testTimes() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        double initVal = 1;
-        double timVal = 2;
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        initMatrix(cacheMatrix);
-        cacheMatrix.assign(initVal);
-        cacheMatrix.times(timVal);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                assertTrue(Double.compare(cacheMatrix.get(i, j), initVal * timVal) == 0);
-    }
-
-    /** */
-    public void testSum() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        double initVal = 1;
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        double sum = 0;
-
-        initMatrix(cacheMatrix);
-        sum = cacheMatrix.sum();
-
-        assertTrue(Double.compare(sum, 0d) == 0);
-
-        cacheMatrix.assign(1d);
-        sum = cacheMatrix.sum();
-
-        assertTrue(Double.compare(sum, rows * cols) == 0);
-    }
-
-    /** */
-    public void testAssignSingleValue() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        double initVal = 1;
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        initMatrix(cacheMatrix);
-
-        cacheMatrix.assign(initVal);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                assertEquals(initVal, cacheMatrix.get(i, j));
-    }
-
-    /** */
-    public void testAssignArray() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        double[][] initVal = new double[rows][cols];
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                initVal[i][j] = Math.random();
-
-        cacheMatrix.assign(initVal);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                assertEquals(initVal[i][j], cacheMatrix.get(i, j));
-    }
-
-    /** */
-    public void testAttributes() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isSequentialAccess());
-        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isDense());
-        assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isArrayBased());
-        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isRandomAccess());
-        assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isDistributed());
-    }
-
-    /** */
-    public void testExternalization() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        ExternalizeTest<CacheMatrix<Integer, Double>> externalizeTest = new ExternalizeTest<CacheMatrix<Integer, Double>>() {
-
-            @Override public void externalizeTest() {
-                super.externalizeTest(cacheMatrix);
-            }
-        };
-
-        externalizeTest.externalizeTest();
-    }
-
-    /** */
-    public void testMinMax() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                cacheMatrix.set(i, j, i * rows + j);
-
-        assertEquals(0.0, cacheMatrix.minValue(), 0.0);
-        assertEquals(rows * cols - 1, cacheMatrix.maxValue(), 0.0);
-    }
-
-    /** */
-    public void testMap() {
-        IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
-        MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
-        IgniteCache<Integer, Double> cache = getCache();
-        final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
-
-        initMatrix(cacheMatrix);
-
-        cacheMatrix.map(value -> value + 10);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                assertEquals(10.0, cacheMatrix.getX(i, j), 0.0);
-    }
-
-    /** */
-    private IgniteCache<Integer, Double> getCache() {
-        assert ignite != null;
-
-        CacheConfiguration cfg = new CacheConfiguration();
-        cfg.setName(CACHE_NAME);
-
-        IgniteCache<Integer, Double> cache = ignite.getOrCreateCache(CACHE_NAME);
-
-        assert cache != null;
-        return cache;
-    }
-
-    /** */
-    private MatrixKeyMapper<Integer> getKeyMapper(final int rows, final int cols) {
-        return new MatrixKeyMapperForTests(rows, cols);
-    }
-
-    /** Init the given matrix by random values. */
-    private void fillMatrix(Matrix m) {
-        for (int i = 0; i < m.rowSize(); i++)
-            for (int j = 0; j < m.columnSize(); j++)
-                m.set(i, j, Math.random());
-    }
-
-    /** Init the given matrix by zeros. */
-    private void initMatrix(Matrix m) {
-        for (int i = 0; i < m.rowSize(); i++)
-            for (int j = 0; j < m.columnSize(); j++)
-                m.set(i, j, 0d);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java
deleted file mode 100644
index 1f0537c..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOffHeapMatrixConstructorTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class DenseLocalOffHeapMatrixConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(0, 1), "invalid row parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(1, 0), "invalid col parameter");
-
-        //noinspection ConstantConditions
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(null), "null matrix parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DenseLocalOffHeapMatrix(new double[][] {null, new double[1]}),
-            "null row in matrix");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        assertEquals("Expected number of rows, int parameters.", 1,
-            new DenseLocalOffHeapMatrix(1, 2).rowSize());
-
-        assertEquals("Expected number of rows, double[][] parameter.", 1,
-            new DenseLocalOffHeapMatrix(new double[][] {new double[2]}).rowSize());
-
-        assertEquals("Expected number of cols, int parameters.", 1,
-            new DenseLocalOffHeapMatrix(2, 1).columnSize());
-
-        assertEquals("Expected number of cols, double[][] parameter.", 1,
-            new DenseLocalOffHeapMatrix(new double[][] {new double[1], new double[1]}).columnSize());
-
-        double[][] data1 = new double[][] {{1, 2}, {3, 4}}, data2 = new double[][] {{1, 2}, {3, 5}};
-
-        assertTrue("Matrices with same values are expected to be equal",
-            new DenseLocalOffHeapMatrix(data1).equals(new DenseLocalOffHeapMatrix(data1)));
-
-        assertFalse("Matrices with same values are expected to be equal",
-            new DenseLocalOffHeapMatrix(data1).equals(new DenseLocalOffHeapMatrix(data2)));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java
deleted file mode 100644
index 0a25e31..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DenseLocalOnHeapMatrixConstructorTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.util.function.Supplier;
-import org.apache.ignite.math.Matrix;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-/** */
-public class DenseLocalOnHeapMatrixConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(0, 1), "invalid row parameter");
-
-        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(1, 0), "invalid col parameter");
-
-        //noinspection ConstantConditions
-        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(null), "null matrix parameter");
-
-        verifyAssertionError(() -> new DenseLocalOnHeapMatrix(new double[][] {null, new double[1]}),
-            "null row in matrix");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        assertEquals("Expected number of rows, int parameters.", 1,
-            new DenseLocalOnHeapMatrix(1, 2).rowSize());
-
-        assertEquals("Expected number of rows, double[][] parameter.", 1,
-            new DenseLocalOnHeapMatrix(new double[][] {new double[2]}).rowSize());
-
-        assertEquals("Expected number of cols, int parameters.", 1,
-            new DenseLocalOnHeapMatrix(2, 1).columnSize());
-
-        assertEquals("Expected number of cols, double[][] parameter.", 1,
-            new DenseLocalOnHeapMatrix(new double[][] {new double[1], new double[1]}).columnSize());
-    }
-
-    /** */
-    static void verifyAssertionError(Supplier<Matrix> ctor, String desc) {
-        try {
-            assertNotNull("Unexpected null matrix in " + desc, ctor.get());
-        }
-        catch (AssertionError ae) {
-            return;
-        }
-
-        fail("Expected error not caught in " + desc);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DiagonalMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DiagonalMatrixTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DiagonalMatrixTest.java
deleted file mode 100644
index c0c2af7..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/DiagonalMatrixTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.MathTestConstants;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Tests for {@link DiagonalMatrix}.
- */
-public class DiagonalMatrixTest extends ExternalizeTest<DiagonalMatrix> {
-    /** */
-    public static final String UNEXPECTED_VALUE = "Unexpected value";
-
-    /** */
-    private DiagonalMatrix testMatrix;
-
-    /** */
-    @Before
-    public void setup() {
-        DenseLocalOnHeapMatrix parent = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
-        fillMatrix(parent);
-        testMatrix = new DiagonalMatrix(parent);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void externalizeTest() {
-        externalizeTest(testMatrix);
-    }
-
-    /** */
-    @Test
-    public void testSetGetBasic() {
-        double testVal = 42;
-        for (int i = 0; i < MathTestConstants.STORAGE_SIZE; i++) {
-            testMatrix.set(i, i, testVal);
-
-            assertEquals(UNEXPECTED_VALUE + " at (" + i + "," + i + ")", testMatrix.get(i, i), testVal, 0d);
-        }
-
-        //noinspection EqualsWithItself
-        assertTrue("Matrix is expected to be equal to self.", testMatrix.equals(testMatrix));
-        //noinspection ObjectEqualsNull
-        assertFalse("Matrix is expected to be not equal to null.", testMatrix.equals(null));
-    }
-
-    /** */
-    @Test
-    public void testSetGet() {
-        verifyDiagonal(testMatrix);
-
-        final int size = MathTestConstants.STORAGE_SIZE;
-
-        for (Matrix m : new Matrix[] {
-            new DenseLocalOnHeapMatrix(size + 1, size),
-            new DenseLocalOnHeapMatrix(size, size + 1)}) {
-            fillMatrix(m);
-
-            verifyDiagonal(new DiagonalMatrix(m));
-        }
-
-        final double[] data = new double[size];
-
-        for (int i = 0; i < size; i++)
-            data[i] = 1 + i;
-
-        final Matrix m = new DiagonalMatrix(new DenseLocalOnHeapVector(data));
-
-        assertEquals("Rows in matrix constructed from vector", size, m.rowSize());
-        assertEquals("Cols in matrix constructed from vector", size, m.columnSize());
-
-        for (int i = 0; i < size; i++)
-            assertEquals(UNEXPECTED_VALUE + " at vector index " + i, data[i], m.get(i, i), 0d);
-
-        verifyDiagonal(m);
-
-        final Matrix m1 = new DiagonalMatrix(data);
-
-        assertEquals("Rows in matrix constructed from array", size, m1.rowSize());
-        assertEquals("Cols in matrix constructed from array", size, m1.columnSize());
-
-        for (int i = 0; i < size; i++)
-            assertEquals(UNEXPECTED_VALUE + " at array index " + i, data[i], m1.get(i, i), 0d);
-
-        verifyDiagonal(m1);
-    }
-
-    /** */
-    @Test
-    public void testConstant() {
-        final int size = MathTestConstants.STORAGE_SIZE;
-
-        for (double val : new double[] {-1.0, 0.0, 1.0}) {
-            Matrix m = new DiagonalMatrix(size, val);
-
-            assertEquals("Rows in matrix", size, m.rowSize());
-            assertEquals("Cols in matrix", size, m.columnSize());
-
-            for (int i = 0; i < size; i++)
-                assertEquals(UNEXPECTED_VALUE + " at index " + i, val, m.get(i, i), 0d);
-
-            verifyDiagonal(m, true);
-        }
-    }
-
-    /** */
-    @Test
-    public void testAttributes() {
-        assertTrue(UNEXPECTED_VALUE, testMatrix.rowSize() == MathTestConstants.STORAGE_SIZE);
-        assertTrue(UNEXPECTED_VALUE, testMatrix.columnSize() == MathTestConstants.STORAGE_SIZE);
-
-        assertFalse(UNEXPECTED_VALUE, testMatrix.isArrayBased());
-        assertTrue(UNEXPECTED_VALUE, testMatrix.isDense());
-        assertFalse(UNEXPECTED_VALUE, testMatrix.isDistributed());
-
-        assertEquals(UNEXPECTED_VALUE, testMatrix.isRandomAccess(), !testMatrix.isSequentialAccess());
-        assertTrue(UNEXPECTED_VALUE, testMatrix.isRandomAccess());
-    }
-
-    /** */
-    @Test
-    public void testNullParams() {
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DiagonalMatrix((Matrix)null), "Null Matrix parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DiagonalMatrix((Vector)null), "Null Vector parameter");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new DiagonalMatrix((double[])null), "Null double[] parameter");
-    }
-
-    /** */
-    private void verifyDiagonal(Matrix m, boolean readonly) {
-        final int rows = m.rowSize(), cols = m.columnSize();
-
-        final String sizeDetails = "rows" + "X" + "cols " + rows + "X" + cols;
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++) {
-                final String details = " at (" + i + "," + j + "), " + sizeDetails;
-
-                final boolean diagonal = i == j;
-
-                final double old = m.get(i, j);
-
-                if (!diagonal)
-                    assertEquals(UNEXPECTED_VALUE + details, 0, old, 0d);
-
-                final double exp = diagonal && !readonly ? old + 1 : old;
-
-                boolean expECaught = false;
-
-                try {
-                    m.set(i, j, exp);
-                }
-                catch (UnsupportedOperationException uoe) {
-                    if (diagonal && !readonly)
-                        throw uoe;
-
-                    expECaught = true;
-                }
-
-                if ((!diagonal || readonly) && !expECaught)
-                    fail("Expected exception was not caught " + details);
-
-                assertEquals(UNEXPECTED_VALUE + details, exp, m.get(i, j), 0d);
-            }
-    }
-
-    /** */
-    private void verifyDiagonal(Matrix m) {
-        verifyDiagonal(m, false);
-    }
-
-    /** */
-    private void fillMatrix(Matrix m) {
-        final int rows = m.rowSize(), cols = m.columnSize();
-
-        boolean negative = false;
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                m.set(i, j, (negative = !negative) ? -(i * cols + j + 1) : i * cols + j + 1);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/FunctionMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/FunctionMatrixConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/FunctionMatrixConstructorTest.java
deleted file mode 100644
index a5ac84a..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/FunctionMatrixConstructorTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class FunctionMatrixConstructorTest {
-    /** */
-    @Test
-    public void invalidArgsTest() {
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(0, 1, (i, j) -> 0.0),
-            "Invalid row parameter.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 0, (i, j) -> 0.0),
-            "Invalid col parameter.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 1, null),
-            "Invalid func parameter.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(0, 1, (i, j) -> 0.0, null),
-            "Invalid row parameter, with setter func.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 0, (i, j) -> 0.0, null),
-            "Invalid col parameter, with setter func.");
-
-        DenseLocalOnHeapMatrixConstructorTest.verifyAssertionError(() -> new FunctionMatrix(1, 1, null, null),
-            "Invalid func parameter, with setter func.");
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        for (int rows : new int[] {1, 2, 3})
-            for (int cols : new int[] {1, 2, 3})
-                basicTest(rows, cols);
-
-        Matrix m = new FunctionMatrix(1, 1, (i, j) -> 1d);
-        //noinspection EqualsWithItself
-        assertTrue("Matrix is expected to be equal to self.", m.equals(m));
-        //noinspection ObjectEqualsNull
-        assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
-    }
-
-    /** */
-    private void basicTest(int rows, int cols) {
-        double[][] data = new double[rows][cols];
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++)
-                data[row][col] = row * cols + row;
-
-        Matrix mReadOnly = new FunctionMatrix(rows, cols, (i, j) -> data[i][j]);
-
-        assertEquals("Rows in matrix.", rows, mReadOnly.rowSize());
-        assertEquals("Cols in matrix.", cols, mReadOnly.columnSize());
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++) {
-                assertEquals("Unexpected value at " + row + "x" + col, data[row][col], mReadOnly.get(row, col), 0d);
-
-                boolean expECaught = false;
-
-                try {
-                    mReadOnly.set(row, col, 0.0);
-                }
-                catch (UnsupportedOperationException uoe) {
-                    expECaught = true;
-                }
-
-                assertTrue("Expected exception wasn't thrown at " + row + "x" + col, expECaught);
-            }
-
-        Matrix m = new FunctionMatrix(rows, cols, (i, j) -> data[i][j], (i, j, val) -> data[i][j] = val);
-
-        assertEquals("Rows in matrix, with setter function.", rows, m.rowSize());
-        assertEquals("Cols in matrix, with setter function.", cols, m.columnSize());
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++) {
-                assertEquals("Unexpected value at " + row + "x" + col, data[row][col], m.get(row, col), 0d);
-
-                m.set(row, col, -data[row][col]);
-            }
-
-        for (int row = 0; row < rows; row++)
-            for (int col = 0; col < cols; col++)
-                assertEquals("Unexpected value set at " + row + "x" + col, -(row * cols + row), m.get(row, col), 0d);
-
-        assertTrue("Incorrect copy for empty matrix.", m.copy().equals(m));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixAttributeTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixAttributeTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixAttributeTest.java
deleted file mode 100644
index c9fb390..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixAttributeTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Function;
-import org.apache.ignite.math.Matrix;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Attribute tests for matrices.
- *
- * TODO: WIP
- */
-public class MatrixAttributeTest {
-    /** */
-    private final List<MatrixAttributeTest.AttrCfg> attrCfgs = Arrays.asList(
-        new AttrCfg("isDense", Matrix::isDense,
-            DenseLocalOnHeapMatrix.class, DenseLocalOffHeapMatrix.class, RandomMatrix.class, DiagonalMatrix.class),
-        new AttrCfg("isArrayBased", Matrix::isArrayBased, DenseLocalOnHeapMatrix.class),
-        new AttrCfg("isDistributed", Matrix::isDistributed),
-        new AttrCfg("isRandomAccess", Matrix::isRandomAccess, DenseLocalOnHeapMatrix.class, DenseLocalOffHeapMatrix.class, RandomMatrix.class, DiagonalMatrix.class, SparseLocalOnHeapMatrix.class),
-        new AttrCfg("isSequentialAccess", Matrix::isSequentialAccess, DiagonalMatrix.class)
-    );
-
-    /** */
-    private final List<MatrixAttributeTest.Specification> specFixture = Arrays.asList(
-        new Specification(new DenseLocalOnHeapMatrix(1, 1)),
-        new Specification(new DenseLocalOffHeapMatrix(1, 1)),
-        new Specification(new RandomMatrix(1, 1)),
-        new Specification(new DiagonalMatrix(new double[] {1.0})),
-        new Specification(new FunctionMatrix(1, 1, (x, y) -> 1.0)),
-        new Specification(new SparseLocalOnHeapMatrix(1, 1))
-    );
-
-    /** */
-    @Test
-    public void isDenseTest() {
-        assertAttribute("isDense");
-    }
-
-    /** */
-    @Test
-    public void isArrayBasedTest() {
-        assertAttribute("isArrayBased");
-    }
-
-    /** */
-    @Test
-    public void isSequentialAccessTest() {
-        assertAttribute("isSequentialAccess");
-    }
-
-    /** */
-    @Test
-    public void isRandomAccessTest() {
-        assertAttribute("isRandomAccess");
-    }
-
-    /** */
-    @Test
-    public void isDistributedTest() {
-        assertAttribute("isDistributed");
-    }
-
-    /** */
-    private void assertAttribute(String name) {
-        final MatrixAttributeTest.AttrCfg attr = attrCfg(name);
-
-        for (MatrixAttributeTest.Specification spec : specFixture)
-            spec.verify(attr);
-    }
-
-    /** */
-    private MatrixAttributeTest.AttrCfg attrCfg(String name) {
-        for (MatrixAttributeTest.AttrCfg attr : attrCfgs)
-            if (attr.name.equals(name))
-                return attr;
-
-        throw new IllegalArgumentException("Undefined attribute " + name);
-    }
-
-    /** See http://en.wikipedia.org/wiki/Specification_pattern */
-    private static class Specification {
-        /** */
-        private final Matrix m;
-        /** */
-        private final Class<? extends Matrix> underlyingType;
-        /** */
-        private final List<String> attrsFromUnderlying;
-        /** */
-        final String desc;
-
-        /** */
-        Specification(Matrix m, Class<? extends Matrix> underlyingType, String... attrsFromUnderlying) {
-            this.m = m;
-            this.underlyingType = underlyingType;
-            this.attrsFromUnderlying = Arrays.asList(attrsFromUnderlying);
-            final Class<? extends Matrix> clazz = m.getClass();
-            desc = clazz.getSimpleName() + (clazz.equals(underlyingType)
-                ? "" : " (underlying type " + underlyingType.getSimpleName() + ")");
-        }
-
-        /** */
-        Specification(Matrix m) {
-            this(m, m.getClass());
-        }
-
-        /** */
-        void verify(MatrixAttributeTest.AttrCfg attr) {
-            final boolean obtained = attr.obtain.apply(m);
-
-            final Class<? extends Matrix> typeToCheck
-                = attrsFromUnderlying.contains(attr.name) ? underlyingType : m.getClass();
-
-            final boolean exp = attr.trueInTypes.contains(typeToCheck);
-
-            assertEquals("Unexpected " + attr.name + " value for " + desc, exp, obtained);
-        }
-    }
-
-    /** */
-    private static class AttrCfg {
-        /** */
-        final String name;
-        /** */
-        final Function<Matrix, Boolean> obtain;
-        /** */
-        final List<Class> trueInTypes;
-
-        /** */
-        AttrCfg(String name, Function<Matrix, Boolean> obtain, Class... trueInTypes) {
-            this.name = name;
-            this.obtain = obtain;
-            this.trueInTypes = Arrays.asList(trueInTypes);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationFixtures.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationFixtures.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationFixtures.java
deleted file mode 100644
index 88aa4fe..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/matrix/MatrixImplementationFixtures.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.impls.storage.matrix.FunctionMatrixStorage;
-import org.jetbrains.annotations.NotNull;
-
-/** */
-class MatrixImplementationFixtures {
-    /** */
-    private static final List<Supplier<Iterable<Matrix>>> suppliers = Arrays.asList(
-        (Supplier<Iterable<Matrix>>)DenseLocalOnHeapMatrixFixture::new,
-        (Supplier<Iterable<Matrix>>)DenseLocalOffHeapMatrixFixture::new,
-        (Supplier<Iterable<Matrix>>)RandomMatrixFixture::new,
-        (Supplier<Iterable<Matrix>>)SparseLocalOnHeapMatrixFixture::new,
-        (Supplier<Iterable<Matrix>>)PivotedMatrixViewFixture::new,
-        (Supplier<Iterable<Matrix>>)MatrixViewFixture::new,
-        (Supplier<Iterable<Matrix>>)FunctionMatrixFixture::new,
-        (Supplier<Iterable<Matrix>>)DiagonalMatrixFixture::new,
-        (Supplier<Iterable<Matrix>>)TransposedMatrixViewFixture::new
-    );
-
-    /** */
-    void consumeSampleMatrix(BiConsumer<Matrix, String> consumer) {
-        for (Supplier<Iterable<Matrix>> fixtureSupplier : suppliers) {
-            final Iterable<Matrix> fixture = fixtureSupplier.get();
-
-            for (Matrix matrix : fixture) {
-                consumer.accept(matrix, fixture.toString());
-
-                matrix.destroy();
-            }
-        }
-    }
-
-    /** */
-    private static class DenseLocalOnHeapMatrixFixture extends MatrixSizeIterator {
-        /** */
-        DenseLocalOnHeapMatrixFixture() {
-            super(DenseLocalOnHeapMatrix::new, "DenseLocalOnHeapMatrix");
-        }
-    }
-
-    /** */
-    private static class DenseLocalOffHeapMatrixFixture extends MatrixSizeIterator {
-        /** */
-        DenseLocalOffHeapMatrixFixture() {
-            super(DenseLocalOffHeapMatrix::new, "DenseLocalOffHeapMatrix");
-        }
-    }
-
-    /** */
-    private static class RandomMatrixFixture extends MatrixSizeIterator {
-        /** */
-        RandomMatrixFixture() {
-            super(RandomMatrix::new, "RandomMatrix");
-        }
-    }
-
-    /** */
-    private static class SparseLocalOnHeapMatrixFixture extends MatrixSizeIterator {
-        /** */
-        SparseLocalOnHeapMatrixFixture() {
-            super(SparseLocalOnHeapMatrix::new, "SparseLocalOnHeapMatrix");
-        }
-    }
-
-    /** */
-    private static class PivotedMatrixViewFixture extends WrapperMatrixIterator {
-        /** */
-        PivotedMatrixViewFixture() {
-            super(PivotedMatrixView::new, "PivotedMatrixView over DenseLocalOnHeapMatrix");
-        }
-    }
-
-    /** */
-    private static class MatrixViewFixture extends WrapperMatrixIterator {
-        /** */
-        MatrixViewFixture() {
-            super((matrix) -> new MatrixView(matrix, 0, 0, matrix.rowSize(), matrix.columnSize()),
-                "MatrixView over DenseLocalOnHeapMatrix");
-        }
-    }
-
-    /** */
-    private static class FunctionMatrixFixture extends WrapperMatrixIterator {
-        /** */
-        FunctionMatrixFixture() {
-            super(FunctionMatrixForTest::new, "FunctionMatrix wrapping DenseLocalOnHeapMatrix");
-        }
-    }
-
-    /** */
-    private static class DiagonalMatrixFixture extends DiagonalIterator {
-        /** */
-        DiagonalMatrixFixture() {
-            super(DenseLocalOnHeapMatrix::new, "DiagonalMatrix over DenseLocalOnHeapMatrix");
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Matrix> iterator() {
-            return new Iterator<Matrix>() {
-                /** {@inheritDoc} */
-                @Override public boolean hasNext() {
-                    return hasNextSize(getSizeIdx());
-                }
-
-                /** {@inheritDoc} */
-                @Override public Matrix next() {
-                    assert getSize(getSizeIdx()) == 1 : "Only size 1 allowed for diagonal matrix fixture.";
-
-                    Matrix matrix = getConstructor().apply(getSize(getSizeIdx()), getSize(getSizeIdx()));
-
-                    nextIdx();
-
-                    return new DiagonalMatrix(matrix);
-                }
-            };
-        }
-    }
-
-    /** */
-    private static class TransposedMatrixViewFixture extends WrapperMatrixIterator {
-        /** */
-        TransposedMatrixViewFixture() {
-            super(TransposedMatrixView::new, "TransposedMatrixView over DenseLocalOnHeapMatrix");
-        }
-    }
-
-    /** */
-    private static abstract class DiagonalIterator implements Iterable<Matrix> {
-        /** */
-        private final Integer[] sizes = new Integer[] {1, null};
-        /** */
-        private int sizeIdx = 0;
-
-        /** */
-        private BiFunction<Integer, Integer, ? extends Matrix> constructor;
-        /** */
-        private String desc;
-
-        /** */
-        DiagonalIterator(BiFunction<Integer, Integer, ? extends Matrix> constructor, String desc) {
-            this.constructor = constructor;
-            this.desc = desc;
-        }
-
-        /** */
-        public BiFunction<Integer, Integer, ? extends Matrix> getConstructor() {
-            return constructor;
-        }
-
-        /** */
-        int getSizeIdx() {
-            return sizeIdx;
-        }
-
-        /** */
-        @Override public String toString() {
-            return desc + "{rows=" + sizes[sizeIdx] + ", cols=" + sizes[sizeIdx] + "}";
-        }
-
-        /** */
-        boolean hasNextSize(int idx) {
-            return sizes[idx] != null;
-        }
-
-        /** */
-        Integer getSize(int idx) {
-            return sizes[idx];
-        }
-
-        /** */
-        void nextIdx() {
-            sizeIdx++;
-        }
-    }
-
-    /** */
-    private static class WrapperMatrixIterator extends MatrixSizeIterator {
-        /** */
-        private final Function<Matrix, Matrix> wrapperCtor;
-
-        /** */
-        WrapperMatrixIterator(Function<Matrix, Matrix> wrapperCtor, String desc) {
-            super(DenseLocalOnHeapMatrix::new, desc);
-
-            this.wrapperCtor = wrapperCtor;
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Matrix> iterator() {
-            return new Iterator<Matrix>() {
-                /** {@inheritDoc} */
-                @Override public boolean hasNext() {
-                    return hasNextCol(getSizeIdx()) && hasNextRow(getSizeIdx());
-                }
-
-                /** {@inheritDoc} */
-                @Override public Matrix next() {
-                    Matrix matrix = getConstructor().apply(getRow(getSizeIdx()), getCol(getSizeIdx()));
-
-                    nextIdx();
-
-                    return wrapperCtor.apply(matrix);
-                }
-            };
-        }
-    }
-
-    /** */
-    private static class MatrixSizeIterator implements Iterable<Matrix> {
-        /** */
-        private final Integer[] rows = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 1024, null};
-        /** */
-        private final Integer[] cols = new Integer[] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1024, 512, null};
-        /** */
-        private int sizeIdx = 0;
-
-        /** */
-        private BiFunction<Integer, Integer, ? extends Matrix> constructor;
-        /** */
-        private String desc;
-
-        /** */
-        MatrixSizeIterator(BiFunction<Integer, Integer, ? extends Matrix> constructor, String desc) {
-            this.constructor = constructor;
-            this.desc = desc;
-        }
-
-        /** */
-        public BiFunction<Integer, Integer, ? extends Matrix> getConstructor() {
-            return constructor;
-        }
-
-        /** */
-        int getSizeIdx() {
-            return sizeIdx;
-        }
-
-        /** */
-        @Override public String toString() {
-            return desc + "{rows=" + rows[sizeIdx] + ", cols=" + cols[sizeIdx] + "}";
-        }
-
-        /** */
-        boolean hasNextRow(int idx) {
-            return rows[idx] != null;
-        }
-
-        /** */
-        boolean hasNextCol(int idx) {
-            return cols[idx] != null;
-        }
-
-        /** */
-        Integer getRow(int idx) {
-            return rows[idx];
-        }
-
-        /** */
-        int getCol(int idx) {
-            return cols[idx];
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Matrix> iterator() {
-            return new Iterator<Matrix>() {
-                /** {@inheritDoc} */
-                @Override public boolean hasNext() {
-                    return hasNextCol(sizeIdx) && hasNextRow(sizeIdx);
-                }
-
-                /** {@inheritDoc} */
-                @Override public Matrix next() {
-                    Matrix matrix = constructor.apply(rows[sizeIdx], cols[sizeIdx]);
-
-                    nextIdx();
-
-                    return matrix;
-                }
-            };
-        }
-
-        /** */
-        void nextIdx() {
-            sizeIdx++;
-        }
-    }
-
-    /** Subclass tweaked for serialization */
-    private static class FunctionMatrixForTest extends FunctionMatrix {
-        /** */
-        Matrix underlying;
-
-        /** */
-        public FunctionMatrixForTest() {
-            // No-op.
-        }
-
-        /** */
-        FunctionMatrixForTest(Matrix underlying) {
-            super(underlying.rowSize(), underlying.columnSize(), underlying::get, underlying::set);
-
-            this.underlying = underlying;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Matrix copy() {
-            return new FunctionMatrixForTest(underlying);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            super.writeExternal(out);
-
-            out.writeObject(underlying);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            super.readExternal(in);
-
-            underlying = (Matrix)in.readObject();
-
-            setStorage(new FunctionMatrixStorage(underlying.rowSize(), underlying.columnSize(),
-                underlying::get, underlying::set));
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            int res = 1;
-
-            res = res * 37 + underlying.hashCode();
-
-            return res;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            FunctionMatrixForTest that = (FunctionMatrixForTest)o;
-
-            return underlying != null ? underlying.equals(that.underlying) : that.underlying == null;
-        }
-    }
-}


[12/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractVector.java
new file mode 100644
index 0000000..3c075f4
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractVector.java
@@ -0,0 +1,903 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Spliterator;
+import java.util.function.Consumer;
+import java.util.function.IntToDoubleFunction;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.impls.matrix.MatrixView;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * This class provides a helper implementation of the {@link Vector}
+ * interface to minimize the effort required to implement it.
+ * Subclasses may override some of the implemented methods if a more
+ * specific or optimized implementation is desirable.
+ */
+public abstract class AbstractVector implements Vector {
+    /** Vector storage implementation. */
+    private VectorStorage sto;
+
+    /** Meta attribute storage. */
+    private Map<String, Object> meta = new HashMap<>();
+
+    /** Vector's GUID. */
+    private IgniteUuid guid = IgniteUuid.randomUuid();
+
+    /** Cached value for length squared. */
+    private double lenSq = 0.0;
+
+    /** Maximum cached element. */
+    private Element maxElm = null;
+    /** Minimum cached element. */
+    private Element minElm = null;
+
+    /** Readonly flag (false by default). */
+    private boolean readOnly = false;
+
+    /** Read-only error message. */
+    private static final String RO_MSG = "Vector is read-only.";
+
+    /**
+     *
+     */
+    private void ensureReadOnly() {
+        if (readOnly)
+            throw new UnsupportedOperationException(RO_MSG);
+    }
+
+    /**
+     * @param sto Storage.
+     */
+    public AbstractVector(VectorStorage sto) {
+        this(false, sto);
+    }
+
+    /**
+     * @param readOnly Is read only.
+     * @param sto Storage.
+     */
+    public AbstractVector(boolean readOnly, VectorStorage sto) {
+        assert sto != null;
+
+        this.readOnly = readOnly;
+        this.sto = sto;
+    }
+
+    /**
+     *
+     */
+    public AbstractVector() {
+        // No-op.
+    }
+
+    /**
+     * Set storage.
+     *
+     * @param sto Storage.
+     */
+    protected void setStorage(VectorStorage sto) {
+        this.sto = sto;
+    }
+
+    /**
+     * @param i Index.
+     * @param v Value.
+     */
+    protected void storageSet(int i, double v) {
+        ensureReadOnly();
+
+        sto.set(i, v);
+
+        // Reset cached values.
+        lenSq = 0.0;
+        maxElm = minElm = null;
+    }
+
+    /**
+     * @param i Index.
+     * @return Value.
+     */
+    protected double storageGet(int i) {
+        return sto.get(i);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return sto.size();
+    }
+
+    /**
+     * Check index bounds.
+     *
+     * @param idx Index to check.
+     */
+    protected void checkIndex(int idx) {
+        if (idx < 0 || idx >= sto.size())
+            throw new IndexException(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int idx) {
+        checkIndex(idx);
+
+        return storageGet(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getX(int idx) {
+        return storageGet(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return sto.isArrayBased();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector sort() {
+        if (isArrayBased())
+            Arrays.parallelSort(sto.data());
+        else
+            throw new UnsupportedOperationException();
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
+        if (sto.isArrayBased()) {
+            double[] data = sto.data();
+
+            Arrays.setAll(data, (idx) -> fun.apply(data[idx]));
+        }
+        else {
+            int len = size();
+
+            for (int i = 0; i < len; i++)
+                storageSet(i, fun.apply(storageGet(i)));
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun) {
+        checkCardinality(vec);
+
+        int len = size();
+
+        for (int i = 0; i < len; i++)
+            storageSet(i, fun.apply(storageGet(i), vec.get(i)));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
+        int len = size();
+
+        for (int i = 0; i < len; i++)
+            storageSet(i, fun.apply(storageGet(i), y));
+
+        return this;
+    }
+
+    /**
+     * @param idx Index.
+     * @return Value.
+     */
+    protected Element makeElement(int idx) {
+        checkIndex(idx);
+
+        return new Element() {
+            /** {@inheritDoc} */
+            @Override public double get() {
+                return storageGet(idx);
+            }
+
+            /** {@inheritDoc} */
+            @Override public int index() {
+                return idx;
+            }
+
+            /** {@inheritDoc} */
+            @Override public void set(double val) {
+                storageSet(idx, val);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element minElement() {
+        if (minElm == null) {
+            int minIdx = 0;
+            int len = size();
+
+            for (int i = 0; i < len; i++)
+                if (storageGet(i) < storageGet(minIdx))
+                    minIdx = i;
+
+            minElm = makeElement(minIdx);
+        }
+
+        return minElm;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element maxElement() {
+        if (maxElm == null) {
+            int maxIdx = 0;
+            int len = size();
+
+            for (int i = 0; i < len; i++)
+                if (storageGet(i) > storageGet(maxIdx))
+                    maxIdx = i;
+
+            maxElm = makeElement(maxIdx);
+        }
+
+        return maxElm;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double minValue() {
+        return minElement().get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxValue() {
+        return maxElement().get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector set(int idx, double val) {
+        checkIndex(idx);
+
+        storageSet(idx, val);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector setX(int idx, double val) {
+        storageSet(idx, val);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector increment(int idx, double val) {
+        checkIndex(idx);
+
+        storageSet(idx, storageGet(idx) + val);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector incrementX(int idx, double val) {
+        storageSet(idx, storageGet(idx) + val);
+
+        return this;
+    }
+
+    /**
+     * Tests if given value is considered a zero value.
+     *
+     * @param val Value to check.
+     */
+    protected boolean isZero(double val) {
+        return val == 0.0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        double sum = 0;
+        int len = size();
+
+        for (int i = 0; i < len; i++)
+            sum += storageGet(i);
+
+        return sum;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid guid() {
+        return guid;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<Element> all() {
+        return new Iterable<Element>() {
+            private int idx = 0;
+
+            /** {@inheritDoc} */
+            @NotNull
+            @Override public Iterator<Element> iterator() {
+                return new Iterator<Element>() {
+                    /** {@inheritDoc} */
+                    @Override public boolean hasNext() {
+                        return size() > 0 && idx < size();
+                    }
+
+                    /** {@inheritDoc} */
+                    @Override public Element next() {
+                        if (hasNext())
+                            return getElement(idx++);
+
+                        throw new NoSuchElementException();
+                    }
+                };
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public int nonZeroElements() {
+        int cnt = 0;
+
+        for (Element ignored : nonZeroes())
+            cnt++;
+
+        return cnt;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun,
+        T zeroVal) {
+        T res = zeroVal;
+        int len = size();
+
+        for (int i = 0; i < len; i++)
+            res = foldFun.apply(res, mapFun.apply(storageGet(i)));
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T foldMap(Vector vec, IgniteBiFunction<T, Double, T> foldFun,
+        IgniteBiFunction<Double, Double, Double> combFun, T zeroVal) {
+        checkCardinality(vec);
+
+        T res = zeroVal;
+        int len = size();
+
+        for (int i = 0; i < len; i++)
+            res = foldFun.apply(res, combFun.apply(storageGet(i), vec.getX(i)));
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<Element> nonZeroes() {
+        return new Iterable<Element>() {
+            private int idx = 0;
+            private int idxNext = -1;
+
+            /** {@inheritDoc} */
+            @NotNull
+            @Override public Iterator<Element> iterator() {
+                return new Iterator<Element>() {
+                    @Override public boolean hasNext() {
+                        findNext();
+
+                        return !over();
+                    }
+
+                    @Override public Element next() {
+                        if (hasNext()) {
+                            idx = idxNext;
+
+                            return getElement(idxNext);
+                        }
+
+                        throw new NoSuchElementException();
+                    }
+
+                    private void findNext() {
+                        if (over())
+                            return;
+
+                        if (idxNextInitialized() && idx != idxNext)
+                            return;
+
+                        if (idxNextInitialized())
+                            idx = idxNext + 1;
+
+                        while (idx < size() && isZero(get(idx)))
+                            idx++;
+
+                        idxNext = idx++;
+                    }
+
+                    private boolean over() {
+                        return idxNext >= size();
+                    }
+
+                    private boolean idxNextInitialized() {
+                        return idxNext != -1;
+                    }
+                };
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map<String, Object> getMetaStorage() {
+        return meta;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(double val) {
+        if (sto.isArrayBased()) {
+            ensureReadOnly();
+
+            Arrays.fill(sto.data(), val);
+        }
+        else {
+            int len = size();
+
+            for (int i = 0; i < len; i++)
+                storageSet(i, val);
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(double[] vals) {
+        checkCardinality(vals);
+
+        if (sto.isArrayBased()) {
+            ensureReadOnly();
+
+            System.arraycopy(vals, 0, sto.data(), 0, vals.length);
+
+            lenSq = 0.0;
+        }
+        else {
+            int len = size();
+
+            for (int i = 0; i < len; i++)
+                storageSet(i, vals[i]);
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(Vector vec) {
+        checkCardinality(vec);
+
+        for (Vector.Element x : vec.all())
+            storageSet(x.index(), x.get());
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(IntToDoubleFunction fun) {
+        assert fun != null;
+
+        if (sto.isArrayBased()) {
+            ensureReadOnly();
+
+            Arrays.setAll(sto.data(), fun);
+        }
+        else {
+            int len = size();
+
+            for (int i = 0; i < len; i++)
+                storageSet(i, fun.applyAsDouble(i));
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Spliterator<Double> allSpliterator() {
+        return new Spliterator<Double>() {
+            /** {@inheritDoc} */
+            @Override public boolean tryAdvance(Consumer<? super Double> act) {
+                int len = size();
+
+                for (int i = 0; i < len; i++)
+                    act.accept(storageGet(i));
+
+                return true;
+            }
+
+            /** {@inheritDoc} */
+            @Override public Spliterator<Double> trySplit() {
+                return null; // No Splitting.
+            }
+
+            /** {@inheritDoc} */
+            @Override public long estimateSize() {
+                return size();
+            }
+
+            /** {@inheritDoc} */
+            @Override public int characteristics() {
+                return ORDERED | SIZED;
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Spliterator<Double> nonZeroSpliterator() {
+        return new Spliterator<Double>() {
+            /** {@inheritDoc} */
+            @Override public boolean tryAdvance(Consumer<? super Double> act) {
+                int len = size();
+
+                for (int i = 0; i < len; i++) {
+                    double val = storageGet(i);
+
+                    if (!isZero(val))
+                        act.accept(val);
+                }
+
+                return true;
+            }
+
+            /** {@inheritDoc} */
+            @Override public Spliterator<Double> trySplit() {
+                return null; // No Splitting.
+            }
+
+            /** {@inheritDoc} */
+            @Override public long estimateSize() {
+                return nonZeroElements();
+            }
+
+            /** {@inheritDoc} */
+            @Override public int characteristics() {
+                return ORDERED | SIZED;
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public double dot(Vector vec) {
+        checkCardinality(vec);
+
+        double sum = 0.0;
+        int len = size();
+
+        for (int i = 0; i < len; i++)
+            sum += storageGet(i) * vec.getX(i);
+
+        return sum;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getLengthSquared() {
+        if (lenSq == 0.0)
+            lenSq = dotSelf();
+
+        return lenSq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return sto.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return sto.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return sto.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return sto.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public VectorStorage getStorage() {
+        return sto;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewPart(int off, int len) {
+        return new VectorView(this, off, len);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix cross(Vector vec) {
+        Matrix res = likeMatrix(size(), vec.size());
+
+        if (res == null)
+            return null;
+
+        for (Element e : nonZeroes()) {
+            int row = e.index();
+
+            res.assignRow(row, vec.times(getX(row)));
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix toMatrix(boolean rowLike) {
+        Matrix res = likeMatrix(rowLike ? 1 : size(), rowLike ? size() : 1);
+
+        if (res == null)
+            return null;
+
+        if (rowLike)
+            res.assignRow(0, this);
+        else
+            res.assignColumn(0, this);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
+        Matrix res = likeMatrix(rowLike ? 1 : size() + 1, rowLike ? size() + 1 : 1);
+
+        if (res == null)
+            return null;
+
+        res.set(0, 0, zeroVal);
+
+        if (rowLike)
+            new MatrixView(res, 0, 1, 1, size()).assignRow(0, this);
+        else
+            new MatrixView(res, 1, 0, size(), 1).assignColumn(0, this);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getDistanceSquared(Vector vec) {
+        checkCardinality(vec);
+
+        double thisLenSq = getLengthSquared();
+        double thatLenSq = vec.getLengthSquared();
+        double dot = dot(vec);
+        double distEst = thisLenSq + thatLenSq - 2 * dot;
+
+        if (distEst > 1.0e-3 * (thisLenSq + thatLenSq))
+            // The vectors are far enough from each other that the formula is accurate.
+            return Math.max(distEst, 0);
+        else
+            return foldMap(vec, Functions.PLUS, Functions.MINUS_SQUARED, 0d);
+    }
+
+    /** */
+    protected void checkCardinality(Vector vec) {
+        if (vec.size() != size())
+            throw new CardinalityException(size(), vec.size());
+    }
+
+    /** */
+    protected void checkCardinality(double[] vec) {
+        if (vec.length != size())
+            throw new CardinalityException(size(), vec.length);
+    }
+
+    /** */
+    protected void checkCardinality(int[] arr) {
+        if (arr.length != size())
+            throw new CardinalityException(size(), arr.length);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector minus(Vector vec) {
+        checkCardinality(vec);
+
+        Vector cp = copy();
+
+        return cp.map(vec, Functions.MINUS);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector plus(double x) {
+        Vector cp = copy();
+
+        return x != 0.0 ? cp.map(Functions.plus(x)) : cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector divide(double x) {
+        Vector cp = copy();
+
+        if (x != 1.0)
+            for (Element element : cp.all())
+                element.set(element.get() / x);
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        if (x == 0.0)
+            return like(size());
+        else
+            return copy().map(Functions.mult(x));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(Vector vec) {
+        checkCardinality(vec);
+
+        return copy().map(vec, Functions.MULT);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector plus(Vector vec) {
+        checkCardinality(vec);
+
+        Vector cp = copy();
+
+        return cp.map(vec, Functions.PLUS);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector logNormalize() {
+        return logNormalize(2.0, Math.sqrt(getLengthSquared()));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector logNormalize(double power) {
+        return logNormalize(power, kNorm(power));
+    }
+
+    /**
+     * @param power Power.
+     * @param normLen Normalized length.
+     * @return logNormalized value.
+     */
+    private Vector logNormalize(double power, double normLen) {
+        assert !(Double.isInfinite(power) || power <= 1.0);
+
+        double denominator = normLen * Math.log(power);
+
+        Vector cp = copy();
+
+        for (Element element : cp.all())
+            element.set(Math.log1p(element.get()) / denominator);
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double kNorm(double power) {
+        assert power >= 0.0;
+
+        // Special cases.
+        if (Double.isInfinite(power))
+            return foldMap(Math::max, Math::abs, 0d);
+        else if (power == 2.0)
+            return Math.sqrt(getLengthSquared());
+        else if (power == 1.0)
+            return foldMap(Functions.PLUS, Math::abs, 0d);
+        else if (power == 0.0)
+            return nonZeroElements();
+        else
+            // Default case.
+            return Math.pow(foldMap(Functions.PLUS, Functions.pow(power), 0d), 1.0 / power);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector normalize() {
+        return divide(Math.sqrt(getLengthSquared()));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector normalize(double power) {
+        return divide(kNorm(power));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        return like(size()).assign(this);
+    }
+
+    /**
+     * @return Result of dot with self.
+     */
+    protected double dotSelf() {
+        double sum = 0.0;
+        int len = size();
+
+        for (int i = 0; i < len; i++) {
+            double v = storageGet(i);
+
+            sum += v * v;
+        }
+
+        return sum;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element getElement(int idx) {
+        return makeElement(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(sto);
+        out.writeObject(meta);
+        out.writeObject(guid);
+        out.writeBoolean(readOnly);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        sto = (VectorStorage)in.readObject();
+        meta = (Map<String, Object>)in.readObject();
+        guid = (IgniteUuid)in.readObject();
+        readOnly = in.readBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        sto.destroy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+        res += res * 37 + guid.hashCode();
+        res += sto == null ? 0 : res * 37 + sto.hashCode();
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        AbstractVector that = (AbstractVector)obj;
+
+        return (sto != null ? sto.equals(that.sto) : that.sto == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/CacheVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/CacheVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/CacheVector.java
new file mode 100644
index 0000000..7e23791
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/CacheVector.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.ValueMapper;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorKeyMapper;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.impls.CacheUtils;
+import org.apache.ignite.ml.math.impls.storage.vector.CacheVectorStorage;
+
+/**
+ * Vector based on existing cache and index and value mapping functions.
+ */
+public class CacheVector<K, V> extends AbstractVector {
+    /**
+     *
+     */
+    public CacheVector() {
+        // No-op.
+    }
+
+    /**
+     * Creates new vector over existing cache.
+     *
+     * @param size
+     * @param cache
+     * @param keyFunc
+     * @param valMapper
+     */
+    public CacheVector(
+        int size,
+        IgniteCache<K, V> cache,
+        VectorKeyMapper<K> keyFunc,
+        ValueMapper<V> valMapper) {
+        setStorage(new CacheVectorStorage<>(size, cache, keyFunc, valMapper));
+    }
+
+    /**
+     * @param mapper
+     */
+    private Vector mapOverCache(IgniteFunction<Double, Double> mapper) {
+        CacheVectorStorage<K, V> sto = storage();
+
+        CacheUtils.map(sto.cache().getName(), sto.keyMapper(), sto.valueMapper(), mapper);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double minValue() {
+        CacheVectorStorage<K, V> sto = storage();
+
+        return CacheUtils.min(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxValue() {
+        CacheVectorStorage<K, V> sto = storage();
+
+        return CacheUtils.max(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
+        return mapOverCache(fun::apply);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
+        // TODO: provide cache-optimized implementation.
+        return super.map(fun, y); // TODO
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        CacheVectorStorage<K, V> sto = storage();
+
+        return CacheUtils.sum(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(double val) {
+        return mapOverCache((Double d) -> val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector plus(double x) {
+        return mapOverCache((Double d) -> d + x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector divide(double x) {
+        return mapOverCache((Double d) -> d / x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        return mapOverCache((Double d) -> d * x);
+    }
+
+    /**
+     *
+     *
+     */
+    @SuppressWarnings({"unchecked"})
+    private CacheVectorStorage<K, V> storage() {
+        return (CacheVectorStorage<K, V>)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/ConstantVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/ConstantVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/ConstantVector.java
new file mode 100644
index 0000000..71c9c3e
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/ConstantVector.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.storage.vector.ConstantVectorStorage;
+
+/**
+ * Constant value, read-only vector.
+ */
+public class ConstantVector extends AbstractReadOnlyVector {
+    /**
+     *
+     */
+    public ConstantVector() {
+        // No-op.
+    }
+
+    /**
+     * @param size
+     * @param val
+     */
+    public ConstantVector(int size, double val) {
+        super(new ConstantVectorStorage(size, val));
+    }
+
+    /**
+     *
+     *
+     */
+    private ConstantVectorStorage storage() {
+        return (ConstantVectorStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        ConstantVectorStorage sto = storage();
+
+        return new ConstantVector(sto.size(), sto.constant());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return new ConstantVector(crd, storage().constant());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        ConstantVector that = (ConstantVector)o;
+
+        VectorStorage sto = getStorage();
+
+        return (sto != null ? sto.equals(that.getStorage()) : that.getStorage() == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DelegatingVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DelegatingVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DelegatingVector.java
new file mode 100644
index 0000000..891eb8e
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DelegatingVector.java
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.function.IntToDoubleFunction;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+
+/**
+ * Convenient class that can be used to add decorations to an existing vector. Subclasses
+ * can add weights, indices, etc. while maintaining full vector functionality.
+ */
+public class DelegatingVector implements Vector {
+    /** Delegating vector. */
+    private Vector dlg;
+
+    /** Meta attribute storage. */
+    private Map<String, Object> meta = new HashMap<>();
+
+    /** GUID. */
+    private IgniteUuid guid = IgniteUuid.randomUuid();
+
+    /** */
+    public DelegatingVector() {
+        // No-op.
+    }
+
+    /**
+     * @param dlg
+     */
+    public DelegatingVector(Vector dlg) {
+        assert dlg != null;
+
+        this.dlg = dlg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(dlg);
+        out.writeObject(meta);
+        out.writeObject(guid);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        dlg = (Vector)in.readObject();
+        meta = (Map<String, Object>)in.readObject();
+        guid = (IgniteUuid)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map<String, Object> getMetaStorage() {
+        return meta;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return dlg.likeMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix toMatrix(boolean rowLike) {
+        return dlg.toMatrix(rowLike);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
+        return dlg.toMatrixPlusOne(rowLike, zeroVal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return dlg.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return dlg.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double minValue() {
+        return dlg.minValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxValue() {
+        return dlg.maxValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return dlg.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return dlg.isArrayBased();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        return new DelegatingVector(dlg);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<Element> all() {
+        return dlg.all();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<Element> nonZeroes() {
+        return dlg.nonZeroes();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector sort() {
+        return dlg.sort();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Spliterator<Double> allSpliterator() {
+        return dlg.allSpliterator();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Spliterator<Double> nonZeroSpliterator() {
+        return dlg.nonZeroSpliterator();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element getElement(int idx) {
+        return dlg.getElement(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(double val) {
+        return dlg.assign(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(double[] vals) {
+        return dlg.assign(vals);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(Vector vec) {
+        return dlg.assign(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(IntToDoubleFunction fun) {
+        return dlg.assign(fun);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
+        return dlg.map(fun);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun) {
+        return dlg.map(vec, fun);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
+        return dlg.map(fun, y);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector divide(double x) {
+        return dlg.divide(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double dot(Vector vec) {
+        return dlg.dot(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int idx) {
+        return dlg.get(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getX(int idx) {
+        return dlg.getX(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return dlg.like(crd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector minus(Vector vec) {
+        return dlg.minus(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector normalize() {
+        return dlg.normalize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector normalize(double power) {
+        return dlg.normalize(power);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector logNormalize() {
+        return dlg.logNormalize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector logNormalize(double power) {
+        return dlg.logNormalize(power);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double kNorm(double power) {
+        return dlg.kNorm(power);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element minElement() {
+        return dlg.minElement();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element maxElement() {
+        return dlg.maxElement();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector plus(double x) {
+        return dlg.plus(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector plus(Vector vec) {
+        return dlg.plus(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector set(int idx, double val) {
+        return dlg.set(idx, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector setX(int idx, double val) {
+        return dlg.setX(idx, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector incrementX(int idx, double val) {
+        return dlg.incrementX(idx, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector increment(int idx, double val) {
+        return dlg.increment(idx, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int nonZeroElements() {
+        return dlg.nonZeroElements();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        return dlg.times(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(Vector vec) {
+        return dlg.times(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewPart(int off, int len) {
+        return dlg.viewPart(off, len);
+    }
+
+    /** {@inheritDoc} */
+    @Override public VectorStorage getStorage() {
+        return dlg.getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        return dlg.sum();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix cross(Vector vec) {
+        return dlg.cross(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun,
+        T zeroVal) {
+        return dlg.foldMap(foldFun, mapFun, zeroVal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T foldMap(Vector vec, IgniteBiFunction<T, Double, T> foldFun,
+        IgniteBiFunction<Double, Double, Double> combFun, T zeroVal) {
+        return dlg.foldMap(vec, foldFun, combFun, zeroVal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getLengthSquared() {
+        return dlg.getLengthSquared();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getDistanceSquared(Vector vec) {
+        return dlg.getDistanceSquared(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return dlg.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return dlg.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid guid() {
+        return guid;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        dlg.destroy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + meta.hashCode();
+        res = res * 37 + dlg.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        DelegatingVector that = (DelegatingVector)o;
+
+        return meta.equals(that.meta) && dlg.equals(that.dlg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVector.java
new file mode 100644
index 0000000..c635572
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOffHeapVector.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.stream.IntStream;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix;
+import org.apache.ignite.ml.math.impls.storage.vector.DenseLocalOffHeapVectorStorage;
+
+/**
+ * Implementation for {@link Vector} assuming dense logic and local offheap JVM storage.
+ * It is suitable for data sets where local, non-distributed execution is satisfactory and on-heap JVM storage
+ * is not enough to keep the entire data set.
+ */
+public class DenseLocalOffHeapVector extends AbstractVector {
+    /** */
+    public DenseLocalOffHeapVector() {
+        // No-op.
+    }
+
+    /** */
+    private void makeOffheapStorage(int size) {
+        setStorage(new DenseLocalOffHeapVectorStorage(size));
+    }
+
+    /**
+     * @param arr Array to copy to offheap storage.
+     */
+    public DenseLocalOffHeapVector(double[] arr) {
+        makeOffheapStorage(arr.length);
+
+        assign(arr);
+    }
+
+    /**
+     * @param size Vector cardinality.
+     */
+    public DenseLocalOffHeapVector(int size) {
+        makeOffheapStorage(size);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector assign(Vector vec) {
+        checkCardinality(vec);
+
+        IntStream.range(0, size()).parallel().forEach(idx -> set(idx, vec.get(idx)));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        if (x == 0.0)
+            return like(size()).assign(0);
+        else
+            return super.times(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return new DenseLocalOffHeapVector(crd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return new DenseLocalOffHeapMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        return o != null && getClass().equals(o.getClass()) && (getStorage().equals(((Vector)o).getStorage()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVector.java
new file mode 100644
index 0000000..c37bda0
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/DenseLocalOnHeapVector.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Map;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.storage.vector.ArrayVectorStorage;
+
+/**
+ * Basic implementation for vector.
+ * <p>
+ * This is a trivial implementation for vector assuming dense logic, local on-heap JVM storage
+ * based on {@code double[]} array. It is only suitable for data sets where
+ * local, non-distributed execution is satisfactory and on-heap JVM storage is enough
+ * to keep the entire data set.
+ */
+public class DenseLocalOnHeapVector extends AbstractVector {
+    /**
+     * @param size Vector cardinality.
+     */
+    private VectorStorage mkStorage(int size) {
+        return new ArrayVectorStorage(size);
+    }
+
+    /**
+     * @param arr Source array.
+     * @param cp {@code true} to clone array, reuse it otherwise.
+     */
+    private VectorStorage mkStorage(double[] arr, boolean cp) {
+        assert arr != null;
+
+        return new ArrayVectorStorage(cp ? arr.clone() : arr);
+    }
+
+    /**
+     * @param args Parameters for new Vector.
+     */
+    public DenseLocalOnHeapVector(Map<String, Object> args) {
+        assert args != null;
+
+        if (args.containsKey("size"))
+            setStorage(mkStorage((int)args.get("size")));
+        else if (args.containsKey("arr") && args.containsKey("copy"))
+            setStorage(mkStorage((double[])args.get("arr"), (boolean)args.get("copy")));
+        else
+            throw new UnsupportedOperationException("Invalid constructor argument(s).");
+    }
+
+    /** */
+    public DenseLocalOnHeapVector() {
+        // No-op.
+    }
+
+    /**
+     * @param size Vector cardinality.
+     */
+    public DenseLocalOnHeapVector(int size) {
+        setStorage(mkStorage(size));
+    }
+
+    /**
+     * @param arr Source array.
+     * @param shallowCp {@code true} to use shallow copy.
+     */
+    public DenseLocalOnHeapVector(double[] arr, boolean shallowCp) {
+        setStorage(mkStorage(arr, shallowCp));
+    }
+
+    /**
+     * @param arr Source array.
+     */
+    public DenseLocalOnHeapVector(double[] arr) {
+        this(arr, false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return new DenseLocalOnHeapMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return new DenseLocalOnHeapVector(crd);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/FunctionVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/FunctionVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/FunctionVector.java
new file mode 100644
index 0000000..a2ffd90
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/FunctionVector.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Map;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IntDoubleToVoidFunction;
+import org.apache.ignite.ml.math.impls.storage.vector.FunctionVectorStorage;
+
+/**
+ * Implementation of {@link Vector} that maps vector element index to {@link java.util.function} interfaces.
+ */
+public class FunctionVector extends AbstractVector {
+    /**
+     *
+     */
+    public FunctionVector() {
+        // No-op.
+    }
+
+    /**
+     * Creates read-write or read-only function vector.
+     *
+     * @param size Vector size.
+     * @param getFunc Function that returns value corresponding to given element index.
+     * @param setFunc Set function. If {@code null} - this will be a read-only vector.
+     */
+    public FunctionVector(int size, IgniteFunction<Integer, Double> getFunc, IntDoubleToVoidFunction setFunc) {
+        setStorage(new FunctionVectorStorage(size, getFunc, setFunc));
+    }
+
+    /**
+     * Creates read-only function vector.
+     *
+     * @param size Vector size.
+     * @param getFunc Function that returns value corresponding to given element index.
+     */
+    public FunctionVector(int size, IgniteFunction<Integer, Double> getFunc) {
+        setStorage(new FunctionVectorStorage(size, getFunc));
+    }
+
+    /**
+     * @param args Arguments for vector constructor.
+     */
+    public FunctionVector(Map<String, Object> args) {
+        assert args != null;
+
+        if (args.containsKey("size") && args.containsKey("getFunc") && args.containsKey("setFunc")) {
+            @SuppressWarnings("unchecked")
+            IgniteFunction<Integer, Double> getFunc = (IgniteFunction<Integer, Double>)args.get("getFunc");
+            IntDoubleToVoidFunction setFunc = (IntDoubleToVoidFunction)args.get("setFunc");
+            int size = (int)args.get("size");
+
+            setStorage(new FunctionVectorStorage(size, getFunc, setFunc));
+        }
+        else if (args.containsKey("size") && args.containsKey("getFunc")) {
+            @SuppressWarnings("unchecked")
+            IgniteFunction<Integer, Double> getFunc = (IgniteFunction<Integer, Double>)args.get("getFunc");
+            int size = (int)args.get("size");
+
+            setStorage(new FunctionVectorStorage(size, getFunc));
+        }
+        else
+            throw new UnsupportedOperationException("Invalid constructor argument(s).");
+    }
+
+    /**
+     *
+     *
+     */
+    private FunctionVectorStorage storage() {
+        return (FunctionVectorStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        FunctionVectorStorage sto = storage();
+
+        return new FunctionVector(crd, sto.getFunction(), sto.setFunction());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        if (x == 0.0)
+            return like(size()).assign(0);
+        else
+            return super.times(x);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorView.java
new file mode 100644
index 0000000..723c585
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/MatrixVectorView.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.impls.storage.vector.MatrixVectorStorage;
+
+/**
+ * Row or column vector view off the matrix.
+ */
+public class MatrixVectorView extends AbstractVector {
+    /** */ private Matrix parent;
+
+    /** */ private int row;
+    /** */ private int col;
+    
+    /** */ private int rowStride;
+    /** */ private int colStride;
+
+    /**
+     *
+     */
+    public MatrixVectorView() {
+        // No-op.
+    }
+
+    /**
+     * @param parent
+     * @param row
+     * @param col
+     * @param rowStride
+     * @param colStride
+     */
+    public MatrixVectorView(Matrix parent, int row, int col, int rowStride, int colStride) {
+        assert parent != null;
+
+        if (row < 0 || row >= parent.rowSize())
+            throw new IndexException(row);
+        if (col < 0 || col >= parent.columnSize())
+            throw new IndexException(col);
+
+        this.parent = parent;
+
+        this.row = row;
+        this.col = col;
+
+        this.rowStride = rowStride;
+        this.colStride = colStride;
+
+        setStorage(new MatrixVectorStorage(parent, row, col, rowStride, colStride));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        return new MatrixVectorView(parent, row, col, rowStride, colStride);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return parent.likeVector(crd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return parent.like(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        super.writeExternal(out);
+
+        out.writeObject(parent);
+        out.writeInt(row);
+        out.writeInt(col);
+        out.writeInt(rowStride);
+        out.writeInt(colStride);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        super.readExternal(in);
+
+        parent = (Matrix)in.readObject();
+        row = in.readInt();
+        col = in.readInt();
+        rowStride = in.readInt();
+        colStride = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + (parent == null ? 0 : parent.hashCode());
+        res = res * 37 + row;
+        res = res * 37 + col;
+        res = res * 37 + rowStride;
+        res = res * 37 + colStride;
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        MatrixVectorView that = (MatrixVectorView)o;
+
+        return (parent != null ? parent.equals(that.parent) : that.parent == null) &&
+            row == that.row &&
+            col == that.col &&
+            rowStride == that.rowStride &&
+            colStride == that.colStride;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorView.java
new file mode 100644
index 0000000..607bb72
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/PivotedVectorView.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.impls.storage.vector.PivotedVectorStorage;
+
+/**
+ * Pivoted (index mapped) view over another vector.
+ */
+public class PivotedVectorView extends AbstractVector {
+    /** */ private Vector vec;
+
+    /**
+     * @param vec
+     * @param pivot Mapping from external index to internal.
+     * @param unpivot Mapping from internal index to external.
+     */
+    public PivotedVectorView(Vector vec, int[] pivot, int[] unpivot) {
+        setStorage(new PivotedVectorStorage(vec.getStorage(), pivot, unpivot));
+
+        checkCardinality(pivot);
+        checkCardinality(unpivot);
+
+        this.vec = vec;
+    }
+
+    /**
+     * @param vec
+     * @param pivot
+     */
+    public PivotedVectorView(Vector vec, int[] pivot) {
+        setStorage(new PivotedVectorStorage(vec.getStorage(), pivot));
+
+        checkCardinality(pivot);
+
+        this.vec = vec;
+    }
+
+    /**
+     *
+     *
+     */
+    private PivotedVectorStorage storage() {
+        return (PivotedVectorStorage)getStorage();
+    }
+
+    /**
+     *
+     */
+    public PivotedVectorView() {
+        // No-op.
+    }
+
+    /**
+     *
+     *
+     */
+    public Vector getBaseVector() {
+        return vec;
+    }
+
+    /**
+     * @param i
+     */
+    public int pivot(int i) {
+        return storage().pivot()[i];
+    }
+
+    /**
+     * @param i
+     */
+    public int unpivot(int i) {
+        return storage().unpivot()[i];
+    }
+
+    /**
+     * @param idx
+     */
+    protected Vector.Element makeElement(int idx) {
+        checkIndex(idx);
+
+        // External index.
+        int exIdx = storage().pivot()[idx];
+
+        return new Vector.Element() {
+            /** {@inheritDoc */
+            @Override public double get() {
+                return storageGet(idx);
+            }
+
+            /** {@inheritDoc */
+            @Override public int index() {
+                return exIdx;
+            }
+
+            /** {@inheritDoc */
+            @Override public void set(double val) {
+                storageSet(idx, val);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        PivotedVectorStorage sto = storage();
+
+        return new PivotedVectorView(vec, sto.pivot(), sto.unpivot());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return vec.likeMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        if (x == 0.0)
+            return copy().map(Functions.mult(x));
+        else
+            return super.times(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        super.writeExternal(out);
+
+        out.writeObject(vec);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        super.readExternal(in);
+
+        vec = (Vector)in.readObject();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/RandomVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/RandomVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/RandomVector.java
new file mode 100644
index 0000000..08292eb
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/RandomVector.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.matrix.RandomMatrix;
+import org.apache.ignite.ml.math.impls.storage.vector.RandomVectorStorage;
+import org.apache.ignite.ml.math.Vector;
+
+/**
+ * Random vector. Each value is taken from {-1,0,1} with roughly equal probability. Note
+ * that by default, the value is determined by a relatively simple hash of the index.
+ */
+public class RandomVector extends AbstractReadOnlyVector {
+    /** */ private boolean fastHash;
+
+    /**
+     * @param size Vector cardinality.
+     * @param fastHash
+     */
+    private VectorStorage mkStorage(int size, boolean fastHash) {
+        this.fastHash = fastHash;
+
+        return new RandomVectorStorage(size, fastHash);
+    }
+
+    /**
+     * @param size
+     * @param fastHash
+     */
+    public RandomVector(int size, boolean fastHash) {
+        setStorage(mkStorage(size, fastHash));
+    }
+
+    /**
+     * @param size
+     */
+    public RandomVector(int size) {
+        this(size, true);
+    }
+
+    /**
+     * @param args
+     */
+    public RandomVector(Map<String, Object> args) {
+        assert args != null;
+
+        if (args.containsKey("size") && args.containsKey("fastHash"))
+            setStorage(mkStorage((int)args.get("size"), (boolean)args.get("fastHash")));
+        else if (args.containsKey("size"))
+            setStorage(mkStorage((int)args.get("size"), true));
+        else
+            throw new UnsupportedOperationException("Invalid constructor argument(s).");
+    }
+
+    /** */
+    public RandomVector() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return new RandomVector(crd, fastHash);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return new RandomMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        super.writeExternal(out);
+
+        out.writeBoolean(fastHash);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        super.readExternal(in);
+
+        fastHash = in.readBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + Boolean.hashCode(fastHash);
+        res = res * 37 + getStorage().hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        RandomVector that = (RandomVector)o;
+        VectorStorage sto = getStorage();
+
+        return fastHash == that.fastHash && (sto != null ? sto.equals(that.getStorage()) : that.getStorage() == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVector.java
new file mode 100644
index 0000000..cae5ca3
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVector.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.util.Map;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.storage.vector.SingleElementVectorStorage;
+
+/**
+ * Read-write vector holding a single non-zero value at some index.
+ */
+public class SingleElementVector extends AbstractVector {
+    /**
+     *
+     */
+    public SingleElementVector() {
+        // No-op
+    }
+
+    /**
+     * @param size
+     * @param idx
+     * @param val
+     */
+    public SingleElementVector(int size, int idx, double val) {
+        super(new SingleElementVectorStorage(size, idx, val));
+    }
+
+    /**
+     * @param args
+     */
+    public SingleElementVector(Map<String, Object> args) {
+        assert args != null;
+
+        if (args.containsKey("size") && args.containsKey("index") && args.containsKey("value")) {
+            int size = (int)args.get("size");
+            int idx = (int)args.get("index");
+            double val = (double)args.get("value");
+
+            setStorage(new SingleElementVectorStorage(size, idx, val));
+        }
+        else
+            throw new UnsupportedOperationException("Invalid constructor argument(s).");
+    }
+
+    /**
+     *
+     *
+     */
+    private SingleElementVectorStorage storage() {
+        return (SingleElementVectorStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element minElement() {
+        return makeElement(storage().index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element maxElement() {
+        return makeElement(storage().index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        return getX(storage().index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public int nonZeroElements() {
+        return isZero(get(storage().index())) ? 0 : 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        int idx = storage().index();
+
+        return new SingleElementVector(crd, idx, getX(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorView.java
new file mode 100644
index 0000000..0fb4105
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SingleElementVectorView.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.impls.storage.vector.SingleElementVectorDelegateStorage;
+
+/**
+ * Single value vector view over another vector.
+ */
+public class SingleElementVectorView extends AbstractVector {
+    /**
+     *
+     */
+    public SingleElementVectorView() {
+        // No-op.
+    }
+
+    /**
+     * @param vec
+     * @param idx
+     */
+    public SingleElementVectorView(Vector vec, int idx) {
+        super(new SingleElementVectorDelegateStorage(vec, idx));
+    }
+
+    /**
+     *
+     *
+     */
+    private SingleElementVectorDelegateStorage storage() {
+        return (SingleElementVectorDelegateStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector.Element minElement() {
+        return makeElement(storage().index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector.Element maxElement() {
+        return makeElement(storage().index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        return getX(storage().index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public int nonZeroElements() {
+        return isZero(getX(storage().index())) ? 0 : 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        SingleElementVectorDelegateStorage sto = storage();
+
+        return new SingleElementVectorView(sto.delegate(), sto.index());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        if (x == 0.0)
+            return copy().map(Functions.mult(x));
+        else
+            return super.times(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalOffHeapVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalOffHeapVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalOffHeapVector.java
new file mode 100644
index 0000000..fa216ff
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalOffHeapVector.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.storage.vector.SparseLocalOffHeapVectorStorage;
+
+/**
+ * Implementation for {@link Vector} assuming sparse logic and local offheap JVM storage.
+ * It is suitable for data sets where local, non-distributed execution is satisfactory and on-heap JVM storage
+ * is not enough to keep the entire data set.
+ * <p>See also: <a href="https://en.wikipedia.org/wiki/Sparse_array">Wikipedia article</a>.</p>
+ */
+public class SparseLocalOffHeapVector extends AbstractVector {
+    /**
+     * @param crd Vector cardinality.
+     */
+    public SparseLocalOffHeapVector(int crd) {
+        setStorage(new SparseLocalOffHeapVectorStorage(crd));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        return new SparseLocalOffHeapVector(crd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVector.java
new file mode 100644
index 0000000..d60eea8
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/SparseLocalVector.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.SparseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.storage.vector.SparseLocalOnHeapVectorStorage;
+
+/**
+ * Local on-heap sparse vector based on hash map storage.
+ */
+public class SparseLocalVector extends AbstractVector implements StorageConstants {
+    /**
+     *
+     */
+    public SparseLocalVector() {
+        // No-op.
+    }
+
+    /**
+     * @param size
+     * @param acsMode
+     */
+    public SparseLocalVector(int size, int acsMode) {
+        assertAccessMode(acsMode);
+
+        setStorage(new SparseLocalOnHeapVectorStorage(size, acsMode));
+    }
+
+    /** */
+    private SparseLocalOnHeapVectorStorage storage() {
+        return (SparseLocalOnHeapVectorStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        SparseLocalOnHeapVectorStorage sto = storage();
+
+        return new SparseLocalVector(crd, sto.getAccessMode());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        return new SparseLocalOnHeapMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        if (x == 0.0)
+            return assign(0);
+        else
+            return super.times(x);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/VectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/VectorView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/VectorView.java
new file mode 100644
index 0000000..f3bd4dd
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/VectorView.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import java.io.Externalizable;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.storage.vector.DelegateVectorStorage;
+
+/**
+ * Implements the partial view into the parent {@link Vector}.
+ */
+public class VectorView extends AbstractVector {
+    /**
+     * Constructor for {@link Externalizable} interface.
+     */
+    public VectorView() {
+        // No-op.
+    }
+
+    /**
+     * @param parent Backing parent {@link Vector}.
+     * @param off Offset to parent vector.
+     * @param len Size of the view.
+     */
+    public VectorView(Vector parent, int off, int len) {
+        super(new DelegateVectorStorage(parent.getStorage(), off, len));
+    }
+
+    /**
+     * @param sto Backing parent {@link VectorStorage}.
+     * @param off Offset to parent vector.
+     * @param len Size of the view.
+     */
+    public VectorView(VectorStorage sto, int off, int len) {
+        super(new DelegateVectorStorage(sto, off, len));
+    }
+
+    /** */
+    private DelegateVectorStorage storage() {
+        return (DelegateVectorStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        DelegateVectorStorage sto = storage();
+
+        return new VectorView(sto.delegate(), sto.offset(), sto.length());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector like(int crd) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix likeMatrix(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        return this == o ||
+            ((o != null)
+                && o.getClass() == getClass()
+                && (getStorage().equals(((VectorView)o).getStorage())));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/package-info.java
new file mode 100644
index 0000000..b7f485c
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains specific implementations for vectors.
+ */
+package org.apache.ignite.ml.math.impls.vector;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/package-info.java
new file mode 100644
index 0000000..5887d4b
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains main APIs for distributed code algebra.
+ */
+package org.apache.ignite.ml.math;
\ No newline at end of file


[18/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/CacheVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/CacheVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/CacheVector.java
deleted file mode 100644
index 0e9b26f..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/CacheVector.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorKeyMapper;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.impls.CacheUtils;
-import org.apache.ignite.math.impls.storage.vector.CacheVectorStorage;
-
-/**
- * Vector based on existing cache and index and value mapping functions.
- */
-public class CacheVector<K, V> extends AbstractVector {
-    /**
-     *
-     */
-    public CacheVector() {
-        // No-op.
-    }
-
-    /**
-     * Creates new vector over existing cache.
-     *
-     * @param size
-     * @param cache
-     * @param keyFunc
-     * @param valMapper
-     */
-    public CacheVector(
-        int size,
-        IgniteCache<K, V> cache,
-        VectorKeyMapper<K> keyFunc,
-        ValueMapper<V> valMapper) {
-        setStorage(new CacheVectorStorage<>(size, cache, keyFunc, valMapper));
-    }
-
-    /**
-     * @param mapper
-     */
-    private Vector mapOverCache(IgniteFunction<Double, Double> mapper) {
-        CacheVectorStorage<K, V> sto = storage();
-
-        CacheUtils.map(sto.cache().getName(), sto.keyMapper(), sto.valueMapper(), mapper);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double minValue() {
-        CacheVectorStorage<K, V> sto = storage();
-
-        return CacheUtils.min(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxValue() {
-        CacheVectorStorage<K, V> sto = storage();
-
-        return CacheUtils.max(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
-        return mapOverCache(fun::apply);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
-        // TODO: provide cache-optimized implementation.
-        return super.map(fun, y); // TODO
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        CacheVectorStorage<K, V> sto = storage();
-
-        return CacheUtils.sum(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(double val) {
-        return mapOverCache((Double d) -> val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector plus(double x) {
-        return mapOverCache((Double d) -> d + x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector divide(double x) {
-        return mapOverCache((Double d) -> d / x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        return mapOverCache((Double d) -> d * x);
-    }
-
-    /**
-     *
-     *
-     */
-    @SuppressWarnings({"unchecked"})
-    private CacheVectorStorage<K, V> storage() {
-        return (CacheVectorStorage<K, V>)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/ConstantVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/ConstantVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/ConstantVector.java
deleted file mode 100644
index 0fddfd6..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/ConstantVector.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.storage.vector.ConstantVectorStorage;
-
-/**
- * Constant value, read-only vector.
- */
-public class ConstantVector extends AbstractReadOnlyVector {
-    /**
-     *
-     */
-    public ConstantVector() {
-        // No-op.
-    }
-
-    /**
-     * @param size
-     * @param val
-     */
-    public ConstantVector(int size, double val) {
-        super(new ConstantVectorStorage(size, val));
-    }
-
-    /**
-     *
-     *
-     */
-    private ConstantVectorStorage storage() {
-        return (ConstantVectorStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        ConstantVectorStorage sto = storage();
-
-        return new ConstantVector(sto.size(), sto.constant());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        return new ConstantVector(crd, storage().constant());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        ConstantVector that = (ConstantVector)o;
-
-        VectorStorage sto = getStorage();
-
-        return (sto != null ? sto.equals(that.getStorage()) : that.getStorage() == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DelegatingVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DelegatingVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DelegatingVector.java
deleted file mode 100644
index a10fa45..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DelegatingVector.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Spliterator;
-import java.util.function.IntToDoubleFunction;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-
-/**
- * Convenient class that can be used to add decorations to an existing vector. Subclasses
- * can add weights, indices, etc. while maintaining full vector functionality.
- */
-public class DelegatingVector implements Vector {
-    /** Delegating vector. */
-    private Vector dlg;
-
-    /** Meta attribute storage. */
-    private Map<String, Object> meta = new HashMap<>();
-
-    /** GUID. */
-    private IgniteUuid guid = IgniteUuid.randomUuid();
-
-    /** */
-    public DelegatingVector() {
-        // No-op.
-    }
-
-    /**
-     * @param dlg
-     */
-    public DelegatingVector(Vector dlg) {
-        assert dlg != null;
-
-        this.dlg = dlg;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(dlg);
-        out.writeObject(meta);
-        out.writeObject(guid);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        dlg = (Vector)in.readObject();
-        meta = (Map<String, Object>)in.readObject();
-        guid = (IgniteUuid)in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map<String, Object> getMetaStorage() {
-        return meta;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return dlg.likeMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix toMatrix(boolean rowLike) {
-        return dlg.toMatrix(rowLike);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
-        return dlg.toMatrixPlusOne(rowLike, zeroVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return dlg.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return dlg.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double minValue() {
-        return dlg.minValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxValue() {
-        return dlg.maxValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return dlg.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return dlg.isArrayBased();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        return new DelegatingVector(dlg);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable<Element> all() {
-        return dlg.all();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable<Element> nonZeroes() {
-        return dlg.nonZeroes();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector sort() {
-        return dlg.sort();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Spliterator<Double> allSpliterator() {
-        return dlg.allSpliterator();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Spliterator<Double> nonZeroSpliterator() {
-        return dlg.nonZeroSpliterator();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element getElement(int idx) {
-        return dlg.getElement(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(double val) {
-        return dlg.assign(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(double[] vals) {
-        return dlg.assign(vals);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(Vector vec) {
-        return dlg.assign(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(IntToDoubleFunction fun) {
-        return dlg.assign(fun);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
-        return dlg.map(fun);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun) {
-        return dlg.map(vec, fun);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
-        return dlg.map(fun, y);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector divide(double x) {
-        return dlg.divide(x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double dot(Vector vec) {
-        return dlg.dot(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int idx) {
-        return dlg.get(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getX(int idx) {
-        return dlg.getX(idx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        return dlg.like(crd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector minus(Vector vec) {
-        return dlg.minus(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector normalize() {
-        return dlg.normalize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector normalize(double power) {
-        return dlg.normalize(power);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector logNormalize() {
-        return dlg.logNormalize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector logNormalize(double power) {
-        return dlg.logNormalize(power);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double kNorm(double power) {
-        return dlg.kNorm(power);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element minElement() {
-        return dlg.minElement();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element maxElement() {
-        return dlg.maxElement();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector plus(double x) {
-        return dlg.plus(x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector plus(Vector vec) {
-        return dlg.plus(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector set(int idx, double val) {
-        return dlg.set(idx, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector setX(int idx, double val) {
-        return dlg.setX(idx, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector incrementX(int idx, double val) {
-        return dlg.incrementX(idx, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector increment(int idx, double val) {
-        return dlg.increment(idx, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nonZeroElements() {
-        return dlg.nonZeroElements();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        return dlg.times(x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(Vector vec) {
-        return dlg.times(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector viewPart(int off, int len) {
-        return dlg.viewPart(off, len);
-    }
-
-    /** {@inheritDoc} */
-    @Override public VectorStorage getStorage() {
-        return dlg.getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        return dlg.sum();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix cross(Vector vec) {
-        return dlg.cross(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun,
-        T zeroVal) {
-        return dlg.foldMap(foldFun, mapFun, zeroVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T foldMap(Vector vec, IgniteBiFunction<T, Double, T> foldFun,
-        IgniteBiFunction<Double, Double, Double> combFun, T zeroVal) {
-        return dlg.foldMap(vec, foldFun, combFun, zeroVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getLengthSquared() {
-        return dlg.getLengthSquared();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double getDistanceSquared(Vector vec) {
-        return dlg.getDistanceSquared(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return dlg.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return dlg.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteUuid guid() {
-        return guid;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        dlg.destroy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + meta.hashCode();
-        res = res * 37 + dlg.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        DelegatingVector that = (DelegatingVector)o;
-
-        return meta.equals(that.meta) && dlg.equals(that.dlg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVector.java
deleted file mode 100644
index 4e7eb21..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOffHeapVector.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.stream.IntStream;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrix;
-import org.apache.ignite.math.impls.storage.vector.DenseLocalOffHeapVectorStorage;
-
-/**
- * Implementation for {@link Vector} assuming dense logic and local offheap JVM storage.
- * It is suitable for data sets where local, non-distributed execution is satisfactory and on-heap JVM storage
- * is not enough to keep the entire data set.
- */
-public class DenseLocalOffHeapVector extends AbstractVector {
-    /** */
-    public DenseLocalOffHeapVector() {
-        // No-op.
-    }
-
-    /** */
-    private void makeOffheapStorage(int size) {
-        setStorage(new DenseLocalOffHeapVectorStorage(size));
-    }
-
-    /**
-     * @param arr Array to copy to offheap storage.
-     */
-    public DenseLocalOffHeapVector(double[] arr) {
-        makeOffheapStorage(arr.length);
-
-        assign(arr);
-    }
-
-    /**
-     * @param size Vector cardinality.
-     */
-    public DenseLocalOffHeapVector(int size) {
-        makeOffheapStorage(size);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector assign(Vector vec) {
-        checkCardinality(vec);
-
-        IntStream.range(0, size()).parallel().forEach(idx -> set(idx, vec.get(idx)));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        if (x == 0.0)
-            return like(size()).assign(0);
-        else
-            return super.times(x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        return new DenseLocalOffHeapVector(crd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return new DenseLocalOffHeapMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        return o != null && getClass().equals(o.getClass()) && (getStorage().equals(((Vector)o).getStorage()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVector.java
deleted file mode 100644
index 5827998..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/DenseLocalOnHeapVector.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Map;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.storage.vector.ArrayVectorStorage;
-
-/**
- * Basic implementation for vector.
- * <p>
- * This is a trivial implementation for vector assuming dense logic, local on-heap JVM storage
- * based on {@code double[]} array. It is only suitable for data sets where
- * local, non-distributed execution is satisfactory and on-heap JVM storage is enough
- * to keep the entire data set.
- */
-public class DenseLocalOnHeapVector extends AbstractVector {
-    /**
-     * @param size Vector cardinality.
-     */
-    private VectorStorage mkStorage(int size) {
-        return new ArrayVectorStorage(size);
-    }
-
-    /**
-     * @param arr Source array.
-     * @param cp {@code true} to clone array, reuse it otherwise.
-     */
-    private VectorStorage mkStorage(double[] arr, boolean cp) {
-        assert arr != null;
-
-        return new ArrayVectorStorage(cp ? arr.clone() : arr);
-    }
-
-    /**
-     * @param args Parameters for new Vector.
-     */
-    public DenseLocalOnHeapVector(Map<String, Object> args) {
-        assert args != null;
-
-        if (args.containsKey("size"))
-            setStorage(mkStorage((int)args.get("size")));
-        else if (args.containsKey("arr") && args.containsKey("copy"))
-            setStorage(mkStorage((double[])args.get("arr"), (boolean)args.get("copy")));
-        else
-            throw new UnsupportedOperationException("Invalid constructor argument(s).");
-    }
-
-    /** */
-    public DenseLocalOnHeapVector() {
-        // No-op.
-    }
-
-    /**
-     * @param size Vector cardinality.
-     */
-    public DenseLocalOnHeapVector(int size) {
-        setStorage(mkStorage(size));
-    }
-
-    /**
-     * @param arr Source array.
-     * @param shallowCp {@code true} to use shallow copy.
-     */
-    public DenseLocalOnHeapVector(double[] arr, boolean shallowCp) {
-        setStorage(mkStorage(arr, shallowCp));
-    }
-
-    /**
-     * @param arr Source array.
-     */
-    public DenseLocalOnHeapVector(double[] arr) {
-        this(arr, false);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return new DenseLocalOnHeapMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        return new DenseLocalOnHeapVector(crd);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/FunctionVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/FunctionVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/FunctionVector.java
deleted file mode 100644
index 0e7cfad..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/FunctionVector.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Map;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.functions.IntDoubleToVoidFunction;
-import org.apache.ignite.math.impls.storage.vector.FunctionVectorStorage;
-
-/**
- * Implementation of {@link Vector} that maps vector element index to {@link java.util.function} interfaces.
- */
-public class FunctionVector extends AbstractVector {
-    /**
-     *
-     */
-    public FunctionVector() {
-        // No-op.
-    }
-
-    /**
-     * Creates read-write or read-only function vector.
-     *
-     * @param size Vector size.
-     * @param getFunc Function that returns value corresponding to given element index.
-     * @param setFunc Set function. If {@code null} - this will be a read-only vector.
-     */
-    public FunctionVector(int size, IgniteFunction<Integer, Double> getFunc, IntDoubleToVoidFunction setFunc) {
-        setStorage(new FunctionVectorStorage(size, getFunc, setFunc));
-    }
-
-    /**
-     * Creates read-only function vector.
-     *
-     * @param size Vector size.
-     * @param getFunc Function that returns value corresponding to given element index.
-     */
-    public FunctionVector(int size, IgniteFunction<Integer, Double> getFunc) {
-        setStorage(new FunctionVectorStorage(size, getFunc));
-    }
-
-    /**
-     * @param args Arguments for vector constructor.
-     */
-    public FunctionVector(Map<String, Object> args) {
-        assert args != null;
-
-        if (args.containsKey("size") && args.containsKey("getFunc") && args.containsKey("setFunc")) {
-            @SuppressWarnings("unchecked")
-            IgniteFunction<Integer, Double> getFunc = (IgniteFunction<Integer, Double>)args.get("getFunc");
-            IntDoubleToVoidFunction setFunc = (IntDoubleToVoidFunction)args.get("setFunc");
-            int size = (int)args.get("size");
-
-            setStorage(new FunctionVectorStorage(size, getFunc, setFunc));
-        }
-        else if (args.containsKey("size") && args.containsKey("getFunc")) {
-            @SuppressWarnings("unchecked")
-            IgniteFunction<Integer, Double> getFunc = (IgniteFunction<Integer, Double>)args.get("getFunc");
-            int size = (int)args.get("size");
-
-            setStorage(new FunctionVectorStorage(size, getFunc));
-        }
-        else
-            throw new UnsupportedOperationException("Invalid constructor argument(s).");
-    }
-
-    /**
-     *
-     *
-     */
-    private FunctionVectorStorage storage() {
-        return (FunctionVectorStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public org.apache.ignite.math.Vector like(int crd) {
-        FunctionVectorStorage sto = storage();
-
-        return new FunctionVector(crd, sto.getFunction(), sto.setFunction());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        if (x == 0.0)
-            return like(size()).assign(0);
-        else
-            return super.times(x);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/MatrixVectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/MatrixVectorView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/MatrixVectorView.java
deleted file mode 100644
index 8f32a89..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/MatrixVectorView.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.impls.storage.vector.MatrixVectorStorage;
-
-/**
- * Row or column vector view off the matrix.
- */
-public class MatrixVectorView extends AbstractVector {
-    /** */ private Matrix parent;
-
-    /** */ private int row;
-    /** */ private int col;
-    
-    /** */ private int rowStride;
-    /** */ private int colStride;
-
-    /**
-     *
-     */
-    public MatrixVectorView() {
-        // No-op.
-    }
-
-    /**
-     * @param parent
-     * @param row
-     * @param col
-     * @param rowStride
-     * @param colStride
-     */
-    public MatrixVectorView(Matrix parent, int row, int col, int rowStride, int colStride) {
-        assert parent != null;
-
-        if (row < 0 || row >= parent.rowSize())
-            throw new IndexException(row);
-        if (col < 0 || col >= parent.columnSize())
-            throw new IndexException(col);
-
-        this.parent = parent;
-
-        this.row = row;
-        this.col = col;
-
-        this.rowStride = rowStride;
-        this.colStride = colStride;
-
-        setStorage(new MatrixVectorStorage(parent, row, col, rowStride, colStride));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        return new MatrixVectorView(parent, row, col, rowStride, colStride);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        return parent.likeVector(crd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return parent.like(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        super.writeExternal(out);
-
-        out.writeObject(parent);
-        out.writeInt(row);
-        out.writeInt(col);
-        out.writeInt(rowStride);
-        out.writeInt(colStride);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        super.readExternal(in);
-
-        parent = (Matrix)in.readObject();
-        row = in.readInt();
-        col = in.readInt();
-        rowStride = in.readInt();
-        colStride = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + (parent == null ? 0 : parent.hashCode());
-        res = res * 37 + row;
-        res = res * 37 + col;
-        res = res * 37 + rowStride;
-        res = res * 37 + colStride;
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        MatrixVectorView that = (MatrixVectorView)o;
-
-        return (parent != null ? parent.equals(that.parent) : that.parent == null) &&
-            row == that.row &&
-            col == that.col &&
-            rowStride == that.rowStride &&
-            colStride == that.colStride;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/PivotedVectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/PivotedVectorView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/PivotedVectorView.java
deleted file mode 100644
index cc9e835..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/PivotedVectorView.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.impls.storage.vector.PivotedVectorStorage;
-
-/**
- * Pivoted (index mapped) view over another vector.
- */
-public class PivotedVectorView extends AbstractVector {
-    /** */ private Vector vec;
-
-    /**
-     * @param vec
-     * @param pivot Mapping from external index to internal.
-     * @param unpivot Mapping from internal index to external.
-     */
-    public PivotedVectorView(Vector vec, int[] pivot, int[] unpivot) {
-        setStorage(new PivotedVectorStorage(vec.getStorage(), pivot, unpivot));
-
-        checkCardinality(pivot);
-        checkCardinality(unpivot);
-
-        this.vec = vec;
-    }
-
-    /**
-     * @param vec
-     * @param pivot
-     */
-    public PivotedVectorView(Vector vec, int[] pivot) {
-        setStorage(new PivotedVectorStorage(vec.getStorage(), pivot));
-
-        checkCardinality(pivot);
-
-        this.vec = vec;
-    }
-
-    /**
-     *
-     *
-     */
-    private PivotedVectorStorage storage() {
-        return (PivotedVectorStorage)getStorage();
-    }
-
-    /**
-     *
-     */
-    public PivotedVectorView() {
-        // No-op.
-    }
-
-    /**
-     *
-     *
-     */
-    public Vector getBaseVector() {
-        return vec;
-    }
-
-    /**
-     * @param i
-     */
-    public int pivot(int i) {
-        return storage().pivot()[i];
-    }
-
-    /**
-     * @param i
-     */
-    public int unpivot(int i) {
-        return storage().unpivot()[i];
-    }
-
-    /**
-     * @param idx
-     */
-    protected Vector.Element makeElement(int idx) {
-        checkIndex(idx);
-
-        // External index.
-        int exIdx = storage().pivot()[idx];
-
-        return new Vector.Element() {
-            /** {@inheritDoc */
-            @Override public double get() {
-                return storageGet(idx);
-            }
-
-            /** {@inheritDoc */
-            @Override public int index() {
-                return exIdx;
-            }
-
-            /** {@inheritDoc */
-            @Override public void set(double val) {
-                storageSet(idx, val);
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        PivotedVectorStorage sto = storage();
-
-        return new PivotedVectorView(vec, sto.pivot(), sto.unpivot());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return vec.likeMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        if (x == 0.0)
-            return copy().map(Functions.mult(x));
-        else
-            return super.times(x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        super.writeExternal(out);
-
-        out.writeObject(vec);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        super.readExternal(in);
-
-        vec = (Vector)in.readObject();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/RandomVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/RandomVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/RandomVector.java
deleted file mode 100644
index c9121c9..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/RandomVector.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Map;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.matrix.RandomMatrix;
-import org.apache.ignite.math.impls.storage.vector.RandomVectorStorage;
-
-/**
- * Random vector. Each value is taken from {-1,0,1} with roughly equal probability. Note
- * that by default, the value is determined by a relatively simple hash of the index.
- */
-public class RandomVector extends AbstractReadOnlyVector {
-    /** */ private boolean fastHash;
-
-    /**
-     * @param size Vector cardinality.
-     * @param fastHash
-     */
-    private VectorStorage mkStorage(int size, boolean fastHash) {
-        this.fastHash = fastHash;
-
-        return new RandomVectorStorage(size, fastHash);
-    }
-
-    /**
-     * @param size
-     * @param fastHash
-     */
-    public RandomVector(int size, boolean fastHash) {
-        setStorage(mkStorage(size, fastHash));
-    }
-
-    /**
-     * @param size
-     */
-    public RandomVector(int size) {
-        this(size, true);
-    }
-
-    /**
-     * @param args
-     */
-    public RandomVector(Map<String, Object> args) {
-        assert args != null;
-
-        if (args.containsKey("size") && args.containsKey("fastHash"))
-            setStorage(mkStorage((int)args.get("size"), (boolean)args.get("fastHash")));
-        else if (args.containsKey("size"))
-            setStorage(mkStorage((int)args.get("size"), true));
-        else
-            throw new UnsupportedOperationException("Invalid constructor argument(s).");
-    }
-
-    /** */
-    public RandomVector() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public org.apache.ignite.math.Vector like(int crd) {
-        return new RandomVector(crd, fastHash);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return new RandomMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        super.writeExternal(out);
-
-        out.writeBoolean(fastHash);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        super.readExternal(in);
-
-        fastHash = in.readBoolean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + Boolean.hashCode(fastHash);
-        res = res * 37 + getStorage().hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        RandomVector that = (RandomVector)o;
-        VectorStorage sto = getStorage();
-
-        return fastHash == that.fastHash && (sto != null ? sto.equals(that.getStorage()) : that.getStorage() == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVector.java
deleted file mode 100644
index 8d19ee0..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVector.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Map;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.storage.vector.SingleElementVectorStorage;
-
-/**
- * Read-write vector holding a single non-zero value at some index.
- */
-public class SingleElementVector extends AbstractVector {
-    /**
-     *
-     */
-    public SingleElementVector() {
-        // No-op
-    }
-
-    /**
-     * @param size
-     * @param idx
-     * @param val
-     */
-    public SingleElementVector(int size, int idx, double val) {
-        super(new SingleElementVectorStorage(size, idx, val));
-    }
-
-    /**
-     * @param args
-     */
-    public SingleElementVector(Map<String, Object> args) {
-        assert args != null;
-
-        if (args.containsKey("size") && args.containsKey("index") && args.containsKey("value")) {
-            int size = (int)args.get("size");
-            int idx = (int)args.get("index");
-            double val = (double)args.get("value");
-
-            setStorage(new SingleElementVectorStorage(size, idx, val));
-        }
-        else
-            throw new UnsupportedOperationException("Invalid constructor argument(s).");
-    }
-
-    /**
-     *
-     *
-     */
-    private SingleElementVectorStorage storage() {
-        return (SingleElementVectorStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element minElement() {
-        return makeElement(storage().index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Element maxElement() {
-        return makeElement(storage().index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        return getX(storage().index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nonZeroElements() {
-        return isZero(get(storage().index())) ? 0 : 1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        int idx = storage().index();
-
-        return new SingleElementVector(crd, idx, getX(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVectorView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVectorView.java
deleted file mode 100644
index 76a1c0a..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SingleElementVectorView.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.Functions;
-import org.apache.ignite.math.impls.storage.vector.SingleElementVectorDelegateStorage;
-
-/**
- * Single value vector view over another vector.
- */
-public class SingleElementVectorView extends AbstractVector {
-    /**
-     *
-     */
-    public SingleElementVectorView() {
-        // No-op.
-    }
-
-    /**
-     * @param vec
-     * @param idx
-     */
-    public SingleElementVectorView(Vector vec, int idx) {
-        super(new SingleElementVectorDelegateStorage(vec, idx));
-    }
-
-    /**
-     *
-     *
-     */
-    private SingleElementVectorDelegateStorage storage() {
-        return (SingleElementVectorDelegateStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector.Element minElement() {
-        return makeElement(storage().index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector.Element maxElement() {
-        return makeElement(storage().index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        return getX(storage().index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nonZeroElements() {
-        return isZero(getX(storage().index())) ? 0 : 1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        SingleElementVectorDelegateStorage sto = storage();
-
-        return new SingleElementVectorView(sto.delegate(), sto.index());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        if (x == 0.0)
-            return copy().map(Functions.mult(x));
-        else
-            return super.times(x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalOffHeapVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalOffHeapVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalOffHeapVector.java
deleted file mode 100644
index 2fd1c57..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalOffHeapVector.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.storage.vector.SparseLocalOffHeapVectorStorage;
-
-/**
- * Implementation for {@link Vector} assuming sparse logic and local offheap JVM storage.
- * It is suitable for data sets where local, non-distributed execution is satisfactory and on-heap JVM storage
- * is not enough to keep the entire data set.
- * <p>See also: <a href="https://en.wikipedia.org/wiki/Sparse_array">Wikipedia article</a>.</p>
- */
-public class SparseLocalOffHeapVector extends AbstractVector {
-    /**
-     * @param crd Vector cardinality.
-     */
-    public SparseLocalOffHeapVector(int crd) {
-        setStorage(new SparseLocalOffHeapVectorStorage(crd));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        return new SparseLocalOffHeapVector(crd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalVector.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalVector.java
deleted file mode 100644
index ebb6731..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/SparseLocalVector.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.SparseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.storage.vector.SparseLocalOnHeapVectorStorage;
-
-/**
- * Local on-heap sparse vector based on hash map storage.
- */
-public class SparseLocalVector extends AbstractVector implements StorageConstants {
-    /**
-     *
-     */
-    public SparseLocalVector() {
-        // No-op.
-    }
-
-    /**
-     * @param size
-     * @param acsMode
-     */
-    public SparseLocalVector(int size, int acsMode) {
-        assertAccessMode(acsMode);
-
-        setStorage(new SparseLocalOnHeapVectorStorage(size, acsMode));
-    }
-
-    /** */
-    private SparseLocalOnHeapVectorStorage storage() {
-        return (SparseLocalOnHeapVectorStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        SparseLocalOnHeapVectorStorage sto = storage();
-
-        return new SparseLocalVector(crd, sto.getAccessMode());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        return new SparseLocalOnHeapMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector times(double x) {
-        if (x == 0.0)
-            return assign(0);
-        else
-            return super.times(x);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/VectorView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/VectorView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/VectorView.java
deleted file mode 100644
index ce51a45..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/VectorView.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.Externalizable;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.storage.vector.DelegateVectorStorage;
-
-/**
- * Implements the partial view into the parent {@link Vector}.
- */
-public class VectorView extends AbstractVector {
-    /**
-     * Constructor for {@link Externalizable} interface.
-     */
-    public VectorView() {
-        // No-op.
-    }
-
-    /**
-     * @param parent Backing parent {@link Vector}.
-     * @param off Offset to parent vector.
-     * @param len Size of the view.
-     */
-    public VectorView(Vector parent, int off, int len) {
-        super(new DelegateVectorStorage(parent.getStorage(), off, len));
-    }
-
-    /**
-     * @param sto Backing parent {@link VectorStorage}.
-     * @param off Offset to parent vector.
-     * @param len Size of the view.
-     */
-    public VectorView(VectorStorage sto, int off, int len) {
-        super(new DelegateVectorStorage(sto, off, len));
-    }
-
-    /** */
-    private DelegateVectorStorage storage() {
-        return (DelegateVectorStorage)getStorage();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector copy() {
-        DelegateVectorStorage sto = storage();
-
-        return new VectorView(sto.delegate(), sto.offset(), sto.length());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector like(int crd) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix likeMatrix(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        return this == o ||
-            ((o != null)
-                && o.getClass() == getClass()
-                && (getStorage().equals(((VectorView)o).getStorage())));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/package-info.java
deleted file mode 100644
index d6ca1f3..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/vector/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains specific implementations for vectors.
- */
-package org.apache.ignite.math.impls.vector;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/package-info.java
deleted file mode 100644
index 05ce651..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains main APIs for distributed code algebra.
- */
-package org.apache.ignite.math;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java
new file mode 100644
index 0000000..a31503f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java
@@ -0,0 +1,571 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+Copyright 1999 CERN - European Organization for Nuclear Research.
+Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
+is hereby granted without fee, provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear in supporting documentation.
+CERN makes no representations about the suitability of this software for any purpose.
+It is provided "as is" without expressed or implied warranty.
+*/
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Miscellaneous arithmetic and algebra functions.
+ * Lifted from Apache Mahout.
+ */
+public class Algebra extends Constants {
+    /** */ private static final double[] STIRLING_CORRECTION = {
+        0.0,
+        8.106146679532726e-02, 4.134069595540929e-02,
+        2.767792568499834e-02, 2.079067210376509e-02,
+        1.664469118982119e-02, 1.387612882307075e-02,
+        1.189670994589177e-02, 1.041126526197209e-02,
+        9.255462182712733e-03, 8.330563433362871e-03,
+        7.573675487951841e-03, 6.942840107209530e-03,
+        6.408994188004207e-03, 5.951370112758848e-03,
+        5.554733551962801e-03, 5.207655919609640e-03,
+        4.901395948434738e-03, 4.629153749334029e-03,
+        4.385560249232324e-03, 4.166319691996922e-03,
+        3.967954218640860e-03, 3.787618068444430e-03,
+        3.622960224683090e-03, 3.472021382978770e-03,
+        3.333155636728090e-03, 3.204970228055040e-03,
+        3.086278682608780e-03, 2.976063983550410e-03,
+        2.873449362352470e-03, 2.777674929752690e-03,
+    };
+
+    /** */ private static final double[] LOG_FACTORIALS = {
+        0.00000000000000000, 0.00000000000000000, 0.69314718055994531,
+        1.79175946922805500, 3.17805383034794562, 4.78749174278204599,
+        6.57925121201010100, 8.52516136106541430, 10.60460290274525023,
+        12.80182748008146961, 15.10441257307551530, 17.50230784587388584,
+        19.98721449566188615, 22.55216385312342289, 25.19122118273868150,
+        27.89927138384089157, 30.67186010608067280, 33.50507345013688888,
+        36.39544520803305358, 39.33988418719949404, 42.33561646075348503,
+        45.38013889847690803, 48.47118135183522388, 51.60667556776437357,
+        54.78472939811231919, 58.00360522298051994, 61.26170176100200198,
+        64.55753862700633106, 67.88974313718153498, 71.25703896716800901
+    };
+
+    /** */ private static final long[] LONG_FACTORIALS = {
+        1L,
+        1L,
+        2L,
+        6L,
+        24L,
+        120L,
+        720L,
+        5040L,
+        40320L,
+        362880L,
+        3628800L,
+        39916800L,
+        479001600L,
+        6227020800L,
+        87178291200L,
+        1307674368000L,
+        20922789888000L,
+        355687428096000L,
+        6402373705728000L,
+        121645100408832000L,
+        2432902008176640000L
+    };
+
+    /** */ private static final double[] DOUBLE_FACTORIALS = {
+        5.109094217170944E19,
+        1.1240007277776077E21,
+        2.585201673888498E22,
+        6.204484017332394E23,
+        1.5511210043330984E25,
+        4.032914611266057E26,
+        1.0888869450418352E28,
+        3.048883446117138E29,
+        8.841761993739701E30,
+        2.652528598121911E32,
+        8.222838654177924E33,
+        2.6313083693369355E35,
+        8.68331761881189E36,
+        2.952327990396041E38,
+        1.0333147966386144E40,
+        3.719933267899013E41,
+        1.3763753091226346E43,
+        5.23022617466601E44,
+        2.0397882081197447E46,
+        8.15915283247898E47,
+        3.34525266131638E49,
+        1.4050061177528801E51,
+        6.041526306337384E52,
+        2.6582715747884495E54,
+        1.196222208654802E56,
+        5.502622159812089E57,
+        2.5862324151116827E59,
+        1.2413915592536068E61,
+        6.082818640342679E62,
+        3.0414093201713376E64,
+        1.5511187532873816E66,
+        8.06581751709439E67,
+        4.274883284060024E69,
+        2.308436973392413E71,
+        1.2696403353658264E73,
+        7.109985878048632E74,
+        4.052691950487723E76,
+        2.350561331282879E78,
+        1.386831185456898E80,
+        8.32098711274139E81,
+        5.075802138772246E83,
+        3.146997326038794E85,
+        1.9826083154044396E87,
+        1.2688693218588414E89,
+        8.247650592082472E90,
+        5.443449390774432E92,
+        3.6471110918188705E94,
+        2.48003554243683E96,
+        1.7112245242814127E98,
+        1.1978571669969892E100,
+        8.504785885678624E101,
+        6.123445837688612E103,
+        4.470115461512686E105,
+        3.307885441519387E107,
+        2.4809140811395404E109,
+        1.8854947016660506E111,
+        1.451830920282859E113,
+        1.1324281178206295E115,
+        8.94618213078298E116,
+        7.15694570462638E118,
+        5.797126020747369E120,
+        4.7536433370128435E122,
+        3.94552396972066E124,
+        3.314240134565354E126,
+        2.8171041143805494E128,
+        2.4227095383672744E130,
+        2.107757298379527E132,
+        1.854826422573984E134,
+        1.6507955160908465E136,
+        1.4857159644817605E138,
+        1.3520015276784033E140,
+        1.2438414054641305E142,
+        1.156772507081641E144,
+        1.0873661566567426E146,
+        1.0329978488239061E148,
+        9.916779348709491E149,
+        9.619275968248216E151,
+        9.426890448883248E153,
+        9.332621544394415E155,
+        9.332621544394418E157,
+        9.42594775983836E159,
+        9.614466715035125E161,
+        9.902900716486178E163,
+        1.0299016745145631E166,
+        1.0813967582402912E168,
+        1.1462805637347086E170,
+        1.2265202031961373E172,
+        1.324641819451829E174,
+        1.4438595832024942E176,
+        1.5882455415227423E178,
+        1.7629525510902457E180,
+        1.974506857221075E182,
+        2.2311927486598138E184,
+        2.543559733472186E186,
+        2.925093693493014E188,
+        3.393108684451899E190,
+        3.96993716080872E192,
+        4.6845258497542896E194,
+        5.574585761207606E196,
+        6.689502913449135E198,
+        8.094298525273444E200,
+        9.875044200833601E202,
+        1.2146304367025332E205,
+        1.506141741511141E207,
+        1.882677176888926E209,
+        2.3721732428800483E211,
+        3.0126600184576624E213,
+        3.856204823625808E215,
+        4.974504222477287E217,
+        6.466855489220473E219,
+        8.471580690878813E221,
+        1.1182486511960037E224,
+        1.4872707060906847E226,
+        1.99294274616152E228,
+        2.690472707318049E230,
+        3.6590428819525483E232,
+        5.0128887482749884E234,
+        6.917786472619482E236,
+        9.615723196941089E238,
+        1.3462012475717523E241,
+        1.8981437590761713E243,
+        2.6953641378881633E245,
+        3.8543707171800694E247,
+        5.550293832739308E249,
+        8.047926057471989E251,
+        1.1749972043909107E254,
+        1.72724589045464E256,
+        2.5563239178728637E258,
+        3.8089226376305687E260,
+        5.7133839564458575E262,
+        8.627209774233244E264,
+        1.3113358856834527E267,
+        2.0063439050956838E269,
+        3.0897696138473515E271,
+        4.789142901463393E273,
+        7.471062926282892E275,
+        1.1729568794264134E278,
+        1.8532718694937346E280,
+        2.946702272495036E282,
+        4.714723635992061E284,
+        7.590705053947223E286,
+        1.2296942187394494E289,
+        2.0044015765453032E291,
+        3.287218585534299E293,
+        5.423910666131583E295,
+        9.003691705778434E297,
+        1.5036165148649983E300,
+        2.5260757449731988E302,
+        4.2690680090047056E304,
+        7.257415615308004E306
+    };
+
+    /**
+     * Efficiently returns the binomial coefficient, often also referred to as
+     * "n over k" or "n choose k". The binomial coefficient is defined as
+     * {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )}.
+     * <ul> <li>{@code k&lt;0}: {@code 0}.</li>
+     * <li>{@code k==0}: {@code 1}.</li>
+     * <li>{@code k==1}: {@code n}.</li>
+     * <li>else: {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k)}.</li>
+     * </ul>
+     *
+     * @param n
+     * @param k
+     * @return Binomial coefficient.
+     */
+    public static double binomial(double n, long k) {
+        if (k < 0)
+            return 0;
+
+        if (k == 0)
+            return 1;
+
+        if (k == 1)
+            return n;
+
+        // binomial(n,k) = (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )
+        double a = n - k + 1;
+        double b = 1;
+        double binomial = 1;
+
+        for (long i = k; i-- > 0; )
+            binomial *= (a++) / (b++);
+
+        return binomial;
+    }
+
+    /**
+     * Efficiently returns the binomial coefficient, often also referred to as "n over k" or "n choose k".
+     * The binomial coefficient is defined as
+     * <ul> <li>{@code k&lt;0}: {@code 0}. <li>{@code k==0 || k==n}: {@code 1}. <li>{@code k==1 || k==n-1}:
+     * {@code n}. <li>else: {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )}. </ul>
+     *
+     * @param n
+     * @param k
+     * @return Binomial coefficient.
+     */
+    public static double binomial(long n, long k) {
+        if (k < 0)
+            return 0;
+
+        if (k == 0 || k == n)
+            return 1;
+
+        if (k == 1 || k == n - 1)
+            return n;
+
+        if (n > k) {
+            int max = LONG_FACTORIALS.length + DOUBLE_FACTORIALS.length;
+
+            if (n < max) {
+                double nFac = factorial((int)n);
+                double kFac = factorial((int)k);
+                double nMinusKFac = factorial((int)(n - k));
+                double nk = nMinusKFac * kFac;
+
+                if (nk != Double.POSITIVE_INFINITY) // No numeric overflow?
+                    return nFac / nk;
+            }
+
+            if (k > n / 2)
+                k = n - k;
+        }
+
+        // binomial(n,k) = (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )
+        long a = n - k + 1;
+        long b = 1;
+        double binomial = 1;
+
+        for (long i = k; i-- > 0; )
+            binomial *= (double)a++ / (b++);
+
+        return binomial;
+    }
+
+    /**
+     * Returns the smallest <code>long &gt;= value</code>.
+     * <dl><dt>Examples: {@code 1.0 -> 1, 1.2 -> 2, 1.9 -> 2}. This
+     * method is safer than using (long) Math.ceil(value), because of possible rounding error.</dt></dl>
+     *
+     * @param val
+     */
+    public static long ceil(double val) {
+        return Math.round(Math.ceil(val));
+    }
+
+    /**
+     * Evaluates the series of Chebyshev polynomials Ti at argument x/2. The series is given by
+     * <pre>
+     *        N-1
+     *         - '
+     *  y  =   &gt;   coef[i] T (x/2)
+     *         -            i
+     *        i=0
+     * </pre>
+     * Coefficients are stored in reverse order, i.e. the zero order term is last in the array.  Note N is the number of
+     * coefficients, not the order. <p> If coefficients are for the interval a to b, x must have been transformed to x
+     * -&lt; 2(2x - b - a)/(b-a) before entering the routine.  This maps x from (a, b) to (-1, 1), over which the
+     * Chebyshev polynomials are defined. <p> If the coefficients are for the inverted interval, in which (a, b) is
+     * mapped to (1/b, 1/a), the transformation required is {@code x -> 2(2ab/x - b - a)/(b-a)}.  If b is infinity, this
+     * becomes {@code x -> 4a/x - 1}. <p> SPEED: <p> Taking advantage of the recurrence properties of the Chebyshev
+     * polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same
+     * degree.
+     *
+     * @param x Argument to the polynomial.
+     * @param coef Coefficients of the polynomial.
+     * @param N Number of coefficients.
+     */
+    public static double chbevl(double x, double[] coef, int N) {
+        int p = 0;
+
+        double b0 = coef[p++];
+        double b1 = 0.0;
+        int i = N - 1;
+
+        double b2;
+
+        do {
+            b2 = b1;
+            b1 = b0;
+            b0 = x * b1 - b2 + coef[p++];
+        }
+        while (--i > 0);
+
+        return 0.5 * (b0 - b2);
+    }
+
+    /**
+     * Instantly returns the factorial {@code k!}.
+     *
+     * @param k must hold {@code k &gt;= 0}.
+     */
+    private static double factorial(int k) {
+        if (k < 0)
+            throw new IllegalArgumentException();
+
+        int len1 = LONG_FACTORIALS.length;
+
+        if (k < len1)
+            return LONG_FACTORIALS[k];
+
+        int len2 = DOUBLE_FACTORIALS.length;
+
+        return (k < len1 + len2) ? DOUBLE_FACTORIALS[k - len1] : Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * Returns the largest <code>long &lt;= value</code>.
+     * <dl><dt>Examples: {@code 1.0 -> 1, 1.2 -> 1, 1.9 -> 1 <dt> 2.0 -> 2, 2.2 -> 2, 2.9 -> 2}</dt></dl>
+     * This method is safer than using (long) Math.floor(value), because of possible rounding error.
+     */
+    public static long floor(double val) {
+        return Math.round(Math.floor(val));
+    }
+
+    /**
+     * Returns {@code log<sub>base</sub>value}.
+     */
+    public static double log(double base, double val) {
+        return Math.log(val) / Math.log(base);
+    }
+
+    /**
+     * Returns {@code log<sub>10</sub>value}.
+     */
+    public static double log10(double val) {
+        // 1.0 / Math.log(10) == 0.43429448190325176
+        return Math.log(val) * 0.43429448190325176;
+    }
+
+    /**
+     * Returns {@code log<sub>2</sub>value}.
+     */
+    public static double log2(double val) {
+        // 1.0 / Math.log(2) == 1.4426950408889634
+        return Math.log(val) * 1.4426950408889634;
+    }
+
+    /**
+     * Returns {@code log(k!)}. Tries to avoid overflows. For {@code k&lt;30} simply looks up a table in O(1).
+     * For {@code k&gt;=30} uses stirlings approximation.
+     *
+     * @param k must hold {@code k &gt;= 0}.
+     */
+    public static double logFactorial(int k) {
+        if (k >= 30) {
+            double r = 1.0 / k;
+            double rr = r * r;
+            double C7 = -5.95238095238095238e-04;
+            double C5 = 7.93650793650793651e-04;
+            double C3 = -2.77777777777777778e-03;
+            double C1 = 8.33333333333333333e-02;
+            double C0 = 9.18938533204672742e-01;
+
+            return (k + 0.5) * Math.log(k) - k + C0 + r * (C1 + rr * (C3 + rr * (C5 + rr * C7)));
+        }
+        else
+            return LOG_FACTORIALS[k];
+    }
+
+    /**
+     * Instantly returns the factorial {@code k!}.
+     *
+     * @param k must hold {@code k >= 0 && k < 21}
+     */
+    public static long longFactorial(int k) {
+        if (k < 0)
+            throw new IllegalArgumentException("Negative k");
+
+        if (k < LONG_FACTORIALS.length)
+            return LONG_FACTORIALS[k];
+
+        throw new IllegalArgumentException("Overflow");
+    }
+
+    /**
+     * Returns the StirlingCorrection.
+     *
+     * Correction term of the Stirling approximation for {@code log(k!)} (series in
+     * 1/k, or table values for small k) with int parameter k. </p> {@code  log k! = (k + 1/2)log(k + 1) - (k + 1) +
+     * (1/2)log(2Pi) + STIRLING_CORRECTION(k + 1) log k! = (k + 1/2)log(k)     -  k      + (1/2)log(2Pi) +
+     * STIRLING_CORRECTION(k) }
+     */
+    public static double stirlingCorrection(int k) {
+        if (k > 30) {
+            double r = 1.0 / k;
+            double rr = r * r;
+            double C7 = -5.95238095238095238e-04;
+            double C5 = 7.93650793650793651e-04;
+            double C3 = -2.77777777777777778e-03;
+            double C1 = 8.33333333333333333e-02;
+
+            return r * (C1 + rr * (C3 + rr * (C5 + rr * C7)));
+        }
+        else
+            return STIRLING_CORRECTION[k];
+    }
+
+    /**
+     * Evaluates the given polynomial of degree {@code N} at {@code x}, assuming coefficient of N is 1.0. Otherwise same
+     * as {@link #evalPoly(double, double[], int)}.
+     * <pre>
+     *                     2          N
+     * y  =  C  + C x + C x  +...+ C x
+     *        0    1     2          N
+     *
+     * where C  = 1 and hence is omitted from the array.
+     *        N
+     *
+     * Coefficients are stored in reverse order:
+     *
+     * coef[0] = C  , ..., coef[N-1] = C  .
+     *            N-1                   0
+     *
+     * Calling arguments are otherwise the same as {@link #evalPoly(double, double[], int)}.
+     * </pre>
+     * In the interest of speed, there are no checks for out of bounds arithmetic.
+     *
+     * @param x Argument to the polynomial.
+     * @param coef Coefficients of the polynomial.
+     * @param n Degree of the polynomial.
+     */
+    public static double evalPoly1(double x, double[] coef, int n) {
+        double res = x + coef[0];
+
+        for (int i = 1; i < n; i++)
+            res = res * x + coef[i];
+
+        return res;
+    }
+
+    /**
+     * Evaluates the given polynomial of degree {@code N} at {@code x}.
+     * <pre>
+     *                     2          N
+     * y  =  C  + C x + C x  +...+ C x
+     *        0    1     2          N
+     *
+     * Coefficients are stored in reverse order:
+     *
+     * coef[0] = C  , ..., coef[N] = C  .
+     *            N                   0
+     * </pre>
+     * In the interest of speed, there are no checks for out of bounds arithmetic.
+     *
+     * @param x Argument to the polynomial.
+     * @param coef Coefficients of the polynomial.
+     * @param n Degree of the polynomial.
+     */
+    public static double evalPoly(double x, double[] coef, int n) {
+        double res = coef[0];
+
+        for (int i = 1; i <= n; i++)
+            res = res * x + coef[i];
+
+        return res;
+    }
+
+    /**
+     * Gets <code>sqrt(a^2 + b^2)</code> without under/overflow.
+     *
+     * @param a
+     * @param b
+     */
+    public static double hypot(double a, double b) {
+        double r;
+
+        if (Math.abs(a) > Math.abs(b)) {
+            r = b / a;
+            r = Math.abs(a) * Math.sqrt(1 + r * r);
+        }
+        else if (b != 0) {
+            r = a / b;
+            r = Math.abs(b) * Math.sqrt(1 + r * r);
+        }
+        else
+            r = 0.0;
+
+        return r;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java
new file mode 100644
index 0000000..e20c139
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+Copyright 1999 CERN - European Organization for Nuclear Research.
+Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
+is hereby granted without fee, provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear in supporting documentation.
+CERN makes no representations about the suitability of this software for any purpose.
+It is provided "as is" without expressed or implied warranty.
+*/
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Math constants. Lifted from Apache Mahout.
+ */
+public class Constants {
+    /** */ public static final double MACHEP = 1.11022302462515654042E-16;
+    /** */ public static final double MAXLOG = 7.09782712893383996732E2;
+    /** */ public static final double MINLOG = -7.451332191019412076235E2;
+    /** */ public static final double MAXGAM = 171.624376956302725;
+    /** */ public static final double SQTPI = 2.50662827463100050242E0;
+    /** */ public static final double SQRTH = 7.07106781186547524401E-1;
+    /** */ public static final double LOGPI = 1.14472988584940017414;
+    /** */ public static final double BIG = 4.503599627370496e15;
+    /** */ public static final double BIGINV = 2.22044604925031308085e-16;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/Destroyable.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Destroyable.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Destroyable.java
new file mode 100644
index 0000000..8e7ce95
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Destroyable.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Support for destroying objects that are managed outside of JVM.
+ */
+public interface Destroyable {
+    /**
+     * Destroys object if managed outside of JVM. It's a no-op in all other cases.
+     */
+    public default void destroy() {
+        // No-op.
+    }
+}


[25/50] [abbrv] ignite git commit: ignite-4982 Fixed GridIntList.

Posted by sb...@apache.org.
ignite-4982 Fixed GridIntList.


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

Branch: refs/heads/ignite-1561
Commit: d60cf53bbfae162ac96ec1525bcd1772b8249a79
Parents: 58a8cb2
Author: Konstantin Dudkov <kd...@ya.ru>
Authored: Tue Apr 18 16:50:16 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Apr 18 16:50:16 2017 +0300

----------------------------------------------------------------------
 .../communication/GridIoMessageFactory.java     |   8 +-
 .../ignite/internal/util/GridIntList.java       |   5 +-
 ...ClientWriteBehindStoreNonCoalescingTest.java |  13 +-
 .../testsuites/IgniteUtilSelfTestSuite.java     |   2 +
 .../apache/ignite/util/GridIntListSelfTest.java | 153 +++++++++++++++++++
 5 files changed, 167 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index e1c9511..b972a31 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -36,7 +36,6 @@ import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage;
 import org.apache.ignite.internal.pagemem.snapshot.SnapshotFinishedMessage;
 import org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse;
 import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicateContainsValue;
 import org.apache.ignite.internal.processors.cache.CacheEntrySerializablePredicate;
@@ -46,6 +45,7 @@ import org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo;
 import org.apache.ignite.internal.processors.cache.GridCacheReturn;
+import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse;
 import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage;
 import org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage;
@@ -144,6 +144,7 @@ import org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQuery
 import org.apache.ignite.internal.processors.rest.handlers.task.GridTaskResultRequest;
 import org.apache.ignite.internal.processors.rest.handlers.task.GridTaskResultResponse;
 import org.apache.ignite.internal.util.GridByteArrayList;
+import org.apache.ignite.internal.util.GridIntList;
 import org.apache.ignite.internal.util.GridLongList;
 import org.apache.ignite.internal.util.GridMessageCollection;
 import org.apache.ignite.internal.util.UUIDCollectionMessage;
@@ -176,6 +177,11 @@ public class GridIoMessageFactory implements MessageFactory {
         Message msg = null;
 
         switch (type) {
+            case -52:
+                msg = new GridIntList();
+
+                break;
+
             case -51:
                 msg = new NearCacheUpdates();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
index 1de8106..968b88e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
@@ -132,8 +132,7 @@ public class GridIntList implements Message, Externalizable {
 
         for (int i = 0; i < idx; i++) {
             int element  = arr[i];
-            int elementHash = (int)(element ^ (element >>> 32));
-            res = 31 * res + elementHash;
+            res = 31 * res + element;
         }
 
         return res;
@@ -577,7 +576,7 @@ public class GridIntList implements Message, Externalizable {
 
     /** {@inheritDoc} */
     @Override public short directType() {
-        return 85;
+        return -52;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
index 8ea109d..1d44a98 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
@@ -29,7 +29,6 @@ import javax.cache.processor.EntryProcessorException;
 import javax.cache.processor.MutableEntry;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.store.CacheStore;
@@ -40,7 +39,6 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest;
 import org.apache.ignite.lang.IgniteBiInClosure;
 import org.apache.ignite.lang.IgniteFuture;
 
-import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
 
 /**
@@ -63,11 +61,6 @@ public class IgnteCacheClientWriteBehindStoreNonCoalescingTest extends IgniteCac
     }
 
     /** {@inheritDoc} */
-    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
-        return CLOCK;
-    }
-
-    /** {@inheritDoc} */
     @Override protected NearCacheConfiguration nearConfiguration() {
         return null;
     }
@@ -155,10 +148,10 @@ public class IgnteCacheClientWriteBehindStoreNonCoalescingTest extends IgniteCac
 
         /** {@inheritDoc} */
         @Override public void write(Cache.Entry<? extends Object, ? extends Object> entry) {
-            Object oldValue = storeMap.put(entry.getKey(), entry.getValue());
+            Object oldVal = storeMap.put(entry.getKey(), entry.getValue());
 
-            if (oldValue instanceof Integer && entry.getValue() instanceof Integer) {
-                Integer oldInt = (Integer)oldValue;
+            if (oldVal instanceof Integer && entry.getValue() instanceof Integer) {
+                Integer oldInt = (Integer) oldVal;
                 Integer newInt = (Integer)entry.getValue();
 
                 assertTrue(

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
index 066f8ea..64a94fd 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
@@ -39,6 +39,7 @@ import org.apache.ignite.spi.discovery.ClusterMetricsSnapshotSerializeSelfTest;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.thread.GridThreadPoolExecutorServiceSelfTest;
 import org.apache.ignite.thread.IgniteThreadPoolSizeTest;
+import org.apache.ignite.util.GridIntListSelfTest;
 import org.apache.ignite.util.GridLongListSelfTest;
 import org.apache.ignite.util.GridMessageCollectionTest;
 import org.apache.ignite.util.GridQueueSelfTest;
@@ -76,6 +77,7 @@ public class IgniteUtilSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridByteArrayListSelfTest.class);
         suite.addTestSuite(GridMBeanSelfTest.class);
         suite.addTestSuite(GridLongListSelfTest.class);
+        suite.addTestSuite(GridIntListSelfTest.class);
         suite.addTestSuite(GridArraysSelfTest.class);
         suite.addTestSuite(GridCacheUtilsSelfTest.class);
         suite.addTestSuite(IgniteExceptionRegistrySelfTest.class);

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java
new file mode 100644
index 0000000..cc48fa8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.util;
+
+import junit.framework.TestCase;
+import org.apache.ignite.internal.util.GridIntList;
+
+import static org.apache.ignite.internal.util.GridIntList.asList;
+
+/**
+ *
+ */
+public class GridIntListSelfTest extends TestCase {
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("ZeroLengthArrayAllocation")
+    public void testCopyWithout() throws Exception {
+        assertCopy(
+            new GridIntList(new int[] {}),
+            new GridIntList(new int[] {}));
+
+        assertCopy(
+            new GridIntList(new int[] {}),
+            new GridIntList(new int[] {1}));
+
+        assertCopy(
+            new GridIntList(new int[] {1}),
+            new GridIntList(new int[] {}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3}),
+            new GridIntList(new int[] {4, 5, 6}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3}),
+            new GridIntList(new int[] {1, 2, 3}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3, 4, 5, 1}),
+            new GridIntList(new int[] {1, 1}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 1, 1, 2, 3, 4, 5, 1, 1, 1}),
+            new GridIntList(new int[] {1, 1}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3}),
+            new GridIntList(new int[] {1, 1, 2, 2, 3, 3}));
+    }
+
+    /**
+     *
+     */
+    public void testTruncate() {
+        GridIntList list = asList(1, 2, 3, 4, 5, 6, 7, 8);
+
+        list.truncate(4, true);
+
+        assertEquals(asList(1, 2, 3, 4), list);
+
+        list.truncate(2, false);
+
+        assertEquals(asList(3, 4), list);
+
+        list = new GridIntList();
+
+        list.truncate(0, false);
+        list.truncate(0, true);
+
+        assertEquals(new GridIntList(), list);
+    }
+
+    /**
+     * Assert {@link GridIntList#copyWithout(GridIntList)} on given lists.
+     *
+     * @param lst Source lists.
+     * @param rmv Exclude list.
+     */
+    private void assertCopy(GridIntList lst, GridIntList rmv) {
+        GridIntList res = lst.copyWithout(rmv);
+
+        for (int i = 0; i < lst.size(); i++) {
+            int v = lst.get(i);
+
+            if (rmv.contains(v))
+                assertFalse(res.contains(v));
+            else
+                assertTrue(res.contains(v));
+        }
+    }
+
+    /**
+     *
+     */
+    public void testRemove() {
+        GridIntList list = asList(1, 2, 3, 4, 5, 6);
+
+        assertEquals(2, list.removeValue(0, 3));
+        assertEquals(asList(1, 2, 4, 5, 6), list);
+
+        assertEquals(-1, list.removeValue(1, 1));
+        assertEquals(-1, list.removeValue(0, 3));
+
+        assertEquals(4, list.removeValue(0, 6));
+        assertEquals(asList(1, 2, 4, 5), list);
+
+        assertEquals(2, list.removeIndex(1));
+        assertEquals(asList(1, 4, 5), list);
+
+        assertEquals(1, list.removeIndex(0));
+        assertEquals(asList(4, 5), list);
+    }
+
+    /**
+     *
+     */
+    public void testSort() {
+        assertEquals(new GridIntList(), new GridIntList().sort());
+        assertEquals(asList(1), asList(1).sort());
+        assertEquals(asList(1, 2), asList(2, 1).sort());
+        assertEquals(asList(1, 2, 3), asList(2, 1, 3).sort());
+
+        GridIntList list = new GridIntList();
+
+        list.add(4);
+        list.add(3);
+        list.add(5);
+        list.add(1);
+
+        assertEquals(asList(1, 3, 4, 5), list.sort());
+
+        list.add(0);
+
+        assertEquals(asList(1, 3, 4, 5, 0), list);
+        assertEquals(asList(0, 1, 3, 4, 5), list.sort());
+    }
+}


[32/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index 98d227c..a9c1a20 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -17,12 +17,10 @@
 
 package org.apache.ignite.internal.processors.query.h2.opt;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
@@ -35,11 +33,9 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory;
-import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.lang.IgniteBiTuple;
-import org.h2.api.TableEngine;
 import org.h2.command.ddl.CreateTableData;
 import org.h2.engine.Session;
 import org.h2.index.Index;
@@ -50,7 +46,6 @@ import org.h2.result.SearchRow;
 import org.h2.result.SortOrder;
 import org.h2.table.IndexColumn;
 import org.h2.table.TableBase;
-import org.h2.table.TableFilter;
 import org.h2.value.Value;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
@@ -72,7 +67,10 @@ public class GridH2Table extends TableBase {
     private final GridH2RowDescriptor desc;
 
     /** */
-    private final ArrayList<Index> idxs;
+    private volatile ArrayList<Index> idxs;
+
+    /** */
+    private final Map<String, GridH2IndexBase> tmpIdxs = new HashMap<>();
 
     /** */
     private final ReadWriteLock lock;
@@ -81,7 +79,7 @@ public class GridH2Table extends TableBase {
     private boolean destroyed;
 
     /** */
-    private final Set<Session> sessions = Collections.newSetFromMap(new ConcurrentHashMap8<Session,Boolean>());
+    private final ConcurrentMap<Session, Boolean> sessions = new ConcurrentHashMap8<>();
 
     /** */
     private final AtomicReference<Object[]> actualSnapshot = new AtomicReference<>();
@@ -106,11 +104,12 @@ public class GridH2Table extends TableBase {
      *
      * @param createTblData Table description.
      * @param desc Row descriptor.
+     * @param rowFactory Row factory.
      * @param idxsFactory Indexes factory.
      * @param spaceName Space name.
      */
-    public GridH2Table(CreateTableData createTblData, @Nullable GridH2RowDescriptor desc, IndexesFactory idxsFactory,
-        @Nullable String spaceName) {
+    public GridH2Table(CreateTableData createTblData, @Nullable GridH2RowDescriptor desc, H2RowFactory rowFactory,
+        GridH2SystemIndexFactory idxsFactory, @Nullable String spaceName) {
         super(createTblData);
 
         assert idxsFactory != null;
@@ -143,18 +142,18 @@ public class GridH2Table extends TableBase {
             }
         }
 
+        this.rowFactory = rowFactory;
+
         // Indexes must be created in the end when everything is ready.
-        rowFactory = idxsFactory.createRowFactory(this);
-        idxs = idxsFactory.createIndexes(this);
+        idxs = idxsFactory.createSystemIndexes(this);
 
         assert idxs != null;
 
         // Add scan index at 0 which is required by H2.
-        if (idxs.size() >= 2
-                && index(0).getIndexType().isHash())
-            idxs.add(0, new ScanIndex(index(1), index(0)));
+        if (idxs.size() >= 2 && index(0).getIndexType().isHash())
+            idxs.add(0, new GridH2PrimaryScanIndex(this, index(1), index(0)));
         else
-            idxs.add(0, new ScanIndex(index(0), null));
+            idxs.add(0, new GridH2PrimaryScanIndex(this, index(0), null));
 
         snapshotEnabled = desc == null || desc.snapshotableIndex();
 
@@ -238,6 +237,8 @@ public class GridH2Table extends TableBase {
             desc.guard().begin();
 
         try {
+            ensureNotDestroyed();
+
             GridH2AbstractKeyValueRow row = (GridH2AbstractKeyValueRow)pk.findOne(searchRow);
 
             if (row == null)
@@ -266,13 +267,21 @@ public class GridH2Table extends TableBase {
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings({"LockAcquiredButNotSafelyReleased", "SynchronizationOnLocalVariableOrMethodParameter", "unchecked"})
-    @Override public boolean lock(@Nullable final Session ses, boolean exclusive, boolean force) {
-        if (ses != null) {
-            if (!sessions.add(ses))
-                return false;
+    @Override public boolean lock(Session ses, boolean exclusive, boolean force) {
+        Boolean putRes = sessions.putIfAbsent(ses, exclusive);
+
+        // In accordance with base method semantics, we'll return true if we were already exclusively locked
+        if (putRes != null)
+            return putRes;
+
+        ses.addLock(this);
+
+        lock(exclusive);
+
+        if (destroyed) {
+            unlock(exclusive);
 
-            ses.addLock(this);
+            throw new IllegalStateException("Table " + identifier() + " already destroyed.");
         }
 
         if (snapshotInLock())
@@ -320,6 +329,8 @@ public class GridH2Table extends TableBase {
         }
 
         try {
+            ensureNotDestroyed();
+
             // Try again inside of the lock.
             snapshots = actualSnapshot.get();
 
@@ -362,12 +373,6 @@ public class GridH2Table extends TableBase {
 
             throw new IgniteInterruptedException("Thread got interrupted while trying to acquire table lock.", e);
         }
-
-        if (destroyed) {
-            unlock(exclusive);
-
-            throw new IllegalStateException("Table " + identifier() + " already destroyed.");
-        }
     }
 
     /**
@@ -388,12 +393,6 @@ public class GridH2Table extends TableBase {
             throw new IgniteInterruptedException("Thread got interrupted while trying to acquire table lock.", e);
         }
 
-        if (destroyed) {
-            unlock(exclusive);
-
-            throw new IllegalStateException("Table " + identifier() + " already destroyed.");
-        }
-
         return true;
     }
 
@@ -409,6 +408,14 @@ public class GridH2Table extends TableBase {
     }
 
     /**
+     * Check if table is not destroyed.
+     */
+    private void ensureNotDestroyed() {
+        if (destroyed)
+            throw new IllegalStateException("Table " + identifier() + " already destroyed.");
+    }
+
+    /**
      * Must be called inside of write lock because when using multiple indexes we have to ensure that all of them have
      * the same contents at snapshot taking time.
      *
@@ -462,6 +469,8 @@ public class GridH2Table extends TableBase {
         lock(true);
 
         try {
+            ensureNotDestroyed();
+
             assert sessions.isEmpty() : sessions;
 
             destroyed = true;
@@ -475,12 +484,16 @@ public class GridH2Table extends TableBase {
     }
 
     /** {@inheritDoc} */
-    @Override public void unlock(@Nullable Session ses) {
-        if (ses != null && !sessions.remove(ses))
+    @Override public void unlock(Session ses) {
+        Boolean exclusive = sessions.remove(ses);
+
+        if (exclusive == null)
             return;
 
         if (snapshotInLock())
             releaseSnapshots();
+
+        unlock(exclusive);
     }
 
     /**
@@ -599,6 +612,8 @@ public class GridH2Table extends TableBase {
             desc.guard().begin();
 
         try {
+            ensureNotDestroyed();
+
             GridH2IndexBase pk = pk();
 
             if (!del) {
@@ -623,18 +638,11 @@ public class GridH2Table extends TableBase {
                 while (++i < len) {
                     GridH2IndexBase idx = index(i);
 
-                    assert !idx.getIndexType().isUnique() : "Unique indexes are not supported: " + idx;
-
-                    GridH2Row old2 = idx.put(row);
-
-                    if (old2 != null) { // Row was replaced in index.
-                        if (!eq(pk, old2, old))
-                            throw new IllegalStateException("Row conflict should never happen, unique indexes are " +
-                                "not supported [idx=" + idx + ", old=" + old + ", old2=" + old2 + ']');
-                    }
-                    else if (old != null) // Row was not replaced, need to remove manually.
-                        idx.removex(old);
+                    addToIndex(idx, pk, row, old, false);
                 }
+
+                for (GridH2IndexBase idx : tmpIdxs.values())
+                    addToIndex(idx, pk, row, old, true);
             }
             else {
                 //  index(1) is PK, get full row from there (search row here contains only key but no other columns).
@@ -656,6 +664,9 @@ public class GridH2Table extends TableBase {
                         assert eq(pk, res, old) : "\n" + old + "\n" + res + "\n" + i + " -> " + index(i).getName();
                     }
 
+                    for (GridH2IndexBase idx : tmpIdxs.values())
+                        idx.remove(old);
+
                     size.decrement();
                 }
                 else
@@ -676,6 +687,31 @@ public class GridH2Table extends TableBase {
     }
 
     /**
+     * Add row to index.
+     *
+     * @param idx Index to add row to.
+     * @param pk Primary key index.
+     * @param row Row to add to index.
+     * @param old Previous row state, if any.
+     * @param tmp {@code True} if this is proposed index which may be not consistent yet.
+     */
+    private void addToIndex(GridH2IndexBase idx, Index pk, GridH2Row row, GridH2Row old, boolean tmp) {
+        assert !idx.getIndexType().isUnique() : "Unique indexes are not supported: " + idx;
+
+        GridH2Row old2 = idx.put(row);
+
+        if (old2 != null) { // Row was replaced in index.
+            if (!tmp) {
+                if (!eq(pk, old2, old))
+                    throw new IllegalStateException("Row conflict should never happen, unique indexes are " +
+                        "not supported [idx=" + idx + ", old=" + old + ", old2=" + old2 + ']');
+            }
+        }
+        else if (old != null) // Row was not replaced, need to remove manually.
+            idx.removex(old);
+    }
+
+    /**
      * Check row equality.
      *
      * @param pk Primary key index.
@@ -716,9 +752,119 @@ public class GridH2Table extends TableBase {
     }
 
     /** {@inheritDoc} */
-    @Override public Index addIndex(Session ses, String s, int i, IndexColumn[] idxCols, IndexType idxType,
-        boolean b, String s1) {
-        throw DbException.getUnsupportedException("addIndex");
+    @Override public Index addIndex(Session ses, String idxName, int idxId, IndexColumn[] cols, IndexType idxType,
+        boolean create, String idxComment) {
+        return commitUserIndex(ses, idxName);
+    }
+
+    /**
+     * Add index that is in an intermediate state and is still being built, thus is not used in queries until it is
+     * promoted.
+     *
+     * @param idx Index to add.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void proposeUserIndex(Index idx) throws IgniteCheckedException {
+        assert idx instanceof GridH2IndexBase;
+
+        lock(true);
+
+        try {
+            ensureNotDestroyed();
+
+            for (Index oldIdx : idxs) {
+                if (F.eq(oldIdx.getName(), idx.getName()))
+                    throw new IgniteCheckedException("Index already exists: " + idx.getName());
+            }
+
+            Index oldTmpIdx = tmpIdxs.put(idx.getName(), (GridH2IndexBase)idx);
+
+            assert oldTmpIdx == null;
+        }
+        finally {
+            unlock(true);
+        }
+    }
+
+    /**
+     * Promote temporary index to make it usable in queries.
+     *
+     * @param ses H2 session.
+     * @param idxName Index name.
+     * @return Temporary index with given name.
+     */
+    private Index commitUserIndex(Session ses, String idxName) {
+        lock(true);
+
+        try {
+            ensureNotDestroyed();
+
+            Index idx = tmpIdxs.remove(idxName);
+
+            assert idx != null;
+
+            ArrayList<Index> newIdxs = new ArrayList<>(idxs.size() + 1);
+
+            newIdxs.addAll(idxs);
+
+            newIdxs.add(idx);
+
+            idxs = newIdxs;
+
+            database.addSchemaObject(ses, idx);
+
+            setModified();
+
+            return idx;
+        }
+        finally {
+            unlock(true);
+        }
+    }
+
+    /**
+     * Remove user index without promoting it.
+     *
+     * @param idxName Index name.
+     */
+    public void rollbackUserIndex(String idxName) {
+        lock(true);
+
+        try {
+            ensureNotDestroyed();
+
+            GridH2IndexBase rmvIdx = tmpIdxs.remove(idxName);
+
+            assert rmvIdx != null;
+        }
+        finally {
+            unlock(true);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeIndex(Index h2Idx) {
+        lock(true);
+
+        try {
+            ArrayList<Index> idxs = new ArrayList<>(this.idxs);
+
+            for (int i = 2; i < idxs.size(); i++) {
+                GridH2IndexBase idx = (GridH2IndexBase)idxs.get(i);
+
+                if (idx != h2Idx)
+                    continue;
+
+                idxs.remove(i);
+
+                this.idxs = idxs;
+
+                return;
+            }
+        }
+        finally {
+            unlock(true);
+        }
     }
 
     /** {@inheritDoc} */
@@ -848,136 +994,4 @@ public class GridH2Table extends TableBase {
         return rowFactory;
     }
 
-    /**
-     * H2 Table engine.
-     */
-    @SuppressWarnings({"PublicInnerClass", "FieldAccessedSynchronizedAndUnsynchronized"})
-    public static class Engine implements TableEngine {
-        /** */
-        private static GridH2RowDescriptor rowDesc;
-
-        /** */
-        private static IndexesFactory idxsFactory;
-
-        /** */
-        private static GridH2Table resTbl;
-
-        /** */
-        private static String spaceName;
-
-        /** {@inheritDoc} */
-        @Override public TableBase createTable(CreateTableData createTblData) {
-            resTbl = new GridH2Table(createTblData, rowDesc, idxsFactory, spaceName);
-
-            return resTbl;
-        }
-
-        /**
-         * Creates table using given connection, DDL clause for given type descriptor and list of indexes.
-         *
-         * @param conn Connection.
-         * @param sql DDL clause.
-         * @param desc Row descriptor.
-         * @param factory Indexes factory.
-         * @param space Space name.
-         * @throws SQLException If failed.
-         * @return Created table.
-         */
-        public static synchronized GridH2Table createTable(Connection conn, String sql,
-            @Nullable GridH2RowDescriptor desc, IndexesFactory factory, String space)
-            throws SQLException {
-            rowDesc = desc;
-            idxsFactory = factory;
-            spaceName = space;
-
-            try {
-                try (Statement s = conn.createStatement()) {
-                    s.execute(sql + " engine \"" + Engine.class.getName() + "\"");
-                }
-
-                return resTbl;
-            }
-            finally {
-                resTbl = null;
-                idxsFactory = null;
-                rowDesc = null;
-            }
-        }
-    }
-
-    /**
-     * Type which can create indexes list for given table.
-     */
-    @SuppressWarnings({"PackageVisibleInnerClass", "PublicInnerClass"})
-    public static interface IndexesFactory {
-        /**
-         * Create list of indexes. First must be primary key, after that all unique indexes and
-         * only then non-unique indexes.
-         * All indexes must be subtypes of {@link H2TreeIndex}.
-         *
-         * @param tbl Table to create indexes for.
-         * @return List of indexes.
-         */
-        ArrayList<Index> createIndexes(GridH2Table tbl);
-
-        /**
-         * @param tbl Table.
-         * @return Data store.
-         */
-        H2RowFactory createRowFactory(GridH2Table tbl);
-    }
-
-    /**
-     * Wrapper type for primary key.
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    class ScanIndex extends GridH2ScanIndex<GridH2IndexBase> {
-        /** */
-        static final String SCAN_INDEX_NAME_SUFFIX = "__SCAN_";
-
-        /** */
-        private final GridH2IndexBase hashIdx;
-
-        /**
-         * Constructor.
-         */
-        private ScanIndex(GridH2IndexBase treeIdx, GridH2IndexBase hashIdx) {
-            super(treeIdx);
-
-            this.hashIdx = hashIdx;
-        }
-
-        /**
-         *
-         */
-        @Override protected GridH2IndexBase delegate() {
-            if (hashIdx != null)
-                return rebuildFromHashInProgress ? hashIdx : super.delegate();
-            else {
-                assert !rebuildFromHashInProgress;
-
-                return super.delegate();
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public double getCost(Session ses, int[] masks, TableFilter[] filters, int filter,
-            SortOrder sortOrder) {
-            long rows = getRowCountApproximation();
-            double baseCost = getCostRangeIndex(masks, rows, filters, filter, sortOrder, true);
-            int mul = delegate().getDistributedMultiplier(ses, filters, filter);
-
-            return mul * baseCost;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String getPlanSQL() {
-            return delegate().getTable().getSQL() + "." + SCAN_INDEX_NAME_SUFFIX;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String getName() {
-            return delegate().getName() + SCAN_INDEX_NAME_SUFFIX;
-        }
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
index b73bb96..4395024 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
@@ -116,15 +116,7 @@ public class GridLuceneIndex implements AutoCloseable {
             throw new IgniteCheckedException(e);
         }
 
-        GridQueryIndexDescriptor idx = null;
-
-        for (GridQueryIndexDescriptor descriptor : type.indexes().values()) {
-            if (descriptor.type() == QueryIndexType.FULLTEXT) {
-                idx = descriptor;
-
-                break;
-            }
-        }
+        GridQueryIndexDescriptor idx = type.textIndex();
 
         if (idx != null) {
             Collection<String> fields = idx.fields();

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateIndex.java
new file mode 100644
index 0000000..50d455c
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateIndex.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.sql;
+
+import java.util.Map;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
+import org.h2.command.Parser;
+
+/**
+ * CREATE INDEX statement.
+ */
+public class GridSqlCreateIndex extends GridSqlStatement {
+    /** Schema name. */
+    private String schemaName;
+
+    /** Table name. */
+    private String tblName;
+
+    /** Attempt to create the index only if it does not exist. */
+    private boolean ifNotExists;
+
+    /** Index to create. */
+    private QueryIndex idx;
+
+    /**
+     * @return Schema name for new index.
+     */
+    public String schemaName() {
+        return schemaName;
+    }
+
+    /**
+     * @param schemaName Schema name for new index.
+     */
+    public void schemaName(String schemaName) {
+        this.schemaName = schemaName;
+    }
+
+    /**
+     * @return Table name.
+     */
+    public String tableName() {
+        return tblName;
+    }
+
+    /**
+     * @param tblName Table name.
+     */
+    public void tableName(String tblName) {
+        this.tblName = tblName;
+    }
+
+    /**
+     * @return whether attempt to create the index should be made only if it does not exist.
+     */
+    public boolean ifNotExists() {
+        return ifNotExists;
+    }
+
+    /**
+     * @param ifNotExists whether attempt to create the index should be made only if it does not exist.
+     */
+    public void ifNotExists(boolean ifNotExists) {
+        this.ifNotExists = ifNotExists;
+    }
+
+    /**
+     * @return Index to create.
+     */
+    public QueryIndex index() {
+        return idx;
+    }
+
+    /**
+     * @param idx Index to create.
+     */
+    public void index(QueryIndex idx) {
+        this.idx = idx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSQL() {
+        StringBuilder sb = new StringBuilder("CREATE ")
+            .append(idx.getIndexType() == QueryIndexType.GEOSPATIAL ? "SPATIAL " : "")
+            .append("INDEX ").append(ifNotExists ? "IF NOT EXISTS " : "")
+            .append(Parser.quoteIdentifier(schemaName)).append('.')
+            .append(Parser.quoteIdentifier(idx.getName())).append(" ON ")
+            .append(Parser.quoteIdentifier(tblName)).append(" (");
+
+        boolean first = true;
+
+        for (Map.Entry<String, Boolean> e : idx.getFields().entrySet()) {
+            if (first)
+                first = false;
+            else
+                sb.append(", ");
+
+            sb.append(Parser.quoteIdentifier(e.getKey())).append(e.getValue() ? " ASC" : " DESC");
+        }
+
+        sb.append(')');
+
+        return sb.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlDropIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlDropIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlDropIndex.java
new file mode 100644
index 0000000..c844b49
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlDropIndex.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.sql;
+
+import org.h2.command.Parser;
+
+/**
+ * DROP INDEX statement.
+ */
+public class GridSqlDropIndex extends GridSqlStatement {
+    /** Index name. */
+    private String name;
+
+    /** Schema name. */
+    private String schemaName;
+
+    /** Attempt to drop the index only if it exists. */
+    private boolean ifExists;
+
+    /**
+     * @return Index name.
+     */
+    public String name() {
+        return name;
+    }
+
+    /**
+     * @param name Index name.
+     */
+    public void name(String name) {
+        this.name = name;
+    }
+
+    /**
+     * @return Schema name.
+     */
+    public String schemaName() {
+        return schemaName;
+    }
+
+    /**
+     * @param schemaName Schema name.
+     */
+    public void schemaName(String schemaName) {
+        this.schemaName = schemaName;
+    }
+
+    /**
+     * @return whether attempt to drop the index should be made only if it exists.
+     */
+    public boolean ifExists() {
+        return ifExists;
+    }
+
+    /**
+     * @param ifExists whether attempt to drop the index should be made only if it exists.
+     */
+    public void ifExists(boolean ifExists) {
+        this.ifExists = ifExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSQL() {
+        return "DROP INDEX " + (ifExists ? "IF EXISTS " : "") + Parser.quoteIdentifier(schemaName) + '.' +
+            Parser.quoteIdentifier(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
index 0f940e9..199a157 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
@@ -28,9 +28,16 @@ import java.util.List;
 import java.util.Map;
 import javax.cache.CacheException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
 import org.h2.command.Command;
 import org.h2.command.CommandContainer;
 import org.h2.command.Prepared;
+import org.h2.command.ddl.CreateIndex;
+import org.h2.command.ddl.DropIndex;
+import org.h2.command.ddl.SchemaCommand;
 import org.h2.command.dml.Delete;
 import org.h2.command.dml.Explain;
 import org.h2.command.dml.Insert;
@@ -63,8 +70,10 @@ import org.h2.expression.ValueExpression;
 import org.h2.index.ViewIndex;
 import org.h2.jdbc.JdbcPreparedStatement;
 import org.h2.result.SortOrder;
+import org.h2.schema.Schema;
 import org.h2.table.Column;
 import org.h2.table.FunctionTable;
+import org.h2.table.IndexColumn;
 import org.h2.table.RangeTable;
 import org.h2.table.Table;
 import org.h2.table.TableBase;
@@ -302,6 +311,48 @@ public class GridSqlQueryParser {
         GridSqlQueryParser.<Command, Prepared>getter(CommandContainer.class, "prepared");
 
     /** */
+    private static final Getter<CreateIndex, String> CREATE_INDEX_NAME = getter(CreateIndex.class, "indexName");
+
+    /** */
+    private static final Getter<CreateIndex, String> CREATE_INDEX_TABLE_NAME = getter(CreateIndex.class, "tableName");
+
+    /** */
+    private static final Getter<CreateIndex, IndexColumn[]> CREATE_INDEX_COLUMNS = getter(CreateIndex.class,
+        "indexColumns");
+
+    /** */
+    private static final Getter<CreateIndex, Boolean> CREATE_INDEX_SPATIAL = getter(CreateIndex.class, "spatial");
+
+    /** */
+    private static final Getter<CreateIndex, Boolean> CREATE_INDEX_PRIMARY_KEY = getter(CreateIndex.class,
+        "primaryKey");
+
+    /** */
+    private static final Getter<CreateIndex, Boolean> CREATE_INDEX_UNIQUE = getter(CreateIndex.class, "unique");
+
+    /** */
+    private static final Getter<CreateIndex, Boolean> CREATE_INDEX_HASH = getter(CreateIndex.class, "hash");
+
+    /** */
+    private static final Getter<CreateIndex, Boolean> CREATE_INDEX_IF_NOT_EXISTS = getter(CreateIndex.class,
+        "ifNotExists");
+
+    /** */
+    private static final Getter<IndexColumn, String> INDEX_COLUMN_NAME = getter(IndexColumn.class, "columnName");
+
+    /** */
+    private static final Getter<IndexColumn, Integer> INDEX_COLUMN_SORT_TYPE = getter(IndexColumn.class, "sortType");
+
+    /** */
+    private static final Getter<DropIndex, String> DROP_INDEX_NAME = getter(DropIndex.class, "indexName");
+
+    /** */
+    private static final Getter<DropIndex, Boolean> DROP_INDEX_IF_EXISTS = getter(DropIndex.class, "ifExists");
+
+    /** */
+    private static final Getter<SchemaCommand, Schema> SCHEMA_COMMAND_SCHEMA = getter(SchemaCommand.class, "schema");
+
+    /** */
     private final IdentityHashMap<Object, Object> h2ObjToGridObj = new IdentityHashMap<>();
 
     /** */
@@ -659,6 +710,72 @@ public class GridSqlQueryParser {
         return res;
     }
 
+
+
+    /**
+     * Parse {@code DROP INDEX} statement.
+     *
+     * @param dropIdx {@code DROP INDEX} statement.
+     * @see <a href="http://h2database.com/html/grammar.html#drop_index">H2 {@code DROP INDEX} spec.</a>
+     */
+    private GridSqlDropIndex parseDropIndex(DropIndex dropIdx) {
+        GridSqlDropIndex res = new GridSqlDropIndex();
+
+        res.name(DROP_INDEX_NAME.get(dropIdx));
+        res.schemaName(SCHEMA_COMMAND_SCHEMA.get(dropIdx).getName());
+        res.ifExists(DROP_INDEX_IF_EXISTS.get(dropIdx));
+
+        return res;
+    }
+
+    /**
+     * Parse {@code CREATE INDEX} statement.
+     *
+     * @param createIdx {@code CREATE INDEX} statement.
+     * @see <a href="http://h2database.com/html/grammar.html#create_index">H2 {@code CREATE INDEX} spec.</a>
+     */
+    private GridSqlCreateIndex parseCreateIndex(CreateIndex createIdx) {
+        if (CREATE_INDEX_HASH.get(createIdx) || CREATE_INDEX_PRIMARY_KEY.get(createIdx) ||
+            CREATE_INDEX_UNIQUE.get(createIdx))
+            throw new IgniteSQLException("Only SPATIAL modifier is supported for CREATE INDEX",
+                IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
+
+        GridSqlCreateIndex res = new GridSqlCreateIndex();
+
+        Schema schema = SCHEMA_COMMAND_SCHEMA.get(createIdx);
+
+        String tblName = CREATE_INDEX_TABLE_NAME.get(createIdx);
+
+        res.schemaName(schema.getName());
+        res.tableName(tblName);
+        res.ifNotExists(CREATE_INDEX_IF_NOT_EXISTS.get(createIdx));
+
+        QueryIndex idx = new QueryIndex();
+
+        idx.setName(CREATE_INDEX_NAME.get(createIdx));
+        idx.setIndexType(CREATE_INDEX_SPATIAL.get(createIdx) ? QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);
+
+        IndexColumn[] cols = CREATE_INDEX_COLUMNS.get(createIdx);
+
+        LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>(cols.length);
+
+        for (IndexColumn col : CREATE_INDEX_COLUMNS.get(createIdx)) {
+            int sortType = INDEX_COLUMN_SORT_TYPE.get(col);
+
+            if ((sortType & SortOrder.NULLS_FIRST) != 0 || (sortType & SortOrder.NULLS_LAST) != 0)
+                throw new IgniteSQLException("NULLS FIRST and NULLS LAST modifiers are not supported for index columns",
+                    IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
+
+            flds.put(INDEX_COLUMN_NAME.get(col), (sortType & SortOrder.DESCENDING) == 0);
+        }
+
+        idx.setFields(flds);
+
+        res.index(idx);
+
+        return res;
+    }
+
     /**
      * @param sortOrder Sort order.
      * @param qry Query.
@@ -722,6 +839,12 @@ public class GridSqlQueryParser {
         if (stmt instanceof Explain)
             return parse(EXPLAIN_COMMAND.get((Explain)stmt)).explain(true);
 
+        if (stmt instanceof CreateIndex)
+            return parseCreateIndex((CreateIndex)stmt);
+
+        if (stmt instanceof DropIndex)
+            return parseDropIndex((DropIndex)stmt);
+
         throw new CacheException("Unsupported SQL statement: " + stmt);
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
new file mode 100644
index 0000000..a865b18
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
@@ -0,0 +1,512 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
+import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests for dynamic schema changes.
+ */
+@SuppressWarnings("unchecked")
+public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
+    /** Cache. */
+    protected static final String CACHE_NAME = "cache";
+
+    /** Table name. */
+    protected static final String TBL_NAME = tableName(ValueClass.class);
+
+    /** Table name 2. */
+    protected static final String TBL_NAME_2 = tableName(ValueClass2.class);
+
+    /** Index name 1. */
+    protected static final String IDX_NAME_1 = "idx_1";
+
+    /** Index name 2. */
+    protected static final String IDX_NAME_2 = "idx_2";
+
+    /** Index name 3. */
+    protected static final String IDX_NAME_3 = "idx_3";
+
+    /** Key ID field. */
+    protected static final String FIELD_KEY = "id";
+
+    /** Field 1. */
+    protected static final String FIELD_NAME_1 = "field1";
+
+    /** Field 1. */
+    protected static final String FIELD_NAME_2 = "field2";
+
+    /** Field 3. */
+    protected static final String FIELD_NAME_3 = "field3";
+
+    /**
+     * Get type on the given node for the given cache and table name. Type must exist.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @return Type.
+     */
+    protected static QueryTypeDescriptorImpl typeExisting(IgniteEx node, String cacheName, String tblName) {
+        QueryTypeDescriptorImpl res = type(node, cacheName, tblName);
+
+        assertNotNull(res);
+
+        return res;
+    }
+
+    /**
+     * Get type on the given node for the given cache and table name.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @return Type.
+     */
+    @Nullable protected static QueryTypeDescriptorImpl type(IgniteEx node, String cacheName, String tblName) {
+        return types(node, cacheName).get(tblName);
+    }
+
+    /**
+     * Get available types on the given node for the given cache.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @return Map from table name to type.
+     */
+    protected static Map<String, QueryTypeDescriptorImpl> types(IgniteEx node, String cacheName) {
+        Map<String, QueryTypeDescriptorImpl> res = new HashMap<>();
+
+        Collection<GridQueryTypeDescriptor> descs = node.context().query().types(cacheName);
+
+        for (GridQueryTypeDescriptor desc : descs) {
+            QueryTypeDescriptorImpl desc0 = (QueryTypeDescriptorImpl)desc;
+
+            res.put(desc0.tableName(), desc0);
+        }
+
+        return res;
+    }
+
+    /**
+     * Assert index state on all nodes.
+     *
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idxName Index name.
+     * @param fields Fields.
+     */
+    protected static void assertIndex(String cacheName, String tblName, String idxName,
+        IgniteBiTuple<String, Boolean>... fields) {
+        for (Ignite node : Ignition.allGrids())
+            assertIndex((IgniteEx)node, cacheName, tblName, idxName, fields);
+    }
+
+    /**
+     * Assert index state on particular node.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idxName Index name.
+     * @param fields Fields.
+     */
+    protected static void assertIndex(IgniteEx node, String cacheName, String tblName, String idxName,
+        IgniteBiTuple<String, Boolean>... fields) {
+        assertIndexDescriptor(node, cacheName, tblName, idxName, fields);
+
+        if (affinityNode(node, cacheName)) {
+            QueryTypeDescriptorImpl typeDesc = typeExisting(node, cacheName, tblName);
+
+            assertIndex(typeDesc, idxName, fields);
+        }
+    }
+
+    /**
+     * Make sure index exists in cache descriptor.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idxName Index name.
+     * @param fields Fields.
+     */
+    protected static void assertIndexDescriptor(IgniteEx node, String cacheName, String tblName, String idxName,
+        IgniteBiTuple<String, Boolean>... fields) {
+        awaitCompletion();
+
+        DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
+
+        assert desc != null;
+
+        for (QueryEntity entity : desc.schema().entities()) {
+            if (F.eq(tblName, QueryUtils.tableName(entity))) {
+                for (QueryIndex idx : entity.getIndexes()) {
+                    if (F.eq(QueryUtils.indexName(entity, idx), idxName)) {
+                        LinkedHashMap<String, Boolean> idxFields = idx.getFields();
+
+                        assertEquals(idxFields.size(), fields.length);
+
+                        int i = 0;
+
+                        for (String idxField : idxFields.keySet()) {
+                            assertEquals(idxField, fields[i].get1());
+                            assertEquals(idxFields.get(idxField), fields[i].get2());
+
+                            i++;
+                        }
+
+                        return;
+                    }
+                }
+            }
+        }
+
+        fail("Index not found [cacheName=" + cacheName + ", tlbName=" + tblName + ", idxName=" + idxName + ']');
+    }
+
+    /**
+     * Assert index state.
+     *
+     * @param typeDesc Type descriptor.
+     * @param idxName Index name.
+     * @param fields Fields (order is important).
+     */
+    protected static void assertIndex(QueryTypeDescriptorImpl typeDesc, String idxName,
+        IgniteBiTuple<String, Boolean>... fields) {
+        QueryIndexDescriptorImpl idxDesc = typeDesc.index(idxName);
+
+        assertNotNull(idxDesc);
+
+        assertEquals(idxName, idxDesc.name());
+        assertEquals(typeDesc, idxDesc.typeDescriptor());
+        assertEquals(QueryIndexType.SORTED, idxDesc.type());
+
+        List<String> fieldNames = new ArrayList<>(idxDesc.fields());
+
+        assertEquals(fields.length, fieldNames.size());
+
+        for (int i = 0; i < fields.length; i++) {
+            String expFieldName = fields[i].get1();
+            boolean expFieldAsc = fields[i].get2();
+
+            assertEquals("Index field mismatch [pos=" + i + ", expField=" + expFieldName +
+                ", actualField=" + fieldNames.get(i) + ']', expFieldName, fieldNames.get(i));
+
+            boolean fieldAsc = !idxDesc.descending(expFieldName);
+
+            assertEquals("Index field sort mismatch [pos=" + i + ", field=" + expFieldName +
+                ", expAsc=" + expFieldAsc + ", actualAsc=" + fieldAsc + ']', expFieldAsc, fieldAsc);
+        }
+    }
+
+    /**
+     * Assert index doesn't exist on all nodes.
+     *
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idxName Index name.
+     */
+    protected static void assertNoIndex(String cacheName, String tblName, String idxName) {
+        for (Ignite node : Ignition.allGrids())
+            assertNoIndex((IgniteEx)node, cacheName, tblName, idxName);
+    }
+
+    /**
+     * Assert index doesn't exist on particular node.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idxName Index name.
+     */
+    protected static void assertNoIndex(IgniteEx node, String cacheName, String tblName, String idxName) {
+        assertNoIndexDescriptor(node, cacheName, tblName, idxName);
+
+        if (affinityNode(node, cacheName)) {
+            QueryTypeDescriptorImpl typeDesc = typeExisting(node, cacheName, tblName);
+
+            assertNoIndex(typeDesc, idxName);
+        }
+    }
+
+    /**
+     * Assert index doesn't exist in particular node's cache descriptor.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idxName Index name.
+     */
+    protected static void assertNoIndexDescriptor(IgniteEx node, String cacheName, String tblName, String idxName) {
+        awaitCompletion();
+
+        DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
+
+        if (desc == null)
+            return;
+
+        for (QueryEntity entity : desc.schema().entities()) {
+            for (QueryIndex idx : entity.getIndexes()) {
+                if (F.eq(idxName, QueryUtils.indexName(entity, idx)))
+                    fail("Index exists: " + idxName);
+            }
+        }
+    }
+
+    /**
+     * Await completion (hopefully) of pending operations.
+     */
+    private static void awaitCompletion() {
+        try {
+            U.sleep(100);
+        }
+        catch (IgniteInterruptedCheckedException e) {
+            fail();
+        }
+    }
+
+    /**
+     * Assert index doesn't exist.
+     *
+     * @param typeDesc Type descriptor.
+     * @param idxName Index name.
+     */
+    protected static void assertNoIndex(QueryTypeDescriptorImpl typeDesc, String idxName) {
+        assertNull(typeDesc.index(idxName));
+    }
+
+    /**
+     * Check whether this is affinity node for cache.
+     *
+     * @param node Node.
+     * @param cacheName Cache name.
+     * @return {@code True} if affinity node.
+     */
+    private static boolean affinityNode(IgniteEx node, String cacheName) {
+        if (node.configuration().isClientMode())
+            return false;
+
+        DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor(cacheName);
+
+        IgnitePredicate<ClusterNode> filter = cacheDesc.cacheConfiguration().getNodeFilter();
+
+        return filter == null || filter.apply(node.localNode());
+    }
+
+    /**
+     * Get table name for class.
+     *
+     * @param cls Class.
+     * @return Table name.
+     */
+    protected static String tableName(Class cls) {
+        return cls.getSimpleName();
+    }
+
+    /**
+     * Convenient method for index creation.
+     *
+     * @param name Name.
+     * @param fields Fields.
+     * @return Index.
+     */
+    protected static QueryIndex index(String name, IgniteBiTuple<String, Boolean>... fields) {
+        QueryIndex idx = new QueryIndex();
+
+        idx.setName(name);
+
+        LinkedHashMap<String, Boolean> fields0 = new LinkedHashMap<>();
+
+        for (IgniteBiTuple<String, Boolean> field : fields)
+            fields0.put(field.getKey(), field.getValue());
+
+        idx.setFields(fields0);
+
+        return idx;
+    }
+
+    /**
+     * Get query processor.
+     *
+     * @param node Node.
+     * @return Query processor.
+     */
+    protected static GridQueryProcessor queryProcessor(Ignite node) {
+        return ((IgniteEx)node).context().query();
+    }
+
+    /**
+     * Field for index state check (ascending).
+     *
+     * @param name Name.
+     * @return Field.
+     */
+    protected static IgniteBiTuple<String, Boolean> field(String name) {
+        return field(name, true);
+    }
+
+    /**
+     * Field for index state check.
+     *
+     * @param name Name.
+     * @param asc Ascending flag.
+     * @return Field.
+     */
+    protected static IgniteBiTuple<String, Boolean> field(String name, boolean asc) {
+        return F.t(name, asc);
+    }
+
+    /**
+     * @param fieldName Field name.
+     * @return Alias.
+     */
+    protected static String alias(String fieldName) {
+        return fieldName + "_alias";
+    }
+
+    /**
+     * Key class.
+     */
+    public static class KeyClass {
+        /** ID. */
+        @QuerySqlField
+        private long id;
+
+        /**
+         * Constructor.
+         *
+         * @param id ID.
+         */
+        public KeyClass(long id) {
+            this.id = id;
+        }
+
+        /**
+         * @return ID.
+         */
+        public long id() {
+            return id;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            KeyClass keyClass = (KeyClass) o;
+
+            return id == keyClass.id;
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return (int) (id ^ (id >>> 32));
+        }
+    }
+
+    /**
+     * Key class.
+     */
+    public static class ValueClass {
+        /** Field 1. */
+        @QuerySqlField
+        private String field1;
+
+        /**
+         * Constructor.
+         *
+         * @param field1 Field 1.
+         */
+        public ValueClass(String field1) {
+            this.field1 = field1;
+        }
+
+        /**
+         * @return Field 1
+         */
+        public String field1() {
+            return field1;
+        }
+    }
+
+    /**
+     * Key class.
+     */
+    public static class ValueClass2 {
+        /** Field 1. */
+        @QuerySqlField(name = "field1")
+        private String field;
+
+        /**
+         * Constructor.
+         *
+         * @param field Field 1.
+         */
+        public ValueClass2(String field) {
+            this.field = field;
+        }
+
+        /**
+         * @return Field 1
+         */
+        public String field() {
+            return field;
+        }
+    }
+
+    /**
+     * Runnable which can throw checked exceptions.
+     */
+    protected interface RunnableX {
+        /**
+         * Do run.
+         *
+         * @throws Exception If failed.
+         */
+        public void run() throws Exception;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
new file mode 100644
index 0000000..6bc1576
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
@@ -0,0 +1,950 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ * Tests for dynamic index creation.
+ */
+@SuppressWarnings({"unchecked", "ThrowableResultOfMethodCallIgnored"})
+public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbstractSelfTest {
+    /** Node index for regular server (coordinator). */
+    protected static final int IDX_SRV_CRD = 0;
+
+    /** Node index for regular server (not coordinator). */
+    protected static final int IDX_SRV_NON_CRD = 1;
+
+    /** Node index for regular client. */
+    protected static final int IDX_CLI = 2;
+
+    /** Node index for server which doesn't pass node filter. */
+    protected static final int IDX_SRV_FILTERED = 3;
+
+    /** Node index for client with near-only cache. */
+    protected static final int IDX_CLI_NEAR_ONLY = 4;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        for (IgniteConfiguration cfg : configurations())
+            Ignition.start(cfg);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        node().destroyCache(CACHE_NAME);
+
+        super.afterTest();
+    }
+
+    /**
+     * Initialize cache for tests.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     */
+    private void initialize(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) {
+        node().getOrCreateCache(cacheConfiguration(mode, atomicityMode, near));
+
+        grid(IDX_CLI_NEAR_ONLY).getOrCreateNearCache(CACHE_NAME, new NearCacheConfiguration<>());
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+
+        loadInitialData();
+    }
+
+    /**
+     * Create cache with the given cache mode and atomicity mode.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Whether near cache should be initialized.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration<KeyClass, ValueClass> cacheConfiguration(CacheMode mode,
+        CacheAtomicityMode atomicityMode, boolean near) {
+        CacheConfiguration<KeyClass, ValueClass> ccfg = cacheConfiguration();
+
+        ccfg.setCacheMode(mode);
+        ccfg.setAtomicityMode(atomicityMode);
+
+        if (near)
+            ccfg.setNearConfiguration(new NearCacheConfiguration<KeyClass, ValueClass>());
+
+        return ccfg;
+    }
+
+    /**
+     * Load initial data.
+     */
+    private void loadInitialData() {
+        put(node(), 0, KEY_BEFORE);
+    }
+
+    /**
+     * Test simple index create for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreatePartitionedAtomic() throws Exception {
+        checkCreate(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test simple index create for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreatePartitionedAtomicNear() throws Exception {
+        checkCreate(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test simple index create for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreatePartitionedTransactional() throws Exception {
+        checkCreate(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test simple index create for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreatePartitionedTransactionalNear() throws Exception {
+        checkCreate(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test simple index create for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateReplicatedAtomic() throws Exception {
+        checkCreate(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test simple index create for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateReplicatedTransactional() throws Exception {
+        checkCreate(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check normal create operation.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkCreate(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        final IgniteEx node = node();
+
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+            }
+        }, SchemaOperationException.CODE_INDEX_EXISTS);
+
+        queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true).get();
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+    }
+
+    /**
+     * Test composite index creation for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateCompositePartitionedAtomic() throws Exception {
+        checkCreateComposite(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test composite index creation for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateCompositePartitionedAtomicNear() throws Exception {
+        checkCreateComposite(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test composite index creation for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateCompositePartitionedTransactional() throws Exception {
+        checkCreateComposite(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test composite index creation for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateCompositePartitionedTransactionalNear() throws Exception {
+        checkCreateComposite(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test composite index creation for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateCompositeReplicatedAtomic() throws Exception {
+        checkCreateComposite(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test composite index creation for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateCompositeReplicatedTransactional() throws Exception {
+        checkCreateComposite(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check composite index creation.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkCreateComposite(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1), field(alias(FIELD_NAME_2)));
+
+        queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1), field(alias(FIELD_NAME_2)));
+
+        assertCompositeIndexOperations(SQL_COMPOSITE);
+
+        assertIndexUsed(IDX_NAME_1, SQL_COMPOSITE, SQL_ARG_1, SQL_ARG_2);
+    }
+
+    /**
+     * Test create when cache doesn't exist for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoCachePartitionedAtomic() throws Exception {
+        checkCreateNotCache(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test create when cache doesn't exist for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoCachePartitionedAtomicNear() throws Exception {
+        checkCreateNotCache(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test create when cache doesn't exist for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoCachePartitionedTransactional() throws Exception {
+        checkCreateNotCache(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test create when cache doesn't exist for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoCachePartitionedTransactionalNear() throws Exception {
+        checkCreateNotCache(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test create when cache doesn't exist for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoCacheReplicatedAtomic() throws Exception {
+        checkCreateNotCache(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test create when cache doesn't exist for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoCacheReplicatedTransactional() throws Exception {
+        checkCreateNotCache(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check create when cache doesn't exist.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkCreateNotCache(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexCreate(randomString(), TBL_NAME, idx, false).get();
+            }
+        }, SchemaOperationException.CODE_CACHE_NOT_FOUND);
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoTablePartitionedAtomic() throws Exception {
+        checkCreateNoTable(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoTablePartitionedAtomicNear() throws Exception {
+        checkCreateNoTable(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoTablePartitionedTransactional() throws Exception {
+        checkCreateNoTable(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoTablePartitionedTransactionalNear() throws Exception {
+        checkCreateNoTable(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test create when table doesn't exist for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoTableReplicatedAtomic() throws Exception {
+        checkCreateNoTable(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test create when table doesn't exist for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoTableReplicatedTransactional() throws Exception {
+        checkCreateNoTable(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check create when table doesn't exist.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkCreateNoTable(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, randomString(), idx, false).get();
+            }
+        }, SchemaOperationException.CODE_TABLE_NOT_FOUND);
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoColumnPartitionedAtomic() throws Exception {
+        checkCreateNoColumn(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoColumnPartitionedAtomicNear() throws Exception {
+        checkCreateNoColumn(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoColumnPartitionedTransactional() throws Exception {
+        checkCreateNoColumn(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test create when table doesn't exist for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoColumnPartitionedTransactionalNear() throws Exception {
+        checkCreateNoColumn(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test create when table doesn't exist for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoColumnReplicatedAtomic() throws Exception {
+        checkCreateNoColumn(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test create when table doesn't exist for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateNoColumnReplicatedTransactional() throws Exception {
+        checkCreateNoColumn(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check create when table doesn't exist.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkCreateNoColumn(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        final QueryIndex idx = index(IDX_NAME_1, field(randomString()));
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+            }
+        }, SchemaOperationException.CODE_COLUMN_NOT_FOUND);
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+    }
+
+    /**
+     * Test index creation on aliased column for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateColumnWithAliasPartitionedAtomic() throws Exception {
+        checkCreateColumnWithAlias(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test index creation on aliased column for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateColumnWithAliasPartitionedAtomicNear() throws Exception {
+        checkCreateColumnWithAlias(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test index creation on aliased column for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateColumnWithAliasPartitionedTransactional() throws Exception {
+        checkCreateColumnWithAlias(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test index creation on aliased column for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateColumnWithAliasPartitionedTransactionalNear() throws Exception {
+        checkCreateColumnWithAlias(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test index creation on aliased column for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateColumnWithAliasReplicatedAtomic() throws Exception {
+        checkCreateColumnWithAlias(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test index creation on aliased column for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCreateColumnWithAliasReplicatedTransactional() throws Exception {
+        checkCreateColumnWithAlias(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check index creation on aliased column.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkCreateColumnWithAlias(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near)
+        throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_2));
+
+                queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+            }
+        }, SchemaOperationException.CODE_COLUMN_NOT_FOUND);
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+
+        QueryIndex idx = index(IDX_NAME_1, field(alias(FIELD_NAME_2)));
+
+        queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(alias(FIELD_NAME_2)));
+
+        assertSimpleIndexOperations(SQL_SIMPLE_FIELD_2);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
+    }
+
+    /**
+     * Test simple index drop for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropPartitionedAtomic() throws Exception {
+        checkDrop(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test simple index drop for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropPartitionedAtomicNear() throws Exception {
+        checkDrop(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test simple index drop for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropPartitionedTransactional() throws Exception {
+        checkDrop(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test simple index drop for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropPartitionedTransactionalNear() throws Exception {
+        checkDrop(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test simple index drop for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropReplicatedAtomic() throws Exception {
+        checkDrop(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test simple index drop for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropReplicatedTransactional() throws Exception {
+        checkDrop(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check simple index drop.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    public void checkDrop(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+
+        assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
+
+        loadInitialData();
+
+        queryProcessor(node()).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, false).get();
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+
+        assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
+
+        assertIndexNotUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+    }
+
+    /**
+     * Test drop when there is no index for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoIndexPartitionedAtomic() throws Exception {
+        checkDropNoIndex(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test drop when there is no index for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoIndexPartitionedAtomicNear() throws Exception {
+        checkDropNoIndex(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test drop when there is no index for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoIndexPartitionedTransactional() throws Exception {
+        checkDropNoIndex(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test drop when there is no index for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoIndexPartitionedTransactionalNear() throws Exception {
+        checkDropNoIndex(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test drop when there is no index for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoIndexReplicatedAtomic() throws Exception {
+        checkDropNoIndex(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test drop when there is no index for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoIndexReplicatedTransactional() throws Exception {
+        checkDropNoIndex(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check drop when there is no index.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkDropNoIndex(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, false).get();
+            }
+        }, SchemaOperationException.CODE_INDEX_NOT_FOUND);
+
+        queryProcessor(node()).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true).get();
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+    }
+
+    /**
+     * Test drop when cache doesn't exist for PARTITIONED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoCachePartitionedAtomic() throws Exception {
+        checkDropNoCache(PARTITIONED, ATOMIC, false);
+    }
+
+    /**
+     * Test drop when cache doesn't exist for PARTITIONED ATOMIC cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoCachePartitionedAtomicNear() throws Exception {
+        checkDropNoCache(PARTITIONED, ATOMIC, true);
+    }
+
+    /**
+     * Test drop when cache doesn't exist for PARTITIONED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoCachePartitionedTransactional() throws Exception {
+        checkDropNoCache(PARTITIONED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Test drop when cache doesn't exist for PARTITIONED TRANSACTIONAL cache with near cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoCachePartitionedTransactionalNear() throws Exception {
+        checkDropNoCache(PARTITIONED, TRANSACTIONAL, true);
+    }
+
+    /**
+     * Test drop when cache doesn't exist for REPLICATED ATOMIC cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoCacheReplicatedAtomic() throws Exception {
+        checkDropNoCache(REPLICATED, ATOMIC, false);
+    }
+
+    /**
+     * Test drop when cache doesn't exist for REPLICATED TRANSACTIONAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDropNoCacheReplicatedTransactional() throws Exception {
+        checkDropNoCache(REPLICATED, TRANSACTIONAL, false);
+    }
+
+    /**
+     * Check drop when cache doesn't exist.
+     *
+     * Check drop when there is no index.
+     *
+     * @param mode Mode.
+     * @param atomicityMode Atomicity mode.
+     * @param near Near flag.
+     * @throws Exception If failed.
+     */
+    private void checkDropNoCache(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
+        initialize(mode, atomicityMode, near);
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexDrop(randomString(), "my_idx", false).get();
+            }
+        }, SchemaOperationException.CODE_CACHE_NOT_FOUND);
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+    }
+
+    /**
+     * Test that operations fail on LOCAL cache.
+     *
+     * @throws Exception If failed.
+     */
+    public void testFailOnLocalCache() throws Exception {
+        for (Ignite node : Ignition.allGrids()) {
+            if (!node.configuration().isClientMode())
+                node.getOrCreateCache(cacheConfiguration().setCacheMode(LOCAL));
+        }
+
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true).get();
+            }
+        }, SchemaOperationException.CODE_GENERIC);
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+
+        assertSchemaException(new RunnableX() {
+            @Override public void run() throws Exception {
+                queryProcessor(node()).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true).get();
+            }
+        }, SchemaOperationException.CODE_GENERIC);
+    }
+
+    /**
+     * Get node which should be used to start operations.
+     *
+     * @return If failed.
+     */
+    protected IgniteEx node() {
+        return grid(nodeIndex());
+    }
+
+    /**
+     * Get index of the node which should be used to start operations.
+     *
+     * @return If failed.
+     */
+    protected abstract int nodeIndex();
+
+    /**
+     * Get configurations to be used in test.
+     *
+     * @return Configurations.
+     * @throws Exception If failed.
+     */
+    protected List<IgniteConfiguration> configurations() throws Exception {
+        return Arrays.asList(
+            serverCoordinatorConfiguration(IDX_SRV_CRD),
+            serverConfiguration(IDX_SRV_NON_CRD),
+            clientConfiguration(IDX_CLI),
+            serverConfiguration(IDX_SRV_FILTERED, true),
+            clientConfiguration(IDX_CLI_NEAR_ONLY)
+        );
+    }
+
+    /**
+     * Get server coordinator configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    protected IgniteConfiguration serverCoordinatorConfiguration(int idx) throws Exception {
+        return serverConfiguration(idx);
+    }
+
+    /**
+     * Assert FIELD_1 index usage.
+     *
+     * @param sql Simple SQL.
+     */
+    private void assertSimpleIndexOperations(String sql) {
+        for (Ignite node : Ignition.allGrids())
+            assertSqlSimpleData(node, sql, KEY_BEFORE - SQL_ARG_1);
+
+        put(node(), KEY_BEFORE, KEY_AFTER);
+
+        for (Ignite node : Ignition.allGrids())
+            assertSqlSimpleData(node, sql, KEY_AFTER - SQL_ARG_1);
+
+        remove(node(), 0, KEY_BEFORE);
+
+        for (Ignite node : Ignition.allGrids())
+            assertSqlSimpleData(node, sql, KEY_AFTER - KEY_BEFORE);
+
+        remove(node(), KEY_BEFORE, KEY_AFTER);
+
+        for (Ignite node : Ignition.allGrids())
+            assertSqlSimpleData(node, sql, 0);
+    }
+
+    /**
+     * Assert composite index usage.
+     *
+     * @param sql Simple SQL.
+     */
+    private void assertCompositeIndexOperations(String sql) {
+        for (Ignite node : Ignition.allGrids())
+            assertSqlCompositeData(node, sql, KEY_BEFORE - SQL_ARG_2);
+
+        put(node(), KEY_BEFORE, KEY_AFTER);
+
+        for (Ignite node : Ignition.allGrids())
+            assertSqlCompositeData(node, sql, KEY_AFTER - SQL_ARG_2);
+
+        remove(node(), 0, KEY_BEFORE);
+
+        for (Ignite node : Ignition.allGrids())
+            assertSqlCompositeData(node, sql, KEY_AFTER - KEY_BEFORE);
+
+        remove(node(), KEY_BEFORE, KEY_AFTER);
+
+        for (Ignite node : Ignition.allGrids())
+            assertSqlCompositeData(node, sql, 0);
+    }
+}


[48/50] [abbrv] ignite git commit: Minor corrections in tests.

Posted by sb...@apache.org.
Minor corrections in tests.


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

Branch: refs/heads/ignite-1561
Commit: 5dab5fb65d97921d7e28e04283a3d47d00c44a25
Parents: fb1dea7
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Wed Apr 19 14:22:00 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Apr 19 14:22:00 2017 +0300

----------------------------------------------------------------------
 ...ServiceProcessorMultiNodeConfigSelfTest.java | 23 ++++++++-------
 .../GridServiceProcessorMultiNodeSelfTest.java  | 31 ++++++++++----------
 2 files changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5dab5fb6/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
index 16e5e30..bd47b53 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
@@ -55,7 +55,6 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
     /** {@inheritDoc} */
     @Override protected ServiceConfiguration[] services() {
-        List<ServiceConfiguration> cfgs = new ArrayList<>();
 
         ServiceConfiguration cfg = new ServiceConfiguration();
 
@@ -64,6 +63,8 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
         cfg.setTotalCount(1);
         cfg.setService(new DummyService());
 
+        List<ServiceConfiguration> cfgs = new ArrayList<>();
+
         cfgs.add(cfg);
 
         cfg = new ServiceConfiguration();
@@ -201,12 +202,12 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
         checkCount(name, g.services().serviceDescriptors(), nodeCount());
 
-        int extraNodes = 2;
-
         CountDownLatch latch = new CountDownLatch(1);
 
         DummyService.exeLatch(name, latch);
 
+        int extraNodes = 2;
+
         startExtraNodes(extraNodes);
 
         try {
@@ -270,10 +271,10 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
             waitForDeployment(name, nodeCount() + newNodes);
 
+            // Since we start extra nodes, there may be extra start and cancel events,
+            // so we check only the difference between start and cancel and
+            // not start and cancel events individually.
             assertEquals(name, newNodes,  DummyService.started(name) - DummyService.cancelled(name));
-// Next may fails. Server can be restarted on unstable topology.
-//            assertEquals(name, newNodes, DummyService.started(name));
-//            assertEquals(name, 0, DummyService.cancelled(name));
 
             checkCount(name, g.services().serviceDescriptors(), nodeCount() + newNodes);
         }
@@ -294,12 +295,13 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
         Ignite g = randomGrid();
 
         int servers = 2;
-        int clients = 2;
 
         CountDownLatch latch = new CountDownLatch(servers);
 
         DummyService.exeLatch(name, latch);
 
+        int clients = 2;
+
         startExtraNodes(servers, clients);
 
         try {
@@ -307,11 +309,10 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
             waitForDeployment(name, nodeCount() + servers);
 
+            // Since we start extra nodes, there may be extra start and cancel events,
+            // so we check only the difference between start and cancel and
+            // not start and cancel events individually.
             assertEquals(name, servers,  DummyService.started(name) - DummyService.cancelled(name));
-// Next may fails. Server can be restarted on unstable topology.
-//            assertEquals(name, servers, DummyService.started(name));
-//            assertEquals(name, 0, DummyService.cancelled(name));
-
 
             checkCount(name, g.services().serviceDescriptors(), nodeCount() + servers);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5dab5fb6/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
index 32d1462..df7ddf1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
@@ -152,12 +152,13 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
             assertEquals(name, 0, DummyService.cancelled(name));
 
             int servers = 2;
-            int clients = 2;
 
             latch = new CountDownLatch(servers);
 
             DummyService.exeLatch(name, latch);
 
+            int clients = 2;
+
             startExtraNodes(servers, clients);
 
             try {
@@ -165,12 +166,11 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
 
                 waitForDeployment(name, servers);
 
+                // Since we start extra nodes, there may be extra start and cancel events,
+                // so we check only the difference between start and cancel and
+                // not start and cancel events individually.
                 assertEquals(name, nodeCount() + servers,  DummyService.started(name) - DummyService.cancelled(name));
 
-//                 Next may fails. Server can be restarted on unstable topology.
-//                assertEquals(name, nodeCount() + servers, DummyService.started(name));
-//                assertEquals(name, 0, DummyService.cancelled(name));
-
                 checkCount(name, g.services().serviceDescriptors(), nodeCount() + servers);
             }
             finally {
@@ -241,13 +241,12 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
 
                 waitForDeployment(name, prestartedNodes + extraNodes);
 
+                // Since we start extra nodes, there may be extra start and cancel events,
+                // so we check only the difference between start and cancel and
+                // not start and cancel events individually.
                 assertEquals(name, prestartedNodes + extraNodes,
                     DummyService.started(name) - DummyService.cancelled(name));
 
-//                 Next may fails. Server can be restarted on unstable topology.
-//                assertEquals(name, prestartedNodes + extraNodes, DummyService.started(name));
-//                assertEquals(name, 0, DummyService.cancelled(name));
-
                 checkCount(name, g.services().serviceDescriptors(), prestartedNodes + extraNodes);
             }
             finally {
@@ -262,6 +261,7 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
     /**
      * @throws Exception If failed.
      */
+    @SuppressWarnings("deprecation")
     public void testDeployLimits() throws Exception {
         final String name = "serviceWithLimitsUpdateTopology";
 
@@ -299,25 +299,24 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
 
         checkCount(name, g.services().serviceDescriptors(), nodeCount());
 
-        int extraNodes = 2;
-
         latch = new CountDownLatch(1);
 
         DummyService.exeLatch(name, latch);
 
-        startExtraNodes(2);
+        int extraNodes = 2;
+
+        startExtraNodes(extraNodes);
 
         try {
             latch.await();
 
             waitForDeployment(name, totalInstances);
 
+            // Since we start extra nodes, there may be extra start and cancel events,
+            // so we check only the difference between start and cancel and
+            // not start and cancel events individually.
             assertEquals(name, totalInstances,  DummyService.started(name) - DummyService.cancelled(name));
 
-//            Next may fails. Server can be restarted on unstable topology.
-//            assertEquals(name, totalInstances, DummyService.started(name));
-//            assertEquals(name, 0, DummyService.cancelled(name));
-
             checkCount(name, g.services().serviceDescriptors(), totalInstances);
         }
         finally {


[40/50] [abbrv] ignite git commit: IGNITE-4988 Cleanup code.

Posted by sb...@apache.org.
IGNITE-4988 Cleanup code.


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

Branch: refs/heads/ignite-1561
Commit: 36e7e19830dc53c0ed02a0d83806b2cb5a7c7ce5
Parents: f82ed01
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Wed Apr 19 11:34:16 2017 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Wed Apr 19 11:34:16 2017 +0700

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 10 +++
 .../visor/cache/VisorCachePartition.java        | 87 -------------------
 .../visor/cache/VisorCachePartitions.java       | 28 +++---
 .../visor/cache/VisorCachePartitionsTask.java   | 20 +++--
 .../cache/VisorCachePartitionsTaskArg.java      | 72 ++++++++++++++++
 .../visor/compute/VisorGatewayTask.java         | 91 ++++++++++++--------
 .../resources/META-INF/classnames.properties    |  2 +-
 7 files changed, 164 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index e5d9997..1321929 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@ -66,6 +66,8 @@ import org.apache.ignite.internal.visor.cache.VisorCacheMetadataTask;
 import org.apache.ignite.internal.visor.cache.VisorCacheMetricsCollectorTask;
 import org.apache.ignite.internal.visor.cache.VisorCacheMetricsCollectorTaskArg;
 import org.apache.ignite.internal.visor.cache.VisorCacheNodesTask;
+import org.apache.ignite.internal.visor.cache.VisorCachePartitionsTask;
+import org.apache.ignite.internal.visor.cache.VisorCachePartitionsTaskArg;
 import org.apache.ignite.internal.visor.cache.VisorCacheRebalanceTask;
 import org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTask;
 import org.apache.ignite.internal.visor.cache.VisorCacheStartTaskArg;
@@ -1283,6 +1285,14 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
 
         jsonTaskResult(ret);
 
+        ret = content(new VisorGatewayArgument(VisorCachePartitionsTask.class)
+            .forNode(locNode)
+            .argument(VisorCachePartitionsTaskArg.class, "person"));
+
+        info("VisorCachePartitionsTask result: " + ret);
+
+        jsonTaskResult(ret);
+
         ret = content(new VisorGatewayArgument(VisorCacheLoadTask.class)
             .forNode(locNode)
             .argument(VisorCacheLoadTaskArg.class, "person", 0, "null"));

http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartition.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartition.java
deleted file mode 100644
index b57bc53..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartition.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.visor.cache;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.visor.VisorDataTransferObject;
-
-/**
- * Data transfer object for information about keys in cache partition.
- */
-public class VisorCachePartition extends VisorDataTransferObject {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private int partId;
-
-    /** */
-    private long cnt;
-
-    /**
-     * Default constructor.
-     */
-    public VisorCachePartition() {
-        // No-op.
-    }
-
-    /**
-     * Full constructor.
-     *
-     * @param partId Partition id.
-     * @param cnt Number of keys in partition.
-     */
-    public VisorCachePartition(int partId, long cnt) {
-        this.partId = partId;
-        this.cnt = cnt;
-    }
-
-    /**
-     * @return Partition id.
-     */
-    public int getPartitionId() {
-        return partId;
-    }
-
-    /**
-     * @return Number of keys in partition.
-     */
-    public long getCount() {
-        return cnt;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeExternalData(ObjectOutput out) throws IOException {
-        out.writeInt(partId);
-        out.writeLong(cnt);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
-        partId = in.readInt();
-        cnt = in.readLong();
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(VisorCachePartition.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitions.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitions.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitions.java
index 2713179..505d98e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitions.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitions.java
@@ -20,8 +20,8 @@ package org.apache.ignite.internal.visor.cache;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.visor.VisorDataTransferObject;
@@ -34,17 +34,17 @@ public class VisorCachePartitions extends VisorDataTransferObject {
     private static final long serialVersionUID = 0L;
 
     /** */
-    private List<VisorCachePartition> primary;
+    private Map<Integer, Long> primary;
 
     /** */
-    private List<VisorCachePartition> backup;
+    private Map<Integer, Long> backup;
 
     /**
      * Default constructor.
      */
     public VisorCachePartitions() {
-        primary = new ArrayList<>();
-        backup = new ArrayList<>();
+        primary = new HashMap<>();
+        backup = new HashMap<>();
     }
 
     /**
@@ -54,7 +54,7 @@ public class VisorCachePartitions extends VisorDataTransferObject {
      * @param cnt Number of primary keys in partition.
      */
     public void addPrimary(int partId, long cnt) {
-       primary.add(new VisorCachePartition(partId, cnt));
+       primary.put(partId, cnt);
     }
 
     /**
@@ -64,33 +64,33 @@ public class VisorCachePartitions extends VisorDataTransferObject {
      * @param cnt Number of backup keys in partition.
      */
     public void addBackup(int partId, long cnt) {
-       backup.add(new VisorCachePartition(partId, cnt));
+       backup.put(partId, cnt);
     }
 
     /**
      * @return Get list of primary partitions.
      */
-    public List<VisorCachePartition> getPrimary() {
+    public Map<Integer, Long> getPrimary() {
         return primary;
     }
 
     /**
      * @return Get list of backup partitions.
      */
-    public List<VisorCachePartition> getBackup() {
+    public Map<Integer, Long> getBackup() {
         return backup;
     }
 
     /** {@inheritDoc} */
     @Override protected void writeExternalData(ObjectOutput out) throws IOException {
-        U.writeCollection(out, primary);
-        U.writeCollection(out, backup);
+        U.writeMap(out, primary);
+        U.writeMap(out, backup);
     }
 
     /** {@inheritDoc} */
     @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
-        primary = U.readList(in);
-        backup = U.readList(in);
+        primary = U.readMap(in);
+        backup = U.readMap(in);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java
index b7ca975..c9339b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java
@@ -45,13 +45,13 @@ import static org.apache.ignite.internal.visor.util.VisorTaskUtils.escapeName;
  * Task that collect keys distribution in partitions.
  */
 @GridInternal
-public class VisorCachePartitionsTask extends VisorMultiNodeTask<String,
+public class VisorCachePartitionsTask extends VisorMultiNodeTask<VisorCachePartitionsTaskArg,
     Map<UUID, VisorCachePartitions>, VisorCachePartitions> {
     /** */
     private static final long serialVersionUID = 0L;
 
     /** {@inheritDoc} */
-    @Override protected VisorCachePartitionsJob job(String arg) {
+    @Override protected VisorCachePartitionsJob job(VisorCachePartitionsTaskArg arg) {
         return new VisorCachePartitionsJob(arg, debug);
     }
 
@@ -72,22 +72,24 @@ public class VisorCachePartitionsTask extends VisorMultiNodeTask<String,
     /**
      * Job that collect cache metrics from node.
      */
-    private static class VisorCachePartitionsJob extends VisorJob<String, VisorCachePartitions> {
+    private static class VisorCachePartitionsJob extends VisorJob<VisorCachePartitionsTaskArg, VisorCachePartitions> {
         /** */
         private static final long serialVersionUID = 0L;
 
         /**
          * Create job with given argument.
          *
-         * @param cacheName Cache name.
+         * @param arg Tasks arguments.
          * @param debug Debug flag.
          */
-        private VisorCachePartitionsJob(String cacheName, boolean debug) {
-            super(cacheName, debug);
+        private VisorCachePartitionsJob(VisorCachePartitionsTaskArg arg, boolean debug) {
+            super(arg, debug);
         }
 
         /** {@inheritDoc} */
-        @Override protected VisorCachePartitions run(final String cacheName) throws IgniteException {
+        @Override protected VisorCachePartitions run(VisorCachePartitionsTaskArg arg) throws IgniteException {
+            String cacheName = arg.getCacheName();
+
             if (debug)
                 log(ignite.log(), "Collecting partitions for cache: " + escapeName(cacheName));
 
@@ -122,9 +124,9 @@ public class VisorCachePartitionsTask extends VisorMultiNodeTask<String,
                     for (GridDhtLocalPartition part : locParts) {
                         int p = part.id();
 
-                        int sz = part.publicSize();
+                        long sz = part.publicSize();
 
-                        // Pass -1 as topology version in order not to wait for topology version.
+                        // Pass NONE as topology version in order not to wait for topology version.
                         if (part.primary(AffinityTopologyVersion.NONE))
                             parts.addPrimary(p, sz);
                         else if (part.state() == GridDhtPartitionState.OWNING && part.backup(AffinityTopologyVersion.NONE))

http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTaskArg.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTaskArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTaskArg.java
new file mode 100644
index 0000000..957f071
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTaskArg.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.visor.cache;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.visor.VisorDataTransferObject;
+
+/**
+ * Arguments for {@link VisorCachePartitionsTask}.
+ */
+public class VisorCachePartitionsTaskArg extends VisorDataTransferObject {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private String cacheName;
+
+    /**
+     * Default constructor.
+     */
+    public VisorCachePartitionsTaskArg() {
+        // No-op.
+    }
+
+    /**
+     * @param cacheName Cache name.
+     */
+    public VisorCachePartitionsTaskArg(String cacheName) {
+        this.cacheName = cacheName;
+    }
+
+    /**
+     * @return Cache name.
+     */
+    public String getCacheName() {
+        return cacheName;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeExternalData(ObjectOutput out) throws IOException {
+        U.writeString(out, cacheName);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
+        cacheName = U.readString(in);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(VisorCachePartitionsTaskArg.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java
index 05112ed..658d6a1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java
@@ -43,6 +43,7 @@ import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.util.lang.GridTuple3;
 import org.apache.ignite.internal.util.typedef.CI1;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.visor.VisorOneNodeTask;
 import org.apache.ignite.internal.visor.VisorTaskArgument;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteFuture;
@@ -59,6 +60,9 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
     /** */
     private static final long serialVersionUID = 0L;
 
+    /** */
+    private static final int JOB_ARG_IDX = 3;
+
     /** Auto-injected grid instance. */
     @IgniteInstanceResource
     protected transient IgniteEx ignite;
@@ -133,24 +137,23 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
         }
 
         /**
-         * Cast argument to target class.
+         * Construct job argument.
          *
          * @param cls Class.
-         * @param idx Argument index.
          */
-        @Nullable private Object toObject(Class cls, int idx) throws ClassNotFoundException {
-            String arg = argument(idx);
+        @Nullable private Object toJobArgument(Class cls) throws ClassNotFoundException {
+            String arg = argument(JOB_ARG_IDX);
 
             if (cls == Collection.class || cls == Set.class) {
                 Class<?> itemsCls = Class.forName(arg);
 
                 Collection<Object> res = cls == Collection.class ? new ArrayList<>() : new HashSet<>();
 
-                String items = argument(idx + 1);
+                String items = argument(JOB_ARG_IDX + 1);
 
                 if (items != null) {
                     for (String item : items.split(";"))
-                        res.add(toSimpleObject(itemsCls, item));
+                        res.add(toObject(itemsCls, item));
                 }
 
                 return res;
@@ -159,20 +162,20 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
             if (cls == IgniteBiTuple.class) {
                 Class<?> keyCls = Class.forName(arg);
 
-                String valClsName = argument(idx + 1);
+                String valClsName = argument(JOB_ARG_IDX + 1);
 
                 assert valClsName != null;
 
                 Class<?> valCls = Class.forName(valClsName);
 
-                return new IgniteBiTuple<>(toSimpleObject(keyCls, (String)argument(idx + 2)),
-                    toSimpleObject(valCls, (String)argument(idx + 3)));
+                return new IgniteBiTuple<>(toObject(keyCls, (String)argument(JOB_ARG_IDX + 2)),
+                    toObject(valCls, (String)argument(JOB_ARG_IDX + 3)));
             }
 
             if (cls == Map.class) {
                 Class<?> keyCls = Class.forName(arg);
 
-                String valClsName = argument(idx + 1);
+                String valClsName = argument(JOB_ARG_IDX + 1);
 
                 assert valClsName != null;
 
@@ -180,7 +183,7 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
 
                 Map<Object, Object> res = new HashMap<>();
 
-                String entries = argument(idx + 2);
+                String entries = argument(JOB_ARG_IDX + 2);
 
                 if (entries != null) {
                     for (String entry : entries.split(";")) {
@@ -189,8 +192,8 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
 
                             assert values.length >= 1;
 
-                            res.put(toSimpleObject(keyCls, values[0]),
-                                values.length > 1 ? toSimpleObject(valCls, values[1]) : null);
+                            res.put(toObject(keyCls, values[0]),
+                                values.length > 1 ? toObject(valCls, values[1]) : null);
                         }
                     }
                 }
@@ -199,8 +202,8 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
             }
 
             if (cls == GridTuple3.class) {
-                String v2ClsName = argument(idx + 1);
-                String v3ClsName = argument(idx + 2);
+                String v2ClsName = argument(JOB_ARG_IDX + 1);
+                String v3ClsName = argument(JOB_ARG_IDX + 2);
 
                 assert v2ClsName != null;
                 assert v3ClsName != null;
@@ -209,20 +212,20 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
                 Class<?> v2Cls = Class.forName(v2ClsName);
                 Class<?> v3Cls = Class.forName(v3ClsName);
 
-                return new GridTuple3<>(toSimpleObject(v1Cls, (String)argument(idx + 3)), toSimpleObject(v2Cls,
-                    (String)argument(idx + 4)), toSimpleObject(v3Cls, (String)argument(idx + 5)));
+                return new GridTuple3<>(toObject(v1Cls, (String)argument(JOB_ARG_IDX + 3)), toObject(v2Cls,
+                    (String)argument(JOB_ARG_IDX + 4)), toObject(v3Cls, (String)argument(JOB_ARG_IDX + 5)));
             }
 
-            return toSimpleObject(cls, arg);
+            return toObject(cls, arg);
         }
 
         /**
-         * Cast from string representation to target class.
+         * Construct from string representation to target class.
          *
          * @param cls Target class.
          * @return Object constructed from string.
          */
-        @Nullable private Object toSimpleObject(Class cls, String val) {
+        @Nullable private Object toObject(Class cls, String val) {
             if (val == null  || "null".equals(val))
                 return null;
 
@@ -297,6 +300,7 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
         }
 
         /** {@inheritDoc} */
+        @SuppressWarnings("unchecked")
         @Override public Object execute() throws IgniteException {
             if (fut != null)
                 return fut.get();
@@ -317,46 +321,63 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
                     if (argCls == Void.class)
                         jobArgs = null;
                     else if (isBuildInObject(argCls))
-                        jobArgs = toObject(argCls, 3);
+                        jobArgs = toJobArgument(argCls);
                     else {
-                        int beanArgsCnt = argsCnt - 3;
+                        int beanArgsCnt = argsCnt - JOB_ARG_IDX;
 
                         for (Constructor ctor : argCls.getDeclaredConstructors()) {
                             Class[] types = ctor.getParameterTypes();
 
                             if (types.length == beanArgsCnt) {
-                                Object[] initargs = new Object[beanArgsCnt];
+                                Object[] initArgs = new Object[beanArgsCnt];
 
                                 for (int i = 0; i < beanArgsCnt; i++) {
-                                    String val = argument(i + 3);
+                                    String val = argument(i + JOB_ARG_IDX);
 
-                                    initargs[i] = toSimpleObject(types[i], val);
+                                    initArgs[i] = toObject(types[i], val);
                                 }
 
-                                jobArgs = ctor.newInstance(initargs);
+                                jobArgs = ctor.newInstance(initArgs);
 
                                 break;
                             }
                         }
 
-                        if (jobArgs == null)
-                            throw new IgniteException("Failed to execute task [task name=" + taskName + "]");
+                        if (jobArgs == null) {
+                            Object[] args = new Object[beanArgsCnt];
+
+                            for (int i = 0; i < beanArgsCnt; i++)
+                                args[i] = argument(i + JOB_ARG_IDX);
+
+                            throw new IgniteException("Failed to find constructor for task argument " +
+                                "[taskName=" + taskName + ", argsCnt=" + args.length +
+                                ", args=" + Arrays.toString(args) + "]");
+                        }
                     }
                 }
                 catch (Exception e) {
-                    throw new IgniteException("Failed to execute task [task name=" + taskName + "]", e);
+                    throw new IgniteException("Failed to construct job argument [taskName=" + taskName + "]", e);
                 }
             }
 
             final List<UUID> nids;
 
-            if (nidsArg == null || "null".equals(nidsArg) || nidsArg.isEmpty()) {
-                Collection<ClusterNode> nodes = ignite.cluster().nodes();
+            if (F.isEmpty(nidsArg) || "null".equals(nidsArg)) {
+                try {
+                    if (VisorOneNodeTask.class.isAssignableFrom(Class.forName(taskName)))
+                        nids = Collections.singletonList(ignite.localNode().id());
+                    else {
+                        Collection<ClusterNode> nodes = ignite.cluster().nodes();
 
-                nids = new ArrayList<>(nodes.size());
+                        nids = new ArrayList<>(nodes.size());
 
-                for (ClusterNode node : nodes)
-                    nids.add(node.id());
+                        for (ClusterNode node : nodes)
+                            nids.add(node.id());
+                    }
+                }
+                catch (ClassNotFoundException e) {
+                    throw new IgniteException("Failed to find task class:" + taskName, e);
+                }
             }
             else {
                 String[] items = nidsArg.split(";");
@@ -367,7 +388,7 @@ public class VisorGatewayTask implements ComputeTask<Object[], Object> {
                     try {
                         nids.add(UUID.fromString(item));
                     } catch (IllegalArgumentException ignore) {
-                        // No-op.
+                        ignite.log().warning("Failed to parse node id [taskName=" + taskName + ", nid=" + item + "]");
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/36e7e198/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 58679ea..6b548c7 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -1686,10 +1686,10 @@ org.apache.ignite.internal.visor.cache.VisorCacheMetricsCollectorTaskArg
 org.apache.ignite.internal.visor.cache.VisorCacheNearConfiguration
 org.apache.ignite.internal.visor.cache.VisorCacheNodesTask
 org.apache.ignite.internal.visor.cache.VisorCacheNodesTask$VisorCacheNodesJob
-org.apache.ignite.internal.visor.cache.VisorCachePartition
 org.apache.ignite.internal.visor.cache.VisorCachePartitions
 org.apache.ignite.internal.visor.cache.VisorCachePartitionsTask
 org.apache.ignite.internal.visor.cache.VisorCachePartitionsTask$VisorCachePartitionsJob
+org.apache.ignite.internal.visor.cache.VisorCachePartitionsTaskArg
 org.apache.ignite.internal.visor.cache.VisorCacheRebalanceConfiguration
 org.apache.ignite.internal.visor.cache.VisorCacheRebalanceTask
 org.apache.ignite.internal.visor.cache.VisorCacheRebalanceTask$VisorCachesRebalanceJob


[34/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
index 7677d0d..119a389 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
@@ -23,7 +23,10 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.A;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -33,6 +36,9 @@ import java.util.Map;
  * Descriptor of type.
  */
 public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
+    /** Space. */
+    private final String space;
+
     /** */
     private String name;
 
@@ -50,9 +56,15 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
     /** Map with upper cased property names to help find properties based on SQL INSERT and MERGE queries. */
     private final Map<String, GridQueryProperty> uppercaseProps = new HashMap<>();
 
+    /** Mutex for operations on indexes. */
+    private final Object idxMux = new Object();
+
     /** */
     @GridToStringInclude
-    private final Map<String, QueryIndexDescriptorImpl> indexes = new HashMap<>();
+    private final Map<String, QueryIndexDescriptorImpl> idxs = new HashMap<>();
+
+    /** Aliases. */
+    private Map<String, String> aliases;
 
     /** */
     private QueryIndexDescriptorImpl fullTextIdx;
@@ -78,6 +90,25 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
     /** */
     private String affKey;
 
+    /** Obsolete. */
+    private volatile boolean obsolete;
+
+    /**
+     * Constructor.
+     *
+     * @param space Cache name.
+     */
+    public QueryTypeDescriptorImpl(String space) {
+        this.space = space;
+    }
+
+    /**
+     * @return Space.
+     */
+    public String space() {
+        return space;
+    }
+
     /** {@inheritDoc} */
     @Override public String name() {
         return name;
@@ -97,7 +128,7 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
      * @return Table name.
      */
     @Override public String tableName() {
-        return tblName;
+        return tblName != null ? tblName : name;
     }
 
     /**
@@ -160,7 +191,9 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
 
     /** {@inheritDoc} */
     @Override public Map<String, GridQueryIndexDescriptor> indexes() {
-        return Collections.<String, GridQueryIndexDescriptor>unmodifiableMap(indexes);
+        synchronized (idxMux) {
+            return Collections.<String, GridQueryIndexDescriptor>unmodifiableMap(idxs);
+        }
     }
 
     /** {@inheritDoc} */
@@ -176,59 +209,74 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
     }
 
     /**
-     * Adds index.
+     * Get index by name.
      *
-     * @param idxName Index name.
-     * @param type Index type.
-     * @param inlineSize Inline size.
-     * @return Index descriptor.
-     * @throws IgniteCheckedException In case of error.
+     * @param name Name.
+     * @return Index.
      */
-    public QueryIndexDescriptorImpl addIndex(String idxName, QueryIndexType type, int inlineSize) throws IgniteCheckedException {
-        QueryIndexDescriptorImpl idx = new QueryIndexDescriptorImpl(type, inlineSize);
+    @Nullable public QueryIndexDescriptorImpl index(String name) {
+        synchronized (idxMux) {
+            return idxs.get(name);
+        }
+    }
 
-        if (indexes.put(idxName, idx) != null)
-            throw new IgniteCheckedException("Index with name '" + idxName + "' already exists.");
+    /**
+     * @return Raw index descriptors.
+     */
+    public Collection<QueryIndexDescriptorImpl> indexes0() {
+        synchronized (idxMux) {
+            return new ArrayList<>(idxs.values());
+        }
+    }
 
-        return idx;
+    /** {@inheritDoc} */
+    @Override public GridQueryIndexDescriptor textIndex() {
+        return fullTextIdx;
     }
 
     /**
-     * Adds field to index.
+     * Add index.
      *
-     * @param idxName Index name.
-     * @param field Field name.
-     * @param orderNum Fields order number in index.
-     * @param inlineSize Inline size.
-     * @param descending Sorting order.
+     * @param idx Index.
      * @throws IgniteCheckedException If failed.
      */
-    public void addFieldToIndex(
-        String idxName,
-        String field,
-        int orderNum,
-        int inlineSize,
-        boolean descending
-    ) throws IgniteCheckedException {
-        QueryIndexDescriptorImpl desc = indexes.get(idxName);
+    public void addIndex(QueryIndexDescriptorImpl idx) throws IgniteCheckedException {
+        synchronized (idxMux) {
+            if (idxs.put(idx.name(), idx) != null)
+                throw new IgniteCheckedException("Index with name '" + idx.name() + "' already exists.");
+        }
+    }
 
-        if (desc == null)
-            desc = addIndex(idxName, QueryIndexType.SORTED, inlineSize);
+    /**
+     * Drop index.
+     *
+     * @param idxName Index name.
+     */
+    public void dropIndex(String idxName) {
+        synchronized (idxMux) {
+            idxs.remove(idxName);
+        }
+    }
 
-        desc.addField(field, orderNum, descending);
+    /**
+     * Chedk if particular field exists.
+     *
+     * @param field Field.
+     * @return {@code True} if exists.
+     */
+    public boolean hasField(String field) {
+        return props.containsKey(field) || QueryUtils._VAL.equalsIgnoreCase(field);
     }
 
     /**
      * Adds field to text index.
      *
      * @param field Field name.
+     * @throws IgniteCheckedException If failed.
      */
-    public void addFieldToTextIndex(String field) {
-        if (fullTextIdx == null) {
-            fullTextIdx = new QueryIndexDescriptorImpl(QueryIndexType.FULLTEXT, 0);
-
-            indexes.put(null, fullTextIdx);
-        }
+    public void addFieldToTextIndex(String field) throws IgniteCheckedException {
+        if (fullTextIdx == null)
+            fullTextIdx = new QueryIndexDescriptorImpl(this, null, QueryIndexType.FULLTEXT, 0);
 
         fullTextIdx.addField(field, 0, false);
     }
@@ -335,6 +383,34 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
         this.affKey = affKey;
     }
 
+    /**
+     * @return Aliases.
+     */
+    public Map<String, String> aliases() {
+        return aliases != null ? aliases : Collections.<String, String>emptyMap();
+    }
+
+    /**
+     * @param aliases Aliases.
+     */
+    public void aliases(Map<String, String> aliases) {
+        this.aliases = aliases;
+    }
+
+    /**
+     * @return {@code True} if obsolete.
+     */
+    public boolean obsolete() {
+        return obsolete;
+    }
+
+    /**
+     * Mark index as obsolete.
+     */
+    public void markObsolete() {
+        obsolete = true;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(QueryTypeDescriptorImpl.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index f00cbd6..3a7437b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@ -29,6 +29,7 @@ import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
 import org.apache.ignite.internal.processors.query.property.QueryBinaryProperty;
 import org.apache.ignite.internal.processors.query.property.QueryClassProperty;
 import org.apache.ignite.internal.processors.query.property.QueryFieldAccessor;
@@ -44,7 +45,6 @@ import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.sql.Time;
 import java.sql.Timestamp;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -52,6 +52,9 @@ import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE;
+import static org.apache.ignite.IgniteSystemProperties.getInteger;
+
 /**
  * Utility methods for queries.
  */
@@ -59,6 +62,9 @@ public class QueryUtils {
     /** */
     public static final String _VAL = "_val";
 
+    /** Discovery history size. */
+    private static final int DISCO_HIST_SIZE = getInteger(IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE, 1000);
+
     /** */
     private static final Class<?> GEOMETRY_CLASS = U.classForName("com.vividsolutions.jts.geom.Geometry", null);
 
@@ -82,6 +88,69 @@ public class QueryUtils {
     ));
 
     /**
+     * Get table name for entity.
+     *
+     * @param entity Entity.
+     * @return Table name.
+     */
+    public static String tableName(QueryEntity entity) {
+        String res = entity.getTableName();
+
+        if (res == null)
+            res = typeName(entity.getValueType());
+
+        return res;
+    }
+
+    /**
+     * Get index name.
+     *
+     * @param entity Query entity.
+     * @param idx Index.
+     * @return Index name.
+     */
+    public static String indexName(QueryEntity entity, QueryIndex idx) {
+        return indexName(tableName(entity), idx);
+    }
+
+    /**
+     * Get index name.
+     *
+     * @param tblName Table name.
+     * @param idx Index.
+     * @return Index name.
+     */
+    public static String indexName(String tblName, QueryIndex idx) {
+        String res = idx.getName();
+
+        if (res == null) {
+            StringBuilder idxName = new StringBuilder(tblName + "_");
+
+            for (Map.Entry<String, Boolean> field : idx.getFields().entrySet()) {
+                idxName.append(field.getKey());
+
+                idxName.append('_');
+                idxName.append(field.getValue() ? "asc_" : "desc_");
+            }
+
+            for (int i = 0; i < idxName.length(); i++) {
+                char ch = idxName.charAt(i);
+
+                if (Character.isWhitespace(ch))
+                    idxName.setCharAt(i, '_');
+                else
+                    idxName.setCharAt(i, Character.toLowerCase(ch));
+            }
+
+            idxName.append("idx");
+
+            return idxName.toString();
+        }
+
+        return res;
+    }
+
+    /**
      * Create type candidate for query entity.
      *
      * @param space Space.
@@ -103,7 +172,9 @@ public class QueryUtils {
 
         CacheObjectContext coCtx = binaryEnabled ? ctx.cacheObjects().contextForCache(ccfg) : null;
 
-        QueryTypeDescriptorImpl desc = new QueryTypeDescriptorImpl();
+        QueryTypeDescriptorImpl desc = new QueryTypeDescriptorImpl(space);
+
+        desc.aliases(qryEntity.getAliases());
 
         // Key and value classes still can be available if they are primitive or JDK part.
         // We need that to set correct types for _key and _val columns.
@@ -206,11 +277,6 @@ public class QueryUtils {
      */
     public static void processBinaryMeta(GridKernalContext ctx, QueryEntity qryEntity, QueryTypeDescriptorImpl d)
         throws IgniteCheckedException {
-        Map<String,String> aliases = qryEntity.getAliases();
-
-        if (aliases == null)
-            aliases = Collections.emptyMap();
-
         Set<String> keyFields = qryEntity.getKeyFields();
 
         // We have to distinguish between empty and null keyFields when the key is not of SQL type -
@@ -239,7 +305,7 @@ public class QueryUtils {
                 isKeyField = (hasKeyFields ? keyFields.contains(entry.getKey()) : null);
 
             QueryBinaryProperty prop = buildBinaryProperty(ctx, entry.getKey(),
-                U.classForName(entry.getValue(), Object.class, true), aliases, isKeyField);
+                U.classForName(entry.getValue(), Object.class, true), d.aliases(), isKeyField);
 
             d.addProperty(prop, false);
         }
@@ -256,18 +322,13 @@ public class QueryUtils {
      */
     public static void processClassMeta(QueryEntity qryEntity, QueryTypeDescriptorImpl d, CacheObjectContext coCtx)
         throws IgniteCheckedException {
-        Map<String,String> aliases = qryEntity.getAliases();
-
-        if (aliases == null)
-            aliases = Collections.emptyMap();
-
         for (Map.Entry<String, String> entry : qryEntity.getFields().entrySet()) {
             QueryClassProperty prop = buildClassProperty(
                 d.keyClass(),
                 d.valueClass(),
                 entry.getKey(),
                 U.classForName(entry.getValue(), Object.class),
-                aliases,
+                d.aliases(),
                 coCtx);
 
             d.addProperty(prop, false);
@@ -275,7 +336,7 @@ public class QueryUtils {
 
         processIndexes(qryEntity, d);
     }
-    
+
     /**
      * Processes indexes based on query entity.
      *
@@ -285,53 +346,90 @@ public class QueryUtils {
      */
     private static void processIndexes(QueryEntity qryEntity, QueryTypeDescriptorImpl d) throws IgniteCheckedException {
         if (!F.isEmpty(qryEntity.getIndexes())) {
-            Map<String, String> aliases = qryEntity.getAliases();
+            for (QueryIndex idx : qryEntity.getIndexes())
+                processIndex(idx, d);
+        }
+    }
 
-            if (aliases == null)
-                aliases = Collections.emptyMap();
+    /**
+     * Process dynamic index change.
+     *
+     * @param idx Index.
+     * @param d Type descriptor to populate.
+     * @throws IgniteCheckedException If failed to build index information.
+     */
+    public static void processDynamicIndexChange(String idxName, @Nullable QueryIndex idx, QueryTypeDescriptorImpl d)
+        throws IgniteCheckedException {
+        d.dropIndex(idxName);
 
-            for (QueryIndex idx : qryEntity.getIndexes()) {
-                String idxName = idx.getName();
+        if (idx != null)
+            processIndex(idx, d);
+    }
 
-                if (idxName == null)
-                    idxName = QueryEntity.defaultIndexName(idx);
+    /**
+     * Create index descriptor.
+     *
+     * @param typeDesc Type descriptor.
+     * @param idx Index.
+     * @return Index descriptor.
+     * @throws IgniteCheckedException If failed.
+     */
+    public static QueryIndexDescriptorImpl createIndexDescriptor(QueryTypeDescriptorImpl typeDesc, QueryIndex idx)
+        throws IgniteCheckedException {
+        String idxName = indexName(typeDesc.tableName(), idx);
+        QueryIndexType idxTyp = idx.getIndexType();
 
-                QueryIndexType idxTyp = idx.getIndexType();
+        assert idxTyp == QueryIndexType.SORTED || idxTyp == QueryIndexType.GEOSPATIAL;
 
-                if (idxTyp == QueryIndexType.SORTED || idxTyp == QueryIndexType.GEOSPATIAL) {
-                    d.addIndex(idxName, idxTyp, idx.getInlineSize());
+        QueryIndexDescriptorImpl res = new QueryIndexDescriptorImpl(typeDesc, idxName, idxTyp, idx.getInlineSize());
 
-                    int i = 0;
+        int i = 0;
 
-                    for (Map.Entry<String, Boolean> entry : idx.getFields().entrySet()) {
-                        String field = entry.getKey();
-                        boolean asc = entry.getValue();
+        for (Map.Entry<String, Boolean> entry : idx.getFields().entrySet()) {
+            String field = entry.getKey();
+            boolean asc = entry.getValue();
 
-                        String alias = aliases.get(field);
+            String alias = typeDesc.aliases().get(field);
 
-                        if (alias != null)
-                            field = alias;
+            if (alias != null)
+                field = alias;
 
-                        d.addFieldToIndex(idxName, field, i++, idx.getInlineSize(), !asc);
-                    }
-                }
-                else if (idxTyp == QueryIndexType.FULLTEXT){
-                    for (String field : idx.getFields().keySet()) {
-                        String alias = aliases.get(field);
+            res.addField(field, i++, !asc);
+        }
 
-                        if (alias != null)
-                            field = alias;
+        return res;
+    }
 
-                        d.addFieldToTextIndex(field);
-                    }
-                }
-                else if (idxTyp != null)
-                    throw new IllegalArgumentException("Unsupported index type [idx=" + idx.getName() +
-                        ", typ=" + idxTyp + ']');
-                else
-                    throw new IllegalArgumentException("Index type is not set: " + idx.getName());
+    /**
+     * Process single index.
+     *
+     * @param idx Index.
+     * @param d Type descriptor to populate.
+     * @throws IgniteCheckedException If failed to build index information.
+     */
+    private static void processIndex(QueryIndex idx, QueryTypeDescriptorImpl d) throws IgniteCheckedException {
+        QueryIndexType idxTyp = idx.getIndexType();
+
+        if (idxTyp == QueryIndexType.SORTED || idxTyp == QueryIndexType.GEOSPATIAL) {
+            QueryIndexDescriptorImpl idxDesc = createIndexDescriptor(d, idx);
+
+            d.addIndex(idxDesc);
+        }
+        else if (idxTyp == QueryIndexType.FULLTEXT){
+            for (String field : idx.getFields().keySet()) {
+                String alias = d.aliases().get(field);
+
+                if (alias != null)
+                    field = alias;
+
+                d.addFieldToTextIndex(field);
             }
         }
+        else if (idxTyp != null)
+            throw new IllegalArgumentException("Unsupported index type [idx=" + idx.getName() +
+                ", typ=" + idxTyp + ']');
+        else
+            throw new IllegalArgumentException("Index type is not set: " + idx.getName());
     }
     
     /**
@@ -674,6 +772,31 @@ public class QueryUtils {
     }
 
     /**
+     * Discovery history size.
+     *
+     * @return Discovery history size.
+     */
+    public static int discoveryHistorySize() {
+        return DISCO_HIST_SIZE;
+    }
+
+    /**
+     * Wrap schema exception if needed.
+     *
+     * @param e Original exception.
+     * @return Schema exception.
+     */
+    @Nullable public static SchemaOperationException wrapIfNeeded(@Nullable Exception e) {
+        if (e == null)
+            return null;
+
+        if (e instanceof SchemaOperationException)
+            return (SchemaOperationException)e;
+
+        return new SchemaOperationException("Unexpected exception.", e);
+    }
+
+    /**
      * Private constructor.
      */
     private QueryUtils() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
new file mode 100644
index 0000000..f97f931
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Cache schema change task for exchange worker.
+ */
+public class SchemaExchangeWorkerTask implements CachePartitionExchangeWorkerTask {
+    /** Message. */
+    private final SchemaAbstractDiscoveryMessage msg;
+
+    /**
+     * Constructor.
+     *
+     * @param msg Message.
+     */
+    public SchemaExchangeWorkerTask(SchemaAbstractDiscoveryMessage msg) {
+        assert msg != null;
+
+        this.msg = msg;
+    }
+
+    /**
+     * @return Message.
+     */
+    public SchemaAbstractDiscoveryMessage message() {
+        return msg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaExchangeWorkerTask.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitor.java
new file mode 100644
index 0000000..3321e66
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitor.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Closure that internally applies given {@link SchemaIndexCacheVisitorClosure} to some set of entries.
+ */
+public interface SchemaIndexCacheVisitor {
+    /**
+     * Visit cache entries and pass them to closure.
+     *
+     * @param clo Closure.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void visit(SchemaIndexCacheVisitorClosure clo) throws IgniteCheckedException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorClosure.java
new file mode 100644
index 0000000..7f50089
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorClosure.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+
+/**
+ * Index closure accepting current entry state.
+ */
+public interface SchemaIndexCacheVisitorClosure {
+    /**
+     * Apply closure.
+     *
+     * @param key Key.
+     * @param part Partition.
+     * @param val Value.
+     * @param ver Version.
+     * @param expiration Expiration.
+     * @param link Link.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void apply(KeyCacheObject key, int part, CacheObject val, GridCacheVersion ver, long expiration, long link)
+        throws IgniteCheckedException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java
new file mode 100644
index 0000000..58c909d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.util.lang.GridCursor;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.Collection;
+
+import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED;
+import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING;
+import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.RENTING;
+
+/**
+ * Traversor operating all primary and backup partitions of given cache.
+ */
+public class SchemaIndexCacheVisitorImpl implements SchemaIndexCacheVisitor {
+    /** Query procssor. */
+    private final GridQueryProcessor qryProc;
+
+    /** Cache context. */
+    private final GridCacheContext cctx;
+
+    /** Space name. */
+    private final String spaceName;
+
+    /** Table name. */
+    private final String tblName;
+
+    /** Cancellation token. */
+    private final SchemaIndexOperationCancellationToken cancel;
+
+    /**
+     * Constructor.
+     *
+     * @param cctx Cache context.
+     * @param spaceName Space name.
+     * @param tblName Table name.
+     * @param cancel Cancellation token.
+     */
+    public SchemaIndexCacheVisitorImpl(GridQueryProcessor qryProc, GridCacheContext cctx, String spaceName,
+        String tblName, SchemaIndexOperationCancellationToken cancel) {
+        this.qryProc = qryProc;
+        this.spaceName = spaceName;
+        this.tblName = tblName;
+        this.cancel = cancel;
+
+        if (cctx.isNear())
+            cctx = ((GridNearCacheAdapter)cctx.cache()).dht().context();
+
+        this.cctx = cctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void visit(SchemaIndexCacheVisitorClosure clo) throws IgniteCheckedException {
+        assert clo != null;
+
+        FilteringVisitorClosure filterClo = new FilteringVisitorClosure(clo);
+
+        Collection<GridDhtLocalPartition> parts = cctx.topology().localPartitions();
+
+        for (GridDhtLocalPartition part : parts)
+            processPartition(part, filterClo);
+    }
+
+    /**
+     * Process partition.
+     *
+     * @param part Partition.
+     * @param clo Index closure.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void processPartition(GridDhtLocalPartition part, FilteringVisitorClosure clo)
+        throws IgniteCheckedException {
+        checkCancelled();
+
+        boolean reserved = false;
+
+        if (part != null && part.state() != EVICTED)
+            reserved = (part.state() == OWNING || part.state() == RENTING) && part.reserve();
+
+        if (!reserved)
+            return;
+
+        try {
+            GridCursor<? extends CacheDataRow> cursor = part.dataStore().cursor();
+
+            while (cursor.next()) {
+                CacheDataRow row = cursor.get();
+
+                KeyCacheObject key = row.key();
+
+                processKey(key, row.link(), clo);
+            }
+        }
+        finally {
+            part.release();
+        }
+    }
+
+    /**
+     * Process single key.
+     *
+     * @param key Key.
+     * @param link Link.
+     * @param clo Closure.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void processKey(KeyCacheObject key, long link, FilteringVisitorClosure clo) throws IgniteCheckedException {
+        while (true) {
+            try {
+                checkCancelled();
+
+                GridCacheEntryEx entry = cctx.cache().entryEx(key);
+
+                try {
+                    entry.updateIndex(clo, link);
+                }
+                finally {
+                    cctx.evicts().touch(entry, AffinityTopologyVersion.NONE);
+                }
+
+                break;
+            }
+            catch (GridCacheEntryRemovedException ignored) {
+                // No-op.
+            }
+        }
+    }
+
+    /**
+     * Check if visit process is not cancelled.
+     *
+     * @throws IgniteCheckedException If cancelled.
+     */
+    private void checkCancelled() throws IgniteCheckedException {
+        if (cancel.isCancelled())
+            throw new IgniteCheckedException("Index creation was cancelled.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaIndexCacheVisitorImpl.class, this);
+    }
+
+    /**
+     * Filtering visitor closure.
+     */
+    private class FilteringVisitorClosure implements SchemaIndexCacheVisitorClosure {
+
+        /** Target closure. */
+        private final SchemaIndexCacheVisitorClosure target;
+
+        /**
+         * Constructor.
+         *
+         * @param target Target.
+         */
+        public FilteringVisitorClosure(SchemaIndexCacheVisitorClosure target) {
+            this.target = target;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void apply(KeyCacheObject key, int part, CacheObject val, GridCacheVersion ver,
+            long expiration, long link) throws IgniteCheckedException {
+            if (qryProc.belongsToTable(cctx, spaceName, tblName, key, val))
+                target.apply(key, part, val, ver, expiration, link);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexOperationCancellationToken.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexOperationCancellationToken.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexOperationCancellationToken.java
new file mode 100644
index 0000000..1bc3434
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexOperationCancellationToken.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Index operation cancellation token.
+ */
+public class SchemaIndexOperationCancellationToken {
+    /** Cancel flag. */
+    private final AtomicBoolean flag = new AtomicBoolean();
+
+    /**
+     * Get cancel state.
+     *
+     * @return {@code True} if cancelled.
+     */
+    public boolean isCancelled() {
+        return flag.get();
+    }
+
+    /**
+     * Do cancel.
+     *
+     * @return {@code True} if cancel flag was set by this call.
+     */
+    public boolean cancel() {
+        return flag.compareAndSet(false, true);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaIndexOperationCancellationToken.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaKey.java
new file mode 100644
index 0000000..3f12b77
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaKey.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Schema key.
+ */
+public class SchemaKey {
+    /** Space. */
+    private final String space;
+
+    /** Deployment ID. */
+    private final IgniteUuid depId;
+
+    /**
+     * Constructor.
+     *
+     * @param space Space.
+     * @param depId Deployment ID.
+     */
+    public SchemaKey(String space, IgniteUuid depId) {
+        this.space = space;
+        this.depId = depId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return 31 * (space != null ? space.hashCode() : 0) + depId.hashCode();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (obj instanceof SchemaKey) {
+            SchemaKey other = (SchemaKey)obj;
+
+            return F.eq(space, other.space) && F.eq(depId, other.depId);
+        }
+
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
new file mode 100644
index 0000000..79fbfcd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Node leave exchange worker task.
+ */
+public class SchemaNodeLeaveExchangeWorkerTask implements CachePartitionExchangeWorkerTask {
+    /** Node. */
+    @GridToStringInclude
+    private final ClusterNode node;
+
+    /**
+     * Constructor.
+     *
+     * @param node Node.
+     */
+    public SchemaNodeLeaveExchangeWorkerTask(ClusterNode node) {
+        this.node = node;
+    }
+
+    /**
+     * @return Node.
+     */
+    public ClusterNode node() {
+        return node;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaNodeLeaveExchangeWorkerTask.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationClientFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationClientFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationClientFuture.java
new file mode 100644
index 0000000..6c47aff
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationClientFuture.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.UUID;
+
+/**
+ * Schema operation client future.
+ */
+public class SchemaOperationClientFuture extends GridFutureAdapter<Object> {
+    /** Operation ID. */
+    private final UUID opId;
+
+    /**
+     * Constructor.
+     *
+     * @param opId Operation ID.
+     */
+    public SchemaOperationClientFuture(UUID opId) {
+        this.opId = opId;
+    }
+
+    /**
+     * @return Operation ID.
+     */
+    public UUID operationId() {
+        return opId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaOperationClientFuture.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationException.java
new file mode 100644
index 0000000..f0db026
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationException.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Schema operation exception.
+ */
+public class SchemaOperationException extends IgniteCheckedException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Code: generic error. */
+    public static final int CODE_GENERIC = 0;
+
+    /** Code: cache not found. */
+    public static final int CODE_CACHE_NOT_FOUND = 1;
+
+    /** Code: table not found. */
+    public static final int CODE_TABLE_NOT_FOUND = 2;
+
+    /** Code: table already exists. */
+    public static final int CODE_TABLE_EXISTS = 3;
+
+    /** Code: column not found. */
+    public static final int CODE_COLUMN_NOT_FOUND = 4;
+
+    /** Code: column already exists. */
+    public static final int CODE_COLUMN_EXISTS = 5;
+
+    /** Code: index not found. */
+    public static final int CODE_INDEX_NOT_FOUND = 6;
+
+    /** Code: index already exists. */
+    public static final int CODE_INDEX_EXISTS = 7;
+
+    /** Error code. */
+    private final int code;
+
+    /**
+     * Constructor for specific error type.
+     *
+     * @param code Code.
+     * @param objName Object name.
+     */
+    public SchemaOperationException(int code, String objName) {
+        super(message(code, objName));
+
+        this.code = code;
+    }
+
+    /**
+     * Constructor for generic error.
+     *
+     * @param msg Message.
+     */
+    public SchemaOperationException(String msg) {
+        this(msg, null);
+    }
+
+    /**
+     * Constructor for generic error.
+     *
+     * @param msg Message.
+     * @param cause Cause.
+     */
+    public SchemaOperationException(String msg, Throwable cause) {
+        super(msg, cause);
+
+        code = CODE_GENERIC;
+    }
+
+    /**
+     * @return Code.
+     */
+    public int code() {
+        return code;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaOperationException.class, this, "msg", getMessage());
+    }
+
+    /**
+     * Create message for specific code and object name.
+     *
+     * @param code Code.
+     * @param objName Object name.
+     * @return Message.
+     */
+    private static String message(int code, String objName) {
+        switch (code) {
+            case CODE_CACHE_NOT_FOUND:
+                return "Cache doesn't exist: " + objName;
+
+            case CODE_TABLE_NOT_FOUND:
+                return "Table doesn't exist: " + objName;
+
+            case CODE_TABLE_EXISTS:
+                return "Table already exists: " + objName;
+
+            case CODE_COLUMN_NOT_FOUND:
+                return "Column doesn't exist: " + objName;
+
+            case CODE_COLUMN_EXISTS:
+                return "Column already exists: " + objName;
+
+            case CODE_INDEX_NOT_FOUND:
+                return "Index doesn't exist: " + objName;
+
+            case CODE_INDEX_EXISTS:
+                return "Index already exists: " + objName;
+
+            default:
+                assert false;
+
+                return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationManager.java
new file mode 100644
index 0000000..eb0f3cd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationManager.java
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteInClosure;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Schema operation manager.
+ */
+@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+public class SchemaOperationManager {
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /** Query processor. */
+    private final GridQueryProcessor qryProc;
+
+    /** Logger. */
+    private final IgniteLogger log;
+
+    /** Operation handler. */
+    private final SchemaOperationWorker worker;
+
+    /** Mutex for concurrency control. */
+    private final Object mux = new Object();
+
+    /** Participants. */
+    private Collection<UUID> nodeIds;
+
+    /** Node results. */
+    private Map<UUID, SchemaOperationException> nodeRess;
+
+    /** Current coordinator node. */
+    private ClusterNode crd;
+
+    /** Whether coordinator state is mapped. */
+    private boolean crdMapped;
+
+    /** Coordinator finished flag. */
+    private boolean crdFinished;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param qryProc Query processor.
+     * @param worker Operation handler.
+     * @param crd Coordinator node.
+     */
+    public SchemaOperationManager(GridKernalContext ctx, GridQueryProcessor qryProc, SchemaOperationWorker worker,
+        @Nullable ClusterNode crd) {
+        assert !ctx.clientNode() || crd == null;
+
+        this.ctx = ctx;
+
+        log = ctx.log(SchemaOperationManager.class);
+
+        this.qryProc = qryProc;
+        this.worker = worker;
+
+        synchronized (mux) {
+            this.crd = crd;
+
+            prepareCoordinator();
+        }
+    }
+
+    /**
+     * Map operation handling.
+     */
+    @SuppressWarnings("unchecked")
+    public void start() {
+        worker.start();
+
+        synchronized (mux) {
+            worker.future().listen(new IgniteInClosure<IgniteInternalFuture>() {
+                @Override public void apply(IgniteInternalFuture fut) {
+                    onLocalNodeFinished(fut);
+                }
+            });
+        }
+    }
+
+    /**
+     * Handle local node finish.
+     *
+     * @param fut Future.
+     */
+    private void onLocalNodeFinished(IgniteInternalFuture fut) {
+        assert fut.isDone();
+
+        if (ctx.clientNode())
+            return;
+
+        SchemaOperationException err;
+
+        try {
+            fut.get();
+
+            err = null;
+        }
+        catch (Exception e) {
+            err = QueryUtils.wrapIfNeeded(e);
+        }
+
+        synchronized (mux) {
+            if (isLocalCoordinator())
+                onNodeFinished(ctx.localNodeId(), err);
+            else
+                qryProc.sendStatusMessage(crd.id(), operationId(), err);
+        }
+    }
+
+    /**
+     * Handle node finish.
+     *
+     * @param nodeId Node ID.
+     * @param err Error.
+     */
+    public void onNodeFinished(UUID nodeId, @Nullable SchemaOperationException err) {
+        synchronized (mux) {
+            assert isLocalCoordinator();
+
+            if (nodeRess.containsKey(nodeId)) {
+                if (log.isDebugEnabled())
+                    log.debug("Received duplicate result [opId=" + operationId() + ", nodeId=" + nodeId +
+                        ", err=" + err + ']');
+
+                return;
+            }
+
+            if (nodeIds.contains(nodeId)) {
+                if (log.isDebugEnabled())
+                    log.debug("Received result [opId=" + operationId() + ", nodeId=" + nodeId + ", err=" + err + ']');
+
+                nodeRess.put(nodeId, err);
+            }
+            else {
+                if (log.isDebugEnabled())
+                    log.debug("Received result from non-tracked node (joined after operation started, will ignore) " +
+                        "[opId=" + operationId() + ", nodeId=" + nodeId + ", err=" + err + ']');
+            }
+
+            checkFinished();
+        }
+    }
+
+    /**
+     * Handle node leave event.
+     *
+     * @param nodeId ID of the node that has left the grid.
+     * @param curCrd Current coordinator node.
+     */
+    public void onNodeLeave(UUID nodeId, ClusterNode curCrd) {
+        synchronized (mux) {
+            assert crd != null;
+
+            if (F.eq(nodeId, crd.id())) {
+                // Coordinator has left!
+                crd = curCrd;
+
+                prepareCoordinator();
+            }
+            else if (isLocalCoordinator()) {
+                // Other node has left, remove it from the coordinator's wait set.
+                // Handle this as success.
+                if (nodeIds.remove(nodeId))
+                    nodeRess.remove(nodeId);
+            }
+
+            IgniteInternalFuture fut = worker().future();
+
+            if (fut.isDone())
+                onLocalNodeFinished(fut);
+
+            checkFinished();
+        }
+    }
+
+    /**
+     * Check if operation finished.
+     */
+    private void checkFinished() {
+        assert Thread.holdsLock(mux);
+
+        if (isLocalCoordinator()) {
+            if (crdFinished)
+                return;
+
+            if (nodeIds.size() == nodeRess.size()) {
+                // Initiate finish request.
+                SchemaOperationException err = null;
+
+                for (Map.Entry<UUID, SchemaOperationException> nodeRes : nodeRess.entrySet()) {
+                    if (nodeRes.getValue() != null) {
+                        err = nodeRes.getValue();
+
+                        break;
+                    }
+                }
+
+                if (log.isDebugEnabled())
+                    log.debug("Collected all results, about to send finish message [opId=" + operationId() +
+                        ", err=" + err + ']');
+
+                crdFinished = true;
+
+                qryProc.onCoordinatorFinished(worker.operation(), err);
+            }
+        }
+    }
+
+    /**
+     * Prepare topology state in case local node is coordinator.
+     *
+     * @return {@code True} if state was changed by this call.
+     */
+    private boolean prepareCoordinator() {
+        if (isLocalCoordinator() && !crdMapped) {
+            // Initialize local structures.
+            nodeIds = new HashSet<>();
+            nodeRess = new HashMap<>();
+
+            for (ClusterNode alive : ctx.discovery().aliveServerNodes())
+                nodeIds.add(alive.id());
+
+            if (log.isDebugEnabled())
+                log.debug("Mapped participating nodes on coordinator [opId=" + operationId() +
+                    ", crdNodeId=" + ctx.localNodeId() + ", nodes=" + nodeIds + ']');
+
+            crdMapped = true;
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Check if current node is local coordinator.
+     *
+     * @return {@code True} if coordinator.
+     */
+    private boolean isLocalCoordinator() {
+        assert Thread.holdsLock(mux);
+
+        return crd != null && crd.isLocal();
+    }
+
+    /**
+     * @return Worker.
+     */
+    public SchemaOperationWorker worker() {
+        return worker;
+    }
+
+    /**
+     * @return Operation ID.
+     */
+    private UUID operationId() {
+        return worker.operation().id();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationWorker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationWorker.java
new file mode 100644
index 0000000..06feecb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaOperationWorker.java
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.thread.IgniteThread;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Schema operation executor.
+ */
+public class SchemaOperationWorker extends GridWorker {
+    /** Query processor */
+    private final GridQueryProcessor qryProc;
+
+    /** Deployment ID. */
+    private final IgniteUuid depId;
+
+    /** Target operation. */
+    private final SchemaAbstractOperation op;
+
+    /** No-op flag. */
+    private final boolean nop;
+
+    /** Whether cache started. */
+    private final boolean cacheRegistered;
+
+    /** Type descriptor. */
+    private final QueryTypeDescriptorImpl type;
+
+    /** Operation future. */
+    private final GridFutureAdapter fut;
+
+    /** Public operation future. */
+    private final GridFutureAdapter pubFut;
+
+    /** Start guard. */
+    private final AtomicBoolean startGuard = new AtomicBoolean();
+
+    /** Cancellation token. */
+    private final SchemaIndexOperationCancellationToken cancelToken = new SchemaIndexOperationCancellationToken();
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param qryProc Query processor.
+     * @param depId Deployment ID.
+     * @param op Target operation.
+     * @param nop No-op flag.
+     * @param err Predefined error.
+     * @param cacheRegistered Whether cache is registered in indexing at this point.
+     * @param type Type descriptor (if available).
+     */
+    public SchemaOperationWorker(GridKernalContext ctx, GridQueryProcessor qryProc, IgniteUuid depId,
+        SchemaAbstractOperation op, boolean nop, @Nullable SchemaOperationException err, boolean cacheRegistered,
+        @Nullable QueryTypeDescriptorImpl type) {
+        super(ctx.igniteInstanceName(), workerName(op), ctx.log(SchemaOperationWorker.class));
+
+        this.qryProc = qryProc;
+        this.depId = depId;
+        this.op = op;
+        this.nop = nop;
+        this.cacheRegistered = cacheRegistered;
+        this.type = type;
+
+        fut = new GridFutureAdapter();
+
+        if (err != null)
+            fut.onDone(err);
+        else if (nop || !cacheRegistered)
+            fut.onDone();
+
+        pubFut = publicFuture(fut);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void body() throws InterruptedException, IgniteInterruptedCheckedException {
+        try {
+            // Execute.
+            qryProc.processIndexOperationLocal(op, type, depId, cancelToken);
+
+            fut.onDone();
+        }
+        catch (Exception e) {
+            fut.onDone(QueryUtils.wrapIfNeeded(e));
+        }
+    }
+
+    /**
+     * Perform initialization routine.
+     *
+     * @return This instance.
+     */
+    public SchemaOperationWorker start() {
+        if (startGuard.compareAndSet(false, true)) {
+            if (!fut.isDone())
+                new IgniteThread(this).start();
+        }
+
+        return this;
+    }
+
+    /**
+     * Chain the future making sure that operation is completed after local schema is updated.
+     *
+     * @param fut Current future.
+     * @return Chained future.
+     */
+    @SuppressWarnings("unchecked")
+    private GridFutureAdapter<?> publicFuture(GridFutureAdapter fut) {
+        final GridFutureAdapter<?> chainedFut = new GridFutureAdapter<>();
+
+        fut.listen(new IgniteInClosure<IgniteInternalFuture>() {
+            @Override public void apply(IgniteInternalFuture fut) {
+                Exception err = null;
+
+                try {
+                    fut.get();
+
+                    if (cacheRegistered && !nop)
+                        qryProc.onLocalOperationFinished(op, type);
+                }
+                catch (Exception e) {
+                    err = e;
+                }
+                finally {
+                    chainedFut.onDone(null, err);
+                }
+            }
+        });
+
+        return chainedFut;
+    }
+
+    /**
+     * @return No-op flag.
+     */
+    public boolean nop() {
+        return nop;
+    }
+
+    /**
+     * @return Whether cache is registered.
+     */
+    public boolean cacheRegistered() {
+        return cacheRegistered;
+    }
+
+    /**
+     * Cancel operation.
+     */
+    public void cancel() {
+        if (cancelToken.cancel())
+            super.cancel();
+    }
+
+    /**
+     * @return Operation.
+     */
+    public SchemaAbstractOperation operation() {
+        return op;
+    }
+
+    /**
+     * @return Future completed when operation is ready.
+     */
+    public IgniteInternalFuture future() {
+        return pubFut;
+    }
+
+    /**
+     * @return Worker name.
+     */
+    private static String workerName(SchemaAbstractOperation op) {
+        return "schema-op-worker-" + op.id();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaAbstractDiscoveryMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaAbstractDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaAbstractDiscoveryMessage.java
new file mode 100644
index 0000000..9fdc6c3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaAbstractDiscoveryMessage.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.message;
+
+import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Abstract discovery message for schema operations.
+ */
+public abstract class SchemaAbstractDiscoveryMessage implements DiscoveryCustomMessage {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** ID */
+    private final IgniteUuid id = IgniteUuid.randomUuid();
+
+    /** Operation. */
+    @GridToStringInclude
+    protected final SchemaAbstractOperation op;
+
+    /**
+     * Constructor.
+     *
+     * @param op Operation.
+     */
+    protected SchemaAbstractDiscoveryMessage(SchemaAbstractOperation op) {
+        this.op = op;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid id() {
+        return id;
+    }
+
+    /**
+     * @return Operation.
+     */
+    public SchemaAbstractOperation operation() {
+        return op;
+    }
+
+    /**
+     * @return Whether request must be propagated to exchange thread.
+     */
+    public abstract boolean exchange();
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaAbstractDiscoveryMessage.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaFinishDiscoveryMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaFinishDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaFinishDiscoveryMessage.java
new file mode 100644
index 0000000..2245b24
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaFinishDiscoveryMessage.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.message;
+
+import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Schema change finish discovery message.
+ */
+public class SchemaFinishDiscoveryMessage extends SchemaAbstractDiscoveryMessage {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Error. */
+    private final SchemaOperationException err;
+
+    /** Original propose message. */
+    private transient SchemaProposeDiscoveryMessage proposeMsg;
+
+    /**
+     * Constructor.
+     *
+     * @param op Original operation.
+     * @param err Error.
+     */
+    public SchemaFinishDiscoveryMessage(SchemaAbstractOperation op, SchemaOperationException err) {
+        super(op);
+
+        this.err = err;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public DiscoveryCustomMessage ackMessage() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isMutable() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean exchange() {
+        return false;
+    }
+
+    /**
+     * @return {@code True} if error was reported during init.
+     */
+    public boolean hasError() {
+        return err != null;
+    }
+
+    /**
+     * @return Error message (if any).
+     */
+    @Nullable public SchemaOperationException error() {
+        return err;
+    }
+
+    /**
+     * @return Propose message.
+     */
+    public SchemaProposeDiscoveryMessage proposeMessage() {
+        return proposeMsg;
+    }
+
+    /**
+     * @param proposeMsg Propose message.
+     */
+    public void proposeMessage(SchemaProposeDiscoveryMessage proposeMsg) {
+        this.proposeMsg = proposeMsg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaFinishDiscoveryMessage.class, this, "parent", super.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaOperationStatusMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaOperationStatusMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaOperationStatusMessage.java
new file mode 100644
index 0000000..5f75e60
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaOperationStatusMessage.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.message;
+
+import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.jetbrains.annotations.Nullable;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+/**
+ * Schema operation status message.
+ */
+public class SchemaOperationStatusMessage implements Message {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Operation ID. */
+    private UUID opId;
+
+    /** Error bytes (if any). */
+    private byte[] errBytes;
+
+    /** Sender node ID. */
+    @GridDirectTransient
+    private UUID sndNodeId;
+
+    /**
+     * Default constructor.
+     */
+    public SchemaOperationStatusMessage() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param opId Operation ID.
+     * @param errBytes Error bytes.
+     */
+    public SchemaOperationStatusMessage(UUID opId, byte[] errBytes) {
+        this.opId = opId;
+        this.errBytes = errBytes;
+    }
+
+    /**
+     * @return Operation ID.
+     */
+    public UUID operationId() {
+        return opId;
+    }
+
+    /**
+     * @return Error bytes.
+     */
+    @Nullable public byte[] errorBytes() {
+        return errBytes;
+    }
+
+    /**
+     * @return Sender node ID.
+     */
+    public UUID senderNodeId() {
+        return sndNodeId;
+    }
+
+    /**
+     * @param sndNodeId Sender node ID.
+     */
+    public void senderNodeId(UUID sndNodeId) {
+        this.sndNodeId = sndNodeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeUuid("opId", opId))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeByteArray("errBytes", errBytes))
+                    return false;
+
+                writer.incrementState();
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                opId = reader.readUuid("opId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                errBytes = reader.readByteArray("errBytes");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+        }
+
+        return reader.afterMessageRead(SchemaOperationStatusMessage.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public short directType() {
+        return -53;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onAckReceived() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaOperationStatusMessage.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaProposeDiscoveryMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaProposeDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaProposeDiscoveryMessage.java
new file mode 100644
index 0000000..664ee03
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/message/SchemaProposeDiscoveryMessage.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.message;
+
+import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
+import org.apache.ignite.internal.processors.query.schema.SchemaKey;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Schema change propose discovery message.
+ */
+public class SchemaProposeDiscoveryMessage extends SchemaAbstractDiscoveryMessage {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Cache deployment ID. */
+    private IgniteUuid depId;
+
+    /** Error. */
+    private SchemaOperationException err;
+
+    /** Whether to perform exchange. */
+    private transient boolean exchange;
+
+    /**
+     * Constructor.
+     *
+     * @param op Operation.
+     */
+    public SchemaProposeDiscoveryMessage(SchemaAbstractOperation op) {
+        super(op);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public DiscoveryCustomMessage ackMessage() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isMutable() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean exchange() {
+        return exchange;
+    }
+
+    /**
+     * @param exchange Whether to perform exchange.
+     */
+    public void exchange(boolean exchange) {
+        this.exchange = exchange;
+    }
+
+    /**
+     * @return Deployment ID.
+     */
+    @Nullable public IgniteUuid deploymentId() {
+        return depId;
+    }
+
+    /**
+     * @param depId Deployment ID.
+     */
+    public void deploymentId(IgniteUuid depId) {
+        this.depId = depId;
+    }
+
+    /**
+     *
+     * @return {@code True} if message is initialized.
+     */
+    public boolean initialized() {
+        return deploymentId() != null || hasError();
+    }
+
+    /**
+     * Set error.
+     *
+     * @param err Error.
+     */
+    public void onError(SchemaOperationException err) {
+        if (!hasError()) {
+            this.err = err;
+        }
+    }
+
+    /**
+     * @return {@code True} if error was reported during init.
+     */
+    public boolean hasError() {
+        return err != null;
+    }
+
+    /**
+     * @return Error message (if any).
+     */
+    @Nullable public SchemaOperationException error() {
+        return err;
+    }
+
+    /**
+     * @return Schema key.
+     */
+    public SchemaKey schemaKey() {
+        return new SchemaKey(operation().space(), depId);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaProposeDiscoveryMessage.class, this, "parent", super.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaAbstractOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaAbstractOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaAbstractOperation.java
new file mode 100644
index 0000000..8418ece
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaAbstractOperation.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.operation;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+/**
+ * Abstract operation on schema.
+ */
+public abstract class SchemaAbstractOperation implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Operation ID. */
+    private final UUID opId;
+
+    /** Space. */
+    private final String space;
+
+    /**
+     * Constructor.
+     *
+     * @param opId Operation ID.
+     * @param space Space.
+     */
+    public SchemaAbstractOperation(UUID opId, String space) {
+        this.opId = opId;
+        this.space = space;
+    }
+
+    /**
+     * @return Operation id.
+     */
+    public UUID id() {
+        return opId;
+    }
+
+    /**
+     * @return Space.
+     */
+    public String space() {
+        return space;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaAbstractOperation.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexAbstractOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexAbstractOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexAbstractOperation.java
new file mode 100644
index 0000000..fc4a9ff
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexAbstractOperation.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.operation;
+
+import java.util.UUID;
+
+/**
+ * Schema index abstract operation.
+ */
+public abstract class SchemaIndexAbstractOperation extends SchemaAbstractOperation {
+    /**
+     * Constructor.
+     *
+     * @param opId Operation ID.
+     * @param space Space.
+     */
+    public SchemaIndexAbstractOperation(UUID opId, String space) {
+        super(opId, space);
+    }
+
+    /**
+     * @return Index name.
+     */
+    public abstract String indexName();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java
new file mode 100644
index 0000000..9281f2a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.operation;
+
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.UUID;
+
+/**
+ * Schema index create operation.
+ */
+public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Table name. */
+    private final String tblName;
+
+    /** Index. */
+    @GridToStringInclude
+    private final QueryIndex idx;
+
+    /** Ignore operation if index exists. */
+    private final boolean ifNotExists;
+
+    /**
+     * Constructor.
+     *
+     * @param opId Operation id.
+     * @param space Space.
+     * @param tblName Table name.
+     * @param idx Index params.
+     * @param ifNotExists Ignore operation if index exists.
+     */
+    public SchemaIndexCreateOperation(UUID opId, String space, String tblName, QueryIndex idx, boolean ifNotExists) {
+        super(opId, space);
+
+        this.tblName = tblName;
+        this.idx = idx;
+        this.ifNotExists = ifNotExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String indexName() {
+        return QueryUtils.indexName(tblName, idx);
+    }
+
+    /**
+     * @return Table name.
+     */
+    public String tableName() {
+        return tblName;
+    }
+
+    /**
+     * @return Index params.
+     */
+    public QueryIndex index() {
+        return idx;
+    }
+
+    /**
+     * @return Ignore operation if index exists.
+     */
+    public boolean ifNotExists() {
+        return ifNotExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaIndexCreateOperation.class, this, "parent", super.toString());
+    }
+}


[13/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/package-info.java
new file mode 100644
index 0000000..e0a760c
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains specific implementations for matrix storage models.
+ */
+package org.apache.ignite.ml.math.impls.storage.matrix;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ArrayVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ArrayVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ArrayVectorStorage.java
new file mode 100644
index 0000000..dc23611
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ArrayVectorStorage.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import org.apache.ignite.ml.math.VectorStorage;
+
+/**
+ * Array based {@link VectorStorage} implementation.
+ */
+public class ArrayVectorStorage implements VectorStorage {
+    /** Backing data array. */
+    private double[] data;
+
+    /**
+     * IMPL NOTE required by {@link Externalizable}.
+     */
+    public ArrayVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size Vector size.
+     */
+    public ArrayVectorStorage(int size) {
+        assert size > 0;
+
+        data = new double[size];
+    }
+
+    /**
+     * @param data Backing data array.
+     */
+    public ArrayVectorStorage(double[] data) {
+        assert data != null;
+
+        this.data = data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return data == null ? 0 : data.length;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return data[i];
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        data[i] = v;
+    }
+
+    /** {@inheritDoc}} */
+    @Override public boolean isArrayBased() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[] data() {
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(data);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        data = (double[])in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + Arrays.hashCode(data);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        ArrayVectorStorage that = (ArrayVectorStorage)obj;
+
+        return Arrays.equals(data, (that.data));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/CacheVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/CacheVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/CacheVectorStorage.java
new file mode 100644
index 0000000..7aa317c
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/CacheVectorStorage.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.ml.math.ValueMapper;
+import org.apache.ignite.ml.math.VectorKeyMapper;
+import org.apache.ignite.ml.math.VectorStorage;
+
+/**
+ * Vector storage based on existing cache and index and value mapping functions.
+ */
+public class CacheVectorStorage<K, V> implements VectorStorage {
+    /** Storage size. */
+    private int size;
+    /** Key mapper. */
+    private VectorKeyMapper<K> keyMapper;
+    /** Value mapper. */
+    private ValueMapper<V> valMapper;
+    /** Underlying ignite cache. */
+    private IgniteCache<K, V> cache;
+
+    /**
+     *
+     */
+    public CacheVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size
+     * @param cache
+     * @param keyMapper
+     * @param valMapper
+     */
+    public CacheVectorStorage(int size, IgniteCache<K, V> cache, VectorKeyMapper<K> keyMapper,
+        ValueMapper<V> valMapper) {
+        assert size > 0;
+        assert cache != null;
+        assert keyMapper != null;
+        assert valMapper != null;
+
+        this.size = size;
+        this.cache = cache;
+        this.keyMapper = keyMapper;
+        this.valMapper = valMapper;
+    }
+
+    /**
+     *
+     *
+     */
+    public IgniteCache<K, V> cache() {
+        return cache;
+    }
+
+    /**
+     *
+     *
+     */
+    public VectorKeyMapper<K> keyMapper() {
+        return keyMapper;
+    }
+
+    /**
+     *
+     *
+     */
+    public ValueMapper<V> valueMapper() {
+        return valMapper;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return valMapper.toDouble(cache.get(keyMapper.apply(i)));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        cache.put(keyMapper.apply(i), valMapper.fromDouble(v));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(size);
+        out.writeObject(keyMapper);
+        out.writeObject(valMapper);
+        out.writeUTF(cache.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        size = in.readInt();
+        keyMapper = (VectorKeyMapper<K>)in.readObject();
+        valMapper = (ValueMapper<V>)in.readObject();
+        cache = Ignition.localIgnite().getOrCreateCache(in.readUTF());
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + size();
+        res = res * 37 + keyMapper.hashCode();
+        res = res * 37 + valMapper.hashCode();
+        res = res * 37 + cache.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        CacheVectorStorage that = (CacheVectorStorage)obj;
+
+        return size == that.size
+            && (keyMapper != null ? keyMapper.getClass().equals(that.keyMapper.getClass()) : that.keyMapper == null)
+            && (valMapper != null ? valMapper.getClass().equals(that.valMapper.getClass()) : that.valMapper == null)
+            && (cache != null ? cache.equals(that.cache) : that.cache == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ConstantVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ConstantVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ConstantVectorStorage.java
new file mode 100644
index 0000000..31469ea
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/ConstantVectorStorage.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+
+/**
+ * Constant read-only vector storage.
+ */
+public class ConstantVectorStorage implements VectorStorage {
+    /** */ private int size;
+    /** */ private double val;
+
+    /**
+     *
+     */
+    public ConstantVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size Vector size.
+     * @param val Value to set for vector elements.
+     */
+    public ConstantVectorStorage(int size, double val) {
+        assert size > 0;
+
+        this.size = size;
+        this.val = val;
+    }
+
+    /**
+     *
+     *
+     */
+    public double constant() {
+        return val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        throw new UnsupportedOperationException("Can't set value into constant vector.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(size);
+        out.writeDouble(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        size = in.readInt();
+        val = in.readDouble();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + size;
+        res = res * 37 + Double.hashCode(val);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        ConstantVectorStorage that = (ConstantVectorStorage)o;
+
+        return size == that.size && val == that.val;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DelegateVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DelegateVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DelegateVectorStorage.java
new file mode 100644
index 0000000..c431bdb
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DelegateVectorStorage.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.VectorStorage;
+
+/**
+ * {@link VectorStorage} implementation that delegates to parent matrix.
+ */
+public class DelegateVectorStorage implements VectorStorage {
+    /** Parent vector storage. */
+    private VectorStorage sto;
+
+    /** Offset in the parent vector. */
+    private int off;
+
+    /** Size of the vector. */
+    private int len;
+
+    /**
+     *
+     */
+    public DelegateVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param sto Vector storage to delegate to.
+     * @param off Offset in the parent vector.
+     * @param len Size of the vector.
+     */
+    public DelegateVectorStorage(VectorStorage sto, int off, int len) {
+        assert sto != null;
+        assert off >= 0;
+        assert len > 0;
+
+        this.sto = sto;
+        this.off = off;
+        this.len = len;
+    }
+
+    /** */
+    public VectorStorage delegate() {
+        return sto;
+    }
+
+    /** */
+    public int offset() {
+        return off;
+    }
+
+    /** */
+    public int length() {
+        return len;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return len;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return sto.get(off + i);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        sto.set(off + i, v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[] data() {
+        return sto.data();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return sto.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return sto.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return sto.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return sto.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return sto.isArrayBased();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(sto);
+        out.writeInt(off);
+        out.writeInt(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        sto = (VectorStorage)in.readObject();
+        off = in.readInt();
+        len = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        DelegateVectorStorage that = (DelegateVectorStorage)o;
+
+        return len == that.len && off == that.off && (sto != null ? sto.equals(that.sto) : that.sto == null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + off;
+        res = res * 37 + len;
+        res = res * 37 + sto.hashCode();
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java
new file mode 100644
index 0000000..a9965cc
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/DenseLocalOffHeapVectorStorage.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.ml.math.VectorStorage;
+
+/**
+ * Local, dense off-heap vector storage.
+ */
+public class DenseLocalOffHeapVectorStorage implements VectorStorage {
+    /** Vector size. */
+    private int size;
+
+    /** */
+    private transient long ptr;
+    //TODO: temp solution.
+    /** */
+    private int ptrInitHash;
+
+    /**
+     *
+     */
+    public DenseLocalOffHeapVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size Vector size.
+     */
+    public DenseLocalOffHeapVectorStorage(int size) {
+        assert size > 0;
+
+        this.size = size;
+
+        allocateMemory(size);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return GridUnsafe.getDouble(pointerOffset(i));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        GridUnsafe.putDouble(pointerOffset(i), v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[] data() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(size);
+        out.writeInt(ptrInitHash);
+
+        for (int i = 0; i < size; i++)
+            out.writeDouble(get(i));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        size = in.readInt();
+
+        allocateMemory(size);
+
+        ptrInitHash = in.readInt();
+
+        for (int i = 0; i < size; i++)
+            set(i, in.readDouble());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        GridUnsafe.freeMemory(ptr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + size;
+        res = res * 37 + ptrInitHash;
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        DenseLocalOffHeapVectorStorage that = (DenseLocalOffHeapVectorStorage)o;
+
+        return size == that.size && isMemoryEquals(that);
+    }
+
+    /** */
+    private boolean isMemoryEquals(DenseLocalOffHeapVectorStorage otherStorage) {
+        return IntStream.range(0, size).parallel().noneMatch(idx -> Double.compare(get(idx), otherStorage.get(idx)) != 0);
+    }
+
+    /**
+     * Pointer offset for specific index.
+     *
+     * @param i Offset index.
+     */
+    private long pointerOffset(int i) {
+        return ptr + i * Double.BYTES;
+    }
+
+    /** */
+    private void allocateMemory(int size) {
+        ptr = GridUnsafe.allocateMemory(size * Double.BYTES);
+
+        ptrInitHash = Long.hashCode(ptr);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/FunctionVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/FunctionVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/FunctionVectorStorage.java
new file mode 100644
index 0000000..0f13bb6
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/FunctionVectorStorage.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IntDoubleToVoidFunction;
+
+/**
+ * Read-only or read-write function-based vector storage.
+ */
+public class FunctionVectorStorage implements VectorStorage {
+    /** */ private IgniteFunction<Integer, Double> getFunc;
+    /** */ private IntDoubleToVoidFunction setFunc;
+    /** */ private int size;
+
+    /**
+     *
+     */
+    public FunctionVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * Creates read-only or read-write storage.
+     *
+     * @param size Cardinality of this vector storage.
+     * @param getFunc Get function.
+     * @param setFunc Optional set function ({@code null} for read-only storage).
+     */
+    public FunctionVectorStorage(int size, IgniteFunction<Integer, Double> getFunc, IntDoubleToVoidFunction setFunc) {
+        assert size > 0;
+        assert getFunc != null; // At least get function is required.
+
+        this.size = size;
+        this.getFunc = getFunc;
+        this.setFunc = setFunc;
+    }
+
+    /**
+     *
+     *
+     */
+    public IgniteFunction<Integer, Double> getFunction() {
+        return getFunc;
+    }
+
+    /**
+     *
+     *
+     */
+    public IntDoubleToVoidFunction setFunction() {
+        return setFunc;
+    }
+
+    /**
+     * Creates read-only storage.
+     *
+     * @param size Cardinality of this vector storage.
+     * @param getFunc Get function.
+     */
+    public FunctionVectorStorage(int size, IgniteFunction<Integer, Double> getFunc) {
+        this(size, getFunc, null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return getFunc.apply(i);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        if (setFunc != null)
+            setFunc.accept(i, v);
+        else
+            throw new UnsupportedOperationException("Cannot set into read-only vector.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(setFunc);
+        out.writeObject(getFunc);
+        out.writeInt(size);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        setFunc = (IntDoubleToVoidFunction)in.readObject();
+        getFunc = (IgniteFunction<Integer, Double>)in.readObject();
+        size = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/MatrixVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/MatrixVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/MatrixVectorStorage.java
new file mode 100644
index 0000000..a7d7e26
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/MatrixVectorStorage.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+
+/**
+ * Row, column or diagonal vector-based view of the matrix
+ */
+public class MatrixVectorStorage implements VectorStorage {
+    /** */ private Matrix parent;
+
+    /** */ private int row;
+    /** */ private int col;
+
+    /** */ private int rowStride;
+    /** */  private int colStride;
+
+    /** */ private int size;
+
+    /**
+     *
+     */
+    public MatrixVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param parent
+     * @param row
+     * @param col
+     * @param rowStride
+     * @param colStride
+     */
+    public MatrixVectorStorage(Matrix parent, int row, int col, int rowStride, int colStride) {
+        assert parent != null;
+        assert rowStride >= 0;
+        assert colStride >= 0;
+        assert rowStride > 0 || colStride > 0;
+
+        if (row < 0 || row >= parent.rowSize())
+            throw new IndexException(row);
+        if (col < 0 || col >= parent.columnSize())
+            throw new IndexException(col);
+
+        this.parent = parent;
+
+        this.row = row;
+        this.col = col;
+
+        this.rowStride = rowStride;
+        this.colStride = colStride;
+
+        this.size = getSize();
+    }
+
+    /**
+     *
+     *
+     */
+    int row() {
+        return row;
+    }
+
+    /**
+     *
+     *
+     */
+    int column() {
+        return col;
+    }
+
+    /**
+     *
+     *
+     */
+    int rowStride() {
+        return rowStride;
+    }
+
+    /**
+     *
+     *
+     */
+    int columnStride() {
+        return colStride;
+    }
+
+    /**
+     *
+     *
+     */
+    private int getSize() {
+        if (rowStride != 0 && colStride != 0) {
+            int n1 = (parent.rowSize() - row) / rowStride;
+            int n2 = (parent.columnSize() - col) / colStride;
+
+            return Math.min(n1, n2);
+        }
+        else if (rowStride > 0)
+            return (parent.rowSize() - row) / rowStride;
+        else
+            return (parent.columnSize() - col) / colStride;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return parent.get(row + i * rowStride, col + i * colStride);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        parent.set(row + i * rowStride, col + i * colStride, v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return parent.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return parent.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return parent.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return parent.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(parent);
+        out.writeInt(row);
+        out.writeInt(col);
+        out.writeInt(rowStride);
+        out.writeInt(colStride);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        parent = (Matrix)in.readObject();
+        row = in.readInt();
+        col = in.readInt();
+        rowStride = in.readInt();
+        colStride = in.readInt();
+
+        size = getSize();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/PivotedVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/PivotedVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/PivotedVectorStorage.java
new file mode 100644
index 0000000..a524838
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/PivotedVectorStorage.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import org.apache.ignite.ml.math.VectorStorage;
+
+/**
+ * Pivoted (index mapped) view over another vector storage implementation.
+ */
+public class PivotedVectorStorage implements VectorStorage {
+    /** */ private VectorStorage sto;
+
+    /** */ private int[] pivot;
+    /** */ private int[] unpivot;
+
+    /**
+     * @param pivot Pivot array.
+     */
+    private static int[] reverse(int[] pivot) {
+        int[] res = new int[pivot.length];
+
+        for (int i = 0; i < pivot.length; i++)
+            res[pivot[i]] = i;
+
+        return res;
+    }
+
+    /**
+     *
+     *
+     */
+    public int[] pivot() {
+        return pivot;
+    }
+
+    /**
+     *
+     *
+     */
+    public int[] unpivot() {
+        return unpivot;
+    }
+
+    /**
+     * @param sto Backing vector storage.
+     * @param pivot Mapping from external index to internal.
+     * @param unpivot Mapping from internal index to external.
+     */
+    public PivotedVectorStorage(VectorStorage sto, int[] pivot, int[] unpivot) {
+        assert sto != null;
+        assert pivot != null;
+        assert unpivot != null;
+
+        this.sto = sto;
+        this.pivot = pivot;
+        this.unpivot = unpivot;
+    }
+
+    /**
+     * @param sto Backing vector storage.
+     * @param pivot Mapping from external index to internal.
+     */
+    public PivotedVectorStorage(VectorStorage sto, int[] pivot) {
+        this(sto, pivot, reverse(pivot));
+    }
+
+    /**
+     *
+     */
+    public PivotedVectorStorage() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return sto.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return sto.get(pivot[i]);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        sto.set(pivot[i], v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(sto);
+        out.writeObject(pivot);
+        out.writeObject(unpivot);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        sto = (VectorStorage)in.readObject();
+        pivot = (int[])in.readObject();
+        unpivot = (int[])in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return sto.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return sto.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return sto.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return sto.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return sto.isArrayBased();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[] data() {
+        return isArrayBased() ? sto.data() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        PivotedVectorStorage that = (PivotedVectorStorage)o;
+
+        return (sto != null ? sto.equals(that.sto) : that.sto == null) && Arrays.equals(pivot, that.pivot)
+            && Arrays.equals(unpivot, that.unpivot);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = sto != null ? sto.hashCode() : 0;
+
+        res = 31 * res + Arrays.hashCode(pivot);
+        res = 31 * res + Arrays.hashCode(unpivot);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/RandomVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/RandomVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/RandomVectorStorage.java
new file mode 100644
index 0000000..be1ad91
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/RandomVectorStorage.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.nio.ByteBuffer;
+import java.util.Random;
+import org.apache.ignite.ml.math.MurmurHash;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+
+/**
+ * {@link VectorStorage} implementation with random values in the vector elements.
+ */
+public class RandomVectorStorage implements VectorStorage {
+    /** */
+    private static final long SCALE = 1L << 32;
+    /** */
+    private static final int PRIME = 104047;
+
+    /** Random generation seed. */
+    private int seed;
+
+    /** Vector size. */
+    private int size;
+
+    /** Whether fast hash is used, in {@link #get(int)}. */
+    private boolean fastHash;
+
+    /** */
+    public RandomVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size Size of the storage.
+     * @param fastHash Whether or not to use fast hashing or Murmur hashing.
+     */
+    public RandomVectorStorage(int size, boolean fastHash) {
+        assert size > 0;
+
+        this.size = size;
+        this.fastHash = fastHash;
+
+        seed = new Random().nextInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        if (!fastHash) {
+            ByteBuffer buf = ByteBuffer.allocate(4);
+
+            buf.putInt(i);
+            buf.flip();
+
+            return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / (double)SCALE;
+        }
+        else
+            // This isn't a fantastic random number generator, but it is just fine for random projections.
+            return (((i * PRIME) & 8) * 0.25) - 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        throw new UnsupportedOperationException("Random vector storage is a read-only storage.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(size);
+        out.writeInt(seed);
+        out.writeBoolean(fastHash);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        size = in.readInt();
+        seed = in.readInt();
+        fastHash = in.readBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + Boolean.hashCode(fastHash);
+        res = res * 37 + seed;
+        res = res * 37 + size;
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        RandomVectorStorage that = (RandomVectorStorage)o;
+
+        return size == that.size && seed == that.seed && fastHash == that.fastHash;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorDelegateStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorDelegateStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorDelegateStorage.java
new file mode 100644
index 0000000..d472e3a
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorDelegateStorage.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+
+/**
+ * Single value view storage over another vector.
+ */
+public class SingleElementVectorDelegateStorage implements VectorStorage {
+    /** */ private int idx;
+    /** */ private Vector vec;
+
+    /**
+     *
+     */
+    public SingleElementVectorDelegateStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param vec Parent vector.
+     * @param idx Element index.
+     */
+    public SingleElementVectorDelegateStorage(Vector vec, int idx) {
+        assert vec != null;
+        assert idx >= 0;
+
+        this.vec = vec;
+        this.idx = idx;
+    }
+
+    /**
+     *
+     *
+     */
+    public int index() {
+        return idx;
+    }
+
+    /**
+     *
+     *
+     */
+    public Vector delegate() {
+        return vec;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return vec.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return i == idx ? vec.get(i) : 0.0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        if (i == idx)
+            vec.set(i, v);
+        else
+            throw new UnsupportedOperationException("Can't set element outside of index: " + idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(vec);
+        out.writeInt(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        vec = (Vector)in.readObject();
+        idx = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        SingleElementVectorDelegateStorage that = (SingleElementVectorDelegateStorage)o;
+
+        return idx == that.idx && (vec != null ? vec.equals(that.vec) : that.vec == null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = idx;
+
+        res = 31 * res + (vec != null ? vec.hashCode() : 0);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorStorage.java
new file mode 100644
index 0000000..854b732
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SingleElementVectorStorage.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+
+/**
+ * Vector storage holding a single non-zero value at some index.
+ */
+public class SingleElementVectorStorage implements VectorStorage {
+    /** */ private int idx;
+    /** */ private double val;
+    /** */ private int size;
+
+    /**
+     *
+     */
+    public SingleElementVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size Parent vector size.
+     * @param idx Element index in the parent vector.
+     * @param val Value of the element.
+     */
+    public SingleElementVectorStorage(int size, int idx, double val) {
+        assert size > 0;
+        assert idx >= 0;
+
+        this.size = size;
+        this.idx = idx;
+        this.val = val;
+    }
+
+    /**
+     *
+     * @return Index of the element in the parent vector.
+     */
+    public int index() {
+        return idx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return i == idx ? val : 0.0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        if (i == idx)
+            val = v;
+        else
+            throw new UnsupportedOperationException("Can't set element outside of index: " + idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(size);
+        out.writeInt(idx);
+        out.writeDouble(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        size = in.readInt();
+        idx = in.readInt();
+        val = in.readDouble();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        SingleElementVectorStorage that = (SingleElementVectorStorage)o;
+
+        return idx == that.idx && Double.compare(that.val, val) == 0 && size == that.size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = idx;
+        long temp = Double.doubleToLongBits(val);
+
+        res = 31 * res + (int)(temp ^ (temp >>> 32));
+        res = 31 * res + size;
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java
new file mode 100644
index 0000000..7b3da78
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOffHeapVectorStorage.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.nio.ByteBuffer;
+import org.apache.ignite.internal.util.offheap.GridOffHeapMap;
+import org.apache.ignite.internal.util.offheap.GridOffHeapMapFactory;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.vector.SparseLocalOffHeapVector;
+
+/**
+ * {@link VectorStorage} implementation for {@link SparseLocalOffHeapVector}.
+ */
+public class SparseLocalOffHeapVectorStorage implements VectorStorage {
+    /** Assume 10% density. */
+    private static final int INIT_DENSITY = 10;
+    /** Storage capacity. */
+    private int size;
+    /** Local off heap map. */
+    private GridOffHeapMap gridOffHeapMap;
+
+    /** */
+    public SparseLocalOffHeapVectorStorage() {
+        //No-op.
+    }
+
+    /** */
+    public SparseLocalOffHeapVectorStorage(int cap) {
+        assert cap > 0;
+
+        gridOffHeapMap = GridOffHeapMapFactory.unsafeMap(cap / INIT_DENSITY);
+        size = cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        byte[] bytes = gridOffHeapMap.get(hash(i), intToByteArray(i));
+        return bytes == null ? 0 : ByteBuffer.wrap(bytes).getDouble();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        if (v != 0.0)
+            gridOffHeapMap.put(hash(i), intToByteArray(i), doubleToByteArray(v));
+        else if (gridOffHeapMap.contains(hash(i), intToByteArray(i)))
+            gridOffHeapMap.remove(hash(i), intToByteArray(i));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        throw new UnsupportedOperationException(); // TODO: add externalization support.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        gridOffHeapMap.destruct();
+    }
+
+    /** */
+    private int hash(int h) {
+        // Apply base step of MurmurHash; see http://code.google.com/p/smhasher/
+        // Despite two multiplies, this is often faster than others
+        // with comparable bit-spread properties.
+        h ^= h >>> 16;
+        h *= 0x85ebca6b;
+        h ^= h >>> 13;
+        h *= 0xc2b2ae35;
+
+        return (h >>> 16) ^ h;
+    }
+
+    /** */
+    private byte[] intToByteArray(int val) {
+        return new byte[] {
+            (byte)(val >>> 24),
+            (byte)(val >>> 16),
+            (byte)(val >>> 8),
+            (byte)val};
+    }
+
+    /** */
+    private byte[] doubleToByteArray(double val) {
+        long l = Double.doubleToRawLongBits(val);
+        return new byte[] {
+            (byte)((l >> 56) & 0xff),
+            (byte)((l >> 48) & 0xff),
+            (byte)((l >> 40) & 0xff),
+            (byte)((l >> 32) & 0xff),
+            (byte)((l >> 24) & 0xff),
+            (byte)((l >> 16) & 0xff),
+            (byte)((l >> 8) & 0xff),
+            (byte)((l) & 0xff),
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java
new file mode 100644
index 0000000..75318d6
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/SparseLocalOnHeapVectorStorage.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.vector;
+
+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 org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.VectorStorage;
+
+/**
+ * Sparse, local, on-heap vector storage.
+ */
+public class SparseLocalOnHeapVectorStorage implements VectorStorage, StorageConstants {
+    /** */ private int size;
+    /** */ private int acsMode;
+
+    /** Actual map storage. */
+    private Map<Integer, Double> sto;
+
+    /**
+     *
+     */
+    public SparseLocalOnHeapVectorStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param size Vector size.
+     * @param acsMode Access mode.
+     */
+    public SparseLocalOnHeapVectorStorage(int size, int acsMode) {
+        assert size > 0;
+        assertAccessMode(acsMode);
+
+        this.size = size;
+        this.acsMode = acsMode;
+
+        if (acsMode == SEQUENTIAL_ACCESS_MODE)
+            sto = new Int2DoubleRBTreeMap();
+        else
+            sto = new Int2DoubleOpenHashMap();
+    }
+
+    /**
+     *
+     *
+     */
+    public int getAccessMode() {
+        return acsMode;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int i) {
+        return sto.getOrDefault(i, 0.0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int i, double v) {
+        if (v != 0.0)
+            sto.put(i, v);
+        else if (sto.containsKey(i))
+            sto.remove(i);
+
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(size);
+        out.writeInt(acsMode);
+        out.writeObject(sto);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"unchecked"})
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        size = in.readInt();
+        acsMode = in.readInt();
+        sto = (Map<Integer, Double>)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return acsMode == SEQUENTIAL_ACCESS_MODE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        SparseLocalOnHeapVectorStorage that = (SparseLocalOnHeapVectorStorage)o;
+
+        return size == that.size && acsMode == that.acsMode && (sto != null ? sto.equals(that.sto) : that.sto == null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = size;
+
+        res = 31 * res + acsMode;
+        res = 31 * res + (sto != null ? sto.hashCode() : 0);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/package-info.java
new file mode 100644
index 0000000..a9825b3
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/vector/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains specific implementations for vector storage models.
+ */
+package org.apache.ignite.ml.math.impls.storage.vector;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractReadOnlyVector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractReadOnlyVector.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractReadOnlyVector.java
new file mode 100644
index 0000000..e48542b
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/vector/AbstractReadOnlyVector.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.vector;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.impls.matrix.FunctionMatrix;
+
+/**
+ * This class provides a helper implementation of the read-only implementation of {@link Vector}
+ * interface to minimize the effort required to implement it.
+ * Subclasses may override some of the implemented methods if a more
+ * specific or optimized implementation is desirable.
+ */
+public abstract class AbstractReadOnlyVector extends AbstractVector {
+    /** */
+    public AbstractReadOnlyVector() {
+        // No-op.
+    }
+
+    /**
+     * @param sto Storage.
+     */
+    public AbstractReadOnlyVector(VectorStorage sto) {
+        super(true, sto);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix cross(Vector vec) {
+        return new FunctionMatrix(size(), vec.size(),
+            (row, col) -> vec.get(col) * get(row));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix toMatrix(boolean rowLike) {
+        return new FunctionMatrix(rowLike ? 1 : size(), rowLike ? size() : 1,
+            (row, col) -> rowLike ? get(col) : get(row));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
+        return new FunctionMatrix(rowLike ? 1 : size() + 1, rowLike ? size() + 1 : 1, (row, col) -> {
+            if (row == 0 && col == 0)
+                return zeroVal;
+
+            return rowLike ? get(col - 1) : get(row - 1);
+        });
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector copy() {
+        return this; // This exploits read-only feature of this type vector.
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector logNormalize() {
+        return logNormalize(2.0, Math.sqrt(getLengthSquared()));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector logNormalize(double power) {
+        return logNormalize(power, kNorm(power));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteDoubleFunction<Double> fun) {
+        return new FunctionVector(size(), (i) -> fun.apply(get(i)));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun) {
+        checkCardinality(vec);
+
+        return new FunctionVector(size(), (i) -> fun.apply(get(i), vec.get(i)));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y) {
+        return new FunctionVector(size(), (i) -> fun.apply(get(i), y));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector divide(double x) {
+        if (x == 1.0)
+            return this;
+
+        return new FunctionVector(size(), (i) -> get(i) / x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(double x) {
+        return x == 0 ? new ConstantVector(size(), 0) : new FunctionVector(size(), (i) -> get(i) * x);
+    }
+
+    /**
+     * @param power Power.
+     * @param normLen Normalized length.
+     * @return logNormalized value.
+     */
+    private Vector logNormalize(double power, double normLen) {
+        assert !(Double.isInfinite(power) || power <= 1.0);
+
+        double denominator = normLen * Math.log(power);
+
+        return new FunctionVector(size(), (idx) -> Math.log1p(get(idx)) / denominator);
+    }
+}


[17/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java
new file mode 100644
index 0000000..00bf915
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Identity value mapper.
+ */
+public class IdentityValueMapper implements ValueMapper<Double> {
+    /** */ private static final long serialVersionUID = -8010078306142216389L;
+
+    /** {@inheritDoc} */
+    @Override public Double fromDouble(double v) {
+        return v;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double toDouble(Double v) {
+        assert v != null;
+
+        return v;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return Long.hashCode(serialVersionUID);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/KeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/KeyMapper.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/KeyMapper.java
new file mode 100644
index 0000000..1ac2f3d
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/KeyMapper.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.Serializable;
+
+/**
+ * Maps key objects to index in {@link Vector} or {@link Matrix}.
+ */
+public interface KeyMapper<K> extends Serializable {
+    /**
+     * Checks given cache key corresponds to a valid index in vector or matrix.
+     *
+     * @param k Key to check.
+     * @return {@code true} if there is a valid index, {@code false} otherwise.
+     */
+    public boolean isValid(K k);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..1039484
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java
@@ -0,0 +1,518 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.Externalizable;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
+
+/**
+ * A matrix interface.
+ *
+ * Based on its flavor it can have vastly different implementations tailored for
+ * for different types of data (e.g. dense vs. sparse), different sizes of data or different operation
+ * optimizations.
+ *
+ * Note also that not all operations can be supported by all underlying implementations. If an operation is not
+ * supported a {@link UnsupportedOperationException} is thrown. This exception can also be thrown in partial cases
+ * where an operation is unsupported only in special cases, e.g. where a given operation cannot be deterministically
+ * completed in polynomial time.
+ *
+ * Based on ideas from <a href="http://mahout.apache.org/">Apache Mahout</a>.
+ */
+public interface Matrix extends MetaAttributes, Externalizable, StorageOpsMetrics, Destroyable {
+    /**
+     * Holder for matrix's element.
+     */
+    interface Element {
+        /**
+         * Gets element's value.
+         *
+         * @return The value of this matrix element.
+         */
+        double get();
+
+        /**
+         * Gets element's row index.
+         *
+         * @return The row index of this element.
+         */
+        int row();
+
+        /**
+         * Gets element's column index.
+         *
+         * @return The column index of this element.
+         */
+        int column();
+
+        /**
+         * Sets element's value.
+         *
+         * @param val Value to set.
+         */
+        void set(double val);
+    }
+
+    /**
+     * Gets the maximum value in this matrix.
+     *
+     * @return Maximum value in this matrix.
+     */
+    public double maxValue();
+
+    /**
+     * Gets the minimum value in this matrix.
+     *
+     * @return Minimum value in this matrix.
+     */
+    public double minValue();
+
+    /**
+     * Gets the maximum element in this matrix.
+     *
+     * @return Maximum element in this matrix.
+     */
+    public Element maxElement();
+
+    /**
+     * Gets the minimum element in this matrix.
+     *
+     * @return Minimum element in this matrix.
+     */
+    public Element minElement();
+
+    /**
+     * Gets the matrix's element at the given coordinates.
+     *
+     * @param row Row index.
+     * @param col Column index.
+     * @return Element at the given coordinates.
+     */
+    public Element getElement(int row, int col);
+
+    /**
+     * Swaps two rows in this matrix.
+     *
+     * @param row1 Row #1.
+     * @param row2 Row #2.
+     * @return This matrix.
+     */
+    public Matrix swapRows(int row1, int row2);
+
+    /**
+     * Swaps two columns in this matrix.
+     *
+     * @param col1 Column #1.
+     * @param col2 Column #2.
+     * @return This matrix.
+     */
+    public Matrix swapColumns(int col1, int col2);
+
+    /**
+     * Assigns given value to all elements of this matrix.
+     *
+     * @param val Value to assign to all elements.
+     * @return This matrix.
+     */
+    public Matrix assign(double val);
+
+    /**
+     * Assigns given values to this matrix.
+     *
+     * @param vals Values to assign.
+     * @return This matrix.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix assign(double[][] vals);
+
+    /**
+     * Assigns values from given matrix to this matrix.
+     *
+     * @param mtx Matrix to assign to this matrix.
+     * @return This matrix.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix assign(Matrix mtx);
+
+    /**
+     * Assigns each matrix element to the value generated by given function.
+     *
+     * @param fun Function that takes the row and column and returns the value to assign.
+     * @return This matrix.
+     */
+    public Matrix assign(IntIntToDoubleFunction fun);
+
+    /**
+     * Maps all values in this matrix through a given function.
+     *
+     * @param fun Mapping function.
+     * @return This matrix.
+     */
+    public Matrix map(IgniteDoubleFunction<Double> fun);
+
+    /**
+     * Maps all values in this matrix through a given function.
+     *
+     * For this matrix <code>A</code>, argument matrix <code>B</code> and the
+     * function <code>F</code> this method maps every cell <code>x, y</code> as:
+     * <code>A(x,y) = fun(A(x,y), B(x,y))</code>
+     *
+     * @param mtx Argument matrix.
+     * @param fun Mapping function.
+     * @return This function.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix map(Matrix mtx, IgniteBiFunction<Double, Double, Double> fun);
+
+    /**
+     * Assigns values from given vector to the specified column in this matrix.
+     *
+     * @param col Column index.
+     * @param vec Vector to get values from.
+     * @return This matrix.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix assignColumn(int col, Vector vec);
+
+    /**
+     * Assigns values from given vector to the specified row in this matrix.
+     *
+     * @param row Row index.
+     * @param vec Vector to get values from.
+     * @return This matrix.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix assignRow(int row, Vector vec);
+
+    /**
+     * Collects the results of applying a given function to all rows in this matrix.
+     *
+     * @param fun Aggregating function.
+     * @return Vector of row aggregates.
+     */
+    public Vector foldRows(IgniteFunction<Vector, Double> fun);
+
+    /**
+     * Collects the results of applying a given function to all columns in this matrix.
+     *
+     * @param fun Aggregating function.
+     * @return Vector of column aggregates.
+     */
+    public Vector foldColumns(IgniteFunction<Vector, Double> fun);
+
+    /**
+     * Folds this matrix into a single value.
+     *
+     * @param foldFun Folding function that takes two parameters: accumulator and the current value.
+     * @param mapFun Mapping function that is called on each matrix cell before its passed to the accumulator (as its
+     * second parameter).
+     * @param <T> Type of the folded value.
+     * @param zeroVal Zero value for fold function.
+     * @return Folded value of this matrix.
+     */
+    public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal);
+
+    /**
+     * Calculates the density of the matrix based on supplied criteria.
+     * Returns {@code true} if this matrix is denser than threshold with at least 80% confidence.
+     *
+     * @param threshold the threshold value [0, 1] of non-zero elements above which the matrix is considered dense.
+     */
+    public boolean density(double threshold);
+
+    /**
+     * Gets number of columns in this matrix.
+     *
+     * @return The number of columns in this matrix.
+     */
+    public int columnSize();
+
+    /**
+     * Gets number of rows in this matrix.
+     *
+     * @return The number of rows in this matrix.
+     */
+    public int rowSize();
+
+    /**
+     * Returns matrix determinant using Laplace theorem.
+     *
+     * @return A determinant for this matrix.
+     * @throws CardinalityException Thrown if matrix is not square.
+     */
+    public double determinant();
+
+    /**
+     * Returns the inverse matrix of this matrix
+     *
+     * @return Inverse of this matrix
+     */
+    public Matrix inverse();
+
+    /**
+     * Divides each value in this matrix by the argument.
+     *
+     * @param x Divider value.
+     * @return This matrix.
+     */
+    public Matrix divide(double x);
+
+    /**
+     * Gets the matrix value at the provided location.
+     *
+     * @param row Row index.
+     * @param col Column index.
+     * @return Matrix value.
+     * @throws IndexException Thrown in case of index is out of bound.
+     */
+    public double get(int row, int col);
+
+    /**
+     * Gets the matrix value at the provided location without checking boundaries.
+     * This method is marginally quicker than its {@link #get(int, int)} sibling.
+     *
+     * @param row Row index.
+     * @param col Column index.
+     * @return Matrix value.
+     */
+    public double getX(int row, int col);
+
+    /**
+     * Gets matrix storage model.
+     */
+    public MatrixStorage getStorage();
+
+    /**
+     * Clones this matrix.
+     *
+     * NOTE: new matrix will have the same flavor as the this matrix but a different ID.
+     *
+     * @return New matrix of the same underlying class, the same size and the same values.
+     */
+    public Matrix copy();
+
+    /**
+     * Creates new empty matrix of the same underlying class but of different size.
+     *
+     * NOTE: new matrix will have the same flavor as the this matrix but a different ID.
+     *
+     * @param rows Number of rows for new matrix.
+     * @param cols Number of columns for new matrix.
+     * @return New matrix of the same underlying class and size.
+     */
+    public Matrix like(int rows, int cols);
+
+    /**
+     * Creates new empty vector of compatible properties (similar or the same flavor) to this matrix.
+     *
+     * @param crd Cardinality of the vector.
+     * @return Newly created empty vector "compatible" to this matrix.
+     */
+    public Vector likeVector(int crd);
+
+    /**
+     * Creates new matrix where each value is a difference between corresponding value of this matrix and
+     * passed in argument matrix.
+     *
+     * @param mtx Argument matrix.
+     * @return New matrix of the same underlying class and size.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix minus(Matrix mtx);
+
+    /**
+     * Creates new matrix where each value is a sum of the corresponding value of this matrix and
+     * argument value.
+     *
+     * @param x Value to add.
+     * @return New matrix of the same underlying class and size.
+     */
+    public Matrix plus(double x);
+
+    /**
+     * Creates new matrix where each value is a sum of corresponding values of this matrix and
+     * passed in argument matrix.
+     *
+     * @param mtx Argument matrix.
+     * @return New matrix of the same underlying class and size.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix plus(Matrix mtx);
+
+    /**
+     * Auto-generated globally unique matrix ID.
+     *
+     * @return Matrix GUID.
+     */
+    public IgniteUuid guid();
+
+    /**
+     * Sets given value.
+     *
+     * @param row Row index.
+     * @param col Column index.
+     * @param val Value to set.
+     * @return This matrix.
+     * @throws IndexException Thrown in case of either index is out of bound.
+     */
+    public Matrix set(int row, int col, double val);
+
+    /**
+     * Sets values for given row.
+     *
+     * @param row Row index.
+     * @param data Row data to set.
+     * @return This matrix.
+     * @throws IndexException Thrown in case of index is out of bound.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix setRow(int row, double[] data);
+
+    /**
+     * Sets values for given column.
+     *
+     * @param col Column index.
+     * @param data Column data to set.
+     * @return This matrix.
+     * @throws IndexException Thrown in case of index is out of bound.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix setColumn(int col, double[] data);
+
+    /**
+     * Sets given value without checking for index bounds. This method is marginally faster
+     * than its {@link #set(int, int, double)} sibling.
+     *
+     * @param row Row index.
+     * @param col Column index.
+     * @param val Value to set.
+     * @return This matrix.
+     */
+    public Matrix setX(int row, int col, double val);
+
+    /**
+     * Creates new matrix containing the product of given value and values in this matrix.
+     *
+     * @param x Value to multiply.
+     * @return New matrix.
+     */
+    public Matrix times(double x);
+
+    /**
+     * Creates new matrix that is the product of multiplying this matrix and the argument matrix.
+     *
+     * @param mtx Argument matrix.
+     * @return New matrix.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Matrix times(Matrix mtx);
+
+    /**
+     * Creates new matrix that is the product of multiplying this matrix and the argument vector.
+     *
+     * @param vec Argument vector.
+     * @return New matrix.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector times(Vector vec);
+
+    /**
+     * Gets maximum absolute row sum norm of this matrix.
+     * See http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html
+     *
+     * @return Maximum absolute row sum norm of this matrix.
+     */
+    public double maxAbsRowSumNorm();
+
+    /**
+     * Gets sum of all elements in the matrix.
+     *
+     * @return Sum of all elements in this matrix.
+     */
+    public double sum();
+
+    /**
+     * Creates new matrix that is transpose of this matrix.
+     *
+     * @return New transposed matrix.
+     */
+    public Matrix transpose();
+
+    /**
+     * Creates new view into this matrix. Changes to the view will be propagated to this matrix.
+     *
+     * @param off View offset as <code>int[x,y]</code>.
+     * @param size View size as <code>int[rows, cols]</code>
+     * @return New view.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     * @throws IndexException Thrown in case of offset is out of bound.
+     */
+    public Matrix viewPart(int[] off, int[] size);
+
+    /**
+     * Creates new view into this matrix. Changes to the view will be propagated to this matrix.
+     *
+     * @param rowOff
+     * @param rows
+     * @param colOff
+     * @param cols
+     * @return New view.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     * @throws IndexException Thrown in case of offset is out of bound.
+     */
+    public Matrix viewPart(int rowOff, int rows, int colOff, int cols);
+
+    /**
+     * Creates new view into matrix row. Changes to the view will be propagated to this matrix.
+     *
+     * @param row Row index.
+     * @return New view.
+     * @throws IndexException Thrown in case of index is out of bound.
+     */
+    public Vector viewRow(int row);
+
+    /**
+     * Creates new view into matrix column . Changes to the view will be propagated to this matrix.
+     *
+     * @param col Column index.
+     * @return New view.
+     * @throws IndexException Thrown in case of index is out of bound.
+     */
+    public Vector viewColumn(int col);
+
+    /**
+     * Creates new view into matrix diagonal. Changes to the view will be propagated to this matrix.
+     *
+     * @return New view.
+     */
+    public Vector viewDiagonal();
+
+    /**
+     * Destroys matrix if managed outside of JVM. It's a no-op in all other cases.
+     */
+    public default void destroy() {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixKeyMapper.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixKeyMapper.java
new file mode 100644
index 0000000..54d2088
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixKeyMapper.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Maps {@link Matrix} row and column index to cache key.
+ */
+public interface MatrixKeyMapper<K> extends KeyMapper<K> {
+    /**
+     * @param x Matrix row index.
+     * @param y Matrix column index.
+     * @return Cache key for given row and column.
+     */
+    public K apply(int x, int y);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..ccfebe5
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/MatrixStorage.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.Externalizable;
+
+/**
+ * Data storage support for {@link Matrix}.
+ */
+public interface MatrixStorage extends Externalizable, StorageOpsMetrics, Destroyable {
+    /**
+     * @param x Matrix row index.
+     * @param y Matrix column index.
+     * @return Value corresponding to given row and column.
+     */
+    public double get(int x, int y);
+
+    /**
+     * @param x Matrix row index.
+     * @param y Matrix column index.
+     * @param v Value to set at given row and column.
+     */
+    public void set(int x, int y, double v);
+
+    /**
+     *
+     */
+    public int columnSize();
+
+    /**
+     *
+     */
+    public int rowSize();
+
+    /**
+     * Gets underlying array if {@link StorageOpsMetrics#isArrayBased()} returns {@code true}.
+     *
+     * @see StorageOpsMetrics#isArrayBased()
+     */
+    default public double[][] data() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/MetaAttributes.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/MetaAttributes.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/MetaAttributes.java
new file mode 100644
index 0000000..8befc6a
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/MetaAttributes.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.util.Map;
+
+/**
+ * Interface provides support for meta attributes on vectors and matrices.
+ */
+public interface MetaAttributes {
+    /**
+     * Implementation should return an instance of the map to store meta attributes.
+     */
+    public Map<String, Object> getMetaStorage();
+
+    /**
+     * Gets meta attribute with given name.
+     *
+     * @param name Name of the vector meta attribute to get.
+     * @param <T> Attribute's type.
+     */
+    @SuppressWarnings("unchecked")
+    public default <T> T getAttribute(String name) {
+        return (T)getMetaStorage().get(name);
+    }
+
+    /**
+     * Sets meta attribute with given name and value.
+     *
+     * @param name Name of the meta attribute.
+     * @param val Attribute value.
+     * @param <T> Attribute's type.
+     */
+    public default <T> void setAttribute(String name, T val) {
+        getMetaStorage().put(name, val);
+    }
+
+    /**
+     * Removes meta attribute with given name.
+     *
+     * @param name Name of the meta attribute.
+     * @return {@code true} if attribute was present and was removed, {@code false} otherwise.
+     */
+    public default boolean removeAttribute(String name) {
+        boolean is = getMetaStorage().containsKey(name);
+
+        if (is)
+            getMetaStorage().remove(name);
+
+        return is;
+    }
+
+    /**
+     * Checks if given meta attribute is present.
+     *
+     * @param name Attribute name to check.
+     */
+    public default boolean hasAttribute(String name) {
+        return getMetaStorage().containsKey(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/MurmurHash.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/MurmurHash.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/MurmurHash.java
new file mode 100644
index 0000000..0cbcbdf
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/MurmurHash.java
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * This is a very fast, non-cryptographic hash suitable for general hash-based lookup.
+ *
+ * See http://murmurhash.googlepages.com/ for mre details.
+ */
+public class MurmurHash {
+    /** Hide it. */
+    private MurmurHash() {
+    }
+
+    /**
+     * This produces exactly the same hash values as the final C+ version of MurmurHash3 and is
+     * thus suitable for producing the same hash values across platforms.
+     *
+     * The 32 bit x86 version of this hash should be the fastest variant for relatively short keys like IDs.
+     *
+     * Note - The x86 and x64 versions do _not_ produce the same results, as the algorithms are
+     * optimized for their respective platforms.
+     *
+     * See also http://github.com/yonik/java_util for future updates to this method.
+     *
+     * @param data
+     * @param off
+     * @param len
+     * @param seed
+     * @return 32 bit hash platform compatible with C++ MurmurHash3 implementation on x86.
+     */
+    public static int hash3X86(byte[] data, int off, int len, int seed) {
+        int c1 = 0xcc9e2d51;
+        int c2 = 0x1b873593;
+
+        int h1 = seed;
+        int roundedEnd = off + (len & 0xfffffffc);  // Round down to 4 byte block.
+
+        for (int i = off; i < roundedEnd; i += 4) {
+            int k1 = (data[i] & 0xff) | ((data[i + 1] & 0xff) << 8) | ((data[i + 2] & 0xff) << 16) | (data[i + 3] << 24);
+
+            k1 *= c1;
+            k1 = (k1 << 15) | (k1 >>> 17);
+            k1 *= c2;
+
+            h1 ^= k1;
+            h1 = (h1 << 13) | (h1 >>> 19);
+            h1 = h1 * 5 + 0xe6546b64;
+        }
+
+        // Tail.
+        int k1 = 0;
+
+        switch (len & 0x03) {
+            case 3:
+                k1 = (data[roundedEnd + 2] & 0xff) << 16;
+                // Fallthrough - WTF?
+            case 2:
+                k1 |= (data[roundedEnd + 1] & 0xff) << 8;
+                // Fallthrough - WTF?
+            case 1:
+                k1 |= data[roundedEnd] & 0xff;
+                k1 *= c1;
+                k1 = (k1 << 15) | (k1 >>> 17);
+                k1 *= c2;
+                h1 ^= k1;
+            default:
+        }
+
+        // Finalization.
+        h1 ^= len;
+
+        h1 ^= h1 >>> 16;
+        h1 *= 0x85ebca6b;
+        h1 ^= h1 >>> 13;
+        h1 *= 0xc2b2ae35;
+        h1 ^= h1 >>> 16;
+
+        return h1;
+    }
+
+    /**
+     * Hashes an int.
+     *
+     * @param data The int to hash.
+     * @param seed The seed for the hash.
+     * @return The 32 bit hash of the bytes in question.
+     */
+    public static int hash(int data, int seed) {
+        byte[] arr = new byte[] {
+            (byte)(data >>> 24),
+            (byte)(data >>> 16),
+            (byte)(data >>> 8),
+            (byte)data
+        };
+
+        return hash(ByteBuffer.wrap(arr), seed);
+    }
+
+    /**
+     * Hashes bytes in an array.
+     *
+     * @param data The bytes to hash.
+     * @param seed The seed for the hash.
+     * @return The 32 bit hash of the bytes in question.
+     */
+    public static int hash(byte[] data, int seed) {
+        return hash(ByteBuffer.wrap(data), seed);
+    }
+
+    /**
+     * Hashes bytes in part of an array.
+     *
+     * @param data The data to hash.
+     * @param off Where to start munging.
+     * @param len How many bytes to process.
+     * @param seed The seed to start with.
+     * @return The 32-bit hash of the data in question.
+     */
+    public static int hash(byte[] data, int off, int len, int seed) {
+        return hash(ByteBuffer.wrap(data, off, len), seed);
+    }
+
+    /**
+     * Hashes the bytes in a buffer from the current position to the limit.
+     *
+     * @param buf The bytes to hash.
+     * @param seed The seed for the hash.
+     * @return The 32 bit murmur hash of the bytes in the buffer.
+     */
+    public static int hash(ByteBuffer buf, int seed) {
+        ByteOrder byteOrder = buf.order();
+        buf.order(ByteOrder.LITTLE_ENDIAN);
+
+        int m = 0x5bd1e995;
+        int r = 24;
+
+        int h = seed ^ buf.remaining();
+
+        while (buf.remaining() >= 4) {
+            int k = buf.getInt();
+
+            k *= m;
+            k ^= k >>> r;
+            k *= m;
+
+            h *= m;
+            h ^= k;
+        }
+
+        if (buf.remaining() > 0) {
+            ByteBuffer finish = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
+
+            finish.put(buf).rewind();
+
+            h ^= finish.getInt();
+            h *= m;
+        }
+
+        h ^= h >>> 13;
+        h *= m;
+        h ^= h >>> 15;
+
+        buf.order(byteOrder);
+
+        return h;
+    }
+
+    /**
+     * @param data
+     * @param seed
+     */
+    public static long hash64A(byte[] data, int seed) {
+        return hash64A(ByteBuffer.wrap(data), seed);
+    }
+
+    /**
+     * @param data
+     * @param off
+     * @param len
+     * @param seed
+     */
+    public static long hash64A(byte[] data, int off, int len, int seed) {
+        return hash64A(ByteBuffer.wrap(data, off, len), seed);
+    }
+
+    /**
+     * @param buf
+     * @param seed
+     */
+    public static long hash64A(ByteBuffer buf, int seed) {
+        ByteOrder byteOrder = buf.order();
+        buf.order(ByteOrder.LITTLE_ENDIAN);
+
+        long m = 0xc6a4a7935bd1e995L;
+        int r = 47;
+
+        long h = seed ^ (buf.remaining() * m);
+
+        while (buf.remaining() >= 8) {
+            long k = buf.getLong();
+
+            k *= m;
+            k ^= k >>> r;
+            k *= m;
+
+            h ^= k;
+            h *= m;
+        }
+
+        if (buf.remaining() > 0) {
+            ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
+
+            finish.put(buf).rewind();
+
+            h ^= finish.getLong();
+            h *= m;
+        }
+
+        h ^= h >>> r;
+        h *= m;
+        h ^= h >>> r;
+
+        buf.order(byteOrder);
+
+        return h;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageConstants.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageConstants.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageConstants.java
new file mode 100644
index 0000000..ec2ee65
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageConstants.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Support for different modes of accessing data storage.
+ */
+public interface StorageConstants {
+    /** Storage mode optimized for sequential access. */
+    public static final int SEQUENTIAL_ACCESS_MODE = 1001;
+
+    /** Storage mode optimized for random access. */
+    public static final int RANDOM_ACCESS_MODE = 1002;
+
+    /** Storage mode optimized for row access. */
+    public static final int ROW_STORAGE_MODE = 2001;
+
+    /** Storage mode optimized for column access. */
+    public static final int COLUMN_STORAGE_MODE = 2002;
+
+    /**
+     * @param mode Access mode to verify.
+     */
+    public default void assertAccessMode(int mode) {
+        assert mode == SEQUENTIAL_ACCESS_MODE || mode == RANDOM_ACCESS_MODE;
+    }
+
+    /**
+     * @param mode Storage mode to verify.
+     */
+    public default void assertStorageMode(int mode) {
+        assert mode == ROW_STORAGE_MODE || mode == COLUMN_STORAGE_MODE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageOpsMetrics.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageOpsMetrics.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageOpsMetrics.java
new file mode 100644
index 0000000..aa39481
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/StorageOpsMetrics.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Storage and operation cost characteristics.
+ */
+public interface StorageOpsMetrics {
+    /**
+     * Checks if this implementation should be considered to be iterable in index order in an efficient way.
+     */
+    public boolean isSequentialAccess();
+
+    /**
+     * Checks if this implementation is optimized for random access.
+     */
+    public boolean isRandomAccess();
+
+    /**
+     * Checks if this implementation should be considered dense so that it explicitly
+     * represents every value.
+     */
+    public boolean isDense();
+
+    /**
+     * Checks if implementation is based on Java arrays.
+     */
+    public boolean isArrayBased();
+
+    /**
+     * Checks whether implementation is JVM-local or distributed (multi-JVM).
+     */
+    public boolean isDistributed();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
new file mode 100644
index 0000000..007a8fe
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
@@ -0,0 +1,456 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.awt.Color;
+import java.awt.Desktop;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.Locale;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Utility methods to support output of {@link Vector} and {@link Matrix} instances to plain text or HTML.
+ */
+public class Tracer {
+    /**
+     * Double to color mapper.
+     */
+    public interface ColorMapper extends Function<Double, Color> {
+    }
+
+    /** Continuous red-to-blue color mapping. */
+    static private ColorMapper defaultColorMapper(double min, double max) {
+        double range = max - min;
+
+        return new ColorMapper() {
+            /** {@inheritDoc} */
+            @Override public Color apply(Double d) {
+                int r = (int)Math.round(255 * d);
+                int g = 0;
+                int b = (int)Math.round(255 * (1 - d));
+
+                return new Color(r, g, b);
+            }
+        };
+    }
+
+    /**
+     * Default vector color mapper implementation that map given double value
+     * to continuous red-blue (R_B) specter.
+     *
+     * @param vec Vector to map.
+     * @return {@link ColorMapper} for the given vector.
+     */
+    static private ColorMapper mkVectorColorMapper(Vector vec) {
+        return defaultColorMapper(vec.minValue(), vec.maxValue());
+    }
+
+    /** Default matrix color mapper implementation that map given double value
+     * to continuous red-blue (R_B) specter.
+     * @param mtx Matrix to be mapped.
+     * @return Color mapper for given matrix.
+     */
+    static private ColorMapper mkMatrixColorMapper(Matrix mtx) {
+        return defaultColorMapper(mtx.minValue(), mtx.maxValue());
+    }
+
+    /**
+     * @param vec Vector to show.
+     * @param log {@link IgniteLogger} instance for output.
+     * @param fmt Format string for vector elements.
+     */
+    public static void showAscii(Vector vec, IgniteLogger log, String fmt) {
+        String cls = vec.getClass().getSimpleName();
+
+        log.info(String.format("%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
+    }
+
+    /**
+     * @param vec Vector to show as plain text.
+     * @param log {@link IgniteLogger} instance for output.
+     */
+    public static void showAscii(Vector vec, IgniteLogger log) {
+        showAscii(vec, log, "%4f");
+    }
+
+    /**
+     * @param vec Vector to show as plain text.
+     * @param fmt Format string for vector elements.
+     */
+    public static void showAscii(Vector vec, String fmt) {
+        String cls = vec.getClass().getSimpleName();
+
+        System.out.println(String.format("%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
+    }
+
+    /**
+     * @param mtx Matrix to show as plain text.
+     */
+    public static void showAscii(Matrix mtx) {
+        showAscii(mtx, "%4f");
+    }
+
+    /**
+     * @param mtx Matrix to show.
+     * @param row Matrix row to output.
+     * @param fmt Format string for matrix elements in the row.
+     * @return String representation of given matrix row according to given format.
+     */
+    static private String rowStr(Matrix mtx, int row, String fmt) {
+        StringBuilder buf = new StringBuilder();
+
+        boolean first = true;
+
+        int cols = mtx.columnSize();
+
+        for (int col = 0; col < cols; col++) {
+            String s = String.format(fmt, mtx.get(row, col));
+
+            if (!first)
+                buf.append(", ");
+
+            buf.append(s);
+
+            first = false;
+        }
+
+        return buf.toString();
+    }
+
+    /**
+     * @param mtx {@link Matrix} object to show as a plain text.
+     * @param fmt Format string for matrix rows.
+     */
+    public static void showAscii(Matrix mtx, String fmt) {
+        String cls = mtx.getClass().getSimpleName();
+
+        int rows = mtx.rowSize();
+        int cols = mtx.columnSize();
+
+        System.out.println(String.format("%s(%dx%d)", cls, rows, cols));
+
+        for (int row = 0; row < rows; row++)
+            System.out.println(rowStr(mtx, row, fmt));
+    }
+
+    /**
+     * @param mtx {@link Matrix} object to show as a plain text.
+     * @param log {@link IgniteLogger} instance to output the logged matrix.
+     * @param fmt Format string for matrix rows.
+     */
+    public static void showAscii(Matrix mtx, IgniteLogger log, String fmt) {
+        String cls = mtx.getClass().getSimpleName();
+
+        int rows = mtx.rowSize();
+        int cols = mtx.columnSize();
+
+        log.info(String.format("%s(%dx%d)", cls, rows, cols));
+
+        for (int row = 0; row < rows; row++)
+            log.info(rowStr(mtx, row, fmt));
+    }
+
+    /**
+     * @param vec {@link Vector} object to show as a plain text.
+     */
+    public static void showAscii(Vector vec) {
+        showAscii(vec, "%4f");
+    }
+
+    /**
+     * Saves given vector as CSV file.
+     *
+     * @param vec Vector to save.
+     * @param fmt Format to use.
+     * @param filePath Path of the file to save to.
+     */
+    public static void saveAsCsv(Vector vec, String fmt, String filePath) throws IOException {
+        String s = mkString(vec, fmt);
+
+        Files.write(Paths.get(filePath), s.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
+    }
+
+    /**
+     * Saves given matrix as CSV file.
+     *
+     * @param mtx Matrix to save.
+     * @param fmt Format to use.
+     * @param filePath Path of the file to save to.
+     */
+    public static void saveAsCsv(Matrix mtx, String fmt, String filePath) throws IOException {
+        String s = mkString(mtx, fmt);
+
+        Files.write(Paths.get(filePath), s.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
+    }
+
+    /**
+     * Shows given matrix in the browser with D3-based visualization.
+     *
+     * @param mtx Matrix to show.
+     * @throws IOException Thrown in case of any errors.
+     */
+    public static void showHtml(Matrix mtx) throws IOException {
+        showHtml(mtx, mkMatrixColorMapper(mtx));
+    }
+
+    /**
+     * Shows given matrix in the browser with D3-based visualization.
+     *
+     * @param mtx Matrix to show.
+     * @param cm Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
+     * @throws IOException Thrown in case of any errors.
+     */
+    public static void showHtml(Matrix mtx, ColorMapper cm) throws IOException {
+        // Read it every time so that we can change it at runtime.
+        String tmpl = fileToString("d3-matrix-template.html");
+
+        String cls = mtx.getClass().getSimpleName();
+
+        double min = mtx.minValue();
+        double max = mtx.maxValue();
+
+        openHtmlFile(tmpl.
+            replaceAll("/\\*@NAME@\\*/.*\n", "var name = \"" + cls + "\";\n").
+            replaceAll("/\\*@MIN@\\*/.*\n", "var min = " + dataColorJson(min, cm.apply(min)) + ";\n").
+            replaceAll("/\\*@MAX@\\*/.*\n", "var max = " + dataColorJson(max, cm.apply(max)) + ";\n").
+            replaceAll("/\\*@DATA@\\*/.*\n", "var data = " + mkJsArrayString(mtx, cm) + ";\n")
+        );
+    }
+
+    /**
+     * Shows given vector in the browser with D3-based visualization.
+     *
+     * @param vec Vector to show.
+     * @throws IOException Thrown in case of any errors.
+     */
+    public static void showHtml(Vector vec) throws IOException {
+        showHtml(vec, mkVectorColorMapper(vec));
+    }
+
+    /**
+     * @param d Value of {@link Matrix} or {@link Vector} element.
+     * @param clr {@link Color} to paint.
+     * @return JSON representation for given value and color.
+     */
+    static private String dataColorJson(double d, Color clr) {
+        return "{" +
+            "d: " + String.format("%4f", d) +
+            ", r: " + clr.getRed() +
+            ", g: " + clr.getGreen() +
+            ", b: " + clr.getBlue() +
+            "}";
+    }
+
+    /**
+     * Shows given vector in the browser with D3-based visualization.
+     *
+     * @param vec Vector to show.
+     * @param cm Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
+     * @throws IOException Thrown in case of any errors.
+     */
+    public static void showHtml(Vector vec, ColorMapper cm) throws IOException {
+        // Read it every time so that we can change it at runtime.
+        String tmpl = fileToString("d3-vector-template.html");
+
+        String cls = vec.getClass().getSimpleName();
+
+        double min = vec.minValue();
+        double max = vec.maxValue();
+
+        openHtmlFile(tmpl.
+            replaceAll("/\\*@NAME@\\*/.*\n", "var name = \"" + cls + "\";\n").
+            replaceAll("/\\*@MIN@\\*/.*\n", "var min = " + dataColorJson(min, cm.apply(min)) + ";\n").
+            replaceAll("/\\*@MAX@\\*/.*\n", "var max = " + dataColorJson(max, cm.apply(max)) + ";\n").
+            replaceAll("/\\*@DATA@\\*/.*\n", "var data = " + mkJsArrayString(vec, cm) + ";\n")
+        );
+    }
+
+    /**
+     * Reads file content into the string.
+     *
+     * @param fileName Name of the file (on classpath) to read.
+     * @return Content of the file.
+     * @throws IOException If an I/O error of some sort has occurred.
+     */
+    private static String fileToString(String fileName) throws IOException {
+        assert Tracer.class.getResourceAsStream(fileName) != null : "Can't get resource: " + fileName;
+
+        InputStreamReader is = new InputStreamReader(Tracer.class.getResourceAsStream(fileName));
+
+        String str = new BufferedReader(is).lines().collect(Collectors.joining("\n"));
+
+        is.close();
+
+        return str;
+    }
+
+    /**
+     * Opens file in the browser with given HTML content.
+     *
+     * @param html HTML content.
+     * @throws IOException Thrown in case of any errors.
+     */
+    static private void openHtmlFile(String html) throws IOException {
+        File temp = File.createTempFile(IgniteUuid.randomUuid().toString(), ".html");
+
+        BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
+
+        bw.write(html);
+
+        bw.close();
+
+        Desktop.getDesktop().browse(temp.toURI());
+    }
+
+    /**
+     * Gets string presentation of this vector.
+     *
+     * @param vec Vector to string-ify.
+     * @param fmt {@link String#format(Locale, String, Object...)} format.
+     */
+    private static String mkString(Vector vec, String fmt) {
+        boolean first = true;
+
+        StringBuilder buf = new StringBuilder();
+
+        for (Vector.Element x : vec.all()) {
+            String s = String.format(Locale.US, fmt, x.get());
+
+            if (!first) {
+                buf.append(", ");
+                buf.append(s);
+            }
+            else {
+                buf.append(s);
+                first = false;
+            }
+        }
+
+        return buf.toString();
+    }
+
+    /**
+     * Gets JavaScript array presentation of this vector.
+     *
+     * @param vec Vector to JavaScript-ify.
+     * @param cm Color mapper to user.
+     */
+    private static String mkJsArrayString(Vector vec, ColorMapper cm) {
+        boolean first = true;
+
+        StringBuilder buf = new StringBuilder();
+
+        for (Vector.Element x : vec.all()) {
+            double d = x.get();
+
+            String s = dataColorJson(d, cm.apply(d));
+
+            if (!first)
+                buf.append(", ");
+
+            buf.append(s);
+
+            first = false;
+        }
+
+        return '[' + buf.toString() + ']';
+    }
+
+    /**
+     * Gets JavaScript array presentation of this vector.
+     *
+     * @param mtx Matrix to JavaScript-ify.
+     * @param cm Color mapper to user.
+     */
+    private static String mkJsArrayString(Matrix mtx, ColorMapper cm) {
+        boolean first = true;
+
+        StringBuilder buf = new StringBuilder();
+
+        int rows = mtx.rowSize();
+        int cols = mtx.columnSize();
+
+        for (int row = 0; row < rows; row++) {
+            StringBuilder rowBuf = new StringBuilder();
+
+            boolean rowFirst = true;
+
+            for (int col = 0; col < cols; col++) {
+                double d = mtx.get(row, col);
+
+                String s = dataColorJson(d, cm.apply(d));
+
+                if (!rowFirst)
+                    rowBuf.append(", ");
+
+                rowBuf.append(s);
+
+                rowFirst = false;
+            }
+
+            if (!first)
+                buf.append(", ");
+
+            buf.append('[').append(rowBuf.toString()).append(']');
+
+            first = false;
+        }
+
+        return '[' + buf.toString() + ']';
+    }
+
+    /**
+     * @param mtx Matrix to log.
+     * @param fmt Output format.
+     * @return Formatted representation of a matrix.
+     */
+    private static String mkString(Matrix mtx, String fmt) {
+        StringBuilder buf = new StringBuilder();
+
+        int rows = mtx.rowSize();
+        int cols = mtx.columnSize();
+
+        for (int row = 0; row < rows; row++) {
+            for (int col = 0; col < cols; col++) {
+                String s = String.format(Locale.US, fmt, mtx.get(row, col));
+
+                if (col != 0)
+                    buf.append(", ");
+
+                buf.append(s);
+
+                if (col == cols - 1 && row != rows - 1)
+                    buf.append(",\n");
+
+            }
+        }
+
+        return buf.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/ValueMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/ValueMapper.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/ValueMapper.java
new file mode 100644
index 0000000..2b62c0b
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/ValueMapper.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.Serializable;
+
+/**
+ * Utility mapper that can be used to map arbitrary values types to and from double.
+ */
+public interface ValueMapper<V> extends Serializable {
+    /**
+     * @param v
+     */
+    public V fromDouble(double v);
+
+    /**
+     * @param v
+     */
+    public double toDouble(V v);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..b5e1d69
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Vector.java
@@ -0,0 +1,498 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.Externalizable;
+import java.util.Spliterator;
+import java.util.function.IntToDoubleFunction;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+
+/**
+ * A vector interface.
+ *
+ * Based on its flavor it can have vastly different implementations tailored for
+ * for different types of data (e.g. dense vs. sparse), different sizes of data or different operation
+ * optimizations.
+ *
+ * Note also that not all operations can be supported by all underlying implementations. If an operation is not
+ * supported a {@link UnsupportedOperationException} is thrown. This exception can also be thrown in partial cases
+ * where an operation is unsupported only in special cases, e.g. where a given operation cannot be deterministically
+ * completed in polynomial time.
+ *
+ * Based on ideas from <a href="http://mahout.apache.org/">Apache Mahout</a>.
+ */
+public interface Vector extends MetaAttributes, Externalizable, StorageOpsMetrics, Destroyable {
+    /**
+     * Holder for vector's element.
+     */
+    interface Element {
+        /**
+         * Gets element's value.
+         *
+         * @return The value of this vector element.
+         */
+        double get();
+
+        /**
+         * Gets element's index in the vector.
+         *
+         * @return The index of this vector element.
+         */
+        int index();
+
+        /**
+         * Sets element's value.
+         *
+         * @param val Value to set.
+         */
+        void set(double val);
+    }
+
+    /**
+     * Gets cardinality of this vector (maximum number of the elements).
+     *
+     * @return This vector's cardinality.
+     */
+    public int size();
+
+    /**
+     * Creates new copy of this vector.
+     *
+     * @return New copy vector.
+     */
+    public Vector copy();
+
+    /**
+     * Gets iterator over all elements in this vector.
+     *
+     * NOTE: implementation can choose to reuse {@link Element} instance so you need to copy it
+     * if you want to retain it outside of iteration.
+     *
+     * @return Iterator.
+     */
+    public Iterable<Element> all();
+
+    /**
+     * Iterates ove all non-zero elements in this vector.
+     *
+     * NOTE: implementation can choose to reuse {@link Element} instance so you need to copy it
+     * if you want to retain it outside of iteration.
+     *
+     * @return Iterator.
+     */
+    public Iterable<Element> nonZeroes();
+
+    /**
+     * Gets spliterator for all values in this vector.
+     *
+     * @return Spliterator for all values.
+     */
+    public Spliterator<Double> allSpliterator();
+
+    /**
+     * Gets spliterator for all non-zero values in this vector.
+     *
+     * @return Spliterator for all non-zero values.
+     */
+    public Spliterator<Double> nonZeroSpliterator();
+
+    /**
+     * Sorts this vector in ascending order.
+     */
+    public Vector sort();
+
+    /**
+     * Gets element at the given index.
+     *
+     * NOTE: implementation can choose to reuse {@link Element} instance so you need to copy it
+     * if you want to retain it outside of iteration.
+     *
+     * @param idx Element's index.
+     * @return Vector's element at the given index.
+     * @throws IndexException Throw if index is out of bounds.
+     */
+    public Element getElement(int idx);
+
+    /**
+     * Assigns given value to all elements of this vector.
+     *
+     * @param val Value to assign.
+     * @return This vector.
+     */
+    public Vector assign(double val);
+
+    /**
+     * Assigns values from given array to this vector.
+     *
+     * @param vals Values to assign.
+     * @return This vector.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector assign(double[] vals);
+
+    /**
+     * Copies values from the argument vector to this one.
+     *
+     * @param vec Argument vector.
+     * @return This vector.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector assign(Vector vec);
+
+    /**
+     * Assigns each vector element to the value generated by given function.
+     *
+     * @param fun Function that takes the index and returns value.
+     * @return This vector.
+     */
+    public Vector assign(IntToDoubleFunction fun);
+
+    /**
+     * Maps all values in this vector through a given function.
+     *
+     * @param fun Mapping function.
+     * @return This vector.
+     */
+    public Vector map(IgniteDoubleFunction<Double> fun);
+
+    /**
+     * Maps all values in this vector through a given function.
+     *
+     * For this vector <code>A</code>, argument vector <code>B</code> and the
+     * function <code>F</code> this method maps every element <code>x</code> as:
+     * <code>A(x) = F(A(x), B(x))</code>
+     *
+     * @param vec Argument vector.
+     * @param fun Mapping function.
+     * @return This function.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun);
+
+    /**
+     * Maps all elements of this vector by applying given function to each element with a constant
+     * second parameter <code>y</code>.
+     *
+     * @param fun Mapping function.
+     * @param y Second parameter for mapping function.
+     * @return This vector.
+     */
+    public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y);
+
+    /**
+     * Creates new vector containing values from this vector divided by the argument.
+     *
+     * @param x Division argument.
+     * @return New vector.
+     */
+    public Vector divide(double x);
+
+    /**
+     * Gets dot product of two vectors.
+     *
+     * @param vec Argument vector.
+     * @return Dot product of two vectors.
+     */
+    public double dot(Vector vec);
+
+    /**
+     * Gets the value at specified index.
+     *
+     * @param idx Vector index.
+     * @return Vector value.
+     * @throws IndexException Throw if index is out of bounds.
+     */
+    public double get(int idx);
+
+    /**
+     * Gets the value at specified index without checking for index boundaries.
+     *
+     * @param idx Vector index.
+     * @return Vector value.
+     */
+    public double getX(int idx);
+
+    /**
+     * Creates new empty vector of the same underlying class but of different cardinality.
+     *
+     * @param crd Cardinality for new vector.
+     * @return New vector.
+     */
+    public Vector like(int crd);
+
+    /**
+     * Creates new matrix of compatible flavor with given size.
+     *
+     * @param rows Number of rows.
+     * @param cols Number of columns.
+     * @return New matrix.
+     */
+    public Matrix likeMatrix(int rows, int cols);
+
+    /**
+     * Converts this vector into [N x 1] or [1 x N] matrix where N is this vector cardinality.
+     *
+     * @param rowLike {@code true} for rowLike [N x 1], or {@code false} for column [1 x N] matrix.
+     * @return Newly created matrix.
+     */
+    public Matrix toMatrix(boolean rowLike);
+
+    /**
+     * Converts this vector into [N+1 x 1] or [1 x N+1] matrix where N is this vector cardinality.
+     * (0,0) element of this matrix will be {@code zeroVal} parameter.
+     *
+     * @param rowLike {@code true} for rowLike [N+1 x 1], or {@code false} for column [1 x N+1] matrix.
+     * @return Newly created matrix.
+     */
+    public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal);
+
+    /**
+     * Creates new vector containing element by element difference between this vector and the argument one.
+     *
+     * @param vec Argument vector.
+     * @return New vector.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector minus(Vector vec);
+
+    /**
+     * Creates new vector containing the normalized (L_2 norm) values of this vector.
+     *
+     * @return New vector.
+     */
+    public Vector normalize();
+
+    /**
+     * Creates new vector containing the normalized (L_power norm) values of this vector.
+     * See http://en.wikipedia.org/wiki/Lp_space for details.
+     *
+     * @param power The power to use. Must be >= 0. May also be {@link Double#POSITIVE_INFINITY}.
+     * @return New vector {@code x} such that {@code norm(x, power) == 1}
+     */
+    public Vector normalize(double power);
+
+    /**
+     * Creates new vector containing the {@code log(1 + entry) / L_2 norm} values of this vector.
+     *
+     * @return New vector.
+     */
+    public Vector logNormalize();
+
+    /**
+     * Creates new vector with a normalized value calculated as {@code log_power(1 + entry) / L_power norm}.
+     *
+     * @param power The power to use. Must be > 1. Cannot be {@link Double#POSITIVE_INFINITY}.
+     * @return New vector
+     */
+    public Vector logNormalize(double power);
+
+    /**
+     * Gets the k-norm of the vector. See http://en.wikipedia.org/wiki/Lp_space for more details.
+     *
+     * @param power The power to use.
+     * @see #normalize(double)
+     */
+    public double kNorm(double power);
+
+    /**
+     * Gets minimal value in this vector.
+     *
+     * @return Minimal value.
+     */
+    public double minValue();
+
+    /**
+     * Gets maximum value in this vector.
+     *
+     * @return Maximum c.
+     */
+    public double maxValue();
+
+    /**
+     * Gets minimal element in this vector.
+     *
+     * @return Minimal element.
+     */
+    public Element minElement();
+
+    /**
+     * Gets maximum element in this vector.
+     *
+     * @return Maximum element.
+     */
+    public Element maxElement();
+
+    /**
+     * Creates new vector containing sum of each element in this vector and argument.
+     *
+     * @param x Argument value.
+     * @return New vector.
+     */
+    public Vector plus(double x);
+
+    /**
+     * Creates new vector containing element by element sum from both vectors.
+     *
+     * @param vec Other argument vector to add.
+     * @return New vector.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector plus(Vector vec);
+
+    /**
+     * Sets value.
+     *
+     * @param idx Vector index to set value at.
+     * @param val Value to set.
+     * @return This vector.
+     * @throws IndexException Throw if index is out of bounds.
+     */
+    public Vector set(int idx, double val);
+
+    /**
+     * Sets value without checking for index boundaries.
+     *
+     * @param idx Vector index to set value at.
+     * @param val Value to set.
+     * @return This vector.
+     */
+    public Vector setX(int idx, double val);
+
+    /**
+     * Increments value at given index without checking for index boundaries.
+     *
+     * @param idx Vector index.
+     * @param val Increment value.
+     * @return This vector.
+     */
+    public Vector incrementX(int idx, double val);
+
+    /**
+     * Increments value at given index.
+     *
+     * @param idx Vector index.
+     * @param val Increment value.
+     * @return This vector.
+     * @throws IndexException Throw if index is out of bounds.
+     */
+    public Vector increment(int idx, double val);
+
+    /**
+     * Gets number of non-zero elements in this vector.
+     *
+     * @return Number of non-zero elements in this vector.
+     */
+    public int nonZeroElements();
+
+    /**
+     * Gets a new vector that contains product of each element and the argument.
+     *
+     * @param x Multiply argument.
+     * @return New vector.
+     */
+    public Vector times(double x);
+
+    /**
+     * Gets a new vector that is an element-wie product of this vector and the argument.
+     *
+     * @param vec Vector to multiply by.
+     * @return New vector.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public Vector times(Vector vec);
+
+    /**
+     * @param off Offset into parent vector.
+     * @param len Length of the view.
+     */
+    public Vector viewPart(int off, int len);
+
+    /**
+     * Gets vector storage model.
+     */
+    public VectorStorage getStorage();
+
+    /**
+     * Gets the sum of all elements in this vector.
+     *
+     * @return Vector's sum
+     */
+    public double sum();
+
+    /**
+     * Gets the cross product of this vector and the other vector.
+     *
+     * @param vec Second vector.
+     * @return New matrix as a cross product of two vectors.
+     */
+    public Matrix cross(Vector vec);
+
+    /**
+     * Folds this vector into a single value.
+     *
+     * @param foldFun Folding function that takes two parameters: accumulator and the current value.
+     * @param mapFun Mapping function that is called on each vector element before its passed to the accumulator (as its
+     * second parameter).
+     * @param <T> Type of the folded value.
+     * @param zeroVal Zero value for fold operation.
+     * @return Folded value of this vector.
+     */
+    public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal);
+
+    /**
+     * Combines & maps two vector and folds them into a single value.
+     *
+     * @param vec Another vector to combine with.
+     * @param foldFun Folding function.
+     * @param combFun Combine function.
+     * @param <T> Type of the folded value.
+     * @param zeroVal Zero value for fold operation.
+     * @return Folded value of these vectors.
+     * @throws CardinalityException Thrown when cardinalities mismatch.
+     */
+    public <T> T foldMap(Vector vec, IgniteBiFunction<T, Double, T> foldFun, IgniteBiFunction<Double, Double, Double> combFun,
+        T zeroVal);
+
+    /**
+     * Gets the sum of squares of all elements in this vector.
+     *
+     * @return Length squared value.
+     */
+    public double getLengthSquared();
+
+    /**
+     * Get the square of the distance between this vector and the argument vector.
+     *
+     * @param vec Another vector.
+     * @return Distance squared.
+     * @throws CardinalityException Thrown if cardinalities mismatch.
+     */
+    public double getDistanceSquared(Vector vec);
+
+    /**
+     * Auto-generated globally unique vector ID.
+     *
+     * @return Vector GUID.
+     */
+    public IgniteUuid guid();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorKeyMapper.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorKeyMapper.java
new file mode 100644
index 0000000..4b8fadb
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorKeyMapper.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+/**
+ * Maps {@link Vector} element index to cache key.
+ */
+public interface VectorKeyMapper<K> extends KeyMapper<K> {
+    /**
+     * @param i Vector element index.
+     * @return Cache key for given element index.
+     */
+    public K apply(int i);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorStorage.java
new file mode 100644
index 0000000..3b66e4f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorStorage.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math;
+
+import java.io.Externalizable;
+
+/**
+ * Data storage support for {@link Vector}.
+ */
+public interface VectorStorage extends Externalizable, StorageOpsMetrics, Destroyable {
+    /**
+     *
+     *
+     */
+    public int size();
+
+    /**
+     * @param i Vector element index.
+     * @return Value obtained for given element index.
+     */
+    public double get(int i);
+
+    /**
+     * @param i Vector element index.
+     * @param v Value to set at given index.
+     */
+    public void set(int i, double v);
+
+    /**
+     * Gets underlying array if {@link StorageOpsMetrics#isArrayBased()} returns {@code true}.
+     * Returns {@code null} if in other cases.
+     *
+     * @see StorageOpsMetrics#isArrayBased()
+     */
+    public default double[] data() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/CholeskyDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/CholeskyDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/CholeskyDecomposition.java
new file mode 100644
index 0000000..bc18307
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/CholeskyDecomposition.java
@@ -0,0 +1,306 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.NonPositiveDefiniteMatrixException;
+import org.apache.ignite.ml.math.exceptions.NonSymmetricMatrixException;
+
+/**
+ * Calculates the Cholesky decomposition of a matrix.
+ *
+ * This class inspired by class from Apache Common Math with similar name.
+ *
+ * @see <a href="http://mathworld.wolfram.com/CholeskyDecomposition.html">MathWorld</a>
+ * @see <a href="http://en.wikipedia.org/wiki/Cholesky_decomposition">Wikipedia</a>
+ */
+public class CholeskyDecomposition extends DecompositionSupport {
+    /**
+     * Default threshold above which off-diagonal elements are considered too different
+     * and matrix not symmetric.
+     */
+    public static final double DFLT_REL_SYMMETRY_THRESHOLD = 1.0e-15;
+
+    /**
+     * Default threshold below which diagonal elements are considered null
+     * and matrix not positive definite.
+     */
+    public static final double DFLT_ABS_POSITIVITY_THRESHOLD = 1.0e-10;
+
+    /** Row-oriented storage for L<sup>T</sup> matrix data. */
+    private double[][] lTData;
+    /** Cached value of L. */
+    private Matrix cachedL;
+    /** Cached value of LT. */
+    private Matrix cachedLT;
+    /** Origin matrix */
+    private Matrix origin;
+
+    /**
+     * Calculates the Cholesky decomposition of the given matrix.
+     *
+     * Calling this constructor is equivalent to call {@link #CholeskyDecomposition(Matrix, double, double)} with the
+     * thresholds set to the default values {@link #DFLT_REL_SYMMETRY_THRESHOLD} and
+     * {@link #DFLT_ABS_POSITIVITY_THRESHOLD}.
+     *
+     * @param mtx the matrix to decompose.
+     * @throws CardinalityException if matrix is not square.
+     * @see #CholeskyDecomposition(Matrix, double, double)
+     * @see #DFLT_REL_SYMMETRY_THRESHOLD
+     * @see #DFLT_ABS_POSITIVITY_THRESHOLD
+     */
+    public CholeskyDecomposition(final Matrix mtx) {
+        this(mtx, DFLT_REL_SYMMETRY_THRESHOLD, DFLT_ABS_POSITIVITY_THRESHOLD);
+    }
+
+    /**
+     * Calculates the Cholesky decomposition of the given matrix.
+     *
+     * @param mtx the matrix to decompose.
+     * @param relSymmetryThreshold threshold above which off-diagonal elements are considered too different and matrix
+     * not symmetric
+     * @param absPositivityThreshold threshold below which diagonal elements are considered null and matrix not positive
+     * definite
+     * @see #CholeskyDecomposition(Matrix)
+     * @see #DFLT_REL_SYMMETRY_THRESHOLD
+     * @see #DFLT_ABS_POSITIVITY_THRESHOLD
+     */
+    public CholeskyDecomposition(final Matrix mtx, final double relSymmetryThreshold,
+        final double absPositivityThreshold) {
+        assert mtx != null;
+
+        if (mtx.columnSize() != mtx.rowSize())
+            throw new CardinalityException(mtx.rowSize(), mtx.columnSize());
+
+        origin = mtx;
+
+        final int order = mtx.rowSize();
+
+        lTData = toDoubleArr(mtx);
+        cachedL = null;
+        cachedLT = null;
+
+        // Check the matrix before transformation.
+        for (int i = 0; i < order; ++i) {
+            final double[] lI = lTData[i];
+
+            // Check off-diagonal elements (and reset them to 0).
+            for (int j = i + 1; j < order; ++j) {
+                final double[] lJ = lTData[j];
+
+                final double lIJ = lI[j];
+                final double lJI = lJ[i];
+
+                final double maxDelta = relSymmetryThreshold * Math.max(Math.abs(lIJ), Math.abs(lJI));
+
+                if (Math.abs(lIJ - lJI) > maxDelta)
+                    throw new NonSymmetricMatrixException(i, j, relSymmetryThreshold);
+
+                lJ[i] = 0;
+            }
+        }
+
+        // Transform the matrix.
+        for (int i = 0; i < order; ++i) {
+            final double[] ltI = lTData[i];
+
+            // Check diagonal element.
+            if (ltI[i] <= absPositivityThreshold)
+                throw new NonPositiveDefiniteMatrixException(ltI[i], i, absPositivityThreshold);
+
+            ltI[i] = Math.sqrt(ltI[i]);
+            final double inverse = 1.0 / ltI[i];
+
+            for (int q = order - 1; q > i; --q) {
+                ltI[q] *= inverse;
+                final double[] ltQ = lTData[q];
+
+                for (int p = q; p < order; ++p)
+                    ltQ[p] -= ltI[q] * ltI[p];
+            }
+        }
+    }
+
+    /** */
+    @Override public void destroy() {
+        if (cachedL != null)
+            cachedL.destroy();
+        if (cachedLT != null)
+            cachedLT.destroy();
+    }
+
+    /**
+     * Returns the matrix L of the decomposition.
+     * <p>L is an lower-triangular matrix</p>
+     *
+     * @return the L matrix
+     */
+    public Matrix getL() {
+        if (cachedL == null)
+            cachedL = getLT().transpose();
+
+        return cachedL;
+    }
+
+    /**
+     * Returns the transpose of the matrix L of the decomposition.
+     * <p>L<sup>T</sup> is an upper-triangular matrix</p>
+     *
+     * @return the transpose of the matrix L of the decomposition
+     */
+    public Matrix getLT() {
+
+        if (cachedLT == null) {
+            Matrix like = like(origin, origin.rowSize(), origin.columnSize());
+            like.assign(lTData);
+
+            cachedLT = like;
+        }
+
+        // return the cached matrix
+        return cachedLT;
+    }
+
+    /**
+     * Return the determinant of the matrix
+     *
+     * @return determinant of the matrix
+     */
+    public double getDeterminant() {
+        double determinant = 1.0;
+
+        for (int i = 0; i < lTData.length; ++i) {
+            double lTii = lTData[i][i];
+            determinant *= lTii * lTii;
+        }
+
+        return determinant;
+    }
+
+    /**
+     * Solve the linear equation A &times; X = B for matrices A.
+     *
+     * @param b right-hand side of the equation A &times; X = B
+     * @return a vector X that minimizes the two norm of A &times; X - B
+     * @throws CardinalityException if the vectors dimensions do not match
+     */
+    public Vector solve(final Vector b) {
+        final int m = lTData.length;
+
+        if (b.size() != m)
+            throw new CardinalityException(b.size(), m);
+
+        final double[] x = b.getStorage().data();
+
+        // Solve LY = b
+        for (int j = 0; j < m; j++) {
+            final double[] lJ = lTData[j];
+
+            x[j] /= lJ[j];
+
+            final double xJ = x[j];
+
+            for (int i = j + 1; i < m; i++)
+                x[i] -= xJ * lJ[i];
+        }
+
+        // Solve LTX = Y
+        for (int j = m - 1; j >= 0; j--) {
+            x[j] /= lTData[j][j];
+
+            final double xJ = x[j];
+
+            for (int i = 0; i < j; i++)
+                x[i] -= xJ * lTData[i][j];
+        }
+
+        return likeVector(origin, m).assign(x);
+    }
+
+    /**
+     * Solve the linear equation A &times; X = B for matrices A.
+     *
+     * @param b right-hand side of the equation A &times; X = B
+     * @return a matrix X that minimizes the two norm of A &times; X - B
+     * @throws CardinalityException if the matrices dimensions do not match
+     */
+    public Matrix solve(final Matrix b) {
+        final int m = lTData.length;
+
+        if (b.rowSize() != m)
+            throw new CardinalityException(b.rowSize(), m);
+
+        final int nColB = b.columnSize();
+        final double[][] x = b.getStorage().data();
+
+        // Solve LY = b
+        for (int j = 0; j < m; j++) {
+            final double[] lJ = lTData[j];
+            final double lJJ = lJ[j];
+            final double[] xJ = x[j];
+
+            for (int k = 0; k < nColB; ++k)
+                xJ[k] /= lJJ;
+
+            for (int i = j + 1; i < m; i++) {
+                final double[] xI = x[i];
+                final double lJI = lJ[i];
+
+                for (int k = 0; k < nColB; ++k)
+                    xI[k] -= xJ[k] * lJI;
+            }
+        }
+
+        // Solve LTX = Y
+        for (int j = m - 1; j >= 0; j--) {
+            final double lJJ = lTData[j][j];
+            final double[] xJ = x[j];
+
+            for (int k = 0; k < nColB; ++k)
+                xJ[k] /= lJJ;
+
+            for (int i = 0; i < j; i++) {
+                final double[] xI = x[i];
+                final double lIJ = lTData[i][j];
+
+                for (int k = 0; k < nColB; ++k)
+                    xI[k] -= xJ[k] * lIJ;
+            }
+        }
+
+        return like(origin, m, b.columnSize()).assign(x);
+    }
+
+    /** */
+    private double[][] toDoubleArr(Matrix mtx) {
+        if (mtx.isArrayBased())
+            return mtx.getStorage().data();
+
+        double[][] res = new double[mtx.rowSize()][];
+
+        for (int row = 0; row < mtx.rowSize(); row++) {
+            res[row] = new double[mtx.columnSize()];
+            for (int col = 0; col < mtx.columnSize(); col++)
+                res[row][col] = mtx.get(row, col);
+        }
+
+        return res;
+    }
+}


[26/50] [abbrv] ignite git commit: Merge remote-tracking branch 'origin/ignite-2.0' into ignite-2.0

Posted by sb...@apache.org.
Merge remote-tracking branch 'origin/ignite-2.0' into ignite-2.0


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

Branch: refs/heads/ignite-1561
Commit: 43d6d7e7eb9eb146c48b843293849ac687ead216
Parents: d60cf53 d78e071
Author: sboikov <sb...@gridgain.com>
Authored: Tue Apr 18 16:50:45 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Apr 18 16:50:45 2017 +0300

----------------------------------------------------------------------
 examples/pom-standalone-lgpl.xml                |    4 -
 examples/pom-standalone.xml                     |    4 -
 examples/pom.xml                                |    4 -
 .../CholeskyDecompositionExample.java           |    8 +-
 .../EigenDecompositionExample.java              |    8 +-
 .../decompositions/LUDecompositionExample.java  |    8 +-
 .../SingularValueDecompositionExample.java      |    6 +-
 .../ml/math/matrix/CacheMatrixExample.java      |   10 +-
 .../ml/math/matrix/ExampleMatrixStorage.java    |    4 +-
 .../math/matrix/MatrixCustomStorageExample.java |   12 +-
 .../examples/ml/math/matrix/MatrixExample.java  |    4 +-
 .../ml/math/matrix/MatrixExampleUtil.java       |    4 +-
 .../ml/math/matrix/OffHeapMatrixExample.java    |    4 +-
 .../matrix/SparseDistributedMatrixExample.java  |    5 +-
 .../ml/math/matrix/SparseMatrixExample.java     |    4 +-
 .../examples/ml/math/tracer/TracerExample.java  |    4 +-
 .../ml/math/vector/CacheVectorExample.java      |    8 +-
 .../ml/math/vector/ExampleVectorStorage.java    |    4 +-
 .../ml/math/vector/OffHeapVectorExample.java    |    4 +-
 .../ml/math/vector/SparseVectorExample.java     |    6 +-
 .../math/vector/VectorCustomStorageExample.java |   14 +-
 .../examples/ml/math/vector/VectorExample.java  |    4 +-
 modules/ml/pom.xml                              |    6 -
 .../java/org/apache/ignite/math/Algebra.java    |  571 ---------
 .../java/org/apache/ignite/math/Constants.java  |   42 -
 .../org/apache/ignite/math/Destroyable.java     |   30 -
 .../apache/ignite/math/IdentityValueMapper.java |   53 -
 .../java/org/apache/ignite/math/KeyMapper.java  |   33 -
 .../java/org/apache/ignite/math/Matrix.java     |  518 --------
 .../org/apache/ignite/math/MatrixKeyMapper.java |   30 -
 .../org/apache/ignite/math/MatrixStorage.java   |   58 -
 .../org/apache/ignite/math/MetaAttributes.java  |   76 --
 .../java/org/apache/ignite/math/MurmurHash.java |  246 ----
 .../apache/ignite/math/StorageConstants.java    |   49 -
 .../apache/ignite/math/StorageOpsMetrics.java   |   49 -
 .../java/org/apache/ignite/math/Tracer.java     |  456 -------
 .../org/apache/ignite/math/ValueMapper.java     |   27 -
 .../java/org/apache/ignite/math/Vector.java     |  498 --------
 .../org/apache/ignite/math/VectorKeyMapper.java |   29 -
 .../org/apache/ignite/math/VectorStorage.java   |   53 -
 .../decompositions/CholeskyDecomposition.java   |  306 -----
 .../decompositions/DecompositionSupport.java    |  105 --
 .../math/decompositions/EigenDecomposition.java |  923 ---------------
 .../math/decompositions/LUDecomposition.java    |  366 ------
 .../math/decompositions/QRDecomposition.java    |  186 ---
 .../SingularValueDecomposition.java             |  620 ----------
 .../math/decompositions/package-info.java       |   22 -
 .../math/exceptions/CardinalityException.java   |   38 -
 .../math/exceptions/ColumnIndexException.java   |   35 -
 .../ignite/math/exceptions/IndexException.java  |   35 -
 .../NonPositiveDefiniteMatrixException.java     |   20 -
 .../exceptions/NonSymmetricMatrixException.java |   18 -
 .../math/exceptions/RowIndexException.java      |   35 -
 .../exceptions/SingularMatrixException.java     |   30 -
 .../exceptions/UnknownProviderException.java    |   35 -
 .../UnsupportedOperationException.java          |   44 -
 .../ignite/math/exceptions/package-info.java    |   22 -
 .../apache/ignite/math/functions/Functions.java |  136 ---
 .../ignite/math/functions/IgniteBiConsumer.java |   12 -
 .../ignite/math/functions/IgniteBiFunction.java |   29 -
 .../ignite/math/functions/IgniteConsumer.java   |   29 -
 .../math/functions/IgniteDoubleFunction.java    |   29 -
 .../ignite/math/functions/IgniteFunction.java   |   30 -
 .../math/functions/IntDoubleToVoidFunction.java |   25 -
 .../functions/IntIntDoubleToVoidFunction.java   |   28 -
 .../math/functions/IntIntToDoubleFunction.java  |   24 -
 .../ignite/math/functions/package-info.java     |   22 -
 .../apache/ignite/math/impls/CacheUtils.java    |  356 ------
 .../math/impls/matrix/AbstractMatrix.java       |  880 --------------
 .../ignite/math/impls/matrix/CacheMatrix.java   |  158 ---
 .../impls/matrix/DenseLocalOffHeapMatrix.java   |   90 --
 .../impls/matrix/DenseLocalOnHeapMatrix.java    |   86 --
 .../math/impls/matrix/DiagonalMatrix.java       |  101 --
 .../math/impls/matrix/FunctionMatrix.java       |   95 --
 .../ignite/math/impls/matrix/MatrixView.java    |   84 --
 .../math/impls/matrix/PivotedMatrixView.java    |  243 ----
 .../ignite/math/impls/matrix/RandomMatrix.java  |   97 --
 .../impls/matrix/SparseDistributedMatrix.java   |  155 ---
 .../impls/matrix/SparseLocalOnHeapMatrix.java   |   72 --
 .../math/impls/matrix/TransposedMatrixView.java |   84 --
 .../ignite/math/impls/matrix/package-info.java  |   22 -
 .../apache/ignite/math/impls/package-info.java  |   22 -
 .../storage/matrix/ArrayMatrixStorage.java      |  161 ---
 .../storage/matrix/CacheMatrixStorage.java      |  180 ---
 .../matrix/DenseOffHeapMatrixStorage.java       |  197 ----
 .../storage/matrix/DiagonalMatrixStorage.java   |  136 ---
 .../storage/matrix/FunctionMatrixStorage.java   |  175 ---
 .../storage/matrix/MatrixDelegateStorage.java   |  205 ----
 .../storage/matrix/PivotedMatrixStorage.java    |  256 ----
 .../storage/matrix/RandomMatrixStorage.java     |  176 ---
 .../matrix/SparseDistributedMatrixStorage.java  |  281 -----
 .../matrix/SparseLocalOnHeapMatrixStorage.java  |  226 ----
 .../math/impls/storage/matrix/package-info.java |   22 -
 .../storage/vector/ArrayVectorStorage.java      |  135 ---
 .../storage/vector/CacheVectorStorage.java      |  175 ---
 .../storage/vector/ConstantVectorStorage.java   |  133 ---
 .../storage/vector/DelegateVectorStorage.java   |  157 ---
 .../vector/DenseLocalOffHeapVectorStorage.java  |  172 ---
 .../storage/vector/FunctionVectorStorage.java   |  141 ---
 .../storage/vector/MatrixVectorStorage.java     |  185 ---
 .../storage/vector/PivotedVectorStorage.java    |  175 ---
 .../storage/vector/RandomVectorStorage.java     |  152 ---
 .../SingleElementVectorDelegateStorage.java     |  145 ---
 .../vector/SingleElementVectorStorage.java      |  143 ---
 .../vector/SparseLocalOffHeapVectorStorage.java |  148 ---
 .../vector/SparseLocalOnHeapVectorStorage.java  |  152 ---
 .../math/impls/storage/vector/package-info.java |   22 -
 .../impls/vector/AbstractReadOnlyVector.java    |  108 --
 .../math/impls/vector/AbstractVector.java       |  903 --------------
 .../ignite/math/impls/vector/CacheVector.java   |  140 ---
 .../math/impls/vector/ConstantVector.java       |   84 --
 .../math/impls/vector/DelegatingVector.java     |  391 ------
 .../impls/vector/DenseLocalOffHeapVector.java   |   89 --
 .../impls/vector/DenseLocalOnHeapVector.java    |  104 --
 .../math/impls/vector/FunctionVector.java       |  112 --
 .../math/impls/vector/MatrixVectorView.java     |  139 ---
 .../math/impls/vector/PivotedVectorView.java    |  163 ---
 .../ignite/math/impls/vector/RandomVector.java  |  128 --
 .../math/impls/vector/SingleElementVector.java  |  102 --
 .../impls/vector/SingleElementVectorView.java   |   97 --
 .../impls/vector/SparseLocalOffHeapVector.java  |   47 -
 .../math/impls/vector/SparseLocalVector.java    |   71 --
 .../ignite/math/impls/vector/VectorView.java    |   85 --
 .../ignite/math/impls/vector/package-info.java  |   22 -
 .../org/apache/ignite/math/package-info.java    |   22 -
 .../java/org/apache/ignite/ml/math/Algebra.java |  571 +++++++++
 .../org/apache/ignite/ml/math/Constants.java    |   42 +
 .../org/apache/ignite/ml/math/Destroyable.java  |   30 +
 .../ignite/ml/math/IdentityValueMapper.java     |   53 +
 .../org/apache/ignite/ml/math/KeyMapper.java    |   33 +
 .../java/org/apache/ignite/ml/math/Matrix.java  |  518 ++++++++
 .../apache/ignite/ml/math/MatrixKeyMapper.java  |   30 +
 .../apache/ignite/ml/math/MatrixStorage.java    |   58 +
 .../apache/ignite/ml/math/MetaAttributes.java   |   76 ++
 .../org/apache/ignite/ml/math/MurmurHash.java   |  246 ++++
 .../apache/ignite/ml/math/StorageConstants.java |   49 +
 .../ignite/ml/math/StorageOpsMetrics.java       |   49 +
 .../java/org/apache/ignite/ml/math/Tracer.java  |  456 +++++++
 .../org/apache/ignite/ml/math/ValueMapper.java  |   35 +
 .../java/org/apache/ignite/ml/math/Vector.java  |  498 ++++++++
 .../apache/ignite/ml/math/VectorKeyMapper.java  |   29 +
 .../apache/ignite/ml/math/VectorStorage.java    |   53 +
 .../decompositions/CholeskyDecomposition.java   |  306 +++++
 .../decompositions/DecompositionSupport.java    |  105 ++
 .../math/decompositions/EigenDecomposition.java |  923 +++++++++++++++
 .../ml/math/decompositions/LUDecomposition.java |  366 ++++++
 .../ml/math/decompositions/QRDecomposition.java |  186 +++
 .../SingularValueDecomposition.java             |  620 ++++++++++
 .../ml/math/decompositions/package-info.java    |   22 +
 .../math/exceptions/CardinalityException.java   |   38 +
 .../math/exceptions/ColumnIndexException.java   |   35 +
 .../ml/math/exceptions/IndexException.java      |   35 +
 .../NonPositiveDefiniteMatrixException.java     |   37 +
 .../exceptions/NonSymmetricMatrixException.java |   35 +
 .../ml/math/exceptions/RowIndexException.java   |   35 +
 .../exceptions/SingularMatrixException.java     |   30 +
 .../exceptions/UnknownProviderException.java    |   35 +
 .../UnsupportedOperationException.java          |   44 +
 .../ignite/ml/math/exceptions/package-info.java |   22 +
 .../ignite/ml/math/functions/Functions.java     |  136 +++
 .../ml/math/functions/IgniteBiConsumer.java     |   29 +
 .../ml/math/functions/IgniteBiFunction.java     |   29 +
 .../ml/math/functions/IgniteConsumer.java       |   29 +
 .../ml/math/functions/IgniteDoubleFunction.java |   29 +
 .../ml/math/functions/IgniteFunction.java       |   30 +
 .../math/functions/IntDoubleToVoidFunction.java |   25 +
 .../functions/IntIntDoubleToVoidFunction.java   |   28 +
 .../math/functions/IntIntToDoubleFunction.java  |   24 +
 .../ignite/ml/math/functions/package-info.java  |   22 +
 .../apache/ignite/ml/math/impls/CacheUtils.java |  356 ++++++
 .../ml/math/impls/matrix/AbstractMatrix.java    |  880 ++++++++++++++
 .../ml/math/impls/matrix/CacheMatrix.java       |  158 +++
 .../impls/matrix/DenseLocalOffHeapMatrix.java   |   90 ++
 .../impls/matrix/DenseLocalOnHeapMatrix.java    |   86 ++
 .../ml/math/impls/matrix/DiagonalMatrix.java    |  101 ++
 .../ml/math/impls/matrix/FunctionMatrix.java    |   95 ++
 .../ignite/ml/math/impls/matrix/MatrixView.java |   84 ++
 .../ml/math/impls/matrix/PivotedMatrixView.java |  243 ++++
 .../ml/math/impls/matrix/RandomMatrix.java      |   97 ++
 .../impls/matrix/SparseDistributedMatrix.java   |  155 +++
 .../impls/matrix/SparseLocalOnHeapMatrix.java   |   72 ++
 .../math/impls/matrix/TransposedMatrixView.java |   84 ++
 .../ml/math/impls/matrix/package-info.java      |   22 +
 .../ignite/ml/math/impls/package-info.java      |   22 +
 .../storage/matrix/ArrayMatrixStorage.java      |  161 +++
 .../storage/matrix/CacheMatrixStorage.java      |  180 +++
 .../matrix/DenseOffHeapMatrixStorage.java       |  197 ++++
 .../storage/matrix/DiagonalMatrixStorage.java   |  136 +++
 .../storage/matrix/FunctionMatrixStorage.java   |  175 +++
 .../storage/matrix/MatrixDelegateStorage.java   |  205 ++++
 .../storage/matrix/PivotedMatrixStorage.java    |  256 ++++
 .../storage/matrix/RandomMatrixStorage.java     |  176 +++
 .../matrix/SparseDistributedMatrixStorage.java  |  290 +++++
 .../matrix/SparseLocalOnHeapMatrixStorage.java  |  226 ++++
 .../math/impls/storage/matrix/package-info.java |   22 +
 .../storage/vector/ArrayVectorStorage.java      |  135 +++
 .../storage/vector/CacheVectorStorage.java      |  175 +++
 .../storage/vector/ConstantVectorStorage.java   |  133 +++
 .../storage/vector/DelegateVectorStorage.java   |  157 +++
 .../vector/DenseLocalOffHeapVectorStorage.java  |  172 +++
 .../storage/vector/FunctionVectorStorage.java   |  141 +++
 .../storage/vector/MatrixVectorStorage.java     |  185 +++
 .../storage/vector/PivotedVectorStorage.java    |  175 +++
 .../storage/vector/RandomVectorStorage.java     |  152 +++
 .../SingleElementVectorDelegateStorage.java     |  145 +++
 .../vector/SingleElementVectorStorage.java      |  143 +++
 .../vector/SparseLocalOffHeapVectorStorage.java |  149 +++
 .../vector/SparseLocalOnHeapVectorStorage.java  |  152 +++
 .../math/impls/storage/vector/package-info.java |   22 +
 .../impls/vector/AbstractReadOnlyVector.java    |  125 ++
 .../ml/math/impls/vector/AbstractVector.java    |  903 ++++++++++++++
 .../ml/math/impls/vector/CacheVector.java       |  140 +++
 .../ml/math/impls/vector/ConstantVector.java    |   84 ++
 .../ml/math/impls/vector/DelegatingVector.java  |  391 ++++++
 .../impls/vector/DenseLocalOffHeapVector.java   |   89 ++
 .../impls/vector/DenseLocalOnHeapVector.java    |  104 ++
 .../ml/math/impls/vector/FunctionVector.java    |  112 ++
 .../ml/math/impls/vector/MatrixVectorView.java  |  139 +++
 .../ml/math/impls/vector/PivotedVectorView.java |  163 +++
 .../ml/math/impls/vector/RandomVector.java      |  129 ++
 .../math/impls/vector/SingleElementVector.java  |  102 ++
 .../impls/vector/SingleElementVectorView.java   |   97 ++
 .../impls/vector/SparseLocalOffHeapVector.java  |   47 +
 .../ml/math/impls/vector/SparseLocalVector.java |   71 ++
 .../ignite/ml/math/impls/vector/VectorView.java |   85 ++
 .../ml/math/impls/vector/package-info.java      |   22 +
 .../org/apache/ignite/ml/math/package-info.java |   22 +
 .../apache/ignite/math/d3-matrix-template.html  |  128 --
 .../apache/ignite/math/d3-vector-template.html  |  111 --
 .../ignite/ml/math/d3-matrix-template.html      |  128 ++
 .../ignite/ml/math/d3-vector-template.html      |  111 ++
 .../org/apache/ignite/math/ExternalizeTest.java |   66 --
 .../math/MathImplDistributedTestSuite.java      |   39 -
 .../ignite/math/MathImplLocalTestSuite.java     |  123 --
 .../ignite/math/MathImplMainTestSuite.java      |   33 -
 .../java/org/apache/ignite/math/TracerTest.java |  195 ---
 .../ignite/math/benchmark/MathBenchmark.java    |  205 ----
 .../math/benchmark/MathBenchmarkSelfTest.java   |  100 --
 .../ignite/math/benchmark/ResultsWriter.java    |  127 --
 .../math/benchmark/VectorBenchmarkTest.java     |  138 ---
 .../ignite/math/benchmark/package-info.java     |   18 -
 .../CholeskyDecompositionTest.java              |  158 ---
 .../decompositions/EigenDecompositionTest.java  |  193 ---
 .../decompositions/LUDecompositionTest.java     |  250 ----
 .../decompositions/QRDecompositionTest.java     |  139 ---
 .../SingularValueDecompositionTest.java         |  120 --
 .../ignite/math/impls/MathTestConstants.java    |   88 --
 .../math/impls/matrix/CacheMatrixTest.java      |  369 ------
 .../DenseLocalOffHeapMatrixConstructorTest.java |   65 -
 .../DenseLocalOnHeapMatrixConstructorTest.java  |   71 --
 .../math/impls/matrix/DiagonalMatrixTest.java   |  209 ----
 .../matrix/FunctionMatrixConstructorTest.java   |  113 --
 .../math/impls/matrix/MatrixAttributeTest.java  |  156 ---
 .../matrix/MatrixImplementationFixtures.java    |  381 ------
 .../impls/matrix/MatrixImplementationsTest.java | 1113 ------------------
 .../impls/matrix/MatrixKeyMapperForTests.java   |   69 --
 .../impls/matrix/MatrixViewConstructorTest.java |  114 --
 .../PivotedMatrixViewConstructorTest.java       |  128 --
 .../matrix/RandomMatrixConstructorTest.java     |   71 --
 .../matrix/SparseDistributedMatrixTest.java     |  265 -----
 .../SparseLocalOnHeapMatrixConstructorTest.java |   53 -
 .../impls/matrix/TransposedMatrixViewTest.java  |   87 --
 .../storage/matrix/MatrixArrayStorageTest.java  |   63 -
 .../storage/matrix/MatrixBaseStorageTest.java   |   89 --
 .../matrix/MatrixOffHeapStorageTest.java        |   39 -
 .../storage/matrix/MatrixStorageFixtures.java   |  141 ---
 .../matrix/MatrixStorageImplementationTest.java |   73 --
 .../SparseDistributedMatrixStorageTest.java     |  126 --
 .../RandomAccessSparseVectorStorageTest.java    |   60 -
 .../SparseLocalOffHeapVectorStorageTest.java    |   78 --
 .../storage/vector/VectorArrayStorageTest.java  |   58 -
 .../storage/vector/VectorBaseStorageTest.java   |   69 --
 .../vector/VectorOffheapStorageTest.java        |   73 --
 .../math/impls/vector/AbstractVectorTest.java   |  543 ---------
 .../math/impls/vector/CacheVectorTest.java      |  417 -------
 .../vector/ConstantVectorConstructorTest.java   |   52 -
 .../vector/DelegatingVectorConstructorTest.java |   62 -
 .../DenseLocalOffHeapVectorConstructorTest.java |   59 -
 .../DenseLocalOnHeapVectorConstructorTest.java  |  163 ---
 .../vector/FunctionVectorConstructorTest.java   |  121 --
 .../math/impls/vector/MatrixVectorViewTest.java |  209 ----
 .../PivotedVectorViewConstructorTest.java       |  211 ----
 .../vector/RandomVectorConstructorTest.java     |  145 ---
 .../SingleElementVectorConstructorTest.java     |  159 ---
 .../SingleElementVectorViewConstructorTest.java |  137 ---
 .../SparseLocalVectorConstructorTest.java       |   54 -
 .../math/impls/vector/VectorAttributesTest.java |  217 ----
 .../math/impls/vector/VectorFoldMapTest.java    |  122 --
 .../vector/VectorImplementationsFixtures.java   |  655 -----------
 .../impls/vector/VectorImplementationsTest.java |  860 --------------
 .../math/impls/vector/VectorIterableTest.java   |  376 ------
 .../math/impls/vector/VectorNormTest.java       |  247 ----
 .../math/impls/vector/VectorToMatrixTest.java   |  291 -----
 .../math/impls/vector/VectorViewTest.java       |  162 ---
 .../apache/ignite/ml/math/ExternalizeTest.java  |   66 ++
 .../ml/math/MathImplDistributedTestSuite.java   |   39 +
 .../ignite/ml/math/MathImplLocalTestSuite.java  |  123 ++
 .../ignite/ml/math/MathImplMainTestSuite.java   |   33 +
 .../org/apache/ignite/ml/math/TracerTest.java   |  195 +++
 .../ignite/ml/math/benchmark/MathBenchmark.java |  205 ++++
 .../math/benchmark/MathBenchmarkSelfTest.java   |  100 ++
 .../ignite/ml/math/benchmark/ResultsWriter.java |  127 ++
 .../ml/math/benchmark/VectorBenchmarkTest.java  |  138 +++
 .../ignite/ml/math/benchmark/package-info.java  |   18 +
 .../CholeskyDecompositionTest.java              |  158 +++
 .../decompositions/EigenDecompositionTest.java  |  193 +++
 .../decompositions/LUDecompositionTest.java     |  250 ++++
 .../decompositions/QRDecompositionTest.java     |  139 +++
 .../SingularValueDecompositionTest.java         |  120 ++
 .../ignite/ml/math/impls/MathTestConstants.java |   88 ++
 .../ml/math/impls/matrix/CacheMatrixTest.java   |  369 ++++++
 .../DenseLocalOffHeapMatrixConstructorTest.java |   65 +
 .../DenseLocalOnHeapMatrixConstructorTest.java  |   71 ++
 .../math/impls/matrix/DiagonalMatrixTest.java   |  209 ++++
 .../matrix/FunctionMatrixConstructorTest.java   |  113 ++
 .../math/impls/matrix/MatrixAttributeTest.java  |  156 +++
 .../matrix/MatrixImplementationFixtures.java    |  381 ++++++
 .../impls/matrix/MatrixImplementationsTest.java | 1113 ++++++++++++++++++
 .../impls/matrix/MatrixKeyMapperForTests.java   |   69 ++
 .../impls/matrix/MatrixViewConstructorTest.java |  114 ++
 .../PivotedMatrixViewConstructorTest.java       |  129 ++
 .../matrix/RandomMatrixConstructorTest.java     |   71 ++
 .../matrix/SparseDistributedMatrixTest.java     |  265 +++++
 .../SparseLocalOnHeapMatrixConstructorTest.java |   53 +
 .../impls/matrix/TransposedMatrixViewTest.java  |   87 ++
 .../storage/matrix/MatrixArrayStorageTest.java  |   63 +
 .../storage/matrix/MatrixBaseStorageTest.java   |   89 ++
 .../matrix/MatrixOffHeapStorageTest.java        |   39 +
 .../storage/matrix/MatrixStorageFixtures.java   |  137 +++
 .../matrix/MatrixStorageImplementationTest.java |   73 ++
 .../SparseDistributedMatrixStorageTest.java     |  126 ++
 .../RandomAccessSparseVectorStorageTest.java    |   60 +
 .../SparseLocalOffHeapVectorStorageTest.java    |   78 ++
 .../storage/vector/VectorArrayStorageTest.java  |   58 +
 .../storage/vector/VectorBaseStorageTest.java   |   69 ++
 .../vector/VectorOffheapStorageTest.java        |   73 ++
 .../math/impls/vector/AbstractVectorTest.java   |  543 +++++++++
 .../ml/math/impls/vector/CacheVectorTest.java   |  434 +++++++
 .../vector/ConstantVectorConstructorTest.java   |   52 +
 .../vector/DelegatingVectorConstructorTest.java |   62 +
 .../DenseLocalOffHeapVectorConstructorTest.java |   59 +
 .../DenseLocalOnHeapVectorConstructorTest.java  |  163 +++
 .../vector/FunctionVectorConstructorTest.java   |  121 ++
 .../math/impls/vector/MatrixVectorViewTest.java |  226 ++++
 .../PivotedVectorViewConstructorTest.java       |  211 ++++
 .../vector/RandomVectorConstructorTest.java     |  145 +++
 .../SingleElementVectorConstructorTest.java     |  159 +++
 .../SingleElementVectorViewConstructorTest.java |  137 +++
 .../SparseLocalVectorConstructorTest.java       |   54 +
 .../math/impls/vector/VectorAttributesTest.java |  217 ++++
 .../ml/math/impls/vector/VectorFoldMapTest.java |  122 ++
 .../vector/VectorImplementationsFixtures.java   |  655 +++++++++++
 .../impls/vector/VectorImplementationsTest.java |  861 ++++++++++++++
 .../math/impls/vector/VectorIterableTest.java   |  376 ++++++
 .../ml/math/impls/vector/VectorNormTest.java    |  247 ++++
 .../math/impls/vector/VectorToMatrixTest.java   |  308 +++++
 .../ml/math/impls/vector/VectorViewTest.java    |  162 +++
 357 files changed, 27247 insertions(+), 27128 deletions(-)
----------------------------------------------------------------------



[29/50] [abbrv] ignite git commit: Merge branch 'master' into ignite-2.0

Posted by sb...@apache.org.
Merge branch 'master' into ignite-2.0


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

Branch: refs/heads/ignite-1561
Commit: 9e7421f261354b28119094b3b53b9490fd817b24
Parents: 8ea9f83 735ce60
Author: devozerov <vo...@gridgain.com>
Authored: Tue Apr 18 17:04:43 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Tue Apr 18 17:04:43 2017 +0300

----------------------------------------------------------------------
 .../store/cassandra/datasource/DataSource.java  | 50 ++++++++++++++------
 .../cassandra/session/CassandraSessionImpl.java | 23 +++++----
 .../cassandra/session/pool/SessionPool.java     |  6 +--
 .../cassandra/session/pool/SessionWrapper.java  | 15 +++---
 4 files changed, 62 insertions(+), 32 deletions(-)
----------------------------------------------------------------------



[07/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/RandomVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/RandomVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/RandomVectorConstructorTest.java
deleted file mode 100644
index 6d4e4f1..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/RandomVectorConstructorTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class RandomVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = org.apache.ignite.math.exceptions.UnsupportedOperationException.class)
-    public void mapInvalidArgsTest() {
-        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
-            new RandomVector(new HashMap<String, Object>() {{
-                put("invalid", 99);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void mapMissingArgsTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("paramMissing", "whatever");
-        }};
-
-        assertEquals("Expect exception due to missing args.",
-            -1, new RandomVector(test).size());
-    }
-
-    /** */
-    @Test(expected = ClassCastException.class)
-    public void mapInvalidParamTypeTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("size", "whatever");
-            put("fastHash", true);
-        }};
-
-        assertEquals("Expect exception due to invalid param type.", IMPOSSIBLE_SIZE,
-            new RandomVector(test).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void mapNullTest() {
-        //noinspection ConstantConditions
-        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
-            new RandomVector(null).size());
-    }
-
-    /** */
-    @Test
-    public void mapTest() {
-        assertEquals("Size from args.", 99,
-            new RandomVector(new HashMap<String, Object>() {{
-                put("size", 99);
-            }}).size());
-
-        final int test = 99;
-
-        assertEquals("Size from args with fastHash false.", test,
-            new RandomVector(new HashMap<String, Object>() {{
-                put("size", test);
-                put("fastHash", false);
-            }}).size());
-
-        assertEquals("Size from args with fastHash true.", test,
-            new RandomVector(new HashMap<String, Object>() {{
-                put("size", test);
-                put("fastHash", true);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new RandomVector(-1).size());
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        final int basicSize = 3;
-
-        Vector v1 = new RandomVector(basicSize);
-
-        //noinspection EqualsWithItself
-        assertTrue("Expect vector to be equal to self", v1.equals(v1));
-
-        //noinspection ObjectEqualsNull
-        assertFalse("Expect vector to be not equal to null", v1.equals(null));
-
-        assertEquals("Size differs from expected", basicSize, v1.size());
-
-        verifyValues(v1);
-
-        Vector v2 = new RandomVector(basicSize, true);
-
-        assertEquals("Size differs from expected", basicSize, v2.size());
-
-        verifyValues(v2);
-
-        Vector v3 = new RandomVector(basicSize, false);
-
-        assertEquals("Size differs from expected", basicSize, v3.size());
-
-        verifyValues(v3);
-    }
-
-    /** */
-    private void verifyValues(Vector v) {
-        for (Vector.Element e : v.all()) {
-            double val = e.get();
-
-            assertTrue("Value too small: " + val + " at index " + e.index(), -1d <= val);
-
-            assertTrue("Value too large: " + val + " at index " + e.index(), val <= 1d);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorConstructorTest.java
deleted file mode 100644
index 69e22e0..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorConstructorTest.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class SingleElementVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void mapInvalidArgsTest() {
-        assertEquals("Expect exception due to invalid args.", IMPOSSIBLE_SIZE,
-            new SingleElementVector(new HashMap<String, Object>() {{
-                put("invalid", 99);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = UnsupportedOperationException.class)
-    public void mapMissingArgsTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("size", 1);
-
-            put("paramMissing", "whatever");
-        }};
-
-        assertEquals("Expect exception due to missing args.",
-            -1, new SingleElementVector(test).size());
-    }
-
-    /** */
-    @Test(expected = ClassCastException.class)
-    public void mapInvalidParamTypeTest() {
-        final Map<String, Object> test = new HashMap<String, Object>() {{
-            put("size", "whatever");
-
-            put("index", 0);
-            put("value", 1.0);
-        }};
-
-        assertEquals("Expect exception due to invalid param type.", IMPOSSIBLE_SIZE,
-            new SingleElementVector(test).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void mapNullTest() {
-        //noinspection ConstantConditions
-        assertEquals("Null map args.", IMPOSSIBLE_SIZE,
-            new SingleElementVector(null).size());
-    }
-
-    /** */
-    @Test
-    public void mapTest() {
-        assertEquals("Size from array in args.", 99,
-            new SingleElementVector(new HashMap<String, Object>() {{
-                put("size", 99);
-                put("index", 0);
-                put("value", 1.0);
-            }}).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new SingleElementVector(-1, 0, 1.0).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void zeroSizeTest() {
-        assertEquals("Zero size.", IMPOSSIBLE_SIZE,
-            new SingleElementVector(0, 0, 1.0).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void wrongIndexTest() {
-        //noinspection ConstantConditions
-        assertEquals("Wrong index.", IMPOSSIBLE_SIZE,
-            new SingleElementVector(1, 2, 1.0).size());
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        final int[] sizes = new int[] {1, 4, 8};
-
-        for (int size : sizes)
-            for (int idx = 0; idx < size; idx++)
-                basicTest(size, idx);
-    }
-
-    /** */
-    private void basicTest(int size, int idx) {
-        final Double expVal = (double)(size - idx);
-
-        Vector v = new SingleElementVector(size, idx, expVal);
-
-        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
-            expVal.equals(v.get(idx)));
-
-        final double delta = 1.0;
-
-        v.set(idx, expVal - delta);
-
-        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
-            expVal.equals(v.get(idx) + delta));
-
-        final Double zero = 0.0;
-
-        for (int i = 0; i < size; i++) {
-            if (i == idx)
-                continue;
-
-            assertTrue("Expect zero at index " + i + " for size " + size,
-                zero.equals(v.get(i)));
-
-            boolean eCaught = false;
-
-            try {
-                v.set(i, 1.0);
-            }
-            catch (UnsupportedOperationException uoe) {
-                eCaught = true;
-            }
-
-            assertTrue("Expect " + java.lang.UnsupportedOperationException.class.getSimpleName()
-                + " at index " + i + " for size " + size, eCaught);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorViewConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorViewConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorViewConstructorTest.java
deleted file mode 100644
index 957f3b7..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SingleElementVectorViewConstructorTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class SingleElementVectorViewConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    private static final SampleHelper helper = new SampleHelper();
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void nullVecParamTest() {
-        assertEquals("Expect exception due to null vector param.", IMPOSSIBLE_SIZE,
-            new SingleElementVectorView(null, helper.idx).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeIdxParamTest() {
-        assertEquals("Expect exception due to negative index param.", IMPOSSIBLE_SIZE,
-            new SingleElementVectorView(helper.vec, -1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void tooLargeIdxParamTest() {
-        assertEquals("Expect exception due to too large index param.", IMPOSSIBLE_SIZE,
-            new SingleElementVectorView(helper.vec, helper.vec.size()).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void emptyVecParamTest() {
-        assertEquals("Expect exception due to empty vector param.", IMPOSSIBLE_SIZE,
-            new SingleElementVectorView(helper.vecEmpty, 0).size());
-    }
-
-    /** */
-    @Test
-    public void basicTest() {
-        final int[] sizes = new int[] {1, 4, 8};
-
-        for (int size : sizes)
-            for (int idx = 0; idx < size; idx++)
-                basicTest(size, idx);
-    }
-
-    /** */
-    private void basicTest(int size, int idx) {
-        final Double expVal = (double)(size - idx);
-
-        Vector orig = helper.newSample(size, idx, expVal);
-
-        SingleElementVectorView svv = new SingleElementVectorView(orig, idx);
-
-        assertEquals("Size differs from expected", size, svv.size());
-
-        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
-            expVal.equals(svv.get(idx)));
-
-        final double delta = 1.0;
-
-        svv.set(idx, expVal - delta);
-
-        assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size,
-            expVal.equals(orig.get(idx) + delta));
-
-        final Double zero = 0.0;
-
-        for (int i = 0; i < size; i++) {
-            if (i == idx)
-                continue;
-
-            assertTrue("Expect zero at index " + i + " for size " + size,
-                zero.equals(svv.get(i)));
-
-            boolean eCaught = false;
-
-            try {
-                svv.set(i, 1.0);
-            }
-            catch (UnsupportedOperationException uoe) {
-                eCaught = true;
-            }
-
-            assertTrue("Expect " + UnsupportedOperationException.class.getSimpleName()
-                + " at index " + i + " for size " + size, eCaught);
-        }
-    }
-
-    /** */
-    private static class SampleHelper {
-        /** */
-        final double[] data = new double[] {0, 1};
-        /** */
-        final Vector vec = new DenseLocalOnHeapVector(data);
-        /** */
-        final Vector vecEmpty = new DenseLocalOnHeapVector(new double[] {});
-        /** */
-        final int idx = 0;
-
-        /** */
-        Vector newSample(int size, int idx, double expVal) {
-            final Vector v = new DenseLocalOnHeapVector(size);
-
-            for (int i = 0; i < size; i++)
-                v.set(i, i == idx ? expVal : i);
-
-            return v;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SparseLocalVectorConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SparseLocalVectorConstructorTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SparseLocalVectorConstructorTest.java
deleted file mode 100644
index 2be4a10..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/SparseLocalVectorConstructorTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import org.apache.ignite.math.StorageConstants;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class SparseLocalVectorConstructorTest {
-    /** */
-    private static final int IMPOSSIBLE_SIZE = -1;
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void negativeSizeTest() {
-        assertEquals("Negative size.", IMPOSSIBLE_SIZE,
-            new SparseLocalVector(-1, 1).size());
-    }
-
-    /** */
-    @Test(expected = AssertionError.class)
-    public void zeroSizeTest() {
-        assertEquals("0 size.", IMPOSSIBLE_SIZE,
-            new SparseLocalVector(0, 1).size());
-    }
-
-    /** */
-    @Test
-    public void primitiveTest() {
-        assertEquals("1 size, random access.", 1,
-            new SparseLocalVector(1, StorageConstants.RANDOM_ACCESS_MODE).size());
-
-        assertEquals("1 size, sequential access.", 1,
-            new SparseLocalVector(1, StorageConstants.SEQUENTIAL_ACCESS_MODE).size());
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorAttributesTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorAttributesTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorAttributesTest.java
deleted file mode 100644
index 992018a..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorAttributesTest.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Function;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/** */
-public class VectorAttributesTest {
-    /** */
-    private final List<AttrCfg> attrCfgs = Arrays.asList(
-        new AttrCfg("isDense", Vector::isDense,
-            DenseLocalOnHeapVector.class, DenseLocalOffHeapVector.class, RandomVector.class, ConstantVector.class,
-            SingleElementVector.class),
-        new AttrCfg("isArrayBased", Vector::isArrayBased,
-            DenseLocalOnHeapVector.class),
-        new AttrCfg("isSequentialAccess", Vector::isSequentialAccess,
-            DenseLocalOnHeapVector.class, DenseLocalOffHeapVector.class, SparseLocalVectorSequentialAccess.class,
-            RandomVector.class, ConstantVector.class, SingleElementVector.class),
-        new AttrCfg("guidNotNull", v -> v.guid() == null), // IMPL NOTE this is somewhat artificial
-        new AttrCfg("isRandomAccess", Vector::isRandomAccess,
-            DenseLocalOnHeapVector.class, DenseLocalOffHeapVector.class, RandomVector.class, ConstantVector.class,
-            SingleElementVector.class, SparseLocalVectorSequentialAccess.class, SparseLocalVectorRandomAccess.class),
-        new AttrCfg("isDistributed", Vector::isDistributed));
-
-    /** */
-    private final List<Specification> specFixture = Arrays.asList(
-        new Specification(new DenseLocalOnHeapVector(1)),
-        new Specification(new DenseLocalOffHeapVector(1)),
-        new Specification(new DelegatingVector(new DenseLocalOnHeapVector(1)),
-            DenseLocalOnHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
-            "isRandomAccess", "isDistributed"),
-        new Specification(new DelegatingVector(new DenseLocalOffHeapVector(1)),
-            DenseLocalOffHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
-            "isRandomAccess", "isDistributed"),
-        new Specification(new SparseLocalVectorSequentialAccess(1)),
-        new Specification(new SparseLocalVectorRandomAccess(1)),
-        new Specification(new RandomVector(1)),
-        new Specification(new ConstantVector(1, 1.0)),
-        new Specification(new FunctionVector(1, idx -> (double)idx)),
-        new Specification(new SingleElementVector(1, 0, 1.0)),
-        new Specification(new PivotedVectorView(new DenseLocalOnHeapVector(1), new int[] {0}),
-            DenseLocalOnHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
-            "isRandomAccess", "isDistributed"),
-        new Specification(new PivotedVectorView(new DenseLocalOffHeapVector(1), new int[] {0}),
-            DenseLocalOffHeapVector.class, "isDense", "isArrayBased", "isSequentialAccess",
-            "isRandomAccess", "isDistributed"),
-        new Specification(new SingleElementVectorView(new DenseLocalOnHeapVector(1), 0),
-            DenseLocalOnHeapVector.class, "isDense", "isSequentialAccess",
-            "isRandomAccess", "isDistributed"),
-        new Specification(new SingleElementVectorView(new DenseLocalOffHeapVector(1), 0),
-            DenseLocalOffHeapVector.class, "isDense", "isSequentialAccess",
-            "isRandomAccess", "isDistributed"),
-        new Specification(new MatrixVectorView(new DenseLocalOnHeapMatrix(1, 1), 0, 0, 1, 1),
-            DenseLocalOnHeapVector.class, "isDense",
-            "isRandomAccess", "isDistributed"), // todo find out why "isSequentialAccess" fails here
-        new Specification(new MatrixVectorView(new DenseLocalOffHeapMatrix(1, 1), 0, 0, 1, 1),
-            DenseLocalOffHeapVector.class, "isDense",
-            "isRandomAccess", "isDistributed"));
-
-    /** */
-    @Test
-    public void isDenseTest() {
-        assertAttribute("isDense");
-    }
-
-    /** */
-    @Test
-    public void isArrayBasedTest() {
-        assertAttribute("isArrayBased");
-    }
-
-    /** */
-    @Test
-    public void isSequentialAccessTest() {
-        assertAttribute("isSequentialAccess");
-    }
-
-    /** */
-    @Test
-    public void guidTest() {
-        assertAttribute("guidNotNull");
-    }
-
-    /** */
-    @Test
-    public void isRandomAccessTest() {
-        assertAttribute("isRandomAccess");
-    }
-
-    /** */
-    @Test
-    public void isDistributedTest() {
-        assertAttribute("isDistributed");
-    }
-
-    /** */
-    private void assertAttribute(String name) {
-        final AttrCfg attr = attrCfg(name);
-
-        for (Specification spec : specFixture)
-            spec.verify(attr);
-    }
-
-    /** */
-    private AttrCfg attrCfg(String name) {
-        for (AttrCfg attr : attrCfgs)
-            if (attr.name.equals(name))
-                return attr;
-
-        throw new IllegalArgumentException("Undefined attribute " + name);
-    }
-
-    /** See http://en.wikipedia.org/wiki/Specification_pattern */
-    private static class Specification {
-        /** */
-        private final Vector v;
-        /** */
-        private final Class<? extends Vector> underlyingType;
-        /** */
-        private final List<String> attrsFromUnderlying;
-        /** */
-        final String desc;
-
-        /** */
-        Specification(Vector v, Class<? extends Vector> underlyingType, String... attrsFromUnderlying) {
-            this.v = v;
-            this.underlyingType = underlyingType;
-            this.attrsFromUnderlying = Arrays.asList(attrsFromUnderlying);
-            final Class<? extends Vector> clazz = v.getClass();
-            desc = clazz.getSimpleName() + (clazz.equals(underlyingType)
-                ? "" : " (underlying type " + underlyingType.getSimpleName() + ")");
-        }
-
-        /** */
-        Specification(Vector v) {
-            this(v, v.getClass());
-        }
-
-        /** */
-        void verify(AttrCfg attr) {
-            final boolean obtained = attr.obtain.apply(v);
-
-            final Class<? extends Vector> typeToCheck
-                = attrsFromUnderlying.contains(attr.name) ? underlyingType : v.getClass();
-
-            final boolean exp = attr.trueInTypes.contains(typeToCheck);
-
-            assertEquals("Unexpected " + attr.name + " value for " + desc, exp, obtained);
-        }
-    }
-
-    /** */
-    private static class AttrCfg {
-        /** */
-        final String name;
-        /** */
-        final Function<Vector, Boolean> obtain;
-        /** */
-        final List<Class> trueInTypes;
-
-        /** */
-        AttrCfg(String name, Function<Vector, Boolean> obtain, Class... trueInTypes) {
-            this.name = name;
-            this.obtain = obtain;
-            this.trueInTypes = Arrays.asList(trueInTypes);
-        }
-    }
-
-    /** */
-    private static class SparseLocalVectorSequentialAccess extends SparseLocalVector {
-        /** */
-        public SparseLocalVectorSequentialAccess() {
-            // No-op.
-        }
-
-        /** */
-        SparseLocalVectorSequentialAccess(int size) {
-            super(size, SEQUENTIAL_ACCESS_MODE);
-        }
-    }
-
-    /** */
-    private static class SparseLocalVectorRandomAccess extends SparseLocalVector {
-        /** */
-        public SparseLocalVectorRandomAccess() {
-            // No-op.
-        }
-
-        /** */
-        SparseLocalVectorRandomAccess(int size) {
-            super(size, RANDOM_ACCESS_MODE);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorFoldMapTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorFoldMapTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorFoldMapTest.java
deleted file mode 100644
index 67eb8ba..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorFoldMapTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Arrays;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.functions.Functions;
-import org.junit.Test;
-
-import static java.util.function.DoubleUnaryOperator.identity;
-import static org.junit.Assert.assertTrue;
-
-/** See also: {@link AbstractVectorTest} and {@link VectorToMatrixTest}. */
-public class VectorFoldMapTest {
-    /** */
-    @Test
-    public void mapVectorTest() {
-        operationVectorTest((operand1, operand2) -> operand1 + operand2, (Vector v1, Vector v2) -> v1.map(v2, Functions.PLUS));
-    }
-
-    /** */
-    @Test
-    public void mapDoubleFunctionTest() {
-        consumeSampleVectors((v, desc) -> operatorTest(v, desc,
-            (vec) -> vec.map(Functions.INV), (val) -> 1.0 / val));
-    }
-
-    /** */
-    @Test
-    public void mapBiFunctionTest() {
-        consumeSampleVectors((v, desc) -> operatorTest(v, desc,
-            (vec) -> vec.map(Functions.PLUS, 1.0), (val) -> 1.0 + val));
-    }
-
-    /** */
-    @Test
-    public void foldMapTest() {
-        toDoubleTest(
-            ref -> Arrays.stream(ref).map(identity()).sum(),
-            (v) -> v.foldMap(Functions.PLUS, Functions.IDENTITY, 0.0));
-    }
-
-    /** */
-    @Test
-    public void foldMapVectorTest() {
-        toDoubleTest(
-            ref -> 2.0 * Arrays.stream(ref).sum(),
-            (v) -> v.foldMap(v, Functions.PLUS, Functions.PLUS, 0.0));
-
-    }
-
-    /** */
-    private void operatorTest(Vector v, String desc, Function<Vector, Vector> op, Function<Double, Double> refOp) {
-        final int size = v.size();
-        final double[] ref = new double[size];
-
-        VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
-
-        Vector actual = op.apply(v);
-
-        for (int idx = 0; idx < size; idx++)
-            ref[idx] = refOp.apply(ref[idx]);
-
-        checker.assertCloseEnough(actual, ref);
-    }
-
-    /** */
-    private void toDoubleTest(Function<double[], Double> calcRef, Function<Vector, Double> calcVec) {
-        consumeSampleVectors((v, desc) -> {
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            new VectorImplementationsTest.ElementsChecker(v, ref, desc); // IMPL NOTE this initialises vector and reference array
-
-            final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(calcRef.apply(ref), calcVec.apply(v));
-
-            assertTrue("Not close enough at " + desc
-                + ", " + metric, metric.closeEnough());
-        });
-    }
-
-    /** */
-    private void operationVectorTest(BiFunction<Double, Double, Double> operation,
-        BiFunction<Vector, Vector, Vector> vecOperation) {
-        consumeSampleVectors((v, desc) -> {
-            // TODO find out if more elaborate testing scenario is needed or it's okay as is.
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            final VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
-            final Vector operand = v.copy();
-
-            for (int idx = 0; idx < size; idx++)
-                ref[idx] = operation.apply(ref[idx], ref[idx]);
-
-            checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
-        });
-    }
-
-    /** */
-    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
-        new VectorImplementationsFixtures().consumeSampleVectors(null, consumer);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsFixtures.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsFixtures.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsFixtures.java
deleted file mode 100644
index 5a46218..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsFixtures.java
+++ /dev/null
@@ -1,655 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.storage.vector.FunctionVectorStorage;
-import org.jetbrains.annotations.NotNull;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/** */
-class VectorImplementationsFixtures {
-    /** */
-    private static final List<Supplier<Iterable<Vector>>> suppliers = Arrays.asList(
-        (Supplier<Iterable<Vector>>)DenseLocalOnHeapVectorFixture::new,
-        (Supplier<Iterable<Vector>>)DenseLocalOffHeapVectorFixture::new,
-        (Supplier<Iterable<Vector>>)SparseLocalVectorFixture::new,
-        (Supplier<Iterable<Vector>>)RandomVectorFixture::new,
-        (Supplier<Iterable<Vector>>)ConstantVectorFixture::new,
-        (Supplier<Iterable<Vector>>)DelegatingVectorFixture::new,
-        (Supplier<Iterable<Vector>>)FunctionVectorFixture::new,
-        (Supplier<Iterable<Vector>>)SingleElementVectorFixture::new,
-        (Supplier<Iterable<Vector>>)PivotedVectorViewFixture::new,
-        (Supplier<Iterable<Vector>>)SingleElementVectorViewFixture::new,
-        (Supplier<Iterable<Vector>>)MatrixVectorViewFixture::new,
-        (Supplier<Iterable<Vector>>)SparseLocalOffHeapVectorFixture::new
-    );
-
-    /** */
-    void consumeSampleVectors(Consumer<Integer> paramsConsumer, BiConsumer<Vector, String> consumer) {
-        for (Supplier<Iterable<Vector>> fixtureSupplier : VectorImplementationsFixtures.suppliers) {
-            final Iterable<Vector> fixture = fixtureSupplier.get();
-
-            for (Vector v : fixture) {
-                if (paramsConsumer != null)
-                    paramsConsumer.accept(v.size());
-
-                consumer.accept(v, fixture.toString());
-            }
-        }
-    }
-
-    /** */
-    void selfTest() {
-        new VectorSizesExtraIterator<>("VectorSizesExtraIterator test",
-            (size, shallowCp) -> new DenseLocalOnHeapVector(new double[size], shallowCp),
-            null, "shallow copy", new Boolean[] {false, true, null}).selfTest();
-
-        new VectorSizesIterator("VectorSizesIterator test", DenseLocalOffHeapVector::new, null).selfTest();
-    }
-
-    /** */
-    private static class DenseLocalOnHeapVectorFixture extends VectorSizesExtraFixture<Boolean> {
-        /** */
-        DenseLocalOnHeapVectorFixture() {
-            super("DenseLocalOnHeapVector",
-                (size, shallowCp) -> new DenseLocalOnHeapVector(new double[size], shallowCp),
-                "shallow copy", new Boolean[] {false, true, null});
-        }
-    }
-
-    /** */
-    private static class DenseLocalOffHeapVectorFixture extends VectorSizesFixture {
-        /** */
-        DenseLocalOffHeapVectorFixture() {
-            super("DenseLocalOffHeapVector", DenseLocalOffHeapVector::new);
-        }
-    }
-
-    /** */
-    private static class SparseLocalVectorFixture extends VectorSizesExtraFixture<Integer> {
-        /** */
-        SparseLocalVectorFixture() {
-            super("SparseLocalVector", SparseLocalVector::new, "access mode",
-                new Integer[] {StorageConstants.SEQUENTIAL_ACCESS_MODE, StorageConstants.RANDOM_ACCESS_MODE, null});
-        }
-    }
-
-    /** */
-    private static class RandomVectorFixture extends VectorSizesFixture {
-        /** */
-        RandomVectorFixture() {
-            super("RandomVector", RandomVector::new);
-        }
-    }
-
-    /** */
-    private static class ConstantVectorFixture extends VectorSizesExtraFixture<Double> {
-        /** */
-        ConstantVectorFixture() {
-            super("ConstantVector", ConstantVector::new,
-                "value", new Double[] {-1.0, 0.0, 0.5, 1.0, 2.0, null});
-        }
-    }
-
-    /** */
-    private static class FunctionVectorFixture extends VectorSizesExtraFixture<Double> {
-        /** */
-        FunctionVectorFixture() {
-            super("FunctionVector",
-                (size, scale) -> new FunctionVectorForTest(new double[size], scale),
-                "scale", new Double[] {0.5, 1.0, 2.0, null});
-        }
-    }
-
-    /** */
-    private static class SingleElementVectorFixture implements Iterable<Vector> {
-        /** */
-        private final Supplier<TwoParamsIterator<Integer, Double>> iter;
-
-        /** */
-        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
-
-        /** */
-        SingleElementVectorFixture() {
-            iter = () -> new TwoParamsIterator<Integer, Double>("SingleElementVector",
-                null, ctxDescrHolder::set,
-                "size", new Integer[] {1, null},
-                "value", new Double[] {-1.0, 0.0, 0.5, 1.0, 2.0, null}) {
-
-                /** {@inheritDoc} */
-                @Override BiFunction<Integer, Double, Vector> ctor() {
-                    return (size, value) -> new SingleElementVector(size, 0, value);
-                }
-            };
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Vector> iterator() {
-            return iter.get();//(
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return ctxDescrHolder.get();
-        }
-    }
-
-    /** */
-    private static class PivotedVectorViewFixture extends VectorSizesFixture {
-        /** */
-        PivotedVectorViewFixture() {
-            super("PivotedVectorView", PivotedVectorViewFixture::pivotedVectorView);
-        }
-
-        /** */
-        private static PivotedVectorView pivotedVectorView(int size) {
-            final DenseLocalOnHeapVector vec = new DenseLocalOnHeapVector(size);
-
-            final int[] pivot = new int[size];
-
-            for (int idx = 0; idx < size; idx++)
-                pivot[idx] = size - 1 - idx;
-
-            PivotedVectorView tmp = new PivotedVectorView(vec, pivot);
-
-            final int[] unpivot = new int[size];
-
-            for (int idx = 0; idx < size; idx++)
-                unpivot[idx] = tmp.unpivot(idx);
-
-            final int[] idxRecovery = new int[size];
-
-            for (int idx = 0; idx < size; idx++)
-                idxRecovery[idx] = idx;
-
-            return new PivotedVectorView(new PivotedVectorView(tmp, unpivot), idxRecovery);
-        }
-    }
-
-    /** */
-    private static class SingleElementVectorViewFixture implements Iterable<Vector> {
-        /** */
-        private final Supplier<TwoParamsIterator<Integer, Double>> iter;
-
-        /** */
-        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
-
-        /** */
-        SingleElementVectorViewFixture() {
-            iter = () -> new TwoParamsIterator<Integer, Double>("SingleElementVectorView",
-                null, ctxDescrHolder::set,
-                "size", new Integer[] {1, null},
-                "value", new Double[] {-1.0, 0.0, 0.5, 1.0, 2.0, null}) {
-
-                /** {@inheritDoc} */
-                @Override BiFunction<Integer, Double, Vector> ctor() {
-                    return (size, value) -> new SingleElementVectorView(new SingleElementVector(size, 0, value), 0);
-                }
-            };
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Vector> iterator() {
-            return iter.get();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return ctxDescrHolder.get();
-        }
-    }
-
-    /** */
-    private static class MatrixVectorViewFixture extends VectorSizesExtraFixture<Integer> {
-        /** */
-        MatrixVectorViewFixture() {
-            super("MatrixVectorView",
-                MatrixVectorViewFixture::newView,
-                "stride kind", new Integer[] {0, 1, 2, null});
-        }
-
-        /** */
-        private static Vector newView(int size, int strideKind) {
-            final Matrix parent = new DenseLocalOnHeapMatrix(size, size);
-
-            return new MatrixVectorView(parent, 0, 0, strideKind != 1 ? 1 : 0, strideKind != 0 ? 1 : 0);
-        }
-    }
-
-    /** */
-    private static class VectorSizesExtraFixture<T> implements Iterable<Vector> {
-        /** */
-        private final Supplier<VectorSizesExtraIterator<T>> iter;
-
-        /** */
-        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
-
-        /** */
-        VectorSizesExtraFixture(String vectorKind, BiFunction<Integer, T, Vector> ctor, String extraParamName,
-            T[] extras) {
-            iter = () -> new VectorSizesExtraIterator<>(vectorKind, ctor, ctxDescrHolder::set, extraParamName, extras);
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Vector> iterator() {
-            return iter.get();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return ctxDescrHolder.get();
-        }
-    }
-
-    /** */
-    private static abstract class VectorSizesFixture implements Iterable<Vector> {
-        /** */
-        private final Supplier<VectorSizesIterator> iter;
-
-        /** */
-        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
-
-        /** */
-        VectorSizesFixture(String vectorKind, Function<Integer, Vector> ctor) {
-            iter = () -> new VectorSizesIterator(vectorKind, ctor, ctxDescrHolder::set);
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Vector> iterator() {
-            return iter.get();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return ctxDescrHolder.get();
-        }
-    }
-
-    /** */
-    private static class VectorSizesExtraIterator<T> extends VectorSizesIterator {
-        /** */
-        private final T[] extras;
-        /** */
-        private int extraIdx = 0;
-        /** */
-        private final BiFunction<Integer, T, Vector> ctor;
-        /** */
-        private final String extraParamName;
-
-        /**
-         * @param vectorKind Descriptive name to use for context logging.
-         * @param ctor Constructor for objects to iterate over.
-         * @param ctxDescrConsumer Context logging consumer.
-         * @param extraParamName Name of extra parameter to iterate over.
-         * @param extras Array of extra parameter values to iterate over.
-         */
-        VectorSizesExtraIterator(String vectorKind, BiFunction<Integer, T, Vector> ctor,
-            Consumer<String> ctxDescrConsumer, String extraParamName, T[] extras) {
-            super(vectorKind, null, ctxDescrConsumer);
-
-            this.ctor = ctor;
-            this.extraParamName = extraParamName;
-            this.extras = extras;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasNext() {
-            return super.hasNext() && hasNextExtra(extraIdx);
-        }
-
-        /** {@inheritDoc} */
-        @Override void nextIdx() {
-            assert extras[extraIdx] != null
-                : "Index(es) out of bound at " + VectorSizesExtraIterator.this;
-
-            if (hasNextExtra(extraIdx + 1)) {
-                extraIdx++;
-
-                return;
-            }
-
-            extraIdx = 0;
-
-            super.nextIdx();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return "{" + super.toString() +
-                ", " + extraParamName + "=" + extras[extraIdx] +
-                '}';
-        }
-
-        /** {@inheritDoc} */
-        @Override BiFunction<Integer, Integer, Vector> ctor() {
-            return (size, delta) -> ctor.apply(size + delta, extras[extraIdx]);
-        }
-
-        /** */
-        void selfTest() {
-            final Set<Integer> extraIdxs = new HashSet<>();
-
-            int cnt = 0;
-
-            while (hasNext()) {
-                assertNotNull("Expect not null vector at " + this, next());
-
-                if (extras[extraIdx] != null)
-                    extraIdxs.add(extraIdx);
-
-                cnt++;
-            }
-
-            assertEquals("Extra param tested", extraIdxs.size(), extras.length - 1);
-
-            assertEquals("Combinations tested mismatch.",
-                7 * 3 * (extras.length - 1), cnt);
-        }
-
-        /** */
-        private boolean hasNextExtra(int idx) {
-            return extras[idx] != null;
-        }
-    }
-
-    /** */
-    private static class VectorSizesIterator extends TwoParamsIterator<Integer, Integer> {
-        /** */
-        private final Function<Integer, Vector> ctor;
-
-        /** */
-        VectorSizesIterator(String vectorKind, Function<Integer, Vector> ctor, Consumer<String> ctxDescrConsumer) {
-            super(vectorKind, null, ctxDescrConsumer,
-                "size", new Integer[] {2, 4, 8, 16, 32, 64, 128, null},
-                "size delta", new Integer[] {-1, 0, 1, null});
-
-            this.ctor = ctor;
-        }
-
-        /** {@inheritDoc} */
-        @Override BiFunction<Integer, Integer, Vector> ctor() {
-            return (size, delta) -> ctor.apply(size + delta);
-        }
-    }
-
-    /** */
-    private static class TwoParamsIterator<T, U> implements Iterator<Vector> {
-        /** */
-        private final T params1[];
-
-        /** */
-        private final U params2[];
-
-        /** */
-        private final String vectorKind;
-
-        /** */
-        private final String param1Name;
-
-        /** */
-        private final String param2Name;
-
-        /** */
-        private final BiFunction<T, U, Vector> ctor;
-
-        /** */
-        private final Consumer<String> ctxDescrConsumer;
-
-        /** */
-        private int param1Idx = 0;
-
-        /** */
-        private int param2Idx = 0;
-
-        /** */
-        TwoParamsIterator(String vectorKind, BiFunction<T, U, Vector> ctor,
-            Consumer<String> ctxDescrConsumer, String param1Name, T[] params1, String param2Name, U[] params2) {
-            this.param1Name = param1Name;
-            this.params1 = params1;
-
-            this.param2Name = param2Name;
-            this.params2 = params2;
-
-            this.vectorKind = vectorKind;
-
-            this.ctor = ctor;
-
-            this.ctxDescrConsumer = ctxDescrConsumer;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasNext() {
-            return hasNextParam1(param1Idx) && hasNextParam2(param2Idx);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Vector next() {
-            if (!hasNext())
-                throw new NoSuchElementException(TwoParamsIterator.this.toString());
-
-            if (ctxDescrConsumer != null)
-                ctxDescrConsumer.accept(toString());
-
-            Vector res = ctor().apply(params1[param1Idx], params2[param2Idx]);
-
-            nextIdx();
-
-            return res;
-        }
-
-        /** */
-        void selfTest() {
-            final Set<Integer> sizeIdxs = new HashSet<>(), deltaIdxs = new HashSet<>();
-
-            int cnt = 0;
-
-            while (hasNext()) {
-                assertNotNull("Expect not null vector at " + this, next());
-
-                if (params1[param1Idx] != null)
-                    sizeIdxs.add(param1Idx);
-
-                if (params2[param2Idx] != null)
-                    deltaIdxs.add(param2Idx);
-
-                cnt++;
-            }
-
-            assertEquals("Sizes tested mismatch.", sizeIdxs.size(), params1.length - 1);
-
-            assertEquals("Deltas tested", deltaIdxs.size(), params2.length - 1);
-
-            assertEquals("Combinations tested mismatch.",
-                (params1.length - 1) * (params2.length - 1), cnt);
-        }
-
-        /** IMPL NOTE override in subclasses if needed */
-        void nextIdx() {
-            assert params1[param1Idx] != null && params2[param2Idx] != null
-                : "Index(es) out of bound at " + TwoParamsIterator.this;
-
-            if (hasNextParam2(param2Idx + 1)) {
-                param2Idx++;
-
-                return;
-            }
-
-            param2Idx = 0;
-
-            param1Idx++;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return vectorKind + "{" + param1Name + "=" + params1[param1Idx] +
-                ", " + param2Name + "=" + params2[param2Idx] +
-                '}';
-        }
-
-        /** IMPL NOTE override in subclasses if needed */
-        BiFunction<T, U, Vector> ctor() {
-            return ctor;
-        }
-
-        /** */
-        private boolean hasNextParam1(int idx) {
-            return params1[idx] != null;
-        }
-
-        /** */
-        private boolean hasNextParam2(int idx) {
-            return params2[idx] != null;
-        }
-    }
-
-    /** Delegating vector with dense local onheap vector */
-    private static class DelegatingVectorFixture implements Iterable<Vector> {
-
-        /** */
-        private final Supplier<VectorSizesExtraIterator<Boolean>> iter;
-
-        /** */
-        private final AtomicReference<String> ctxDescrHolder = new AtomicReference<>("Iterator not started.");
-
-        /** */
-        DelegatingVectorFixture() {
-            iter = () -> new VectorSizesExtraIterator<>("DelegatingVector with DenseLocalOnHeapVector",
-                (size, shallowCp) -> new DelegatingVector(new DenseLocalOnHeapVector(new double[size], shallowCp)),
-                ctxDescrHolder::set, "shallow copy", new Boolean[] {false, true, null});
-        }
-
-        /** {@inheritDoc} */
-        @NotNull
-        @Override public Iterator<Vector> iterator() {
-            return iter.get();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            // IMPL NOTE index within bounds is expected to be guaranteed by proper code in this class
-            return ctxDescrHolder.get();
-        }
-    }
-
-    /** Subclass tweaked for serialization */
-    private static class FunctionVectorForTest extends FunctionVector {
-        /** */
-        double[] arr;
-
-        /** */
-        double scale;
-
-        /** */
-        public FunctionVectorForTest() {
-            // No-op.
-        }
-
-        /** */
-        FunctionVectorForTest(double[] arr, double scale) {
-            super(arr.length, idx -> arr[idx] * scale, (idx, value) -> arr[idx] = value / scale);
-
-            this.arr = arr;
-
-            this.scale = scale;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            super.writeExternal(out);
-
-            out.writeObject(arr);
-
-            out.writeDouble(scale);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            super.readExternal(in);
-
-            arr = (double[])in.readObject();
-
-            scale = in.readDouble();
-
-            setStorage(new FunctionVectorStorage(arr.length, idx -> arr[idx] * scale, (idx, value) -> arr[idx] = value / scale));
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            int res = 1;
-
-            res = res * 37 + Double.hashCode(scale);
-            res = res * 37 + Integer.hashCode(getStorage().size());
-
-            return res;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            FunctionVectorForTest that = (FunctionVectorForTest)o;
-
-            return new Double(scale).equals(that.scale)
-                && (arr != null ? Arrays.equals(arr, that.arr) : that.arr == null);
-        }
-    }
-
-    /** */
-    private static class SparseLocalOffHeapVectorFixture extends VectorSizesFixture {
-
-        /** */
-        SparseLocalOffHeapVectorFixture() {
-            super("SparseLocalOffHeapVector", SparseLocalOffHeapVector::new);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsTest.java b/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsTest.java
deleted file mode 100644
index 0e61513..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/math/impls/vector/VectorImplementationsTest.java
+++ /dev/null
@@ -1,860 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.vector;
-
-import java.util.Arrays;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.math.ExternalizeTest;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/** See also: {@link AbstractVectorTest} and {@link VectorToMatrixTest}. */
-public class VectorImplementationsTest { // todo split this to smaller cohesive test classes
-    /** */
-    @Test
-    public void vectorImplementationsFixturesTest() {
-        new VectorImplementationsFixtures().selfTest();
-    }
-
-    /** */
-    @Test
-    public void setGetTest() {
-        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
-            vec.set(idx, val);
-
-            return val;
-        }));
-    }
-
-    /** */
-    @Test
-    public void setXTest() {
-        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
-            vec.setX(idx, val);
-
-            return val;
-        }));
-    }
-
-    /** */
-    @Test
-    public void incrementTest() {
-        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
-            double old = vec.get(idx);
-
-            vec.increment(idx, val);
-
-            return old + val;
-        }));
-    }
-
-    /** */
-    @Test
-    public void incrementXTest() {
-        consumeSampleVectors((v, desc) -> mutateAtIdxTest(v, desc, (vec, idx, val) -> {
-            double old = vec.getX(idx);
-
-            vec.incrementX(idx, val);
-
-            return old + val;
-        }));
-    }
-
-    /** */
-    @Test
-    public void operateXOutOfBoundsTest() {
-        consumeSampleVectors((v, desc) -> {
-            if (v instanceof DenseLocalOffHeapVector || v instanceof SparseLocalVector || v instanceof SparseLocalOffHeapVector)
-                return; // todo find out if it's OK to skip by instances here
-
-            boolean expECaught = false;
-
-            try {
-                v.getX(-1);
-            }
-            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
-                expECaught = true;
-            }
-
-            if (!getXOutOfBoundsOK(v))
-                assertTrue("Expect exception at negative index getX in " + desc, expECaught);
-
-            expECaught = false;
-
-            try {
-                v.setX(-1, 0);
-            }
-            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
-                expECaught = true;
-            }
-
-            assertTrue("Expect exception at negative index setX in " + desc, expECaught);
-
-            expECaught = false;
-
-            try {
-                v.incrementX(-1, 1);
-            }
-            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
-                expECaught = true;
-            }
-
-            assertTrue("Expect exception at negative index incrementX in " + desc, expECaught);
-
-            expECaught = false;
-
-            try {
-                v.getX(v.size());
-            }
-            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
-                expECaught = true;
-            }
-
-            if (!getXOutOfBoundsOK(v))
-                assertTrue("Expect exception at too large index getX in " + desc, expECaught);
-
-            expECaught = false;
-
-            try {
-                v.setX(v.size(), 1);
-            }
-            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
-                expECaught = true;
-            }
-
-            assertTrue("Expect exception at too large index setX in " + desc, expECaught);
-
-            expECaught = false;
-
-            try {
-                v.incrementX(v.size(), 1);
-            }
-            catch (ArrayIndexOutOfBoundsException | IgniteException e) {
-                expECaught = true;
-            }
-
-            assertTrue("Expect exception at too large index incrementX in " + desc, expECaught);
-        });
-    }
-
-    /** */
-    @Test
-    public void sizeTest() {
-        final AtomicReference<Integer> expSize = new AtomicReference<>(0);
-
-        consumeSampleVectors(
-            expSize::set,
-            (v, desc) -> assertEquals("Expected size for " + desc,
-                (int)expSize.get(), v.size())
-        );
-    }
-
-    /** */
-    @Test
-    public void getElementTest() {
-        consumeSampleVectors((v, desc) -> new ElementsChecker(v, desc).assertCloseEnough(v));
-    }
-
-    /** */
-    @Test
-    public void copyTest() {
-        consumeSampleVectors((v, desc) -> new ElementsChecker(v, desc).assertCloseEnough(v.copy()));
-    }
-
-    /** */
-    @Test
-    public void divideTest() {
-        operationTest((val, operand) -> val / operand, Vector::divide);
-    }
-
-    /** */
-    @Test
-    public void likeTest() {
-        for (int card : new int[] {1, 2, 4, 8, 16, 32, 64, 128})
-            consumeSampleVectors((v, desc) -> {
-                Class<? extends Vector> expType = expLikeType(v);
-
-                if (expType == null) {
-                    try {
-                        v.like(card);
-                    }
-                    catch (UnsupportedOperationException uoe) {
-                        return;
-                    }
-
-                    fail("Expected exception wasn't caught for " + desc);
-
-                    return;
-                }
-
-                Vector vLike = v.like(card);
-
-                assertNotNull("Expect non-null like vector for " + expType.getSimpleName() + " in " + desc, vLike);
-                assertEquals("Expect size equal to cardinality at " + desc, card, vLike.size());
-
-                Class<? extends Vector> actualType = vLike.getClass();
-
-                assertTrue("Actual vector type " + actualType.getSimpleName()
-                        + " should be assignable from expected type " + expType.getSimpleName() + " in " + desc,
-                    actualType.isAssignableFrom(expType));
-            });
-    }
-
-    /** */
-    @Test
-    public void minusTest() {
-        operationVectorTest((operand1, operand2) -> operand1 - operand2, Vector::minus);
-    }
-
-    /** */
-    @Test
-    public void plusVectorTest() {
-        operationVectorTest((operand1, operand2) -> operand1 + operand2, Vector::plus);
-    }
-
-    /** */
-    @Test
-    public void plusDoubleTest() {
-        operationTest((val, operand) -> val + operand, Vector::plus);
-    }
-
-    /** */
-    @Test
-    public void timesVectorTest() {
-        operationVectorTest((operand1, operand2) -> operand1 * operand2, Vector::times);
-    }
-
-    /** */
-    @Test
-    public void timesDoubleTest() {
-        operationTest((val, operand) -> val * operand, Vector::times);
-    }
-
-    /** */
-    @Test
-    public void viewPartTest() {
-        consumeSampleVectors((v, desc) -> {
-            final int size = v.size();
-            final double[] ref = new double[size];
-            final int delta = size > 32 ? 3 : 1; // IMPL NOTE this is for faster test execution
-
-            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
-
-            for (int off = 0; off < size; off += delta)
-                for (int len = 1; len < size - off; len += delta)
-                    checker.assertCloseEnough(v.viewPart(off, len), Arrays.copyOfRange(ref, off, off + len));
-        });
-    }
-
-    /** */
-    @Test
-    public void sumTest() {
-        toDoubleTest(
-            ref -> Arrays.stream(ref).sum(),
-            Vector::sum);
-    }
-
-    /** */
-    @Test
-    public void minValueTest() {
-        toDoubleTest(
-            ref -> Arrays.stream(ref).min().getAsDouble(),
-            Vector::minValue);
-    }
-
-    /** */
-    @Test
-    public void maxValueTest() {
-        toDoubleTest(
-            ref -> Arrays.stream(ref).max().getAsDouble(),
-            Vector::maxValue);
-    }
-
-    /** */
-    @Test
-    public void sortTest() {
-        consumeSampleVectors((v, desc) -> {
-            if (readOnly(v) || !v.isArrayBased()) {
-                boolean expECaught = false;
-
-                try {
-                    v.sort();
-                }
-                catch (UnsupportedOperationException uoe) {
-                    expECaught = true;
-                }
-
-                assertTrue("Expected exception was not caught for sort in " + desc, expECaught);
-
-                return;
-            }
-
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            new ElementsChecker(v, ref, desc).assertCloseEnough(v.sort(), Arrays.stream(ref).sorted().toArray());
-        });
-    }
-
-    /** */
-    @Test
-    public void metaAttributesTest() {
-        consumeSampleVectors((v, desc) -> {
-            assertNotNull("Null meta storage in " + desc, v.getMetaStorage());
-
-            final String key = "test key";
-            final String val = "test value";
-            final String details = "key [" + key + "] for " + desc;
-
-            v.setAttribute(key, val);
-            assertTrue("Expect to have meta attribute for " + details, v.hasAttribute(key));
-            assertEquals("Unexpected meta attribute value for " + details, val, v.getAttribute(key));
-
-            v.removeAttribute(key);
-            assertFalse("Expect not to have meta attribute for " + details, v.hasAttribute(key));
-            assertNull("Unexpected meta attribute value for " + details, v.getAttribute(key));
-        });
-    }
-
-    /** */
-    @Test
-    public void assignDoubleTest() {
-        consumeSampleVectors((v, desc) -> {
-            if (readOnly(v))
-                return;
-
-            for (double val : new double[] {0, -1, 0, 1}) {
-                v.assign(val);
-
-                for (int idx = 0; idx < v.size(); idx++) {
-                    final Metric metric = new Metric(val, v.get(idx));
-
-                    assertTrue("Not close enough at index " + idx + ", val " + val + ", " + metric
-                        + ", " + desc, metric.closeEnough());
-                }
-            }
-        });
-    }
-
-    /** */
-    @Test
-    public void assignDoubleArrTest() {
-        consumeSampleVectors((v, desc) -> {
-            if (readOnly(v))
-                return;
-
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
-
-            for (int idx = 0; idx < size; idx++)
-                ref[idx] = -ref[idx];
-
-            v.assign(ref);
-
-            checker.assertCloseEnough(v, ref);
-
-            assignDoubleArrWrongCardinality(v, desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void assignVectorTest() {
-        consumeSampleVectors((v, desc) -> {
-            if (readOnly(v))
-                return;
-
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
-
-            for (int idx = 0; idx < size; idx++)
-                ref[idx] = -ref[idx];
-
-            v.assign(new DenseLocalOnHeapVector(ref));
-
-            checker.assertCloseEnough(v, ref);
-
-            assignVectorWrongCardinality(v, desc);
-        });
-    }
-
-    /** */
-    @Test
-    public void assignFunctionTest() {
-        consumeSampleVectors((v, desc) -> {
-            if (readOnly(v))
-                return;
-
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
-
-            for (int idx = 0; idx < size; idx++)
-                ref[idx] = -ref[idx];
-
-            v.assign((idx) -> ref[idx]);
-
-            checker.assertCloseEnough(v, ref);
-        });
-    }
-
-    /** */
-    @Test
-    public void minElementTest() {
-        consumeSampleVectors((v, desc) -> {
-            final ElementsChecker checker = new ElementsChecker(v, desc);
-
-            final Vector.Element minE = v.minElement();
-
-            final int minEIdx = minE.index();
-
-            assertTrue("Unexpected index from minElement " + minEIdx + ", " + desc,
-                minEIdx >= 0 && minEIdx < v.size());
-
-            final Metric metric = new Metric(minE.get(), v.minValue());
-
-            assertTrue("Not close enough minElement at index " + minEIdx + ", " + metric
-                + ", " + desc, metric.closeEnough());
-
-            checker.assertNewMinElement(v);
-        });
-    }
-
-    /** */
-    @Test
-    public void maxElementTest() {
-        consumeSampleVectors((v, desc) -> {
-            final ElementsChecker checker = new ElementsChecker(v, desc);
-
-            final Vector.Element maxE = v.maxElement();
-
-            final int minEIdx = maxE.index();
-
-            assertTrue("Unexpected index from minElement " + minEIdx + ", " + desc,
-                minEIdx >= 0 && minEIdx < v.size());
-
-            final Metric metric = new Metric(maxE.get(), v.maxValue());
-
-            assertTrue("Not close enough maxElement at index " + minEIdx + ", " + metric
-                + ", " + desc, metric.closeEnough());
-
-            checker.assertNewMaxElement(v);
-        });
-    }
-
-    /** */
-    @Test
-    public void externalizeTest() {
-        (new ExternalizeTest<Vector>() {
-            /** {@inheritDoc} */
-            @Override public void externalizeTest() {
-                consumeSampleVectors((v, desc) -> {
-                    if (v instanceof SparseLocalOffHeapVector)
-                        return; //TODO: wait till SparseLocalOffHeapVector externalization support.
-
-                    externalizeTest(v);
-                });
-            }
-        }).externalizeTest();
-    }
-
-    /** */
-    @Test
-    public void hashCodeTest() {
-        consumeSampleVectors((v, desc) -> assertTrue("Zero hash code for " + desc, v.hashCode() != 0));
-    }
-
-    /** */
-    private boolean getXOutOfBoundsOK(Vector v) {
-        // todo find out if this is indeed OK
-        return v instanceof RandomVector || v instanceof ConstantVector
-            || v instanceof SingleElementVector || v instanceof SingleElementVectorView;
-    }
-
-    /** */
-    private void mutateAtIdxTest(Vector v, String desc, MutateAtIdx operation) {
-        if (readOnly(v)) {
-            if (v.size() < 1)
-                return;
-
-            boolean expECaught = false;
-
-            try {
-                operation.apply(v, 0, 1);
-            }
-            catch (UnsupportedOperationException uoe) {
-                expECaught = true;
-            }
-
-            assertTrue("Expect exception at attempt to mutate element in " + desc, expECaught);
-
-            return;
-        }
-
-        for (double val : new double[] {0, -1, 0, 1})
-            for (int idx = 0; idx < v.size(); idx++) {
-                double exp = operation.apply(v, idx, val);
-
-                final Metric metric = new Metric(exp, v.get(idx));
-
-                assertTrue("Not close enough at index " + idx + ", val " + val + ", " + metric
-                    + ", " + desc, metric.closeEnough());
-            }
-    }
-
-    /** */
-    private Class<? extends Vector> expLikeType(Vector v) {
-        Class<? extends Vector> clazz = v.getClass();
-
-        if (clazz.isAssignableFrom(PivotedVectorView.class) || clazz.isAssignableFrom(SingleElementVectorView.class))
-            return null;
-
-        if (clazz.isAssignableFrom(MatrixVectorView.class) || clazz.isAssignableFrom(DelegatingVector.class))
-            return DenseLocalOnHeapVector.class; // IMPL NOTE per fixture
-
-        return clazz;
-    }
-
-    /** */
-    private void toDoubleTest(Function<double[], Double> calcRef, Function<Vector, Double> calcVec) {
-        consumeSampleVectors((v, desc) -> {
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            new ElementsChecker(v, ref, desc); // IMPL NOTE this initialises vector and reference array
-
-            final Metric metric = new Metric(calcRef.apply(ref), calcVec.apply(v));
-
-            assertTrue("Not close enough at " + desc
-                + ", " + metric, metric.closeEnough());
-        });
-    }
-
-    /** */
-    private void operationVectorTest(BiFunction<Double, Double, Double> operation,
-        BiFunction<Vector, Vector, Vector> vecOperation) {
-        consumeSampleVectors((v, desc) -> {
-            // TODO find out if more elaborate testing scenario is needed or it's okay as is.
-            final int size = v.size();
-            final double[] ref = new double[size];
-
-            final ElementsChecker checker = new ElementsChecker(v, ref, desc);
-            final Vector operand = v.copy();
-
-            for (int idx = 0; idx < size; idx++)
-                ref[idx] = operation.apply(ref[idx], ref[idx]);
-
-            checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
-
-            assertWrongCardinality(v, desc, vecOperation);
-        });
-    }
-
-    /** */
-    private void assignDoubleArrWrongCardinality(Vector v, String desc) {
-        boolean expECaught = false;
-
-        try {
-            v.assign(new double[v.size() + 1]);
-        }
-        catch (CardinalityException ce) {
-            expECaught = true;
-        }
-
-        assertTrue("Expect exception at too large size in " + desc, expECaught);
-
-        if (v.size() < 2)
-            return;
-
-        expECaught = false;
-
-        try {
-            v.assign(new double[v.size() - 1]);
-        }
-        catch (CardinalityException ce) {
-            expECaught = true;
-        }
-
-        assertTrue("Expect exception at too small size in " + desc, expECaught);
-    }
-
-    /** */
-    private void assignVectorWrongCardinality(Vector v, String desc) {
-        boolean expECaught = false;
-
-        try {
-            v.assign(new DenseLocalOnHeapVector(v.size() + 1));
-        }
-        catch (CardinalityException ce) {
-            expECaught = true;
-        }
-
-        assertTrue("Expect exception at too large size in " + desc, expECaught);
-
-        if (v.size() < 2)
-            return;
-
-        expECaught = false;
-
-        try {
-            v.assign(new DenseLocalOnHeapVector(v.size() - 1));
-        }
-        catch (CardinalityException ce) {
-            expECaught = true;
-        }
-
-        assertTrue("Expect exception at too small size in " + desc, expECaught);
-    }
-
-    /** */
-    private void assertWrongCardinality(
-        Vector v, String desc, BiFunction<Vector, Vector, Vector> vecOperation) {
-        boolean expECaught = false;
-
-        try {
-            vecOperation.apply(v, new DenseLocalOnHeapVector(v.size() + 1));
-        }
-        catch (CardinalityException ce) {
-            expECaught = true;
-        }
-
-        assertTrue("Expect exception at too large size in " + desc, expECaught);
-
-        if (v.size() < 2)
-            return;
-
-        expECaught = false;
-
-        try {
-            vecOperation.apply(v, new DenseLocalOnHeapVector(v.size() - 1));
-        }
-        catch (CardinalityException ce) {
-            expECaught = true;
-        }
-
-        assertTrue("Expect exception at too small size in " + desc, expECaught);
-    }
-
-    /** */
-    private void operationTest(BiFunction<Double, Double, Double> operation,
-        BiFunction<Vector, Double, Vector> vecOperation) {
-        for (double val : new double[] {0, 0.1, 1, 2, 10})
-            consumeSampleVectors((v, desc) -> {
-                final int size = v.size();
-                final double[] ref = new double[size];
-
-                final ElementsChecker checker = new ElementsChecker(v, ref, "val " + val + ", " + desc);
-
-                for (int idx = 0; idx < size; idx++)
-                    ref[idx] = operation.apply(ref[idx], val);
-
-                checker.assertCloseEnough(vecOperation.apply(v, val), ref);
-            });
-    }
-
-    /** */
-    private void consumeSampleVectors(BiConsumer<Vector, String> consumer) {
-        consumeSampleVectors(null, consumer);
-    }
-
-    /** */
-    private void consumeSampleVectors(Consumer<Integer> paramsConsumer, BiConsumer<Vector, String> consumer) {
-        new VectorImplementationsFixtures().consumeSampleVectors(paramsConsumer, consumer);
-    }
-
-    /** */
-    private static boolean readOnly(Vector v) {
-        return v instanceof RandomVector || v instanceof ConstantVector;
-    }
-
-    /** */
-    private interface MutateAtIdx {
-        /** */
-        double apply(Vector v, int idx, double val);
-    }
-
-    /** */
-    static class ElementsChecker {
-        /** */
-        private final String fixtureDesc;
-
-        /** */
-        private final double[] refReadOnly;
-
-        /** */
-        private final boolean nonNegative;
-
-        /** */
-        ElementsChecker(Vector v, double[] ref, String fixtureDesc, boolean nonNegative) {
-            this.fixtureDesc = fixtureDesc;
-
-            this.nonNegative = nonNegative;
-
-            refReadOnly = readOnly(v) && ref == null ? new double[v.size()] : null;
-
-            init(v, ref);
-        }
-
-        /** */
-        ElementsChecker(Vector v, double[] ref, String fixtureDesc) {
-            this(v, ref, fixtureDesc, false);
-        }
-
-        /** */
-        ElementsChecker(Vector v, String fixtureDesc) {
-            this(v, null, fixtureDesc);
-        }
-
-        /** */
-        void assertCloseEnough(Vector obtained, double[] exp) {
-            final int size = obtained.size();
-
-            for (int i = 0; i < size; i++) {
-                final Vector.Element e = obtained.getElement(i);
-
-                if (refReadOnly != null && exp == null)
-                    exp = refReadOnly;
-
-                final Metric metric = new Metric(exp == null ? generated(i) : exp[i], e.get());
-
-                assertEquals("Unexpected vector index at " + fixtureDesc, i, e.index());
-                assertTrue("Not close enough at index " + i + ", size " + size + ", " + metric
-                    + ", " + fixtureDesc, metric.closeEnough());
-            }
-        }
-
-        /** */
-        void assertCloseEnough(Vector obtained) {
-            assertCloseEnough(obtained, null);
-        }
-
-        /** */
-        void assertNewMinElement(Vector v) {
-            if (readOnly(v))
-                return;
-
-            int exp = v.size() / 2;
-
-            v.set(exp, -(v.size() * 2 + 1));
-
-            assertEquals("Unexpected minElement index at " + fixtureDesc, exp, v.minElement().index());
-        }
-
-        /** */
-        void assertNewMaxElement(Vector v) {
-            if (readOnly(v))
-                return;
-
-            int exp = v.size() / 2;
-
-            v.set(exp, v.size() * 2 + 1);
-
-            assertEquals("Unexpected minElement index at " + fixtureDesc, exp, v.maxElement().index());
-        }
-
-        /** */
-        private void init(Vector v, double[] ref) {
-            if (readOnly(v)) {
-                initReadonly(v, ref);
-
-                return;
-            }
-
-            for (Vector.Element e : v.all()) {
-                int idx = e.index();
-
-                // IMPL NOTE introduce negative values because their absence
-                //    blocked catching an ugly bug in AbstractVector#kNorm
-                int val = generated(idx);
-
-                e.set(val);
-
-                if (ref != null)
-                    ref[idx] = val;
-            }
-        }
-
-        /** */
-        private void initReadonly(Vector v, double[] ref) {
-            if (refReadOnly != null)
-                for (Vector.Element e : v.all())
-                    refReadOnly[e.index()] = e.get();
-
-            if (ref != null)
-                for (Vector.Element e : v.all())
-                    ref[e.index()] = e.get();
-        }
-
-        /** */
-        private int generated(int idx) {
-            return nonNegative || (idx & 1) == 0 ? idx : -idx;
-        }
-    }
-
-    /** */
-    static class Metric { // todo consider if softer tolerance (like say 0.1 or 0.01) would make sense here
-        /** */
-        private final double exp;
-
-        /** */
-        private final double obtained;
-
-        /** **/
-        Metric(double exp, double obtained) {
-            this.exp = exp;
-            this.obtained = obtained;
-        }
-
-        /** */
-        boolean closeEnough() {
-            return new Double(exp).equals(obtained) || closeEnoughToZero();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Metric{" + "expected=" + exp +
-                ", obtained=" + obtained +
-                '}';
-        }
-
-        /** */
-        private boolean closeEnoughToZero() {
-            return (new Double(exp).equals(0.0) && new Double(obtained).equals(-0.0))
-                || (new Double(exp).equals(-0.0) && new Double(obtained).equals(0.0));
-        }
-    }
-}


[39/50] [abbrv] ignite git commit: master - Fix mvcc tests after CLOCK mode removal

Posted by sb...@apache.org.
master - Fix mvcc tests after CLOCK mode removal


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

Branch: refs/heads/ignite-1561
Commit: f82ed01807c80b36b7e361a5800ea131c1431c14
Parents: 9b21c85
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Tue Apr 18 18:40:55 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Tue Apr 18 18:43:28 2017 +0300

----------------------------------------------------------------------
 .../cache/GridCacheMvccPartitionedSelfTest.java | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f82ed018/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
index 2fb5d25..0c53fee 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
@@ -604,9 +604,9 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
     public void testSerializableReadLocksAdd() throws Exception {
         GridCacheAdapter<String, String> cache = grid.internalCache();
 
-        GridCacheVersion serOrder1 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder2 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder3 = new GridCacheVersion(0, 0, 1);
+        GridCacheVersion serOrder1 = new GridCacheVersion(0, 10, 1);
+        GridCacheVersion serOrder2 = new GridCacheVersion(0, 20, 1);
+        GridCacheVersion serOrder3 = new GridCacheVersion(0, 15, 1);
 
         {
             GridCacheMvcc mvcc = new GridCacheMvcc(cache.context());
@@ -681,9 +681,9 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
     public void testSerializableReadLocksAssign() throws Exception {
         GridCacheAdapter<String, String> cache = grid.internalCache();
 
-        GridCacheVersion serOrder1 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder2 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder3 = new GridCacheVersion(0, 0, 1);
+        GridCacheVersion serOrder1 = new GridCacheVersion(0, 10, 1);
+        GridCacheVersion serOrder2 = new GridCacheVersion(0, 20, 1);
+        GridCacheVersion serOrder3 = new GridCacheVersion(0, 15, 1);
 
         {
             GridCacheMvcc mvcc = new GridCacheMvcc(cache.context());
@@ -883,10 +883,10 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
 
         GridCacheTestEntryEx e = new GridCacheTestEntryEx(cache.context(), "1");
 
-        GridCacheVersion serOrder1 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder2 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder3 = new GridCacheVersion(0, 0, 1);
-        GridCacheVersion serOrder4 = new GridCacheVersion(0, 0, 1);
+        GridCacheVersion serOrder1 = new GridCacheVersion(0, 10, 1);
+        GridCacheVersion serOrder2 = new GridCacheVersion(0, 20, 1);
+        GridCacheVersion serOrder3 = new GridCacheVersion(0, 15, 1);
+        GridCacheVersion serOrder4 = new GridCacheVersion(0, 30, 1);
 
         GridCacheVersion ver1 = incVer ? version(1) : version(4);
         GridCacheVersion ver2 = incVer ? version(2) : version(3);


[14/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixView.java
new file mode 100644
index 0000000..b9a3b17
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/PivotedMatrixView.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.storage.matrix.PivotedMatrixStorage;
+import org.apache.ignite.ml.math.impls.vector.PivotedVectorView;
+
+/**
+ * Pivoted (index mapped) view over another matrix implementation.
+ */
+public class PivotedMatrixView extends AbstractMatrix {
+    /** Pivoted matrix. */
+    private Matrix mtx;
+
+    /**
+     *
+     */
+    public PivotedMatrixView() {
+        // No-op.
+    }
+
+    /**
+     * @param mtx
+     * @param rowPivot
+     * @param colPivot
+     */
+    public PivotedMatrixView(Matrix mtx, int[] rowPivot, int[] colPivot) {
+        super(new PivotedMatrixStorage(mtx == null ? null : mtx.getStorage(), rowPivot, colPivot));
+
+        this.mtx = mtx;
+    }
+
+    /**
+     * @param mtx
+     */
+    public PivotedMatrixView(Matrix mtx) {
+        super(new PivotedMatrixStorage(mtx == null ? null : mtx.getStorage()));
+
+        this.mtx = mtx;
+    }
+
+    /**
+     * @param mtx
+     * @param pivot
+     */
+    public PivotedMatrixView(Matrix mtx, int[] pivot) {
+        super(new PivotedMatrixStorage(mtx == null ? null : mtx.getStorage(), pivot));
+
+        this.mtx = mtx;
+    }
+
+    /**
+     * Swaps indexes {@code i} and {@code j} for both both row and column.
+     *
+     * @param i First index to swap.
+     * @param j Second index to swap.
+     */
+    public Matrix swap(int i, int j) {
+        swapRows(i, j);
+        swapColumns(i, j);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix swapRows(int i, int j) {
+        if (i < 0 || i >= storage().rowPivot().length)
+            throw new IndexException(i);
+        if (j < 0 || j >= storage().rowPivot().length)
+            throw new IndexException(j);
+
+        storage().swapRows(i, j);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix swapColumns(int i, int j) {
+        if (i < 0 || i >= storage().columnPivot().length)
+            throw new IndexException(i);
+        if (j < 0 || j >= storage().columnPivot().length)
+            throw new IndexException(j);
+
+        storage().swapColumns(i, j);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewRow(int row) {
+        return new PivotedVectorView(
+            mtx.viewRow(storage().rowPivot()[row]),
+            storage().columnPivot(),
+            storage().columnUnpivot()
+        );
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewColumn(int col) {
+        return new PivotedVectorView(
+            mtx.viewColumn(storage().columnPivot()[col]),
+            storage().rowPivot(),
+            storage().rowUnpivot()
+        );
+    }
+
+    /**
+     *
+     *
+     */
+    public Matrix getBaseMatrix() {
+        return mtx;
+    }
+
+    /**
+     *
+     *
+     */
+    public int[] rowPivot() {
+        return storage().rowPivot();
+    }
+
+    /**
+     *
+     *
+     */
+    public int[] columnPivot() {
+        return storage().columnPivot();
+    }
+
+    /**
+     * @param i
+     */
+    public int rowPivot(int i) {
+        return storage().rowPivot()[i];
+    }
+
+    /**
+     * @param i
+     */
+    public int columnPivot(int i) {
+        return storage().columnPivot()[i];
+    }
+
+    /**
+     * @param i
+     */
+    public int rowUnpivot(int i) {
+        return storage().rowUnpivot()[i];
+    }
+
+    /**
+     * @param i
+     */
+    public int columnUnpivot(int i) {
+        return storage().columnUnpivot()[i];
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        super.writeExternal(out);
+
+        out.writeObject(mtx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        super.readExternal(in);
+
+        mtx = (Matrix)in.readObject();
+    }
+
+    /**
+     *
+     *
+     */
+    private PivotedMatrixStorage storage() {
+        return (PivotedMatrixStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        return new PivotedMatrixView(mtx, storage().rowPivot(), storage().columnPivot());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + mtx.hashCode();
+        res = res * 37 + getStorage().hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        PivotedMatrixView that = (PivotedMatrixView)o;
+
+        MatrixStorage sto = storage();
+
+        return mtx.equals(that.mtx) && sto.equals(that.storage());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrix.java
new file mode 100644
index 0000000..ece4ca9
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/RandomMatrix.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.storage.matrix.RandomMatrixStorage;
+import org.apache.ignite.ml.math.impls.vector.RandomVector;
+
+/**
+ * Implementation of {@link Matrix} with random values in the elements.
+ */
+public class RandomMatrix extends AbstractMatrix {
+    /** Whether fast hash is used, see {@link RandomMatrixStorage}. */
+    private boolean fastHash;
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param fastHash Whether fast hash is used.
+     */
+    private MatrixStorage mkStorage(int rows, int cols, boolean fastHash) {
+        this.fastHash = fastHash;
+
+        return new RandomMatrixStorage(rows, cols, fastHash);
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param fastHash Whether fast hash is used.
+     */
+    public RandomMatrix(int rows, int cols, boolean fastHash) {
+        setStorage(mkStorage(rows, cols, fastHash));
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     */
+    public RandomMatrix(int rows, int cols) {
+        this(rows, cols, true);
+    }
+
+    /** */
+    public RandomMatrix() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        return new RandomMatrix(rowSize(), columnSize(), fastHash);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        return new RandomMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        return new RandomVector(crd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        super.writeExternal(out);
+
+        out.writeBoolean(fastHash);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        super.readExternal(in);
+
+        fastHash = in.readBoolean();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..8a7cffe
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
@@ -0,0 +1,155 @@
+// @java.file.header
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.impls.CacheUtils;
+import org.apache.ignite.ml.math.impls.storage.matrix.SparseDistributedMatrixStorage;
+
+/**
+ * Sparse distributed matrix implementation based on data grid.
+ *
+ * Unlike {@link CacheMatrix} that is based on existing cache, this implementation creates distributed
+ * cache internally and doesn't rely on pre-existing cache.
+ *
+ * You also need to call {@link #destroy()} to remove the underlying cache when you no longer need this
+ * matrix.
+ *
+ * <b>Currently fold supports only commutative operations.<b/>
+ */
+public class SparseDistributedMatrix extends AbstractMatrix implements StorageConstants {
+    /**
+     *
+     */
+    public SparseDistributedMatrix() {
+        // No-op.
+    }
+
+    /**
+     * @param rows
+     * @param cols
+     * @param stoMode
+     * @param acsMode
+     */
+    public SparseDistributedMatrix(int rows, int cols, int stoMode, int acsMode) {
+        assert rows > 0;
+        assert cols > 0;
+        assertAccessMode(acsMode);
+        assertStorageMode(stoMode);
+
+        setStorage(new SparseDistributedMatrixStorage(rows, cols, stoMode, acsMode));
+    }
+
+    /**
+     *
+     *
+     */
+    private SparseDistributedMatrixStorage storage() {
+        return (SparseDistributedMatrixStorage)getStorage();
+    }
+
+    /**
+     * Return the same matrix with updates values (broken contract).
+     *
+     * @param d
+     */
+    @Override public Matrix divide(double d) {
+        return mapOverValues((Double v) -> v / d);
+    }
+
+    /**
+     * Return the same matrix with updates values (broken contract).
+     *
+     * @param x
+     */
+    @Override public Matrix plus(double x) {
+        return mapOverValues((Double v) -> v + x);
+    }
+
+    /**
+     * Return the same matrix with updates values (broken contract).
+     *
+     * @param x
+     */
+    @Override public Matrix times(double x) {
+        return mapOverValues((Double v) -> v * x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assign(double val) {
+        return mapOverValues((Double v) -> val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix map(IgniteDoubleFunction<Double> fun) {
+        return mapOverValues(fun::apply);
+    }
+
+    /**
+     * @param mapper
+     */
+    private Matrix mapOverValues(IgniteFunction<Double, Double> mapper) {
+        CacheUtils.sparseMap(storage().cache().getName(), mapper);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        return CacheUtils.sparseSum(storage().cache().getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxValue() {
+        return CacheUtils.sparseMax(storage().cache().getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double minValue() {
+        return CacheUtils.sparseMin(storage().cache().getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrix.java
new file mode 100644
index 0000000..d711295
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseLocalOnHeapMatrix.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.storage.matrix.SparseLocalOnHeapMatrixStorage;
+import org.apache.ignite.ml.math.impls.vector.SparseLocalVector;
+
+/**
+ * Sparse local onheap matrix with {@link SparseLocalVector} as rows.
+ */
+public class SparseLocalOnHeapMatrix extends AbstractMatrix implements StorageConstants {
+    /**
+     *
+     */
+    public SparseLocalOnHeapMatrix() {
+        // No-op.
+    }
+
+    /**
+     * Construct new {@link SparseLocalOnHeapMatrix}.
+     *
+     * By default storage sets in row optimized mode and in random access mode.
+     */
+    public SparseLocalOnHeapMatrix(int rows, int cols) {
+        setStorage(mkStorage(rows, cols));
+    }
+
+    /**
+     * Create new {@link SparseLocalOnHeapMatrixStorage}.
+     */
+    private MatrixStorage mkStorage(int rows, int cols) {
+        return new SparseLocalOnHeapMatrixStorage(rows, cols, StorageConstants.RANDOM_ACCESS_MODE, StorageConstants.ROW_STORAGE_MODE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        return new SparseLocalOnHeapMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        return new SparseLocalVector(crd, StorageConstants.RANDOM_ACCESS_MODE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        Matrix cp = like(rowSize(), columnSize());
+
+        cp.assign(this);
+
+        return cp;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixView.java
new file mode 100644
index 0000000..309570b
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/TransposedMatrixView.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.storage.matrix.MatrixDelegateStorage;
+
+/**
+ * Implements transposed view of the parent {@link Matrix}.
+ */
+public class TransposedMatrixView extends AbstractMatrix {
+    /** */
+    public TransposedMatrixView() {
+        //No-op.
+    }
+
+    /**
+     * @param mtx Parent matrix.
+     */
+    public TransposedMatrixView(Matrix mtx) {
+        this(mtx == null ? null : mtx.getStorage());
+    }
+
+    /** */
+    private TransposedMatrixView(MatrixStorage sto) {
+        super(new MatrixDelegateStorage(sto, 0, 0,
+            sto == null ? 0 : sto.rowSize(), sto == null ? 0 : sto.columnSize()));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void storageSet(int row, int col, double v) {
+        super.storageSet(col, row, v);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected double storageGet(int row, int col) {
+        return super.storageGet(col, row);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return getStorage().columnSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return getStorage().rowSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        MatrixDelegateStorage sto = (MatrixDelegateStorage)getStorage();
+
+        return new TransposedMatrixView(sto.delegate());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/package-info.java
new file mode 100644
index 0000000..9eabf80
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains several matrix implementations.
+ */
+package org.apache.ignite.ml.math.impls.matrix;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/package-info.java
new file mode 100644
index 0000000..d531014
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains specific implementations for core algebra.
+ */
+package org.apache.ignite.ml.math.impls;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/ArrayMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/ArrayMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/ArrayMatrixStorage.java
new file mode 100644
index 0000000..397bf93
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/ArrayMatrixStorage.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import org.apache.ignite.ml.math.MatrixStorage;
+
+/**
+ * Array based {@link MatrixStorage} implementation.
+ */
+public class ArrayMatrixStorage implements MatrixStorage {
+    /** Backing data array. */
+    private double[][] data;
+    /** Amount of rows in the matrix. */
+    private int rows;
+    /** Amount of columns in the matrix. */
+    private int cols;
+
+    /**
+     *
+     */
+    public ArrayMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     */
+    public ArrayMatrixStorage(int rows, int cols) {
+        assert rows > 0;
+        assert cols > 0;
+
+        this.data = new double[rows][cols];
+        this.rows = rows;
+        this.cols = cols;
+    }
+
+    /**
+     * @param data Backing data array.
+     */
+    public ArrayMatrixStorage(double[][] data) {
+        assert data != null;
+        assert data[0] != null;
+
+        this.data = data;
+        this.rows = data.length;
+        this.cols = data[0].length;
+
+        assert rows > 0;
+        assert cols > 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return data[x][y];
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        data[x][y] = v;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[][] data() {
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(rows);
+        out.writeInt(cols);
+
+        out.writeObject(data);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        rows = in.readInt();
+        cols = in.readInt();
+
+        data = (double[][])in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res += res * 37 + rows;
+        res += res * 37 + cols;
+        res += res * 37 + Arrays.deepHashCode(data);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        ArrayMatrixStorage that = (ArrayMatrixStorage)o;
+
+        return Arrays.deepEquals(data, that.data);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/CacheMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/CacheMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/CacheMatrixStorage.java
new file mode 100644
index 0000000..510c4cf
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/CacheMatrixStorage.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.ml.math.MatrixKeyMapper;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.ValueMapper;
+
+/**
+ * Matrix storage based on arbitrary cache and key and value mapping functions.
+ */
+public class CacheMatrixStorage<K, V> implements MatrixStorage {
+    /** */ private int rows;
+    /** */  private int cols;
+    /** */ private IgniteCache<K, V> cache;
+    /** */ private MatrixKeyMapper<K> keyMapper;
+    /** */ private ValueMapper<V> valMapper;
+
+    /**
+     *
+     */
+    public CacheMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param rows
+     * @param cols
+     * @param cache
+     * @param keyMapper
+     * @param valMapper
+     */
+    public CacheMatrixStorage(int rows, int cols, IgniteCache<K, V> cache, MatrixKeyMapper<K> keyMapper,
+        ValueMapper<V> valMapper) {
+        assert rows > 0;
+        assert cols > 0;
+        assert cache != null;
+        assert keyMapper != null;
+        assert valMapper != null;
+
+        this.rows = rows;
+        this.cols = cols;
+        this.cache = cache;
+        this.keyMapper = keyMapper;
+        this.valMapper = valMapper;
+    }
+
+    /**
+     * @return Ignite cache.
+     */
+    public IgniteCache<K, V> cache() {
+        return cache;
+    }
+
+    /**
+     * @return Key mapper.
+     */
+    public MatrixKeyMapper<K> keyMapper() {
+        return keyMapper;
+    }
+
+    /**
+     * @return Value mapper.
+     */
+    public ValueMapper<V> valueMapper() {
+        return valMapper;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return valMapper.toDouble(cache.get(keyMapper.apply(x, y)));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        cache.put(keyMapper.apply(x, y), valMapper.fromDouble(v));
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(rows);
+        out.writeInt(cols);
+        out.writeUTF(cache.getName());
+        out.writeObject(keyMapper);
+        out.writeObject(valMapper);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"unchecked"})
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        rows = in.readInt();
+        cols = in.readInt();
+        cache = Ignition.localIgnite().getOrCreateCache(in.readUTF());
+        keyMapper = (MatrixKeyMapper<K>)in.readObject();
+        valMapper = (ValueMapper<V>)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + rows;
+        res = res * 37 + cols;
+        res = res * 37 + cache.hashCode();
+        res = res * 37 + keyMapper.hashCode();
+        res = res * 37 + valMapper.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        CacheMatrixStorage that = (CacheMatrixStorage)o;
+
+        return (cache != null ? cache.equals(that.cache) : that.cache == null) &&
+            (keyMapper != null ? keyMapper.equals(that.keyMapper) : that.keyMapper == null) &&
+            (valMapper != null ? valMapper.equals(that.valMapper) : that.valMapper == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java
new file mode 100644
index 0000000..74952a9
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.ml.math.MatrixStorage;
+
+/**
+ * Local, dense off-heap matrix storage.
+ */
+public class DenseOffHeapMatrixStorage implements MatrixStorage {
+    /** */ private int rows;
+    /** */ private int cols;
+    /** */ private transient long ptr;
+    //TODO: temp solution.
+    /** */ private int ptrInitHash;
+
+    /** */
+    public DenseOffHeapMatrixStorage() {
+        // No-op.
+    }
+
+    /** */
+    public DenseOffHeapMatrixStorage(int rows, int cols) {
+        assert rows > 0;
+        assert cols > 0;
+
+        this.rows = rows;
+        this.cols = cols;
+
+        allocateMemory(rows, cols);
+    }
+
+    /** */
+    public DenseOffHeapMatrixStorage(double[][] data) {
+        assert data != null;
+        assert data[0] != null;
+
+        this.rows = data.length;
+        this.cols = data[0].length;
+
+        assert rows > 0;
+        assert cols > 0;
+
+        allocateMemory(rows, cols);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                set(i, j, data[i][j]);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return GridUnsafe.getDouble(pointerOffset(x, y));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        GridUnsafe.putDouble(pointerOffset(x, y), v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[][] data() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(rows);
+        out.writeInt(cols);
+        out.writeInt(ptrInitHash);
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                out.writeDouble(get(i, j));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        rows = in.readInt();
+        cols = in.readInt();
+
+        allocateMemory(rows, cols);
+
+        ptrInitHash = in.readInt();
+
+        for (int i = 0; i < rows; i++)
+            for (int j = 0; j < cols; j++)
+                set(i, j, in.readDouble());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        GridUnsafe.freeMemory(ptr);
+    }
+
+    /** {@inheritDoc} */
+    private long pointerOffset(int x, int y) {
+        return ptr + x * cols * Double.BYTES + y * Double.BYTES;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        return obj != null &&
+            getClass().equals(obj.getClass()) &&
+            (rows == ((DenseOffHeapMatrixStorage)obj).rows) &&
+            (cols == ((DenseOffHeapMatrixStorage)obj).cols) &&
+            (rows == 0 || cols == 0 || ptr == ((DenseOffHeapMatrixStorage)obj).ptr || isMemoryEquals((DenseOffHeapMatrixStorage)obj));
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + rows;
+        res = res * 37 + cols;
+        res = res * 37 + ptrInitHash;
+
+        return res;
+    }
+
+    /** */
+    private boolean isMemoryEquals(DenseOffHeapMatrixStorage otherStorage) {
+        boolean res = true;
+
+        for (int i = 0; i < otherStorage.rows; i++) {
+            for (int j = 0; j < otherStorage.cols; j++) {
+                if (Double.compare(get(i, j), otherStorage.get(i, j)) != 0) {
+                    res = false;
+                    break;
+                }
+            }
+        }
+
+        return res;
+    }
+
+    /** */
+    private void allocateMemory(int rows, int cols) {
+        ptr = GridUnsafe.allocateMemory(rows * cols * Double.BYTES);
+
+        ptrInitHash = Long.hashCode(ptr);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DiagonalMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DiagonalMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DiagonalMatrixStorage.java
new file mode 100644
index 0000000..9daacee
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/DiagonalMatrixStorage.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+
+/**
+ * {@link MatrixStorage} implementation for diagonal Matrix view.
+ */
+public class DiagonalMatrixStorage implements MatrixStorage {
+    /** Backing vector for matrix diagonal. */
+    private Vector diagonal;
+
+    /**
+     *
+     */
+    public DiagonalMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param diagonal Backing {@link Vector} for matrix diagonal.
+     */
+    public DiagonalMatrixStorage(Vector diagonal) {
+        assert diagonal != null;
+
+        this.diagonal = diagonal;
+    }
+
+    /**
+     *
+     */
+    public Vector diagonal() {
+        return diagonal;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return x == y ? diagonal.get(x) : 0.0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        if (x == y)
+            diagonal.set(x, v);
+        else
+            throw new UnsupportedOperationException("Can't set off-diagonal element.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return diagonal.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return diagonal.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(diagonal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        diagonal = (Vector)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return diagonal.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return diagonal.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return diagonal.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return diagonal.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + diagonal.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        DiagonalMatrixStorage that = (DiagonalMatrixStorage)o;
+
+        return diagonal.equals(that.diagonal);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/FunctionMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/FunctionMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/FunctionMatrixStorage.java
new file mode 100644
index 0000000..acd7c29
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/FunctionMatrixStorage.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IntIntDoubleToVoidFunction;
+import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
+
+/**
+ * Read-only or read-write function-based matrix storage.
+ */
+public class FunctionMatrixStorage implements MatrixStorage {
+    /** */ private int rows;
+    /** */ private int cols;
+
+    /** */ private IntIntToDoubleFunction getFunc;
+    /** */ private IntIntDoubleToVoidFunction setFunc;
+
+    /**
+     *
+     */
+    public FunctionMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param getFunc Function that returns value corresponding to given row and column index.
+     * @param setFunc Set function. If {@code null} - this will be a read-only matrix.
+     */
+    public FunctionMatrixStorage(int rows, int cols, IntIntToDoubleFunction getFunc,
+        IntIntDoubleToVoidFunction setFunc) {
+        assert rows > 0;
+        assert cols > 0;
+        assert getFunc != null;
+
+        this.rows = rows;
+        this.cols = cols;
+        this.getFunc = getFunc;
+        this.setFunc = setFunc;
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param getFunc Function that returns value corresponding to given row and column index.
+     */
+    public FunctionMatrixStorage(int rows, int cols, IntIntToDoubleFunction getFunc) {
+        this(rows, cols, getFunc, null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return getFunc.apply(x, y);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        if (setFunc != null)
+            setFunc.apply(x, y, v);
+        else
+            throw new UnsupportedOperationException("Cannot set into read-only matrix.");
+    }
+
+    /**
+     *
+     */
+    public IntIntToDoubleFunction getFunction() {
+        return getFunc;
+    }
+
+    /**
+     *
+     */
+    public IntIntDoubleToVoidFunction setFunction() {
+        return setFunc;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(setFunc);
+        out.writeObject(getFunc);
+        out.writeInt(rows);
+        out.writeInt(cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        setFunc = (IntIntDoubleToVoidFunction)in.readObject();
+        getFunc = (IntIntToDoubleFunction)in.readObject();
+        rows = in.readInt();
+        cols = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        FunctionMatrixStorage that = (FunctionMatrixStorage)o;
+
+        return rows == that.rows && cols == that.cols
+            && (getFunc != null ? getFunc.equals(that.getFunc) : that.getFunc == null)
+            && (setFunc != null ? setFunc.equals(that.setFunc) : that.setFunc == null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = rows;
+
+        res = 31 * res + cols;
+        res = 31 * res + (getFunc != null ? getFunc.hashCode() : 0);
+        res = 31 * res + (setFunc != null ? setFunc.hashCode() : 0);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixDelegateStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixDelegateStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixDelegateStorage.java
new file mode 100644
index 0000000..1f77d0f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/MatrixDelegateStorage.java
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.MatrixStorage;
+
+/**
+ * {@link MatrixStorage} implementation that delegates to parent matrix.
+ */
+public class MatrixDelegateStorage implements MatrixStorage {
+    /** Parent matrix storage. */
+    private MatrixStorage sto;
+
+    /** Row offset in the parent matrix. */
+    private int rowOff;
+    /** Column offset in the parent matrix. */
+    private int colOff;
+
+    /** Amount of rows in the matrix. */
+    private int rows;
+    /** Amount of columns in the matrix. */
+    private int cols;
+
+    /**
+     *
+     */
+    public MatrixDelegateStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param sto Backing parent storage.
+     * @param rowOff Row offset to parent matrix.
+     * @param colOff Column offset to parent matrix.
+     * @param rows Amount of rows in the view.
+     * @param cols Amount of columns in the view.
+     */
+    public MatrixDelegateStorage(MatrixStorage sto, int rowOff, int colOff, int rows, int cols) {
+        assert sto != null;
+        assert rowOff >= 0;
+        assert colOff >= 0;
+        assert rows > 0;
+        assert cols > 0;
+
+        this.sto = sto;
+
+        this.rowOff = rowOff;
+        this.colOff = colOff;
+
+        this.rows = rows;
+        this.cols = cols;
+    }
+
+    /**
+     *
+     */
+    public MatrixStorage delegate() {
+        return sto;
+    }
+
+    /**
+     *
+     */
+    public int rowOffset() {
+        return rowOff;
+    }
+
+    /**
+     *
+     */
+    public int columnOffset() {
+        return colOff;
+    }
+
+    /**
+     *
+     */
+    public int rowsLength() {
+        return rows;
+    }
+
+    /**
+     *
+     */
+    public int columnsLength() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return sto.get(rowOff + x, colOff + y);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        sto.set(rowOff + x, colOff + y, v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return sto.isArrayBased() && rowOff == 0 && colOff == 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return sto.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return sto.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return sto.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return sto.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[][] data() {
+        return sto.data();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(sto);
+
+        out.writeInt(rowOff);
+        out.writeInt(colOff);
+
+        out.writeInt(rows);
+        out.writeInt(cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        sto = (MatrixStorage)in.readObject();
+
+        rowOff = in.readInt();
+        colOff = in.readInt();
+
+        rows = in.readInt();
+        cols = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + rows;
+        res = res * 37 + cols;
+        res = res * 37 + rowOff;
+        res = res * 37 + colOff;
+        res = res * 37 + sto.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        MatrixDelegateStorage that = (MatrixDelegateStorage)o;
+
+        return rows == that.rows && cols == that.cols && rowOff == that.rowOff && colOff == that.colOff &&
+            (sto != null ? sto.equals(that.sto) : that.sto == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/PivotedMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/PivotedMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/PivotedMatrixStorage.java
new file mode 100644
index 0000000..ab9b871
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/PivotedMatrixStorage.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import org.apache.ignite.ml.math.MatrixStorage;
+
+/**
+ * Pivoted (index mapped) view over another matrix storage implementation.
+ */
+public class PivotedMatrixStorage implements MatrixStorage {
+    /** Matrix storage. */
+    private MatrixStorage sto;
+
+    /** */
+    private int[] rowPivot;
+    /** */
+    private int[] colPivot;
+    /** */
+    private int[] rowUnpivot;
+    /** */
+    private int[] colUnpivot;
+
+    /**
+     *
+     */
+    public PivotedMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param sto Matrix storage.
+     * @param rowPivot Pivot array for rows.
+     * @param colPivot Pivot array for columns.
+     */
+    public PivotedMatrixStorage(MatrixStorage sto, int[] rowPivot, int[] colPivot) {
+        assert sto != null;
+        assert rowPivot != null;
+        assert colPivot != null;
+
+        this.sto = sto;
+        this.rowPivot = rowPivot;
+        this.colPivot = colPivot;
+
+        rowUnpivot = invert(rowPivot);
+        colUnpivot = invert(colPivot);
+    }
+
+    /**
+     *
+     */
+    public int[] rowPivot() {
+        return rowPivot;
+    }
+
+    /**
+     *
+     */
+    public int[] columnPivot() {
+        return colPivot;
+    }
+
+    /**
+     *
+     */
+    public int[] rowUnpivot() {
+        return rowUnpivot;
+    }
+
+    /**
+     *
+     */
+    public int[] columnUnpivot() {
+        return colUnpivot;
+    }
+
+    /**
+     * @param sto Matrix storage.
+     * @param pivot Pivot array.
+     */
+    public PivotedMatrixStorage(MatrixStorage sto, int[] pivot) {
+        this(sto, pivot, pivot == null ? null : java.util.Arrays.copyOf(pivot, pivot.length));
+    }
+
+    /**
+     * @param sto Matrix storage.
+     */
+    public PivotedMatrixStorage(MatrixStorage sto) {
+        this(sto, sto == null ? null : identityPivot(sto.rowSize()), sto == null ? null : identityPivot(sto.columnSize()));
+    }
+
+    /**
+     * @param i First row index to swap.
+     * @param j Second row index to swap.
+     */
+    public void swapRows(int i, int j) {
+        if (i != j) {
+            int tmp = rowPivot[i];
+
+            rowPivot[i] = rowPivot[j];
+            rowPivot[j] = tmp;
+
+            rowUnpivot[rowPivot[i]] = i;
+            rowUnpivot[rowPivot[j]] = j;
+        }
+    }
+
+    /**
+     * @param i First column index to swap.
+     * @param j Second column index to swap.
+     */
+    public void swapColumns(int i, int j) {
+        if (i != j) {
+            int tmp = colPivot[i];
+
+            colPivot[i] = colPivot[j];
+            colPivot[j] = tmp;
+
+            colUnpivot[colPivot[i]] = i;
+            colUnpivot[colPivot[j]] = j;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        return sto.get(rowPivot[x], colPivot[y]);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        sto.set(rowPivot[x], colPivot[y], v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return sto.columnSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return sto.rowSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(sto);
+        out.writeObject(rowPivot);
+        out.writeObject(colPivot);
+        out.writeObject(rowUnpivot);
+        out.writeObject(colUnpivot);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        sto = (MatrixStorage)in.readObject();
+        rowPivot = (int[])in.readObject();
+        colPivot = (int[])in.readObject();
+        rowUnpivot = (int[])in.readObject();
+        colUnpivot = (int[])in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return sto.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return sto.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return sto.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return sto.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + sto.hashCode();
+        res = res * 37 + Arrays.hashCode(rowPivot);
+        res = res * 37 + Arrays.hashCode(rowUnpivot);
+        res = res * 37 + Arrays.hashCode(colPivot);
+        res = res * 37 + Arrays.hashCode(colUnpivot);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        PivotedMatrixStorage that = (PivotedMatrixStorage)obj;
+
+        return Arrays.equals(rowPivot, that.rowPivot) && Arrays.equals(rowUnpivot, that.rowUnpivot)
+            && Arrays.equals(colPivot, that.colPivot) && Arrays.equals(colUnpivot, that.colUnpivot)
+            && (sto != null ? sto.equals(that.sto) : that.sto == null);
+    }
+
+    /**
+     * @param n Pivot array length.
+     */
+    private static int[] identityPivot(int n) {
+        int[] pivot = new int[n];
+
+        for (int i = 0; i < n; i++)
+            pivot[i] = i;
+
+        return pivot;
+    }
+
+    /**
+     * @param pivot Pivot array to be inverted.
+     */
+    private static int[] invert(int[] pivot) {
+        int[] x = new int[pivot.length];
+
+        for (int i = 0; i < pivot.length; i++)
+            x[pivot[i]] = i;
+
+        return x;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/RandomMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/RandomMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/RandomMatrixStorage.java
new file mode 100644
index 0000000..7e0ef27
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/RandomMatrixStorage.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.storage.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.nio.ByteBuffer;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.MurmurHash;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+
+/**
+ * {@link MatrixStorage} implementation with random values in the matrix elements.
+ */
+public class RandomMatrixStorage implements MatrixStorage {
+    /** */
+    private static final int PRIME1 = 104047;
+    /** */
+    private static final int PRIME2 = 101377;
+    /** */
+    private static final int PRIME3 = 64661;
+    /** */
+    private static final long SCALE = 1L << 32;
+
+    /** Random generation seed. */
+    private int seed;
+
+    /** Amount of rows in the matrix. */
+    private int rows;
+    /** Amount of columns in the matrix. */
+    private int cols;
+
+    /** Whether fast hash is used, in {@link #get(int, int)}. */
+    private boolean fastHash;
+
+    /**
+     * For externalization.
+     */
+    public RandomMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param fastHash Whether fast hash is used.
+     */
+    public RandomMatrixStorage(int rows, int cols, boolean fastHash) {
+        assert rows > 0;
+        assert cols > 0;
+
+        this.rows = rows;
+        this.cols = cols;
+        this.fastHash = fastHash;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        if (!fastHash) {
+            ByteBuffer buf = ByteBuffer.allocate(8);
+
+            buf.putInt(x);
+            buf.putInt(y);
+            buf.flip();
+
+            return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / (double)SCALE;
+        }
+        else
+            // This isn't a fantastic random number generator, but it is just fine for random projections.
+            return ((((x * PRIME1) + y * PRIME2 + x * y * PRIME3) & 8) * 0.25) - 1;
+    }
+
+    /**
+     *
+     */
+    public boolean isFastHash() {
+        return fastHash;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        throw new UnsupportedOperationException("Random matrix storage is a read-only storage.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(rows);
+        out.writeInt(cols);
+        out.writeInt(seed);
+        out.writeBoolean(fastHash);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        rows = in.readInt();
+        cols = in.readInt();
+        seed = in.readInt();
+        fastHash = in.readBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + Boolean.hashCode(fastHash);
+        res = res * 37 + seed;
+        res = res * 37 + cols;
+        res = res * 37 + rows;
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        RandomMatrixStorage that = (RandomMatrixStorage)o;
+
+        return rows == that.rows && cols == that.cols && seed == that.seed && fastHash == that.fastHash;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..cf200c7
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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 org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+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.lang.IgniteUuid;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.impls.CacheUtils;
+import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
+
+/**
+ * {@link MatrixStorage} implementation for {@link SparseDistributedMatrix}.
+ */
+public class SparseDistributedMatrixStorage extends CacheUtils implements MatrixStorage, StorageConstants {
+    /** 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;
+
+    /** Actual distributed storage. */
+    private IgniteCache<
+        Integer /* Row or column index. */,
+        Map<Integer, Double> /* Map-based row or column. */
+        > cache = null;
+
+    /**
+     *
+     */
+    public SparseDistributedMatrixStorage() {
+        // No-op.
+    }
+
+    /**
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param stoMode Row or column based storage mode.
+     * @param acsMode Random or sequential access mode.
+     */
+    public SparseDistributedMatrixStorage(int rows, int cols, int stoMode, int acsMode) {
+        assert rows > 0;
+        assert cols > 0;
+        assertAccessMode(acsMode);
+        assertStorageMode(stoMode);
+
+        this.rows = rows;
+        this.cols = cols;
+        this.stoMode = stoMode;
+        this.acsMode = acsMode;
+
+        cache = newCache();
+    }
+
+    /**
+     *
+     *
+     */
+    private IgniteCache<Integer, Map<Integer, Double>> newCache() {
+        CacheConfiguration<Integer, Map<Integer, Double>> cfg = new CacheConfiguration<>();
+
+        // Assume 10% density.
+        cfg.setStartSize(Math.max(1024, (rows * cols) / 10));
+
+        // Write to primary.
+        cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
+
+        // Atomic transactions only.
+        cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+        // No eviction.
+        cfg.setEvictionPolicy(null);
+
+        // No copying of values.
+        cfg.setCopyOnRead(false);
+
+        // Cache is partitioned.
+        cfg.setCacheMode(CacheMode.PARTITIONED);
+
+        // Random cache name.
+        cfg.setName(new IgniteUuid().shortString());
+
+        return Ignition.localIgnite().getOrCreateCache(cfg);
+    }
+
+    /**
+     *
+     *
+     */
+    public IgniteCache<Integer, Map<Integer, Double>> cache() {
+        return cache;
+    }
+
+    /**
+     *
+     *
+     */
+    public int accessMode() {
+        return acsMode;
+    }
+
+    /**
+     *
+     *
+     */
+    public int storageMode() {
+        return stoMode;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        if (stoMode == ROW_STORAGE_MODE)
+            return matrixGet(cache.getName(), x, y);
+        else
+            return matrixGet(cache.getName(), y, x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        if (stoMode == ROW_STORAGE_MODE)
+            matrixSet(cache.getName(), x, y, v);
+        else
+            matrixSet(cache.getName(), y, x, v);
+    }
+
+    /**
+     * Distributed matrix get.
+     *
+     * @param cacheName Matrix's cache.
+     * @param a Row or column index.
+     * @param b Row or column index.
+     * @return Matrix value at (a, b) index.
+     */
+    private double matrixGet(String cacheName, int a, int b) {
+        // Remote get from the primary node (where given row or column is stored locally).
+        return ignite().compute(groupForKey(cacheName, a)).call(() -> {
+            IgniteCache<Integer, Map<Integer, Double>> cache = Ignition.localIgnite().getOrCreateCache(cacheName);
+
+            // Local get.
+            Map<Integer, Double> map = cache.localPeek(a, CachePeekMode.PRIMARY);
+
+            return (map == null || !map.containsKey(b)) ? 0.0 : map.get(b);
+        });
+    }
+
+    /**
+     * Distributed matrix set.
+     *
+     * @param cacheName Matrix's cache.
+     * @param a Row or column index.
+     * @param b Row or column index.
+     * @param v New value to set.
+     */
+    private void matrixSet(String cacheName, int a, int b, double v) {
+        // Remote set on the primary node (where given row or column is stored locally).
+        ignite().compute(groupForKey(cacheName, a)).run(() -> {
+            IgniteCache<Integer, Map<Integer, Double>> cache = Ignition.localIgnite().getOrCreateCache(cacheName);
+
+            // Local get.
+            Map<Integer, Double> map = cache.localPeek(a, CachePeekMode.PRIMARY);
+
+            if (map == null)
+                map = acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap();
+
+            if (v != 0.0)
+                map.put(b, v);
+            else if (map.containsKey(b))
+                map.remove(b);
+
+            // Local put.
+            cache.put(a, map);
+        });
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(rows);
+        out.writeInt(cols);
+        out.writeInt(acsMode);
+        out.writeInt(stoMode);
+        out.writeUTF(cache.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        rows = in.readInt();
+        cols = in.readInt();
+        acsMode = in.readInt();
+        stoMode = in.readInt();
+        cache = ignite().getOrCreateCache(in.readUTF());
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return acsMode == SEQUENTIAL_ACCESS_MODE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return acsMode == RANDOM_ACCESS_MODE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** Destroy underlying cache. */
+    @Override public void destroy() {
+        cache.destroy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + cols;
+        res = res * 37 + rows;
+        res = res * 37 + acsMode;
+        res = res * 37 + stoMode;
+        res = res * 37 + cache.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        SparseDistributedMatrixStorage that = (SparseDistributedMatrixStorage)obj;
+
+        return rows == that.rows && cols == that.cols && acsMode == that.acsMode && stoMode == that.stoMode
+            && (cache != null ? cache.equals(that.cache) : that.cache == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..4530900
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.HashMap;
+import java.util.Map;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.StorageConstants;
+
+/**
+ * Storage for sparse, local, on-heap matrix.
+ */
+public class SparseLocalOnHeapMatrixStorage implements MatrixStorage, StorageConstants {
+    /** Default zero value. */
+    private static final double DEFAULT_VALUE = 0.0;
+
+    /** */ private int rows;
+    /** */ private int cols;
+
+    /** */ private int acsMode;
+    /** */ private int stoMode;
+
+    /** Actual map storage. */
+    private Map<Integer, Map<Integer, Double>> sto;
+
+    /** */
+    public SparseLocalOnHeapMatrixStorage() {
+        // No-op.
+    }
+
+    /** */
+    public SparseLocalOnHeapMatrixStorage(int rows, int cols, int acsMode, int stoMode) {
+        assert rows > 0;
+        assert cols > 0;
+        assertAccessMode(acsMode);
+        assertStorageMode(stoMode);
+
+        this.rows = rows;
+        this.cols = cols;
+        this.acsMode = acsMode;
+        this.stoMode = stoMode;
+
+        sto = new HashMap<>();
+    }
+
+    /**
+     *
+     *
+     */
+    public int getStorageMode() {
+        return stoMode;
+    }
+
+    /**
+     *
+     *
+     */
+    public int getAccessMode() {
+        return acsMode;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int x, int y) {
+        if (stoMode == ROW_STORAGE_MODE) {
+            Map<Integer, Double> row = sto.get(x);
+
+            if (row != null) {
+                Double val = row.get(y);
+
+                if (val != null)
+                    return val;
+            }
+
+            return DEFAULT_VALUE;
+        }
+        else {
+            Map<Integer, Double> col = sto.get(y);
+
+            if (col != null) {
+                Double val = col.get(x);
+
+                if (val != null)
+                    return val;
+            }
+
+            return DEFAULT_VALUE;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(int x, int y, double v) {
+        // Ignore default values (currently 0.0).
+        if (v != DEFAULT_VALUE) {
+            if (stoMode == ROW_STORAGE_MODE) {
+                Map<Integer, Double> row = sto.computeIfAbsent(x, k ->
+                    acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap());
+
+                row.put(y, v);
+            }
+            else {
+                Map<Integer, Double> col = sto.computeIfAbsent(y, k ->
+                    acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap());
+
+                col.put(x, v);
+            }
+        }
+        else {
+            if (stoMode == ROW_STORAGE_MODE) {
+                if (sto.containsKey(x)) {
+                    Map<Integer, Double> row = sto.get(x);
+
+                    if (row.containsKey(y))
+                        row.remove(y);
+                }
+
+            }
+            else {
+                if (sto.containsKey(y)) {
+                    Map<Integer, Double> col = sto.get(y);
+
+                    if (col.containsKey(x))
+                        col.remove(x);
+                }
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return cols;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return rows;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(rows);
+        out.writeInt(cols);
+        out.writeInt(acsMode);
+        out.writeInt(stoMode);
+        out.writeObject(sto);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"unchecked"})
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        rows = in.readInt();
+        cols = in.readInt();
+        acsMode = in.readInt();
+        stoMode = in.readInt();
+        sto = (Map<Integer, Map<Integer, Double>>)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return acsMode == SEQUENTIAL_ACCESS_MODE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return acsMode == RANDOM_ACCESS_MODE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + rows;
+        res = res * 37 + cols;
+        res = res * 37 + sto.hashCode();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        SparseLocalOnHeapMatrixStorage that = (SparseLocalOnHeapMatrixStorage)o;
+
+        return rows == that.rows && cols == that.cols && acsMode == that.acsMode && stoMode == that.stoMode
+            && (sto != null ? sto.equals(that.sto) : that.sto == null);
+    }
+}


[33/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexDropOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexDropOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexDropOperation.java
new file mode 100644
index 0000000..da60560
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexDropOperation.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.operation;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.UUID;
+
+/**
+ * Schema index drop operation.
+ */
+public class SchemaIndexDropOperation extends SchemaIndexAbstractOperation {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Index name. */
+    private final String idxName;
+
+    /** Ignore operation if index doesn't exist. */
+    private final boolean ifExists;
+
+    /**
+     * Constructor.
+     *
+     * @param opId Operation id.
+     * @param space Space.
+     * @param idxName Index name.
+     * @param ifExists Ignore operation if index doesn't exist.
+     */
+    public SchemaIndexDropOperation(UUID opId, String space, String idxName, boolean ifExists) {
+        super(opId, space);
+
+        this.idxName = idxName;
+        this.ifExists = ifExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String indexName() {
+        return idxName;
+    }
+
+    /**
+     * @return Ignore operation if index doesn't exist.
+     */
+    public boolean ifExists() {
+        return ifExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SchemaIndexDropOperation.class, this, "parent", super.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
index 1545b8c..a060f7e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
@@ -32,6 +32,7 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersionedEntryEx;
 import org.apache.ignite.internal.processors.dr.GridDrType;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure;
 import org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter;
 import org.apache.ignite.internal.util.lang.GridTuple3;
 import org.jetbrains.annotations.Nullable;
@@ -853,6 +854,12 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
     }
 
     /** {@inheritDoc} */
+    @Override public void updateIndex(SchemaIndexCacheVisitorClosure clo, long link) throws IgniteCheckedException,
+        GridCacheEntryRemovedException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
     @Override public boolean deleted() {
         return false;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
index 77d0ea7..ff67b77 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
@@ -66,6 +66,7 @@ public class GridTestKernalContext extends GridKernalContextImpl {
                 null,
                 null,
                 null,
+                null,
                 U.allPluginProviders()
         );
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
index b53387f..4404e9c 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
@@ -101,7 +101,7 @@ public class GridH2IndexingGeoSelfTest extends GridCacheAbstractSelfTest {
             List<List<?>> res = cache.query(new SqlFieldsQuery("explain select _key from Geometry where _val && ?")
                 .setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))")).setLocal(true)).getAll();
 
-            assertTrue("__ explain: " + res, res.get(0).get(0).toString().contains("_val_idx"));
+            assertTrue("__ explain: " + res, res.get(0).get(0).toString().toLowerCase().contains("_val_idx"));
         }
         finally {
             cache.destroy();
@@ -167,7 +167,7 @@ public class GridH2IndexingGeoSelfTest extends GridCacheAbstractSelfTest {
 
             // Check explaint request.
             assertTrue(F.first(cache.query(new SqlFieldsQuery("explain select * from EnemyCamp " +
-                "where coords && 'POINT(25 75)'")).getAll()).get(0).toString().contains("coords_idx"));
+                "where coords && 'POINT(25 75)'")).getAll()).get(0).toString().toLowerCase().contains("coords_idx"));
         }
         finally {
             cache.destroy();

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 7129691..e8dc73b 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -41,9 +41,11 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.cache.CacheOperationContext;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
@@ -51,7 +53,6 @@ import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
 import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator;
 import org.apache.ignite.internal.processors.query.GridQueryCancel;
-import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata;
 import org.apache.ignite.internal.processors.query.GridQueryFieldsResult;
 import org.apache.ignite.internal.processors.query.GridQueryFieldsResultAdapter;
 import org.apache.ignite.internal.processors.query.GridQueryProperty;
@@ -73,14 +74,18 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.h2.command.Prepared;
+import org.h2.command.dml.Delete;
+import org.h2.command.dml.Insert;
+import org.h2.command.dml.Merge;
+import org.h2.command.dml.Update;
 import org.h2.table.Column;
 import org.h2.value.DataType;
 import org.h2.value.Value;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
 
 import static org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode.createJdbcSqlException;
+import static org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.UPDATE_RESULT_META;
 
 /**
  *
@@ -90,11 +95,10 @@ public class DmlStatementsProcessor {
     private final static int DFLT_DML_RERUN_ATTEMPTS = 4;
 
     /** Indexing. */
-    private final IgniteH2Indexing indexing;
+    private IgniteH2Indexing idx;
 
-    /** Set of binary type ids for which warning about missing identity in configuration has been printed. */
-    private final static Set<Integer> WARNED_TYPES =
-        Collections.newSetFromMap(new ConcurrentHashMap8<Integer, Boolean>());
+    /** Logger. */
+    private IgniteLogger log;
 
     /** Default size for update plan cache. */
     private static final int PLAN_CACHE_SIZE = 1024;
@@ -102,15 +106,16 @@ public class DmlStatementsProcessor {
     /** Update plans cache. */
     private final ConcurrentMap<String, ConcurrentMap<String, UpdatePlan>> planCache = new ConcurrentHashMap<>();
 
-    /** Dummy metadata for update result. */
-    private final static List<GridQueryFieldMetadata> UPDATE_RESULT_META = Collections.<GridQueryFieldMetadata>
-        singletonList(new IgniteH2Indexing.SqlFieldMetadata(null, null, "UPDATED", Long.class.getName()));
-
     /**
-     * @param indexing indexing.
+     * Constructor.
+     *
+     * @param ctx Kernal context.
+     * @param idx indexing.
      */
-    DmlStatementsProcessor(IgniteH2Indexing indexing) {
-        this.indexing = indexing;
+    public void start(GridKernalContext ctx, IgniteH2Indexing idx) {
+        this.idx = idx;
+
+        log = ctx.log(DmlStatementsProcessor.class);
     }
 
     /**
@@ -251,7 +256,7 @@ public class DmlStatementsProcessor {
 
             final ArrayList<List<?>> data = new ArrayList<>(plan.rowsNum);
 
-            final GridQueryFieldsResult res = indexing.queryLocalSqlFields(cctx.name(), plan.selectQry,
+            final GridQueryFieldsResult res = idx.queryLocalSqlFields(cctx.name(), plan.selectQry,
                 F.asList(args), null, false, 0, null);
 
             QueryCursorImpl<List<?>> stepCur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@@ -335,10 +340,10 @@ public class DmlStatementsProcessor {
                 .setPageSize(fieldsQry.getPageSize())
                 .setTimeout(fieldsQry.getTimeout(), TimeUnit.MILLISECONDS);
 
-            cur = (QueryCursorImpl<List<?>>) indexing.queryTwoStep(cctx, newFieldsQry, cancel);
+            cur = (QueryCursorImpl<List<?>>) idx.queryTwoStep(cctx, newFieldsQry, cancel);
         }
         else {
-            final GridQueryFieldsResult res = indexing.queryLocalSqlFields(cctx.name(), plan.selectQry,
+            final GridQueryFieldsResult res = idx.queryLocalSqlFields(cctx.name(), plan.selectQry,
                 F.asList(fieldsQry.getArgs()), filters, fieldsQry.isEnforceJoinOrder(), fieldsQry.getTimeout(), cancel);
 
             cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@@ -476,7 +481,7 @@ public class DmlStatementsProcessor {
         while (it.hasNext()) {
             List<?> e = it.next();
             if (e.size() != 2) {
-                U.warn(indexing.getLogger(), "Invalid row size on DELETE - expected 2, got " + e.size());
+                U.warn(log, "Invalid row size on DELETE - expected 2, got " + e.size());
                 continue;
             }
 
@@ -1069,6 +1074,16 @@ public class DmlStatementsProcessor {
         }
     }
 
+    /**
+     * Check whether statement is DML statement.
+     *
+     * @param stmt Statement.
+     * @return {@code True} if this is DML.
+     */
+    static boolean isDmlStatement(Prepared stmt) {
+        return stmt instanceof Merge || stmt instanceof Insert || stmt instanceof Update || stmt instanceof Delete;
+    }
+
     /** Update result - modifications count and keys to re-run query with, if needed. */
     private final static class UpdateResult {
         /** Result to return for operations that affected 1 item - mostly to be used for fast updates and deletes. */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 531b760..4f0a9f9 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -78,10 +78,10 @@ import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
 import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
 import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
@@ -100,6 +100,9 @@ import org.apache.ignite.internal.processors.query.GridQueryProperty;
 import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
 import org.apache.ignite.internal.processors.query.GridRunningQueryInfo;
 import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl;
+import org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor;
+import org.apache.ignite.internal.processors.query.h2.opt.DistributedJoinMode;
 import org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex;
 import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory;
 import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex;
@@ -107,8 +110,9 @@ import org.apache.ignite.internal.processors.query.h2.database.io.H2ExtrasInnerI
 import org.apache.ignite.internal.processors.query.h2.database.io.H2ExtrasLeafIO;
 import org.apache.ignite.internal.processors.query.h2.database.io.H2InnerIO;
 import org.apache.ignite.internal.processors.query.h2.database.io.H2LeafIO;
-import org.apache.ignite.internal.processors.query.h2.opt.DistributedJoinMode;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2DefaultTableEngine;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2SystemIndexFactory;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOffheap;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext;
@@ -116,17 +120,19 @@ import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowFactory;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2TreeIndex;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject;
 import org.apache.ignite.internal.processors.query.h2.opt.GridLuceneIndex;
 import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser;
 import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter;
 import org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor;
 import org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap;
 import org.apache.ignite.internal.util.GridEmptyCloseableIterator;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
+import org.apache.ignite.internal.util.GridStringBuilder;
 import org.apache.ignite.internal.util.lang.GridCloseableIterator;
 import org.apache.ignite.internal.util.lang.GridPlainRunnable;
 import org.apache.ignite.internal.util.lang.IgniteInClosure2X;
@@ -150,14 +156,15 @@ import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.h2.api.ErrorCode;
 import org.h2.api.JavaObjectSerializer;
+import org.h2.api.TableEngine;
 import org.h2.command.CommandInterface;
 import org.h2.command.Prepared;
+import org.h2.command.ddl.CreateTableData;
 import org.h2.command.dml.Insert;
 import org.h2.engine.Session;
 import org.h2.engine.SysProperties;
 import org.h2.index.Cursor;
 import org.h2.index.Index;
-import org.h2.index.SpatialIndex;
 import org.h2.jdbc.JdbcConnection;
 import org.h2.jdbc.JdbcPreparedStatement;
 import org.h2.jdbc.JdbcStatement;
@@ -167,6 +174,7 @@ import org.h2.result.SortOrder;
 import org.h2.server.web.WebServer;
 import org.h2.table.Column;
 import org.h2.table.IndexColumn;
+import org.h2.table.TableBase;
 import org.h2.tools.Server;
 import org.h2.util.JdbcUtils;
 import org.h2.value.DataType;
@@ -221,8 +229,7 @@ import static org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryType
  */
 @SuppressWarnings({"UnnecessaryFullyQualifiedName", "NonFinalStaticVariableUsedInClassInitialization"})
 public class IgniteH2Indexing implements GridQueryIndexing {
-
-    /**
+    /*
      * Register IO for indexes.
      */
     static {
@@ -231,6 +238,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         H2ExtrasLeafIO.register();
     }
 
+    /** Spatial index class name. */
+    private static final String SPATIAL_IDX_CLS =
+        "org.apache.ignite.internal.processors.query.h2.opt.GridH2SpatialIndex";
+
     /** Default DB options. */
     private static final String DB_OPTIONS = ";LOCK_MODE=3;MULTI_THREADED=1;DB_CLOSE_ON_EXIT=FALSE" +
         ";DEFAULT_LOCK_TIMEOUT=10000;FUNCTIONS_IN_SCHEMA=true;OPTIMIZE_REUSE_RESULTS=0;QUERY_CACHE_SIZE=0" +
@@ -241,6 +252,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         // Uncomment this setting to get debug output from H2 to sysout.
 //        ";TRACE_LEVEL_SYSTEM_OUT=3";
 
+    /** Dummy metadata for update result. */
+    public static final List<GridQueryFieldMetadata> UPDATE_RESULT_META = Collections.<GridQueryFieldMetadata>
+        singletonList(new SqlFieldMetadata(null, null, "UPDATED", Long.class.getName()));
+
     /** */
     private static final int PREPARED_STMT_CACHE_SIZE = 256;
 
@@ -371,10 +386,13 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     };
 
     /** */
-    private volatile GridKernalContext ctx;
+    protected volatile GridKernalContext ctx;
+
+    /** */
+    private final DmlStatementsProcessor dmlProc = new DmlStatementsProcessor();
 
     /** */
-    private final DmlStatementsProcessor dmlProc = new DmlStatementsProcessor(this);
+    private DdlStatementsProcessor ddlProc;
 
     /** */
     private final ConcurrentMap<String, GridH2Table> dataTables = new ConcurrentHashMap8<>();
@@ -419,13 +437,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * @return Logger.
-     */
-    IgniteLogger getLogger() {
-        return log;
-    }
-
-    /**
      * @param c Connection.
      * @param sql SQL.
      * @param useStmtCache If {@code true} uses statement cache.
@@ -468,15 +479,15 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public PreparedStatement prepareNativeStatement(String schema, String sql) throws SQLException {
-        return prepareStatement(connectionForSpace(space(schema)), sql, true);
+    @Override public PreparedStatement prepareNativeStatement(String space, String sql) throws SQLException {
+        return prepareStatement(connectionForSpace(space), sql, true);
     }
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public IgniteDataStreamer<?, ?> createStreamer(String spaceName, PreparedStatement nativeStmt,
         long autoFlushFreq, int nodeBufSize, int nodeParOps, boolean allowOverwrite) {
-        Prepared prep = GridSqlQueryParser.prepared((JdbcPreparedStatement) nativeStmt);
+        Prepared prep = GridSqlQueryParser.prepared(nativeStmt);
 
         if (!(prep instanceof Insert))
             throw new IgniteSQLException("Only INSERT operations are supported in streaming mode",
@@ -625,14 +636,14 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
     /** {@inheritDoc} */
     @Override public void store(@Nullable String spaceName,
-        GridQueryTypeDescriptor type,
+        String typeName,
         KeyCacheObject k,
         int partId,
         CacheObject v,
         GridCacheVersion ver,
         long expirationTime,
         long link) throws IgniteCheckedException {
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+        TableDescriptor tbl = tableDescriptor(typeName, spaceName);
 
         if (tbl == null)
             return; // Type was rejected.
@@ -700,7 +711,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (log.isDebugEnabled())
             log.debug("Removing key from cache query index [locId=" + nodeId + ", key=" + key + ", val=" + val + ']');
 
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+        TableDescriptor tbl = tableDescriptor(type.name(), spaceName);
 
         if (tbl == null)
             return;
@@ -803,12 +814,232 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         tbl.schema.tbls.remove(tbl.typeName());
     }
 
+    /**
+     * Add initial user index.
+     *
+     * @param spaceName Space name.
+     * @param desc Table descriptor.
+     * @param h2Idx User index.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void addInitialUserIndex(String spaceName, TableDescriptor desc, GridH2IndexBase h2Idx)
+        throws IgniteCheckedException {
+        GridH2Table h2Tbl = desc.tbl;
+
+        h2Tbl.proposeUserIndex(h2Idx);
+
+        try {
+            String sql = indexCreateSql(desc.fullTableName(), h2Idx, false, desc.schema.escapeAll());
+
+            executeSql(spaceName, sql);
+        }
+        catch (Exception e) {
+            // Rollback and re-throw.
+            h2Tbl.rollbackUserIndex(h2Idx.getName());
+
+            throw e;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void dynamicIndexCreate(@Nullable final String spaceName, final String tblName,
+        final QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)
+        throws IgniteCheckedException {
+        // Locate table.
+        String schemaName = schema(spaceName);
+
+        Schema schema = schemas.get(schemaName);
+
+        TableDescriptor desc = (schema != null ? schema.tbls.get(tblName) : null);
+
+        if (desc == null)
+            throw new IgniteCheckedException("Table not found in internal H2 database [schemaName=" + schemaName +
+                ", tblName=" + tblName + ']');
+
+        GridH2Table h2Tbl = desc.tbl;
+
+        // Create index.
+        final GridH2IndexBase h2Idx = desc.createUserIndex(idxDesc);
+
+        h2Tbl.proposeUserIndex(h2Idx);
+
+        try {
+            // Populate index with existing cache data.
+            final GridH2RowDescriptor rowDesc = h2Tbl.rowDescriptor();
+
+            SchemaIndexCacheVisitorClosure clo = new SchemaIndexCacheVisitorClosure() {
+                @Override public void apply(KeyCacheObject key, int part, CacheObject val, GridCacheVersion ver,
+                    long expTime, long link) throws IgniteCheckedException {
+                    if (expTime == 0L)
+                        expTime = Long.MAX_VALUE;
+
+                    GridH2Row row = rowDesc.createRow(key, part, val, ver, expTime);
+
+                    row.link(link);
+
+                    h2Idx.put(row);
+                }
+            };
+
+            cacheVisitor.visit(clo);
+
+            // At this point index is in consistent state, promote it through H2 SQL statement, so that cached
+            // prepared statements are re-built.
+            String sql = indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists, schema.escapeAll());
+
+            executeSql(spaceName, sql);
+        }
+        catch (Exception e) {
+            // Rollback and re-throw.
+            h2Tbl.rollbackUserIndex(h2Idx.getName());
+
+            throw e;
+        }
+    }
+
     /** {@inheritDoc} */
+    @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
+    @Override public void dynamicIndexDrop(@Nullable final String spaceName, String idxName, boolean ifExists)
+        throws IgniteCheckedException{
+        String schemaName = schema(spaceName);
+
+        Schema schema = schemas.get(schemaName);
+
+        String sql = indexDropSql(schemaName, idxName, ifExists, schema.escapeAll());
+
+        executeSql(spaceName, sql);
+    }
+
+    /**
+     * Execute DDL command.
+     *
+     * @param spaceName Space name.
+     * @param sql SQL.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void executeSql(String spaceName, String sql) throws IgniteCheckedException {
+        try {
+            Connection conn = connectionForSpace(spaceName);
+
+            try (PreparedStatement stmt = prepareStatement(conn, sql, false)) {
+                stmt.execute();
+            }
+        }
+        catch (Exception e) {
+            throw new IgniteCheckedException("Failed to execute SQL statement on internal H2 database: " + sql, e);
+        }
+    }
+
+    /**
+     * Generate {@code CREATE INDEX} SQL statement for given params.
+     * @param fullTblName Fully qualified table name.
+     * @param h2Idx H2 index.
+     * @param ifNotExists Quietly skip index creation if it exists.
+     * @return Statement string.
+     */
+    private static String indexCreateSql(String fullTblName, GridH2IndexBase h2Idx, boolean ifNotExists,
+        boolean escapeAll) {
+        boolean spatial = F.eq(SPATIAL_IDX_CLS, h2Idx.getClass().getName());
+
+        GridStringBuilder sb = new SB("CREATE ")
+            .a(spatial ? "SPATIAL " : "")
+            .a("INDEX ")
+            .a(ifNotExists ? "IF NOT EXISTS " : "")
+            .a(escapeName(h2Idx.getName(), escapeAll))
+            .a(" ON ")
+            .a(fullTblName)
+            .a(" (");
+
+        boolean first = true;
+
+        for (IndexColumn col : h2Idx.getIndexColumns()) {
+            if (first)
+                first = false;
+            else
+                sb.a(", ");
+
+            sb.a("\"" + col.columnName + "\"").a(" ").a(col.sortType == SortOrder.ASCENDING ? "ASC" : "DESC");
+        }
+
+        sb.a(')');
+
+        return sb.toString();
+    }
+
+    /**
+     * Generate {@code CREATE INDEX} SQL statement for given params.
+     * @param schemaName <b>Quoted</b> schema name.
+     * @param idxName Index name.
+     * @param ifExists Quietly skip index drop if it exists.
+     * @param escapeAll Escape flag.
+     * @return Statement string.
+     */
+    private static String indexDropSql(String schemaName, String idxName, boolean ifExists, boolean escapeAll) {
+        return "DROP INDEX " + (ifExists ? "IF EXISTS " : "") + schemaName + '.' + escapeName(idxName, escapeAll);
+    }
+
+    /**
+     * Create sorted index.
+     *
+     * @param schema Schema.
+     * @param name Index name,
+     * @param tbl Table.
+     * @param pk Primary key flag.
+     * @param cols Columns.
+     * @return Index.
+     */
+    private GridH2IndexBase createSortedIndex(Schema schema, String name, GridH2Table tbl, boolean pk,
+        List<IndexColumn> cols, int inlineSize) {
+        try {
+            GridCacheContext cctx = schema.cacheContext();
+
+            if (log.isDebugEnabled())
+                log.debug("Creating cache index [cacheId=" + cctx.cacheId() + ", idxName=" + name + ']');
+
+            final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
+
+            return new H2TreeIndex(cctx, tbl, name, pk, cols, inlineSize, segments);
+        }
+        catch (IgniteCheckedException e) {
+            throw new IgniteException(e);
+        }
+    }
+
+    /**
+     * Create spatial index.
+     *
+     * @param tbl Table.
+     * @param idxName Index name.
+     * @param cols Columns.
+     */
+    private GridH2IndexBase createSpatialIndex(GridH2Table tbl, String idxName, IndexColumn[] cols
+    ) {
+        try {
+            Class<?> cls = Class.forName(SPATIAL_IDX_CLS);
+
+            Constructor<?> ctor = cls.getConstructor(
+                GridH2Table.class,
+                String.class,
+                Integer.TYPE,
+                IndexColumn[].class);
+
+            if (!ctor.isAccessible())
+                ctor.setAccessible(true);
+
+            final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
+
+            return (GridH2IndexBase)ctor.newInstance(tbl, idxName, segments, cols);
+        }
+        catch (Exception e) {
+            throw new IgniteException("Failed to instantiate: " + SPATIAL_IDX_CLS, e);
+        }
+    }
+
     @SuppressWarnings("unchecked")
     @Override public <K, V> GridCloseableIterator<IgniteBiTuple<K, V>> queryLocalText(
-        @Nullable String spaceName, String qry, GridQueryTypeDescriptor type,
+        @Nullable String spaceName, String qry, String typeName,
         IndexingQueryFilter filters) throws IgniteCheckedException {
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+        TableDescriptor tbl = tableDescriptor(typeName, spaceName);
 
         if (tbl != null && tbl.luceneIdx != null) {
             GridRunningQueryInfo run = new GridRunningQueryInfo(qryIdGen.incrementAndGet(), qry, TEXT, spaceName,
@@ -828,9 +1059,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void unregisterType(@Nullable String spaceName, GridQueryTypeDescriptor type)
+    @Override public void unregisterType(@Nullable String spaceName, String typeName)
         throws IgniteCheckedException {
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+        TableDescriptor tbl = tableDescriptor(typeName, spaceName);
 
         if (tbl != null)
             removeTable(tbl);
@@ -860,9 +1091,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         final PreparedStatement stmt = preparedStatementWithParams(conn, qry, params, true);
 
-        Prepared p = GridSqlQueryParser.prepared((JdbcPreparedStatement)stmt);
+        Prepared p = GridSqlQueryParser.prepared(stmt);
 
-        if (!p.isQuery()) {
+        if (DmlStatementsProcessor.isDmlStatement(p)) {
             SqlFieldsQuery fldsQry = new SqlFieldsQuery(qry);
 
             if (params != null)
@@ -873,6 +1104,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             return dmlProc.updateLocalSqlFields(spaceName, stmt, fldsQry, filter, cancel);
         }
+        else if (DdlStatementsProcessor.isDdlStatement(p))
+            throw new IgniteSQLException("DDL statements are supported for the whole cluster only",
+                IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
 
         List<GridQueryFieldMetadata> meta;
 
@@ -1419,6 +1653,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 .distributedJoinMode(distributedJoinMode));
 
             PreparedStatement stmt = null;
+            Prepared prepared;
 
             boolean cachesCreated = false;
 
@@ -1434,7 +1669,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                         catch (SQLException e) {
                             if (!cachesCreated && e.getErrorCode() == ErrorCode.SCHEMA_NOT_FOUND_1) {
                                 try {
-                                    ctx.cache().createMissingCaches();
+                                    ctx.cache().createMissingQueryCaches();
                                 }
                                 catch (IgniteCheckedException ignored) {
                                     throw new CacheException("Failed to create missing caches.", e);
@@ -1449,7 +1684,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                     }
 
 
-                    Prepared prepared = GridSqlQueryParser.prepared(stmt);
+                    prepared = GridSqlQueryParser.prepared(stmt);
 
                     if (qry instanceof JdbcSqlFieldsQuery && ((JdbcSqlFieldsQuery) qry).isQuery() != prepared.isQuery())
                         throw new IgniteSQLException("Given statement type does not match that declared by JDBC driver",
@@ -1470,12 +1705,23 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
                 // It is a DML statement if we did not create a twoStepQuery.
                 if (twoStepQry == null) {
-                    try {
-                        return dmlProc.updateSqlFieldsTwoStep(cctx.namexx(), stmt, qry, cancel);
+                    if (DmlStatementsProcessor.isDmlStatement(prepared)) {
+                        try {
+                            return dmlProc.updateSqlFieldsTwoStep(cctx.namexx(), stmt, qry, cancel);
+                        }
+                        catch (IgniteCheckedException e) {
+                            throw new IgniteSQLException("Failed to execute DML statement [stmt=" + sqlQry +
+                                ", params=" + Arrays.deepToString(qry.getArgs()) + "]", e);
+                        }
                     }
-                    catch (IgniteCheckedException e) {
-                        throw new IgniteSQLException("Failed to execute DML statement [qry=" + sqlQry + ", params=" +
-                            Arrays.deepToString(qry.getArgs()) + "]", e);
+
+                    if (DdlStatementsProcessor.isDdlStatement(prepared)) {
+                        try {
+                            return ddlProc.runDdlStatement(stmt);
+                        }
+                        catch (IgniteCheckedException e) {
+                            throw new IgniteSQLException("Failed to execute DDL statement [stmt=" + sqlQry + ']', e);
+                        }
                     }
                 }
 
@@ -1660,7 +1906,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         try {
             Connection conn = connectionForThread(schemaName);
 
-            createTable(schema, tbl, conn);
+            createTable(spaceName, schema, tbl, conn);
 
             schema.add(tbl);
         }
@@ -1754,12 +2000,15 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /**
      * Create db table by using given table descriptor.
      *
+     * @param spaceName Space name.
      * @param schema Schema.
      * @param tbl Table descriptor.
      * @param conn Connection.
      * @throws SQLException If failed to create db table.
+     * @throws IgniteCheckedException If failed.
      */
-    private void createTable(Schema schema, TableDescriptor tbl, Connection conn) throws SQLException {
+    private void createTable(String spaceName, Schema schema, TableDescriptor tbl, Connection conn)
+        throws SQLException, IgniteCheckedException {
         assert schema != null;
         assert tbl != null;
 
@@ -1783,12 +2032,17 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (log.isDebugEnabled())
             log.debug("Creating DB table with SQL: " + sql);
 
-        GridH2RowDescriptor desc = new RowDescriptor(tbl.type(), schema);
+        GridH2RowDescriptor rowDesc = new RowDescriptor(tbl.type(), schema);
 
-        GridH2Table res = GridH2Table.Engine.createTable(conn, sql.toString(), desc, tbl, tbl.schema.spaceName);
+        H2RowFactory rowFactory = tbl.rowFactory(rowDesc);
 
-        if (dataTables.putIfAbsent(res.identifier(), res) != null)
-            throw new IllegalStateException("Table already exists: " + res.identifier());
+        GridH2Table h2Tbl = H2TableEngine.createTable(conn, sql.toString(), rowDesc, rowFactory, tbl);
+
+        for (GridH2IndexBase usrIdx : tbl.createUserIndexes())
+            addInitialUserIndex(spaceName, tbl, usrIdx);
+
+        if (dataTables.putIfAbsent(h2Tbl.identifier(), h2Tbl) != null)
+            throw new IllegalStateException("Table already exists: " + h2Tbl.identifier());
     }
 
     /**
@@ -1800,24 +2054,29 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * Gets corresponding DB type from java class.
+     * Find table by name in given schema.
      *
-     * @param cls Java class.
-     * @return DB type name.
+     * @param schemaName Schema name.
+     * @param tblName Table name.
+     * @return Table or {@code null} if none found.
      */
-    private String dbTypeFromClass(Class<?> cls) {
-        return DBTypeEnum.fromClass(cls).dBTypeAsString();
+    public GridH2Table dataTable(String schemaName, String tblName) {
+        for (GridH2Table tbl : dataTables.values()) {
+            if (tbl.getSchema().getName().equals(schemaName) && tbl.getName().equals(tblName))
+                return tbl;
+        }
+
+        return null;
     }
 
     /**
-     * Gets table descriptor by value type.
+     * Gets corresponding DB type from java class.
      *
-     * @param spaceName Space name.
-     * @param type Value type descriptor.
-     * @return Table descriptor or {@code null} if not found.
+     * @param cls Java class.
+     * @return DB type name.
      */
-    @Nullable private TableDescriptor tableDescriptor(@Nullable String spaceName, GridQueryTypeDescriptor type) {
-        return tableDescriptor(type.name(), spaceName);
+    private String dbTypeFromClass(Class<?> cls) {
+        return DBTypeEnum.fromClass(cls).dBTypeAsString();
     }
 
     /**
@@ -1903,7 +2162,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      */
     @Override public void rebuildIndexesFromHash(@Nullable String spaceName,
         GridQueryTypeDescriptor type) throws IgniteCheckedException {
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+        TableDescriptor tbl = tableDescriptor(type.name(), spaceName);
 
         if (tbl == null)
             return;
@@ -1961,7 +2220,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
     /** {@inheritDoc} */
     @Override public void markForRebuildFromHash(@Nullable String spaceName, GridQueryTypeDescriptor type) {
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+        TableDescriptor tbl = tableDescriptor(type.name(), spaceName);
 
         if (tbl == null)
             return;
@@ -1975,12 +2234,12 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * Gets size (for tests only).
      *
      * @param spaceName Space name.
-     * @param type Type descriptor.
+     * @param typeName Type name.
      * @return Size.
      * @throws IgniteCheckedException If failed or {@code -1} if the type is unknown.
      */
-    long size(@Nullable String spaceName, GridQueryTypeDescriptor type) throws IgniteCheckedException {
-        TableDescriptor tbl = tableDescriptor(spaceName, type);
+    long size(@Nullable String spaceName, String typeName) throws IgniteCheckedException {
+        TableDescriptor tbl = tableDescriptor(typeName, spaceName);
 
         if (tbl == null)
             return -1;
@@ -2093,6 +2352,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                     cleanupStatementCache();
                 }
             }, CLEANUP_STMT_CACHE_PERIOD, CLEANUP_STMT_CACHE_PERIOD);
+
+            ddlProc = new DdlStatementsProcessor();
+
+            dmlProc.start(ctx, this);
+            ddlProc.start(ctx, this);
         }
 
         if (JdbcUtils.serializer != null)
@@ -2255,7 +2519,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             log.debug("Stopping cache query index...");
 
 //        unregisterMBean(); TODO https://issues.apache.org/jira/browse/IGNITE-2139
-
         if (ctx != null && !ctx.cache().context().database().persistenceEnabled()) {
             for (Schema schema : schemas.values())
                 schema.onDrop();
@@ -2778,7 +3041,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /**
      * Information about table in database.
      */
-    private class TableDescriptor implements GridH2Table.IndexesFactory {
+    private class TableDescriptor implements GridH2SystemIndexFactory {
         /** */
         private final String fullTblName;
 
@@ -2795,9 +3058,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         private GridLuceneIndex luceneIdx;
 
         /** */
-        private Index pkTreeIdx;
-
-        /** */
         private H2PkHashIndex pkHashIdx;
 
         /**
@@ -2808,7 +3068,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             this.type = type;
             this.schema = schema;
 
-            String tblName = escapeName(type.tableName() != null ? type.tableName() : type.name(), schema.escapeAll());
+            String tblName = escapeName(type.tableName(), schema.escapeAll());
 
             fullTblName = schema.schemaName + "." + tblName;
         }
@@ -2846,22 +3106,23 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             return S.toString(TableDescriptor.class, this);
         }
 
-        /** {@inheritDoc} */
-        @Override public H2RowFactory createRowFactory(GridH2Table tbl) {
-            int cacheId = CU.cacheId(schema.ccfg.getName());
-
-            GridCacheContext cctx = ctx.cache().context().cacheContext(cacheId);
+        /**
+         * Create H2 row factory.
+         *
+         * @param rowDesc Row descriptor.
+         * @return H2 row factory.
+         */
+        H2RowFactory rowFactory(GridH2RowDescriptor rowDesc) {
+            GridCacheContext cctx = schema.cacheContext();
 
             if (cctx.affinityNode() && cctx.offheapIndex())
-                return new H2RowFactory(tbl.rowDescriptor(), cctx);
+                return new H2RowFactory(rowDesc, cctx);
 
             return null;
         }
 
         /** {@inheritDoc} */
-        @Override public ArrayList<Index> createIndexes(GridH2Table tbl) {
-            this.tbl = tbl;
-
+        @Override public ArrayList<Index> createSystemIndexes(GridH2Table tbl) {
             ArrayList<Index> idxs = new ArrayList<>();
 
             IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
@@ -2870,25 +3131,27 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             if (affCol != null && equal(affCol, keyCol))
                 affCol = null;
 
-            int cacheId = CU.cacheId(schema.ccfg.getName());
-
             Index hashIdx = createHashIndex(
-                    cacheId,
-                    "_key_PK_hash",
-                    tbl,
-                    treeIndexColumns(new ArrayList<IndexColumn>(2), keyCol, affCol));
+                schema,
+                tbl,
+                "_key_PK_hash",
+                treeIndexColumns(new ArrayList<IndexColumn>(2), keyCol, affCol)
+            );
 
             if (hashIdx != null)
                 idxs.add(hashIdx);
 
             // Add primary key index.
-            idxs.add(createSortedIndex(
-                cacheId,
+            Index pkIdx = createSortedIndex(
+                schema,
                 "_key_PK",
                 tbl,
                 true,
                 treeIndexColumns(new ArrayList<IndexColumn>(2), keyCol, affCol),
-                -1));
+                -1
+            );
+
+            idxs.add(pkIdx);
 
             if (type().valueClass() == String.class) {
                 try {
@@ -2901,50 +3164,40 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             boolean affIdxFound = false;
 
-            for (Map.Entry<String, GridQueryIndexDescriptor> e : type.indexes().entrySet()) {
-                String name = e.getKey();
-                GridQueryIndexDescriptor idx = e.getValue();
+            GridQueryIndexDescriptor textIdx = type.textIndex();
 
-                if (idx.type() == QueryIndexType.FULLTEXT) {
-                    try {
-                        luceneIdx = new GridLuceneIndex(ctx, schema.offheap, schema.spaceName, type);
-                    }
-                    catch (IgniteCheckedException e1) {
-                        throw new IgniteException(e1);
-                    }
+            if (textIdx != null) {
+                try {
+                    luceneIdx = new GridLuceneIndex(ctx, schema.offheap, schema.spaceName, type);
                 }
-                else {
-                    List<IndexColumn> cols = new ArrayList<>(idx.fields().size() + 2);
-
-                    boolean escapeAll = schema.escapeAll();
+                catch (IgniteCheckedException e1) {
+                    throw new IgniteException(e1);
+                }
+            }
 
-                    for (String field : idx.fields()) {
-                        String fieldName = escapeAll ? field : escapeName(field, false).toUpperCase();
+            // Locate index where affinity column is first (if any).
+            if (affCol != null) {
+                for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
+                    if (idxDesc.type() != QueryIndexType.SORTED)
+                        continue;
 
-                        Column col = tbl.getColumn(fieldName);
+                    String firstField = idxDesc.fields().iterator().next();
 
-                        cols.add(tbl.indexColumn(col.getColumnId(),
-                            idx.descending(field) ? SortOrder.DESCENDING : SortOrder.ASCENDING));
-                    }
+                    String firstFieldName =
+                        schema.escapeAll() ? firstField : escapeName(firstField, false).toUpperCase();
 
-                    if (idx.type() == QueryIndexType.SORTED) {
-                        // We don't care about number of fields in affinity index, just affinity key must be the first.
-                        affIdxFound |= affCol != null && equal(cols.get(0), affCol);
+                    Column col = tbl.getColumn(firstFieldName);
 
-                        cols = treeIndexColumns(cols, keyCol, affCol);
+                    IndexColumn idxCol = tbl.indexColumn(col.getColumnId(),
+                        idxDesc.descending(firstField) ? SortOrder.DESCENDING : SortOrder.ASCENDING);
 
-                        idxs.add(createSortedIndex(cacheId, name, tbl, false, cols, idx.inlineSize()));
-                    }
-                    else if (idx.type() == QueryIndexType.GEOSPATIAL)
-                        idxs.add(createH2SpatialIndex(tbl, name, cols.toArray(new IndexColumn[cols.size()])));
-                    else
-                        throw new IllegalStateException("Index type: " + idx.type());
+                    affIdxFound |= equal(idxCol, affCol);
                 }
             }
 
             // Add explicit affinity key index if nothing alike was found.
             if (affCol != null && !affIdxFound) {
-                idxs.add(createSortedIndex(cacheId, "AFFINITY_KEY", tbl, false,
+                idxs.add(createSortedIndex(schema, "AFFINITY_KEY", tbl, false,
                     treeIndexColumns(new ArrayList<IndexColumn>(2), affCol, keyCol), -1));
             }
 
@@ -2952,121 +3205,92 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
 
         /**
-         * @param cacheId Cache ID.
-         * @param name Index name,
-         * @param tbl Table.
-         * @param pk Primary key flag.
-         * @param cols Columns.
-         * @return Index.
+         * Get collection of user indexes.
+         *
+         * @return User indexes.
          */
-        private Index createSortedIndex(
-            int cacheId,
-            String name,
-            GridH2Table tbl,
-            boolean pk,
-            List<IndexColumn> cols,
-            int inlineSize
-        ) {
-            try {
-                GridCacheSharedContext<Object, Object> scctx = ctx.cache().context();
+        public Collection<GridH2IndexBase> createUserIndexes() {
+            assert tbl != null;
 
-                GridCacheContext cctx = scctx.cacheContext(cacheId);
+            ArrayList<GridH2IndexBase> res = new ArrayList<>();
 
-                if (log.isInfoEnabled())
-                    log.info("Creating cache index [cacheId=" + cctx.cacheId() + ", idxName=" + name + ']');
+            for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
+                GridH2IndexBase idx = createUserIndex(idxDesc);
 
-                final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
-
-                return new H2TreeIndex(cctx, tbl, name, pk, cols, inlineSize, segments);
-            }
-            catch (IgniteCheckedException e) {
-                throw new IgniteException(e);
+                res.add(idx);
             }
+
+            return res;
         }
 
         /**
+         * Create user index.
+         *
+         * @param idxDesc Index descriptor.
          * @return Index.
          */
-        private Index createHashIndex(
-            int cacheId,
-            String name,
-            GridH2Table tbl,
-            List<IndexColumn> cols
-        ) {
-            GridCacheSharedContext<Object, Object> scctx = ctx.cache().context();
+        private GridH2IndexBase createUserIndex(GridQueryIndexDescriptor idxDesc) {
+            String name = schema.escapeAll() ? idxDesc.name() : escapeName(idxDesc.name(), false).toUpperCase();
 
-            GridCacheContext cctx = scctx.cacheContext(cacheId);
+            IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
+            IndexColumn affCol = tbl.getAffinityKeyColumn();
 
-            if (cctx.affinityNode() && cctx.offheapIndex()) {
-                assert pkHashIdx == null : pkHashIdx;
+            List<IndexColumn> cols = new ArrayList<>(idxDesc.fields().size() + 2);
 
-                pkHashIdx = new H2PkHashIndex(
-                    cctx,
-                    tbl,
-                    name,
-                    cols);
+            boolean escapeAll = schema.escapeAll();
 
-                return pkHashIdx;
-            }
+            for (String field : idxDesc.fields()) {
+                String fieldName = escapeAll ? field : escapeName(field, false).toUpperCase();
 
-            return null;
-        }
+                Column col = tbl.getColumn(fieldName);
 
-        /**
-         *
-         */
-        void onDrop() {
-            dataTables.remove(tbl.identifier(), tbl);
+                cols.add(tbl.indexColumn(col.getColumnId(),
+                    idxDesc.descending(field) ? SortOrder.DESCENDING : SortOrder.ASCENDING));
+            }
 
-            tbl.destroy();
+            if (idxDesc.type() == QueryIndexType.SORTED) {
+                cols = treeIndexColumns(cols, keyCol, affCol);
 
-            U.closeQuiet(luceneIdx);
+                return createSortedIndex(schema, name, tbl, false, cols, idxDesc.inlineSize());
+            }
+            else if (idxDesc.type() == QueryIndexType.GEOSPATIAL)
+                return createSpatialIndex(tbl, name, cols.toArray(new IndexColumn[cols.size()]));
+
+            throw new IllegalStateException("Index type: " + idxDesc.type());
         }
 
         /**
+         * Create hash index.
+         *
+         * @param schema Schema.
          * @param tbl Table.
          * @param idxName Index name.
          * @param cols Columns.
+         * @return Index.
          */
-        private SpatialIndex createH2SpatialIndex(
-            GridH2Table tbl,
-            String idxName,
-            IndexColumn[] cols
-        ) {
-            String className = "org.apache.ignite.internal.processors.query.h2.opt.GridH2SpatialIndex";
-
-            try {
-                Class<?> cls = Class.forName(className);
+        private Index createHashIndex(Schema schema, GridH2Table tbl, String idxName, List<IndexColumn> cols) {
+            GridCacheContext cctx = schema.cacheContext();
 
-                Constructor<?> ctor = cls.getConstructor(
-                    GridH2Table.class,
-                    String.class,
-                    Integer.TYPE,
-                    IndexColumn[].class);
-
-                if (!ctor.isAccessible())
-                    ctor.setAccessible(true);
+            if (cctx.affinityNode() && cctx.offheapIndex()) {
+                assert pkHashIdx == null : pkHashIdx;
 
-                final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
+                pkHashIdx = new H2PkHashIndex(cctx, tbl, idxName, cols);
 
-                return (SpatialIndex)ctor.newInstance(tbl, idxName, segments, cols);
-            }
-            catch (Exception e) {
-                throw new IgniteException("Failed to instantiate: " + className, e);
+                return pkHashIdx;
             }
+
+            return null;
         }
 
         /**
-         * @param idxName Index name.
-         * @param tbl Table.
-         * @param pk Primary key flag.
-         * @param columns Index column list.
-         * @return
+         *
          */
-        private Index createTreeIndex(String idxName, GridH2Table tbl, boolean pk, List<IndexColumn> columns) {
-            final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
+        void onDrop() {
+            dataTables.remove(tbl.identifier(), tbl);
+
+            tbl.destroy();
 
-            return new GridH2TreeIndex(idxName, tbl, pk, columns, segments);
+            U.closeQuiet(luceneIdx);
         }
     }
 
@@ -3252,6 +3476,13 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
 
         /**
+         * @return Cache context.
+         */
+        public GridCacheContext cacheContext() {
+            return cctx;
+        }
+
+        /**
          * @param tbl Table descriptor.
          */
         public void add(TableDescriptor tbl) {
@@ -3368,7 +3599,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         /** {@inheritDoc} */
         @Override public GridCacheContext<?, ?> context() {
-            return schema.cctx;
+            return schema.cacheContext();
         }
 
         /** {@inheritDoc} */
@@ -3625,4 +3856,63 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             lastUsage = U.currentTimeMillis();
         }
     }
+
+    /**
+     * H2 Table engine.
+     */
+    public static class H2TableEngine implements TableEngine {
+        /** */
+        private static GridH2RowDescriptor rowDesc0;
+
+        /** */
+        private static H2RowFactory rowFactory0;
+
+        /** */
+        private static TableDescriptor tblDesc0;
+
+        /** */
+        private static GridH2Table resTbl0;
+
+        /**
+         * Creates table using given connection, DDL clause for given type descriptor and list of indexes.
+         *
+         * @param conn Connection.
+         * @param sql DDL clause.
+         * @param rowDesc Row descriptor.
+         * @param rowFactory Row factory.
+         * @param tblDesc Table descriptor.
+         * @throws SQLException If failed.
+         * @return Created table.
+         */
+        public static synchronized GridH2Table createTable(Connection conn, String sql,
+            @Nullable GridH2RowDescriptor rowDesc, H2RowFactory rowFactory, TableDescriptor tblDesc)
+            throws SQLException {
+            rowDesc0 = rowDesc;
+            rowFactory0 = rowFactory;
+            tblDesc0 = tblDesc;
+
+            try {
+                try (Statement s = conn.createStatement()) {
+                    s.execute(sql + " engine \"" + H2TableEngine.class.getName() + "\"");
+                }
+
+                tblDesc.tbl = resTbl0;
+
+                return resTbl0;
+            }
+            finally {
+                resTbl0 = null;
+                tblDesc0 = null;
+                rowFactory0 = null;
+                rowDesc0 = null;
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public TableBase createTable(CreateTableData createTblData) {
+            resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, tblDesc0, tblDesc0.schema.spaceName);
+
+            return resTbl0;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
new file mode 100644
index 0000000..5b4b494
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.ddl;
+
+import java.sql.PreparedStatement;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
+import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
+import org.apache.ignite.internal.processors.query.GridQueryProperty;
+import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateIndex;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+import org.h2.command.Prepared;
+import org.h2.command.ddl.CreateIndex;
+import org.h2.command.ddl.DropIndex;
+import org.h2.jdbc.JdbcPreparedStatement;
+
+import static org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.UPDATE_RESULT_META;
+
+/**
+ * DDL statements processor.<p>
+ * Contains higher level logic to handle operations as a whole and communicate with the client.
+ */
+public class DdlStatementsProcessor {
+    /** Kernal context. */
+    GridKernalContext ctx;
+
+    /** Indexing. */
+    IgniteH2Indexing idx;
+
+    /**
+     * Initialize message handlers and this' fields needed for further operation.
+     *
+     * @param ctx Kernal context.
+     * @param idx Indexing.
+     */
+    public void start(final GridKernalContext ctx, IgniteH2Indexing idx) {
+        this.ctx = ctx;
+        this.idx = idx;
+    }
+
+    /**
+     * Execute DDL statement.
+     *
+     * @param stmt H2 statement to parse and execute.
+     */
+    @SuppressWarnings("unchecked")
+    public QueryCursor<List<?>> runDdlStatement(PreparedStatement stmt)
+        throws IgniteCheckedException {
+        assert stmt instanceof JdbcPreparedStatement;
+
+        IgniteInternalFuture fut;
+
+        try {
+            GridSqlStatement gridStmt = new GridSqlQueryParser(false).parse(GridSqlQueryParser.prepared(stmt));
+
+            if (gridStmt instanceof GridSqlCreateIndex) {
+                GridSqlCreateIndex createIdx = (GridSqlCreateIndex)gridStmt;
+
+                String spaceName = idx.space(createIdx.schemaName());
+
+                QueryIndex newIdx = new QueryIndex();
+
+                newIdx.setName(createIdx.index().getName());
+
+                newIdx.setIndexType(createIdx.index().getIndexType());
+
+                LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>();
+
+                GridH2Table tbl = idx.dataTable(createIdx.schemaName(), createIdx.tableName());
+
+                if (tbl == null)
+                    throw new IgniteSQLException("Table not found [schemaName=" + createIdx.schemaName() + ", " +
+                        "tblName=" + createIdx.tableName() + ']', IgniteQueryErrorCode.TABLE_NOT_FOUND);
+
+                assert tbl.rowDescriptor() != null;
+
+                // Let's replace H2's table and property names by those operated by GridQueryProcessor.
+                GridQueryTypeDescriptor typeDesc = tbl.rowDescriptor().type();
+
+                for (Map.Entry<String, Boolean> e : createIdx.index().getFields().entrySet()) {
+                    GridQueryProperty prop = typeDesc.property(e.getKey());
+
+                    if (prop == null)
+                        throw new IgniteSQLException("Property not found [typeName=" + typeDesc.name() + ", propName=" +
+                            e.getKey() + ']');
+
+                    flds.put(prop.name(), e.getValue());
+                }
+
+                newIdx.setFields(flds);
+
+                fut = ctx.query().dynamicIndexCreate(spaceName, typeDesc.tableName(), newIdx, createIdx.ifNotExists());
+            }
+            else if (gridStmt instanceof GridSqlDropIndex) {
+                GridSqlDropIndex dropIdx = (GridSqlDropIndex)gridStmt;
+
+                String spaceName = idx.space(dropIdx.schemaName());
+
+                fut = ctx.query().dynamicIndexDrop(spaceName, dropIdx.name(), dropIdx.ifExists());
+            }
+            else
+                throw new IgniteSQLException("Unexpected DDL operation [type=" + gridStmt.getClass() + ']',
+                    IgniteQueryErrorCode.UNEXPECTED_OPERATION);
+
+            fut.get();
+
+            QueryCursorImpl<List<?>> resCur = (QueryCursorImpl<List<?>>)new QueryCursorImpl(Collections.singletonList
+                (Collections.singletonList(0L)), null, false);
+
+            resCur.fieldsMeta(UPDATE_RESULT_META);
+
+            return resCur;
+        }
+        catch (SchemaOperationException e) {
+            throw convert(e);
+        }
+        catch (Exception e) {
+            throw new IgniteSQLException("DLL operation failed.", e);
+        }
+    }
+
+    /**
+     * @return {@link IgniteSQLException} with the message same as of {@code this}'s and
+     */
+    private IgniteSQLException convert(SchemaOperationException e) {
+        int sqlCode;
+
+        switch (e.code()) {
+            case SchemaOperationException.CODE_CACHE_NOT_FOUND:
+                sqlCode = IgniteQueryErrorCode.CACHE_NOT_FOUND;
+
+                break;
+
+            case SchemaOperationException.CODE_TABLE_NOT_FOUND:
+                sqlCode = IgniteQueryErrorCode.TABLE_NOT_FOUND;
+
+                break;
+
+            case SchemaOperationException.CODE_TABLE_EXISTS:
+                sqlCode = IgniteQueryErrorCode.TABLE_ALREADY_EXISTS;
+
+                break;
+
+            case SchemaOperationException.CODE_COLUMN_NOT_FOUND:
+                sqlCode = IgniteQueryErrorCode.COLUMN_NOT_FOUND;
+
+                break;
+
+            case SchemaOperationException.CODE_COLUMN_EXISTS:
+                sqlCode = IgniteQueryErrorCode.COLUMN_ALREADY_EXISTS;
+
+                break;
+
+            case SchemaOperationException.CODE_INDEX_NOT_FOUND:
+                sqlCode = IgniteQueryErrorCode.INDEX_NOT_FOUND;
+
+                break;
+
+            case SchemaOperationException.CODE_INDEX_EXISTS:
+                sqlCode = IgniteQueryErrorCode.INDEX_ALREADY_EXISTS;
+
+                break;
+
+            default:
+                sqlCode = IgniteQueryErrorCode.UNKNOWN;
+        }
+
+        return new IgniteSQLException(e.getMessage(), sqlCode);
+    }
+
+    /**
+     * @param cmd Statement.
+     * @return Whether {@code cmd} is a DDL statement we're able to handle.
+     */
+    public static boolean isDdlStatement(Prepared cmd) {
+        return cmd instanceof CreateIndex || cmd instanceof DropIndex;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
index 67e294a..7163834 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
@@ -376,7 +376,7 @@ public abstract class GridH2IndexBase extends BaseIndex {
 
     /** {@inheritDoc} */
     @Override public void remove(Session ses) {
-        throw DbException.getUnsupportedException("remove index");
+        // No-op: destroyed from owning table.
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PrimaryScanIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PrimaryScanIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PrimaryScanIndex.java
new file mode 100644
index 0000000..097b34e
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PrimaryScanIndex.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.opt;
+
+import org.h2.engine.Session;
+import org.h2.result.SortOrder;
+import org.h2.table.TableFilter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wrapper type for primary key.
+ */
+@SuppressWarnings("PackageVisibleInnerClass")
+public class GridH2PrimaryScanIndex extends GridH2ScanIndex<GridH2IndexBase> {
+    /** */
+    static final String SCAN_INDEX_NAME_SUFFIX = "__SCAN_";
+
+    /** Parent table. */
+    private final GridH2Table tbl;
+
+    /** */
+    private final GridH2IndexBase hashIdx;
+
+    /**
+     * Constructor.
+     *
+     * @param tbl Table.
+     * @param treeIdx Tree index.
+     * @param hashIdx Hash index.
+     */
+    GridH2PrimaryScanIndex(GridH2Table tbl, GridH2IndexBase treeIdx, @Nullable GridH2IndexBase hashIdx) {
+        super(treeIdx);
+
+        this.tbl = tbl;
+        this.hashIdx = hashIdx;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected GridH2IndexBase delegate() {
+        boolean rebuildFromHashInProgress = tbl.rebuildFromHashInProgress();
+
+        if (hashIdx != null)
+            return rebuildFromHashInProgress ? hashIdx : super.delegate();
+        else {
+            assert !rebuildFromHashInProgress;
+
+            return super.delegate();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getCost(Session ses, int[] masks, TableFilter[] filters, int filter,
+        SortOrder sortOrder) {
+        long rows = getRowCountApproximation();
+
+        double baseCost = getCostRangeIndex(masks, rows, filters, filter, sortOrder, true);
+
+        int mul = delegate().getDistributedMultiplier(ses, filters, filter);
+
+        return mul * baseCost;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getPlanSQL() {
+        return delegate().getTable().getSQL() + "." + SCAN_INDEX_NAME_SUFFIX;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getName() {
+        return delegate().getName() + SCAN_INDEX_NAME_SUFFIX;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SystemIndexFactory.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SystemIndexFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SystemIndexFactory.java
new file mode 100644
index 0000000..f150b6a
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SystemIndexFactory.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.opt;
+
+import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex;
+import org.h2.index.Index;
+
+import java.util.ArrayList;
+
+/**
+ * Factory for system table indexes.
+ */
+public interface GridH2SystemIndexFactory {
+    /**
+     * Create list of indexes. First must be primary key, after that all unique indexes and
+     * only then non-unique indexes.
+     * All indexes must be subtypes of {@link H2TreeIndex}.
+     *
+     * @param tbl Table to create indexes for.
+     * @return List of indexes.
+     */
+    ArrayList<Index> createSystemIndexes(GridH2Table tbl);
+}


[50/50] [abbrv] ignite git commit: Merge remote-tracking branch 'origin/ignite-1561' into ignite-1561

Posted by sb...@apache.org.
Merge remote-tracking branch 'origin/ignite-1561' into ignite-1561


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

Branch: refs/heads/ignite-1561
Commit: 78601cb180d6b6f450824ff9db2fe02a61e98fe3
Parents: df28c1a db84aad
Author: sboikov <sb...@gridgain.com>
Authored: Wed Apr 19 17:46:37 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Apr 19 17:46:37 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/dht/preloader/GridDhtPreloader.java          | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------



[16/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/DecompositionSupport.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/DecompositionSupport.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/DecompositionSupport.java
new file mode 100644
index 0000000..20d6e79
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/DecompositionSupport.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Destroyable;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.CacheMatrix;
+import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
+import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView;
+import org.apache.ignite.ml.math.impls.matrix.RandomMatrix;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+
+/**
+ * Helper methods to support decomposition of matrix types having some functionality limited.
+ */
+public abstract class DecompositionSupport implements Destroyable {
+    /**
+     * Create the like matrix with read-only matrices support.
+     *
+     * @param matrix Matrix for like.
+     * @return Like matrix.
+     */
+    protected Matrix like(Matrix matrix) {
+        if (isCopyLikeSupport(matrix))
+            return new DenseLocalOnHeapMatrix(matrix.rowSize(), matrix.columnSize());
+        else
+            return matrix.like(matrix.rowSize(), matrix.columnSize());
+    }
+
+    /**
+     * Create the like matrix with specified size with read-only matrices support.
+     *
+     * @param matrix Matrix for like.
+     * @return Like matrix.
+     */
+    protected Matrix like(Matrix matrix, int rows, int cols) {
+        if (isCopyLikeSupport(matrix))
+            return new DenseLocalOnHeapMatrix(rows, cols);
+        else
+            return matrix.like(rows, cols);
+    }
+
+    /**
+     * Create the like vector with read-only matrices support.
+     *
+     * @param matrix Matrix for like.
+     * @param crd Cardinality of the vector.
+     * @return Like vector.
+     */
+    protected Vector likeVector(Matrix matrix, int crd) {
+        if (isCopyLikeSupport(matrix))
+            return new DenseLocalOnHeapVector(crd);
+        else
+            return matrix.likeVector(crd);
+    }
+
+    /**
+     * Create the like vector with read-only matrices support.
+     *
+     * @param matrix Matrix for like.
+     * @return Like vector.
+     */
+    protected Vector likeVector(Matrix matrix) {
+        return likeVector(matrix, matrix.rowSize());
+    }
+
+    /**
+     * Create the copy of matrix with read-only matrices support.
+     *
+     * @param matrix Matrix for copy.
+     * @return Copy.
+     */
+    protected Matrix copy(Matrix matrix) {
+        if (isCopyLikeSupport(matrix)) {
+            DenseLocalOnHeapMatrix cp = new DenseLocalOnHeapMatrix(matrix.rowSize(), matrix.columnSize());
+
+            cp.assign(matrix);
+
+            return cp;
+        }
+        else
+            return matrix.copy();
+    }
+
+    /** */
+    private boolean isCopyLikeSupport(Matrix matrix) {
+        return matrix instanceof RandomMatrix || matrix instanceof PivotedMatrixView || matrix instanceof CacheMatrix;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/EigenDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/EigenDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/EigenDecomposition.java
new file mode 100644
index 0000000..01af989
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/EigenDecomposition.java
@@ -0,0 +1,923 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.functions.Functions;
+
+/**
+ * This class provides EigenDecomposition of given matrix. The class is based on
+ * class with similar name from <a href="http://mahout.apache.org/">Apache Mahout</a> library.
+ *
+ * @see <a href=http://mathworld.wolfram.com/EigenDecomposition.html>MathWorld</a>
+ */
+public class EigenDecomposition extends DecompositionSupport {
+    /** Row and column dimension (square matrix). */
+    private final int n;
+
+    /** Array for internal storage of eigen vectors. */
+    private final Matrix v;
+
+    /** Array for internal storage of eigenvalues. */
+    private final Vector d;
+    /** Array for internal storage of eigenvalues. */
+    private final Vector e;
+
+    /** */
+    public EigenDecomposition(Matrix matrix) {
+        this(matrix, isSymmetric(matrix));
+    }
+
+    /** */
+    public EigenDecomposition(Matrix matrix, boolean isSymmetric) {
+        n = matrix.columnSize();
+
+        d = likeVector(matrix);
+        e = likeVector(matrix);
+        v = like(matrix);
+
+        if (isSymmetric) {
+            v.assign(matrix);
+
+            // Tridiagonalize.
+            tred2();
+
+            // Diagonalize.
+            tql2();
+
+        }
+        else
+            // Reduce to Hessenberg form.
+            // Reduce Hessenberg to real Schur form.
+            hqr2(orthes(matrix));
+    }
+
+    /**
+     * Return the eigen vector matrix
+     *
+     * @return V
+     */
+    public Matrix getV() {
+        return like(v).assign(v);
+    }
+
+    /**
+     * Return the real parts of the eigenvalues
+     */
+    public Vector getRealEigenValues() {
+        return d;
+    }
+
+    /**
+     * Return the imaginary parts of the eigenvalues
+     */
+    public Vector getImagEigenvalues() {
+        return e;
+    }
+
+    /**
+     * Return the block diagonal eigenvalue matrix
+     *
+     * @return D
+     */
+    public Matrix getD() {
+        Matrix res = like(v, d.size(), d.size());
+        res.assign(0);
+        res.viewDiagonal().assign(d);
+        for (int i = 0; i < n; i++) {
+            double v = e.getX(i);
+            if (v > 0)
+                res.setX(i, i + 1, v);
+            else if (v < 0)
+                res.setX(i, i - 1, v);
+        }
+        return res;
+    }
+
+    /**
+     * Destroys decomposition components and other internal components of decomposition.
+     */
+    @Override public void destroy() {
+        e.destroy();
+        v.destroy();
+        d.destroy();
+    }
+
+    /** */
+    private void tred2() {
+        //  This is derived from the Algol procedures tred2 by
+        //  Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
+        //  Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
+        //  Fortran subroutine in EISPACK.
+
+        d.assign(v.viewColumn(n - 1));
+
+        // Householder reduction to tridiagonal form.
+
+        for (int i = n - 1; i > 0; i--) {
+
+            // Scale to avoid under/overflow.
+            double scale = d.viewPart(0, i).kNorm(1);
+            double h = 0.0;
+
+            if (scale == 0.0) {
+                e.setX(i, d.getX(i - 1));
+                for (int j = 0; j < i; j++) {
+                    d.setX(j, v.getX(i - 1, j));
+                    v.setX(i, j, 0.0);
+                    v.setX(j, i, 0.0);
+                }
+            }
+            else {
+
+                // Generate Householder vector.
+
+                for (int k = 0; k < i; k++) {
+                    d.setX(k, d.getX(k) / scale);
+                    h += d.getX(k) * d.getX(k);
+                }
+
+                double f = d.getX(i - 1);
+                double g = Math.sqrt(h);
+
+                if (f > 0)
+                    g = -g;
+
+                e.setX(i, scale * g);
+                h -= f * g;
+                d.setX(i - 1, f - g);
+
+                for (int j = 0; j < i; j++)
+                    e.setX(j, 0.0);
+
+                // Apply similarity transformation to remaining columns.
+
+                for (int j = 0; j < i; j++) {
+                    f = d.getX(j);
+                    v.setX(j, i, f);
+                    g = e.getX(j) + v.getX(j, j) * f;
+
+                    for (int k = j + 1; k <= i - 1; k++) {
+                        g += v.getX(k, j) * d.getX(k);
+                        e.setX(k, e.getX(k) + v.getX(k, j) * f);
+                    }
+
+                    e.setX(j, g);
+                }
+
+                f = 0.0;
+
+                for (int j = 0; j < i; j++) {
+                    e.setX(j, e.getX(j) / h);
+                    f += e.getX(j) * d.getX(j);
+                }
+
+                double hh = f / (h + h);
+
+                for (int j = 0; j < i; j++)
+                    e.setX(j, e.getX(j) - hh * d.getX(j));
+
+                for (int j = 0; j < i; j++) {
+                    f = d.getX(j);
+                    g = e.getX(j);
+
+                    for (int k = j; k <= i - 1; k++)
+                        v.setX(k, j, v.getX(k, j) - (f * e.getX(k) + g * d.getX(k)));
+
+                    d.setX(j, v.getX(i - 1, j));
+                    v.setX(i, j, 0.0);
+                }
+            }
+
+            d.setX(i, h);
+        }
+    }
+
+    /** */
+    private Matrix orthes(Matrix matrix) {
+        // Working storage for nonsymmetric algorithm.
+        Vector ort = likeVector(matrix);
+        Matrix hessenBerg = like(matrix).assign(matrix);
+
+        //  This is derived from the Algol procedures orthes and ortran,
+        //  by Martin and Wilkinson, Handbook for Auto. Comp.,
+        //  Vol.ii-Linear Algebra, and the corresponding
+        //  Fortran subroutines in EISPACK.
+
+        int low = 0;
+        int high = n - 1;
+
+        for (int m = low + 1; m <= high - 1; m++) {
+
+            // Scale column.
+
+            Vector hCol = hessenBerg.viewColumn(m - 1).viewPart(m, high - m + 1);
+            double scale = hCol.kNorm(1);
+
+            if (scale != 0.0) {
+                // Compute Householder transformation.
+                ort.viewPart(m, high - m + 1).map(hCol, Functions.plusMult(1 / scale));
+                double h = ort.viewPart(m, high - m + 1).getLengthSquared();
+
+                double g = Math.sqrt(h);
+
+                if (ort.getX(m) > 0)
+                    g = -g;
+
+                h -= ort.getX(m) * g;
+                ort.setX(m, ort.getX(m) - g);
+
+                // Apply Householder similarity transformation
+                // H = (I-u*u'/h)*H*(I-u*u')/h)
+
+                Vector ortPiece = ort.viewPart(m, high - m + 1);
+
+                for (int j = m; j < n; j++) {
+                    double f = ortPiece.dot(hessenBerg.viewColumn(j).viewPart(m, high - m + 1)) / h;
+                    hessenBerg.viewColumn(j).viewPart(m, high - m + 1).map(ortPiece, Functions.plusMult(-f));
+                }
+
+                for (int i = 0; i <= high; i++) {
+                    double f = ortPiece.dot(hessenBerg.viewRow(i).viewPart(m, high - m + 1)) / h;
+                    hessenBerg.viewRow(i).viewPart(m, high - m + 1).map(ortPiece, Functions.plusMult(-f));
+                }
+
+                ort.setX(m, scale * ort.getX(m));
+                hessenBerg.setX(m, m - 1, scale * g);
+            }
+        }
+
+        // Accumulate transformations (Algol's ortran).
+
+        v.assign(0);
+        v.viewDiagonal().assign(1);
+
+        for (int m = high - 1; m >= low + 1; m--) {
+            if (hessenBerg.getX(m, m - 1) != 0.0) {
+                ort.viewPart(m + 1, high - m).assign(hessenBerg.viewColumn(m - 1).viewPart(m + 1, high - m));
+
+                for (int j = m; j <= high; j++) {
+                    double g = ort.viewPart(m, high - m + 1).dot(v.viewColumn(j).viewPart(m, high - m + 1));
+
+                    // Double division avoids possible underflow
+                    g = g / ort.getX(m) / hessenBerg.getX(m, m - 1);
+                    v.viewColumn(j).viewPart(m, high - m + 1).map(ort.viewPart(m, high - m + 1), Functions.plusMult(g));
+                }
+            }
+        }
+
+        return hessenBerg;
+    }
+
+    /** Symmetric tridiagonal QL algorithm. */
+    private void tql2() {
+        //  This is derived from the Algol procedures tql2, by
+        //  Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
+        //  Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
+        //  Fortran subroutine in EISPACK.
+
+        e.viewPart(0, n - 1).assign(e.viewPart(1, n - 1));
+        e.setX(n - 1, 0.0);
+
+        double f = 0.0;
+        double tst1 = 0.0;
+        double eps = Math.pow(2.0, -52.0);
+
+        for (int l = 0; l < n; l++) {
+            // Find small subdiagonal element.
+
+            tst1 = Math.max(tst1, Math.abs(d.getX(l)) + Math.abs(e.getX(l)));
+            int m = l;
+
+            while (m < n) {
+                if (Math.abs(e.getX(m)) <= eps * tst1)
+                    break;
+
+                m++;
+            }
+
+            // If m == l, d.getX(l) is an eigenvalue,
+            // otherwise, iterate.
+
+            if (m > l) {
+                do {
+                    // Compute implicit shift
+
+                    double g = d.getX(l);
+                    double p = (d.getX(l + 1) - g) / (2.0 * e.getX(l));
+                    double r = Math.hypot(p, 1.0);
+
+                    if (p < 0)
+                        r = -r;
+
+                    d.setX(l, e.getX(l) / (p + r));
+                    d.setX(l + 1, e.getX(l) * (p + r));
+                    double dl1 = d.getX(l + 1);
+                    double h = g - d.getX(l);
+
+                    for (int i = l + 2; i < n; i++)
+                        d.setX(i, d.getX(i) - h);
+
+                    f += h;
+
+                    // Implicit QL transformation.
+
+                    p = d.getX(m);
+                    double c = 1.0;
+                    double c2 = c;
+                    double c3 = c;
+                    double el1 = e.getX(l + 1);
+                    double s = 0.0;
+                    double s2 = 0.0;
+
+                    for (int i = m - 1; i >= l; i--) {
+                        c3 = c2;
+                        c2 = c;
+                        s2 = s;
+                        g = c * e.getX(i);
+                        h = c * p;
+                        r = Math.hypot(p, e.getX(i));
+                        e.setX(i + 1, s * r);
+                        s = e.getX(i) / r;
+                        c = p / r;
+                        p = c * d.getX(i) - s * g;
+                        d.setX(i + 1, h + s * (c * g + s * d.getX(i)));
+
+                        // Accumulate transformation.
+
+                        for (int k = 0; k < n; k++) {
+                            h = v.getX(k, i + 1);
+                            v.setX(k, i + 1, s * v.getX(k, i) + c * h);
+                            v.setX(k, i, c * v.getX(k, i) - s * h);
+                        }
+                    }
+
+                    p = -s * s2 * c3 * el1 * e.getX(l) / dl1;
+                    e.setX(l, s * p);
+                    d.setX(l, c * p);
+
+                    // Check for convergence.
+
+                }
+                while (Math.abs(e.getX(l)) > eps * tst1);
+            }
+
+            d.setX(l, d.getX(l) + f);
+            e.setX(l, 0.0);
+        }
+
+        // Sort eigenvalues and corresponding vectors.
+
+        for (int i = 0; i < n - 1; i++) {
+            int k = i;
+            double p = d.getX(i);
+
+            for (int j = i + 1; j < n; j++)
+                if (d.getX(j) > p) {
+                    k = j;
+                    p = d.getX(j);
+                }
+
+            if (k != i) {
+                d.setX(k, d.getX(i));
+                d.setX(i, p);
+
+                for (int j = 0; j < n; j++) {
+                    p = v.getX(j, i);
+                    v.setX(j, i, v.getX(j, k));
+                    v.setX(j, k, p);
+                }
+            }
+        }
+    }
+
+    /** */
+    private void hqr2(Matrix h) {
+        //  This is derived from the Algol procedure hqr2,
+        //  by Martin and Wilkinson, Handbook for Auto. Comp.,
+        //  Vol.ii-Linear Algebra, and the corresponding
+        //  Fortran subroutine in EISPACK.
+
+        // Initialize
+
+        int nn = this.n;
+        int n = nn - 1;
+        int low = 0;
+        int high = nn - 1;
+        double eps = Math.pow(2.0, -52.0);
+        double exshift = 0.0;
+        double p = 0;
+        double q = 0;
+        double r = 0;
+        double s = 0;
+        double z = 0;
+        double w;
+        double x;
+        double y;
+
+        // Store roots isolated by balanc and compute matrix norm
+
+        double norm = h.foldMap(Functions.PLUS, Functions.ABS, 0.0);
+
+        // Outer loop over eigenvalue index
+
+        int iter = 0;
+        while (n >= low) {
+            // Look for single small sub-diagonal element
+            int l = n;
+
+            while (l > low) {
+                s = Math.abs(h.getX(l - 1, l - 1)) + Math.abs(h.getX(l, l));
+
+                if (s == 0.0)
+                    s = norm;
+
+                if (Math.abs(h.getX(l, l - 1)) < eps * s)
+                    break;
+
+                l--;
+            }
+
+            // Check for convergence
+
+            if (l == n) {
+                // One root found
+                h.setX(n, n, h.getX(n, n) + exshift);
+                d.setX(n, h.getX(n, n));
+                e.setX(n, 0.0);
+                n--;
+                iter = 0;
+            }
+            else if (l == n - 1) {
+                // Two roots found
+                w = h.getX(n, n - 1) * h.getX(n - 1, n);
+                p = (h.getX(n - 1, n - 1) - h.getX(n, n)) / 2.0;
+                q = p * p + w;
+                z = Math.sqrt(Math.abs(q));
+                h.setX(n, n, h.getX(n, n) + exshift);
+                h.setX(n - 1, n - 1, h.getX(n - 1, n - 1) + exshift);
+                x = h.getX(n, n);
+
+                // Real pair
+                if (q >= 0) {
+                    if (p >= 0)
+                        z = p + z;
+                    else
+                        z = p - z;
+
+                    d.setX(n - 1, x + z);
+                    d.setX(n, d.getX(n - 1));
+
+                    if (z != 0.0)
+                        d.setX(n, x - w / z);
+
+                    e.setX(n - 1, 0.0);
+                    e.setX(n, 0.0);
+                    x = h.getX(n, n - 1);
+                    s = Math.abs(x) + Math.abs(z);
+                    p = x / s;
+                    q = z / s;
+                    r = Math.sqrt(p * p + q * q);
+                    p /= r;
+                    q /= r;
+
+                    // Row modification
+
+                    for (int j = n - 1; j < nn; j++) {
+                        z = h.getX(n - 1, j);
+                        h.setX(n - 1, j, q * z + p * h.getX(n, j));
+                        h.setX(n, j, q * h.getX(n, j) - p * z);
+                    }
+
+                    // Column modification
+
+                    for (int i = 0; i <= n; i++) {
+                        z = h.getX(i, n - 1);
+                        h.setX(i, n - 1, q * z + p * h.getX(i, n));
+                        h.setX(i, n, q * h.getX(i, n) - p * z);
+                    }
+
+                    // Accumulate transformations
+
+                    for (int i = low; i <= high; i++) {
+                        z = v.getX(i, n - 1);
+                        v.setX(i, n - 1, q * z + p * v.getX(i, n));
+                        v.setX(i, n, q * v.getX(i, n) - p * z);
+                    }
+
+                    // Complex pair
+
+                }
+                else {
+                    d.setX(n - 1, x + p);
+                    d.setX(n, x + p);
+                    e.setX(n - 1, z);
+                    e.setX(n, -z);
+                }
+
+                n -= 2;
+                iter = 0;
+
+                // No convergence yet
+
+            }
+            else {
+                // Form shift
+                x = h.getX(n, n);
+                y = 0.0;
+                w = 0.0;
+
+                if (l < n) {
+                    y = h.getX(n - 1, n - 1);
+                    w = h.getX(n, n - 1) * h.getX(n - 1, n);
+                }
+
+                // Wilkinson's original ad hoc shift
+
+                if (iter == 10) {
+                    exshift += x;
+
+                    for (int i = low; i <= n; i++)
+                        h.setX(i, i, x);
+
+                    s = Math.abs(h.getX(n, n - 1)) + Math.abs(h.getX(n - 1, n - 2));
+                    x = y = 0.75 * s;
+                    w = -0.4375 * s * s;
+                }
+
+                // MATLAB's new ad hoc shift
+
+                if (iter == 30) {
+                    s = (y - x) / 2.0;
+                    s = s * s + w;
+
+                    if (s > 0) {
+                        s = Math.sqrt(s);
+
+                        if (y < x)
+                            s = -s;
+
+                        s = x - w / ((y - x) / 2.0 + s);
+
+                        for (int i = low; i <= n; i++)
+                            h.setX(i, i, h.getX(i, i) - s);
+
+                        exshift += s;
+                        x = y = w = 0.964;
+                    }
+                }
+
+                iter++;   // (Could check iteration count here.)
+
+                // Look for two consecutive small sub-diagonal elements
+
+                int m = n - 2;
+
+                while (m >= l) {
+                    z = h.getX(m, m);
+                    r = x - z;
+                    s = y - z;
+                    p = (r * s - w) / h.getX(m + 1, m) + h.getX(m, m + 1);
+                    q = h.getX(m + 1, m + 1) - z - r - s;
+                    r = h.getX(m + 2, m + 1);
+                    s = Math.abs(p) + Math.abs(q) + Math.abs(r);
+                    p /= s;
+                    q /= s;
+                    r /= s;
+
+                    if (m == l)
+                        break;
+
+                    double hmag = Math.abs(h.getX(m - 1, m - 1)) + Math.abs(h.getX(m + 1, m + 1));
+                    double threshold = eps * Math.abs(p) * (Math.abs(z) + hmag);
+
+                    if (Math.abs(h.getX(m, m - 1)) * (Math.abs(q) + Math.abs(r)) < threshold)
+                        break;
+
+                    m--;
+                }
+
+                for (int i = m + 2; i <= n; i++) {
+                    h.setX(i, i - 2, 0.0);
+
+                    if (i > m + 2)
+                        h.setX(i, i - 3, 0.0);
+                }
+
+                // Double QR step involving rows l:n and columns m:n
+
+                for (int k = m; k <= n - 1; k++) {
+                    boolean notlast = k != n - 1;
+
+                    if (k != m) {
+                        p = h.getX(k, k - 1);
+                        q = h.getX(k + 1, k - 1);
+                        r = notlast ? h.getX(k + 2, k - 1) : 0.0;
+                        x = Math.abs(p) + Math.abs(q) + Math.abs(r);
+                        if (x != 0.0) {
+                            p /= x;
+                            q /= x;
+                            r /= x;
+                        }
+                    }
+
+                    if (x == 0.0)
+                        break;
+
+                    s = Math.sqrt(p * p + q * q + r * r);
+
+                    if (p < 0)
+                        s = -s;
+
+                    if (s != 0) {
+                        if (k != m)
+                            h.setX(k, k - 1, -s * x);
+                        else if (l != m)
+                            h.setX(k, k - 1, -h.getX(k, k - 1));
+
+                        p += s;
+                        x = p / s;
+                        y = q / s;
+                        z = r / s;
+                        q /= p;
+                        r /= p;
+
+                        // Row modification
+
+                        for (int j = k; j < nn; j++) {
+                            p = h.getX(k, j) + q * h.getX(k + 1, j);
+
+                            if (notlast) {
+                                p += r * h.getX(k + 2, j);
+                                h.setX(k + 2, j, h.getX(k + 2, j) - p * z);
+                            }
+
+                            h.setX(k, j, h.getX(k, j) - p * x);
+                            h.setX(k + 1, j, h.getX(k + 1, j) - p * y);
+                        }
+
+                        // Column modification
+
+                        for (int i = 0; i <= Math.min(n, k + 3); i++) {
+                            p = x * h.getX(i, k) + y * h.getX(i, k + 1);
+
+                            if (notlast) {
+                                p += z * h.getX(i, k + 2);
+                                h.setX(i, k + 2, h.getX(i, k + 2) - p * r);
+                            }
+
+                            h.setX(i, k, h.getX(i, k) - p);
+                            h.setX(i, k + 1, h.getX(i, k + 1) - p * q);
+                        }
+
+                        // Accumulate transformations
+
+                        for (int i = low; i <= high; i++) {
+                            p = x * v.getX(i, k) + y * v.getX(i, k + 1);
+
+                            if (notlast) {
+                                p += z * v.getX(i, k + 2);
+                                v.setX(i, k + 2, v.getX(i, k + 2) - p * r);
+                            }
+
+                            v.setX(i, k, v.getX(i, k) - p);
+                            v.setX(i, k + 1, v.getX(i, k + 1) - p * q);
+                        }
+                    }  // (s != 0)
+                }  // k loop
+            }  // check convergence
+        }  // while (n >= low)
+
+        // Back substitute to find vectors of upper triangular form
+
+        if (norm == 0.0)
+            return;
+
+        for (n = nn - 1; n >= 0; n--) {
+            p = d.getX(n);
+            q = e.getX(n);
+
+            // Real vector
+
+            double t;
+
+            if (q == 0) {
+                int l = n;
+                h.setX(n, n, 1.0);
+
+                for (int i = n - 1; i >= 0; i--) {
+                    w = h.getX(i, i) - p;
+                    r = 0.0;
+
+                    for (int j = l; j <= n; j++)
+                        r += h.getX(i, j) * h.getX(j, n);
+
+                    if (e.getX(i) < 0.0) {
+                        z = w;
+                        s = r;
+                    }
+                    else {
+                        l = i;
+
+                        if (e.getX(i) == 0.0) {
+                            if (w == 0.0)
+                                h.setX(i, n, -r / (eps * norm));
+                            else
+                                h.setX(i, n, -r / w);
+
+                            // Solve real equations
+
+                        }
+                        else {
+                            x = h.getX(i, i + 1);
+                            y = h.getX(i + 1, i);
+                            q = (d.getX(i) - p) * (d.getX(i) - p) + e.getX(i) * e.getX(i);
+                            t = (x * s - z * r) / q;
+                            h.setX(i, n, t);
+
+                            if (Math.abs(x) > Math.abs(z))
+                                h.setX(i + 1, n, (-r - w * t) / x);
+                            else
+                                h.setX(i + 1, n, (-s - y * t) / z);
+                        }
+
+                        // Overflow control
+
+                        t = Math.abs(h.getX(i, n));
+
+                        if (eps * t * t > 1) {
+                            for (int j = i; j <= n; j++)
+                                h.setX(j, n, h.getX(j, n) / t);
+                        }
+                    }
+                }
+
+                // Complex vector
+
+            }
+            else if (q < 0) {
+                int l = n - 1;
+
+                // Last vector component imaginary so matrix is triangular
+
+                if (Math.abs(h.getX(n, n - 1)) > Math.abs(h.getX(n - 1, n))) {
+                    h.setX(n - 1, n - 1, q / h.getX(n, n - 1));
+                    h.setX(n - 1, n, -(h.getX(n, n) - p) / h.getX(n, n - 1));
+                }
+                else {
+                    cdiv(0.0, -h.getX(n - 1, n), h.getX(n - 1, n - 1) - p, q);
+                    h.setX(n - 1, n - 1, cdivr);
+                    h.setX(n - 1, n, cdivi);
+                }
+
+                h.setX(n, n - 1, 0.0);
+                h.setX(n, n, 1.0);
+
+                for (int i = n - 2; i >= 0; i--) {
+                    double ra = 0.0;
+                    double sa = 0.0;
+
+                    for (int j = l; j <= n; j++) {
+                        ra += h.getX(i, j) * h.getX(j, n - 1);
+                        sa += h.getX(i, j) * h.getX(j, n);
+                    }
+
+                    w = h.getX(i, i) - p;
+
+                    if (e.getX(i) < 0.0) {
+                        z = w;
+                        r = ra;
+                        s = sa;
+                    }
+                    else {
+                        l = i;
+
+                        if (e.getX(i) == 0) {
+                            cdiv(-ra, -sa, w, q);
+                            h.setX(i, n - 1, cdivr);
+                            h.setX(i, n, cdivi);
+                        }
+                        else {
+
+                            // Solve complex equations
+
+                            x = h.getX(i, i + 1);
+                            y = h.getX(i + 1, i);
+
+                            double vr = (d.getX(i) - p) * (d.getX(i) - p) + e.getX(i) * e.getX(i) - q * q;
+                            double vi = (d.getX(i) - p) * 2.0 * q;
+
+                            if (vr == 0.0 && vi == 0.0) {
+                                double hmag = Math.abs(x) + Math.abs(y);
+                                vr = eps * norm * (Math.abs(w) + Math.abs(q) + hmag + Math.abs(z));
+                            }
+
+                            cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi);
+
+                            h.setX(i, n - 1, cdivr);
+                            h.setX(i, n, cdivi);
+
+                            if (Math.abs(x) > (Math.abs(z) + Math.abs(q))) {
+                                h.setX(i + 1, n - 1, (-ra - w * h.getX(i, n - 1) + q * h.getX(i, n)) / x);
+                                h.setX(i + 1, n, (-sa - w * h.getX(i, n) - q * h.getX(i, n - 1)) / x);
+                            }
+                            else {
+                                cdiv(-r - y * h.getX(i, n - 1), -s - y * h.getX(i, n), z, q);
+
+                                h.setX(i + 1, n - 1, cdivr);
+                                h.setX(i + 1, n, cdivi);
+                            }
+                        }
+
+                        // Overflow control
+
+                        t = Math.max(Math.abs(h.getX(i, n - 1)), Math.abs(h.getX(i, n)));
+
+                        if (eps * t * t > 1)
+                            for (int j = i; j <= n; j++) {
+                                h.setX(j, n - 1, h.getX(j, n - 1) / t);
+                                h.setX(j, n, h.getX(j, n) / t);
+                            }
+                    }
+                }
+            }
+        }
+
+        // Vectors of isolated roots
+
+        for (int i = 0; i < nn; i++)
+            if (i < low || i > high) {
+                for (int j = i; j < nn; j++)
+                    v.setX(i, j, h.getX(i, j));
+            }
+
+        // Back transformation to get eigen vectors of original matrix
+
+        for (int j = nn - 1; j >= low; j--)
+            for (int i = low; i <= high; i++) {
+                z = 0.0;
+
+                for (int k = low; k <= Math.min(j, high); k++)
+                    z += v.getX(i, k) * h.getX(k, j);
+
+                v.setX(i, j, z);
+            }
+    }
+
+    /** */
+    private static boolean isSymmetric(Matrix matrix) {
+        int cols = matrix.columnSize();
+        int rows = matrix.rowSize();
+
+        if (cols != rows)
+            return false;
+
+        for (int i = 0; i < cols; i++)
+            for (int j = 0; j < rows; j++) {
+                if (matrix.getX(i, j) != matrix.get(j, i))
+                    return false;
+            }
+
+        return true;
+    }
+
+    /** Complex scalar division - real part. */
+    private double cdivr;
+    /** Complex scalar division - imaginary part. */
+    private double cdivi;
+
+    /** */
+    private void cdiv(double xr, double xi, double yr, double yi) {
+        double r;
+        double d;
+
+        if (Math.abs(yr) > Math.abs(yi)) {
+            r = yi / yr;
+            d = yr + r * yi;
+            cdivr = (xr + r * xi) / d;
+            cdivi = (xi - r * xr) / d;
+        }
+        else {
+            r = yr / yi;
+            d = yi + r * yr;
+            cdivr = (r * xr + xi) / d;
+            cdivi = (r * xi - xr) / d;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/LUDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/LUDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/LUDecomposition.java
new file mode 100644
index 0000000..b1efc09
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/LUDecomposition.java
@@ -0,0 +1,366 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.SingularMatrixException;
+
+/**
+ * Calculates the LU-decomposition of a square matrix.
+ *
+ * This class inspired by class from Apache Common Math with similar name.
+ *
+ * @see <a href="http://mathworld.wolfram.com/LUDecomposition.html">MathWorld</a>
+ * @see <a href="http://en.wikipedia.org/wiki/LU_decomposition">Wikipedia</a>
+ */
+public class LUDecomposition extends DecompositionSupport {
+    /** Default bound to determine effective singularity in LU decomposition. */
+    private static final double DEFAULT_TOO_SMALL = 1e-11;
+
+    /** Pivot permutation associated with LU decomposition. */
+    private final Vector pivot;
+    /** Parity of the permutation associated with the LU decomposition. */
+    private boolean even;
+    /** Singularity indicator. */
+    private boolean singular;
+    /** Cached value of L. */
+    private Matrix cachedL;
+    /** Cached value of U. */
+    private Matrix cachedU;
+    /** Cached value of P. */
+    private Matrix cachedP;
+    /** Original matrix. */
+    private Matrix matrix;
+    /** Entries of LU decomposition. */
+    private Matrix lu;
+
+    /**
+     * Calculates the LU-decomposition of the given matrix.
+     * This constructor uses 1e-11 as default value for the singularity
+     * threshold.
+     *
+     * @param matrix Matrix to decompose.
+     * @throws CardinalityException if matrix is not square.
+     */
+    public LUDecomposition(Matrix matrix) {
+        this(matrix, DEFAULT_TOO_SMALL);
+    }
+
+    /**
+     * Calculates the LUP-decomposition of the given matrix.
+     *
+     * @param matrix Matrix to decompose.
+     * @param singularityThreshold threshold (based on partial row norm).
+     * @throws CardinalityException if matrix is not square.
+     */
+    public LUDecomposition(Matrix matrix, double singularityThreshold) {
+        assert matrix != null;
+
+        int rows = matrix.rowSize();
+        int cols = matrix.columnSize();
+
+        if (rows != cols)
+            throw new CardinalityException(rows, cols);
+
+        this.matrix = matrix;
+
+        lu = copy(matrix);
+
+        pivot = likeVector(matrix);
+
+        for (int i = 0; i < pivot.size(); i++)
+            pivot.setX(i, i);
+
+        even = true;
+        singular = false;
+
+        cachedL = null;
+        cachedU = null;
+        cachedP = null;
+
+        for (int col = 0; col < cols; col++) {
+
+            //upper
+            for (int row = 0; row < col; row++) {
+                Vector luRow = lu.viewRow(row);
+                double sum = luRow.get(col);
+
+                for (int i = 0; i < row; i++)
+                    sum -= luRow.getX(i) * lu.getX(i, col);
+
+                luRow.setX(col, sum);
+            }
+
+            // permutation row
+            int max = col;
+
+            double largest = Double.NEGATIVE_INFINITY;
+
+            // lower
+            for (int row = col; row < rows; row++) {
+                Vector luRow = lu.viewRow(row);
+                double sum = luRow.getX(col);
+
+                for (int i = 0; i < col; i++)
+                    sum -= luRow.getX(i) * lu.getX(i, col);
+
+                luRow.setX(col, sum);
+
+                if (Math.abs(sum) > largest) {
+                    largest = Math.abs(sum);
+                    max = row;
+                }
+            }
+
+            // Singularity check
+            if (Math.abs(lu.getX(max, col)) < singularityThreshold) {
+                singular = true;
+                return;
+            }
+
+            // Pivot if necessary
+            if (max != col) {
+                double tmp;
+                Vector luMax = lu.viewRow(max);
+                Vector luCol = lu.viewRow(col);
+
+                for (int i = 0; i < cols; i++) {
+                    tmp = luMax.getX(i);
+                    luMax.setX(i, luCol.getX(i));
+                    luCol.setX(i, tmp);
+                }
+
+                int temp = (int)pivot.getX(max);
+                pivot.setX(max, pivot.getX(col));
+                pivot.setX(col, temp);
+
+                even = !even;
+            }
+
+            // Divide the lower elements by the "winning" diagonal elt.
+            final double luDiag = lu.getX(col, col);
+
+            for (int row = col + 1; row < cols; row++) {
+                double val = lu.getX(row, col) / luDiag;
+                lu.setX(row, col, val);
+            }
+        }
+    }
+
+    /**
+     * Destroys decomposition components and other internal components of decomposition.
+     */
+    @Override public void destroy() {
+        if (cachedL != null)
+            cachedL.destroy();
+        if (cachedU != null)
+            cachedU.destroy();
+        if (cachedP != null)
+            cachedP.destroy();
+        lu.destroy();
+    }
+
+    /**
+     * Returns the matrix L of the decomposition.
+     * <p>L is a lower-triangular matrix</p>
+     *
+     * @return the L matrix (or null if decomposed matrix is singular).
+     */
+    public Matrix getL() {
+        if ((cachedL == null) && !singular) {
+            final int m = pivot.size();
+
+            cachedL = like(matrix);
+            cachedL.assign(0.0);
+
+            for (int i = 0; i < m; ++i) {
+                for (int j = 0; j < i; ++j)
+                    cachedL.setX(i, j, lu.getX(i, j));
+
+                cachedL.setX(i, i, 1.0);
+            }
+        }
+
+        return cachedL;
+    }
+
+    /**
+     * Returns the matrix U of the decomposition.
+     * <p>U is an upper-triangular matrix</p>
+     *
+     * @return the U matrix (or null if decomposed matrix is singular).
+     */
+    public Matrix getU() {
+        if ((cachedU == null) && !singular) {
+            final int m = pivot.size();
+
+            cachedU = like(matrix);
+            cachedU.assign(0.0);
+
+            for (int i = 0; i < m; ++i)
+                for (int j = i; j < m; ++j)
+                    cachedU.setX(i, j, lu.getX(i, j));
+        }
+
+        return cachedU;
+    }
+
+    /**
+     * Returns the P rows permutation matrix.
+     * <p>P is a sparse matrix with exactly one element set to 1.0 in
+     * each row and each column, all other elements being set to 0.0.</p>
+     * <p>The positions of the 1 elements are given by the {@link #getPivot()
+     * pivot permutation vector}.</p>
+     *
+     * @return the P rows permutation matrix (or null if decomposed matrix is singular).
+     * @see #getPivot()
+     */
+    public Matrix getP() {
+        if ((cachedP == null) && !singular) {
+            final int m = pivot.size();
+
+            cachedP = like(matrix);
+            cachedP.assign(0.0);
+
+            for (int i = 0; i < m; ++i)
+                cachedP.setX(i, (int)pivot.get(i), 1.0);
+        }
+
+        return cachedP;
+    }
+
+    /**
+     * Returns the pivot permutation vector.
+     *
+     * @return the pivot permutation vector.
+     * @see #getP()
+     */
+    public Vector getPivot() {
+        return pivot.copy();
+    }
+
+    /**
+     * Return the determinant of the matrix.
+     *
+     * @return determinant of the matrix.
+     */
+    public double determinant() {
+        if (singular)
+            return 0;
+
+        final int m = pivot.size();
+        double determinant = even ? 1 : -1;
+
+        for (int i = 0; i < m; i++)
+            determinant *= lu.getX(i, i);
+
+        return determinant;
+    }
+
+    /** */
+    public Vector solve(Vector b) {
+        final int m = pivot.size();
+
+        if (b.size() != m)
+            throw new CardinalityException(b.size(), m);
+
+        if (singular)
+            throw new SingularMatrixException();
+
+        final double[] bp = new double[m];
+
+        // Apply permutations to b
+        for (int row = 0; row < m; row++)
+            bp[row] = b.get((int)pivot.get(row));
+
+        // Solve LY = b
+        for (int col = 0; col < m; col++) {
+            final double bpCol = bp[col];
+
+            for (int i = col + 1; i < m; i++)
+                bp[i] -= bpCol * lu.get(i, col);
+        }
+
+        // Solve UX = Y
+        for (int col = m - 1; col >= 0; col--) {
+            bp[col] /= lu.get(col, col);
+            final double bpCol = bp[col];
+
+            for (int i = 0; i < col; i++)
+                bp[i] -= bpCol * lu.get(i, col);
+        }
+
+        return b.like(m).assign(bp);
+    }
+
+    /** */
+    public Matrix solve(Matrix b) {
+        final int m = pivot.size();
+
+        if (b.rowSize() != m)
+            throw new CardinalityException(b.rowSize(), m);
+
+        if (singular)
+            throw new SingularMatrixException();
+
+        final int nColB = b.columnSize();
+
+        // Apply permutations to b
+        final double[][] bp = new double[m][nColB];
+        for (int row = 0; row < m; row++) {
+            final double[] bpRow = bp[row];
+            final int pRow = (int)pivot.get(row);
+
+            for (int col = 0; col < nColB; col++)
+                bpRow[col] = b.get(pRow, col);
+        }
+
+        // Solve LY = b
+        for (int col = 0; col < m; col++) {
+            final double[] bpCol = bp[col];
+            for (int i = col + 1; i < m; i++) {
+                final double[] bpI = bp[i];
+                final double luICol = lu.get(i, col);
+
+                for (int j = 0; j < nColB; j++)
+                    bpI[j] -= bpCol[j] * luICol;
+            }
+        }
+
+        // Solve UX = Y
+        for (int col = m - 1; col >= 0; col--) {
+            final double[] bpCol = bp[col];
+            final double luDiag = lu.getX(col, col);
+
+            for (int j = 0; j < nColB; j++)
+                bpCol[j] /= luDiag;
+
+            for (int i = 0; i < col; i++) {
+                final double[] bpI = bp[i];
+                final double luICol = lu.get(i, col);
+
+                for (int j = 0; j < nColB; j++)
+                    bpI[j] -= bpCol[j] * luICol;
+            }
+        }
+
+        return b.like(b.rowSize(), b.columnSize()).assign(bp);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/QRDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/QRDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/QRDecomposition.java
new file mode 100644
index 0000000..39215e8
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/QRDecomposition.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.functions.Functions;
+
+/**
+ * For an {@code m x n} matrix {@code A} with {@code m >= n}, the QR decomposition
+ * is an {@code m x n} orthogonal matrix {@code Q} and an {@code n x n} upper
+ * triangular matrix {@code R} so that {@code A = Q*R}.
+ */
+public class QRDecomposition extends DecompositionSupport {
+    /** */
+    private final Matrix q;
+    /** */
+    private final Matrix r;
+
+    /** */
+    private final Matrix mType;
+    /** */
+    private final boolean fullRank;
+
+    /** */
+    private final int rows;
+    /** */
+    private final int cols;
+
+    /**
+     * @param v Value to be checked for being an ordinary double.
+     */
+    private void checkDouble(double v) {
+        if (Double.isInfinite(v) || Double.isNaN(v))
+            throw new ArithmeticException("Invalid intermediate result");
+    }
+
+    /**
+     * Constructs a new QR decomposition object computed by Householder reflections.
+     *
+     * @param mtx A rectangular matrix.
+     */
+    public QRDecomposition(Matrix mtx) {
+        assert mtx != null;
+
+        rows = mtx.rowSize();
+
+        int min = Math.min(mtx.rowSize(), mtx.columnSize());
+
+        cols = mtx.columnSize();
+
+        mType = like(mtx, 1, 1);
+
+        Matrix qTmp = copy(mtx);
+
+        boolean fullRank = true;
+
+        r = like(mtx, min, cols);
+
+        for (int i = 0; i < min; i++) {
+            Vector qi = qTmp.viewColumn(i);
+
+            double alpha = qi.kNorm(2);
+
+            if (Math.abs(alpha) > Double.MIN_VALUE)
+                qi.map(Functions.div(alpha));
+            else {
+                checkDouble(alpha);
+
+                fullRank = false;
+            }
+
+            r.set(i, i, alpha);
+
+            for (int j = i + 1; j < cols; j++) {
+                Vector qj = qTmp.viewColumn(j);
+
+                double norm = qj.kNorm(2);
+
+                if (Math.abs(norm) > Double.MIN_VALUE) {
+                    double beta = qi.dot(qj);
+
+                    r.set(i, j, beta);
+
+                    if (j < min)
+                        qj.map(qi, Functions.plusMult(-beta));
+                }
+                else
+                    checkDouble(norm);
+            }
+        }
+
+        if (cols > min)
+            q = qTmp.viewPart(0, rows, 0, min).copy();
+        else
+            q = qTmp;
+
+        this.fullRank = fullRank;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        q.destroy();
+        r.destroy();
+        mType.destroy();
+    }
+
+    /**
+     * Gets orthogonal factor {@code Q}.
+     */
+    public Matrix getQ() {
+        return q;
+    }
+
+    /**
+     * Gets triangular factor {@code R}.
+     */
+    public Matrix getR() {
+        return r;
+    }
+
+    /**
+     * Returns whether the matrix {@code A} has full rank.
+     *
+     * @return true if {@code R}, and hence {@code A} , has full rank.
+     */
+    public boolean hasFullRank() {
+        return fullRank;
+    }
+
+    /**
+     * Least squares solution of {@code A*X = B}; {@code returns X}.
+     *
+     * @param mtx A matrix with as many rows as {@code A} and any number of cols.
+     * @return {@code X<} that minimizes the two norm of {@code Q*R*X - B}.
+     * @throws IllegalArgumentException if {@code B.rows() != A.rows()}.
+     */
+    public Matrix solve(Matrix mtx) {
+        if (mtx.rowSize() != rows)
+            throw new IllegalArgumentException("Matrix row dimensions must agree.");
+
+        int cols = mtx.columnSize();
+
+        Matrix x = like(mType, this.cols, cols);
+
+        Matrix qt = getQ().transpose();
+        Matrix y = qt.times(mtx);
+
+        Matrix r = getR();
+
+        for (int k = Math.min(this.cols, rows) - 1; k > 0; k--) {
+            // X[k,] = Y[k,] / R[k,k], note that X[k,] starts with 0 so += is same as =
+            x.viewRow(k).map(y.viewRow(k), Functions.plusMult(1 / r.get(k, k)));
+
+            // Y[0:(k-1),] -= R[0:(k-1),k] * X[k,]
+            Vector rCol = r.viewColumn(k).viewPart(0, k);
+
+            for (int c = 0; c < cols; c++)
+                y.viewColumn(c).viewPart(0, k).map(rCol, Functions.plusMult(-x.get(k, c)));
+        }
+
+        return x;
+    }
+
+    /**
+     * Returns a rough string rendition of a QR.
+     */
+    @Override public String toString() {
+        return String.format("QR(%d x %d, fullRank=%s)", rows, cols, hasFullRank());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/SingularValueDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/SingularValueDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/SingularValueDecomposition.java
new file mode 100644
index 0000000..1b04e4f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/SingularValueDecomposition.java
@@ -0,0 +1,620 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.decompositions;
+
+import org.apache.ignite.ml.math.Algebra;
+import org.apache.ignite.ml.math.Matrix;
+
+/**
+ * Compute a singular value decomposition (SVD) of {@code (l x k)} matrix {@code m}.
+ * <p>This decomposition can be thought
+ * as an extension of {@link EigenDecomposition} to rectangular matrices. The factorization we get is following:</p>
+ * <p>{@code m = u * s * v^{*}}, where</p>
+ * <ul><li>{@code u} is a real or complex unitary matrix.</li>
+ * <li>{@code s} is a rectangular diagonal matrix with non-negative real numbers on diagonal
+ * (these numbers are singular values of {@code m}).</li>
+ * <li>{@code v} is a real or complex unitary matrix.</li></ul>
+ * <p>If {@code m} is real then {@code u} and {@code v} are also real.</p>
+ * <p>See also: <a href="https://en.wikipedia.org/wiki/Singular_value_decomposition">Wikipedia article on SVD</a>.</p>
+ * <p>Note: complex case is currently not supported.</p>
+ */
+public class SingularValueDecomposition extends DecompositionSupport {
+    // U and V.
+    /** */
+    private final double[][] u;
+    /** */
+    private final double[][] v;
+
+    /** Singular values. */
+    private final double[] s;
+
+    /** Row dimension. */
+    private final int m;
+    /** Column dimension. */
+    private final int n;
+
+    /** */
+    private Matrix arg;
+
+    /** */
+    private boolean transpositionNeeded;
+
+    /**
+     * Singular value decomposition object.
+     *
+     * @param arg A rectangular matrix.
+     */
+    public SingularValueDecomposition(Matrix arg) {
+        assert arg != null;
+
+        this.arg = arg;
+
+        if (arg.rowSize() < arg.columnSize())
+            transpositionNeeded = true;
+
+        double[][] a;
+
+        if (transpositionNeeded) {
+            // Use the transpose matrix.
+            m = arg.columnSize();
+            n = arg.rowSize();
+
+            a = new double[m][n];
+
+            for (int i = 0; i < m; i++)
+                for (int j = 0; j < n; j++)
+                    a[i][j] = arg.get(j, i);
+        }
+        else {
+            m = arg.rowSize();
+            n = arg.columnSize();
+
+            a = new double[m][n];
+
+            for (int i = 0; i < m; i++)
+                for (int j = 0; j < n; j++)
+                    a[i][j] = arg.get(i, j);
+        }
+
+        int nu = Math.min(m, n);
+
+        s = new double[Math.min(m + 1, n)];
+        u = new double[m][nu];
+        v = new double[n][n];
+
+        double[] e = new double[n];
+        double[] work = new double[m];
+
+        int nct = Math.min(m - 1, n);
+        int nrt = Math.max(0, Math.min(n - 2, m));
+
+        for (int k = 0; k < Math.max(nct, nrt); k++) {
+            if (k < nct) {
+                // Compute the transformation for the k-th column and
+                // place the k-th diagonal in s[k]. Compute 2-norm of k-th
+                // column without under/overflow.
+                s[k] = 0;
+
+                for (int i = k; i < m; i++)
+                    s[k] = Algebra.hypot(s[k], a[i][k]);
+
+                if (s[k] != 0.0) {
+                    if (a[k][k] < 0.0)
+                        s[k] = -s[k];
+
+                    for (int i = k; i < m; i++)
+                        a[i][k] /= s[k];
+
+                    a[k][k] += 1.0;
+                }
+
+                s[k] = -s[k];
+            }
+
+            for (int j = k + 1; j < n; j++) {
+                if (k < nct && s[k] != 0.0) {
+                    // Apply the transformation.
+                    double t = 0;
+
+                    for (int i = k; i < m; i++)
+                        t += a[i][k] * a[i][j];
+
+                    t = -t / a[k][k];
+
+                    for (int i = k; i < m; i++)
+                        a[i][j] += t * a[i][k];
+                }
+
+                // Place the k-th row of A into e for the
+                // subsequent calculation of the row transformation.
+                e[j] = a[k][j];
+            }
+
+            if (k < nct)
+                // Place the transformation in U for subsequent back
+                // multiplication.
+                for (int i = k; i < m; i++)
+                    u[i][k] = a[i][k];
+
+            if (k < nrt) {
+                // Compute the k-th row transformation and place the
+                // k-th super-diagonal in e[k].
+                // Compute 2-norm without under/overflow.
+                e[k] = 0;
+
+                for (int i = k + 1; i < n; i++)
+                    e[k] = Algebra.hypot(e[k], e[i]);
+
+                if (e[k] != 0.0) {
+                    if (e[k + 1] < 0.0)
+                        e[k] = -e[k];
+
+                    for (int i = k + 1; i < n; i++)
+                        e[i] /= e[k];
+
+                    e[k + 1] += 1.0;
+                }
+
+                e[k] = -e[k];
+
+                if (k + 1 < m && e[k] != 0.0) {
+                    // Apply the transformation.
+                    for (int i = k + 1; i < m; i++)
+                        work[i] = 0.0;
+
+                    for (int j = k + 1; j < n; j++)
+                        for (int i = k + 1; i < m; i++)
+                            work[i] += e[j] * a[i][j];
+
+                    for (int j = k + 1; j < n; j++) {
+                        double t = -e[j] / e[k + 1];
+
+                        for (int i = k + 1; i < m; i++)
+                            a[i][j] += t * work[i];
+                    }
+                }
+
+                // Place the transformation in V for subsequent
+                // back multiplication.
+                for (int i = k + 1; i < n; i++)
+                    v[i][k] = e[i];
+            }
+        }
+
+        // Set up the final bi-diagonal matrix or order p.
+        int p = Math.min(n, m + 1);
+
+        if (nct < n)
+            s[nct] = a[nct][nct];
+
+        if (m < p)
+            s[p - 1] = 0.0;
+
+        if (nrt + 1 < p)
+            e[nrt] = a[nrt][p - 1];
+
+        e[p - 1] = 0.0;
+
+        // Generate U.
+        for (int j = nct; j < nu; j++) {
+            for (int i = 0; i < m; i++)
+                u[i][j] = 0.0;
+
+            u[j][j] = 1.0;
+        }
+
+        for (int k = nct - 1; k >= 0; k--) {
+            if (s[k] != 0.0) {
+                for (int j = k + 1; j < nu; j++) {
+                    double t = 0;
+
+                    for (int i = k; i < m; i++)
+                        t += u[i][k] * u[i][j];
+
+                    t = -t / u[k][k];
+
+                    for (int i = k; i < m; i++)
+                        u[i][j] += t * u[i][k];
+                }
+
+                for (int i = k; i < m; i++)
+                    u[i][k] = -u[i][k];
+
+                u[k][k] = 1.0 + u[k][k];
+
+                for (int i = 0; i < k - 1; i++)
+                    u[i][k] = 0.0;
+            }
+            else {
+                for (int i = 0; i < m; i++)
+                    u[i][k] = 0.0;
+
+                u[k][k] = 1.0;
+            }
+        }
+
+        // Generate V.
+        for (int k = n - 1; k >= 0; k--) {
+            if (k < nrt && e[k] != 0.0) {
+                for (int j = k + 1; j < nu; j++) {
+                    double t = 0;
+
+                    for (int i = k + 1; i < n; i++)
+                        t += v[i][k] * v[i][j];
+
+                    t = -t / v[k + 1][k];
+
+                    for (int i = k + 1; i < n; i++)
+                        v[i][j] += t * v[i][k];
+                }
+            }
+
+            for (int i = 0; i < n; i++)
+                v[i][k] = 0.0;
+
+            v[k][k] = 1.0;
+        }
+
+        // Main iteration loop for the singular values.
+        int pp = p - 1;
+        int iter = 0;
+
+        double eps = Math.pow(2.0, -52.0);
+        double tiny = Math.pow(2.0, -966.0);
+
+        while (p > 0) {
+            int k;
+
+            for (k = p - 2; k >= -1; k--) {
+                if (k == -1)
+                    break;
+
+                if (Math.abs(e[k]) <= tiny + eps * (Math.abs(s[k]) + Math.abs(s[k + 1]))) {
+                    e[k] = 0.0;
+
+                    break;
+                }
+            }
+
+            int kase;
+
+            if (k == p - 2)
+                kase = 4;
+            else {
+                int ks;
+
+                for (ks = p - 1; ks >= k; ks--) {
+                    if (ks == k)
+                        break;
+
+                    double t =
+                        (ks != p ? Math.abs(e[ks]) : 0.) +
+                            (ks != k + 1 ? Math.abs(e[ks - 1]) : 0.);
+
+                    if (Math.abs(s[ks]) <= tiny + eps * t) {
+                        s[ks] = 0.0;
+
+                        break;
+                    }
+                }
+
+                if (ks == k)
+                    kase = 3;
+                else if (ks == p - 1)
+                    kase = 1;
+                else {
+                    kase = 2;
+
+                    k = ks;
+                }
+            }
+
+            k++;
+
+            // Perform the task indicated by kase.
+            switch (kase) {
+                // Deflate negligible s(p).
+                case 1: {
+                    double f = e[p - 2];
+
+                    e[p - 2] = 0.0;
+
+                    for (int j = p - 2; j >= k; j--) {
+                        double t = Algebra.hypot(s[j], f);
+                        double cs = s[j] / t;
+                        double sn = f / t;
+
+                        s[j] = t;
+
+                        if (j != k) {
+                            f = -sn * e[j - 1];
+                            e[j - 1] = cs * e[j - 1];
+                        }
+
+                        for (int i = 0; i < n; i++) {
+                            t = cs * v[i][j] + sn * v[i][p - 1];
+
+                            v[i][p - 1] = -sn * v[i][j] + cs * v[i][p - 1];
+                            v[i][j] = t;
+                        }
+                    }
+                }
+
+                break;
+
+                // Split at negligible s(k).
+                case 2: {
+                    double f = e[k - 1];
+                    e[k - 1] = 0.0;
+
+                    for (int j = k; j < p; j++) {
+                        double t = Algebra.hypot(s[j], f);
+                        double cs = s[j] / t;
+                        double sn = f / t;
+
+                        s[j] = t;
+                        f = -sn * e[j];
+                        e[j] = cs * e[j];
+
+                        for (int i = 0; i < m; i++) {
+                            t = cs * u[i][j] + sn * u[i][k - 1];
+
+                            u[i][k - 1] = -sn * u[i][j] + cs * u[i][k - 1];
+                            u[i][j] = t;
+                        }
+                    }
+                }
+
+                break;
+
+                // Perform one qr step.
+                case 3: {
+                    // Calculate the shift.
+                    double scale = Math.max(Math.max(Math.max(Math.max(
+                        Math.abs(s[p - 1]), Math.abs(s[p - 2])), Math.abs(e[p - 2])),
+                        Math.abs(s[k])), Math.abs(e[k]));
+
+                    double sp = s[p - 1] / scale;
+                    double spm1 = s[p - 2] / scale;
+                    double epm1 = e[p - 2] / scale;
+                    double sk = s[k] / scale;
+                    double ek = e[k] / scale;
+                    double b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0;
+                    double c = sp * epm1 * sp * epm1;
+                    double shift = 0.0;
+
+                    if (b != 0.0 || c != 0.0) {
+                        shift = Math.sqrt(b * b + c);
+
+                        if (b < 0.0)
+                            shift = -shift;
+
+                        shift = c / (b + shift);
+                    }
+
+                    double f = (sk + sp) * (sk - sp) + shift;
+                    double g = sk * ek;
+
+                    // Chase zeros.
+                    for (int j = k; j < p - 1; j++) {
+                        double t = Algebra.hypot(f, g);
+                        double cs = f / t;
+                        double sn = g / t;
+
+                        if (j != k)
+                            e[j - 1] = t;
+
+                        f = cs * s[j] + sn * e[j];
+                        e[j] = cs * e[j] - sn * s[j];
+                        g = sn * s[j + 1];
+                        s[j + 1] = cs * s[j + 1];
+
+                        for (int i = 0; i < n; i++) {
+                            t = cs * v[i][j] + sn * v[i][j + 1];
+
+                            v[i][j + 1] = -sn * v[i][j] + cs * v[i][j + 1];
+                            v[i][j] = t;
+                        }
+
+                        t = Algebra.hypot(f, g);
+                        cs = f / t;
+                        sn = g / t;
+                        s[j] = t;
+                        f = cs * e[j] + sn * s[j + 1];
+                        s[j + 1] = -sn * e[j] + cs * s[j + 1];
+                        g = sn * e[j + 1];
+                        e[j + 1] = cs * e[j + 1];
+
+                        if (j < m - 1)
+                            for (int i = 0; i < m; i++) {
+                                t = cs * u[i][j] + sn * u[i][j + 1];
+
+                                u[i][j + 1] = -sn * u[i][j] + cs * u[i][j + 1];
+                                u[i][j] = t;
+                            }
+                    }
+
+                    e[p - 2] = f;
+                    iter = iter + 1;
+                }
+
+                break;
+
+                // Convergence.
+                case 4: {
+                    // Make the singular values positive.
+                    if (s[k] <= 0.0) {
+                        s[k] = s[k] < 0.0 ? -s[k] : 0.0;
+
+                        for (int i = 0; i <= pp; i++)
+                            v[i][k] = -v[i][k];
+                    }
+
+                    // Order the singular values.
+                    while (k < pp) {
+                        if (s[k] >= s[k + 1])
+                            break;
+
+                        double t = s[k];
+
+                        s[k] = s[k + 1];
+                        s[k + 1] = t;
+
+                        if (k < n - 1)
+                            for (int i = 0; i < n; i++) {
+                                t = v[i][k + 1];
+
+                                v[i][k + 1] = v[i][k];
+                                v[i][k] = t;
+                            }
+
+                        if (k < m - 1)
+                            for (int i = 0; i < m; i++) {
+                                t = u[i][k + 1];
+
+                                u[i][k + 1] = u[i][k];
+                                u[i][k] = t;
+                            }
+
+                        k++;
+                    }
+
+                    iter = 0;
+                    p--;
+                }
+
+                break;
+
+                default:
+                    throw new IllegalStateException();
+            }
+        }
+    }
+
+    /**
+     * Gets the two norm condition number, which is {@code max(S) / min(S)} .
+     */
+    public double cond() {
+        return s[0] / s[Math.min(m, n) - 1];
+    }
+
+    /**
+     * @return the diagonal matrix of singular values.
+     */
+    public Matrix getS() {
+        double[][] s = new double[n][n];
+
+        for (int i = 0; i < n; i++) {
+            for (int j = 0; j < n; j++)
+                s[i][j] = 0.0;
+
+            s[i][i] = this.s[i];
+        }
+
+        return like(arg, n, n).assign(s);
+    }
+
+    /**
+     * Gets the diagonal of {@code S}, which is a one-dimensional array of
+     * singular values.
+     *
+     * @return diagonal of {@code S}.
+     */
+    public double[] getSingularValues() {
+        return s;
+    }
+
+    /**
+     * Gets the left singular vectors {@code U}.
+     *
+     * @return {@code U}
+     */
+    public Matrix getU() {
+        if (transpositionNeeded)
+            return like(arg, v.length, v.length).assign(v);
+        else {
+            int numCols = Math.min(m + 1, n);
+
+            Matrix r = like(arg, m, numCols);
+
+            for (int i = 0; i < m; i++)
+                for (int j = 0; j < numCols; j++)
+                    r.set(i, j, u[i][j]);
+
+            return r;
+        }
+    }
+
+    /**
+     * Gets the right singular vectors {@code V}.
+     *
+     * @return {@code V}
+     */
+    public Matrix getV() {
+        if (transpositionNeeded) {
+            int numCols = Math.min(m + 1, n);
+
+            Matrix r = like(arg, m, numCols);
+
+            for (int i = 0; i < m; i++)
+                for (int j = 0; j < numCols; j++)
+                    r.set(i, j, u[i][j]);
+
+            return r;
+        }
+        else
+            return like(arg, v.length, v.length).assign(v);
+    }
+
+    /**
+     * Gets the two norm, which is {@code max(S)}.
+     */
+    public double norm2() {
+        return s[0];
+    }
+
+    /**
+     * Gets effective numerical matrix rank.
+     */
+    public int rank() {
+        double eps = Math.pow(2.0, -52.0);
+        double tol = Math.max(m, n) * s[0] * eps;
+        int r = 0;
+
+        for (double value : s)
+            if (value > tol)
+                r++;
+
+        return r;
+    }
+
+    /**
+     * Gets [n � n] covariance matrix.
+     *
+     * @param minSingularVal Value below which singular values are ignored.
+     */
+    Matrix getCovariance(double minSingularVal) {
+        Matrix j = like(arg, s.length, s.length);
+        Matrix vMat = like(arg, v.length, v.length).assign(v);
+
+        for (int i = 0; i < s.length; i++)
+            j.set(i, i, s[i] >= minSingularVal ? 1 / (s[i] * s[i]) : 0.0);
+
+        return vMat.times(j).times(vMat.transpose());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/package-info.java
new file mode 100644
index 0000000..d317ccd
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/decompositions/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains matrix decompositions for distributed code algebra.
+ */
+package org.apache.ignite.ml.math.decompositions;

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/CardinalityException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/CardinalityException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/CardinalityException.java
new file mode 100644
index 0000000..f03e5d8
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/CardinalityException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * Indicates a cardinality mismatch in matrix or vector operations.
+ */
+public class CardinalityException extends IgniteException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Creates new cardinality violation exception.
+     *
+     * @param exp Expected cardinality.
+     * @param act Actual cardinality.
+     */
+    public CardinalityException(int exp, int act) {
+        super("Cardinality violation [expected=" + exp + ", actual=" + act + "]");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/ColumnIndexException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/ColumnIndexException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/ColumnIndexException.java
new file mode 100644
index 0000000..08a67b5
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/ColumnIndexException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * This exception is used to indicate any error condition accessing matrix elements by invalid column index.
+ */
+public class ColumnIndexException extends IgniteException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * @param idx Index value that caused this exception.
+     */
+    public ColumnIndexException(int idx) {
+        super("Invalid (out of bound) column index: " + idx);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/IndexException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/IndexException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/IndexException.java
new file mode 100644
index 0000000..93ca11e
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/IndexException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * Indicates an invalid, i.e. out of bound, index on matrix or vector operations.
+ */
+public class IndexException extends IgniteException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * @param idx Index value that caused this exception.
+     */
+    public IndexException(int idx) {
+        super("Invalid (out of bound) index: " + idx);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonPositiveDefiniteMatrixException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonPositiveDefiniteMatrixException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonPositiveDefiniteMatrixException.java
new file mode 100644
index 0000000..b0cf294
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonPositiveDefiniteMatrixException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * This exception is used to indicate error condition of matrix elements failing the positivity check.
+ */
+public class NonPositiveDefiniteMatrixException extends IgniteException {
+    /**
+     * Construct an exception.
+     *
+     * @param wrong Value that fails the positivity check.
+     * @param idx Row (and column) index.
+     * @param threshold Absolute positivity threshold.
+     */
+    public NonPositiveDefiniteMatrixException(double wrong, int idx, double threshold) {
+        super("Matrix must be positive, wrong element located on diagonal with index "
+            + idx + " and has value " + wrong + " with this threshold " + threshold);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonSymmetricMatrixException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonSymmetricMatrixException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonSymmetricMatrixException.java
new file mode 100644
index 0000000..7c563fe
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/NonSymmetricMatrixException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * This exception is used to indicate error condition of matrix failing the symmetry check.
+ */
+public class NonSymmetricMatrixException extends IgniteException {
+    /**
+     * @param row Row.
+     * @param col Column.
+     * @param threshold Threshold.
+     */
+    public NonSymmetricMatrixException(int row, int col, double threshold) {
+        super("Symmetric matrix expected, the symmetry is broken on row "
+            + row + " and col " + col + " with this threshold " + threshold);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/RowIndexException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/RowIndexException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/RowIndexException.java
new file mode 100644
index 0000000..ebbbca3
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/RowIndexException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * This exception is used to indicate any error condition accessing matrix elements by invalid row index.
+ */
+public class RowIndexException extends IgniteException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * @param idx Index value that caused this exception.
+     */
+    public RowIndexException(int idx) {
+        super("Invalid (out of bound) row index: " + idx);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/SingularMatrixException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/SingularMatrixException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/SingularMatrixException.java
new file mode 100644
index 0000000..789b686
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/SingularMatrixException.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * Exception to be thrown when a non-singular matrix is expected.
+ */
+public class SingularMatrixException extends IgniteException {
+    /** */
+    public SingularMatrixException() {
+        super("Regular (or non-singular) matrix expected.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnknownProviderException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnknownProviderException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnknownProviderException.java
new file mode 100644
index 0000000..940b9aa
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnknownProviderException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * Indicates that no provider has been found for a given vector or matrix flavor.
+ */
+public class UnknownProviderException extends IgniteException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * @param flv Flavor (a.k.a. operation performance hints) that has no registered provider for.
+     */
+    public UnknownProviderException(String flv) {
+        super("No provider has been found for the flavor: " + flv);
+    }
+}


[49/50] [abbrv] ignite git commit: Merge remote-tracking branch 'remotes/origin/ignite-2.0' into ignite-1561

Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/origin/ignite-2.0' into ignite-1561


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

Branch: refs/heads/ignite-1561
Commit: df28c1adc87cfe1af9e5b18269733426c26fdda4
Parents: 63001f1 5dab5fb
Author: sboikov <sb...@gridgain.com>
Authored: Wed Apr 19 17:45:05 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Apr 19 17:45:05 2017 +0300

----------------------------------------------------------------------
 doap_Ignite.rdf                                 |   11 +-
 examples/README.txt                             |   10 +-
 examples/config/example-memory-policies.xml     |  105 +
 examples/config/filesystem/example-igfs.xml     |    7 -
 examples/pom-standalone-lgpl.xml                |   19 +
 examples/pom-standalone.xml                     |   19 +
 examples/pom.xml                                |   30 +
 .../datagrid/MemoryPoliciesExample.java         |  114 +
 .../MemcacheRestExampleNodeStartup.java         |    7 -
 .../CholeskyDecompositionExample.java           |   80 +
 .../EigenDecompositionExample.java              |   69 +
 .../decompositions/LUDecompositionExample.java  |   83 +
 .../SingularValueDecompositionExample.java      |   70 +
 .../ml/math/decompositions/package-info.java    |   22 +
 .../ml/math/matrix/CacheMatrixExample.java      |   91 +
 .../ml/math/matrix/ExampleMatrixStorage.java    |  162 ++
 .../math/matrix/MatrixCustomStorageExample.java |  141 ++
 .../examples/ml/math/matrix/MatrixExample.java  |   79 +
 .../ml/math/matrix/MatrixExampleUtil.java       |   52 +
 .../ml/math/matrix/OffHeapMatrixExample.java    |   84 +
 .../matrix/SparseDistributedMatrixExample.java  |   66 +
 .../ml/math/matrix/SparseMatrixExample.java     |   84 +
 .../examples/ml/math/matrix/package-info.java   |   22 +
 .../ignite/examples/ml/math/package-info.java   |   22 +
 .../examples/ml/math/tracer/TracerExample.java  |   63 +
 .../examples/ml/math/tracer/package-info.java   |   22 +
 .../ml/math/vector/CacheVectorExample.java      |  102 +
 .../ml/math/vector/ExampleVectorStorage.java    |  126 +
 .../ml/math/vector/OffHeapVectorExample.java    |   78 +
 .../ml/math/vector/SparseVectorExample.java     |   80 +
 .../math/vector/VectorCustomStorageExample.java |  124 +
 .../examples/ml/math/vector/VectorExample.java  |   75 +
 .../examples/ml/math/vector/package-info.java   |   22 +
 .../examples/ScalarCacheAffinityExample.scala   |    2 +-
 .../ignite/examples/CacheExamplesSelfTest.java  |    8 +
 .../optimized/OptimizedMarshallerAopTest.java   |  105 +
 .../optimized/OptimizedMarshallerAopTest.java   |  104 -
 .../store/cassandra/datasource/DataSource.java  |   50 +-
 .../cassandra/session/CassandraSessionImpl.java |   23 +-
 .../cassandra/session/pool/SessionPool.java     |    6 +-
 .../cassandra/session/pool/SessionWrapper.java  |   15 +-
 .../ignite/ignite-cassandra-server-template.xml |    6 -
 .../tests/ignite-cassandra-client-template.xml  |    6 -
 modules/clients/src/test/config/jdbc-config.xml |    2 +-
 .../jdbc2/JdbcAbstractDmlStatementSelfTest.java |   92 +-
 ...BinaryMarshallerInsertStatementSelfTest.java |    9 +-
 ...cBinaryMarshallerMergeStatementSelfTest.java |    9 +-
 .../jdbc2/JdbcDynamicIndexAbstractSelfTest.java |  367 +++
 ...namicIndexAtomicPartitionedNearSelfTest.java |   26 +
 ...bcDynamicIndexAtomicPartitionedSelfTest.java |   39 +
 ...dbcDynamicIndexAtomicReplicatedSelfTest.java |   39 +
 ...dexTransactionalPartitionedNearSelfTest.java |   26 +
 ...icIndexTransactionalPartitionedSelfTest.java |   39 +
 ...micIndexTransactionalReplicatedSelfTest.java |   39 +
 .../jdbc2/JdbcInsertStatementSelfTest.java      |    4 +-
 .../JettyRestProcessorAbstractSelfTest.java     |  102 +-
 .../jdbc/suite/IgniteJdbcDriverTestSuite.java   |    8 +
 .../ignite/codegen/MessageCodeGenerator.java    |    4 +
 modules/core/pom.xml                            |    3 +
 .../java/org/apache/ignite/IgniteCache.java     |   13 -
 .../java/org/apache/ignite/IgniteCluster.java   |   52 -
 .../apache/ignite/IgniteSystemProperties.java   |   10 +-
 .../ignite/binary/BinaryBasicNameMapper.java    |    3 +
 .../ignite/cache/CacheAtomicWriteOrderMode.java |   64 -
 .../org/apache/ignite/cache/CacheEntry.java     |   12 -
 .../ignite/cache/PartitionLossPolicy.java       |   16 +-
 .../org/apache/ignite/cache/QueryEntity.java    |   82 +-
 .../org/apache/ignite/cache/QueryIndex.java     |    9 +
 .../org/apache/ignite/cache/QueryIndexType.java |   17 +-
 .../AffinityNodeAddressHashResolver.java        |   44 -
 .../affinity/AffinityNodeHashResolver.java      |   47 -
 .../affinity/AffinityNodeIdHashResolver.java    |   45 -
 .../rendezvous/RendezvousAffinityFunction.java  |   51 +-
 .../ignite/cache/query/SqlFieldsQuery.java      |   25 +
 .../org/apache/ignite/cache/query/SqlQuery.java |   31 +-
 .../configuration/CacheConfiguration.java       |   84 +-
 .../configuration/DataPageEvictionMode.java     |   33 +-
 .../configuration/FileSystemConfiguration.java  |  226 +-
 .../configuration/IgniteConfiguration.java      |  102 +-
 .../configuration/MemoryConfiguration.java      |   87 +-
 .../MemoryPolicyConfiguration.java              |  112 +-
 .../org/apache/ignite/hadoop/package-info.java  |   22 +
 .../java/org/apache/ignite/igfs/IgfsPath.java   |   31 +-
 .../apache/ignite/internal/GridComponent.java   |    5 +-
 .../ignite/internal/GridKernalContext.java      |   23 +-
 .../ignite/internal/GridKernalContextImpl.java  |   44 +-
 .../org/apache/ignite/internal/GridTopic.java   |    5 +-
 .../apache/ignite/internal/IgniteKernal.java    |   87 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |   24 +-
 .../apache/ignite/internal/LessNamingBean.java  |   28 -
 .../internal/binary/BinaryClassDescriptor.java  |    2 +-
 .../ignite/internal/binary/BinaryContext.java   |    2 +-
 .../GridClientOptimizedMarshaller.java          |    2 +-
 .../GridClientZipOptimizedMarshaller.java       |    2 +-
 .../cluster/IgniteClusterAsyncImpl.java         |   11 -
 .../internal/cluster/IgniteClusterImpl.java     |   38 -
 .../igfs/common/IgfsControlResponse.java        |   28 +
 .../internal/igfs/common/IgfsIpcCommand.java    |    5 +-
 .../ignite/internal/igfs/common/IgfsLogger.java |   60 +-
 .../internal/igfs/common/IgfsMarshaller.java    |   12 +
 .../igfs/common/IgfsModeResolverRequest.java    |   35 +
 .../ignite/internal/jdbc2/JdbcQueryTask.java    |   41 +-
 .../ignite/internal/jdbc2/JdbcQueryTaskV2.java  |  406 ----
 .../ignite/internal/jdbc2/JdbcResultSet.java    |   64 +-
 .../ignite/internal/jdbc2/JdbcStatement.java    |   12 +-
 .../managers/communication/GridIoManager.java   |    2 +
 .../communication/GridIoMessageFactory.java     |   26 +-
 .../managers/communication/GridIoPolicy.java    |    3 +
 .../optimized/OptimizedClassDescriptor.java     | 1141 +++++++++
 .../optimized/OptimizedFieldType.java           |   50 +
 .../optimized/OptimizedMarshaller.java          |  313 +++
 .../optimized/OptimizedMarshallerIdMapper.java  |   33 +
 .../optimized/OptimizedMarshallerUtils.java     |  551 +++++
 .../optimized/OptimizedObjectInputStream.java   | 1231 ++++++++++
 .../optimized/OptimizedObjectOutputStream.java  |  875 +++++++
 .../OptimizedObjectStreamRegistry.java          |  244 ++
 .../cache/CacheAffinitySharedManager.java       |   11 +-
 .../processors/cache/CacheEntryImplEx.java      |    8 +-
 .../cache/CachePartitionExchangeWorkerTask.java |    6 +-
 .../cache/DynamicCacheChangeRequest.java        |   23 +-
 .../cache/DynamicCacheDescriptor.java           |   50 +-
 .../processors/cache/GridCacheAdapter.java      |   61 +-
 .../cache/GridCacheAtomicVersionComparator.java |   24 +-
 .../processors/cache/GridCacheAttributes.java   |   16 -
 .../cache/GridCacheConcurrentMap.java           |    5 -
 .../cache/GridCacheConcurrentMapImpl.java       |   10 -
 .../processors/cache/GridCacheEntryEx.java      |   13 +-
 .../processors/cache/GridCacheMapEntry.java     |   38 +-
 .../processors/cache/GridCacheMvcc.java         |   23 +-
 .../GridCachePartitionExchangeManager.java      |   36 +-
 .../processors/cache/GridCacheProcessor.java    |  285 +--
 .../cache/GridCacheSharedContext.java           |    2 +
 .../cache/GridCacheSwapEntryImpl.java           |    4 +-
 .../processors/cache/GridCacheUtils.java        |    7 +-
 .../processors/cache/GridNoStorageCacheMap.java |    5 -
 .../processors/cache/IgniteCacheProxy.java      |   25 +-
 .../IgniteCacheDatabaseSharedManager.java       |   14 +-
 .../cache/database/tree/io/CacheVersionIO.java  |   14 +-
 .../dht/GridCachePartitionedConcurrentMap.java  |    5 -
 .../GridDhtAtomicAbstractUpdateRequest.java     |   14 +
 .../dht/atomic/GridDhtAtomicCache.java          |   25 +-
 .../GridDhtAtomicSingleUpdateRequest.java       |   21 +-
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  |   52 +-
 ...idNearAtomicAbstractSingleUpdateRequest.java |    1 -
 .../atomic/GridNearAtomicFullUpdateRequest.java |    3 +-
 ...GridNearAtomicSingleUpdateFilterRequest.java |    3 +-
 ...GridNearAtomicSingleUpdateInvokeRequest.java |    3 +-
 .../dht/colocated/GridDhtColocatedCache.java    |    6 +-
 .../GridDhtPartitionsExchangeFuture.java        |    5 -
 .../distributed/near/GridNearAtomicCache.java   |   16 +-
 .../distributed/near/GridNearCacheAdapter.java  |    6 -
 .../near/GridNearTransactionalCache.java        |    2 +-
 .../local/atomic/GridLocalAtomicCache.java      |    6 +-
 .../cache/query/GridCacheQueryManager.java      |    7 +-
 .../cache/query/GridCacheSqlIndexMetadata.java  |    3 +-
 .../cache/query/GridCacheSqlMetadata.java       |    3 +-
 .../cache/query/GridCacheSqlQuery.java          |  114 +-
 .../cache/query/IgniteQueryErrorCode.java       |   27 +-
 .../cache/store/GridCacheWriteBehindStore.java  |  614 ++++-
 .../cache/transactions/IgniteTxEntry.java       |    8 +-
 .../cache/transactions/IgniteTxManager.java     |    2 +-
 .../version/GridCachePlainVersionedEntry.java   |    5 -
 .../version/GridCacheRawVersionedEntry.java     |    5 -
 .../cache/version/GridCacheVersion.java         |   47 +-
 .../cache/version/GridCacheVersionEx.java       |   19 +-
 .../cache/version/GridCacheVersionManager.java  |    9 +-
 .../cache/version/GridCacheVersionedEntry.java  |    7 -
 .../clock/GridClockDeltaSnapshot.java           |  235 --
 .../clock/GridClockDeltaSnapshotMessage.java    |  154 --
 .../processors/clock/GridClockDeltaVersion.java |  194 --
 .../processors/clock/GridClockMessage.java      |  171 --
 .../processors/clock/GridClockServer.java       |  222 --
 .../processors/clock/GridClockSource.java       |   30 -
 .../clock/GridClockSyncProcessor.java           |  481 ----
 .../processors/clock/GridJvmClockSource.java    |   28 -
 .../datastructures/DataStructuresProcessor.java |    2 -
 .../processors/hadoop/HadoopPayloadAware.java   |   28 -
 .../internal/processors/igfs/IgfsAsyncImpl.java |    5 -
 .../ignite/internal/processors/igfs/IgfsEx.java |    7 -
 .../processors/igfs/IgfsHandshakeResponse.java  |   22 +-
 .../internal/processors/igfs/IgfsImpl.java      |   45 +-
 .../processors/igfs/IgfsIpcHandler.java         |   20 +-
 .../processors/igfs/IgfsModeResolver.java       |   91 +-
 .../internal/processors/igfs/IgfsPaths.java     |  152 --
 .../internal/processors/igfs/IgfsUtils.java     |    2 -
 .../callback/PlatformCallbackGateway.java       |   68 -
 .../PlatformDotNetConfigurationClosure.java     |   66 +-
 .../cache/PlatformCachePluginProvider.java      |  121 -
 .../utils/PlatformConfigurationUtils.java       |   11 +-
 .../internal/processors/pool/PoolProcessor.java |    5 +
 .../query/GridQueryIndexDescriptor.java         |    5 +
 .../processors/query/GridQueryIndexing.java     |   43 +-
 .../processors/query/GridQueryProcessor.java    | 1707 +++++++++++++-
 .../query/GridQueryTypeDescriptor.java          |    7 +
 .../processors/query/IgniteSQLException.java    |    7 +
 .../query/QueryIndexDescriptorImpl.java         |   42 +-
 .../processors/query/QueryIndexKey.java         |   85 +
 .../internal/processors/query/QuerySchema.java  |  168 ++
 .../query/QueryTypeDescriptorImpl.java          |  150 +-
 .../internal/processors/query/QueryUtils.java   |  224 +-
 .../query/schema/SchemaExchangeWorkerTask.java  |   53 +
 .../query/schema/SchemaIndexCacheVisitor.java   |   33 +
 .../schema/SchemaIndexCacheVisitorClosure.java  |   42 +
 .../schema/SchemaIndexCacheVisitorImpl.java     |  197 ++
 .../SchemaIndexOperationCancellationToken.java  |   53 +
 .../processors/query/schema/SchemaKey.java      |   59 +
 .../SchemaNodeLeaveExchangeWorkerTask.java      |   53 +
 .../schema/SchemaOperationClientFuture.java     |   52 +
 .../query/schema/SchemaOperationException.java  |  138 ++
 .../query/schema/SchemaOperationManager.java    |  292 +++
 .../query/schema/SchemaOperationWorker.java     |  205 ++
 .../message/SchemaAbstractDiscoveryMessage.java |   70 +
 .../message/SchemaFinishDiscoveryMessage.java   |   98 +
 .../message/SchemaOperationStatusMessage.java   |  168 ++
 .../message/SchemaProposeDiscoveryMessage.java  |  133 ++
 .../operation/SchemaAbstractOperation.java      |   67 +
 .../operation/SchemaIndexAbstractOperation.java |   40 +
 .../operation/SchemaIndexCreateOperation.java   |   91 +
 .../operation/SchemaIndexDropOperation.java     |   68 +
 .../processors/rest/GridRestProcessor.java      |   19 +-
 .../rest/client/message/GridClientNodeBean.java |    2 +-
 .../top/GridTopologyCommandHandler.java         |    4 +
 .../service/GridServiceProcessor.java           |   13 +-
 .../ignite/internal/util/GridIntList.java       |  586 +++++
 .../internal/util/IgniteExceptionRegistry.java  |    3 +-
 .../ignite/internal/util/IgniteUtils.java       |   26 +-
 .../ignite/internal/util/lang/GridTupleV.java   |  194 --
 .../internal/visor/VisorDataTransferObject.java |   87 +
 .../visor/VisorDataTransferObjectInput.java     |  156 ++
 .../visor/VisorDataTransferObjectOutput.java    |  141 ++
 .../ignite/internal/visor/VisorEither.java      |  103 +
 .../internal/visor/VisorMultiNodeTask.java      |    6 +-
 .../ignite/internal/visor/VisorOneNodeTask.java |    5 +-
 .../internal/visor/VisorTaskArgument.java       |   51 +-
 .../visor/binary/VisorBinaryMetadata.java       |  139 ++
 .../VisorBinaryMetadataCollectorTask.java       |   70 +
 .../VisorBinaryMetadataCollectorTaskResult.java |   87 +
 .../visor/binary/VisorBinaryMetadataField.java  |  101 +
 .../ignite/internal/visor/cache/VisorCache.java |  124 +-
 .../cache/VisorCacheAffinityConfiguration.java  |   91 +-
 .../visor/cache/VisorCacheAffinityNodeTask.java |   13 +-
 .../cache/VisorCacheAffinityNodeTaskArg.java    |   86 +
 .../cache/VisorCacheAggregatedMetrics.java      |  205 +-
 .../visor/cache/VisorCacheClearTask.java        |  100 +-
 .../visor/cache/VisorCacheClearTaskResult.java  |   85 +
 .../visor/cache/VisorCacheConfiguration.java    |  284 ++-
 .../VisorCacheConfigurationCollectorJob.java    |    4 +-
 .../cache/VisorCacheDefaultConfiguration.java   |   58 -
 .../cache/VisorCacheEvictionConfiguration.java  |   52 +-
 .../visor/cache/VisorCacheJdbcType.java         |  189 ++
 .../visor/cache/VisorCacheJdbcTypeField.java    |  117 +
 .../visor/cache/VisorCacheLoadTask.java         |   20 +-
 .../visor/cache/VisorCacheLoadTaskArg.java      |  101 +
 .../visor/cache/VisorCacheMetadataTask.java     |   18 +-
 .../internal/visor/cache/VisorCacheMetrics.java |  208 +-
 .../cache/VisorCacheMetricsCollectorTask.java   |   29 +-
 .../VisorCacheMetricsCollectorTaskArg.java      |   87 +
 .../cache/VisorCacheNearConfiguration.java      |   59 +-
 .../visor/cache/VisorCachePartition.java        |   78 -
 .../visor/cache/VisorCachePartitions.java       |   55 +-
 .../visor/cache/VisorCachePartitionsTask.java   |   25 +-
 .../cache/VisorCachePartitionsTaskArg.java      |   72 +
 .../cache/VisorCacheQueryConfiguration.java     |  122 -
 .../cache/VisorCacheQueryDetailMetrics.java     |  167 --
 ...sorCacheQueryDetailMetricsCollectorTask.java |  146 --
 .../visor/cache/VisorCacheQueryMetrics.java     |  102 -
 .../cache/VisorCacheRebalanceConfiguration.java |   71 +-
 .../VisorCacheResetQueryDetailMetricsTask.java  |   71 -
 .../cache/VisorCacheResetQueryMetricsTask.java  |   69 -
 .../visor/cache/VisorCacheSqlIndexMetadata.java |  115 +
 .../visor/cache/VisorCacheSqlMetadata.java      |  162 ++
 .../visor/cache/VisorCacheStartArg.java         |  100 +
 .../visor/cache/VisorCacheStartTask.java        |   68 +-
 .../visor/cache/VisorCacheStartTaskArg.java     |  100 +
 .../cache/VisorCacheStoreConfiguration.java     |   77 +-
 .../cache/VisorCacheTypeFieldMetadata.java      |   92 -
 .../visor/cache/VisorCacheTypeMetadata.java     |  294 ---
 .../internal/visor/cache/VisorPartitionMap.java |   90 +
 .../compute/VisorComputeMonitoringHolder.java   |    8 +-
 .../VisorComputeToggleMonitoringTask.java       |   52 +-
 .../VisorComputeToggleMonitoringTaskArg.java    |   86 +
 .../visor/compute/VisorGatewayTask.java         |   97 +-
 .../visor/debug/VisorThreadDumpTask.java        |   13 +-
 .../visor/debug/VisorThreadDumpTaskResult.java  |   88 +
 .../internal/visor/debug/VisorThreadInfo.java   |  234 +-
 .../visor/debug/VisorThreadLockInfo.java        |   51 +-
 .../visor/debug/VisorThreadMonitorInfo.java     |   76 +-
 .../visor/event/VisorGridDeploymentEvent.java   |   43 +-
 .../visor/event/VisorGridDiscoveryEvent.java    |   59 +-
 .../internal/visor/event/VisorGridEvent.java    |   66 +-
 .../visor/event/VisorGridEventsLost.java        |   15 +-
 .../internal/visor/event/VisorGridJobEvent.java |   61 +-
 .../visor/event/VisorGridTaskEvent.java         |   61 +-
 .../internal/visor/file/VisorFileBlock.java     |   60 +-
 .../internal/visor/file/VisorFileBlockArg.java  |  114 +
 .../internal/visor/file/VisorFileBlockTask.java |   68 +-
 .../visor/file/VisorFileBlockTaskArg.java       |  114 +
 .../visor/file/VisorLatestTextFilesTask.java    |   17 +-
 .../visor/file/VisorLatestTextFilesTaskArg.java |   86 +
 .../ignite/internal/visor/igfs/VisorIgfs.java   |   76 +-
 .../internal/visor/igfs/VisorIgfsEndpoint.java  |   72 +-
 .../internal/visor/igfs/VisorIgfsMetrics.java   |  118 +-
 .../internal/visor/igfs/VisorIgfsProfiler.java  |   24 +-
 .../visor/igfs/VisorIgfsProfilerClearTask.java  |   11 +-
 .../igfs/VisorIgfsProfilerClearTaskResult.java  |   85 +
 .../visor/igfs/VisorIgfsProfilerEntry.java      |  106 +-
 .../visor/igfs/VisorIgfsProfilerTask.java       |   41 +-
 .../VisorIgfsProfilerUniformityCounters.java    |   38 +-
 .../visor/igfs/VisorIgfsSamplingStateTask.java  |   17 +-
 .../igfs/VisorIgfsSamplingStateTaskArg.java     |   86 +
 .../ignite/internal/visor/log/VisorLogFile.java |   43 +-
 .../internal/visor/log/VisorLogSearchArg.java   |  114 +
 .../visor/log/VisorLogSearchResult.java         |   80 +-
 .../internal/visor/log/VisorLogSearchTask.java  |   81 +-
 .../visor/log/VisorLogSearchTaskArg.java        |  114 +
 .../visor/log/VisorLogSearchTaskResult.java     |   92 +
 .../visor/node/VisorAtomicConfiguration.java    |   49 +-
 .../visor/node/VisorBasicConfiguration.java     |  163 +-
 .../node/VisorExecutorServiceConfiguration.java |   81 +-
 .../visor/node/VisorGridConfiguration.java      |  126 +-
 .../visor/node/VisorIgfsConfiguration.java      |  222 +-
 .../visor/node/VisorLifecycleConfiguration.java |   39 +-
 .../visor/node/VisorMemoryConfiguration.java    |   60 +-
 .../node/VisorMemoryPolicyConfiguration.java    |   37 +-
 .../visor/node/VisorMetricsConfiguration.java   |   50 +-
 .../VisorNodeConfigurationCollectorJob.java     |    4 +-
 .../visor/node/VisorNodeDataCollectorJob.java   |   63 +-
 .../node/VisorNodeDataCollectorJobResult.java   |  109 +-
 .../visor/node/VisorNodeDataCollectorTask.java  |   40 +-
 .../node/VisorNodeDataCollectorTaskArg.java     |   54 +-
 .../node/VisorNodeDataCollectorTaskResult.java  |  110 +-
 .../node/VisorNodeEventsCollectorTask.java      |  133 +-
 .../node/VisorNodeEventsCollectorTaskArg.java   |  163 ++
 .../internal/visor/node/VisorNodeGcTask.java    |   18 +-
 .../visor/node/VisorNodeGcTaskResult.java       |   85 +
 .../internal/visor/node/VisorNodePingTask.java  |   15 +-
 .../visor/node/VisorNodePingTaskResult.java     |   99 +
 .../visor/node/VisorNodeSuppressedErrors.java   |   89 +
 .../node/VisorNodeSuppressedErrorsTask.java     |   23 +-
 .../node/VisorPeerToPeerConfiguration.java      |   57 +-
 .../visor/node/VisorRestConfiguration.java      |   93 +-
 .../node/VisorSegmentationConfiguration.java    |   67 +-
 .../visor/node/VisorSpiDescription.java         |   89 +
 .../visor/node/VisorSpisConfiguration.java      |  128 +-
 .../visor/node/VisorSuppressedError.java        |  147 ++
 .../node/VisorTransactionConfiguration.java     |  104 +-
 .../visor/query/VisorCancelQueriesTask.java     |   72 -
 .../query/VisorCollectRunningQueriesTask.java   |   96 -
 .../internal/visor/query/VisorQueryArg.java     |   81 +-
 .../visor/query/VisorQueryCancelTask.java       |   72 +
 .../visor/query/VisorQueryCleanupTask.java      |    6 +-
 .../visor/query/VisorQueryConfiguration.java    |  142 ++
 .../visor/query/VisorQueryDetailMetrics.java    |  205 ++
 .../VisorQueryDetailMetricsCollectorTask.java   |  146 ++
 .../internal/visor/query/VisorQueryEntity.java  |  188 ++
 .../internal/visor/query/VisorQueryField.java   |   42 +-
 .../internal/visor/query/VisorQueryIndex.java   |  105 +
 .../visor/query/VisorQueryIndexField.java       |  106 +
 .../internal/visor/query/VisorQueryJob.java     |  275 ---
 .../internal/visor/query/VisorQueryMetrics.java |  125 +
 .../visor/query/VisorQueryNextPageTask.java     |   33 +-
 .../visor/query/VisorQueryNextPageTaskArg.java  |   86 +
 .../query/VisorQueryResetDetailMetricsTask.java |   71 +
 .../visor/query/VisorQueryResetMetricsTask.java |   69 +
 .../internal/visor/query/VisorQueryResult.java  |   97 +-
 .../visor/query/VisorQueryResultEx.java         |   89 -
 .../visor/query/VisorQueryScanRegexFilter.java  |   59 +
 .../query/VisorQueryScanSubstringFilter.java    |   64 -
 .../internal/visor/query/VisorQueryTask.java    |  103 +-
 .../internal/visor/query/VisorQueryTaskArg.java |  155 ++
 .../internal/visor/query/VisorQueryUtils.java   |   43 +-
 .../query/VisorRunningQueriesCollectorTask.java |   96 +
 .../internal/visor/query/VisorRunningQuery.java |   47 +-
 .../internal/visor/query/VisorScanQueryArg.java |  157 ++
 .../visor/query/VisorScanQueryTask.java         |  185 ++
 .../visor/query/VisorScanQueryTaskArg.java      |  157 ++
 .../visor/service/VisorServiceDescriptor.java   |   40 +-
 .../internal/visor/util/VisorTaskUtils.java     |   38 +-
 .../apache/ignite/marshaller/Marshaller.java    |    3 +-
 .../ignite/marshaller/jdk/JdkMarshaller.java    |    3 +-
 .../optimized/OptimizedClassDescriptor.java     | 1141 ---------
 .../optimized/OptimizedFieldType.java           |   50 -
 .../optimized/OptimizedMarshaller.java          |  313 ---
 .../optimized/OptimizedMarshallerIdMapper.java  |   33 -
 .../optimized/OptimizedMarshallerUtils.java     |  551 -----
 .../optimized/OptimizedObjectInputStream.java   | 1231 ----------
 .../optimized/OptimizedObjectOutputStream.java  |  875 -------
 .../OptimizedObjectStreamRegistry.java          |  244 --
 .../marshaller/optimized/package-info.java      |   22 -
 .../ignite/plugin/platform/package-info.java    |   22 +
 .../plugin/security/SecurityPermissionSet.java  |    3 +-
 .../ignite/plugin/security/SecuritySubject.java |    3 +-
 .../plugin/segmentation/SegmentationPolicy.java |   18 +-
 .../communication/tcp/TcpCommunicationSpi.java  |  109 -
 .../tcp/TcpCommunicationSpiMBean.java           |   54 -
 .../ignite/startup/BasicWarmupClosure.java      |    3 +-
 .../resources/META-INF/classnames.properties    |  252 +-
 modules/core/src/test/config/example-cache.xml  |    2 +-
 modules/core/src/test/config/igfs-loopback.xml  |    2 +-
 modules/core/src/test/config/igfs-shmem.xml     |    2 +-
 .../src/test/config/spring-start-nodes-attr.xml |    2 +-
 .../core/src/test/config/spring-start-nodes.xml |    2 +-
 .../config/websession/example-cache-base.xml    |    3 +-
 .../test/config/websession/spring-cache-1.xml   |    6 -
 .../test/config/websession/spring-cache-2.xml   |    6 -
 .../test/config/websession/spring-cache-3.xml   |    6 -
 .../IgniteExternalizableAbstractTest.java       |    2 +-
 ...ndezvousAffinityFunctionSimpleBenchmark.java |   48 +-
 ...dbcPojoStoreOptimizedMarshallerSelfTest.java |    2 +-
 .../apache/ignite/igfs/IgfsPathSelfTest.java    |    2 +-
 .../internal/ClusterNodeMetricsSelfTest.java    |   37 +-
 .../internal/GridLifecycleAwareSelfTest.java    |    2 +-
 .../IgniteClientReconnectCacheTest.java         |   87 +-
 .../internal/TestRecordingCommunicationSpi.java |   16 +-
 ...ryConfigurationCustomSerializerSelfTest.java |  147 ++
 .../managers/GridManagerStopSelfTest.java       |    2 +-
 .../GridCommunicationSendMessageSelfTest.java   |    2 -
 .../GridDiscoveryManagerAttributesSelfTest.java |    2 +-
 .../OptimizedMarshallerEnumSelfTest.java        |   87 +
 .../OptimizedMarshallerNodeFailoverTest.java    |  358 +++
 .../OptimizedMarshallerPooledSelfTest.java      |   46 +
 .../optimized/OptimizedMarshallerSelfTest.java  |  284 +++
 ...arshallerSerialPersistentFieldsSelfTest.java |  116 +
 .../optimized/OptimizedMarshallerTest.java      |  790 +++++++
 .../OptimizedObjectStreamSelfTest.java          | 2162 ++++++++++++++++++
 .../TestTcpDiscoveryIpFinderAdapter.java        |   43 +
 .../CacheAtomicSingleMessageCountSelfTest.java  |    2 -
 .../cache/CacheEnumOperationsAbstractTest.java  |    2 -
 ...CacheExchangeMessageDuplicatedStateTest.java |   41 +-
 ...torPartitionCounterRandomOperationsTest.java |    2 -
 .../CacheStartupInDeploymentModesTest.java      |    2 +-
 .../CacheStoreUsageMultinodeAbstractTest.java   |    2 -
 .../EntryVersionConsistencyReadThroughTest.java |    2 -
 ...idAbstractCacheInterceptorRebalanceTest.java |    2 -
 .../cache/GridCacheAbstractFullApiSelfTest.java |   15 +-
 .../GridCacheAbstractLocalStoreSelfTest.java    |   16 +-
 .../GridCacheAbstractRemoveFailureTest.java     |    9 -
 .../GridCacheAtomicMessageCountSelfTest.java    |   54 +-
 .../cache/GridCacheConcurrentMapTest.java       |  138 --
 ...idCacheConfigurationConsistencySelfTest.java |   14 -
 .../cache/GridCacheDeploymentSelfTest.java      |    2 +-
 .../cache/GridCacheEntryMemorySizeSelfTest.java |   82 +-
 .../cache/GridCacheEntryVersionSelfTest.java    |    2 -
 .../cache/GridCacheIncrementTransformTest.java  |    2 -
 .../GridCacheInterceptorAbstractSelfTest.java   |   24 +-
 ...erceptorAtomicPrimaryWriteOrderSelfTest.java |   47 -
 ...omicReplicatedPrimaryWriteOrderSelfTest.java |   48 -
 ...acheInterceptorAtomicReplicatedSelfTest.java |    8 -
 .../GridCacheInterceptorAtomicSelfTest.java     |    8 -
 ...GridCacheInterceptorLocalAtomicSelfTest.java |    8 -
 .../cache/GridCacheMvccFlagsTest.java           |    4 +-
 .../cache/GridCacheMvccPartitionedSelfTest.java |   24 +-
 .../processors/cache/GridCacheMvccSelfTest.java |    8 +-
 ...HeapMultiThreadedUpdateAbstractSelfTest.java |    6 +-
 .../GridCachePreloadingEvictionsSelfTest.java   |    3 +-
 ...ridCacheReplicatedSynchronousCommitTest.java |    2 +-
 .../GridCacheReturnValueTransferSelfTest.java   |   15 +-
 ...ridCacheStoreManagerDeserializationTest.java |   12 +-
 .../processors/cache/GridCacheTestEntryEx.java  |    9 +-
 ...idCacheValueConsistencyAbstractSelfTest.java |   10 -
 .../cache/GridCacheVersionMultinodeTest.java    |   40 -
 .../cache/GridCacheVersionSelfTest.java         |    6 +-
 .../GridCacheVersionTopologyChangeTest.java     |    2 -
 .../cache/IgniteCacheAbstractTest.java          |   14 -
 .../cache/IgniteCacheAtomicInvokeTest.java      |    7 -
 .../cache/IgniteCacheAtomicPeekModesTest.java   |    7 -
 ...eCacheAtomicPrimaryWriteOrderInvokeTest.java |   57 -
 ...maryWriteOrderNearEnabledStoreValueTest.java |   31 -
 ...heAtomicPrimaryWriteOrderStoreValueTest.java |   32 -
 ...micPrimaryWriteOrderWithStoreInvokeTest.java |   32 -
 .../cache/IgniteCacheAtomicStoreValueTest.java  |    7 -
 .../IgniteCacheAtomicWithStoreInvokeTest.java   |   32 +
 .../IgniteCacheBinaryObjectsScanSelfTest.java   |   11 +-
 .../IgniteCacheConfigVariationsFullApiTest.java |    6 -
 .../IgniteCacheEntryListenerAbstractTest.java   |    2 +-
 .../IgniteCacheEntryListenerAtomicTest.java     |    7 -
 ...niteCacheEntryListenerExpiredEventsTest.java |    2 -
 .../IgniteCacheEntryProcessorCallTest.java      |    3 -
 .../IgniteCacheInterceptorSelfTestSuite.java    |    2 -
 ...gniteCacheInvokeReadThroughAbstractTest.java |    2 -
 .../IgniteCacheP2pUnmarshallingErrorTest.java   |    6 -
 .../IgniteCacheReadThroughStoreCallTest.java    |    2 -
 .../IgniteCacheStoreValueAbstractTest.java      |    4 -
 .../cache/IgniteCacheTxPeekModesTest.java       |    7 -
 .../cache/IgniteExchangeFutureHistoryTest.java  |    6 -
 ...logyValidatorPartitionedAtomicCacheTest.java |    7 -
 ...ologyValidatorReplicatedAtomicCacheTest.java |    7 -
 ...sExchangeOnDiscoveryHistoryOverflowTest.java |    7 -
 .../IgniteCacheAtomicExecutionContextTest.java  |    7 -
 ...iteCachePartitionedExecutionContextTest.java |    7 -
 ...niteCacheReplicatedExecutionContextTest.java |    7 -
 .../IgniteCacheTxExecutionContextTest.java      |    7 -
 ...eAbstractDataStructuresFailoverSelfTest.java |    2 +-
 .../distributed/CacheAffinityEarlyTest.java     |    2 +-
 ...CacheAtomicNearUpdateTopologyChangeTest.java |    7 -
 .../CacheGetFutureHangsSelfTest.java            |    2 +-
 .../CacheLateAffinityAssignmentTest.java        |    2 -
 ...NearDisabledAtomicInvokeRestartSelfTest.java |    6 -
 ...acheEntrySetIterationPreloadingSelfTest.java |    6 +-
 ...dCacheMultithreadedFailoverAbstractTest.java |   18 +-
 ...chePartitionedReloadAllAbstractSelfTest.java |   11 -
 .../GridCacheTransformEventSelfTest.java        |    2 -
 .../IgniteCacheAtomicNodeJoinTest.java          |    6 -
 ...niteCacheClientNodeChangingTopologyTest.java |   92 +-
 .../IgniteCacheCreatePutMultiNodeSelfTest.java  |    2 +-
 .../distributed/IgniteCacheCreatePutTest.java   |    2 +-
 .../IgniteCacheMessageRecoveryAbstractTest.java |    2 -
 ...tPartitionedOnlyByteArrayValuesSelfTest.java |    2 -
 .../dht/GridCacheAtomicFullApiSelfTest.java     |   19 -
 .../dht/GridCacheAtomicNearCacheSelfTest.java   |   52 +-
 ...EnabledPrimaryWriteOrderFullApiSelfTest.java |   31 -
 ...eAtomicPrimaryWriteOrderFullApiSelfTest.java |   32 -
 ...tomicPrimaryWriteOrderReloadAllSelfTest.java |   32 -
 .../GridCacheDhtAtomicRemoveFailureTest.java    |    7 -
 .../dht/IgniteCacheConcurrentPutGetRemove.java  |    2 -
 ...artitionedBackupNodeFailureRecoveryTest.java |    7 -
 .../IgniteCachePutRetryAbstractSelfTest.java    |   16 -
 .../atomic/GridCacheAtomicFailoverSelfTest.java |    3 -
 ...eAtomicInvalidPartitionHandlingSelfTest.java |   39 +-
 ...AtomicPrimaryWriteOrderFailoverSelfTest.java |   36 -
 ...tomicPrimaryWriteOrderRemoveFailureTest.java |   53 -
 .../GridCacheAtomicRemoveFailureTest.java       |    7 -
 ...micPrimaryWriteOrderNearEnabledSelfTest.java |   39 -
 ...sistencyAtomicPrimaryWriteOrderSelfTest.java |   32 -
 ...PutRetryAtomicPrimaryWriteOrderSelfTest.java |   32 -
 ...LateAffDisabledMultiNodeFullApiSelfTest.java |   35 +
 ...imaryWriteOrderMultiNodeFullApiSelfTest.java |   35 -
 ...GridCacheAtomicMultiNodeFullApiSelfTest.java |   10 -
 ...omicMultiNodeP2PDisabledFullApiSelfTest.java |   19 -
 ...imaryWriteOrderMultiNodeFullApiSelfTest.java |   31 -
 .../GridCacheAtomicNearRemoveFailureTest.java   |    7 -
 ...idCacheAtomicPartitionedMetricsSelfTest.java |    2 -
 ...imaryWriteOrderMultiNodeFullApiSelfTest.java |   32 -
 ...rderMultiNodeP2PDisabledFullApiSelfTest.java |   33 -
 ...cPrimaryWriteOrderNearRemoveFailureTest.java |   52 -
 ...cPrimaryWriteOrderOnheapFullApiSelfTest.java |   28 -
 ...riteOrderOnheapMultiNodeFullApiSelfTest.java |   29 -
 .../near/GridCacheNearEvictionSelfTest.java     |    2 -
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java |    2 -
 .../near/GridCacheNearTxForceKeyTest.java       |    1 -
 ...rtitionedAffinityHashIdResolverSelfTest.java |  102 -
 ...achePartitionedMultiNodeFullApiSelfTest.java |    4 -
 .../near/NearCacheSyncUpdateTest.java           |   27 +-
 .../GridCacheRebalancingOrderingTest.java       |    2 -
 ...cheRebalancingPartitionDistributionTest.java |    2 -
 ...ridCacheAtomicReplicatedMetricsSelfTest.java |    2 -
 ...eplicatedAtomicMultiNodeFullApiSelfTest.java |   19 -
 ...imaryWriteOrderMultiNodeFullApiSelfTest.java |   33 -
 .../IgniteCacheAtomicExpiryPolicyTest.java      |    7 -
 ...iteCacheAtomicExpiryPolicyWithStoreTest.java |    7 -
 ...AtomicPrimaryWriteOrderExpiryPolicyTest.java |   32 -
 ...maryWriteOrderWithStoreExpiryPolicyTest.java |   32 -
 .../IgniteCacheExpiryPolicyAbstractTest.java    |   57 +-
 .../IgniteCacheExpiryPolicyTestSuite.java       |    2 -
 .../IgniteCacheAtomicLoadAllTest.java           |    7 -
 .../IgniteCacheAtomicLoaderWriterTest.java      |    7 -
 ...gniteCacheAtomicNoLoadPreviousValueTest.java |    7 -
 .../IgniteCacheAtomicNoReadThroughTest.java     |    7 -
 .../IgniteCacheAtomicNoWriteThroughTest.java    |    7 -
 .../IgniteCacheAtomicStoreSessionTest.java      |    7 -
 ...eCacheAtomicStoreSessionWriteBehindTest.java |    7 -
 ...IgniteCacheJdbcBlobStoreNodeRestartTest.java |    8 -
 .../GridCacheAtomicLocalMetricsSelfTest.java    |    2 -
 ...rimaryWriteOrderMultiJvmFullApiSelfTest.java |   31 -
 ...rimaryWriteOrderMultiJvmFullApiSelfTest.java |   31 -
 ...OrderMultiJvmP2PDisabledFullApiSelfTest.java |   31 -
 ...WriteOrderOnheapMultiJvmFullApiSelfTest.java |   29 -
 ...rimaryWriteOrderMultiJvmFullApiSelfTest.java |   31 -
 ...FailoverAtomicPrimaryWriteOrderSelfTest.java |   50 -
 ...tinuousQueryAsyncFailoverAtomicSelfTest.java |   43 +
 ...eContinuousQueryAsyncFilterListenerTest.java |    2 -
 ...acheContinuousQueryExecuteInPrimaryTest.java |    2 -
 ...ContinuousQueryFailoverAbstractSelfTest.java |   10 -
 ...ryFailoverAtomicNearEnabledSelfSelfTest.java |    9 +-
 ...FailoverAtomicPrimaryWriteOrderSelfTest.java |   44 -
 ...usQueryFailoverAtomicReplicatedSelfTest.java |    9 +-
 ...heContinuousQueryFailoverAtomicSelfTest.java |   36 +
 ...ontinuousQueryOperationFromCallbackTest.java |    2 -
 .../CacheContinuousQueryOperationP2PTest.java   |    2 -
 .../CacheContinuousQueryOrderingEventTest.java  |    2 -
 ...acheContinuousQueryRandomOperationsTest.java |    2 -
 .../CacheEntryProcessorNonSerializableTest.java |    2 +-
 .../CacheKeepBinaryIterationTest.java           |    2 -
 ...idCacheWriteBehindStoreAbstractSelfTest.java |   24 +-
 .../GridCacheWriteBehindStoreAbstractTest.java  |    4 +
 ...heWriteBehindStoreMultithreadedSelfTest.java |   88 +-
 .../GridCacheWriteBehindStoreSelfTest.java      |  159 +-
 ...teCacheClientWriteBehindStoreAtomicTest.java |    7 -
 ...ClientWriteBehindStoreNonCoalescingTest.java |  168 ++
 .../transactions/DepthFirstSearchTest.java      |   18 +-
 .../CacheVersionedEntryAbstractTest.java        |   13 -
 .../clock/GridTimeSyncProcessorSelfTest.java    |  224 --
 .../database/FreeListImplSelfTest.java          |    2 +-
 .../IgniteDbMemoryLeakAbstractTest.java         |   14 +-
 .../DataStreamerUpdateAfterLoadTest.java        |   18 +-
 .../igfs/IgfsAbstractBaseSelfTest.java          |   11 +-
 .../igfs/IgfsDualAbstractSelfTest.java          |   33 -
 .../processors/igfs/IgfsFileInfoSelfTest.java   |    2 +-
 ...fsLocalSecondaryFileSystemProxySelfTest.java |    1 -
 .../internal/processors/igfs/IgfsMock.java      |    7 -
 .../processors/igfs/IgfsModesSelfTest.java      |  130 --
 .../processors/igfs/IgfsSizeSelfTest.java       |    5 -
 .../service/ClosureServiceClientsNodesTest.java |    2 +-
 .../GridServiceProcessorAbstractSelfTest.java   |   28 +
 ...ServiceProcessorMultiNodeConfigSelfTest.java |  156 +-
 .../GridServiceProcessorMultiNodeSelfTest.java  |  188 +-
 ...ent2ClassLoadersOptimizedMarshallerTest.java |    2 +-
 ...mentClassLoadingOptimizedMarshallerTest.java |    2 +-
 .../ServicePredicateAccessCacheTest.java        |    4 +-
 .../apache/ignite/lang/GridTupleSelfTest.java   |   35 -
 .../communication/GridIoManagerBenchmark0.java  |    1 -
 ...namicProxySerializationMultiJvmSelfTest.java |    2 +-
 .../GridMarshallerPerformanceTest.java          |    2 +-
 .../OptimizedMarshallerEnumSelfTest.java        |   87 -
 .../OptimizedMarshallerNodeFailoverTest.java    |  357 ---
 .../OptimizedMarshallerPooledSelfTest.java      |   44 -
 .../optimized/OptimizedMarshallerSelfTest.java  |  283 ---
 ...arshallerSerialPersistentFieldsSelfTest.java |  114 -
 .../optimized/OptimizedMarshallerTest.java      |  790 -------
 .../OptimizedObjectStreamSelfTest.java          | 2157 -----------------
 .../TestTcpDiscoveryIpFinderAdapter.java        |   43 -
 .../marshaller/optimized/package-info.java      |   22 -
 .../IgniteMessagingWithClientTest.java          |    2 +-
 .../tcp/TcpCommunicationSpiDropNodesTest.java   |    1 -
 .../TcpCommunicationSpiFaultyClientTest.java    |    1 -
 ...pClientDiscoveryMarshallerCheckSelfTest.java |    2 +-
 .../TcpDiscoveryMarshallerCheckSelfTest.java    |    2 +-
 .../GridInternalTasksLoadBalancingSelfTest.java |   21 +-
 .../configvariations/ConfigVariations.java      |    5 +-
 .../testframework/junits/GridAbstractTest.java  |    2 -
 .../junits/GridTestKernalContext.java           |    1 +
 .../junits/IgniteTestResources.java             |    2 +-
 .../junits/common/GridCommonAbstractTest.java   |   52 +-
 .../multijvm/IgniteCacheProcessProxy.java       |    5 -
 .../multijvm/IgniteClusterProcessProxy.java     |   11 -
 .../testsuites/IgniteBinaryBasicTestSuite.java  |   14 +-
 .../IgniteBinaryObjectsTestSuite.java           |    2 +
 .../IgniteCacheFailoverTestSuite.java           |    4 -
 .../IgniteCacheFailoverTestSuite2.java          |    2 -
 .../IgniteCacheFailoverTestSuite3.java          |    2 -
 ...IgniteCacheFullApiMultiJvmSelfTestSuite.java |   10 -
 .../IgniteCacheFullApiSelfTestSuite.java        |   24 +-
 .../ignite/testsuites/IgniteCacheTestSuite.java |    6 +-
 .../testsuites/IgniteCacheTestSuite2.java       |    2 -
 .../testsuites/IgniteCacheTestSuite3.java       |    4 -
 .../IgniteCacheWriteBehindTestSuite.java        |    2 +
 .../IgniteMarshallerSelfTestSuite.java          |   14 +-
 .../testsuites/IgniteUtilSelfTestSuite.java     |    2 +
 .../apache/ignite/util/GridIntListSelfTest.java |  153 ++
 .../webapp/META-INF/ignite-webapp-config.xml    |    2 +-
 .../query/h2/GridH2IndexingGeoSelfTest.java     |    4 +-
 .../fs/IgniteHadoopIgfsSecondaryFileSystem.java |    9 +-
 .../hadoop/fs/v1/IgniteHadoopFileSystem.java    |  698 ++----
 .../hadoop/fs/v2/IgniteHadoopFileSystem.java    |  481 +---
 .../ignite/hadoop/planner/package-info.java     |   22 +
 ...doopIgfsSecondaryFileSystemDelegateImpl.java |   11 +-
 .../hadoop/impl/igfs/HadoopIgfsEx.java          |    8 +
 .../hadoop/impl/igfs/HadoopIgfsInProc.java      |   23 +-
 .../hadoop/impl/igfs/HadoopIgfsOutProc.java     |   12 +
 .../hadoop/impl/igfs/HadoopIgfsWrapper.java     |   14 +
 .../resources/META-INF/classnames.properties    |    8 -
 .../test/config/hadoop-fs-open-test/grid-0.xml  |    2 +-
 .../test/config/hadoop-fs-open-test/grid-1.xml  |    2 +-
 .../test/config/hadoop-fs-open-test/grid-2.xml  |    2 +-
 .../test/config/igfs-cli-config-dual-async.xml  |    2 +-
 .../test/config/igfs-cli-config-dual-sync.xml   |    2 +-
 .../src/test/config/igfs-cli-config-primary.xml |    2 +-
 .../src/test/config/igfs-cli-config-proxy.xml   |    2 +-
 .../igfs/HadoopFIleSystemFactorySelfTest.java   |   26 +-
 .../IgniteHadoopFileSystemAbstractSelfTest.java |   12 +-
 .../IgniteHadoopFileSystemLoggerSelfTest.java   |   32 +-
 ...condaryFileSystemInitializationSelfTest.java |  213 --
 .../testsuites/IgniteHadoopTestSuite.java       |    3 -
 .../CacheHibernateBlobStoreNodeRestartTest.java |    8 -
 .../CacheHibernateBlobStoreNodeRestartTest.java |    8 -
 .../cache/query/GridCacheTwoStepQuery.java      |   26 +-
 .../query/h2/DmlStatementsProcessor.java        |   49 +-
 .../processors/query/h2/IgniteH2Indexing.java   |  706 ++++--
 .../query/h2/ddl/DdlStatementsProcessor.java    |  208 ++
 .../query/h2/opt/GridH2IndexBase.java           |   33 +-
 .../query/h2/opt/GridH2PrimaryScanIndex.java    |   87 +
 .../query/h2/opt/GridH2SystemIndexFactory.java  |   38 +
 .../processors/query/h2/opt/GridH2Table.java    |  382 ++--
 .../query/h2/opt/GridH2TreeIndex.java           |    2 +-
 .../query/h2/opt/GridLuceneIndex.java           |   10 +-
 .../query/h2/sql/GridSqlCreateIndex.java        |  121 +
 .../query/h2/sql/GridSqlDropIndex.java          |   82 +
 .../query/h2/sql/GridSqlQueryParser.java        |  123 +
 .../query/h2/sql/GridSqlQuerySplitter.java      |   85 +-
 .../query/h2/twostep/GridMapQueryExecutor.java  |   68 +-
 .../h2/twostep/GridReduceQueryExecutor.java     |  154 +-
 .../h2/twostep/msg/GridH2QueryRequest.java      |  109 +-
 .../CacheOperationsWithExpirationTest.java      |    2 -
 .../CacheRandomOperationsMultithreadedTest.java |    2 -
 .../IgniteCacheAbstractFieldsQuerySelfTest.java |   51 +-
 .../IgniteCacheCrossCacheJoinRandomTest.java    |    2 -
 ...acheDistributedJoinCollocatedAndNotTest.java |    2 -
 ...acheDistributedJoinCustomAffinityMapper.java |    2 -
 .../IgniteCacheDistributedJoinNoIndexTest.java  |    2 -
 ...ributedJoinPartitionedAndReplicatedTest.java |    2 -
 ...CacheDistributedJoinQueryConditionsTest.java |    2 -
 ...PartitionedAndReplicatedCollocationTest.java |    2 -
 ...teCacheJoinPartitionedAndReplicatedTest.java |   14 +-
 .../cache/IgniteCacheNoClassQuerySelfTest.java  |    2 +-
 ...iteCacheReplicatedFieldsQueryROSelfTest.java |   27 +
 .../cache/index/AbstractSchemaSelfTest.java     |  512 +++++
 .../DynamicIndexAbstractBasicSelfTest.java      |  950 ++++++++
 .../DynamicIndexAbstractConcurrentSelfTest.java |  921 ++++++++
 .../index/DynamicIndexAbstractSelfTest.java     |  467 ++++
 .../index/DynamicIndexClientBasicSelfTest.java  |   28 +
 ...ndexPartitionedAtomicConcurrentSelfTest.java |   33 +
 ...titionedTransactionalConcurrentSelfTest.java |   33 +
 ...IndexReplicatedAtomicConcurrentSelfTest.java |   33 +
 ...plicatedTransactionalConcurrentSelfTest.java |   33 +
 .../index/DynamicIndexServerBasicSelfTest.java  |   28 +
 ...amicIndexServerCoordinatorBasicSelfTest.java |   28 +
 ...namicIndexServerNodeFIlterBasicSelfTest.java |   28 +
 ...erverNodeFilterCoordinatorBasicSelfTest.java |   30 +
 .../index/H2DynamicIndexAbstractSelfTest.java   |  400 ++++
 ...namicIndexAtomicPartitionedNearSelfTest.java |   26 +
 ...H2DynamicIndexAtomicPartitionedSelfTest.java |   39 +
 .../H2DynamicIndexAtomicReplicatedSelfTest.java |   39 +
 ...dexTransactionalPartitionedNearSelfTest.java |   26 +
 ...icIndexTransactionalPartitionedSelfTest.java |   39 +
 ...micIndexTransactionalReplicatedSelfTest.java |   39 +
 .../cache/index/SchemaExchangeSelfTest.java     |  589 +++++
 .../local/IgniteCacheLocalQuerySelfTest.java    |    2 +-
 .../database/IgniteDbMemoryLeakIndexedTest.java |    2 +-
 .../IgniteDbMemoryLeakSqlQueryTest.java         |    2 +-
 .../query/IgniteQueryDedicatedPoolTest.java     |    1 -
 ...gniteSqlSegmentedIndexMultiNodeSelfTest.java |   28 +
 .../query/IgniteSqlSegmentedIndexSelfTest.java  |  154 +-
 .../query/IgniteSqlSplitterSelfTest.java        |  127 +-
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  109 +-
 .../query/h2/IgniteSqlQueryMinMaxTest.java      |   16 +-
 .../query/h2/opt/GridH2TableSelfTest.java       |  171 +-
 .../h2/sql/AbstractH2CompareQueryTest.java      |    2 +-
 .../query/h2/sql/GridQueryParsingTest.java      |  212 +-
 .../FetchingQueryCursorStressTest.java          |    2 +-
 .../IgniteCacheQuerySelfTestSuite.java          |   43 +-
 .../IgniteCacheQuerySelfTestSuite2.java         |   11 +
 .../IgniteCacheQuerySelfTestSuite4.java         |    8 +-
 modules/ml/README.txt                           |   15 +
 modules/ml/licenses/apache-2.0.txt              |  202 ++
 modules/ml/licenses/mit.txt                     |    7 +
 modules/ml/pom.xml                              |  103 +
 .../java/org/apache/ignite/ml/math/Algebra.java |  571 +++++
 .../org/apache/ignite/ml/math/Constants.java    |   42 +
 .../org/apache/ignite/ml/math/Destroyable.java  |   30 +
 .../ignite/ml/math/IdentityValueMapper.java     |   53 +
 .../org/apache/ignite/ml/math/KeyMapper.java    |   33 +
 .../java/org/apache/ignite/ml/math/Matrix.java  |  518 +++++
 .../apache/ignite/ml/math/MatrixKeyMapper.java  |   30 +
 .../apache/ignite/ml/math/MatrixStorage.java    |   58 +
 .../apache/ignite/ml/math/MetaAttributes.java   |   76 +
 .../org/apache/ignite/ml/math/MurmurHash.java   |  246 ++
 .../apache/ignite/ml/math/StorageConstants.java |   49 +
 .../ignite/ml/math/StorageOpsMetrics.java       |   49 +
 .../java/org/apache/ignite/ml/math/Tracer.java  |  456 ++++
 .../org/apache/ignite/ml/math/ValueMapper.java  |   35 +
 .../java/org/apache/ignite/ml/math/Vector.java  |  498 ++++
 .../apache/ignite/ml/math/VectorKeyMapper.java  |   29 +
 .../apache/ignite/ml/math/VectorStorage.java    |   53 +
 .../decompositions/CholeskyDecomposition.java   |  306 +++
 .../decompositions/DecompositionSupport.java    |  105 +
 .../math/decompositions/EigenDecomposition.java |  923 ++++++++
 .../ml/math/decompositions/LUDecomposition.java |  366 +++
 .../ml/math/decompositions/QRDecomposition.java |  186 ++
 .../SingularValueDecomposition.java             |  620 +++++
 .../ml/math/decompositions/package-info.java    |   22 +
 .../math/exceptions/CardinalityException.java   |   38 +
 .../math/exceptions/ColumnIndexException.java   |   35 +
 .../ml/math/exceptions/IndexException.java      |   35 +
 .../NonPositiveDefiniteMatrixException.java     |   37 +
 .../exceptions/NonSymmetricMatrixException.java |   35 +
 .../ml/math/exceptions/RowIndexException.java   |   35 +
 .../exceptions/SingularMatrixException.java     |   30 +
 .../exceptions/UnknownProviderException.java    |   35 +
 .../UnsupportedOperationException.java          |   44 +
 .../ignite/ml/math/exceptions/package-info.java |   22 +
 .../ignite/ml/math/functions/Functions.java     |  136 ++
 .../ml/math/functions/IgniteBiConsumer.java     |   29 +
 .../ml/math/functions/IgniteBiFunction.java     |   29 +
 .../ml/math/functions/IgniteConsumer.java       |   29 +
 .../ml/math/functions/IgniteDoubleFunction.java |   29 +
 .../ml/math/functions/IgniteFunction.java       |   30 +
 .../math/functions/IntDoubleToVoidFunction.java |   25 +
 .../functions/IntIntDoubleToVoidFunction.java   |   28 +
 .../math/functions/IntIntToDoubleFunction.java  |   24 +
 .../ignite/ml/math/functions/package-info.java  |   22 +
 .../apache/ignite/ml/math/impls/CacheUtils.java |  356 +++
 .../ml/math/impls/matrix/AbstractMatrix.java    |  880 +++++++
 .../ml/math/impls/matrix/CacheMatrix.java       |  158 ++
 .../impls/matrix/DenseLocalOffHeapMatrix.java   |   90 +
 .../impls/matrix/DenseLocalOnHeapMatrix.java    |   86 +
 .../ml/math/impls/matrix/DiagonalMatrix.java    |  101 +
 .../ml/math/impls/matrix/FunctionMatrix.java    |   95 +
 .../ignite/ml/math/impls/matrix/MatrixView.java |   84 +
 .../ml/math/impls/matrix/PivotedMatrixView.java |  243 ++
 .../ml/math/impls/matrix/RandomMatrix.java      |   97 +
 .../impls/matrix/SparseDistributedMatrix.java   |  155 ++
 .../impls/matrix/SparseLocalOnHeapMatrix.java   |   72 +
 .../math/impls/matrix/TransposedMatrixView.java |   84 +
 .../ml/math/impls/matrix/package-info.java      |   22 +
 .../ignite/ml/math/impls/package-info.java      |   22 +
 .../storage/matrix/ArrayMatrixStorage.java      |  161 ++
 .../storage/matrix/CacheMatrixStorage.java      |  180 ++
 .../matrix/DenseOffHeapMatrixStorage.java       |  197 ++
 .../storage/matrix/DiagonalMatrixStorage.java   |  136 ++
 .../storage/matrix/FunctionMatrixStorage.java   |  175 ++
 .../storage/matrix/MatrixDelegateStorage.java   |  205 ++
 .../storage/matrix/PivotedMatrixStorage.java    |  256 +++
 .../storage/matrix/RandomMatrixStorage.java     |  176 ++
 .../matrix/SparseDistributedMatrixStorage.java  |  290 +++
 .../matrix/SparseLocalOnHeapMatrixStorage.java  |  226 ++
 .../math/impls/storage/matrix/package-info.java |   22 +
 .../storage/vector/ArrayVectorStorage.java      |  135 ++
 .../storage/vector/CacheVectorStorage.java      |  175 ++
 .../storage/vector/ConstantVectorStorage.java   |  133 ++
 .../storage/vector/DelegateVectorStorage.java   |  157 ++
 .../vector/DenseLocalOffHeapVectorStorage.java  |  172 ++
 .../storage/vector/FunctionVectorStorage.java   |  141 ++
 .../storage/vector/MatrixVectorStorage.java     |  185 ++
 .../storage/vector/PivotedVectorStorage.java    |  175 ++
 .../storage/vector/RandomVectorStorage.java     |  152 ++
 .../SingleElementVectorDelegateStorage.java     |  145 ++
 .../vector/SingleElementVectorStorage.java      |  143 ++
 .../vector/SparseLocalOffHeapVectorStorage.java |  149 ++
 .../vector/SparseLocalOnHeapVectorStorage.java  |  152 ++
 .../math/impls/storage/vector/package-info.java |   22 +
 .../impls/vector/AbstractReadOnlyVector.java    |  125 +
 .../ml/math/impls/vector/AbstractVector.java    |  903 ++++++++
 .../ml/math/impls/vector/CacheVector.java       |  140 ++
 .../ml/math/impls/vector/ConstantVector.java    |   84 +
 .../ml/math/impls/vector/DelegatingVector.java  |  391 ++++
 .../impls/vector/DenseLocalOffHeapVector.java   |   89 +
 .../impls/vector/DenseLocalOnHeapVector.java    |  104 +
 .../ml/math/impls/vector/FunctionVector.java    |  112 +
 .../ml/math/impls/vector/MatrixVectorView.java  |  139 ++
 .../ml/math/impls/vector/PivotedVectorView.java |  163 ++
 .../ml/math/impls/vector/RandomVector.java      |  129 ++
 .../math/impls/vector/SingleElementVector.java  |  102 +
 .../impls/vector/SingleElementVectorView.java   |   97 +
 .../impls/vector/SparseLocalOffHeapVector.java  |   47 +
 .../ml/math/impls/vector/SparseLocalVector.java |   71 +
 .../ignite/ml/math/impls/vector/VectorView.java |   85 +
 .../ml/math/impls/vector/package-info.java      |   22 +
 .../org/apache/ignite/ml/math/package-info.java |   22 +
 .../ignite/ml/math/d3-matrix-template.html      |  128 ++
 .../ignite/ml/math/d3-vector-template.html      |  111 +
 .../apache/ignite/ml/math/ExternalizeTest.java  |   66 +
 .../ml/math/MathImplDistributedTestSuite.java   |   39 +
 .../ignite/ml/math/MathImplLocalTestSuite.java  |  123 +
 .../ignite/ml/math/MathImplMainTestSuite.java   |   33 +
 .../org/apache/ignite/ml/math/TracerTest.java   |  195 ++
 .../ignite/ml/math/benchmark/MathBenchmark.java |  205 ++
 .../math/benchmark/MathBenchmarkSelfTest.java   |  100 +
 .../ignite/ml/math/benchmark/ResultsWriter.java |  127 +
 .../ml/math/benchmark/VectorBenchmarkTest.java  |  138 ++
 .../ignite/ml/math/benchmark/package-info.java  |   18 +
 .../CholeskyDecompositionTest.java              |  158 ++
 .../decompositions/EigenDecompositionTest.java  |  193 ++
 .../decompositions/LUDecompositionTest.java     |  250 ++
 .../decompositions/QRDecompositionTest.java     |  139 ++
 .../SingularValueDecompositionTest.java         |  120 +
 .../ignite/ml/math/impls/MathTestConstants.java |   88 +
 .../ml/math/impls/matrix/CacheMatrixTest.java   |  369 +++
 .../DenseLocalOffHeapMatrixConstructorTest.java |   65 +
 .../DenseLocalOnHeapMatrixConstructorTest.java  |   71 +
 .../math/impls/matrix/DiagonalMatrixTest.java   |  209 ++
 .../matrix/FunctionMatrixConstructorTest.java   |  113 +
 .../math/impls/matrix/MatrixAttributeTest.java  |  156 ++
 .../matrix/MatrixImplementationFixtures.java    |  381 +++
 .../impls/matrix/MatrixImplementationsTest.java | 1113 +++++++++
 .../impls/matrix/MatrixKeyMapperForTests.java   |   69 +
 .../impls/matrix/MatrixViewConstructorTest.java |  114 +
 .../PivotedMatrixViewConstructorTest.java       |  129 ++
 .../matrix/RandomMatrixConstructorTest.java     |   71 +
 .../matrix/SparseDistributedMatrixTest.java     |  265 +++
 .../SparseLocalOnHeapMatrixConstructorTest.java |   53 +
 .../impls/matrix/TransposedMatrixViewTest.java  |   87 +
 .../storage/matrix/MatrixArrayStorageTest.java  |   63 +
 .../storage/matrix/MatrixBaseStorageTest.java   |   89 +
 .../matrix/MatrixOffHeapStorageTest.java        |   39 +
 .../storage/matrix/MatrixStorageFixtures.java   |  137 ++
 .../matrix/MatrixStorageImplementationTest.java |   73 +
 .../SparseDistributedMatrixStorageTest.java     |  126 +
 .../RandomAccessSparseVectorStorageTest.java    |   60 +
 .../SparseLocalOffHeapVectorStorageTest.java    |   78 +
 .../storage/vector/VectorArrayStorageTest.java  |   58 +
 .../storage/vector/VectorBaseStorageTest.java   |   69 +
 .../vector/VectorOffheapStorageTest.java        |   73 +
 .../math/impls/vector/AbstractVectorTest.java   |  543 +++++
 .../ml/math/impls/vector/CacheVectorTest.java   |  434 ++++
 .../vector/ConstantVectorConstructorTest.java   |   52 +
 .../vector/DelegatingVectorConstructorTest.java |   62 +
 .../DenseLocalOffHeapVectorConstructorTest.java |   59 +
 .../DenseLocalOnHeapVectorConstructorTest.java  |  163 ++
 .../vector/FunctionVectorConstructorTest.java   |  121 +
 .../math/impls/vector/MatrixVectorViewTest.java |  226 ++
 .../PivotedVectorViewConstructorTest.java       |  211 ++
 .../vector/RandomVectorConstructorTest.java     |  145 ++
 .../SingleElementVectorConstructorTest.java     |  159 ++
 .../SingleElementVectorViewConstructorTest.java |  137 ++
 .../SparseLocalVectorConstructorTest.java       |   54 +
 .../math/impls/vector/VectorAttributesTest.java |  217 ++
 .../ml/math/impls/vector/VectorFoldMapTest.java |  122 +
 .../vector/VectorImplementationsFixtures.java   |  655 ++++++
 .../impls/vector/VectorImplementationsTest.java |  861 +++++++
 .../math/impls/vector/VectorIterableTest.java   |  376 +++
 .../ml/math/impls/vector/VectorNormTest.java    |  247 ++
 .../math/impls/vector/VectorToMatrixTest.java   |  308 +++
 .../ml/math/impls/vector/VectorViewTest.java    |  162 ++
 .../cpp/core-test/config/cache-test-default.xml |    3 -
 .../platforms/cpp/core-test/src/cache_test.cpp  |   38 +-
 .../Apache.Ignite.Core.Tests.csproj             |   10 +-
 .../Binary/BinaryBuilderSelfTest.cs             |  122 +-
 .../Binary/BinaryBuilderSelfTestSimpleName.cs   |   33 +
 .../Binary/BinaryCompactFooterInteropTest.cs    |    3 +
 .../Binary/BinaryDynamicRegistrationTest.cs     |   10 +-
 .../Binary/BinaryNameMapperTest.cs              |  108 +
 .../Binary/BinarySelfTest.cs                    |   40 +-
 .../Binary/BinarySelfTestSimpleName.cs          |   33 +
 .../Binary/Serializable/SqlDmlTest.cs           |    3 +
 .../Binary/TypeNameParserTest.cs                |  232 ++
 .../Cache/Affinity/AffinityFunctionTest.cs      |   26 +-
 .../Cache/CacheConfigurationTest.cs             |   16 +-
 .../Cache/CacheDynamicStartTest.cs              |    4 +-
 .../Cache/Query/CacheDmlQueriesTest.cs          |   15 +
 .../Query/CacheDmlQueriesTestSimpleName.cs      |   35 +
 .../Cache/Query/CacheLinqTest.cs                |   29 +-
 .../Cache/Query/CacheLinqTestSimpleName.cs      |   35 +
 .../Query/CacheQueriesCodeConfigurationTest.cs  |   10 +-
 .../Cache/Query/CacheQueriesTest.cs             |   13 +-
 .../Cache/Query/CacheQueriesTestSimpleName.cs   |   35 +
 .../Continuous/ContinuousQueryAbstractTest.cs   |   36 +-
 .../Cache/Store/CacheStoreTest.cs               |    4 +-
 .../Compute/ComputeApiTest.cs                   |    3 +-
 .../Config/Compute/compute-grid2.xml            |   10 -
 .../Config/cache-binarizables.xml               |   16 +-
 .../Config/cache-query-continuous.xml           |    8 +-
 .../Config/cache-query.xml                      |    2 +-
 .../Config/marshaller-invalid.xml               |    2 +-
 .../Config/native-client-test-cache.xml         |    3 -
 .../ConsoleRedirectTest.cs                      |    5 +-
 .../DataStructures/AtomicLongTest.cs            |    1 +
 .../Apache.Ignite.Core.Tests/ExecutableTest.cs  |    5 +-
 .../IgniteConfigurationSerializerTest.cs        |   38 +-
 .../IgniteStartStopTest.cs                      |   24 +
 .../Apache.Ignite.Core.Tests/LifecycleTest.cs   |   15 +-
 .../Log/CustomLoggerTest.cs                     |    8 +-
 .../Apache.Ignite.Core.Tests/MessagingTest.cs   |   13 +-
 .../Plugin/Cache/CachePlugin.cs                 |  127 -
 .../Plugin/Cache/CachePluginConfiguration.cs    |   64 -
 .../Plugin/Cache/CachePluginTest.cs             |  218 --
 .../Services/ServicesTest.cs                    |    3 +
 .../Apache.Ignite.Core.Tests/TestUtils.cs       |    4 +-
 .../Apache.Ignite.Core.csproj                   |   15 +-
 .../Binary/BinaryBasicNameMapper.cs             |  129 ++
 .../Configuration/CacheAtomicWriteOrderMode.cs  |   43 -
 .../Cache/Configuration/CacheConfiguration.cs   |   13 -
 .../Cache/Configuration/QueryEntity.cs          |    4 +-
 .../Cache/Configuration/QueryField.cs           |    2 +-
 .../Apache.Ignite.Core/IgniteConfiguration.cs   |   30 +-
 .../IgniteConfigurationSection.xsd              |   23 +-
 .../dotnet/Apache.Ignite.Core/Ignition.cs       |  101 +-
 .../Apache.Ignite.Core/Impl/Binary/Binary.cs    |   10 +-
 .../Impl/Binary/BinaryObjectBuilder.cs          |    4 +-
 .../Binary/BinarySurrogateTypeDescriptor.cs     |   15 +-
 .../Impl/Binary/BinarySystemHandlers.cs         |   10 +
 .../Impl/Binary/BinaryUtils.cs                  |  125 +-
 .../Impl/Binary/Marshaller.cs                   |   96 +-
 .../Impl/Binary/TypeNameParser.cs               |  384 ++++
 .../Impl/Binary/TypeResolver.cs                 |   95 +-
 .../Impl/Compute/ComputeFunc.cs                 |    2 +-
 .../Impl/Compute/ComputeJob.cs                  |    2 +-
 .../Impl/Compute/ComputeOutFunc.cs              |    2 +-
 .../dotnet/Apache.Ignite.Core/Impl/Ignite.cs    |   30 +-
 .../Apache.Ignite.Core/Impl/IgniteProxy.cs      |  464 ----
 .../Impl/LifecycleBeanHolder.cs                 |   66 -
 .../Impl/LifecycleHandlerHolder.cs              |   66 +
 .../Impl/Plugin/Cache/CachePluginContext.cs     |   82 -
 .../Impl/Plugin/Cache/CachePluginProcessor.cs   |   77 -
 .../Plugin/Cache/CachePluginProviderProxy.cs    |   75 -
 .../Plugin/Cache/ICachePluginProviderProxy.cs   |   52 -
 .../Impl/Resource/ResourceProcessor.cs          |   10 -
 .../Impl/Resource/ResourceTypeDescriptor.cs     |   12 +-
 .../Impl/Unmanaged/UnmanagedCallbackOp.cs       |    4 -
 .../Impl/Unmanaged/UnmanagedCallbacks.cs        |   58 +-
 .../Lifecycle/ILifecycleBean.cs                 |   64 -
 .../Lifecycle/ILifecycleHandler.cs              |   64 +
 .../Lifecycle/LifecycleEventType.cs             |    2 +-
 .../Cache/CachePluginProviderTypeAttribute.cs   |   52 -
 .../Plugin/Cache/ICachePluginConfiguration.cs   |   21 -
 .../Plugin/Cache/ICachePluginContext.cs         |   47 -
 .../Plugin/Cache/ICachePluginProvider.cs        |   52 -
 .../Impl/CacheFieldsQueryProvider.cs            |   24 +-
 .../Impl/CacheQueryExpressionVisitor.cs         |    4 +-
 .../Impl/CacheQueryModelVisitor.cs              |   15 +
 .../Apache.Ignite/Service/IgniteService.cs      |    6 +-
 .../Misc/LifecycleExample.cs                    |   12 +-
 .../http/jetty/GridJettyObjectMapper.java       |  119 +-
 .../config/EnableIgniteRepositories.java        |   10 +-
 .../repository/query/IgniteQueryGenerator.java  |    8 +-
 .../support/IgniteRepositoryFactory.java        |    8 +-
 .../GridSpringBeanSerializationSelfTest.java    |    2 +-
 .../commands/cache/VisorCacheClearCommand.scala |    2 +-
 .../commands/cache/VisorCacheCommand.scala      |  290 ++-
 .../commands/cache/VisorCacheScanCommand.scala  |   19 +-
 .../config/VisorConfigurationCommand.scala      |  183 +-
 .../commands/disco/VisorDiscoveryCommand.scala  |   22 +-
 .../commands/events/VisorEventsCommand.scala    |   30 +-
 .../visor/commands/gc/VisorGcCommand.scala      |    4 +-
 .../commands/tasks/VisorTasksCommand.scala      |   61 +-
 .../scala/org/apache/ignite/visor/visor.scala   |   34 +-
 .../commands/cache/VisorCacheCommandSpec.scala  |    4 +
 .../commands/open/VisorOpenCommandSpec.scala    |    6 +-
 modules/web-console/backend/app/agent.js        |  934 --------
 modules/web-console/backend/app/agentSocket.js  |  249 ++
 .../web-console/backend/app/agentsHandler.js    |  400 ++++
 modules/web-console/backend/app/apiServer.js    |   68 +
 modules/web-console/backend/app/app.js          |   63 -
 modules/web-console/backend/app/browser.js      |  523 -----
 .../web-console/backend/app/browsersHandler.js  |  279 +++
 modules/web-console/backend/app/mongo.js        |   36 +-
 modules/web-console/backend/app/routes.js       |    6 +-
 modules/web-console/backend/index.js            |   44 +-
 modules/web-console/backend/package.json        |   52 +-
 modules/web-console/backend/routes/agent.js     |   57 -
 modules/web-console/backend/routes/demo.js      |   14 +-
 modules/web-console/backend/routes/downloads.js |   57 +
 modules/web-console/backend/services/agents.js  |   83 -
 .../web-console/backend/services/downloads.js   |   80 +
 modules/web-console/backend/services/users.js   |   10 +-
 .../web-console/backend/test/app/httpAgent.js   |    6 +-
 .../web-console/backend/test/routes/clusters.js |    4 +-
 modules/web-console/frontend/app/app.config.js  |    1 +
 modules/web-console/frontend/app/app.js         |   12 +-
 .../components/activities-user-dialog/index.js  |    1 -
 .../cluster-select/cluster-select.controller.js |   55 +
 .../cluster-select/cluster-select.pug           |   40 +
 .../app/components/cluster-select/index.js      |   28 +
 .../input-dialog/input-dialog.service.js        |    1 -
 .../list-of-registered-users.column-defs.js     |    2 +-
 .../frontend/app/data/pom-dependencies.json     |    1 +
 .../app/helpers/jade/form/form-field-text.pug   |   55 +-
 .../frontend/app/helpers/jade/mixins.pug        |   26 +-
 .../app/modules/agent/AgentManager.service.js   |  529 +++++
 .../app/modules/agent/AgentModal.service.js     |   89 +
 .../frontend/app/modules/agent/agent.module.js  |  312 +--
 .../frontend/app/modules/cluster/Cache.js       |   59 +
 .../app/modules/cluster/CacheMetrics.js         |   59 +
 .../frontend/app/modules/cluster/Node.js        |   54 +
 .../frontend/app/modules/cluster/NodeMetrics.js |   19 +
 .../generator/AbstractTransformer.js            |   10 -
 .../generator/ConfigurationGenerator.js         |   74 +-
 .../generator/JavaTransformer.service.js        |    3 +
 .../generator/PlatformGenerator.js              |   11 +-
 .../defaults/Cache.platform.service.js          |    9 -
 .../generator/defaults/Cache.service.js         |   13 +-
 .../generator/defaults/Cluster.service.js       |    9 +-
 .../generator/defaults/IGFS.service.js          |    5 +-
 .../frontend/app/modules/demo/Demo.module.js    |    5 +-
 .../app/modules/dialog/dialog.factory.js        |    1 -
 .../getting-started/GettingStarted.provider.js  |    2 +-
 .../app/modules/navbar/userbar.directive.js     |    4 +-
 .../frontend/app/modules/nodes/Nodes.service.js |    1 -
 .../app/modules/sql/notebook.controller.js      |    2 +-
 .../frontend/app/modules/sql/sql.controller.js  |  101 +-
 .../frontend/app/modules/states/admin.state.js  |    4 +-
 .../app/modules/states/configuration.state.js   |   17 +-
 .../states/configuration/caches/affinity.pug    |    2 +-
 .../states/configuration/caches/concurrency.pug |   11 -
 .../states/configuration/caches/general.pug     |   25 +
 .../states/configuration/caches/memory.pug      |   64 +-
 .../states/configuration/caches/query.pug       |    3 +
 .../states/configuration/clusters/events.pug    |    6 +-
 .../states/configuration/clusters/general.pug   |    3 +
 .../clusters/general/discovery/kubernetes.pug   |   37 +
 .../configuration/clusters/marshaller.pug       |    6 -
 .../states/configuration/clusters/swap.pug      |   72 -
 .../states/configuration/clusters/time.pug      |   10 +-
 .../modules/states/configuration/igfs/dual.pug  |   42 -
 .../modules/states/configuration/igfs/misc.pug  |    4 +-
 .../configuration/summary/summary.controller.js |    3 +
 .../configuration/summary/summary.worker.js     |   22 +
 .../app/modules/states/profile.state.js         |    2 +-
 .../frontend/app/modules/user/Auth.service.js   |    6 +-
 .../frontend/app/primitives/btn-group/index.pug |   35 +
 .../frontend/app/services/Confirm.service.js    |    2 +-
 .../app/services/ConfirmBatch.service.js        |    1 -
 .../frontend/controllers/caches-controller.js   |   31 +-
 .../frontend/controllers/clusters-controller.js |   41 +-
 .../frontend/controllers/domains-controller.js  |   20 +-
 modules/web-console/frontend/package.json       |   62 +-
 .../stylesheets/_bootstrap-variables.scss       |    2 +-
 .../stylesheets/_font-awesome-custom.scss       |    5 +
 .../frontend/public/stylesheets/style.scss      |   57 +-
 .../views/configuration/clusters.tpl.pug        |    1 -
 .../views/configuration/domains-import.tpl.pug  |    2 +-
 .../views/configuration/domains.tpl.pug         |    1 -
 .../frontend/views/configuration/igfs.tpl.pug   |    1 -
 .../frontend/views/includes/header.pug          |   23 +-
 .../web-console/frontend/views/sql/sql.tpl.pug  |   12 +-
 .../views/templates/agent-download.tpl.pug      |   39 +-
 .../frontend/views/templates/demo-info.tpl.pug  |    2 +-
 modules/web-console/web-agent/pom.xml           |   16 +-
 .../console/agent/AgentConfiguration.java       |   47 +-
 .../ignite/console/agent/AgentLauncher.java     |  196 +-
 .../apache/ignite/console/agent/AgentUtils.java |    6 +-
 .../console/agent/handlers/ClusterListener.java |  266 +++
 .../agent/handlers/DatabaseListener.java        |    6 +-
 .../console/agent/handlers/DemoListener.java    |  131 ++
 .../console/agent/handlers/RestListener.java    |  229 +-
 .../ignite/console/agent/rest/RestExecutor.java |  197 ++
 .../ignite/console/agent/rest/RestResult.java   |   81 +
 .../ignite/console/demo/AgentClusterDemo.java   |  177 +-
 .../ignite/console/demo/AgentDemoUtils.java     |    2 +-
 .../demo/service/DemoCachesLoadService.java     |   35 +-
 .../src/main/resources/log4j.properties         |    1 -
 .../webapp2/META-INF/ignite-webapp-config.xml   |    2 +-
 modules/yardstick/README.txt                    |    1 -
 modules/yardstick/config/ignite-base-config.xml |   25 +-
 .../ignite-int-max-values-onheap-config.xml     |    2 +-
 modules/yardstick/config/ignite-jdbc-config.xml |    2 +-
 .../yardstick/IgniteBenchmarkArguments.java     |   15 +-
 .../org/apache/ignite/yardstick/IgniteNode.java |    3 -
 pom.xml                                         |   36 +
 1128 files changed, 69715 insertions(+), 28278 deletions(-)
----------------------------------------------------------------------



[36/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 7841f06..da6ebc1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -60,7 +60,12 @@ import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.events.EventType;
 import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.query.QuerySchema;
 import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.schema.SchemaExchangeWorkerTask;
+import org.apache.ignite.internal.processors.query.schema.SchemaNodeLeaveExchangeWorkerTask;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage;
 import org.apache.ignite.internal.suggestions.GridPerformanceSuggestions;
 import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException;
 import org.apache.ignite.internal.IgniteComponentType;
@@ -343,6 +348,13 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @return Task or {@code null} if message doesn't require any special processing.
      */
     public CachePartitionExchangeWorkerTask exchangeTaskForCustomDiscoveryMessage(DiscoveryCustomMessage msg) {
+        if (msg instanceof SchemaAbstractDiscoveryMessage) {
+            SchemaAbstractDiscoveryMessage msg0 = (SchemaAbstractDiscoveryMessage)msg;
+
+            if (msg0.exchange())
+                return new SchemaExchangeWorkerTask(msg0);
+        }
+
         return null;
     }
 
@@ -352,7 +364,24 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @param task Task.
      */
     public void processCustomExchangeTask(CachePartitionExchangeWorkerTask task) {
-        // No-op.
+        if (task instanceof SchemaExchangeWorkerTask) {
+            SchemaAbstractDiscoveryMessage msg = ((SchemaExchangeWorkerTask)task).message();
+
+            if (msg instanceof SchemaProposeDiscoveryMessage) {
+                SchemaProposeDiscoveryMessage msg0 = (SchemaProposeDiscoveryMessage)msg;
+
+                ctx.query().onSchemaPropose(msg0);
+            }
+            else
+                U.warn(log, "Unsupported schema discovery message: " + msg);
+        }
+        else if (task instanceof SchemaNodeLeaveExchangeWorkerTask) {
+            SchemaNodeLeaveExchangeWorkerTask task0 = (SchemaNodeLeaveExchangeWorkerTask)task;
+
+            ctx.query().onNodeLeave(task0.node());
+        }
+        else
+            U.warn(log, "Unsupported custom exchange task: " + task);
     }
 
     /**
@@ -719,7 +748,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             cfg,
             cacheType,
             template,
-            IgniteUuid.randomUuid());
+            IgniteUuid.randomUuid(),
+            new QuerySchema(cfg.getQueryEntities()));
 
         desc.locallyConfigured(true);
         desc.staticallyConfigured(true);
@@ -755,7 +785,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 cfg,
                 cacheType,
                 true,
-                IgniteUuid.randomUuid());
+                IgniteUuid.randomUuid(),
+                new QuerySchema(cfg.getQueryEntities()));
 
             desc0.locallyConfigured(true);
             desc0.staticallyConfigured(true);
@@ -831,6 +862,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             // Must start database before start first cache.
             sharedCtx.database().onKernalStart(false);
 
+            ctx.query().onCacheKernalStart();
+
             // Start dynamic caches received from collect discovery data.
             for (DynamicCacheDescriptor desc : cacheDescriptors()) {
                 if (ctx.config().isDaemon())
@@ -866,7 +899,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
                     caches.put(maskNull(name), cache);
 
-                    startCache(cache);
+                    startCache(cache, desc.schema());
 
                     jCacheProxies.put(maskNull(name), new IgniteCacheProxy(ctx, cache, null, false));
                 }
@@ -1177,10 +1210,11 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
     /**
      * @param cache Cache to start.
+     * @param schema Cache schema.
      * @throws IgniteCheckedException If failed to start cache.
      */
     @SuppressWarnings({"TypeMayBeWeakened", "unchecked"})
-    private void startCache(GridCacheAdapter<?, ?> cache) throws IgniteCheckedException {
+    private void startCache(GridCacheAdapter<?, ?> cache, QuerySchema schema) throws IgniteCheckedException {
         GridCacheContext<?, ?> cacheCtx = cache.context();
 
         ctx.continuous().onCacheStart(cacheCtx);
@@ -1220,7 +1254,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         cacheCtx.cache().start();
 
-        ctx.query().onCacheStart(cacheCtx);
+        ctx.query().onCacheStart(cacheCtx, schema);
 
         cacheCtx.onStarted();
 
@@ -1779,6 +1813,11 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         assert req.start() : req;
         assert req.cacheType() != null : req;
 
+        DynamicCacheDescriptor desc = cacheDescriptor(req.cacheName());
+
+        if (desc != null)
+            desc.onStart();
+
         prepareCacheStart(
             req.startCacheConfiguration(),
             req.nearCacheConfiguration(),
@@ -1786,13 +1825,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             req.clientStartOnly(),
             req.initiatingNodeId(),
             req.deploymentId(),
-            topVer
+            topVer,
+            desc != null ? desc.schema() : null
         );
-
-        DynamicCacheDescriptor desc = cacheDescriptor(req.cacheName());
-
-        if (desc != null)
-            desc.onStart();
     }
 
     /**
@@ -1828,7 +1863,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                         false,
                         null,
                         desc.deploymentId(),
-                        topVer
+                        topVer,
+                        desc.schema()
                     );
                 }
             }
@@ -1845,6 +1881,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @param initiatingNodeId Initiating node ID.
      * @param deploymentId Deployment ID.
      * @param topVer Topology version.
+     * @param schema Query schema.
      * @throws IgniteCheckedException If failed.
      */
     private void prepareCacheStart(
@@ -1854,7 +1891,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         boolean clientStartOnly,
         UUID initiatingNodeId,
         IgniteUuid deploymentId,
-        AffinityTopologyVersion topVer
+        AffinityTopologyVersion topVer,
+        @Nullable QuerySchema schema
     ) throws IgniteCheckedException {
         CacheConfiguration ccfg = new CacheConfiguration(cfg);
 
@@ -1890,7 +1928,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             caches.put(maskNull(cacheCtx.name()), cache);
 
-            startCache(cache);
+            startCache(cache, schema != null ? schema : new QuerySchema());
 
             onKernalStart(cache);
         }
@@ -2137,6 +2175,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             req.cacheType(desc.cacheType());
             req.deploymentId(desc.deploymentId());
             req.receivedFrom(desc.receivedFrom());
+            req.schema(desc.schema());
 
             reqs.add(req);
         }
@@ -2149,6 +2188,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 null);
 
             req.startCacheConfiguration(desc.cacheConfiguration());
+            req.schema(desc.schema());
 
             req.template(true);
 
@@ -2178,6 +2218,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             req.cacheType(desc.cacheType());
             req.deploymentId(desc.deploymentId());
             req.receivedFrom(desc.receivedFrom());
+            req.schema(desc.schema());
 
             reqs.add(req);
 
@@ -2199,7 +2240,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 onDiscoDataReceived(
                         data.joiningNodeId(),
                         data.joiningNodeId(),
-                        (DynamicCacheChangeBatch) joiningNodeData);
+                        (DynamicCacheChangeBatch) joiningNodeData, true);
         }
     }
 
@@ -2212,7 +2253,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 if (e.getValue() != null && e.getValue() instanceof DynamicCacheChangeBatch) {
                     DynamicCacheChangeBatch batch = (DynamicCacheChangeBatch) e.getValue();
 
-                    onDiscoDataReceived(data.joiningNodeId(), e.getKey(), batch);
+                    onDiscoDataReceived(data.joiningNodeId(), e.getKey(), batch, false);
                 }
             }
         }
@@ -2222,8 +2263,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @param joiningNodeId Joining node id.
      * @param rmtNodeId Rmt node id.
      * @param batch Batch.
+     * @param join Whether this is data from joining node.
      */
-    private void onDiscoDataReceived(UUID joiningNodeId, UUID rmtNodeId, DynamicCacheChangeBatch batch) {
+    private void onDiscoDataReceived(UUID joiningNodeId, UUID rmtNodeId, DynamicCacheChangeBatch batch, boolean join) {
         if (batch.clientReconnect()) {
             if (ctx.clientDisconnected()) {
                 if (clientReconnectReqs == null)
@@ -2253,7 +2295,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                                 ccfg,
                                 req.cacheType(),
                                 true,
-                                req.deploymentId());
+                                req.deploymentId(),
+                                req.schema());
 
                         registeredTemplates.put(maskNull(req.cacheName()), desc);
                     }
@@ -2275,6 +2318,10 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                         if (existing.locallyConfigured()) {
                             existing.addRemoteConfiguration(rmtNodeId, req.startCacheConfiguration());
 
+                            if (!join)
+                                // Overwrite existing with remote.
+                                existing.schema(req.schema());
+
                             ctx.discovery().setCacheFilter(
                                     req.cacheName(),
                                     ccfg.getNodeFilter(),
@@ -2290,7 +2337,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                                 ccfg,
                                 req.cacheType(),
                                 false,
-                                req.deploymentId());
+                                req.deploymentId(),
+                                req.schema());
 
                         // Received statically configured cache.
                         if (req.initiatingNodeId() == null)
@@ -2791,12 +2839,10 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             UUID.randomUUID(), cacheName, ctx.localNodeId());
 
         req.startCacheConfiguration(cfg);
-
         req.template(cfg.getName() != null && cfg.getName().endsWith("*"));
-
         req.nearCacheConfiguration(cfg.getNearConfiguration());
-
         req.deploymentId(IgniteUuid.randomUuid());
+        req.schema(new QuerySchema(cfg.getQueryEntities()));
 
         if (CU.isUtilityCache(cacheName))
             req.cacheType(CacheType.UTILITY);
@@ -2923,10 +2969,13 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @param topVer Current topology version.
      * @return {@code True} if minor topology version should be increased.
      */
-    public boolean onCustomEvent(
-        DiscoveryCustomMessage msg,
-        AffinityTopologyVersion topVer
-    ) {
+    public boolean onCustomEvent(DiscoveryCustomMessage msg, AffinityTopologyVersion topVer) {
+        if (msg instanceof SchemaAbstractDiscoveryMessage) {
+            ctx.query().onDiscovery((SchemaAbstractDiscoveryMessage)msg);
+
+            return false;
+        }
+
         if (msg instanceof CacheAffinityChangeMessage)
             return sharedCtx.affinity().onCustomEvent(((CacheAffinityChangeMessage)msg));
 
@@ -2964,8 +3013,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 DynamicCacheDescriptor desc = registeredTemplates.get(maskNull(req.cacheName()));
 
                 if (desc == null) {
-                    DynamicCacheDescriptor templateDesc =
-                        new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), true, req.deploymentId());
+                    DynamicCacheDescriptor templateDesc = new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), true,
+                        req.deploymentId(), req.schema());
 
                     DynamicCacheDescriptor old = registeredTemplates.put(maskNull(ccfg.getName()), templateDesc);
 
@@ -3008,8 +3057,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                         assert req.cacheType() != null : req;
                         assert F.eq(ccfg.getName(), req.cacheName()) : req;
 
-                        DynamicCacheDescriptor startDesc =
-                            new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), false, req.deploymentId());
+                        DynamicCacheDescriptor startDesc = new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), false,
+                            req.deploymentId(), req.schema());
 
                         if (newTopVer == null) {
                             newTopVer = new AffinityTopologyVersion(topVer.topologyVersion(),
@@ -3605,6 +3654,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         req.template(true);
 
         req.startCacheConfiguration(cfg);
+        req.schema(new QuerySchema(cfg.getQueryEntities()));
 
         req.deploymentId(IgniteUuid.randomUuid());
 
@@ -3769,16 +3819,28 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      *
      * @throws IgniteCheckedException In case of error.
      */
-    public void createMissingCaches() throws IgniteCheckedException {
+    public void createMissingQueryCaches() throws IgniteCheckedException {
         for (Map.Entry<String, DynamicCacheDescriptor> e : registeredCaches.entrySet()) {
-            CacheConfiguration ccfg = e.getValue().cacheConfiguration();
+            DynamicCacheDescriptor desc = e.getValue();
 
-            if (!caches.containsKey(maskNull(ccfg.getName())) && QueryUtils.isEnabled(ccfg))
-                dynamicStartCache(null, ccfg.getName(), null, false, true, true).get();
+            if (isMissingQueryCache(desc))
+                dynamicStartCache(null, desc.cacheConfiguration().getName(), null, false, true, true).get();
         }
     }
 
     /**
+     * Whether cache defined by provided descriptor is not yet started and has queries enabled.
+     *
+     * @param desc Descriptor.
+     * @return {@code True} if this is missing query cache.
+     */
+    private boolean isMissingQueryCache(DynamicCacheDescriptor desc) {
+        CacheConfiguration ccfg = desc.cacheConfiguration();
+
+        return !caches.containsKey(maskNull(ccfg.getName())) && QueryUtils.isEnabled(ccfg);
+    }
+
+    /**
      * Registers MBean for cache components.
      *
      * @param obj Cache component.
@@ -4008,6 +4070,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
                     req.deploymentId(desc.deploymentId());
                     req.startCacheConfiguration(descCfg);
+                    req.schema(desc.schema());
                 }
             }
             else {
@@ -4020,6 +4083,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 initialize(cfg, cacheObjCtx);
 
                 req.startCacheConfiguration(cfg);
+                req.schema(new QuerySchema(cfg.getQueryEntities()));
             }
         }
         else {
@@ -4039,6 +4103,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             req.deploymentId(desc.deploymentId());
             req.startCacheConfiguration(ccfg);
+            req.schema(desc.schema());
         }
 
         if (nearCfg != null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
index ad9eeb1..34bb321 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
@@ -293,6 +293,8 @@ public class GridCacheSharedContext<K, V> {
                 mgr.start(this);
         }
 
+        kernalCtx.query().onCacheReconnect();
+
         for (GridCacheSharedManager<?, ?> mgr : mgrs)
             mgr.onKernalStart(true);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index f6827ab..654d306 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -2077,11 +2077,6 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
     }
 
     /** {@inheritDoc} */
-    @Override public boolean isExchange() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
     @Override public int compareTo(GridDhtPartitionsExchangeFuture fut) {
         return exchId.compareTo(fut.exchId);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index e1ed3c5..94ff0d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -2145,10 +2145,11 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
 
                         fields.put(type.name(), fieldsMap);
 
-                        Collection<GridCacheSqlIndexMetadata> indexesCol =
-                            new ArrayList<>(type.indexes().size());
+                        Map<String, GridQueryIndexDescriptor> idxs = type.indexes();
 
-                        for (Map.Entry<String, GridQueryIndexDescriptor> e : type.indexes().entrySet()) {
+                        Collection<GridCacheSqlIndexMetadata> indexesCol = new ArrayList<>(idxs.size());
+
+                        for (Map.Entry<String, GridQueryIndexDescriptor> e : idxs.entrySet()) {
                             GridQueryIndexDescriptor desc = e.getValue();
 
                             // Add only SQL indexes.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/IgniteQueryErrorCode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/IgniteQueryErrorCode.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/IgniteQueryErrorCode.java
index 93b8d47..d05c9fd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/IgniteQueryErrorCode.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/IgniteQueryErrorCode.java
@@ -33,7 +33,7 @@ public final class IgniteQueryErrorCode {
     /** General parsing error - for the cases when there's no more specific code available. */
     public final static int PARSING = 1001;
 
-    /** Code encountered unexpected type of SQL operation - like {@code EXPLAIN MERGE}. */
+    /** Requested operation is not supported. */
     public final static int UNSUPPORTED_OPERATION = 1002;
 
     /* 2xxx - analysis errors */
@@ -58,9 +58,24 @@ public final class IgniteQueryErrorCode {
     /** Statement type does not match that declared by JDBC driver. */
     public final static int STMT_TYPE_MISMATCH = 3003;
 
-    /** Statement type does not match that declared by JDBC driver. */
+    /** DROP TABLE failed. */
     public final static int TABLE_DROP_FAILED = 3004;
 
+    /** Index already exists. */
+    public final static int INDEX_ALREADY_EXISTS = 3005;
+
+    /** Index does not exist. */
+    public final static int INDEX_NOT_FOUND = 3006;
+
+    /** Required table already exists. */
+    public final static int TABLE_ALREADY_EXISTS = 3007;
+
+    /** Required column not found. */
+    public final static int COLUMN_NOT_FOUND = 3008;
+
+    /** Required column already exists. */
+    public final static int COLUMN_ALREADY_EXISTS = 3009;
+
     /* 4xxx - cache related runtime errors */
 
     /** Attempt to INSERT a key that is already in cache. */
@@ -78,6 +93,14 @@ public final class IgniteQueryErrorCode {
     /** {@link EntryProcessor} has thrown an exception during {@link IgniteCache#invokeAll}. */
     public final static int ENTRY_PROCESSING = 4005;
 
+    /** Cache not found. */
+    public final static int CACHE_NOT_FOUND = 4006;
+
+    /** */
+    private IgniteQueryErrorCode() {
+        // No-op.
+    }
+
     /**
      * Create a {@link SQLException} for given code and message with null state.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
index f6c8b2e..37bbb54 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
@@ -137,6 +137,11 @@ public class PoolProcessor extends GridProcessorAdapter {
 
                 return ctx.getQueryExecutorService();
 
+            case GridIoPolicy.SCHEMA_POOL:
+                assert ctx.getSchemaExecutorService() != null : "Query pool is not configured.";
+
+                return ctx.getSchemaExecutorService();
+
             default: {
                 if (plc < 0)
                     throw new IgniteCheckedException("Policy cannot be negative: " + plc);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
index 7f64dd7..69130fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
@@ -29,6 +29,11 @@ import java.util.Collection;
  */
 public interface GridQueryIndexDescriptor {
     /**
+     * @return Name.
+     */
+    public String name();
+
+    /**
      * Gets all fields to be indexed.
      *
      * @return Fields to be indexed.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index d49ea57..7746ba5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -24,6 +24,7 @@ import java.util.List;
 import javax.cache.Cache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
@@ -36,6 +37,7 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
 import org.apache.ignite.internal.util.lang.GridCloseableIterator;
 import org.apache.ignite.lang.IgniteBiTuple;
@@ -128,13 +130,38 @@ public interface GridQueryIndexing {
      *
      * @param spaceName Space name.
      * @param qry Text query.
-     * @param type Query return type.
+     * @param typeName Type name.
      * @param filter Space name and key filter.
      * @return Queried rows.
      * @throws IgniteCheckedException If failed.
      */
     public <K, V> GridCloseableIterator<IgniteBiTuple<K, V>> queryLocalText(@Nullable String spaceName, String qry,
-        GridQueryTypeDescriptor type, IndexingQueryFilter filter) throws IgniteCheckedException;
+        String typeName, IndexingQueryFilter filter) throws IgniteCheckedException;
+
+    /**
+     * Create new index locally.
+     *
+     * @param spaceName Space name.
+     * @param tblName Table name.
+     * @param idxDesc Index descriptor.
+     * @param ifNotExists Ignore operation if index exists (instead of throwing an error).
+     * @param cacheVisitor Cache visitor
+     * @throws IgniteCheckedException if failed.
+     */
+    public void dynamicIndexCreate(@Nullable String spaceName, String tblName, QueryIndexDescriptorImpl idxDesc,
+        boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor) throws IgniteCheckedException;
+
+    /**
+     * Remove index from the space.
+     *
+     * @param spaceName Space name.
+     * @param idxName Index name.
+     * @param ifExists Ignore operation if index does not exist (instead of throwing an error).
+     * @throws IgniteCheckedException If failed.
+     */
+    @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
+    public void dynamicIndexDrop(@Nullable String spaceName, String idxName, boolean ifExists)
+        throws IgniteCheckedException;
 
     /**
      * Registers cache.
@@ -169,17 +196,17 @@ public interface GridQueryIndexing {
      * Unregisters type and removes all corresponding data.
      *
      * @param spaceName Space name.
-     * @param type Type descriptor.
+     * @param typeName Type name.
      * @throws IgniteCheckedException If failed.
      */
-    public void unregisterType(@Nullable String spaceName, GridQueryTypeDescriptor type) throws IgniteCheckedException;
+    public void unregisterType(@Nullable String spaceName, String typeName) throws IgniteCheckedException;
 
     /**
      * Updates index. Note that key is unique for space, so if space contains multiple indexes
      * the key should be removed from indexes other than one being updated.
      *
      * @param spaceName Space name.
-     * @param type Value type.
+     * @param typeName Type name.
      * @param key Key.
      * @param val Value.
      * @param ver Version.
@@ -187,7 +214,7 @@ public interface GridQueryIndexing {
      * @throws IgniteCheckedException If failed.
      */
     public void store(@Nullable String spaceName,
-        GridQueryTypeDescriptor type,
+        String typeName,
         KeyCacheObject key,
         int partId,
         CacheObject val,
@@ -266,11 +293,11 @@ public interface GridQueryIndexing {
     /**
      * Prepare native statement to retrieve JDBC metadata from.
      *
-     * @param schema Schema.
+     * @param space Schema.
      * @param sql Query.
      * @return {@link PreparedStatement} from underlying engine to supply metadata to Prepared - most likely H2.
      */
-    public PreparedStatement prepareNativeStatement(String schema, String sql) throws SQLException;
+    public PreparedStatement prepareNativeStatement(String space, String sql) throws SQLException;
 
     /**
      * Gets space name from database schema.


[45/50] [abbrv] ignite git commit: IGNITE-4925 Fix IgniteCacheBinaryObjectsScanSelfTest.testScanNoClasses - Fixes #1750.

Posted by sb...@apache.org.
IGNITE-4925 Fix IgniteCacheBinaryObjectsScanSelfTest.testScanNoClasses - Fixes #1750.


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

Branch: refs/heads/ignite-1561
Commit: b47f29d83f25037c5bf3cfe489b7120a238c7120
Parents: 800b8bd
Author: Evgenii Zhuravlev <ez...@gridgain.com>
Authored: Wed Apr 19 14:01:21 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Apr 19 14:01:21 2017 +0300

----------------------------------------------------------------------
 .../cache/IgniteCacheBinaryObjectsScanSelfTest.java      | 11 +++++++++--
 .../cache/IgniteCacheEntryListenerAbstractTest.java      |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b47f29d8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java
index 666505b..e0da1f6 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java
@@ -17,10 +17,12 @@
 
 package org.apache.ignite.internal.processors.cache;
 
+import java.util.ArrayList;
 import java.util.List;
 import javax.cache.Cache;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
@@ -127,9 +129,14 @@ public class IgniteCacheBinaryObjectsScanSelfTest extends GridCommonAbstractTest
             assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName());
         }
 
-        entries = cache.query(new ScanQuery<>(1023)).getAll();
+        entries = new ArrayList<>();
 
-        assertFalse(entries.isEmpty());
+        int partCnt = client.affinity("testCache").partitions();
+
+        for (int i = 0; i < partCnt; i++)
+            entries.addAll(cache.query(new ScanQuery<>(i)).getAll());
+
+        assertEquals(100, entries.size());
 
         for (Cache.Entry<Object, Object> entry : entries) {
             assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName());

http://git-wip-us.apache.org/repos/asf/ignite/blob/b47f29d8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
index e0e2771..ef2f156 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
@@ -329,7 +329,7 @@ public abstract class IgniteCacheEntryListenerAbstractTest extends IgniteCacheAb
                 if (!eagerTtl()) {
                     U.sleep(1100);
 
-                    assertNull(primaryCache(key, cache.getName()).get(key(key)));
+                    assertNull(primaryCache(key(key), cache.getName()).get(key(key)));
 
                     evtsLatch.await(5000, MILLISECONDS);
 


[20/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/RandomMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/RandomMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/RandomMatrix.java
deleted file mode 100644
index 2c3dcb2..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/RandomMatrix.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.storage.matrix.RandomMatrixStorage;
-import org.apache.ignite.math.impls.vector.RandomVector;
-
-/**
- * Implementation of {@link Matrix} with random values in the elements.
- */
-public class RandomMatrix extends AbstractMatrix {
-    /** Whether fast hash is used, see {@link RandomMatrixStorage}. */
-    private boolean fastHash;
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param fastHash Whether fast hash is used.
-     */
-    private MatrixStorage mkStorage(int rows, int cols, boolean fastHash) {
-        this.fastHash = fastHash;
-
-        return new RandomMatrixStorage(rows, cols, fastHash);
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param fastHash Whether fast hash is used.
-     */
-    public RandomMatrix(int rows, int cols, boolean fastHash) {
-        setStorage(mkStorage(rows, cols, fastHash));
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     */
-    public RandomMatrix(int rows, int cols) {
-        this(rows, cols, true);
-    }
-
-    /** */
-    public RandomMatrix() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        return new RandomMatrix(rowSize(), columnSize(), fastHash);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        return new RandomMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        return new RandomVector(crd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        super.writeExternal(out);
-
-        out.writeBoolean(fastHash);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        super.readExternal(in);
-
-        fastHash = in.readBoolean();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrix.java
deleted file mode 100644
index 5c40d70..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrix.java
+++ /dev/null
@@ -1,155 +0,0 @@
-// @java.file.header
-
-/*  _________        _____ __________________        _____
- *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
- *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
- *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
- *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
- */
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.impls.CacheUtils;
-import org.apache.ignite.math.impls.storage.matrix.SparseDistributedMatrixStorage;
-
-/**
- * Sparse distributed matrix implementation based on data grid.
- *
- * Unlike {@link CacheMatrix} that is based on existing cache, this implementation creates distributed
- * cache internally and doesn't rely on pre-existing cache.
- *
- * You also need to call {@link #destroy()} to remove the underlying cache when you no longer need this
- * matrix.
- *
- * <b>Currently fold supports only commutative operations.<b/>
- */
-public class SparseDistributedMatrix extends AbstractMatrix implements StorageConstants {
-    /**
-     *
-     */
-    public SparseDistributedMatrix() {
-        // No-op.
-    }
-
-    /**
-     * @param rows
-     * @param cols
-     * @param stoMode
-     * @param acsMode
-     */
-    public SparseDistributedMatrix(int rows, int cols, int stoMode, int acsMode) {
-        assert rows > 0;
-        assert cols > 0;
-        assertAccessMode(acsMode);
-        assertStorageMode(stoMode);
-
-        setStorage(new SparseDistributedMatrixStorage(rows, cols, stoMode, acsMode));
-    }
-
-    /**
-     *
-     *
-     */
-    private SparseDistributedMatrixStorage storage() {
-        return (SparseDistributedMatrixStorage)getStorage();
-    }
-
-    /**
-     * Return the same matrix with updates values (broken contract).
-     *
-     * @param d
-     */
-    @Override public Matrix divide(double d) {
-        return mapOverValues((Double v) -> v / d);
-    }
-
-    /**
-     * Return the same matrix with updates values (broken contract).
-     *
-     * @param x
-     */
-    @Override public Matrix plus(double x) {
-        return mapOverValues((Double v) -> v + x);
-    }
-
-    /**
-     * Return the same matrix with updates values (broken contract).
-     *
-     * @param x
-     */
-    @Override public Matrix times(double x) {
-        return mapOverValues((Double v) -> v * x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix assign(double val) {
-        return mapOverValues((Double v) -> val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix map(IgniteDoubleFunction<Double> fun) {
-        return mapOverValues(fun::apply);
-    }
-
-    /**
-     * @param mapper
-     */
-    private Matrix mapOverValues(IgniteFunction<Double, Double> mapper) {
-        CacheUtils.sparseMap(storage().cache().getName(), mapper);
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double sum() {
-        return CacheUtils.sparseSum(storage().cache().getName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double maxValue() {
-        return CacheUtils.sparseMax(storage().cache().getName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double minValue() {
-        return CacheUtils.sparseMin(storage().cache().getName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrix.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrix.java
deleted file mode 100644
index cb08939..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrix.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.storage.matrix.SparseLocalOnHeapMatrixStorage;
-import org.apache.ignite.math.impls.vector.SparseLocalVector;
-
-/**
- * Sparse local onheap matrix with {@link SparseLocalVector} as rows.
- */
-public class SparseLocalOnHeapMatrix extends AbstractMatrix implements StorageConstants {
-    /**
-     *
-     */
-    public SparseLocalOnHeapMatrix() {
-        // No-op.
-    }
-
-    /**
-     * Construct new {@link SparseLocalOnHeapMatrix}.
-     *
-     * By default storage sets in row optimized mode and in random access mode.
-     */
-    public SparseLocalOnHeapMatrix(int rows, int cols) {
-        setStorage(mkStorage(rows, cols));
-    }
-
-    /**
-     * Create new {@link SparseLocalOnHeapMatrixStorage}.
-     */
-    private MatrixStorage mkStorage(int rows, int cols) {
-        return new SparseLocalOnHeapMatrixStorage(rows, cols, StorageConstants.RANDOM_ACCESS_MODE, StorageConstants.ROW_STORAGE_MODE);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        return new SparseLocalOnHeapMatrix(rows, cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        return new SparseLocalVector(crd, StorageConstants.RANDOM_ACCESS_MODE);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        Matrix cp = like(rowSize(), columnSize());
-
-        cp.assign(this);
-
-        return cp;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/TransposedMatrixView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/TransposedMatrixView.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/TransposedMatrixView.java
deleted file mode 100644
index 9da909b..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/TransposedMatrixView.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.matrix;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.impls.storage.matrix.MatrixDelegateStorage;
-
-/**
- * Implements transposed view of the parent {@link Matrix}.
- */
-public class TransposedMatrixView extends AbstractMatrix {
-    /** */
-    public TransposedMatrixView() {
-        //No-op.
-    }
-
-    /**
-     * @param mtx Parent matrix.
-     */
-    public TransposedMatrixView(Matrix mtx) {
-        this(mtx == null ? null : mtx.getStorage());
-    }
-
-    /** */
-    private TransposedMatrixView(MatrixStorage sto) {
-        super(new MatrixDelegateStorage(sto, 0, 0,
-            sto == null ? 0 : sto.rowSize(), sto == null ? 0 : sto.columnSize()));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void storageSet(int row, int col, double v) {
-        super.storageSet(col, row, v);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected double storageGet(int row, int col) {
-        return super.storageGet(col, row);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return getStorage().columnSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return getStorage().rowSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix copy() {
-        MatrixDelegateStorage sto = (MatrixDelegateStorage)getStorage();
-
-        return new TransposedMatrixView(sto.delegate());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Matrix like(int rows, int cols) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Vector likeVector(int crd) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/package-info.java
deleted file mode 100644
index 75d7532..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/matrix/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains several matrix implementations.
- */
-package org.apache.ignite.math.impls.matrix;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/package-info.java
deleted file mode 100644
index f1b2e36..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains specific implementations for core algebra.
- */
-package org.apache.ignite.math.impls;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/ArrayMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/ArrayMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/ArrayMatrixStorage.java
deleted file mode 100644
index eb65b1d..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/ArrayMatrixStorage.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import org.apache.ignite.math.MatrixStorage;
-
-/**
- * Array based {@link MatrixStorage} implementation.
- */
-public class ArrayMatrixStorage implements MatrixStorage {
-    /** Backing data array. */
-    private double[][] data;
-    /** Amount of rows in the matrix. */
-    private int rows;
-    /** Amount of columns in the matrix. */
-    private int cols;
-
-    /**
-     *
-     */
-    public ArrayMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     */
-    public ArrayMatrixStorage(int rows, int cols) {
-        assert rows > 0;
-        assert cols > 0;
-
-        this.data = new double[rows][cols];
-        this.rows = rows;
-        this.cols = cols;
-    }
-
-    /**
-     * @param data Backing data array.
-     */
-    public ArrayMatrixStorage(double[][] data) {
-        assert data != null;
-        assert data[0] != null;
-
-        this.data = data;
-        this.rows = data.length;
-        this.cols = data[0].length;
-
-        assert rows > 0;
-        assert cols > 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return data[x][y];
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        data[x][y] = v;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[][] data() {
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(rows);
-        out.writeInt(cols);
-
-        out.writeObject(data);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        rows = in.readInt();
-        cols = in.readInt();
-
-        data = (double[][])in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res += res * 37 + rows;
-        res += res * 37 + cols;
-        res += res * 37 + Arrays.deepHashCode(data);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        ArrayMatrixStorage that = (ArrayMatrixStorage)o;
-
-        return Arrays.deepEquals(data, that.data);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/CacheMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/CacheMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/CacheMatrixStorage.java
deleted file mode 100644
index 7aefa2c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/CacheMatrixStorage.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.math.MatrixKeyMapper;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.ValueMapper;
-
-/**
- * Matrix storage based on arbitrary cache and key and value mapping functions.
- */
-public class CacheMatrixStorage<K, V> implements MatrixStorage {
-    /** */ private int rows;
-    /** */  private int cols;
-    /** */ private IgniteCache<K, V> cache;
-    /** */ private MatrixKeyMapper<K> keyMapper;
-    /** */ private ValueMapper<V> valMapper;
-
-    /**
-     *
-     */
-    public CacheMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param rows
-     * @param cols
-     * @param cache
-     * @param keyMapper
-     * @param valMapper
-     */
-    public CacheMatrixStorage(int rows, int cols, IgniteCache<K, V> cache, MatrixKeyMapper<K> keyMapper,
-        ValueMapper<V> valMapper) {
-        assert rows > 0;
-        assert cols > 0;
-        assert cache != null;
-        assert keyMapper != null;
-        assert valMapper != null;
-
-        this.rows = rows;
-        this.cols = cols;
-        this.cache = cache;
-        this.keyMapper = keyMapper;
-        this.valMapper = valMapper;
-    }
-
-    /**
-     * @return Ignite cache.
-     */
-    public IgniteCache<K, V> cache() {
-        return cache;
-    }
-
-    /**
-     * @return Key mapper.
-     */
-    public MatrixKeyMapper<K> keyMapper() {
-        return keyMapper;
-    }
-
-    /**
-     * @return Value mapper.
-     */
-    public ValueMapper<V> valueMapper() {
-        return valMapper;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return valMapper.toDouble(cache.get(keyMapper.apply(x, y)));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        cache.put(keyMapper.apply(x, y), valMapper.fromDouble(v));
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(rows);
-        out.writeInt(cols);
-        out.writeUTF(cache.getName());
-        out.writeObject(keyMapper);
-        out.writeObject(valMapper);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked"})
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        rows = in.readInt();
-        cols = in.readInt();
-        cache = Ignition.localIgnite().getOrCreateCache(in.readUTF());
-        keyMapper = (MatrixKeyMapper<K>)in.readObject();
-        valMapper = (ValueMapper<V>)in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + rows;
-        res = res * 37 + cols;
-        res = res * 37 + cache.hashCode();
-        res = res * 37 + keyMapper.hashCode();
-        res = res * 37 + valMapper.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        CacheMatrixStorage that = (CacheMatrixStorage)o;
-
-        return (cache != null ? cache.equals(that.cache) : that.cache == null) &&
-            (keyMapper != null ? keyMapper.equals(that.keyMapper) : that.keyMapper == null) &&
-            (valMapper != null ? valMapper.equals(that.valMapper) : that.valMapper == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java
deleted file mode 100644
index 6695bc2..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DenseOffHeapMatrixStorage.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.math.MatrixStorage;
-
-/**
- * Local, dense off-heap matrix storage.
- */
-public class DenseOffHeapMatrixStorage implements MatrixStorage {
-    /** */ private int rows;
-    /** */ private int cols;
-    /** */ private transient long ptr;
-    //TODO: temp solution.
-    /** */ private int ptrInitHash;
-
-    /** */
-    public DenseOffHeapMatrixStorage() {
-        // No-op.
-    }
-
-    /** */
-    public DenseOffHeapMatrixStorage(int rows, int cols) {
-        assert rows > 0;
-        assert cols > 0;
-
-        this.rows = rows;
-        this.cols = cols;
-
-        allocateMemory(rows, cols);
-    }
-
-    /** */
-    public DenseOffHeapMatrixStorage(double[][] data) {
-        assert data != null;
-        assert data[0] != null;
-
-        this.rows = data.length;
-        this.cols = data[0].length;
-
-        assert rows > 0;
-        assert cols > 0;
-
-        allocateMemory(rows, cols);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                set(i, j, data[i][j]);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return GridUnsafe.getDouble(pointerOffset(x, y));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        GridUnsafe.putDouble(pointerOffset(x, y), v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[][] data() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(rows);
-        out.writeInt(cols);
-        out.writeInt(ptrInitHash);
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                out.writeDouble(get(i, j));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        rows = in.readInt();
-        cols = in.readInt();
-
-        allocateMemory(rows, cols);
-
-        ptrInitHash = in.readInt();
-
-        for (int i = 0; i < rows; i++)
-            for (int j = 0; j < cols; j++)
-                set(i, j, in.readDouble());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() {
-        GridUnsafe.freeMemory(ptr);
-    }
-
-    /** {@inheritDoc} */
-    private long pointerOffset(int x, int y) {
-        return ptr + x * cols * Double.BYTES + y * Double.BYTES;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        return obj != null &&
-            getClass().equals(obj.getClass()) &&
-            (rows == ((DenseOffHeapMatrixStorage)obj).rows) &&
-            (cols == ((DenseOffHeapMatrixStorage)obj).cols) &&
-            (rows == 0 || cols == 0 || ptr == ((DenseOffHeapMatrixStorage)obj).ptr || isMemoryEquals((DenseOffHeapMatrixStorage)obj));
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + rows;
-        res = res * 37 + cols;
-        res = res * 37 + ptrInitHash;
-
-        return res;
-    }
-
-    /** */
-    private boolean isMemoryEquals(DenseOffHeapMatrixStorage otherStorage) {
-        boolean res = true;
-
-        for (int i = 0; i < otherStorage.rows; i++) {
-            for (int j = 0; j < otherStorage.cols; j++) {
-                if (Double.compare(get(i, j), otherStorage.get(i, j)) != 0) {
-                    res = false;
-                    break;
-                }
-            }
-        }
-
-        return res;
-    }
-
-    /** */
-    private void allocateMemory(int rows, int cols) {
-        ptr = GridUnsafe.allocateMemory(rows * cols * Double.BYTES);
-
-        ptrInitHash = Long.hashCode(ptr);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DiagonalMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DiagonalMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DiagonalMatrixStorage.java
deleted file mode 100644
index 099db38..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/DiagonalMatrixStorage.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * {@link MatrixStorage} implementation for diagonal Matrix view.
- */
-public class DiagonalMatrixStorage implements MatrixStorage {
-    /** Backing vector for matrix diagonal. */
-    private Vector diagonal;
-
-    /**
-     *
-     */
-    public DiagonalMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param diagonal Backing {@link Vector} for matrix diagonal.
-     */
-    public DiagonalMatrixStorage(Vector diagonal) {
-        assert diagonal != null;
-
-        this.diagonal = diagonal;
-    }
-
-    /**
-     *
-     */
-    public Vector diagonal() {
-        return diagonal;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return x == y ? diagonal.get(x) : 0.0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        if (x == y)
-            diagonal.set(x, v);
-        else
-            throw new UnsupportedOperationException("Can't set off-diagonal element.");
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return diagonal.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return diagonal.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(diagonal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        diagonal = (Vector)in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return diagonal.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return diagonal.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return diagonal.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return diagonal.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + diagonal.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        DiagonalMatrixStorage that = (DiagonalMatrixStorage)o;
-
-        return diagonal.equals(that.diagonal);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/FunctionMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/FunctionMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/FunctionMatrixStorage.java
deleted file mode 100644
index 6b0c6b4..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/FunctionMatrixStorage.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IntIntDoubleToVoidFunction;
-import org.apache.ignite.math.functions.IntIntToDoubleFunction;
-
-/**
- * Read-only or read-write function-based matrix storage.
- */
-public class FunctionMatrixStorage implements MatrixStorage {
-    /** */ private int rows;
-    /** */ private int cols;
-
-    /** */ private IntIntToDoubleFunction getFunc;
-    /** */ private IntIntDoubleToVoidFunction setFunc;
-
-    /**
-     *
-     */
-    public FunctionMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param getFunc Function that returns value corresponding to given row and column index.
-     * @param setFunc Set function. If {@code null} - this will be a read-only matrix.
-     */
-    public FunctionMatrixStorage(int rows, int cols, IntIntToDoubleFunction getFunc,
-        IntIntDoubleToVoidFunction setFunc) {
-        assert rows > 0;
-        assert cols > 0;
-        assert getFunc != null;
-
-        this.rows = rows;
-        this.cols = cols;
-        this.getFunc = getFunc;
-        this.setFunc = setFunc;
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param getFunc Function that returns value corresponding to given row and column index.
-     */
-    public FunctionMatrixStorage(int rows, int cols, IntIntToDoubleFunction getFunc) {
-        this(rows, cols, getFunc, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return getFunc.apply(x, y);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        if (setFunc != null)
-            setFunc.apply(x, y, v);
-        else
-            throw new UnsupportedOperationException("Cannot set into read-only matrix.");
-    }
-
-    /**
-     *
-     */
-    public IntIntToDoubleFunction getFunction() {
-        return getFunc;
-    }
-
-    /**
-     *
-     */
-    public IntIntDoubleToVoidFunction setFunction() {
-        return setFunc;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(setFunc);
-        out.writeObject(getFunc);
-        out.writeInt(rows);
-        out.writeInt(cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        setFunc = (IntIntDoubleToVoidFunction)in.readObject();
-        getFunc = (IntIntToDoubleFunction)in.readObject();
-        rows = in.readInt();
-        cols = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        FunctionMatrixStorage that = (FunctionMatrixStorage)o;
-
-        return rows == that.rows && cols == that.cols
-            && (getFunc != null ? getFunc.equals(that.getFunc) : that.getFunc == null)
-            && (setFunc != null ? setFunc.equals(that.setFunc) : that.setFunc == null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = rows;
-
-        res = 31 * res + cols;
-        res = 31 * res + (getFunc != null ? getFunc.hashCode() : 0);
-        res = 31 * res + (setFunc != null ? setFunc.hashCode() : 0);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/MatrixDelegateStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/MatrixDelegateStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/MatrixDelegateStorage.java
deleted file mode 100644
index 2e1fc12..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/MatrixDelegateStorage.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.math.MatrixStorage;
-
-/**
- * {@link MatrixStorage} implementation that delegates to parent matrix.
- */
-public class MatrixDelegateStorage implements MatrixStorage {
-    /** Parent matrix storage. */
-    private MatrixStorage sto;
-
-    /** Row offset in the parent matrix. */
-    private int rowOff;
-    /** Column offset in the parent matrix. */
-    private int colOff;
-
-    /** Amount of rows in the matrix. */
-    private int rows;
-    /** Amount of columns in the matrix. */
-    private int cols;
-
-    /**
-     *
-     */
-    public MatrixDelegateStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param sto Backing parent storage.
-     * @param rowOff Row offset to parent matrix.
-     * @param colOff Column offset to parent matrix.
-     * @param rows Amount of rows in the view.
-     * @param cols Amount of columns in the view.
-     */
-    public MatrixDelegateStorage(MatrixStorage sto, int rowOff, int colOff, int rows, int cols) {
-        assert sto != null;
-        assert rowOff >= 0;
-        assert colOff >= 0;
-        assert rows > 0;
-        assert cols > 0;
-
-        this.sto = sto;
-
-        this.rowOff = rowOff;
-        this.colOff = colOff;
-
-        this.rows = rows;
-        this.cols = cols;
-    }
-
-    /**
-     *
-     */
-    public MatrixStorage delegate() {
-        return sto;
-    }
-
-    /**
-     *
-     */
-    public int rowOffset() {
-        return rowOff;
-    }
-
-    /**
-     *
-     */
-    public int columnOffset() {
-        return colOff;
-    }
-
-    /**
-     *
-     */
-    public int rowsLength() {
-        return rows;
-    }
-
-    /**
-     *
-     */
-    public int columnsLength() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return sto.get(rowOff + x, colOff + y);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        sto.set(rowOff + x, colOff + y, v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return sto.isArrayBased() && rowOff == 0 && colOff == 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return sto.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return sto.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return sto.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return sto.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[][] data() {
-        return sto.data();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sto);
-
-        out.writeInt(rowOff);
-        out.writeInt(colOff);
-
-        out.writeInt(rows);
-        out.writeInt(cols);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sto = (MatrixStorage)in.readObject();
-
-        rowOff = in.readInt();
-        colOff = in.readInt();
-
-        rows = in.readInt();
-        cols = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + rows;
-        res = res * 37 + cols;
-        res = res * 37 + rowOff;
-        res = res * 37 + colOff;
-        res = res * 37 + sto.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        MatrixDelegateStorage that = (MatrixDelegateStorage)o;
-
-        return rows == that.rows && cols == that.cols && rowOff == that.rowOff && colOff == that.colOff &&
-            (sto != null ? sto.equals(that.sto) : that.sto == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/PivotedMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/PivotedMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/PivotedMatrixStorage.java
deleted file mode 100644
index 32c8624..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/PivotedMatrixStorage.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import org.apache.ignite.math.MatrixStorage;
-
-/**
- * Pivoted (index mapped) view over another matrix storage implementation.
- */
-public class PivotedMatrixStorage implements MatrixStorage {
-    /** Matrix storage. */
-    private MatrixStorage sto;
-
-    /** */
-    private int[] rowPivot;
-    /** */
-    private int[] colPivot;
-    /** */
-    private int[] rowUnpivot;
-    /** */
-    private int[] colUnpivot;
-
-    /**
-     *
-     */
-    public PivotedMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param sto Matrix storage.
-     * @param rowPivot Pivot array for rows.
-     * @param colPivot Pivot array for columns.
-     */
-    public PivotedMatrixStorage(MatrixStorage sto, int[] rowPivot, int[] colPivot) {
-        assert sto != null;
-        assert rowPivot != null;
-        assert colPivot != null;
-
-        this.sto = sto;
-        this.rowPivot = rowPivot;
-        this.colPivot = colPivot;
-
-        rowUnpivot = invert(rowPivot);
-        colUnpivot = invert(colPivot);
-    }
-
-    /**
-     *
-     */
-    public int[] rowPivot() {
-        return rowPivot;
-    }
-
-    /**
-     *
-     */
-    public int[] columnPivot() {
-        return colPivot;
-    }
-
-    /**
-     *
-     */
-    public int[] rowUnpivot() {
-        return rowUnpivot;
-    }
-
-    /**
-     *
-     */
-    public int[] columnUnpivot() {
-        return colUnpivot;
-    }
-
-    /**
-     * @param sto Matrix storage.
-     * @param pivot Pivot array.
-     */
-    public PivotedMatrixStorage(MatrixStorage sto, int[] pivot) {
-        this(sto, pivot, pivot == null ? null : java.util.Arrays.copyOf(pivot, pivot.length));
-    }
-
-    /**
-     * @param sto Matrix storage.
-     */
-    public PivotedMatrixStorage(MatrixStorage sto) {
-        this(sto, sto == null ? null : identityPivot(sto.rowSize()), sto == null ? null : identityPivot(sto.columnSize()));
-    }
-
-    /**
-     * @param i First row index to swap.
-     * @param j Second row index to swap.
-     */
-    public void swapRows(int i, int j) {
-        if (i != j) {
-            int tmp = rowPivot[i];
-
-            rowPivot[i] = rowPivot[j];
-            rowPivot[j] = tmp;
-
-            rowUnpivot[rowPivot[i]] = i;
-            rowUnpivot[rowPivot[j]] = j;
-        }
-    }
-
-    /**
-     * @param i First column index to swap.
-     * @param j Second column index to swap.
-     */
-    public void swapColumns(int i, int j) {
-        if (i != j) {
-            int tmp = colPivot[i];
-
-            colPivot[i] = colPivot[j];
-            colPivot[j] = tmp;
-
-            colUnpivot[colPivot[i]] = i;
-            colUnpivot[colPivot[j]] = j;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        return sto.get(rowPivot[x], colPivot[y]);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        sto.set(rowPivot[x], colPivot[y], v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return sto.columnSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return sto.rowSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sto);
-        out.writeObject(rowPivot);
-        out.writeObject(colPivot);
-        out.writeObject(rowUnpivot);
-        out.writeObject(colUnpivot);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sto = (MatrixStorage)in.readObject();
-        rowPivot = (int[])in.readObject();
-        colPivot = (int[])in.readObject();
-        rowUnpivot = (int[])in.readObject();
-        colUnpivot = (int[])in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return sto.isSequentialAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return sto.isDense();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return sto.isRandomAccess();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return sto.isDistributed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + sto.hashCode();
-        res = res * 37 + Arrays.hashCode(rowPivot);
-        res = res * 37 + Arrays.hashCode(rowUnpivot);
-        res = res * 37 + Arrays.hashCode(colPivot);
-        res = res * 37 + Arrays.hashCode(colUnpivot);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-
-        if (obj == null || getClass() != obj.getClass())
-            return false;
-
-        PivotedMatrixStorage that = (PivotedMatrixStorage)obj;
-
-        return Arrays.equals(rowPivot, that.rowPivot) && Arrays.equals(rowUnpivot, that.rowUnpivot)
-            && Arrays.equals(colPivot, that.colPivot) && Arrays.equals(colUnpivot, that.colUnpivot)
-            && (sto != null ? sto.equals(that.sto) : that.sto == null);
-    }
-
-    /**
-     * @param n Pivot array length.
-     */
-    private static int[] identityPivot(int n) {
-        int[] pivot = new int[n];
-
-        for (int i = 0; i < n; i++)
-            pivot[i] = i;
-
-        return pivot;
-    }
-
-    /**
-     * @param pivot Pivot array to be inverted.
-     */
-    private static int[] invert(int[] pivot) {
-        int[] x = new int[pivot.length];
-
-        for (int i = 0; i < pivot.length; i++)
-            x[pivot[i]] = i;
-
-        return x;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/RandomMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/RandomMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/RandomMatrixStorage.java
deleted file mode 100644
index 8283201..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/RandomMatrixStorage.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.nio.ByteBuffer;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.MurmurHash;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-
-/**
- * {@link MatrixStorage} implementation with random values in the matrix elements.
- */
-public class RandomMatrixStorage implements MatrixStorage {
-    /** */
-    private static final int PRIME1 = 104047;
-    /** */
-    private static final int PRIME2 = 101377;
-    /** */
-    private static final int PRIME3 = 64661;
-    /** */
-    private static final long SCALE = 1L << 32;
-
-    /** Random generation seed. */
-    private int seed;
-
-    /** Amount of rows in the matrix. */
-    private int rows;
-    /** Amount of columns in the matrix. */
-    private int cols;
-
-    /** Whether fast hash is used, in {@link #get(int, int)}. */
-    private boolean fastHash;
-
-    /**
-     * For externalization.
-     */
-    public RandomMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param fastHash Whether fast hash is used.
-     */
-    public RandomMatrixStorage(int rows, int cols, boolean fastHash) {
-        assert rows > 0;
-        assert cols > 0;
-
-        this.rows = rows;
-        this.cols = cols;
-        this.fastHash = fastHash;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        if (!fastHash) {
-            ByteBuffer buf = ByteBuffer.allocate(8);
-
-            buf.putInt(x);
-            buf.putInt(y);
-            buf.flip();
-
-            return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / (double)SCALE;
-        }
-        else
-            // This isn't a fantastic random number generator, but it is just fine for random projections.
-            return ((((x * PRIME1) + y * PRIME2 + x * y * PRIME3) & 8) * 0.25) - 1;
-    }
-
-    /**
-     *
-     */
-    public boolean isFastHash() {
-        return fastHash;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        throw new UnsupportedOperationException("Random matrix storage is a read-only storage.");
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(rows);
-        out.writeInt(cols);
-        out.writeInt(seed);
-        out.writeBoolean(fastHash);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        rows = in.readInt();
-        cols = in.readInt();
-        seed = in.readInt();
-        fastHash = in.readBoolean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + Boolean.hashCode(fastHash);
-        res = res * 37 + seed;
-        res = res * 37 + cols;
-        res = res * 37 + rows;
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        RandomMatrixStorage that = (RandomMatrixStorage)o;
-
-        return rows == that.rows && cols == that.cols && seed == that.seed && fastHash == that.fastHash;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
deleted file mode 100644
index 82807c5..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorage.java
+++ /dev/null
@@ -1,281 +0,0 @@
-// @java.file.header
-
-/*  _________        _____ __________________        _____
- *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
- *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
- *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
- *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
- */
-
-package org.apache.ignite.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 org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheAtomicityMode;
-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.lang.IgniteUuid;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.StorageConstants;
-import org.apache.ignite.math.impls.CacheUtils;
-
-/**
- * {@link MatrixStorage} implementation for {@link org.apache.ignite.math.impls.matrix.SparseDistributedMatrix}.
- */
-public class SparseDistributedMatrixStorage extends CacheUtils implements MatrixStorage, StorageConstants {
-    /** 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;
-
-    /** Actual distributed storage. */
-    private IgniteCache<
-        Integer /* Row or column index. */,
-        Map<Integer, Double> /* Map-based row or column. */
-        > cache = null;
-
-    /**
-     *
-     */
-    public SparseDistributedMatrixStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param rows Amount of rows in the matrix.
-     * @param cols Amount of columns in the matrix.
-     * @param stoMode Row or column based storage mode.
-     * @param acsMode Random or sequential access mode.
-     */
-    public SparseDistributedMatrixStorage(int rows, int cols, int stoMode, int acsMode) {
-        assert rows > 0;
-        assert cols > 0;
-        assertAccessMode(acsMode);
-        assertStorageMode(stoMode);
-
-        this.rows = rows;
-        this.cols = cols;
-        this.stoMode = stoMode;
-        this.acsMode = acsMode;
-
-        cache = newCache();
-    }
-
-    /**
-     *
-     *
-     */
-    private IgniteCache<Integer, Map<Integer, Double>> newCache() {
-        CacheConfiguration<Integer, Map<Integer, Double>> cfg = new CacheConfiguration<>();
-
-        // Assume 10% density.
-        cfg.setStartSize(Math.max(1024, (rows * cols) / 10));
-
-        // Write to primary.
-        cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
-
-        // Atomic transactions only.
-        cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
-
-        // No eviction.
-        cfg.setEvictionPolicy(null);
-
-        // No copying of values.
-        cfg.setCopyOnRead(false);
-
-        // Cache is partitioned.
-        cfg.setCacheMode(CacheMode.PARTITIONED);
-
-        // Random cache name.
-        cfg.setName(new IgniteUuid().shortString());
-
-        return Ignition.localIgnite().getOrCreateCache(cfg);
-    }
-
-    /**
-     *
-     *
-     */
-    public IgniteCache<Integer, Map<Integer, Double>> cache() {
-        return cache;
-    }
-
-    /**
-     *
-     *
-     */
-    public int accessMode() {
-        return acsMode;
-    }
-
-    /**
-     *
-     *
-     */
-    public int storageMode() {
-        return stoMode;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        if (stoMode == ROW_STORAGE_MODE)
-            return matrixGet(cache.getName(), x, y);
-        else
-            return matrixGet(cache.getName(), y, x);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        if (stoMode == ROW_STORAGE_MODE)
-            matrixSet(cache.getName(), x, y, v);
-        else
-            matrixSet(cache.getName(), y, x, v);
-    }
-
-    /**
-     * Distributed matrix get.
-     *
-     * @param cacheName Matrix's cache.
-     * @param a Row or column index.
-     * @param b Row or column index.
-     * @return Matrix value at (a, b) index.
-     */
-    private double matrixGet(String cacheName, int a, int b) {
-        // Remote get from the primary node (where given row or column is stored locally).
-        return ignite().compute(groupForKey(cacheName, a)).call(() -> {
-            IgniteCache<Integer, Map<Integer, Double>> cache = Ignition.localIgnite().getOrCreateCache(cacheName);
-
-            // Local get.
-            Map<Integer, Double> map = cache.localPeek(a, CachePeekMode.PRIMARY);
-
-            return (map == null || !map.containsKey(b)) ? 0.0 : map.get(b);
-        });
-    }
-
-    /**
-     * Distributed matrix set.
-     *
-     * @param cacheName Matrix's cache.
-     * @param a Row or column index.
-     * @param b Row or column index.
-     * @param v New value to set.
-     */
-    private void matrixSet(String cacheName, int a, int b, double v) {
-        // Remote set on the primary node (where given row or column is stored locally).
-        ignite().compute(groupForKey(cacheName, a)).run(() -> {
-            IgniteCache<Integer, Map<Integer, Double>> cache = Ignition.localIgnite().getOrCreateCache(cacheName);
-
-            // Local get.
-            Map<Integer, Double> map = cache.localPeek(a, CachePeekMode.PRIMARY);
-
-            if (map == null)
-                map = acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap();
-
-            if (v != 0.0)
-                map.put(b, v);
-            else if (map.containsKey(b))
-                map.remove(b);
-
-            // Local put.
-            cache.put(a, map);
-        });
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(rows);
-        out.writeInt(cols);
-        out.writeInt(acsMode);
-        out.writeInt(stoMode);
-        out.writeUTF(cache.getName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        rows = in.readInt();
-        cols = in.readInt();
-        acsMode = in.readInt();
-        stoMode = in.readInt();
-        cache = ignite().getOrCreateCache(in.readUTF());
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return acsMode == SEQUENTIAL_ACCESS_MODE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return acsMode == RANDOM_ACCESS_MODE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** Destroy underlying cache. */
-    @Override public void destroy() {
-        cache.destroy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + cols;
-        res = res * 37 + rows;
-        res = res * 37 + acsMode;
-        res = res * 37 + stoMode;
-        res = res * 37 + cache.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-
-        if (obj == null || getClass() != obj.getClass())
-            return false;
-
-        SparseDistributedMatrixStorage that = (SparseDistributedMatrixStorage)obj;
-
-        return rows == that.rows && cols == that.cols && acsMode == that.acsMode && stoMode == that.stoMode
-            && (cache != null ? cache.equals(that.cache) : that.cache == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
deleted file mode 100644
index e72da70..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/SparseLocalOnHeapMatrixStorage.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.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.HashMap;
-import java.util.Map;
-import org.apache.ignite.math.MatrixStorage;
-import org.apache.ignite.math.StorageConstants;
-
-/**
- * Storage for sparse, local, on-heap matrix.
- */
-public class SparseLocalOnHeapMatrixStorage implements MatrixStorage, StorageConstants {
-    /** Default zero value. */
-    private static final double DEFAULT_VALUE = 0.0;
-
-    /** */ private int rows;
-    /** */ private int cols;
-
-    /** */ private int acsMode;
-    /** */ private int stoMode;
-
-    /** Actual map storage. */
-    private Map<Integer, Map<Integer, Double>> sto;
-
-    /** */
-    public SparseLocalOnHeapMatrixStorage() {
-        // No-op.
-    }
-
-    /** */
-    public SparseLocalOnHeapMatrixStorage(int rows, int cols, int acsMode, int stoMode) {
-        assert rows > 0;
-        assert cols > 0;
-        assertAccessMode(acsMode);
-        assertStorageMode(stoMode);
-
-        this.rows = rows;
-        this.cols = cols;
-        this.acsMode = acsMode;
-        this.stoMode = stoMode;
-
-        sto = new HashMap<>();
-    }
-
-    /**
-     *
-     *
-     */
-    public int getStorageMode() {
-        return stoMode;
-    }
-
-    /**
-     *
-     *
-     */
-    public int getAccessMode() {
-        return acsMode;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int x, int y) {
-        if (stoMode == ROW_STORAGE_MODE) {
-            Map<Integer, Double> row = sto.get(x);
-
-            if (row != null) {
-                Double val = row.get(y);
-
-                if (val != null)
-                    return val;
-            }
-
-            return DEFAULT_VALUE;
-        }
-        else {
-            Map<Integer, Double> col = sto.get(y);
-
-            if (col != null) {
-                Double val = col.get(x);
-
-                if (val != null)
-                    return val;
-            }
-
-            return DEFAULT_VALUE;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int x, int y, double v) {
-        // Ignore default values (currently 0.0).
-        if (v != DEFAULT_VALUE) {
-            if (stoMode == ROW_STORAGE_MODE) {
-                Map<Integer, Double> row = sto.computeIfAbsent(x, k ->
-                    acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap());
-
-                row.put(y, v);
-            }
-            else {
-                Map<Integer, Double> col = sto.computeIfAbsent(y, k ->
-                    acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap());
-
-                col.put(x, v);
-            }
-        }
-        else {
-            if (stoMode == ROW_STORAGE_MODE) {
-                if (sto.containsKey(x)) {
-                    Map<Integer, Double> row = sto.get(x);
-
-                    if (row.containsKey(y))
-                        row.remove(y);
-                }
-
-            }
-            else {
-                if (sto.containsKey(y)) {
-                    Map<Integer, Double> col = sto.get(y);
-
-                    if (col.containsKey(x))
-                        col.remove(x);
-                }
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public int columnSize() {
-        return cols;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int rowSize() {
-        return rows;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(rows);
-        out.writeInt(cols);
-        out.writeInt(acsMode);
-        out.writeInt(stoMode);
-        out.writeObject(sto);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked"})
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        rows = in.readInt();
-        cols = in.readInt();
-        acsMode = in.readInt();
-        stoMode = in.readInt();
-        sto = (Map<Integer, Map<Integer, Double>>)in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return acsMode == SEQUENTIAL_ACCESS_MODE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return acsMode == RANDOM_ACCESS_MODE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isArrayBased() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + rows;
-        res = res * 37 + cols;
-        res = res * 37 + sto.hashCode();
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        SparseLocalOnHeapMatrixStorage that = (SparseLocalOnHeapMatrixStorage)o;
-
-        return rows == that.rows && cols == that.cols && acsMode == that.acsMode && stoMode == that.stoMode
-            && (sto != null ? sto.equals(that.sto) : that.sto == null);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/package-info.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/package-info.java
deleted file mode 100644
index aba47db..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/matrix/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains specific implementations for matrix storage models.
- */
-package org.apache.ignite.math.impls.storage.matrix;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ArrayVectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ArrayVectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ArrayVectorStorage.java
deleted file mode 100644
index ef59c62..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/impls/storage/vector/ArrayVectorStorage.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.impls.storage.vector;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * Array based {@link VectorStorage} implementation.
- */
-public class ArrayVectorStorage implements VectorStorage {
-    /** Backing data array. */
-    private double[] data;
-
-    /**
-     * IMPL NOTE required by {@link Externalizable}.
-     */
-    public ArrayVectorStorage() {
-        // No-op.
-    }
-
-    /**
-     * @param size Vector size.
-     */
-    public ArrayVectorStorage(int size) {
-        assert size > 0;
-
-        data = new double[size];
-    }
-
-    /**
-     * @param data Backing data array.
-     */
-    public ArrayVectorStorage(double[] data) {
-        assert data != null;
-
-        this.data = data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return data == null ? 0 : data.length;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double get(int i) {
-        return data[i];
-    }
-
-    /** {@inheritDoc} */
-    @Override public void set(int i, double v) {
-        data[i] = v;
-    }
-
-    /** {@inheritDoc}} */
-    @Override public boolean isArrayBased() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[] data() {
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isSequentialAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDense() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isRandomAccess() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isDistributed() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(data);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        data = (double[])in.readObject();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = 1;
-
-        res = res * 37 + Arrays.hashCode(data);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-
-        if (obj == null || getClass() != obj.getClass())
-            return false;
-
-        ArrayVectorStorage that = (ArrayVectorStorage)obj;
-
-        return Arrays.equals(data, (that.data));
-    }
-}


[23/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/Matrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/Matrix.java b/modules/ml/src/main/java/org/apache/ignite/math/Matrix.java
deleted file mode 100644
index ee7a807..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/Matrix.java
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.io.Externalizable;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-import org.apache.ignite.math.functions.IgniteFunction;
-import org.apache.ignite.math.functions.IntIntToDoubleFunction;
-
-/**
- * A matrix interface.
- *
- * Based on its flavor it can have vastly different implementations tailored for
- * for different types of data (e.g. dense vs. sparse), different sizes of data or different operation
- * optimizations.
- *
- * Note also that not all operations can be supported by all underlying implementations. If an operation is not
- * supported a {@link UnsupportedOperationException} is thrown. This exception can also be thrown in partial cases
- * where an operation is unsupported only in special cases, e.g. where a given operation cannot be deterministically
- * completed in polynomial time.
- *
- * Based on ideas from <a href="http://mahout.apache.org/">Apache Mahout</a>.
- */
-public interface Matrix extends MetaAttributes, Externalizable, StorageOpsMetrics, Destroyable {
-    /**
-     * Holder for matrix's element.
-     */
-    interface Element {
-        /**
-         * Gets element's value.
-         *
-         * @return The value of this matrix element.
-         */
-        double get();
-
-        /**
-         * Gets element's row index.
-         *
-         * @return The row index of this element.
-         */
-        int row();
-
-        /**
-         * Gets element's column index.
-         *
-         * @return The column index of this element.
-         */
-        int column();
-
-        /**
-         * Sets element's value.
-         *
-         * @param val Value to set.
-         */
-        void set(double val);
-    }
-
-    /**
-     * Gets the maximum value in this matrix.
-     *
-     * @return Maximum value in this matrix.
-     */
-    public double maxValue();
-
-    /**
-     * Gets the minimum value in this matrix.
-     *
-     * @return Minimum value in this matrix.
-     */
-    public double minValue();
-
-    /**
-     * Gets the maximum element in this matrix.
-     *
-     * @return Maximum element in this matrix.
-     */
-    public Element maxElement();
-
-    /**
-     * Gets the minimum element in this matrix.
-     *
-     * @return Minimum element in this matrix.
-     */
-    public Element minElement();
-
-    /**
-     * Gets the matrix's element at the given coordinates.
-     *
-     * @param row Row index.
-     * @param col Column index.
-     * @return Element at the given coordinates.
-     */
-    public Element getElement(int row, int col);
-
-    /**
-     * Swaps two rows in this matrix.
-     *
-     * @param row1 Row #1.
-     * @param row2 Row #2.
-     * @return This matrix.
-     */
-    public Matrix swapRows(int row1, int row2);
-
-    /**
-     * Swaps two columns in this matrix.
-     *
-     * @param col1 Column #1.
-     * @param col2 Column #2.
-     * @return This matrix.
-     */
-    public Matrix swapColumns(int col1, int col2);
-
-    /**
-     * Assigns given value to all elements of this matrix.
-     *
-     * @param val Value to assign to all elements.
-     * @return This matrix.
-     */
-    public Matrix assign(double val);
-
-    /**
-     * Assigns given values to this matrix.
-     *
-     * @param vals Values to assign.
-     * @return This matrix.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix assign(double[][] vals);
-
-    /**
-     * Assigns values from given matrix to this matrix.
-     *
-     * @param mtx Matrix to assign to this matrix.
-     * @return This matrix.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix assign(Matrix mtx);
-
-    /**
-     * Assigns each matrix element to the value generated by given function.
-     *
-     * @param fun Function that takes the row and column and returns the value to assign.
-     * @return This matrix.
-     */
-    public Matrix assign(IntIntToDoubleFunction fun);
-
-    /**
-     * Maps all values in this matrix through a given function.
-     *
-     * @param fun Mapping function.
-     * @return This matrix.
-     */
-    public Matrix map(IgniteDoubleFunction<Double> fun);
-
-    /**
-     * Maps all values in this matrix through a given function.
-     *
-     * For this matrix <code>A</code>, argument matrix <code>B</code> and the
-     * function <code>F</code> this method maps every cell <code>x, y</code> as:
-     * <code>A(x,y) = fun(A(x,y), B(x,y))</code>
-     *
-     * @param mtx Argument matrix.
-     * @param fun Mapping function.
-     * @return This function.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix map(Matrix mtx, IgniteBiFunction<Double, Double, Double> fun);
-
-    /**
-     * Assigns values from given vector to the specified column in this matrix.
-     *
-     * @param col Column index.
-     * @param vec Vector to get values from.
-     * @return This matrix.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix assignColumn(int col, Vector vec);
-
-    /**
-     * Assigns values from given vector to the specified row in this matrix.
-     *
-     * @param row Row index.
-     * @param vec Vector to get values from.
-     * @return This matrix.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix assignRow(int row, Vector vec);
-
-    /**
-     * Collects the results of applying a given function to all rows in this matrix.
-     *
-     * @param fun Aggregating function.
-     * @return Vector of row aggregates.
-     */
-    public Vector foldRows(IgniteFunction<Vector, Double> fun);
-
-    /**
-     * Collects the results of applying a given function to all columns in this matrix.
-     *
-     * @param fun Aggregating function.
-     * @return Vector of column aggregates.
-     */
-    public Vector foldColumns(IgniteFunction<Vector, Double> fun);
-
-    /**
-     * Folds this matrix into a single value.
-     *
-     * @param foldFun Folding function that takes two parameters: accumulator and the current value.
-     * @param mapFun Mapping function that is called on each matrix cell before its passed to the accumulator (as its
-     * second parameter).
-     * @param <T> Type of the folded value.
-     * @param zeroVal Zero value for fold function.
-     * @return Folded value of this matrix.
-     */
-    public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal);
-
-    /**
-     * Calculates the density of the matrix based on supplied criteria.
-     * Returns {@code true} if this matrix is denser than threshold with at least 80% confidence.
-     *
-     * @param threshold the threshold value [0, 1] of non-zero elements above which the matrix is considered dense.
-     */
-    public boolean density(double threshold);
-
-    /**
-     * Gets number of columns in this matrix.
-     *
-     * @return The number of columns in this matrix.
-     */
-    public int columnSize();
-
-    /**
-     * Gets number of rows in this matrix.
-     *
-     * @return The number of rows in this matrix.
-     */
-    public int rowSize();
-
-    /**
-     * Returns matrix determinant using Laplace theorem.
-     *
-     * @return A determinant for this matrix.
-     * @throws CardinalityException Thrown if matrix is not square.
-     */
-    public double determinant();
-
-    /**
-     * Returns the inverse matrix of this matrix
-     *
-     * @return Inverse of this matrix
-     */
-    public Matrix inverse();
-
-    /**
-     * Divides each value in this matrix by the argument.
-     *
-     * @param x Divider value.
-     * @return This matrix.
-     */
-    public Matrix divide(double x);
-
-    /**
-     * Gets the matrix value at the provided location.
-     *
-     * @param row Row index.
-     * @param col Column index.
-     * @return Matrix value.
-     * @throws IndexException Thrown in case of index is out of bound.
-     */
-    public double get(int row, int col);
-
-    /**
-     * Gets the matrix value at the provided location without checking boundaries.
-     * This method is marginally quicker than its {@link #get(int, int)} sibling.
-     *
-     * @param row Row index.
-     * @param col Column index.
-     * @return Matrix value.
-     */
-    public double getX(int row, int col);
-
-    /**
-     * Gets matrix storage model.
-     */
-    public MatrixStorage getStorage();
-
-    /**
-     * Clones this matrix.
-     *
-     * NOTE: new matrix will have the same flavor as the this matrix but a different ID.
-     *
-     * @return New matrix of the same underlying class, the same size and the same values.
-     */
-    public Matrix copy();
-
-    /**
-     * Creates new empty matrix of the same underlying class but of different size.
-     *
-     * NOTE: new matrix will have the same flavor as the this matrix but a different ID.
-     *
-     * @param rows Number of rows for new matrix.
-     * @param cols Number of columns for new matrix.
-     * @return New matrix of the same underlying class and size.
-     */
-    public Matrix like(int rows, int cols);
-
-    /**
-     * Creates new empty vector of compatible properties (similar or the same flavor) to this matrix.
-     *
-     * @param crd Cardinality of the vector.
-     * @return Newly created empty vector "compatible" to this matrix.
-     */
-    public Vector likeVector(int crd);
-
-    /**
-     * Creates new matrix where each value is a difference between corresponding value of this matrix and
-     * passed in argument matrix.
-     *
-     * @param mtx Argument matrix.
-     * @return New matrix of the same underlying class and size.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix minus(Matrix mtx);
-
-    /**
-     * Creates new matrix where each value is a sum of the corresponding value of this matrix and
-     * argument value.
-     *
-     * @param x Value to add.
-     * @return New matrix of the same underlying class and size.
-     */
-    public Matrix plus(double x);
-
-    /**
-     * Creates new matrix where each value is a sum of corresponding values of this matrix and
-     * passed in argument matrix.
-     *
-     * @param mtx Argument matrix.
-     * @return New matrix of the same underlying class and size.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix plus(Matrix mtx);
-
-    /**
-     * Auto-generated globally unique matrix ID.
-     *
-     * @return Matrix GUID.
-     */
-    public IgniteUuid guid();
-
-    /**
-     * Sets given value.
-     *
-     * @param row Row index.
-     * @param col Column index.
-     * @param val Value to set.
-     * @return This matrix.
-     * @throws IndexException Thrown in case of either index is out of bound.
-     */
-    public Matrix set(int row, int col, double val);
-
-    /**
-     * Sets values for given row.
-     *
-     * @param row Row index.
-     * @param data Row data to set.
-     * @return This matrix.
-     * @throws IndexException Thrown in case of index is out of bound.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix setRow(int row, double[] data);
-
-    /**
-     * Sets values for given column.
-     *
-     * @param col Column index.
-     * @param data Column data to set.
-     * @return This matrix.
-     * @throws IndexException Thrown in case of index is out of bound.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix setColumn(int col, double[] data);
-
-    /**
-     * Sets given value without checking for index bounds. This method is marginally faster
-     * than its {@link #set(int, int, double)} sibling.
-     *
-     * @param row Row index.
-     * @param col Column index.
-     * @param val Value to set.
-     * @return This matrix.
-     */
-    public Matrix setX(int row, int col, double val);
-
-    /**
-     * Creates new matrix containing the product of given value and values in this matrix.
-     *
-     * @param x Value to multiply.
-     * @return New matrix.
-     */
-    public Matrix times(double x);
-
-    /**
-     * Creates new matrix that is the product of multiplying this matrix and the argument matrix.
-     *
-     * @param mtx Argument matrix.
-     * @return New matrix.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Matrix times(Matrix mtx);
-
-    /**
-     * Creates new matrix that is the product of multiplying this matrix and the argument vector.
-     *
-     * @param vec Argument vector.
-     * @return New matrix.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector times(Vector vec);
-
-    /**
-     * Gets maximum absolute row sum norm of this matrix.
-     * See http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html
-     *
-     * @return Maximum absolute row sum norm of this matrix.
-     */
-    public double maxAbsRowSumNorm();
-
-    /**
-     * Gets sum of all elements in the matrix.
-     *
-     * @return Sum of all elements in this matrix.
-     */
-    public double sum();
-
-    /**
-     * Creates new matrix that is transpose of this matrix.
-     *
-     * @return New transposed matrix.
-     */
-    public Matrix transpose();
-
-    /**
-     * Creates new view into this matrix. Changes to the view will be propagated to this matrix.
-     *
-     * @param off View offset as <code>int[x,y]</code>.
-     * @param size View size as <code>int[rows, cols]</code>
-     * @return New view.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     * @throws IndexException Thrown in case of offset is out of bound.
-     */
-    public Matrix viewPart(int[] off, int[] size);
-
-    /**
-     * Creates new view into this matrix. Changes to the view will be propagated to this matrix.
-     *
-     * @param rowOff
-     * @param rows
-     * @param colOff
-     * @param cols
-     * @return New view.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     * @throws IndexException Thrown in case of offset is out of bound.
-     */
-    public Matrix viewPart(int rowOff, int rows, int colOff, int cols);
-
-    /**
-     * Creates new view into matrix row. Changes to the view will be propagated to this matrix.
-     *
-     * @param row Row index.
-     * @return New view.
-     * @throws IndexException Thrown in case of index is out of bound.
-     */
-    public Vector viewRow(int row);
-
-    /**
-     * Creates new view into matrix column . Changes to the view will be propagated to this matrix.
-     *
-     * @param col Column index.
-     * @return New view.
-     * @throws IndexException Thrown in case of index is out of bound.
-     */
-    public Vector viewColumn(int col);
-
-    /**
-     * Creates new view into matrix diagonal. Changes to the view will be propagated to this matrix.
-     *
-     * @return New view.
-     */
-    public Vector viewDiagonal();
-
-    /**
-     * Destroys matrix if managed outside of JVM. It's a no-op in all other cases.
-     */
-    public default void destroy() {
-        // No-op.
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/MatrixKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/MatrixKeyMapper.java b/modules/ml/src/main/java/org/apache/ignite/math/MatrixKeyMapper.java
deleted file mode 100644
index d6ae06f..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/MatrixKeyMapper.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-/**
- * Maps {@link Matrix} row and column index to cache key.
- */
-public interface MatrixKeyMapper<K> extends KeyMapper<K> {
-    /**
-     * @param x Matrix row index.
-     * @param y Matrix column index.
-     * @return Cache key for given row and column.
-     */
-    public K apply(int x, int y);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/MatrixStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/MatrixStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/MatrixStorage.java
deleted file mode 100644
index 11eced7..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/MatrixStorage.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.io.Externalizable;
-
-/**
- * Data storage support for {@link Matrix}.
- */
-public interface MatrixStorage extends Externalizable, StorageOpsMetrics, Destroyable {
-    /**
-     * @param x Matrix row index.
-     * @param y Matrix column index.
-     * @return Value corresponding to given row and column.
-     */
-    public double get(int x, int y);
-
-    /**
-     * @param x Matrix row index.
-     * @param y Matrix column index.
-     * @param v Value to set at given row and column.
-     */
-    public void set(int x, int y, double v);
-
-    /**
-     *
-     */
-    public int columnSize();
-
-    /**
-     *
-     */
-    public int rowSize();
-
-    /**
-     * Gets underlying array if {@link StorageOpsMetrics#isArrayBased()} returns {@code true}.
-     *
-     * @see StorageOpsMetrics#isArrayBased()
-     */
-    default public double[][] data() {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/MetaAttributes.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/MetaAttributes.java b/modules/ml/src/main/java/org/apache/ignite/math/MetaAttributes.java
deleted file mode 100644
index 8973b55..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/MetaAttributes.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.util.Map;
-
-/**
- * Interface provides support for meta attributes on vectors and matrices.
- */
-public interface MetaAttributes {
-    /**
-     * Implementation should return an instance of the map to store meta attributes.
-     */
-    public Map<String, Object> getMetaStorage();
-
-    /**
-     * Gets meta attribute with given name.
-     *
-     * @param name Name of the vector meta attribute to get.
-     * @param <T> Attribute's type.
-     */
-    @SuppressWarnings("unchecked")
-    public default <T> T getAttribute(String name) {
-        return (T)getMetaStorage().get(name);
-    }
-
-    /**
-     * Sets meta attribute with given name and value.
-     *
-     * @param name Name of the meta attribute.
-     * @param val Attribute value.
-     * @param <T> Attribute's type.
-     */
-    public default <T> void setAttribute(String name, T val) {
-        getMetaStorage().put(name, val);
-    }
-
-    /**
-     * Removes meta attribute with given name.
-     *
-     * @param name Name of the meta attribute.
-     * @return {@code true} if attribute was present and was removed, {@code false} otherwise.
-     */
-    public default boolean removeAttribute(String name) {
-        boolean is = getMetaStorage().containsKey(name);
-
-        if (is)
-            getMetaStorage().remove(name);
-
-        return is;
-    }
-
-    /**
-     * Checks if given meta attribute is present.
-     *
-     * @param name Attribute name to check.
-     */
-    public default boolean hasAttribute(String name) {
-        return getMetaStorage().containsKey(name);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/MurmurHash.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/MurmurHash.java b/modules/ml/src/main/java/org/apache/ignite/math/MurmurHash.java
deleted file mode 100644
index 3d1252e..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/MurmurHash.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * This is a very fast, non-cryptographic hash suitable for general hash-based lookup.
- *
- * See http://murmurhash.googlepages.com/ for mre details.
- */
-public class MurmurHash {
-    /** Hide it. */
-    private MurmurHash() {
-    }
-
-    /**
-     * This produces exactly the same hash values as the final C+ version of MurmurHash3 and is
-     * thus suitable for producing the same hash values across platforms.
-     *
-     * The 32 bit x86 version of this hash should be the fastest variant for relatively short keys like IDs.
-     *
-     * Note - The x86 and x64 versions do _not_ produce the same results, as the algorithms are
-     * optimized for their respective platforms.
-     *
-     * See also http://github.com/yonik/java_util for future updates to this method.
-     *
-     * @param data
-     * @param off
-     * @param len
-     * @param seed
-     * @return 32 bit hash platform compatible with C++ MurmurHash3 implementation on x86.
-     */
-    public static int hash3X86(byte[] data, int off, int len, int seed) {
-        int c1 = 0xcc9e2d51;
-        int c2 = 0x1b873593;
-
-        int h1 = seed;
-        int roundedEnd = off + (len & 0xfffffffc);  // Round down to 4 byte block.
-
-        for (int i = off; i < roundedEnd; i += 4) {
-            int k1 = (data[i] & 0xff) | ((data[i + 1] & 0xff) << 8) | ((data[i + 2] & 0xff) << 16) | (data[i + 3] << 24);
-
-            k1 *= c1;
-            k1 = (k1 << 15) | (k1 >>> 17);
-            k1 *= c2;
-
-            h1 ^= k1;
-            h1 = (h1 << 13) | (h1 >>> 19);
-            h1 = h1 * 5 + 0xe6546b64;
-        }
-
-        // Tail.
-        int k1 = 0;
-
-        switch (len & 0x03) {
-            case 3:
-                k1 = (data[roundedEnd + 2] & 0xff) << 16;
-                // Fallthrough - WTF?
-            case 2:
-                k1 |= (data[roundedEnd + 1] & 0xff) << 8;
-                // Fallthrough - WTF?
-            case 1:
-                k1 |= data[roundedEnd] & 0xff;
-                k1 *= c1;
-                k1 = (k1 << 15) | (k1 >>> 17);
-                k1 *= c2;
-                h1 ^= k1;
-            default:
-        }
-
-        // Finalization.
-        h1 ^= len;
-
-        h1 ^= h1 >>> 16;
-        h1 *= 0x85ebca6b;
-        h1 ^= h1 >>> 13;
-        h1 *= 0xc2b2ae35;
-        h1 ^= h1 >>> 16;
-
-        return h1;
-    }
-
-    /**
-     * Hashes an int.
-     *
-     * @param data The int to hash.
-     * @param seed The seed for the hash.
-     * @return The 32 bit hash of the bytes in question.
-     */
-    public static int hash(int data, int seed) {
-        byte[] arr = new byte[] {
-            (byte)(data >>> 24),
-            (byte)(data >>> 16),
-            (byte)(data >>> 8),
-            (byte)data
-        };
-
-        return hash(ByteBuffer.wrap(arr), seed);
-    }
-
-    /**
-     * Hashes bytes in an array.
-     *
-     * @param data The bytes to hash.
-     * @param seed The seed for the hash.
-     * @return The 32 bit hash of the bytes in question.
-     */
-    public static int hash(byte[] data, int seed) {
-        return hash(ByteBuffer.wrap(data), seed);
-    }
-
-    /**
-     * Hashes bytes in part of an array.
-     *
-     * @param data The data to hash.
-     * @param off Where to start munging.
-     * @param len How many bytes to process.
-     * @param seed The seed to start with.
-     * @return The 32-bit hash of the data in question.
-     */
-    public static int hash(byte[] data, int off, int len, int seed) {
-        return hash(ByteBuffer.wrap(data, off, len), seed);
-    }
-
-    /**
-     * Hashes the bytes in a buffer from the current position to the limit.
-     *
-     * @param buf The bytes to hash.
-     * @param seed The seed for the hash.
-     * @return The 32 bit murmur hash of the bytes in the buffer.
-     */
-    public static int hash(ByteBuffer buf, int seed) {
-        ByteOrder byteOrder = buf.order();
-        buf.order(ByteOrder.LITTLE_ENDIAN);
-
-        int m = 0x5bd1e995;
-        int r = 24;
-
-        int h = seed ^ buf.remaining();
-
-        while (buf.remaining() >= 4) {
-            int k = buf.getInt();
-
-            k *= m;
-            k ^= k >>> r;
-            k *= m;
-
-            h *= m;
-            h ^= k;
-        }
-
-        if (buf.remaining() > 0) {
-            ByteBuffer finish = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
-
-            finish.put(buf).rewind();
-
-            h ^= finish.getInt();
-            h *= m;
-        }
-
-        h ^= h >>> 13;
-        h *= m;
-        h ^= h >>> 15;
-
-        buf.order(byteOrder);
-
-        return h;
-    }
-
-    /**
-     * @param data
-     * @param seed
-     */
-    public static long hash64A(byte[] data, int seed) {
-        return hash64A(ByteBuffer.wrap(data), seed);
-    }
-
-    /**
-     * @param data
-     * @param off
-     * @param len
-     * @param seed
-     */
-    public static long hash64A(byte[] data, int off, int len, int seed) {
-        return hash64A(ByteBuffer.wrap(data, off, len), seed);
-    }
-
-    /**
-     * @param buf
-     * @param seed
-     */
-    public static long hash64A(ByteBuffer buf, int seed) {
-        ByteOrder byteOrder = buf.order();
-        buf.order(ByteOrder.LITTLE_ENDIAN);
-
-        long m = 0xc6a4a7935bd1e995L;
-        int r = 47;
-
-        long h = seed ^ (buf.remaining() * m);
-
-        while (buf.remaining() >= 8) {
-            long k = buf.getLong();
-
-            k *= m;
-            k ^= k >>> r;
-            k *= m;
-
-            h ^= k;
-            h *= m;
-        }
-
-        if (buf.remaining() > 0) {
-            ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
-
-            finish.put(buf).rewind();
-
-            h ^= finish.getLong();
-            h *= m;
-        }
-
-        h ^= h >>> r;
-        h *= m;
-        h ^= h >>> r;
-
-        buf.order(byteOrder);
-
-        return h;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/StorageConstants.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/StorageConstants.java b/modules/ml/src/main/java/org/apache/ignite/math/StorageConstants.java
deleted file mode 100644
index e8bfdf6..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/StorageConstants.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-/**
- * Support for different modes of accessing data storage.
- */
-public interface StorageConstants {
-    /** Storage mode optimized for sequential access. */
-    public static final int SEQUENTIAL_ACCESS_MODE = 1001;
-
-    /** Storage mode optimized for random access. */
-    public static final int RANDOM_ACCESS_MODE = 1002;
-
-    /** Storage mode optimized for row access. */
-    public static final int ROW_STORAGE_MODE = 2001;
-
-    /** Storage mode optimized for column access. */
-    public static final int COLUMN_STORAGE_MODE = 2002;
-
-    /**
-     * @param mode Access mode to verify.
-     */
-    public default void assertAccessMode(int mode) {
-        assert mode == SEQUENTIAL_ACCESS_MODE || mode == RANDOM_ACCESS_MODE;
-    }
-
-    /**
-     * @param mode Storage mode to verify.
-     */
-    public default void assertStorageMode(int mode) {
-        assert mode == ROW_STORAGE_MODE || mode == COLUMN_STORAGE_MODE;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/StorageOpsMetrics.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/StorageOpsMetrics.java b/modules/ml/src/main/java/org/apache/ignite/math/StorageOpsMetrics.java
deleted file mode 100644
index c3252ba..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/StorageOpsMetrics.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-/**
- * Storage and operation cost characteristics.
- */
-public interface StorageOpsMetrics {
-    /**
-     * Checks if this implementation should be considered to be iterable in index order in an efficient way.
-     */
-    public boolean isSequentialAccess();
-
-    /**
-     * Checks if this implementation is optimized for random access.
-     */
-    public boolean isRandomAccess();
-
-    /**
-     * Checks if this implementation should be considered dense so that it explicitly
-     * represents every value.
-     */
-    public boolean isDense();
-
-    /**
-     * Checks if implementation is based on Java arrays.
-     */
-    public boolean isArrayBased();
-
-    /**
-     * Checks whether implementation is JVM-local or distributed (multi-JVM).
-     */
-    public boolean isDistributed();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/Tracer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/Tracer.java b/modules/ml/src/main/java/org/apache/ignite/math/Tracer.java
deleted file mode 100644
index 89d4669..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/Tracer.java
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.awt.Color;
-import java.awt.Desktop;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.Locale;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.lang.IgniteUuid;
-
-/**
- * Utility methods to support output of {@link Vector} and {@link Matrix} instances to plain text or HTML.
- */
-public class Tracer {
-    /**
-     * Double to color mapper.
-     */
-    public interface ColorMapper extends Function<Double, Color> {
-    }
-
-    /** Continuous red-to-blue color mapping. */
-    static private ColorMapper defaultColorMapper(double min, double max) {
-        double range = max - min;
-
-        return new ColorMapper() {
-            /** {@inheritDoc} */
-            @Override public Color apply(Double d) {
-                int r = (int)Math.round(255 * d);
-                int g = 0;
-                int b = (int)Math.round(255 * (1 - d));
-
-                return new Color(r, g, b);
-            }
-        };
-    }
-
-    /**
-     * Default vector color mapper implementation that map given double value
-     * to continuous red-blue (R_B) specter.
-     *
-     * @param vec Vector to map.
-     * @return {@link ColorMapper} for the given vector.
-     */
-    static private ColorMapper mkVectorColorMapper(Vector vec) {
-        return defaultColorMapper(vec.minValue(), vec.maxValue());
-    }
-
-    /** Default matrix color mapper implementation that map given double value
-     * to continuous red-blue (R_B) specter.
-     * @param mtx Matrix to be mapped.
-     * @return Color mapper for given matrix.
-     */
-    static private ColorMapper mkMatrixColorMapper(Matrix mtx) {
-        return defaultColorMapper(mtx.minValue(), mtx.maxValue());
-    }
-
-    /**
-     * @param vec Vector to show.
-     * @param log {@link IgniteLogger} instance for output.
-     * @param fmt Format string for vector elements.
-     */
-    public static void showAscii(Vector vec, IgniteLogger log, String fmt) {
-        String cls = vec.getClass().getSimpleName();
-
-        log.info(String.format("%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
-    }
-
-    /**
-     * @param vec Vector to show as plain text.
-     * @param log {@link IgniteLogger} instance for output.
-     */
-    public static void showAscii(Vector vec, IgniteLogger log) {
-        showAscii(vec, log, "%4f");
-    }
-
-    /**
-     * @param vec Vector to show as plain text.
-     * @param fmt Format string for vector elements.
-     */
-    public static void showAscii(Vector vec, String fmt) {
-        String cls = vec.getClass().getSimpleName();
-
-        System.out.println(String.format("%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
-    }
-
-    /**
-     * @param mtx Matrix to show as plain text.
-     */
-    public static void showAscii(Matrix mtx) {
-        showAscii(mtx, "%4f");
-    }
-
-    /**
-     * @param mtx Matrix to show.
-     * @param row Matrix row to output.
-     * @param fmt Format string for matrix elements in the row.
-     * @return String representation of given matrix row according to given format.
-     */
-    static private String rowStr(Matrix mtx, int row, String fmt) {
-        StringBuilder buf = new StringBuilder();
-
-        boolean first = true;
-
-        int cols = mtx.columnSize();
-
-        for (int col = 0; col < cols; col++) {
-            String s = String.format(fmt, mtx.get(row, col));
-
-            if (!first)
-                buf.append(", ");
-
-            buf.append(s);
-
-            first = false;
-        }
-
-        return buf.toString();
-    }
-
-    /**
-     * @param mtx {@link Matrix} object to show as a plain text.
-     * @param fmt Format string for matrix rows.
-     */
-    public static void showAscii(Matrix mtx, String fmt) {
-        String cls = mtx.getClass().getSimpleName();
-
-        int rows = mtx.rowSize();
-        int cols = mtx.columnSize();
-
-        System.out.println(String.format("%s(%dx%d)", cls, rows, cols));
-
-        for (int row = 0; row < rows; row++)
-            System.out.println(rowStr(mtx, row, fmt));
-    }
-
-    /**
-     * @param mtx {@link Matrix} object to show as a plain text.
-     * @param log {@link IgniteLogger} instance to output the logged matrix.
-     * @param fmt Format string for matrix rows.
-     */
-    public static void showAscii(Matrix mtx, IgniteLogger log, String fmt) {
-        String cls = mtx.getClass().getSimpleName();
-
-        int rows = mtx.rowSize();
-        int cols = mtx.columnSize();
-
-        log.info(String.format("%s(%dx%d)", cls, rows, cols));
-
-        for (int row = 0; row < rows; row++)
-            log.info(rowStr(mtx, row, fmt));
-    }
-
-    /**
-     * @param vec {@link Vector} object to show as a plain text.
-     */
-    public static void showAscii(Vector vec) {
-        showAscii(vec, "%4f");
-    }
-
-    /**
-     * Saves given vector as CSV file.
-     *
-     * @param vec Vector to save.
-     * @param fmt Format to use.
-     * @param filePath Path of the file to save to.
-     */
-    public static void saveAsCsv(Vector vec, String fmt, String filePath) throws IOException {
-        String s = mkString(vec, fmt);
-
-        Files.write(Paths.get(filePath), s.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
-    }
-
-    /**
-     * Saves given matrix as CSV file.
-     *
-     * @param mtx Matrix to save.
-     * @param fmt Format to use.
-     * @param filePath Path of the file to save to.
-     */
-    public static void saveAsCsv(Matrix mtx, String fmt, String filePath) throws IOException {
-        String s = mkString(mtx, fmt);
-
-        Files.write(Paths.get(filePath), s.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
-    }
-
-    /**
-     * Shows given matrix in the browser with D3-based visualization.
-     *
-     * @param mtx Matrix to show.
-     * @throws IOException Thrown in case of any errors.
-     */
-    public static void showHtml(Matrix mtx) throws IOException {
-        showHtml(mtx, mkMatrixColorMapper(mtx));
-    }
-
-    /**
-     * Shows given matrix in the browser with D3-based visualization.
-     *
-     * @param mtx Matrix to show.
-     * @param cm Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
-     * @throws IOException Thrown in case of any errors.
-     */
-    public static void showHtml(Matrix mtx, ColorMapper cm) throws IOException {
-        // Read it every time so that we can change it at runtime.
-        String tmpl = fileToString("d3-matrix-template.html");
-
-        String cls = mtx.getClass().getSimpleName();
-
-        double min = mtx.minValue();
-        double max = mtx.maxValue();
-
-        openHtmlFile(tmpl.
-            replaceAll("/\\*@NAME@\\*/.*\n", "var name = \"" + cls + "\";\n").
-            replaceAll("/\\*@MIN@\\*/.*\n", "var min = " + dataColorJson(min, cm.apply(min)) + ";\n").
-            replaceAll("/\\*@MAX@\\*/.*\n", "var max = " + dataColorJson(max, cm.apply(max)) + ";\n").
-            replaceAll("/\\*@DATA@\\*/.*\n", "var data = " + mkJsArrayString(mtx, cm) + ";\n")
-        );
-    }
-
-    /**
-     * Shows given vector in the browser with D3-based visualization.
-     *
-     * @param vec Vector to show.
-     * @throws IOException Thrown in case of any errors.
-     */
-    public static void showHtml(Vector vec) throws IOException {
-        showHtml(vec, mkVectorColorMapper(vec));
-    }
-
-    /**
-     * @param d Value of {@link Matrix} or {@link Vector} element.
-     * @param clr {@link Color} to paint.
-     * @return JSON representation for given value and color.
-     */
-    static private String dataColorJson(double d, Color clr) {
-        return "{" +
-            "d: " + String.format("%4f", d) +
-            ", r: " + clr.getRed() +
-            ", g: " + clr.getGreen() +
-            ", b: " + clr.getBlue() +
-            "}";
-    }
-
-    /**
-     * Shows given vector in the browser with D3-based visualization.
-     *
-     * @param vec Vector to show.
-     * @param cm Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
-     * @throws IOException Thrown in case of any errors.
-     */
-    public static void showHtml(Vector vec, ColorMapper cm) throws IOException {
-        // Read it every time so that we can change it at runtime.
-        String tmpl = fileToString("d3-vector-template.html");
-
-        String cls = vec.getClass().getSimpleName();
-
-        double min = vec.minValue();
-        double max = vec.maxValue();
-
-        openHtmlFile(tmpl.
-            replaceAll("/\\*@NAME@\\*/.*\n", "var name = \"" + cls + "\";\n").
-            replaceAll("/\\*@MIN@\\*/.*\n", "var min = " + dataColorJson(min, cm.apply(min)) + ";\n").
-            replaceAll("/\\*@MAX@\\*/.*\n", "var max = " + dataColorJson(max, cm.apply(max)) + ";\n").
-            replaceAll("/\\*@DATA@\\*/.*\n", "var data = " + mkJsArrayString(vec, cm) + ";\n")
-        );
-    }
-
-    /**
-     * Reads file content into the string.
-     *
-     * @param fileName Name of the file (on classpath) to read.
-     * @return Content of the file.
-     * @throws IOException If an I/O error of some sort has occurred.
-     */
-    private static String fileToString(String fileName) throws IOException {
-        assert Tracer.class.getResourceAsStream(fileName) != null : "Can't get resource: " + fileName;
-
-        InputStreamReader is = new InputStreamReader(Tracer.class.getResourceAsStream(fileName));
-
-        String str = new BufferedReader(is).lines().collect(Collectors.joining("\n"));
-
-        is.close();
-
-        return str;
-    }
-
-    /**
-     * Opens file in the browser with given HTML content.
-     *
-     * @param html HTML content.
-     * @throws IOException Thrown in case of any errors.
-     */
-    static private void openHtmlFile(String html) throws IOException {
-        File temp = File.createTempFile(IgniteUuid.randomUuid().toString(), ".html");
-
-        BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
-
-        bw.write(html);
-
-        bw.close();
-
-        Desktop.getDesktop().browse(temp.toURI());
-    }
-
-    /**
-     * Gets string presentation of this vector.
-     *
-     * @param vec Vector to string-ify.
-     * @param fmt {@link String#format(Locale, String, Object...)} format.
-     */
-    private static String mkString(Vector vec, String fmt) {
-        boolean first = true;
-
-        StringBuilder buf = new StringBuilder();
-
-        for (Vector.Element x : vec.all()) {
-            String s = String.format(Locale.US, fmt, x.get());
-
-            if (!first) {
-                buf.append(", ");
-                buf.append(s);
-            }
-            else {
-                buf.append(s);
-                first = false;
-            }
-        }
-
-        return buf.toString();
-    }
-
-    /**
-     * Gets JavaScript array presentation of this vector.
-     *
-     * @param vec Vector to JavaScript-ify.
-     * @param cm Color mapper to user.
-     */
-    private static String mkJsArrayString(Vector vec, ColorMapper cm) {
-        boolean first = true;
-
-        StringBuilder buf = new StringBuilder();
-
-        for (Vector.Element x : vec.all()) {
-            double d = x.get();
-
-            String s = dataColorJson(d, cm.apply(d));
-
-            if (!first)
-                buf.append(", ");
-
-            buf.append(s);
-
-            first = false;
-        }
-
-        return '[' + buf.toString() + ']';
-    }
-
-    /**
-     * Gets JavaScript array presentation of this vector.
-     *
-     * @param mtx Matrix to JavaScript-ify.
-     * @param cm Color mapper to user.
-     */
-    private static String mkJsArrayString(Matrix mtx, ColorMapper cm) {
-        boolean first = true;
-
-        StringBuilder buf = new StringBuilder();
-
-        int rows = mtx.rowSize();
-        int cols = mtx.columnSize();
-
-        for (int row = 0; row < rows; row++) {
-            StringBuilder rowBuf = new StringBuilder();
-
-            boolean rowFirst = true;
-
-            for (int col = 0; col < cols; col++) {
-                double d = mtx.get(row, col);
-
-                String s = dataColorJson(d, cm.apply(d));
-
-                if (!rowFirst)
-                    rowBuf.append(", ");
-
-                rowBuf.append(s);
-
-                rowFirst = false;
-            }
-
-            if (!first)
-                buf.append(", ");
-
-            buf.append('[').append(rowBuf.toString()).append(']');
-
-            first = false;
-        }
-
-        return '[' + buf.toString() + ']';
-    }
-
-    /**
-     * @param mtx Matrix to log.
-     * @param fmt Output format.
-     * @return Formatted representation of a matrix.
-     */
-    private static String mkString(Matrix mtx, String fmt) {
-        StringBuilder buf = new StringBuilder();
-
-        int rows = mtx.rowSize();
-        int cols = mtx.columnSize();
-
-        for (int row = 0; row < rows; row++) {
-            for (int col = 0; col < cols; col++) {
-                String s = String.format(Locale.US, fmt, mtx.get(row, col));
-
-                if (col != 0)
-                    buf.append(", ");
-
-                buf.append(s);
-
-                if (col == cols - 1 && row != rows - 1)
-                    buf.append(",\n");
-
-            }
-        }
-
-        return buf.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/ValueMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/ValueMapper.java b/modules/ml/src/main/java/org/apache/ignite/math/ValueMapper.java
deleted file mode 100644
index 9459bd1..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/ValueMapper.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// @java.file.header
-
-/*  _________        _____ __________________        _____
- *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
- *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
- *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
- *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
- */
-
-package org.apache.ignite.math;
-
-import java.io.Serializable;
-
-/**
- * Utility mapper that can be used to map arbitrary values types to and from double.
- */
-public interface ValueMapper<V> extends Serializable {
-    /**
-     * @param v
-     */
-    public V fromDouble(double v);
-
-    /**
-     * @param v
-     */
-    public double toDouble(V v);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/Vector.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/Vector.java b/modules/ml/src/main/java/org/apache/ignite/math/Vector.java
deleted file mode 100644
index ac2a6c7..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/Vector.java
+++ /dev/null
@@ -1,498 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.io.Externalizable;
-import java.util.Spliterator;
-import java.util.function.IntToDoubleFunction;
-import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.IndexException;
-import org.apache.ignite.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.math.functions.IgniteBiFunction;
-import org.apache.ignite.math.functions.IgniteDoubleFunction;
-
-/**
- * A vector interface.
- *
- * Based on its flavor it can have vastly different implementations tailored for
- * for different types of data (e.g. dense vs. sparse), different sizes of data or different operation
- * optimizations.
- *
- * Note also that not all operations can be supported by all underlying implementations. If an operation is not
- * supported a {@link UnsupportedOperationException} is thrown. This exception can also be thrown in partial cases
- * where an operation is unsupported only in special cases, e.g. where a given operation cannot be deterministically
- * completed in polynomial time.
- *
- * Based on ideas from <a href="http://mahout.apache.org/">Apache Mahout</a>.
- */
-public interface Vector extends MetaAttributes, Externalizable, StorageOpsMetrics, Destroyable {
-    /**
-     * Holder for vector's element.
-     */
-    interface Element {
-        /**
-         * Gets element's value.
-         *
-         * @return The value of this vector element.
-         */
-        double get();
-
-        /**
-         * Gets element's index in the vector.
-         *
-         * @return The index of this vector element.
-         */
-        int index();
-
-        /**
-         * Sets element's value.
-         *
-         * @param val Value to set.
-         */
-        void set(double val);
-    }
-
-    /**
-     * Gets cardinality of this vector (maximum number of the elements).
-     *
-     * @return This vector's cardinality.
-     */
-    public int size();
-
-    /**
-     * Creates new copy of this vector.
-     *
-     * @return New copy vector.
-     */
-    public Vector copy();
-
-    /**
-     * Gets iterator over all elements in this vector.
-     *
-     * NOTE: implementation can choose to reuse {@link Element} instance so you need to copy it
-     * if you want to retain it outside of iteration.
-     *
-     * @return Iterator.
-     */
-    public Iterable<Element> all();
-
-    /**
-     * Iterates ove all non-zero elements in this vector.
-     *
-     * NOTE: implementation can choose to reuse {@link Element} instance so you need to copy it
-     * if you want to retain it outside of iteration.
-     *
-     * @return Iterator.
-     */
-    public Iterable<Element> nonZeroes();
-
-    /**
-     * Gets spliterator for all values in this vector.
-     *
-     * @return Spliterator for all values.
-     */
-    public Spliterator<Double> allSpliterator();
-
-    /**
-     * Gets spliterator for all non-zero values in this vector.
-     *
-     * @return Spliterator for all non-zero values.
-     */
-    public Spliterator<Double> nonZeroSpliterator();
-
-    /**
-     * Sorts this vector in ascending order.
-     */
-    public Vector sort();
-
-    /**
-     * Gets element at the given index.
-     *
-     * NOTE: implementation can choose to reuse {@link Element} instance so you need to copy it
-     * if you want to retain it outside of iteration.
-     *
-     * @param idx Element's index.
-     * @return Vector's element at the given index.
-     * @throws IndexException Throw if index is out of bounds.
-     */
-    public Element getElement(int idx);
-
-    /**
-     * Assigns given value to all elements of this vector.
-     *
-     * @param val Value to assign.
-     * @return This vector.
-     */
-    public Vector assign(double val);
-
-    /**
-     * Assigns values from given array to this vector.
-     *
-     * @param vals Values to assign.
-     * @return This vector.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector assign(double[] vals);
-
-    /**
-     * Copies values from the argument vector to this one.
-     *
-     * @param vec Argument vector.
-     * @return This vector.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector assign(Vector vec);
-
-    /**
-     * Assigns each vector element to the value generated by given function.
-     *
-     * @param fun Function that takes the index and returns value.
-     * @return This vector.
-     */
-    public Vector assign(IntToDoubleFunction fun);
-
-    /**
-     * Maps all values in this vector through a given function.
-     *
-     * @param fun Mapping function.
-     * @return This vector.
-     */
-    public Vector map(IgniteDoubleFunction<Double> fun);
-
-    /**
-     * Maps all values in this vector through a given function.
-     *
-     * For this vector <code>A</code>, argument vector <code>B</code> and the
-     * function <code>F</code> this method maps every element <code>x</code> as:
-     * <code>A(x) = F(A(x), B(x))</code>
-     *
-     * @param vec Argument vector.
-     * @param fun Mapping function.
-     * @return This function.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector map(Vector vec, IgniteBiFunction<Double, Double, Double> fun);
-
-    /**
-     * Maps all elements of this vector by applying given function to each element with a constant
-     * second parameter <code>y</code>.
-     *
-     * @param fun Mapping function.
-     * @param y Second parameter for mapping function.
-     * @return This vector.
-     */
-    public Vector map(IgniteBiFunction<Double, Double, Double> fun, double y);
-
-    /**
-     * Creates new vector containing values from this vector divided by the argument.
-     *
-     * @param x Division argument.
-     * @return New vector.
-     */
-    public Vector divide(double x);
-
-    /**
-     * Gets dot product of two vectors.
-     *
-     * @param vec Argument vector.
-     * @return Dot product of two vectors.
-     */
-    public double dot(Vector vec);
-
-    /**
-     * Gets the value at specified index.
-     *
-     * @param idx Vector index.
-     * @return Vector value.
-     * @throws IndexException Throw if index is out of bounds.
-     */
-    public double get(int idx);
-
-    /**
-     * Gets the value at specified index without checking for index boundaries.
-     *
-     * @param idx Vector index.
-     * @return Vector value.
-     */
-    public double getX(int idx);
-
-    /**
-     * Creates new empty vector of the same underlying class but of different cardinality.
-     *
-     * @param crd Cardinality for new vector.
-     * @return New vector.
-     */
-    public Vector like(int crd);
-
-    /**
-     * Creates new matrix of compatible flavor with given size.
-     *
-     * @param rows Number of rows.
-     * @param cols Number of columns.
-     * @return New matrix.
-     */
-    public Matrix likeMatrix(int rows, int cols);
-
-    /**
-     * Converts this vector into [N x 1] or [1 x N] matrix where N is this vector cardinality.
-     *
-     * @param rowLike {@code true} for rowLike [N x 1], or {@code false} for column [1 x N] matrix.
-     * @return Newly created matrix.
-     */
-    public Matrix toMatrix(boolean rowLike);
-
-    /**
-     * Converts this vector into [N+1 x 1] or [1 x N+1] matrix where N is this vector cardinality.
-     * (0,0) element of this matrix will be {@code zeroVal} parameter.
-     *
-     * @param rowLike {@code true} for rowLike [N+1 x 1], or {@code false} for column [1 x N+1] matrix.
-     * @return Newly created matrix.
-     */
-    public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal);
-
-    /**
-     * Creates new vector containing element by element difference between this vector and the argument one.
-     *
-     * @param vec Argument vector.
-     * @return New vector.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector minus(Vector vec);
-
-    /**
-     * Creates new vector containing the normalized (L_2 norm) values of this vector.
-     *
-     * @return New vector.
-     */
-    public Vector normalize();
-
-    /**
-     * Creates new vector containing the normalized (L_power norm) values of this vector.
-     * See http://en.wikipedia.org/wiki/Lp_space for details.
-     *
-     * @param power The power to use. Must be >= 0. May also be {@link Double#POSITIVE_INFINITY}.
-     * @return New vector {@code x} such that {@code norm(x, power) == 1}
-     */
-    public Vector normalize(double power);
-
-    /**
-     * Creates new vector containing the {@code log(1 + entry) / L_2 norm} values of this vector.
-     *
-     * @return New vector.
-     */
-    public Vector logNormalize();
-
-    /**
-     * Creates new vector with a normalized value calculated as {@code log_power(1 + entry) / L_power norm}.
-     *
-     * @param power The power to use. Must be > 1. Cannot be {@link Double#POSITIVE_INFINITY}.
-     * @return New vector
-     */
-    public Vector logNormalize(double power);
-
-    /**
-     * Gets the k-norm of the vector. See http://en.wikipedia.org/wiki/Lp_space for more details.
-     *
-     * @param power The power to use.
-     * @see #normalize(double)
-     */
-    public double kNorm(double power);
-
-    /**
-     * Gets minimal value in this vector.
-     *
-     * @return Minimal value.
-     */
-    public double minValue();
-
-    /**
-     * Gets maximum value in this vector.
-     *
-     * @return Maximum c.
-     */
-    public double maxValue();
-
-    /**
-     * Gets minimal element in this vector.
-     *
-     * @return Minimal element.
-     */
-    public Element minElement();
-
-    /**
-     * Gets maximum element in this vector.
-     *
-     * @return Maximum element.
-     */
-    public Element maxElement();
-
-    /**
-     * Creates new vector containing sum of each element in this vector and argument.
-     *
-     * @param x Argument value.
-     * @return New vector.
-     */
-    public Vector plus(double x);
-
-    /**
-     * Creates new vector containing element by element sum from both vectors.
-     *
-     * @param vec Other argument vector to add.
-     * @return New vector.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector plus(Vector vec);
-
-    /**
-     * Sets value.
-     *
-     * @param idx Vector index to set value at.
-     * @param val Value to set.
-     * @return This vector.
-     * @throws IndexException Throw if index is out of bounds.
-     */
-    public Vector set(int idx, double val);
-
-    /**
-     * Sets value without checking for index boundaries.
-     *
-     * @param idx Vector index to set value at.
-     * @param val Value to set.
-     * @return This vector.
-     */
-    public Vector setX(int idx, double val);
-
-    /**
-     * Increments value at given index without checking for index boundaries.
-     *
-     * @param idx Vector index.
-     * @param val Increment value.
-     * @return This vector.
-     */
-    public Vector incrementX(int idx, double val);
-
-    /**
-     * Increments value at given index.
-     *
-     * @param idx Vector index.
-     * @param val Increment value.
-     * @return This vector.
-     * @throws IndexException Throw if index is out of bounds.
-     */
-    public Vector increment(int idx, double val);
-
-    /**
-     * Gets number of non-zero elements in this vector.
-     *
-     * @return Number of non-zero elements in this vector.
-     */
-    public int nonZeroElements();
-
-    /**
-     * Gets a new vector that contains product of each element and the argument.
-     *
-     * @param x Multiply argument.
-     * @return New vector.
-     */
-    public Vector times(double x);
-
-    /**
-     * Gets a new vector that is an element-wie product of this vector and the argument.
-     *
-     * @param vec Vector to multiply by.
-     * @return New vector.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public Vector times(Vector vec);
-
-    /**
-     * @param off Offset into parent vector.
-     * @param len Length of the view.
-     */
-    public Vector viewPart(int off, int len);
-
-    /**
-     * Gets vector storage model.
-     */
-    public VectorStorage getStorage();
-
-    /**
-     * Gets the sum of all elements in this vector.
-     *
-     * @return Vector's sum
-     */
-    public double sum();
-
-    /**
-     * Gets the cross product of this vector and the other vector.
-     *
-     * @param vec Second vector.
-     * @return New matrix as a cross product of two vectors.
-     */
-    public Matrix cross(Vector vec);
-
-    /**
-     * Folds this vector into a single value.
-     *
-     * @param foldFun Folding function that takes two parameters: accumulator and the current value.
-     * @param mapFun Mapping function that is called on each vector element before its passed to the accumulator (as its
-     * second parameter).
-     * @param <T> Type of the folded value.
-     * @param zeroVal Zero value for fold operation.
-     * @return Folded value of this vector.
-     */
-    public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal);
-
-    /**
-     * Combines & maps two vector and folds them into a single value.
-     *
-     * @param vec Another vector to combine with.
-     * @param foldFun Folding function.
-     * @param combFun Combine function.
-     * @param <T> Type of the folded value.
-     * @param zeroVal Zero value for fold operation.
-     * @return Folded value of these vectors.
-     * @throws CardinalityException Thrown when cardinalities mismatch.
-     */
-    public <T> T foldMap(Vector vec, IgniteBiFunction<T, Double, T> foldFun, IgniteBiFunction<Double, Double, Double> combFun,
-        T zeroVal);
-
-    /**
-     * Gets the sum of squares of all elements in this vector.
-     *
-     * @return Length squared value.
-     */
-    public double getLengthSquared();
-
-    /**
-     * Get the square of the distance between this vector and the argument vector.
-     *
-     * @param vec Another vector.
-     * @return Distance squared.
-     * @throws CardinalityException Thrown if cardinalities mismatch.
-     */
-    public double getDistanceSquared(Vector vec);
-
-    /**
-     * Auto-generated globally unique vector ID.
-     *
-     * @return Vector GUID.
-     */
-    public IgniteUuid guid();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/VectorKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/VectorKeyMapper.java b/modules/ml/src/main/java/org/apache/ignite/math/VectorKeyMapper.java
deleted file mode 100644
index 17d76f5..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/VectorKeyMapper.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-/**
- * Maps {@link Vector} element index to cache key.
- */
-public interface VectorKeyMapper<K> extends KeyMapper<K> {
-    /**
-     * @param i Vector element index.
-     * @return Cache key for given element index.
-     */
-    public K apply(int i);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/VectorStorage.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/VectorStorage.java b/modules/ml/src/main/java/org/apache/ignite/math/VectorStorage.java
deleted file mode 100644
index f410254..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/VectorStorage.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math;
-
-import java.io.Externalizable;
-
-/**
- * Data storage support for {@link Vector}.
- */
-public interface VectorStorage extends Externalizable, StorageOpsMetrics, Destroyable {
-    /**
-     *
-     *
-     */
-    public int size();
-
-    /**
-     * @param i Vector element index.
-     * @return Value obtained for given element index.
-     */
-    public double get(int i);
-
-    /**
-     * @param i Vector element index.
-     * @param v Value to set at given index.
-     */
-    public void set(int i, double v);
-
-    /**
-     * Gets underlying array if {@link StorageOpsMetrics#isArrayBased()} returns {@code true}.
-     * Returns {@code null} if in other cases.
-     *
-     * @see StorageOpsMetrics#isArrayBased()
-     */
-    public default double[] data() {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/CholeskyDecomposition.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/CholeskyDecomposition.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/CholeskyDecomposition.java
deleted file mode 100644
index 9554737..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/CholeskyDecomposition.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.exceptions.CardinalityException;
-import org.apache.ignite.math.exceptions.NonPositiveDefiniteMatrixException;
-import org.apache.ignite.math.exceptions.NonSymmetricMatrixException;
-
-/**
- * Calculates the Cholesky decomposition of a matrix.
- *
- * This class inspired by class from Apache Common Math with similar name.
- *
- * @see <a href="http://mathworld.wolfram.com/CholeskyDecomposition.html">MathWorld</a>
- * @see <a href="http://en.wikipedia.org/wiki/Cholesky_decomposition">Wikipedia</a>
- */
-public class CholeskyDecomposition extends DecompositionSupport {
-    /**
-     * Default threshold above which off-diagonal elements are considered too different
-     * and matrix not symmetric.
-     */
-    public static final double DFLT_REL_SYMMETRY_THRESHOLD = 1.0e-15;
-
-    /**
-     * Default threshold below which diagonal elements are considered null
-     * and matrix not positive definite.
-     */
-    public static final double DFLT_ABS_POSITIVITY_THRESHOLD = 1.0e-10;
-
-    /** Row-oriented storage for L<sup>T</sup> matrix data. */
-    private double[][] lTData;
-    /** Cached value of L. */
-    private Matrix cachedL;
-    /** Cached value of LT. */
-    private Matrix cachedLT;
-    /** Origin matrix */
-    private Matrix origin;
-
-    /**
-     * Calculates the Cholesky decomposition of the given matrix.
-     *
-     * Calling this constructor is equivalent to call {@link #CholeskyDecomposition(Matrix, double, double)} with the
-     * thresholds set to the default values {@link #DFLT_REL_SYMMETRY_THRESHOLD} and
-     * {@link #DFLT_ABS_POSITIVITY_THRESHOLD}.
-     *
-     * @param mtx the matrix to decompose.
-     * @throws CardinalityException if matrix is not square.
-     * @see #CholeskyDecomposition(Matrix, double, double)
-     * @see #DFLT_REL_SYMMETRY_THRESHOLD
-     * @see #DFLT_ABS_POSITIVITY_THRESHOLD
-     */
-    public CholeskyDecomposition(final Matrix mtx) {
-        this(mtx, DFLT_REL_SYMMETRY_THRESHOLD, DFLT_ABS_POSITIVITY_THRESHOLD);
-    }
-
-    /**
-     * Calculates the Cholesky decomposition of the given matrix.
-     *
-     * @param mtx the matrix to decompose.
-     * @param relSymmetryThreshold threshold above which off-diagonal elements are considered too different and matrix
-     * not symmetric
-     * @param absPositivityThreshold threshold below which diagonal elements are considered null and matrix not positive
-     * definite
-     * @see #CholeskyDecomposition(Matrix)
-     * @see #DFLT_REL_SYMMETRY_THRESHOLD
-     * @see #DFLT_ABS_POSITIVITY_THRESHOLD
-     */
-    public CholeskyDecomposition(final Matrix mtx, final double relSymmetryThreshold,
-        final double absPositivityThreshold) {
-        assert mtx != null;
-
-        if (mtx.columnSize() != mtx.rowSize())
-            throw new CardinalityException(mtx.rowSize(), mtx.columnSize());
-
-        origin = mtx;
-
-        final int order = mtx.rowSize();
-
-        lTData = toDoubleArr(mtx);
-        cachedL = null;
-        cachedLT = null;
-
-        // Check the matrix before transformation.
-        for (int i = 0; i < order; ++i) {
-            final double[] lI = lTData[i];
-
-            // Check off-diagonal elements (and reset them to 0).
-            for (int j = i + 1; j < order; ++j) {
-                final double[] lJ = lTData[j];
-
-                final double lIJ = lI[j];
-                final double lJI = lJ[i];
-
-                final double maxDelta = relSymmetryThreshold * Math.max(Math.abs(lIJ), Math.abs(lJI));
-
-                if (Math.abs(lIJ - lJI) > maxDelta)
-                    throw new NonSymmetricMatrixException(i, j, relSymmetryThreshold);
-
-                lJ[i] = 0;
-            }
-        }
-
-        // Transform the matrix.
-        for (int i = 0; i < order; ++i) {
-            final double[] ltI = lTData[i];
-
-            // Check diagonal element.
-            if (ltI[i] <= absPositivityThreshold)
-                throw new NonPositiveDefiniteMatrixException(ltI[i], i, absPositivityThreshold);
-
-            ltI[i] = Math.sqrt(ltI[i]);
-            final double inverse = 1.0 / ltI[i];
-
-            for (int q = order - 1; q > i; --q) {
-                ltI[q] *= inverse;
-                final double[] ltQ = lTData[q];
-
-                for (int p = q; p < order; ++p)
-                    ltQ[p] -= ltI[q] * ltI[p];
-            }
-        }
-    }
-
-    /** */
-    @Override public void destroy() {
-        if (cachedL != null)
-            cachedL.destroy();
-        if (cachedLT != null)
-            cachedLT.destroy();
-    }
-
-    /**
-     * Returns the matrix L of the decomposition.
-     * <p>L is an lower-triangular matrix</p>
-     *
-     * @return the L matrix
-     */
-    public Matrix getL() {
-        if (cachedL == null)
-            cachedL = getLT().transpose();
-
-        return cachedL;
-    }
-
-    /**
-     * Returns the transpose of the matrix L of the decomposition.
-     * <p>L<sup>T</sup> is an upper-triangular matrix</p>
-     *
-     * @return the transpose of the matrix L of the decomposition
-     */
-    public Matrix getLT() {
-
-        if (cachedLT == null) {
-            Matrix like = like(origin, origin.rowSize(), origin.columnSize());
-            like.assign(lTData);
-
-            cachedLT = like;
-        }
-
-        // return the cached matrix
-        return cachedLT;
-    }
-
-    /**
-     * Return the determinant of the matrix
-     *
-     * @return determinant of the matrix
-     */
-    public double getDeterminant() {
-        double determinant = 1.0;
-
-        for (int i = 0; i < lTData.length; ++i) {
-            double lTii = lTData[i][i];
-            determinant *= lTii * lTii;
-        }
-
-        return determinant;
-    }
-
-    /**
-     * Solve the linear equation A &times; X = B for matrices A.
-     *
-     * @param b right-hand side of the equation A &times; X = B
-     * @return a vector X that minimizes the two norm of A &times; X - B
-     * @throws CardinalityException if the vectors dimensions do not match
-     */
-    public Vector solve(final Vector b) {
-        final int m = lTData.length;
-
-        if (b.size() != m)
-            throw new CardinalityException(b.size(), m);
-
-        final double[] x = b.getStorage().data();
-
-        // Solve LY = b
-        for (int j = 0; j < m; j++) {
-            final double[] lJ = lTData[j];
-
-            x[j] /= lJ[j];
-
-            final double xJ = x[j];
-
-            for (int i = j + 1; i < m; i++)
-                x[i] -= xJ * lJ[i];
-        }
-
-        // Solve LTX = Y
-        for (int j = m - 1; j >= 0; j--) {
-            x[j] /= lTData[j][j];
-
-            final double xJ = x[j];
-
-            for (int i = 0; i < j; i++)
-                x[i] -= xJ * lTData[i][j];
-        }
-
-        return likeVector(origin, m).assign(x);
-    }
-
-    /**
-     * Solve the linear equation A &times; X = B for matrices A.
-     *
-     * @param b right-hand side of the equation A &times; X = B
-     * @return a matrix X that minimizes the two norm of A &times; X - B
-     * @throws CardinalityException if the matrices dimensions do not match
-     */
-    public Matrix solve(final Matrix b) {
-        final int m = lTData.length;
-
-        if (b.rowSize() != m)
-            throw new CardinalityException(b.rowSize(), m);
-
-        final int nColB = b.columnSize();
-        final double[][] x = b.getStorage().data();
-
-        // Solve LY = b
-        for (int j = 0; j < m; j++) {
-            final double[] lJ = lTData[j];
-            final double lJJ = lJ[j];
-            final double[] xJ = x[j];
-
-            for (int k = 0; k < nColB; ++k)
-                xJ[k] /= lJJ;
-
-            for (int i = j + 1; i < m; i++) {
-                final double[] xI = x[i];
-                final double lJI = lJ[i];
-
-                for (int k = 0; k < nColB; ++k)
-                    xI[k] -= xJ[k] * lJI;
-            }
-        }
-
-        // Solve LTX = Y
-        for (int j = m - 1; j >= 0; j--) {
-            final double lJJ = lTData[j][j];
-            final double[] xJ = x[j];
-
-            for (int k = 0; k < nColB; ++k)
-                xJ[k] /= lJJ;
-
-            for (int i = 0; i < j; i++) {
-                final double[] xI = x[i];
-                final double lIJ = lTData[i][j];
-
-                for (int k = 0; k < nColB; ++k)
-                    xI[k] -= xJ[k] * lIJ;
-            }
-        }
-
-        return like(origin, m, b.columnSize()).assign(x);
-    }
-
-    /** */
-    private double[][] toDoubleArr(Matrix mtx) {
-        if (mtx.isArrayBased())
-            return mtx.getStorage().data();
-
-        double[][] res = new double[mtx.rowSize()][];
-
-        for (int row = 0; row < mtx.rowSize(); row++) {
-            res[row] = new double[mtx.columnSize()];
-            for (int col = 0; col < mtx.columnSize(); col++)
-                res[row][col] = mtx.get(row, col);
-        }
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/DecompositionSupport.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/DecompositionSupport.java b/modules/ml/src/main/java/org/apache/ignite/math/decompositions/DecompositionSupport.java
deleted file mode 100644
index 2c76284..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/math/decompositions/DecompositionSupport.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.math.decompositions;
-
-import org.apache.ignite.math.Destroyable;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.matrix.CacheMatrix;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.matrix.PivotedMatrixView;
-import org.apache.ignite.math.impls.matrix.RandomMatrix;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-
-/**
- * Helper methods to support decomposition of matrix types having some functionality limited.
- */
-public abstract class DecompositionSupport implements Destroyable {
-    /**
-     * Create the like matrix with read-only matrices support.
-     *
-     * @param matrix Matrix for like.
-     * @return Like matrix.
-     */
-    protected Matrix like(Matrix matrix) {
-        if (isCopyLikeSupport(matrix))
-            return new DenseLocalOnHeapMatrix(matrix.rowSize(), matrix.columnSize());
-        else
-            return matrix.like(matrix.rowSize(), matrix.columnSize());
-    }
-
-    /**
-     * Create the like matrix with specified size with read-only matrices support.
-     *
-     * @param matrix Matrix for like.
-     * @return Like matrix.
-     */
-    protected Matrix like(Matrix matrix, int rows, int cols) {
-        if (isCopyLikeSupport(matrix))
-            return new DenseLocalOnHeapMatrix(rows, cols);
-        else
-            return matrix.like(rows, cols);
-    }
-
-    /**
-     * Create the like vector with read-only matrices support.
-     *
-     * @param matrix Matrix for like.
-     * @param crd Cardinality of the vector.
-     * @return Like vector.
-     */
-    protected Vector likeVector(Matrix matrix, int crd) {
-        if (isCopyLikeSupport(matrix))
-            return new DenseLocalOnHeapVector(crd);
-        else
-            return matrix.likeVector(crd);
-    }
-
-    /**
-     * Create the like vector with read-only matrices support.
-     *
-     * @param matrix Matrix for like.
-     * @return Like vector.
-     */
-    protected Vector likeVector(Matrix matrix) {
-        return likeVector(matrix, matrix.rowSize());
-    }
-
-    /**
-     * Create the copy of matrix with read-only matrices support.
-     *
-     * @param matrix Matrix for copy.
-     * @return Copy.
-     */
-    protected Matrix copy(Matrix matrix) {
-        if (isCopyLikeSupport(matrix)) {
-            DenseLocalOnHeapMatrix cp = new DenseLocalOnHeapMatrix(matrix.rowSize(), matrix.columnSize());
-
-            cp.assign(matrix);
-
-            return cp;
-        }
-        else
-            return matrix.copy();
-    }
-
-    /** */
-    private boolean isCopyLikeSupport(Matrix matrix) {
-        return matrix instanceof RandomMatrix || matrix instanceof PivotedMatrixView || matrix instanceof CacheMatrix;
-    }
-}


[31/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
new file mode 100644
index 0000000..d2a2f49
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
@@ -0,0 +1,921 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl;
+import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.jetbrains.annotations.Nullable;
+
+import javax.cache.Cache;
+import java.util.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Concurrency tests for dynamic index create/drop.
+ */
+@SuppressWarnings("unchecked")
+public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicIndexAbstractSelfTest {
+    /** Test duration. */
+    private static final long TEST_DUR = 10_000L;
+
+    /** Large cache size. */
+    private static final int LARGE_CACHE_SIZE = 100_000;
+
+    /** Latches to block certain index operations. */
+    private static final ConcurrentHashMap<UUID, T2<CountDownLatch, AtomicBoolean>> BLOCKS = new ConcurrentHashMap<>();
+
+    /** Cache mode. */
+    private final CacheMode cacheMode;
+
+    /** Atomicity mode. */
+    private final CacheAtomicityMode atomicityMode;
+
+    /**
+     * Constructor.
+     *
+     * @param cacheMode Cache mode.
+     * @param atomicityMode Atomicity mode.
+     */
+    protected DynamicIndexAbstractConcurrentSelfTest(CacheMode cacheMode, CacheAtomicityMode atomicityMode) {
+        this.cacheMode = cacheMode;
+        this.atomicityMode = atomicityMode;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        GridQueryProcessor.idxCls = BlockingIndexing.class;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        GridQueryProcessor.idxCls = null;
+
+        for (T2<CountDownLatch, AtomicBoolean> block : BLOCKS.values())
+            block.get1().countDown();
+
+        BLOCKS.clear();
+
+        stopAllGrids();
+
+        super.afterTest();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 5 * 60 * 1000L;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration<KeyClass, ValueClass> cacheConfiguration() {
+        CacheConfiguration<KeyClass, ValueClass> ccfg =  super.cacheConfiguration();
+
+        return ccfg.setCacheMode(cacheMode).setAtomicityMode(atomicityMode);
+    }
+
+    /**
+     * Make sure that coordinator migrates correctly between nodes.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCoordinatorChange() throws Exception {
+        // Start servers.
+        Ignite srv1 = Ignition.start(serverConfiguration(1));
+        Ignite srv2 = Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+        Ignition.start(serverConfiguration(4));
+
+        UUID srv1Id = srv1.cluster().localNode().id();
+        UUID srv2Id = srv2.cluster().localNode().id();
+
+        // Start client which will execute operations.
+        Ignite cli = Ignition.start(clientConfiguration(5));
+
+        cli.getOrCreateCache(cacheConfiguration());
+
+        put(srv1, 0, KEY_AFTER);
+
+        // Test migration between normal servers.
+        blockIndexing(srv1Id);
+
+        QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        IgniteInternalFuture<?> idxFut1 = queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx1, false);
+
+        Thread.sleep(100);
+
+        //srv1.close();
+        Ignition.stop(srv1.name(), true);
+
+        unblockIndexing(srv1Id);
+
+        idxFut1.get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+
+        // Test migration from normal server to non-affinity server.
+        blockIndexing(srv2Id);
+
+        QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2)));
+
+        IgniteInternalFuture<?> idxFut2 = queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx2, false);
+
+        Thread.sleep(100);
+
+        //srv2.close();
+        Ignition.stop(srv2.name(), true);
+
+        unblockIndexing(srv2Id);
+
+        idxFut2.get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        assertIndexUsed(IDX_NAME_2, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_2, KEY_AFTER - SQL_ARG_1);
+    }
+
+    /**
+     * Test operations join.
+     *
+     * @throws Exception If failed.
+     */
+    public void testOperationChaining() throws Exception {
+        Ignite srv1 = Ignition.start(serverConfiguration(1));
+
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+        Ignition.start(clientConfiguration(4));
+
+        srv1.getOrCreateCache(cacheConfiguration());
+
+        blockIndexing(srv1);
+
+        QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1));
+        QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2)));
+
+        IgniteInternalFuture<?> idxFut1 = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx1, false);
+        IgniteInternalFuture<?> idxFut2 = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx2, false);
+
+        // Start even more nodes of different flavors
+        Ignition.start(serverConfiguration(5));
+        Ignition.start(serverConfiguration(6, true));
+        Ignition.start(clientConfiguration(7));
+
+        assert !idxFut1.isDone();
+        assert !idxFut2.isDone();
+
+        unblockIndexing(srv1);
+
+        idxFut1.get();
+        idxFut2.get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+
+        Thread.sleep(100);
+
+        put(srv1, 0, KEY_AFTER);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertIndexUsed(IDX_NAME_2, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
+
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_2, KEY_AFTER - SQL_ARG_1);
+    }
+
+    /**
+     * Test node join on pending operation.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNodeJoinOnPendingOperation() throws Exception {
+        Ignite srv1 = Ignition.start(serverConfiguration(1));
+
+        srv1.getOrCreateCache(cacheConfiguration());
+
+        blockIndexing(srv1);
+
+        QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        IgniteInternalFuture<?> idxFut = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
+
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+        Ignition.start(clientConfiguration(4));
+
+        assert !idxFut.isDone();
+
+        unblockIndexing(srv1);
+
+        idxFut.get();
+
+        Thread.sleep(100L);
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        put(srv1, 0, KEY_AFTER);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+    }
+
+    /**
+     * PUT/REMOVE data from cache and build index concurrently.
+     *
+     * @throws Exception If failed,
+     */
+    public void testConcurrentPutRemove() throws Exception {
+        // Start several nodes.
+        Ignite srv1 = Ignition.start(serverConfiguration(1));
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3));
+        Ignition.start(serverConfiguration(4));
+
+        awaitPartitionMapExchange();
+
+        IgniteCache<BinaryObject, BinaryObject> cache = srv1.createCache(cacheConfiguration()).withKeepBinary();
+
+        // Start data change operations from several threads.
+        final AtomicBoolean stopped = new AtomicBoolean();
+
+        IgniteInternalFuture updateFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    int key = ThreadLocalRandom.current().nextInt(0, LARGE_CACHE_SIZE);
+                    int val = ThreadLocalRandom.current().nextInt();
+
+                    BinaryObject keyObj = key(node, key);
+
+                    if (ThreadLocalRandom.current().nextBoolean()) {
+                        BinaryObject valObj = value(node, val);
+
+                        node.cache(CACHE_NAME).put(keyObj, valObj);
+                    }
+                    else
+                        node.cache(CACHE_NAME).remove(keyObj);
+                }
+
+                return null;
+            }
+        }, 4);
+
+        // Let some to arrive.
+        Thread.sleep(500L);
+
+        // Create index.
+        QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get();
+
+        // Stop updates once index is ready.
+        stopped.set(true);
+
+        updateFut.get();
+
+        // Make sure index is there.
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+
+        // Get expected values.
+        Map<Long, Long> expKeys = new HashMap<>();
+
+        for (int i = 0; i < LARGE_CACHE_SIZE; i++) {
+            BinaryObject val = cache.get(key(srv1, i));
+
+            if (val != null) {
+                long fieldVal = val.field(FIELD_NAME_1);
+
+                if (fieldVal >= SQL_ARG_1)
+                    expKeys.put((long)i, fieldVal);
+            }
+        }
+
+        // Validate query result.
+        for (Ignite node : Ignition.allGrids()) {
+            IgniteCache<BinaryObject, BinaryObject> nodeCache = node.cache(CACHE_NAME).withKeepBinary();
+
+            SqlQuery qry = new SqlQuery(tableName(ValueClass.class), SQL_SIMPLE_FIELD_1).setArgs(SQL_ARG_1);
+
+            List<Cache.Entry<BinaryObject, BinaryObject>> res = nodeCache.query(qry).getAll();
+
+            assertEquals("Cache size mismatch [exp=" + expKeys.size() + ", actual=" + res.size() + ']',
+                expKeys.size(), res.size());
+
+            for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
+                long key = entry.getKey().field(FIELD_KEY);
+                Long fieldVal = entry.getValue().field(FIELD_NAME_1);
+
+                assertTrue("Expected key is not in result set: " + key, expKeys.containsKey(key));
+
+                assertEquals("Unexpected value [key=" + key + ", expVal=" + expKeys.get(key) +
+                    ", actualVal=" + fieldVal + ']', expKeys.get(key), fieldVal);
+            }
+
+        }
+    }
+
+    /**
+     * Test index consistency on re-balance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testConcurrentRebalance() throws Exception {
+        // Start cache and populate it with data.
+        Ignite srv1 = Ignition.start(serverConfiguration(1));
+        Ignite srv2 = Ignition.start(serverConfiguration(2));
+
+        srv1.createCache(cacheConfiguration());
+
+        awaitPartitionMapExchange();
+
+        put(srv1, 0, LARGE_CACHE_SIZE);
+
+        // Start index operation in blocked state.
+        blockIndexing(srv1);
+        blockIndexing(srv2);
+
+        QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        final IgniteInternalFuture<?> idxFut =
+            queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
+
+        Thread.sleep(100);
+
+        // Start two more nodes and unblock index operation in the middle.
+        Ignition.start(serverConfiguration(3));
+
+        unblockIndexing(srv1);
+        unblockIndexing(srv2);
+
+        Ignition.start(serverConfiguration(4));
+
+        awaitPartitionMapExchange();
+
+        // Validate index state.
+        idxFut.get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, LARGE_CACHE_SIZE - SQL_ARG_1);
+    }
+
+    /**
+     * Check what happen in case cache is destroyed before operation is started.
+     *
+     * @throws Exception If failed.
+     */
+    public void testConcurrentCacheDestroy() throws Exception {
+        // Start complex topology.
+        Ignite srv1 = Ignition.start(serverConfiguration(1));
+
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+
+        Ignite cli = Ignition.start(clientConfiguration(4));
+
+        // Start cache and populate it with data.
+        IgniteCache cache = cli.getOrCreateCache(cacheConfiguration());
+
+        put(cli, KEY_AFTER);
+
+        // Start index operation and block it on coordinator.
+        blockIndexing(srv1);
+
+        QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        final IgniteInternalFuture<?> idxFut =
+            queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
+
+        Thread.sleep(100);
+
+        // Destroy cache.
+        cache.destroy();
+
+        // Unblock indexing and see what happens.
+        unblockIndexing(srv1);
+
+        try {
+            idxFut.get();
+
+            fail("Exception has not been thrown.");
+        }
+        catch (SchemaOperationException e) {
+            // No-op.
+        }
+    }
+
+    /**
+     * Make sure that contended operations on the same index from different nodes do not hang.
+     *
+     * @throws Exception If failed.
+     */
+    public void testConcurrentOperationsMultithreaded() throws Exception {
+        // Start complex topology.
+        Ignition.start(serverConfiguration(1));
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+
+        Ignite cli = Ignition.start(clientConfiguration(4));
+
+        cli.createCache(cacheConfiguration());
+
+        final AtomicBoolean stopped = new AtomicBoolean();
+
+        // Start several threads which will mess around indexes.
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        IgniteInternalFuture idxFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                boolean exists = false;
+
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    IgniteInternalFuture fut;
+
+                    if (exists) {
+                        fut = queryProcessor(node).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true);
+
+                        exists = false;
+                    }
+                    else {
+                        fut = queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
+
+                        exists = true;
+                    }
+
+                    try {
+                        fut.get();
+                    }
+                    catch (SchemaOperationException e) {
+                        // No-op.
+                    }
+                    catch (Exception e) {
+                        fail("Unexpected exception: " + e);
+                    }
+                }
+
+                return null;
+            }
+        }, 8);
+
+        Thread.sleep(TEST_DUR);
+
+        stopped.set(true);
+
+        // Make sure nothing hanged.
+        idxFut.get();
+
+        queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true).get();
+        queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true).get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        put(cli, 0, KEY_AFTER);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+    }
+
+    /**
+     * Make sure that contended operations on the same index from different nodes do not hang when we issue both
+     * CREATE/DROP and SELECT statements.
+     *
+     * @throws Exception If failed.
+     */
+    public void testQueryConsistencyMultithreaded() throws Exception {
+        // Start complex topology.
+        Ignition.start(serverConfiguration(1));
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+
+        Ignite cli = Ignition.start(clientConfiguration(4));
+
+        cli.createCache(cacheConfiguration());
+
+        put(cli, 0, KEY_AFTER);
+
+        final AtomicBoolean stopped = new AtomicBoolean();
+
+        // Thread which will mess around indexes.
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        IgniteInternalFuture idxFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                boolean exists = false;
+
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    IgniteInternalFuture fut;
+
+                    if (exists) {
+                        fut = queryProcessor(node).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true);
+
+                        exists = false;
+                    }
+                    else {
+                        fut = queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
+
+                        exists = true;
+                    }
+
+                    try {
+                        fut.get();
+                    }
+                    catch (SchemaOperationException e) {
+                        // No-op.
+                    }
+                    catch (Exception e) {
+                        fail("Unexpected exception: " + e);
+                    }
+                }
+
+                return null;
+            }
+        }, 1);
+
+        IgniteInternalFuture qryFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    assertSqlSimpleData(node, SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+                }
+
+                return null;
+            }
+        }, 8);
+
+        Thread.sleep(TEST_DUR);
+
+        stopped.set(true);
+
+        // Make sure nothing hanged.
+        idxFut.get();
+        qryFut.get();
+    }
+
+    /**
+     * Test concurrent node start/stop along with index operations. Nothing should hang.
+     *
+     * @throws Exception If failed.
+     */
+    public void testConcurrentOperationsAndNodeStartStopMultithreaded() throws Exception {
+        // Start several stable nodes.
+        Ignition.start(serverConfiguration(1));
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+
+        final Ignite cli = Ignition.start(clientConfiguration(4));
+
+        cli.createCache(cacheConfiguration());
+
+        final AtomicBoolean stopped = new AtomicBoolean();
+
+        // Start node start/stop worker.
+        final AtomicInteger nodeIdx = new AtomicInteger(4);
+
+        IgniteInternalFuture startStopFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                boolean exists = false;
+
+                int lastIdx = 0;
+
+                while (!stopped.get()) {
+                    if (exists) {
+                        stopGrid(lastIdx);
+
+                        exists = false;
+                    }
+                    else {
+                        lastIdx = nodeIdx.incrementAndGet();
+
+                        IgniteConfiguration cfg;
+
+                        switch (ThreadLocalRandom.current().nextInt(0, 3)) {
+                            case 1:
+                                cfg = serverConfiguration(lastIdx, false);
+
+                                break;
+
+                            case 2:
+
+                                cfg = serverConfiguration(lastIdx, true);
+
+                                break;
+
+                            default:
+                                cfg = clientConfiguration(lastIdx);
+                        }
+
+                        Ignition.start(cfg);
+
+                        exists = true;
+                    }
+
+                    Thread.sleep(ThreadLocalRandom.current().nextLong(500L, 1500L));
+                }
+
+                return null;
+            }
+        }, 1);
+
+        // Start several threads which will mess around indexes.
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        IgniteInternalFuture idxFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                boolean exists = false;
+
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    IgniteInternalFuture fut;
+
+                    if (exists) {
+                        fut = queryProcessor(node).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true);
+
+                        exists = false;
+                    }
+                    else {
+                        fut = queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
+
+                        exists = true;
+                    }
+
+                    try {
+                        fut.get();
+                    }
+                    catch (SchemaOperationException e) {
+                        // No-op.
+                    }
+                    catch (Exception e) {
+                        fail("Unexpected exception: " + e);
+                    }
+                }
+
+                return null;
+            }
+        }, 1);
+
+        Thread.sleep(TEST_DUR);
+
+        stopped.set(true);
+
+        // Make sure nothing hanged.
+        startStopFut.get();
+        idxFut.get();
+
+        // Make sure cache is operational at this point.
+        cli.getOrCreateCache(cacheConfiguration());
+
+        queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true).get();
+        queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true).get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        put(cli, 0, KEY_AFTER);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+    }
+
+    /**
+     * Multithreaded cache start/stop along with index operations. Nothing should hang.
+     *
+     * @throws Exception If failed.
+     */
+    public void testConcurrentOperationsAndCacheStartStopMultithreaded() throws Exception {
+        // Start complex topology.
+        Ignition.start(serverConfiguration(1));
+        Ignition.start(serverConfiguration(2));
+        Ignition.start(serverConfiguration(3, true));
+
+        Ignite cli = Ignition.start(clientConfiguration(4));
+
+        final AtomicBoolean stopped = new AtomicBoolean();
+
+        // Start cache create/destroy worker.
+        IgniteInternalFuture startStopFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                boolean exists = false;
+
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    if (exists) {
+                        node.destroyCache(CACHE_NAME);
+
+                        exists = false;
+                    }
+                    else {
+                        node.createCache(cacheConfiguration());
+
+                        exists = true;
+                    }
+
+                    Thread.sleep(ThreadLocalRandom.current().nextLong(200L, 400L));
+                }
+
+                return null;
+            }
+        }, 1);
+
+        // Start several threads which will mess around indexes.
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+
+        IgniteInternalFuture idxFut = multithreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                boolean exists = false;
+
+                while (!stopped.get()) {
+                    Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
+
+                    IgniteInternalFuture fut;
+
+                    if (exists) {
+                        fut = queryProcessor(node).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true);
+
+                        exists = false;
+                    }
+                    else {
+                        fut = queryProcessor(node).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
+
+                        exists = true;
+                    }
+
+                    try {
+                        fut.get();
+                    }
+                    catch (SchemaOperationException e) {
+                        // No-op.
+                    }
+                    catch (Exception e) {
+                        fail("Unexpected exception: " + e);
+                    }
+                }
+
+                return null;
+            }
+        }, 8);
+
+        Thread.sleep(TEST_DUR);
+
+        stopped.set(true);
+
+        // Make sure nothing hanged.
+        startStopFut.get();
+        idxFut.get();
+
+        // Make sure cache is operational at this point.
+        cli.getOrCreateCache(cacheConfiguration());
+
+        queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true).get();
+        queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true).get();
+
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+
+        put(cli, 0, KEY_AFTER);
+
+        assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
+        assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+    }
+
+    /**
+     * Block indexing.
+     *
+     * @param node Node.
+     */
+    @SuppressWarnings("SuspiciousMethodCalls")
+    private static void blockIndexing(Ignite node) {
+        UUID nodeId = ((IgniteEx)node).localNode().id();
+
+        blockIndexing(nodeId);
+    }
+
+    /**
+     * Block indexing.
+     *
+     * @param nodeId Node.
+     */
+    @SuppressWarnings("SuspiciousMethodCalls")
+    private static void blockIndexing(UUID nodeId) {
+        assertFalse(BLOCKS.contains(nodeId));
+
+        BLOCKS.put(nodeId, new T2<>(new CountDownLatch(1), new AtomicBoolean()));
+    }
+
+    /**
+     * Unblock indexing.
+     *
+     * @param node Node.
+     */
+    private static void unblockIndexing(Ignite node) {
+        UUID nodeId = ((IgniteEx)node).localNode().id();
+
+        unblockIndexing(nodeId);
+    }
+
+    /**
+     * Unblock indexing.
+     *
+     * @param nodeId Node ID.
+     */
+    private static void unblockIndexing(UUID nodeId) {
+        T2<CountDownLatch, AtomicBoolean> blocker = BLOCKS.remove(nodeId);
+
+        assertNotNull(blocker);
+
+        blocker.get1().countDown();
+    }
+
+    /**
+     * Await indexing.
+     *
+     * @param nodeId Node ID.
+     */
+    private static void awaitIndexing(UUID nodeId) {
+        T2<CountDownLatch, AtomicBoolean> blocker = BLOCKS.get(nodeId);
+
+        if (blocker != null) {
+            assertTrue(blocker.get2().compareAndSet(false, true));
+
+            while (true) {
+                try {
+                    blocker.get1().await();
+
+                    break;
+                }
+                catch (InterruptedException e) {
+                    // No-op.
+                }
+            }
+        }
+    }
+
+    /**
+     * Blocking indexing processor.
+     */
+    private static class BlockingIndexing extends IgniteH2Indexing {
+        /** {@inheritDoc} */
+        @Override public void dynamicIndexCreate(@Nullable String spaceName, String tblName,
+            QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)
+            throws IgniteCheckedException {
+            awaitIndexing(ctx.localNodeId());
+
+            super.dynamicIndexCreate(spaceName, tblName, idxDesc, ifNotExists, cacheVisitor);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void dynamicIndexDrop(@Nullable String spaceName, String idxName, boolean ifExists)
+            throws IgniteCheckedException{
+            awaitIndexing(ctx.localNodeId());
+
+            super.dynamicIndexDrop(spaceName, idxName, ifExists);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
new file mode 100644
index 0000000..e52e0d3
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
@@ -0,0 +1,467 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+
+import javax.cache.Cache;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+/**
+ * Tests for dynamic index creation.
+ */
+@SuppressWarnings({"unchecked", "ThrowableResultOfMethodCallIgnored"})
+public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTest {
+    /** Attribute to filter node out of cache data nodes. */
+    protected static final String ATTR_FILTERED = "FILTERED";
+
+    /** Key range limit for "before" step. */
+    protected static final int KEY_BEFORE = 100;
+
+    /** Key range limit for "after" step. */
+    protected static final int KEY_AFTER = 200;
+
+    /** SQL to check index on the field 1. */
+    protected static final String SQL_SIMPLE_FIELD_1 = "SELECT * FROM " + TBL_NAME + " WHERE " + FIELD_NAME_1 + " >= ?";
+
+    /** SQL to check composite index */
+    protected static final String SQL_COMPOSITE = "SELECT * FROM " + TBL_NAME + " WHERE " + FIELD_NAME_1 +
+        " >= ? AND " + alias(FIELD_NAME_2) + " >= ?";
+
+    /** SQL to check index on the field 2. */
+    protected static final String SQL_SIMPLE_FIELD_2 =
+        "SELECT * FROM " + TBL_NAME + " WHERE " + alias(FIELD_NAME_2) + " >= ?";
+
+    /** Argument for simple SQL (1). */
+    protected static final int SQL_ARG_1 = 40;
+
+    /** Argument for simple SQL (2). */
+    protected static final int SQL_ARG_2 = 80;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /**
+     * Create server configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    protected IgniteConfiguration serverConfiguration(int idx) throws Exception {
+        return serverConfiguration(idx, false);
+    }
+
+    /**
+     * Create server configuration.
+     *
+     * @param idx Index.
+     * @param filter Whether to filter the node out of cache.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    protected IgniteConfiguration serverConfiguration(int idx, boolean filter) throws Exception {
+        IgniteConfiguration cfg = commonConfiguration(idx);
+
+        if (filter)
+            cfg.setUserAttributes(Collections.singletonMap(ATTR_FILTERED, true));
+
+        return cfg;
+    }
+
+    /**
+     * Create client configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    protected IgniteConfiguration clientConfiguration(int idx) throws Exception {
+        return commonConfiguration(idx).setClientMode(true);
+    }
+
+    /**
+     * Create common node configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    protected IgniteConfiguration commonConfiguration(int idx) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(getTestIgniteInstanceName(idx));
+
+        cfg.setDiscoverySpi(new TcpDiscoverySpi());
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return optimize(cfg);
+    }
+
+    /**
+     * @return Default cache configuration.
+     */
+    protected CacheConfiguration<KeyClass, ValueClass> cacheConfiguration() {
+        CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME);
+
+        QueryEntity entity = new QueryEntity();
+
+        entity.setKeyType(KeyClass.class.getName());
+        entity.setValueType(ValueClass.class.getName());
+
+        entity.addQueryField(FIELD_KEY, Long.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_1, Long.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_2, Long.class.getName(), null);
+
+        entity.setKeyFields(Collections.singleton(FIELD_KEY));
+
+        entity.setAliases(Collections.singletonMap(FIELD_NAME_2, alias(FIELD_NAME_2)));
+
+        ccfg.setQueryEntities(Collections.singletonList(entity));
+
+        ccfg.setNodeFilter(new NodeFilter());
+
+        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+        ccfg.setBackups(1);
+
+        return ccfg;
+    }
+
+    /**
+     * Ensure that schema exception is thrown.
+     *
+     * @param r Runnable.
+     * @param expCode Error code.
+     */
+    protected static void assertSchemaException(RunnableX r, int expCode) {
+        try {
+            r.run();
+        }
+        catch (SchemaOperationException e) {
+            assertEquals("Unexpected error code [expected=" + expCode + ", actual=" + e.code() + ']',
+                expCode, e.code());
+
+            return;
+        }
+        catch (Exception e) {
+            fail("Unexpected exception: " + e);
+        }
+
+        fail(SchemaOperationException.class.getSimpleName() +  " is not thrown.");
+    }
+
+    /**
+     * Ensure index is used in plan.
+     *
+     * @param idxName Index name.
+     * @param sql SQL.
+     * @param args Arguments.
+     */
+    protected static void assertIndexUsed(String idxName, String sql, Object... args) {
+        for (Ignite node : Ignition.allGrids())
+            assertIndexUsed((IgniteEx)node, idxName, sql, args);
+    }
+
+    /**
+     * Ensure index is used in plan.
+     *
+     * @param node Node.
+     * @param idxName Index name.
+     * @param sql SQL.
+     * @param args Arguments.
+     */
+    protected static void assertIndexUsed(IgniteEx node, String idxName, String sql, Object... args) {
+        SqlFieldsQuery qry = new SqlFieldsQuery("EXPLAIN " + sql);
+
+        if (args != null && args.length > 0)
+            qry.setArgs(args);
+
+        String plan = (String)node.cache(CACHE_NAME).query(qry).getAll().get(0).get(0);
+
+        assertTrue("Index is not used: " + plan, plan.toLowerCase().contains(idxName.toLowerCase()));
+    }
+
+    /**
+     * Ensure index is not used in plan.
+     *
+     * @param idxName Index name.
+     * @param sql SQL.
+     * @param args Arguments.
+     */
+    protected static void assertIndexNotUsed(String idxName, String sql, Object... args) {
+        for (Ignite node : Ignition.allGrids())
+            assertIndexNotUsed((IgniteEx)node, idxName, sql, args);
+    }
+
+    /**
+     * Ensure index is not used in plan.
+     *
+     * @param node Node.
+     * @param idxName Index name.
+     * @param sql SQL.
+     * @param args Arguments.
+     */
+    protected static void assertIndexNotUsed(IgniteEx node, String idxName, String sql, Object... args) {
+        SqlFieldsQuery qry = new SqlFieldsQuery("EXPLAIN " + sql);
+
+        if (args != null && args.length > 0)
+            qry.setArgs(args);
+
+        String plan = (String)node.cache(CACHE_NAME).query(qry).getAll().get(0).get(0);
+
+        assertFalse("Index is used: " + plan, plan.contains(idxName));
+    }
+
+    /**
+     * Create key object.
+     *
+     * @param ignite Ignite instance.
+     * @param id ID.
+     * @return Key object.
+     */
+    protected static BinaryObject key(Ignite ignite, long id) {
+        return ignite.binary().builder(KeyClass.class.getName()).setField(FIELD_KEY, id).build();
+    }
+
+    /**
+     * Create value object.
+     *
+     * @param ignite Ignite instance.
+     * @param id ID.
+     * @return Value object.
+     */
+    protected static BinaryObject value(Ignite ignite, long id) {
+        return ignite.binary().builder(ValueClass.class.getName())
+            .setField(FIELD_NAME_1, id)
+            .setField(FIELD_NAME_2, id)
+            .build();
+    }
+
+    /**
+     * Create key/value entry for the given key.
+     *
+     * @param ignite Ignite instance.
+     * @param id ID.
+     * @return Entry.
+     */
+    protected static T2<BinaryObject, BinaryObject> entry(Ignite ignite, long id) {
+        return new T2<>(key(ignite, id), value(ignite, id));
+    }
+
+    /**
+     * Get common cache.
+     *
+     * @param node Node.
+     * @return Cache.
+     */
+    protected static IgniteCache<BinaryObject, BinaryObject> cache(Ignite node) {
+        return node.cache(CACHE_NAME).withKeepBinary();
+    }
+
+    /**
+     * Get key.
+     *
+     * @param node Node.
+     * @param id ID.
+     */
+    protected static BinaryObject get(Ignite node, int id) {
+        BinaryObject key = key(node, id);
+
+        return cache(node).get(key);
+    }
+
+    /**
+     * Put key range.
+     *
+     * @param node Node.
+     * @param from From key.
+     * @param to To key.
+     */
+    protected static void put(Ignite node, int from, int to) {
+        try (IgniteDataStreamer streamer = node.dataStreamer(CACHE_NAME)) {
+            streamer.allowOverwrite(true);
+            streamer.keepBinary(true);
+
+            for (int i = from; i < to; i++) {
+                BinaryObject key = key(node, i);
+                BinaryObject val = value(node, i);
+
+                streamer.addData(key, val);
+            }
+
+            streamer.flush();
+        }
+    }
+
+    /**
+     * Put key to cache.
+     *
+     * @param node Node.
+     * @param id ID.
+     */
+    protected static void put(Ignite node, long id) {
+        BinaryObject key = key(node, id);
+        BinaryObject val = value(node, id);
+
+        cache(node).put(key, val);
+    }
+
+    /**
+     * Remove key range.
+     *
+     * @param node Node.
+     * @param from From key.
+     * @param to To key.
+     */
+    protected static void remove(Ignite node, int from, int to) {
+        for (int i = from; i < to; i++)
+            remove(node, i);
+    }
+
+    /**
+     * Remove key form cache.
+     *
+     * @param node Node.
+     * @param id ID.
+     */
+    protected static void remove(Ignite node, long id) {
+        BinaryObject key = key(node, id);
+
+        cache(node).remove(key);
+    }
+
+    /**
+     * @return Random string.
+     */
+    protected static String randomString() {
+        return UUID.randomUUID().toString();
+    }
+
+    /**
+     * Assert SQL simple data state.
+     *
+     * @param sql SQL query.
+     * @param expSize Expected size.
+     */
+    protected static void assertSqlSimpleData(String sql, int expSize) {
+        for (Ignite node : Ignition.allGrids())
+            assertSqlSimpleData(node, sql, expSize);
+    }
+
+    /**
+     * Assert SQL simple data state.
+     *
+     * @param node Node.
+     * @param sql SQL query.
+     * @param expSize Expected size.
+     */
+    protected static void assertSqlSimpleData(Ignite node, String sql, int expSize) {
+        SqlQuery qry = new SqlQuery(tableName(ValueClass.class), sql).setArgs(SQL_ARG_1);
+
+        List<Cache.Entry<BinaryObject, BinaryObject>> res = node.cache(CACHE_NAME).withKeepBinary().query(qry).getAll();
+
+        Set<Long> ids = new HashSet<>();
+
+        for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
+            long id = entry.getKey().field(FIELD_KEY);
+
+            long field1 = entry.getValue().field(FIELD_NAME_1);
+            long field2 = entry.getValue().field(FIELD_NAME_2);
+
+            assertTrue(field1 >= SQL_ARG_1);
+
+            assertEquals(id, field1);
+            assertEquals(id, field2);
+
+            assertTrue(ids.add(id));
+        }
+
+        assertEquals("Size mismatch [node=" + node.name() + ", exp=" + expSize + ", actual=" + res.size() +
+            ", ids=" + ids + ']', expSize, res.size());
+    }
+
+    /**
+     * Assert SQL simple data state.
+     *
+     * @param node Node.
+     * @param sql SQL query.
+     * @param expSize Expected size.
+     */
+    protected static void assertSqlCompositeData(Ignite node, String sql, int expSize) {
+        SqlQuery qry = new SqlQuery(tableName(ValueClass.class), sql).setArgs(SQL_ARG_1, SQL_ARG_2);
+
+        List<Cache.Entry<BinaryObject, BinaryObject>> res = node.cache(CACHE_NAME).withKeepBinary().query(qry).getAll();
+
+        Set<Long> ids = new HashSet<>();
+
+        for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
+            long id = entry.getKey().field(FIELD_KEY);
+
+            long field1 = entry.getValue().field(FIELD_NAME_1);
+            long field2 = entry.getValue().field(FIELD_NAME_2);
+
+            assertTrue(field1 >= SQL_ARG_2);
+
+            assertEquals(id, field1);
+            assertEquals(id, field2);
+
+            assertTrue(ids.add(id));
+        }
+
+        assertEquals("Size mismatch [exp=" + expSize + ", actual=" + res.size() + ", ids=" + ids + ']',
+            expSize, res.size());
+    }
+
+    /**
+     * Node filter.
+     */
+    protected static class NodeFilter implements IgnitePredicate<ClusterNode>, Serializable {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode node) {
+            return node.attribute(ATTR_FILTERED) == null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexClientBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexClientBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexClientBasicSelfTest.java
new file mode 100644
index 0000000..10f4f85
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexClientBasicSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+/**
+ * Test dynamic schema operations from client node.
+ */
+public class DynamicIndexClientBasicSelfTest extends DynamicIndexAbstractBasicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int nodeIndex() {
+        return IDX_CLI;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedAtomicConcurrentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedAtomicConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedAtomicConcurrentSelfTest.java
new file mode 100644
index 0000000..497ec39
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedAtomicConcurrentSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/**
+ * Concurrency tests for dynamic index create/drop for PARTITIONED/ATOMIC cache.
+ */
+public class DynamicIndexPartitionedAtomicConcurrentSelfTest extends DynamicIndexAbstractConcurrentSelfTest {
+    /**
+     * Constructor.
+     */
+    public DynamicIndexPartitionedAtomicConcurrentSelfTest() {
+        super(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedTransactionalConcurrentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedTransactionalConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedTransactionalConcurrentSelfTest.java
new file mode 100644
index 0000000..fed0149
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexPartitionedTransactionalConcurrentSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/**
+ * Concurrency tests for dynamic index create/drop for PARTITIONED/TRANSACTIONAL cache.
+ */
+public class DynamicIndexPartitionedTransactionalConcurrentSelfTest extends DynamicIndexAbstractConcurrentSelfTest {
+    /**
+     * Constructor.
+     */
+    public DynamicIndexPartitionedTransactionalConcurrentSelfTest() {
+        super(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedAtomicConcurrentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedAtomicConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedAtomicConcurrentSelfTest.java
new file mode 100644
index 0000000..2c6c9a9
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedAtomicConcurrentSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/**
+ * Concurrency tests for dynamic index create/drop for REPLICATED/ATOMIC cache.
+ */
+public class DynamicIndexReplicatedAtomicConcurrentSelfTest extends DynamicIndexAbstractConcurrentSelfTest {
+    /**
+     * Constructor.
+     */
+    public DynamicIndexReplicatedAtomicConcurrentSelfTest() {
+        super(CacheMode.REPLICATED, CacheAtomicityMode.ATOMIC);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedTransactionalConcurrentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedTransactionalConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedTransactionalConcurrentSelfTest.java
new file mode 100644
index 0000000..9dc92a4
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexReplicatedTransactionalConcurrentSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/**
+ * Concurrency tests for dynamic index create/drop for REPLICATED/TRANSACTIONAL cache.
+ */
+public class DynamicIndexReplicatedTransactionalConcurrentSelfTest extends DynamicIndexAbstractConcurrentSelfTest {
+    /**
+     * Constructor.
+     */
+    public DynamicIndexReplicatedTransactionalConcurrentSelfTest() {
+        super(CacheMode.REPLICATED, CacheAtomicityMode.TRANSACTIONAL);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerBasicSelfTest.java
new file mode 100644
index 0000000..c014229
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerBasicSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+/**
+ * Test dynamic schema operations from non-coordinator node.
+ */
+public class DynamicIndexServerBasicSelfTest extends DynamicIndexAbstractBasicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int nodeIndex() {
+        return IDX_SRV_NON_CRD;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerCoordinatorBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerCoordinatorBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerCoordinatorBasicSelfTest.java
new file mode 100644
index 0000000..7427a4c
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerCoordinatorBasicSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+/**
+ * Test dynamic schema operations from coordinator node.
+ */
+public class DynamicIndexServerCoordinatorBasicSelfTest extends DynamicIndexAbstractBasicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int nodeIndex() {
+        return IDX_SRV_CRD;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFIlterBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFIlterBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFIlterBasicSelfTest.java
new file mode 100644
index 0000000..b8acd1d
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFIlterBasicSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+/**
+ * Test dynamic schema operations from server node which do not pass node filter.
+ */
+public class DynamicIndexServerNodeFIlterBasicSelfTest extends DynamicIndexAbstractBasicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int nodeIndex() {
+        return IDX_SRV_FILTERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFilterCoordinatorBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFilterCoordinatorBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFilterCoordinatorBasicSelfTest.java
new file mode 100644
index 0000000..e297fe1
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexServerNodeFilterCoordinatorBasicSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+
+/**
+ * Test dynamic schema operations from server node which do not pass node filter and which is coordinator.
+ */
+public class DynamicIndexServerNodeFilterCoordinatorBasicSelfTest extends DynamicIndexServerCoordinatorBasicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration serverCoordinatorConfiguration(int idx) throws Exception {
+        return serverConfiguration(idx, true);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
new file mode 100644
index 0000000..cf563cc
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
@@ -0,0 +1,400 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.F;
+
+/**
+ * Test that checks indexes handling on H2 side.
+ */
+public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTest {
+    /** Client node index. */
+    private final static int CLIENT = 2;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        for (IgniteConfiguration cfg : configurations())
+            Ignition.start(cfg);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        client().getOrCreateCache(cacheConfiguration());
+
+        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+
+        IgniteCache<KeyClass, ValueClass> cache = client().cache(CACHE_NAME);
+
+        cache.put(new KeyClass(1), new ValueClass("val1"));
+        cache.put(new KeyClass(2), new ValueClass("val2"));
+        cache.put(new KeyClass(3), new ValueClass("val3"));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        client().destroyCache(CACHE_NAME);
+
+        super.afterTest();
+    }
+
+    /**
+     * Test that after index creation index is used by queries.
+     */
+    public void testCreateIndex() throws Exception {
+        IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        assertSize(3);
+
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
+            + FIELD_NAME_1 + "\" ASC)")).getAll();
+
+        // Test that local queries on all nodes use new index.
+        for (int i = 0 ; i < 4; i++) {
+            List<List<?>> locRes = ignite(i).cache("cache").query(new SqlFieldsQuery("explain select \"id\" from " +
+                "\"cache\".\"ValueClass\" where \"field1\" = 'A'").setLocal(true)).getAll();
+
+            assertEquals(F.asList(
+                Collections.singletonList("SELECT\n" +
+                    "    \"id\"\n" +
+                    "FROM \"cache\".\"ValueClass\"\n" +
+                    "    /* \"cache\".\"idx_1\": \"field1\" = 'A' */\n" +
+                    "WHERE \"field1\" = 'A'")
+            ), locRes);
+        }
+
+        assertSize(3);
+
+        cache.remove(new KeyClass(2));
+
+        assertSize(2);
+
+        cache.put(new KeyClass(4), new ValueClass("someVal"));
+
+        assertSize(3);
+    }
+
+    /**
+     * Test that creating an index with duplicate name yields an error.
+     */
+    public void testCreateIndexWithDuplicateName() {
+        final IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
+            + FIELD_NAME_1 + "\" ASC)"));
+
+        assertSqlException(new RunnableX() {
+            @Override public void run() throws Exception {
+                cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\"id\" ASC)"));
+            }
+        }, IgniteQueryErrorCode.INDEX_ALREADY_EXISTS);
+    }
+
+    /**
+     * Test that creating an index with duplicate name does not yield an error with {@code IF NOT EXISTS}.
+     */
+    public void testCreateIndexIfNotExists() {
+        final IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
+            + FIELD_NAME_1 + "\" ASC)"));
+
+        cache.query(new SqlFieldsQuery("CREATE INDEX IF NOT EXISTS \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME +
+            "\"(\"id\" ASC)"));
+    }
+
+    /**
+     * Test that after index drop there are no attempts to use it, and data state remains intact.
+     */
+    public void testDropIndex() {
+        IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        assertSize(3);
+
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
+            + FIELD_NAME_1 + "\" ASC)"));
+
+        assertSize(3);
+
+        cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1 + "\""));
+
+        // Test that no local queries on all nodes use new index.
+        for (int i = 0 ; i < 4; i++) {
+            List<List<?>> locRes = ignite(i).cache("cache").query(new SqlFieldsQuery("explain select \"id\" from " +
+                "\"cache\".\"ValueClass\" where \"field1\" = 'A'").setLocal(true)).getAll();
+
+            assertEquals(F.asList(
+                Collections.singletonList("SELECT\n" +
+                    "    \"id\"\n" +
+                    "FROM \"cache\".\"ValueClass\"\n" +
+                    "    /* \"cache\".\"ValueClass\".__SCAN_ */\n" +
+                    "WHERE \"field1\" = 'A'")
+            ), locRes);
+        }
+
+        assertSize(3);
+    }
+
+    /**
+     * Test that dropping a non-existent index yields an error.
+     */
+    public void testDropMissingIndex() {
+        final IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        assertSqlException(new RunnableX() {
+            @Override public void run() throws Exception {
+                cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1 + "\""));
+            }
+        }, IgniteQueryErrorCode.INDEX_NOT_FOUND);
+    }
+
+    /**
+     * Test that dropping a non-existent index does not yield an error with {@code IF EXISTS}.
+     */
+    public void testDropMissingIndexIfExists() {
+        final IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        cache.query(new SqlFieldsQuery("DROP INDEX IF EXISTS \"" + IDX_NAME_1 + "\""));
+    }
+
+    /**
+     * Test that changes in cache affect index, and vice versa.
+     */
+    public void testIndexState() {
+        IgniteCache<KeyClass, ValueClass> cache = cache();
+
+        assertColumnValues("val1", "val2", "val3");
+
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
+            + FIELD_NAME_1 + "\" ASC)"));
+
+        assertColumnValues("val1", "val2", "val3");
+
+        cache.remove(new KeyClass(2));
+
+        assertColumnValues("val1", "val3");
+
+        cache.put(new KeyClass(0), new ValueClass("someVal"));
+
+        assertColumnValues("someVal", "val1", "val3");
+
+        cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1 + "\""));
+
+        assertColumnValues("someVal", "val1", "val3");
+    }
+
+    /**
+     * Check that values of {@code field1} match what we expect.
+     * @param vals Expected values.
+     */
+    private void assertColumnValues(String... vals) {
+        List<List<?>> expRes = new ArrayList<>(vals.length);
+
+        for (String v : vals)
+            expRes.add(Collections.singletonList(v));
+
+        assertEquals(expRes, cache().query(new SqlFieldsQuery("SELECT \"" + FIELD_NAME_1 + "\" FROM \"" + TBL_NAME +
+            "\" ORDER BY \"id\""))
+            .getAll());
+    }
+
+    /**
+     * Do a {@code SELECT COUNT(*)} query to check index state correctness.
+     * @param expSize Expected number of items in table.
+     */
+    private void assertSize(long expSize) {
+        assertEquals(expSize, cache().size());
+
+        assertEquals(expSize, cache().query(new SqlFieldsQuery("SELECT COUNT(*) from \"ValueClass\""))
+            .getAll().get(0).get(0));
+    }
+
+    /**
+     * Get configurations to be used in test.
+     *
+     * @return Configurations.
+     * @throws Exception If failed.
+     */
+    private List<IgniteConfiguration> configurations() throws Exception {
+        return Arrays.asList(
+            serverConfiguration(0),
+            serverConfiguration(1),
+            clientConfiguration(2),
+            serverConfiguration(3)
+        );
+    }
+
+    /**
+     * @return Client node.
+     */
+    private Ignite client() {
+        return ignite(CLIENT);
+    }
+
+    /**
+     * @return Cache.
+     */
+    private IgniteCache<KeyClass, ValueClass> cache() {
+        return client().cache(CACHE_NAME);
+    }
+
+    /**
+     * Create server configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    private IgniteConfiguration serverConfiguration(int idx) throws Exception {
+        return commonConfiguration(idx);
+    }
+
+    /**
+     * Create client configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    private IgniteConfiguration clientConfiguration(int idx) throws Exception {
+        return commonConfiguration(idx).setClientMode(true);
+    }
+
+    /**
+     * Create common node configuration.
+     *
+     * @param idx Index.
+     * @return Configuration.
+     * @throws Exception If failed.
+     */
+    private IgniteConfiguration commonConfiguration(int idx) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(getTestIgniteInstanceName(idx));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return optimize(cfg);
+    }
+
+    /**
+     * @return Default cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration() {
+        CacheConfiguration<KeyClass, ValueClass> ccfg = new CacheConfiguration<KeyClass, ValueClass>()
+            .setName(CACHE_NAME);
+
+        QueryEntity entity = new QueryEntity();
+
+        entity.setKeyType(KeyClass.class.getName());
+        entity.setValueType(ValueClass.class.getName());
+
+        entity.addQueryField("id", Long.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_1, String.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_2, String.class.getName(), null);
+
+        entity.setKeyFields(Collections.singleton("id"));
+
+        entity.setAliases(Collections.singletonMap(FIELD_NAME_2, alias(FIELD_NAME_2)));
+
+        ccfg.setQueryEntities(Collections.singletonList(entity));
+
+        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+        ccfg.setSqlEscapeAll(true);
+        ccfg.setAtomicityMode(atomicityMode());
+        ccfg.setCacheMode(cacheMode());
+
+        if (nearCache())
+            ccfg.setNearConfiguration(new NearCacheConfiguration<KeyClass, ValueClass>());
+
+        return ccfg;
+    }
+
+    /**
+     * @return Cache mode to use.
+     */
+    protected abstract CacheMode cacheMode();
+
+    /**
+     * @return Cache atomicity mode to use.
+     */
+    protected abstract CacheAtomicityMode atomicityMode();
+
+    /**
+     * @return Whether to use near cache.
+     */
+    protected abstract boolean nearCache();
+
+    /**
+     * Ensure that SQL exception is thrown.
+     *
+     * @param r Runnable.
+     * @param expCode Error code.
+     */
+    private static void assertSqlException(DynamicIndexAbstractBasicSelfTest.RunnableX r, int expCode) {
+        try {
+            try {
+                r.run();
+            }
+            catch (CacheException e) {
+                if (e.getCause() != null)
+                    throw (Exception)e.getCause();
+                else
+                    throw e;
+            }
+        }
+        catch (IgniteSQLException e) {
+            assertEquals("Unexpected error code [expected=" + expCode + ", actual=" + e.statusCode() + ']',
+                expCode, e.statusCode());
+
+            return;
+        }
+        catch (Exception e) {
+            fail("Unexpected exception: " + e);
+        }
+
+        fail(IgniteSQLException.class.getSimpleName() +  " is not thrown.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedNearSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedNearSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedNearSelfTest.java
new file mode 100644
index 0000000..96a7c14
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedNearSelfTest.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+/** */
+public class H2DynamicIndexAtomicPartitionedNearSelfTest extends H2DynamicIndexAtomicPartitionedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedSelfTest.java
new file mode 100644
index 0000000..0a4c48c
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicPartitionedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class H2DynamicIndexAtomicPartitionedSelfTest extends H2DynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicReplicatedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicReplicatedSelfTest.java
new file mode 100644
index 0000000..fc9f9e7
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAtomicReplicatedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class H2DynamicIndexAtomicReplicatedSelfTest extends H2DynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedNearSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedNearSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedNearSelfTest.java
new file mode 100644
index 0000000..e8c4fb2
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedNearSelfTest.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+/** */
+public class H2DynamicIndexTransactionalPartitionedNearSelfTest extends H2DynamicIndexTransactionalPartitionedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedSelfTest.java
new file mode 100644
index 0000000..ad61412
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexTransactionalPartitionedSelfTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+/** */
+public class H2DynamicIndexTransactionalPartitionedSelfTest extends H2DynamicIndexAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean nearCache() {
+        return false;
+    }
+}


[44/50] [abbrv] ignite git commit: IGNITE-4993 - Fixing distributed joins on segmented index.

Posted by sb...@apache.org.
IGNITE-4993 - Fixing distributed joins on segmented index.


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

Branch: refs/heads/ignite-1561
Commit: 800b8bd90033ab64f4299ba242cc89b1f4c98417
Parents: 2ded758
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Wed Apr 19 13:55:02 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Apr 19 13:55:35 2017 +0300

----------------------------------------------------------------------
 .../query/h2/opt/GridH2IndexBase.java           | 31 +++++++++++---------
 .../query/IgniteSqlSegmentedIndexSelfTest.java  |  2 +-
 2 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/800b8bd9/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
index 7163834..0eac559 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
@@ -413,9 +413,7 @@ public abstract class GridH2IndexBase extends BaseIndex {
 
         GridCacheContext<?, ?> cctx = getTable().rowDescriptor().context();
 
-        boolean isLocal = qctx.distributedJoinMode() == LOCAL_ONLY;
-
-        return new DistributedLookupBatch(cctx, ucast, affColId, isLocal);
+        return new DistributedLookupBatch(cctx, ucast, affColId);
     }
 
     /**
@@ -1086,9 +1084,6 @@ public abstract class GridH2IndexBase extends BaseIndex {
         final int affColId;
 
         /** */
-        private final boolean localQuery;
-
-        /** */
         GridH2QueryContext qctx;
 
         /** */
@@ -1113,13 +1108,11 @@ public abstract class GridH2IndexBase extends BaseIndex {
          * @param cctx Cache Cache context.
          * @param ucast Unicast or broadcast query.
          * @param affColId Affinity column ID.
-         * @param localQuery Local query flag.
          */
-        DistributedLookupBatch(GridCacheContext<?, ?> cctx, boolean ucast, int affColId, boolean localQuery) {
+        DistributedLookupBatch(GridCacheContext<?, ?> cctx, boolean ucast, int affColId) {
             this.cctx = cctx;
             this.ucast = ucast;
             this.affColId = affColId;
-            this.localQuery = localQuery;
         }
 
         /**
@@ -1191,25 +1184,26 @@ public abstract class GridH2IndexBase extends BaseIndex {
 
             Object affKey = affColId == -1 ? null : getAffinityKey(firstRow, lastRow);
 
+            boolean locQry = localQuery();
+
             List<SegmentKey> segmentKeys;
-            Future<Cursor> fut;
 
             if (affKey != null) {
                 // Affinity key is provided.
                 if (affKey == EXPLICIT_NULL) // Affinity key is explicit null, we will not find anything.
                     return false;
 
-                segmentKeys = F.asList(rangeSegment(cctx, qctx, affKey, localQuery));
+                segmentKeys = F.asList(rangeSegment(cctx, qctx, affKey, locQry));
             }
             else {
                 // Affinity key is not provided or is not the same in upper and lower bounds, we have to broadcast.
                 if (broadcastSegments == null)
-                    broadcastSegments = broadcastSegments(qctx, cctx, localQuery);
+                    broadcastSegments = broadcastSegments(qctx, cctx, locQry);
 
                 segmentKeys = broadcastSegments;
             }
 
-            if (localQuery && segmentKeys.isEmpty())
+            if (locQry && segmentKeys.isEmpty())
                 return false; // Nothing to do
 
             assert !F.isEmpty(segmentKeys) : segmentKeys;
@@ -1250,7 +1244,7 @@ public abstract class GridH2IndexBase extends BaseIndex {
                     batchFull = true;
             }
 
-            fut = new DoneFuture<>(segmentKeys.size() == 1 ?
+            Future<Cursor> fut = new DoneFuture<>(segmentKeys.size() == 1 ?
                 new UnicastCursor(rangeId, segmentKeys, rangeStreams) :
                 new BroadcastCursor(rangeId, segmentKeys, rangeStreams));
 
@@ -1265,6 +1259,15 @@ public abstract class GridH2IndexBase extends BaseIndex {
         }
 
         /**
+         * @return {@code True} if local query execution is enforced.
+         */
+        private boolean localQuery() {
+            assert qctx != null : "Missing query context: " + this;
+
+            return qctx.distributedJoinMode() == LOCAL_ONLY;
+        }
+
+        /**
          *
          */
         private void startStreams() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/800b8bd9/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
index 1715a56..586b81e 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
@@ -90,7 +90,7 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
 
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(nodesCount(), false);
+        startGrids(nodesCount());
     }
 
     /** {@inheritDoc} */


[15/50] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnsupportedOperationException.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnsupportedOperationException.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnsupportedOperationException.java
new file mode 100644
index 0000000..0fea255
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/UnsupportedOperationException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.exceptions;
+
+import org.apache.ignite.IgniteException;
+
+/**
+ * Indicate that a specific operation is not supported by the underlying implementation.
+ * In some cases, an operation may be unsupported only in certain cases where, for example,
+ * it could not be deterministically completed in polynomial time.
+ */
+public class UnsupportedOperationException extends IgniteException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * @param errMsg Error message.
+     */
+    public UnsupportedOperationException(String errMsg) {
+        super(errMsg);
+    }
+
+    /**
+     *
+     */
+    public UnsupportedOperationException() {
+        this("Unsupported operation.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/package-info.java
new file mode 100644
index 0000000..1990a8a
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/exceptions/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains exceptions for distributed code algebra.
+ */
+package org.apache.ignite.ml.math.exceptions;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..cd48daa
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/Functions.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+/**
+ * Compatibility with Apache Mahout.
+ */
+public final class Functions {
+    /** Function that returns {@code Math.abs(a)}. */
+    public static final IgniteDoubleFunction<Double> ABS = Math::abs;
+
+    /** Function that returns its argument. */
+    public static final IgniteDoubleFunction<Double> IDENTITY = (a) -> a;
+
+    /** Function that returns {@code Math.log(a) / Math.log(2)}. */
+    public static final IgniteDoubleFunction<Double> LOG2 = (a) -> Math.log(a) * 1.4426950408889634;
+
+    /** Function that returns {@code -a}. */
+    public static final IgniteDoubleFunction<Double> NEGATE = (a) -> -a;
+
+    /** Function that returns {@code  a < 0 ? -1 : a > 0 ? 1 : 0 }. */
+    public static final IgniteDoubleFunction<Double> SIGN = (a) -> a < 0.0 ? -1.0 : a > 0.0 ? 1.0 : 0.0;
+
+    /** Function that returns {@code a * a}. */
+    public static final IgniteDoubleFunction<Double> SQUARE = (a) -> a * a;
+
+    /** Function that returns {@code  1 / (1 + exp(-a) } */
+    public static final IgniteDoubleFunction<Double> SIGMOID = (a) -> 1.0 / (1.0 + Math.exp(-a));
+
+    /** Function that returns {@code  1 / a } */
+    public static final IgniteDoubleFunction<Double> INV = (a) -> 1.0 / a;
+
+    /** Function that returns {@code  a * (1-a) } */
+    public static final IgniteDoubleFunction<Double> SIGMOIDGRADIENT = (a) -> a * (1.0 - a);
+
+    /** Function that returns {@code a % b}. */
+    public static final IgniteBiFunction<Double, Double, Double> MOD = (a, b) -> a % b;
+
+    /** Function that returns {@code a * b}. */
+    public static final IgniteBiFunction<Double, Double, Double> MULT = (a, b) -> a * b;
+
+    /** Function that returns {@code Math.log(a) / Math.log(b)}. */
+    public static final IgniteBiFunction<Double, Double, Double> LG = (a, b) -> Math.log(a) / Math.log(b);
+
+    /** Function that returns {@code a + b}. */
+    public static final IgniteBiFunction<Double, Double, Double> PLUS = (a, b) -> a + b;
+
+    /** Function that returns {@code a - b}. */
+    public static final IgniteBiFunction<Double, Double, Double> MINUS = (a, b) -> a - b;
+
+    /** Function that returns {@code abs(a - b)}. */
+    public static final IgniteBiFunction<Double, Double, Double> MINUS_ABS = (a, b) -> Math.abs(a - b);
+
+    /** Function that returns {@code max(abs(a), abs(b))}. */
+    public static final IgniteBiFunction<Double, Double, Double> MAX_ABS = (a, b) -> Math.max(Math.abs(a), Math.abs(b));
+
+    /** Function that returns {@code min(abs(a), abs(b))}. */
+    public static final IgniteBiFunction<Double, Double, Double> MIN_ABS = (a, b) -> Math.min(Math.abs(a), Math.abs(b));
+
+    /** Function that returns {@code Math.abs(a) + Math.abs(b)}. */
+    public static final IgniteBiFunction<Double, Double, Double> PLUS_ABS = (a, b) -> Math.abs(a) + Math.abs(b);
+
+    /** Function that returns {@code (a - b) * (a - b)} */
+    public static final IgniteBiFunction<Double, Double, Double> MINUS_SQUARED = (a, b) -> (a - b) * (a - b);
+
+    /**
+     * Function that returns {@code a &lt; b ? -1 : a &gt; b ? 1 : 0}.
+     */
+    public static final IgniteBiFunction<Double, Double, Double> COMPARE = (a, b) -> a < b ? -1.0 : a > b ? 1.0 : 0.0;
+
+    /**
+     * Function that returns {@code a + b}. {@code a} is a variable, {@code b} is fixed.
+     *
+     * @param b
+     */
+    public static IgniteDoubleFunction<Double> plus(final double b) {
+        return (a) -> a + b;
+    }
+
+    /**
+     * Function that returns {@code a * b}. {@code a} is a variable, {@code b} is fixed.
+     *
+     * @param b
+     */
+    public static IgniteDoubleFunction<Double> mult(final double b) {
+        return (a) -> a * b;
+    }
+
+    /** Function that returns {@code a / b}. {@code a} is a variable, {@code b} is fixed. */
+    public static IgniteDoubleFunction<Double> div(double b) {
+        return mult(1 / b);
+    }
+
+    /**
+     * Function that returns {@code a + b*constant}. {@code a} and {@code b} are variables,
+     * {@code constant} is fixed.
+     */
+    public static IgniteBiFunction<Double, Double, Double> plusMult(double constant) {
+        return (a, b) -> a + b * constant;
+    }
+
+    /**
+     * Function that returns {@code a - b*constant}. {@code a} and {@code b} are variables,
+     * {@code constant} is fixed.
+     */
+    public static IgniteBiFunction<Double, Double, Double> minusMult(double constant) {
+        return (a, b) -> a - b * constant;
+    }
+
+    /**
+     * @param b
+     */
+    public static IgniteDoubleFunction<Double> pow(final double b) {
+        return (a) -> {
+            if (b == 2)
+                return a * a;
+            else
+                return Math.pow(a, b);
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiConsumer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiConsumer.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiConsumer.java
new file mode 100644
index 0000000..f3303cd
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiConsumer.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+import java.io.Serializable;
+import java.util.function.BiConsumer;
+
+/**
+ * Serializable binary consumer.
+ *
+ * @see java.util.function.BiConsumer
+ */
+public interface IgniteBiConsumer<T, U> extends BiConsumer<T, U>, Serializable {
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiFunction.java
new file mode 100644
index 0000000..dc49739
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteBiFunction.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+import java.io.Serializable;
+import java.util.function.BiFunction;
+
+/**
+ * Serializable binary function.
+ *
+ * @see java.util.function.BiFunction
+ */
+public interface IgniteBiFunction<A, B, T> extends BiFunction<A, B, T>, Serializable {
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteConsumer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteConsumer.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteConsumer.java
new file mode 100644
index 0000000..1d52e1d
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteConsumer.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+import java.io.Serializable;
+import java.util.function.Consumer;
+
+/**
+ * Serializable consumer.
+ *
+ * @see java.util.function.Consumer
+ */
+public interface IgniteConsumer<T> extends Consumer<T>, Serializable {
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteDoubleFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteDoubleFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteDoubleFunction.java
new file mode 100644
index 0000000..dfbf393
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteDoubleFunction.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+import java.io.Serializable;
+import java.util.function.DoubleFunction;
+
+/**
+ * Serializable double function.
+ *
+ * @see java.util.function.DoubleFunction
+ */
+public interface IgniteDoubleFunction<Double> extends DoubleFunction<Double>, Serializable {
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteFunction.java
new file mode 100644
index 0000000..9d19592
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IgniteFunction.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+import java.io.Serializable;
+import java.util.function.Function;
+
+/**
+ * Serializable function.
+ *
+ * @see java.util.function.Function
+ */
+public interface IgniteFunction<T, R> extends Function<T, R>, Serializable {
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntDoubleToVoidFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntDoubleToVoidFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntDoubleToVoidFunction.java
new file mode 100644
index 0000000..981e0c5
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntDoubleToVoidFunction.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+/**
+ * Setter function for the vector.
+ */
+public interface IntDoubleToVoidFunction extends IgniteBiConsumer<Integer, Double> {
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntDoubleToVoidFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntDoubleToVoidFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntDoubleToVoidFunction.java
new file mode 100644
index 0000000..a9b3f9c
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntDoubleToVoidFunction.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+import java.io.Serializable;
+
+/**
+ * Setter function for matrices.
+ */
+public interface IntIntDoubleToVoidFunction extends Serializable {
+    /** */
+    public void apply(int x, int y, double v);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntToDoubleFunction.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntToDoubleFunction.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntToDoubleFunction.java
new file mode 100644
index 0000000..5fabfb7
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/IntIntToDoubleFunction.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.functions;
+
+/**
+ * Getters functions for matrices.
+ */
+public interface IntIntToDoubleFunction extends IgniteBiFunction<Integer, Integer, Double> {
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/package-info.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/package-info.java
new file mode 100644
index 0000000..d41f94d
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/functions/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains serializable functions for distributed code algebra.
+ */
+package org.apache.ignite.ml.math.functions;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/CacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/CacheUtils.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/CacheUtils.java
new file mode 100644
index 0000000..cfb01be
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/CacheUtils.java
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cluster.ClusterGroup;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.ml.math.KeyMapper;
+import org.apache.ignite.ml.math.ValueMapper;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteConsumer;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+
+/**
+ * Distribution-related misc. support.
+ */
+public class CacheUtils {
+    /**
+     * Cache entry support.
+     *
+     * @param <K>
+     * @param <V>
+     */
+    public static class CacheEntry<K, V> {
+        /** */
+        private Cache.Entry<K, V> entry;
+        /** */
+        private IgniteCache<K, V> cache;
+
+        /**
+         * @param entry Original cache entry.
+         * @param cache Cache instance.
+         */
+        CacheEntry(Cache.Entry<K, V> entry, IgniteCache<K, V> cache) {
+            this.entry = entry;
+            this.cache = cache;
+        }
+
+        /**
+         *
+         *
+         */
+        public Cache.Entry<K, V> entry() {
+            return entry;
+        }
+
+        /**
+         *
+         *
+         */
+        public IgniteCache<K, V> cache() {
+            return cache;
+        }
+    }
+
+    /**
+     * Gets local Ignite instance.
+     */
+    public static Ignite ignite() {
+        return Ignition.localIgnite();
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param k Key into the cache.
+     * @param <K> Key type.
+     * @return Cluster group for given key.
+     */
+    public static <K> ClusterGroup groupForKey(String cacheName, K k) {
+        return ignite().cluster().forNode(ignite().affinity(cacheName).mapKeyToNode(k));
+    }
+
+    /**
+     * @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.
+     * @return Sum of the values obtained for valid keys.
+     */
+    public static <K, V> double sum(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
+        Collection<Double> subSums = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
+            if (keyMapper.isValid(ce.entry().getKey())) {
+                double v = valMapper.toDouble(ce.entry().getValue());
+
+                return acc == null ? v : acc + v;
+            }
+            else
+                return acc;
+        });
+
+        return sum(subSums);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Sum obtained using sparse logic.
+     */
+    public static <K, V> double sparseSum(String cacheName) {
+        Collection<Double> subSums = fold(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce, Double acc) -> {
+            Map<Integer, Double> map = ce.entry().getValue();
+
+            double sum = sum(map.values());
+
+            return acc == null ? sum : acc + sum;
+        });
+
+        return sum(subSums);
+    }
+
+    /**
+     * @param c {@link Collection} of double values to sum.
+     * @return Sum of the values.
+     */
+    private static double sum(Collection<Double> c) {
+        double sum = 0.0;
+
+        for (double d : c)
+            sum += d;
+
+        return sum;
+    }
+
+    /**
+     * @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.
+     * @return Minimum value for valid keys.
+     */
+    public static <K, V> double min(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
+        Collection<Double> mins = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
+            if (keyMapper.isValid(ce.entry().getKey())) {
+                double v = valMapper.toDouble(ce.entry().getValue());
+
+                if (acc == null)
+                    return v;
+                else
+                    return Math.min(acc, v);
+            }
+            else
+                return acc;
+        });
+
+        return Collections.min(mins);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Minimum value obtained using sparse logic.
+     */
+    public static <K, V> double sparseMin(String cacheName) {
+        Collection<Double> mins = fold(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce, Double acc) -> {
+            Map<Integer, Double> map = ce.entry().getValue();
+
+            double min = Collections.min(map.values());
+
+            if (acc == null)
+                return min;
+            else
+                return Math.min(acc, min);
+        });
+
+        return Collections.min(mins);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Maximum value obtained using sparse logic.
+     */
+    public static <K, V> double sparseMax(String cacheName) {
+        Collection<Double> maxes = fold(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce, Double acc) -> {
+            Map<Integer, Double> map = ce.entry().getValue();
+
+            double max = Collections.max(map.values());
+
+            if (acc == null)
+                return max;
+            else
+                return Math.max(acc, max);
+        });
+
+        return Collections.max(maxes);
+    }
+
+    /**
+     * @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.
+     * @return Maximum value for valid keys.
+     */
+    public static <K, V> double max(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper) {
+        Collection<Double> maxes = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
+            if (keyMapper.isValid(ce.entry().getKey())) {
+                double v = valMapper.toDouble(ce.entry().getValue());
+
+                if (acc == null)
+                    return v;
+                else
+                    return Math.max(acc, v);
+            }
+            else
+                return acc;
+        });
+
+        return Collections.max(maxes);
+    }
+
+    /**
+     * @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.
+     */
+    public static <K, V> void map(String cacheName, KeyMapper<K> keyMapper, ValueMapper<V> valMapper,
+        IgniteFunction<Double, Double> mapper) {
+        foreach(cacheName, (CacheEntry<K, V> ce) -> {
+            K k = ce.entry().getKey();
+
+            if (keyMapper.isValid(k))
+                // Actual assignment.
+                ce.cache().put(k, valMapper.fromDouble(mapper.apply(valMapper.toDouble(ce.entry().getValue()))));
+        });
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param mapper Mapping {@link IgniteFunction}.
+     */
+    public static <K, V> void sparseMap(String cacheName, IgniteFunction<Double, Double> mapper) {
+        foreach(cacheName, (CacheEntry<Integer, Map<Integer, Double>> ce) -> {
+            Integer k = ce.entry().getKey();
+            Map<Integer, Double> v = ce.entry().getValue();
+
+            for (Map.Entry<Integer, Double> e : v.entrySet())
+                e.setValue(mapper.apply(e.getValue()));
+
+            ce.cache().put(k, v);
+        });
+    }
+
+    /**
+     * @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.
+     */
+    public static <K, V> void foreach(String cacheName, IgniteConsumer<CacheEntry<K, V>> fun) {
+        bcast(cacheName, () -> {
+            Ignite ignite = Ignition.localIgnite();
+            IgniteCache<K, V> cache = ignite.getOrCreateCache(cacheName);
+
+            int partsCnt = ignite.affinity(cacheName).partitions();
+
+            // Use affinity in filter for scan query. Otherwise we accept consumer in each node which is wrong.
+            Affinity affinity = ignite.affinity(cacheName);
+            ClusterNode locNode = ignite.cluster().localNode();
+
+            // Iterate over all partitions. Some of them will be stored on that local node.
+            for (int part = 0; part < partsCnt; part++) {
+                int p = part;
+
+                // 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)))
+                    fun.accept(new CacheEntry<>(entry, cache));
+            }
+        });
+    }
+
+    /**
+     * <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.
+     * @return Fold operation result.
+     */
+    public static <K, V, A> Collection<A> fold(String cacheName, IgniteBiFunction<CacheEntry<K, V>, A, A> folder) {
+        return bcast(cacheName, () -> {
+            Ignite ignite = Ignition.localIgnite();
+            IgniteCache<K, V> cache = ignite.getOrCreateCache(cacheName);
+
+            int partsCnt = ignite.affinity(cacheName).partitions();
+
+            // Use affinity in filter for ScanQuery. Otherwise we accept consumer in each node which is wrong.
+            Affinity affinity = ignite.affinity(cacheName);
+            ClusterNode locNode = ignite.cluster().localNode();
+
+            A a = null;
+
+            // Iterate over all partitions. Some of them will be stored on that local node.
+            for (int part = 0; part < partsCnt; part++) {
+                int p = part;
+
+                // 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)))
+                    a = folder.apply(new CacheEntry<>(entry, cache), a);
+            }
+
+            return a;
+        });
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param run {@link Runnable} to broadcast to cache nodes for given cache name.
+     */
+    public static void bcast(String cacheName, IgniteRunnable run) {
+        ignite().compute(ignite().cluster().forCacheNodes(cacheName)).broadcast(run);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @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 ignite().compute(ignite().cluster().forCacheNodes(cacheName)).broadcast(call);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/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
new file mode 100644
index 0000000..c5edeb1
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/AbstractMatrix.java
@@ -0,0 +1,880 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.decompositions.LUDecomposition;
+import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.exceptions.ColumnIndexException;
+import org.apache.ignite.ml.math.exceptions.RowIndexException;
+import org.apache.ignite.ml.math.functions.Functions;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
+import org.apache.ignite.ml.math.impls.vector.MatrixVectorView;
+
+/**
+ * This class provides a helper implementation of the {@link Matrix}
+ * interface to minimize the effort required to implement it.
+ * Subclasses may override some of the implemented methods if a more
+ * specific or optimized implementation is desirable.
+ *
+ * TODO: add row/column optimization.
+ */
+public abstract class AbstractMatrix implements Matrix {
+    // Stochastic sparsity analysis.
+    /** */
+    private static final double Z95 = 1.959964;
+    /** */
+    private static final double Z80 = 1.281552;
+    /** */
+    private static final int MAX_SAMPLES = 500;
+    /** */
+    private static final int MIN_SAMPLES = 15;
+
+    /** Cached minimum element. */
+    private Element minElm;
+    /** Cached maximum element. */
+    private Element maxElm = null;
+
+    /** Matrix storage implementation. */
+    private MatrixStorage sto;
+
+    /** Meta attributes storage. */
+    private Map<String, Object> meta = new HashMap<>();
+
+    /** Matrix's GUID. */
+    private IgniteUuid guid = IgniteUuid.randomUuid();
+
+    /**
+     * @param sto Backing {@link MatrixStorage}.
+     */
+    public AbstractMatrix(MatrixStorage sto) {
+        this.sto = sto;
+    }
+
+    /**
+     *
+     */
+    public AbstractMatrix() {
+        // No-op.
+    }
+
+    /**
+     * @param sto Backing {@link MatrixStorage}.
+     */
+    protected void setStorage(MatrixStorage sto) {
+        assert sto != null;
+
+        this.sto = sto;
+    }
+
+    /**
+     * @param row Row index in the matrix.
+     * @param col Column index in the matrix.
+     * @param v Value to set.
+     */
+    protected void storageSet(int row, int col, double v) {
+        sto.set(row, col, v);
+
+        // Reset cached values.
+        minElm = maxElm = null;
+    }
+
+    /**
+     * @param row Row index in the matrix.
+     * @param col Column index in the matrix.
+     */
+    protected double storageGet(int row, int col) {
+        return sto.get(row, col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element maxElement() {
+        if (maxElm == null) {
+            double max = Double.NEGATIVE_INFINITY;
+            int row = 0, col = 0;
+
+            int rows = rowSize();
+            int cols = columnSize();
+
+            for (int x = 0; x < rows; x++)
+                for (int y = 0; y < cols; y++) {
+                    double d = storageGet(x, y);
+
+                    if (d > max) {
+                        max = d;
+                        row = x;
+                        col = y;
+                    }
+                }
+
+            maxElm = mkElement(row, col);
+        }
+
+        return maxElm;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element minElement() {
+        if (minElm == null) {
+            double min = Double.MAX_VALUE;
+            int row = 0, col = 0;
+
+            int rows = rowSize();
+            int cols = columnSize();
+
+            for (int x = 0; x < rows; x++)
+                for (int y = 0; y < cols; y++) {
+                    double d = storageGet(x, y);
+
+                    if (d < min) {
+                        min = d;
+                        row = x;
+                        col = y;
+                    }
+                }
+
+            minElm = mkElement(row, col);
+        }
+
+        return minElm;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxValue() {
+        return maxElement().get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double minValue() {
+        return minElement().get();
+    }
+
+    /**
+     * @param row Row index in the matrix.
+     * @param col Column index in the matrix.
+     */
+    private Element mkElement(int row, int col) {
+        return new Element() {
+            /** {@inheritDoc} */
+            @Override public double get() {
+                return storageGet(row, col);
+            }
+
+            /** {@inheritDoc} */
+            @Override public int row() {
+                return row;
+            }
+
+            /** {@inheritDoc} */
+            @Override public int column() {
+                return col;
+            }
+
+            /** {@inheritDoc} */
+            @Override public void set(double d) {
+                storageSet(row, col, d);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Element getElement(int row, int col) {
+        return mkElement(row, col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix swapRows(int row1, int row2) {
+        checkRowIndex(row1);
+        checkRowIndex(row2);
+
+        int cols = columnSize();
+
+        for (int y = 0; y < cols; y++) {
+            double v = getX(row1, y);
+
+            setX(row1, y, getX(row2, y));
+            setX(row2, y, v);
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix swapColumns(int col1, int col2) {
+        checkColumnIndex(col1);
+        checkColumnIndex(col2);
+
+        int rows = rowSize();
+
+        for (int x = 0; x < rows; x++) {
+            double v = getX(x, col1);
+
+            setX(x, col1, getX(x, col2));
+            setX(x, col2, v);
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public MatrixStorage getStorage() {
+        return sto;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSequentialAccess() {
+        return sto.isSequentialAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDense() {
+        return sto.isDense();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isRandomAccess() {
+        return sto.isRandomAccess();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isDistributed() {
+        return sto.isDistributed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isArrayBased() {
+        return sto.isArrayBased();
+    }
+
+    /**
+     * Check row index bounds.
+     *
+     * @param row Row index.
+     */
+    private void checkRowIndex(int row) {
+        if (row < 0 || row >= rowSize())
+            throw new RowIndexException(row);
+    }
+
+    /**
+     * Check column index bounds.
+     *
+     * @param col Column index.
+     */
+    private void checkColumnIndex(int col) {
+        if (col < 0 || col >= columnSize())
+            throw new ColumnIndexException(col);
+    }
+
+    /**
+     * Check column and row index bounds.
+     *
+     * @param row Row index.
+     * @param col Column index.
+     */
+    protected void checkIndex(int row, int col) {
+        checkRowIndex(row);
+        checkColumnIndex(col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(sto);
+        out.writeObject(meta);
+        out.writeObject(guid);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map<String, Object> getMetaStorage() {
+        return meta;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        sto = (MatrixStorage)in.readObject();
+        meta = (Map<String, Object>)in.readObject();
+        guid = (IgniteUuid)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assign(double val) {
+        if (sto.isArrayBased())
+            for (double[] column : sto.data())
+                Arrays.fill(column, val);
+        else {
+            int rows = rowSize();
+            int cols = columnSize();
+
+            for (int x = 0; x < rows; x++)
+                for (int y = 0; y < cols; y++)
+                    storageSet(x, y, val);
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assign(IntIntToDoubleFunction fun) {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                storageSet(x, y, fun.apply(x, y));
+
+        return this;
+    }
+
+    /** */
+    private void checkCardinality(Matrix mtx) {
+        checkCardinality(mtx.rowSize(), mtx.columnSize());
+    }
+
+    /** */
+    private void checkCardinality(int rows, int cols) {
+        if (rows != rowSize())
+            throw new CardinalityException(rowSize(), rows);
+
+        if (cols != columnSize())
+            throw new CardinalityException(columnSize(), cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assign(double[][] vals) {
+        checkCardinality(vals.length, vals[0].length);
+
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                storageSet(x, y, vals[x][y]);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assign(Matrix mtx) {
+        checkCardinality(mtx);
+
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                storageSet(x, y, mtx.getX(x, y));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix map(IgniteDoubleFunction<Double> fun) {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                storageSet(x, y, fun.apply(storageGet(x, y)));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix map(Matrix mtx, IgniteBiFunction<Double, Double, Double> fun) {
+        checkCardinality(mtx);
+
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                storageSet(x, y, fun.apply(storageGet(x, y), mtx.getX(x, y)));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assignColumn(int col, Vector vec) {
+        checkColumnIndex(col);
+
+        int rows = rowSize();
+
+        for (int x = 0; x < rows; x++)
+            storageSet(x, col, vec.getX(x));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assignRow(int row, Vector vec) {
+        checkRowIndex(row);
+
+        int cols = columnSize();
+
+        if (cols != vec.size())
+            throw new CardinalityException(cols, vec.size());
+
+        if (sto.isArrayBased() && vec.getStorage().isArrayBased())
+            System.arraycopy(vec.getStorage().data(), 0, sto.data()[row], 0, cols);
+        else
+            for (int y = 0; y < cols; y++)
+                storageSet(row, y, vec.getX(y));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector foldRows(IgniteFunction<Vector, Double> fun) {
+        int rows = rowSize();
+
+        Vector vec = likeVector(rows);
+
+        for (int i = 0; i < rows; i++)
+            vec.setX(i, fun.apply(viewRow(i)));
+
+        return vec;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector foldColumns(IgniteFunction<Vector, Double> fun) {
+        int cols = columnSize();
+
+        Vector vec = likeVector(cols);
+
+        for (int i = 0; i < cols; i++)
+            vec.setX(i, fun.apply(viewColumn(i)));
+
+        return vec;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T foldMap(IgniteBiFunction<T, Double, T> foldFun, IgniteDoubleFunction<Double> mapFun,
+        T zeroVal) {
+        T res = zeroVal;
+
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                res = foldFun.apply(res, mapFun.apply(storageGet(x, y)));
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int columnSize() {
+        return sto.columnSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int rowSize() {
+        return sto.rowSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public double determinant() {
+        //TODO: This decomposition should be cached
+        LUDecomposition dec = new LUDecomposition(this);
+        double res = dec.determinant();
+        dec.destroy();
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix inverse() {
+        if (rowSize() != columnSize())
+            throw new CardinalityException(rowSize(), columnSize());
+
+        //TODO: This decomposition should be cached
+        LUDecomposition dec = new LUDecomposition(this);
+
+        Matrix res = dec.solve(likeIdentity());
+        dec.destroy();
+
+        return res;
+    }
+
+    /** */
+    protected Matrix likeIdentity() {
+        int n = rowSize();
+        Matrix res = like(n, n);
+
+        for (int i = 0; i < n; i++)
+            res.setX(i, i, 1.0);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix divide(double d) {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                setX(x, y, getX(x, y) / d);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double get(int row, int col) {
+        checkIndex(row, col);
+
+        return storageGet(row, col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double getX(int row, int col) {
+        return storageGet(row, col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix minus(Matrix mtx) {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        checkCardinality(rows, cols);
+
+        Matrix res = like(rows, cols);
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                res.setX(x, y, getX(x, y) - mtx.getX(x, y));
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix plus(double x) {
+        Matrix cp = copy();
+
+        cp.map(Functions.plus(x));
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix plus(Matrix mtx) {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        checkCardinality(rows, cols);
+
+        Matrix res = like(rows, cols);
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                res.setX(x, y, getX(x, y) + mtx.getX(x, y));
+
+        return res;
+
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid guid() {
+        return guid;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix set(int row, int col, double val) {
+        checkIndex(row, col);
+
+        storageSet(row, col, val);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix setRow(int row, double[] data) {
+        checkRowIndex(row);
+
+        int cols = columnSize();
+
+        if (cols != data.length)
+            throw new CardinalityException(cols, data.length);
+
+        if (sto.isArrayBased())
+            System.arraycopy(data, 0, sto.data()[row], 0, cols);
+        else
+            for (int y = 0; y < cols; y++)
+                setX(row, y, data[y]);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix setColumn(int col, double[] data) {
+        checkColumnIndex(col);
+
+        int rows = rowSize();
+
+        if (rows != data.length)
+            throw new CardinalityException(rows, data.length);
+
+        for (int x = 0; x < rows; x++)
+            setX(x, col, data[x]);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix setX(int row, int col, double val) {
+        storageSet(row, col, val);
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix times(double x) {
+        Matrix cp = copy();
+
+        cp.map(Functions.mult(x));
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxAbsRowSumNorm() {
+        double max = 0.0;
+
+        int rows = rowSize();
+        int cols = columnSize();
+
+        for (int x = 0; x < rows; x++) {
+            double sum = 0;
+
+            for (int y = 0; y < cols; y++)
+                sum += Math.abs(getX(x, y));
+
+            if (sum > max)
+                max = sum;
+        }
+
+        return max;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector times(Vector vec) {
+        int cols = columnSize();
+
+        if (cols != vec.size())
+            throw new CardinalityException(cols, vec.size());
+
+        int rows = rowSize();
+
+        Vector res = likeVector(rows);
+
+        for (int x = 0; x < rows; x++)
+            res.setX(x, vec.dot(viewRow(x)));
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix times(Matrix mtx) {
+        int cols = columnSize();
+
+        if (cols != mtx.rowSize())
+            throw new CardinalityException(cols, mtx.rowSize());
+
+        int rows = rowSize();
+
+        int mtxCols = mtx.columnSize();
+
+        Matrix res = like(rows, mtxCols);
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < mtxCols; y++) {
+                double sum = 0.0;
+
+                for (int k = 0; k < cols; k++)
+                    sum += getX(x, k) * mtx.getX(k, y);
+
+                res.setX(x, y, sum);
+            }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        double sum = 0.0;
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                sum += getX(x, y);
+
+        return sum;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix transpose() {
+        int rows = rowSize();
+        int cols = columnSize();
+
+        Matrix mtx = like(cols, rows);
+
+        for (int x = 0; x < rows; x++)
+            for (int y = 0; y < cols; y++)
+                mtx.setX(y, x, getX(x, y));
+
+        return mtx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean density(double threshold) {
+        assert threshold >= 0.0 && threshold <= 1.0;
+
+        int n = MIN_SAMPLES;
+        int rows = rowSize();
+        int cols = columnSize();
+
+        double mean = 0.0;
+        double pq = threshold * (1 - threshold);
+
+        Random rnd = new Random();
+
+        for (int i = 0; i < MIN_SAMPLES; i++)
+            if (getX(rnd.nextInt(rows), rnd.nextInt(cols)) != 0.0)
+                mean++;
+
+        mean /= MIN_SAMPLES;
+
+        double iv = Z80 * Math.sqrt(pq / n);
+
+        if (mean < threshold - iv)
+            return false; // Sparse.
+        else if (mean > threshold + iv)
+            return true; // Dense.
+
+        while (n < MAX_SAMPLES) {
+            // Determine upper bound we may need for 'n' to likely relinquish the uncertainty.
+            // Here, we use confidence interval formula but solved for 'n'.
+            double ivX = Math.max(Math.abs(threshold - mean), 1e-11);
+
+            double stdErr = ivX / Z80;
+            double nX = Math.min(Math.max((int)Math.ceil(pq / (stdErr * stdErr)), n), MAX_SAMPLES) - n;
+
+            if (nX < 1.0) // IMPL NOTE this can happen with threshold 1.0
+                nX = 1.0;
+
+            double meanNext = 0.0;
+
+            for (int i = 0; i < nX; i++)
+                if (getX(rnd.nextInt(rows), rnd.nextInt(cols)) != 0.0)
+                    meanNext++;
+
+            mean = (n * mean + meanNext) / (n + nX);
+
+            n += nX;
+
+            // Are we good now?
+            iv = Z80 * Math.sqrt(pq / n);
+
+            if (mean < threshold - iv)
+                return false; // Sparse.
+            else if (mean > threshold + iv)
+                return true; // Dense.
+        }
+
+        return mean > threshold; // Dense if mean > threshold.
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix viewPart(int[] off, int[] size) {
+        return new MatrixView(this, off[0], off[1], size[0], size[1]);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix viewPart(int rowOff, int rows, int colOff, int cols) {
+        return viewPart(new int[] {rowOff, colOff}, new int[] {rows, cols});
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewRow(int row) {
+        return new MatrixVectorView(this, row, 0, 0, 1);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewColumn(int col) {
+        return new MatrixVectorView(this, 0, col, 1, 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewDiagonal() {
+        return new MatrixVectorView(this, 0, 0, 1, 1);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        Matrix cp = like(rowSize(), columnSize());
+
+        cp.assign(this);
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = 1;
+
+        res = res * 37 + guid.hashCode();
+        res = res * 37 + sto.hashCode();
+        res = res * 37 + meta.hashCode();
+
+        return res;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * We ignore guid's for comparisons.
+     */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        AbstractMatrix that = (AbstractMatrix)o;
+
+        MatrixStorage sto = getStorage();
+
+        return (sto != null ? sto.equals(that.getStorage()) : that.getStorage() == null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrix.java
new file mode 100644
index 0000000..73a3493
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/CacheMatrix.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixKeyMapper;
+import org.apache.ignite.ml.math.ValueMapper;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.impls.CacheUtils;
+import org.apache.ignite.ml.math.impls.storage.matrix.CacheMatrixStorage;
+
+/**
+ * Matrix based on existing cache and key and value mapping functions.
+ */
+public class CacheMatrix<K, V> extends AbstractMatrix {
+    /**
+     *
+     */
+    public CacheMatrix() {
+        // No-op.
+    }
+
+    /**
+     * Creates new matrix over existing cache.
+     *
+     * @param rows
+     * @param cols
+     * @param cache
+     * @param keyMapper
+     * @param valMapper
+     */
+    public CacheMatrix(
+        int rows,
+        int cols,
+        IgniteCache<K, V> cache,
+        MatrixKeyMapper<K> keyMapper,
+        ValueMapper<V> valMapper) {
+        assert rows > 0;
+        assert cols > 0;
+        assert cache != null;
+        assert keyMapper != null;
+        assert valMapper != null;
+
+        setStorage(new CacheMatrixStorage<>(rows, cols, cache, keyMapper, valMapper));
+    }
+
+    /**
+     *
+     *
+     */
+    @SuppressWarnings({"unchecked"})
+    private CacheMatrixStorage<K, V> storage() {
+        return (CacheMatrixStorage<K, V>)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Return the same matrix with updates values (broken contract).
+     *
+     * @param d
+     */
+    @Override public Matrix divide(double d) {
+        return mapOverValues((Double v) -> v / d);
+    }
+
+    /**
+     * Return the same matrix with updates values (broken contract).
+     *
+     * @param x
+     */
+    @Override public Matrix plus(double x) {
+        return mapOverValues((Double v) -> v + x);
+    }
+
+    /**
+     * Return the same matrix with updates values (broken contract).
+     *
+     * @param x
+     */
+    @Override public Matrix times(double x) {
+        return mapOverValues((Double v) -> v * x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix assign(double val) {
+        return mapOverValues((Double v) -> val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix map(IgniteDoubleFunction<Double> fun) {
+        return mapOverValues(fun::apply);
+    }
+
+    /** {@inheritDoc} */
+    @Override public double sum() {
+        CacheMatrixStorage<K, V> sto = storage();
+
+        return CacheUtils.sum(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double maxValue() {
+        CacheMatrixStorage<K, V> sto = storage();
+
+        return CacheUtils.max(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double minValue() {
+        CacheMatrixStorage<K, V> sto = storage();
+
+        return CacheUtils.min(sto.cache().getName(), sto.keyMapper(), sto.valueMapper());
+    }
+
+    /**
+     * @param mapper
+     */
+    private Matrix mapOverValues(IgniteFunction<Double, Double> mapper) {
+        CacheMatrixStorage<K, V> sto = storage();
+
+        CacheUtils.map(sto.cache().getName(), sto.keyMapper(), sto.valueMapper(), mapper);
+
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrix.java
new file mode 100644
index 0000000..4161228
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOffHeapMatrix.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.storage.matrix.DenseOffHeapMatrixStorage;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector;
+
+/**
+ * Dense local off-heap implementation of the {@link Matrix} interface.
+ */
+public class DenseLocalOffHeapMatrix extends AbstractMatrix {
+    /** */
+    public DenseLocalOffHeapMatrix() {
+        // No-op.
+    }
+
+    /**
+     * @param data Backing data array.
+     */
+    public DenseLocalOffHeapMatrix(double[][] data) {
+        assert data != null;
+
+        setStorage(new DenseOffHeapMatrixStorage(data));
+    }
+
+    /**
+     * @param rows Amount of rows in matrix.
+     * @param cols Amount of columns in matrix.
+     */
+    public DenseLocalOffHeapMatrix(int rows, int cols) {
+        assert rows > 0;
+        assert cols > 0;
+
+        setStorage(new DenseOffHeapMatrixStorage(rows, cols));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        DenseLocalOffHeapMatrix cp = new DenseLocalOffHeapMatrix(getStorage().rowSize(), getStorage().columnSize());
+
+        cp.assign(this);
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        return new DenseLocalOffHeapMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        return new DenseLocalOffHeapVector(crd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() {
+        getStorage().destroy();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Matrix likeIdentity() {
+        int n = rowSize();
+        Matrix res = like(n, n);
+
+        // IMPL NOTE as opposed to on-heap matrices this one isn't initialized with zeroes
+        for (int i = 0; i < n; i++)
+            for (int j = 0; j < n; j++)
+                res.setX(i, j, i == j ? 1.0 : 0.0);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrix.java
new file mode 100644
index 0000000..f95e0cc
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DenseLocalOnHeapMatrix.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.storage.matrix.ArrayMatrixStorage;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+
+/**
+ * Basic implementation for matrix.
+ *
+ * This is a trivial implementation for matrix assuming dense logic, local on-heap JVM storage
+ * based on <code>double[][]</code> array. It is only suitable for data sets where
+ * local, non-distributed execution is satisfactory and on-heap JVM storage is enough
+ * to keep the entire data set.
+ */
+public class DenseLocalOnHeapMatrix extends AbstractMatrix {
+    /**
+     *
+     */
+    public DenseLocalOnHeapMatrix() {
+        // No-op.
+    }
+
+    /**
+     * @param rows Amount of rows in matrix.
+     * @param cols Amount of columns in matrix.
+     */
+    public DenseLocalOnHeapMatrix(int rows, int cols) {
+        assert rows > 0;
+        assert cols > 0;
+
+        setStorage(new ArrayMatrixStorage(rows, cols));
+    }
+
+    /**
+     * @param mtx Backing data array.
+     */
+    public DenseLocalOnHeapMatrix(double[][] mtx) {
+        assert mtx != null;
+
+        setStorage(new ArrayMatrixStorage(mtx));
+    }
+
+    /**
+     * @param orig Original matrix.
+     */
+    private DenseLocalOnHeapMatrix(DenseLocalOnHeapMatrix orig) {
+        assert orig != null;
+
+        setStorage(new ArrayMatrixStorage(orig.rowSize(), orig.columnSize()));
+
+        assign(orig);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        return new DenseLocalOnHeapMatrix(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        return new DenseLocalOnHeapMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        return new DenseLocalOnHeapVector(crd);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrix.java
new file mode 100644
index 0000000..bd9a4a1
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/DiagonalMatrix.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.storage.matrix.DiagonalMatrixStorage;
+import org.apache.ignite.ml.math.impls.vector.ConstantVector;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.apache.ignite.ml.math.impls.vector.SingleElementVectorView;
+
+/**
+ * Implementation of diagonal view of the {@link Matrix}.
+ *
+ * <p>See also: <a href="https://en.wikipedia.org/wiki/Diagonal_matrix">Wikipedia article</a>.</p>
+ */
+public class DiagonalMatrix extends AbstractMatrix {
+    /**
+     *
+     */
+    public DiagonalMatrix() {
+        // No-op.
+    }
+
+    /**
+     * @param diagonal Backing {@link Vector}.
+     */
+    public DiagonalMatrix(Vector diagonal) {
+        super(new DiagonalMatrixStorage(diagonal));
+    }
+
+    /**
+     * @param mtx Backing {@link Matrix}.
+     */
+    public DiagonalMatrix(Matrix mtx) {
+        super(new DiagonalMatrixStorage(mtx == null ? null : mtx.viewDiagonal()));
+    }
+
+    /**
+     * @param vals Backing array of values at diagonal.
+     */
+    public DiagonalMatrix(double[] vals) {
+        super(new DiagonalMatrixStorage(new DenseLocalOnHeapVector(vals)));
+    }
+
+    /**
+     *
+     *
+     */
+    private DiagonalMatrixStorage storage() {
+        return (DiagonalMatrixStorage)getStorage();
+    }
+
+    /**
+     * @param size Size of diagonal.
+     * @param val Constant value at diagonal.
+     */
+    public DiagonalMatrix(int size, double val) {
+        super(new DiagonalMatrixStorage(new ConstantVector(size, val)));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewRow(int row) {
+        return new SingleElementVectorView(storage().diagonal(), row);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector viewColumn(int col) {
+        return new SingleElementVectorView(storage().diagonal(), col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        return new DiagonalMatrix(storage().diagonal());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        return storage().diagonal().likeMatrix(rows, cols);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        return storage().diagonal().like(crd);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrix.java
new file mode 100644
index 0000000..020d50a
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/FunctionMatrix.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.functions.IntIntDoubleToVoidFunction;
+import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
+import org.apache.ignite.ml.math.impls.storage.matrix.FunctionMatrixStorage;
+
+/**
+ * Implementation of {@link Matrix} that maps row and column index to {@link java.util.function} interfaces.
+ */
+public class FunctionMatrix extends AbstractMatrix {
+    /**
+     *
+     */
+    public FunctionMatrix() {
+        // No-op.
+    }
+
+    /**
+     * Creates read-write or read-only function matrix.
+     *
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param getFunc Function that returns value corresponding to given row and column index.
+     * @param setFunc Set function. If {@code null} - this will be a read-only matrix.
+     */
+    public FunctionMatrix(int rows, int cols, IntIntToDoubleFunction getFunc, IntIntDoubleToVoidFunction setFunc) {
+        assert rows > 0;
+        assert cols > 0;
+        assert getFunc != null;
+
+        setStorage(new FunctionMatrixStorage(rows, cols, getFunc, setFunc));
+    }
+
+    /**
+     * Creates read-only function matrix.
+     *
+     * @param rows Amount of rows in the matrix.
+     * @param cols Amount of columns in the matrix.
+     * @param getFunc Function that returns value corresponding to given row and column index.
+     */
+    public FunctionMatrix(int rows, int cols, IntIntToDoubleFunction getFunc) {
+        assert rows > 0;
+        assert cols > 0;
+        assert getFunc != null;
+
+        setStorage(new FunctionMatrixStorage(rows, cols, getFunc));
+    }
+
+    /**
+     *
+     *
+     */
+    private FunctionMatrixStorage storage() {
+        return (FunctionMatrixStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        FunctionMatrixStorage sto = storage();
+
+        return new FunctionMatrix(sto.rowSize(), sto.columnSize(), sto.getFunction(), sto.setFunction());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        FunctionMatrixStorage sto = storage();
+
+        return new FunctionMatrix(rows, cols, sto.getFunction(), sto.setFunction());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/MatrixView.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/MatrixView.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/MatrixView.java
new file mode 100644
index 0000000..89b031e
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/MatrixView.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.math.impls.matrix;
+
+import java.io.Externalizable;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.impls.storage.matrix.MatrixDelegateStorage;
+
+/**
+ * Implements the rectangular view into the parent {@link Matrix}.
+ */
+public class MatrixView extends AbstractMatrix {
+    /**
+     * Constructor for {@link Externalizable} interface.
+     */
+    public MatrixView() {
+        // No-op.
+    }
+
+    /**
+     * @param parent Backing parent {@link Matrix}.
+     * @param rowOff Row offset to parent matrix.
+     * @param colOff Column offset to parent matrix.
+     * @param rows Amount of rows in the view.
+     * @param cols Amount of columns in the view.
+     */
+    public MatrixView(Matrix parent, int rowOff, int colOff, int rows, int cols) {
+        this(parent == null ? null : parent.getStorage(), rowOff, colOff, rows, cols);
+    }
+
+    /**
+     * @param sto Backing parent {@link MatrixStorage}.
+     * @param rowOff Row offset to parent storage.
+     * @param colOff Column offset to parent storage.
+     * @param rows Amount of rows in the view.
+     * @param cols Amount of columns in the view.
+     */
+    public MatrixView(MatrixStorage sto, int rowOff, int colOff, int rows, int cols) {
+        super(new MatrixDelegateStorage(sto, rowOff, colOff, rows, cols));
+    }
+
+    /**
+     *
+     *
+     */
+    private MatrixDelegateStorage storage() {
+        return (MatrixDelegateStorage)getStorage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix copy() {
+        MatrixDelegateStorage sto = storage();
+
+        return new MatrixView(sto.delegate(), sto.rowOffset(), sto.columnOffset(), sto.rowSize(), sto.columnSize());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix like(int rows, int cols) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector likeVector(int crd) {
+        throw new UnsupportedOperationException();
+    }
+}


[47/50] [abbrv] ignite git commit: Fixed javadoc.

Posted by sb...@apache.org.
Fixed javadoc.


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

Branch: refs/heads/ignite-1561
Commit: fb1dea79e6bbdadd5152818276d71b77c5f18942
Parents: 15359bc
Author: Andrey V. Mashenkov <an...@gmail.com>
Authored: Wed Apr 19 06:45:08 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Apr 19 14:03:21 2017 +0300

----------------------------------------------------------------------
 .../repository/support/IgniteRepositoryFactory.java          | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fb1dea79/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactory.java
----------------------------------------------------------------------
diff --git a/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactory.java b/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactory.java
index bceee1f..de2549f 100644
--- a/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactory.java
+++ b/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactory.java
@@ -153,11 +153,11 @@ public class IgniteRepositoryFactory extends RepositoryFactorySupport {
     }
 
     /**
-     * @param s
-     * @return
+     * @param qry Query string.
+     * @return {@code true} if query is SQLFieldsQuery.
      */
-    private boolean isFieldQuery(String s) {
-        return s.matches("^SELECT.*") && !s.matches("^SELECT\\s+(?:\\w+\\.)?+\\*.*");
+    private boolean isFieldQuery(String qry) {
+        return qry.matches("^SELECT.*") && !qry.matches("^SELECT\\s+(?:\\w+\\.)?+\\*.*");
     }
 }
 


[43/50] [abbrv] ignite git commit: Merge remote-tracking branch 'origin/ignite-2.0' into ignite-2.0

Posted by sb...@apache.org.
Merge remote-tracking branch 'origin/ignite-2.0' into ignite-2.0


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

Branch: refs/heads/ignite-1561
Commit: 2ded758ad1f1663aea05ca943ecf509b1574c0bf
Parents: 22d5e55 d383484
Author: devozerov <vo...@gridgain.com>
Authored: Wed Apr 19 12:54:34 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Wed Apr 19 12:54:34 2017 +0300

----------------------------------------------------------------------
 .../junits/common/GridCommonAbstractTest.java   | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
----------------------------------------------------------------------



[27/50] [abbrv] ignite git commit: master Fixed Visor tests. (cherry picked from commit 36a6cd0)

Posted by sb...@apache.org.
master Fixed Visor tests.
(cherry picked from commit 36a6cd0)


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

Branch: refs/heads/ignite-1561
Commit: 8ea9f83ce7f21f6ba50c0c644f62319f25b56ebd
Parents: 43d6d7e
Author: Alexey Kuznetsov <ak...@gridgain.com>
Authored: Tue Apr 18 20:39:58 2017 +0700
Committer: Alexey Kuznetsov <ak...@gridgain.com>
Committed: Tue Apr 18 20:56:23 2017 +0700

----------------------------------------------------------------------
 .../ignite/visor/commands/open/VisorOpenCommandSpec.scala      | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8ea9f83c/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
index 4cf2204..f00ff55 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
@@ -29,10 +29,8 @@ class VisorOpenCommandSpec extends VisorRuntimeBaseSpec(3) {
             visor.mlist()
         }
 
-        it("should print error message when already connected") {
-            intercept[IgniteException] {
-                openVisor()
-            }
+        it("should reopen when already connected") {
+            openVisor()
         }
     }
 }


[35/50] [abbrv] ignite git commit: IGNITE-4565: Implemented CREATE INDEX and DROP INDEX. This closes #1773. This closes #1804.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 2b957be..ceb139a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -17,34 +17,29 @@
 
 package org.apache.ignite.internal.processors.query;
 
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-import javax.cache.Cache;
-import javax.cache.CacheException;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.events.CacheQueryExecutedEvent;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.managers.communication.GridMessageListener;
 import org.apache.ignite.internal.NodeStoppingException;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
+import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
@@ -54,7 +49,23 @@ import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorImpl;
+import org.apache.ignite.internal.processors.query.schema.SchemaIndexOperationCancellationToken;
+import org.apache.ignite.internal.processors.query.schema.SchemaKey;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationManager;
+import org.apache.ignite.internal.processors.query.schema.SchemaOperationWorker;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaFinishDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaOperationStatusMessage;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexCreateOperation;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
+import org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
 import org.apache.ignite.internal.util.future.GridCompoundFuture;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
@@ -63,17 +74,45 @@ import org.apache.ignite.internal.util.lang.GridClosureException;
 import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.T3;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.util.worker.GridWorker;
 import org.apache.ignite.internal.util.worker.GridWorkerFuture;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+import org.apache.ignite.spi.discovery.DiscoveryDataBag;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
+import org.apache.ignite.thread.IgniteThread;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
+
+import javax.cache.Cache;
+import javax.cache.CacheException;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED;
+import static org.apache.ignite.internal.GridTopic.TOPIC_SCHEMA;
 import static org.apache.ignite.internal.IgniteComponentType.INDEXING;
+import static org.apache.ignite.internal.managers.communication.GridIoPolicy.SCHEMA_POOL;
 
 /**
  * Indexing processor.
@@ -82,26 +121,70 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /** Queries detail metrics eviction frequency. */
     private static final int QRY_DETAIL_METRICS_EVICTION_FREQ = 3_000;
 
+    /** */
+    private static final ThreadLocal<AffinityTopologyVersion> requestTopVer = new ThreadLocal<>();
+
     /** For tests. */
     public static Class<? extends GridQueryIndexing> idxCls;
 
+    /** JDK marshaller to serialize errors. */
+    private final JdkMarshaller marsh = new JdkMarshaller();
+
     /** */
     private final GridSpinBusyLock busyLock = new GridSpinBusyLock();
 
+    /** */
+    private GridTimeoutProcessor.CancelableTask qryDetailMetricsEvictTask;
+
     /** Type descriptors. */
-    private final Map<QueryTypeIdKey, QueryTypeDescriptorImpl> types = new ConcurrentHashMap8<>();
+    private final Map<QueryTypeIdKey, QueryTypeDescriptorImpl> types = new ConcurrentHashMap<>();
 
     /** Type descriptors. */
-    private final ConcurrentMap<QueryTypeNameKey, QueryTypeDescriptorImpl> typesByName = new ConcurrentHashMap8<>();
+    private final ConcurrentMap<QueryTypeNameKey, QueryTypeDescriptorImpl> typesByName = new ConcurrentHashMap<>();
 
     /** */
     private final GridQueryIndexing idx;
 
-    /** */
-    private GridTimeoutProcessor.CancelableTask qryDetailMetricsEvictTask;
+    /** All indexes. */
+    private final ConcurrentMap<QueryIndexKey, QueryIndexDescriptorImpl> idxs = new ConcurrentHashMap<>();
 
-    /** */
-    private static final ThreadLocal<AffinityTopologyVersion> requestTopVer = new ThreadLocal<>();
+    /** Schema operation futures created on client side. */
+    private final ConcurrentMap<UUID, SchemaOperationClientFuture> schemaCliFuts = new ConcurrentHashMap<>();
+
+    /** IO message listener. */
+    private final GridMessageListener ioLsnr;
+
+    /** Schema operations. */
+    private final ConcurrentHashMap<SchemaKey, SchemaOperation> schemaOps = new ConcurrentHashMap<>();
+
+    /** Active propose messages. */
+    private final LinkedHashMap<UUID, SchemaProposeDiscoveryMessage> activeProposals = new LinkedHashMap<>();
+
+    /** General state mutex. */
+    private final Object stateMux = new Object();
+
+    /** Coordinator node (initialized lazily). */
+    private ClusterNode crd;
+
+    /** Registered spaces. */
+    private final Collection<String> spaces = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
+
+    /** ID history for index create/drop discovery messages. */
+    private final GridBoundedConcurrentLinkedHashSet<IgniteUuid> dscoMsgIdHist =
+        new GridBoundedConcurrentLinkedHashSet<>(QueryUtils.discoveryHistorySize());
+
+    /** History of already completed operations. */
+    private final GridBoundedConcurrentLinkedHashSet<UUID> completedOpIds =
+        new GridBoundedConcurrentLinkedHashSet<>(QueryUtils.discoveryHistorySize());
+
+    /** Pending status messages. */
+    private final LinkedList<SchemaOperationStatusMessage> pendingMsgs = new LinkedList<>();
+
+    /** Disconnected flag. */
+    private boolean disconnected;
+
+    /** Whether exchange thread is ready to process further requests. */
+    private boolean exchangeReady;
 
     /** */
     private boolean skipFieldLookup;
@@ -119,6 +202,20 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
         else
             idx = INDEXING.inClassPath() ? U.<GridQueryIndexing>newInstance(INDEXING.className()) : null;
+
+        ioLsnr = new GridMessageListener() {
+            @Override public void onMessage(UUID nodeId, Object msg) {
+                if (msg instanceof SchemaOperationStatusMessage) {
+                    SchemaOperationStatusMessage msg0 = (SchemaOperationStatusMessage)msg;
+
+                    msg0.senderNodeId(nodeId);
+
+                    processStatusMessage(msg0);
+                }
+                else
+                    U.warn(log, "Unsupported IO message: " + msg);
+            }
+        };
     }
 
     /** {@inheritDoc} */
@@ -131,6 +228,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             idx.start(ctx, busyLock);
         }
 
+        ctx.io().addMessageListener(TOPIC_SCHEMA, ioLsnr);
+
         // Schedule queries detail metrics eviction.
         qryDetailMetricsEvictTask = ctx.timeout().schedule(new Runnable() {
             @Override public void run() {
@@ -140,6 +239,401 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }, QRY_DETAIL_METRICS_EVICTION_FREQ, QRY_DETAIL_METRICS_EVICTION_FREQ);
     }
 
+    /** {@inheritDoc} */
+    @Override public void onKernalStop(boolean cancel) {
+        super.onKernalStop(cancel);
+
+        if (cancel && idx != null) {
+            try {
+                while (!busyLock.tryBlock(500))
+                    idx.cancelAllQueries();
+
+                return;
+            } catch (InterruptedException ignored) {
+                U.warn(log, "Interrupted while waiting for active queries cancellation.");
+
+                Thread.currentThread().interrupt();
+            }
+        }
+
+        busyLock.block();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop(boolean cancel) throws IgniteCheckedException {
+        super.stop(cancel);
+
+        ctx.io().removeMessageListener(TOPIC_SCHEMA, ioLsnr);
+
+        if (idx != null)
+            idx.stop();
+
+        U.closeQuiet(qryDetailMetricsEvictTask);
+    }
+
+    /**
+     * Handle cache kernal start. At this point discovery and IO managers are operational, caches are not started yet.
+     *
+     * @throws IgniteCheckedException If failed.
+     */
+    public void onCacheKernalStart() throws IgniteCheckedException {
+        synchronized (stateMux) {
+            exchangeReady = true;
+
+            // Re-run pending top-level proposals.
+            for (SchemaOperation schemaOp : schemaOps.values())
+                onSchemaPropose(schemaOp.proposeMessage());
+        }
+    }
+
+    /**
+     * Handle cache reconnect.
+     *
+     * @throws IgniteCheckedException If failed.
+     */
+    public void onCacheReconnect() throws IgniteCheckedException {
+        synchronized (stateMux) {
+            assert disconnected;
+
+            disconnected = false;
+
+            onCacheKernalStart();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public DiscoveryDataExchangeType discoveryDataType() {
+        return DiscoveryDataExchangeType.QUERY_PROC;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void collectGridNodeData(DiscoveryDataBag dataBag) {
+        // Collect active proposals.
+        synchronized (stateMux) {
+            LinkedHashMap<UUID, SchemaProposeDiscoveryMessage> data = new LinkedHashMap<>(activeProposals);
+
+            dataBag.addGridCommonData(DiscoveryDataExchangeType.QUERY_PROC.ordinal(), data);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) {
+        synchronized (stateMux) {
+            // Preserve proposals.
+            LinkedHashMap<UUID, SchemaProposeDiscoveryMessage> data0 =
+                (LinkedHashMap<UUID, SchemaProposeDiscoveryMessage>)data.commonData();
+
+            // Process proposals as if they were received as regular discovery messages.
+            if (data0 != null) {
+                for (SchemaProposeDiscoveryMessage activeProposal : data0.values())
+                    onSchemaProposeDiscovery0(activeProposal);
+            }
+        }
+    }
+
+    /**
+     * Process schema propose message from discovery thread.
+     *
+     * @param msg Message.
+     * @return {@code True} if exchange should be triggered.
+     */
+    private boolean onSchemaProposeDiscovery(SchemaProposeDiscoveryMessage msg) {
+        UUID opId = msg.operation().id();
+        String space = msg.operation().space();
+
+        if (!msg.initialized()) {
+            // Ensure cache exists on coordinator node.
+            DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(space);
+
+            if (cacheDesc == null) {
+                if (log.isDebugEnabled())
+                    log.debug("Received schema propose discovery message, but cache doesn't exist " +
+                        "(will report error) [opId=" + opId + ", msg=" + msg + ']');
+
+                msg.onError(new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, space));
+            }
+            else {
+                CacheConfiguration ccfg = cacheDesc.cacheConfiguration();
+
+                if (ccfg.getCacheMode() == CacheMode.LOCAL) {
+                    // Distributed operation is not allowed on LOCAL caches.
+                    if (log.isDebugEnabled())
+                        log.debug("Received schema propose discovery message, but cache is LOCAL " +
+                            "(will report error) [opId=" + opId + ", msg=" + msg + ']');
+
+                    msg.onError(new SchemaOperationException("Schema changes are not supported for LOCAL cache."));
+                }
+                else {
+                    // Preserve deployment ID so that we can distinguish between different caches with the same name.
+                    if (msg.deploymentId() == null)
+                        msg.deploymentId(cacheDesc.deploymentId());
+
+                    assert F.eq(cacheDesc.deploymentId(), msg.deploymentId());
+                }
+            }
+        }
+
+        // Complete client future and exit immediately in case of error.
+        if (msg.hasError()) {
+            SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
+
+            if (cliFut != null)
+                cliFut.onDone(msg.error());
+
+            return false;
+        }
+
+        return onSchemaProposeDiscovery0(msg);
+    }
+
+    /**
+     * Process schema propose message from discovery thread (or from cache start routine).
+     *
+     * @param msg Message.
+     * @return {@code True} if exchange should be triggered.
+     */
+    private boolean onSchemaProposeDiscovery0(SchemaProposeDiscoveryMessage msg) {
+        UUID opId = msg.operation().id();
+
+        synchronized (stateMux) {
+            if (disconnected) {
+                if (log.isDebugEnabled())
+                    log.debug("Processing discovery schema propose message, but node is disconnected (will ignore) " +
+                        "[opId=" + opId + ", msg=" + msg + ']');
+
+                return false;
+            }
+
+            if (log.isDebugEnabled())
+                log.debug("Processing discovery schema propose message [opId=" + opId + ", msg=" + msg + ']');
+
+            // Put message to active operations set.
+            SchemaProposeDiscoveryMessage oldDesc = activeProposals.put(msg.operation().id(), msg);
+
+            assert oldDesc == null;
+
+            // Create schema operation and either trigger it immediately from exchange thread or append to already
+            // running operation.
+            SchemaOperation schemaOp = new SchemaOperation(msg);
+
+            SchemaKey key = msg.schemaKey();
+
+            SchemaOperation prevSchemaOp = schemaOps.get(key);
+
+            if (prevSchemaOp != null) {
+                prevSchemaOp = prevSchemaOp.unwind();
+
+                if (log.isDebugEnabled())
+                    log.debug("Schema change is enqueued and will be executed after previous operation is completed " +
+                        "[opId=" + opId + ", prevOpId=" + prevSchemaOp.id() + ']');
+
+                prevSchemaOp.next(schemaOp);
+
+                return false;
+            }
+            else {
+                schemaOps.put(key, schemaOp);
+
+                return exchangeReady;
+            }
+        }
+    }
+
+    /**
+     * Handle schema propose from exchange thread.
+     *
+     * @param msg Discovery message.
+     */
+    @SuppressWarnings("ThrowableInstanceNeverThrown")
+    public void onSchemaPropose(SchemaProposeDiscoveryMessage msg) {
+        UUID opId = msg.operation().id();
+
+        if (log.isDebugEnabled())
+            log.debug("Processing schema propose message (exchange) [opId=" + opId + ']');
+
+        synchronized (stateMux) {
+            if (disconnected)
+                return;
+
+            SchemaOperation curOp = schemaOps.get(msg.schemaKey());
+
+            assert curOp != null;
+            assert F.eq(opId, curOp.id());
+            assert !curOp.started();
+
+            startSchemaChange(curOp);
+        }
+    }
+
+    /**
+     * Process schema finish message from discovery thread.
+     *
+     * @param msg Message.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    private void onSchemaFinishDiscovery(SchemaFinishDiscoveryMessage msg) {
+        UUID opId = msg.operation().id();
+
+        if (log.isDebugEnabled())
+            log.debug("Received schema finish message (discovery) [opId=" + opId + ", msg=" + msg + ']');
+
+        synchronized (stateMux) {
+            if (disconnected)
+                return;
+
+            boolean completedOpAdded = completedOpIds.add(opId);
+
+            assert completedOpAdded;
+
+            // Remove propose message so that it will not be shared with joining nodes.
+            SchemaProposeDiscoveryMessage proposeMsg = activeProposals.remove(opId);
+
+            assert proposeMsg != null;
+
+            // Apply changes to public cache schema if operation is successful and original cache is still there.
+            if (!msg.hasError()) {
+                DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(msg.operation().space());
+
+                if (cacheDesc != null && F.eq(cacheDesc.deploymentId(), proposeMsg.deploymentId()))
+                    cacheDesc.schemaChangeFinish(msg);
+            }
+
+            // Propose message will be used from exchange thread to
+            msg.proposeMessage(proposeMsg);
+
+            if (exchangeReady) {
+                SchemaOperation op = schemaOps.get(proposeMsg.schemaKey());
+
+                if (F.eq(op.id(), opId)) {
+                    // Completed top operation.
+                    op.finishMessage(msg);
+
+                    if (op.started())
+                        op.doFinish();
+                }
+                else {
+                    // Completed operation in the middle, will schedule completion later.
+                    while (op != null) {
+                        if (F.eq(op.id(), opId))
+                            break;
+
+                        op = op.next();
+                    }
+
+                    assert op != null;
+                    assert !op.started();
+
+                    op.finishMessage(msg);
+                }
+            }
+            else {
+                // Set next operation as top-level one.
+                SchemaKey schemaKey = proposeMsg.schemaKey();
+
+                SchemaOperation op = schemaOps.remove(schemaKey);
+
+                assert op != null;
+                assert F.eq(op.id(), opId);
+
+                // Chain to the next operation (if any).
+                SchemaOperation nextOp = op.next();
+
+                if (nextOp != null)
+                    schemaOps.put(schemaKey, nextOp);
+            }
+
+            // Clean stale IO messages from just-joined nodes.
+            cleanStaleStatusMessages(opId);
+        }
+
+        // Complete client future (if any).
+        SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
+
+        if (cliFut != null) {
+            if (msg.hasError())
+                cliFut.onDone(msg.error());
+            else
+                cliFut.onDone();
+        }
+    }
+
+    /**
+     * Initiate actual schema change operation.
+     *
+     * @param schemaOp Schema operation.
+     */
+    @SuppressWarnings({"unchecked", "ThrowableInstanceNeverThrown"})
+    private void startSchemaChange(SchemaOperation schemaOp) {
+        assert Thread.holdsLock(stateMux);
+        assert !schemaOp.started();
+
+        // Get current cache state.
+        SchemaProposeDiscoveryMessage msg = schemaOp.proposeMessage();
+
+        String space = msg.operation().space();
+
+        DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(space);
+
+        boolean cacheExists = cacheDesc != null && F.eq(msg.deploymentId(), cacheDesc.deploymentId());
+
+        boolean cacheRegistered = cacheExists && spaces.contains(CU.mask(space));
+
+        // Validate schema state and decide whether we should proceed or not.
+        SchemaAbstractOperation op = msg.operation();
+
+        QueryTypeDescriptorImpl type = null;
+        SchemaOperationException err;
+
+        boolean nop = false;
+
+        if (cacheExists) {
+            if (cacheRegistered) {
+                // If cache is started, we perform validation against real schema.
+                T3<QueryTypeDescriptorImpl, Boolean, SchemaOperationException> res = prepareChangeOnStartedCache(op);
+
+                assert res.get2() != null;
+
+                type = res.get1();
+                nop = res.get2();
+                err = res.get3();
+            }
+            else {
+                // If cache is not started yet, there is no schema. Take schema from cache descriptor and validate.
+                QuerySchema schema = cacheDesc.schema();
+
+                T2<Boolean, SchemaOperationException> res = prepareChangeOnNotStartedCache(op, schema);
+
+                assert res.get1() != null;
+
+                type = null;
+                nop = res.get1();
+                err = res.get2();
+            }
+        }
+        else
+            err = new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, op.space());
+
+        // Start operation.
+        SchemaOperationWorker worker =
+            new SchemaOperationWorker(ctx, this, msg.deploymentId(), op, nop, err, cacheRegistered, type);
+
+        SchemaOperationManager mgr = new SchemaOperationManager(ctx, this, worker,
+            ctx.clientNode() ? null : coordinator());
+
+        schemaOp.manager(mgr);
+
+        mgr.start();
+
+        // Unwind pending IO messages.
+        if (!ctx.clientNode() && coordinator().isLocal())
+            unwindPendingMessages(schemaOp.id(), mgr);
+
+        // Schedule operation finish handling if needed.
+        if (schemaOp.hasFinishMessage())
+            schemaOp.doFinish();
+    }
+
     /**
      * @return {@code true} If indexing module is in classpath and successfully initialized.
      */
@@ -148,55 +642,115 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @return Indexing.
+     * @throws IgniteException If module is not enabled.
+     */
+    public GridQueryIndexing getIndexing() throws IgniteException {
+        checkxEnabled();
+
+        return idx;
+    }
+
+    /**
      * @param cctx Cache context.
+     * @param schema Initial schema.
      * @throws IgniteCheckedException If failed.
      */
-    @SuppressWarnings("deprecation")
-    private void initializeCache(GridCacheContext<?, ?> cctx) throws IgniteCheckedException {
+    @SuppressWarnings({"deprecation", "ThrowableResultOfMethodCallIgnored"})
+    private void initializeCache(GridCacheContext<?, ?> cctx, QuerySchema schema) throws IgniteCheckedException {
         String space = cctx.name();
 
-        CacheConfiguration<?,?> ccfg = cctx.config();
-
         // Prepare candidates.
         List<Class<?>> mustDeserializeClss = new ArrayList<>();
 
         Collection<QueryTypeCandidate> cands = new ArrayList<>();
 
-        if (!F.isEmpty(ccfg.getQueryEntities())) {
-            for (QueryEntity qryEntity : ccfg.getQueryEntities()) {
+        Collection<QueryEntity> qryEntities = schema.entities();
+
+        if (!F.isEmpty(qryEntities)) {
+            for (QueryEntity qryEntity : qryEntities) {
                 QueryTypeCandidate cand = QueryUtils.typeForQueryEntity(space, cctx, qryEntity, mustDeserializeClss);
 
                 cands.add(cand);
             }
         }
 
-        // Register candidates.
-        idx.registerCache(space, cctx, cctx.config());
+        // Ensure that candidates has unique index names. Otherwise we will not be able to apply pending operations.
+        Map<String, QueryTypeDescriptorImpl> tblTypMap = new HashMap<>();
+        Map<String, QueryTypeDescriptorImpl> idxTypMap = new HashMap<>();
 
-        try {
-            for (QueryTypeCandidate cand : cands) {
-                QueryTypeIdKey typeId = cand.typeId();
-                QueryTypeIdKey altTypeId = cand.alternativeTypeId();
-                QueryTypeDescriptorImpl desc = cand.descriptor();
+        for (QueryTypeCandidate cand : cands) {
+            QueryTypeDescriptorImpl desc = cand.descriptor();
 
-                if (typesByName.putIfAbsent(new QueryTypeNameKey(space, desc.name()), desc) != null)
-                    throw new IgniteCheckedException("Type with name '" + desc.name() + "' already indexed " +
-                        "in cache '" + space + "'.");
+            QueryTypeDescriptorImpl oldDesc = tblTypMap.put(desc.tableName(), desc);
 
-                types.put(typeId, desc);
+            if (oldDesc != null)
+                throw new IgniteException("Duplicate table name [tblName=" + desc.tableName() +
+                    ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']');
 
-                if (altTypeId != null)
-                    types.put(altTypeId, desc);
+            for (String idxName : desc.indexes().keySet()) {
+                oldDesc = idxTypMap.put(idxName, desc);
 
-                idx.registerType(space, desc);
+                if (oldDesc != null)
+                    throw new IgniteException("Duplicate index name [idxName=" + idxName +
+                        ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']');
             }
         }
-        catch (IgniteCheckedException | RuntimeException e) {
-            unregisterCache0(space);
 
-            throw e;
+        // Apply pending operation which could have been completed as no-op at this point. There could be only one
+        // in-flight operation for a cache.
+        synchronized (stateMux) {
+            if (disconnected)
+                return;
+
+            for (SchemaOperation op : schemaOps.values()) {
+                if (F.eq(op.proposeMessage().deploymentId(), cctx.dynamicDeploymentId())) {
+                    if (op.started()) {
+                        SchemaOperationWorker worker = op.manager().worker();
+
+                        assert !worker.cacheRegistered();
+
+                        if (!worker.nop()) {
+                            IgniteInternalFuture fut = worker.future();
+
+                            assert fut.isDone();
+
+                            if (fut.error() == null) {
+                                SchemaAbstractOperation op0 = op.proposeMessage().operation();
+
+                                if (op0 instanceof SchemaIndexCreateOperation) {
+                                    SchemaIndexCreateOperation opCreate = (SchemaIndexCreateOperation)op0;
+
+                                    QueryTypeDescriptorImpl typeDesc = tblTypMap.get(opCreate.tableName());
+
+                                    assert typeDesc != null;
+
+                                    QueryUtils.processDynamicIndexChange(opCreate.indexName(), opCreate.index(),
+                                        typeDesc);
+                                }
+                                else if (op0 instanceof SchemaIndexDropOperation) {
+                                    SchemaIndexDropOperation opDrop = (SchemaIndexDropOperation)op0;
+
+                                    QueryTypeDescriptorImpl typeDesc = idxTypMap.get(opDrop.indexName());
+
+                                    assert typeDesc != null;
+
+                                    QueryUtils.processDynamicIndexChange(opDrop.indexName(), null, typeDesc);
+                                }
+                                else
+                                    assert false;
+                            }
+                        }
+                    }
+
+                    break;
+                }
+            }
         }
 
+        // Ready to register at this point.
+        registerCache0(space, cctx, cands);
+
         // Warn about possible implicit deserialization.
         if (!mustDeserializeClss.isEmpty()) {
             U.warn(log, "Some classes in query configuration cannot be written in binary format " +
@@ -209,46 +763,41 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public void onKernalStop(boolean cancel) {
-        super.onKernalStop(cancel);
-
-        if (cancel && idx != null)
-            try {
-                while (!busyLock.tryBlock(500))
-                    idx.cancelAllQueries();
-
-                return;
-            }
-            catch (InterruptedException ignored) {
-                U.warn(log, "Interrupted while waiting for active queries cancellation.");
+    @Override public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException {
+        Collection<SchemaOperationClientFuture> futs;
 
-                Thread.currentThread().interrupt();
-            }
+        synchronized (stateMux) {
+            disconnected = true;
+            exchangeReady = false;
 
-        busyLock.block();
-    }
+            // Clear client futures.
+            futs = new ArrayList<>(schemaCliFuts.values());
 
-    /** {@inheritDoc} */
-    @Override public void stop(boolean cancel) throws IgniteCheckedException {
-        super.stop(cancel);
+            schemaCliFuts.clear();
 
-        if (idx != null)
-            idx.stop();
+            // Clear operations data.
+            activeProposals.clear();
+            schemaOps.clear();
+        }
 
-        U.closeQuiet(qryDetailMetricsEvictTask);
-    }
+        // Complete client futures outside of synchonized block because they may have listeners/chains.
+        for (SchemaOperationClientFuture fut : futs)
+            fut.onDone(new SchemaOperationException("Client node is disconnected (operation result is unknown)."));
 
-    /** {@inheritDoc} */
-    @Override public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException {
         if (idx != null)
             idx.onDisconnected(reconnectFut);
     }
 
     /**
+     * Handle cache start. Invoked either from GridCacheProcessor.onKernalStart() method or from exchange worker.
+     * When called for the first time, we initialize topology thus understanding whether current node is coordinator
+     * or not.
+     *
      * @param cctx Cache context.
+     * @param schema Index states.
      * @throws IgniteCheckedException If failed.
      */
-    public void onCacheStart(GridCacheContext cctx) throws IgniteCheckedException {
+    public void onCacheStart(GridCacheContext cctx, QuerySchema schema) throws IgniteCheckedException {
         if (idx == null)
             return;
 
@@ -258,45 +807,506 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         cctx.shared().database().checkpointReadLock();
 
         try {
-            initializeCache(cctx);
+            initializeCache(cctx, schema);
         }
         finally {
             cctx.shared().database().checkpointReadUnlock();
 
-            busyLock.leaveBusy();
+            busyLock.leaveBusy();
+        }
+    }
+
+    /**
+     * @param cctx Cache context.
+     */
+    public void onCacheStop(GridCacheContext cctx) {
+        if (idx == null)
+            return;
+
+        if (!busyLock.enterBusy())
+            return;
+
+        try {
+            unregisterCache0(cctx.name());
+        }
+        finally {
+            busyLock.leaveBusy();
+        }
+    }
+
+    /**
+     * @return Skip field lookup flag.
+     */
+    public boolean skipFieldLookup() {
+        return skipFieldLookup;
+    }
+
+    /**
+     * @param skipFieldLookup Skip field lookup flag.
+     */
+    public void skipFieldLookup(boolean skipFieldLookup) {
+        this.skipFieldLookup = skipFieldLookup;
+    }
+
+    /**
+     * Handle custom discovery message.
+     *
+     * @param msg Message.
+     */
+    public void onDiscovery(SchemaAbstractDiscoveryMessage msg) {
+        IgniteUuid id = msg.id();
+
+        if (!dscoMsgIdHist.add(id)) {
+            U.warn(log, "Received duplicate schema custom discovery message (will ignore) [opId=" +
+                msg.operation().id() + ", msg=" + msg  +']');
+
+            return;
+        }
+
+        if (msg instanceof SchemaProposeDiscoveryMessage) {
+            SchemaProposeDiscoveryMessage msg0 = (SchemaProposeDiscoveryMessage)msg;
+
+            boolean exchange = onSchemaProposeDiscovery(msg0);
+
+            msg0.exchange(exchange);
+        }
+        else if (msg instanceof SchemaFinishDiscoveryMessage) {
+            SchemaFinishDiscoveryMessage msg0 = (SchemaFinishDiscoveryMessage)msg;
+
+            onSchemaFinishDiscovery(msg0);
+        }
+        else
+            U.warn(log, "Received unsupported schema custom discovery message (will ignore) [opId=" +
+                msg.operation().id() + ", msg=" + msg  +']');
+    }
+
+    /**
+     * Prepare change on started cache.
+     *
+     * @param op Operation.
+     * @return Result: affected type, nop flag, error.
+     */
+    private T3<QueryTypeDescriptorImpl, Boolean, SchemaOperationException> prepareChangeOnStartedCache(
+        SchemaAbstractOperation op) {
+        QueryTypeDescriptorImpl type = null;
+        boolean nop = false;
+        SchemaOperationException err = null;
+
+        String space = op.space();
+
+        if (op instanceof SchemaIndexCreateOperation) {
+            SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation) op;
+
+            QueryIndex idx = op0.index();
+
+            // Make sure table exists.
+            String tblName = op0.tableName();
+
+            type = type(space, tblName);
+
+            if (type == null)
+                err = new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, tblName);
+            else {
+                // Make sure that index can be applied to the given table.
+                for (String idxField : idx.getFieldNames()) {
+                    if (!type.fields().containsKey(idxField)) {
+                        err = new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND,
+                            idxField);
+
+                        break;
+                    }
+                }
+            }
+
+            // Check conflict with other indexes.
+            if (err == null) {
+                String idxName = op0.index().getName();
+
+                QueryIndexKey idxKey = new QueryIndexKey(space, idxName);
+
+                if (idxs.get(idxKey) != null) {
+                    if (op0.ifNotExists())
+                        nop = true;
+                    else
+                        err = new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idxName);
+                }
+            }
+        }
+        else if (op instanceof SchemaIndexDropOperation) {
+            SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
+
+            String idxName = op0.indexName();
+
+            QueryIndexDescriptorImpl oldIdx = idxs.get(new QueryIndexKey(space, idxName));
+
+            if (oldIdx == null) {
+                if (op0.ifExists())
+                    nop = true;
+                else
+                    err = new SchemaOperationException(SchemaOperationException.CODE_INDEX_NOT_FOUND, idxName);
+            }
+            else
+                type = oldIdx.typeDescriptor();
+        }
+        else
+            err = new SchemaOperationException("Unsupported operation: " + op);
+
+        return new T3<>(type, nop, err);
+    }
+
+    /**
+     * Prepare operation on non-started cache.
+     *
+     * @param op Operation.
+     * @param schema Known cache schema.
+     * @return Result: nop flag, error.
+     */
+    private T2<Boolean, SchemaOperationException> prepareChangeOnNotStartedCache(SchemaAbstractOperation op,
+        QuerySchema schema) {
+        boolean nop = false;
+        SchemaOperationException err = null;
+
+        // Build table and index maps.
+        Map<String, QueryEntity> tblMap = new HashMap<>();
+        Map<String, T2<QueryEntity, QueryIndex>> idxMap = new HashMap<>();
+
+        for (QueryEntity entity : schema.entities()) {
+            String tblName = QueryUtils.tableName(entity);
+
+            QueryEntity oldEntity = tblMap.put(tblName, entity);
+
+            if (oldEntity != null) {
+                err = new SchemaOperationException("Invalid schema state (duplicate table found): " + tblName);
+
+                break;
+            }
+
+            for (QueryIndex entityIdx : entity.getIndexes()) {
+                String idxName = QueryUtils.indexName(entity, entityIdx);
+
+                T2<QueryEntity, QueryIndex> oldIdxEntity = idxMap.put(idxName, new T2<>(entity, entityIdx));
+
+                if (oldIdxEntity != null) {
+                    err = new SchemaOperationException("Invalid schema state (duplicate index found): " +
+                        idxName);
+
+                    break;
+                }
+            }
+
+            if (err != null)
+                break;
+        }
+
+        // Now check whether operation can be applied to schema.
+        if (op instanceof SchemaIndexCreateOperation) {
+            SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation)op;
+
+            String idxName = op0.indexName();
+
+            T2<QueryEntity, QueryIndex> oldIdxEntity = idxMap.get(idxName);
+
+            if (oldIdxEntity == null) {
+                String tblName = op0.tableName();
+
+                QueryEntity oldEntity = tblMap.get(tblName);
+
+                if (oldEntity == null)
+                    err = new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, tblName);
+                else {
+                    for (String fieldName : op0.index().getFields().keySet()) {
+                        Set<String> oldEntityFields = new HashSet<>(oldEntity.getFields().keySet());
+
+                        for (Map.Entry<String, String> alias : oldEntity.getAliases().entrySet()) {
+                            oldEntityFields.remove(alias.getKey());
+                            oldEntityFields.add(alias.getValue());
+                        }
+
+                        if (!oldEntityFields.contains(fieldName)) {
+                            err = new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND,
+                                fieldName);
+
+                            break;
+                        }
+                    }
+                }
+            }
+            else {
+                if (op0.ifNotExists())
+                    nop = true;
+                else
+                    err = new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idxName);
+            }
+        }
+        else if (op instanceof SchemaIndexDropOperation) {
+            SchemaIndexDropOperation op0 = (SchemaIndexDropOperation)op;
+
+            String idxName = op0.indexName();
+
+            T2<QueryEntity, QueryIndex> oldIdxEntity = idxMap.get(idxName);
+
+            if (oldIdxEntity == null) {
+                if (op0.ifExists())
+                    nop = true;
+                else
+                    err = new SchemaOperationException(SchemaOperationException.CODE_INDEX_NOT_FOUND, idxName);
+            }
+        }
+        else
+            err = new SchemaOperationException("Unsupported operation: " + op);
+
+        return new T2<>(nop, err);
+    }
+
+    /**
+     * Invoked when coordinator finished ensuring that all participants are ready.
+     *
+     * @param op Operation.
+     * @param err Error (if any).
+     */
+    public void onCoordinatorFinished(SchemaAbstractOperation op, @Nullable SchemaOperationException err) {
+        synchronized (stateMux) {
+            SchemaFinishDiscoveryMessage msg = new SchemaFinishDiscoveryMessage(op, err);
+
+            try {
+                ctx.discovery().sendCustomEvent(msg);
+            }
+            catch (Exception e) {
+                // Failed to send finish message over discovery. This is something unrecoverable.
+                U.warn(log, "Failed to send schema finish discovery message [opId=" + op.id() + ']', e);
+            }
+        }
+    }
+
+    /**
+     * Get current coordinator node.
+     *
+     * @return Coordinator node.
+     */
+    private ClusterNode coordinator() {
+        assert !ctx.clientNode();
+
+        synchronized (stateMux) {
+            if (crd == null) {
+                ClusterNode crd0 = null;
+
+                for (ClusterNode node : ctx.discovery().aliveServerNodes()) {
+                    if (crd0 == null || crd0.order() > node.order())
+                        crd0 = node;
+                }
+
+                assert crd0 != null;
+
+                crd = crd0;
+            }
+
+            return crd;
+        }
+    }
+
+    /**
+     * Get rid of stale IO message received from other nodes which joined when operation had been in progress.
+     *
+     * @param opId Operation ID.
+     */
+    private void cleanStaleStatusMessages(UUID opId) {
+        Iterator<SchemaOperationStatusMessage> it = pendingMsgs.iterator();
+
+        while (it.hasNext()) {
+            SchemaOperationStatusMessage statusMsg = it.next();
+
+            if (F.eq(opId, statusMsg.operationId())) {
+                it.remove();
+
+                if (log.isDebugEnabled())
+                    log.debug("Dropped operation status message because it is already completed [opId=" + opId +
+                        ", rmtNode=" + statusMsg.senderNodeId() + ']');
+            }
+        }
+    }
+
+    /**
+     * Apply positive index operation result.
+     *
+     * @param op Operation.
+     * @param type Type descriptor (if available),
+     */
+    public void onLocalOperationFinished(SchemaAbstractOperation op, @Nullable QueryTypeDescriptorImpl type) {
+        synchronized (stateMux) {
+            if (disconnected)
+                return;
+
+            // No need to apply anything to obsolete type.
+            if (type == null || type.obsolete()) {
+                if (log.isDebugEnabled())
+                    log.debug("Local operation finished, but type descriptor is either missing or obsolete " +
+                        "(will ignore) [opId=" + op.id() + ']');
+
+                return;
+            }
+
+            if (log.isDebugEnabled())
+                log.debug("Local operation finished successfully [opId=" + op.id() + ']');
+
+            try {
+                if (op instanceof SchemaIndexCreateOperation) {
+                    SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation)op;
+
+                    QueryUtils.processDynamicIndexChange(op0.indexName(), op0.index(), type);
+
+                    QueryIndexDescriptorImpl idxDesc = type.index(op0.indexName());
+
+                    QueryIndexKey idxKey = new QueryIndexKey(op.space(), op0.indexName());
+
+                    idxs.put(idxKey, idxDesc);
+                }
+                else {
+                    assert op instanceof SchemaIndexDropOperation;
+
+                    SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
+
+                    QueryUtils.processDynamicIndexChange(op0.indexName(), null, type);
+
+                    QueryIndexKey idxKey = new QueryIndexKey(op.space(), op0.indexName());
+
+                    idxs.remove(idxKey);
+                }
+            }
+            catch (IgniteCheckedException e) {
+                U.warn(log, "Failed to finish index operation [opId=" + op.id() + " op=" + op + ']', e);
+            }
+        }
+    }
+
+    /**
+     * Handle node leave.
+     *
+     * @param node Node.
+     */
+    public void onNodeLeave(ClusterNode node) {
+        synchronized (stateMux) {
+            // Clients do not send status messages and are never coordinators.
+            if (ctx.clientNode())
+                return;
+
+            ClusterNode crd0 = coordinator();
+
+            if (F.eq(node.id(), crd0.id())) {
+                crd = null;
+
+                crd0 = coordinator();
+            }
+
+            for (SchemaOperation op : schemaOps.values()) {
+                if (op.started()) {
+                    op.manager().onNodeLeave(node.id(), crd0);
+
+                    if (crd0.isLocal())
+                        unwindPendingMessages(op.id(), op.manager());
+                }
+            }
+        }
+    }
+
+    /**
+     * Process index operation.
+     *
+     * @param op Operation.
+     * @param type Type descriptor.
+     * @param depId Cache deployment ID.
+     * @param cancelTok Cancel token.
+     * @throws SchemaOperationException If failed.
+     */
+    public void processIndexOperationLocal(SchemaAbstractOperation op, QueryTypeDescriptorImpl type, IgniteUuid depId,
+        SchemaIndexOperationCancellationToken cancelTok) throws SchemaOperationException {
+        if (log.isDebugEnabled())
+            log.debug("Started local index operation [opId=" + op.id() + ']');
+
+        String space = op.space();
+
+        GridCacheAdapter cache = ctx.cache().internalCache(op.space());
+
+        if (cache == null || !F.eq(depId, cache.context().dynamicDeploymentId()))
+            throw new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, op.space());
+
+        try {
+            if (op instanceof SchemaIndexCreateOperation) {
+                SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation) op;
+
+                QueryIndexDescriptorImpl idxDesc = QueryUtils.createIndexDescriptor(type, op0.index());
+
+                SchemaIndexCacheVisitor visitor =
+                    new SchemaIndexCacheVisitorImpl(this, cache.context(), space, op0.tableName(), cancelTok);
+
+                idx.dynamicIndexCreate(space, op0.tableName(), idxDesc, op0.ifNotExists(), visitor);
+            }
+            else if (op instanceof SchemaIndexDropOperation) {
+                SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
+
+                idx.dynamicIndexDrop(space, op0.indexName(), op0.ifExists());
+            }
+            else
+                throw new SchemaOperationException("Unsupported operation: " + op);
+        }
+        catch (Exception e) {
+            if (e instanceof SchemaOperationException)
+                throw (SchemaOperationException)e;
+            else
+                throw new SchemaOperationException("Schema change operation failed: " + e.getMessage(), e);
         }
     }
 
     /**
+     * Register cache in indexing SPI.
+     *
+     * @param space Space.
      * @param cctx Cache context.
+     * @param cands Candidates.
+     * @throws IgniteCheckedException If failed.
      */
-    public void onCacheStop(GridCacheContext cctx) {
-        if (idx == null)
-            return;
+    private void registerCache0(String space, GridCacheContext<?, ?> cctx, Collection<QueryTypeCandidate> cands)
+        throws IgniteCheckedException {
+        synchronized (stateMux) {
+            idx.registerCache(space, cctx, cctx.config());
 
-        if (!busyLock.enterBusy())
-            return;
+            try {
+                for (QueryTypeCandidate cand : cands) {
+                    QueryTypeIdKey typeId = cand.typeId();
+                    QueryTypeIdKey altTypeId = cand.alternativeTypeId();
+                    QueryTypeDescriptorImpl desc = cand.descriptor();
 
-        try {
-            unregisterCache0(cctx.name());
-        }
-        finally {
-            busyLock.leaveBusy();
-        }
-    }
+                    if (typesByName.putIfAbsent(new QueryTypeNameKey(space, desc.name()), desc) != null)
+                        throw new IgniteCheckedException("Type with name '" + desc.name() + "' already indexed " +
+                            "in cache '" + space + "'.");
 
-    /**
-     * @return Skip field lookup flag.
-     */
-    public boolean skipFieldLookup() {
-        return skipFieldLookup;
-    }
+                    types.put(typeId, desc);
 
-    /**
-     * @param skipFieldLookup Skip field lookup flag.
-     */
-    public void skipFieldLookup(boolean skipFieldLookup) {
-        this.skipFieldLookup = skipFieldLookup;
+                    if (altTypeId != null)
+                        types.put(altTypeId, desc);
+
+                    for (QueryIndexDescriptorImpl idx : desc.indexes0()) {
+                        QueryIndexKey idxKey = new QueryIndexKey(space, idx.name());
+
+                        QueryIndexDescriptorImpl oldIdx = idxs.putIfAbsent(idxKey, idx);
+
+                        if (oldIdx != null) {
+                            throw new IgniteException("Duplicate index name [space=" + space +
+                                ", idxName=" + idx.name() + ", existingTable=" + oldIdx.typeDescriptor().tableName() +
+                                ", table=" + desc.tableName() + ']');
+                        }
+                    }
+
+                    idx.registerType(space, desc);
+                }
+
+                spaces.add(CU.mask(space));
+            }
+            catch (IgniteCheckedException | RuntimeException e) {
+                unregisterCache0(space);
+
+                throw e;
+            }
+        }
     }
 
     /**
@@ -307,13 +1317,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     private void unregisterCache0(String space) {
         assert idx != null;
 
-        try {
-            idx.unregisterCache(space);
-        }
-        catch (Exception e) {
-            U.error(log, "Failed to clear indexing on cache unregister (will ignore): " + space, e);
-        }
-        finally {
+        synchronized (stateMux) {
+            // Clear types.
             Iterator<Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl>> it = types.entrySet().iterator();
 
             while (it.hasNext()) {
@@ -323,9 +1328,79 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     it.remove();
 
                     typesByName.remove(new QueryTypeNameKey(space, entry.getValue().name()));
+
+                    entry.getValue().markObsolete();
                 }
             }
+
+            // Clear indexes.
+            Iterator<Map.Entry<QueryIndexKey, QueryIndexDescriptorImpl>> idxIt = idxs.entrySet().iterator();
+
+            while (idxIt.hasNext()) {
+                Map.Entry<QueryIndexKey, QueryIndexDescriptorImpl> idxEntry = idxIt.next();
+
+                QueryIndexKey idxKey = idxEntry.getKey();
+
+                if (F.eq(space, idxKey.space()))
+                    idxIt.remove();
+            }
+
+            // Notify in-progress index operations.
+            for (SchemaOperation op : schemaOps.values()) {
+                if (op.started())
+                    op.manager().worker().cancel();
+            }
+
+            // Notify indexing.
+            try {
+                idx.unregisterCache(space);
+            }
+            catch (Exception e) {
+                U.error(log, "Failed to clear indexing on cache unregister (will ignore): " + space, e);
+            }
+
+            spaces.remove(CU.mask(space));
+        }
+    }
+
+    /**
+     * Check whether provided key and value belongs to expected space and table.
+     *
+     * @param cctx Target cache context.
+     * @param expSpace Expected space.
+     * @param expTblName Expected table name.
+     * @param key Key.
+     * @param val Value.
+     * @return {@code True} if this key-value pair belongs to expected space/table, {@code false} otherwise or
+     *     if space or table doesn't exist.
+     * @throws IgniteCheckedException If failed.
+     */
+    @SuppressWarnings("ConstantConditions")
+    public boolean belongsToTable(GridCacheContext cctx, String expSpace, String expTblName, KeyCacheObject key,
+        CacheObject val) throws IgniteCheckedException {
+        QueryTypeDescriptorImpl desc = type(expSpace, val);
+
+        if (desc == null)
+            return false;
+
+        if (!F.eq(expTblName, desc.tableName()))
+            return false;
+
+        if (!cctx.cacheObjects().isBinaryObject(val)) {
+            Class<?> valCls = val.value(cctx.cacheObjectContext(), false).getClass();
+
+            if (!desc.valueClass().isAssignableFrom(valCls))
+                return false;
         }
+
+        if (!cctx.cacheObjects().isBinaryObject(key)) {
+            Class<?> keyCls = key.value(cctx.cacheObjectContext(), false).getClass();
+
+            if (!desc.keyClass().isAssignableFrom(keyCls))
+                return false;
+        }
+
+        return true;
     }
 
     /**
@@ -457,7 +1532,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (desc == null)
                 return;
 
-            idx.store(space, desc, key, partId, val, ver, expirationTime, link);
+            idx.store(space, desc.name(), key, partId, val, ver, expirationTime, link);
         }
         finally {
             busyLock.leaveBusy();
@@ -518,6 +1593,30 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets type descriptor for space by given object's type.
+     *
+     * @param space Space name.
+     * @param val Object to determine type for.
+     * @return Type descriptor.
+     * @throws IgniteCheckedException If failed.
+     */
+    @SuppressWarnings("ConstantConditions")
+    private QueryTypeDescriptorImpl type(@Nullable String space, CacheObject val) throws IgniteCheckedException {
+        CacheObjectContext coctx = cacheObjectContext(space);
+
+        QueryTypeIdKey id;
+
+        boolean binaryVal = ctx.cacheObjects().isBinaryObject(val);
+
+        if (binaryVal)
+            id = new QueryTypeIdKey(space, ctx.cacheObjects().typeId(val));
+        else
+            id = new QueryTypeIdKey(space, val.value(coctx, false).getClass());
+
+        return types.get(id);
+    }
+
+    /**
      * @throws IgniteCheckedException If failed.
      */
     private void checkEnabled() throws IgniteCheckedException {
@@ -637,9 +1736,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     @Override public QueryCursor<Cache.Entry<K, V>> applyx() throws IgniteCheckedException {
                         String type = qry.getType();
 
-                        QueryTypeDescriptorImpl typeDesc = type(cctx.name(), type);
+                        String typeName = typeName(cctx.name(), type);
 
-                        qry.setType(typeDesc.name());
+                        qry.setType(typeName);
 
                         sendQueryExecutedEvent(
                             qry.getSql(),
@@ -682,6 +1781,80 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Entry point for index procedure.
+     *
+     * @param space Space name.
+     * @param tblName Table name.
+     * @param idx Index.
+     * @param ifNotExists When set to {@code true} operation will fail if index already exists.
+     * @return Future completed when index is created.
+     */
+    public IgniteInternalFuture<?> dynamicIndexCreate(String space, String tblName, QueryIndex idx,
+        boolean ifNotExists) {
+        SchemaAbstractOperation op = new SchemaIndexCreateOperation(UUID.randomUUID(), space, tblName, idx, ifNotExists);
+
+        return startIndexOperationDistributed(op);
+    }
+
+    /**
+     * Entry point for index drop procedure
+     *
+     * @param idxName Index name.
+     * @param ifExists When set to {@code true} operation fill fail if index doesn't exists.
+     * @return Future completed when index is created.
+     */
+    public IgniteInternalFuture<?> dynamicIndexDrop(String space, String idxName, boolean ifExists) {
+        SchemaAbstractOperation op = new SchemaIndexDropOperation(UUID.randomUUID(), space, idxName, ifExists);
+
+        return startIndexOperationDistributed(op);
+    }
+
+    /**
+     * Start distributed index change operation.
+     *
+     * @param op Operation.
+     * @return Future.
+     */
+    private IgniteInternalFuture<?> startIndexOperationDistributed(SchemaAbstractOperation op) {
+        SchemaOperationClientFuture fut = new SchemaOperationClientFuture(op.id());
+
+        SchemaOperationClientFuture oldFut = schemaCliFuts.put(op.id(), fut);
+
+        assert oldFut == null;
+
+        try {
+            ctx.discovery().sendCustomEvent(new SchemaProposeDiscoveryMessage(op));
+
+            if (log.isDebugEnabled())
+                log.debug("Sent schema propose discovery message [opId=" + op.id() + ", op=" + op + ']');
+
+            boolean disconnected0;
+
+            synchronized (stateMux) {
+                disconnected0 = disconnected;
+            }
+
+            if (disconnected0) {
+                fut.onDone(new SchemaOperationException("Client node is disconnected (operation result is unknown)."));
+
+                schemaCliFuts.remove(op.id());
+            }
+        }
+        catch (Exception e) {
+            if (e instanceof SchemaOperationException)
+                fut.onDone(e);
+            else {
+                fut.onDone(new SchemaOperationException("Failed to start schema change operation due to " +
+                    "unexpected exception [opId=" + op.id() + ", op=" + op + ']', e));
+            }
+
+            schemaCliFuts.remove(op.id());
+        }
+
+        return fut;
+    }
+
+    /**
      * @param sqlQry Sql query.
      * @param params Params.
      */
@@ -704,14 +1877,15 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * @param schema Schema.
+     *
+     * @param space Space name.
      * @param sql Query.
      * @return {@link PreparedStatement} from underlying engine to supply metadata to Prepared - most likely H2.
      */
-    public PreparedStatement prepareNativeStatement(String schema, String sql) throws SQLException {
+    public PreparedStatement prepareNativeStatement(String space, String sql) throws SQLException {
         checkxEnabled();
 
-        return idx.prepareNativeStatement(schema, sql);
+        return idx.prepareNativeStatement(space, sql);
     }
 
     /**
@@ -838,9 +2012,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             return executeQuery(GridCacheQueryType.TEXT, clause, cctx,
                 new IgniteOutClosureX<GridCloseableIterator<IgniteBiTuple<K, V>>>() {
                     @Override public GridCloseableIterator<IgniteBiTuple<K, V>> applyx() throws IgniteCheckedException {
-                        QueryTypeDescriptorImpl type = type(space, resType);
+                        String typeName = typeName(space, resType);
 
-                        return idx.queryLocalText(space, clause, type, filters);
+                        return idx.queryLocalText(space, clause, typeName, filters);
                     }
                 }, true);
         }
@@ -924,20 +2098,35 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * Gets type descriptor for space and type name.
+     * Get type descriptor for the given space and table name.
+     * @param space Space.
+     * @param tblName Table name.
+     * @return Type (if any).
+     */
+    @Nullable private QueryTypeDescriptorImpl type(@Nullable String space, String tblName) {
+        for (QueryTypeDescriptorImpl type : types.values()) {
+            if (F.eq(space, type.space()) && F.eq(tblName, type.tableName()))
+                return type;
+        }
+
+        return null;
+    }
+
+    /**
+     * Gets type name for provided space and type name if type is still valid.
      *
      * @param space Space name.
      * @param typeName Type name.
      * @return Type descriptor.
      * @throws IgniteCheckedException If failed.
      */
-    public QueryTypeDescriptorImpl type(@Nullable String space, String typeName) throws IgniteCheckedException {
+    private String typeName(@Nullable String space, String typeName) throws IgniteCheckedException {
         QueryTypeDescriptorImpl type = typesByName.get(new QueryTypeNameKey(space, typeName));
 
         if (type == null)
             throw new IgniteCheckedException("Failed to find SQL table for type: " + typeName);
 
-        return type;
+        return type.name();
     }
 
     /**
@@ -972,7 +2161,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             throw (IgniteCheckedException)err;
         }
-        catch (CacheException e) {
+        catch (CacheException | IgniteException e) {
             err = e;
 
             throw e;
@@ -998,6 +2187,146 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Send status message to coordinator node.
+     *
+     * @param destNodeId Destination node ID.
+     * @param opId Operation ID.
+     * @param err Error.
+     */
+    public void sendStatusMessage(UUID destNodeId, UUID opId, SchemaOperationException err) {
+        if (log.isDebugEnabled())
+            log.debug("Sending schema operation status message [opId=" + opId + ", crdNode=" + destNodeId +
+                ", err=" + err + ']');
+
+        try {
+            byte[] errBytes = marshalSchemaError(opId, err);
+
+            SchemaOperationStatusMessage msg = new SchemaOperationStatusMessage(opId, errBytes);
+
+            // Messages must go to dedicated schema pool. We cannot push them to query pool because in this case
+            // they could be blocked with other query requests.
+            ctx.io().sendToGridTopic(destNodeId, TOPIC_SCHEMA, msg, SCHEMA_POOL);
+        }
+        catch (IgniteCheckedException e) {
+            if (log.isDebugEnabled())
+                log.debug("Failed to send schema status response [opId=" + opId + ", destNodeId=" + destNodeId +
+                    ", err=" + e + ']');
+        }
+    }
+
+    /**
+     * Process status message.
+     *
+     * @param msg Status message.
+     */
+    private void processStatusMessage(SchemaOperationStatusMessage msg) {
+        synchronized (stateMux) {
+            if (completedOpIds.contains(msg.operationId())) {
+                // Received message from a node which joined topology in the middle of operation execution.
+                if (log.isDebugEnabled())
+                    log.debug("Received status message for completed operation (will ignore) [" +
+                        "opId=" + msg.operationId() + ", sndNodeId=" + msg.senderNodeId() + ']');
+
+                return;
+            }
+
+            UUID opId = msg.operationId();
+
+            SchemaProposeDiscoveryMessage proposeMsg = activeProposals.get(opId);
+
+            if (proposeMsg != null) {
+                SchemaOperation op = schemaOps.get(proposeMsg.schemaKey());
+
+                if (op != null && F.eq(op.id(), opId) && op.started() && coordinator().isLocal()) {
+                    if (log.isDebugEnabled())
+                        log.debug("Received status message [opId=" + msg.operationId() +
+                            ", sndNodeId=" + msg.senderNodeId() + ']');
+
+                    op.manager().onNodeFinished(msg.senderNodeId(), unmarshalSchemaError(msg.errorBytes()));
+
+                    return;
+                }
+            }
+
+            // Put to pending set if operation is not visible/ready yet.
+            pendingMsgs.add(msg);
+
+            if (log.isDebugEnabled())
+                log.debug("Received status message (added to pending set) [opId=" + msg.operationId() +
+                    ", sndNodeId=" + msg.senderNodeId() + ']');
+        }
+    }
+
+    /**
+     * Unwind pending messages for particular operation.
+     *
+     * @param opId Operation ID.
+     * @param mgr Manager.
+     */
+    private void unwindPendingMessages(UUID opId, SchemaOperationManager mgr) {
+        assert Thread.holdsLock(stateMux);
+
+        Iterator<SchemaOperationStatusMessage> it = pendingMsgs.iterator();
+
+        while (it.hasNext()) {
+            SchemaOperationStatusMessage msg = it.next();
+
+            if (F.eq(msg.operationId(), opId)) {
+                mgr.onNodeFinished(msg.senderNodeId(), unmarshalSchemaError(msg.errorBytes()));
+
+                it.remove();
+            }
+        }
+    }
+
+    /**
+     * Marshal schema error.
+     *
+     * @param err Error.
+     * @return Error bytes.
+     */
+    @Nullable private byte[] marshalSchemaError(UUID opId, @Nullable SchemaOperationException err) {
+        if (err == null)
+            return null;
+
+        try {
+            return U.marshal(marsh, err);
+        }
+        catch (Exception e) {
+            U.warn(log, "Failed to marshal schema operation error [opId=" + opId + ", err=" + err + ']', e);
+
+            try {
+                return U.marshal(marsh, new SchemaOperationException("Operation failed, but error cannot be " +
+                    "serialized (see local node log for more details) [opId=" + opId + ", nodeId=" +
+                    ctx.localNodeId() + ']'));
+            }
+            catch (Exception e0) {
+                assert false; // Impossible situation.
+
+                return null;
+            }
+        }
+    }
+
+    /**
+     * Unmarshal schema error.
+     *
+     * @param errBytes Error bytes.
+     * @return Error.
+     */
+    @Nullable private SchemaOperationException unmarshalSchemaError(@Nullable byte[] errBytes) {
+        if (errBytes == null)
+            return null;
+
+        try {
+            return U.unmarshal(marsh, errBytes, U.resolveClassLoader(ctx.config()));
+        }
+        catch (Exception e) {
+            return new SchemaOperationException("Operation failed, but error cannot be deserialized.");
+        }
+    }
+
+    /**
      * @param ver Version.
      */
     public static void setRequestAffinityTopologyVersion(AffinityTopologyVersion ver) {
@@ -1010,4 +2339,160 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     public static AffinityTopologyVersion getRequestAffinityTopologyVersion() {
         return requestTopVer.get();
     }
+
+    /**
+     * Schema operation.
+     */
+    private class SchemaOperation {
+        /** Original propose msg. */
+        private final SchemaProposeDiscoveryMessage proposeMsg;
+
+        /** Next schema operation. */
+        private SchemaOperation next;
+
+        /** Operation manager. */
+        private SchemaOperationManager mgr;
+
+        /** Finish message. */
+        private SchemaFinishDiscoveryMessage finishMsg;
+
+        /** Finish guard. */
+        private final AtomicBoolean finishGuard = new AtomicBoolean();
+
+        /**
+         * Constructor.
+         *
+         * @param proposeMsg Original propose message.
+         */
+        public SchemaOperation(SchemaProposeDiscoveryMessage proposeMsg) {
+            this.proposeMsg = proposeMsg;
+        }
+
+        /**
+         * @return Operation ID.
+         */
+        public UUID id() {
+            return proposeMsg.operation().id();
+        }
+
+        /**
+         * @return Original propose message.
+         */
+        public SchemaProposeDiscoveryMessage proposeMessage() {
+            return proposeMsg;
+        }
+
+        /**
+         * @return Next schema operation.
+         */
+        @Nullable public SchemaOperation next() {
+            return next;
+        }
+
+        /**
+         * @param next Next schema operation.
+         */
+        public void next(SchemaOperation next) {
+            this.next = next;
+        }
+
+        /**
+         * @param finishMsg Finish message.
+         */
+        public void finishMessage(SchemaFinishDiscoveryMessage finishMsg) {
+            this.finishMsg = finishMsg;
+        }
+
+        /**
+         * @return {@code True} if finish request already received.
+         */
+        public boolean hasFinishMessage() {
+            return finishMsg != null;
+        }
+
+        /**
+         * Handle finish message.
+         */
+        @SuppressWarnings("unchecked")
+        public void doFinish() {
+            assert started();
+
+            if (!finishGuard.compareAndSet(false, true))
+                return;
+
+            final UUID opId = id();
+            final SchemaKey key = proposeMsg.schemaKey();
+
+            // Operation might be still in progress on client nodes which are not tracked by coordinator,
+            // so we chain to operation future instead of doing synchronous unwind.
+            mgr.worker().future().listen(new IgniteInClosure<IgniteInternalFuture>() {
+                @Override public void apply(IgniteInternalFuture fut) {
+                    synchronized (stateMux) {
+                        SchemaOperation op = schemaOps.remove(key);
+
+                        assert op != null;
+                        assert F.eq(op.id(), opId);
+
+                        // Chain to the next operation (if any).
+                        final SchemaOperation nextOp = op.next();
+
+                        if (nextOp != null) {
+                            schemaOps.put(key, nextOp);
+
+                            if (log.isDebugEnabled())
+                                log.debug("Next schema change operation started [opId=" + nextOp.id() + ']');
+
+                            assert !nextOp.started();
+
+                            // Cannot execute operation synchronously because it may cause starvation in exchange
+                            // thread under load. Hence, moving short-lived operation to separate worker.
+                            new IgniteThread(ctx.igniteInstanceName(), "schema-circuit-breaker-" + op.id(),
+                                new Runnable() {
+                                @Override public void run() {
+                                    onSchemaPropose(nextOp.proposeMessage());
+                                }
+                            }).start();
+                        }
+                    }
+                }
+            });
+        }
+
+        /**
+         * Unwind operation queue and get tail operation.
+         *
+         * @return Tail operation.
+         */
+        public SchemaOperation unwind() {
+            if (next == null)
+                return this;
+            else
+                return next.unwind();
+        }
+
+        /**
+         * Whether operation started.
+         *
+         * @return {@code True} if started.
+         */
+        public boolean started() {
+            return mgr != null;
+        }
+
+        /**
+         * @return Operation manager.
+         */
+        public SchemaOperationManager manager() {
+            return mgr;
+        }
+
+        /**
+         * @param mgr Operation manager.
+         */
+        public void manager(SchemaOperationManager mgr) {
+            assert this.mgr == null;
+
+            this.mgr = mgr;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
index 44c41c1..b7434d3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
@@ -81,6 +81,13 @@ public interface GridQueryTypeDescriptor {
     public Map<String, GridQueryIndexDescriptor> indexes();
 
     /**
+     * Get text index for this type (if any).
+     *
+     * @return Text index or {@code null}.
+     */
+    public GridQueryIndexDescriptor textIndex();
+
+    /**
      * Gets value class.
      *
      * @return Value class.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/IgniteSQLException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/IgniteSQLException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/IgniteSQLException.java
index b15007e..0666493 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/IgniteSQLException.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/IgniteSQLException.java
@@ -81,6 +81,13 @@ public class IgniteSQLException extends IgniteException {
     }
 
     /**
+     * @return Ignite SQL error code.
+     */
+    public int statusCode() {
+        return statusCode;
+    }
+
+    /**
      * @return JDBC exception containing details from this instance.
      */
     public SQLException toJdbcException() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
index 9d2d20c..1b85af5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
@@ -17,7 +17,9 @@
 
 package org.apache.ignite.internal.processors.query;
 
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.S;
 
@@ -45,22 +47,48 @@ public class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor {
     /** Fields which should be indexed in descending order. */
     private Collection<String> descendings;
 
+    /** Type descriptor. */
+    @GridToStringExclude
+    private final QueryTypeDescriptorImpl typDesc;
+
+    /** Index name. */
+    private final String name;
+
     /** */
     private final QueryIndexType type;
 
     /** */
-    private int inlineSize;
+    private final int inlineSize;
 
     /**
+     * Constructor.
+     *
+     * @param typDesc Type descriptor.
+     * @param name Index name.
      * @param type Type.
+     * @param inlineSize Inline size.
      */
-    public QueryIndexDescriptorImpl(QueryIndexType type, int inlineSize) {
+    public QueryIndexDescriptorImpl(QueryTypeDescriptorImpl typDesc, String name, QueryIndexType type, int inlineSize) {
         assert type != null;
 
+        this.typDesc = typDesc;
+        this.name = name;
         this.type = type;
         this.inlineSize = inlineSize;
     }
 
+    /**
+     * @return Type descriptor.
+     */
+    public QueryTypeDescriptorImpl typeDescriptor() {
+        return typDesc;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return name;
+    }
+
     /** {@inheritDoc} */
     @Override public Collection<String> fields() {
         Collection<String> res = new ArrayList<>(fields.size());
@@ -87,8 +115,14 @@ public class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor {
      * @param field Field name.
      * @param orderNum Field order number in this index.
      * @param descending Sort order.
+     * @return This instance for chaining.
+     * @throws IgniteCheckedException If failed.
      */
-    public void addField(String field, int orderNum, boolean descending) {
+    public QueryIndexDescriptorImpl addField(String field, int orderNum, boolean descending)
+        throws IgniteCheckedException {
+        if (!typDesc.hasField(field))
+            throw new IgniteCheckedException("Field not found: " + field);
+
         fields.add(new T2<>(field, orderNum));
 
         if (descending) {
@@ -97,6 +131,8 @@ public class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor {
 
             descendings.add(field);
         }
+
+        return this;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
new file mode 100644
index 0000000..f580111
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.io.Serializable;
+
+/**
+ * Index key.
+ */
+public class QueryIndexKey implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Space. */
+    private final String space;
+
+    /** Name. */
+    private final String name;
+
+    /**
+     * Constructor.
+     *
+     * @param space Space.
+     * @param name Name.
+     */
+    public QueryIndexKey(String space, String name) {
+        this.space = space;
+        this.name = name;
+    }
+
+    /**
+     * @return Space.
+     */
+    public String space() {
+        return space;
+    }
+
+    /**
+     * @return Name.
+     */
+    public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return 31 * (space != null ? space.hashCode() : 0) + (name != null ? name.hashCode() : 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        QueryIndexKey other = (QueryIndexKey)o;
+
+        return F.eq(name, other.name) && F.eq(space, other.space);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryIndexKey.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2edb935c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
new file mode 100644
index 0000000..395f077
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaFinishDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexCreateOperation;
+import org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Dynamic cache schema.
+ */
+public class QuerySchema implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Query entities. */
+    private final Collection<QueryEntity> entities = new LinkedList<>();
+
+    /** Mutex for state synchronization. */
+    private final Object mux = new Object();
+
+    /**
+     * Default constructor.
+     */
+    public QuerySchema() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param entities Query entities.
+     */
+    public QuerySchema(Collection<QueryEntity> entities) {
+        assert entities != null;
+
+        for (QueryEntity qryEntity : entities)
+            this.entities.add(new QueryEntity(qryEntity));
+    }
+
+    /**
+     * Copy object.
+     *
+     * @return Copy.
+     */
+    public QuerySchema copy() {
+        synchronized (mux) {
+            QuerySchema res = new QuerySchema();
+
+            for (QueryEntity qryEntity : entities)
+                res.entities.add(new QueryEntity(qryEntity));
+
+            return res;
+        }
+    }
+
+    /**
+     * Process finish message.
+     *
+     * @param msg Message.
+     */
+    public void finish(SchemaFinishDiscoveryMessage msg) {
+        synchronized (mux) {
+            SchemaAbstractOperation op = msg.operation();
+
+            if (op instanceof SchemaIndexCreateOperation) {
+                SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation)op;
+
+                for (QueryEntity entity : entities) {
+                    String tblName = QueryUtils.tableName(entity);
+
+                    if (F.eq(tblName, op0.tableName())) {
+                        boolean exists = false;
+
+                        for (QueryIndex idx : entity.getIndexes()) {
+                            if (F.eq(idx.getName(), op0.indexName())) {
+                                exists = true;
+
+                                break;
+                            }
+                        }
+
+                        if (!exists) {
+                            List<QueryIndex> idxs = new ArrayList<>(entity.getIndexes());
+
+                            idxs.add(op0.index());
+
+                            entity.clearIndexes();
+                            entity.setIndexes(idxs);
+                        }
+
+                        break;
+                    }
+                }
+            }
+            else {
+                assert op instanceof SchemaIndexDropOperation;
+
+                SchemaIndexDropOperation op0 = (SchemaIndexDropOperation)op;
+
+                for (QueryEntity entity : entities) {
+                    Collection<QueryIndex> idxs = entity.getIndexes();
+
+                    QueryIndex victim = null;
+
+                    for (QueryIndex idx : idxs) {
+                        if (F.eq(idx.getName(), op0.indexName())) {
+                            victim = idx;
+
+                            break;
+                        }
+                    }
+
+                    if (victim != null) {
+                        List<QueryIndex> newIdxs = new ArrayList<>(entity.getIndexes());
+
+                        newIdxs.remove(victim);
+
+                        entity.clearIndexes();
+                        entity.setIndexes(idxs);
+
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * @return Query entities.
+     */
+    public Collection<QueryEntity> entities() {
+        synchronized (mux) {
+            return new ArrayList<>(entities);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QuerySchema.class, this);
+    }
+}


[42/50] [abbrv] ignite git commit: IGNITE-3523 IGFS: Remove "initialize default path modes" feature. This closes #1786.

Posted by sb...@apache.org.
IGNITE-3523 IGFS: Remove "initialize default path modes" feature. This closes #1786.


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

Branch: refs/heads/ignite-1561
Commit: 22d5e55bee69403c4f9f8da9c113751ce110aa2d
Parents: 36e7e19
Author: tledkov-gridgain <tl...@gridgain.com>
Authored: Wed Apr 19 12:54:14 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Wed Apr 19 12:54:14 2017 +0300

----------------------------------------------------------------------
 .../configuration/FileSystemConfiguration.java  |  54 +-------
 .../internal/processors/igfs/IgfsImpl.java      |  22 +---
 .../igfs/IgfsAbstractBaseSelfTest.java          |   9 --
 .../igfs/IgfsDualAbstractSelfTest.java          |  33 -----
 .../processors/igfs/IgfsModesSelfTest.java      | 130 -------------------
 .../igfs/HadoopFIleSystemFactorySelfTest.java   |  12 +-
 6 files changed, 14 insertions(+), 246 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/22d5e55b/modules/core/src/main/java/org/apache/ignite/configuration/FileSystemConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/FileSystemConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/FileSystemConfiguration.java
index 337506c..d667fe8 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/FileSystemConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/FileSystemConfiguration.java
@@ -76,9 +76,6 @@ public class FileSystemConfiguration {
     /** Default IPC endpoint enabled flag. */
     public static final boolean DFLT_IPC_ENDPOINT_ENABLED = true;
 
-    /** Default value of whether to initialize default path modes. */
-    public static final boolean DFLT_INIT_DFLT_PATH_MODES = false;
-
     /** Default value of metadata co-location flag. */
     public static final boolean DFLT_COLOCATE_META = true;
 
@@ -145,9 +142,6 @@ public class FileSystemConfiguration {
     /** Maximum range length. */
     private long maxTaskRangeLen;
 
-    /** Whether to initialize default path modes. */
-    private boolean initDfltPathModes = DFLT_INIT_DFLT_PATH_MODES;
-
     /** Metadata co-location flag. */
     private boolean colocateMeta = DFLT_COLOCATE_META;
 
@@ -191,7 +185,6 @@ public class FileSystemConfiguration {
         fragmentizerThrottlingBlockLen = cfg.getFragmentizerThrottlingBlockLength();
         fragmentizerThrottlingDelay = cfg.getFragmentizerThrottlingDelay();
         secondaryFs = cfg.getSecondaryFileSystem();
-        initDfltPathModes = cfg.isInitializeDefaultPathModes();
         ipcEndpointCfg = cfg.getIpcEndpointConfiguration();
         ipcEndpointEnabled = cfg.isIpcEndpointEnabled();
         maxSpace = cfg.getMaxSpaceSize();
@@ -579,15 +572,6 @@ public class FileSystemConfiguration {
      * <p>
      * If path doesn't correspond to any specified prefix or mappings are not provided, then
      * {@link #getDefaultMode()} is used.
-     * <p>
-     * If {@link #isInitializeDefaultPathModes()} is set to {@code true}, the following path modes will be created
-     * by default:
-     * <li>{@code /ignite/primary} and all it's sub-folders will always work in {@code PRIMARY} mode.</li>
-     * <p>
-     * And in case secondary file system URI is provided:
-     * <li>{@code /ignite/proxy} and all it's sub-folders will always work in {@code PROXY} mode.</li>
-     * <li>{@code /ignite/sync} and all it's sub-folders will always work in {@code DUAL_SYNC} mode.</li>
-     * <li>{@code /ignite/async} and all it's sub-folders will always work in {@code DUAL_ASYNC} mode.</li>
      *
      * @return Map of paths to {@code IGFS} modes.
      */
@@ -644,6 +628,7 @@ public class FileSystemConfiguration {
      * Sets delay in milliseconds for which fragmentizer is paused.
      *
      * @param fragmentizerThrottlingDelay Delay in milliseconds.
+     * @return {@code this} for chaining.
      */
     public FileSystemConfiguration setFragmentizerThrottlingDelay(long fragmentizerThrottlingDelay) {
         this.fragmentizerThrottlingDelay = fragmentizerThrottlingDelay;
@@ -759,43 +744,6 @@ public class FileSystemConfiguration {
     }
 
     /**
-     * Get whether to initialize default path modes.
-     * <p>
-     * When set to {@code true} Ignite will automatically create the following path modes:
-     * <ul>
-     *     <li>{@code /ignite/primary} - will work in {@link IgfsMode#PRIMARY} mode;</li>
-     *     <li>{@code /ignite/sync} - will work in {@link IgfsMode#DUAL_SYNC} mode (only if secondary file system
-     *         is set);</li>
-     *     <li>{@code /ignite/async} - will work in {@link IgfsMode#DUAL_ASYNC} mode (only if secondary file system
-     *         is set);</li>
-     *     <li>{@code /ignite/proxy} - will work in {@link IgfsMode#PROXY} mode (only if secondary file system
-     *         is set).</li>
-     * </ul>
-     * See {@link #getPathModes()} for more information about path modes.
-     * <p>
-     * Defaults to {@link #DFLT_INIT_DFLT_PATH_MODES}.
-     *
-     * @return {@code True} if default path modes will be initialized.
-     */
-    public boolean isInitializeDefaultPathModes() {
-        return initDfltPathModes;
-    }
-
-    /**
-     * Set whether to initialize default path modes.
-     * <p>
-     * See {@link #isInitializeDefaultPathModes()} for more information.
-     *
-     * @param initDfltPathModes Whether to initialize default path modes.
-     * @return {@code this} for chaining.
-     */
-    public FileSystemConfiguration setInitializeDefaultPathModes(boolean initDfltPathModes) {
-        this.initDfltPathModes = initDfltPathModes;
-
-        return this;
-    }
-
-    /**
      * Get whether to co-locate metadata on a single node.
      * <p>
      * Normally Ignite spread ownership of particular keys among all cache nodes. Transaction with keys owned by

http://git-wip-us.apache.org/repos/asf/ignite/blob/22d5e55b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
index 1c0fbc2..6a7400c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
@@ -199,28 +199,10 @@ public final class IgfsImpl implements IgfsEx {
             dfltMode = cfg.getDefaultMode();
 
         Map<String, IgfsMode> cfgModes = new LinkedHashMap<>();
-        Map<String, IgfsMode> dfltModes = new LinkedHashMap<>(4, 1.0f);
-
-        if (cfg.isInitializeDefaultPathModes() && IgfsUtils.isDualMode(dfltMode)) {
-            dfltModes.put("/ignite/primary", PRIMARY);
-
-            if (secondaryFs != null) {
-                dfltModes.put("/ignite/proxy", PROXY);
-                dfltModes.put("/ignite/sync", DUAL_SYNC);
-                dfltModes.put("/ignite/async", DUAL_ASYNC);
-            }
-        }
-
-        cfgModes.putAll(dfltModes);
 
         if (cfg.getPathModes() != null) {
-            for (Map.Entry<String, IgfsMode> e : cfg.getPathModes().entrySet()) {
-                if (!dfltModes.containsKey(e.getKey()))
-                    cfgModes.put(e.getKey(), e.getValue());
-                else
-                    U.warn(log, "Ignoring path mode because it conflicts with Ignite reserved path " +
-                        "(use another path) [mode=" + e.getValue() + ", path=" + e.getKey() + ']');
-            }
+            for (Map.Entry<String, IgfsMode> e : cfg.getPathModes().entrySet())
+                cfgModes.put(e.getKey(), e.getValue());
         }
 
         ArrayList<T2<IgfsPath, IgfsMode>> modes = null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/22d5e55b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
index 47a768e..d215815 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
@@ -211,13 +211,6 @@ public abstract class IgfsAbstractBaseSelfTest extends IgfsCommonAbstractTest {
     }
 
     /**
-     * @return Relaxed consistency flag.
-     */
-    protected boolean initializeDefaultPathModes() {
-        return false;
-    }
-
-    /**
      * @return Client flag.
      */
     protected boolean client() {
@@ -369,8 +362,6 @@ public abstract class IgfsAbstractBaseSelfTest extends IgfsCommonAbstractTest {
         igfsCfg.setRelaxedConsistency(relaxedConsistency());
         igfsCfg.setFragmentizerEnabled(fragmentizerEnabled());
 
-        igfsCfg.setInitializeDefaultPathModes(initializeDefaultPathModes());
-
         CacheConfiguration dataCacheCfg = defaultCacheConfiguration();
 
         dataCacheCfg.setNearConfiguration(null);

http://git-wip-us.apache.org/repos/asf/ignite/blob/22d5e55b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java
index 7b83cfc..12f46da 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java
@@ -51,39 +51,6 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest {
         super(mode);
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean initializeDefaultPathModes() {
-        // Enable default modes in order to test various modes.
-        return true;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDefaultDirectories() throws Exception {
-        IgfsPath gg = new IgfsPath("/ignite");
-        IgfsPath[] paths = paths(
-            gg, new IgfsPath(gg, "sync"), new IgfsPath(gg, "async"), new IgfsPath(gg, "primary"));
-
-        create(igfs, paths, null);
-
-        for (IgfsPath p : paths)
-            assert igfs.exists(p);
-
-        assert igfs.modeResolver().resolveMode(gg) == mode;
-
-        if (mode != PROXY) {
-            assert igfs.modeResolver().resolveMode(new IgfsPath(gg, "sync")) == IgfsMode.DUAL_SYNC;
-            assert igfs.modeResolver().resolveMode(new IgfsPath(gg, "async")) == IgfsMode.DUAL_ASYNC;
-            assert igfs.modeResolver().resolveMode(new IgfsPath(gg, "primary")) == IgfsMode.PRIMARY;
-            assert !igfsSecondary.exists("/ignite/primary"); // PRIMARY mode path must exist in upper level fs only.
-        }
-
-        // All the child paths of "/ignite/" must be visible in listings:
-        assert igfs.listFiles(gg).size() == 3;
-        assert igfs.listPaths(gg).size() == 3;
-    }
-
     /**
      * Test existence check when the path exists only remotely.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/22d5e55b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsModesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsModesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsModesSelfTest.java
index 40ac0e1..0720d55 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsModesSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsModesSelfTest.java
@@ -100,7 +100,6 @@ public class IgfsModesSelfTest extends IgfsCommonAbstractTest {
 
         igfsCfg.setName("igfs");
         igfsCfg.setBlockSize(512 * 1024);
-        igfsCfg.setInitializeDefaultPathModes(true);
 
         if (setNullMode)
             igfsCfg.setDefaultMode(null);
@@ -217,135 +216,6 @@ public class IgfsModesSelfTest extends IgfsCommonAbstractTest {
     }
 
     /**
-     * Test predefined path modes for PRIMARY mode.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDefaultFoldersPrimary() throws Exception {
-        setSecondaryFs = true;
-
-        mode = DUAL_ASYNC;
-
-        startUp();
-
-        checkMode("/ignite/primary", PRIMARY);
-        checkMode("/ignite/primary/", PRIMARY);
-        checkMode("/ignite/primary/subfolder", PRIMARY);
-        checkMode("/ignite/primary/folder/file.txt", PRIMARY);
-        checkMode("/ignite/primaryx", DUAL_ASYNC);
-        checkMode("/ignite/primaryx/", DUAL_ASYNC);
-        checkMode("/ignite/primaryx/subfolder", DUAL_ASYNC);
-        checkMode("/ignite/primaryx/folder/file.txt", DUAL_ASYNC);
-    }
-
-    /**
-     * Test predefined path modes for all modes except of PRIMARY mode.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDefaultFoldersNonPrimary() throws Exception {
-        setSecondaryFs = true;
-
-        mode = DUAL_ASYNC;
-
-        startUp();
-
-        checkMode("/ignite/proxy", PROXY);
-        checkMode("/ignite/proxy/", PROXY);
-        checkMode("/ignite/proxy/subfolder", PROXY);
-        checkMode("/ignite/proxy/folder/file.txt", PROXY);
-        checkMode("/ignite/proxyx", mode);
-        checkMode("/ignite/proxyx/", mode);
-        checkMode("/ignite/proxyx/subfolder", mode);
-        checkMode("/ignite/proxyx/folder/file.txt", mode);
-
-        checkMode("/userdir/ignite/proxy", mode);
-        checkMode("/userdir/ignite/proxy/", mode);
-        checkMode("/userdir/ignite/proxy/subfolder", mode);
-        checkMode("/userdir/ignite/proxy/folder/file.txt", mode);
-
-        checkMode("/ignite/sync", DUAL_SYNC);
-        checkMode("/ignite/sync/", DUAL_SYNC);
-        checkMode("/ignite/sync/subfolder", DUAL_SYNC);
-        checkMode("/ignite/sync/folder/file.txt", DUAL_SYNC);
-
-        checkMode("/ignite/syncx", mode);
-        checkMode("/ignite/syncx/", mode);
-        checkMode("/ignite/syncx/subfolder", mode);
-        checkMode("/ignite/syncx/folder/file.txt", mode);
-
-        checkMode("/userdir/ignite/sync", mode);
-        checkMode("/userdir/ignite/sync/", mode);
-        checkMode("/userdir/ignite/sync/subfolder", mode);
-        checkMode("/userdir/ignite/sync/folder/file.txt", mode);
-
-        checkMode("/ignite/async", DUAL_ASYNC);
-        checkMode("/ignite/async/", DUAL_ASYNC);
-        checkMode("/ignite/async/subfolder", DUAL_ASYNC);
-        checkMode("/ignite/async/folder/file.txt", DUAL_ASYNC);
-
-        checkMode("/ignite/asyncx", mode);
-        checkMode("/ignite/asyncx/", mode);
-        checkMode("/ignite/asyncx/subfolder", mode);
-        checkMode("/ignite/asyncx/folder/file.txt", mode);
-
-        checkMode("/userdir/ignite/async", mode);
-        checkMode("/userdir/ignite/async/", mode);
-        checkMode("/userdir/ignite/async/subfolder", mode);
-        checkMode("/userdir/ignite/async/folder/file.txt", mode);
-    }
-
-    /**
-     * Ensure that in case secondary file system URI is not provided, all predefined have no special mappings. This test
-     * doesn't make sense for PRIMARY mode since in case URI is not provided DUAL_* modes automatically transforms to
-     * PRIMARY and for PROXY mode we will have an exception during startup.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDefaultsNoSecondaryUriNonPrimary() throws Exception {
-        startUp();
-
-        checkMode("/ignite/proxy", PRIMARY);
-        checkMode("/ignite/proxy/", PRIMARY);
-        checkMode("/ignite/proxy/subfolder", PRIMARY);
-        checkMode("/ignite/proxy/folder/file.txt", PRIMARY);
-
-        checkMode("/ignite/sync", PRIMARY);
-        checkMode("/ignite/sync/", PRIMARY);
-        checkMode("/ignite/sync/subfolder", PRIMARY);
-        checkMode("/ignite/sync/folder/file.txt", PRIMARY);
-
-        checkMode("/ignite/async", PRIMARY);
-        checkMode("/ignite/async/", PRIMARY);
-        checkMode("/ignite/async/subfolder", PRIMARY);
-        checkMode("/ignite/async/folder/file.txt", PRIMARY);
-    }
-
-    /**
-     * Ensure that it is impossible to override mappings for /ignite/* folders.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDefaultFoldersOverride() throws Exception {
-        setSecondaryFs = true;
-
-        mode = DUAL_ASYNC;
-
-        pathModes(
-            F.t("/ignite/primary", PROXY),
-            F.t("/ignite/proxy", DUAL_SYNC),
-            F.t("/ignite/sync", DUAL_ASYNC),
-            F.t("/ignite/async", PRIMARY));
-
-        startUp();
-
-        checkMode("/ignite/primary", PRIMARY);
-        checkMode("/ignite/proxy", PROXY);
-        checkMode("/ignite/sync", DUAL_SYNC);
-        checkMode("/ignite/async", DUAL_ASYNC);
-    }
-
-    /**
      * Ensure that DUAL_ASYNC mode is set by default.
      *
      * @throws Exception If failed.

http://git-wip-us.apache.org/repos/asf/ignite/blob/22d5e55b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/HadoopFIleSystemFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/HadoopFIleSystemFactorySelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/HadoopFIleSystemFactorySelfTest.java
index 1793a05..04ef263 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/HadoopFIleSystemFactorySelfTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/HadoopFIleSystemFactorySelfTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.processors.hadoop.impl.igfs;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -224,7 +226,6 @@ public class HadoopFIleSystemFactorySelfTest extends IgfsCommonAbstractTest {
         igfsCfg.setDefaultMode(dfltMode);
         igfsCfg.setIpcEndpointConfiguration(endpointCfg);
         igfsCfg.setSecondaryFileSystem(secondaryFs);
-        igfsCfg.setInitializeDefaultPathModes(true);
 
         CacheConfiguration dataCacheCfg = defaultCacheConfiguration();
 
@@ -243,6 +244,15 @@ public class HadoopFIleSystemFactorySelfTest extends IgfsCommonAbstractTest {
         igfsCfg.setDataCacheConfiguration(dataCacheCfg);
         igfsCfg.setMetaCacheConfiguration(metaCacheCfg);
 
+        if (secondaryFs != null) {
+            Map<String, IgfsMode> modes = new HashMap<>();
+            modes.put("/ignite/sync/", IgfsMode.DUAL_SYNC);
+            modes.put("/ignite/async/", IgfsMode.DUAL_ASYNC);
+            modes.put("/ignite/proxy/", IgfsMode.PROXY);
+
+            igfsCfg.setPathModes(modes);
+        }
+
         IgniteConfiguration cfg = new IgniteConfiguration();
 
         cfg.setIgniteInstanceName(name);