You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ch...@apache.org on 2018/05/16 12:36:58 UTC
[2/9] ignite git commit: IGNITE-8450: [ML] Cleanup the ML package:
remove unused vector/matrix classes.
http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/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
deleted file mode 100644
index 65f3453..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrixTest.java
+++ /dev/null
@@ -1,316 +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.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 java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-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.Vector;
-import org.apache.ignite.ml.math.distributed.DistributedStorage;
-import org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey;
-import org.apache.ignite.ml.math.impls.MathTestConstants;
-import org.apache.ignite.ml.math.impls.storage.matrix.SparseDistributedMatrixStorage;
-import org.apache.ignite.ml.math.impls.vector.SparseDistributedVector;
-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;
-
- /** Precision. */
- private static final double PRECISION = 0.0;
-
- /** */
- private static final int MATRIX_SIZE = 10;
-
- /** 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 {
- 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);
-
- assertEquals("Unexpected value for matrix element[" + i + " " + j + "]", v, cacheMatrix.get(i, j), PRECISION);
- }
- }
- }
-
- /** */
- 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, PRECISION);
- }
-
- /** 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);
- }
-
- /**
- * TODO: IGNITE-5102, wrong min/max, wait for fold/map fix
- */
- 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);
-
- Matrix copiedMtx = cacheMatrix.copy();
-
- for (int i = 0; i < cacheMatrix.rowSize(); i++)
- for (int j = 0; j < cacheMatrix.columnSize(); j++)
- assert copiedMtx.get(i, j) == cacheMatrix.get(i, j);
- }
-
- /** */
- public void testCacheBehaviour() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- SparseDistributedMatrix cacheMatrix1 = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
- SparseDistributedMatrix cacheMatrix2 = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
- initMtx(cacheMatrix1);
- initMtx(cacheMatrix2);
-
- Collection<String> cacheNames = ignite.cacheNames();
-
- assert cacheNames.contains(((DistributedStorage)cacheMatrix1.getStorage()).cacheName());
-
- IgniteCache<RowColMatrixKey, Map<Integer, Double>> cache = ignite.getOrCreateCache(((DistributedStorage)cacheMatrix1.getStorage()).cacheName());
-
- Set<RowColMatrixKey> keySet1 = ((SparseDistributedMatrixStorage)cacheMatrix1.getStorage()).getAllKeys();
- Set<RowColMatrixKey> keySet2 = ((SparseDistributedMatrixStorage)cacheMatrix2.getStorage()).getAllKeys();
-
- assert cache.containsKeys(keySet1) ||
- keySet1.stream().allMatch(k -> cache.invoke(k, (entry, arguments) -> entry.getKey().equals(k) && entry.getValue().size() == 100));
- assert cache.containsKeys(keySet2) ||
- keySet2.stream().allMatch(k -> cache.invoke(k, (entry, arguments) -> entry.getKey().equals(k) && entry.getValue().size() == 100));
-
- cacheMatrix2.destroy();
-
- assert cache.containsKeys(keySet1) ||
- keySet1.stream().allMatch(k -> cache.invoke(k, (entry, arguments) -> entry.getKey().equals(k) && entry.getValue().size() == 100));
- assert !cache.containsKeys(keySet2) &&
- keySet2.stream().allMatch(k -> cache.invoke(k, (entry, arguments) -> entry.getKey().equals(k) && entry.getValue() == null));
-
- cacheMatrix1.destroy();
-
- assert !cache.containsKeys(keySet1) &&
- keySet1.stream().allMatch(k -> cache.invoke(k, (entry, arguments) -> entry.getKey().equals(k) && entry.getValue() == null));
- }
-
- /** */
- public void testLike() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
- assertNotNull(cacheMatrix.like(1, 1));
- }
-
- /** */
- public void testLikeVector() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- cacheMatrix = new SparseDistributedMatrix(rows, cols, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
- Vector v = cacheMatrix.likeVector(1);
- assert v.size() == 1;
- assert v instanceof SparseDistributedVector;
- }
-
- /** */
- public void testMatrixTimes() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- int size = MATRIX_SIZE;
-
- SparseDistributedMatrix cacheMatrix1 = new SparseDistributedMatrix(size, size, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
- SparseDistributedMatrix cacheMatrix2 = new SparseDistributedMatrix(size, size, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
-
- for (int i = 0; i < size; i++) {
- cacheMatrix1.setX(i, i, i);
- cacheMatrix2.setX(i, i, i);
- }
-
- Matrix res = cacheMatrix1.times(cacheMatrix2);
-
- for (int i = 0; i < size; i++)
- for (int j = 0; j < size; j++)
- if (i == j)
- assertEquals(UNEXPECTED_VAL, i * i, res.get(i, j), PRECISION);
- else
- assertEquals(UNEXPECTED_VAL, 0, res.get(i, j), PRECISION);
- }
-
- /** */
- 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/9dccb3db/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
deleted file mode 100644
index 22ec7cc..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/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
deleted file mode 100644
index 7c2d415..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseDistributedVectorStorageTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseDistributedVectorStorageTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseDistributedVectorStorageTest.java
deleted file mode 100644
index f433725..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/storage/vector/SparseDistributedVectorStorageTest.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.ml.math.impls.storage.vector;
-
-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 SparseDistributedVectorStorage}.
- */
-@GridCommonTest(group = "Distributed Models")
-public class SparseDistributedVectorStorageTest 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 SparseDistributedVectorStorageTest() {
- 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 size = MathTestConstants.STORAGE_SIZE;
-
- SparseDistributedVectorStorage storage = new SparseDistributedVectorStorage(size, StorageConstants.RANDOM_ACCESS_MODE);
-
- assertNotNull("SparseDistributedMatrixStorage cache is null.", storage.cache());
- }
-
- /** */
- public void testSetGet() throws Exception {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- final int size = MathTestConstants.STORAGE_SIZE;
-
- SparseDistributedVectorStorage storage = new SparseDistributedVectorStorage(size, StorageConstants.RANDOM_ACCESS_MODE);
-
- for (int i = 0; i < size; i++) {
- double v = Math.random();
- storage.set(i, v);
-
- assert Double.compare(v, storage.get(i)) == 0;
- assert Double.compare(v, storage.get(i)) == 0;
- }
- }
-
- /** */
- public void testAttributes() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- final int size = MathTestConstants.STORAGE_SIZE;
-
- SparseDistributedVectorStorage storage = new SparseDistributedVectorStorage(size, StorageConstants.RANDOM_ACCESS_MODE);
-
- assertEquals(UNEXPECTED_ATTRIBUTE_VALUE, storage.size(), size);
-
- 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/9dccb3db/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
deleted file mode 100644
index 1008cc2..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/CacheVectorTest.java
+++ /dev/null
@@ -1,430 +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.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.distributed.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 testSumEmptyVector() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- IdentityValueMapper valMapper = new IdentityValueMapper();
- CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
-
- cacheVector.sum();
- }
-
- /** */
- 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/9dccb3db/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
deleted file mode 100644
index c5c0bbd..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/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
deleted file mode 100644
index 1e99f7e..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/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
deleted file mode 100644
index f07a3fd..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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: IGNITE-5824, 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));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/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
deleted file mode 100644
index 49e1a50..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/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
deleted file mode 100644
index db4d5de..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/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
deleted file mode 100644
index a693319..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/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.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/9dccb3db/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseBlockDistributedVectorTest.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseBlockDistributedVectorTest.java b/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseBlockDistributedVectorTest.java
deleted file mode 100644
index 6b2590c..0000000
--- a/modules/ml/src/test/java/org/apache/ignite/ml/math/impls/vector/SparseBlockDistributedVectorTest.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.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 org.apache.ignite.Ignite;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.ml.math.Vector;
-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 SparseDistributedVector}.
- */
-@GridCommonTest(group = "Distributed Models")
-public class SparseBlockDistributedVectorTest extends GridCommonAbstractTest {
- /** Number of nodes in grid */
- private static final int NODE_COUNT = 3;
-
- /** Precision. */
- private static final double PRECISION = 0.0;
-
- /** Grid instance. */
- private Ignite ignite;
-
- /** Vector size */
- private final int size = MathTestConstants.STORAGE_SIZE;
-
- /** Vector for tests */
- private SparseBlockDistributedVector sparseBlockDistributedVector;
-
- /**
- * Default constructor.
- */
- public SparseBlockDistributedVectorTest() {
- 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 {
- if (sparseBlockDistributedVector != null) {
- sparseBlockDistributedVector.destroy();
- sparseBlockDistributedVector = null;
- }
- }
-
- /** */
- public void testGetSet() throws Exception {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
-
- for (int i = 0; i < size; i++) {
- double v = Math.random();
- sparseBlockDistributedVector.set(i, v);
- assertEquals("Unexpected value for vector element[" + i + "]", v, sparseBlockDistributedVector.get(i), PRECISION);
- }
- }
-
- /** */
- public void testExternalize() throws IOException, ClassNotFoundException {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
-
- sparseBlockDistributedVector.set(1, 1.0);
-
- ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
- ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
-
- objOutputStream.writeObject(sparseBlockDistributedVector);
-
- ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
- ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
-
- SparseBlockDistributedVector objRestored = (SparseBlockDistributedVector)objInputStream.readObject();
-
- assertTrue(MathTestConstants.VAL_NOT_EQUALS, sparseBlockDistributedVector.equals(objRestored));
- assertEquals(MathTestConstants.VAL_NOT_EQUALS, objRestored.get(1), 1.0, PRECISION);
- }
-
- /** Test simple math. */
- public void testMath() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
- initVector(sparseBlockDistributedVector);
-
- sparseBlockDistributedVector.assign(2.0);
- for (int i = 0; i < sparseBlockDistributedVector.size(); i++)
- assertEquals(UNEXPECTED_VAL, 2.0, sparseBlockDistributedVector.get(i), PRECISION);
-
- sparseBlockDistributedVector.plus(3.0);
- for (int i = 0; i < sparseBlockDistributedVector.size(); i++)
- assertEquals(UNEXPECTED_VAL, 5.0, sparseBlockDistributedVector.get(i), PRECISION);
-
- sparseBlockDistributedVector.times(2.0);
- for (int i = 0; i < sparseBlockDistributedVector.size(); i++)
- assertEquals(UNEXPECTED_VAL, 10.0, sparseBlockDistributedVector.get(i), PRECISION);
-
- sparseBlockDistributedVector.divide(10.0);
- for (int i = 0; i < sparseBlockDistributedVector.size(); i++)
- assertEquals(UNEXPECTED_VAL, 1.0, sparseBlockDistributedVector.get(i), PRECISION);
- }
-
- /** */
- public void testMap() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
- initVector(sparseBlockDistributedVector);
-
- sparseBlockDistributedVector.map(i -> 100.0);
- for (int i = 0; i < sparseBlockDistributedVector.size(); i++)
- assertEquals(UNEXPECTED_VAL, 100.0, sparseBlockDistributedVector.get(i), PRECISION);
- }
-
- /** */
- public void testCopy() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
-
- Vector cp = sparseBlockDistributedVector.copy();
- assertNotNull(cp);
- for (int i = 0; i < size; i++)
- assertEquals(UNEXPECTED_VAL, cp.get(i), sparseBlockDistributedVector.get(i), PRECISION);
- }
-
- /** */
- public void testLike() {
- IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
-
- sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
-
- assertNotNull(sparseBlockDistributedVector.like(1));
- }
-
- /** */
- private void initVector(Vector v) {
- for (int i = 0; i < v.size(); i++)
- v.set(i, 1.0);
- }
-}