You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2017/04/17 16:01:57 UTC
[15/26] ignite git commit: IGNITE-5000 Rename Ignite Math module to
Ignite ML module
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/SparseDistributedMatrixTest.java
deleted file mode 100644
index 8218a12..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/SparseLocalOnHeapMatrixConstructorTest.java
deleted file mode 100644
index fc675c1..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/matrix/TransposedMatrixViewTest.java
deleted file mode 100644
index 5eacfea..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixArrayStorageTest.java
deleted file mode 100644
index 817dd49..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixBaseStorageTest.java
deleted file mode 100644
index 8df19e4..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixOffHeapStorageTest.java
deleted file mode 100644
index a3b21bb..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageFixtures.java
deleted file mode 100644
index 6353c38..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/MatrixStorageImplementationTest.java
deleted file mode 100644
index 6ec09bd..0000000
--- a/modules/math/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);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/matrix/SparseDistributedMatrixStorageTest.java
deleted file mode 100644
index 66fe9b4..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/RandomAccessSparseVectorStorageTest.java
deleted file mode 100644
index 8a223fc..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/SparseLocalOffHeapVectorStorageTest.java
deleted file mode 100644
index a7751d8..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorArrayStorageTest.java
deleted file mode 100644
index 2afc97b..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorBaseStorageTest.java
deleted file mode 100644
index 988f8c3..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/storage/vector/VectorOffheapStorageTest.java
deleted file mode 100644
index 2645926..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/vector/AbstractVectorTest.java
deleted file mode 100644
index c7927a5..0000000
--- a/modules/math/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/732dfea9/modules/math/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/math/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java b/modules/math/src/test/java/org/apache/ignite/math/impls/vector/CacheVectorTest.java
deleted file mode 100644
index f276820..0000000
--- a/modules/math/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;
- }
- }
-}