Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C9B9C200C5C for ; Thu, 20 Apr 2017 10:39:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C84E6160BD8; Thu, 20 Apr 2017 08:39:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4DACA160B91 for ; Thu, 20 Apr 2017 10:39:11 +0200 (CEST) Received: (qmail 1913 invoked by uid 500); 20 Apr 2017 08:39:09 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 1503 invoked by uid 99); 20 Apr 2017 08:39:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Apr 2017 08:39:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 32692E10F8; Thu, 20 Apr 2017 08:39:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Thu, 20 Apr 2017 08:39:18 -0000 Message-Id: In-Reply-To: <2e8d7ef222ea405998aa3e7df9518002@git.apache.org> References: <2e8d7ef222ea405998aa3e7df9518002@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/71] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math module to Ignite ML module added missed licenses renamed packages fixed wrong ml profile activation archived-at: Thu, 20 Apr 2017 08:39:13 -0000 http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html b/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html deleted file mode 100644 index 19a907a..0000000 --- a/modules/ml/src/main/resources/org/apache/ignite/math/d3-matrix-template.html +++ /dev/null @@ -1,128 +0,0 @@ - - - -IgniteML - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html b/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html deleted file mode 100644 index 7644481..0000000 --- a/modules/ml/src/main/resources/org/apache/ignite/math/d3-vector-template.html +++ /dev/null @@ -1,111 +0,0 @@ - - - -IgniteML - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html new file mode 100644 index 0000000..19a907a --- /dev/null +++ b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-matrix-template.html @@ -0,0 +1,128 @@ + + + +IgniteML + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html new file mode 100644 index 0000000..7644481 --- /dev/null +++ b/modules/ml/src/main/resources/org/apache/ignite/ml/math/d3-vector-template.html @@ -0,0 +1,111 @@ + + + +IgniteML + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java b/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java deleted file mode 100644 index 218b7ff..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/ExternalizeTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import org.apache.ignite.math.impls.MathTestConstants; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Common test for externalization. - */ -public abstract class ExternalizeTest { - /** */ - protected void externalizeTest(T initObj) { - T objRestored = null; - - try { - ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream(); - ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream); - - objOutputStream.writeObject(initObj); - - ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray()); - ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream); - - objRestored = (T)objInputStream.readObject(); - - assertTrue(MathTestConstants.VAL_NOT_EQUALS, initObj.equals(objRestored)); - assertTrue(MathTestConstants.VAL_NOT_EQUALS, Integer.compare(initObj.hashCode(), objRestored.hashCode()) == 0); - } - catch (ClassNotFoundException | IOException e) { - fail(e + " [" + e.getMessage() + "]"); - } - finally { - if (objRestored != null) - objRestored.destroy(); - } - } - - /** */ - @Test - public abstract void externalizeTest(); -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java deleted file mode 100644 index 318ea95..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/MathImplDistributedTestSuite.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math; - -import org.apache.ignite.math.impls.matrix.CacheMatrixTest; -import org.apache.ignite.math.impls.matrix.SparseDistributedMatrixTest; -import org.apache.ignite.math.impls.storage.matrix.SparseDistributedMatrixStorageTest; -import org.apache.ignite.math.impls.vector.CacheVectorTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * Test suite for all distributed tests located in org.apache.ignite.math.impls.* package. - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ - CacheVectorTest.class, - CacheMatrixTest.class, - SparseDistributedMatrixStorageTest.class, - SparseDistributedMatrixTest.class, -}) -public class MathImplDistributedTestSuite { - // No-op. -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java deleted file mode 100644 index a652e7f..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/MathImplLocalTestSuite.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math; - -import org.apache.ignite.math.decompositions.CholeskyDecompositionTest; -import org.apache.ignite.math.decompositions.EigenDecompositionTest; -import org.apache.ignite.math.decompositions.LUDecompositionTest; -import org.apache.ignite.math.decompositions.QRDecompositionTest; -import org.apache.ignite.math.decompositions.SingularValueDecompositionTest; -import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrixConstructorTest; -import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrixConstructorTest; -import org.apache.ignite.math.impls.matrix.DiagonalMatrixTest; -import org.apache.ignite.math.impls.matrix.FunctionMatrixConstructorTest; -import org.apache.ignite.math.impls.matrix.MatrixAttributeTest; -import org.apache.ignite.math.impls.matrix.MatrixImplementationsTest; -import org.apache.ignite.math.impls.matrix.MatrixViewConstructorTest; -import org.apache.ignite.math.impls.matrix.PivotedMatrixViewConstructorTest; -import org.apache.ignite.math.impls.matrix.RandomMatrixConstructorTest; -import org.apache.ignite.math.impls.matrix.SparseLocalOnHeapMatrixConstructorTest; -import org.apache.ignite.math.impls.matrix.TransposedMatrixViewTest; -import org.apache.ignite.math.impls.storage.matrix.MatrixArrayStorageTest; -import org.apache.ignite.math.impls.storage.matrix.MatrixOffHeapStorageTest; -import org.apache.ignite.math.impls.storage.matrix.MatrixStorageImplementationTest; -import org.apache.ignite.math.impls.storage.vector.RandomAccessSparseVectorStorageTest; -import org.apache.ignite.math.impls.storage.vector.SparseLocalOffHeapVectorStorageTest; -import org.apache.ignite.math.impls.storage.vector.VectorArrayStorageTest; -import org.apache.ignite.math.impls.storage.vector.VectorOffheapStorageTest; -import org.apache.ignite.math.impls.vector.AbstractVectorTest; -import org.apache.ignite.math.impls.vector.ConstantVectorConstructorTest; -import org.apache.ignite.math.impls.vector.DelegatingVectorConstructorTest; -import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVectorConstructorTest; -import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVectorConstructorTest; -import org.apache.ignite.math.impls.vector.FunctionVectorConstructorTest; -import org.apache.ignite.math.impls.vector.MatrixVectorViewTest; -import org.apache.ignite.math.impls.vector.PivotedVectorViewConstructorTest; -import org.apache.ignite.math.impls.vector.RandomVectorConstructorTest; -import org.apache.ignite.math.impls.vector.SingleElementVectorConstructorTest; -import org.apache.ignite.math.impls.vector.SingleElementVectorViewConstructorTest; -import org.apache.ignite.math.impls.vector.SparseLocalVectorConstructorTest; -import org.apache.ignite.math.impls.vector.VectorAttributesTest; -import org.apache.ignite.math.impls.vector.VectorFoldMapTest; -import org.apache.ignite.math.impls.vector.VectorImplementationsTest; -import org.apache.ignite.math.impls.vector.VectorIterableTest; -import org.apache.ignite.math.impls.vector.VectorNormTest; -import org.apache.ignite.math.impls.vector.VectorToMatrixTest; -import org.apache.ignite.math.impls.vector.VectorViewTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * Test suite for all local tests located in org.apache.ignite.math.impls.* package. - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ - // Vector constructors tests. - DenseLocalOnHeapVectorConstructorTest.class, - DenseLocalOffHeapVectorConstructorTest.class, - SparseLocalVectorConstructorTest.class, - RandomVectorConstructorTest.class, - ConstantVectorConstructorTest.class, - FunctionVectorConstructorTest.class, - SingleElementVectorConstructorTest.class, - PivotedVectorViewConstructorTest.class, - SingleElementVectorViewConstructorTest.class, - DelegatingVectorConstructorTest.class, - // Various vectors tests. - AbstractVectorTest.class, - VectorImplementationsTest.class, - VectorViewTest.class, - MatrixVectorViewTest.class, - // Vector particular features tests. - VectorIterableTest.class, - VectorAttributesTest.class, - VectorToMatrixTest.class, - VectorNormTest.class, - VectorFoldMapTest.class, - // Vector storage tests - VectorArrayStorageTest.class, - VectorOffheapStorageTest.class, - RandomAccessSparseVectorStorageTest.class, - SparseLocalOffHeapVectorStorageTest.class, - // Matrix storage tests. - MatrixStorageImplementationTest.class, - MatrixOffHeapStorageTest.class, - MatrixArrayStorageTest.class, - // Matrix constructors tests. - DenseLocalOnHeapMatrixConstructorTest.class, - DenseLocalOffHeapMatrixConstructorTest.class, - RandomMatrixConstructorTest.class, - FunctionMatrixConstructorTest.class, - MatrixViewConstructorTest.class, - PivotedMatrixViewConstructorTest.class, - SparseLocalOnHeapMatrixConstructorTest.class, - // Matrix tests. - MatrixImplementationsTest.class, - DiagonalMatrixTest.class, - MatrixAttributeTest.class, - TransposedMatrixViewTest.class, - // Decomposes - LUDecompositionTest.class, - EigenDecompositionTest.class, - CholeskyDecompositionTest.class, - QRDecompositionTest.class, - SingularValueDecompositionTest.class -}) -public class MathImplLocalTestSuite { - // No-op. -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java b/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java deleted file mode 100644 index 44fa8e6..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/MathImplMainTestSuite.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * Test suite for local and distributed tests - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ - MathImplLocalTestSuite.class, - MathImplDistributedTestSuite.class -}) -public class MathImplMainTestSuite { - // No-op. -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java b/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java deleted file mode 100644 index 35d2f60..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/TracerTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math; - -import java.awt.Color; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import org.apache.ignite.math.impls.MathTestConstants; -import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix; -import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector; -import org.junit.Test; - -import static java.nio.file.Files.createTempFile; -import static org.junit.Assert.assertEquals; - -/** - * Tests for {@link Tracer}. - */ -public class TracerTest { - /** */ private static final String DEFAULT_FORMAT = "%.10f"; - /** */ private static final double DEFAULT_DELTA = 0.000000001d; - - /** - * Color mapper that maps [0, 1] range into three distinct RGB segments. - */ - private static final Tracer.ColorMapper COLOR_MAPPER = new Tracer.ColorMapper() { - /** {@inheritDoc} */ - @Override public Color apply(Double d) { - if (d <= 0.33) - return Color.RED; - else if (d <= 0.66) - return Color.GREEN; - else - return Color.BLUE; - } - }; - - /** - * @param size Vector size. - */ - private Vector makeRandomVector(int size) { - DenseLocalOnHeapVector vec = new DenseLocalOnHeapVector(size); - - vec.assign((idx) -> Math.random()); - - return vec; - } - - /** - * @param rows Amount of rows in matrix. - * @param cols Amount of columns in matrix. - */ - private Matrix makeRandomMatrix(int rows, int cols) { - DenseLocalOnHeapMatrix mtx = new DenseLocalOnHeapMatrix(rows, cols); - - // Missing assign(f)? - mtx.map((d) -> Math.random()); - - return mtx; - } - - /** - * - */ - @Test - public void testAsciiVectorTracer() { - Vector vec = makeRandomVector(20); - - Tracer.showAscii(vec); - Tracer.showAscii(vec, "%2f"); - Tracer.showAscii(vec, "%.3g"); - } - - /** - * - */ - @Test - public void testAsciiMatrixTracer() { - Matrix mtx = makeRandomMatrix(10, 10); - - Tracer.showAscii(mtx); - Tracer.showAscii(mtx, "%2f"); - Tracer.showAscii(mtx, "%.3g"); - } - - /** - * - */ - @Test - public void testHtmlVectorTracer() throws IOException { - Vector vec1 = makeRandomVector(1000); - - // Default color mapping. - Tracer.showHtml(vec1); - - // Custom color mapping. - Tracer.showHtml(vec1, COLOR_MAPPER); - - // Default color mapping with sorted vector. - Tracer.showHtml(vec1.sort()); - } - - /** - * - */ - @Test - public void testHtmlMatrixTracer() throws IOException { - Matrix mtx1 = makeRandomMatrix(100, 100); - - // Custom color mapping. - Tracer.showHtml(mtx1, COLOR_MAPPER); - - Matrix mtx2 = new DenseLocalOnHeapMatrix(100, 100); - - double MAX = (double)(mtx2.rowSize() * mtx2.columnSize()); - - mtx2.assign((x, y) -> (double)(x * y) / MAX); - - Tracer.showHtml(mtx2); - } - - /** */ - @Test - public void testWriteVectorToCSVFile() throws IOException { - DenseLocalOnHeapVector vector = new DenseLocalOnHeapVector(MathTestConstants.STORAGE_SIZE); - - for (int i = 0; i < vector.size(); i++) - vector.set(i, Math.random()); - - Path file = createTempFile("vector", ".csv"); - - Tracer.saveAsCsv(vector, DEFAULT_FORMAT, file.toString()); - - System.out.println("Vector exported: " + file.getFileName()); - - List strings = Files.readAllLines(file); - Optional reduce = strings.stream().reduce((s1, s2) -> s1 + s2); - String[] csvVals = reduce.get().split(","); - - for (int i = 0; i < vector.size(); i++) { - Double csvVal = Double.valueOf(csvVals[i]); - - assertEquals("Unexpected value.", csvVal, vector.get(i), DEFAULT_DELTA); - } - - Files.deleteIfExists(file); - } - - /** */ - @Test - public void testWriteMatrixToCSVFile() throws IOException { - DenseLocalOnHeapMatrix matrix = new DenseLocalOnHeapMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE); - - for (int i = 0; i < matrix.rowSize(); i++) - for (int j = 0; j < matrix.columnSize(); j++) - matrix.set(i, j, Math.random()); - - Path file = createTempFile("matrix", ".csv"); - - Tracer.saveAsCsv(matrix, DEFAULT_FORMAT, file.toString()); - - System.out.println("Matrix exported: " + file.getFileName()); - - List strings = Files.readAllLines(file); - Optional reduce = strings.stream().reduce((s1, s2) -> s1 + s2); - String[] csvVals = reduce.get().split(","); - - for (int i = 0; i < matrix.rowSize(); i++) - for (int j = 0; j < matrix.columnSize(); j++) { - Double csvVal = Double.valueOf(csvVals[i * matrix.rowSize() + j]); - - assertEquals("Unexpected value.", csvVal, matrix.get(i, j), DEFAULT_DELTA); - } - - Files.deleteIfExists(file); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java deleted file mode 100644 index 4c3718a..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmark.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.benchmark; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -/** Refer {@link MathBenchmarkSelfTest} for usage examples. */ -class MathBenchmark { - /** */ - private final boolean outputToConsole; - - /** */ - private final String benchmarkName; - - /** */ - private final int measurementTimes; - - /** */ - private final int warmUpTimes; - - /** */ - private final String tag; - - /** */ - private final String comments; - - /** Constructor strictly for use within this class. */ - private MathBenchmark(String benchmarkName, boolean outputToConsole, int measurementTimes, int warmUpTimes, - String tag, String comments) { - this.benchmarkName = benchmarkName; - this.outputToConsole = outputToConsole; - this.measurementTimes = measurementTimes; - this.warmUpTimes = warmUpTimes; - this.tag = tag; - this.comments = comments; - validate(); - } - - /** - * Benchmark with specified name and default parameters, in particular, default output file. - * - * @param benchmarkName name - */ - MathBenchmark(String benchmarkName) { - this(benchmarkName, false, 100, 1, "", ""); - } - - /** - * Executes the code using config of this benchmark. - * - * @param code code to execute - * @throws Exception if something goes wrong - */ - void execute(BenchmarkCode code) throws Exception { - System.out.println("Started benchmark [" + benchmarkName + "]."); - - for (int cnt = 0; cnt < warmUpTimes; cnt++) - code.call(); - - final long start = System.currentTimeMillis(); - - for (int cnt = 0; cnt < measurementTimes; cnt++) - code.call(); - - final long end = System.currentTimeMillis(); - - writeResults(formatResults(start, end)); - - System.out.println("Finished benchmark [" + benchmarkName + "]."); - } - - /** - * Set optional output mode for using stdout. - * - * @return configured benchmark - */ - MathBenchmark outputToConsole() { - return new MathBenchmark(benchmarkName, true, measurementTimes, warmUpTimes, tag, comments); - } - - /** - * Set optional measurement times. - * - * @param param times - * @return configured benchmark - */ - MathBenchmark measurementTimes(int param) { - return new MathBenchmark(benchmarkName, outputToConsole, param, warmUpTimes, tag, comments); - } - - /** - * Set optional warm-up times. - * - * @param param times - * @return configured benchmark - */ - MathBenchmark warmUpTimes(int param) { - return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, param, tag, comments); - } - - /** - * Set optional tag to help filtering specific kind of benchmark results. - * - * @param param name - * @return configured benchmark - */ - MathBenchmark tag(String param) { - return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, warmUpTimes, param, comments); - } - - /** - * Set optional comments. - * - * @param param name - * @return configured benchmark - */ - MathBenchmark comments(String param) { - return new MathBenchmark(benchmarkName, outputToConsole, measurementTimes, warmUpTimes, tag, param); - } - - /** */ - private void writeResults(String results) throws Exception { - if (outputToConsole) { - System.out.println(results); - - return; - } - - new ResultsWriter().append(results); - } - - /** */ - private String formatResults(long start, long end) { - final String delim = ","; - - assert !formatDouble(1000_000_001.1).contains(delim) : "Formatted results contain [" + delim + "]."; - - final String ts = formatTs(start); - - assert !ts.contains(delim) : "Formatted timestamp contains [" + delim + "]."; - - return benchmarkName + - delim + - ts + // IMPL NOTE timestamp - delim + - formatDouble((double)(end - start) / measurementTimes) + - delim + - measurementTimes + - delim + - warmUpTimes + - delim + - tag + - delim + - comments; - } - - /** */ - private String formatDouble(double val) { - return String.format(Locale.US, "%f", val); - } - - /** */ - private String formatTs(long ts) { - final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); - - sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - - return sdf.format(new Date(ts)); - } - - /** */ - private void validate() { - if (benchmarkName == null || benchmarkName.isEmpty()) - throw new IllegalArgumentException("Invalid benchmark name: [" + benchmarkName + "]."); - - if (measurementTimes < 1) - throw new IllegalArgumentException("Invalid measurement times: [" + measurementTimes + "]."); - } - - /** */ - interface BenchmarkCode { - // todo find out why Callable failed to work here - - /** */ - void call() throws Exception; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java deleted file mode 100644 index 7a86461..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/MathBenchmarkSelfTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.benchmark; - -import org.junit.Ignore; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -/** */ -public class MathBenchmarkSelfTest { - /** */ - @Test - @Ignore("Benchmark tests are intended only for manual execution") - public void demoTest() throws Exception { - for (int i = 0; i < 2; i++) - new MathBenchmark("demo test") - .outputToConsole() // IMPL NOTE this is to write output into console instead of a file - .tag(null) // IMPL NOTE try null for tag, expect it to be formatted reasonably - .comments(null) // IMPL NOTE try null for comments, expect it to be formatted reasonably - .execute(() -> { - double seed = 1.1; - - for (int cnt = 0; cnt < 1000; cnt++) { - seed = Math.pow(seed, 2); - - assertTrue(seed > 0); - } - }); - } - - /** */ - @Test - @Ignore("Benchmark tests are intended only for manual execution") - public void configTest() throws Exception { - new MathBenchmark("demo config test") - .outputToConsole() - .measurementTimes(2) - .warmUpTimes(0) - .tag("demo tag") - .comments("demo comments") - .execute(() -> System.out.println("config test")); - } - - /** */ - @Test(expected = IllegalArgumentException.class) - @Ignore("Benchmark tests are intended only for manual execution") - public void emptyNameTest() throws Exception { - new MathBenchmark("") - .outputToConsole() - .measurementTimes(1) - .warmUpTimes(1) - .tag("empty name test tag") - .comments("empty name test comments") - .execute(() -> System.out.println("empty name test")); - } - - /** */ - @Test(expected = IllegalArgumentException.class) - @Ignore("Benchmark tests are intended only for manual execution") - public void nullDropboxPathTest() throws Exception { - new ResultsWriter(null, "whatever", "whatever"); - } - - /** */ - @Test(expected = IllegalArgumentException.class) - @Ignore("Benchmark tests are intended only for manual execution") - public void nullDropboxUrlTest() throws Exception { - new ResultsWriter("whatever", null, "whatever"); - } - - /** */ - @Test(expected = IllegalArgumentException.class) - @Ignore("Benchmark tests are intended only for manual execution") - public void nullDropboxTokenTest() throws Exception { - new ResultsWriter("whatever", "whatever", null); - } - - /** */ - @Test(expected = IllegalArgumentException.class) - @Ignore("Benchmark tests are intended only for manual execution") - public void nullResultsTest() throws Exception { - new ResultsWriter("whatever", "whatever", "whatever").append(null); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java deleted file mode 100644 index aeec156..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/ResultsWriter.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.benchmark; - -import com.dropbox.core.DbxException; -import com.dropbox.core.DbxRequestConfig; -import com.dropbox.core.v2.DbxClientV2; -import com.dropbox.core.v2.files.WriteMode; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.UUID; - -/** */ -class ResultsWriter { - /** */ - private static final String DROPBOX_PATH - = "/benchmarks/math.benchmark.results.csv"; - - /** */ - private static final String DROPBOX_URL - = "https://www.dropbox.com/s/r7tcle31r7gaty8/math.benchmark.results.csv"; - - /** */ - private static final String ACCESS_TOKEN - = "1MMmQjEyzGAAAAAAAAAAfDFrQ6oBPPi4NX-iU_VrgmXB2JDXqRHGa125cTkkEQ0V"; - - /** */ - private final String dropboxPath; - /** */ - private final String dropboxUrl; - /** */ - private final String accessTok; - - /** */ - ResultsWriter(String dropboxPath, String dropboxUrl, String accessTok) { - this.dropboxPath = dropboxPath; - this.dropboxUrl = dropboxUrl; - this.accessTok = accessTok; - - if (dropboxPath == null || dropboxUrl == null || accessTok == null) - throw new IllegalArgumentException("Neither of dropbox path, URL, access token can be null."); - } - - /** **/ - ResultsWriter() { - this(DROPBOX_PATH, DROPBOX_URL, ACCESS_TOKEN); - } - - /** */ - void append(String res) throws DbxException, IOException { - if (res == null) - throw new IllegalArgumentException("benchmark result is null"); - - if (dropboxPath == null) { - System.out.println(res); - - return; - } - - append(res, client()); - } - - /** */ - private void append(String res, DbxClientV2 client) throws DbxException, IOException { - File tmp = createTmpFile(); - - try (FileOutputStream out = new FileOutputStream(tmp)) { - client.files().download(dropboxPath).download(out); - } - - writeResults(res, tmp); - - try (FileInputStream in = new FileInputStream(tmp)) { - client.files().uploadBuilder(dropboxPath).withMode(WriteMode.OVERWRITE).uploadAndFinish(in); - } - - if (!tmp.delete()) - System.out.println("Failed to delete " + tmp.getAbsolutePath()); - - System.out.println("Uploaded benchmark results to: " + dropboxUrl); - } - - /** */ - private void writeResults(String res, File tmp) throws IOException { - final String unixLineSeparator = "\n"; - - try (final PrintWriter writer = new PrintWriter(Files.newBufferedWriter(Paths.get(tmp.toURI()), - StandardOpenOption.APPEND, StandardOpenOption.CREATE))) { - writer.write(res + unixLineSeparator); - } - } - - /** */ - private File createTmpFile() throws IOException { - File tmp = File.createTempFile(UUID.randomUUID().toString(), ".csv"); - - tmp.deleteOnExit(); - - return tmp; - } - - /** */ - private DbxClientV2 client() { - return new DbxClientV2(DbxRequestConfig.newBuilder("dropbox/MathBenchmark").build(), accessTok); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java deleted file mode 100644 index 1f7b204..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/VectorBenchmarkTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.benchmark; - -import java.util.function.BiConsumer; -import java.util.function.Function; -import org.apache.ignite.math.Vector; -import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVector; -import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector; -import org.junit.Ignore; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -/** */ -public class VectorBenchmarkTest { - // todo add benchmarks for other methods in Vector and for other types of Vector and Matrix - - /** */ - @Test - @Ignore("Benchmark tests are intended only for manual execution") - public void testDenseLocalOnHeapVector() throws Exception { - benchmark("DenseLocalOnHeapVector basic mix", DenseLocalOnHeapVector::new, this::basicMix); - - benchmark("DenseLocalOnHeapVector fold map", DenseLocalOnHeapVector::new, this::foldMapMix); - } - - /** */ - @Test - @Ignore("Benchmark tests are intended only for manual execution") - public void testDenseLocalOffHeapVector() throws Exception { - benchmark("DenseLocalOffHeapVector basic mix", DenseLocalOffHeapVector::new, this::basicMix); - - benchmark("DenseLocalOffHeapVector fold map", DenseLocalOffHeapVector::new, this::foldMapMix); - } - - /** */ - private void benchmark(String namePrefix, Function constructor, - BiConsumer> consumer) throws Exception { - assertNotNull(namePrefix); - - new MathBenchmark(namePrefix + " small sizes").execute(() -> { - for (int size : new int[] {2, 3, 4, 5, 6, 7}) - consumer.accept(size, constructor); - }); - - new MathBenchmark(namePrefix + " sizes powers of 2").execute(() -> { - for (int power : new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}) - consumer.accept(1 << power, constructor); - }); - - new MathBenchmark(namePrefix + " large sizes").execute(() -> { - for (int power : new int[] {10, 12, 14, 16}) - for (int delta : new int[] {-1, 0, 1}) - consumer.accept((1 << power) + delta, constructor); - }); - - new MathBenchmark(namePrefix + " extra large sizes") - .measurementTimes(10) - .execute(() -> { // IMPL NOTE trying below with power 22 almost killed my IDEA and laptop - for (int power : new int[] {17, 18, 19, 20, 21}) - for (int delta : new int[] {-1, 0}) // IMPL NOTE delta +1 is not intended for use here - consumer.accept((1 << power) + delta, constructor); - }); - } - - /** */ - private void basicMix(int size, Function constructor) { - final Vector v1 = constructor.apply(size), v2 = constructor.apply(size); - - for (int idx = 0; idx < size; idx++) { - v1.set(idx, idx); - - v2.set(idx, size - idx); - } - - assertNotNull(v1.sum()); - - assertNotNull(v1.copy()); - - assertFalse(v1.getLengthSquared() < 0); - - assertNotNull(v1.normalize()); - - assertNotNull(v1.logNormalize()); - - assertFalse(v1.getDistanceSquared(v2) < 0); - - assertNotNull(v1.divide(2)); - - assertNotNull(v1.minus(v2)); - - assertNotNull(v1.plus(v2)); - - assertNotNull(v1.dot(v2)); - - assertNotNull(v1.assign(v2)); - - assertNotNull(v1.assign(1)); // IMPL NOTE this would better be last test for it sets all values the same - } - - /** */ - private void foldMapMix(int size, Function constructor) { - final Vector v1 = constructor.apply(size), v2 = constructor.apply(size); - - for (int idx = 0; idx < size; idx++) { - v1.set(idx, idx); - - v2.set(idx, size - idx); - } - - assertNotNull(v1.map((val) -> (val + 1))); - - assertNotNull(v1.map(v2, (one, other) -> one + other / 2.0)); - - assertNotNull(v1.map((val, val1) -> (val + val1), 2.0)); - - assertNotNull(v1.foldMap((sum, val) -> (val + sum), (val) -> val, 0.0)); - - assertNotNull(v1.foldMap(v2, (sum, val) -> (val + sum), (val1, val2) -> val1 + val2, 0.0)); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java b/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java deleted file mode 100644 index cbf5d36..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/benchmark/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.benchmark; http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java deleted file mode 100644 index fa311e0..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/CholeskyDecompositionTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.decompositions; - -import org.apache.ignite.math.Matrix; -import org.apache.ignite.math.Vector; -import org.apache.ignite.math.exceptions.CardinalityException; -import org.apache.ignite.math.exceptions.NonPositiveDefiniteMatrixException; -import org.apache.ignite.math.exceptions.NonSymmetricMatrixException; -import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix; -import org.apache.ignite.math.impls.matrix.PivotedMatrixView; -import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** */ -public class CholeskyDecompositionTest { - /** */ - @Test - public void basicTest() { - basicTest(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - })); - } - - /** - * Test for {@link DecompositionSupport} features. - */ - @Test - public void decompositionSupportTest() { - basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - }))); - } - - /** */ - @Test(expected = AssertionError.class) - public void nullMatrixTest() { - new CholeskyDecomposition(null); - } - - /** */ - @Test(expected = CardinalityException.class) - public void wrongMatrixSizeTest() { - new CholeskyDecomposition(new DenseLocalOnHeapMatrix(2, 3)); - } - - /** */ - @Test(expected = NonSymmetricMatrixException.class) - public void nonSymmetricMatrixTest() { - new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 10.0d}, - {-1.0d, 2.0d, -1.0d}, - {-10.0d, -1.0d, 2.0d} - })); - } - - /** */ - @Test(expected = NonPositiveDefiniteMatrixException.class) - public void nonAbsPositiveMatrixTest() { - new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 0.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - })); - } - - /** */ - @Test(expected = CardinalityException.class) - public void solveWrongVectorSizeTest() { - new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - })).solve(new DenseLocalOnHeapVector(2)); - } - - /** */ - @Test(expected = CardinalityException.class) - public void solveWrongMatrixSizeTest() { - new CholeskyDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - })).solve(new DenseLocalOnHeapMatrix(2, 3)); - } - - /** */ - private void basicTest(Matrix m) { - // This decomposition is useful when dealing with systems of linear equations of the form - // m x = b where m is a Hermitian matrix. - // For such systems Cholesky decomposition provides - // more effective method of solving compared to LU decomposition. - // Suppose we want to solve system - // m x = b for various bs. Then after we computed Cholesky decomposition, we can feed various bs - // as a matrix of the form - // (b1, b2, ..., bm) - // to the method Cholesky::solve which returns solutions in the form - // (sol1, sol2, ..., solm) - CholeskyDecomposition dec = new CholeskyDecomposition(m); - assertEquals("Unexpected value for decomposition determinant.", - 4d, dec.getDeterminant(), 0d); - - Matrix l = dec.getL(); - Matrix lt = dec.getLT(); - - assertNotNull("Matrix l is expected to be not null.", l); - assertNotNull("Matrix lt is expected to be not null.", lt); - - for (int row = 0; row < l.rowSize(); row++) - for (int col = 0; col < l.columnSize(); col++) - assertEquals("Unexpected value transposed matrix at (" + row + "," + col + ").", - l.get(row, col), lt.get(col, row), 0d); - - Matrix bs = new DenseLocalOnHeapMatrix(new double[][] { - {4.0, -6.0, 7.0}, - {1.0, 1.0, 1.0} - }).transpose(); - Matrix sol = dec.solve(bs); - - assertNotNull("Solution matrix is expected to be not null.", sol); - assertEquals("Solution rows are not as expected.", bs.rowSize(), sol.rowSize()); - assertEquals("Solution columns are not as expected.", bs.columnSize(), sol.columnSize()); - - for (int i = 0; i < sol.columnSize(); i++) - assertNotNull("Solution matrix column is expected to be not null at index " + i, sol.viewColumn(i)); - - Vector b = new DenseLocalOnHeapVector(new double[] {4.0, -6.0, 7.0}); - Vector solVec = dec.solve(b); - - for (int idx = 0; idx < b.size(); idx++) - assertEquals("Unexpected value solution vector at " + idx, - b.get(idx), solVec.get(idx), 0d); - - dec.destroy(); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java deleted file mode 100644 index e4e7b15..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/EigenDecompositionTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.decompositions; - -import org.apache.ignite.math.Matrix; -import org.apache.ignite.math.Vector; -import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Tests for {@link EigenDecomposition} - */ -public class EigenDecompositionTest { - /** */ - private static final double EPSILON = 1e-11; - - /** */ - @Test - public void testMatrixWithRealEigenvalues() { - test(new double[][] { - {1.0d, 0.0d, 0.0d, 0.0d}, - {0.0d, 1.0d, 0.0d, 0.0d}, - {0.0d, 0.0d, 2.0d, 0.0d}, - {1.0d, 1.0d, 0.0d, 2.0d}}, - new double[] {1, 2, 2, 1}); - } - - /** */ - @Test - public void testSymmetricMatrix() { - EigenDecomposition decomposition = new EigenDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {1.0d, 0.0d, 0.0d, 1.0d}, - {0.0d, 1.0d, 0.0d, 1.0d}, - {0.0d, 0.0d, 2.0d, 0.0d}, - {1.0d, 1.0d, 0.0d, 2.0d}})); - - Matrix d = decomposition.getD(); - Matrix v = decomposition.getV(); - - assertNotNull("Matrix d is expected to be not null.", d); - assertNotNull("Matrix v is expected to be not null.", v); - - assertEquals("Unexpected rows in d matrix.", 4, d.rowSize()); - assertEquals("Unexpected cols in d matrix.", 4, d.columnSize()); - - assertEquals("Unexpected rows in v matrix.", 4, v.rowSize()); - assertEquals("Unexpected cols in v matrix.", 4, v.columnSize()); - - assertIsDiagonalNonZero(d); - - decomposition.destroy(); - } - - /** */ - @Test - public void testNonSquareMatrix() { - EigenDecomposition decomposition = new EigenDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {1.0d, 0.0d, 0.0d}, - {0.0d, 1.0d, 0.0d}, - {0.0d, 0.0d, 2.0d}, - {1.0d, 1.0d, 0.0d}})); - // todo find out why decomposition of 3X4 matrix throws row index exception - - Matrix d = decomposition.getD(); - Matrix v = decomposition.getV(); - - assertNotNull("Matrix d is expected to be not null.", d); - assertNotNull("Matrix v is expected to be not null.", v); - - assertEquals("Unexpected rows in d matrix.", 4, d.rowSize()); - assertEquals("Unexpected cols in d matrix.", 4, d.columnSize()); - - assertEquals("Unexpected rows in v matrix.", 4, v.rowSize()); - assertEquals("Unexpected cols in v matrix.", 3, v.columnSize()); - - assertIsDiagonal(d, true); - - decomposition.destroy(); - } - - /** */ - private void test(double[][] mRaw, double[] expRealEigenValues) { - DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(mRaw); - EigenDecomposition decomposition = new EigenDecomposition(m); - - Matrix d = decomposition.getD(); - Matrix v = decomposition.getV(); - - assertIsDiagonalNonZero(d); - - // check that d's diagonal consists of eigenvalues of m. - assertDiagonalConsistsOfEigenvalues(m, d, v); - - // m = v d v^{-1} is equivalent to - // m v = v d - assertMatricesAreEqual(m.times(v), v.times(d)); - - assertEigenvalues(decomposition, expRealEigenValues); - - decomposition.destroy(); - } - - /** */ - private void assertEigenvalues(EigenDecomposition decomposition, double[] expRealEigenValues) { - Vector real = decomposition.getRealEigenValues(); - Vector imag = decomposition.getImagEigenvalues(); - - assertEquals("Real values size differs from expected.", expRealEigenValues.length, real.size()); - assertEquals("Imag values size differs from expected.", expRealEigenValues.length, imag.size()); - - for (int idx = 0; idx < expRealEigenValues.length; idx++) { - assertEquals("Real eigen value differs from expected at " + idx, - expRealEigenValues[idx], real.get(idx), 0d); - - assertEquals("Imag eigen value differs from expected at " + idx, - 0d, imag.get(idx), 0d); - } - - } - - /** */ - private void assertDiagonalConsistsOfEigenvalues(DenseLocalOnHeapMatrix m, Matrix d, Matrix v) { - int n = m.columnSize(); - for (int i = 0; i < n; i++) { - Vector eigenVector = v.viewColumn(i); - double eigenVal = d.getX(i, i); - assertVectorsAreEqual(m.times(eigenVector), eigenVector.times(eigenVal)); - } - - } - - /** */ - private void assertMatricesAreEqual(Matrix exp, Matrix actual) { - assertTrue("The row sizes of matrices are not equal", exp.rowSize() == actual.rowSize()); - assertTrue("The col sizes of matrices are not equal", exp.columnSize() == actual.columnSize()); - - // Since matrix is square, we need only one dimension - int n = exp.columnSize(); - - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - assertEquals("Values should be equal", exp.getX(i, j), actual.getX(i, j), EPSILON); - } - - /** */ - private void assertVectorsAreEqual(Vector exp, Vector actual) { - assertTrue("Vectors sizes are not equal", exp.size() == actual.size()); - - // Since matrix is square, we need only one dimension - int n = exp.size(); - - for (int i = 0; i < n; i++) - assertEquals("Values should be equal", exp.getX(i), actual.getX(i), EPSILON); - } - - /** */ - private void assertIsDiagonalNonZero(Matrix m) { - assertIsDiagonal(m, false); - } - - /** */ - private void assertIsDiagonal(Matrix m, boolean zeroesAllowed) { - // Since matrix is square, we need only one dimension - int n = m.columnSize(); - - assertEquals("Diagonal matrix is not square", n, m.rowSize()); - - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - assertTrue("Matrix is not diagonal, violation at (" + i + "," + j + ")", - ((i == j) && (zeroesAllowed || m.getX(i, j) != 0)) - || ((i != j) && m.getX(i, j) == 0)); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java deleted file mode 100644 index 0feb48f..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/LUDecompositionTest.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.decompositions; - -import org.apache.ignite.math.Matrix; -import org.apache.ignite.math.Vector; -import org.apache.ignite.math.exceptions.CardinalityException; -import org.apache.ignite.math.exceptions.SingularMatrixException; -import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix; -import org.apache.ignite.math.impls.matrix.PivotedMatrixView; -import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Tests for {@link LUDecomposition}. - */ -public class LUDecompositionTest { - /** */ - private Matrix testL; - /** */ - private Matrix testU; - /** */ - private Matrix testP; - /** */ - private Matrix testMatrix; - /** */ - private int[] rawPivot; - - /** */ - @Before - public void setUp() { - double[][] rawMatrix = new double[][] { - {2.0d, 1.0d, 1.0d, 0.0d}, - {4.0d, 3.0d, 3.0d, 1.0d}, - {8.0d, 7.0d, 9.0d, 5.0d}, - {6.0d, 7.0d, 9.0d, 8.0d}}; - double[][] rawL = { - {1.0d, 0.0d, 0.0d, 0.0d}, - {3.0d / 4.0d, 1.0d, 0.0d, 0.0d}, - {1.0d / 2.0d, -2.0d / 7.0d, 1.0d, 0.0d}, - {1.0d / 4.0d, -3.0d / 7.0d, 1.0d / 3.0d, 1.0d}}; - double[][] rawU = { - {8.0d, 7.0d, 9.0d, 5.0d}, - {0.0d, 7.0d / 4.0d, 9.0d / 4.0d, 17.0d / 4.0d}, - {0.0d, 0.0d, -6.0d / 7.0d, -2.0d / 7.0d}, - {0.0d, 0.0d, 0.0d, 2.0d / 3.0d}}; - double[][] rawP = new double[][] { - {0, 0, 1.0d, 0}, - {0, 0, 0, 1.0d}, - {0, 1.0d, 0, 0}, - {1.0d, 0, 0, 0}}; - - rawPivot = new int[] {3, 4, 2, 1}; - - testMatrix = new DenseLocalOnHeapMatrix(rawMatrix); - testL = new DenseLocalOnHeapMatrix(rawL); - testU = new DenseLocalOnHeapMatrix(rawU); - testP = new DenseLocalOnHeapMatrix(rawP); - } - - /** */ - @Test - public void getL() throws Exception { - Matrix luDecompositionL = new LUDecomposition(testMatrix).getL(); - - assertEquals("Unexpected row size.", testL.rowSize(), luDecompositionL.rowSize()); - assertEquals("Unexpected column size.", testL.columnSize(), luDecompositionL.columnSize()); - - for (int i = 0; i < testL.rowSize(); i++) - for (int j = 0; j < testL.columnSize(); j++) - assertEquals("Unexpected value at (" + i + "," + j + ").", - testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d); - - luDecompositionL.destroy(); - } - - /** */ - @Test - public void getU() throws Exception { - Matrix luDecompositionU = new LUDecomposition(testMatrix).getU(); - - assertEquals("Unexpected row size.", testU.rowSize(), luDecompositionU.rowSize()); - assertEquals("Unexpected column size.", testU.columnSize(), luDecompositionU.columnSize()); - - for (int i = 0; i < testU.rowSize(); i++) - for (int j = 0; j < testU.columnSize(); j++) - assertEquals("Unexpected value at (" + i + "," + j + ").", - testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d); - - luDecompositionU.destroy(); - } - - /** */ - @Test - public void getP() throws Exception { - Matrix luDecompositionP = new LUDecomposition(testMatrix).getP(); - - assertEquals("Unexpected row size.", testP.rowSize(), luDecompositionP.rowSize()); - assertEquals("Unexpected column size.", testP.columnSize(), luDecompositionP.columnSize()); - - for (int i = 0; i < testP.rowSize(); i++) - for (int j = 0; j < testP.columnSize(); j++) - assertEquals("Unexpected value at (" + i + "," + j + ").", - testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d); - - luDecompositionP.destroy(); - } - - /** */ - @Test - public void getPivot() throws Exception { - Vector pivot = new LUDecomposition(testMatrix).getPivot(); - - assertEquals("Unexpected pivot size.", rawPivot.length, pivot.size()); - - for (int i = 0; i < testU.rowSize(); i++) - assertEquals("Unexpected value at " + i, rawPivot[i], (int)pivot.get(i) + 1); - } - - /** - * Test for {@link DecompositionSupport} features. - */ - @Test - public void decompositionSupportTest() { - LUDecomposition dec = new LUDecomposition(new PivotedMatrixView(testMatrix)); - Matrix luDecompositionL = dec.getL(); - - assertEquals("Unexpected L row size.", testL.rowSize(), luDecompositionL.rowSize()); - assertEquals("Unexpected L column size.", testL.columnSize(), luDecompositionL.columnSize()); - - for (int i = 0; i < testL.rowSize(); i++) - for (int j = 0; j < testL.columnSize(); j++) - assertEquals("Unexpected L value at (" + i + "," + j + ").", - testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d); - - Matrix luDecompositionU = dec.getU(); - - assertEquals("Unexpected U row size.", testU.rowSize(), luDecompositionU.rowSize()); - assertEquals("Unexpected U column size.", testU.columnSize(), luDecompositionU.columnSize()); - - for (int i = 0; i < testU.rowSize(); i++) - for (int j = 0; j < testU.columnSize(); j++) - assertEquals("Unexpected U value at (" + i + "," + j + ").", - testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d); - - Matrix luDecompositionP = dec.getP(); - - assertEquals("Unexpected P row size.", testP.rowSize(), luDecompositionP.rowSize()); - assertEquals("Unexpected P column size.", testP.columnSize(), luDecompositionP.columnSize()); - - for (int i = 0; i < testP.rowSize(); i++) - for (int j = 0; j < testP.columnSize(); j++) - assertEquals("Unexpected P value at (" + i + "," + j + ").", - testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d); - - dec.destroy(); - } - - /** */ - @Test - public void singularDeterminant() throws Exception { - assertEquals("Unexpected determinant for singular matrix decomposition.", - 0d, new LUDecomposition(new DenseLocalOnHeapMatrix(2, 2)).determinant(), 0d); - } - - /** */ - @Test(expected = CardinalityException.class) - public void solveVecWrongSize() throws Exception { - new LUDecomposition(testMatrix).solve(new DenseLocalOnHeapVector(testMatrix.rowSize() + 1)); - } - - /** */ - @Test(expected = SingularMatrixException.class) - public void solveVecSingularMatrix() throws Exception { - new LUDecomposition(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize())) - .solve(new DenseLocalOnHeapVector(testMatrix.rowSize())); - } - - /** */ - @Test - public void solveVec() throws Exception { - Vector sol = new LUDecomposition(new PivotedMatrixView(testMatrix)) - .solve(new DenseLocalOnHeapVector(testMatrix.rowSize())); - - assertEquals("Wrong solution vector size.", testMatrix.rowSize(), sol.size()); - - for (int i = 0; i < sol.size(); i++) - assertEquals("Unexpected value at index " + i, 0d, sol.getX(i), 0.0000001d); - } - - /** */ - @Test(expected = CardinalityException.class) - public void solveMtxWrongSize() throws Exception { - new LUDecomposition(testMatrix).solve( - new DenseLocalOnHeapMatrix(testMatrix.rowSize() + 1, testMatrix.rowSize())); - } - - /** */ - @Test(expected = SingularMatrixException.class) - public void solveMtxSingularMatrix() throws Exception { - new LUDecomposition(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize())) - .solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize())); - } - - /** */ - @Test - public void solveMtx() throws Exception { - Matrix sol = new LUDecomposition(new PivotedMatrixView(testMatrix)) - .solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize())); - - assertEquals("Wrong solution matrix row size.", testMatrix.rowSize(), sol.rowSize()); - - assertEquals("Wrong solution matrix column size.", testMatrix.rowSize(), sol.columnSize()); - - for (int row = 0; row < sol.rowSize(); row++) - for (int col = 0; col < sol.columnSize(); col++) - assertEquals("Unexpected P value at (" + row + "," + col + ").", - 0d, sol.getX(row, col), 0.0000001d); - } - - /** */ - @Test(expected = AssertionError.class) - public void nullMatrixTest() { - new LUDecomposition(null); - } - - /** */ - @Test(expected = CardinalityException.class) - public void nonSquareMatrixTest() { - new LUDecomposition(new DenseLocalOnHeapMatrix(2, 3)); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d78e071a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java b/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java deleted file mode 100644 index 3bb92d1..0000000 --- a/modules/ml/src/test/java/org/apache/ignite/math/decompositions/QRDecompositionTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.math.decompositions; - -import org.apache.ignite.math.Matrix; -import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix; -import org.apache.ignite.math.impls.matrix.PivotedMatrixView; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** */ -public class QRDecompositionTest { - /** */ - @Test - public void basicTest() { - basicTest(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - })); - } - - /** - * Test for {@link DecompositionSupport} features. - */ - @Test - public void decompositionSupportTest() { - basicTest(new PivotedMatrixView(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - }))); - } - - /** */ - @Test(expected = AssertionError.class) - public void nullMatrixTest() { - new QRDecomposition(null); - } - - /** */ - @Test(expected = IllegalArgumentException.class) - public void solveWrongMatrixSizeTest() { - new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d}, - {0.0d, -1.0d, 2.0d} - })).solve(new DenseLocalOnHeapMatrix(2, 3)); - } - - /** */ - private void basicTest(Matrix m) { - QRDecomposition dec = new QRDecomposition(m); - assertTrue("Unexpected value for full rank in decomposition " + dec, dec.hasFullRank()); - - Matrix q = dec.getQ(); - Matrix r = dec.getR(); - - assertNotNull("Matrix q is expected to be not null.", q); - assertNotNull("Matrix r is expected to be not null.", r); - - Matrix qSafeCp = safeCopy(q); - - Matrix expIdentity = qSafeCp.times(qSafeCp.transpose()); - - final double delta = 0.0001; - - for (int row = 0; row < expIdentity.rowSize(); row++) - for (int col = 0; col < expIdentity.columnSize(); col++) - assertEquals("Unexpected identity matrix value at (" + row + "," + col + ").", - row == col ? 1d : 0d, expIdentity.get(col, row), delta); - - for (int row = 0; row < r.rowSize(); row++) - for (int col = 0; col < row - 1; col++) - assertEquals("Unexpected upper triangular matrix value at (" + row + "," + col + ").", - 0d, r.get(row, col), delta); - - Matrix recomposed = qSafeCp.times(r); - - for (int row = 0; row < m.rowSize(); row++) - for (int col = 0; col < m.columnSize(); col++) - assertEquals("Unexpected recomposed matrix value at (" + row + "," + col + ").", - m.get(row, col), recomposed.get(row, col), delta); - - Matrix sol = dec.solve(new DenseLocalOnHeapMatrix(3, 10)); - assertEquals("Unexpected rows in solution matrix.", 3, sol.rowSize()); - assertEquals("Unexpected cols in solution matrix.", 10, sol.columnSize()); - - for (int row = 0; row < sol.rowSize(); row++) - for (int col = 0; col < sol.columnSize(); col++) - assertEquals("Unexpected solution matrix value at (" + row + "," + col + ").", - 0d, sol.get(row, col), delta); - - dec.destroy(); - - QRDecomposition dec1 = new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d}, - {-1.0d, 2.0d}, - {0.0d, -1.0d} - })); - - assertTrue("Unexpected value for full rank in decomposition " + dec1, dec1.hasFullRank()); - - dec1.destroy(); - - QRDecomposition dec2 = new QRDecomposition(new DenseLocalOnHeapMatrix(new double[][] { - {2.0d, -1.0d, 0.0d, 0.0d}, - {-1.0d, 2.0d, -1.0d, 0.0d}, - {0.0d, -1.0d, 2.0d, 0.0d} - })); - - assertTrue("Unexpected value for full rank in decomposition " + dec2, dec2.hasFullRank()); - - dec2.destroy(); - } - - /** */ - private Matrix safeCopy(Matrix orig) { - return new DenseLocalOnHeapMatrix(orig.rowSize(), orig.columnSize()).assign(orig); - } -}