From 11118b577bf9cbc4f78da563e3c572859fbb9f5f Mon Sep 17 00:00:00 2001 From: apete Date: Sat, 10 Aug 2019 13:54:45 +0200 Subject: [PATCH 01/29] Update NonPhysicalTest.java --- test/org/ojalgo/matrix/store/NonPhysicalTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/org/ojalgo/matrix/store/NonPhysicalTest.java b/test/org/ojalgo/matrix/store/NonPhysicalTest.java index 6931eb393..18b023e3b 100644 --- a/test/org/ojalgo/matrix/store/NonPhysicalTest.java +++ b/test/org/ojalgo/matrix/store/NonPhysicalTest.java @@ -47,7 +47,7 @@ private static void testAggregation(final MatrixStore anyS expected = copied.aggregateAll(aggregator); actual = anyStore.aggregateAll(aggregator); - TestUtils.assertEquals(aggregator.name(), expected, actual, CNTXT); + TestUtils.assertEquals(aggregator.name() + "@" + anyStore, expected, actual, CNTXT); if (!((aggregator == Aggregator.AVERAGE) && (anyStore instanceof SparseStore))) { // For a sparse store the AVERAGE aggreghator will get an incorrect result From a3e28f8461e15e85ad35bef3ef9701c58d106060 Mon Sep 17 00:00:00 2001 From: apete Date: Sat, 10 Aug 2019 16:09:56 +0200 Subject: [PATCH 02/29] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6280c3cfd..6a7a74728 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ oj! Algorithms - ojAlgo - is Open Source Java code that has to do with mathematics, linear algebra and optimisation. UTF-8 - 5.4.1 + 5.5.1 Optimatika From 537983bb7f57063b4473844cc8f5a8017b47684a Mon Sep 17 00:00:00 2001 From: apete Date: Tue, 13 Aug 2019 21:56:23 +0200 Subject: [PATCH 03/29] Update ExpressionsBasedModel.java --- src/org/ojalgo/optimisation/ExpressionsBasedModel.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/org/ojalgo/optimisation/ExpressionsBasedModel.java b/src/org/ojalgo/optimisation/ExpressionsBasedModel.java index 23ac518cf..f056db66f 100644 --- a/src/org/ojalgo/optimisation/ExpressionsBasedModel.java +++ b/src/org/ojalgo/optimisation/ExpressionsBasedModel.java @@ -430,6 +430,10 @@ boolean isApplicable(final Variable target) { ExpressionsBasedModel.addPresolver(Presolvers.REDUNDANT_CONSTRAINT); } + /** + * Add a solver that will be used for problem types the built-in solvers cannot handle as defined by + * {@link Integration#isCapable(org.ojalgo.optimisation.Optimisation.Model)}. + */ public static boolean addFallbackSolver(final Integration integration) { return FALLBACK_INTEGRATIONS.add(integration); } @@ -443,6 +447,9 @@ public static boolean addIntegration(final Integration integration) { return ExpressionsBasedModel.addPreferredSolver(integration); } + /** + * Add a solver that will be used rather than the built-in solvers + */ public static boolean addPreferredSolver(final Integration integration) { return PREFERRED_INTEGRATIONS.add(integration); } From b6d1d8955b7d7e57e9e5bde5a3d709d46effd918 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Mon, 2 Sep 2019 07:39:01 +0200 Subject: [PATCH 04/29] No parallel aggregations (#220) * Test dimensions * Update PrimitiveDenseStore.java * Update PrimitiveDenseStore.java * No more merge * No parallel streams * Update pom.xml --- .settings/org.eclipse.jdt.core.prefs | 2 + CHANGELOG.md | 12 +++- pom.xml | 2 +- .../aggregator/AggregatorFunction.java | 7 ++ .../matrix/store/GenericDenseStore.java | 36 ---------- .../matrix/store/PrimitiveDenseStore.java | 36 ---------- src/org/ojalgo/matrix/store/SparseStore.java | 6 +- src/org/ojalgo/structure/ColumnView.java | 10 ++- src/org/ojalgo/structure/ElementView1D.java | 10 ++- src/org/ojalgo/structure/RowView.java | 10 ++- ...edColumnsCase.java => AboveBelowCase.java} | 20 +++--- ...ectedColumnsCase.java => ColumnsCase.java} | 14 ++-- .../ojalgo/matrix/store/ConjugatedCase.java | 16 +++-- .../org/ojalgo/matrix/store/IdentityCase.java | 12 ++-- ...MergedRowsCase.java => LeftRightCase.java} | 20 +++--- .../ojalgo/matrix/store/NonPhysicalTest.java | 69 ++++++++++++------- .../{SelectedRowsCase.java => RowsCase.java} | 14 ++-- test/org/ojalgo/matrix/store/SparseCase.java | 10 ++- ...nCase.java => SuperimposedColumnCase.java} | 16 +++-- ...Case.java => SuperimposedElementCase.java} | 24 ++++--- ...xRowCase.java => SuperimposedRowCase.java} | 16 +++-- .../ojalgo/matrix/store/TransposedCase.java | 10 ++- test/org/ojalgo/matrix/store/ZeroCase.java | 8 ++- 23 files changed, 210 insertions(+), 170 deletions(-) rename test/org/ojalgo/matrix/store/{MergedColumnsCase.java => AboveBelowCase.java} (70%) rename test/org/ojalgo/matrix/store/{SelectedColumnsCase.java => ColumnsCase.java} (80%) rename test/org/ojalgo/matrix/store/{MergedRowsCase.java => LeftRightCase.java} (70%) rename test/org/ojalgo/matrix/store/{SelectedRowsCase.java => RowsCase.java} (80%) rename test/org/ojalgo/matrix/store/{SuperimposedMatrixColumnCase.java => SuperimposedColumnCase.java} (77%) rename test/org/ojalgo/matrix/store/{SuperimposedMatrixElementCase.java => SuperimposedElementCase.java} (75%) rename test/org/ojalgo/matrix/store/{SuperimposedMatrixRowCase.java => SuperimposedRowCase.java} (77%) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 5163ad209..e80778d52 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -8,8 +8,10 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CHANGELOG.md b/CHANGELOG.md index a5b310d50..f57919d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- +#### org.ojalgo.function + +- The merge functionality of AggregatorFunction is deprecated. + +#### org.ojalgo.matrix + +- The multithreaded implementations of aggregateAll in PrimkitiveDenseStoree and GenericDenseStore are removed. + +#### org.ojalgo.structure + +- The stream(boolean) methods of ElementView, RowView and ColumnView are deprecated and replaced with a simple stream() method. You no longer have the option to use parallel streams. ### Deprecated diff --git a/pom.xml b/pom.xml index 6a7a74728..125aa9c7e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.ojalgo ojalgo - 47.3.0 + 47.3.1-SNAPSHOT jar ojAlgo http://ojalgo.org diff --git a/src/org/ojalgo/function/aggregator/AggregatorFunction.java b/src/org/ojalgo/function/aggregator/AggregatorFunction.java index 52ceaf173..52e0f8f10 100644 --- a/src/org/ojalgo/function/aggregator/AggregatorFunction.java +++ b/src/org/ojalgo/function/aggregator/AggregatorFunction.java @@ -27,13 +27,20 @@ public interface AggregatorFunction extends VoidFunction, AccessScalar { + /** + * @deprecated v48 Merging will no longer be supported + */ + @Deprecated default boolean isMergeable() { return true; } /** * Only works if {@link #isMergeable()}! + * + * @deprecated v48 Merging will no longer be supported */ + @Deprecated void merge(N result); AggregatorFunction reset(); diff --git a/src/org/ojalgo/matrix/store/GenericDenseStore.java b/src/org/ojalgo/matrix/store/GenericDenseStore.java index becefdb2c..445b15945 100644 --- a/src/org/ojalgo/matrix/store/GenericDenseStore.java +++ b/src/org/ojalgo/matrix/store/GenericDenseStore.java @@ -34,8 +34,6 @@ import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; -import org.ojalgo.function.aggregator.Aggregator; -import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.matrix.MatrixUtils; import org.ojalgo.matrix.decomposition.DecompositionStore; @@ -489,40 +487,6 @@ public void add(final long row, final long col, final Number addend) { myUtility.add(row, col, addend); } - public N aggregateAll(final Aggregator aggregator) { - - final int tmpRowDim = myRowDim; - final int tmpColDim = myColDim; - - final AggregatorFunction mainAggr = aggregator.getFunction(myFactory.aggregator()); - - if (mainAggr.isMergeable() && (tmpColDim > AggregateAll.THRESHOLD)) { - - final DivideAndConquer tmpConquerer = new DivideAndConquer() { - - @Override - public void conquer(final int aFirst, final int aLimit) { - - final AggregatorFunction tmpPartAggr = aggregator.getFunction(myFactory.aggregator()); - - GenericDenseStore.this.visit(tmpRowDim * aFirst, tmpRowDim * aLimit, 1, tmpPartAggr); - - synchronized (mainAggr) { - mainAggr.merge(tmpPartAggr.get()); - } - } - }; - - tmpConquerer.invoke(0, tmpColDim, AggregateAll.THRESHOLD); - - } else { - - GenericDenseStore.this.visit(0, this.size(), 1, mainAggr); - } - - return mainAggr.get(); - } - public void applyCholesky(final int iterationPoint, final BasicArray multipliers) { final N[] tmpData = data; diff --git a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java b/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java index 90872f1d0..bfae73d29 100644 --- a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java +++ b/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java @@ -42,8 +42,6 @@ import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; -import org.ojalgo.function.aggregator.Aggregator; -import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; @@ -531,40 +529,6 @@ public void add(final long row, final long col, final Number addend) { myUtility.add(row, col, addend); } - public Double aggregateAll(final Aggregator aggregator) { - - final int tmpRowDim = myRowDim; - final int tmpColDim = myColDim; - - final AggregatorFunction mainAggr = aggregator.getFunction(PrimitiveAggregator.getSet()); - - if (mainAggr.isMergeable() && (tmpColDim > AggregateAll.THRESHOLD)) { - - final DivideAndConquer tmpConquerer = new DivideAndConquer() { - - @Override - public void conquer(final int first, final int limit) { - - final AggregatorFunction tmpPartAggr = aggregator.getFunction(PrimitiveAggregator.getSet()); - - PrimitiveDenseStore.this.visit(tmpRowDim * first, tmpRowDim * limit, 1, tmpPartAggr); - - synchronized (mainAggr) { - mainAggr.merge(tmpPartAggr.get()); - } - } - }; - - tmpConquerer.invoke(0, tmpColDim, AggregateAll.THRESHOLD); - - } else { - - PrimitiveDenseStore.this.visit(0, this.size(), 1, mainAggr); - } - - return mainAggr.get(); - } - public void applyCholesky(final int iterationPoint, final BasicArray multipliers) { final double[] tmpData = data; diff --git a/src/org/ojalgo/matrix/store/SparseStore.java b/src/org/ojalgo/matrix/store/SparseStore.java index 46a6faa59..a99712514 100644 --- a/src/org/ojalgo/matrix/store/SparseStore.java +++ b/src/org/ojalgo/matrix/store/SparseStore.java @@ -97,7 +97,7 @@ static void multiply(final SparseStore left, final SparseS target.reset(); - right.nonzeros().stream(false).forEach(element -> { + right.nonzeros().stream().forEach(element -> { left.doColumnAXPY(element.row(), element.column(), element.doubleValue(), target); }); @@ -306,7 +306,7 @@ public void multiply(final Access1D right, final TransformableRegion targe target.reset(); - this.nonzeros().stream(false).forEach(element -> { + this.nonzeros().stream().forEach(element -> { final long row = element.row(); final long col = element.column(); @@ -426,7 +426,7 @@ public ElementsSupplier premultiply(final Access1D left) { final SparseStore retVal = SparseStore.makeSparse(this.physical(), numberOfRows, numberOfColumns); - this.nonzeros().stream(false).forEach(element -> { + this.nonzeros().stream().forEach(element -> { final long row = element.row(); final long col = element.column(); diff --git a/src/org/ojalgo/structure/ColumnView.java b/src/org/ojalgo/structure/ColumnView.java index 3cf6a281f..4d40b2149 100644 --- a/src/org/ojalgo/structure/ColumnView.java +++ b/src/org/ojalgo/structure/ColumnView.java @@ -115,8 +115,16 @@ public final void remove() { ProgrammingError.throwForUnsupportedOptionalOperation(); } + /** + * @deprecated v48 Use {@link #stream()} instead + */ + @Deprecated public Stream> stream(final boolean parallel) { - return StreamSupport.stream(this, parallel); + return this.stream(); + } + + public Stream> stream() { + return StreamSupport.stream(this, false); } @Override diff --git a/src/org/ojalgo/structure/ElementView1D.java b/src/org/ojalgo/structure/ElementView1D.java index c4d75588f..56662e36c 100644 --- a/src/org/ojalgo/structure/ElementView1D.java +++ b/src/org/ojalgo/structure/ElementView1D.java @@ -81,8 +81,16 @@ default boolean step() { } } + /** + * @deprecated v48 Use {@link #stream()} instead + */ + @Deprecated default Stream stream(final boolean parallel) { - return StreamSupport.stream(this, parallel); + return this.stream(); + } + + default Stream stream() { + return StreamSupport.stream(this, false); } default boolean tryAdvance(final Consumer action) { diff --git a/src/org/ojalgo/structure/RowView.java b/src/org/ojalgo/structure/RowView.java index 7bfa60449..db537a653 100644 --- a/src/org/ojalgo/structure/RowView.java +++ b/src/org/ojalgo/structure/RowView.java @@ -114,8 +114,16 @@ public long row() { return myRow; } + /** + * @deprecated v48 Use {@link #stream()} instead + */ + @Deprecated public Stream> stream(final boolean parallel) { - return StreamSupport.stream(this, parallel); + return this.stream(); + } + + public Stream> stream() { + return StreamSupport.stream(this, false); } @Override diff --git a/test/org/ojalgo/matrix/store/MergedColumnsCase.java b/test/org/ojalgo/matrix/store/AboveBelowCase.java similarity index 70% rename from test/org/ojalgo/matrix/store/MergedColumnsCase.java rename to test/org/ojalgo/matrix/store/AboveBelowCase.java index f73009b50..fbbc717c3 100644 --- a/test/org/ojalgo/matrix/store/MergedColumnsCase.java +++ b/test/org/ojalgo/matrix/store/AboveBelowCase.java @@ -25,20 +25,24 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; -public class MergedColumnsCase extends NonPhysicalTest { +public class AboveBelowCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final MatrixStore tmpLower = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore above = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore below = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new AboveBelowStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), GenericDenseStore.RATIONAL.copy(tmpLower)); - complexStore = new AboveBelowStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), GenericDenseStore.COMPLEX.copy(tmpLower)); - primitiveStore = new AboveBelowStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), PrimitiveDenseStore.FACTORY.copy(tmpLower)); + rationalStore = new AboveBelowStore<>(GenericDenseStore.RATIONAL.copy(above), GenericDenseStore.RATIONAL.copy(below)); + complexStore = new AboveBelowStore<>(GenericDenseStore.COMPLEX.copy(above), GenericDenseStore.COMPLEX.copy(below)); + primitiveStore = new AboveBelowStore<>(PrimitiveDenseStore.FACTORY.copy(above), PrimitiveDenseStore.FACTORY.copy(below)); + + numberOfRows = tmpRowDim + tmpRowDim; + numberOfColumns = tmpColDim; } } diff --git a/test/org/ojalgo/matrix/store/SelectedColumnsCase.java b/test/org/ojalgo/matrix/store/ColumnsCase.java similarity index 80% rename from test/org/ojalgo/matrix/store/SelectedColumnsCase.java rename to test/org/ojalgo/matrix/store/ColumnsCase.java index 404d813a0..775a239c9 100644 --- a/test/org/ojalgo/matrix/store/SelectedColumnsCase.java +++ b/test/org/ojalgo/matrix/store/ColumnsCase.java @@ -25,17 +25,18 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; -public class SelectedColumnsCase extends NonPhysicalTest { +public class ColumnsCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final int[] tmpCols = new int[Uniform.randomInteger(1, tmpColDim)]; + int[] tmpCols = new int[Uniform.randomInteger(1, tmpColDim)]; for (int i = 0; i < tmpCols.length; i++) { tmpCols[i] = Uniform.randomInteger(tmpColDim); } @@ -43,6 +44,9 @@ public void setUp() { rationalStore = new ColumnsStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), tmpCols); complexStore = new ColumnsStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), tmpCols); primitiveStore = new ColumnsStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), tmpCols); + + numberOfRows = tmpRowDim; + numberOfColumns = tmpCols.length; } } diff --git a/test/org/ojalgo/matrix/store/ConjugatedCase.java b/test/org/ojalgo/matrix/store/ConjugatedCase.java index 28b8e8456..252d3458a 100644 --- a/test/org/ojalgo/matrix/store/ConjugatedCase.java +++ b/test/org/ojalgo/matrix/store/ConjugatedCase.java @@ -27,17 +27,21 @@ public class ConjugatedCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore base = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new ConjugatedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase)); - complexStore = new ConjugatedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase)); - primitiveStore = new ConjugatedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase)); + rationalStore = new ConjugatedStore<>(GenericDenseStore.RATIONAL.copy(base)); + complexStore = new ConjugatedStore<>(GenericDenseStore.COMPLEX.copy(base)); + primitiveStore = new ConjugatedStore<>(PrimitiveDenseStore.FACTORY.copy(base)); + + numberOfRows = tmpColDim; + numberOfColumns = tmpRowDim; } } diff --git a/test/org/ojalgo/matrix/store/IdentityCase.java b/test/org/ojalgo/matrix/store/IdentityCase.java index e037f7392..f9bf107a2 100644 --- a/test/org/ojalgo/matrix/store/IdentityCase.java +++ b/test/org/ojalgo/matrix/store/IdentityCase.java @@ -26,14 +26,18 @@ public class IdentityCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpDim = Uniform.randomInteger(1, 9); + int dim = Uniform.randomInteger(1, 9); - rationalStore = new IdentityStore<>(GenericDenseStore.RATIONAL, tmpDim); - complexStore = new IdentityStore<>(GenericDenseStore.COMPLEX, tmpDim); - primitiveStore = new IdentityStore<>(PrimitiveDenseStore.FACTORY, tmpDim); + rationalStore = new IdentityStore<>(GenericDenseStore.RATIONAL, dim); + complexStore = new IdentityStore<>(GenericDenseStore.COMPLEX, dim); + primitiveStore = new IdentityStore<>(PrimitiveDenseStore.FACTORY, dim); + + numberOfRows = dim; + numberOfColumns = dim; } } diff --git a/test/org/ojalgo/matrix/store/MergedRowsCase.java b/test/org/ojalgo/matrix/store/LeftRightCase.java similarity index 70% rename from test/org/ojalgo/matrix/store/MergedRowsCase.java rename to test/org/ojalgo/matrix/store/LeftRightCase.java index 93dba6729..f6d933bae 100644 --- a/test/org/ojalgo/matrix/store/MergedRowsCase.java +++ b/test/org/ojalgo/matrix/store/LeftRightCase.java @@ -25,20 +25,24 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; -public class MergedRowsCase extends NonPhysicalTest { +public class LeftRightCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final MatrixStore tmpRight = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore left = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore right = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new LeftRightStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), GenericDenseStore.RATIONAL.copy(tmpRight)); - complexStore = new LeftRightStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), GenericDenseStore.COMPLEX.copy(tmpRight)); - primitiveStore = new LeftRightStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), PrimitiveDenseStore.FACTORY.copy(tmpRight)); + rationalStore = new LeftRightStore<>(GenericDenseStore.RATIONAL.copy(left), GenericDenseStore.RATIONAL.copy(right)); + complexStore = new LeftRightStore<>(GenericDenseStore.COMPLEX.copy(left), GenericDenseStore.COMPLEX.copy(right)); + primitiveStore = new LeftRightStore<>(PrimitiveDenseStore.FACTORY.copy(left), PrimitiveDenseStore.FACTORY.copy(right)); + + numberOfRows = tmpRowDim; + numberOfColumns = tmpColDim + tmpColDim; } } diff --git a/test/org/ojalgo/matrix/store/NonPhysicalTest.java b/test/org/ojalgo/matrix/store/NonPhysicalTest.java index 18b023e3b..c8b1a7128 100644 --- a/test/org/ojalgo/matrix/store/NonPhysicalTest.java +++ b/test/org/ojalgo/matrix/store/NonPhysicalTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.function.aggregator.Aggregator; +import org.ojalgo.netio.BasicLogger; import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; @@ -33,12 +34,15 @@ public abstract class NonPhysicalTest extends MatrixStoreTests { - private static NumberContext CNTXT = StandardType.DECIMAL_032; + private static final NumberContext ACCURACY = StandardType.DECIMAL_032; private static void testAggregation(final MatrixStore anyStore) { final PhysicalStore copied = anyStore.copy(); + BasicLogger.debug("Any", anyStore); + BasicLogger.debug("Copy", copied); + Number expected; Number actual; @@ -47,7 +51,7 @@ private static void testAggregation(final MatrixStore anyS expected = copied.aggregateAll(aggregator); actual = anyStore.aggregateAll(aggregator); - TestUtils.assertEquals(aggregator.name() + "@" + anyStore, expected, actual, CNTXT); + TestUtils.assertEquals(aggregator.name() + "@" + anyStore, expected, actual, ACCURACY); if (!((aggregator == Aggregator.AVERAGE) && (anyStore instanceof SparseStore))) { // For a sparse store the AVERAGE aggreghator will get an incorrect result @@ -56,54 +60,60 @@ private static void testAggregation(final MatrixStore anyS for (int i = 0; i < copied.countRows(); i++) { expected = copied.aggregateRow(i, aggregator); actual = anyStore.aggregateRow(i, aggregator); - TestUtils.assertEquals("Row: " + i + " " + aggregator.name(), expected, actual, CNTXT); + TestUtils.assertEquals("Row: " + i + " " + aggregator.name(), expected, actual, ACCURACY); } for (int j = 0; j < copied.countColumns(); j++) { expected = copied.aggregateColumn(j, aggregator); actual = anyStore.aggregateColumn(j, aggregator); - TestUtils.assertEquals("Col: " + j + " " + aggregator.name(), expected, actual, CNTXT); + TestUtils.assertEquals("Col: " + j + " " + aggregator.name(), expected, actual, ACCURACY); } } } } - private static void testElements(final MatrixStore aStore) { - TestUtils.assertEquals(aStore, aStore.copy(), CNTXT); + private static void testCopy(final MatrixStore anyStore) { + TestUtils.assertEquals(anyStore, anyStore.copy(), ACCURACY); + } + + private static void testDimensions(final MatrixStore anyStore, final int numberOfRows, final int numberOfColumns) { + TestUtils.assertEquals(numberOfRows, anyStore.countRows()); + TestUtils.assertEquals(numberOfColumns, anyStore.countColumns()); + TestUtils.assertEquals(numberOfRows * numberOfColumns, anyStore.count()); } - private static void testMultiplication(final MatrixStore matrixStore) { + private static void testMultiplication(final MatrixStore anyStore) { - final PhysicalStore tmpCopy = matrixStore.copy(); + final PhysicalStore tmpCopy = anyStore.copy(); - final int tmpRowDim = (int) matrixStore.countRows(); - final int tmpColDim = (int) matrixStore.countColumns(); + final int tmpRowDim = (int) anyStore.countRows(); + final int tmpColDim = (int) anyStore.countColumns(); final int tmpNewDim = Uniform.randomInteger(1, tmpRowDim + tmpColDim); // multiplyLeft final MatrixStore tmpLeftMtrx = NonPhysicalTest.makeRandomMatrix(tmpNewDim, tmpRowDim); - final PhysicalStore tmpLeft = matrixStore.physical().copy(tmpLeftMtrx); + final PhysicalStore tmpLeft = anyStore.physical().copy(tmpLeftMtrx); MatrixStore tmpExpected = tmpLeft.multiply(tmpCopy); - MatrixStore tmpActual = tmpLeft.multiply(matrixStore); - TestUtils.assertEquals(tmpExpected, tmpActual, CNTXT); + MatrixStore tmpActual = tmpLeft.multiply(anyStore); + TestUtils.assertEquals(tmpExpected, tmpActual, ACCURACY); tmpExpected = tmpCopy.premultiply(tmpLeft).get(); - tmpActual = matrixStore.premultiply(tmpLeft).get(); - TestUtils.assertEquals(tmpExpected, tmpActual, CNTXT); + tmpActual = anyStore.premultiply(tmpLeft).get(); + TestUtils.assertEquals(tmpExpected, tmpActual, ACCURACY); // multiplyRight final MatrixStore tmpRightMtrx = NonPhysicalTest.makeRandomMatrix(tmpColDim, tmpNewDim); - final PhysicalStore tmpRight = matrixStore.physical().copy(tmpRightMtrx); + final PhysicalStore tmpRight = anyStore.physical().copy(tmpRightMtrx); tmpExpected = tmpCopy.multiply(tmpRight); - tmpActual = matrixStore.multiply(tmpRight); - TestUtils.assertEquals(tmpExpected, tmpActual, CNTXT); + tmpActual = anyStore.multiply(tmpRight); + TestUtils.assertEquals(tmpExpected, tmpActual, ACCURACY); tmpExpected = tmpRight.premultiply(tmpCopy).get(); - tmpActual = tmpRight.premultiply(matrixStore).get(); - TestUtils.assertEquals(tmpExpected, tmpActual, CNTXT); + tmpActual = tmpRight.premultiply(anyStore).get(); + TestUtils.assertEquals(tmpExpected, tmpActual, ACCURACY); } protected static MatrixStore makeRandomMatrix(final int numberOfRows, final int numberOfColumns) { @@ -111,9 +121,13 @@ protected static MatrixStore makeRandomMatrix(final int numberOfR } MatrixStore complexStore; + int numberOfColumns; + int numberOfRows; MatrixStore primitiveStore; MatrixStore rationalStore; + public abstract void setUp(); + @AfterEach public void tearDown() { rationalStore = null; @@ -129,10 +143,17 @@ public void testAggregator() { } @Test - public void testElements() { - NonPhysicalTest.testElements(primitiveStore); - NonPhysicalTest.testElements(complexStore); - NonPhysicalTest.testElements(rationalStore); + public void testCopy() { + NonPhysicalTest.testCopy(primitiveStore); + NonPhysicalTest.testCopy(complexStore); + NonPhysicalTest.testCopy(rationalStore); + } + + @Test + public void testDimensions() { + NonPhysicalTest.testDimensions(primitiveStore, numberOfRows, numberOfColumns); + NonPhysicalTest.testDimensions(complexStore, numberOfRows, numberOfColumns); + NonPhysicalTest.testDimensions(rationalStore, numberOfRows, numberOfColumns); } @Test diff --git a/test/org/ojalgo/matrix/store/SelectedRowsCase.java b/test/org/ojalgo/matrix/store/RowsCase.java similarity index 80% rename from test/org/ojalgo/matrix/store/SelectedRowsCase.java rename to test/org/ojalgo/matrix/store/RowsCase.java index 68af11572..84c7aa494 100644 --- a/test/org/ojalgo/matrix/store/SelectedRowsCase.java +++ b/test/org/ojalgo/matrix/store/RowsCase.java @@ -25,17 +25,18 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; -public class SelectedRowsCase extends NonPhysicalTest { +public class RowsCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final int[] tmpRows = new int[Uniform.randomInteger(1, tmpRowDim)]; + int[] tmpRows = new int[Uniform.randomInteger(1, tmpRowDim)]; for (int i = 0; i < tmpRows.length; i++) { tmpRows[i] = Uniform.randomInteger(tmpRowDim); } @@ -43,6 +44,9 @@ public void setUp() { rationalStore = new RowsStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), tmpRows); complexStore = new RowsStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), tmpRows); primitiveStore = new RowsStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), tmpRows); + + numberOfRows = tmpRows.length; + numberOfColumns = tmpColDim; } } diff --git a/test/org/ojalgo/matrix/store/SparseCase.java b/test/org/ojalgo/matrix/store/SparseCase.java index 7413ad742..7bef9e417 100644 --- a/test/org/ojalgo/matrix/store/SparseCase.java +++ b/test/org/ojalgo/matrix/store/SparseCase.java @@ -29,10 +29,11 @@ public class SparseCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int dim = Uniform.randomInteger(1, 9); + int dim = Uniform.randomInteger(1, 9); rationalStore = SparseStore.RATIONAL.make(dim, dim); complexStore = SparseStore.COMPLEX.make(dim, dim); @@ -43,6 +44,9 @@ public void setUp() { ((SparseStore) complexStore).set(ij, ij, 1.0); ((SparseStore) primitiveStore).set(ij, ij, 1.0); } + + numberOfRows = dim; + numberOfColumns = dim; } @Test @@ -78,7 +82,7 @@ public void testMultiplySparseDense() { @Test public void testOneFullColumn() { - final int ind = Uniform.randomInteger(0, 10); + int ind = Uniform.randomInteger(0, 10); SparseStore store = SparseStore.PRIMITIVE.make(10, 10); store.fillColumn(ind, 1.0); @@ -106,7 +110,7 @@ public void testOneFullColumn() { @Test public void testOneFullRow() { - final int ind = Uniform.randomInteger(0, 10); + int ind = Uniform.randomInteger(0, 10); SparseStore store = SparseStore.PRIMITIVE.make(10, 10); store.fillRow(ind, 1.0); diff --git a/test/org/ojalgo/matrix/store/SuperimposedMatrixColumnCase.java b/test/org/ojalgo/matrix/store/SuperimposedColumnCase.java similarity index 77% rename from test/org/ojalgo/matrix/store/SuperimposedMatrixColumnCase.java rename to test/org/ojalgo/matrix/store/SuperimposedColumnCase.java index 2f64d481d..27d54ed17 100644 --- a/test/org/ojalgo/matrix/store/SuperimposedMatrixColumnCase.java +++ b/test/org/ojalgo/matrix/store/SuperimposedColumnCase.java @@ -25,21 +25,25 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; -public class SuperimposedMatrixColumnCase extends NonPhysicalTest { +public class SuperimposedColumnCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final MatrixStore tmpColumn = NonPhysicalTest.makeRandomMatrix(tmpRowDim, 1); - final int tmpIndex = Uniform.randomInteger(tmpColDim); + MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore tmpColumn = NonPhysicalTest.makeRandomMatrix(tmpRowDim, 1); + int tmpIndex = Uniform.randomInteger(tmpColDim); rationalStore = new SuperimposedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), 0, tmpIndex, GenericDenseStore.RATIONAL.copy(tmpColumn)); complexStore = new SuperimposedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), 0, tmpIndex, GenericDenseStore.COMPLEX.copy(tmpColumn)); primitiveStore = new SuperimposedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), 0, tmpIndex, PrimitiveDenseStore.FACTORY.copy(tmpColumn)); + + numberOfRows = tmpRowDim; + numberOfColumns = tmpColDim; } } diff --git a/test/org/ojalgo/matrix/store/SuperimposedMatrixElementCase.java b/test/org/ojalgo/matrix/store/SuperimposedElementCase.java similarity index 75% rename from test/org/ojalgo/matrix/store/SuperimposedMatrixElementCase.java rename to test/org/ojalgo/matrix/store/SuperimposedElementCase.java index c439ace7c..d93759d81 100644 --- a/test/org/ojalgo/matrix/store/SuperimposedMatrixElementCase.java +++ b/test/org/ojalgo/matrix/store/SuperimposedElementCase.java @@ -29,30 +29,34 @@ import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; -public class SuperimposedMatrixElementCase extends NonPhysicalTest { +public class SuperimposedElementCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final int tmpRowIndex = Uniform.randomInteger(tmpRowDim); - final int tmpColumnIndex = Uniform.randomInteger(tmpColDim); - final BigDecimal tmpElement = BigMath.PI; - final MatrixStore aBase = GenericDenseStore.RATIONAL.copy(tmpBase); + MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + int tmpRowIndex = Uniform.randomInteger(tmpRowDim); + int tmpColumnIndex = Uniform.randomInteger(tmpColDim); + BigDecimal tmpElement = BigMath.PI; + MatrixStore aBase = GenericDenseStore.RATIONAL.copy(tmpBase); // myBigStore = new SuperimposedMatrixStore(BigDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, tmpColumnIndex, tmpElement); // myComplexStore = new SuperimposedMatrixStore(ComplexDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, tmpColumnIndex, ComplexNumber.makeReal(tmpElement.doubleValue())); // myPrimitiveStore = new SuperimposedMatrixStore(PrimitiveDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, tmpColumnIndex, tmpElement.doubleValue()); rationalStore = new SuperimposedStore<>(aBase, tmpRowIndex, tmpColumnIndex, new SingleStore<>(aBase.physical(), tmpElement)); - final MatrixStore aBase1 = GenericDenseStore.COMPLEX.copy(tmpBase); + MatrixStore aBase1 = GenericDenseStore.COMPLEX.copy(tmpBase); complexStore = new SuperimposedStore<>(aBase1, tmpRowIndex, tmpColumnIndex, new SingleStore<>(aBase1.physical(), ComplexNumber.valueOf(tmpElement.doubleValue()))); - final MatrixStore aBase2 = PrimitiveDenseStore.FACTORY.copy(tmpBase); + MatrixStore aBase2 = PrimitiveDenseStore.FACTORY.copy(tmpBase); primitiveStore = new SuperimposedStore<>(aBase2, tmpRowIndex, tmpColumnIndex, new SingleStore<>(aBase2.physical(), tmpElement.doubleValue())); + + numberOfRows = tmpRowDim; + numberOfColumns = tmpColDim; } } diff --git a/test/org/ojalgo/matrix/store/SuperimposedMatrixRowCase.java b/test/org/ojalgo/matrix/store/SuperimposedRowCase.java similarity index 77% rename from test/org/ojalgo/matrix/store/SuperimposedMatrixRowCase.java rename to test/org/ojalgo/matrix/store/SuperimposedRowCase.java index 804185822..403a24a3f 100644 --- a/test/org/ojalgo/matrix/store/SuperimposedMatrixRowCase.java +++ b/test/org/ojalgo/matrix/store/SuperimposedRowCase.java @@ -25,21 +25,25 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; -public class SuperimposedMatrixRowCase extends NonPhysicalTest { +public class SuperimposedRowCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - final MatrixStore tmpRow = NonPhysicalTest.makeRandomMatrix(1, tmpColDim); - final int tmpIndex = Uniform.randomInteger(tmpRowDim); + MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore tmpRow = NonPhysicalTest.makeRandomMatrix(1, tmpColDim); + int tmpIndex = Uniform.randomInteger(tmpRowDim); rationalStore = new SuperimposedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), tmpIndex, 0, GenericDenseStore.RATIONAL.copy(tmpRow)); complexStore = new SuperimposedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), tmpIndex, 0, GenericDenseStore.COMPLEX.copy(tmpRow)); primitiveStore = new SuperimposedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), tmpIndex, 0, PrimitiveDenseStore.FACTORY.copy(tmpRow)); + + numberOfRows = tmpRowDim; + numberOfColumns = tmpColDim; } } diff --git a/test/org/ojalgo/matrix/store/TransposedCase.java b/test/org/ojalgo/matrix/store/TransposedCase.java index abce7dbf3..514391fd4 100644 --- a/test/org/ojalgo/matrix/store/TransposedCase.java +++ b/test/org/ojalgo/matrix/store/TransposedCase.java @@ -27,17 +27,21 @@ public class TransposedCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); - final MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); + MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); rationalStore = new TransposedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase)); complexStore = new TransposedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase)); primitiveStore = new TransposedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase)); + + numberOfRows = tmpColDim; + numberOfColumns = tmpRowDim; } } diff --git a/test/org/ojalgo/matrix/store/ZeroCase.java b/test/org/ojalgo/matrix/store/ZeroCase.java index 80c2f94ee..42ec3f455 100644 --- a/test/org/ojalgo/matrix/store/ZeroCase.java +++ b/test/org/ojalgo/matrix/store/ZeroCase.java @@ -26,15 +26,19 @@ public class ZeroCase extends NonPhysicalTest { + @Override @BeforeEach public void setUp() { - final int tmpRowDim = Uniform.randomInteger(1, 9); - final int tmpColDim = Uniform.randomInteger(1, 9); + int tmpRowDim = Uniform.randomInteger(1, 9); + int tmpColDim = Uniform.randomInteger(1, 9); rationalStore = new ZeroStore<>(GenericDenseStore.RATIONAL, tmpRowDim, tmpColDim); complexStore = new ZeroStore<>(GenericDenseStore.COMPLEX, tmpRowDim, tmpColDim); primitiveStore = new ZeroStore<>(PrimitiveDenseStore.FACTORY, tmpRowDim, tmpColDim); + + numberOfRows = tmpRowDim; + numberOfColumns = tmpColDim; } } From 1266cbd361d4cffb0a4632889a6b24c0c339170e Mon Sep 17 00:00:00 2001 From: apete Date: Mon, 2 Sep 2019 20:35:59 +0200 Subject: [PATCH 05/29] Update NonPhysicalTest.java --- test/org/ojalgo/matrix/store/NonPhysicalTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/org/ojalgo/matrix/store/NonPhysicalTest.java b/test/org/ojalgo/matrix/store/NonPhysicalTest.java index c8b1a7128..d5a4e3cb2 100644 --- a/test/org/ojalgo/matrix/store/NonPhysicalTest.java +++ b/test/org/ojalgo/matrix/store/NonPhysicalTest.java @@ -40,8 +40,10 @@ private static void testAggregation(final MatrixStore anyS final PhysicalStore copied = anyStore.copy(); - BasicLogger.debug("Any", anyStore); - BasicLogger.debug("Copy", copied); + if (DEBUG) { + BasicLogger.debug("Any", anyStore); + BasicLogger.debug("Copy", copied); + } Number expected; Number actual; From 14a00446a950ed138dff47b71534bc9b0c88483f Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Thu, 12 Sep 2019 08:29:59 +0200 Subject: [PATCH 06/29] Feature/convex solver stuck (#223) * setIterationsLimit in ConjugateGradientSolver * Changes * he compareTo method of CalendarDateDuration --- CHANGELOG.md | 7 ++++++- .../matrix/task/iterative/IterativeSolverTask.java | 2 +- .../ojalgo/optimisation/convex/ActiveSetSolver.java | 12 ++++++------ .../optimisation/convex/ConstrainedSolver.java | 2 +- src/org/ojalgo/optimisation/convex/ConvexSolver.java | 8 ++++---- src/org/ojalgo/optimisation/convex/IterativeASS.java | 11 ++++++----- src/org/ojalgo/type/CalendarDateDuration.java | 4 ++-- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f57919d79..3a83d400d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), @@ -22,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The multithreaded implementations of aggregateAll in PrimkitiveDenseStoree and GenericDenseStore are removed. +#### org.ojalgo.optimisation + +- The iterative version of the ActiveSetSolver now enforce an iterations limit. + #### org.ojalgo.structure - The stream(boolean) methods of ElementView, RowView and ColumnView are deprecated and replaced with a simple stream() method. You no longer have the option to use parallel streams. @@ -36,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- +- The compareTo method of CalendarDateDuration didn't work when the unit of either instances was "nanos". ### Security diff --git a/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java b/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java index f996c5d65..95b564a89 100644 --- a/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java +++ b/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java @@ -134,7 +134,7 @@ public final PhysicalStore preallocate(final Structure2D templateBody, f if (templateRHS.countColumns() != 1L) { throw new IllegalArgumentException("The RHS must have precisely 1 column!"); } - return PrimitiveDenseStore.FACTORY.makeZero(templateBody.countColumns(), 1L); + return PrimitiveDenseStore.FACTORY.make(templateBody.countColumns(), 1L); } public final Optional> solve(final MatrixStore body, final MatrixStore rhs) { diff --git a/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java b/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java index 94c2409ab..00b6dbfed 100644 --- a/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java +++ b/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java @@ -61,10 +61,10 @@ abstract class ActiveSetSolver extends ConstrainedSolver { myActivator = new IndexSelector(numberOfInequalityConstraints); - mySolutionL = PrimitiveDenseStore.FACTORY.makeZero(numberOfEqualityConstraints + numberOfInequalityConstraints, 1L); - myIterationX = PrimitiveDenseStore.FACTORY.makeZero(numberOfVariables, 1L); + mySolutionL = PrimitiveDenseStore.FACTORY.make(numberOfEqualityConstraints + numberOfInequalityConstraints, 1L); + myIterationX = PrimitiveDenseStore.FACTORY.make(numberOfVariables, 1L); - mySlackI = PrimitiveDenseStore.FACTORY.makeZero(numberOfInequalityConstraints, 1L); + mySlackI = PrimitiveDenseStore.FACTORY.make(numberOfInequalityConstraints, 1L); } private void handleIterationSolution(final PrimitiveDenseStore iterX, final int[] excluded) { @@ -230,7 +230,7 @@ private final int suggestUsingVectorProjection() { final int[] incl = myActivator.getIncluded(); int lastIncluded = myActivator.getLastIncluded(); - AggregatorFunction aggregator = PrimitiveAggregator.NORM2.get(); + AggregatorFunction aggregator = PrimitiveAggregator.getSet().norm2(); SparseArray lastRow = this.getMatrixAI(lastIncluded); lastRow.visitAll(aggregator); double lastNorm = aggregator.doubleValue(); @@ -524,7 +524,7 @@ final MatrixStore getIterationA() { final int numbVars = this.countVariables(); final int[] incl = myActivator.getIncluded(); - final PhysicalStore retVal = PrimitiveDenseStore.FACTORY.makeZero(numbEqus + incl.length, numbVars); + final PhysicalStore retVal = PrimitiveDenseStore.FACTORY.make(numbEqus + incl.length, numbVars); if (numbEqus > 0) { this.getMatrixAE().supplyTo(retVal.regionByLimits(numbEqus, numbVars)); @@ -542,7 +542,7 @@ final MatrixStore getIterationB() { final int numbEqus = this.countEqualityConstraints(); final int[] incl = myActivator.getIncluded(); - final PhysicalStore retVal = PrimitiveDenseStore.FACTORY.makeZero(numbEqus + incl.length, 1); + final PhysicalStore retVal = PrimitiveDenseStore.FACTORY.make(numbEqus + incl.length, 1); for (int i = 0; i < numbEqus; i++) { retVal.set(i, this.getMatrixBE().doubleValue(i)); diff --git a/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java b/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java index 868067c23..3da46303f 100644 --- a/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java +++ b/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java @@ -38,7 +38,7 @@ protected ConstrainedSolver(final ConvexSolver.Builder matrices, final Options s int numberOfEqualityConstraints = this.countEqualityConstraints(); - mySlackE = PrimitiveDenseStore.FACTORY.makeZero(numberOfEqualityConstraints, 1L); + mySlackE = PrimitiveDenseStore.FACTORY.make(numberOfEqualityConstraints, 1L); } @Override diff --git a/src/org/ojalgo/optimisation/convex/ConvexSolver.java b/src/org/ojalgo/optimisation/convex/ConvexSolver.java index b4bdd3f4f..f0100d6d5 100644 --- a/src/org/ojalgo/optimisation/convex/ConvexSolver.java +++ b/src/org/ojalgo/optimisation/convex/ConvexSolver.java @@ -297,7 +297,7 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol if (numbEqExpr > 0) { final SparseStore mtrxAE = SparseStore.PRIMITIVE.make(numbEqExpr, numbVars); - final PhysicalStore mtrxBE = PrimitiveDenseStore.FACTORY.makeZero(numbEqExpr, 1); + final PhysicalStore mtrxBE = PrimitiveDenseStore.FACTORY.make(numbEqExpr, 1); for (int i = 0; i < numbEqExpr; i++) { @@ -321,7 +321,7 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol PhysicalStore mtrxQ = null; if (tmpObjExpr.isAnyQuadraticFactorNonZero()) { - mtrxQ = PrimitiveDenseStore.FACTORY.makeZero(numbVars, numbVars); + mtrxQ = PrimitiveDenseStore.FACTORY.make(numbVars, numbVars); final BinaryFunction tmpBaseFunc = sourceModel.isMaximisation() ? SUBTRACT : ADD; UnaryFunction tmpModifier; @@ -338,7 +338,7 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol PhysicalStore mtrxC = null; if (tmpObjExpr.isAnyLinearFactorNonZero()) { - mtrxC = PrimitiveDenseStore.FACTORY.makeZero(numbVars, 1); + mtrxC = PrimitiveDenseStore.FACTORY.make(numbVars, 1); if (sourceModel.isMinimisation()) { for (final IntIndex tmpKey : tmpObjExpr.getLinearKeySet()) { final int tmpIndex = sourceModel.indexOfFreeVariable(tmpKey.index); @@ -377,7 +377,7 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol if ((numbUpExpr + numbUpVar + numbLoExpr + numbLoVar) > 0) { final RowsSupplier mtrxAI = PrimitiveDenseStore.FACTORY.makeRowsSupplier(numbVars); - final PhysicalStore mtrxBI = PrimitiveDenseStore.FACTORY.makeZero(numbUpExpr + numbUpVar + numbLoExpr + numbLoVar, 1); + final PhysicalStore mtrxBI = PrimitiveDenseStore.FACTORY.make(numbUpExpr + numbUpVar + numbLoExpr + numbLoVar, 1); if (numbUpExpr > 0) { for (int i = 0; i < numbUpExpr; i++) { diff --git a/src/org/ojalgo/optimisation/convex/IterativeASS.java b/src/org/ojalgo/optimisation/convex/IterativeASS.java index d099dfe1f..1e961d631 100644 --- a/src/org/ojalgo/optimisation/convex/IterativeASS.java +++ b/src/org/ojalgo/optimisation/convex/IterativeASS.java @@ -56,7 +56,7 @@ final class MyIterativeSolver extends MutableSolver imp private final PhysicalStore myColumnE; private final int myCountE = IterativeASS.this.countEqualityConstraints(); - private final long myFullDim = myCountE + IterativeASS.this.countInequalityConstraints(); + private final int myFullDim = myCountE + IterativeASS.this.countInequalityConstraints(); private final Equation[] myIterationRows; MyIterativeSolver() { @@ -69,12 +69,13 @@ final class MyIterativeSolver extends MutableSolver imp // ConjugateGradient this.setAccuracyContext(ITERATIVE_ACCURACY); + this.setIterationsLimit(myFullDim + myFullDim); // this.setDebugPrinter(BasicLogger.DEBUG); - myIterationRows = new Equation[(int) myFullDim]; + myIterationRows = new Equation[myFullDim]; - myColumnE = PrimitiveDenseStore.FACTORY.makeZero(myCountE, 1); + myColumnE = PrimitiveDenseStore.FACTORY.make(myCountE, 1); } @Override @@ -172,7 +173,7 @@ void remove(final int i) { super(matrices, solverOptions); myS = new MyIterativeSolver(); - myColumnS = PrimitiveDenseStore.FACTORY.makeZero(this.countVariables(), 1); + myColumnS = PrimitiveDenseStore.FACTORY.make(this.countVariables(), 1); } private void addConstraint(final int constrIndex, final Access1D constrBody, final double constrRHS) { @@ -243,7 +244,7 @@ protected void performIteration() { if (!solved) { // The above failed, try solving the full KKT system instaed - final PrimitiveDenseStore tmpXL = PrimitiveDenseStore.FACTORY.makeZero(this.countVariables() + this.countIterationConstraints(), 1L); + final PrimitiveDenseStore tmpXL = PrimitiveDenseStore.FACTORY.make(this.countVariables() + this.countIterationConstraints(), 1L); if (solved = this.solveFullKKT(tmpXL)) { diff --git a/src/org/ojalgo/type/CalendarDateDuration.java b/src/org/ojalgo/type/CalendarDateDuration.java index 93e39d9bc..c595cf98e 100644 --- a/src/org/ojalgo/type/CalendarDateDuration.java +++ b/src/org/ojalgo/type/CalendarDateDuration.java @@ -87,8 +87,8 @@ public Temporal adjustInto(final Temporal temporal) { } public int compareTo(final CalendarDateDuration reference) { - final long tmpVal = this.toDurationInMillis(); - final long refVal = reference.toDurationInMillis(); + final long tmpVal = this.toDurationInNanos(); + final long refVal = reference.toDurationInNanos(); return Long.signum(tmpVal - refVal); } From 95672871e7c12368177431dcd5dbb4eff97114b9 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Sun, 22 Sep 2019 10:14:13 +0200 Subject: [PATCH 07/29] PowerOf2 (#224) * PowerOf2 * Update CHANGELOG.md --- CHANGELOG.md | 13 +- src/org/ojalgo/array/BasicArray.java | 4 +- src/org/ojalgo/array/SegmentedArray.java | 7 +- .../function/constant/PrimitiveMath.java | 27 +- src/org/ojalgo/function/special/PowerOf2.java | 178 ++++++++ .../ojalgo/netio/EnumeratedColumnsParser.java | 398 ++++++++++++++++++ .../function/constant/PrimitiveMathTest.java | 16 - .../ojalgo/function/special/PowerOf2Test.java | 61 +++ 8 files changed, 661 insertions(+), 43 deletions(-) create mode 100644 src/org/ojalgo/function/special/PowerOf2.java create mode 100644 src/org/ojalgo/netio/EnumeratedColumnsParser.java create mode 100644 test/org/ojalgo/function/special/PowerOf2Test.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a83d400d..23e9c3c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- +#### org.ojalgo.function -### Changed +- New special function utility class PowerOf2. It replaces what was in PrimitiveMath, amde some improvements and addition and added support or 'int' (used to be only 'long'). -#### org.ojalgo.function +### Changed -- The merge functionality of AggregatorFunction is deprecated. +- #### org.ojalgo.matrix @@ -33,7 +33,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated -- +#### org.ojalgo.function + +- The merge functionality of AggregatorFunction is deprecated. +- Everything related to "power of 2" has been deprecetd in PrimitiveMath. ### Removed diff --git a/src/org/ojalgo/array/BasicArray.java b/src/org/ojalgo/array/BasicArray.java index 0dd0b1898..f2ca27400 100644 --- a/src/org/ojalgo/array/BasicArray.java +++ b/src/org/ojalgo/array/BasicArray.java @@ -28,7 +28,7 @@ import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.aggregator.AggregatorSet; -import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.PowerOf2; import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; @@ -52,7 +52,7 @@ public abstract class BasicArray public static final class Factory extends ArrayFactory> { - private static final long SPARSE_SEGMENTATION_LIMIT = PrimitiveMath.POWERS_OF_2[46]; + private static final long SPARSE_SEGMENTATION_LIMIT = PowerOf2.powerOfLong2(46); private final DenseArray.Factory myDenseFactory; diff --git a/src/org/ojalgo/array/SegmentedArray.java b/src/org/ojalgo/array/SegmentedArray.java index 098001a9a..9924387f5 100644 --- a/src/org/ojalgo/array/SegmentedArray.java +++ b/src/org/ojalgo/array/SegmentedArray.java @@ -21,14 +21,11 @@ */ package org.ojalgo.array; -import static org.ojalgo.function.constant.PrimitiveMath.*; - -import java.util.Arrays; - import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; +import org.ojalgo.function.special.PowerOf2; import org.ojalgo.structure.Access1D; /** @@ -69,7 +66,7 @@ final class SegmentedArray extends BasicArray { throw new IllegalArgumentException("The last segment cannot be larger than the others!"); } - myIndexBits = Arrays.binarySearch(POWERS_OF_2, mySegmentSize); + myIndexBits = PowerOf2.find(mySegmentSize); if ((myIndexBits < 0) || (mySegmentSize != (1L << myIndexBits))) { throw new IllegalArgumentException("The segment size must be a power of 2!"); } diff --git a/src/org/ojalgo/function/constant/PrimitiveMath.java b/src/org/ojalgo/function/constant/PrimitiveMath.java index 67ee70e5e..7b5b53d31 100644 --- a/src/org/ojalgo/function/constant/PrimitiveMath.java +++ b/src/org/ojalgo/function/constant/PrimitiveMath.java @@ -21,10 +21,9 @@ */ package org.ojalgo.function.constant; -import java.util.Arrays; - import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.special.MissingMath; +import org.ojalgo.function.special.PowerOf2; import org.ojalgo.scalar.PrimitiveScalar; public abstract class PrimitiveMath { @@ -120,14 +119,6 @@ public static class Prefix { 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271 }; - public static final long[] POWERS_OF_2 = new long[63]; - static { - POWERS_OF_2[0] = 1L; - for (int p = 1; p < POWERS_OF_2.length; p++) { - POWERS_OF_2[p] = POWERS_OF_2[p - 1] * 2L; - } - } - /* * The lambdas below should not (cannot) reference each other. Implementations must be written in terms of * java.lang.Math and/or org.ojalgo.function.special.MissingMath. @@ -182,24 +173,30 @@ public static final int getPrimeNumber(final int index) { return PRIME[index]; } + /** + * @deprecated v48 Use {@link PowerOf2#isPowerOf2(long)} instead + */ + @Deprecated public static final boolean isPowerOf2(final long value) { - return Arrays.binarySearch(POWERS_OF_2, value) >= 0; + return PowerOf2.isPowerOf2(value); } /** * @return The smallest integer exponent so that 2^exp >= value. + * @deprecated v48 Use {@link PowerOf2#powerOf2Larger(long)} instead */ + @Deprecated public static final int powerOf2Larger(final long value) { - final int index = Arrays.binarySearch(POWERS_OF_2, value); - return index >= 0 ? index : Math.min(-(index + 1), 62); + return PowerOf2.powerOf2Larger(value); } /** * @return The largest integer exponent so that 2^exp <= value. + * @deprecated v48 Use {@link PowerOf2#powerOf2Smaller(long)} instead */ + @Deprecated public static final int powerOf2Smaller(final long value) { - final int index = Arrays.binarySearch(POWERS_OF_2, value); - return index >= 0 ? index : Math.max(-(index + 2), 0); + return PowerOf2.powerOf2Smaller(value); } } diff --git a/src/org/ojalgo/function/special/PowerOf2.java b/src/org/ojalgo/function/special/PowerOf2.java new file mode 100644 index 000000000..03e6cd728 --- /dev/null +++ b/src/org/ojalgo/function/special/PowerOf2.java @@ -0,0 +1,178 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import java.util.Arrays; + +import org.ojalgo.function.constant.PrimitiveMath; + +public abstract class PowerOf2 { + + public static final class IntPower extends PowerOf2 { + + public final int value; + private final int myModuloMask; + + IntPower(int exponent, int value) { + super(exponent); + this.value = value; + myModuloMask = value - 1; + } + + public int divide(int dividend) { + return dividend >> exponent; + } + + public int getModuloMask() { + return myModuloMask; + } + + public int modulo(int dividend) { + return dividend & myModuloMask; + } + + } + + public static final class LongPower extends PowerOf2 { + + public final long value; + private final long myModuloMask; + + LongPower(int exponent, long value) { + super(exponent); + this.value = value; + myModuloMask = value - 1L; + } + + public long divide(long dividend) { + return dividend >> exponent; + } + + public long getModuloMask() { + return myModuloMask; + } + + public long modulo(long dividend) { + return dividend & myModuloMask; + } + + } + + private static final int[] INT_POWERS = new int[31]; + private static double LN2 = Math.log(PrimitiveMath.TWO); + private static final long[] LONG_POWERS = new long[63]; + + static { + + INT_POWERS[0] = 1; + for (int p = 1; p < INT_POWERS.length; p++) { + INT_POWERS[p] = INT_POWERS[p - 1] * 2; + } + + LONG_POWERS[0] = 1L; + for (int p = 1; p < LONG_POWERS.length; p++) { + LONG_POWERS[p] = LONG_POWERS[p - 1] * 2L; + } + } + + public static int exponent(final double value) { + return MissingMath.roundToInt(Math.log(value) / LN2); + } + + /** + * If the input value is a power of 2 then the exponent is returned, if not a negative number is returned. + */ + public static int find(final int value) { + return Arrays.binarySearch(INT_POWERS, value); + } + + /** + * @see PowerOf2#find(int) + */ + public static int find(final long value) { + return Arrays.binarySearch(LONG_POWERS, value); + } + + public static IntPower getIntPower(int exponent) { + return new IntPower(exponent, INT_POWERS[exponent]); + } + + public static LongPower getLongPower(int exponent) { + return new LongPower(exponent, LONG_POWERS[exponent]); + } + + public static boolean isPowerOf2(final int value) { + return (value > 0) && ((value & (value - 1)) == 0); + } + + public static boolean isPowerOf2(final long value) { + return (value > 0L) && ((value & (value - 1L)) == 0L); + } + + /** + * @return The smallest integer exponent so that 2^exp >= value. + */ + public static int powerOf2Larger(final int value) { + final int index = Arrays.binarySearch(INT_POWERS, value); + return index >= 0 ? index : Math.min(-(index + 1), 30); + } + + /** + * @return The smallest integer exponent so that 2^exp >= value. + */ + public static int powerOf2Larger(final long value) { + final int index = Arrays.binarySearch(LONG_POWERS, value); + return index >= 0 ? index : Math.min(-(index + 1), 62); + } + + /** + * @return The largest integer exponent so that 2^exp <= value. + */ + public static int powerOf2Smaller(final int value) { + final int index = Arrays.binarySearch(INT_POWERS, value); + return index >= 0 ? index : Math.max(-(index + 2), 0); + } + + /** + * @return The largest integer exponent so that 2^exp <= value. + */ + public static int powerOf2Smaller(final long value) { + final int index = Arrays.binarySearch(LONG_POWERS, value); + return index >= 0 ? index : Math.max(-(index + 2), 0); + } + + public static int powerOfInt2(int exponent) { + return INT_POWERS[exponent]; + } + + public static long powerOfLong2(int exponent) { + return LONG_POWERS[exponent]; + } + + public final int exponent; + + PowerOf2(int exponent) { + super(); + this.exponent = exponent; + } + +} diff --git a/src/org/ojalgo/netio/EnumeratedColumnsParser.java b/src/org/ojalgo/netio/EnumeratedColumnsParser.java new file mode 100644 index 000000000..7cf06d17a --- /dev/null +++ b/src/org/ojalgo/netio/EnumeratedColumnsParser.java @@ -0,0 +1,398 @@ +/* + * Copyright 1997-2019 Optimatika (www.optimatika.se) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.netio; + +import java.io.BufferedReader; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.function.Supplier; + +import org.ojalgo.netio.EnumeratedColumnsParser.LineView; +import org.ojalgo.type.context.TypeContext; + +public class EnumeratedColumnsParser extends AbstractParser { + + public static class Builder implements Supplier { + + private char myDelimiter = ','; + private final int myNumberOfColumns; + private ParseStrategy myStrategy = ParseStrategy.RFC4180; + + Builder(final int numberOfColumns) { + + super(); + + myNumberOfColumns = numberOfColumns; + } + + public Builder delimiter(final char delimiter) { + myDelimiter = delimiter; + return this; + } + + public EnumeratedColumnsParser get() { + return new EnumeratedColumnsParser(myNumberOfColumns, myDelimiter, myStrategy); + } + + public Builder strategy(final ParseStrategy quoted) { + myStrategy = quoted; + return this; + } + + } + + public static abstract class LineView { + + final char delimiter; + transient String line = null; + final int numberOfColumns; + + @SuppressWarnings("unused") + private LineView() { + this(0, ','); + } + + LineView(final int numberOfColumns, final char delimiter) { + + super(); + + this.numberOfColumns = numberOfColumns; + this.delimiter = delimiter; + } + + public final double doubleValue(final Enum column) { + final String tmpStringValue = this.get(column.ordinal()); + if ((tmpStringValue != null) && (tmpStringValue.length() > 0)) { + return Double.parseDouble(tmpStringValue); + } else { + return Double.NaN; + } + } + + public final double floatValue(final Enum column) { + final String tmpStringValue = this.get(column.ordinal()); + if ((tmpStringValue != null) && (tmpStringValue.length() > 0)) { + return Float.parseFloat(tmpStringValue); + } else { + return Float.NaN; + } + } + + public final String get(final Enum column) { + return this.get(column.ordinal()); + } + + public final

P get(final Enum column, final TypeContext

typeContext) { + final String tmpStringValue = this.get(column.ordinal()); + if ((tmpStringValue != null) && (tmpStringValue.length() > 0)) { + return typeContext.parse(tmpStringValue); + } else { + return null; + } + } + + public abstract String get(final int column); + + public final long intValue(final Enum column) { + final String tmpStringValue = this.get(column.ordinal()); + if ((tmpStringValue != null) && (tmpStringValue.length() > 0)) { + return Integer.parseInt(tmpStringValue); + } else { + return 0; + } + } + + public boolean isLineOK() { + return (line != null) && (line.length() > 0); + } + + public final long longValue(final Enum column) { + final String tmpStringValue = this.get(column.ordinal()); + if ((tmpStringValue != null) && (tmpStringValue.length() > 0)) { + return Long.parseLong(tmpStringValue); + } else { + return 0L; + } + } + + public final BigDecimal toBigDecimal(final Enum column) { + final String tmpStringValue = this.get(column.ordinal()); + if ((tmpStringValue != null) && (tmpStringValue.length() > 0)) { + return new BigDecimal(tmpStringValue); + } else { + return null; + } + } + + abstract boolean index(final String line, BufferedReader reader); + + } + + public enum ParseStrategy { + + /** + * Simplest possible. Just delimited data. No quoting or any special characters... + */ + FAST { + + @Override + public LineView make(final int numberOfColumns, final char delimiter) { + return new FastViewStrategy(numberOfColumns, delimiter); + } + }, + + /** + * Same as {@link #FAST} but assumes values are quoted (they have to be, ALL of them). + */ + QUOTED() { + + @Override + public LineView make(final int numberOfColumns, final char delimiter) { + return new QuotedViewStrategy(numberOfColumns, delimiter); + } + }, + + /** + * As specified by the RFC4180 standard. + */ + RFC4180 { + + @Override + public LineView make(final int numberOfColumns, final char delimiter) { + return new RFC4180(numberOfColumns, delimiter); + } + }; + + public abstract LineView make(int numberOfColumns, char delimiter); + + } + + static class FastViewStrategy extends LineView { + + private final int[] myIndices; + + FastViewStrategy(final int numberOfColumns, final char delimiter) { + + super(numberOfColumns, delimiter); + + myIndices = new int[numberOfColumns + 1]; + } + + @Override + public String get(final int column) { + return line.substring(myIndices[column] + 1, myIndices[column + 1]); + } + + @Override + boolean index(final String line, final BufferedReader reader) { + + int tmpIndex = 0; + int tmpPosition = -1; + myIndices[tmpIndex] = tmpPosition; + + while ((tmpPosition = line.indexOf(delimiter, ++tmpPosition)) >= 0) { + myIndices[++tmpIndex] = tmpPosition; + } + + tmpPosition = line.length(); + myIndices[++tmpIndex] = tmpPosition; + + this.line = line; + + return tmpIndex == numberOfColumns; + } + } + + static class QuotedViewStrategy extends LineView { + + private final int[] myIndices; + private final String mySplitter; + + QuotedViewStrategy(final int numberOfColumns, final char delimiter) { + + super(numberOfColumns, delimiter); + + myIndices = new int[numberOfColumns + 1]; + mySplitter = String.valueOf(new char[] { '"', delimiter, '"' }); + } + + @Override + public String get(final int column) { + return line.substring(myIndices[column] + 3, myIndices[column + 1]); + } + + @Override + boolean index(final String line, final BufferedReader reader) { + + int tmpIndex = 0; + int tmpPosition = -2; + myIndices[tmpIndex] = tmpPosition; + + while ((tmpPosition = line.indexOf(mySplitter, ++tmpPosition)) >= 0) { + myIndices[++tmpIndex] = tmpPosition; + } + + tmpPosition = line.length() - 1; + myIndices[++tmpIndex] = tmpPosition; + + this.line = line; + + return tmpIndex == numberOfColumns; + } + + } + + static class RFC4180 extends LineView { + + private static final char QUOTE = '"'; + + private final int[] myBegin; + private final int[] myEnd; + private boolean myEscaped; + + RFC4180(final int numberOfColumns, final char delimiter) { + + super(numberOfColumns, delimiter); + + myBegin = new int[numberOfColumns]; + myEnd = new int[numberOfColumns]; + } + + @Override + public String get(final int column) { + if (myEscaped) { + return line.substring(myBegin[column], myEnd[column]).replace("\"\"", "\""); + } else { + return line.substring(myBegin[column], myEnd[column]); + } + } + + @Override + boolean index(final String line, final BufferedReader reader) { + + myEscaped = false; + + String tmpLine = line; + + int c = 0; + myBegin[0] = 0; + int tmpMode = 0; + int tmpNumberOfQuotes = 0; + + char tmpCurChar; + int tmpNextInd; + for (int i = 0; i < tmpLine.length(); i++) { + tmpCurChar = tmpLine.charAt(i); + tmpNextInd = i + 1; + + switch (tmpMode) { + + case 1: // Within quotes - look for the end of the quote + + if (tmpCurChar == QUOTE) { + tmpNumberOfQuotes++; + if (((tmpNumberOfQuotes % 2) == 0) && ((tmpNextInd == tmpLine.length()) || (tmpLine.charAt(tmpNextInd) != QUOTE))) { + myEnd[c++] = i; + tmpMode = 2; + } else { + myEscaped = true; + } + } else if (tmpNextInd == tmpLine.length()) { + try { + tmpLine = tmpLine + '\n' + reader.readLine(); + } catch (final IOException exception) { + exception.printStackTrace(); + return false; + } + } + + break; + + case 2: // Quote ended but not yet found next delimiter + + if (tmpCurChar == delimiter) { + myBegin[c] = tmpNextInd; + if (tmpNextInd == tmpLine.length()) { + myEnd[c++] = tmpNextInd; + } + tmpMode = 0; + } else if (tmpNextInd == tmpLine.length()) { + myEnd[c++] = tmpNextInd; + } + + break; + + default: // Not quoted + + if (tmpCurChar == QUOTE) { + tmpNumberOfQuotes++; + myBegin[c] = tmpNextInd; + tmpMode = 1; + } else if (tmpCurChar == delimiter) { + myEnd[c++] = i; + myBegin[c] = tmpNextInd; + if (tmpNextInd == tmpLine.length()) { + myEnd[c++] = tmpNextInd; + } + } else if (tmpNextInd == tmpLine.length()) { + myEnd[c++] = tmpNextInd; + } + + break; + } + } + + this.line = tmpLine; + + return numberOfColumns == c; + } + + } + + public static EnumeratedColumnsParser.Builder make(final Class> columns) { + return new EnumeratedColumnsParser.Builder(columns.getFields().length); + } + + public static EnumeratedColumnsParser.Builder make(final int numberOfColumns) { + return new EnumeratedColumnsParser.Builder(numberOfColumns); + } + + private final LineView myLineView; + + EnumeratedColumnsParser(final int columns, final char delimiter, final ParseStrategy strategy) { + + super(); + + myLineView = strategy.make(columns, delimiter); + } + + @Override + LineView parse(final String line, final BufferedReader reader) { + + if (myLineView.index(line, reader)) { + return myLineView; + } else { + return null; + } + } + +} diff --git a/test/org/ojalgo/function/constant/PrimitiveMathTest.java b/test/org/ojalgo/function/constant/PrimitiveMathTest.java index f5ae4ba6b..9b9d89919 100644 --- a/test/org/ojalgo/function/constant/PrimitiveMathTest.java +++ b/test/org/ojalgo/function/constant/PrimitiveMathTest.java @@ -146,22 +146,6 @@ public void testPOWER() { TestUtils.assertEquals(1 / E, POWER.invoke(E, -1), MACHINE_EPSILON); } - @Test - public void testPowersOf2() { - - long previous = POWERS_OF_2[0]; - TestUtils.assertEquals(1L, previous); - - for (int i = 1; i < POWERS_OF_2.length; i++) { - final long current = POWERS_OF_2[i]; - - TestUtils.assertTrue(previous < current); - TestUtils.assertEquals(2, current / previous); - - previous = current; - } - } - @Test public void testPrefixes() { diff --git a/test/org/ojalgo/function/special/PowerOf2Test.java b/test/org/ojalgo/function/special/PowerOf2Test.java new file mode 100644 index 000000000..a0cea1eca --- /dev/null +++ b/test/org/ojalgo/function/special/PowerOf2Test.java @@ -0,0 +1,61 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; +import org.ojalgo.function.special.PowerOf2.IntPower; +import org.ojalgo.function.special.PowerOf2.LongPower; + +public class PowerOf2Test { + + @Test + public void testPowerOfInt2() { + + int value = 1; + TestUtils.assertEquals(value, PowerOf2.powerOfInt2(0)); + for (int i = 1; i < 31; i++) { + value *= 2; + TestUtils.assertEquals(value, PowerOf2.powerOfInt2(i)); + TestUtils.assertEquals(PowerOf2.exponent(value), PowerOf2.find(value)); + IntPower power = PowerOf2.getIntPower(i); + TestUtils.assertEquals(1, power.divide(value)); + TestUtils.assertEquals(0, power.modulo(value)); + } + } + + @Test + public void testPowerOfLong2() { + + long value = 1L; + TestUtils.assertEquals(value, PowerOf2.powerOfLong2(0)); + for (int i = 1; i < 63; i++) { + value *= 2L; + TestUtils.assertEquals(value, PowerOf2.powerOfLong2(i)); + TestUtils.assertEquals(PowerOf2.exponent(value), PowerOf2.find(value)); + LongPower power = PowerOf2.getLongPower(i); + TestUtils.assertEquals(1L, power.divide(value)); + TestUtils.assertEquals(0L, power.modulo(value)); + } + } + +} From 25839cbad5e96c08d874c7b6bc76d0e94a7d42c1 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Sun, 22 Sep 2019 22:26:58 +0200 Subject: [PATCH 08/29] Sparse tests (#225) * Create SparseTest.java --- src/org/ojalgo/array/SparseArray.java | 14 +---- test/org/ojalgo/array/SparseTest.java | 84 +++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 test/org/ojalgo/array/SparseTest.java diff --git a/src/org/ojalgo/array/SparseArray.java b/src/org/ojalgo/array/SparseArray.java index db489f71a..94fa895e4 100644 --- a/src/org/ojalgo/array/SparseArray.java +++ b/src/org/ojalgo/array/SparseArray.java @@ -211,7 +211,7 @@ public SparseArray make(final long count) { } - static final NumberContext MATH_CONTEXT = NumberContext.getMath(MathContext.DECIMAL64); + private static final NumberContext MATH_CONTEXT = NumberContext.getMath(MathContext.DECIMAL64); public static SparseFactory factory(final DenseArray.Factory denseFactory) { return new SparseFactory<>(denseFactory); @@ -285,7 +285,6 @@ public long countZeros() { return myCount - myActualLength; } - @Override public double dot(final Access1D vector) { double retVal = PrimitiveMath.ZERO; @@ -297,8 +296,8 @@ public double dot(final Access1D vector) { return retVal; } - @Override public double doubleValue(final long index) { + final int tmpIndex = this.index(index); if (tmpIndex >= 0) { return this.doubleValueInternally(tmpIndex); @@ -307,7 +306,6 @@ public double doubleValue(final long index) { } } - @Override public void fillAll(final N value) { if (PrimitiveScalar.isSmall(PrimitiveMath.ONE, value.doubleValue())) { @@ -330,7 +328,6 @@ public void fillAll(final N value) { } } - @Override public void fillAll(final NullaryFunction supplier) { // Bad idea... @@ -362,12 +359,10 @@ public void fillOne(final long index, final NullaryFunction supplier) { this.set(index, supplier.get()); } - @Override public void fillRange(final long first, final long limit, final N value) { this.fill(first, limit, 1L, value); } - @Override public void fillRange(final long first, final long limit, final NullaryFunction supplier) { this.fill(first, limit, 1L, supplier); } @@ -384,8 +379,8 @@ public long firstInRange(final long rangeFirst, final long rangeLimit) { } } - @Override public N get(final long index) { + final int tmpIndex = this.index(index); if (tmpIndex >= 0) { return this.getInternally(tmpIndex); @@ -447,13 +442,11 @@ public NonzeroView nonzeros() { return new NonzeroView<>(myIndices, myValues, myActualLength); } - @Override public void reset() { myActualLength = 0; myValues.reset(); } - @Override public void set(final long index, final double value) { final int internalIndex = this.index(index); @@ -461,7 +454,6 @@ public void set(final long index, final double value) { this.update(index, internalIndex, value, false); } - @Override public void set(final long index, final Number value) { final int internalIndex = this.index(index); diff --git a/test/org/ojalgo/array/SparseTest.java b/test/org/ojalgo/array/SparseTest.java new file mode 100644 index 000000000..e13adaf76 --- /dev/null +++ b/test/org/ojalgo/array/SparseTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; +import org.ojalgo.function.aggregator.Aggregator; +import org.ojalgo.random.Uniform; + +public class SparseTest extends ArrayTests { + + @Test + @Tag("slow") + @Tag("unstable") + public void testRandomAccess() { + + long dim = 100_000L; + + SparseArray array = SparseArray.factory(Primitive64Array.FACTORY).make(dim * dim); + + for (long i = 0L; i < dim; i++) { + array.set(Uniform.randomInteger(dim * dim), 1.0); + } + + double sumOfAll = 0D; + for (long i = 0L, limit = array.count(); i < limit; i++) { + sumOfAll += array.doubleValue(i); + } + + // There is of course a chanse the same random index was generated more + // than once (when setting the values). In that case the test will fail. + TestUtils.assertEquals(dim, sumOfAll); + } + + @Test + public void testAggregateSumDifferentWays() { + + long dim = 1000L; + long dim2 = dim * dim; + + SparseArray plain = SparseArray.factory(Primitive64Array.FACTORY).make(dim2); + Array1D array1D = Array1D.PRIMITIVE64.make(dim2); + Array2D array2D = Array2D.PRIMITIVE64.make(dim, dim); + + for (int i = 0; i < 100; i++) { + long index = Uniform.randomInteger(dim2); + plain.set(index, 1.0); + array1D.set(index, 1.0); + array2D.set(index, 1.0); + } + + double expected = plain.nonzeros().stream().mapToDouble(nz -> nz.doubleValue()).sum(); + + double stream1D = array1D.nonzeros().stream().mapToDouble(nz -> nz.doubleValue()).sum(); + double stream2D = array2D.nonzeros().stream().mapToDouble(nz -> nz.doubleValue()).sum(); + + TestUtils.assertEquals(expected, stream1D); + TestUtils.assertEquals(expected, stream2D); + + TestUtils.assertEquals(expected, array1D.aggregateAll(Aggregator.SUM).doubleValue()); + TestUtils.assertEquals(expected, array2D.aggregateAll(Aggregator.SUM).doubleValue()); + } + +} From 4542ca754bcef3fae8458b981d09ce9c460e64a1 Mon Sep 17 00:00:00 2001 From: apete Date: Sat, 28 Sep 2019 12:03:51 +0200 Subject: [PATCH 09/29] Deprecated FunctionUtils --- src/org/ojalgo/array/Primitive32Array.java | 10 +- src/org/ojalgo/array/Primitive64Array.java | 10 +- src/org/ojalgo/array/ReferenceTypeArray.java | 10 +- src/org/ojalgo/function/FunctionUtils.java | 209 +++++++++++++----- src/org/ojalgo/function/UnaryFunction.java | 6 + .../ojalgo/function/special/MissingMath.java | 152 +++++++++++++ .../matrix/store/GenericDenseStore.java | 22 +- .../matrix/store/PrimitiveDenseStore.java | 22 +- .../ojalgo/matrix/task/AbstractInverter.java | 18 +- .../ojalgo/matrix/task/AbstractSolver.java | 18 +- src/org/ojalgo/structure/Mutate1D.java | 9 +- src/org/ojalgo/structure/MutateAnyD.java | 4 +- .../function/constant/PrimitiveMathTest.java | 30 --- .../function/special/MissingMathTest.java | 43 ++++ test/org/ojalgo/matrix/MatrixUtilsTest.java | 45 ---- 15 files changed, 394 insertions(+), 214 deletions(-) delete mode 100644 test/org/ojalgo/matrix/MatrixUtilsTest.java diff --git a/src/org/ojalgo/array/Primitive32Array.java b/src/org/ojalgo/array/Primitive32Array.java index 7092b2100..17dd4a2dc 100644 --- a/src/org/ojalgo/array/Primitive32Array.java +++ b/src/org/ojalgo/array/Primitive32Array.java @@ -32,7 +32,6 @@ import org.ojalgo.function.BinaryFunction.FixedFirst; import org.ojalgo.function.BinaryFunction.FixedSecond; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.ParameterFunction.FixedParameter; @@ -42,6 +41,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.scalar.Scalar; @@ -396,13 +396,13 @@ public void fillMatching(final Access1D values) { } public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), left.count(), right.count()); - Primitive32Array.invoke(data, 0, tmpLimit, 1, left, function, right); + int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); + Primitive32Array.invoke(data, 0, limit, 1, left, function, right); } public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), arguments.count()); - Primitive32Array.invoke(data, 0, tmpLimit, 1, arguments, function); + int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); + Primitive32Array.invoke(data, 0, limit, 1, arguments, function); } @Override diff --git a/src/org/ojalgo/array/Primitive64Array.java b/src/org/ojalgo/array/Primitive64Array.java index 282f90f66..f02e26eff 100644 --- a/src/org/ojalgo/array/Primitive64Array.java +++ b/src/org/ojalgo/array/Primitive64Array.java @@ -36,7 +36,6 @@ import org.ojalgo.function.BinaryFunction.FixedFirst; import org.ojalgo.function.BinaryFunction.FixedSecond; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.ParameterFunction.FixedParameter; @@ -46,6 +45,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.scalar.Scalar; @@ -400,13 +400,13 @@ public void fillMatching(final Access1D values) { } public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), left.count(), right.count()); - Primitive64Array.invoke(data, 0, tmpLimit, 1, left, function, right); + int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); + Primitive64Array.invoke(data, 0, limit, 1, left, function, right); } public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), arguments.count()); - Primitive64Array.invoke(data, 0, tmpLimit, 1, arguments, function); + int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); + Primitive64Array.invoke(data, 0, limit, 1, arguments, function); } @Override diff --git a/src/org/ojalgo/array/ReferenceTypeArray.java b/src/org/ojalgo/array/ReferenceTypeArray.java index 4e9359da0..b1b6dc02d 100644 --- a/src/org/ojalgo/array/ReferenceTypeArray.java +++ b/src/org/ojalgo/array/ReferenceTypeArray.java @@ -27,12 +27,12 @@ import org.ojalgo.array.operation.COPY; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; @@ -148,15 +148,15 @@ public void fillMatching(final Access1D values) { } public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), left.count(), right.count()); - for (int i = 0; i < tmpLimit; i++) { + int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); + for (int i = 0; i < limit; i++) { data[i] = function.invoke(left.get(i), right.get(i)); } } public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), arguments.count()); - for (int i = 0; i < tmpLimit; i++) { + int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); + for (int i = 0; i < limit; i++) { data[i] = function.invoke(arguments.get(i)); } } diff --git a/src/org/ojalgo/function/FunctionUtils.java b/src/org/ojalgo/function/FunctionUtils.java index 4d81fdd1f..d2efa01a7 100644 --- a/src/org/ojalgo/function/FunctionUtils.java +++ b/src/org/ojalgo/function/FunctionUtils.java @@ -21,153 +21,244 @@ */ package org.ojalgo.function; -import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.scalar.PrimitiveScalar; +import org.ojalgo.function.special.MissingMath; +/** + * @deprecated v48 + */ +@Deprecated public abstract class FunctionUtils { + /** + * @deprecated v48 Use {@link UnaryFunction#isZeroModified(UnaryFunction)} instead + */ + @Deprecated public static boolean isZeroModified(final UnaryFunction function) { - return !PrimitiveScalar.isSmall(PrimitiveMath.ONE, function.invoke(PrimitiveMath.ZERO)); + return UnaryFunction.isZeroModified(function); } + /** + * @deprecated v48 Use {@link MissingMath#max(double...)} instead + */ + @Deprecated public static double max(final double... values) { - double retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.max(values); } + /** + * @deprecated v48 Use {@link MissingMath#max(double,double)} instead + */ + @Deprecated public static double max(final double a, final double b) { - return Math.max(a, b); + return MissingMath.max(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#max(double,double,double)} instead + */ + @Deprecated public static double max(final double a, final double b, final double c) { - return Math.max(Math.max(a, b), c); + return MissingMath.max(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#max(double,double,double,double)} instead + */ + @Deprecated public static double max(final double a, final double b, final double c, final double d) { - return Math.max(Math.max(a, b), Math.max(c, d)); + return MissingMath.max(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#max(int...)} instead + */ + @Deprecated public static int max(final int... values) { - int retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.max(values); } + /** + * @deprecated v48 Use {@link MissingMath#max(int,int)} instead + */ + @Deprecated public static int max(final int a, final int b) { - return Math.max(a, b); + return MissingMath.max(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#max(int,int,int)} instead + */ + @Deprecated public static int max(final int a, final int b, final int c) { - return Math.max(Math.max(a, b), c); + return MissingMath.max(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#max(int,int,int,int)} instead + */ + @Deprecated public static int max(final int a, final int b, final int c, final int d) { - return Math.max(Math.max(a, b), Math.max(c, d)); + return MissingMath.max(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#max(long...)} instead + */ + @Deprecated public static long max(final long... values) { - long retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.max(values); } + /** + * @deprecated v48 Use {@link MissingMath#max(long,long)} instead + */ + @Deprecated public static long max(final long a, final long b) { - return Math.max(a, b); + return MissingMath.max(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#max(long,long,long)} instead + */ + @Deprecated public static long max(final long a, final long b, final long c) { - return Math.max(Math.max(a, b), c); + return MissingMath.max(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#max(long,long,long,long)} instead + */ + @Deprecated public static long max(final long a, final long b, final long c, final long d) { - return Math.max(Math.max(a, b), Math.max(c, d)); + return MissingMath.max(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#min(double...)} instead + */ + @Deprecated public static double min(final double... values) { - double retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] < retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.min(values); } + /** + * @deprecated v48 Use {@link MissingMath#min(double,double)} instead + */ + @Deprecated public static double min(final double a, final double b) { - return Math.min(a, b); + return MissingMath.min(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#min(double,double,double)} instead + */ + @Deprecated public static double min(final double a, final double b, final double c) { - return Math.min(Math.min(a, b), c); + return MissingMath.min(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#min(double,double,double,double)} instead + */ + @Deprecated public static double min(final double a, final double b, final double c, final double d) { - return Math.min(Math.min(a, b), Math.min(c, d)); + return MissingMath.min(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#min(int...)} instead + */ + @Deprecated public static int min(final int... values) { - int retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] < retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.min(values); } + /** + * @deprecated v48 Use {@link MissingMath#min(int,int)} instead + */ + @Deprecated public static int min(final int a, final int b) { - return Math.min(a, b); + return MissingMath.min(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#min(int,int,int)} instead + */ + @Deprecated public static int min(final int a, final int b, final int c) { - return Math.min(Math.min(a, b), c); + return MissingMath.min(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#min(int,int,int,int)} instead + */ + @Deprecated public static int min(final int a, final int b, final int c, final int d) { - return Math.min(Math.min(a, b), Math.min(c, d)); + return MissingMath.min(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#min(long...)} instead + */ + @Deprecated public static long min(final long... values) { - long retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] < retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.min(values); } + /** + * @deprecated v48 Use {@link MissingMath#min(long,long)} instead + */ + @Deprecated public static long min(final long a, final long b) { - return Math.min(a, b); + return MissingMath.min(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#min(long,long,long)} instead + */ + @Deprecated public static long min(final long a, final long b, final long c) { - return Math.min(Math.min(a, b), c); + return MissingMath.min(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#min(long,long,long,long)} instead + */ + @Deprecated public static long min(final long a, final long b, final long c, final long d) { - return Math.min(Math.min(a, b), Math.min(c, d)); + return MissingMath.min(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double...)} instead + */ + @Deprecated public static double norm(final double... values) { - double retVal = Math.abs(values[0]); - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? Math.abs(values[i]) : retVal; - } - return retVal; + return MissingMath.norm(values); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double,double)} instead + */ + @Deprecated public static double norm(final double a, final double b) { - return Math.max(Math.abs(a), Math.abs(b)); + return MissingMath.norm(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double,double,double)} instead + */ + @Deprecated public static double norm(final double a, final double b, final double c) { - return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.abs(c)); + return MissingMath.norm(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double,double,double,double)} instead + */ + @Deprecated public static double norm(final double a, final double b, final double c, final double d) { - return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.max(Math.abs(c), Math.abs(d))); + return MissingMath.norm(a, b, c, d); } private FunctionUtils() { diff --git a/src/org/ojalgo/function/UnaryFunction.java b/src/org/ojalgo/function/UnaryFunction.java index 48be43c08..0ffb8fe27 100644 --- a/src/org/ojalgo/function/UnaryFunction.java +++ b/src/org/ojalgo/function/UnaryFunction.java @@ -25,9 +25,15 @@ import java.util.function.UnaryOperator; import org.ojalgo.ProgrammingError; +import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.scalar.PrimitiveScalar; public interface UnaryFunction extends BasicFunction, UnaryOperator, DoubleUnaryOperator { + static boolean isZeroModified(final UnaryFunction function) { + return !PrimitiveScalar.isSmall(PrimitiveMath.ONE, function.invoke(PrimitiveMath.ZERO)); + } + default UnaryFunction andThen(final UnaryFunction after) { ProgrammingError.throwIfNull(after); return new UnaryFunction() { diff --git a/src/org/ojalgo/function/special/MissingMath.java b/src/org/ojalgo/function/special/MissingMath.java index 791be96ec..be00c5814 100644 --- a/src/org/ojalgo/function/special/MissingMath.java +++ b/src/org/ojalgo/function/special/MissingMath.java @@ -131,6 +131,146 @@ public static double logit(final double arg) { return Math.log(1.0 / (1.0 - arg)); } + public static double max(final double... values) { + double retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? values[i] : retVal; + } + return retVal; + } + + public static double max(final double a, final double b) { + return Math.max(a, b); + } + + public static double max(final double a, final double b, final double c) { + return Math.max(Math.max(a, b), c); + } + + public static double max(final double a, final double b, final double c, final double d) { + return Math.max(Math.max(a, b), Math.max(c, d)); + } + + public static int max(final int... values) { + int retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? values[i] : retVal; + } + return retVal; + } + + public static int max(final int a, final int b) { + return Math.max(a, b); + } + + public static int max(final int a, final int b, final int c) { + return Math.max(Math.max(a, b), c); + } + + public static int max(final int a, final int b, final int c, final int d) { + return Math.max(Math.max(a, b), Math.max(c, d)); + } + + public static long max(final long... values) { + long retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? values[i] : retVal; + } + return retVal; + } + + public static long max(final long a, final long b) { + return Math.max(a, b); + } + + public static long max(final long a, final long b, final long c) { + return Math.max(Math.max(a, b), c); + } + + public static long max(final long a, final long b, final long c, final long d) { + return Math.max(Math.max(a, b), Math.max(c, d)); + } + + public static double min(final double... values) { + double retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] < retVal ? values[i] : retVal; + } + return retVal; + } + + public static double min(final double a, final double b) { + return Math.min(a, b); + } + + public static double min(final double a, final double b, final double c) { + return Math.min(Math.min(a, b), c); + } + + public static double min(final double a, final double b, final double c, final double d) { + return Math.min(Math.min(a, b), Math.min(c, d)); + } + + public static int min(final int... values) { + int retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] < retVal ? values[i] : retVal; + } + return retVal; + } + + public static int min(final int a, final int b) { + return Math.min(a, b); + } + + public static int min(final int a, final int b, final int c) { + return Math.min(Math.min(a, b), c); + } + + public static int min(final int a, final int b, final int c, final int d) { + return Math.min(Math.min(a, b), Math.min(c, d)); + } + + public static long min(final long... values) { + long retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] < retVal ? values[i] : retVal; + } + return retVal; + } + + public static long min(final long a, final long b) { + return Math.min(a, b); + } + + public static long min(final long a, final long b, final long c) { + return Math.min(Math.min(a, b), c); + } + + public static long min(final long a, final long b, final long c, final long d) { + return Math.min(Math.min(a, b), Math.min(c, d)); + } + + public static double norm(final double... values) { + double retVal = Math.abs(values[0]); + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? Math.abs(values[i]) : retVal; + } + return retVal; + } + + public static double norm(final double a, final double b) { + return Math.max(Math.abs(a), Math.abs(b)); + } + + public static double norm(final double a, final double b, final double c) { + return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.abs(c)); + } + + public static double norm(final double a, final double b, final double c, final double d) { + return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.max(Math.abs(c), Math.abs(d))); + } + public static BigDecimal pow(final BigDecimal arg1, final BigDecimal arg2) { if (arg2.signum() == 0) { return BigDecimal.ONE; @@ -284,8 +424,20 @@ public static double sqrt1px2(final double arg) { return Math.sqrt(1.0 + (arg * arg)); } + public static int toMinIntExact(final long... values) { + return Math.toIntExact(MissingMath.min(values)); + } + public static int toMinIntExact(final long a, final long b) { return Math.toIntExact(Math.min(a, b)); } + public static int toMinIntExact(final long a, final long b, final long c) { + return Math.toIntExact(MissingMath.min(a, b, c)); + } + + public static int toMinIntExact(final long a, final long b, final long c, final long d) { + return Math.toIntExact(MissingMath.min(a, b, c, d)); + } + } diff --git a/src/org/ojalgo/matrix/store/GenericDenseStore.java b/src/org/ojalgo/matrix/store/GenericDenseStore.java index 445b15945..a9d0395bb 100644 --- a/src/org/ojalgo/matrix/store/GenericDenseStore.java +++ b/src/org/ojalgo/matrix/store/GenericDenseStore.java @@ -30,11 +30,11 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.aggregator.AggregatorSet; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.MatrixUtils; import org.ojalgo.matrix.decomposition.DecompositionStore; import org.ojalgo.matrix.store.DiagonalStore.Builder; @@ -744,7 +744,7 @@ public void conquer(final int first, final int limit) { @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int matchingCount = (int) FunctionUtils.min(this.count(), left.count(), right.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); if (myColDim > FillMatchingDual.THRESHOLD) { @@ -768,7 +768,7 @@ protected void conquer(final int first, final int limit) { @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int matchingCount = (int) FunctionUtils.min(this.count(), arguments.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), arguments.count()); if (myColDim > FillMatchingSingle.THRESHOLD) { @@ -895,22 +895,6 @@ public void modifyDiagonal(final long row, final long col, final UnaryFunction left, final BinaryFunction function) { - final long tmpLimit = FunctionUtils.min(left.count(), this.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.fillOne(i, function.invoke(left.get(i), this.get(i))); - } - } - - @Override - public void modifyMatching(final BinaryFunction function, final Access1D right) { - final long tmpLimit = FunctionUtils.min(this.count(), right.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.fillOne(i, function.invoke(this.get(i), right.get(i))); - } - } - public void modifyOne(final long row, final long col, final UnaryFunction modifier) { N tmpValue = this.get(row, col); diff --git a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java b/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java index bfae73d29..5fd315c2b 100644 --- a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java +++ b/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java @@ -37,7 +37,6 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; @@ -45,6 +44,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.machine.MemoryEstimator; import org.ojalgo.matrix.MatrixUtils; @@ -798,7 +798,7 @@ public void conquer(final int first, final int limit) { @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int matchingCount = (int) FunctionUtils.min(this.count(), left.count(), right.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); if (myColDim > FillMatchingDual.THRESHOLD) { @@ -822,7 +822,7 @@ protected void conquer(final int first, final int limit) { @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int matchingCount = (int) FunctionUtils.min(this.count(), arguments.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), arguments.count()); if (myColDim > FillMatchingSingle.THRESHOLD) { @@ -949,22 +949,6 @@ public void modifyDiagonal(final long row, final long col, final UnaryFunction left, final BinaryFunction function) { - final long tmpLimit = FunctionUtils.min(left.count(), this.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.set(i, function.invoke(left.doubleValue(i), this.doubleValue(i))); - } - } - - @Override - public void modifyMatching(final BinaryFunction function, final Access1D right) { - final long tmpLimit = FunctionUtils.min(this.count(), right.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.set(i, function.invoke(this.doubleValue(i), right.doubleValue(i))); - } - } - public void modifyOne(final long row, final long col, final UnaryFunction modifier) { double tmpValue = this.doubleValue(row, col); diff --git a/src/org/ojalgo/matrix/task/AbstractInverter.java b/src/org/ojalgo/matrix/task/AbstractInverter.java index 92dbc4303..4a8970510 100644 --- a/src/org/ojalgo/matrix/task/AbstractInverter.java +++ b/src/org/ojalgo/matrix/task/AbstractInverter.java @@ -24,7 +24,7 @@ import static org.ojalgo.function.constant.PrimitiveMath.*; import org.ojalgo.RecoverableCondition; -import org.ojalgo.function.FunctionUtils; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PrimitiveDenseStore; @@ -171,7 +171,7 @@ static void full2X2(final Access2D source, final PhysicalStore destination double tmp01 = source.doubleValue(2L); double tmp11 = source.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp10, tmp11); + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp10, tmp11); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -202,7 +202,7 @@ static void full3X3(final Access2D source, final PhysicalStore destination double tmp12 = source.doubleValue(7L); double tmp22 = source.doubleValue(8L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp02, tmp10, tmp11, tmp12, tmp20, tmp21, tmp22); + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp10, tmp11, tmp12, tmp20, tmp21, tmp22); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -265,7 +265,7 @@ static void full4X4(final Access2D source, final PhysicalStore destination double tmp23 = source.doubleValue(14L); double tmp33 = source.doubleValue(15L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp02, tmp03, tmp10, tmp11, tmp12, tmp13, tmp20, tmp21, tmp22, tmp23, tmp30, tmp31, tmp32, + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp03, tmp10, tmp11, tmp12, tmp13, tmp20, tmp21, tmp22, tmp23, tmp30, tmp31, tmp32, tmp33); tmp00 /= tmpScale; @@ -363,7 +363,7 @@ static void full5X5(final Access2D source, final PhysicalStore destination double tmp34 = source.doubleValue(23L); double tmp44 = source.doubleValue(24L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp02, tmp03, tmp04, tmp10, tmp11, tmp12, tmp13, tmp14, tmp20, tmp21, tmp22, tmp23, tmp24, + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp03, tmp04, tmp10, tmp11, tmp12, tmp13, tmp14, tmp20, tmp21, tmp22, tmp23, tmp24, tmp30, tmp31, tmp32, tmp33, tmp34, tmp40, tmp41, tmp42, tmp43, tmp44); tmp00 /= tmpScale; @@ -491,7 +491,7 @@ static void symmetric2X2(final Access2D source, final PhysicalStore destin double tmp11 = source.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -518,7 +518,7 @@ static void symmetric3X3(final Access2D source, final PhysicalStore destin double tmp22 = source.doubleValue(8L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -569,7 +569,7 @@ static void symmetric4X4(final Access2D source, final PhysicalStore destin double tmp33 = source.doubleValue(15L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -644,7 +644,7 @@ static void symmetric5X5(final Access2D source, final PhysicalStore destin double tmp44 = source.doubleValue(24L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33, tmp40, tmp41, tmp42, tmp43, tmp44); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33, tmp40, tmp41, tmp42, tmp43, tmp44); tmp00 /= tmpScale; tmp10 /= tmpScale; diff --git a/src/org/ojalgo/matrix/task/AbstractSolver.java b/src/org/ojalgo/matrix/task/AbstractSolver.java index 2251f8376..b86fa3b7f 100644 --- a/src/org/ojalgo/matrix/task/AbstractSolver.java +++ b/src/org/ojalgo/matrix/task/AbstractSolver.java @@ -22,7 +22,7 @@ package org.ojalgo.matrix.task; import org.ojalgo.RecoverableCondition; -import org.ojalgo.function.FunctionUtils; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PrimitiveDenseStore; @@ -137,7 +137,7 @@ static void full2X2(final Access2D body, final Access1D rhs, final Physica double tmp0 = rhs.doubleValue(0L); double tmp1 = rhs.doubleValue(1L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1); + final double tmpScale = MissingMath.norm(tmp0, tmp1); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -172,7 +172,7 @@ static void full3X3(final Access2D body, final Access1D rhs, final Physica double tmp1 = rhs.doubleValue(1L); double tmp2 = rhs.doubleValue(2L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -236,7 +236,7 @@ static void full4X4(final Access2D body, final Access1D rhs, final Physica double tmp2 = rhs.doubleValue(2L); double tmp3 = rhs.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -329,7 +329,7 @@ static void full5X5(final Access2D body, final Access1D rhs, final Physica double tmp3 = rhs.doubleValue(3L); double tmp4 = rhs.doubleValue(4L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3, tmp4); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3, tmp4); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -475,7 +475,7 @@ static void symmetric2X2(final Access2D body, final Access1D rhs, final Ph double tmp0 = rhs.doubleValue(0L); double tmp1 = rhs.doubleValue(1L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1); + final double tmpScale = MissingMath.norm(tmp0, tmp1); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -506,7 +506,7 @@ static void symmetric3X3(final Access2D body, final Access1D rhs, final Ph double tmp1 = rhs.doubleValue(1L); double tmp2 = rhs.doubleValue(2L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -558,7 +558,7 @@ static void symmetric4X4(final Access2D body, final Access1D rhs, final Ph double tmp2 = rhs.doubleValue(2L); double tmp3 = rhs.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -629,7 +629,7 @@ static void symmetric5X5(final Access2D body, final Access1D rhs, final Ph double tmp3 = rhs.doubleValue(3L); double tmp4 = rhs.doubleValue(4L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3, tmp4); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3, tmp4); tmp00 /= tmpScale; tmp10 /= tmpScale; diff --git a/src/org/ojalgo/structure/Mutate1D.java b/src/org/ojalgo/structure/Mutate1D.java index e0c7b7519..195343b39 100644 --- a/src/org/ojalgo/structure/Mutate1D.java +++ b/src/org/ojalgo/structure/Mutate1D.java @@ -25,7 +25,6 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.constant.PrimitiveMath; @@ -112,15 +111,11 @@ default void modifyAll(final UnaryFunction modifier) { } default void modifyMatching(final Access1D left, final BinaryFunction function) { - for (long i = 0L, limit = FunctionUtils.min(left.count(), this.count()); i < limit; i++) { - this.modifyOne(i, function.first(left.get(i))); - } + Structure1D.loopMatching(left, this, i -> this.modifyOne(i, function.first(left.get(i)))); } default void modifyMatching(final BinaryFunction function, final Access1D right) { - for (long i = 0L, limit = FunctionUtils.min(this.count(), right.count()); i < limit; i++) { - this.modifyOne(i, function.second(right.get(i))); - } + Structure1D.loopMatching(this, right, i -> this.modifyOne(i, function.second(right.get(i)))); } void modifyOne(long index, UnaryFunction modifier); diff --git a/src/org/ojalgo/structure/MutateAnyD.java b/src/org/ojalgo/structure/MutateAnyD.java index 66deed71b..37b8f5a7b 100644 --- a/src/org/ojalgo/structure/MutateAnyD.java +++ b/src/org/ojalgo/structure/MutateAnyD.java @@ -25,9 +25,9 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; +import org.ojalgo.function.special.MissingMath; /** * N-dimensional mutator methods @@ -103,7 +103,7 @@ default boolean isAcceptable(final StructureAnyD supplier) { boolean retVal = true; - int tmpRank = FunctionUtils.max(this.shape().length, this.shape().length); + int tmpRank = MissingMath.max(this.shape().length, this.shape().length); for (int i = 0; i < tmpRank; i++) { retVal &= this.count(i) >= supplier.count(i); diff --git a/test/org/ojalgo/function/constant/PrimitiveMathTest.java b/test/org/ojalgo/function/constant/PrimitiveMathTest.java index 9b9d89919..c53b7d4b3 100644 --- a/test/org/ojalgo/function/constant/PrimitiveMathTest.java +++ b/test/org/ojalgo/function/constant/PrimitiveMathTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.constant.PrimitiveMath.Prefix; import org.ojalgo.type.context.NumberContext; @@ -97,35 +96,6 @@ public void testHYPOT() { } - @Test - public void testMinMax() { - - TestUtils.assertEquals(Math.min(2, -78), FunctionUtils.min(2, -78)); - TestUtils.assertEquals(MAX.invoke(2, -78), FunctionUtils.max(2, -78)); - - TestUtils.assertEquals(67, FunctionUtils.max(new int[] { 67 })); - TestUtils.assertEquals(67, FunctionUtils.min(new int[] { 67 })); - - TestUtils.assertEquals(FunctionUtils.max(67, -76), FunctionUtils.max(new int[] { 67, -76 })); - TestUtils.assertEquals(FunctionUtils.min(67, -76), FunctionUtils.min(new int[] { 67, -76 })); - - TestUtils.assertEquals(FunctionUtils.max(0, 67, -76), FunctionUtils.max(new int[] { 0, 67, -76 })); - TestUtils.assertEquals(FunctionUtils.min(0, 67, -76), FunctionUtils.min(new int[] { 0, 67, -76 })); - - TestUtils.assertEquals(FunctionUtils.max(0, 67, -76, 80), FunctionUtils.max(new int[] { 0, 67, -76, 80 })); - TestUtils.assertEquals(FunctionUtils.min(0, 67, -76, -80), FunctionUtils.min(new int[] { 0, 67, -76, -80 })); - - TestUtils.assertEquals(FunctionUtils.max(80, 0, 67, -76), FunctionUtils.max(new int[] { 80, 0, 67, -76 })); - TestUtils.assertEquals(FunctionUtils.min(-80, 0, 67, -76), FunctionUtils.min(new int[] { -80, 0, 67, -76 })); - - TestUtils.assertEquals(80, FunctionUtils.max(new int[] { 0, 67, -76, 80 })); - TestUtils.assertEquals(-80, FunctionUtils.min(new int[] { 0, 67, -76, -80 })); - - TestUtils.assertEquals(80, FunctionUtils.max(new int[] { 80, 0, 67, -76 })); - TestUtils.assertEquals(-80, FunctionUtils.min(new int[] { -80, 0, 67, -76 })); - - } - @Test public void testPOWER() { diff --git a/test/org/ojalgo/function/special/MissingMathTest.java b/test/org/ojalgo/function/special/MissingMathTest.java index 7eb77385d..47ab45db8 100644 --- a/test/org/ojalgo/function/special/MissingMathTest.java +++ b/test/org/ojalgo/function/special/MissingMathTest.java @@ -21,11 +21,54 @@ */ package org.ojalgo.function.special; +import static org.ojalgo.function.constant.PrimitiveMath.*; + import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; public class MissingMathTest { + @Test + public void testMax() { + TestUtils.assertEquals(9, MissingMath.max(9, 0, -9)); + TestUtils.assertEquals(9, MissingMath.max(-9, 0, 9)); + } + + @Test + public void testMin() { + TestUtils.assertEquals(-9, MissingMath.min(9, 0, -9)); + TestUtils.assertEquals(-9, MissingMath.min(-9, 0, 9)); + } + + @Test + public void testMinMax() { + + TestUtils.assertEquals(Math.min(2, -78), MissingMath.min(2, -78)); + TestUtils.assertEquals(MAX.invoke(2, -78), MissingMath.max(2, -78)); + + TestUtils.assertEquals(67, MissingMath.max(new int[] { 67 })); + TestUtils.assertEquals(67, MissingMath.min(new int[] { 67 })); + + TestUtils.assertEquals(MissingMath.max(67, -76), MissingMath.max(new int[] { 67, -76 })); + TestUtils.assertEquals(MissingMath.min(67, -76), MissingMath.min(new int[] { 67, -76 })); + + TestUtils.assertEquals(MissingMath.max(0, 67, -76), MissingMath.max(new int[] { 0, 67, -76 })); + TestUtils.assertEquals(MissingMath.min(0, 67, -76), MissingMath.min(new int[] { 0, 67, -76 })); + + TestUtils.assertEquals(MissingMath.max(0, 67, -76, 80), MissingMath.max(new int[] { 0, 67, -76, 80 })); + TestUtils.assertEquals(MissingMath.min(0, 67, -76, -80), MissingMath.min(new int[] { 0, 67, -76, -80 })); + + TestUtils.assertEquals(MissingMath.max(80, 0, 67, -76), MissingMath.max(new int[] { 80, 0, 67, -76 })); + TestUtils.assertEquals(MissingMath.min(-80, 0, 67, -76), MissingMath.min(new int[] { -80, 0, 67, -76 })); + + TestUtils.assertEquals(80, MissingMath.max(new int[] { 0, 67, -76, 80 })); + TestUtils.assertEquals(-80, MissingMath.min(new int[] { 0, 67, -76, -80 })); + + TestUtils.assertEquals(80, MissingMath.max(new int[] { 80, 0, 67, -76 })); + TestUtils.assertEquals(-80, MissingMath.min(new int[] { -80, 0, 67, -76 })); + + } + @Test public void testPower() { diff --git a/test/org/ojalgo/matrix/MatrixUtilsTest.java b/test/org/ojalgo/matrix/MatrixUtilsTest.java deleted file mode 100644 index 0d903e0a0..000000000 --- a/test/org/ojalgo/matrix/MatrixUtilsTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 1997-2019 Optimatika - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package org.ojalgo.matrix; - -import org.junit.jupiter.api.Test; -import org.ojalgo.TestUtils; -import org.ojalgo.function.FunctionUtils; - -/** - * @author apete - */ -public class MatrixUtilsTest extends MatrixTests { - - @Test - public void testMax() { - TestUtils.assertEquals(9, FunctionUtils.max(9, 0, -9)); - TestUtils.assertEquals(9, FunctionUtils.max(-9, 0, 9)); - } - - @Test - public void testMin() { - TestUtils.assertEquals(-9, FunctionUtils.min(9, 0, -9)); - TestUtils.assertEquals(-9, FunctionUtils.min(-9, 0, 9)); - } - -} From 4e3139c2fc68b98a823b9826d6d9b773bbb7b9eb Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 29 Sep 2019 10:00:30 +0200 Subject: [PATCH 10/29] PrimitiveNumber --- src/org/ojalgo/structure/AccessScalar.java | 11 ++---- src/org/ojalgo/type/PrimitiveNumber.java | 42 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/org/ojalgo/type/PrimitiveNumber.java diff --git a/src/org/ojalgo/structure/AccessScalar.java b/src/org/ojalgo/structure/AccessScalar.java index 929f717d2..6b0ac8898 100644 --- a/src/org/ojalgo/structure/AccessScalar.java +++ b/src/org/ojalgo/structure/AccessScalar.java @@ -21,7 +21,9 @@ */ package org.ojalgo.structure; -public interface AccessScalar { +import org.ojalgo.type.PrimitiveNumber; + +public interface AccessScalar extends PrimitiveNumber { /** * @see Number#byteValue() @@ -30,13 +32,6 @@ default byte byteValue() { return (byte) this.shortValue(); } - /** - * @see Number#doubleValue() - */ - default double doubleValue() { - return this.get().doubleValue(); - } - /** * @see Number#floatValue() */ diff --git a/src/org/ojalgo/type/PrimitiveNumber.java b/src/org/ojalgo/type/PrimitiveNumber.java new file mode 100644 index 000000000..b6de0860e --- /dev/null +++ b/src/org/ojalgo/type/PrimitiveNumber.java @@ -0,0 +1,42 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.type; + +/** + * An interface that defines what is in {@link java.lang.Number}. Hopefully Java itself will one day get an + * interface that does this. + */ +public interface PrimitiveNumber { + + byte byteValue(); + + double doubleValue(); + + float floatValue(); + + int intValue(); + + long longValue(); + + short shortValue(); + +} From 4b21d52a73525ff71451836b4ebe113d6c3ee09f Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 29 Sep 2019 15:27:31 +0200 Subject: [PATCH 11/29] Update PrimitiveNumber.java --- src/org/ojalgo/type/PrimitiveNumber.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/ojalgo/type/PrimitiveNumber.java b/src/org/ojalgo/type/PrimitiveNumber.java index b6de0860e..e5b086435 100644 --- a/src/org/ojalgo/type/PrimitiveNumber.java +++ b/src/org/ojalgo/type/PrimitiveNumber.java @@ -23,7 +23,8 @@ /** * An interface that defines what is in {@link java.lang.Number}. Hopefully Java itself will one day get an - * interface that does this. + * interface that does this. When/if that happens then this interface AND any/all usage of + * extends java.lang.Number will be replaced by that new interface. */ public interface PrimitiveNumber { From c9f9d591098279b54c611c096c98360d1d76c8cf Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 29 Sep 2019 15:50:41 +0200 Subject: [PATCH 12/29] Update CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23e9c3c33..79ac8c500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +Added / Changed / Deprecated / Removed / Fixed / Security + ## [Unreleased] > Corresponds to changes in the `develop` branch since the last release @@ -25,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### org.ojalgo.optimisation -- The iterative version of the ActiveSetSolver now enforce an iterations limit. +- The iterative version of the ActiveSetSolver now enforce an iterations limit on its internal subsolver. #### org.ojalgo.structure @@ -37,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The merge functionality of AggregatorFunction is deprecated. - Everything related to "power of 2" has been deprecetd in PrimitiveMath. +- FunctionUtils has been deprecated. Everything in it has been moved elsewhere – mostly to MissingMath. ### Removed From 8a9e9fa149c1cb3222a5acaf5acf1a4822a34916 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Sun, 29 Sep 2019 16:22:25 +0200 Subject: [PATCH 13/29] PrimitiveNumber (#226) * Deprecated FunctionUtils * PrimitiveNumber * Update PrimitiveNumber.java * Update CHANGELOG.md --- CHANGELOG.md | 5 +- src/org/ojalgo/array/Primitive32Array.java | 10 +- src/org/ojalgo/array/Primitive64Array.java | 10 +- src/org/ojalgo/array/ReferenceTypeArray.java | 10 +- src/org/ojalgo/function/FunctionUtils.java | 209 +++++++++++++----- src/org/ojalgo/function/UnaryFunction.java | 6 + .../ojalgo/function/special/MissingMath.java | 152 +++++++++++++ .../matrix/store/GenericDenseStore.java | 22 +- .../matrix/store/PrimitiveDenseStore.java | 22 +- .../ojalgo/matrix/task/AbstractInverter.java | 18 +- .../ojalgo/matrix/task/AbstractSolver.java | 18 +- src/org/ojalgo/structure/AccessScalar.java | 11 +- src/org/ojalgo/structure/Mutate1D.java | 9 +- src/org/ojalgo/structure/MutateAnyD.java | 4 +- .../org/ojalgo/type/PrimitiveNumber.java | 36 ++- .../function/constant/PrimitiveMathTest.java | 30 --- .../function/special/MissingMathTest.java | 43 ++++ 17 files changed, 418 insertions(+), 197 deletions(-) rename test/org/ojalgo/matrix/MatrixUtilsTest.java => src/org/ojalgo/type/PrimitiveNumber.java (67%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23e9c3c33..79ac8c500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +Added / Changed / Deprecated / Removed / Fixed / Security + ## [Unreleased] > Corresponds to changes in the `develop` branch since the last release @@ -25,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### org.ojalgo.optimisation -- The iterative version of the ActiveSetSolver now enforce an iterations limit. +- The iterative version of the ActiveSetSolver now enforce an iterations limit on its internal subsolver. #### org.ojalgo.structure @@ -37,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The merge functionality of AggregatorFunction is deprecated. - Everything related to "power of 2" has been deprecetd in PrimitiveMath. +- FunctionUtils has been deprecated. Everything in it has been moved elsewhere – mostly to MissingMath. ### Removed diff --git a/src/org/ojalgo/array/Primitive32Array.java b/src/org/ojalgo/array/Primitive32Array.java index 7092b2100..17dd4a2dc 100644 --- a/src/org/ojalgo/array/Primitive32Array.java +++ b/src/org/ojalgo/array/Primitive32Array.java @@ -32,7 +32,6 @@ import org.ojalgo.function.BinaryFunction.FixedFirst; import org.ojalgo.function.BinaryFunction.FixedSecond; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.ParameterFunction.FixedParameter; @@ -42,6 +41,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.scalar.Scalar; @@ -396,13 +396,13 @@ public void fillMatching(final Access1D values) { } public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), left.count(), right.count()); - Primitive32Array.invoke(data, 0, tmpLimit, 1, left, function, right); + int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); + Primitive32Array.invoke(data, 0, limit, 1, left, function, right); } public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), arguments.count()); - Primitive32Array.invoke(data, 0, tmpLimit, 1, arguments, function); + int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); + Primitive32Array.invoke(data, 0, limit, 1, arguments, function); } @Override diff --git a/src/org/ojalgo/array/Primitive64Array.java b/src/org/ojalgo/array/Primitive64Array.java index 282f90f66..f02e26eff 100644 --- a/src/org/ojalgo/array/Primitive64Array.java +++ b/src/org/ojalgo/array/Primitive64Array.java @@ -36,7 +36,6 @@ import org.ojalgo.function.BinaryFunction.FixedFirst; import org.ojalgo.function.BinaryFunction.FixedSecond; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.ParameterFunction.FixedParameter; @@ -46,6 +45,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.scalar.Scalar; @@ -400,13 +400,13 @@ public void fillMatching(final Access1D values) { } public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), left.count(), right.count()); - Primitive64Array.invoke(data, 0, tmpLimit, 1, left, function, right); + int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); + Primitive64Array.invoke(data, 0, limit, 1, left, function, right); } public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), arguments.count()); - Primitive64Array.invoke(data, 0, tmpLimit, 1, arguments, function); + int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); + Primitive64Array.invoke(data, 0, limit, 1, arguments, function); } @Override diff --git a/src/org/ojalgo/array/ReferenceTypeArray.java b/src/org/ojalgo/array/ReferenceTypeArray.java index 4e9359da0..b1b6dc02d 100644 --- a/src/org/ojalgo/array/ReferenceTypeArray.java +++ b/src/org/ojalgo/array/ReferenceTypeArray.java @@ -27,12 +27,12 @@ import org.ojalgo.array.operation.COPY; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; @@ -148,15 +148,15 @@ public void fillMatching(final Access1D values) { } public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), left.count(), right.count()); - for (int i = 0; i < tmpLimit; i++) { + int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); + for (int i = 0; i < limit; i++) { data[i] = function.invoke(left.get(i), right.get(i)); } } public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int tmpLimit = (int) FunctionUtils.min(this.count(), arguments.count()); - for (int i = 0; i < tmpLimit; i++) { + int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); + for (int i = 0; i < limit; i++) { data[i] = function.invoke(arguments.get(i)); } } diff --git a/src/org/ojalgo/function/FunctionUtils.java b/src/org/ojalgo/function/FunctionUtils.java index 4d81fdd1f..d2efa01a7 100644 --- a/src/org/ojalgo/function/FunctionUtils.java +++ b/src/org/ojalgo/function/FunctionUtils.java @@ -21,153 +21,244 @@ */ package org.ojalgo.function; -import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.scalar.PrimitiveScalar; +import org.ojalgo.function.special.MissingMath; +/** + * @deprecated v48 + */ +@Deprecated public abstract class FunctionUtils { + /** + * @deprecated v48 Use {@link UnaryFunction#isZeroModified(UnaryFunction)} instead + */ + @Deprecated public static boolean isZeroModified(final UnaryFunction function) { - return !PrimitiveScalar.isSmall(PrimitiveMath.ONE, function.invoke(PrimitiveMath.ZERO)); + return UnaryFunction.isZeroModified(function); } + /** + * @deprecated v48 Use {@link MissingMath#max(double...)} instead + */ + @Deprecated public static double max(final double... values) { - double retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.max(values); } + /** + * @deprecated v48 Use {@link MissingMath#max(double,double)} instead + */ + @Deprecated public static double max(final double a, final double b) { - return Math.max(a, b); + return MissingMath.max(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#max(double,double,double)} instead + */ + @Deprecated public static double max(final double a, final double b, final double c) { - return Math.max(Math.max(a, b), c); + return MissingMath.max(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#max(double,double,double,double)} instead + */ + @Deprecated public static double max(final double a, final double b, final double c, final double d) { - return Math.max(Math.max(a, b), Math.max(c, d)); + return MissingMath.max(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#max(int...)} instead + */ + @Deprecated public static int max(final int... values) { - int retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.max(values); } + /** + * @deprecated v48 Use {@link MissingMath#max(int,int)} instead + */ + @Deprecated public static int max(final int a, final int b) { - return Math.max(a, b); + return MissingMath.max(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#max(int,int,int)} instead + */ + @Deprecated public static int max(final int a, final int b, final int c) { - return Math.max(Math.max(a, b), c); + return MissingMath.max(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#max(int,int,int,int)} instead + */ + @Deprecated public static int max(final int a, final int b, final int c, final int d) { - return Math.max(Math.max(a, b), Math.max(c, d)); + return MissingMath.max(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#max(long...)} instead + */ + @Deprecated public static long max(final long... values) { - long retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.max(values); } + /** + * @deprecated v48 Use {@link MissingMath#max(long,long)} instead + */ + @Deprecated public static long max(final long a, final long b) { - return Math.max(a, b); + return MissingMath.max(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#max(long,long,long)} instead + */ + @Deprecated public static long max(final long a, final long b, final long c) { - return Math.max(Math.max(a, b), c); + return MissingMath.max(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#max(long,long,long,long)} instead + */ + @Deprecated public static long max(final long a, final long b, final long c, final long d) { - return Math.max(Math.max(a, b), Math.max(c, d)); + return MissingMath.max(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#min(double...)} instead + */ + @Deprecated public static double min(final double... values) { - double retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] < retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.min(values); } + /** + * @deprecated v48 Use {@link MissingMath#min(double,double)} instead + */ + @Deprecated public static double min(final double a, final double b) { - return Math.min(a, b); + return MissingMath.min(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#min(double,double,double)} instead + */ + @Deprecated public static double min(final double a, final double b, final double c) { - return Math.min(Math.min(a, b), c); + return MissingMath.min(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#min(double,double,double,double)} instead + */ + @Deprecated public static double min(final double a, final double b, final double c, final double d) { - return Math.min(Math.min(a, b), Math.min(c, d)); + return MissingMath.min(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#min(int...)} instead + */ + @Deprecated public static int min(final int... values) { - int retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] < retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.min(values); } + /** + * @deprecated v48 Use {@link MissingMath#min(int,int)} instead + */ + @Deprecated public static int min(final int a, final int b) { - return Math.min(a, b); + return MissingMath.min(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#min(int,int,int)} instead + */ + @Deprecated public static int min(final int a, final int b, final int c) { - return Math.min(Math.min(a, b), c); + return MissingMath.min(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#min(int,int,int,int)} instead + */ + @Deprecated public static int min(final int a, final int b, final int c, final int d) { - return Math.min(Math.min(a, b), Math.min(c, d)); + return MissingMath.min(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#min(long...)} instead + */ + @Deprecated public static long min(final long... values) { - long retVal = values[0]; - for (int i = values.length; i-- != 1;) { - retVal = values[i] < retVal ? values[i] : retVal; - } - return retVal; + return MissingMath.min(values); } + /** + * @deprecated v48 Use {@link MissingMath#min(long,long)} instead + */ + @Deprecated public static long min(final long a, final long b) { - return Math.min(a, b); + return MissingMath.min(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#min(long,long,long)} instead + */ + @Deprecated public static long min(final long a, final long b, final long c) { - return Math.min(Math.min(a, b), c); + return MissingMath.min(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#min(long,long,long,long)} instead + */ + @Deprecated public static long min(final long a, final long b, final long c, final long d) { - return Math.min(Math.min(a, b), Math.min(c, d)); + return MissingMath.min(a, b, c, d); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double...)} instead + */ + @Deprecated public static double norm(final double... values) { - double retVal = Math.abs(values[0]); - for (int i = values.length; i-- != 1;) { - retVal = values[i] > retVal ? Math.abs(values[i]) : retVal; - } - return retVal; + return MissingMath.norm(values); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double,double)} instead + */ + @Deprecated public static double norm(final double a, final double b) { - return Math.max(Math.abs(a), Math.abs(b)); + return MissingMath.norm(a, b); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double,double,double)} instead + */ + @Deprecated public static double norm(final double a, final double b, final double c) { - return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.abs(c)); + return MissingMath.norm(a, b, c); } + /** + * @deprecated v48 Use {@link MissingMath#norm(double,double,double,double)} instead + */ + @Deprecated public static double norm(final double a, final double b, final double c, final double d) { - return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.max(Math.abs(c), Math.abs(d))); + return MissingMath.norm(a, b, c, d); } private FunctionUtils() { diff --git a/src/org/ojalgo/function/UnaryFunction.java b/src/org/ojalgo/function/UnaryFunction.java index 48be43c08..0ffb8fe27 100644 --- a/src/org/ojalgo/function/UnaryFunction.java +++ b/src/org/ojalgo/function/UnaryFunction.java @@ -25,9 +25,15 @@ import java.util.function.UnaryOperator; import org.ojalgo.ProgrammingError; +import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.scalar.PrimitiveScalar; public interface UnaryFunction extends BasicFunction, UnaryOperator, DoubleUnaryOperator { + static boolean isZeroModified(final UnaryFunction function) { + return !PrimitiveScalar.isSmall(PrimitiveMath.ONE, function.invoke(PrimitiveMath.ZERO)); + } + default UnaryFunction andThen(final UnaryFunction after) { ProgrammingError.throwIfNull(after); return new UnaryFunction() { diff --git a/src/org/ojalgo/function/special/MissingMath.java b/src/org/ojalgo/function/special/MissingMath.java index 791be96ec..be00c5814 100644 --- a/src/org/ojalgo/function/special/MissingMath.java +++ b/src/org/ojalgo/function/special/MissingMath.java @@ -131,6 +131,146 @@ public static double logit(final double arg) { return Math.log(1.0 / (1.0 - arg)); } + public static double max(final double... values) { + double retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? values[i] : retVal; + } + return retVal; + } + + public static double max(final double a, final double b) { + return Math.max(a, b); + } + + public static double max(final double a, final double b, final double c) { + return Math.max(Math.max(a, b), c); + } + + public static double max(final double a, final double b, final double c, final double d) { + return Math.max(Math.max(a, b), Math.max(c, d)); + } + + public static int max(final int... values) { + int retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? values[i] : retVal; + } + return retVal; + } + + public static int max(final int a, final int b) { + return Math.max(a, b); + } + + public static int max(final int a, final int b, final int c) { + return Math.max(Math.max(a, b), c); + } + + public static int max(final int a, final int b, final int c, final int d) { + return Math.max(Math.max(a, b), Math.max(c, d)); + } + + public static long max(final long... values) { + long retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? values[i] : retVal; + } + return retVal; + } + + public static long max(final long a, final long b) { + return Math.max(a, b); + } + + public static long max(final long a, final long b, final long c) { + return Math.max(Math.max(a, b), c); + } + + public static long max(final long a, final long b, final long c, final long d) { + return Math.max(Math.max(a, b), Math.max(c, d)); + } + + public static double min(final double... values) { + double retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] < retVal ? values[i] : retVal; + } + return retVal; + } + + public static double min(final double a, final double b) { + return Math.min(a, b); + } + + public static double min(final double a, final double b, final double c) { + return Math.min(Math.min(a, b), c); + } + + public static double min(final double a, final double b, final double c, final double d) { + return Math.min(Math.min(a, b), Math.min(c, d)); + } + + public static int min(final int... values) { + int retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] < retVal ? values[i] : retVal; + } + return retVal; + } + + public static int min(final int a, final int b) { + return Math.min(a, b); + } + + public static int min(final int a, final int b, final int c) { + return Math.min(Math.min(a, b), c); + } + + public static int min(final int a, final int b, final int c, final int d) { + return Math.min(Math.min(a, b), Math.min(c, d)); + } + + public static long min(final long... values) { + long retVal = values[0]; + for (int i = values.length; i-- != 1;) { + retVal = values[i] < retVal ? values[i] : retVal; + } + return retVal; + } + + public static long min(final long a, final long b) { + return Math.min(a, b); + } + + public static long min(final long a, final long b, final long c) { + return Math.min(Math.min(a, b), c); + } + + public static long min(final long a, final long b, final long c, final long d) { + return Math.min(Math.min(a, b), Math.min(c, d)); + } + + public static double norm(final double... values) { + double retVal = Math.abs(values[0]); + for (int i = values.length; i-- != 1;) { + retVal = values[i] > retVal ? Math.abs(values[i]) : retVal; + } + return retVal; + } + + public static double norm(final double a, final double b) { + return Math.max(Math.abs(a), Math.abs(b)); + } + + public static double norm(final double a, final double b, final double c) { + return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.abs(c)); + } + + public static double norm(final double a, final double b, final double c, final double d) { + return Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.max(Math.abs(c), Math.abs(d))); + } + public static BigDecimal pow(final BigDecimal arg1, final BigDecimal arg2) { if (arg2.signum() == 0) { return BigDecimal.ONE; @@ -284,8 +424,20 @@ public static double sqrt1px2(final double arg) { return Math.sqrt(1.0 + (arg * arg)); } + public static int toMinIntExact(final long... values) { + return Math.toIntExact(MissingMath.min(values)); + } + public static int toMinIntExact(final long a, final long b) { return Math.toIntExact(Math.min(a, b)); } + public static int toMinIntExact(final long a, final long b, final long c) { + return Math.toIntExact(MissingMath.min(a, b, c)); + } + + public static int toMinIntExact(final long a, final long b, final long c, final long d) { + return Math.toIntExact(MissingMath.min(a, b, c, d)); + } + } diff --git a/src/org/ojalgo/matrix/store/GenericDenseStore.java b/src/org/ojalgo/matrix/store/GenericDenseStore.java index 445b15945..a9d0395bb 100644 --- a/src/org/ojalgo/matrix/store/GenericDenseStore.java +++ b/src/org/ojalgo/matrix/store/GenericDenseStore.java @@ -30,11 +30,11 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.aggregator.AggregatorSet; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.MatrixUtils; import org.ojalgo.matrix.decomposition.DecompositionStore; import org.ojalgo.matrix.store.DiagonalStore.Builder; @@ -744,7 +744,7 @@ public void conquer(final int first, final int limit) { @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int matchingCount = (int) FunctionUtils.min(this.count(), left.count(), right.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); if (myColDim > FillMatchingDual.THRESHOLD) { @@ -768,7 +768,7 @@ protected void conquer(final int first, final int limit) { @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int matchingCount = (int) FunctionUtils.min(this.count(), arguments.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), arguments.count()); if (myColDim > FillMatchingSingle.THRESHOLD) { @@ -895,22 +895,6 @@ public void modifyDiagonal(final long row, final long col, final UnaryFunction left, final BinaryFunction function) { - final long tmpLimit = FunctionUtils.min(left.count(), this.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.fillOne(i, function.invoke(left.get(i), this.get(i))); - } - } - - @Override - public void modifyMatching(final BinaryFunction function, final Access1D right) { - final long tmpLimit = FunctionUtils.min(this.count(), right.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.fillOne(i, function.invoke(this.get(i), right.get(i))); - } - } - public void modifyOne(final long row, final long col, final UnaryFunction modifier) { N tmpValue = this.get(row, col); diff --git a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java b/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java index bfae73d29..5fd315c2b 100644 --- a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java +++ b/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java @@ -37,7 +37,6 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.FunctionSet; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; @@ -45,6 +44,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.machine.MemoryEstimator; import org.ojalgo.matrix.MatrixUtils; @@ -798,7 +798,7 @@ public void conquer(final int first, final int limit) { @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { - final int matchingCount = (int) FunctionUtils.min(this.count(), left.count(), right.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); if (myColDim > FillMatchingDual.THRESHOLD) { @@ -822,7 +822,7 @@ protected void conquer(final int first, final int limit) { @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { - final int matchingCount = (int) FunctionUtils.min(this.count(), arguments.count()); + int matchingCount = MissingMath.toMinIntExact(this.count(), arguments.count()); if (myColDim > FillMatchingSingle.THRESHOLD) { @@ -949,22 +949,6 @@ public void modifyDiagonal(final long row, final long col, final UnaryFunction left, final BinaryFunction function) { - final long tmpLimit = FunctionUtils.min(left.count(), this.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.set(i, function.invoke(left.doubleValue(i), this.doubleValue(i))); - } - } - - @Override - public void modifyMatching(final BinaryFunction function, final Access1D right) { - final long tmpLimit = FunctionUtils.min(this.count(), right.count(), this.count()); - for (long i = 0L; i < tmpLimit; i++) { - this.set(i, function.invoke(this.doubleValue(i), right.doubleValue(i))); - } - } - public void modifyOne(final long row, final long col, final UnaryFunction modifier) { double tmpValue = this.doubleValue(row, col); diff --git a/src/org/ojalgo/matrix/task/AbstractInverter.java b/src/org/ojalgo/matrix/task/AbstractInverter.java index 92dbc4303..4a8970510 100644 --- a/src/org/ojalgo/matrix/task/AbstractInverter.java +++ b/src/org/ojalgo/matrix/task/AbstractInverter.java @@ -24,7 +24,7 @@ import static org.ojalgo.function.constant.PrimitiveMath.*; import org.ojalgo.RecoverableCondition; -import org.ojalgo.function.FunctionUtils; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PrimitiveDenseStore; @@ -171,7 +171,7 @@ static void full2X2(final Access2D source, final PhysicalStore destination double tmp01 = source.doubleValue(2L); double tmp11 = source.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp10, tmp11); + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp10, tmp11); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -202,7 +202,7 @@ static void full3X3(final Access2D source, final PhysicalStore destination double tmp12 = source.doubleValue(7L); double tmp22 = source.doubleValue(8L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp02, tmp10, tmp11, tmp12, tmp20, tmp21, tmp22); + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp10, tmp11, tmp12, tmp20, tmp21, tmp22); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -265,7 +265,7 @@ static void full4X4(final Access2D source, final PhysicalStore destination double tmp23 = source.doubleValue(14L); double tmp33 = source.doubleValue(15L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp02, tmp03, tmp10, tmp11, tmp12, tmp13, tmp20, tmp21, tmp22, tmp23, tmp30, tmp31, tmp32, + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp03, tmp10, tmp11, tmp12, tmp13, tmp20, tmp21, tmp22, tmp23, tmp30, tmp31, tmp32, tmp33); tmp00 /= tmpScale; @@ -363,7 +363,7 @@ static void full5X5(final Access2D source, final PhysicalStore destination double tmp34 = source.doubleValue(23L); double tmp44 = source.doubleValue(24L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp01, tmp02, tmp03, tmp04, tmp10, tmp11, tmp12, tmp13, tmp14, tmp20, tmp21, tmp22, tmp23, tmp24, + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp03, tmp04, tmp10, tmp11, tmp12, tmp13, tmp14, tmp20, tmp21, tmp22, tmp23, tmp24, tmp30, tmp31, tmp32, tmp33, tmp34, tmp40, tmp41, tmp42, tmp43, tmp44); tmp00 /= tmpScale; @@ -491,7 +491,7 @@ static void symmetric2X2(final Access2D source, final PhysicalStore destin double tmp11 = source.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -518,7 +518,7 @@ static void symmetric3X3(final Access2D source, final PhysicalStore destin double tmp22 = source.doubleValue(8L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -569,7 +569,7 @@ static void symmetric4X4(final Access2D source, final PhysicalStore destin double tmp33 = source.doubleValue(15L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -644,7 +644,7 @@ static void symmetric5X5(final Access2D source, final PhysicalStore destin double tmp44 = source.doubleValue(24L); - final double tmpScale = FunctionUtils.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33, tmp40, tmp41, tmp42, tmp43, tmp44); + final double tmpScale = MissingMath.norm(tmp00, tmp10, tmp11, tmp20, tmp21, tmp22, tmp30, tmp31, tmp32, tmp33, tmp40, tmp41, tmp42, tmp43, tmp44); tmp00 /= tmpScale; tmp10 /= tmpScale; diff --git a/src/org/ojalgo/matrix/task/AbstractSolver.java b/src/org/ojalgo/matrix/task/AbstractSolver.java index 2251f8376..b86fa3b7f 100644 --- a/src/org/ojalgo/matrix/task/AbstractSolver.java +++ b/src/org/ojalgo/matrix/task/AbstractSolver.java @@ -22,7 +22,7 @@ package org.ojalgo.matrix.task; import org.ojalgo.RecoverableCondition; -import org.ojalgo.function.FunctionUtils; +import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PrimitiveDenseStore; @@ -137,7 +137,7 @@ static void full2X2(final Access2D body, final Access1D rhs, final Physica double tmp0 = rhs.doubleValue(0L); double tmp1 = rhs.doubleValue(1L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1); + final double tmpScale = MissingMath.norm(tmp0, tmp1); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -172,7 +172,7 @@ static void full3X3(final Access2D body, final Access1D rhs, final Physica double tmp1 = rhs.doubleValue(1L); double tmp2 = rhs.doubleValue(2L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -236,7 +236,7 @@ static void full4X4(final Access2D body, final Access1D rhs, final Physica double tmp2 = rhs.doubleValue(2L); double tmp3 = rhs.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -329,7 +329,7 @@ static void full5X5(final Access2D body, final Access1D rhs, final Physica double tmp3 = rhs.doubleValue(3L); double tmp4 = rhs.doubleValue(4L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3, tmp4); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3, tmp4); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -475,7 +475,7 @@ static void symmetric2X2(final Access2D body, final Access1D rhs, final Ph double tmp0 = rhs.doubleValue(0L); double tmp1 = rhs.doubleValue(1L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1); + final double tmpScale = MissingMath.norm(tmp0, tmp1); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -506,7 +506,7 @@ static void symmetric3X3(final Access2D body, final Access1D rhs, final Ph double tmp1 = rhs.doubleValue(1L); double tmp2 = rhs.doubleValue(2L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -558,7 +558,7 @@ static void symmetric4X4(final Access2D body, final Access1D rhs, final Ph double tmp2 = rhs.doubleValue(2L); double tmp3 = rhs.doubleValue(3L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3); tmp00 /= tmpScale; tmp10 /= tmpScale; @@ -629,7 +629,7 @@ static void symmetric5X5(final Access2D body, final Access1D rhs, final Ph double tmp3 = rhs.doubleValue(3L); double tmp4 = rhs.doubleValue(4L); - final double tmpScale = FunctionUtils.norm(tmp0, tmp1, tmp2, tmp3, tmp4); + final double tmpScale = MissingMath.norm(tmp0, tmp1, tmp2, tmp3, tmp4); tmp00 /= tmpScale; tmp10 /= tmpScale; diff --git a/src/org/ojalgo/structure/AccessScalar.java b/src/org/ojalgo/structure/AccessScalar.java index 929f717d2..6b0ac8898 100644 --- a/src/org/ojalgo/structure/AccessScalar.java +++ b/src/org/ojalgo/structure/AccessScalar.java @@ -21,7 +21,9 @@ */ package org.ojalgo.structure; -public interface AccessScalar { +import org.ojalgo.type.PrimitiveNumber; + +public interface AccessScalar extends PrimitiveNumber { /** * @see Number#byteValue() @@ -30,13 +32,6 @@ default byte byteValue() { return (byte) this.shortValue(); } - /** - * @see Number#doubleValue() - */ - default double doubleValue() { - return this.get().doubleValue(); - } - /** * @see Number#floatValue() */ diff --git a/src/org/ojalgo/structure/Mutate1D.java b/src/org/ojalgo/structure/Mutate1D.java index e0c7b7519..195343b39 100644 --- a/src/org/ojalgo/structure/Mutate1D.java +++ b/src/org/ojalgo/structure/Mutate1D.java @@ -25,7 +25,6 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.constant.PrimitiveMath; @@ -112,15 +111,11 @@ default void modifyAll(final UnaryFunction modifier) { } default void modifyMatching(final Access1D left, final BinaryFunction function) { - for (long i = 0L, limit = FunctionUtils.min(left.count(), this.count()); i < limit; i++) { - this.modifyOne(i, function.first(left.get(i))); - } + Structure1D.loopMatching(left, this, i -> this.modifyOne(i, function.first(left.get(i)))); } default void modifyMatching(final BinaryFunction function, final Access1D right) { - for (long i = 0L, limit = FunctionUtils.min(this.count(), right.count()); i < limit; i++) { - this.modifyOne(i, function.second(right.get(i))); - } + Structure1D.loopMatching(this, right, i -> this.modifyOne(i, function.second(right.get(i)))); } void modifyOne(long index, UnaryFunction modifier); diff --git a/src/org/ojalgo/structure/MutateAnyD.java b/src/org/ojalgo/structure/MutateAnyD.java index 66deed71b..37b8f5a7b 100644 --- a/src/org/ojalgo/structure/MutateAnyD.java +++ b/src/org/ojalgo/structure/MutateAnyD.java @@ -25,9 +25,9 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; +import org.ojalgo.function.special.MissingMath; /** * N-dimensional mutator methods @@ -103,7 +103,7 @@ default boolean isAcceptable(final StructureAnyD supplier) { boolean retVal = true; - int tmpRank = FunctionUtils.max(this.shape().length, this.shape().length); + int tmpRank = MissingMath.max(this.shape().length, this.shape().length); for (int i = 0; i < tmpRank; i++) { retVal &= this.count(i) >= supplier.count(i); diff --git a/test/org/ojalgo/matrix/MatrixUtilsTest.java b/src/org/ojalgo/type/PrimitiveNumber.java similarity index 67% rename from test/org/ojalgo/matrix/MatrixUtilsTest.java rename to src/org/ojalgo/type/PrimitiveNumber.java index 0d903e0a0..e5b086435 100644 --- a/test/org/ojalgo/matrix/MatrixUtilsTest.java +++ b/src/org/ojalgo/type/PrimitiveNumber.java @@ -19,27 +19,25 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.ojalgo.matrix; - -import org.junit.jupiter.api.Test; -import org.ojalgo.TestUtils; -import org.ojalgo.function.FunctionUtils; +package org.ojalgo.type; /** - * @author apete + * An interface that defines what is in {@link java.lang.Number}. Hopefully Java itself will one day get an + * interface that does this. When/if that happens then this interface AND any/all usage of + * extends java.lang.Number will be replaced by that new interface. */ -public class MatrixUtilsTest extends MatrixTests { - - @Test - public void testMax() { - TestUtils.assertEquals(9, FunctionUtils.max(9, 0, -9)); - TestUtils.assertEquals(9, FunctionUtils.max(-9, 0, 9)); - } - - @Test - public void testMin() { - TestUtils.assertEquals(-9, FunctionUtils.min(9, 0, -9)); - TestUtils.assertEquals(-9, FunctionUtils.min(-9, 0, 9)); - } +public interface PrimitiveNumber { + + byte byteValue(); + + double doubleValue(); + + float floatValue(); + + int intValue(); + + long longValue(); + + short shortValue(); } diff --git a/test/org/ojalgo/function/constant/PrimitiveMathTest.java b/test/org/ojalgo/function/constant/PrimitiveMathTest.java index 9b9d89919..c53b7d4b3 100644 --- a/test/org/ojalgo/function/constant/PrimitiveMathTest.java +++ b/test/org/ojalgo/function/constant/PrimitiveMathTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.function.FunctionUtils; import org.ojalgo.function.constant.PrimitiveMath.Prefix; import org.ojalgo.type.context.NumberContext; @@ -97,35 +96,6 @@ public void testHYPOT() { } - @Test - public void testMinMax() { - - TestUtils.assertEquals(Math.min(2, -78), FunctionUtils.min(2, -78)); - TestUtils.assertEquals(MAX.invoke(2, -78), FunctionUtils.max(2, -78)); - - TestUtils.assertEquals(67, FunctionUtils.max(new int[] { 67 })); - TestUtils.assertEquals(67, FunctionUtils.min(new int[] { 67 })); - - TestUtils.assertEquals(FunctionUtils.max(67, -76), FunctionUtils.max(new int[] { 67, -76 })); - TestUtils.assertEquals(FunctionUtils.min(67, -76), FunctionUtils.min(new int[] { 67, -76 })); - - TestUtils.assertEquals(FunctionUtils.max(0, 67, -76), FunctionUtils.max(new int[] { 0, 67, -76 })); - TestUtils.assertEquals(FunctionUtils.min(0, 67, -76), FunctionUtils.min(new int[] { 0, 67, -76 })); - - TestUtils.assertEquals(FunctionUtils.max(0, 67, -76, 80), FunctionUtils.max(new int[] { 0, 67, -76, 80 })); - TestUtils.assertEquals(FunctionUtils.min(0, 67, -76, -80), FunctionUtils.min(new int[] { 0, 67, -76, -80 })); - - TestUtils.assertEquals(FunctionUtils.max(80, 0, 67, -76), FunctionUtils.max(new int[] { 80, 0, 67, -76 })); - TestUtils.assertEquals(FunctionUtils.min(-80, 0, 67, -76), FunctionUtils.min(new int[] { -80, 0, 67, -76 })); - - TestUtils.assertEquals(80, FunctionUtils.max(new int[] { 0, 67, -76, 80 })); - TestUtils.assertEquals(-80, FunctionUtils.min(new int[] { 0, 67, -76, -80 })); - - TestUtils.assertEquals(80, FunctionUtils.max(new int[] { 80, 0, 67, -76 })); - TestUtils.assertEquals(-80, FunctionUtils.min(new int[] { -80, 0, 67, -76 })); - - } - @Test public void testPOWER() { diff --git a/test/org/ojalgo/function/special/MissingMathTest.java b/test/org/ojalgo/function/special/MissingMathTest.java index 7eb77385d..47ab45db8 100644 --- a/test/org/ojalgo/function/special/MissingMathTest.java +++ b/test/org/ojalgo/function/special/MissingMathTest.java @@ -21,11 +21,54 @@ */ package org.ojalgo.function.special; +import static org.ojalgo.function.constant.PrimitiveMath.*; + import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; public class MissingMathTest { + @Test + public void testMax() { + TestUtils.assertEquals(9, MissingMath.max(9, 0, -9)); + TestUtils.assertEquals(9, MissingMath.max(-9, 0, 9)); + } + + @Test + public void testMin() { + TestUtils.assertEquals(-9, MissingMath.min(9, 0, -9)); + TestUtils.assertEquals(-9, MissingMath.min(-9, 0, 9)); + } + + @Test + public void testMinMax() { + + TestUtils.assertEquals(Math.min(2, -78), MissingMath.min(2, -78)); + TestUtils.assertEquals(MAX.invoke(2, -78), MissingMath.max(2, -78)); + + TestUtils.assertEquals(67, MissingMath.max(new int[] { 67 })); + TestUtils.assertEquals(67, MissingMath.min(new int[] { 67 })); + + TestUtils.assertEquals(MissingMath.max(67, -76), MissingMath.max(new int[] { 67, -76 })); + TestUtils.assertEquals(MissingMath.min(67, -76), MissingMath.min(new int[] { 67, -76 })); + + TestUtils.assertEquals(MissingMath.max(0, 67, -76), MissingMath.max(new int[] { 0, 67, -76 })); + TestUtils.assertEquals(MissingMath.min(0, 67, -76), MissingMath.min(new int[] { 0, 67, -76 })); + + TestUtils.assertEquals(MissingMath.max(0, 67, -76, 80), MissingMath.max(new int[] { 0, 67, -76, 80 })); + TestUtils.assertEquals(MissingMath.min(0, 67, -76, -80), MissingMath.min(new int[] { 0, 67, -76, -80 })); + + TestUtils.assertEquals(MissingMath.max(80, 0, 67, -76), MissingMath.max(new int[] { 80, 0, 67, -76 })); + TestUtils.assertEquals(MissingMath.min(-80, 0, 67, -76), MissingMath.min(new int[] { -80, 0, 67, -76 })); + + TestUtils.assertEquals(80, MissingMath.max(new int[] { 0, 67, -76, 80 })); + TestUtils.assertEquals(-80, MissingMath.min(new int[] { 0, 67, -76, -80 })); + + TestUtils.assertEquals(80, MissingMath.max(new int[] { 80, 0, 67, -76 })); + TestUtils.assertEquals(-80, MissingMath.min(new int[] { -80, 0, 67, -76 })); + + } + @Test public void testPower() { From 44282d50510f36edb16f582efe08c58623819c16 Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 29 Sep 2019 18:23:30 +0200 Subject: [PATCH 14/29] Update CHANGELOG.md --- CHANGELOG.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ac8c500..b1bf3563d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,10 @@ Added / Changed / Deprecated / Removed / Fixed / Security #### org.ojalgo.function -- New special function utility class PowerOf2. It replaces what was in PrimitiveMath, amde some improvements and addition and added support or 'int' (used to be only 'long'). +- New special function utility class PowerOf2. It replaces what was in PrimitiveMath, made some improvements and addition and added support or 'int' (used to be only 'long'). ### Changed -- - #### org.ojalgo.matrix - The multithreaded implementations of aggregateAll in PrimkitiveDenseStoree and GenericDenseStore are removed. @@ -41,18 +39,10 @@ Added / Changed / Deprecated / Removed / Fixed / Security - Everything related to "power of 2" has been deprecetd in PrimitiveMath. - FunctionUtils has been deprecated. Everything in it has been moved elsewhere – mostly to MissingMath. -### Removed - -- - ### Fixed - The compareTo method of CalendarDateDuration didn't work when the unit of either instances was "nanos". -### Security - -- - ## [47.3.0] – 2019-08-08 ### Changed From 7385c35ab127ef3c94b5b522ae8e14aa1cc5a850 Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 29 Sep 2019 20:29:20 +0200 Subject: [PATCH 15/29] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1bf3563d..bbf19800b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -Added / Changed / Deprecated / Removed / Fixed / Security - ## [Unreleased] > Corresponds to changes in the `develop` branch since the last release +Added / Changed / Deprecated / Removed / Fixed / Security + +## [47.3.1] – 2019-09-29 + ### Added #### org.ojalgo.function From 7b9686eca4b92eb8ba73e732fd821512671ece14 Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 29 Sep 2019 20:56:24 +0200 Subject: [PATCH 16/29] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 125aa9c7e..4c735b9c5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.ojalgo ojalgo - 47.3.1-SNAPSHOT + 47.3.1 jar ojAlgo http://ojalgo.org From 4b642ff84bbe9315baec0ccb190265c1735b82e6 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Sat, 12 Oct 2019 11:45:20 +0200 Subject: [PATCH 17/29] DaemonFactory (#229) * DivideAndConquer * Revert "DivideAndConquer" This reverts commit 53ace4e3c7e043c13516a807d850674ec9ae77f4. * Update DaemonFactory.java --- src/org/ojalgo/concurrent/DaemonFactory.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/org/ojalgo/concurrent/DaemonFactory.java b/src/org/ojalgo/concurrent/DaemonFactory.java index 1776e7977..8490c1098 100644 --- a/src/org/ojalgo/concurrent/DaemonFactory.java +++ b/src/org/ojalgo/concurrent/DaemonFactory.java @@ -26,30 +26,23 @@ final class DaemonFactory implements ThreadFactory { - private static final String OJALGO_DAEMON_GROUP = "ojAlgo-daemon-group"; - private static final String PREFIX = "ojAlgo-daemon-"; - private static final int PRIORITY = Thread.NORM_PRIORITY - 1; - static final DaemonFactory INSTANCE = new DaemonFactory(); - private final AtomicInteger myNextThreadID = new AtomicInteger(1); + private final AtomicInteger myLastThreadID = new AtomicInteger(); private final ThreadGroup myThreadGroup; private DaemonFactory() { super(); - myThreadGroup = new ThreadGroup(OJALGO_DAEMON_GROUP); + myThreadGroup = new ThreadGroup("ojAlgo-daemon-group"); } public Thread newThread(final Runnable runnable) { - final String tmpName = PREFIX + myNextThreadID.getAndIncrement(); - - final Thread retVal = new Thread(myThreadGroup, runnable, tmpName); + Thread retVal = new Thread(myThreadGroup, runnable, "ojAlgo-daemon-" + myLastThreadID.incrementAndGet()); retVal.setDaemon(true); - retVal.setPriority(PRIORITY); return retVal; } From 2aa90ec6077037d8b226ddcc545b06addca0f97c Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Sat, 12 Oct 2019 14:11:45 +0200 Subject: [PATCH 18/29] More special functions (#228) * New special unctions * BetaFunction * Gamma - logarithmic Laczos approximation * TDistributionTest * Incomplete gamma for integers * Remove tree --- CHANGELOG.md | 10 +- pom.xml | 2 +- .../ojalgo/function/special/BetaFunction.java | 87 +++++++ .../special/CombinatorialFunctions.java | 45 ++-- .../function/special/GammaFunction.java | 216 ++++++++++++++++-- .../special/HypergeometricFunction.java | 45 ++++ .../ojalgo/function/special/MissingMath.java | 44 ++++ .../function/special/PochhammerSymbol.java | 40 ++++ .../ojalgo/matrix/task/AbstractInverter.java | 4 +- src/org/ojalgo/random/Poisson.java | 4 +- src/org/ojalgo/random/RandomUtils.java | 13 +- src/org/ojalgo/random/TDistribution.java | 38 +-- .../function/special/BetaFunctionTest.java | 94 ++++++++ .../function/special/GammaFunctionTest.java | 213 +++++++++++++++++ .../special/HypergeometricFunctionTest.java | 98 ++++++++ .../special/PochhammerSymbolTest.java | 81 +++++++ test/org/ojalgo/random/RandomNumberTest.java | 55 ----- test/org/ojalgo/random/TDistributionTest.java | 68 ++++++ 18 files changed, 1024 insertions(+), 133 deletions(-) create mode 100644 src/org/ojalgo/function/special/BetaFunction.java create mode 100644 src/org/ojalgo/function/special/HypergeometricFunction.java create mode 100644 src/org/ojalgo/function/special/PochhammerSymbol.java create mode 100644 test/org/ojalgo/function/special/BetaFunctionTest.java create mode 100644 test/org/ojalgo/function/special/GammaFunctionTest.java create mode 100644 test/org/ojalgo/function/special/HypergeometricFunctionTest.java create mode 100644 test/org/ojalgo/function/special/PochhammerSymbolTest.java create mode 100644 test/org/ojalgo/random/TDistributionTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d8e9a4c1..3848e4c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,15 @@ Added / Changed / Deprecated / Removed / Fixed / Security > Corresponds to changes in the `develop` branch since the last release -Added / Changed / Deprecated / Removed / Fixed / Security +### Added + +#### org.ojalgo.function + +- New special functions: beta (complete, incomplete and regularized), gamma (logarithmic), Hypergeometric and Pochhammer symbol. Inluding complex valued variants where applicable. The complete gamma function existed previously, and the upper/lower incomplete gamma functions are only implemented for the integer case. + +#### org.ojalgo.random + +- The `getDistribution()` method in the TDistribution is now implemented for the general case. Previously it was only implemented for a few distinct degrees of freedom. ## [47.3.1] – 2019-09-29 diff --git a/pom.xml b/pom.xml index 4c735b9c5..ef4cbe764 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.ojalgo ojalgo - 47.3.1 + 47.4.0-SNAPSHOT jar ojAlgo http://ojalgo.org diff --git a/src/org/ojalgo/function/special/BetaFunction.java b/src/org/ojalgo/function/special/BetaFunction.java new file mode 100644 index 000000000..52f80c23a --- /dev/null +++ b/src/org/ojalgo/function/special/BetaFunction.java @@ -0,0 +1,87 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +import org.ojalgo.scalar.ComplexNumber; + +public abstract class BetaFunction { + + public static abstract class Incomplete extends BetaFunction { + + public static ComplexNumber beta(double limit, ComplexNumber a, ComplexNumber b) { + // TODO Implement it! + return ComplexNumber.NaN; + } + + public static double beta(double limit, double a, double b) { + + double tmp = ONE; + double sum = tmp / a; + + // This implementation isn't very good numerically, + // but icreasing the number of iterations doesn't seem to help much. + for (int n = 1; n < 100; n++) { + tmp *= ((n - b) / n) * limit; + sum += tmp / (a + n); + } + + // return Math.pow(limit, a) * sum; + return Math.exp((a * Math.log(limit)) + Math.log(sum)); + } + + public static double beta(double limit, int a, int b) { + return Incomplete.beta(limit, (double) a, (double) b); + } + + } + + public static abstract class Regularized extends BetaFunction { + + public static ComplexNumber beta(double limit, ComplexNumber a, ComplexNumber b) { + return BetaFunction.Incomplete.beta(limit, a, b).divide(BetaFunction.beta(a, b)); + } + + public static double beta(double limit, double a, double b) { + return BetaFunction.Incomplete.beta(limit, a, b) / BetaFunction.beta(a, b); + } + + public static double beta(double limit, int a, int b) { + return BetaFunction.Incomplete.beta(limit, a, b) / BetaFunction.beta(a, b); + } + + } + + public static ComplexNumber beta(ComplexNumber a, ComplexNumber b) { + return GammaFunction.gamma(a).multiply(GammaFunction.gamma(b)).divide(GammaFunction.gamma(a.add(b))); + } + + public static double beta(double a, double b) { + return (GammaFunction.gamma(a) * GammaFunction.gamma(b)) / GammaFunction.gamma(a + b); + } + + public static double beta(int a, int b) { + return (GammaFunction.gamma(a) * GammaFunction.gamma(b)) / GammaFunction.gamma(a + b); + } + +} diff --git a/src/org/ojalgo/function/special/CombinatorialFunctions.java b/src/org/ojalgo/function/special/CombinatorialFunctions.java index 7f8635f42..ece847f1c 100644 --- a/src/org/ojalgo/function/special/CombinatorialFunctions.java +++ b/src/org/ojalgo/function/special/CombinatorialFunctions.java @@ -21,8 +21,6 @@ */ package org.ojalgo.function.special; -import static org.ojalgo.function.constant.PrimitiveMath.*; - /** * https://reference.wolfram.com/language/tutorial/CombinatorialFunctions.html * @@ -30,36 +28,36 @@ */ public abstract class CombinatorialFunctions { + /** + * 13! does not fit in an int, and 21! does not fit in a long - that's why this + * method returns a double. + * + * @deprecated v48 Use {@link MissingMath#factorial(int)} instead + */ + @Deprecated public static double factorial(final int arg) { - - double retVal = ONE; - - for (int i = 2; i <= arg; i++) { - retVal *= i; - } - - return retVal; + return MissingMath.factorial(arg); } /** * @param n The number of elements in the set * @param k A vector of subset sizes the sum of which must equal the size of the full set - * @return The number of ways the set can be partioned in to subsets of the given sizes + * @return The number of ways the set can be partitioned in to subsets of the given sizes */ - public static int partitions(final int n, final int[] k) { - int retVal = (int) CombinatorialFunctions.factorial(n); - for (int i = 0; i < k.length; i++) { - retVal /= CombinatorialFunctions.factorial(k[i]); + public static long partitions(final int n, final int[] k) { + double retVal = MissingMath.factorial(n); + for (int i = 0, limit = k.length; i < limit; i++) { + retVal /= MissingMath.factorial(k[i]); } - return retVal; + return Math.round(retVal); } /** * @param n The number of elements in the set * @return The number of permutations of the set */ - public static int permutations(final int n) { - return (int) CombinatorialFunctions.factorial(n); + public static long permutations(final int n) { + return Math.round(MissingMath.factorial(n)); } /** @@ -67,8 +65,8 @@ public static int permutations(final int n) { * @param k The number of elements in the subset * @return The number of subsets to the set */ - public static int subsets(final int n, final int k) { - return (int) (CombinatorialFunctions.factorial(n) / (CombinatorialFunctions.factorial(k) * CombinatorialFunctions.factorial(n - k))); + public static long subsets(final int n, final int k) { + return Math.round(MissingMath.factorial(n) / (MissingMath.factorial(k) * MissingMath.factorial(n - k))); } /** @@ -76,11 +74,8 @@ public static int subsets(final int n, final int k) { * @param k The size of the tuple * @return The number of ordered k-tuples (variations) of the set */ - public static int variations(final int n, final int k) { - return (int) (CombinatorialFunctions.factorial(n) / CombinatorialFunctions.factorial(n - k)); - } - - private CombinatorialFunctions() { + public static long variations(final int n, final int k) { + return Math.round(MissingMath.factorial(n) / MissingMath.factorial(n - k)); } } diff --git a/src/org/ojalgo/function/special/GammaFunction.java b/src/org/ojalgo/function/special/GammaFunction.java index 34959d8eb..729d3dc9b 100644 --- a/src/org/ojalgo/function/special/GammaFunction.java +++ b/src/org/ojalgo/function/special/GammaFunction.java @@ -23,51 +23,221 @@ import static org.ojalgo.function.constant.PrimitiveMath.*; -import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.function.constant.ComplexMath; +import org.ojalgo.scalar.ComplexNumber; public abstract class GammaFunction { - /** - * For the Lanczos approximation of the gamma function - */ - private static final double[] L9 = { 0.99999999999980993227684700473478, 676.520368121885098567009190444019, -1259.13921672240287047156078755283, - 771.3234287776530788486528258894, -176.61502916214059906584551354, 12.507343278686904814458936853, -0.13857109526572011689554707, - 9.984369578019570859563e-6, 1.50563273514931155834e-7 }; + public static abstract class Incomplete extends GammaFunction { + + public static ComplexNumber lower(final ComplexNumber z, double limit) { + // TODO Implement it! + return ComplexNumber.NaN; + } + + public static double lower(final double x, double limit) { + // TODO Implement it! + return NaN; + } + + public static double lower(final int n, double limit) { + + double incr = ONE, sum = ONE; + for (int k = 1; k < n; k++) { + incr *= (limit / k); + sum += incr; + } + + return (ONE - (sum * Math.exp(-limit))) * MissingMath.factorial(n - 1); + } + + public static ComplexNumber upper(final ComplexNumber z, double limit) { + // TODO Implement it! + return ComplexNumber.NaN; + } + + public static double upper(final double x, double limit) { + // TODO Implement it! + return NaN; + } + + public static double upper(final int n, double limit) { + + double incr = ONE, sum = ONE; + for (int k = 1; k < n; k++) { + incr *= (limit / k); + sum += incr; + } + + return sum * Math.exp(-limit) * MissingMath.factorial(n - 1); + } + + } + + public static abstract class Logarithmic extends GammaFunction { + + public static ComplexNumber gamma(ComplexNumber z) { + return GammaFunction.LanczosApproximation.logarithmic(z); + } + + public static double gamma(double x) { + return GammaFunction.LanczosApproximation.logarithmic(x); + } + + public static double gamma(int n) { + return Math.log(GammaFunction.gamma(n)); + } + + } + + public static abstract class Regularized extends GammaFunction { + + public static ComplexNumber lower(final ComplexNumber z, double limit) { + return GammaFunction.Incomplete.lower(z, limit).divide(GammaFunction.gamma(z)); + } + + public static double lower(final double x, double limit) { + return GammaFunction.Incomplete.lower(x, limit) / GammaFunction.gamma(x); + } + + public static double lower(final int n, double limit) { + return GammaFunction.Incomplete.lower(n, limit) / GammaFunction.gamma(n); + } + + public static ComplexNumber upper(final ComplexNumber z, double limit) { + return GammaFunction.Incomplete.upper(z, limit).divide(GammaFunction.gamma(z)); + } + + public static double upper(final double x, double limit) { + return GammaFunction.Incomplete.upper(x, limit) / GammaFunction.gamma(x); + } + + public static double upper(final int n, double limit) { + return GammaFunction.Incomplete.upper(n, limit) / GammaFunction.gamma(n); + } + + } /** - * Lanczos approximation. The abritray constant is 7, and there are 9 coefficients used. Essentially the - * algorithm is taken from WikipediA , - * but it's modified a bit and I found more exact coefficients somewhere else. + * Lanczos approximation. The abritray constant is 7, and there are 9 coefficients used. + * + *

+     * http://en.wikipedia.org/wiki/Lanczos_approximation
+     * http://mathworld.wolfram.com/LanczosApproximation.html
+     * https://mrob.com/pub/ries/lanczos-gamma.html
+     * 
*/ - public static double gamma(final double arg) { + static abstract class LanczosApproximation { - if ((arg <= ZERO) && (PrimitiveMath.ABS.invoke(arg % ONE) < MACHINE_EPSILON)) { + /** + * Arbitrary constant + */ + private static final double A = SEVEN; + /** + * Coefficients + */ + private static final double[] C = { 0.99999999999980993227684700473478, 676.520368121885098567009190444019, -1259.13921672240287047156078755283, + 771.3234287776530788486528258894, -176.61502916214059906584551354, 12.507343278686904814458936853, -0.13857109526572011689554707, + 9.984369578019570859563e-6, 1.50563273514931155834e-7 }; + private static final double LOG_SQRT_TWO_PI = LOG.invoke(SQRT_TWO_PI); - return NaN; + static ComplexNumber gamma(final ComplexNumber z) { - } else { + double zr = z.getReal(); - if (arg < HALF) { + if ((zr <= ZERO) && (ABS.invoke(zr % ONE) < MACHINE_EPSILON)) { - return PI / (PrimitiveMath.SIN.invoke(PI * arg) * GammaFunction.gamma(ONE - arg)); + return ComplexNumber.NaN; } else { - final double z = arg - ONE; + if (zr < HALF) { + + return ComplexMath.SIN.invoke(z.multiply(PI)).multiply(GammaFunction.gamma(ComplexNumber.ONE.subtract(z))).invert().multiply(PI); + + } else { + + final ComplexNumber z1 = z.subtract(ONE); + final ComplexNumber za = z1.add(A + HALF); + + ComplexNumber zs = ComplexNumber.valueOf(C[0]); + for (int i = C.length - 1; i > 0; i--) { + zs = zs.add(z1.add(i).invert().multiply(C[i])); + } - double x = GammaFunction.L9[0]; - for (int i = 1; i < GammaFunction.L9.length; i++) { - x += GammaFunction.L9[i] / (z + i); + return ComplexMath.POW.invoke(za, z1.add(HALF)).multiply(SQRT_TWO_PI).multiply(ComplexMath.EXP.invoke(za.negate())).multiply(zs); } + } + } + + static double gamma(final double x) { + + if ((x <= ZERO) && (ABS.invoke(x % ONE) < MACHINE_EPSILON)) { + + return NaN; + + } else { + + if (x < HALF) { + + return PI / (SIN.invoke(PI * x) * GammaFunction.gamma(ONE - x)); + + } else { - final double t = z + (7 + HALF); + final double x1 = x - ONE; + final double xa = x1 + (A + HALF); - return SQRT_TWO_PI * PrimitiveMath.POW.invoke(t, z + HALF) * PrimitiveMath.EXP.invoke(-t) * x; + double xs = C[0]; + for (int i = C.length - 1; i > 0; i--) { + xs += C[i] / (x1 + i); + } + + return POW.invoke(xa, x1 + HALF) * SQRT_TWO_PI * EXP.invoke(-xa) * xs; + } + } + } + + static ComplexNumber logarithmic(ComplexNumber z) { + + final ComplexNumber z1 = z.subtract(ONE); + final ComplexNumber za = z1.add(A + HALF); + + ComplexNumber zs = ComplexNumber.valueOf(C[0]); + for (int i = C.length - 1; i > 0; i--) { + zs = zs.add(z1.add(i).invert().multiply(C[i])); + } + + return z1.add(HALF).multiply(ComplexMath.LOG.invoke(za)).add(LOG_SQRT_TWO_PI).subtract(za).add(ComplexMath.LOG.invoke(zs)); + } + + static double logarithmic(double x) { + + final double x1 = x - ONE; + final double xa = x1 + (A + HALF); + + double xs = C[0]; + for (int i = C.length - 1; i > 0; i--) { + xs += C[i] / (x1 + i); } + + return ((((x1 + HALF) * LOG.invoke(xa)) + LOG_SQRT_TWO_PI) - xa) + LOG.invoke(xs); } + } - private GammaFunction() { + public static ComplexNumber gamma(final ComplexNumber z) { + return GammaFunction.LanczosApproximation.gamma(z); + } + + public static double gamma(final double x) { + return GammaFunction.LanczosApproximation.gamma(x); + } + + public static double gamma(final int n) { + if (n < 1) { + throw new IllegalArgumentException(); + } + return MissingMath.factorial(n - 1); } } diff --git a/src/org/ojalgo/function/special/HypergeometricFunction.java b/src/org/ojalgo/function/special/HypergeometricFunction.java new file mode 100644 index 000000000..230482372 --- /dev/null +++ b/src/org/ojalgo/function/special/HypergeometricFunction.java @@ -0,0 +1,45 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +public class HypergeometricFunction { + + public static double hypergeometric(final double a, final double b, final double c, final double x) { + + double incr = ONE; + double sum = ONE; + + double a1 = a - ONE; + double b1 = b - ONE; + double c1 = c - ONE; + + for (int n = 1; n < 100_000; n++) { + incr *= ((a1 + n) * (b1 + n) * x) / ((c1 + n) * n); + sum += incr; + } + + return sum; + } + +} diff --git a/src/org/ojalgo/function/special/MissingMath.java b/src/org/ojalgo/function/special/MissingMath.java index be00c5814..1f6dccf4a 100644 --- a/src/org/ojalgo/function/special/MissingMath.java +++ b/src/org/ojalgo/function/special/MissingMath.java @@ -21,6 +21,8 @@ */ package org.ojalgo.function.special; +import static org.ojalgo.function.constant.PrimitiveMath.*; + import java.math.BigDecimal; import java.math.MathContext; @@ -42,6 +44,24 @@ public static BigDecimal divide(final BigDecimal numerator, final BigDecimal den return numerator.divide(denominator, MathContext.DECIMAL128); } + /** + * 13! does not fit in an int, and 21! does not fit in a + * long - that's why this method returns a double. + */ + public static double factorial(final int arg) { + if (arg < 0) { + throw new IllegalArgumentException(); + } else if (arg < 2) { + return ONE; + } else if (arg < 13) { + return MissingMath.factorialInt(arg); + } else if (arg < 21) { + return MissingMath.factorialLong(arg); + } else { + return MissingMath.factorialDouble(arg); + } + } + /** * Greatest Common Denominator */ @@ -440,4 +460,28 @@ public static int toMinIntExact(final long a, final long b, final long c, final return Math.toIntExact(MissingMath.min(a, b, c, d)); } + static double factorialDouble(final int arg) { + double retVal = ONE; + for (int i = 2; i <= arg; i++) { + retVal *= i; + } + return retVal; + } + + static int factorialInt(final int arg) { + int retVal = 1; + for (int i = 2; i <= arg; i++) { + retVal *= i; + } + return retVal; + } + + static long factorialLong(final int arg) { + long retVal = 1L; + for (int i = 2; i <= arg; i++) { + retVal *= i; + } + return retVal; + } + } diff --git a/src/org/ojalgo/function/special/PochhammerSymbol.java b/src/org/ojalgo/function/special/PochhammerSymbol.java new file mode 100644 index 000000000..95e16e671 --- /dev/null +++ b/src/org/ojalgo/function/special/PochhammerSymbol.java @@ -0,0 +1,40 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +/** + * http://mathworld.wolfram.com/PochhammerSymbol.html + * https://en.wikipedia.org/wiki/Falling_and_rising_factorials + */ +public abstract class PochhammerSymbol { + + public static double pochhammer(final double x, final int n) { + double retVal = ONE; + for (int i = 0; i < n; i++) { + retVal *= (x + i); + } + return retVal; + } + +} diff --git a/src/org/ojalgo/matrix/task/AbstractInverter.java b/src/org/ojalgo/matrix/task/AbstractInverter.java index 4a8970510..46ecd3e68 100644 --- a/src/org/ojalgo/matrix/task/AbstractInverter.java +++ b/src/org/ojalgo/matrix/task/AbstractInverter.java @@ -363,8 +363,8 @@ static void full5X5(final Access2D source, final PhysicalStore destination double tmp34 = source.doubleValue(23L); double tmp44 = source.doubleValue(24L); - final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp03, tmp04, tmp10, tmp11, tmp12, tmp13, tmp14, tmp20, tmp21, tmp22, tmp23, tmp24, - tmp30, tmp31, tmp32, tmp33, tmp34, tmp40, tmp41, tmp42, tmp43, tmp44); + final double tmpScale = MissingMath.norm(tmp00, tmp01, tmp02, tmp03, tmp04, tmp10, tmp11, tmp12, tmp13, tmp14, tmp20, tmp21, tmp22, tmp23, tmp24, tmp30, + tmp31, tmp32, tmp33, tmp34, tmp40, tmp41, tmp42, tmp43, tmp44); tmp00 /= tmpScale; tmp10 /= tmpScale; diff --git a/src/org/ojalgo/random/Poisson.java b/src/org/ojalgo/random/Poisson.java index 6fb632496..be7e5d1a3 100644 --- a/src/org/ojalgo/random/Poisson.java +++ b/src/org/ojalgo/random/Poisson.java @@ -24,7 +24,7 @@ import static org.ojalgo.function.constant.PrimitiveMath.*; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.function.special.CombinatorialFunctions; +import org.ojalgo.function.special.MissingMath; /** * The Poisson distribution is a discrete probability distribution that expresses the probability of a given @@ -62,7 +62,7 @@ public double getExpected() { } public double getProbability(final int value) { - return (PrimitiveMath.EXP.invoke(-myLambda) * PrimitiveMath.POW.invoke(myLambda, value)) / CombinatorialFunctions.factorial(value); + return (PrimitiveMath.EXP.invoke(-myLambda) * PrimitiveMath.POW.invoke(myLambda, value)) / MissingMath.factorial(value); } @Override diff --git a/src/org/ojalgo/random/RandomUtils.java b/src/org/ojalgo/random/RandomUtils.java index a704bba93..0b6ca27bc 100644 --- a/src/org/ojalgo/random/RandomUtils.java +++ b/src/org/ojalgo/random/RandomUtils.java @@ -24,6 +24,7 @@ import org.ojalgo.function.special.CombinatorialFunctions; import org.ojalgo.function.special.ErrorFunction; import org.ojalgo.function.special.GammaFunction; +import org.ojalgo.function.special.MissingMath; /** * RandomUtils @@ -83,11 +84,11 @@ public static double erfi(final double arg) { } /** - * @deprecated v48 Use {@link CombinatorialFunctions#factorial(int)} instead + * @deprecated v48 Use {@link MissingMath#factorial(int)} instead */ @Deprecated public static double factorial(final int aVal) { - return CombinatorialFunctions.factorial(aVal); + return MissingMath.factorial(aVal); } /** @@ -110,7 +111,7 @@ public static double gamma(final double arg) { */ @Deprecated public static int partitions(final int n, final int[] k) { - return CombinatorialFunctions.partitions(n, k); + return Math.toIntExact(CombinatorialFunctions.partitions(n, k)); } /** @@ -120,7 +121,7 @@ public static int partitions(final int n, final int[] k) { */ @Deprecated public static int permutations(final int n) { - return CombinatorialFunctions.permutations(n); + return Math.toIntExact(CombinatorialFunctions.permutations(n)); } /** @@ -131,7 +132,7 @@ public static int permutations(final int n) { */ @Deprecated public static int subsets(final int n, final int k) { - return CombinatorialFunctions.subsets(n, k); + return Math.toIntExact(CombinatorialFunctions.subsets(n, k)); } /** @@ -142,7 +143,7 @@ public static int subsets(final int n, final int k) { */ @Deprecated public static int variations(final int n, final int k) { - return CombinatorialFunctions.variations(n, k); + return Math.toIntExact(CombinatorialFunctions.variations(n, k)); } private RandomUtils() { diff --git a/src/org/ojalgo/random/TDistribution.java b/src/org/ojalgo/random/TDistribution.java index 70ba7ad68..e30d06189 100644 --- a/src/org/ojalgo/random/TDistribution.java +++ b/src/org/ojalgo/random/TDistribution.java @@ -24,6 +24,7 @@ import static org.ojalgo.function.constant.PrimitiveMath.*; import org.ojalgo.function.special.GammaFunction; +import org.ojalgo.function.special.HypergeometricFunction; public class TDistribution extends AbstractContinuous { @@ -59,7 +60,7 @@ protected double generate() { static final class Degree2 extends TDistribution { - public Degree2() { + Degree2() { super(TWO); } @@ -83,7 +84,7 @@ public double getQuantile(final double probability) { static final class Degree3 extends TDistribution { - public Degree3() { + Degree3() { super(THREE); } @@ -96,7 +97,7 @@ public double getDensity(final double value) { static final class Degree4 extends TDistribution { - public Degree4() { + Degree4() { super(FOUR); } @@ -114,7 +115,7 @@ static final class DegreeInfinity extends TDistribution { private final Normal myNormal = new Normal(); - public DegreeInfinity() { + DegreeInfinity() { super(POSITIVE_INFINITY); } @@ -140,6 +141,14 @@ protected double generate() { } + /** + * @deprecated v48 + */ + @Deprecated + public static TDistribution make(final int degreesOfFreedom) { + return TDistribution.of(degreesOfFreedom); + } + public static TDistribution of(final int degreesOfFreedom) { switch (degreesOfFreedom) { case 1: @@ -157,24 +166,17 @@ public static TDistribution of(final int degreesOfFreedom) { } } - /** - * @deprecated v48 - */ - @Deprecated - public static TDistribution make(final int degreesOfFreedom) { - return TDistribution.of(degreesOfFreedom); - } - /** * The density and distribution functions share a common constant factor */ private final double myConstant; private final double myDegreesOfFreedom; - public TDistribution(final double degreesOfFreedom) { + TDistribution(final double degreesOfFreedom) { super(); - myDegreesOfFreedom = degreesOfFreedom; - myConstant = GammaFunction.gamma((degreesOfFreedom + ONE) / TWO) / (Math.sqrt(degreesOfFreedom * PI) * GammaFunction.gamma(degreesOfFreedom / TWO)); + myDegreesOfFreedom = Math.min(100, degreesOfFreedom); + myConstant = GammaFunction.gamma((myDegreesOfFreedom + ONE) / TWO) + / (Math.sqrt(myDegreesOfFreedom * PI) * GammaFunction.gamma(myDegreesOfFreedom / TWO)); } public double getDensity(final double value) { @@ -182,8 +184,8 @@ public double getDensity(final double value) { } public double getDistribution(final double value) { - // TODO Auto-generated method stub - return 0; + return HALF + (value * myConstant + * HypergeometricFunction.hypergeometric(HALF, (myDegreesOfFreedom - ONE) / TWO, THREE / TWO, -(value * value) / myDegreesOfFreedom)); } public double getExpected() { @@ -196,7 +198,7 @@ public double getExpected() { public double getQuantile(final double probability) { // TODO Auto-generated method stub - return 0; + return NaN; } @Override diff --git a/test/org/ojalgo/function/special/BetaFunctionTest.java b/test/org/ojalgo/function/special/BetaFunctionTest.java new file mode 100644 index 000000000..99e315675 --- /dev/null +++ b/test/org/ojalgo/function/special/BetaFunctionTest.java @@ -0,0 +1,94 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; +import org.ojalgo.scalar.ComplexNumber; +import org.ojalgo.type.StandardType; + +public class BetaFunctionTest { + + @Test + public void testCompareImplementations() { + + int lim = 50; + for (int a = 1; a < lim; a++) { + for (int b = 1; b < lim; b++) { + + double intResult = BetaFunction.beta(a, b); + double doubleResult = BetaFunction.beta((double) a, (double) b); + ComplexNumber complexResult = BetaFunction.beta(ComplexNumber.valueOf(a), ComplexNumber.valueOf(b)); + + TestUtils.assertEquals(intResult, doubleResult); + TestUtils.assertEquals(intResult, complexResult); + } + } + } + + @Test + public void testIdentities() { + + int lim = 50; + for (int a = 1; a < lim; a++) { + for (int b = 1; b < lim; b++) { + TestUtils.assertEquals(BetaFunction.beta(a, b), BetaFunction.beta(a + 1, b) + BetaFunction.beta(a, b + 1)); + TestUtils.assertEquals(BetaFunction.beta(a + 1, b), (BetaFunction.beta(a, b) * a) / (a + b)); + TestUtils.assertEquals(BetaFunction.beta(a, b + 1), (BetaFunction.beta(a, b) * b) / (a + b)); + } + } + + } + + @Test + public void testIncompleteReducesToTheUsualBetaFunction() { + int lim = 15; + for (int a = 1; a < lim; a++) { + for (int b = 1; b < lim; b++) { + TestUtils.assertEquals("a=" + a + ", b=" + b, BetaFunction.beta(a, b), BetaFunction.Incomplete.beta(ONE, a, b), StandardType.MATH_032); + } + } + } + + @Test + public void testRegularizedReducesToTheUsualBetaFunction() { + int lim = 15; + for (int a = 1; a < lim; a++) { + for (int b = 1; b < lim; b++) { + TestUtils.assertEquals("a=" + a + ", b=" + b, ONE, BetaFunction.Regularized.beta(ONE, a, b), StandardType.MATH_032); + } + } + } + + @Test + public void testIncompleteZeroIntegral() { + int lim = 50; + for (int a = 1; a < lim; a++) { + for (int b = 1; b < lim; b++) { + TestUtils.assertEquals("a=" + a + ", b=" + b, ZERO, BetaFunction.Incomplete.beta(ZERO, a, b)); + } + } + } + +} diff --git a/test/org/ojalgo/function/special/GammaFunctionTest.java b/test/org/ojalgo/function/special/GammaFunctionTest.java new file mode 100644 index 000000000..49978d6d4 --- /dev/null +++ b/test/org/ojalgo/function/special/GammaFunctionTest.java @@ -0,0 +1,213 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; +import org.ojalgo.scalar.ComplexNumber; +import org.ojalgo.type.StandardType; +import org.ojalgo.type.context.NumberContext; + +public class GammaFunctionTest { + + @Test + public void testCompareImplementations() { + + int lim = 50; + for (int a = 1; a < lim; a++) { + + double intResult = GammaFunction.gamma(a); + double doubleResult = GammaFunction.gamma((double) a); + ComplexNumber complexResult = GammaFunction.gamma(ComplexNumber.valueOf(a)); + + TestUtils.assertEquals(intResult, doubleResult); + TestUtils.assertEquals(intResult, complexResult); + } + } + + @Test + public void testCompareLogarithmicImplementations() { + + int lim = 50; + for (int a = 1; a < lim; a++) { + + double intResult = GammaFunction.Logarithmic.gamma(a); + double doubleResult = GammaFunction.Logarithmic.gamma((double) a); + ComplexNumber complexResult = GammaFunction.Logarithmic.gamma(ComplexNumber.valueOf(a)); + + TestUtils.assertEquals(intResult, doubleResult); + TestUtils.assertEquals(intResult, complexResult); + } + } + + @Test + public void testGammaFunction() { + + final double tmpEps = 0.000005; + + // From a table of values 1.0 <= x <= 2.0 + TestUtils.assertEquals(ONE, GammaFunction.gamma(1.0), 1E-14 / THREE); + TestUtils.assertEquals(0.95135, GammaFunction.gamma(1.10), tmpEps); + TestUtils.assertEquals(0.91817, GammaFunction.gamma(1.20), tmpEps); + TestUtils.assertEquals(0.89747, GammaFunction.gamma(1.30), tmpEps); + TestUtils.assertEquals(0.88726, GammaFunction.gamma(1.40), tmpEps); + TestUtils.assertEquals(0.88623, GammaFunction.gamma(1.50), tmpEps); + TestUtils.assertEquals(0.89352, GammaFunction.gamma(1.60), tmpEps); + TestUtils.assertEquals(0.90864, GammaFunction.gamma(1.70), tmpEps); + TestUtils.assertEquals(0.93138, GammaFunction.gamma(1.80), tmpEps); + TestUtils.assertEquals(0.96177, GammaFunction.gamma(1.90), tmpEps); + TestUtils.assertEquals(ONE, GammaFunction.gamma(2.0), 1E-14 / THREE); + + // Values larger than 2.0 and smaller than 1.0 + TestUtils.assertEquals("π", GammaFunction.gamma(PI), (PI - ONE) * (PI - TWO) * GammaFunction.gamma(PI - TWO), 1E-14 / THREE); + TestUtils.assertEquals("0.5", GammaFunction.gamma(HALF), GammaFunction.gamma(HALF + ONE) / HALF, 1E-14 / THREE); + TestUtils.assertEquals("0.25", GammaFunction.gamma(QUARTER), GammaFunction.gamma(QUARTER + ONE) / QUARTER, 1E-14 / THREE); + TestUtils.assertEquals("0.1", GammaFunction.gamma(TENTH), GammaFunction.gamma(TENTH + ONE) / TENTH, tmpEps); + TestUtils.assertEquals("0.01", GammaFunction.gamma(HUNDREDTH), GammaFunction.gamma(HUNDREDTH + ONE) / HUNDREDTH, tmpEps); + TestUtils.assertEquals("0.001", GammaFunction.gamma(THOUSANDTH), GammaFunction.gamma(THOUSANDTH + ONE) / THOUSANDTH, tmpEps); + + // Should align with n! for positve integers + for (int n = 0; n < 10; n++) { + TestUtils.assertEquals("n!:" + n, MissingMath.factorial(n), GammaFunction.gamma(n + ONE), tmpEps); + } + + // Negative values + TestUtils.assertEquals("-0.5", GammaFunction.gamma(-0.5), GammaFunction.gamma(HALF) / (-0.5), tmpEps); + TestUtils.assertEquals("-1.5", GammaFunction.gamma(-1.5), GammaFunction.gamma(HALF) / (-1.5 * -0.5), tmpEps); + TestUtils.assertEquals("-2.5", GammaFunction.gamma(-2.5), GammaFunction.gamma(HALF) / (-2.5 * -1.5 * -0.5), tmpEps); + TestUtils.assertEquals("-3.5", GammaFunction.gamma(-3.5), GammaFunction.gamma(HALF) / (-3.5 * -2.5 * -1.5 * -0.5), tmpEps); + TestUtils.assertEquals("-4.5", GammaFunction.gamma(-4.5), GammaFunction.gamma(HALF) / (-4.5 * -3.5 * -2.5 * -1.5 * -0.5), tmpEps); + + // Should be undefined for 0, -1, -2, -3... + for (int n = 0; n < 10; n++) { + TestUtils.assertTrue("-" + n, Double.isNaN(GammaFunction.gamma(NEG * n))); + } + + final NumberContext tmpEval = new NumberContext(10, 10); + + // Positive half integer + for (int n = 0; n < 10; n++) { + TestUtils.assertEquals(n + ".5", (SQRT_PI * MissingMath.factorial(2 * n)) / (POW.invoke(FOUR, n) * MissingMath.factorial(n)), + GammaFunction.gamma(n + HALF), tmpEval); + } + + } + + @Test + public void testIntIncompleteParts() { + + int lim = 50; + for (int n = 1; n < lim; n++) { + + for (int e = -2; e <= 2; e++) { + double x = Math.pow(TEN, e); + + double complete = GammaFunction.gamma(n); + + double lower = GammaFunction.Incomplete.lower(n, x); + double upper = GammaFunction.Incomplete.upper(n, x); + + TestUtils.assertEquals(complete, lower + upper); + } + } + } + + @Test + public void testIntIncompleteSteps() { + + NumberContext accuracy = StandardType.MATH_032; + + int lim = 5; + for (int n = 1; n < lim; n++) { + + for (int e = -1; e <= 1; e++) { + double x = Math.pow(TEN, e); + + double lowExp = (n * GammaFunction.Incomplete.lower(n, x)) - (Math.pow(x, n) * Math.exp(-x)); + double lowAct = GammaFunction.Incomplete.lower(n + 1, x); + + TestUtils.assertEquals(lowExp, lowAct, accuracy); + + double uppExp = (n * GammaFunction.Incomplete.upper(n, x)) + (Math.pow(x, n) * Math.exp(-x)); + double uppAct = GammaFunction.Incomplete.upper(n + 1, x); + + TestUtils.assertEquals(uppExp, uppAct, accuracy); + } + } + } + + @Test + public void testLogarithmic() { + + int lim = 50; + for (int a = 1; a < lim; a++) { + double x = a / TEN; + + double expected = Math.log(GammaFunction.gamma(x)); + double actual = GammaFunction.Logarithmic.gamma(x); + + TestUtils.assertEquals(expected, actual); + } + } + + @Test + public void testSpecialCeseLimitZero() { + + double x = ZERO; + + int lim = 50; + for (int n = 1; n < lim; n++) { + + double complete = GammaFunction.gamma(n); + + double lower = GammaFunction.Incomplete.lower(n, x); + double upper = GammaFunction.Incomplete.upper(n, x); + + TestUtils.assertEquals(complete, upper); + TestUtils.assertEquals(ZERO, lower); + TestUtils.assertEquals(complete, lower + upper); + } + } + + @Test + public void testSpecialCeseValueOne() { + + int n = 1; + + for (int e = -2; e <= 2; e++) { + double x = Math.pow(TEN, e); + + double lowExp = ONE - Math.exp(-x); + double lowAct = GammaFunction.Incomplete.lower(n, x); + + TestUtils.assertEquals(lowExp, lowAct); + + double uppExp = Math.exp(-x); + double uppAct = GammaFunction.Incomplete.upper(n, x); + + TestUtils.assertEquals(uppExp, uppAct); + } + } + +} diff --git a/test/org/ojalgo/function/special/HypergeometricFunctionTest.java b/test/org/ojalgo/function/special/HypergeometricFunctionTest.java new file mode 100644 index 000000000..d2ec8d092 --- /dev/null +++ b/test/org/ojalgo/function/special/HypergeometricFunctionTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +import java.util.Random; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; + +public class HypergeometricFunctionTest { + + private static final Random RANDOM = new Random(); + + @Test + public void testKnownValues() { + + // http://mathworld.wolfram.com/HypergeometricFunction.html + + // M. Trott, pers. comm., Aug. 5, 2002; Zucker and Joyce 2001 + TestUtils.assertEquals(EIGHT / FIVE, HypergeometricFunction.hypergeometric(THIRD, TWO_THIRDS, FIVE / SIX, 27.0 / 32.0)); + TestUtils.assertEquals(NINE / FIVE, HypergeometricFunction.hypergeometric(QUARTER, HALF, THREE_QUARTERS, 80.0 / 81.0)); + + // Zucker and Joyce 2001 + TestUtils.assertEquals(Math.sqrt(SEVEN) * TWO_THIRDS, HypergeometricFunction.hypergeometric(EIGHTH, THREE / EIGHT, HALF, 2400.0 / 2401.0)); + TestUtils.assertEquals(Math.sqrt(THREE) * THREE_QUARTERS, HypergeometricFunction.hypergeometric(SIXTH, THIRD, HALF, 25.0 / 27.0)); + + // Zucker and Joyce 2001, 2003 + TestUtils.assertEquals((Math.pow(TWO, SIXTH) * FOUR) / THREE, HypergeometricFunction.hypergeometric(SIXTH, HALF, TWO_THIRDS, 125.0 / 128.0)); + TestUtils.assertEquals((Math.pow(ELEVEN, QUARTER) * THREE) / FOUR, + HypergeometricFunction.hypergeometric(TWELFTH, FIVE / TWELVE, HALF, 1323.0 / 1331.0)); + + } + + @Test + public void testRepresentationAsinX() { + RANDOM.doubles(10, -1, 1).forEach(x -> { + TestUtils.assertEquals(Math.asin(x), x * HypergeometricFunction.hypergeometric(HALF, HALF, THREE / TWO, x * x)); + }); + } + + @Test + public void testRepresentationLogOnePlusX() { + RANDOM.doubles(10).forEach(x -> { + TestUtils.assertEquals(Math.log(ONE + x), x * HypergeometricFunction.hypergeometric(ONE, ONE, TWO, -x)); + }); + } + + @Test + public void testSpecialArguments111() { + RANDOM.doubles(10).forEach(x -> { + TestUtils.assertEquals(ONE / (ONE - x), HypergeometricFunction.hypergeometric(ONE, ONE, ONE, x)); + }); + } + + @Test + public void testSpecialArguments112() { + RANDOM.doubles(10).forEach(x -> { + TestUtils.assertEquals(-Math.log(ONE - x) / x, HypergeometricFunction.hypergeometric(ONE, ONE, TWO, x)); + }); + } + + @Test + public void testSpecialArguments121() { + RANDOM.doubles(10).forEach(x -> { + TestUtils.assertEquals(ONE / ((ONE - x) * (ONE - x)), HypergeometricFunction.hypergeometric(ONE, TWO, ONE, x)); + }); + + } + + @Test + public void testSpecialArguments122() { + RANDOM.doubles(10).forEach(x -> { + TestUtils.assertEquals(ONE / (ONE - x), HypergeometricFunction.hypergeometric(ONE, TWO, TWO, x)); + }); + } + +} diff --git a/test/org/ojalgo/function/special/PochhammerSymbolTest.java b/test/org/ojalgo/function/special/PochhammerSymbolTest.java new file mode 100644 index 000000000..2024ee432 --- /dev/null +++ b/test/org/ojalgo/function/special/PochhammerSymbolTest.java @@ -0,0 +1,81 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.function.special; + +import java.util.Random; +import java.util.function.DoubleConsumer; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; + +public class PochhammerSymbolTest { + + private static final Random RANDOM = new Random(); + + private static void compareToGammaImplementation(double x, int n) { + TestUtils.assertEquals("x=" + x + ", n=" + n, GammaFunction.gamma(x + n) / GammaFunction.gamma(x), PochhammerSymbol.pochhammer(x, n)); + } + + static void doTestDefinition(double x) { + PochhammerSymbolTest.compareToGammaImplementation(x, 0); + PochhammerSymbolTest.compareToGammaImplementation(x, 1); + PochhammerSymbolTest.compareToGammaImplementation(x, 2); + PochhammerSymbolTest.compareToGammaImplementation(x, 5); + PochhammerSymbolTest.compareToGammaImplementation(x, 10); + PochhammerSymbolTest.compareToGammaImplementation(x, 20); + PochhammerSymbolTest.compareToGammaImplementation(x, 50); + } + + static void doTestImplementation(double x) { + TestUtils.assertEquals(1.0, PochhammerSymbol.pochhammer(x, 0)); + TestUtils.assertEquals(x, PochhammerSymbol.pochhammer(x, 1)); + TestUtils.assertEquals((x * x) + x, PochhammerSymbol.pochhammer(x, 2)); + TestUtils.assertEquals((x * x * x) + (3.0 * x * x) + (2 * x), PochhammerSymbol.pochhammer(x, 3)); + TestUtils.assertEquals((x * x * x * x) + (6.0 * x * x * x) + (11.0 * x * x) + (6 * x), PochhammerSymbol.pochhammer(x, 4)); + } + + static void performTest(DoubleConsumer testFunction) { + RANDOM.doubles(10, -1.0, 1.0).forEach(testFunction); + RANDOM.doubles(10, -2.0, 2.0).forEach(testFunction); + RANDOM.doubles(10, -5.0, 5.0).forEach(testFunction); + RANDOM.doubles(10, -10.0, 10.0).forEach(testFunction); + RANDOM.doubles(10, -20.0, 20.0).forEach(testFunction); + RANDOM.doubles(10, -50.0, 50.0).forEach(testFunction); + } + + /** + * Test against alternative definition using the gamma function + */ + @Test + public void testDefinition() { + PochhammerSymbolTest.performTest(PochhammerSymbolTest::doTestDefinition); + } + + /** + * Test against first few known explicit values + */ + @Test + public void testImplementation() { + PochhammerSymbolTest.performTest(PochhammerSymbolTest::doTestImplementation); + } + +} diff --git a/test/org/ojalgo/random/RandomNumberTest.java b/test/org/ojalgo/random/RandomNumberTest.java index d51809ea9..9a793a935 100644 --- a/test/org/ojalgo/random/RandomNumberTest.java +++ b/test/org/ojalgo/random/RandomNumberTest.java @@ -28,9 +28,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.array.Primitive64Array; -import org.ojalgo.function.special.CombinatorialFunctions; import org.ojalgo.function.special.ErrorFunction; -import org.ojalgo.function.special.GammaFunction; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.series.CalendarDateSeries; @@ -252,59 +250,6 @@ public void testGamma() { this.testDist2(new Dist2Gamma(), new double[] { .01, .01 }, new double[] { 10, 10 }, new double[] { 100, 100 }, 200000, .15); } - @Test - public void testGammaFunction() { - - final double tmpEps = 0.000005; - - // From a table of values 1.0 <= x <= 2.0 - TestUtils.assertEquals(ONE, GammaFunction.gamma(1.0), 1E-14 / THREE); - TestUtils.assertEquals(0.95135, GammaFunction.gamma(1.10), tmpEps); - TestUtils.assertEquals(0.91817, GammaFunction.gamma(1.20), tmpEps); - TestUtils.assertEquals(0.89747, GammaFunction.gamma(1.30), tmpEps); - TestUtils.assertEquals(0.88726, GammaFunction.gamma(1.40), tmpEps); - TestUtils.assertEquals(0.88623, GammaFunction.gamma(1.50), tmpEps); - TestUtils.assertEquals(0.89352, GammaFunction.gamma(1.60), tmpEps); - TestUtils.assertEquals(0.90864, GammaFunction.gamma(1.70), tmpEps); - TestUtils.assertEquals(0.93138, GammaFunction.gamma(1.80), tmpEps); - TestUtils.assertEquals(0.96177, GammaFunction.gamma(1.90), tmpEps); - TestUtils.assertEquals(ONE, GammaFunction.gamma(2.0), 1E-14 / THREE); - - // Values larger than 2.0 and smaller than 1.0 - TestUtils.assertEquals("π", GammaFunction.gamma(PI), (PI - ONE) * (PI - TWO) * GammaFunction.gamma(PI - TWO), 1E-14 / THREE); - TestUtils.assertEquals("0.5", GammaFunction.gamma(HALF), GammaFunction.gamma(HALF + ONE) / HALF, 1E-14 / THREE); - TestUtils.assertEquals("0.25", GammaFunction.gamma(QUARTER), GammaFunction.gamma(QUARTER + ONE) / QUARTER, 1E-14 / THREE); - TestUtils.assertEquals("0.1", GammaFunction.gamma(TENTH), GammaFunction.gamma(TENTH + ONE) / TENTH, tmpEps); - TestUtils.assertEquals("0.01", GammaFunction.gamma(HUNDREDTH), GammaFunction.gamma(HUNDREDTH + ONE) / HUNDREDTH, tmpEps); - TestUtils.assertEquals("0.001", GammaFunction.gamma(THOUSANDTH), GammaFunction.gamma(THOUSANDTH + ONE) / THOUSANDTH, tmpEps); - - // Should align with n! for positve integers - for (int n = 0; n < 10; n++) { - TestUtils.assertEquals("n!:" + n, CombinatorialFunctions.factorial(n), GammaFunction.gamma(n + ONE), tmpEps); - } - - // Negative values - TestUtils.assertEquals("-0.5", GammaFunction.gamma(-0.5), GammaFunction.gamma(HALF) / (-0.5), tmpEps); - TestUtils.assertEquals("-1.5", GammaFunction.gamma(-1.5), GammaFunction.gamma(HALF) / (-1.5 * -0.5), tmpEps); - TestUtils.assertEquals("-2.5", GammaFunction.gamma(-2.5), GammaFunction.gamma(HALF) / (-2.5 * -1.5 * -0.5), tmpEps); - TestUtils.assertEquals("-3.5", GammaFunction.gamma(-3.5), GammaFunction.gamma(HALF) / (-3.5 * -2.5 * -1.5 * -0.5), tmpEps); - TestUtils.assertEquals("-4.5", GammaFunction.gamma(-4.5), GammaFunction.gamma(HALF) / (-4.5 * -3.5 * -2.5 * -1.5 * -0.5), tmpEps); - - // Should be undefined for 0, -1, -2, -3... - for (int n = 0; n < 10; n++) { - TestUtils.assertTrue("-" + n, Double.isNaN(GammaFunction.gamma(NEG * n))); - } - - final NumberContext tmpEval = new NumberContext(10, 10); - - // Positive half integer - for (int n = 0; n < 10; n++) { - TestUtils.assertEquals(n + ".5", (SQRT_PI * CombinatorialFunctions.factorial(2 * n)) / (POW.invoke(FOUR, n) * CombinatorialFunctions.factorial(n)), - GammaFunction.gamma(n + HALF), tmpEval); - } - - } - @Test @Tag("unstable") public void testGeometricMeanAndStandardDeviation() { diff --git a/test/org/ojalgo/random/TDistributionTest.java b/test/org/ojalgo/random/TDistributionTest.java new file mode 100644 index 000000000..39558df31 --- /dev/null +++ b/test/org/ojalgo/random/TDistributionTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.random; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; + +public class TDistributionTest { + + @Test + public void testAgainstSpecificVariants() { + + TDistribution s1 = new TDistribution.Degree1(); + TDistribution g1 = new TDistribution(1); + + TDistribution s2 = new TDistribution.Degree2(); + TDistribution g2 = new TDistribution(2); + + TDistribution s3 = new TDistribution.Degree3(); + TDistribution g3 = new TDistribution(3); + + TDistribution s4 = new TDistribution.Degree4(); + TDistribution g4 = new TDistribution(4); + + TDistribution sInf = new TDistribution.DegreeInfinity(); + TDistribution gInf = new TDistribution(Integer.MAX_VALUE); + + for (int x = -5; x <= 5; x++) { + + TestUtils.assertEquals("Density(1): " + x, s1.getDensity(x), g1.getDensity(x)); + //TestUtils.assertEquals("Distribution(1): " + x, s1.getDistribution(x), g1.getDistribution(x)); + + TestUtils.assertEquals("Density(2): " + x, s2.getDensity(x), g2.getDensity(x)); + //TestUtils.assertEquals("Distribution(2): " + x, s2.getDistribution(x), g2.getDistribution(x)); + + TestUtils.assertEquals("Density(3): " + x, s3.getDensity(x), g3.getDensity(x)); + TestUtils.assertEquals("Distribution(3): " + x, s3.getDistribution(x), g3.getDistribution(x)); + + TestUtils.assertEquals("Density(4): " + x, s4.getDensity(x), g4.getDensity(x)); + TestUtils.assertEquals("Distribution(4): " + x, s4.getDistribution(x), g4.getDistribution(x)); + + //TestUtils.assertEquals("Density(Inf): " + x, sInf.getDensity(x), gInf.getDensity(x)); + //TestUtils.assertEquals("Distribution(Inf): " + x, sInf.getDistribution(x), gInf.getDistribution(x)); + + } + + } + +} From 1cd39e5ef10fd2333f683cfbbb56e37edb3a12ae Mon Sep 17 00:00:00 2001 From: apete Date: Fri, 18 Oct 2019 19:56:54 +0200 Subject: [PATCH 19/29] Update TestUtils.java --- test/org/ojalgo/TestUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/org/ojalgo/TestUtils.java b/test/org/ojalgo/TestUtils.java index 4f9fceb30..498a6ccfb 100644 --- a/test/org/ojalgo/TestUtils.java +++ b/test/org/ojalgo/TestUtils.java @@ -386,6 +386,22 @@ public static void assertNotNullOrEmpty(final String actual) { } } + public static void assertResult(final Optimisation.Result expected, final Optimisation.Result actual) { + TestUtils.assertResult(expected, actual, EQUALS); + } + + public static void assertResult(final Optimisation.Result expected, final Optimisation.Result actual, final NumberContext context) { + TestUtils.assertResult("Optimisation.Result != Optimisation.Result", expected, actual, context); + } + + public static void assertResult(final String message, final Optimisation.Result expected, final Optimisation.Result actual) { + TestUtils.assertResult(message, expected, actual, EQUALS); + } + + public static void assertResult(final String message, final Optimisation.Result expected, final Optimisation.Result actual, final NumberContext context) { + TestUtils.assertOptimisationResult(message, expected, actual, context, true, true, true, true); + } + public static void assertSolutionFeasible(final ExpressionsBasedModel model, final Optimisation.Result solution) { TestUtils.assertSolutionFeasible(model, solution, EQUALS); } From a6ac88d0ad878791c84ad2aae5f40033453e877c Mon Sep 17 00:00:00 2001 From: apete Date: Sat, 2 Nov 2019 09:43:44 +0100 Subject: [PATCH 20/29] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 6a27bbd1f..874c49bc9 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,10 @@ ojAlgo is Open Source, and you are strongly encouraged to clone or fork this rep Tidelift Subscription [Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=readme) + +## org.ojalgo:ojalgo for enterprise + +Available as part of the Tidelift Subscription + +The maintainers of org.ojalgo:ojalgo and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) + From 26612182e1f3b4db556bf86dc90c9809023ebe8e Mon Sep 17 00:00:00 2001 From: apete Date: Sat, 2 Nov 2019 11:04:31 +0100 Subject: [PATCH 21/29] Update README.md --- README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 874c49bc9..df4998bcf 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,6 @@ ojAlgo is available at [The Central (Maven) Repository](https://search.maven.org X.Y.Z ``` -...or download the jar from SourceForge. -

-Download oj! Algorithms -

### Documentation and Support @@ -36,11 +32,9 @@ ojAlgo is Open Source, and you are strongly encouraged to clone or fork this rep Tidelift Subscription -[Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=readme) - -## org.ojalgo:ojalgo for enterprise +### Enterprise-Grade Support Available as part of the Tidelift Subscription -The maintainers of org.ojalgo:ojalgo and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) +The maintainers of ojAlgo and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) From ad0430322c07a5ef48b62d10cac2a71274634f28 Mon Sep 17 00:00:00 2001 From: apete Date: Sat, 2 Nov 2019 11:05:39 +0100 Subject: [PATCH 22/29] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df4998bcf..890c0908c 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,11 @@ The [ojAlgo-user mailing list](https://sourceforge.net/p/ojalgo/mailman/ojalgo-u ojAlgo is Open Source, and you are strongly encouraged to clone or fork this repository and work directly with the source code. The source code is (part of) the documentation, and you should read it. -Tidelift Subscription - ### Enterprise-Grade Support Available as part of the Tidelift Subscription The maintainers of ojAlgo and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) +Tidelift Subscription + From 5d103fb99df5f61465fcac644d697efcda8db469 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Sun, 3 Nov 2019 12:41:01 +0100 Subject: [PATCH 23/29] No more java.lang.Number (#232) * N extends Comparable (#230) * It compiles * T & N * PrimitiveNumber * RandomNumber * Update CHANGELOG.md * Update SparsePerformance.java * Update SparsePerformance.java * Update BasicMatrix.java * Update BasicArray.java * float support (#231) * Step 1 * Update SparsePerformance.java * Update SparsePerformance.java * Update SparsePerformance.java * Primitive32Matrix * get/set/operate float * Update SparsePerformance.java * BasicMatrix tests step 1 * changes * transformations * Primitive32Store done * Update HouseholderLeft.java * matrix multiplication * More BasicMatrix tests * Update CHANGELOG.md * Create SpecialTest.java * java.lang.Number (#233) * extends Object * Removed a couple of more Number:s * Number -> Comparable * Remove serialVersionUID * Update README.md * Revert "Update README.md" This reverts commit 75219b4874eef3cfd1d6eb52b6e02845672f0d21. * Series comparable * final Scalar * Update CHANGELOG.md --- CHANGELOG.md | 50 + pom.xml | 2 +- rsrc/csv/example.csv | 15 + rsrc/csv/fast.csv | 22 + rsrc/csv/quoted.csv | 22 + src/org/ojalgo/algebra/Field.java | 2 +- src/org/ojalgo/algebra/Group.java | 8 +- src/org/ojalgo/algebra/NormedVectorSpace.java | 4 +- src/org/ojalgo/algebra/Ring.java | 2 +- src/org/ojalgo/algebra/ScalarOperation.java | 36 +- src/org/ojalgo/algebra/VectorSpace.java | 11 +- .../ojalgo/ann/ArtificialNeuralNetwork.java | 10 +- src/org/ojalgo/ann/CalculationLayer.java | 24 +- src/org/ojalgo/ann/NetworkBuilder.java | 10 +- src/org/ojalgo/array/Array1D.java | 84 +- src/org/ojalgo/array/Array2D.java | 191 ++- src/org/ojalgo/array/ArrayAnyD.java | 118 +- src/org/ojalgo/array/ArrayFactory.java | 6 +- src/org/ojalgo/array/BasicArray.java | 10 +- src/org/ojalgo/array/BigArray.java | 19 +- src/org/ojalgo/array/BufferArray.java | 25 +- src/org/ojalgo/array/DenseArray.java | 5 +- .../ojalgo/array/DenseCapacityStrategy.java | 2 +- src/org/ojalgo/array/LongToNumberMap.java | 19 +- src/org/ojalgo/array/NumberList.java | 65 +- src/org/ojalgo/array/PlainArray.java | 52 +- src/org/ojalgo/array/Primitive32Array.java | 36 +- src/org/ojalgo/array/Primitive64Array.java | 26 +- src/org/ojalgo/array/ReferenceTypeArray.java | 56 +- src/org/ojalgo/array/ScalarArray.java | 21 +- src/org/ojalgo/array/SegmentedArray.java | 44 +- src/org/ojalgo/array/SparseArray.java | 87 +- src/org/ojalgo/array/StrategyBuilder.java | 2 +- src/org/ojalgo/array/operation/AMAX.java | 4 +- src/org/ojalgo/array/operation/AXPY.java | 11 +- .../ojalgo/array/operation/ApplyCholesky.java | 3 +- src/org/ojalgo/array/operation/ApplyLDL.java | 4 +- src/org/ojalgo/array/operation/ApplyLU.java | 4 +- src/org/ojalgo/array/operation/DOT.java | 12 +- .../array/operation/FillMatchingSingle.java | 32 +- ...GenerateApplyAndCopyHouseholderColumn.java | 54 +- .../GenerateApplyAndCopyHouseholderRow.java | 55 +- .../array/operation/HermitianRank2Update.java | 3 +- .../array/operation/HouseholderHermitian.java | 4 +- .../array/operation/HouseholderLeft.java | 18 +- .../array/operation/HouseholderRight.java | 21 +- .../ojalgo/array/operation/MultiplyBoth.java | 90 +- .../operation/MultiplyHermitianAndVector.java | 2 +- .../ojalgo/array/operation/MultiplyLeft.java | 85 +- .../array/operation/MultiplyNeither.java | 77 +- .../ojalgo/array/operation/MultiplyRight.java | 80 +- .../ojalgo/array/operation/RotateLeft.java | 23 +- .../ojalgo/array/operation/RotateRight.java | 23 +- .../array/operation/SubstituteBackwards.java | 35 +- .../array/operation/SubstituteForwards.java | 38 +- .../ojalgo/concurrent/DivideAndConquer.java | 2 +- src/org/ojalgo/equation/Equation.java | 9 +- src/org/ojalgo/function/BasicFunction.java | 4 +- src/org/ojalgo/function/BigFunction.java | 20 + src/org/ojalgo/function/BinaryFunction.java | 29 +- src/org/ojalgo/function/ComplexFunction.java | 20 + src/org/ojalgo/function/FunctionSet.java | 2 +- src/org/ojalgo/function/FunctionUtils.java | 2 +- src/org/ojalgo/function/NullaryFunction.java | 3 +- .../ojalgo/function/ParameterFunction.java | 18 +- .../ojalgo/function/PredicateFunction.java | 8 +- .../ojalgo/function/PrimitiveFunction.java | 20 + .../ojalgo/function/QuaternionFunction.java | 20 + src/org/ojalgo/function/RationalFunction.java | 20 + src/org/ojalgo/function/UnaryFunction.java | 14 +- src/org/ojalgo/function/VoidFunction.java | 8 +- .../function/aggregator/Aggregator.java | 2 +- .../aggregator/AggregatorFunction.java | 2 +- .../function/aggregator/AggregatorSet.java | 2 +- .../function/aggregator/BigAggregator.java | 4 + .../aggregator/ComplexAggregator.java | 4 + .../aggregator/PrimitiveAggregator.java | 8 +- .../aggregator/QuaternionAggregator.java | 4 + .../aggregator/RationalAggregator.java | 4 + .../function/multiary/AffineFunction.java | 22 +- .../multiary/ApproximateFunction.java | 2 +- .../function/multiary/ConstantFunction.java | 28 +- .../multiary/FirstOrderApproximation.java | 2 +- .../function/multiary/LinearFunction.java | 20 +- .../function/multiary/MultiaryFunction.java | 18 +- .../multiary/PureQuadraticFunction.java | 22 +- .../function/multiary/QuadraticFunction.java | 22 +- .../multiary/SecondOrderApproximation.java | 2 +- .../polynomial/AbstractPolynomial.java | 25 +- .../function/polynomial/BigPolynomial.java | 6 +- .../polynomial/ComplexPolynomial.java | 6 +- .../polynomial/PolynomialFunction.java | 4 +- .../polynomial/PrimitivePolynomial.java | 6 +- .../polynomial/RationalPolynomial.java | 6 +- src/org/ojalgo/matrix/BasicMatrix.java | 77 +- src/org/ojalgo/matrix/ComplexMatrix.java | 22 +- src/org/ojalgo/matrix/MatrixFactory.java | 54 +- src/org/ojalgo/matrix/MatrixUtils.java | 42 +- ...tiveMatrix.java => Primitive32Matrix.java} | 46 +- src/org/ojalgo/matrix/Primitive64Matrix.java | 205 ++++ src/org/ojalgo/matrix/QuaternionMatrix.java | 4 +- src/org/ojalgo/matrix/RationalMatrix.java | 4 +- .../decomposition/AbstractDecomposition.java | 2 +- .../matrix/decomposition/Bidiagonal.java | 10 +- .../BidiagonalDecomposition.java | 14 +- .../ojalgo/matrix/decomposition/Cholesky.java | 10 +- .../decomposition/CholeskyDecomposition.java | 14 +- .../decomposition/DecompositionStore.java | 2 +- .../decomposition/DeferredTridiagonal.java | 14 +- .../matrix/decomposition/DynamicEvD.java | 6 +- .../matrix/decomposition/Eigenvalue.java | 28 +- .../EigenvalueDecomposition.java | 2 +- .../matrix/decomposition/GeneralEvD.java | 6 +- .../matrix/decomposition/GeneralisedEvD.java | 2 +- .../decomposition/GenericDecomposition.java | 2 +- .../matrix/decomposition/HermitianEvD.java | 14 +- .../matrix/decomposition/Hessenberg.java | 10 +- .../HessenbergDecomposition.java | 14 +- .../decomposition/InPlaceDecomposition.java | 2 +- src/org/ojalgo/matrix/decomposition/LDL.java | 10 +- .../decomposition/LDLDecomposition.java | 17 +- src/org/ojalgo/matrix/decomposition/LDU.java | 2 +- src/org/ojalgo/matrix/decomposition/LU.java | 10 +- .../matrix/decomposition/LUDecomposition.java | 17 +- .../decomposition/MatrixDecomposition.java | 18 +- src/org/ojalgo/matrix/decomposition/QR.java | 10 +- .../matrix/decomposition/QRDecomposition.java | 17 +- .../decomposition/RawDecomposition.java | 12 +- .../ojalgo/matrix/decomposition/RawLU.java | 2 +- .../ojalgo/matrix/decomposition/RawQR.java | 22 +- .../decomposition/RawSingularValue.java | 8 +- .../SimultaneousTridiagonal.java | 4 +- .../matrix/decomposition/SingularValue.java | 10 +- .../SingularValueDecomposition.java | 14 +- .../matrix/decomposition/Tridiagonal.java | 10 +- .../TridiagonalDecomposition.java | 2 +- .../matrix/geometry/GeometryMatrix.java | 6 +- .../matrix/geometry/GeometryVector.java | 21 +- .../matrix/geometry/Primitive32Vector2.java | 2 +- .../matrix/geometry/Primitive32Vector3.java | 2 +- .../matrix/geometry/Primitive32Vector4.java | 2 +- .../matrix/geometry/Primitive64Vector2.java | 2 +- .../matrix/geometry/Primitive64Vector3.java | 2 +- .../matrix/geometry/Primitive64Vector4.java | 2 +- .../ojalgo/matrix/store/AboveBelowStore.java | 2 +- .../ojalgo/matrix/store/AbstractStore.java | 2 +- src/org/ojalgo/matrix/store/ColumnsStore.java | 2 +- .../ojalgo/matrix/store/ColumnsSupplier.java | 8 +- .../ojalgo/matrix/store/ComposingStore.java | 2 +- .../ojalgo/matrix/store/ConjugatedStore.java | 2 +- .../ojalgo/matrix/store/DiagonalStore.java | 6 +- .../ojalgo/matrix/store/ElementsSupplier.java | 3 +- src/org/ojalgo/matrix/store/FactoryStore.java | 2 +- ...nericDenseStore.java => GenericStore.java} | 194 ++-- .../ojalgo/matrix/store/IdentityStore.java | 2 +- .../ojalgo/matrix/store/LeftRightStore.java | 2 +- src/org/ojalgo/matrix/store/LimitStore.java | 2 +- src/org/ojalgo/matrix/store/LogicalStore.java | 2 +- .../matrix/store/LowerHermitianStore.java | 2 +- .../matrix/store/LowerHessenbergStore.java | 2 +- .../matrix/store/LowerTriangularStore.java | 2 +- .../ojalgo/matrix/store/MatrixPipeline.java | 22 +- src/org/ojalgo/matrix/store/MatrixStore.java | 105 +- src/org/ojalgo/matrix/store/OffsetStore.java | 2 +- .../ojalgo/matrix/store/PhysicalStore.java | 6 +- .../ojalgo/matrix/store/Primitive32Store.java | 1024 +++++++++++++++++ ...eDenseStore.java => Primitive64Store.java} | 312 ++--- .../ojalgo/matrix/store/PrimitiveFactory.java | 84 ++ src/org/ojalgo/matrix/store/RawStore.java | 112 +- src/org/ojalgo/matrix/store/RowsStore.java | 2 +- src/org/ojalgo/matrix/store/RowsSupplier.java | 8 +- .../ojalgo/matrix/store/SelectingStore.java | 2 +- src/org/ojalgo/matrix/store/ShadingStore.java | 2 +- src/org/ojalgo/matrix/store/SingleStore.java | 9 +- src/org/ojalgo/matrix/store/SparseStore.java | 41 +- .../matrix/store/SuperimposedStore.java | 2 +- .../matrix/store/TransformableRegion.java | 74 +- .../matrix/store/TransjugatedStore.java | 2 +- .../ojalgo/matrix/store/TransposedStore.java | 2 +- .../matrix/store/UnaryOperatoStore.java | 2 +- .../matrix/store/UpperHermitianStore.java | 2 +- .../matrix/store/UpperHessenbergStore.java | 2 +- .../matrix/store/UpperTriangularStore.java | 2 +- src/org/ojalgo/matrix/store/WrapperStore.java | 2 +- src/org/ojalgo/matrix/store/ZeroStore.java | 2 +- .../ojalgo/matrix/task/AbstractInverter.java | 6 +- .../ojalgo/matrix/task/AbstractSolver.java | 10 +- .../ojalgo/matrix/task/DeterminantTask.java | 4 +- src/org/ojalgo/matrix/task/InverterTask.java | 4 +- src/org/ojalgo/matrix/task/MatrixTask.java | 2 +- src/org/ojalgo/matrix/task/SolverTask.java | 4 +- .../iterative/ConjugateGradientSolver.java | 34 +- .../task/iterative/IterativeSolverTask.java | 4 +- .../matrix/task/iterative/JacobiSolver.java | 8 +- .../matrix/transformation/Householder.java | 105 +- .../transformation/HouseholderColumn.java | 2 +- .../transformation/HouseholderReference.java | 8 +- .../matrix/transformation/HouseholderRow.java | 2 +- .../matrix/transformation/Rotation.java | 7 +- src/org/ojalgo/netio/BasicLogger.java | 8 +- src/org/ojalgo/netio/DelimitedData.java | 2 +- src/org/ojalgo/optimisation/Expression.java | 30 +- .../optimisation/ExpressionsBasedModel.java | 16 +- .../ojalgo/optimisation/GenericSolver.java | 4 +- .../ojalgo/optimisation/MathProgSysModel.java | 4 +- src/org/ojalgo/optimisation/ModelEntity.java | 15 +- src/org/ojalgo/optimisation/Variable.java | 6 +- .../optimisation/convex/ActiveSetSolver.java | 30 +- .../convex/ConstrainedSolver.java | 6 +- .../convex/ConvexObjectiveFunction.java | 2 +- .../optimisation/convex/ConvexSolver.java | 36 +- .../ojalgo/optimisation/convex/DirectASS.java | 10 +- .../optimisation/convex/IterativeASS.java | 10 +- .../ojalgo/optimisation/convex/QPESolver.java | 14 +- .../optimisation/integer/IntegerSolver.java | 6 +- .../optimisation/linear/LinearSolver.java | 16 +- .../optimisation/linear/SimplexSolver.java | 4 +- .../optimisation/linear/SimplexTableau.java | 71 +- src/org/ojalgo/random/Binomial.java | 2 - src/org/ojalgo/random/Deterministic.java | 12 +- src/org/ojalgo/random/Erlang.java | 2 - src/org/ojalgo/random/Exponential.java | 2 - src/org/ojalgo/random/Gamma.java | 2 - src/org/ojalgo/random/Geometric.java | 2 - src/org/ojalgo/random/LogNormal.java | 2 - src/org/ojalgo/random/Normal.java | 2 - src/org/ojalgo/random/Poisson.java | 2 - src/org/ojalgo/random/Random1D.java | 12 +- src/org/ojalgo/random/RandomNumber.java | 9 +- src/org/ojalgo/random/Uniform.java | 2 - src/org/ojalgo/random/Weibull.java | 2 - .../ojalgo/random/process/GaussianField.java | 22 +- src/org/ojalgo/scalar/BigScalar.java | 84 +- src/org/ojalgo/scalar/ComplexNumber.java | 244 ++-- src/org/ojalgo/scalar/ExactDecimal.java | 43 +- src/org/ojalgo/scalar/Money.java | 15 +- src/org/ojalgo/scalar/PrimitiveScalar.java | 95 +- src/org/ojalgo/scalar/Quaternion.java | 411 +++---- src/org/ojalgo/scalar/RationalNumber.java | 182 +-- src/org/ojalgo/scalar/Scalar.java | 82 +- src/org/ojalgo/series/BasicSeries.java | 18 +- src/org/ojalgo/series/CalendarDateSeries.java | 5 +- src/org/ojalgo/series/CoordinationSet.java | 2 +- src/org/ojalgo/series/MappedIndexSeries.java | 3 +- src/org/ojalgo/series/NumberSeries.java | 5 +- src/org/ojalgo/series/SeriesInterpolator.java | 4 +- src/org/ojalgo/series/TreeSeries.java | 8 +- .../series/function/SeriesExtrapolator.java | 4 +- .../series/function/SeriesForecaster.java | 6 +- .../series/function/SeriesFunction.java | 8 +- .../series/function/SeriesInterpolator.java | 4 +- .../series/primitive/CoordinatedSet.java | 6 +- src/org/ojalgo/structure/Access1D.java | 25 +- src/org/ojalgo/structure/Access2D.java | 20 +- src/org/ojalgo/structure/AccessAnyD.java | 16 +- src/org/ojalgo/structure/AccessScalar.java | 19 +- src/org/ojalgo/structure/ColumnView.java | 2 +- src/org/ojalgo/structure/ElementView1D.java | 2 +- src/org/ojalgo/structure/ElementView2D.java | 2 +- src/org/ojalgo/structure/Factory1D.java | 32 +- src/org/ojalgo/structure/Factory2D.java | 34 +- src/org/ojalgo/structure/FactoryAnyD.java | 27 + src/org/ojalgo/structure/Iterator1D.java | 2 +- src/org/ojalgo/structure/MatrixView.java | 2 +- src/org/ojalgo/structure/Mutate1D.java | 29 +- src/org/ojalgo/structure/Mutate2D.java | 95 +- src/org/ojalgo/structure/MutateAnyD.java | 49 +- src/org/ojalgo/structure/RowView.java | 3 +- src/org/ojalgo/structure/Stream1D.java | 2 +- src/org/ojalgo/structure/Stream2D.java | 2 +- src/org/ojalgo/structure/StreamAnyD.java | 2 +- .../ojalgo/structure/Transformation1D.java | 2 +- .../ojalgo/structure/Transformation2D.java | 2 +- .../ojalgo/structure/TransformationAnyD.java | 2 +- src/org/ojalgo/tensor/AnyTensor.java | 2 +- src/org/ojalgo/tensor/Tensor.java | 4 +- src/org/ojalgo/type/CalendarDateDuration.java | 2 +- src/org/ojalgo/type/ColourData.java | 2 +- src/org/ojalgo/type/ComparableNumber.java | 26 + src/org/ojalgo/type/NumberDefinition.java | 47 + src/org/ojalgo/type/PrimitiveNumber.java | 18 +- src/org/ojalgo/type/StandardType.java | 24 +- src/org/ojalgo/type/TypeUtils.java | 56 +- .../ojalgo/type/context/NumberContext.java | 13 +- .../type/format/TransformationFormat.java | 2 +- .../type/keyvalue/ComparableToObject.java | 2 +- src/org/ojalgo/type/keyvalue/IntToObject.java | 2 +- src/org/ojalgo/type/keyvalue/KeyValue.java | 2 +- .../ojalgo/type/keyvalue/LongToObject.java | 2 +- src/org/ojalgo/type/keyvalue/MapEntry.java | 2 +- .../ojalgo/type/keyvalue/StringToObject.java | 2 +- .../ojalgo/SymmetricEigenvalueProfiling.java | 4 +- test/org/ojalgo/TestUtils.java | 45 +- .../ojalgo/ann/BackPropagationExample.java | 24 +- test/org/ojalgo/ann/DesignTestANN.java | 6 +- .../ann/NeuralNetworkWorkedExample.java | 8 +- .../ojalgo/ann/NeuralNetworksDemystified.java | 6 +- .../ann/StepByStepBackpropagationExample.java | 8 +- .../array/operation/SubstitutionTest.java | 28 +- .../function/multiary/ApproximationCase.java | 20 +- .../ojalgo/function/multiary/LinearCase.java | 8 +- .../function/multiary/QuadraticCase.java | 8 +- test/org/ojalgo/matrix/BasicMatrixTest.java | 974 +++++++++------- .../org/ojalgo/matrix/LargerCholeskyCase.java | 28 +- test/org/ojalgo/matrix/NormTest.java | 6 +- test/org/ojalgo/matrix/P20030422Case.java | 64 +- test/org/ojalgo/matrix/P20030512Case.java | 57 +- test/org/ojalgo/matrix/P20030528Case.java | 22 +- test/org/ojalgo/matrix/P20050125Case.java | 36 +- test/org/ojalgo/matrix/P20050827Case.java | 22 +- test/org/ojalgo/matrix/P20061119Case.java | 58 +- test/org/ojalgo/matrix/P20071019Case.java | 30 +- test/org/ojalgo/matrix/ReductionTest.java | 8 +- .../org/ojalgo/matrix/SimpleCholeskyCase.java | 31 +- .../ojalgo/matrix/SimpleEigenvalueCase.java | 36 +- .../org/ojalgo/matrix/SimpleEquationCase.java | 16 +- test/org/ojalgo/matrix/SimpleLUCase.java | 27 +- .../ojalgo/matrix/SimpleLeastSquaresCase.java | 28 +- test/org/ojalgo/matrix/SimpleQRCase.java | 30 +- .../matrix/SimpleSingularValueCase.java | 32 +- test/org/ojalgo/matrix/SpecialTest.java | 65 ++ .../matrix/decomposition/CaseBidiagonal.java | 22 +- .../matrix/decomposition/CaseEigenvalue.java | 50 +- .../matrix/decomposition/CaseHessenberg.java | 10 +- .../ojalgo/matrix/decomposition/CaseLDL.java | 2 +- .../ojalgo/matrix/decomposition/CaseLU.java | 14 +- .../ojalgo/matrix/decomposition/CaseQR.java | 34 +- .../decomposition/CaseSingularValue.java | 36 +- .../matrix/decomposition/CaseTridiagonal.java | 30 +- .../CompareJamaAndPrimitive.java | 12 +- .../decomposition/DecompositionProblems.java | 44 +- .../decomposition/DegenerateLUCase.java | 14 +- .../matrix/decomposition/DesignCase.java | 30 +- .../decomposition/ExtremeElementsCase.java | 33 +- .../ojalgo/matrix/decomposition/SVDbyEvD.java | 8 +- .../ojalgo/matrix/decomposition/TestJama.java | 12 +- .../decomposition/TestSolveAndInvert.java | 12 +- .../ojalgo/matrix/store/AboveBelowCase.java | 6 +- test/org/ojalgo/matrix/store/ColumnsCase.java | 6 +- .../matrix/store/ComposingStoreTest.java | 2 +- .../ojalgo/matrix/store/ConjugatedCase.java | 6 +- .../org/ojalgo/matrix/store/IdentityCase.java | 6 +- .../ojalgo/matrix/store/LeftRightCase.java | 6 +- .../matrix/store/MultiplicationTest.java | 18 +- .../ojalgo/matrix/store/NonPhysicalTest.java | 12 +- test/org/ojalgo/matrix/store/RowsCase.java | 6 +- test/org/ojalgo/matrix/store/SparseCase.java | 6 +- .../matrix/store/SparsePerformance.java | 24 +- .../ojalgo/matrix/store/StoreProblems.java | 52 +- .../matrix/store/SuperimposedColumnCase.java | 6 +- .../matrix/store/SuperimposedElementCase.java | 10 +- .../matrix/store/SuperimposedRowCase.java | 6 +- .../matrix/store/SuppliersAndConsumers.java | 8 +- .../ojalgo/matrix/store/TransposedCase.java | 6 +- test/org/ojalgo/matrix/store/ZeroCase.java | 6 +- .../ojalgo/matrix/task/DeterminantTest.java | 4 +- test/org/ojalgo/matrix/task/InverterTest.java | 4 +- test/org/ojalgo/matrix/task/SolverTest.java | 24 +- test/org/ojalgo/netio/NetioTests.java | 28 + test/org/ojalgo/netio/TestCSV.java | 131 +++ .../optimisation/convex/ConvexProblems.java | 189 +-- .../convex/FinancePortfolioProblem.java | 14 +- .../convex/GenericQPSolverTest.java | 38 +- .../ojalgo/optimisation/convex/P20150720.java | 13 +- .../optimisation/integer/MarketShareCase.java | 18 +- .../integer/NextGenSysModTest.java | 32 +- .../optimisation/integer/UCLAee236aCase.java | 26 +- .../linear/BurkardtDatasetsMps.java | 2 +- .../linear/ComPictetPamBamTest.java | 4 +- .../linear/LinearDesignTestCases.java | 52 +- .../optimisation/linear/LinearProblems.java | 22 +- .../linear/SpecialSituations.java | 26 +- .../random/process/GaussianProcessTest.java | 4 +- test/org/ojalgo/scalar/QuaternionTest.java | 4 +- 374 files changed, 6936 insertions(+), 3436 deletions(-) create mode 100644 rsrc/csv/example.csv create mode 100644 rsrc/csv/fast.csv create mode 100644 rsrc/csv/quoted.csv rename src/org/ojalgo/matrix/{PrimitiveMatrix.java => Primitive32Matrix.java} (73%) create mode 100644 src/org/ojalgo/matrix/Primitive64Matrix.java rename src/org/ojalgo/matrix/store/{GenericDenseStore.java => GenericStore.java} (83%) create mode 100644 src/org/ojalgo/matrix/store/Primitive32Store.java rename src/org/ojalgo/matrix/store/{PrimitiveDenseStore.java => Primitive64Store.java} (76%) create mode 100644 src/org/ojalgo/matrix/store/PrimitiveFactory.java create mode 100644 src/org/ojalgo/type/ComparableNumber.java create mode 100644 src/org/ojalgo/type/NumberDefinition.java create mode 100644 test/org/ojalgo/matrix/SpecialTest.java create mode 100644 test/org/ojalgo/netio/NetioTests.java create mode 100644 test/org/ojalgo/netio/TestCSV.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3848e4c82..687199c71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,20 +7,51 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Added / Changed / Deprecated / Removed / Fixed / Security + ## [Unreleased] > Corresponds to changes in the `develop` branch since the last release ### Added +- Improved support for float throughout the library, and specifically added matrices with float elements. + +#### org.ojalgo.algebra + +- ScalarOperation has been extended with support for float arguments. + #### org.ojalgo.function - New special functions: beta (complete, incomplete and regularized), gamma (logarithmic), Hypergeometric and Pochhammer symbol. Inluding complex valued variants where applicable. The complete gamma function existed previously, and the upper/lower incomplete gamma functions are only implemented for the integer case. +- All the function interaces now have float specific methods. + +#### org.ojalgo.matrix + +- There is a new float based matrix store implementation, Primitive32Store. #### org.ojalgo.random - The `getDistribution()` method in the TDistribution is now implemented for the general case. Previously it was only implemented for a few distinct degrees of freedom. +### Changed + +- Generic declarations in interfaces and abstract classes (everywhere) that used to be `` are now `>`. Code that extends/implements ojAlgo classes and interaces will most likely need to be updated. Simple usage may not require any changes at all. Please note that `java.lang.Number` is NOT `Comparable` but all the speciic subclasses are. +- Everything (classes/interfaces, constants...) named "Primitive" -something now separates between "Primitive32" and "Primitive64". + +#### org.ojalgo.matrix + +- PrimitiveDenseStore has been renamed Primitive64Store (and there is now also a Primitive32Store). GenericDenseStore was also renamed GenericStore. + +#### org.ojalgo.scalar + +- ComplexNumber and Quaternion are now final. That means there are no longer special normalised subclasses (no Versor). + +#### org.ojalgo.structure + +- The methods in the Mutate*D.Fillable interaces that take a NullaryFunction as input has changed the generic declaration from `NullaryFunction` to `NullaryFunction`. +- Reftactoring of the Factory*D interfaces. + + ## [47.3.1] – 2019-09-29 ### Added @@ -55,6 +86,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security - The compareTo method of CalendarDateDuration didn't work when the unit of either instances was "nanos". + ## [47.3.0] – 2019-08-08 ### Changed @@ -118,6 +150,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security * Additions to Structure2D.Logical (Moved definitions from MatrixStore.LogicalBuilder to here). * Refactoring to Factory1D, Factory2D and FactoryAnyD – makeZero(...) is renamed make(...) and everything else is moved to a nested subinterface Dense. + ## [47.2.0] – 2019-05-03 ### Changed @@ -153,6 +186,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security * The Stream2D interface now has methods operateOnColumns(...) and operateOnRows(...) + ## [47.1.2] – 2019-04-23 ### Changed @@ -162,6 +196,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security * Fixed bug related to LDL – stackoverflow if you called isSolvable() on some LDL instances. * Various tweaks and cleanup with MatrixDecompostion:s + ## [47.1.1] – 2019-04-12 ### Changed @@ -184,6 +219,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security * The Stream1D, Stream2D and StreamAnyD each got a new method named operateOnAny that takes a Transformation?D as input. * The Mutate1D.ModifiableReceiver, Mutate2D.ModifiableReceiver and MutateAnyD.ModifiableReceiver each got a new method named modifyAny that takes a Transformation?D as input. + ## [47.1.0] – 2019-04-09 ### Changed @@ -238,6 +274,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security * Additions to Stopwatch that make it easier to compare with time limits in various forms. + ## [47.0.0] – 2018-12-16 ### Changed @@ -286,6 +323,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security * The BasicMatrix interface has been deprecated!!! The various implementations will remain - all of them - but you should use those implementations directly/explicitly rather than the interface. + ## [46.2.0] – 2018-10-04 ### Changed @@ -305,6 +343,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * Access1D no longer extends Iterable. To iterate over the elements use `elements()`. + ## [46.1.0] – 2018-09-17 ### Changed @@ -330,6 +369,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * Added default methods to get all primitive number types from Access1D, Access2D and AccessAnyD and to somewhat modified the ones in AccessScalar: `byteValue(), shortValue(), intValue(), longValue(), floatValue(), doubleValue()`. * AccessAnyD now has a method `matrices()` that return a `Iterable>`. On a multi-dimensional data structure you can iterate over its 2D (sub)matrices. Useful when you have a 3-dimensional (or more) data structure that is actually a collection of 2D matrices. + ## [46.0.0] – 2018-08-19 ### Changed @@ -391,6 +431,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * New class ObjectPool * The generics type parameter of NumberContext.Enforceable changed from `` to ``. + ## [45.1.0] – 2018-04-13 ### Changed @@ -424,6 +465,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * New class LineSplittingParser - a very simple csv parser * New class TableData - used to create a "table" of values that can then be exported to a csv file. + ## [45.0.0] – 2018-03-30 ### Changed @@ -485,6 +527,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * New TypeContext implementation, named TemporalContext, to handle the classes from Java's new date time API. The older DateContext is still available. * Bug fixed in a NumberContext factory method - getPercent(int,Locale) + ## [44.0.0] – 2017-09-27 ### Changed @@ -550,6 +593,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * NumberContext now has specific format(double) and format(long) methods, and now formats decimals with a variable number of fraction digits. * NumberContext now has new compare(double,double) and compare(float,float) that are alternatives to the compare(...) methods in Double and Float - the only difference is that these return 0 when the two input args are ==. + ## [43.0.0] – 2017-04-22 ### Changed @@ -616,6 +660,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * Refactoring and additions to CalendarDate, CalendarDateUnit and CalendarDateDuration. Among other things there is a now an interface CalendarDate.Resolution that both CalendarDateUnit and CalendarDateDuration implement. + ## [42.0.0] – 2017-02-03 ### Changed @@ -664,6 +709,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * All previously existing variations of getXXFunction(...) in NumberContext has been deprecated and are replaced by by 1 new variant that takes a FunctionSet as input. * New class NativeMemory used as single point to allocate, read or write native memory. + ## [41.0.0] – 2016-11-13 ### Changed @@ -728,6 +774,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * New builder instances in the BasicSeries interface. If you use them they will return implementations, new to v41, backed by array classes from the org.ojalgo.array package. It is now possible to use just about any date/time related class as a time series key. * The methods getDataSeries() and getPrimitiveValues() are deprecated, both replaced by the new method getPrimitiveSeries(). Further the modifyAll(UnaryFunction) method is deprecated. You should do modifications on the series returned by getPrimitiveSeries(). + ## [40.0.0] – 2016-06-20 ### Changed @@ -788,6 +835,7 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th * CalendarDateUnit now implements TemporalUnit * CalendarDateDuration now implements TemporalAmount + ## [39.0.0] – 2015-11-28 ### Changed @@ -872,12 +920,14 @@ Nothing in ojAlgo implements Serializable - a few odd classes used to declare th >API-breaking! + ## [38.0.0] ### Changed The first version to require Java 8! + ## [37.0.0] / [37.1.0] ### Changed diff --git a/pom.xml b/pom.xml index ef4cbe764..91e16ebe9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.ojalgo ojalgo - 47.4.0-SNAPSHOT + 48.0.0-SNAPSHOT jar ojAlgo http://ojalgo.org diff --git a/rsrc/csv/example.csv b/rsrc/csv/example.csv new file mode 100644 index 000000000..ae9ccc548 --- /dev/null +++ b/rsrc/csv/example.csv @@ -0,0 +1,15 @@ +# This example was extracted from Wikipedia (en.wikipedia.org/wiki/Comma-separated_values) +# +# 2 double quotes ("") are used as the escape sequence for quoted fields, as per the RFC4180 standard +# + +Year,Make,Model,Description,Price +1997,Ford,E350,"ac, abs, moon",3000.00 +1999,Chevy,"Venture ""Extended Edition""","",4900.00 + +# Look, a multi line value. And blank rows around it! + +1996,Jeep,Grand Cherokee,"MUST SELL! +air, moon roof, loaded",4799.00 +1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00 +,,"Venture ""Extended Edition""","",4900.00 diff --git a/rsrc/csv/fast.csv b/rsrc/csv/fast.csv new file mode 100644 index 000000000..207dec822 --- /dev/null +++ b/rsrc/csv/fast.csv @@ -0,0 +1,22 @@ +A,B,C,D,E,F,G,H,I,J +,B,C,D,E,F,G,H,I,J +A,,C,D,E,F,G,H,I,J +A,B,,D,E,F,G,H,I,J +A,B,C,,E,F,G,H,I,J +A,B,C,D,,F,G,H,I,J +A,B,C,D,E,,G,H,I,J +A,B,C,D,E,F,,H,I,J +A,B,C,D,E,F,G,,I,J +A,B,C,D,E,F,G,H,,J +A,B,C,D,E,F,G,H,I, +,,,,,,,,, +A,,,,,,,,, +,B,,,,,,,, +,,C,,,,,,, +,,,D,,,,,, +,,,,E,,,,, +,,,,,F,,,, +,,,,,,G,,, +,,,,,,,H,, +,,,,,,,,I, +,,,,,,,,,J \ No newline at end of file diff --git a/rsrc/csv/quoted.csv b/rsrc/csv/quoted.csv new file mode 100644 index 000000000..b495e8035 --- /dev/null +++ b/rsrc/csv/quoted.csv @@ -0,0 +1,22 @@ +"A","B","C","D","E","F","G","H","I","J" +"","B","C","D","E","F","G","H","I","J" +"A","","C","D","E","F","G","H","I","J" +"A","B","","D","E","F","G","H","I","J" +"A","B","C","","E","F","G","H","I","J" +"A","B","C","D","","F","G","H","I","J" +"A","B","C","D","E","","G","H","I","J" +"A","B","C","D","E","F","","H","I","J" +"A","B","C","D","E","F","G","","I","J" +"A","B","C","D","E","F","G","H","","J" +"A","B","C","D","E","F","G","H","I","" +"","","","","","","","","","" +"A","","","","","","","","","" +"","B","","","","","","","","" +"","","C","","","","","","","" +"","","","D","","","","","","" +"","","","","E","","","","","" +"","","","","","F","","","","" +"","","","","","","G","","","" +"","","","","","","","H","","" +"","","","","","","","","I","" +"","","","","","","","","","J" \ No newline at end of file diff --git a/src/org/ojalgo/algebra/Field.java b/src/org/ojalgo/algebra/Field.java index 34c1f8305..75d206bfa 100644 --- a/src/org/ojalgo/algebra/Field.java +++ b/src/org/ojalgo/algebra/Field.java @@ -37,6 +37,6 @@ * @see Field * @see Division ring */ -public interface Field extends Ring, Group.Multiplicative, Operation.Subtraction, Operation.Division { +public interface Field extends Ring, Group.Multiplicative, Operation.Subtraction, Operation.Division { } diff --git a/src/org/ojalgo/algebra/Group.java b/src/org/ojalgo/algebra/Group.java index 4fd4d43f9..5e96a3569 100644 --- a/src/org/ojalgo/algebra/Group.java +++ b/src/org/ojalgo/algebra/Group.java @@ -46,28 +46,28 @@ public interface Group { /** * @see Additive group */ - public interface Additive extends Group, Operation.Addition { + public interface Additive extends Group, Operation.Addition { /** * The additive inverse of this. * * @return -this. */ - S negate(); + T negate(); } /** * @see Multiplicative group */ - public interface Multiplicative extends Group, Operation.Multiplication { + public interface Multiplicative extends Group, Operation.Multiplication { /** * The multiplicative inverse. * * @return IDENTITY / this. */ - S invert(); + T invert(); } diff --git a/src/org/ojalgo/algebra/NormedVectorSpace.java b/src/org/ojalgo/algebra/NormedVectorSpace.java index 0c769d66c..1fa0e7691 100644 --- a/src/org/ojalgo/algebra/NormedVectorSpace.java +++ b/src/org/ojalgo/algebra/NormedVectorSpace.java @@ -24,7 +24,7 @@ /** * @author apete */ -public interface NormedVectorSpace extends VectorSpace { +public interface NormedVectorSpace> extends VectorSpace { /** * @param comparedTo What to compare with @@ -44,6 +44,6 @@ public interface NormedVectorSpace extends VectorSpaceDistributive property * @see Associative property */ -public interface Ring extends Group.Additive, Operation.Multiplication { +public interface Ring extends Group.Additive, Operation.Multiplication { } diff --git a/src/org/ojalgo/algebra/ScalarOperation.java b/src/org/ojalgo/algebra/ScalarOperation.java index 982287e6a..06b8c1212 100644 --- a/src/org/ojalgo/algebra/ScalarOperation.java +++ b/src/org/ojalgo/algebra/ScalarOperation.java @@ -26,13 +26,20 @@ */ public interface ScalarOperation { - public interface Addition extends ScalarOperation { + public interface Addition> extends ScalarOperation { /** * @return this + scalarAddend. */ T add(double scalarAddend); + /** + * @return this + scalarAddend. + */ + default T add(float scalarAddend) { + return this.add((double) scalarAddend); + } + /** * @return this + scalarAddend. */ @@ -40,13 +47,20 @@ public interface Addition extends ScalarOperation { } - public interface Division extends ScalarOperation { + public interface Division> extends ScalarOperation { /** * @return this / scalarDivisor. */ T divide(double scalarDivisor); + /** + * @return this / scalarDivisor. + */ + default T divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + /** * @return this / scalarDivisor. */ @@ -54,13 +68,20 @@ public interface Division extends ScalarOperation { } - public interface Multiplication extends ScalarOperation { + public interface Multiplication> extends ScalarOperation { /** * @return this * scalarMultiplicand. */ T multiply(double scalarMultiplicand); + /** + * @return this * scalarMultiplicand. + */ + default T multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + /** * @return this * multiplicand. */ @@ -68,13 +89,20 @@ public interface Multiplication extends ScalarOperation { } - public interface Subtraction extends ScalarOperation { + public interface Subtraction> extends ScalarOperation { /** * @return this - scalarSubtrahend. */ T subtract(double scalarSubtrahend); + /** + * @return this - scalarSubtrahend. + */ + default T subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + /** * @return this - scalarSubtrahend. */ diff --git a/src/org/ojalgo/algebra/VectorSpace.java b/src/org/ojalgo/algebra/VectorSpace.java index 054b0b13a..6f9918ede 100644 --- a/src/org/ojalgo/algebra/VectorSpace.java +++ b/src/org/ojalgo/algebra/VectorSpace.java @@ -37,21 +37,22 @@ * *

* To enable the use of existing Java classes as scalars this interface declares the scalar type to be a - * subclass of {@linkplain Number} rather than an implementation of {@linkplain Field}. + * subclass of {@linkplain Comparable} (think {@linkplain Number}) rather than an implementation of + * {@linkplain Field}. *

*

* Any field is also a vector space in itself. *

* - * @param The vector type - * @param The scalar type + * @param The vector type + * @param The scalar type * @author apete * @see Group.Additive * @see Field * @see Vector space * @see Examples of vector spaces */ -public interface VectorSpace extends Group.Additive, ScalarOperation.Multiplication { +public interface VectorSpace> extends Group.Additive, ScalarOperation.Multiplication { /** *

@@ -66,6 +67,6 @@ public interface VectorSpace extends Group.Additive, Sca * The conjugate transpose of a real matrix is simply its transpose. *

*/ - V conjugate(); + T conjugate(); } diff --git a/src/org/ojalgo/ann/ArtificialNeuralNetwork.java b/src/org/ojalgo/ann/ArtificialNeuralNetwork.java index 41b11a872..378cee6db 100644 --- a/src/org/ojalgo/ann/ArtificialNeuralNetwork.java +++ b/src/org/ojalgo/ann/ArtificialNeuralNetwork.java @@ -32,7 +32,7 @@ import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Structure2D; @@ -64,7 +64,7 @@ public enum Activator { * training. */ SOFTMAX(args -> { - PrimitiveDenseStore parts = args.copy(); + Primitive64Store parts = args.copy(); parts.modifyAll(EXP); final double total = parts.aggregateAll(Aggregator.SUM); return arg -> EXP.invoke(arg) / total; @@ -88,7 +88,7 @@ PrimitiveFunction.Unary getDerivativeInTermsOfOutput() { return myDerivativeInTermsOfOutput; } - PrimitiveFunction.Unary getFunction(final PrimitiveDenseStore arguments) { + PrimitiveFunction.Unary getFunction(final Primitive64Store arguments) { return myFunction.make(arguments); } @@ -138,7 +138,7 @@ PrimitiveFunction.Binary getDerivative() { interface ActivatorFunctionFactory { - PrimitiveFunction.Unary make(PrimitiveDenseStore arguments); + PrimitiveFunction.Unary make(Primitive64Store arguments); } @@ -216,7 +216,7 @@ CalculationLayer getLayer(final int index) { return myLayers[index]; } - PrimitiveDenseStore getOutput(final int layer) { + Primitive64Store getOutput(final int layer) { return myLayers[layer].getOutput(); } diff --git a/src/org/ojalgo/ann/CalculationLayer.java b/src/org/ojalgo/ann/CalculationLayer.java index 4222135c0..e1e1f24aa 100644 --- a/src/org/ojalgo/ann/CalculationLayer.java +++ b/src/org/ojalgo/ann/CalculationLayer.java @@ -25,25 +25,25 @@ import org.ojalgo.function.BasicFunction; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Uniform; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Structure2D; -final class CalculationLayer implements BasicFunction.PlainUnary, PrimitiveDenseStore> { +final class CalculationLayer implements BasicFunction.PlainUnary, Primitive64Store> { private ArtificialNeuralNetwork.Activator myActivator; - private final PrimitiveDenseStore myBias; - private final PrimitiveDenseStore myOutput; - private final PrimitiveDenseStore myWeights; + private final Primitive64Store myBias; + private final Primitive64Store myOutput; + private final Primitive64Store myWeights; CalculationLayer(final int numberOfInputs, final int numberOfOutputs, final ArtificialNeuralNetwork.Activator activator) { super(); - myWeights = PrimitiveDenseStore.FACTORY.make(numberOfInputs, numberOfOutputs); - myBias = PrimitiveDenseStore.FACTORY.make(1, numberOfOutputs); - myOutput = PrimitiveDenseStore.FACTORY.make(1, numberOfOutputs); + myWeights = Primitive64Store.FACTORY.make(numberOfInputs, numberOfOutputs); + myBias = Primitive64Store.FACTORY.make(1, numberOfOutputs); + myOutput = Primitive64Store.FACTORY.make(1, numberOfOutputs); myActivator = activator; @@ -92,7 +92,7 @@ public int hashCode() { return result; } - public PrimitiveDenseStore invoke(final Access1D input) { + public Primitive64Store invoke(final Access1D input) { myWeights.premultiply(input).operateOnMatching(ADD, myBias).supplyTo(myOutput); myOutput.modifyAll(myActivator.getFunction(myOutput)); return myOutput; @@ -122,8 +122,8 @@ private void randomise(final double numberOfInputs) { myBias.fillAll(randomiser); } - void adjust(final Access1D layerInput, final PrimitiveDenseStore downstreamGradient, final double learningRate, - final PrimitiveDenseStore upstreamGradient) { + void adjust(final Access1D layerInput, final Primitive64Store downstreamGradient, final double learningRate, + final Primitive64Store upstreamGradient) { downstreamGradient.modifyMatching(MULTIPLY, myOutput.operateOnAll(myActivator.getDerivativeInTermsOfOutput())); @@ -150,7 +150,7 @@ MatrixStore getLogicalWeights() { return myWeights.logical().below(myBias).get(); } - PrimitiveDenseStore getOutput() { + Primitive64Store getOutput() { return myOutput; } diff --git a/src/org/ojalgo/ann/NetworkBuilder.java b/src/org/ojalgo/ann/NetworkBuilder.java index a5de75497..f5060bed2 100644 --- a/src/org/ojalgo/ann/NetworkBuilder.java +++ b/src/org/ojalgo/ann/NetworkBuilder.java @@ -27,7 +27,7 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure2D; @@ -41,7 +41,7 @@ public final class NetworkBuilder implements Supplier { private final ArtificialNeuralNetwork myANN; private ArtificialNeuralNetwork.Error myError = ArtificialNeuralNetwork.Error.HALF_SQUARED_DIFFERENCE; - private final PrimitiveDenseStore[] myLayerValues; + private final Primitive64Store[] myLayerValues; private double myLearningRate = 1.0; NetworkBuilder(final int numberOfInputNodes, final int... outputNodesPerCalculationLayer) { @@ -54,10 +54,10 @@ public final class NetworkBuilder implements Supplier { myANN = new ArtificialNeuralNetwork(numberOfInputNodes, outputNodesPerCalculationLayer); - myLayerValues = new PrimitiveDenseStore[1 + outputNodesPerCalculationLayer.length]; - myLayerValues[0] = PrimitiveDenseStore.FACTORY.make(numberOfInputNodes, 1); + myLayerValues = new Primitive64Store[1 + outputNodesPerCalculationLayer.length]; + myLayerValues[0] = Primitive64Store.FACTORY.make(numberOfInputNodes, 1); for (int l = 0; l < outputNodesPerCalculationLayer.length; l++) { - myLayerValues[1 + l] = PrimitiveDenseStore.FACTORY.make(outputNodesPerCalculationLayer[l], 1); + myLayerValues[1 + l] = Primitive64Store.FACTORY.make(outputNodesPerCalculationLayer[l], 1); } } diff --git a/src/org/ojalgo/array/Array1D.java b/src/org/ojalgo/array/Array1D.java index fc24648c4..aecb6d4b9 100644 --- a/src/org/ojalgo/array/Array1D.java +++ b/src/org/ojalgo/array/Array1D.java @@ -51,10 +51,10 @@ * * @author apete */ -public final class Array1D extends AbstractList implements Access1D, Access1D.Visitable, Access1D.Aggregatable, +public final class Array1D> extends AbstractList implements Access1D, Access1D.Visitable, Access1D.Aggregatable, Access1D.Sliceable, Access1D.Elements, Access1D.IndexOf, Mutate1D.ModifiableReceiver, Mutate1D.Mixable, Mutate1D.Sortable, RandomAccess { - public static final class Factory implements Factory1D> { + public static final class Factory> implements Factory1D.MayBeSparse, Array1D, Array1D> { private final BasicArray.Factory myDelegate; @@ -67,15 +67,15 @@ public Array1D copy(final Access1D source) { return myDelegate.copy(source).wrapInArray1D(); } - public Array1D copy(final double... source) { + public Array1D copy(final Comparable... source) { return myDelegate.copy(source).wrapInArray1D(); } - public Array1D copy(final List source) { + public Array1D copy(final double... source) { return myDelegate.copy(source).wrapInArray1D(); } - public Array1D copy(final Number... source) { + public Array1D copy(final List> source) { return myDelegate.copy(source).wrapInArray1D(); } @@ -84,6 +84,11 @@ public FunctionSet function() { return myDelegate.function(); } + @Override + public Array1D make(final long count) { + return this.makeDense(count); + } + public Array1D makeFilled(final long count, final NullaryFunction supplier) { return myDelegate.makeFilled(count, supplier).wrapInArray1D(); } @@ -92,10 +97,6 @@ public Array1D makeSparse(final long count) { return myDelegate.makeStructuredZero(count).wrapInArray1D(); } - public Array1D make(final long count) { - return myDelegate.makeToBeFilled(count).wrapInArray1D(); - } - @Override public Scalar.Factory scalar() { return myDelegate.scalar(); @@ -105,6 +106,10 @@ public Array1D wrap(final BasicArray array) { return array.wrapInArray1D(); } + public Array1D makeDense(long count) { + return myDelegate.makeToBeFilled(count).wrapInArray1D(); + } + } static final class QuickAscendingSorter extends RecursiveAction { @@ -238,7 +243,7 @@ protected void compute() { public static final Factory QUATERNION = new Factory<>(QuaternionArray.FACTORY); public static final Factory RATIONAL = new Factory<>(RationalArray.FACTORY); - public static Array1D.Factory factory(final DenseArray.Factory denseFactory) { + public static > Array1D.Factory factory(final DenseArray.Factory denseFactory) { return new Array1D.Factory<>(denseFactory); } @@ -266,16 +271,25 @@ public static Array1D.Factory factory(final DenseArray.Fac length = (myLimit - myFirst) / myStep; } + @Override + public void add(final long index, final Comparable addend) { + final long tmpIndex = myFirst + (myStep * index); + myDelegate.add(tmpIndex, addend); + } + + @Override public void add(final long index, final double addend) { final long tmpIndex = myFirst + (myStep * index); myDelegate.add(tmpIndex, addend); } - public void add(final long index, final Number addend) { + @Override + public void add(final long index, final float addend) { final long tmpIndex = myFirst + (myStep * index); myDelegate.add(tmpIndex, addend); } + @Override public N aggregateRange(final long first, final long limit, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitRange(first, limit, visitor); @@ -379,43 +393,52 @@ public Array1D copy(final int... indices) { } } + @Override public long count() { return length; } + @Override public double doubleValue(final long index) { return myDelegate.doubleValue(myFirst + (myStep * index)); } + @Override public void fillAll(final N value) { myDelegate.fill(myFirst, myLimit, myStep, value); } - public void fillAll(final NullaryFunction supplier) { + @Override + public void fillAll(final NullaryFunction supplier) { myDelegate.fill(myFirst, myLimit, myStep, supplier); } + @Override public void fillOne(final long index, final Access1D values, final long valueIndex) { myDelegate.fillOne(myFirst + (myStep * index), values, valueIndex); } + @Override public void fillOne(final long index, final N value) { final long tmpIndex = myFirst + (myStep * index); myDelegate.fillOne(tmpIndex, value); } - public void fillOne(final long index, final NullaryFunction supplier) { + @Override + public void fillOne(final long index, final NullaryFunction supplier) { final long tmpIndex = myFirst + (myStep * index); myDelegate.fillOne(tmpIndex, supplier); } + @Override public void fillRange(final long first, final long limit, final N value) { final long tmpFirst = myFirst + (myStep * first); final long tmpLimit = myFirst + (myStep * limit); myDelegate.fill(tmpFirst, tmpLimit, myStep, value); } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + @Override + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { final long tmpFirst = myFirst + (myStep * first); final long tmpLimit = myFirst + (myStep * limit); myDelegate.fill(tmpFirst, tmpLimit, myStep, supplier); @@ -426,6 +449,7 @@ public N get(final int index) { return myDelegate.get(myFirst + (myStep * index)); } + @Override public N get(final long index) { return myDelegate.get(myFirst + (myStep * index)); } @@ -439,7 +463,7 @@ public int indexOf(final Object obj) { return i; } } - } else if (obj instanceof Number) { + } else if (obj instanceof Comparable) { for (int i = 0; i < tmpLength; i++) { if (obj.equals(this.get(i))) { return i; @@ -449,10 +473,12 @@ public int indexOf(final Object obj) { return -1; } + @Override public long indexOfLargest() { return this.indexOfLargestInRange(myFirst, myLimit); } + @Override public long indexOfLargestInRange(final long first, final long limit) { return (myDelegate.indexOfLargest(myFirst + (myStep * first), myFirst + (myStep * limit), myStep) - myFirst) / myStep; } @@ -460,10 +486,12 @@ public long indexOfLargestInRange(final long first, final long limit) { /** * @see Scalar#isAbsolute() */ + @Override public boolean isAbsolute(final long index) { return myDelegate.isAbsolute(myFirst + (myStep * index)); } + @Override public boolean isAllSmall(final double comparedTo) { return myDelegate.isSmall(myFirst, myLimit, myStep, comparedTo); } @@ -476,10 +504,12 @@ public boolean isEmpty() { /** * @see Scalar#isSmall(double) */ + @Override public boolean isSmall(final long index, final double comparedTo) { return myDelegate.isSmall(myFirst + (myStep * index), comparedTo); } + @Override public double mix(final long index, final BinaryFunction mixer, final double addend) { ProgrammingError.throwIfNull(mixer); synchronized (myDelegate) { @@ -490,6 +520,7 @@ public double mix(final long index, final BinaryFunction mixer, final double } } + @Override public N mix(final long index, final BinaryFunction mixer, final N addend) { ProgrammingError.throwIfNull(mixer); synchronized (myDelegate) { @@ -500,14 +531,17 @@ public N mix(final long index, final BinaryFunction mixer, final N addend) { } } + @Override public void modifyAll(final UnaryFunction modifier) { myDelegate.modify(myFirst, myLimit, myStep, modifier); } + @Override public void modifyAny(final Transformation1D modifier) { modifier.transform(this); } + @Override public void modifyMatching(final Access1D left, final BinaryFunction function) { final long tmpLength = Math.min(length, left.count()); if (myDelegate.isPrimitive()) { @@ -521,6 +555,7 @@ public void modifyMatching(final Access1D left, final BinaryFunction funct } } + @Override public void modifyMatching(final BinaryFunction function, final Access1D right) { final long tmpLength = Math.min(length, right.count()); if (myDelegate.isPrimitive()) { @@ -534,10 +569,12 @@ public void modifyMatching(final BinaryFunction function, final Access1D r } } + @Override public void modifyOne(final long index, final UnaryFunction modifier) { myDelegate.modifyOne(myFirst + (myStep * index), modifier); } + @Override public void modifyRange(final long first, final long limit, final UnaryFunction modifier) { final long tmpFirst = myFirst + (myStep * first); final long tmpLimit = myFirst + (myStep * limit); @@ -545,18 +582,25 @@ public void modifyRange(final long first, final long limit, final UnaryFunction< } @Override - public N set(final int index, final Number value) { + public N set(final int index, final N value) { final long tmpIndex = myFirst + (myStep * index); final N retVal = myDelegate.get(tmpIndex); myDelegate.set(tmpIndex, value); return retVal; } + @Override + public void set(final long index, final Comparable value) { + myDelegate.set(myFirst + (myStep * index), value); + } + + @Override public void set(final long index, final double value) { myDelegate.set(myFirst + (myStep * index), value); } - public void set(final long index, final Number value) { + @Override + public void set(final long index, final float value) { myDelegate.set(myFirst + (myStep * index), value); } @@ -565,10 +609,12 @@ public int size() { return (int) length; } + @Override public Array1D sliceRange(final long first, final long limit) { return new Array1D<>(myDelegate, myFirst + (myStep * first), myFirst + (myStep * limit), myStep); } + @Override public void sortAscending() { if ((myDelegate instanceof Mutate1D.Sortable) && (this.count() == myDelegate.count())) { @@ -587,6 +633,7 @@ public void sortAscending() { } } + @Override public void sortDescending() { if ((myDelegate instanceof Mutate1D.Sortable) && (this.count() == myDelegate.count())) { @@ -615,14 +662,17 @@ public String toString() { return Access1D.toString(this); } + @Override public void visitAll(final VoidFunction visitor) { myDelegate.visit(myFirst, myLimit, myStep, visitor); } + @Override public void visitOne(final long index, final VoidFunction visitor) { myDelegate.visitOne(myFirst + (myStep * index), visitor); } + @Override public void visitRange(final long first, final long limit, final VoidFunction visitor) { final long tmpFirst = myFirst + (myStep * first); final long tmpLimit = myFirst + (myStep * limit); diff --git a/src/org/ojalgo/array/Array2D.java b/src/org/ojalgo/array/Array2D.java index ab1a3f3af..e64269ced 100644 --- a/src/org/ojalgo/array/Array2D.java +++ b/src/org/ojalgo/array/Array2D.java @@ -48,10 +48,10 @@ * * @author apete */ -public final class Array2D implements Access2D, Access2D.Visitable, Access2D.Aggregatable, Access2D.Sliceable, Access2D.Elements, - Access2D.IndexOf, Structure2D.ReducibleTo1D>, Mutate2D.ModifiableReceiver, Mutate2D.Mixable { +public final class Array2D> implements Access2D, Access2D.Visitable, Access2D.Aggregatable, Access2D.Sliceable, + Access2D.Elements, Access2D.IndexOf, Structure2D.ReducibleTo1D>, Mutate2D.ModifiableReceiver, Mutate2D.Mixable { - public static final class Factory implements Factory2D> { + public static final class Factory> implements Factory2D.MayBeSparse, Array2D, Array2D> { private final BasicArray.Factory myDelegate; @@ -88,7 +88,7 @@ public Array2D columns(final Access1D... source) { return tmpDelegate.wrapInArray2D(tmpRows); } - public Array2D columns(final double[]... source) { + public Array2D columns(final Comparable[]... source) { final int tmpColumns = source.length; final int tmpRows = source[0].length; @@ -97,7 +97,7 @@ public Array2D columns(final double[]... source) { long tmpIndex = 0L; for (int j = 0; j < tmpColumns; j++) { - final double[] tmpColumn = source[j]; + final Comparable[] tmpColumn = source[j]; for (int i = 0; i < tmpRows; i++) { tmpDelegate.set(tmpIndex++, tmpColumn[i]); } @@ -106,36 +106,36 @@ public Array2D columns(final double[]... source) { return tmpDelegate.wrapInArray2D(tmpRows); } - public Array2D columns(final List... source) { + public Array2D columns(final double[]... source) { final int tmpColumns = source.length; - final int tmpRows = source[0].size(); + final int tmpRows = source[0].length; final BasicArray tmpDelegate = myDelegate.makeToBeFilled(tmpRows, tmpColumns); long tmpIndex = 0L; for (int j = 0; j < tmpColumns; j++) { - final List tmpColumn = source[j]; + final double[] tmpColumn = source[j]; for (int i = 0; i < tmpRows; i++) { - tmpDelegate.set(tmpIndex++, tmpColumn.get(i)); + tmpDelegate.set(tmpIndex++, tmpColumn[i]); } } return tmpDelegate.wrapInArray2D(tmpRows); } - public Array2D columns(final Number[]... source) { + public Array2D columns(final List>... source) { final int tmpColumns = source.length; - final int tmpRows = source[0].length; + final int tmpRows = source[0].size(); final BasicArray tmpDelegate = myDelegate.makeToBeFilled(tmpRows, tmpColumns); long tmpIndex = 0L; for (int j = 0; j < tmpColumns; j++) { - final Number[] tmpColumn = source[j]; + final List> tmpColumn = source[j]; for (int i = 0; i < tmpRows; i++) { - tmpDelegate.set(tmpIndex++, tmpColumn[i]); + tmpDelegate.set(tmpIndex++, tmpColumn.get(i)); } } @@ -151,6 +151,11 @@ public FunctionSet function() { return myDelegate.function(); } + @Override + public Array2D make(final long rows, final long columns) { + return this.makeDense(rows, columns); + } + public Array2D makeFilled(final long rows, final long columns, final NullaryFunction supplier) { final BasicArray tmpDelegate = myDelegate.makeToBeFilled(rows, columns); @@ -169,10 +174,6 @@ public Array2D makeSparse(final long rows, final long columns) { return myDelegate.makeStructuredZero(rows, columns).wrapInArray2D(rows); } - public Array2D make(final long rows, final long columns) { - return myDelegate.makeToBeFilled(rows, columns).wrapInArray2D(rows); - } - public Array2D rows(final Access1D... source) { final int tmpRows = source.length; @@ -199,7 +200,7 @@ public Array2D rows(final Access1D... source) { return tmpDelegate.wrapInArray2D(tmpRows); } - public Array2D rows(final double[]... source) { + public Array2D rows(final Comparable[]... source) { final int tmpRows = source.length; final int tmpColumns = source[0].length; @@ -207,7 +208,7 @@ public Array2D rows(final double[]... source) { final BasicArray tmpDelegate = myDelegate.makeToBeFilled(tmpRows, tmpColumns); for (int i = 0; i < tmpRows; i++) { - final double[] tmpRow = source[i]; + final Comparable[] tmpRow = source[i]; for (int j = 0; j < tmpColumns; j++) { tmpDelegate.set(Structure2D.index(tmpRows, i, j), tmpRow[j]); } @@ -216,35 +217,35 @@ public Array2D rows(final double[]... source) { return tmpDelegate.wrapInArray2D(tmpRows); } - @SuppressWarnings("unchecked") - public Array2D rows(final List... source) { + public Array2D rows(final double[]... source) { final int tmpRows = source.length; - final int tmpColumns = source[0].size(); + final int tmpColumns = source[0].length; final BasicArray tmpDelegate = myDelegate.makeToBeFilled(tmpRows, tmpColumns); for (int i = 0; i < tmpRows; i++) { - final List tmpRow = source[i]; + final double[] tmpRow = source[i]; for (int j = 0; j < tmpColumns; j++) { - tmpDelegate.set(Structure2D.index(tmpRows, i, j), tmpRow.get(j)); + tmpDelegate.set(Structure2D.index(tmpRows, i, j), tmpRow[j]); } } return tmpDelegate.wrapInArray2D(tmpRows); } - public Array2D rows(final Number[]... source) { + @SuppressWarnings("unchecked") + public Array2D rows(final List>... source) { final int tmpRows = source.length; - final int tmpColumns = source[0].length; + final int tmpColumns = source[0].size(); final BasicArray tmpDelegate = myDelegate.makeToBeFilled(tmpRows, tmpColumns); for (int i = 0; i < tmpRows; i++) { - final Number[] tmpRow = source[i]; + final List> tmpRow = source[i]; for (int j = 0; j < tmpColumns; j++) { - tmpDelegate.set(Structure2D.index(tmpRows, i, j), tmpRow[j]); + tmpDelegate.set(Structure2D.index(tmpRows, i, j), tmpRow.get(j)); } } @@ -256,6 +257,10 @@ public Scalar.Factory scalar() { return myDelegate.scalar(); } + public Array2D makeDense(long rows, long columns) { + return myDelegate.makeToBeFilled(rows, columns).wrapInArray2D(rows); + } + } public static final Factory BIG = new Factory<>(BigArray.FACTORY); @@ -267,7 +272,7 @@ public Scalar.Factory scalar() { public static final Factory QUATERNION = new Factory<>(QuaternionArray.FACTORY); public static final Factory RATIONAL = new Factory<>(RationalArray.FACTORY); - public static Array2D.Factory factory(final DenseArray.Factory denseArray) { + public static > Array2D.Factory factory(final DenseArray.Factory denseArray) { return new Array2D.Factory<>(denseArray); } @@ -285,40 +290,58 @@ public static Array2D.Factory factory(final DenseArray.Fac myColumnsCount = structure == 0L ? 0L : delegate.count() / structure; } + @Override + public void add(final long index, final Comparable addend) { + myDelegate.add(index, addend); + } + + @Override public void add(final long index, final double addend) { myDelegate.add(index, addend); } - public void add(final long row, final long col, final double addend) { + @Override + public void add(final long index, final float addend) { + myDelegate.add(index, addend); + } + + @Override + public void add(final long row, final long col, final Comparable addend) { myDelegate.add(Structure2D.index(myRowsCount, row, col), addend); } - public void add(final long row, final long col, final Number addend) { + @Override + public void add(final long row, final long col, final double addend) { myDelegate.add(Structure2D.index(myRowsCount, row, col), addend); } - public void add(final long index, final Number addend) { - myDelegate.add(index, addend); + @Override + public void add(final long row, final long col, final float addend) { + myDelegate.add(Structure2D.index(myRowsCount, row, col), addend); } + @Override public N aggregateColumn(final long row, final long col, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitColumn(row, col, visitor); return visitor.get(); } + @Override public N aggregateDiagonal(final long row, final long col, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitDiagonal(row, col, visitor); return visitor.get(); } + @Override public N aggregateRange(final long first, final long limit, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitRange(first, limit, visitor); return visitor.get(); } + @Override public N aggregateRow(final long row, final long col, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitRow(row, col, visitor); @@ -340,22 +363,27 @@ public void clear() { myDelegate.reset(); } + @Override public long count() { return myDelegate.count(); } + @Override public long countColumns() { return myColumnsCount; } + @Override public long countRows() { return myRowsCount; } + @Override public double doubleValue(final long index) { return myDelegate.doubleValue(index); } + @Override public double doubleValue(final long row, final long col) { return myDelegate.doubleValue(Structure2D.index(myRowsCount, row, col)); } @@ -371,22 +399,27 @@ public boolean equals(final Object obj) { } } + @Override public void exchangeColumns(final long colA, final long colB) { myDelegate.exchange(colA * myRowsCount, colB * myRowsCount, 1L, myRowsCount); } + @Override public void exchangeRows(final long rowA, final long rowB) { myDelegate.exchange(rowA, rowB, myRowsCount, myColumnsCount); } + @Override public void fillAll(final N value) { myDelegate.fill(0L, this.count(), 1L, value); } - public void fillAll(final NullaryFunction supplier) { + @Override + public void fillAll(final NullaryFunction supplier) { myDelegate.fill(0L, this.count(), 1L, supplier); } + @Override public void fillColumn(final long row, final long col, final Access1D values) { final long offset = Structure2D.index(myRowsCount, row, col); @@ -403,56 +436,69 @@ public void fillColumn(final long row, final long col, final Access1D values) } } + @Override public void fillColumn(final long row, final long col, final N value) { myDelegate.fill(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L, value); } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + @Override + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { myDelegate.fill(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L, supplier); } + @Override public void fillDiagonal(final long row, final long col, final N value) { final long tmpCount = Math.min(myRowsCount - row, myColumnsCount - col); myDelegate.fill(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row + tmpCount, col + tmpCount), 1L + myRowsCount, value); } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + @Override + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { final long tmpCount = Math.min(myRowsCount - row, myColumnsCount - col); myDelegate.fill(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row + tmpCount, col + tmpCount), 1L + myRowsCount, supplier); } + @Override public void fillOne(final long index, final Access1D values, final long valueIndex) { myDelegate.fillOne(index, values, valueIndex); } + @Override public void fillOne(final long row, final long col, final Access1D values, final long valueIndex) { myDelegate.fillOne(Structure2D.index(myRowsCount, row, col), values, valueIndex); } + @Override public void fillOne(final long row, final long col, final N value) { myDelegate.fillOne(Structure2D.index(myRowsCount, row, col), value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + @Override + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myDelegate.fillOne(Structure2D.index(myRowsCount, row, col), supplier); } + @Override public void fillOne(final long index, final N value) { myDelegate.fillOne(index, value); } - public void fillOne(final long index, final NullaryFunction supplier) { + @Override + public void fillOne(final long index, final NullaryFunction supplier) { myDelegate.fillOne(index, supplier); } + @Override public void fillRange(final long first, final long limit, final N value) { myDelegate.fill(first, limit, 1L, value); } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + @Override + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { myDelegate.fill(first, limit, 1L, supplier); } + @Override public void fillRow(final long row, final long col, final Access1D values) { final long offset = Structure2D.index(myRowsCount, row, col); @@ -469,18 +515,22 @@ public void fillRow(final long row, final long col, final Access1D values) { } } + @Override public void fillRow(final long row, final long col, final N value) { myDelegate.fill(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount, value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + @Override + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myDelegate.fill(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount, supplier); } + @Override public N get(final long index) { return myDelegate.get(index); } + @Override public N get(final long row, final long col) { return myDelegate.get(Structure2D.index(myRowsCount, row, col)); } @@ -490,6 +540,7 @@ public int hashCode() { return (int) (myRowsCount * myColumnsCount * myDelegate.hashCode()); } + @Override public long indexOfLargest() { return myDelegate.indexOfLargest(); } @@ -497,10 +548,12 @@ public long indexOfLargest() { /** * @return The row-index of the largest absolute value in a column, starting at the specified row. */ + @Override public long indexOfLargestInColumn(final long row, final long col) { return myDelegate.indexOfLargest(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L) % myRowsCount; } + @Override public long indexOfLargestInRange(final long first, final long limit) { return myDelegate.indexOfLargestInRange(first, limit); } @@ -508,11 +561,13 @@ public long indexOfLargestInRange(final long first, final long limit) { /** * @return The column-index of the largest absolute value in a row, starting at the specified column. */ + @Override public long indexOfLargestInRow(final long row, final long col) { return myDelegate.indexOfLargest(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount) / myRowsCount; } + @Override public long indexOfLargestOnDiagonal(final long first) { final long tmpMinCount = Math.min(myRowsCount, myColumnsCount); @@ -524,6 +579,7 @@ public long indexOfLargestOnDiagonal(final long first) { return myDelegate.indexOfLargest(tmpFirst, tmpLimit, tmpStep) / myRowsCount; } + @Override public boolean isAbsolute(final long index) { return myDelegate.isAbsolute(index); } @@ -531,30 +587,37 @@ public boolean isAbsolute(final long index) { /** * @see Scalar#isAbsolute() */ + @Override public boolean isAbsolute(final long row, final long col) { return myDelegate.isAbsolute(Structure2D.index(myRowsCount, row, col)); } + @Override public boolean isAllSmall(final double comparedTo) { return myDelegate.isSmall(0L, this.count(), 1L, comparedTo); } + @Override public boolean isColumnSmall(final long row, final long col, final double comparedTo) { return myDelegate.isSmall(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L, comparedTo); } + @Override public boolean isRowSmall(final long row, final long col, final double comparedTo) { return myDelegate.isSmall(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount, comparedTo); } + @Override public boolean isSmall(final long index, final double comparedTo) { return myDelegate.isSmall(index, comparedTo); } + @Override public boolean isSmall(final long row, final long col, final double comparedTo) { return myDelegate.isSmall(Structure2D.index(myRowsCount, row, col), comparedTo); } + @Override public double mix(final long row, final long col, final BinaryFunction mixer, final double addend) { ProgrammingError.throwIfNull(mixer); synchronized (myDelegate) { @@ -565,6 +628,7 @@ public double mix(final long row, final long col, final BinaryFunction mixer, } } + @Override public N mix(final long row, final long col, final BinaryFunction mixer, final N addend) { ProgrammingError.throwIfNull(mixer); synchronized (myDelegate) { @@ -575,97 +639,129 @@ public N mix(final long row, final long col, final BinaryFunction mixer, fina } } + @Override public void modifyAll(final UnaryFunction modifier) { myDelegate.modify(0L, this.count(), 1L, modifier); } + @Override public void modifyAny(final Transformation2D modifier) { modifier.transform(this); } + @Override public void modifyColumn(final long row, final long col, final UnaryFunction modifier) { myDelegate.modify(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L, modifier); } + @Override public void modifyDiagonal(final long row, final long col, final UnaryFunction modifier) { final long tmpCount = Math.min(myRowsCount - row, myColumnsCount - col); myDelegate.modify(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row + tmpCount, col + tmpCount), 1L + myRowsCount, modifier); } + @Override public void modifyMatching(final Access1D left, final BinaryFunction function) { myDelegate.modify(0L, this.count(), 1L, left, function); } + @Override public void modifyMatching(final BinaryFunction function, final Access1D right) { myDelegate.modify(0L, this.count(), 1L, function, right); } + @Override public void modifyOne(final long row, final long col, final UnaryFunction modifier) { myDelegate.modifyOne(Structure2D.index(myRowsCount, row, col), modifier); } + @Override public void modifyOne(final long index, final UnaryFunction modifier) { myDelegate.modifyOne(index, modifier); } + @Override public void modifyRange(final long first, final long limit, final UnaryFunction modifier) { myDelegate.modify(first, limit, 1L, modifier); } + @Override public void modifyRow(final long row, final long col, final UnaryFunction modifier) { myDelegate.modify(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount, modifier); } + @Override public Array1D reduceColumns(final Aggregator aggregator) { Array1D retVal = myDelegate.factory().makeZero(myColumnsCount).wrapInArray1D(); this.reduceColumns(aggregator, retVal); return retVal; } + @Override public Array1D reduceRows(final Aggregator aggregator) { Array1D retVal = myDelegate.factory().makeZero(myRowsCount).wrapInArray1D(); this.reduceRows(aggregator, retVal); return retVal; } + @Override + public void set(final long index, final Comparable value) { + myDelegate.set(index, value); + } + + @Override public void set(final long index, final double value) { myDelegate.set(index, value); } - public void set(final long row, final long col, final double value) { + @Override + public void set(final long index, final float value) { + myDelegate.set(index, value); + } + + @Override + public void set(final long row, final long col, final Comparable value) { myDelegate.set(Structure2D.index(myRowsCount, row, col), value); } - public void set(final long row, final long col, final Number value) { + @Override + public void set(final long row, final long col, final double value) { myDelegate.set(Structure2D.index(myRowsCount, row, col), value); } - public void set(final long index, final Number value) { - myDelegate.set(index, value); + @Override + public void set(final long row, final long col, final float value) { + myDelegate.set(Structure2D.index(myRowsCount, row, col), value); } + @Override public Array1D sliceColumn(final long col) { return this.sliceColumn(0L, col); } + @Override public Array1D sliceColumn(final long row, final long col) { return new Array1D<>(myDelegate, Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L); } + @Override public Array1D sliceDiagonal(final long row, final long col) { final long tmpCount = Math.min(myRowsCount - row, myColumnsCount - col); return new Array1D<>(myDelegate, Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row + tmpCount, col + tmpCount), 1L + myRowsCount); } + @Override public Array1D sliceRange(final long first, final long limit) { return myDelegate.wrapInArray1D().sliceRange(first, limit); } + @Override public Array1D sliceRow(final long row) { return this.sliceRow(row, 0L); } + @Override public Array1D sliceRow(final long row, final long col) { return new Array1D<>(myDelegate, Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount); } @@ -675,31 +771,38 @@ public String toString() { return Access2D.toString(this); } + @Override public void visitAll(final VoidFunction visitor) { myDelegate.visit(0L, this.count(), 1L, visitor); } + @Override public void visitColumn(final long row, final long col, final VoidFunction visitor) { myDelegate.visit(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, myRowsCount, col), 1L, visitor); } + @Override public void visitDiagonal(final long row, final long col, final VoidFunction visitor) { final long tmpCount = Math.min(myRowsCount - row, myColumnsCount - col); myDelegate.visit(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row + tmpCount, col + tmpCount), 1L + myRowsCount, visitor); } + @Override public void visitOne(final long row, final long col, final VoidFunction visitor) { myDelegate.visitOne(Structure2D.index(myRowsCount, row, col), visitor); } + @Override public void visitOne(final long index, final VoidFunction visitor) { myDelegate.visitOne(index, visitor); } + @Override public void visitRange(final long first, final long limit, final VoidFunction visitor) { myDelegate.visit(first, limit, 1L, visitor); } + @Override public void visitRow(final long row, final long col, final VoidFunction visitor) { myDelegate.visit(Structure2D.index(myRowsCount, row, col), Structure2D.index(myRowsCount, row, myColumnsCount), myRowsCount, visitor); } diff --git a/src/org/ojalgo/array/ArrayAnyD.java b/src/org/ojalgo/array/ArrayAnyD.java index 3a8dfff17..a376d245f 100644 --- a/src/org/ojalgo/array/ArrayAnyD.java +++ b/src/org/ojalgo/array/ArrayAnyD.java @@ -49,11 +49,11 @@ * * @author apete */ -public final class ArrayAnyD +public final class ArrayAnyD> implements AccessAnyD, AccessAnyD.Visitable, AccessAnyD.Aggregatable, AccessAnyD.Sliceable, AccessAnyD.Elements, AccessAnyD.IndexOf, StructureAnyD.ReducibleTo1D>, StructureAnyD.ReducibleTo2D>, MutateAnyD.ModifiableReceiver, MutateAnyD.Mixable { - public static final class Factory implements FactoryAnyD> { + public static final class Factory> implements FactoryAnyD.MayBeSparse, ArrayAnyD, ArrayAnyD> { private final BasicArray.Factory myDelegate; @@ -62,6 +62,10 @@ public static final class Factory implements FactoryAnyD(denseArray); } + /** + * @deprecated v48 Use {@link ArrayAnyD#fillMatching(Access1D)} + */ + @Deprecated public ArrayAnyD copy(final AccessAnyD source) { return myDelegate.copy(source).wrapInArrayAnyD(source.shape()); } @@ -71,6 +75,10 @@ public FunctionSet function() { return myDelegate.function(); } + /** + * @deprecated v48 Use {@link ArrayAnyD#fillAll(NullaryFunction)} + */ + @Deprecated public ArrayAnyD makeFilled(final long[] structure, final NullaryFunction supplier) { return myDelegate.makeFilled(StructureAnyD.count(structure), supplier).wrapInArrayAnyD(structure); } @@ -79,8 +87,9 @@ public ArrayAnyD makeSparse(final long... structure) { return myDelegate.makeStructuredZero(structure).wrapInArrayAnyD(structure); } + @Override public ArrayAnyD make(final long... structure) { - return myDelegate.makeToBeFilled(structure).wrapInArrayAnyD(structure); + return this.makeDense(structure); } @Override @@ -88,6 +97,10 @@ public Scalar.Factory scalar() { return myDelegate.scalar(); } + public ArrayAnyD makeDense(long... structure) { + return myDelegate.makeToBeFilled(structure).wrapInArrayAnyD(structure); + } + } public static final Factory BIG = new Factory<>(BigArray.FACTORY); @@ -99,7 +112,7 @@ public Scalar.Factory scalar() { public static final Factory QUATERNION = new Factory<>(QuaternionArray.FACTORY); public static final Factory RATIONAL = new Factory<>(RationalArray.FACTORY); - public static ArrayAnyD.Factory factory(final DenseArray.Factory denseArray) { + public static > ArrayAnyD.Factory factory(final DenseArray.Factory denseArray) { return new ArrayAnyD.Factory<>(denseArray); } @@ -119,36 +132,52 @@ private ArrayAnyD() { myStructure = structure; } + @Override public void add(final long index, final double addend) { myDelegate.add(index, addend); } - public void add(final long index, final Number addend) { + @Override + public void add(final long index, final float addend) { myDelegate.add(index, addend); } + @Override + public void add(final long index, final Comparable addend) { + myDelegate.add(index, addend); + } + + @Override public void add(final long[] reference, final double addend) { myDelegate.add(StructureAnyD.index(myStructure, reference), addend); } - public void add(final long[] reference, final Number addend) { + @Override + public void add(final long[] reference, final float addend) { myDelegate.add(StructureAnyD.index(myStructure, reference), addend); } + @Override + public void add(final long[] reference, final Comparable addend) { + myDelegate.add(StructureAnyD.index(myStructure, reference), addend); + } + + @Override public N aggregateRange(final long first, final long limit, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitRange(first, limit, visitor); return visitor.get(); } - public Number aggregateSet(final int dimension, final long dimensionalIndex, final Aggregator aggregator) { + @Override + public N aggregateSet(final int dimension, final long dimensionalIndex, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitSet(dimension, dimensionalIndex, visitor); return visitor.get(); } @Override - public Number aggregateSet(final long[] initial, final int dimension, final Aggregator aggregator) { + public N aggregateSet(final long[] initial, final int dimension, final Aggregator aggregator) { AggregatorFunction visitor = aggregator.getFunction(myDelegate.factory().aggregator()); this.visitSet(initial, dimension, visitor); return visitor.get(); @@ -169,18 +198,22 @@ public void clear() { myDelegate.reset(); } + @Override public long count() { return myDelegate.count(); } + @Override public long count(final int dimension) { return StructureAnyD.count(myStructure, dimension); } + @Override public double doubleValue(final long index) { return myDelegate.doubleValue(index); } + @Override public double doubleValue(final long[] ref) { return myDelegate.doubleValue(StructureAnyD.index(myStructure, ref)); } @@ -196,39 +229,48 @@ public boolean equals(final Object obj) { } } + @Override public void fillAll(final N value) { myDelegate.fill(0L, this.count(), 1L, value); } - public void fillAll(final NullaryFunction supplier) { + @Override + public void fillAll(final NullaryFunction supplier) { myDelegate.fill(0L, this.count(), 1L, supplier); } + @Override public void fillOne(final long index, final Access1D values, final long valueIndex) { myDelegate.fillOne(index, values, valueIndex); } + @Override public void fillOne(final long index, final N value) { myDelegate.fillOne(index, value); } - public void fillOne(final long index, final NullaryFunction supplier) { + @Override + public void fillOne(final long index, final NullaryFunction supplier) { myDelegate.fillOne(index, supplier); } + @Override public void fillOne(final long[] reference, final N value) { myDelegate.fillOne(StructureAnyD.index(myStructure, reference), value); } - public void fillOne(final long[] reference, final NullaryFunction supplier) { + @Override + public void fillOne(final long[] reference, final NullaryFunction supplier) { myDelegate.fillOne(StructureAnyD.index(myStructure, reference), supplier); } + @Override public void fillRange(final long first, final long limit, final N value) { myDelegate.fill(first, limit, 1L, value); } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + @Override + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { myDelegate.fill(first, limit, 1L, supplier); } @@ -238,23 +280,26 @@ public void fillSet(final int dimension, final long dimensionalIndex, final N va } @Override - public void fillSet(final int dimension, final long dimensionalIndex, final NullaryFunction supplier) { + public void fillSet(final int dimension, final long dimensionalIndex, final NullaryFunction supplier) { this.loop(dimension, dimensionalIndex, (f, l, s) -> myDelegate.fill(f, l, s, supplier)); } + @Override public void fillSet(final long[] initial, final int dimension, final N value) { this.loop(initial, dimension, (f, l, s) -> myDelegate.fill(f, l, s, value)); } @Override - public void fillSet(final long[] initial, final int dimension, final NullaryFunction supplier) { + public void fillSet(final long[] initial, final int dimension, final NullaryFunction supplier) { this.loop(initial, dimension, (f, l, s) -> myDelegate.fill(f, l, s, supplier)); } + @Override public N get(final long index) { return myDelegate.get(index); } + @Override public N get(final long[] ref) { return myDelegate.get(StructureAnyD.index(myStructure, ref)); } @@ -264,14 +309,17 @@ public int hashCode() { return myDelegate.hashCode(); } + @Override public long indexOfLargest() { return myDelegate.indexOfLargest(); } + @Override public long indexOfLargestInRange(final long first, final long limit) { return myDelegate.indexOfLargestInRange(first, limit); } + @Override public boolean isAbsolute(final long index) { return myDelegate.isAbsolute(index); } @@ -279,18 +327,22 @@ public boolean isAbsolute(final long index) { /** * @see Scalar#isAbsolute() */ + @Override public boolean isAbsolute(final long[] reference) { return myDelegate.isAbsolute(StructureAnyD.index(myStructure, reference)); } + @Override public boolean isSmall(final long index, final double comparedTo) { return myDelegate.isSmall(index, comparedTo); } + @Override public boolean isSmall(final long[] reference, final double comparedTo) { return myDelegate.isSmall(StructureAnyD.index(myStructure, reference), comparedTo); } + @Override public double mix(final long[] reference, final BinaryFunction mixer, final double addend) { ProgrammingError.throwIfNull(mixer); synchronized (myDelegate) { @@ -301,6 +353,7 @@ public double mix(final long[] reference, final BinaryFunction mixer, final d } } + @Override public N mix(final long[] reference, final BinaryFunction mixer, final N addend) { ProgrammingError.throwIfNull(mixer); synchronized (myDelegate) { @@ -311,30 +364,37 @@ public N mix(final long[] reference, final BinaryFunction mixer, final N adde } } + @Override public void modifyAll(final UnaryFunction modifier) { myDelegate.modify(0L, this.count(), 1L, modifier); } + @Override public void modifyAny(final TransformationAnyD modifier) { modifier.transform(this); } + @Override public void modifyMatching(final Access1D left, final BinaryFunction function) { myDelegate.modify(0L, this.count(), 1L, left, function); } + @Override public void modifyMatching(final BinaryFunction function, final Access1D right) { myDelegate.modify(0L, this.count(), 1L, function, right); } + @Override public void modifyOne(final long index, final UnaryFunction modifier) { myDelegate.modifyOne(index, modifier); } + @Override public void modifyOne(final long[] reference, final UnaryFunction modifier) { myDelegate.modifyOne(StructureAnyD.index(myStructure, reference), modifier); } + @Override public void modifyRange(final long first, final long limit, final UnaryFunction modifier) { myDelegate.modify(first, limit, 1L, modifier); } @@ -344,14 +404,17 @@ public void modifySet(final int dimension, final long dimensionalIndex, final Un this.loop(dimension, dimensionalIndex, (f, l, s) -> myDelegate.modify(f, l, s, modifier)); } + @Override public void modifySet(final long[] initial, final int dimension, final UnaryFunction modifier) { this.loop(initial, dimension, (f, l, s) -> myDelegate.modify(f, l, s, modifier)); } + @Override public int rank() { return myStructure.length; } + @Override public Array1D reduce(final int dimension, final Aggregator aggregator) { final long reduceToCount = StructureAnyD.count(myStructure, dimension); Array1D retVal = myDelegate.factory().makeZero(reduceToCount).wrapInArray1D(); @@ -392,30 +455,47 @@ public Array2D reduce(final int rowDimension, final int columnDimension, fina return retVal; } + @Override public void set(final long index, final double value) { myDelegate.set(index, value); } - public void set(final long index, final Number value) { + @Override + public void set(final long index, final float value) { myDelegate.set(index, value); } + @Override + public void set(final long index, final Comparable value) { + myDelegate.set(index, value); + } + + @Override public void set(final long[] reference, final double value) { myDelegate.set(StructureAnyD.index(myStructure, reference), value); } - public void set(final long[] reference, final Number value) { + @Override + public void set(final long[] reference, final float value) { + myDelegate.set(StructureAnyD.index(myStructure, reference), value); + } + + @Override + public void set(final long[] reference, final Comparable value) { myDelegate.set(StructureAnyD.index(myStructure, reference), value); } + @Override public long[] shape() { return myStructure; } + @Override public Array1D sliceRange(final long first, final long limit) { return myDelegate.wrapInArray1D().sliceRange(first, limit); } + @Override public Array1D sliceSet(final long[] initial, final int dimension) { AtomicLong first = new AtomicLong(); @@ -453,26 +533,32 @@ public String toString() { return retVal.toString(); } + @Override public void visitAll(final VoidFunction visitor) { myDelegate.visit(0L, this.count(), 1L, visitor); } + @Override public void visitOne(final long index, final VoidFunction visitor) { myDelegate.visitOne(index, visitor); } + @Override public void visitOne(final long[] reference, final VoidFunction visitor) { myDelegate.visitOne(StructureAnyD.index(myStructure, reference), visitor); } + @Override public void visitRange(final long first, final long limit, final VoidFunction visitor) { myDelegate.visit(first, limit, 1L, visitor); } + @Override public void visitSet(final int dimension, final long dimensionalIndex, final VoidFunction visitor) { this.loop(dimension, dimensionalIndex, (f, l, s) -> myDelegate.visit(f, l, s, visitor)); } + @Override public void visitSet(final long[] initial, final int dimension, final VoidFunction visitor) { this.loop(initial, dimension, (f, l, s) -> myDelegate.visit(f, l, s, visitor)); } diff --git a/src/org/ojalgo/array/ArrayFactory.java b/src/org/ojalgo/array/ArrayFactory.java index 37b9a4555..8b30a8de5 100644 --- a/src/org/ojalgo/array/ArrayFactory.java +++ b/src/org/ojalgo/array/ArrayFactory.java @@ -33,7 +33,7 @@ import org.ojalgo.structure.Factory1D; import org.ojalgo.structure.StructureAnyD; -abstract class ArrayFactory> extends Object implements Factory1D> { +abstract class ArrayFactory, I extends BasicArray> implements Factory1D { public abstract AggregatorSet aggregator(); @@ -53,7 +53,7 @@ public final I copy(final double... source) { return retVal; } - public final I copy(final List source) { + public final I copy(final List> source) { final int size = source.size(); final I retVal = this.makeToBeFilled(size); for (int i = 0; i < size; i++) { @@ -62,7 +62,7 @@ public final I copy(final List source) { return retVal; } - public final I copy(final Number... source) { + public final I copy(final Comparable... source) { final int length = source.length; final I retVal = this.makeToBeFilled(length); for (int i = 0; i < length; i++) { diff --git a/src/org/ojalgo/array/BasicArray.java b/src/org/ojalgo/array/BasicArray.java index f2ca27400..cae39e68c 100644 --- a/src/org/ojalgo/array/BasicArray.java +++ b/src/org/ojalgo/array/BasicArray.java @@ -37,8 +37,8 @@ /** *

* A BasicArray is 1-dimensional, but designed to easily be extended or encapsulated, and then treated as - * arbitrary-dimensional. It stores/handles (any subclass of) {@linkplain java.lang.Number} elements depending - * on the subclass/implementation. + * arbitrary-dimensional. It stores/handles (any subclass of) {@linkplain java.lang.Comparable} elements + * depending on the subclass/implementation. *

*

* This abstract class defines a set of methods to access and modify array elements. It does not "know" @@ -47,10 +47,10 @@ * * @author apete */ -public abstract class BasicArray +public abstract class BasicArray> implements Access1D, Access1D.Elements, Access1D.IndexOf, Access1D.Visitable, Mutate1D, Mutate1D.Fillable, Mutate1D.Modifiable { - public static final class Factory extends ArrayFactory> { + public static final class Factory> extends ArrayFactory> { private static final long SPARSE_SEGMENTATION_LIMIT = PowerOf2.powerOfLong2(46); @@ -212,7 +212,7 @@ public void visitRange(final long first, final long limit, final VoidFunction protected abstract void fill(long first, long limit, long step, N value); - protected abstract void fill(long first, long limit, long step, NullaryFunction supplier); + protected abstract void fill(long first, long limit, long step, NullaryFunction supplier); protected long indexOfLargest(final long first, final long limit, final long step) { return AMAX.invoke(this, first, limit, step); diff --git a/src/org/ojalgo/array/BigArray.java b/src/org/ojalgo/array/BigArray.java index 43f60779c..551f342f9 100644 --- a/src/org/ojalgo/array/BigArray.java +++ b/src/org/ojalgo/array/BigArray.java @@ -34,6 +34,7 @@ import org.ojalgo.machine.MemoryEstimator; import org.ojalgo.scalar.BigScalar; import org.ojalgo.scalar.Scalar; +import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; /** @@ -90,6 +91,7 @@ protected BigArray(final int size) { super(FACTORY, size); } + @Override public final void axpy(final double a, final Mutate1D y) { AXPY.invoke(y, a, data); } @@ -124,7 +126,12 @@ protected final void add(final int index, final double addend) { } @Override - protected final void add(final int index, final Number addend) { + protected final void add(final int index, final float addend) { + this.fillOne(index, this.get(index).add(this.valueOf(addend))); + } + + @Override + protected final void add(final int index, final Comparable addend) { this.fillOne(index, this.get(index).add(this.valueOf(addend))); } @@ -143,4 +150,14 @@ protected boolean isSmall(final int index, final double comparedTo) { return BigScalar.isSmall(comparedTo, data[index]); } + @Override + protected final double doubleValue(final int index) { + return data[index].doubleValue(); + } + + @Override + protected final void fillOne(final int index, final Access1D values, final long valueIndex) { + data[index] = this.valueOf(values.get(valueIndex)); + } + } diff --git a/src/org/ojalgo/array/BufferArray.java b/src/org/ojalgo/array/BufferArray.java index 96bd2ec02..97203313f 100644 --- a/src/org/ojalgo/array/BufferArray.java +++ b/src/org/ojalgo/array/BufferArray.java @@ -84,6 +84,11 @@ protected void set(final int index, final double value) { myDoubleBuffer.put(index, value); } + @Override + protected void set(final int index, final float value) { + myDoubleBuffer.put(index, value); + } + } static final class FloatBufferArray extends BufferArray { @@ -107,6 +112,11 @@ protected void set(final int index, final double value) { myFloatBuffer.put(index, (float) value); } + @Override + protected void set(final int index, final float value) { + myFloatBuffer.put(index, value); + } + } public static final DenseArray.Factory DIRECT32 = new DenseArray.Factory() { @@ -384,8 +394,13 @@ protected void add(final int index, final double addend) { } @Override - protected void add(final int index, final Number addend) { - this.set(index, this.doubleValue(index) + addend.doubleValue()); + protected void add(final int index, final float addend) { + this.set(index, this.floatValue(index) + addend); + } + + @Override + protected void add(final int index, final Comparable addend) { + this.set(index, this.doubleValue(index) + Scalar.doubleValue(addend)); } @Override @@ -428,7 +443,7 @@ protected void fill(final int first, final int limit, final int step, final Doub } @Override - protected void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { + protected void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { BufferArray.fill(this, first, limit, step, supplier); } @@ -522,8 +537,8 @@ protected int searchAscending(final Double number) { } @Override - protected void set(final int index, final Number value) { - this.set(index, value.doubleValue()); + protected void set(final int index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); } @Override diff --git a/src/org/ojalgo/array/DenseArray.java b/src/org/ojalgo/array/DenseArray.java index 52848b86e..60a991ab8 100644 --- a/src/org/ojalgo/array/DenseArray.java +++ b/src/org/ojalgo/array/DenseArray.java @@ -26,6 +26,7 @@ import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.structure.Access1D; +import org.ojalgo.structure.Factory1D; import org.ojalgo.structure.StructureAnyD; /** @@ -35,9 +36,9 @@ * * @author apete */ -public abstract class DenseArray extends BasicArray { +public abstract class DenseArray> extends BasicArray { - public static abstract class Factory extends ArrayFactory> { + public static abstract class Factory> extends ArrayFactory> implements Factory1D.Dense> { @Override long getCapacityLimit() { diff --git a/src/org/ojalgo/array/DenseCapacityStrategy.java b/src/org/ojalgo/array/DenseCapacityStrategy.java index 669486726..454686ac0 100644 --- a/src/org/ojalgo/array/DenseCapacityStrategy.java +++ b/src/org/ojalgo/array/DenseCapacityStrategy.java @@ -12,7 +12,7 @@ * * @author apete */ -final class DenseCapacityStrategy { +final class DenseCapacityStrategy> { /** * 512 diff --git a/src/org/ojalgo/array/LongToNumberMap.java b/src/org/ojalgo/array/LongToNumberMap.java index d7d6b0892..c74bee199 100644 --- a/src/org/ojalgo/array/LongToNumberMap.java +++ b/src/org/ojalgo/array/LongToNumberMap.java @@ -12,21 +12,22 @@ import org.ojalgo.array.SparseArray.NonzeroView; import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; import org.ojalgo.type.context.NumberContext; /** - * A {@link SortedMap} with primitive valued long keys and {@link Number} values (incl. possibly primitive + * A {@link SortedMap} with primitive valued long keys and {@link Comparable} values (incl. possibly primitive * double values). The main benefits of using this class is its use of primitive keys and values, and how it * integrates with other parts of ojAlgo. As a general purpose {@link Map} implementation (usage with high * frequency of randomly ordered put and remove operations) it is not very efficient. * * @author apete */ -public final class LongToNumberMap implements SortedMap, Access1D, Mutate1D.Mixable { +public final class LongToNumberMap> implements SortedMap, Access1D, Mutate1D.Mixable { - public static final class MapFactory extends StrategyBuilder, MapFactory> { + public static final class MapFactory> extends StrategyBuilder, MapFactory> { MapFactory(final Factory denseFactory) { super(denseFactory); @@ -39,7 +40,7 @@ public LongToNumberMap make() { } - public static MapFactory factory(final DenseArray.Factory denseFactory) { + public static > MapFactory factory(final DenseArray.Factory denseFactory) { return new MapFactory<>(denseFactory); } @@ -77,8 +78,8 @@ public boolean containsKey(final long key) { } public boolean containsKey(final Object key) { - if (key instanceof Number) { - return this.containsKey(((Number) key).longValue()); + if (key instanceof Comparable) { + return this.containsKey(Scalar.longValue((Comparable) key)); } else { return false; } @@ -175,7 +176,7 @@ public N get(final long key) { } public N get(final Object key) { - return key instanceof Number ? this.get(((Number) key).longValue()) : null; + return key instanceof Comparable ? this.get(Scalar.longValue((Comparable) key)) : null; } public LongToNumberMap headMap(final long toKey) { @@ -280,8 +281,8 @@ public N remove(final long key) { } public N remove(final Object key) { - if (key instanceof Number) { - return this.remove(((Number) key).longValue()); + if (key instanceof Comparable) { + return this.remove(Scalar.longValue((Comparable) key)); } else { return null; } diff --git a/src/org/ojalgo/array/NumberList.java b/src/org/ojalgo/array/NumberList.java index e7d3d41f6..8ffd0a4a4 100644 --- a/src/org/ojalgo/array/NumberList.java +++ b/src/org/ojalgo/array/NumberList.java @@ -49,9 +49,9 @@ * * @author apete */ -public final class NumberList implements List, RandomAccess, Access1D, Access1D.Visitable, Mutate1D, Mutate1D.Mixable { +public final class NumberList> implements List, RandomAccess, Access1D, Access1D.Visitable, Mutate1D, Mutate1D.Mixable { - public static final class ListFactory extends StrategyBuilder, ListFactory> { + public static final class ListFactory> extends StrategyBuilder, ListFactory> { ListFactory(final DenseArray.Factory denseFactory) { super(denseFactory); @@ -64,7 +64,7 @@ public NumberList make() { } - public static Collector, NumberList> collector(final DenseArray.Factory arrayFactory) { + public static > Collector, NumberList> collector(final DenseArray.Factory arrayFactory) { final Supplier> tmpSupplier = () -> NumberList.factory(arrayFactory).make(); final BiConsumer, N> tmpAccumulator = (list, element) -> list.add(element); final BinaryOperator> tmpCombiner = (part1, part2) -> { @@ -75,7 +75,7 @@ public static Collector, NumberList> coll return Collector.of(tmpSupplier, tmpAccumulator, tmpCombiner, tmpIdentity, Collector.Characteristics.IDENTITY_FINISH); } - public static ListFactory factory(final DenseArray.Factory arrayFactory) { + public static > ListFactory factory(final DenseArray.Factory arrayFactory) { return new ListFactory<>(arrayFactory); } @@ -112,6 +112,7 @@ public boolean add(final double element) { return true; } + @Override public void add(final int index, final N element) { this.ensureCapacity(); @@ -124,6 +125,7 @@ public void add(final int index, final N element) { myActualCount++; } + @Override public void add(final long index, final double addend) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); @@ -132,7 +134,8 @@ public void add(final long index, final double addend) { } } - public void add(final long index, final Number addend) { + @Override + public void add(final long index, final float addend) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -140,6 +143,16 @@ public void add(final long index, final Number addend) { } } + @Override + public void add(final long index, final Comparable addend) { + if (index >= myActualCount) { + throw new ArrayIndexOutOfBoundsException(); + } else { + myStorage.add(index, addend); + } + } + + @Override public boolean add(final N element) { this.ensureCapacity(); @@ -149,6 +162,7 @@ public boolean add(final N element) { return true; } + @Override public boolean addAll(final Collection elements) { for (final N tmpElement : elements) { this.add(tmpElement); @@ -163,6 +177,7 @@ public boolean addAll(final double[] elements) { return true; } + @Override public boolean addAll(final int index, final Collection elements) { int counter = 0; for (final N value : elements) { @@ -185,19 +200,22 @@ public long capacity() { return myStorage.count(); } + @Override public void clear() { myActualCount = 0L; myStorage.reset(); } + @Override public boolean contains(final Object object) { - if (object instanceof Number) { + if (object instanceof Comparable) { return this.indexOf(object) >= 0; } else { return false; } } + @Override public boolean containsAll(final Collection c) { for (final Object tmpObject : c) { if (!this.contains(tmpObject)) { @@ -207,10 +225,12 @@ public boolean containsAll(final Collection c) { return true; } + @Override public long count() { return myActualCount; } + @Override public double doubleValue(final long index) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); @@ -219,6 +239,7 @@ public double doubleValue(final long index) { } } + @Override public N get(final int index) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); @@ -227,6 +248,7 @@ public N get(final int index) { } } + @Override public N get(final long index) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); @@ -235,6 +257,7 @@ public N get(final long index) { } } + @Override public int indexOf(final Object object) { final ListIterator tmpIterator = this.listIterator(); if (object == null) { @@ -253,14 +276,17 @@ public int indexOf(final Object object) { return -1; } + @Override public boolean isEmpty() { return myActualCount == 0L; } + @Override public Iterator iterator() { return new Iterator1D<>(this); } + @Override public int lastIndexOf(final Object object) { final ListIterator tmpIterator = this.listIterator(this.size()); if (object == null) { @@ -279,14 +305,17 @@ public int lastIndexOf(final Object object) { return -1; } + @Override public ListIterator listIterator() { return new Iterator1D<>(this); } + @Override public ListIterator listIterator(final int index) { return new Iterator1D<>(this, index); } + @Override public double mix(final long index, final BinaryFunction mixer, final double addend) { ProgrammingError.throwIfNull(mixer); if (index >= myActualCount) { @@ -301,6 +330,7 @@ public double mix(final long index, final BinaryFunction mixer, final double } } + @Override public N mix(final long index, final BinaryFunction mixer, final N addend) { ProgrammingError.throwIfNull(mixer); if (index >= myActualCount) { @@ -315,6 +345,7 @@ public N mix(final long index, final BinaryFunction mixer, final N addend) { } } + @Override public N remove(final int index) { final N oldValue = myStorage.get(index); @@ -328,6 +359,7 @@ public N remove(final int index) { return oldValue; } + @Override public boolean remove(final Object o) { final int index = this.indexOf(o); if (index >= 0) { @@ -338,6 +370,7 @@ public boolean remove(final Object o) { } } + @Override public boolean removeAll(final Collection c) { boolean retVal = false; for (final Object o : c) { @@ -346,6 +379,7 @@ public boolean removeAll(final Collection c) { return retVal; } + @Override public boolean retainAll(final Collection onlyKeep) { boolean retVal = false; final Object[] values = this.toArray(); @@ -357,6 +391,7 @@ public boolean retainAll(final Collection onlyKeep) { return retVal; } + @Override public N set(final int index, final N element) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); @@ -367,6 +402,7 @@ public N set(final int index, final N element) { } } + @Override public void set(final long index, final double value) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); @@ -375,7 +411,17 @@ public void set(final long index, final double value) { } } - public void set(final long index, final Number value) { + @Override + public void set(final long index, final float value) { + if (index >= myActualCount) { + throw new ArrayIndexOutOfBoundsException(); + } else { + myStorage.set(index, value); + } + } + + @Override + public void set(final long index, final Comparable value) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -383,10 +429,12 @@ public void set(final long index, final Number value) { } } + @Override public int size() { return (int) myActualCount; } + @Override public NumberList subList(final int fromIndex, final int toIndex) { final NumberList retVal = new NumberList<>(myStrategy); if (myStorage instanceof Primitive64Array) { @@ -401,10 +449,12 @@ public NumberList subList(final int fromIndex, final int toIndex) { return retVal; } + @Override public Object[] toArray() { return this.toArray(new Object[this.size()]); } + @Override @SuppressWarnings("unchecked") public T[] toArray(final T[] array) { for (int i = 0; i < array.length; i++) { @@ -418,6 +468,7 @@ public String toString() { return Access1D.toString(this); } + @Override public void visitOne(final long index, final VoidFunction visitor) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); diff --git a/src/org/ojalgo/array/PlainArray.java b/src/org/ojalgo/array/PlainArray.java index 98a56ef16..b98849285 100644 --- a/src/org/ojalgo/array/PlainArray.java +++ b/src/org/ojalgo/array/PlainArray.java @@ -40,7 +40,7 @@ * * @author apete */ -abstract class PlainArray extends DenseArray implements RandomAccess { +abstract class PlainArray> extends DenseArray implements RandomAccess { static final int CHARACTERISTICS = Spliterator.ORDERED | Spliterator.IMMUTABLE; @@ -53,50 +53,67 @@ abstract class PlainArray extends DenseArray implements Ran } } + @Override public void add(final long index, final double addend) { this.add((int) index, addend); } - public void add(final long index, final Number addend) { + @Override + public void add(final long index, final float addend) { this.add((int) index, addend); } + @Override + public void add(final long index, final Comparable addend) { + this.add((int) index, addend); + } + + @Override public final long count() { return this.size(); } + @Override public final double doubleValue(final long index) { return this.doubleValue((int) index); } + @Override public final void fillAll(final N number) { this.fill(0, this.size(), 1, number); } - public final void fillAll(final NullaryFunction supplier) { + @Override + public final void fillAll(final NullaryFunction supplier) { this.fill(0, this.size(), 1, supplier); } + @Override public final void fillOne(final long index, final Access1D values, final long valueIndex) { this.fillOne((int) index, values, valueIndex); } + @Override public void fillOne(final long index, final N value) { this.fillOne((int) index, value); } - public void fillOne(final long index, final NullaryFunction supplier) { + @Override + public void fillOne(final long index, final NullaryFunction supplier) { this.fillOne((int) index, supplier); } + @Override public final void fillRange(final long first, final long limit, final N number) { this.fill(first, limit, 1L, number); } - public final void fillRange(final long first, final long limit, final NullaryFunction supplier) { + @Override + public final void fillRange(final long first, final long limit, final NullaryFunction supplier) { this.fill(first, limit, 1L, supplier); } + @Override public final N get(final long index) { return this.get((int) index); } @@ -104,6 +121,7 @@ public final N get(final long index) { /** * @see Scalar#isAbsolute() */ + @Override public final boolean isAbsolute(final long index) { return this.isAbsolute((int) index); } @@ -111,22 +129,32 @@ public final boolean isAbsolute(final long index) { /** * @see Scalar#isSmall(double) */ + @Override public final boolean isSmall(final long index, final double comparedTo) { return this.isSmall((int) index, comparedTo); } + @Override public final void modifyOne(final long index, final UnaryFunction modifier) { this.modifyOne((int) index, modifier); } + @Override public final void set(final long index, final double value) { this.set((int) index, value); } - public final void set(final long index, final Number number) { + @Override + public final void set(final long index, final float value) { + this.set((int) index, value); + } + + @Override + public final void set(final long index, final Comparable number) { this.set((int) index, number); } + @Override public void visitOne(final long index, final VoidFunction visitor) { this.visitOne((int) index, visitor); } @@ -144,7 +172,9 @@ private final boolean isSmall(final int first, final int limit, final int step, protected abstract void add(int index, double addend); - protected abstract void add(int index, Number addend); + protected abstract void add(int index, float addend); + + protected abstract void add(int index, Comparable addend); protected abstract double doubleValue(final int index); @@ -161,7 +191,7 @@ protected final void exchange(final long firstA, final long firstB, final long s protected abstract void fill(int first, int limit, int step, N value); - protected abstract void fill(int first, int limit, int step, NullaryFunction supplier); + protected abstract void fill(int first, int limit, int step, NullaryFunction supplier); protected abstract void fill(final int first, final int limit, final N left, final BinaryFunction function, final Access1D right); @@ -171,7 +201,7 @@ protected final void fill(final long first, final long limit, final long step, f } @Override - protected final void fill(final long first, final long limit, final long step, final NullaryFunction supplier) { + protected final void fill(final long first, final long limit, final long step, final NullaryFunction supplier) { this.fill((int) first, (int) limit, (int) step, supplier); } @@ -238,7 +268,9 @@ protected final void modify(final long first, final long limit, final long step, protected abstract void set(final int index, final double value); - protected abstract void set(final int index, final Number number); + protected abstract void set(final int index, final float value); + + protected abstract void set(final int index, final Comparable number); protected abstract void sortAscending(); diff --git a/src/org/ojalgo/array/Primitive32Array.java b/src/org/ojalgo/array/Primitive32Array.java index 17dd4a2dc..6164f85c3 100644 --- a/src/org/ojalgo/array/Primitive32Array.java +++ b/src/org/ojalgo/array/Primitive32Array.java @@ -203,7 +203,7 @@ protected static void fill(final float[] data, final int first, final int limit, } } - protected static void fill(final float[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { + protected static void fill(final float[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { for (int i = first; i < limit; i += step) { data[i] = (float) supplier.doubleValue(); } @@ -316,7 +316,7 @@ static void invoke(final float[] data, final int first, final int limit, final i Primitive32Array.subtract(data, first, limit, step, left, right); } else { for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(left[i], right[i]); + data[i] = function.invoke(left[i], right[i]); } } } @@ -324,7 +324,7 @@ static void invoke(final float[] data, final int first, final int limit, final i static void invoke(final float[] data, final int first, final int limit, final int step, final float[] values, final ParameterFunction function, final int aParam) { for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(values[i], aParam); + data[i] = function.invoke(values[i], aParam); } } @@ -342,7 +342,7 @@ static void invoke(final float[] data, final int first, final int limit, final i Primitive32Array.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.getParameter()); } else { for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(values[i]); + data[i] = function.invoke(values[i]); } } } @@ -366,6 +366,7 @@ protected Primitive32Array(final int size) { data = new float[size]; } + @Override public void axpy(final double a, final Mutate1D y) { AXPY.invoke(y, a, data); } @@ -391,15 +392,18 @@ public boolean equals(final Object anObj) { } } + @Override public void fillMatching(final Access1D values) { Primitive32Array.fill(data, values); } + @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); Primitive32Array.invoke(data, 0, limit, 1, left, function, right); } + @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); Primitive32Array.invoke(data, 0, limit, 1, arguments, function); @@ -433,8 +437,13 @@ protected void add(final int index, final double addend) { } @Override - protected void add(final int index, final Number addend) { - data[index] += addend.floatValue(); + protected void add(final int index, final float addend) { + data[index] += addend; + } + + @Override + protected void add(final int index, final Comparable addend) { + data[index] += Scalar.floatValue(addend); } protected final float[] copyOfData() { @@ -473,7 +482,7 @@ protected final void fill(final int first, final int limit, final int step, fina } @Override - protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { + protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { Primitive32Array.fill(data, first, limit, step, supplier); } @@ -544,7 +553,7 @@ protected final void modify(final int first, final int limit, final int step, fi @Override protected final void modifyOne(final int index, final UnaryFunction modifier) { - data[index] = (float) modifier.invoke(data[index]); + data[index] = modifier.invoke(data[index]); } @Override @@ -558,8 +567,13 @@ protected final void set(final int index, final double value) { } @Override - protected final void set(final int index, final Number value) { - data[index] = value.floatValue(); + protected final void set(final int index, final float value) { + data[index] = value; + } + + @Override + protected final void set(final int index, final Comparable value) { + data[index] = Scalar.floatValue(value); } @Override @@ -584,7 +598,7 @@ void modify(final long extIndex, final int intIndex, final BinaryFunction function) { - data[intIndex] = (float) function.invoke(data[intIndex]); + data[intIndex] = function.invoke(data[intIndex]); } } diff --git a/src/org/ojalgo/array/Primitive64Array.java b/src/org/ojalgo/array/Primitive64Array.java index f02e26eff..fece33a8c 100644 --- a/src/org/ojalgo/array/Primitive64Array.java +++ b/src/org/ojalgo/array/Primitive64Array.java @@ -207,7 +207,7 @@ protected static void fill(final double[] data, final int first, final int limit } } - protected static void fill(final double[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { + protected static void fill(final double[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { for (int i = first; i < limit; i += step) { data[i] = supplier.doubleValue(); } @@ -370,6 +370,7 @@ protected Primitive64Array(final int size) { data = new double[size]; } + @Override public void axpy(final double a, final Mutate1D y) { AXPY.invoke(y, a, data); } @@ -395,15 +396,18 @@ public boolean equals(final Object anObj) { } } + @Override public void fillMatching(final Access1D values) { Primitive64Array.fill(data, values); } + @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); Primitive64Array.invoke(data, 0, limit, 1, left, function, right); } + @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); Primitive64Array.invoke(data, 0, limit, 1, arguments, function); @@ -445,8 +449,13 @@ protected void add(final int index, final double addend) { } @Override - protected void add(final int index, final Number addend) { - data[index] += addend.doubleValue(); + protected void add(final int index, final float addend) { + data[index] += addend; + } + + @Override + protected void add(final int index, final Comparable addend) { + data[index] += Scalar.doubleValue(addend); } protected final double[] copyOfData() { @@ -485,7 +494,7 @@ protected final void fill(final int first, final int limit, final int step, fina } @Override - protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { + protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { Primitive64Array.fill(data, first, limit, step, supplier); } @@ -570,8 +579,13 @@ protected final void set(final int index, final double value) { } @Override - protected final void set(final int index, final Number value) { - data[index] = value.doubleValue(); + protected final void set(final int index, final float value) { + data[index] = value; + } + + @Override + protected final void set(final int index, final Comparable value) { + data[index] = Scalar.doubleValue(value); } @Override diff --git a/src/org/ojalgo/array/ReferenceTypeArray.java b/src/org/ojalgo/array/ReferenceTypeArray.java index b1b6dc02d..d741df824 100644 --- a/src/org/ojalgo/array/ReferenceTypeArray.java +++ b/src/org/ojalgo/array/ReferenceTypeArray.java @@ -33,17 +33,18 @@ import org.ojalgo.function.VoidFunction; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; /** - * A one- and/or arbitrary-dimensional array of {@linkplain java.lang.Number}. + * A one- and/or arbitrary-dimensional array of {@linkplain java.lang.Comparable}. * * @author apete */ -public abstract class ReferenceTypeArray extends PlainArray implements Mutate1D.Sortable { +public abstract class ReferenceTypeArray> extends PlainArray implements Mutate1D.Sortable { - protected static void exchange(final N[] data, final int firstA, final int firstB, final int step, final int aCount) { + protected static > void exchange(final N[] data, final int firstA, final int firstB, final int step, final int aCount) { int tmpIndexA = firstA; int tmpIndexB = firstB; @@ -61,54 +62,55 @@ protected static void exchange(final N[] data, final int firs } } - protected static void fill(final N[] data, final int first, final int limit, final int step, final N value) { + protected static > void fill(final N[] data, final int first, final int limit, final int step, final N value) { for (int i = first; i < limit; i += step) { data[i] = value; } } - protected static void fill(final N[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { + protected static > void fill(final N[] data, final int first, final int limit, final int step, final NullaryFunction supplier, + Scalar.Factory scalar) { for (int i = first; i < limit; i += step) { - data[i] = supplier.invoke(); + data[i] = scalar.cast(supplier.invoke()); } } - protected static void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, + protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, final BinaryFunction function, final Access1D right) { for (int i = first; i < limit; i += step) { data[i] = function.invoke(left.get(i), right.get(i)); } } - protected static void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, + protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, final BinaryFunction function, final N right) { for (int i = first; i < limit; i += step) { data[i] = function.invoke(left.get(i), right); } } - protected static void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, + protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, final ParameterFunction function, final int aParam) { for (int i = first; i < limit; i += step) { data[i] = function.invoke(value.get(i), aParam); } } - protected static void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, + protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, final UnaryFunction function) { for (int i = first; i < limit; i += step) { data[i] = function.invoke(value.get(i)); } } - protected static void invoke(final N[] data, final int first, final int limit, final int step, final N left, + protected static > void invoke(final N[] data, final int first, final int limit, final int step, final N left, final BinaryFunction function, final Access1D right) { for (int i = first; i < limit; i += step) { data[i] = function.invoke(left, right.get(i)); } } - protected static void invoke(final N[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { + protected static > void invoke(final N[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { for (int i = first; i < limit; i += step) { aVisitor.invoke(data[i]); } @@ -141,12 +143,14 @@ public boolean equals(final Object anObj) { } } + @Override public void fillMatching(final Access1D values) { for (int i = 0, limit = (int) Math.min(this.count(), values.count()); i < limit; i++) { data[i] = this.factory().scalar().cast(values.get(i)); } } + @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); for (int i = 0; i < limit; i++) { @@ -154,6 +158,7 @@ public void fillMatching(final Access1D left, final BinaryFunction functio } } + @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); for (int i = 0; i < limit; i++) { @@ -184,11 +189,6 @@ protected final N[] copyOfData() { return COPY.copyOf(data); } - @Override - protected final double doubleValue(final int index) { - return data[index].doubleValue(); - } - @Override protected final void exchange(final int firstA, final int firstB, final int step, final int count) { ReferenceTypeArray.exchange(data, firstA, firstB, step, count); @@ -210,8 +210,8 @@ protected final void fill(final int first, final int limit, final int step, fina } @Override - protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { - ReferenceTypeArray.fill(data, first, limit, step, supplier); + protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { + ReferenceTypeArray.fill(data, first, limit, step, supplier, this.factory().scalar()); } @Override @@ -219,11 +219,6 @@ protected final void fill(final int first, final int limit, final N left, final ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right); } - @Override - protected final void fillOne(final int index, final Access1D values, final long valueIndex) { - data[index] = this.valueOf(values.get(valueIndex)); - } - @Override protected final void fillOne(final int index, final N value) { data[index] = value; @@ -286,7 +281,12 @@ protected final void set(final int index, final double value) { } @Override - protected final void set(final int index, final Number value) { + protected final void set(final int index, final float value) { + data[index] = this.valueOf(value); + } + + @Override + protected final void set(final int index, final Comparable value) { data[index] = this.valueOf(value); } @@ -324,7 +324,11 @@ final N valueOf(final double value) { return this.factory().scalar().cast(value); } - final N valueOf(final Number number) { + final N valueOf(final float value) { + return this.factory().scalar().cast(value); + } + + final N valueOf(final Comparable number) { return this.factory().scalar().cast(number); } diff --git a/src/org/ojalgo/array/ScalarArray.java b/src/org/ojalgo/array/ScalarArray.java index b5e5a21a0..1f0e86b57 100644 --- a/src/org/ojalgo/array/ScalarArray.java +++ b/src/org/ojalgo/array/ScalarArray.java @@ -27,6 +27,7 @@ import org.ojalgo.array.operation.AMAX; import org.ojalgo.array.operation.AXPY; import org.ojalgo.scalar.Scalar; +import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; /** @@ -34,7 +35,7 @@ * * @author apete */ -public abstract class ScalarArray> extends ReferenceTypeArray { +public abstract class ScalarArray> extends ReferenceTypeArray { protected ScalarArray(final DenseArray.Factory factory, final int length) { super(factory, length); @@ -44,6 +45,7 @@ protected ScalarArray(final DenseArray.Factory factory, final N[] data) { super(factory, data); } + @Override public final void axpy(final double a, final Mutate1D y) { AXPY.invoke(y, a, data); } @@ -64,7 +66,12 @@ protected final void add(final int index, final double addend) { } @Override - protected final void add(final int index, final Number addend) { + protected final void add(final int index, final float addend) { + this.fillOne(index, this.get(index).add(this.valueOf(addend)).get()); + } + + @Override + protected final void add(final int index, final Comparable addend) { this.fillOne(index, this.get(index).add(this.valueOf(addend)).get()); } @@ -83,4 +90,14 @@ protected final boolean isSmall(final int index, final double comparedTo) { return data[index].isSmall(comparedTo); } + @Override + protected final double doubleValue(final int index) { + return data[index].doubleValue(); + } + + @Override + protected final void fillOne(final int index, final Access1D values, final long valueIndex) { + data[index] = this.valueOf(values.get(valueIndex)); + } + } diff --git a/src/org/ojalgo/array/SegmentedArray.java b/src/org/ojalgo/array/SegmentedArray.java index 9924387f5..3104353a0 100644 --- a/src/org/ojalgo/array/SegmentedArray.java +++ b/src/org/ojalgo/array/SegmentedArray.java @@ -26,6 +26,7 @@ import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.special.PowerOf2; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; /** @@ -38,7 +39,7 @@ * * @author apete */ -final class SegmentedArray extends BasicArray { +final class SegmentedArray> extends BasicArray { private final int myIndexBits; private final long myIndexMask; @@ -105,11 +106,18 @@ final class SegmentedArray extends BasicArray { mySegmentFactory = segmentFactory; } + @Override public void add(final long index, final double addend) { mySegments[(int) (index >> myIndexBits)].add(index & myIndexMask, addend); } - public void add(final long index, final Number addend) { + @Override + public void add(final long index, final float addend) { + mySegments[(int) (index >> myIndexBits)].add(index & myIndexMask, addend); + } + + @Override + public void add(final long index, final Comparable addend) { mySegments[(int) (index >> myIndexBits)].add(index & myIndexMask, addend); } @@ -118,34 +126,41 @@ public long count() { return (mySegments[0].count() * (mySegments.length - 1)) + mySegments[mySegments.length - 1].count(); } + @Override public double doubleValue(final long index) { return mySegments[(int) (index >> myIndexBits)].doubleValue(index & myIndexMask); } + @Override public void fillAll(final N value) { for (final BasicArray tmpSegment : mySegments) { tmpSegment.fillAll(value); } } - public void fillAll(final NullaryFunction supplier) { + @Override + public void fillAll(final NullaryFunction supplier) { for (final BasicArray tmpSegment : mySegments) { tmpSegment.fillAll(supplier); } } + @Override public void fillOne(final long index, final Access1D values, final long valueIndex) { mySegments[(int) (index >> myIndexBits)].fillOne(index & myIndexMask, values, valueIndex); } + @Override public void fillOne(final long index, final N value) { mySegments[(int) (index >> myIndexBits)].fillOne(index & myIndexMask, value); } - public void fillOne(final long index, final NullaryFunction supplier) { + @Override + public void fillOne(final long index, final NullaryFunction supplier) { mySegments[(int) (index >> myIndexBits)].fillOne(index & myIndexMask, supplier); } + @Override public void fillRange(final long first, final long limit, final N value) { final int tmpFirstSegment = (int) (first / mySegmentSize); @@ -161,7 +176,8 @@ public void fillRange(final long first, final long limit, final N value) { } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + @Override + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { final int tmpFirstSegment = (int) (first / mySegmentSize); final int tmpLastSegemnt = (int) ((limit - 1) / mySegmentSize); @@ -176,6 +192,7 @@ public void fillRange(final long first, final long limit, final NullaryFunction< } + @Override public N get(final long index) { return mySegments[(int) (index >> myIndexBits)].get(index & myIndexMask); } @@ -218,14 +235,17 @@ public SegmentedArray grow() { } } + @Override public boolean isAbsolute(final long index) { return mySegments[(int) (index >> myIndexBits)].isAbsolute(index & myIndexMask); } + @Override public boolean isSmall(final long index, final double comparedTo) { return mySegments[(int) (index >> myIndexBits)].isSmall(index & myIndexMask, comparedTo); } + @Override public void modifyOne(final long index, final UnaryFunction modifier) { final BasicArray tmpSegment = mySegments[(int) (index >> myIndexBits)]; final long tmpIndex = index & myIndexMask; @@ -239,14 +259,22 @@ public void reset() { } } + @Override public void set(final long index, final double value) { mySegments[(int) (index >> myIndexBits)].set(index & myIndexMask, value); } - public void set(final long index, final Number value) { + @Override + public void set(final long index, final float value) { + mySegments[(int) (index >> myIndexBits)].set(index & myIndexMask, value); + } + + @Override + public void set(final long index, final Comparable value) { mySegments[(int) (index >> myIndexBits)].set(index & myIndexMask, value); } + @Override public void visitOne(final long index, final VoidFunction visitor) { if (this.isPrimitive()) { visitor.invoke(this.doubleValue(index)); @@ -314,7 +342,7 @@ protected void fill(final long first, final long limit, final long step, final N } else if (this.isPrimitive()) { - final double tmpValue = value.doubleValue(); + final double tmpValue = Scalar.doubleValue(value); for (long i = first; i < limit; i += step) { this.set(i, tmpValue); } @@ -328,7 +356,7 @@ protected void fill(final long first, final long limit, final long step, final N } @Override - protected void fill(final long first, final long limit, final long step, final NullaryFunction supplier) { + protected void fill(final long first, final long limit, final long step, final NullaryFunction supplier) { if (step <= mySegmentSize) { // Will use a continuous range of segements diff --git a/src/org/ojalgo/array/SparseArray.java b/src/org/ojalgo/array/SparseArray.java index 94fa895e4..4d331bf39 100644 --- a/src/org/ojalgo/array/SparseArray.java +++ b/src/org/ojalgo/array/SparseArray.java @@ -46,7 +46,7 @@ * * @author apete */ -public final class SparseArray extends BasicArray { +public final class SparseArray> extends BasicArray { @FunctionalInterface public interface NonzeroPrimitiveCallback { @@ -60,7 +60,7 @@ public interface NonzeroPrimitiveCallback { } @FunctionalInterface - public interface NonzeroReferenceTypeCallback { + public interface NonzeroReferenceTypeCallback> { /** * @param index Index @@ -70,7 +70,7 @@ public interface NonzeroReferenceTypeCallback { } - public static final class NonzeroView implements ElementView1D> { + public static final class NonzeroView> implements ElementView1D> { private int myCursor = -1; private final long[] myIndices; @@ -92,14 +92,17 @@ private NonzeroView(final long[] indices, final DenseArray values, final int this(indices, values, -1, actualLength - 1); } + @Override public double doubleValue() { return myValues.doubleValue(myCursor); } + @Override public long estimateSize() { return myLastCursor - myCursor; } + @Override public void forEachRemaining(final Consumer> action) { // BasicLogger.debug("forEachRemaining [{}, {})", myCursor, myLastCursor); @@ -107,22 +110,27 @@ public void forEachRemaining(final Consumer> action) { ElementView1D.super.forEachRemaining(action); } + @Override public N get() { return myValues.get(myCursor); } + @Override public boolean hasNext() { return myCursor < myLastCursor; } + @Override public boolean hasPrevious() { return myCursor > 0; } + @Override public long index() { return myIndices[myCursor]; } + @Override public NonzeroView iterator() { return new NonzeroView<>(myIndices, myValues, -1, myLastCursor); } @@ -143,28 +151,34 @@ public void modify(final N left, final BinaryFunction function) { myValues.set(myCursor, function.invoke(left, myValues.get(myCursor))); } + @Override public NonzeroView next() { myCursor++; return this; } + @Override public long nextIndex() { return myIndices[myCursor + 1]; } + @Override public NonzeroView previous() { myCursor--; return this; } + @Override public long previousIndex() { return myIndices[myCursor - 1]; } + @Override public boolean tryAdvance(final Consumer> action) { return ElementView1D.super.tryAdvance(action); } + @Override public NonzeroView trySplit() { final int remaining = myLastCursor - myCursor; @@ -189,7 +203,7 @@ public NonzeroView trySplit() { } - public static final class SparseFactory extends StrategyBuilder, SparseFactory> { + public static final class SparseFactory> extends StrategyBuilder, SparseFactory> { SparseFactory(final DenseArray.Factory denseFactory) { super(denseFactory); @@ -213,11 +227,11 @@ public SparseArray make(final long count) { private static final NumberContext MATH_CONTEXT = NumberContext.getMath(MathContext.DECIMAL64); - public static SparseFactory factory(final DenseArray.Factory denseFactory) { + public static > SparseFactory factory(final DenseArray.Factory denseFactory) { return new SparseFactory<>(denseFactory); } - public static SparseFactory factory(final DenseArray.Factory denseFactory, final long count) { + public static > SparseFactory factory(final DenseArray.Factory denseFactory, final long count) { return new SparseFactory<>(denseFactory, count); } @@ -246,9 +260,10 @@ public static SparseFactory factory(final DenseArray.Facto myZeroScalar = strategy.scalar().zero(); myZeroNumber = myZeroScalar.get(); - myZeroValue = myZeroNumber.doubleValue(); + myZeroValue = myZeroScalar.doubleValue(); } + @Override public void add(final long index, final double addend) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { @@ -258,7 +273,8 @@ public void add(final long index, final double addend) { } } - public void add(final long index, final Number addend) { + @Override + public void add(final long index, final float addend) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { myValues.add(tmpIndex, addend); @@ -267,12 +283,24 @@ public void add(final long index, final Number addend) { } } + @Override + public void add(final long index, final Comparable addend) { + final int tmpIndex = this.index(index); + if (tmpIndex >= 0) { + myValues.add(tmpIndex, addend); + } else { + this.set(index, addend); + } + } + + @Override public void axpy(final double a, final Mutate1D y) { for (int n = 0; n < myActualLength; n++) { y.add(myIndices[n], a * myValues.doubleValue(n)); } } + @Override public long count() { return myCount; } @@ -285,6 +313,7 @@ public long countZeros() { return myCount - myActualLength; } + @Override public double dot(final Access1D vector) { double retVal = PrimitiveMath.ZERO; @@ -296,6 +325,7 @@ public double dot(final Access1D vector) { return retVal; } + @Override public double doubleValue(final long index) { final int tmpIndex = this.index(index); @@ -306,9 +336,10 @@ public double doubleValue(final long index) { } } + @Override public void fillAll(final N value) { - if (PrimitiveScalar.isSmall(PrimitiveMath.ONE, value.doubleValue())) { + if (PrimitiveScalar.isSmall(PrimitiveMath.ONE, Scalar.doubleValue(value))) { myValues.fillAll(myZeroNumber); @@ -328,7 +359,8 @@ public void fillAll(final N value) { } } - public void fillAll(final NullaryFunction supplier) { + @Override + public void fillAll(final NullaryFunction supplier) { // Bad idea... @@ -343,6 +375,7 @@ public void fillAll(final NullaryFunction supplier) { myValues.fillAll(supplier); } + @Override public void fillOne(final long index, final Access1D values, final long valueIndex) { if (this.isPrimitive()) { this.set(index, values.doubleValue(valueIndex)); @@ -351,19 +384,23 @@ public void fillOne(final long index, final Access1D values, final long value } } + @Override public void fillOne(final long index, final N value) { this.set(index, value); } - public void fillOne(final long index, final NullaryFunction supplier) { + @Override + public void fillOne(final long index, final NullaryFunction supplier) { this.set(index, supplier.get()); } + @Override public void fillRange(final long first, final long limit, final N value) { this.fill(first, limit, 1L, value); } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + @Override + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { this.fill(first, limit, 1L, supplier); } @@ -379,6 +416,7 @@ public long firstInRange(final long rangeFirst, final long rangeLimit) { } } + @Override public N get(final long index) { final int tmpIndex = this.index(index); @@ -389,6 +427,7 @@ public N get(final long index) { } } + @Override public boolean isAbsolute(final long index) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { @@ -398,6 +437,7 @@ public boolean isAbsolute(final long index) { } } + @Override public boolean isSmall(final long index, final double comparedTo) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { @@ -434,19 +474,23 @@ public void modifyAll(final UnaryFunction modifier) { } } + @Override public void modifyOne(final long index, final UnaryFunction modifier) { this.set(index, modifier.invoke(this.get(index))); } + @Override public NonzeroView nonzeros() { return new NonzeroView<>(myIndices, myValues, myActualLength); } + @Override public void reset() { myActualLength = 0; myValues.reset(); } + @Override public void set(final long index, final double value) { final int internalIndex = this.index(index); @@ -454,7 +498,16 @@ public void set(final long index, final double value) { this.update(index, internalIndex, value, false); } - public void set(final long index, final Number value) { + @Override + public void set(final long index, final float value) { + + final int internalIndex = this.index(index); + + this.update(index, internalIndex, value, false); + } + + @Override + public void set(final long index, final Comparable value) { final int internalIndex = this.index(index); @@ -473,6 +526,7 @@ public void supplyNonZerosTo(final Mutate1D consumer) { } } + @Override public void visitOne(final long index, final VoidFunction visitor) { if (this.isPrimitive()) { visitor.invoke(this.doubleValue(index)); @@ -591,7 +645,7 @@ private void update(final long externalIndex, final int internalIndex, final dou /** * Will never remove anything - just insert or update */ - private void update(final long externalIndex, final int internalIndex, final Number value, final boolean shouldStoreZero) { + private void update(final long externalIndex, final int internalIndex, final Comparable value, final boolean shouldStoreZero) { if (internalIndex >= 0) { // Existing value, just update @@ -689,7 +743,7 @@ protected void fill(final long first, final long limit, final long step, final N } @Override - protected void fill(final long first, final long limit, final long step, final NullaryFunction supplier) { + protected void fill(final long first, final long limit, final long step, final NullaryFunction supplier) { for (long i = first; i < limit; i += step) { this.fillOne(i, supplier); } @@ -868,14 +922,17 @@ Access1D getValues(final long fromIncl, final long toExcl) { return new Access1D() { + @Override public long count() { return limit - first; } + @Override public double doubleValue(final long index) { return myValues.doubleValue(first + index); } + @Override public N get(final long index) { return myValues.get(first + index); } diff --git a/src/org/ojalgo/array/StrategyBuilder.java b/src/org/ojalgo/array/StrategyBuilder.java index ac0f87e65..646bd0981 100644 --- a/src/org/ojalgo/array/StrategyBuilder.java +++ b/src/org/ojalgo/array/StrategyBuilder.java @@ -2,7 +2,7 @@ import org.ojalgo.structure.Access1D; -abstract class StrategyBuilder, SB extends StrategyBuilder> { +abstract class StrategyBuilder, I extends Access1D, SB extends StrategyBuilder> { private final DenseCapacityStrategy myStrategy; diff --git a/src/org/ojalgo/array/operation/AMAX.java b/src/org/ojalgo/array/operation/AMAX.java index f1016c0f8..64f70015a 100644 --- a/src/org/ojalgo/array/operation/AMAX.java +++ b/src/org/ojalgo/array/operation/AMAX.java @@ -40,7 +40,7 @@ public final class AMAX implements BLAS1 { public static int THRESHOLD = 128; - public static long invoke(final BasicArray data, final long first, final long limit, final long step) { + public static > long invoke(final BasicArray data, final long first, final long limit, final long step) { long retVal = first; double tmpLargest = 0D; @@ -104,7 +104,7 @@ public static int invoke(final float[] data, final int first, final int limit, f return retVal; } - public static > int invoke(final N[] data, final int first, final int limit, final int step) { + public static > int invoke(final N[] data, final int first, final int limit, final int step) { int retVal = first; double tmpLargest = 0D; diff --git a/src/org/ojalgo/array/operation/AXPY.java b/src/org/ojalgo/array/operation/AXPY.java index 03d13be5f..ebe076a01 100644 --- a/src/org/ojalgo/array/operation/AXPY.java +++ b/src/org/ojalgo/array/operation/AXPY.java @@ -50,6 +50,12 @@ public static void invoke(final double[] y, final int basey, final double a, fin } } + public static void invoke(final float[] y, final int basey, final float a, final float[] x, final int basex, final int first, final int limit) { + for (int i = first; i < limit; i++) { + y[basey + i] += a * x[basex + i]; + } + } + public static void invoke(final Mutate1D y, final double a, final BigDecimal[] x) { final BigDecimal tmpA = new BigDecimal(a); for (int i = 0; i < x.length; i++) { @@ -69,14 +75,13 @@ public static void invoke(final Mutate1D y, final double a, final float[] x) { } } - public static > void invoke(final Mutate1D y, final double a, final N[] x) { + public static > void invoke(final Mutate1D y, final double a, final N[] x) { for (int i = 0; i < x.length; i++) { y.add(i, x[i].multiply(a).get()); } } - public static > void invoke(final N[] y, final int basey, final N a, final N[] x, final int basex, final int first, - final int limit) { + public static > void invoke(final N[] y, final int basey, final N a, final N[] x, final int basex, final int first, final int limit) { for (int i = first; i < limit; i++) { y[basey + i] = y[basey + i].add(a.multiply(x[basex + i])).get(); } diff --git a/src/org/ojalgo/array/operation/ApplyCholesky.java b/src/org/ojalgo/array/operation/ApplyCholesky.java index 5c8a943b9..5e4799d6c 100644 --- a/src/org/ojalgo/array/operation/ApplyCholesky.java +++ b/src/org/ojalgo/array/operation/ApplyCholesky.java @@ -33,8 +33,7 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static > void invoke(final N[] data, final int structure, final int firstColumn, final int columnLimit, - final N[] multipliers) { + public static > void invoke(final N[] data, final int structure, final int firstColumn, final int columnLimit, final N[] multipliers) { for (int j = firstColumn; j < columnLimit; j++) { AXPY.invoke(data, j * structure, multipliers[j].conjugate().negate().get(), multipliers, 0, j, structure); } diff --git a/src/org/ojalgo/array/operation/ApplyLDL.java b/src/org/ojalgo/array/operation/ApplyLDL.java index 0f45fc341..d4106924a 100644 --- a/src/org/ojalgo/array/operation/ApplyLDL.java +++ b/src/org/ojalgo/array/operation/ApplyLDL.java @@ -35,8 +35,8 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static > void invoke(final N[] data, final int structure, final int firstColumn, final int columnLimit, - final N[] multipliers, final int iterationPoint) { + public static > void invoke(final N[] data, final int structure, final int firstColumn, final int columnLimit, final N[] multipliers, + final int iterationPoint) { final Scalar diagVal = data[iterationPoint + (iterationPoint * structure)]; for (int j = firstColumn; j < columnLimit; j++) { AXPY.invoke(data, j * structure, diagVal.multiply(multipliers[j].conjugate()).negate().get(), multipliers, 0, j, structure); diff --git a/src/org/ojalgo/array/operation/ApplyLU.java b/src/org/ojalgo/array/operation/ApplyLU.java index 67d5799d1..b32d89a50 100644 --- a/src/org/ojalgo/array/operation/ApplyLU.java +++ b/src/org/ojalgo/array/operation/ApplyLU.java @@ -34,8 +34,8 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static > void invoke(final N[] data, final int structure, final int firstColumn, final int columnLimit, - final N[] multipliers, final int iterationPoint) { + public static > void invoke(final N[] data, final int structure, final int firstColumn, final int columnLimit, final N[] multipliers, + final int iterationPoint) { for (int j = firstColumn; j < columnLimit; j++) { AXPY.invoke(data, j * structure, data[iterationPoint + (j * structure)].negate().get(), multipliers, 0, iterationPoint + 1, structure); } diff --git a/src/org/ojalgo/array/operation/DOT.java b/src/org/ojalgo/array/operation/DOT.java index 5f8b5a26f..62d18ae98 100644 --- a/src/org/ojalgo/array/operation/DOT.java +++ b/src/org/ojalgo/array/operation/DOT.java @@ -64,8 +64,16 @@ public static double invoke(final double[] array1, final int offset1, final doub return retVal; } - public static > N invoke(final N[] array1, final int offset1, final N[] array2, final int offset2, final int first, - final int limit, final Scalar.Factory factory) { + public static float invoke(final float[] array1, final int offset1, final float[] array2, final int offset2, final int first, final int limit) { + float retVal = 0F; + for (int i = first; i < limit; i++) { + retVal += array1[offset1 + i] * array2[offset2 + i]; + } + return retVal; + } + + public static > N invoke(final N[] array1, final int offset1, final N[] array2, final int offset2, final int first, final int limit, + final Scalar.Factory factory) { Scalar retVal = factory.zero(); for (int i = first; i < limit; i++) { retVal = retVal.add(array1[offset1 + i].multiply(array2[offset2 + i])); diff --git a/src/org/ojalgo/array/operation/FillMatchingSingle.java b/src/org/ojalgo/array/operation/FillMatchingSingle.java index 5bfb813ce..ade125c38 100644 --- a/src/org/ojalgo/array/operation/FillMatchingSingle.java +++ b/src/org/ojalgo/array/operation/FillMatchingSingle.java @@ -39,7 +39,7 @@ public static void conjugate(final double[] data, final int structure, final int FillMatchingSingle.transpose(data, structure, firstColumn, limitColumn, source); } - public static > void conjugate(final N[] data, final int structure, final int firstColumn, final int limitColumn, + public static > void conjugate(final N[] data, final int structure, final int firstColumn, final int limitColumn, final Access2D source, final Scalar.Factory scalar) { int index = structure * firstColumn; for (int j = firstColumn; j < limitColumn; j++) { @@ -50,7 +50,7 @@ public static > void conjugate(final N[] data, fina } public static void copy(final BigDecimal[] data, final int structure, final int firstColumn, final int limitColumn, - final Access2D source) { + final Access2D> source) { int index = structure * firstColumn; for (int j = firstColumn; j < limitColumn; j++) { for (int i = 0; i < structure; i++) { @@ -59,7 +59,8 @@ public static void copy(final BigDecimal[] data, final int structure, final int } } - public static void copy(final double[] data, final int structure, final int firstColumn, final int limitColumn, final Access2D source) { + public static void copy(final double[] data, final int structure, final int firstColumn, final int limitColumn, + final Access2D> source) { int index = structure * firstColumn; for (int j = firstColumn; j < limitColumn; j++) { for (int i = 0; i < structure; i++) { @@ -68,8 +69,18 @@ public static void copy(final double[] data, final int structure, final int firs } } - public static > void copy(final N[] data, final int structure, final int firstColumn, final int limitColumn, - final Access2D source, final Scalar.Factory scalar) { + public static void copy(final float[] data, final int structure, final int firstColumn, final int limitColumn, + final Access2D> source) { + int index = structure * firstColumn; + for (int j = firstColumn; j < limitColumn; j++) { + for (int i = 0; i < structure; i++) { + data[index++] = source.floatValue(i, j); + } + } + } + + public static > void copy(final N[] data, final int structure, final int firstColumn, final int limitColumn, final Access2D source, + final Scalar.Factory scalar) { int index = structure * firstColumn; for (int j = firstColumn; j < limitColumn; j++) { for (int i = 0; i < structure; i++) { @@ -96,7 +107,16 @@ public static void transpose(final double[] data, final int structure, final int } } - public static > void transpose(final N[] data, final int structure, final int firstColumn, final int limitColumn, + public static void transpose(final float[] data, final int structure, final int firstColumn, final int limitColumn, final Access2D source) { + int index = structure * firstColumn; + for (int j = firstColumn; j < limitColumn; j++) { + for (int i = 0; i < structure; i++) { + data[index++] = source.floatValue(j, i); + } + } + } + + public static > void transpose(final N[] data, final int structure, final int firstColumn, final int limitColumn, final Access2D source, final Scalar.Factory scalar) { int index = structure * firstColumn; for (int j = firstColumn; j < limitColumn; j++) { diff --git a/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderColumn.java b/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderColumn.java index b919b7bf9..75b358beb 100644 --- a/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderColumn.java +++ b/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderColumn.java @@ -30,7 +30,7 @@ public final class GenerateApplyAndCopyHouseholderColumn implements ArrayOperati public static int THRESHOLD = 128; - public static boolean invoke(final double[] data, final int structure, final int row, final int col, final Householder.Primitive destination) { + public static boolean invoke(final double[] data, final int structure, final int row, final int col, final Householder.Primitive64 destination) { final int tmpColBase = col * structure; @@ -80,7 +80,57 @@ public static boolean invoke(final double[] data, final int structure, final int return retVal; } - public static > boolean invoke(final N[] data, final int structure, final int row, final int col, + public static boolean invoke(final float[] data, final int structure, final int row, final int col, final Householder.Primitive32 destination) { + + final int tmpColBase = col * structure; + + final float[] tmpVector = destination.vector; + destination.first = row; + + double tmpNormInf = PrimitiveMath.ZERO; // Copy column and calculate its infinity-norm. + for (int i = row; i < structure; i++) { + tmpNormInf = PrimitiveMath.MAX.invoke(tmpNormInf, PrimitiveMath.ABS.invoke(tmpVector[i] = data[i + tmpColBase])); + } + + boolean retVal = tmpNormInf != PrimitiveMath.ZERO; + double tmpVal; + double tmpNorm2 = PrimitiveMath.ZERO; + + if (retVal) { + for (int i = row + 1; i < structure; i++) { + tmpVal = tmpVector[i] /= tmpNormInf; + tmpNorm2 += tmpVal * tmpVal; + } + retVal = !PrimitiveScalar.isSmall(PrimitiveMath.ONE, tmpNorm2); + } + + if (retVal) { + + double tmpScale = tmpVector[row] / tmpNormInf; + tmpNorm2 += tmpScale * tmpScale; + tmpNorm2 = PrimitiveMath.SQRT.invoke(tmpNorm2); // 2-norm of the vector to transform (scaled by inf-norm) + + if (tmpScale <= PrimitiveMath.ZERO) { + data[(row + tmpColBase)] = (float) (tmpNorm2 * tmpNormInf); + tmpScale -= tmpNorm2; + } else { + data[(row + tmpColBase)] = (float) (-tmpNorm2 * tmpNormInf); + tmpScale += tmpNorm2; + } + + tmpVector[row] = (float) PrimitiveMath.ONE; + + for (int i = row + 1; i < structure; i++) { + data[i + tmpColBase] = tmpVector[i] /= tmpScale; + } + + destination.beta = (float) (PrimitiveMath.ABS.invoke(tmpScale) / tmpNorm2); + } + + return retVal; + } + + public static > boolean invoke(final N[] data, final int structure, final int row, final int col, final Householder.Generic destination, final Scalar.Factory scalar) { final int tmpColBase = col * structure; diff --git a/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderRow.java b/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderRow.java index 2fd817fdd..5e24599b6 100644 --- a/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderRow.java +++ b/src/org/ojalgo/array/operation/GenerateApplyAndCopyHouseholderRow.java @@ -30,7 +30,7 @@ public final class GenerateApplyAndCopyHouseholderRow implements ArrayOperation public static int THRESHOLD = 128; - public static boolean invoke(final double[] data, final int structure, final int row, final int col, final Householder.Primitive destination) { + public static boolean invoke(final double[] data, final int structure, final int row, final int col, final Householder.Primitive64 destination) { final int tmpColDim = data.length / structure; @@ -81,7 +81,58 @@ public static boolean invoke(final double[] data, final int structure, final int return retVal; } - public static > boolean invoke(final N[] data, final int structure, final int row, final int col, + public static boolean invoke(final float[] data, final int structure, final int row, final int col, final Householder.Primitive32 destination) { + + final int tmpColDim = data.length / structure; + + final float[] tmpVector = destination.vector; + destination.first = col; + + double tmpNormInf = PrimitiveMath.ZERO; // Copy row and calculate its infinity-norm. + for (int j = col; j < tmpColDim; j++) { + tmpNormInf = PrimitiveMath.MAX.invoke(tmpNormInf, PrimitiveMath.ABS.invoke(tmpVector[j] = data[row + (j * structure)])); + } + + boolean retVal = tmpNormInf != PrimitiveMath.ZERO; + double tmpVal; + double tmpNorm2 = PrimitiveMath.ZERO; + + if (retVal) { + for (int j = col + 1; j < tmpColDim; j++) { + tmpVal = tmpVector[j] /= tmpNormInf; + tmpNorm2 += tmpVal * tmpVal; + } + final double value = tmpNorm2; + retVal = !PrimitiveScalar.isSmall(PrimitiveMath.ONE, value); + } + + if (retVal) { + + double tmpScale = tmpVector[col] / tmpNormInf; + tmpNorm2 += tmpScale * tmpScale; + tmpNorm2 = PrimitiveMath.SQRT.invoke(tmpNorm2); // 2-norm of the vector to transform (scaled by inf-norm) + + if (tmpScale <= PrimitiveMath.ZERO) { + data[(row + (col * structure))] = (float) (tmpNorm2 * tmpNormInf); + tmpScale -= tmpNorm2; + } else { + data[(row + (col * structure))] = (float) (-tmpNorm2 * tmpNormInf); + tmpScale += tmpNorm2; + } + + tmpVector[col] = (float) PrimitiveMath.ONE; + + for (int j = col + 1; j < tmpColDim; j++) { + data[row + (j * structure)] = tmpVector[j] /= tmpScale; + } + + destination.beta = (float) (PrimitiveMath.ABS.invoke(tmpScale) / tmpNorm2); + } + + return retVal; + } + + public static > boolean invoke(final N[] data, final int structure, final int row, final int col, final Householder.Generic destination, final Scalar.Factory scalar) { final int tmpColDim = data.length / structure; diff --git a/src/org/ojalgo/array/operation/HermitianRank2Update.java b/src/org/ojalgo/array/operation/HermitianRank2Update.java index 8602e4318..8a5899a30 100644 --- a/src/org/ojalgo/array/operation/HermitianRank2Update.java +++ b/src/org/ojalgo/array/operation/HermitianRank2Update.java @@ -76,8 +76,7 @@ public static void invoke(final double[] data, final int firstColumn, final int } } - public static > void invoke(final N[] data, final int firstColumn, final int columnLimit, final N[] vector1, - final N[] vector2) { + public static > void invoke(final N[] data, final int firstColumn, final int columnLimit, final N[] vector1, final N[] vector2) { final int structure = vector1.length; diff --git a/src/org/ojalgo/array/operation/HouseholderHermitian.java b/src/org/ojalgo/array/operation/HouseholderHermitian.java index ae0a3ad02..eaa76d995 100644 --- a/src/org/ojalgo/array/operation/HouseholderHermitian.java +++ b/src/org/ojalgo/array/operation/HouseholderHermitian.java @@ -39,7 +39,7 @@ */ public final class HouseholderHermitian implements ArrayOperation { - public static void invoke(final double[] data, final Householder.Primitive householder, final double[] worker) { + public static void invoke(final double[] data, final Householder.Primitive64 householder, final double[] worker) { final double[] tmpVector = householder.vector; final int tmpFirst = householder.first; @@ -91,7 +91,7 @@ protected void conquer(final int first, final int limit) { } } - public static > void invoke(final N[] data, final Householder.Generic householder, final N[] worker, + public static > void invoke(final N[] data, final Householder.Generic householder, final N[] worker, final Scalar.Factory scalar) { final N[] tmpVector = householder.vector; diff --git a/src/org/ojalgo/array/operation/HouseholderLeft.java b/src/org/ojalgo/array/operation/HouseholderLeft.java index 0a7f41b30..3a85dc291 100644 --- a/src/org/ojalgo/array/operation/HouseholderLeft.java +++ b/src/org/ojalgo/array/operation/HouseholderLeft.java @@ -28,7 +28,7 @@ public final class HouseholderLeft implements ArrayOperation { public static int THRESHOLD = 128; - public static void invoke(final double[] data, final int structure, final int first, final int limit, final Householder.Primitive householder) { + public static void invoke(final double[] data, final int structure, final int first, final int limit, final Householder.Primitive64 householder) { final double[] tmpHouseholderVector = householder.vector; final int tmpFirstNonZero = householder.first; @@ -42,7 +42,21 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static > void invoke(final N[] data, final int structure, final int first, final int limit, + public static void invoke(final float[] data, final int structure, final int first, final int limit, final Householder.Primitive32 householder) { + + final float[] tmpHouseholderVector = householder.vector; + final int tmpFirstNonZero = householder.first; + final float tmpBeta = householder.beta; + + float tmpScale; + for (int j = first; j < limit; j++) { + tmpScale = DOT.invoke(data, j * structure, tmpHouseholderVector, 0, tmpFirstNonZero, structure); + tmpScale *= tmpBeta; + AXPY.invoke(data, j * structure, -tmpScale, tmpHouseholderVector, 0, tmpFirstNonZero, structure); + } + } + + public static > void invoke(final N[] data, final int structure, final int first, final int limit, final Householder.Generic householder, final Scalar.Factory scalar) { final N[] tmpHouseholderVector = householder.vector; diff --git a/src/org/ojalgo/array/operation/HouseholderRight.java b/src/org/ojalgo/array/operation/HouseholderRight.java index e743cb348..c8da45578 100644 --- a/src/org/ojalgo/array/operation/HouseholderRight.java +++ b/src/org/ojalgo/array/operation/HouseholderRight.java @@ -30,7 +30,7 @@ public final class HouseholderRight implements ArrayOperation { public static int THRESHOLD = 512; public static void invoke(final double[] data, final int structure, final int firstRow, final int rowLimit, final int numberOfColumns, - final Householder.Primitive householder, final double[] work) { + final Householder.Primitive64 householder, final double[] work) { final double[] vector = householder.vector; final int firstNonZero = householder.first; @@ -44,7 +44,22 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static > void invoke(final N[] data, final int first, final int limit, final int tmpColDim, + public static void invoke(final float[] data, final int structure, final int firstRow, final int rowLimit, final int numberOfColumns, + final Householder.Primitive32 householder, final float[] work) { + + final float[] vector = householder.vector; + final int firstNonZero = householder.first; + final float beta = householder.beta; + + for (int j = firstNonZero; j < numberOfColumns; j++) { + AXPY.invoke(work, 0, beta * vector[j], data, j * structure, firstRow, rowLimit); + } + for (int j = firstNonZero; j < numberOfColumns; j++) { + AXPY.invoke(data, j * structure, -vector[j], work, 0, firstRow, rowLimit); + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int tmpColDim, final Householder.Generic householder, final Scalar.Factory scalar) { final N[] tmpHouseholderVector = householder.vector; @@ -71,7 +86,7 @@ public static > void invoke(final N[] data, final i } } - private static void invoke2old(final double[] data, final int first, final int limit, final int tmpColDim, final Householder.Primitive householder) { + private static void invoke2old(final double[] data, final int first, final int limit, final int tmpColDim, final Householder.Primitive64 householder) { final double[] tmpHouseholderVector = householder.vector; final int tmpFirstNonZero = householder.first; diff --git a/src/org/ojalgo/array/operation/MultiplyBoth.java b/src/org/ojalgo/array/operation/MultiplyBoth.java index e6864621f..7fd360ec5 100644 --- a/src/org/ojalgo/array/operation/MultiplyBoth.java +++ b/src/org/ojalgo/array/operation/MultiplyBoth.java @@ -26,9 +26,7 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore.GenericMultiplyBoth; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore.PrimitiveMultiplyBoth; import org.ojalgo.matrix.store.TransformableRegion; import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; @@ -36,12 +34,22 @@ public final class MultiplyBoth implements ArrayOperation { + @FunctionalInterface + public interface Generic> extends TransformableRegion.FillByMultiplying { + + } + + @FunctionalInterface + public interface Primitive extends TransformableRegion.FillByMultiplying { + + } + public static int THRESHOLD = 16; - static final PrimitiveMultiplyBoth PRIMITIVE = (product, left, complexity, right) -> MultiplyBoth.invokePrimitive(product, 0, + static final MultiplyBoth.Primitive PRIMITIVE = (product, left, complexity, right) -> MultiplyBoth.invokePrimitive64(product, 0, ((int) left.count()) / complexity, left, complexity, right); - static final PrimitiveMultiplyBoth PRIMITIVE_0XN = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_0XN = (product, left, complexity, right) -> { left.count(); final int tmpColDim = (int) (right.count() / complexity); @@ -87,7 +95,7 @@ public final class MultiplyBoth implements ArrayOperation { } }; - static final PrimitiveMultiplyBoth PRIMITIVE_1X1 = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_1X1 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; @@ -98,7 +106,7 @@ public final class MultiplyBoth implements ArrayOperation { product.set(0L, 0L, tmp00); }; - static final PrimitiveMultiplyBoth PRIMITIVE_1XN = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_1XN = (product, left, complexity, right) -> { final int tmpColDim = (int) (right.count() / complexity); @@ -115,7 +123,7 @@ public final class MultiplyBoth implements ArrayOperation { } }; - static final PrimitiveMultiplyBoth PRIMITIVE_2X2 = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_2X2 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -147,7 +155,7 @@ public final class MultiplyBoth implements ArrayOperation { product.set(1, 1, tmp11); }; - static final PrimitiveMultiplyBoth PRIMITIVE_3X3 = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_3X3 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -199,7 +207,7 @@ public final class MultiplyBoth implements ArrayOperation { product.set(2, 2, tmp22); }; - static final PrimitiveMultiplyBoth PRIMITIVE_4X4 = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_4X4 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -277,7 +285,7 @@ public final class MultiplyBoth implements ArrayOperation { product.set(3, 3, tmp33); }; - static final PrimitiveMultiplyBoth PRIMITIVE_5X5 = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_5X5 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -387,7 +395,7 @@ public final class MultiplyBoth implements ArrayOperation { product.set(4, 4, tmp44); }; - static final PrimitiveMultiplyBoth PRIMITIVE_6XN = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_6XN = (product, left, complexity, right) -> { final int tmpColDim = (int) (right.count() / complexity); @@ -420,7 +428,7 @@ public final class MultiplyBoth implements ArrayOperation { } }; - static final PrimitiveMultiplyBoth PRIMITIVE_7XN = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_7XN = (product, left, complexity, right) -> { left.count(); final int tmpColDim = (int) (right.count() / complexity); @@ -457,7 +465,7 @@ public final class MultiplyBoth implements ArrayOperation { } }; - static final PrimitiveMultiplyBoth PRIMITIVE_8XN = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_8XN = (product, left, complexity, right) -> { left.count(); final int tmpColDim = (int) (right.count() / complexity); @@ -497,7 +505,7 @@ public final class MultiplyBoth implements ArrayOperation { } }; - static final PrimitiveMultiplyBoth PRIMITIVE_9XN = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_9XN = (product, left, complexity, right) -> { left.count(); final int tmpColDim = (int) (right.count() / complexity); @@ -540,20 +548,20 @@ public final class MultiplyBoth implements ArrayOperation { } }; - static final PrimitiveMultiplyBoth PRIMITIVE_MT = (product, left, complexity, right) -> { + static final MultiplyBoth.Primitive PRIMITIVE_MT = (product, left, complexity, right) -> { final DivideAndConquer tmpConquerer = new DivideAndConquer() { @Override public void conquer(final int first, final int limit) { - MultiplyBoth.invokePrimitive(product, first, limit, left, complexity, right); + MultiplyBoth.invokePrimitive64(product, first, limit, left, complexity, right); } }; tmpConquerer.invoke(0, ((int) left.count()) / complexity, THRESHOLD); }; - public static > GenericMultiplyBoth getGeneric(final long rows, final long columns) { + public static > MultiplyBoth.Generic newGeneric(final long rows, final long columns) { if (rows > THRESHOLD) { @@ -576,7 +584,7 @@ public void conquer(final int first, final int limit) { } } - public static PrimitiveMultiplyBoth getPrimitive(final long rows, final long columns) { + public static MultiplyBoth.Primitive newPrimitive64(final long rows, final long columns) { if (rows > THRESHOLD) { return PRIMITIVE_MT; } else if (rows == 10) { @@ -604,6 +612,10 @@ public static PrimitiveMultiplyBoth getPrimitive(final long rows, final long col } } + public static MultiplyBoth.Primitive newPrimitive32(final int rows, final int columns) { + return MultiplyBoth.newPrimitive64(rows, columns); + } + static void invoke(final double[] product, final int firstColumn, final int columnLimit, final Access1D left, final int complexity, final Access1D right) { @@ -629,8 +641,8 @@ static void invoke(final double[] product, final int firstColumn, final int colu } } - static > void invokeGeneric(final TransformableRegion product, final int firstRow, final int rowLimit, - final Access1D left, final int complexity, final Access1D right) { + static > void invokeGeneric(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, + final int complexity, final Access1D right) { @SuppressWarnings("unchecked") final Class componenetType = (Class) left.get(0L).getClass(); @@ -676,7 +688,7 @@ static > void invokeGeneric(final TransformableRegi } } - static void invokePrimitive(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, + static void invokePrimitive64(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, final int complexity, final Access1D right) { final int tmpRowDim = (int) product.countRows(); @@ -712,6 +724,42 @@ static void invokePrimitive(final TransformableRegion product, final int } } + static void invokePrimitive32(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, + final int complexity, final Access1D right) { + + final int tmpRowDim = (int) product.countRows(); + final int tmpColDim = (int) product.countColumns(); + + final float[] tmpLeftRow = new float[complexity]; + float tmpVal; + + int tmpFirst = 0; + int tmpLimit = complexity; + + for (int i = firstRow; i < rowLimit; i++) { + + final int tmpFirstInRow = MatrixStore.firstInRow(left, i, 0); + final int tmpLimitOfRow = MatrixStore.limitOfRow(left, i, complexity); + + for (int c = tmpFirstInRow; c < tmpLimitOfRow; c++) { + tmpLeftRow[c] = left.floatValue(Structure2D.index(tmpRowDim, i, c)); + } + + for (int j = 0; j < tmpColDim; j++) { + final int tmpColBase = j * complexity; + + tmpFirst = MatrixStore.firstInColumn(right, j, tmpFirstInRow); + tmpLimit = MatrixStore.limitOfColumn(right, j, tmpLimitOfRow); + + tmpVal = 0F; + for (int c = tmpFirst; c < tmpLimit; c++) { + tmpVal += tmpLeftRow[c] * right.floatValue(c + tmpColBase); + } + product.set(i, j, tmpVal); + } + } + } + @Override public int threshold() { return THRESHOLD; diff --git a/src/org/ojalgo/array/operation/MultiplyHermitianAndVector.java b/src/org/ojalgo/array/operation/MultiplyHermitianAndVector.java index 8839e5cd2..dc6cc8648 100644 --- a/src/org/ojalgo/array/operation/MultiplyHermitianAndVector.java +++ b/src/org/ojalgo/array/operation/MultiplyHermitianAndVector.java @@ -53,7 +53,7 @@ public static void invoke(final double[] productMatrix, final int firstRow, fina } } - public static > void invoke(final N[] productMatrix, final int firstRow, final int rowLimit, final N[] hermitianMatrix, + public static > void invoke(final N[] productMatrix, final int firstRow, final int rowLimit, final N[] hermitianMatrix, final N[] rightVector, final int firstColumn, final Scalar.Factory scalar) { final int structure = rightVector.length; diff --git a/src/org/ojalgo/array/operation/MultiplyLeft.java b/src/org/ojalgo/array/operation/MultiplyLeft.java index 07bbd7e8b..a7d4d4647 100644 --- a/src/org/ojalgo/array/operation/MultiplyLeft.java +++ b/src/org/ojalgo/array/operation/MultiplyLeft.java @@ -25,25 +25,48 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore.GenericMultiplyLeft; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore.PrimitiveMultiplyLeft; import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Structure2D; public final class MultiplyLeft implements ArrayOperation { + public interface Generic> { + + void invoke(N[] product, Access1D left, int complexity, N[] right, Scalar.Factory scalar); + + } + + public interface Primitive64 { + + void invoke(double[] product, Access1D left, int complexity, double[] right); + + } + + public interface Primitive32 { + + void invoke(float[] product, Access1D left, int complexity, float[] right); + + } + public static int THRESHOLD = 32; - static final PrimitiveMultiplyLeft PRIMITIVE = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE = (product, left, complexity, right) -> { Arrays.fill(product, 0.0); MultiplyLeft.invoke(product, 0, right.length / complexity, left, complexity, right); }; - static final PrimitiveMultiplyLeft PRIMITIVE_0XN = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive32 PRIMITIVE32 = (product, left, complexity, right) -> { + + Arrays.fill(product, 0F); + + MultiplyLeft.invoke(product, 0, right.length / complexity, left, complexity, right); + }; + + static final MultiplyLeft.Primitive64 PRIMITIVE_0XN = (product, left, complexity, right) -> { final int tmpRowDim = 10; final int tmpColDim = right.length / complexity; @@ -89,7 +112,7 @@ public final class MultiplyLeft implements ArrayOperation { } }; - static final PrimitiveMultiplyLeft PRIMITIVE_1X1 = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_1X1 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; @@ -100,7 +123,7 @@ public final class MultiplyLeft implements ArrayOperation { product[0] = tmp00; }; - static final PrimitiveMultiplyLeft PRIMITIVE_1XN = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_1XN = (product, left, complexity, right) -> { final int tmpColDim = right.length / complexity; @@ -117,7 +140,7 @@ public final class MultiplyLeft implements ArrayOperation { } }; - static final PrimitiveMultiplyLeft PRIMITIVE_2X2 = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_2X2 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -148,7 +171,7 @@ public final class MultiplyLeft implements ArrayOperation { product[3] = tmp11; }; - static final PrimitiveMultiplyLeft PRIMITIVE_3X3 = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_3X3 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -198,7 +221,7 @@ public final class MultiplyLeft implements ArrayOperation { product[8] = tmp22; }; - static final PrimitiveMultiplyLeft PRIMITIVE_4X4 = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_4X4 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -273,7 +296,7 @@ public final class MultiplyLeft implements ArrayOperation { product[15] = tmp33; }; - static final PrimitiveMultiplyLeft PRIMITIVE_5X5 = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_5X5 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -379,7 +402,7 @@ public final class MultiplyLeft implements ArrayOperation { product[24] = tmp44; }; - static final PrimitiveMultiplyLeft PRIMITIVE_6XN = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_6XN = (product, left, complexity, right) -> { final int tmpRowDim = 6; final int tmpColDim = right.length / complexity; @@ -413,7 +436,7 @@ public final class MultiplyLeft implements ArrayOperation { } }; - static final PrimitiveMultiplyLeft PRIMITIVE_7XN = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_7XN = (product, left, complexity, right) -> { final int tmpRowDim = 7; final int tmpColDim = right.length / complexity; @@ -450,7 +473,7 @@ public final class MultiplyLeft implements ArrayOperation { } }; - static final PrimitiveMultiplyLeft PRIMITIVE_8XN = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_8XN = (product, left, complexity, right) -> { final int tmpRowDim = 8; final int tmpColDim = right.length / complexity; @@ -490,7 +513,7 @@ public final class MultiplyLeft implements ArrayOperation { } }; - static final PrimitiveMultiplyLeft PRIMITIVE_9XN = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_9XN = (product, left, complexity, right) -> { final int tmpRowDim = 9; final int tmpColDim = right.length / complexity; @@ -533,7 +556,7 @@ public final class MultiplyLeft implements ArrayOperation { } }; - static final PrimitiveMultiplyLeft PRIMITIVE_MT = (product, left, complexity, right) -> { + static final MultiplyLeft.Primitive64 PRIMITIVE_MT = (product, left, complexity, right) -> { Arrays.fill(product, 0.0); @@ -548,7 +571,7 @@ public void conquer(final int first, final int limit) { tmpConquerer.invoke(0, right.length / complexity, THRESHOLD); }; - public static > GenericMultiplyLeft getGeneric(final long rows, final long columns) { + public static > MultiplyLeft.Generic newGeneric(final long rows, final long columns) { if (rows > THRESHOLD) { @@ -578,7 +601,11 @@ public void conquer(final int first, final int limit) { } } - public static PrimitiveMultiplyLeft getPrimitive(final long rows, final long columns) { + public static MultiplyLeft.Primitive32 newPrimitive32(final long rows, final long columns) { + return PRIMITIVE32; + } + + public static MultiplyLeft.Primitive64 newPrimitive64(final long rows, final long columns) { if (rows > THRESHOLD) { return PRIMITIVE_MT; } else if (rows == 10) { @@ -627,8 +654,28 @@ static void invoke(final double[] product, final int firstColumn, final int colu } } - static > void invoke(final N[] product, final int firstColumn, final int columnLimit, final Access1D left, - final int complexity, final N[] right, final Scalar.Factory scalar) { + static void invoke(final float[] product, final int firstColumn, final int columnLimit, final Access1D left, final int complexity, final float[] right) { + + final int structure = ((int) left.count()) / complexity; + + final float[] leftColumn = new float[structure]; + for (int c = 0; c < complexity; c++) { + + final int firstInLeftColumn = MatrixStore.firstInColumn(left, c, 0); + final int limitOfLeftColumn = MatrixStore.limitOfColumn(left, c, structure); + + for (int i = firstInLeftColumn; i < limitOfLeftColumn; i++) { + leftColumn[i] = left.floatValue(Structure2D.index(structure, i, c)); + } + + for (int j = firstColumn; j < columnLimit; j++) { + AXPY.invoke(product, j * structure, right[c + (j * complexity)], leftColumn, 0, firstInLeftColumn, limitOfLeftColumn); + } + } + } + + static > void invoke(final N[] product, final int firstColumn, final int columnLimit, final Access1D left, final int complexity, + final N[] right, final Scalar.Factory scalar) { final int structure = ((int) left.count()) / complexity; diff --git a/src/org/ojalgo/array/operation/MultiplyNeither.java b/src/org/ojalgo/array/operation/MultiplyNeither.java index 8aa9dbe40..c8faa420b 100644 --- a/src/org/ojalgo/array/operation/MultiplyNeither.java +++ b/src/org/ojalgo/array/operation/MultiplyNeither.java @@ -25,22 +25,45 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore.GenericMultiplyNeither; -import org.ojalgo.matrix.store.PrimitiveDenseStore.PrimitiveMultiplyNeither; import org.ojalgo.scalar.Scalar; public final class MultiplyNeither implements ArrayOperation { + public interface Generic> { + + void invoke(N[] product, N[] left, int complexity, N[] right, Scalar.Factory scalar); + + } + + public interface Primitive64 { + + void invoke(double[] product, double[] left, int complexity, double[] right); + + } + + public interface Primitive32 { + + void invoke(float[] product, float[] left, int complexity, float[] right); + + } + public static int THRESHOLD = 32; - static final PrimitiveMultiplyNeither PRIMITIVE = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE = (product, left, complexity, right) -> { Arrays.fill(product, 0.0); MultiplyNeither.invoke(product, 0, right.length / complexity, left, complexity, right); }; - static final PrimitiveMultiplyNeither PRIMITIVE_0XN = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive32 PRIMITIVE32 = (product, left, complexity, right) -> { + + Arrays.fill(product, 0F); + + MultiplyNeither.invoke(product, 0, right.length / complexity, left, complexity, right); + }; + + static final MultiplyNeither.Primitive64 PRIMITIVE_0XN = (product, left, complexity, right) -> { final int tmpRowDim = 10; final int tmpColDim = right.length / complexity; @@ -86,7 +109,7 @@ public final class MultiplyNeither implements ArrayOperation { } }; - static final PrimitiveMultiplyNeither PRIMITIVE_1X1 = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_1X1 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; @@ -99,7 +122,7 @@ public final class MultiplyNeither implements ArrayOperation { product[0] = tmp00; }; - static final PrimitiveMultiplyNeither PRIMITIVE_1XN = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_1XN = (product, left, complexity, right) -> { final int tmpColDim = right.length / complexity; @@ -116,7 +139,7 @@ public final class MultiplyNeither implements ArrayOperation { } }; - static final PrimitiveMultiplyNeither PRIMITIVE_2X2 = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_2X2 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -147,7 +170,7 @@ public final class MultiplyNeither implements ArrayOperation { product[3] = tmp11; }; - static final PrimitiveMultiplyNeither PRIMITIVE_3X3 = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_3X3 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -197,7 +220,7 @@ public final class MultiplyNeither implements ArrayOperation { product[8] = tmp22; }; - static final PrimitiveMultiplyNeither PRIMITIVE_4X4 = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_4X4 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -272,7 +295,7 @@ public final class MultiplyNeither implements ArrayOperation { product[15] = tmp33; }; - static final PrimitiveMultiplyNeither PRIMITIVE_5X5 = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_5X5 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -378,7 +401,7 @@ public final class MultiplyNeither implements ArrayOperation { product[24] = tmp44; }; - static final PrimitiveMultiplyNeither PRIMITIVE_6XN = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_6XN = (product, left, complexity, right) -> { final int tmpRowDim = 6; final int tmpColDim = right.length / complexity; @@ -412,7 +435,7 @@ public final class MultiplyNeither implements ArrayOperation { } }; - static final PrimitiveMultiplyNeither PRIMITIVE_7XN = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_7XN = (product, left, complexity, right) -> { final int tmpRowDim = 7; final int tmpColDim = right.length / complexity; @@ -449,7 +472,7 @@ public final class MultiplyNeither implements ArrayOperation { } }; - static final PrimitiveMultiplyNeither PRIMITIVE_8XN = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_8XN = (product, left, complexity, right) -> { final int tmpRowDim = 8; final int tmpColDim = right.length / complexity; @@ -489,7 +512,7 @@ public final class MultiplyNeither implements ArrayOperation { } }; - static final PrimitiveMultiplyNeither PRIMITIVE_9XN = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_9XN = (product, left, complexity, right) -> { final int tmpRowDim = 9; final int tmpColDim = right.length / complexity; @@ -532,7 +555,7 @@ public final class MultiplyNeither implements ArrayOperation { } }; - static final PrimitiveMultiplyNeither PRIMITIVE_MT = (product, left, complexity, right) -> { + static final MultiplyNeither.Primitive64 PRIMITIVE_MT = (product, left, complexity, right) -> { Arrays.fill(product, 0.0); @@ -547,7 +570,7 @@ public void conquer(final int first, final int limit) { tmpConquerer.invoke(0, right.length / complexity, THRESHOLD); }; - public static > GenericMultiplyNeither getGeneric(final long rows, final long columns) { + public static > MultiplyNeither.Generic newGeneric(final long rows, final long columns) { if (rows > THRESHOLD) { @@ -577,7 +600,7 @@ public void conquer(final int first, final int limit) { } } - public static PrimitiveMultiplyNeither getPrimitive(final long rows, final long columns) { + public static MultiplyNeither.Primitive64 newPrimitive64(final long rows, final long columns) { if (rows > THRESHOLD) { return PRIMITIVE_MT; } else if (rows == 10) { @@ -605,6 +628,10 @@ public static PrimitiveMultiplyNeither getPrimitive(final long rows, final long } } + public static MultiplyNeither.Primitive32 newPrimitive32(final long rows, final long columns) { + return PRIMITIVE32; + } + static void invoke(final double[] product, final int firstColumn, final int columnLimit, final double[] left, final int complexity, final double[] right) { final int structure = left.length / complexity; @@ -619,7 +646,21 @@ static void invoke(final double[] product, final int firstColumn, final int colu } } - static > void invoke(final N[] product, final int firstColumn, final int columnLimit, final N[] left, final int complexity, + static void invoke(final float[] product, final int firstColumn, final int columnLimit, final float[] left, final int complexity, final float[] right) { + + final int structure = left.length / complexity; + + final float[] leftColumn = new float[structure]; + for (int c = 0; c < complexity; c++) { + System.arraycopy(left, c * structure, leftColumn, 0, structure); + + for (int j = firstColumn; j < columnLimit; j++) { + AXPY.invoke(product, j * structure, right[c + (j * complexity)], leftColumn, 0, 0, structure); + } + } + } + + static > void invoke(final N[] product, final int firstColumn, final int columnLimit, final N[] left, final int complexity, final N[] right, final Scalar.Factory scalar) { final int structure = left.length / complexity; diff --git a/src/org/ojalgo/array/operation/MultiplyRight.java b/src/org/ojalgo/array/operation/MultiplyRight.java index 358d82b3d..9e8bea7c3 100644 --- a/src/org/ojalgo/array/operation/MultiplyRight.java +++ b/src/org/ojalgo/array/operation/MultiplyRight.java @@ -25,25 +25,48 @@ import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore.GenericMultiplyRight; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore.PrimitiveMultiplyRight; import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Structure2D; public final class MultiplyRight implements ArrayOperation { + public interface Generic> { + + void invoke(N[] product, N[] left, int complexity, Access1D right, Scalar.Factory scalar); + + } + + public interface Primitive64 { + + void invoke(double[] product, double[] left, int complexity, Access1D right); + + } + + public interface Primitive32 { + + void invoke(float[] product, float[] left, int complexity, Access1D right); + + } + public static int THRESHOLD = 32; - static final PrimitiveMultiplyRight PRIMITIVE = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE = (product, left, complexity, right) -> { Arrays.fill(product, 0.0); MultiplyRight.invoke(product, 0, (int) (right.count() / complexity), left, complexity, right); }; - static final PrimitiveMultiplyRight PRIMITIVE_0XN = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive32 PRIMITIVE32 = (product, left, complexity, right) -> { + + Arrays.fill(product, 0F); + + MultiplyRight.invoke(product, 0, (int) (right.count() / complexity), left, complexity, right); + }; + + static final MultiplyRight.Primitive64 PRIMITIVE_0XN = (product, left, complexity, right) -> { final int tmpRowDim = 10; final int tmpColDim = product.length / tmpRowDim; @@ -89,7 +112,7 @@ public final class MultiplyRight implements ArrayOperation { } }; - static final PrimitiveMultiplyRight PRIMITIVE_1X1 = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_1X1 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; @@ -102,7 +125,7 @@ public final class MultiplyRight implements ArrayOperation { product[0] = tmp00; }; - static final PrimitiveMultiplyRight PRIMITIVE_1XN = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_1XN = (product, left, complexity, right) -> { final int tmpColDim = product.length; @@ -119,7 +142,7 @@ public final class MultiplyRight implements ArrayOperation { } }; - static final PrimitiveMultiplyRight PRIMITIVE_2X2 = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_2X2 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -150,7 +173,7 @@ public final class MultiplyRight implements ArrayOperation { product[3] = tmp11; }; - static final PrimitiveMultiplyRight PRIMITIVE_3X3 = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_3X3 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -200,7 +223,7 @@ public final class MultiplyRight implements ArrayOperation { product[8] = tmp22; }; - static final PrimitiveMultiplyRight PRIMITIVE_4X4 = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_4X4 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -275,7 +298,7 @@ public final class MultiplyRight implements ArrayOperation { product[15] = tmp33; }; - static final PrimitiveMultiplyRight PRIMITIVE_5X5 = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_5X5 = (product, left, complexity, right) -> { double tmp00 = PrimitiveMath.ZERO; double tmp10 = PrimitiveMath.ZERO; @@ -381,7 +404,7 @@ public final class MultiplyRight implements ArrayOperation { product[24] = tmp44; }; - static final PrimitiveMultiplyRight PRIMITIVE_6XN = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_6XN = (product, left, complexity, right) -> { final int tmpRowDim = 6; final int tmpColDim = product.length / tmpRowDim; @@ -415,7 +438,7 @@ public final class MultiplyRight implements ArrayOperation { } }; - static final PrimitiveMultiplyRight PRIMITIVE_7XN = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_7XN = (product, left, complexity, right) -> { final int tmpRowDim = 7; final int tmpColDim = product.length / tmpRowDim; @@ -452,7 +475,7 @@ public final class MultiplyRight implements ArrayOperation { } }; - static final PrimitiveMultiplyRight PRIMITIVE_8XN = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_8XN = (product, left, complexity, right) -> { final int tmpRowDim = 8; final int tmpColDim = product.length / tmpRowDim; @@ -492,7 +515,7 @@ public final class MultiplyRight implements ArrayOperation { } }; - static final PrimitiveMultiplyRight PRIMITIVE_9XN = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_9XN = (product, left, complexity, right) -> { final int tmpRowDim = 9; final int tmpColDim = product.length / tmpRowDim; @@ -535,7 +558,7 @@ public final class MultiplyRight implements ArrayOperation { } }; - static final PrimitiveMultiplyRight PRIMITIVE_MT = (product, left, complexity, right) -> { + static final MultiplyRight.Primitive64 PRIMITIVE_MT = (product, left, complexity, right) -> { Arrays.fill(product, 0.0); @@ -550,7 +573,7 @@ public void conquer(final int first, final int limit) { tmpConquerer.invoke(0, (int) (right.count() / complexity), THRESHOLD); }; - public static > GenericMultiplyRight getGeneric(final long rows, final long columns) { + public static > MultiplyRight.Generic newGeneric(final long rows, final long columns) { if (columns > THRESHOLD) { @@ -580,7 +603,11 @@ public void conquer(final int first, final int limit) { } } - public static PrimitiveMultiplyRight getPrimitive(final long rows, final long columns) { + public static MultiplyRight.Primitive32 newPrimitive32(final long rows, final long columns) { + return PRIMITIVE32; + } + + public static MultiplyRight.Primitive64 newPrimitive64(final long rows, final long columns) { if (columns > THRESHOLD) { return PRIMITIVE_MT; } else if (rows == 10) { @@ -626,7 +653,24 @@ static void invoke(final double[] product, final int firstColumn, final int colu } } - static > void invoke(final N[] product, final int firstColumn, final int columnLimit, final N[] left, final int complexity, + static void invoke(final float[] product, final int firstColumn, final int columnLimit, final float[] left, final int complexity, final Access1D right) { + + final int structure = left.length / complexity; + + final float[] leftColumn = new float[structure]; + for (int c = 0; c < complexity; c++) { + System.arraycopy(left, c * structure, leftColumn, 0, structure); + + final int firstInRightRow = MatrixStore.firstInRow(right, c, firstColumn); + final int limitOfRightRow = MatrixStore.limitOfRow(right, c, columnLimit); + + for (int j = firstInRightRow; j < limitOfRightRow; j++) { + AXPY.invoke(product, j * structure, right.floatValue(Structure2D.index(complexity, c, j)), leftColumn, 0, 0, structure); + } + } + } + + static > void invoke(final N[] product, final int firstColumn, final int columnLimit, final N[] left, final int complexity, final Access1D right, final Scalar.Factory scalar) { final int structure = left.length / complexity; diff --git a/src/org/ojalgo/array/operation/RotateLeft.java b/src/org/ojalgo/array/operation/RotateLeft.java index 11255bb4e..54bbc74fc 100644 --- a/src/org/ojalgo/array/operation/RotateLeft.java +++ b/src/org/ojalgo/array/operation/RotateLeft.java @@ -48,7 +48,28 @@ public static void invoke(final double[] data, final int structure, final int ro } } - public static > void invoke(final N[] data, final int structure, final int rowA, final int rowB, final N cos, final N sin) { + public static void invoke(final float[] data, final int structure, final int rowA, final int rowB, final float cos, final float sin) { + + float oldA; + float oldB; + + int indexA = rowA; + int indexB = rowB; + + for (int j = 0, lim = data.length / structure; j < lim; j++) { + + oldA = data[indexA]; + oldB = data[indexB]; + + data[indexA] = (cos * oldA) + (sin * oldB); + data[indexB] = (cos * oldB) - (sin * oldA); + + indexA += structure; + indexB += structure; + } + } + + public static > void invoke(final N[] data, final int structure, final int rowA, final int rowB, final N cos, final N sin) { N oldA; N oldB; diff --git a/src/org/ojalgo/array/operation/RotateRight.java b/src/org/ojalgo/array/operation/RotateRight.java index a92972a0d..fe8d9757a 100644 --- a/src/org/ojalgo/array/operation/RotateRight.java +++ b/src/org/ojalgo/array/operation/RotateRight.java @@ -48,7 +48,28 @@ public static void invoke(final double[] data, final int structure, final int co } } - public static > void invoke(final N[] data, final int structure, final int colA, final int colB, final N cos, final N sin) { + public static void invoke(final float[] data, final int structure, final int colA, final int colB, final float cos, final float sin) { + + float oldA; + float oldB; + + int indexA = colA * structure; + int indexB = colB * structure; + + for (int i = 0; i < structure; i++) { + + oldA = data[indexA]; + oldB = data[indexB]; + + data[indexA] = (cos * oldA) - (sin * oldB); + data[indexB] = (cos * oldB) + (sin * oldA); + + indexA++; + indexB++; + } + } + + public static > void invoke(final N[] data, final int structure, final int colA, final int colB, final N cos, final N sin) { N oldA; N oldB; diff --git a/src/org/ojalgo/array/operation/SubstituteBackwards.java b/src/org/ojalgo/array/operation/SubstituteBackwards.java index 381a273b7..7ecaa63e5 100644 --- a/src/org/ojalgo/array/operation/SubstituteBackwards.java +++ b/src/org/ojalgo/array/operation/SubstituteBackwards.java @@ -74,6 +74,39 @@ public static void invoke(final double[] data, final int structure, final int fi } } + public static void invoke(final float[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, + final boolean conjugated, final boolean hermitian) { + + int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); + float[] bodyRow = new float[diagDim]; + float tmpVal; + int colBaseIndex; + + int firstRow = hermitian ? first : 0; + for (int i = diagDim - 1; i >= firstRow; i--) { + + for (int j = i; j < diagDim; j++) { + bodyRow[j] = conjugated ? body.floatValue(j, i) : body.floatValue(i, j); + } + + int columnLimit = hermitian ? Math.min(i + 1, limit) : limit; + for (int s = first; s < columnLimit; s++) { + colBaseIndex = s * structure; + + tmpVal = 0F; + for (int j = i + 1; j < diagDim; j++) { + tmpVal += bodyRow[j] * data[j + colBaseIndex]; + } + tmpVal = data[i + colBaseIndex] - tmpVal; + if (!unitDiagonal) { + tmpVal /= bodyRow[i]; + } + + data[i + colBaseIndex] = tmpVal; + } + } + } + /** * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) */ @@ -111,7 +144,7 @@ public static void invoke(final double[][] data, final Access2D body, final b /** * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) */ - public static > void invoke(final N[] data, final int structure, final int first, final int limit, final Access2D body, + public static > void invoke(final N[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean hermitian, final Scalar.Factory scalar) { int diagDim = (int) Math.min(body.countRows(), body.countColumns()); diff --git a/src/org/ojalgo/array/operation/SubstituteForwards.java b/src/org/ojalgo/array/operation/SubstituteForwards.java index d32488cbf..423041409 100644 --- a/src/org/ojalgo/array/operation/SubstituteForwards.java +++ b/src/org/ojalgo/array/operation/SubstituteForwards.java @@ -77,6 +77,42 @@ public static void invoke(final double[] data, final int structure, final int fi } } + public static void invoke(final float[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, + final boolean conjugated, final boolean identity) { + + int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); + float[] bodyRow = new float[diagDim]; + float tmpVal; + int colBaseIndex; + + for (int i = 0; i < diagDim; i++) { + + for (int j = 0; j <= i; j++) { + bodyRow[j] = conjugated ? body.floatValue(j, i) : body.floatValue(i, j); + } + + for (int s = first; s < limit; s++) { + colBaseIndex = s * structure; + + tmpVal = 0F; + for (int j = identity ? s : 0; j < i; j++) { + tmpVal += bodyRow[j] * data[j + colBaseIndex]; + } + if (identity) { + tmpVal = i == s ? 1F - tmpVal : -tmpVal; + } else { + tmpVal = data[i + colBaseIndex] - tmpVal; + } + + if (!unitDiagonal) { + tmpVal /= bodyRow[i]; + } + + data[i + colBaseIndex] = tmpVal; + } + } + } + /** * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) */ @@ -118,7 +154,7 @@ public static void invoke(final double[][] data, final Access2D body, final b /** * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) */ - public static > void invoke(final N[] data, final int structure, final int first, final int limit, final Access2D body, + public static > void invoke(final N[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean identity, final Scalar.Factory scalar) { int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); diff --git a/src/org/ojalgo/concurrent/DivideAndConquer.java b/src/org/ojalgo/concurrent/DivideAndConquer.java index 0de80e8cb..7a572b681 100644 --- a/src/org/ojalgo/concurrent/DivideAndConquer.java +++ b/src/org/ojalgo/concurrent/DivideAndConquer.java @@ -30,7 +30,7 @@ /** * @author apete */ -public abstract class DivideAndConquer extends Object { +public abstract class DivideAndConquer { public DivideAndConquer() { super(); diff --git a/src/org/ojalgo/equation/Equation.java b/src/org/ojalgo/equation/Equation.java index 53b792cd3..4cd032bb2 100644 --- a/src/org/ojalgo/equation/Equation.java +++ b/src/org/ojalgo/equation/Equation.java @@ -26,6 +26,7 @@ import org.ojalgo.array.Primitive64Array; import org.ojalgo.array.SparseArray; import org.ojalgo.matrix.store.PhysicalStore; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; @@ -63,8 +64,8 @@ public void add(final long index, final double addend) { } } - public void add(final long index, final Number addend) { - this.add(index, addend.doubleValue()); + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); } /** @@ -149,8 +150,8 @@ public void set(final long index, final double value) { } } - public void set(final long index, final Number value) { - this.set(index, value.doubleValue()); + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); } @Override diff --git a/src/org/ojalgo/function/BasicFunction.java b/src/org/ojalgo/function/BasicFunction.java index 4d1e3671e..4a4b4ed9c 100644 --- a/src/org/ojalgo/function/BasicFunction.java +++ b/src/org/ojalgo/function/BasicFunction.java @@ -23,13 +23,13 @@ public interface BasicFunction { - public interface Differentiable extends BasicFunction { + public interface Differentiable, F extends BasicFunction> extends BasicFunction { F buildDerivative(); } - public interface Integratable extends BasicFunction { + public interface Integratable, F extends BasicFunction> extends BasicFunction { F buildPrimitive(); diff --git a/src/org/ojalgo/function/BigFunction.java b/src/org/ojalgo/function/BigFunction.java index f0bd688c0..9fd070aed 100644 --- a/src/org/ojalgo/function/BigFunction.java +++ b/src/org/ojalgo/function/BigFunction.java @@ -46,6 +46,10 @@ default double invoke(final double arg1, final double arg2) { return this.invoke(BigDecimal.valueOf(arg1), BigDecimal.valueOf(arg2)).doubleValue(); } + default float invoke(final float arg1, final float arg2) { + return this.invoke(BigDecimal.valueOf(arg1), BigDecimal.valueOf(arg2)).floatValue(); + } + } @FunctionalInterface @@ -55,6 +59,10 @@ default void invoke(final double arg) { this.invoke(BigDecimal.valueOf(arg)); } + default void invoke(final float arg) { + this.invoke(BigDecimal.valueOf(arg)); + } + } @FunctionalInterface @@ -64,6 +72,10 @@ default double invoke(final double arg, final int param) { return this.invoke(BigDecimal.valueOf(arg), param).doubleValue(); } + default float invoke(final float arg, final int param) { + return this.invoke(BigDecimal.valueOf(arg), param).floatValue(); + } + } @FunctionalInterface @@ -73,6 +85,10 @@ default boolean invoke(final double arg) { return this.invoke(BigDecimal.valueOf(arg)); } + default boolean invoke(final float arg) { + return this.invoke(BigDecimal.valueOf(arg)); + } + } @FunctionalInterface @@ -82,6 +98,10 @@ default double invoke(final double arg) { return this.invoke(BigDecimal.valueOf(arg)).doubleValue(); } + default float invoke(final float arg) { + return this.invoke(BigDecimal.valueOf(arg)).floatValue(); + } + } /** diff --git a/src/org/ojalgo/function/BinaryFunction.java b/src/org/ojalgo/function/BinaryFunction.java index a4e6575d9..827aec0d3 100644 --- a/src/org/ojalgo/function/BinaryFunction.java +++ b/src/org/ojalgo/function/BinaryFunction.java @@ -25,15 +25,16 @@ import java.util.function.DoubleBinaryOperator; import org.ojalgo.ProgrammingError; +import org.ojalgo.scalar.Scalar; -public interface BinaryFunction extends BasicFunction, BinaryOperator, DoubleBinaryOperator { +public interface BinaryFunction> extends BasicFunction, BinaryOperator, DoubleBinaryOperator { /** * A {@linkplain BinaryFunction} with a set/fixed first argument. * * @author apete */ - public static final class FixedFirst implements UnaryFunction { + public static final class FixedFirst> implements UnaryFunction { private final BinaryFunction myFunction; private final N myNumber; @@ -57,7 +58,7 @@ public static final class FixedFirst implements UnaryFunction< myFunction = function; myNumber = arg1; - myValue = arg1.doubleValue(); + myValue = Scalar.doubleValue(arg1); } public double doubleValue() { @@ -76,6 +77,10 @@ public double invoke(final double arg2) { return myFunction.invoke(myValue, arg2); } + public float invoke(final float arg2) { + return myFunction.invoke((float) myValue, arg2); + } + public N invoke(final N arg2) { return myFunction.invoke(myNumber, arg2); } @@ -87,7 +92,7 @@ public N invoke(final N arg2) { * * @author apete */ - public static final class FixedSecond implements UnaryFunction { + public static final class FixedSecond> implements UnaryFunction { private final BinaryFunction myFunction; private final N myNumber; @@ -111,7 +116,7 @@ public static final class FixedSecond implements UnaryFunction myFunction = function; myNumber = arg2; - myValue = arg2.doubleValue(); + myValue = Scalar.doubleValue(arg2); } public double doubleValue() { @@ -130,6 +135,10 @@ public double invoke(final double arg1) { return myFunction.invoke(arg1, myValue); } + public float invoke(final float arg1) { + return myFunction.invoke(arg1, (float) myValue); + } + public N invoke(final N arg1) { return myFunction.invoke(arg1, myNumber); } @@ -144,6 +153,10 @@ public double invoke(final double arg1, final double arg2) { return after.invoke(BinaryFunction.this.invoke(arg1, arg2)); } + public float invoke(final float arg1, final float arg2) { + return after.invoke(BinaryFunction.this.invoke(arg1, arg2)); + } + public N invoke(final N arg1, final N arg2) { return after.invoke(BinaryFunction.this.invoke(arg1, arg2)); } @@ -184,7 +197,7 @@ default UnaryFunction by(final N arg2) { } /** - * @see #first(Number) + * @see #first(Comparable) */ default UnaryFunction first(final double arg1) { return new FixedFirst<>(arg1, this); @@ -203,10 +216,12 @@ default UnaryFunction first(final N arg1) { double invoke(double arg1, double arg2); + float invoke(float arg1, float arg2); + N invoke(N arg1, N arg2); /** - * @see #second(Number) + * @see #second(Comparable) */ default UnaryFunction second(final double arg2) { return new FixedSecond<>(this, arg2); diff --git a/src/org/ojalgo/function/ComplexFunction.java b/src/org/ojalgo/function/ComplexFunction.java index f742d3198..e37b1eaa0 100644 --- a/src/org/ojalgo/function/ComplexFunction.java +++ b/src/org/ojalgo/function/ComplexFunction.java @@ -36,6 +36,10 @@ default double invoke(final double arg1, final double arg2) { return this.invoke(ComplexNumber.valueOf(arg1), ComplexNumber.valueOf(arg2)).doubleValue(); } + default float invoke(final float arg1, final float arg2) { + return this.invoke(ComplexNumber.valueOf(arg1), ComplexNumber.valueOf(arg2)).floatValue(); + } + } @FunctionalInterface @@ -45,6 +49,10 @@ default void invoke(final double arg) { this.invoke(ComplexNumber.valueOf(arg)); } + default void invoke(final float arg) { + this.invoke(ComplexNumber.valueOf(arg)); + } + } @FunctionalInterface @@ -54,6 +62,10 @@ default double invoke(final double arg, final int param) { return this.invoke(ComplexNumber.valueOf(arg), param).doubleValue(); } + default float invoke(final float arg, final int param) { + return this.invoke(ComplexNumber.valueOf(arg), param).floatValue(); + } + } @FunctionalInterface @@ -63,6 +75,10 @@ default boolean invoke(final double arg) { return this.invoke(ComplexNumber.valueOf(arg)); } + default boolean invoke(final float arg) { + return this.invoke(ComplexNumber.valueOf(arg)); + } + } @FunctionalInterface @@ -72,6 +88,10 @@ default double invoke(final double arg) { return this.invoke(ComplexNumber.valueOf(arg)).doubleValue(); } + default float invoke(final float arg) { + return this.invoke(ComplexNumber.valueOf(arg)).floatValue(); + } + } /** diff --git a/src/org/ojalgo/function/FunctionSet.java b/src/org/ojalgo/function/FunctionSet.java index f7264e727..0f8733a5c 100644 --- a/src/org/ojalgo/function/FunctionSet.java +++ b/src/org/ojalgo/function/FunctionSet.java @@ -29,7 +29,7 @@ * * @author apete */ -public abstract class FunctionSet { +public abstract class FunctionSet> { protected FunctionSet() { super(); diff --git a/src/org/ojalgo/function/FunctionUtils.java b/src/org/ojalgo/function/FunctionUtils.java index d2efa01a7..d5b709287 100644 --- a/src/org/ojalgo/function/FunctionUtils.java +++ b/src/org/ojalgo/function/FunctionUtils.java @@ -33,7 +33,7 @@ public abstract class FunctionUtils { * @deprecated v48 Use {@link UnaryFunction#isZeroModified(UnaryFunction)} instead */ @Deprecated - public static boolean isZeroModified(final UnaryFunction function) { + public static > boolean isZeroModified(final UnaryFunction function) { return UnaryFunction.isZeroModified(function); } diff --git a/src/org/ojalgo/function/NullaryFunction.java b/src/org/ojalgo/function/NullaryFunction.java index 9ddea23f3..847e4508d 100644 --- a/src/org/ojalgo/function/NullaryFunction.java +++ b/src/org/ojalgo/function/NullaryFunction.java @@ -25,8 +25,9 @@ import java.util.function.Supplier; import org.ojalgo.ProgrammingError; +import org.ojalgo.structure.AccessScalar; -public interface NullaryFunction extends BasicFunction, Supplier, DoubleSupplier { +public interface NullaryFunction> extends BasicFunction, Supplier, DoubleSupplier, AccessScalar { default NullaryFunction andThen(final UnaryFunction after) { ProgrammingError.throwIfNull(after); diff --git a/src/org/ojalgo/function/ParameterFunction.java b/src/org/ojalgo/function/ParameterFunction.java index a269ddffe..09eb01aba 100644 --- a/src/org/ojalgo/function/ParameterFunction.java +++ b/src/org/ojalgo/function/ParameterFunction.java @@ -25,14 +25,14 @@ import org.ojalgo.ProgrammingError; -public interface ParameterFunction extends BasicFunction, BiFunction { +public interface ParameterFunction> extends BasicFunction, BiFunction { /** * A {@linkplain ParameterFunction} with a set/fixed parameter. * * @author apete */ - public static final class FixedParameter implements UnaryFunction { + public static final class FixedParameter> implements UnaryFunction { private final ParameterFunction myFunction; private final int myParameter; @@ -62,6 +62,10 @@ public double invoke(final double arg) { return myFunction.invoke(arg, myParameter); } + public float invoke(final float arg) { + return myFunction.invoke(arg, myParameter); + } + public N invoke(final N arg) { return myFunction.invoke(arg, myParameter); } @@ -76,6 +80,10 @@ public double invoke(final double arg, final int param) { return after.invoke(ParameterFunction.this.invoke(arg, param)); } + public float invoke(final float arg, final int param) { + return after.invoke(ParameterFunction.this.invoke(arg, param)); + } + public N invoke(final N arg, final int param) { return after.invoke(ParameterFunction.this.invoke(arg, param)); } @@ -95,6 +103,10 @@ public double invoke(final double arg, final int param) { return ParameterFunction.this.invoke(before.invoke(arg), param); } + public float invoke(final float arg, final int param) { + return ParameterFunction.this.invoke(before.invoke(arg), param); + } + public N invoke(final N arg, final int param) { return ParameterFunction.this.invoke(before.invoke(arg), param); } @@ -104,6 +116,8 @@ public N invoke(final N arg, final int param) { double invoke(double arg, int param); + float invoke(float arg, int param); + N invoke(N arg, int param); /** diff --git a/src/org/ojalgo/function/PredicateFunction.java b/src/org/ojalgo/function/PredicateFunction.java index 4f3334666..bf196a6e5 100644 --- a/src/org/ojalgo/function/PredicateFunction.java +++ b/src/org/ojalgo/function/PredicateFunction.java @@ -24,7 +24,9 @@ import java.util.function.DoublePredicate; import java.util.function.Predicate; -public interface PredicateFunction extends BasicFunction, Predicate, DoublePredicate { +public interface PredicateFunction> extends BasicFunction, Predicate, DoublePredicate { + + boolean invoke(float arg); boolean invoke(double arg); @@ -41,6 +43,10 @@ public boolean invoke(final N arg) { return !PredicateFunction.this.invoke(arg); } + public boolean invoke(float arg) { + return !PredicateFunction.this.invoke(arg); + } + }; } diff --git a/src/org/ojalgo/function/PrimitiveFunction.java b/src/org/ojalgo/function/PrimitiveFunction.java index 31b0609d7..5281182cf 100644 --- a/src/org/ojalgo/function/PrimitiveFunction.java +++ b/src/org/ojalgo/function/PrimitiveFunction.java @@ -43,6 +43,10 @@ default Double invoke(final Double arg1, final Double arg2) { return this.invoke(arg1.doubleValue(), arg2.doubleValue()); } + default float invoke(final float arg1, final float arg2) { + return (float) this.invoke((double) arg1, (double) arg2); + } + } @FunctionalInterface @@ -52,6 +56,10 @@ default void invoke(final Double arg) { this.invoke(arg.doubleValue()); } + default void invoke(final float arg) { + this.invoke((double) arg); + } + } @FunctionalInterface @@ -61,6 +69,10 @@ default Double invoke(final Double arg, final int param) { return this.invoke(arg.doubleValue(), param); } + default float invoke(final float arg, final int param) { + return (float) this.invoke((double) arg, param); + } + } @FunctionalInterface @@ -70,6 +82,10 @@ default boolean invoke(final Double arg) { return this.invoke(arg.doubleValue()); } + default boolean invoke(final float arg) { + return this.invoke((double) arg); + } + } @FunctionalInterface @@ -79,6 +95,10 @@ default Double invoke(final Double arg) { return this.invoke(arg.doubleValue()); } + default float invoke(final float arg) { + return (float) this.invoke((double) arg); + } + } /** diff --git a/src/org/ojalgo/function/QuaternionFunction.java b/src/org/ojalgo/function/QuaternionFunction.java index 4e02bc790..f5129ef89 100644 --- a/src/org/ojalgo/function/QuaternionFunction.java +++ b/src/org/ojalgo/function/QuaternionFunction.java @@ -36,6 +36,10 @@ default double invoke(final double arg1, final double arg2) { return this.invoke(Quaternion.valueOf(arg1), Quaternion.valueOf(arg2)).doubleValue(); } + default float invoke(final float arg1, final float arg2) { + return this.invoke(Quaternion.valueOf(arg1), Quaternion.valueOf(arg2)).floatValue(); + } + } @FunctionalInterface @@ -45,6 +49,10 @@ default void invoke(final double arg) { this.invoke(Quaternion.valueOf(arg)); } + default void invoke(final float arg) { + this.invoke(Quaternion.valueOf(arg)); + } + } @FunctionalInterface @@ -54,6 +62,10 @@ default double invoke(final double arg, final int param) { return this.invoke(Quaternion.valueOf(arg), param).doubleValue(); } + default float invoke(final float arg, final int param) { + return this.invoke(Quaternion.valueOf(arg), param).floatValue(); + } + } @FunctionalInterface @@ -63,6 +75,10 @@ default boolean invoke(final double arg) { return this.invoke(Quaternion.valueOf(arg)); } + default boolean invoke(final float arg) { + return this.invoke(Quaternion.valueOf(arg)); + } + } @FunctionalInterface @@ -72,6 +88,10 @@ default double invoke(final double arg) { return this.invoke(Quaternion.valueOf(arg)).doubleValue(); } + default float invoke(final float arg) { + return this.invoke(Quaternion.valueOf(arg)).floatValue(); + } + } /** diff --git a/src/org/ojalgo/function/RationalFunction.java b/src/org/ojalgo/function/RationalFunction.java index 9805257f5..23f1e566f 100644 --- a/src/org/ojalgo/function/RationalFunction.java +++ b/src/org/ojalgo/function/RationalFunction.java @@ -41,6 +41,10 @@ default double invoke(final double arg1, final double arg2) { return this.invoke(RationalNumber.valueOf(arg1), RationalNumber.valueOf(arg2)).doubleValue(); } + default float invoke(final float arg1, final float arg2) { + return this.invoke(RationalNumber.valueOf(arg1), RationalNumber.valueOf(arg2)).floatValue(); + } + } @FunctionalInterface @@ -50,6 +54,10 @@ default void invoke(final double arg) { this.invoke(RationalNumber.valueOf(arg)); } + default void invoke(final float arg) { + this.invoke(RationalNumber.valueOf(arg)); + } + } @FunctionalInterface @@ -59,6 +67,10 @@ default double invoke(final double arg, final int param) { return this.invoke(RationalNumber.valueOf(arg), param).doubleValue(); } + default float invoke(final float arg, final int param) { + return this.invoke(RationalNumber.valueOf(arg), param).floatValue(); + } + } @FunctionalInterface @@ -68,6 +80,10 @@ default boolean invoke(final double arg) { return this.invoke(RationalNumber.valueOf(arg)); } + default boolean invoke(final float arg) { + return this.invoke(RationalNumber.valueOf(arg)); + } + } @FunctionalInterface @@ -77,6 +93,10 @@ default double invoke(final double arg) { return this.invoke(RationalNumber.valueOf(arg)).doubleValue(); } + default float invoke(final float arg) { + return this.invoke(RationalNumber.valueOf(arg)).floatValue(); + } + } /** diff --git a/src/org/ojalgo/function/UnaryFunction.java b/src/org/ojalgo/function/UnaryFunction.java index 0ffb8fe27..3e1eac527 100644 --- a/src/org/ojalgo/function/UnaryFunction.java +++ b/src/org/ojalgo/function/UnaryFunction.java @@ -28,9 +28,9 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.scalar.PrimitiveScalar; -public interface UnaryFunction extends BasicFunction, UnaryOperator, DoubleUnaryOperator { +public interface UnaryFunction> extends BasicFunction, UnaryOperator, DoubleUnaryOperator { - static boolean isZeroModified(final UnaryFunction function) { + static > boolean isZeroModified(final UnaryFunction function) { return !PrimitiveScalar.isSmall(PrimitiveMath.ONE, function.invoke(PrimitiveMath.ZERO)); } @@ -42,6 +42,10 @@ public double invoke(final double arg) { return after.invoke(UnaryFunction.this.invoke(arg)); } + public float invoke(final float arg) { + return after.invoke(UnaryFunction.this.invoke(arg)); + } + public N invoke(final N arg) { return after.invoke(UnaryFunction.this.invoke(arg)); } @@ -69,11 +73,17 @@ public N invoke(final N arg) { return UnaryFunction.this.invoke(before.invoke(arg)); } + public float invoke(float arg) { + return UnaryFunction.this.invoke(before.invoke(arg)); + } + }; } double invoke(double arg); + float invoke(float arg); + N invoke(N arg); } diff --git a/src/org/ojalgo/function/VoidFunction.java b/src/org/ojalgo/function/VoidFunction.java index 1fba35d4a..001eb394b 100644 --- a/src/org/ojalgo/function/VoidFunction.java +++ b/src/org/ojalgo/function/VoidFunction.java @@ -26,7 +26,7 @@ import org.ojalgo.ProgrammingError; -public interface VoidFunction extends BasicFunction, Consumer, DoubleConsumer { +public interface VoidFunction> extends BasicFunction, Consumer, DoubleConsumer { default void accept(final double arg) { this.invoke(arg); @@ -44,6 +44,10 @@ public void invoke(final double arg) { VoidFunction.this.invoke(before.invoke(arg)); } + public void invoke(final float arg) { + VoidFunction.this.invoke(before.invoke(arg)); + } + public void invoke(final N arg) { VoidFunction.this.invoke(before.invoke(arg)); } @@ -53,6 +57,8 @@ public void invoke(final N arg) { void invoke(double arg); + void invoke(float arg); + void invoke(N arg); } diff --git a/src/org/ojalgo/function/aggregator/Aggregator.java b/src/org/ojalgo/function/aggregator/Aggregator.java index f365b37fc..e431023df 100644 --- a/src/org/ojalgo/function/aggregator/Aggregator.java +++ b/src/org/ojalgo/function/aggregator/Aggregator.java @@ -25,7 +25,7 @@ public enum Aggregator { AVERAGE, CARDINALITY, LARGEST, MAXIMUM, MINIMUM, NORM1, NORM2, PRODUCT, PRODUCT2, SMALLEST, SUM, SUM2; - public final AggregatorFunction getFunction(final AggregatorSet collection) { + public final > AggregatorFunction getFunction(final AggregatorSet collection) { return collection.get(this); } diff --git a/src/org/ojalgo/function/aggregator/AggregatorFunction.java b/src/org/ojalgo/function/aggregator/AggregatorFunction.java index 52e0f8f10..6c2b1fd17 100644 --- a/src/org/ojalgo/function/aggregator/AggregatorFunction.java +++ b/src/org/ojalgo/function/aggregator/AggregatorFunction.java @@ -25,7 +25,7 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.AccessScalar; -public interface AggregatorFunction extends VoidFunction, AccessScalar { +public interface AggregatorFunction> extends VoidFunction, AccessScalar { /** * @deprecated v48 Merging will no longer be supported diff --git a/src/org/ojalgo/function/aggregator/AggregatorSet.java b/src/org/ojalgo/function/aggregator/AggregatorSet.java index 3b63290b7..eee437fce 100644 --- a/src/org/ojalgo/function/aggregator/AggregatorSet.java +++ b/src/org/ojalgo/function/aggregator/AggregatorSet.java @@ -29,7 +29,7 @@ * * @author apete */ -public abstract class AggregatorSet { +public abstract class AggregatorSet> { protected AggregatorSet() { super(); diff --git a/src/org/ojalgo/function/aggregator/BigAggregator.java b/src/org/ojalgo/function/aggregator/BigAggregator.java index 5f2ba0451..a6bf37841 100644 --- a/src/org/ojalgo/function/aggregator/BigAggregator.java +++ b/src/org/ojalgo/function/aggregator/BigAggregator.java @@ -42,6 +42,10 @@ public final void invoke(final double anArg) { this.invoke(new BigDecimal(anArg)); } + public final void invoke(final float anArg) { + this.invoke(new BigDecimal(anArg)); + } + public final Scalar toScalar() { return BigScalar.of(this.get()); } diff --git a/src/org/ojalgo/function/aggregator/ComplexAggregator.java b/src/org/ojalgo/function/aggregator/ComplexAggregator.java index fde54ca17..6d34db9e0 100644 --- a/src/org/ojalgo/function/aggregator/ComplexAggregator.java +++ b/src/org/ojalgo/function/aggregator/ComplexAggregator.java @@ -40,6 +40,10 @@ public final void invoke(final double anArg) { this.invoke(ComplexNumber.valueOf(anArg)); } + public final void invoke(final float anArg) { + this.invoke(ComplexNumber.valueOf(anArg)); + } + public final Scalar toScalar() { return this.get(); } diff --git a/src/org/ojalgo/function/aggregator/PrimitiveAggregator.java b/src/org/ojalgo/function/aggregator/PrimitiveAggregator.java index 670dbb179..8d3607535 100644 --- a/src/org/ojalgo/function/aggregator/PrimitiveAggregator.java +++ b/src/org/ojalgo/function/aggregator/PrimitiveAggregator.java @@ -37,8 +37,12 @@ public final Double get() { return Double.valueOf(this.doubleValue()); } - public final void invoke(final Double anArg) { - this.invoke(anArg.doubleValue()); + public final void invoke(final Double arg) { + this.invoke(arg.doubleValue()); + } + + public final void invoke(final float arg) { + this.invoke((double) arg); } public final Scalar toScalar() { diff --git a/src/org/ojalgo/function/aggregator/QuaternionAggregator.java b/src/org/ojalgo/function/aggregator/QuaternionAggregator.java index 761fcc5bc..2be91de18 100644 --- a/src/org/ojalgo/function/aggregator/QuaternionAggregator.java +++ b/src/org/ojalgo/function/aggregator/QuaternionAggregator.java @@ -40,6 +40,10 @@ public final void invoke(final double anArg) { this.invoke(Quaternion.valueOf(anArg)); } + public final void invoke(final float anArg) { + this.invoke(Quaternion.valueOf(anArg)); + } + public final Scalar toScalar() { return this.get(); } diff --git a/src/org/ojalgo/function/aggregator/RationalAggregator.java b/src/org/ojalgo/function/aggregator/RationalAggregator.java index 70d61869d..77b202a27 100644 --- a/src/org/ojalgo/function/aggregator/RationalAggregator.java +++ b/src/org/ojalgo/function/aggregator/RationalAggregator.java @@ -40,6 +40,10 @@ public final void invoke(final double anArg) { this.invoke(RationalNumber.valueOf(anArg)); } + public final void invoke(final float anArg) { + this.invoke(RationalNumber.valueOf(anArg)); + } + public final Scalar toScalar() { return this.get(); } diff --git a/src/org/ojalgo/function/multiary/AffineFunction.java b/src/org/ojalgo/function/multiary/AffineFunction.java index 6d399bc03..ed4040d71 100644 --- a/src/org/ojalgo/function/multiary/AffineFunction.java +++ b/src/org/ojalgo/function/multiary/AffineFunction.java @@ -21,11 +21,11 @@ */ package org.ojalgo.function.multiary; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.scalar.Scalar; @@ -36,33 +36,33 @@ * * @author apete */ -public final class AffineFunction implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Affine { +public final class AffineFunction> implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Affine { public static AffineFunction makeComplex(final Access1D coefficients) { - return new AffineFunction<>(GenericDenseStore.COMPLEX.rows(coefficients)); + return new AffineFunction<>(GenericStore.COMPLEX.rows(coefficients)); } public static AffineFunction makeComplex(final int arity) { - return new AffineFunction<>(GenericDenseStore.COMPLEX.make(1, arity)); + return new AffineFunction<>(GenericStore.COMPLEX.make(1, arity)); } public static AffineFunction makePrimitive(final Access1D coefficients) { - return new AffineFunction<>(PrimitiveDenseStore.FACTORY.rows(coefficients)); + return new AffineFunction<>(Primitive64Store.FACTORY.rows(coefficients)); } public static AffineFunction makePrimitive(final int arity) { - return new AffineFunction<>(PrimitiveDenseStore.FACTORY.make(1, arity)); + return new AffineFunction<>(Primitive64Store.FACTORY.make(1, arity)); } public static AffineFunction makeRational(final Access1D coefficients) { - return new AffineFunction<>(GenericDenseStore.RATIONAL.rows(coefficients)); + return new AffineFunction<>(GenericStore.RATIONAL.rows(coefficients)); } public static AffineFunction makeRational(final int arity) { - return new AffineFunction<>(GenericDenseStore.RATIONAL.make(1, arity)); + return new AffineFunction<>(GenericStore.RATIONAL.make(1, arity)); } - public static AffineFunction wrap(final PhysicalStore coefficients) { + public static > AffineFunction wrap(final PhysicalStore coefficients) { return new AffineFunction<>(coefficients); } @@ -116,7 +116,7 @@ public PhysicalStore linear() { return (PhysicalStore) myCoefficients; } - public void setConstant(final Number constant) { + public void setConstant(final Comparable constant) { myConstant.setConstant(constant); } diff --git a/src/org/ojalgo/function/multiary/ApproximateFunction.java b/src/org/ojalgo/function/multiary/ApproximateFunction.java index b2bc99264..8e06d967d 100644 --- a/src/org/ojalgo/function/multiary/ApproximateFunction.java +++ b/src/org/ojalgo/function/multiary/ApproximateFunction.java @@ -25,7 +25,7 @@ import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.structure.Access1D; -abstract class ApproximateFunction implements MultiaryFunction.TwiceDifferentiable { +abstract class ApproximateFunction> implements MultiaryFunction.TwiceDifferentiable { private final Access1D myPoint; diff --git a/src/org/ojalgo/function/multiary/ConstantFunction.java b/src/org/ojalgo/function/multiary/ConstantFunction.java index abbc0766c..714a4dbe1 100644 --- a/src/org/ojalgo/function/multiary/ConstantFunction.java +++ b/src/org/ojalgo/function/multiary/ConstantFunction.java @@ -21,11 +21,11 @@ */ package org.ojalgo.function.multiary; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.scalar.Scalar; @@ -36,37 +36,37 @@ * * @author apete */ -public final class ConstantFunction implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Constant { +public final class ConstantFunction> implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Constant { public static ConstantFunction makeComplex(final int arity) { - return new ConstantFunction<>(arity, GenericDenseStore.COMPLEX); + return new ConstantFunction<>(arity, GenericStore.COMPLEX); } - public static ConstantFunction makeComplex(final int arity, final Number constant) { - return new ConstantFunction<>(arity, GenericDenseStore.COMPLEX, constant); + public static ConstantFunction makeComplex(final int arity, final Comparable constant) { + return new ConstantFunction<>(arity, GenericStore.COMPLEX, constant); } public static ConstantFunction makePrimitive(final int arity) { - return new ConstantFunction<>(arity, PrimitiveDenseStore.FACTORY); + return new ConstantFunction<>(arity, Primitive64Store.FACTORY); } - public static ConstantFunction makePrimitive(final int arity, final Number constant) { - return new ConstantFunction<>(arity, PrimitiveDenseStore.FACTORY, constant); + public static ConstantFunction makePrimitive(final int arity, final Comparable constant) { + return new ConstantFunction<>(arity, Primitive64Store.FACTORY, constant); } public static ConstantFunction makeRational(final int arity) { - return new ConstantFunction<>(arity, GenericDenseStore.RATIONAL); + return new ConstantFunction<>(arity, GenericStore.RATIONAL); } - public static ConstantFunction makeRational(final int arity, final Number constant) { - return new ConstantFunction<>(arity, GenericDenseStore.RATIONAL, constant); + public static ConstantFunction makeRational(final int arity, final Comparable constant) { + return new ConstantFunction<>(arity, GenericStore.RATIONAL, constant); } private final int myArity; private Scalar myConstant = null; private final PhysicalStore.Factory myFactory; - ConstantFunction(final int arity, final PhysicalStore.Factory factory, final Number constant) { + ConstantFunction(final int arity, final PhysicalStore.Factory factory, final Comparable constant) { this(arity, factory); @@ -105,7 +105,7 @@ public N invoke(final Access1D arg) { return this.getConstant(); } - public void setConstant(final Number constant) { + public void setConstant(final Comparable constant) { myConstant = constant != null ? myFactory.scalar().convert(constant) : null; } diff --git a/src/org/ojalgo/function/multiary/FirstOrderApproximation.java b/src/org/ojalgo/function/multiary/FirstOrderApproximation.java index 75d1cb7bc..f991fe8cf 100644 --- a/src/org/ojalgo/function/multiary/FirstOrderApproximation.java +++ b/src/org/ojalgo/function/multiary/FirstOrderApproximation.java @@ -25,7 +25,7 @@ import org.ojalgo.matrix.store.PhysicalStore.Factory; import org.ojalgo.structure.Access1D; -public final class FirstOrderApproximation extends ApproximateFunction { +public final class FirstOrderApproximation> extends ApproximateFunction { private final AffineFunction myDelegate; diff --git a/src/org/ojalgo/function/multiary/LinearFunction.java b/src/org/ojalgo/function/multiary/LinearFunction.java index 71508d8e0..3819f529b 100644 --- a/src/org/ojalgo/function/multiary/LinearFunction.java +++ b/src/org/ojalgo/function/multiary/LinearFunction.java @@ -21,11 +21,11 @@ */ package org.ojalgo.function.multiary; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.structure.Access1D; @@ -35,33 +35,33 @@ * * @author apete */ -public final class LinearFunction implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Linear { +public final class LinearFunction> implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Linear { public static LinearFunction makeComplex(final Access1D coefficients) { - return new LinearFunction<>(GenericDenseStore.COMPLEX.rows(coefficients)); + return new LinearFunction<>(GenericStore.COMPLEX.rows(coefficients)); } public static LinearFunction makeComplex(final int arity) { - return new LinearFunction<>(GenericDenseStore.COMPLEX.make(1, arity)); + return new LinearFunction<>(GenericStore.COMPLEX.make(1, arity)); } public static LinearFunction makePrimitive(final Access1D coefficients) { - return new LinearFunction<>(PrimitiveDenseStore.FACTORY.rows(coefficients)); + return new LinearFunction<>(Primitive64Store.FACTORY.rows(coefficients)); } public static LinearFunction makePrimitive(final int arity) { - return new LinearFunction<>(PrimitiveDenseStore.FACTORY.make(1, arity)); + return new LinearFunction<>(Primitive64Store.FACTORY.make(1, arity)); } public static LinearFunction makeRational(final Access1D coefficients) { - return new LinearFunction<>(GenericDenseStore.RATIONAL.rows(coefficients)); + return new LinearFunction<>(GenericStore.RATIONAL.rows(coefficients)); } public static LinearFunction makeRational(final int arity) { - return new LinearFunction<>(GenericDenseStore.RATIONAL.make(1, arity)); + return new LinearFunction<>(GenericStore.RATIONAL.make(1, arity)); } - public static LinearFunction wrap(final PhysicalStore coefficients) { + public static > LinearFunction wrap(final PhysicalStore coefficients) { return new LinearFunction<>(coefficients); } diff --git a/src/org/ojalgo/function/multiary/MultiaryFunction.java b/src/org/ojalgo/function/multiary/MultiaryFunction.java index b386c2080..9f72d2117 100644 --- a/src/org/ojalgo/function/multiary/MultiaryFunction.java +++ b/src/org/ojalgo/function/multiary/MultiaryFunction.java @@ -28,37 +28,37 @@ import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.structure.Access1D; -public interface MultiaryFunction extends BasicFunction.PlainUnary, N> { +public interface MultiaryFunction> extends BasicFunction.PlainUnary, N> { - public interface Affine extends Linear, Constant { + public interface Affine> extends Linear, Constant { } - public interface Constant extends MultiaryFunction { + public interface Constant> extends MultiaryFunction { N getConstant(); - void setConstant(Number constant); + void setConstant(Comparable constant); } - public interface Convex extends MultiaryFunction { + public interface Convex> extends MultiaryFunction { } - public interface Linear extends MultiaryFunction { + public interface Linear> extends MultiaryFunction { PhysicalStore linear(); } - public interface PureQuadratic extends Constant { + public interface PureQuadratic> extends Constant { PhysicalStore quadratic(); } - public interface Quadratic extends PureQuadratic, Linear { + public interface Quadratic> extends PureQuadratic, Linear { } @@ -67,7 +67,7 @@ public interface Quadratic extends PureQuadratic, Linear * * @author apete */ - public interface TwiceDifferentiable extends MultiaryFunction { + public interface TwiceDifferentiable> extends MultiaryFunction { /** *

diff --git a/src/org/ojalgo/function/multiary/PureQuadraticFunction.java b/src/org/ojalgo/function/multiary/PureQuadraticFunction.java index e38c82db5..8f4964287 100644 --- a/src/org/ojalgo/function/multiary/PureQuadraticFunction.java +++ b/src/org/ojalgo/function/multiary/PureQuadraticFunction.java @@ -21,11 +21,11 @@ */ package org.ojalgo.function.multiary; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.scalar.Scalar; @@ -37,33 +37,33 @@ * * @author apete */ -public final class PureQuadraticFunction implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.PureQuadratic { +public final class PureQuadraticFunction> implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.PureQuadratic { public static PureQuadraticFunction makeComplex(final Access2D coefficients) { - return new PureQuadraticFunction<>(GenericDenseStore.COMPLEX.copy(coefficients)); + return new PureQuadraticFunction<>(GenericStore.COMPLEX.copy(coefficients)); } public static PureQuadraticFunction makeComplex(final int arity) { - return new PureQuadraticFunction<>(GenericDenseStore.COMPLEX.make(arity, arity)); + return new PureQuadraticFunction<>(GenericStore.COMPLEX.make(arity, arity)); } public static PureQuadraticFunction makePrimitive(final Access2D coefficients) { - return new PureQuadraticFunction<>(PrimitiveDenseStore.FACTORY.copy(coefficients)); + return new PureQuadraticFunction<>(Primitive64Store.FACTORY.copy(coefficients)); } public static PureQuadraticFunction makePrimitive(final int arity) { - return new PureQuadraticFunction<>(PrimitiveDenseStore.FACTORY.make(arity, arity)); + return new PureQuadraticFunction<>(Primitive64Store.FACTORY.make(arity, arity)); } public static PureQuadraticFunction makeRational(final Access2D coefficients) { - return new PureQuadraticFunction<>(GenericDenseStore.RATIONAL.copy(coefficients)); + return new PureQuadraticFunction<>(GenericStore.RATIONAL.copy(coefficients)); } public static PureQuadraticFunction makeRational(final int arity) { - return new PureQuadraticFunction<>(GenericDenseStore.RATIONAL.make(arity, arity)); + return new PureQuadraticFunction<>(GenericStore.RATIONAL.make(arity, arity)); } - public static PureQuadraticFunction wrap(final PhysicalStore coefficients) { + public static > PureQuadraticFunction wrap(final PhysicalStore coefficients) { return new PureQuadraticFunction<>(coefficients); } @@ -118,7 +118,7 @@ public PhysicalStore quadratic() { return (PhysicalStore) myCoefficients; } - public void setConstant(final Number constant) { + public void setConstant(final Comparable constant) { myConstant.setConstant(constant); } diff --git a/src/org/ojalgo/function/multiary/QuadraticFunction.java b/src/org/ojalgo/function/multiary/QuadraticFunction.java index b0e7ef0ea..262240f5e 100644 --- a/src/org/ojalgo/function/multiary/QuadraticFunction.java +++ b/src/org/ojalgo/function/multiary/QuadraticFunction.java @@ -21,11 +21,11 @@ */ package org.ojalgo.function.multiary; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.scalar.Scalar; @@ -37,33 +37,33 @@ * * @author apete */ -public final class QuadraticFunction implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Quadratic { +public final class QuadraticFunction> implements MultiaryFunction.TwiceDifferentiable, MultiaryFunction.Quadratic { public static QuadraticFunction makeComplex(final Access2D quadratic, final Access1D linear) { - return new QuadraticFunction<>(GenericDenseStore.COMPLEX.copy(quadratic), GenericDenseStore.COMPLEX.columns(linear)); + return new QuadraticFunction<>(GenericStore.COMPLEX.copy(quadratic), GenericStore.COMPLEX.columns(linear)); } public static QuadraticFunction makeComplex(final int arity) { - return new QuadraticFunction<>(GenericDenseStore.COMPLEX.make(arity, arity), GenericDenseStore.COMPLEX.make(arity, 1)); + return new QuadraticFunction<>(GenericStore.COMPLEX.make(arity, arity), GenericStore.COMPLEX.make(arity, 1)); } public static QuadraticFunction makePrimitive(final Access2D quadratic, final Access1D linear) { - return new QuadraticFunction<>(PrimitiveDenseStore.FACTORY.copy(quadratic), PrimitiveDenseStore.FACTORY.columns(linear)); + return new QuadraticFunction<>(Primitive64Store.FACTORY.copy(quadratic), Primitive64Store.FACTORY.columns(linear)); } public static QuadraticFunction makePrimitive(final int arity) { - return new QuadraticFunction<>(PrimitiveDenseStore.FACTORY.make(arity, arity), PrimitiveDenseStore.FACTORY.make(arity, 1)); + return new QuadraticFunction<>(Primitive64Store.FACTORY.make(arity, arity), Primitive64Store.FACTORY.make(arity, 1)); } public static QuadraticFunction makeRational(final Access2D quadratic, final Access1D linear) { - return new QuadraticFunction<>(GenericDenseStore.RATIONAL.copy(quadratic), GenericDenseStore.RATIONAL.columns(linear)); + return new QuadraticFunction<>(GenericStore.RATIONAL.copy(quadratic), GenericStore.RATIONAL.columns(linear)); } public static QuadraticFunction makeRational(final int arity) { - return new QuadraticFunction<>(GenericDenseStore.RATIONAL.make(arity, arity), GenericDenseStore.RATIONAL.make(arity, 1)); + return new QuadraticFunction<>(GenericStore.RATIONAL.make(arity, arity), GenericStore.RATIONAL.make(arity, 1)); } - public static QuadraticFunction wrap(final PhysicalStore quadratic, final PhysicalStore linear) { + public static > QuadraticFunction wrap(final PhysicalStore quadratic, final PhysicalStore linear) { return new QuadraticFunction<>(quadratic, linear); } @@ -119,7 +119,7 @@ public PhysicalStore quadratic() { return myPureQuadratic.quadratic(); } - public void setConstant(final Number constant) { + public void setConstant(final Comparable constant) { myPureQuadratic.setConstant(constant); } diff --git a/src/org/ojalgo/function/multiary/SecondOrderApproximation.java b/src/org/ojalgo/function/multiary/SecondOrderApproximation.java index 18cf6532a..b8dd09498 100644 --- a/src/org/ojalgo/function/multiary/SecondOrderApproximation.java +++ b/src/org/ojalgo/function/multiary/SecondOrderApproximation.java @@ -26,7 +26,7 @@ import org.ojalgo.matrix.store.PhysicalStore.Factory; import org.ojalgo.structure.Access1D; -public final class SecondOrderApproximation extends ApproximateFunction { +public final class SecondOrderApproximation> extends ApproximateFunction { private final QuadraticFunction myDelegate; diff --git a/src/org/ojalgo/function/polynomial/AbstractPolynomial.java b/src/org/ojalgo/function/polynomial/AbstractPolynomial.java index ffed5c731..da45fc3c7 100644 --- a/src/org/ojalgo/function/polynomial/AbstractPolynomial.java +++ b/src/org/ojalgo/function/polynomial/AbstractPolynomial.java @@ -27,7 +27,7 @@ import org.ojalgo.series.NumberSeries; import org.ojalgo.structure.Access1D; -abstract class AbstractPolynomial implements PolynomialFunction { +abstract class AbstractPolynomial> implements PolynomialFunction { private final Array1D myCoefficients; @@ -91,7 +91,7 @@ public final double doubleValue(final long power) { return myCoefficients.doubleValue(power); } - public final void estimate(final List x, final List y) { + public final void estimate(final List x, final List y) { this.estimate(Access1D.wrap(x), Access1D.wrap(y)); } @@ -105,12 +105,25 @@ public final N get(final long power) { public final double invoke(final double arg) { - int tmpPower = this.degree(); + int power = this.degree(); - double retVal = this.doubleValue(tmpPower); + double retVal = this.doubleValue(power); - while (--tmpPower >= 0) { - retVal = this.doubleValue(tmpPower) + (arg * retVal); + while (--power >= 0) { + retVal = this.doubleValue(power) + (arg * retVal); + } + + return retVal; + } + + public final float invoke(final float arg) { + + int power = this.degree(); + + float retVal = this.floatValue(power); + + while (--power >= 0) { + retVal = this.floatValue(power) + (arg * retVal); } return retVal; diff --git a/src/org/ojalgo/function/polynomial/BigPolynomial.java b/src/org/ojalgo/function/polynomial/BigPolynomial.java index 2f0e42799..0177f916b 100644 --- a/src/org/ojalgo/function/polynomial/BigPolynomial.java +++ b/src/org/ojalgo/function/polynomial/BigPolynomial.java @@ -26,7 +26,7 @@ import org.ojalgo.array.Array1D; import org.ojalgo.function.constant.BigMath; import org.ojalgo.matrix.decomposition.QR; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.structure.Access1D; @@ -52,8 +52,8 @@ public void estimate(final Access1D x, final Access1D y) { final int tmpRowDim = (int) Math.min(x.count(), y.count()); final int tmpColDim = this.size(); - final PhysicalStore tmpBody = GenericDenseStore.RATIONAL.makeZero(tmpRowDim, tmpColDim); - final PhysicalStore tmpRHS = GenericDenseStore.RATIONAL.makeZero(tmpRowDim, 1); + final PhysicalStore tmpBody = GenericStore.RATIONAL.makeZero(tmpRowDim, tmpColDim); + final PhysicalStore tmpRHS = GenericStore.RATIONAL.makeZero(tmpRowDim, 1); for (int i = 0; i < tmpRowDim; i++) { diff --git a/src/org/ojalgo/function/polynomial/ComplexPolynomial.java b/src/org/ojalgo/function/polynomial/ComplexPolynomial.java index 6af39acc6..79803b097 100644 --- a/src/org/ojalgo/function/polynomial/ComplexPolynomial.java +++ b/src/org/ojalgo/function/polynomial/ComplexPolynomial.java @@ -23,7 +23,7 @@ import org.ojalgo.array.Array1D; import org.ojalgo.matrix.decomposition.QR; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.structure.Access1D; @@ -43,8 +43,8 @@ public void estimate(final Access1D x, final Access1D y) { final int tmpRowDim = (int) Math.min(x.count(), y.count()); final int tmpColDim = this.size(); - final PhysicalStore tmpBody = GenericDenseStore.COMPLEX.makeZero(tmpRowDim, tmpColDim); - final PhysicalStore tmpRHS = GenericDenseStore.COMPLEX.makeZero(tmpRowDim, 1); + final PhysicalStore tmpBody = GenericStore.COMPLEX.makeZero(tmpRowDim, tmpColDim); + final PhysicalStore tmpRHS = GenericStore.COMPLEX.makeZero(tmpRowDim, 1); for (int i = 0; i < tmpRowDim; i++) { diff --git a/src/org/ojalgo/function/polynomial/PolynomialFunction.java b/src/org/ojalgo/function/polynomial/PolynomialFunction.java index d8ee22d0b..0f5243851 100644 --- a/src/org/ojalgo/function/polynomial/PolynomialFunction.java +++ b/src/org/ojalgo/function/polynomial/PolynomialFunction.java @@ -29,14 +29,14 @@ import org.ojalgo.series.NumberSeries; import org.ojalgo.structure.Access1D; -public interface PolynomialFunction +public interface PolynomialFunction> extends UnaryFunction, Access1D, Differentiable>, Integratable> { int degree(); void estimate(Access1D x, Access1D y); - void estimate(List x, List y); + void estimate(List x, List y); void estimate(NumberSeries samples); diff --git a/src/org/ojalgo/function/polynomial/PrimitivePolynomial.java b/src/org/ojalgo/function/polynomial/PrimitivePolynomial.java index 50e7d4d65..f1f5203b3 100644 --- a/src/org/ojalgo/function/polynomial/PrimitivePolynomial.java +++ b/src/org/ojalgo/function/polynomial/PrimitivePolynomial.java @@ -25,7 +25,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.decomposition.QR; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; public class PrimitivePolynomial extends AbstractPolynomial { @@ -43,8 +43,8 @@ public void estimate(final Access1D x, final Access1D y) { final int tmpRowDim = (int) Math.min(x.count(), y.count()); final int tmpColDim = this.size(); - final PhysicalStore tmpBody = PrimitiveDenseStore.FACTORY.makeZero(tmpRowDim, tmpColDim); - final PhysicalStore tmpRHS = PrimitiveDenseStore.FACTORY.makeZero(tmpRowDim, 1); + final PhysicalStore tmpBody = Primitive64Store.FACTORY.makeZero(tmpRowDim, tmpColDim); + final PhysicalStore tmpRHS = Primitive64Store.FACTORY.makeZero(tmpRowDim, 1); for (int i = 0; i < tmpRowDim; i++) { diff --git a/src/org/ojalgo/function/polynomial/RationalPolynomial.java b/src/org/ojalgo/function/polynomial/RationalPolynomial.java index 79f4d370f..f4f69e4ce 100644 --- a/src/org/ojalgo/function/polynomial/RationalPolynomial.java +++ b/src/org/ojalgo/function/polynomial/RationalPolynomial.java @@ -26,7 +26,7 @@ import org.ojalgo.array.Array1D; import org.ojalgo.function.constant.BigMath; import org.ojalgo.matrix.decomposition.QR; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.structure.Access1D; @@ -47,8 +47,8 @@ public void estimate(final Access1D x, final Access1D y) { final int tmpRowDim = (int) Math.min(x.count(), y.count()); final int tmpColDim = this.size(); - final PhysicalStore tmpBody = GenericDenseStore.RATIONAL.makeZero(tmpRowDim, tmpColDim); - final PhysicalStore tmpRHS = GenericDenseStore.RATIONAL.makeZero(tmpRowDim, 1); + final PhysicalStore tmpBody = GenericStore.RATIONAL.makeZero(tmpRowDim, tmpColDim); + final PhysicalStore tmpRHS = GenericStore.RATIONAL.makeZero(tmpRowDim, 1); for (int i = 0; i < tmpRowDim; i++) { diff --git a/src/org/ojalgo/matrix/BasicMatrix.java b/src/org/ojalgo/matrix/BasicMatrix.java index 9f85d4b00..1f2880774 100644 --- a/src/org/ojalgo/matrix/BasicMatrix.java +++ b/src/org/ojalgo/matrix/BasicMatrix.java @@ -46,6 +46,7 @@ import org.ojalgo.matrix.store.ElementsSupplier; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; +import org.ojalgo.matrix.store.PhysicalStore.Factory; import org.ojalgo.matrix.task.DeterminantTask; import org.ojalgo.matrix.task.InverterTask; import org.ojalgo.matrix.task.SolverTask; @@ -65,11 +66,11 @@ * * @author apete */ -abstract class BasicMatrix> extends Object implements NormedVectorSpace, Operation.Subtraction, +abstract class BasicMatrix, M extends BasicMatrix> implements NormedVectorSpace, Operation.Subtraction, Operation.Multiplication, ScalarOperation.Addition, ScalarOperation.Division, ScalarOperation.Subtraction, Access2D, Access2D.Elements, Access2D.Aggregatable, Structure2D.ReducibleTo1D, NumberContext.Enforceable, Access2D.Collectable> { - public interface LogicalBuilder> + public interface LogicalBuilder, M extends BasicMatrix> extends Structure2D.Logical>, Access2D.Collectable> { default M build() { @@ -78,7 +79,7 @@ default M build() { } - public interface PhysicalReceiver> + public interface PhysicalReceiver, M extends BasicMatrix> extends Mutate2D.ModifiableReceiver, Supplier, Access2D.Collectable> { default M build() { @@ -108,7 +109,7 @@ public static > double calculateInfinityNorm(final M final long tmpLimit = matrix.countRows(); for (long i = 0L; i < tmpLimit; i++) { - retVal = PrimitiveMath.MAX.invoke(retVal, matrix.aggregateRow(i, Aggregator.NORM1).doubleValue()); + retVal = PrimitiveMath.MAX.invoke(retVal, Scalar.doubleValue(matrix.aggregateRow(i, Aggregator.NORM1))); } return retVal; @@ -123,7 +124,7 @@ public static > double calculateOneNorm(final M matr final long tmpLimit = matrix.countColumns(); for (long j = 0L; j < tmpLimit; j++) { - retVal = PrimitiveMath.MAX.invoke(retVal, matrix.aggregateColumn(j, Aggregator.NORM1).doubleValue()); + retVal = PrimitiveMath.MAX.invoke(retVal, Scalar.doubleValue(matrix.aggregateColumn(j, Aggregator.NORM1))); } return retVal; @@ -153,11 +154,13 @@ private BasicMatrix() { public M add(final double scalarAddend) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); - final N tmpRight = myStore.physical().scalar().cast(scalarAddend); + PhysicalStore retVal = physical.copy(myStore); - retVal.modifyAll(myStore.physical().function().add().second(tmpRight)); + N right = physical.scalar().cast(scalarAddend); + + retVal.modifyAll(physical.function().add().second(right)); return this.getFactory().instantiate(retVal); } @@ -173,15 +176,13 @@ public M add(final M addend) { return this.getFactory().instantiate(retVal); } - public M add(final Number scalarAddend) { - - final org.ojalgo.matrix.store.PhysicalStore.Factory tmpPhysical = myStore.physical(); + public M add(final N scalarAddend) { - final PhysicalStore retVal = tmpPhysical.copy(myStore); + PhysicalStore.Factory physical = myStore.physical(); - final N tmpRight = tmpPhysical.scalar().cast(scalarAddend); + PhysicalStore retVal = physical.copy(myStore); - retVal.modifyAll(tmpPhysical.function().add().second(tmpRight)); + retVal.modifyAll(physical.function().add().second(scalarAddend)); return this.getFactory().instantiate(retVal); } @@ -225,22 +226,24 @@ public long countRows() { public M divide(final double scalarDivisor) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); + + PhysicalStore retVal = physical.copy(myStore); - final N tmpRight = myStore.physical().scalar().cast(scalarDivisor); + N right = physical.scalar().cast(scalarDivisor); - retVal.modifyAll(myStore.physical().function().divide().second(tmpRight)); + retVal.modifyAll(physical.function().divide().second(right)); return this.getFactory().instantiate(retVal); } - public M divide(final Number scalarDivisor) { + public M divide(final N scalarDivisor) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); - final N tmpRight = myStore.physical().scalar().cast(scalarDivisor); + PhysicalStore retVal = physical.copy(myStore); - retVal.modifyAll(myStore.physical().function().divide().second(tmpRight)); + retVal.modifyAll(physical.function().divide().second(scalarDivisor)); return this.getFactory().instantiate(retVal); } @@ -499,11 +502,13 @@ public boolean isSymmetric() { public M multiply(final double scalarMultiplicand) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); - final N tmpRight = myStore.physical().scalar().cast(scalarMultiplicand); + PhysicalStore retVal = physical.copy(myStore); - retVal.modifyAll(myStore.physical().function().multiply().second(tmpRight)); + N right = physical.scalar().cast(scalarMultiplicand); + + retVal.modifyAll(physical.function().multiply().second(right)); return this.getFactory().instantiate(retVal); } @@ -515,13 +520,13 @@ public M multiply(final M multiplicand) { return this.getFactory().instantiate(myStore.multiply(this.cast(multiplicand).get())); } - public M multiply(final Number scalarMultiplicand) { + public M multiply(final N scalarMultiplicand) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); - final N tmpRight = myStore.physical().scalar().cast(scalarMultiplicand); + PhysicalStore retVal = physical.copy(myStore); - retVal.modifyAll(myStore.physical().function().multiply().second(tmpRight)); + retVal.modifyAll(physical.function().multiply().second(scalarMultiplicand)); return this.getFactory().instantiate(retVal); } @@ -618,11 +623,13 @@ public M solve(final Access2D rhs) { public M subtract(final double scalarSubtrahend) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); + + PhysicalStore retVal = physical.copy(myStore); - final N tmpRight = myStore.physical().scalar().cast(scalarSubtrahend); + N right = physical.scalar().cast(scalarSubtrahend); - retVal.modifyAll(myStore.physical().function().subtract().second(tmpRight)); + retVal.modifyAll(physical.function().subtract().second(right)); return this.getFactory().instantiate(retVal); } @@ -638,13 +645,13 @@ public M subtract(final M subtrahend) { return this.getFactory().instantiate(retVal); } - public M subtract(final Number scalarSubtrahend) { + public M subtract(final N scalarSubtrahend) { - final PhysicalStore retVal = myStore.physical().copy(myStore); + Factory physical = myStore.physical(); - final N tmpRight = myStore.physical().scalar().cast(scalarSubtrahend); + PhysicalStore retVal = physical.copy(myStore); - retVal.modifyAll(myStore.physical().function().subtract().second(tmpRight)); + retVal.modifyAll(physical.function().subtract().second(scalarSubtrahend)); return this.getFactory().instantiate(retVal); } diff --git a/src/org/ojalgo/matrix/ComplexMatrix.java b/src/org/ojalgo/matrix/ComplexMatrix.java index cbf598876..02388aebd 100644 --- a/src/org/ojalgo/matrix/ComplexMatrix.java +++ b/src/org/ojalgo/matrix/ComplexMatrix.java @@ -28,10 +28,10 @@ import org.ojalgo.matrix.decomposition.QR; import org.ojalgo.matrix.decomposition.SingularValue; import org.ojalgo.matrix.store.ElementsSupplier; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.SparseStore; import org.ojalgo.matrix.task.DeterminantTask; import org.ojalgo.matrix.task.InverterTask; @@ -61,7 +61,7 @@ public static final class Factory extends MatrixFactory { Factory() { - super(ComplexMatrix.class, GenericDenseStore.COMPLEX); + super(ComplexMatrix.class, GenericStore.COMPLEX); } @Override @@ -125,29 +125,29 @@ public ComplexMatrix.DenseReceiver copy() { /** * @return A primitive double valued matrix containg this matrix' element arguments */ - public PrimitiveMatrix getArgument() { - return PrimitiveMatrix.FACTORY.instantiate(PrimitiveDenseStore.getComplexArgument(this.getStore())); + public Primitive64Matrix getArgument() { + return Primitive64Matrix.FACTORY.instantiate(Primitive64Store.getComplexArgument(this.getStore())); } /** * @return A primitive double valued matrix containg this matrix' element imaginary parts */ - public PrimitiveMatrix getImaginary() { - return PrimitiveMatrix.FACTORY.instantiate(PrimitiveDenseStore.getComplexImaginary(this.getStore())); + public Primitive64Matrix getImaginary() { + return Primitive64Matrix.FACTORY.instantiate(Primitive64Store.getComplexImaginary(this.getStore())); } /** * @return A primitive double valued matrix containg this matrix' element modulus */ - public PrimitiveMatrix getModulus() { - return PrimitiveMatrix.FACTORY.instantiate(PrimitiveDenseStore.getComplexModulus(this.getStore())); + public Primitive64Matrix getModulus() { + return Primitive64Matrix.FACTORY.instantiate(Primitive64Store.getComplexModulus(this.getStore())); } /** * @return A primitive double valued matrix containg this matrix' element real parts */ - public PrimitiveMatrix getReal() { - return PrimitiveMatrix.FACTORY.instantiate(PrimitiveDenseStore.getComplexReal(this.getStore())); + public Primitive64Matrix getReal() { + return Primitive64Matrix.FACTORY.instantiate(Primitive64Store.getComplexReal(this.getStore())); } @Override diff --git a/src/org/ojalgo/matrix/MatrixFactory.java b/src/org/ojalgo/matrix/MatrixFactory.java index a418fcb50..e93a79c91 100644 --- a/src/org/ojalgo/matrix/MatrixFactory.java +++ b/src/org/ojalgo/matrix/MatrixFactory.java @@ -47,8 +47,8 @@ * * @author apete */ -abstract class MatrixFactory, B extends BasicMatrix.LogicalBuilder, DR extends BasicMatrix.PhysicalReceiver, SR extends BasicMatrix.PhysicalReceiver> - implements Factory2D { +abstract class MatrixFactory, M extends BasicMatrix, B extends BasicMatrix.LogicalBuilder, DR extends BasicMatrix.PhysicalReceiver, SR extends BasicMatrix.PhysicalReceiver> + implements Factory2D.MayBeSparse { abstract class DenseReceiver extends Physical> { @@ -280,7 +280,7 @@ public B superimpose(final int row, final int col, final M matrix) { * @deprecated v48 */ @Deprecated - public B superimpose(final int row, final int col, final Number matrix) { + public B superimpose(final int row, final int col, final N matrix) { myDelegate.superimpose(row, col, matrix); return this.self(); } @@ -376,7 +376,7 @@ public void add(final long row, final long col, final double value) { } } - public void add(final long row, final long col, final Number value) { + public void add(final long row, final long col, final Comparable value) { if (mySafe) { myDelegate.add(row, col, value); } else { @@ -384,7 +384,7 @@ public void add(final long row, final long col, final Number value) { } } - public void add(final long index, final Number addend) { + public void add(final long index, final Comparable addend) { if (mySafe) { myDelegate.add(index, addend); } else { @@ -420,7 +420,7 @@ public void exchangeRows(final long rowA, final long rowB) { } } - public void fillAll(final NullaryFunction supplier) { + public void fillAll(final NullaryFunction supplier) { if (mySafe) { myDelegate.fillAll(supplier); } else { @@ -428,7 +428,7 @@ public void fillAll(final NullaryFunction supplier) { } } - public void fillAll(final Number value) { + public void fillAll(final N value) { if (mySafe) { myDelegate.fillAll(myDelegate.physical().scalar().cast(value)); } else { @@ -452,7 +452,7 @@ public void fillColumn(final long row, final long col, final Access1D values) } } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillColumn(row, col, supplier); } else { @@ -460,7 +460,7 @@ public void fillColumn(final long row, final long col, final NullaryFunction } } - public void fillColumn(final long row, final long column, final Number value) { + public void fillColumn(final long row, final long column, final N value) { if (mySafe) { myDelegate.fillColumn((int) row, (int) column, myDelegate.physical().scalar().cast(value)); } else { @@ -476,7 +476,7 @@ public void fillColumn(final long col, final N value) { } } - public void fillColumn(final long col, final NullaryFunction supplier) { + public void fillColumn(final long col, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillColumn(col, supplier); } else { @@ -500,7 +500,7 @@ public void fillDiagonal(final long row, final long col, final Access1D value } } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillDiagonal(row, col, supplier); } else { @@ -508,7 +508,7 @@ public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final NullaryFunction supplier) { if (mySafe) { myDelegate.fillDiagonal(supplier); } else { @@ -580,7 +580,7 @@ public void fillOne(final long row, final long col, final N value) { } } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillOne(row, col, supplier); } else { @@ -596,7 +596,7 @@ public void fillOne(final long index, final N value) { } } - public void fillOne(final long index, final NullaryFunction supplier) { + public void fillOne(final long index, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillOne(index, supplier); } else { @@ -612,7 +612,7 @@ public void fillRange(final long first, final long limit, final N value) { } } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillRange(first, limit, supplier); } else { @@ -636,7 +636,7 @@ public void fillRow(final long row, final long col, final Access1D values) { } } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillRow(row, col, supplier); } else { @@ -644,7 +644,7 @@ public void fillRow(final long row, final long col, final NullaryFunction sup } } - public void fillRow(final long row, final long column, final Number value) { + public void fillRow(final long row, final long column, final N value) { if (mySafe) { myDelegate.fillRow((int) row, (int) column, myDelegate.physical().scalar().cast(value)); } else { @@ -660,7 +660,7 @@ public void fillRow(final long row, final N value) { } } - public void fillRow(final long row, final NullaryFunction supplier) { + public void fillRow(final long row, final NullaryFunction supplier) { if (mySafe) { myDelegate.fillRow(row, supplier); } else { @@ -834,7 +834,7 @@ public void set(final long row, final long col, final double value) { } } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { if (mySafe) { myDelegate.set(row, col, value); } else { @@ -842,7 +842,7 @@ public void set(final long row, final long col, final Number value) { } } - public void set(final long index, final Number value) { + public void set(final long index, final Comparable value) { if (mySafe) { myDelegate.set(index, myDelegate.physical().scalar().cast(value)); } else { @@ -894,11 +894,11 @@ public M columns(final double[]... source) { } @SafeVarargs - public final M columns(final List... source) { + public final M columns(final List>... source) { return this.instantiate(myPhysicalFactory.columns(source)); } - public M columns(final Number[]... source) { + public M columns(final Comparable[]... source) { return this.instantiate(myPhysicalFactory.columns(source)); } @@ -931,7 +931,7 @@ public DR makeDense(final int count) { return this.makeDense(count, 1); } - public DR makeDense(final int rows, final int columns) { + public DR makeDense(final long rows, final long columns) { return this.physical(myPhysicalFactory.make(rows, columns)); } @@ -966,7 +966,7 @@ public M makeSingle(final N element) { return this.instantiate(myPhysicalFactory.builder().makeSingle(element).get()); } - public SR makeSparse(final int rows, final int columns) { + public SR makeSparse(final long rows, final long columns) { return this.physical(myPhysicalFactory.builder().makeSparse(rows, columns)); } @@ -991,11 +991,11 @@ public M rows(final double[]... source) { } @SuppressWarnings("unchecked") - public M rows(final List... source) { + public M rows(final List>... source) { return this.instantiate(myPhysicalFactory.rows(source)); } - public M rows(final Number[]... source) { + public M rows(final Comparable[]... source) { return this.instantiate(myPhysicalFactory.rows(source)); } diff --git a/src/org/ojalgo/matrix/MatrixUtils.java b/src/org/ojalgo/matrix/MatrixUtils.java index 1847211e4..a4f7eb3de 100644 --- a/src/org/ojalgo/matrix/MatrixUtils.java +++ b/src/org/ojalgo/matrix/MatrixUtils.java @@ -25,7 +25,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.PrimitiveScalar; @@ -149,48 +149,48 @@ public static final long firstInRow(final Access1D matrix, final long row, fi /** * Extracts the argument of the ComplexNumber elements to a new primitive double valued matrix. * - * @deprecated v47 Use {@link PrimitiveDenseStore#getComplexArgument(Access2D)} instead + * @deprecated v47 Use {@link Primitive64Store#getComplexArgument(Access2D)} instead */ @Deprecated - public static PrimitiveDenseStore getComplexArgument(final Access2D arg) { - return PrimitiveDenseStore.getComplexArgument(arg); + public static Primitive64Store getComplexArgument(final Access2D arg) { + return Primitive64Store.getComplexArgument(arg); } /** * Extracts the imaginary part of the ComplexNumber elements to a new primitive double valued matrix. * - * @deprecated v47 Use {@link PrimitiveDenseStore#getComplexImaginary(Access2D)} instead + * @deprecated v47 Use {@link Primitive64Store#getComplexImaginary(Access2D)} instead */ @Deprecated - public static PrimitiveDenseStore getComplexImaginary(final Access2D arg) { - return PrimitiveDenseStore.getComplexImaginary(arg); + public static Primitive64Store getComplexImaginary(final Access2D arg) { + return Primitive64Store.getComplexImaginary(arg); } /** * Extracts the modulus of the ComplexNumber elements to a new primitive double valued matrix. * - * @deprecated v47 Use {@link PrimitiveDenseStore#getComplexModulus(Access2D)} instead + * @deprecated v47 Use {@link Primitive64Store#getComplexModulus(Access2D)} instead */ @Deprecated - public static PrimitiveDenseStore getComplexModulus(final Access2D arg) { - return PrimitiveDenseStore.getComplexModulus(arg); + public static Primitive64Store getComplexModulus(final Access2D arg) { + return Primitive64Store.getComplexModulus(arg); } /** * Extracts the real part of the ComplexNumber elements to a new primitive double valued matrix. * - * @deprecated v47 Use {@link PrimitiveDenseStore#getComplexReal(Access2D)} instead + * @deprecated v47 Use {@link Primitive64Store#getComplexReal(Access2D)} instead */ @Deprecated - public static PrimitiveDenseStore getComplexReal(final Access2D arg) { - return PrimitiveDenseStore.getComplexReal(arg); + public static Primitive64Store getComplexReal(final Access2D arg) { + return Primitive64Store.getComplexReal(arg); } /** * @deprecated v47 Use {@link Access1D#hashCode()} instead. */ @Deprecated - public static int hashCode(final BasicMatrix matrix) { + public static > int hashCode(final BasicMatrix matrix) { return Access1D.hashCode(matrix); } @@ -198,7 +198,7 @@ public static int hashCode(final BasicMatrix matrix) { * @deprecated v47 Use {@link Access1D#hashCode()} instead. */ @Deprecated - public static int hashCode(final MatrixStore matrix) { + public static > int hashCode(final MatrixStore matrix) { return Access1D.hashCode(matrix); } @@ -211,7 +211,7 @@ public static boolean isHermitian(final Access2D matrix) { final long tmpRowDim = matrix.countRows(); final long tmpColDim = matrix.countColumns(); - final Number tmpElement = matrix.get(0L); + final Comparable tmpElement = matrix.get(0L); boolean retVal = tmpRowDim == tmpColDim; @@ -245,7 +245,7 @@ public static boolean isHermitian(final Access2D matrix) { * @deprecated v47 {@link MatrixStore#isNormal()} */ @Deprecated - public static boolean isNormal(final MatrixStore matrix) { + public static > boolean isNormal(final MatrixStore matrix) { return matrix.isNormal(); } @@ -287,8 +287,8 @@ public static final long limitOfRow(final Access1D matrix, final long row, fi * @deprecated v47 Use {@link org.ojalgo.matrix.store.PhysicalStore.Factory#makeSPD(int)} instead */ @Deprecated - public static PrimitiveDenseStore makeSPD(final int dim) { - return PrimitiveDenseStore.FACTORY.makeSPD(dim); + public static Primitive64Store makeSPD(final int dim) { + return Primitive64Store.FACTORY.makeSPD(dim); } /** @@ -343,11 +343,11 @@ public static Access2D wrapComplexAccess2D(final BasicMatrix wrapPrimitiveAccess2D(final BasicMatrix matrix) { - return MatrixStore.PRIMITIVE.makeWrapper(matrix).get(); + return MatrixStore.PRIMITIVE64.makeWrapper(matrix).get(); } private MatrixUtils() { diff --git a/src/org/ojalgo/matrix/PrimitiveMatrix.java b/src/org/ojalgo/matrix/Primitive32Matrix.java similarity index 73% rename from src/org/ojalgo/matrix/PrimitiveMatrix.java rename to src/org/ojalgo/matrix/Primitive32Matrix.java index 0b2274e81..7a86b655c 100644 --- a/src/org/ojalgo/matrix/PrimitiveMatrix.java +++ b/src/org/ojalgo/matrix/Primitive32Matrix.java @@ -30,7 +30,7 @@ import org.ojalgo.matrix.store.ElementsSupplier; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive32Store; import org.ojalgo.matrix.store.SparseStore; import org.ojalgo.matrix.task.DeterminantTask; import org.ojalgo.matrix.task.InverterTask; @@ -44,10 +44,10 @@ * * @author apete */ -public final class PrimitiveMatrix extends BasicMatrix { +public final class Primitive32Matrix extends BasicMatrix { public static final class DenseReceiver extends - MatrixFactory.DenseReceiver { + MatrixFactory.DenseReceiver { DenseReceiver(final Factory enclosing, final PhysicalStore delegate) { enclosing.super(delegate); @@ -55,32 +55,32 @@ public static final class DenseReceiver extends } - public static final class Factory - extends MatrixFactory { + public static final class Factory extends + MatrixFactory { Factory() { - super(PrimitiveMatrix.class, PrimitiveDenseStore.FACTORY); + super(Primitive32Matrix.class, Primitive32Store.FACTORY); } @Override - PrimitiveMatrix.LogicalBuilder logical(final MatrixStore delegate) { - return new PrimitiveMatrix.LogicalBuilder(this, delegate); + Primitive32Matrix.LogicalBuilder logical(final MatrixStore delegate) { + return new Primitive32Matrix.LogicalBuilder(this, delegate); } @Override - PrimitiveMatrix.DenseReceiver physical(final PhysicalStore delegate) { - return new PrimitiveMatrix.DenseReceiver(this, delegate); + Primitive32Matrix.DenseReceiver physical(final PhysicalStore delegate) { + return new Primitive32Matrix.DenseReceiver(this, delegate); } @Override - PrimitiveMatrix.SparseReceiver physical(final SparseStore delegate) { - return new PrimitiveMatrix.SparseReceiver(this, delegate); + Primitive32Matrix.SparseReceiver physical(final SparseStore delegate) { + return new Primitive32Matrix.SparseReceiver(this, delegate); } } public static final class LogicalBuilder extends - MatrixFactory.Logical { + MatrixFactory.Logical { LogicalBuilder(final Factory enclosing, final MatrixStore.LogicalBuilder delegate) { enclosing.super(delegate); @@ -98,7 +98,7 @@ LogicalBuilder self() { } public static final class SparseReceiver extends - MatrixFactory.SparseReceiver { + MatrixFactory.SparseReceiver { SparseReceiver(final Factory enclosing, final SparseStore delegate) { enclosing.super(delegate); @@ -111,31 +111,31 @@ public static final class SparseReceiver extends /** * This method is for internal use only - YOU should NOT use it! */ - PrimitiveMatrix(final MatrixStore aStore) { + Primitive32Matrix(final MatrixStore aStore) { super(aStore); } @Override - public PrimitiveMatrix.DenseReceiver copy() { - return new PrimitiveMatrix.DenseReceiver(FACTORY, this.getStore().copy()); + public Primitive32Matrix.DenseReceiver copy() { + return new Primitive32Matrix.DenseReceiver(FACTORY, this.getStore().copy()); } @Override - public PrimitiveMatrix.LogicalBuilder logical() { - return new PrimitiveMatrix.LogicalBuilder(FACTORY, this.getStore()); + public Primitive32Matrix.LogicalBuilder logical() { + return new Primitive32Matrix.LogicalBuilder(FACTORY, this.getStore()); } @SuppressWarnings("unchecked") @Override ElementsSupplier cast(final Access1D matrix) { - if (matrix instanceof PrimitiveMatrix) { + if (matrix instanceof Primitive32Matrix) { - return ((PrimitiveMatrix) matrix).getStore(); + return ((Primitive32Matrix) matrix).getStore(); - } else if (matrix instanceof PrimitiveDenseStore) { + } else if (matrix instanceof Primitive32Store) { - return (PrimitiveDenseStore) matrix; + return (Primitive32Store) matrix; } else if ((matrix instanceof ElementsSupplier) && (matrix.count() > 0L) && (matrix.get(0) instanceof Double)) { diff --git a/src/org/ojalgo/matrix/Primitive64Matrix.java b/src/org/ojalgo/matrix/Primitive64Matrix.java new file mode 100644 index 000000000..d0048c323 --- /dev/null +++ b/src/org/ojalgo/matrix/Primitive64Matrix.java @@ -0,0 +1,205 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.matrix; + +import org.ojalgo.matrix.decomposition.Cholesky; +import org.ojalgo.matrix.decomposition.Eigenvalue; +import org.ojalgo.matrix.decomposition.LDL; +import org.ojalgo.matrix.decomposition.LU; +import org.ojalgo.matrix.decomposition.QR; +import org.ojalgo.matrix.decomposition.SingularValue; +import org.ojalgo.matrix.store.ElementsSupplier; +import org.ojalgo.matrix.store.MatrixStore; +import org.ojalgo.matrix.store.PhysicalStore; +import org.ojalgo.matrix.store.Primitive64Store; +import org.ojalgo.matrix.store.SparseStore; +import org.ojalgo.matrix.task.DeterminantTask; +import org.ojalgo.matrix.task.InverterTask; +import org.ojalgo.matrix.task.SolverTask; +import org.ojalgo.structure.Access1D; +import org.ojalgo.structure.Access2D; +import org.ojalgo.structure.Structure2D; + +/** + * PrimitiveMatrix + * + * @author apete + */ +public final class Primitive64Matrix extends BasicMatrix { + + public static final class DenseReceiver extends + MatrixFactory.DenseReceiver { + + DenseReceiver(final Factory enclosing, final PhysicalStore delegate) { + enclosing.super(delegate); + } + + } + + public static final class Factory extends + MatrixFactory { + + Factory() { + super(Primitive64Matrix.class, Primitive64Store.FACTORY); + } + + @Override + Primitive64Matrix.LogicalBuilder logical(final MatrixStore delegate) { + return new Primitive64Matrix.LogicalBuilder(this, delegate); + } + + @Override + Primitive64Matrix.DenseReceiver physical(final PhysicalStore delegate) { + return new Primitive64Matrix.DenseReceiver(this, delegate); + } + + @Override + Primitive64Matrix.SparseReceiver physical(final SparseStore delegate) { + return new Primitive64Matrix.SparseReceiver(this, delegate); + } + + } + + public static final class LogicalBuilder extends + MatrixFactory.Logical { + + LogicalBuilder(final Factory enclosing, final MatrixStore.LogicalBuilder delegate) { + enclosing.super(delegate); + } + + LogicalBuilder(final Factory enclosing, final MatrixStore store) { + enclosing.super(store); + } + + @Override + LogicalBuilder self() { + return this; + } + + } + + public static final class SparseReceiver extends + MatrixFactory.SparseReceiver { + + SparseReceiver(final Factory enclosing, final SparseStore delegate) { + enclosing.super(delegate); + } + + } + + public static final Factory FACTORY = new Factory(); + + /** + * This method is for internal use only - YOU should NOT use it! + */ + Primitive64Matrix(final MatrixStore aStore) { + super(aStore); + } + + @Override + public Primitive64Matrix.DenseReceiver copy() { + return new Primitive64Matrix.DenseReceiver(FACTORY, this.getStore().copy()); + } + + @Override + public Primitive64Matrix.LogicalBuilder logical() { + return new Primitive64Matrix.LogicalBuilder(FACTORY, this.getStore()); + } + + @SuppressWarnings("unchecked") + @Override + ElementsSupplier cast(final Access1D matrix) { + + if (matrix instanceof Primitive64Matrix) { + + return ((Primitive64Matrix) matrix).getStore(); + + } else if (matrix instanceof Primitive64Store) { + + return (Primitive64Store) matrix; + + } else if ((matrix instanceof ElementsSupplier) && (matrix.count() > 0L) && (matrix.get(0) instanceof Double)) { + + return (ElementsSupplier) matrix; + + } else if (matrix instanceof Access2D) { + + final Access2D tmpAccess2D = (Access2D) matrix; + return this.getStore().physical().builder().makeWrapper(tmpAccess2D); + + } else { + + return this.getStore().physical().columns(matrix); + } + } + + @Override + Cholesky getDecompositionCholesky(final Structure2D typical) { + return Cholesky.PRIMITIVE.make(typical); + } + + @Override + Eigenvalue getDecompositionEigenvalue(final Structure2D typical) { + return Eigenvalue.PRIMITIVE.make(typical, this.isHermitian()); + } + + @Override + LDL getDecompositionLDL(final Structure2D typical) { + return LDL.PRIMITIVE.make(typical); + } + + @Override + LU getDecompositionLU(final Structure2D typical) { + return LU.PRIMITIVE.make(typical); + } + + @Override + QR getDecompositionQR(final Structure2D typical) { + return QR.PRIMITIVE.make(typical); + } + + @Override + SingularValue getDecompositionSingularValue(final Structure2D typical) { + return SingularValue.PRIMITIVE.make(typical); + } + + @Override + Factory getFactory() { + return FACTORY; + } + + @Override + DeterminantTask getTaskDeterminant(final MatrixStore template) { + return DeterminantTask.PRIMITIVE.make(template, this.isHermitian(), false); + } + + @Override + InverterTask getTaskInverter(final MatrixStore base) { + return InverterTask.PRIMITIVE.make(base, this.isHermitian(), false); + } + + @Override + SolverTask getTaskSolver(final MatrixStore templateBody, final Access2D templateRHS) { + return SolverTask.PRIMITIVE.make(templateBody, templateRHS, this.isHermitian(), false); + } + +} diff --git a/src/org/ojalgo/matrix/QuaternionMatrix.java b/src/org/ojalgo/matrix/QuaternionMatrix.java index 8cc05c708..758e9a659 100644 --- a/src/org/ojalgo/matrix/QuaternionMatrix.java +++ b/src/org/ojalgo/matrix/QuaternionMatrix.java @@ -28,7 +28,7 @@ import org.ojalgo.matrix.decomposition.QR; import org.ojalgo.matrix.decomposition.SingularValue; import org.ojalgo.matrix.store.ElementsSupplier; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.SparseStore; @@ -60,7 +60,7 @@ public static final class Factory extends MatrixFactory { Factory() { - super(QuaternionMatrix.class, GenericDenseStore.QUATERNION); + super(QuaternionMatrix.class, GenericStore.QUATERNION); } @Override diff --git a/src/org/ojalgo/matrix/RationalMatrix.java b/src/org/ojalgo/matrix/RationalMatrix.java index 67ec1e448..4191336b6 100644 --- a/src/org/ojalgo/matrix/RationalMatrix.java +++ b/src/org/ojalgo/matrix/RationalMatrix.java @@ -28,7 +28,7 @@ import org.ojalgo.matrix.decomposition.QR; import org.ojalgo.matrix.decomposition.SingularValue; import org.ojalgo.matrix.store.ElementsSupplier; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.SparseStore; @@ -60,7 +60,7 @@ public static final class Factory extends MatrixFactory { Factory() { - super(RationalMatrix.class, GenericDenseStore.RATIONAL); + super(RationalMatrix.class, GenericStore.RATIONAL); } @Override diff --git a/src/org/ojalgo/matrix/decomposition/AbstractDecomposition.java b/src/org/ojalgo/matrix/decomposition/AbstractDecomposition.java index ae173be19..44a38c8f7 100644 --- a/src/org/ojalgo/matrix/decomposition/AbstractDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/AbstractDecomposition.java @@ -30,7 +30,7 @@ /** * @author apete */ -abstract class AbstractDecomposition implements MatrixDecomposition { +abstract class AbstractDecomposition> implements MatrixDecomposition { private boolean myComputed = false; private Boolean mySolvable = null; diff --git a/src/org/ojalgo/matrix/decomposition/Bidiagonal.java b/src/org/ojalgo/matrix/decomposition/Bidiagonal.java index a57dcd039..ef4261be3 100644 --- a/src/org/ojalgo/matrix/decomposition/Bidiagonal.java +++ b/src/org/ojalgo/matrix/decomposition/Bidiagonal.java @@ -42,9 +42,9 @@ * * @author apete */ -public interface Bidiagonal extends MatrixDecomposition, MatrixDecomposition.EconomySize { +public interface Bidiagonal> extends MatrixDecomposition, MatrixDecomposition.EconomySize { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { default Bidiagonal make(final boolean fullSize) { return this.make(TYPICAL, fullSize); @@ -66,7 +66,7 @@ default Bidiagonal make(final Structure2D typical) { Factory RATIONAL = (typical, fullSize) -> new BidiagonalDecomposition.Rational(fullSize); - static boolean equals(final MatrixStore matrix, final Bidiagonal decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final Bidiagonal decomposition, final NumberContext context) { final int tmpRowDim = (int) matrix.countRows(); final int tmpColDim = (int) matrix.countColumns(); @@ -119,7 +119,7 @@ static boolean equals(final MatrixStore matrix, final Bidi */ @Deprecated @SuppressWarnings("unchecked") - static Bidiagonal make(final Access2D typical) { + static > Bidiagonal make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -140,7 +140,7 @@ static Bidiagonal make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final Bidiagonal decomposition) { + static > MatrixStore reconstruct(final Bidiagonal decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/BidiagonalDecomposition.java b/src/org/ojalgo/matrix/decomposition/BidiagonalDecomposition.java index 6e35b21ef..452233d03 100644 --- a/src/org/ojalgo/matrix/decomposition/BidiagonalDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/BidiagonalDecomposition.java @@ -24,10 +24,10 @@ import org.ojalgo.array.Array1D; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.store.DiagonalStore; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.transformation.Householder; import org.ojalgo.matrix.transformation.HouseholderReference; import org.ojalgo.scalar.ComplexNumber; @@ -36,7 +36,7 @@ import org.ojalgo.scalar.RationalNumber; import org.ojalgo.structure.Access2D; -abstract class BidiagonalDecomposition extends InPlaceDecomposition implements Bidiagonal { +abstract class BidiagonalDecomposition> extends InPlaceDecomposition implements Bidiagonal { static final class Complex extends BidiagonalDecomposition { @@ -45,7 +45,7 @@ static final class Complex extends BidiagonalDecomposition { } Complex(final boolean fullSize) { - super(GenericDenseStore.COMPLEX, fullSize); + super(GenericStore.COMPLEX, fullSize); } @Override @@ -133,7 +133,7 @@ static final class Primitive extends BidiagonalDecomposition { } Primitive(final boolean fullSize) { - super(PrimitiveDenseStore.FACTORY, fullSize); + super(Primitive64Store.FACTORY, fullSize); } @Override @@ -150,7 +150,7 @@ static final class Quat extends BidiagonalDecomposition { } Quat(final boolean fullSize) { - super(GenericDenseStore.QUATERNION, fullSize); + super(GenericStore.QUATERNION, fullSize); } @Override @@ -168,7 +168,7 @@ static final class Rational extends BidiagonalDecomposition { } Rational(final boolean fullSize) { - super(GenericDenseStore.RATIONAL, fullSize); + super(GenericStore.RATIONAL, fullSize); } @Override diff --git a/src/org/ojalgo/matrix/decomposition/Cholesky.java b/src/org/ojalgo/matrix/decomposition/Cholesky.java index 6970ab701..06f7586e5 100644 --- a/src/org/ojalgo/matrix/decomposition/Cholesky.java +++ b/src/org/ojalgo/matrix/decomposition/Cholesky.java @@ -47,9 +47,9 @@ * * @author apete */ -public interface Cholesky extends LDU, MatrixDecomposition.Hermitian { +public interface Cholesky> extends LDU, MatrixDecomposition.Hermitian { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { } @@ -67,7 +67,7 @@ interface Factory extends MatrixDecomposition.Factory RATIONAL = typical -> new CholeskyDecomposition.Rational(); - static boolean equals(final MatrixStore matrix, final Cholesky decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final Cholesky decomposition, final NumberContext context) { boolean retVal = false; @@ -84,7 +84,7 @@ static boolean equals(final MatrixStore matrix, final Chol */ @Deprecated @SuppressWarnings("unchecked") - static Cholesky make(final Access2D typical) { + static > Cholesky make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -105,7 +105,7 @@ static Cholesky make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final Cholesky decomposition) { + static > MatrixStore reconstruct(final Cholesky decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/CholeskyDecomposition.java b/src/org/ojalgo/matrix/decomposition/CholeskyDecomposition.java index 272ac23c7..f60670ef1 100644 --- a/src/org/ojalgo/matrix/decomposition/CholeskyDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/CholeskyDecomposition.java @@ -29,10 +29,10 @@ import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.MatrixUtils; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; import org.ojalgo.scalar.RationalNumber; @@ -40,12 +40,12 @@ import org.ojalgo.structure.Access2D.Collectable; import org.ojalgo.structure.Structure2D; -abstract class CholeskyDecomposition extends InPlaceDecomposition implements Cholesky { +abstract class CholeskyDecomposition> extends InPlaceDecomposition implements Cholesky { static final class Complex extends CholeskyDecomposition { Complex() { - super(GenericDenseStore.COMPLEX); + super(GenericStore.COMPLEX); } } @@ -53,7 +53,7 @@ static final class Complex extends CholeskyDecomposition { static final class Primitive extends CholeskyDecomposition { Primitive() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } } @@ -61,7 +61,7 @@ static final class Primitive extends CholeskyDecomposition { static final class Quat extends CholeskyDecomposition { Quat() { - super(GenericDenseStore.QUATERNION); + super(GenericStore.QUATERNION); } } @@ -69,7 +69,7 @@ static final class Quat extends CholeskyDecomposition { static final class Rational extends CholeskyDecomposition { Rational() { - super(GenericDenseStore.RATIONAL); + super(GenericStore.RATIONAL); } } diff --git a/src/org/ojalgo/matrix/decomposition/DecompositionStore.java b/src/org/ojalgo/matrix/decomposition/DecompositionStore.java index 9f42a3134..16adafb43 100644 --- a/src/org/ojalgo/matrix/decomposition/DecompositionStore.java +++ b/src/org/ojalgo/matrix/decomposition/DecompositionStore.java @@ -42,7 +42,7 @@ * * @author apete */ -public interface DecompositionStore extends PhysicalStore, RotateRight, ExchangeColumns, NegateColumn { +public interface DecompositionStore> extends PhysicalStore, RotateRight, ExchangeColumns, NegateColumn { /** * Cholesky transformations diff --git a/src/org/ojalgo/matrix/decomposition/DeferredTridiagonal.java b/src/org/ojalgo/matrix/decomposition/DeferredTridiagonal.java index b3c22f501..e431d7746 100644 --- a/src/org/ojalgo/matrix/decomposition/DeferredTridiagonal.java +++ b/src/org/ojalgo/matrix/decomposition/DeferredTridiagonal.java @@ -24,11 +24,11 @@ import org.ojalgo.array.Array1D; import org.ojalgo.array.BasicArray; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.MatrixStore.LogicalBuilder; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.transformation.Householder; import org.ojalgo.matrix.transformation.HouseholderReference; import org.ojalgo.netio.BasicLogger; @@ -40,12 +40,12 @@ /** * @author apete */ -abstract class DeferredTridiagonal extends TridiagonalDecomposition { +abstract class DeferredTridiagonal> extends TridiagonalDecomposition { static final class Complex extends DeferredTridiagonal { Complex() { - super(GenericDenseStore.COMPLEX); + super(GenericStore.COMPLEX); } @Override @@ -81,7 +81,7 @@ Array1D makeReal(final BasicArray offDiagonal) { static final class Primitive extends DeferredTridiagonal { Primitive() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } @Override @@ -94,7 +94,7 @@ Array1D makeReal(final BasicArray offDiagonal) { static final class Quat extends DeferredTridiagonal { Quat() { - super(GenericDenseStore.QUATERNION); + super(GenericStore.QUATERNION); } @Override @@ -130,7 +130,7 @@ Array1D makeReal(final BasicArray offDiagonal) { static final class Rational extends DeferredTridiagonal { Rational() { - super(GenericDenseStore.RATIONAL); + super(GenericStore.RATIONAL); } @Override diff --git a/src/org/ojalgo/matrix/decomposition/DynamicEvD.java b/src/org/ojalgo/matrix/decomposition/DynamicEvD.java index bdcd87397..668bd8c27 100644 --- a/src/org/ojalgo/matrix/decomposition/DynamicEvD.java +++ b/src/org/ojalgo/matrix/decomposition/DynamicEvD.java @@ -25,16 +25,16 @@ import org.ojalgo.array.Array1D; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.structure.Access2D.Collectable; -abstract class DynamicEvD extends EigenvalueDecomposition { +abstract class DynamicEvD> extends EigenvalueDecomposition { static final class Primitive extends DynamicEvD { Primitive() { - super(PrimitiveDenseStore.FACTORY, new HermitianEvD.Primitive(), new GeneralEvD.Primitive()); + super(Primitive64Store.FACTORY, new HermitianEvD.Primitive(), new GeneralEvD.Primitive()); } } diff --git a/src/org/ojalgo/matrix/decomposition/Eigenvalue.java b/src/org/ojalgo/matrix/decomposition/Eigenvalue.java index 5479cd9e9..0a3ac437b 100644 --- a/src/org/ojalgo/matrix/decomposition/Eigenvalue.java +++ b/src/org/ojalgo/matrix/decomposition/Eigenvalue.java @@ -27,10 +27,10 @@ import org.ojalgo.array.Array1D; import org.ojalgo.array.DenseArray; import org.ojalgo.matrix.MatrixUtils; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; import org.ojalgo.scalar.RationalNumber; @@ -61,7 +61,7 @@ * * @author apete */ -public interface Eigenvalue +public interface Eigenvalue> extends MatrixDecomposition, MatrixDecomposition.Hermitian, MatrixDecomposition.Determinant, MatrixDecomposition.Values { public static class Eigenpair implements Comparable { @@ -119,7 +119,7 @@ public int hashCode() { } - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { default Eigenvalue make(final boolean hermitian) { return this.make(TYPICAL, hermitian); @@ -191,7 +191,7 @@ enum Generalisation { } - interface Generalised extends Eigenvalue { + interface Generalised> extends Eigenvalue { default boolean computeValuesOnly(final Access2D.Collectable> matrixA, final Access2D.Collectable> matrixB) { @@ -217,7 +217,7 @@ public Eigenvalue make(final Structure2D typical, final boolean h @Override public Eigenvalue.Generalised makeGeneralised(final Structure2D typical, final Eigenvalue.Generalisation type) { - PhysicalStore.Factory> factory = GenericDenseStore.COMPLEX; + PhysicalStore.Factory> factory = GenericStore.COMPLEX; Cholesky cholesky = Cholesky.COMPLEX.make(typical); Eigenvalue eigenvalue = this.make(typical, true); @@ -257,7 +257,7 @@ public Eigenvalue make(final Structure2D typical, final boolean hermitia @Override public Eigenvalue.Generalised makeGeneralised(final Structure2D typical, final Eigenvalue.Generalisation type) { - PhysicalStore.Factory factory = PrimitiveDenseStore.FACTORY; + PhysicalStore.Factory factory = Primitive64Store.FACTORY; Cholesky cholesky = Cholesky.PRIMITIVE.make(typical); Eigenvalue eigenvalue = this.make(typical, true); @@ -276,7 +276,7 @@ public Eigenvalue make(final Structure2D typical, final boolean herm @Override public Eigenvalue.Generalised makeGeneralised(final Structure2D typical, final Eigenvalue.Generalisation type) { - PhysicalStore.Factory> factory = GenericDenseStore.QUATERNION; + PhysicalStore.Factory> factory = GenericStore.QUATERNION; Cholesky cholesky = Cholesky.QUATERNION.make(typical); Eigenvalue eigenvalue = this.make(typical, true); @@ -295,7 +295,7 @@ public Eigenvalue make(final Structure2D typical, final boolean @Override public Eigenvalue.Generalised makeGeneralised(final Structure2D typical, final Eigenvalue.Generalisation type) { - PhysicalStore.Factory> factory = GenericDenseStore.RATIONAL; + PhysicalStore.Factory> factory = GenericStore.RATIONAL; Cholesky cholesky = Cholesky.RATIONAL.make(typical); Eigenvalue eigenvalue = this.make(typical, true); @@ -304,7 +304,7 @@ public Eigenvalue.Generalised makeGeneralised(final Structure2D }; - static boolean equals(final MatrixStore matrix, final Eigenvalue decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final Eigenvalue decomposition, final NumberContext context) { final MatrixStore tmpD = decomposition.getD(); final MatrixStore tmpV = decomposition.getV(); @@ -322,7 +322,7 @@ static boolean equals(final MatrixStore matrix, final Eige */ @Deprecated @SuppressWarnings("unchecked") - static Eigenvalue make(final Access2D typical) { + static > Eigenvalue make(final Access2D typical) { return Eigenvalue.make(typical, MatrixUtils.isHermitian(typical)); } @@ -332,7 +332,7 @@ static Eigenvalue make(final Access2D typical) { */ @Deprecated @SuppressWarnings("unchecked") - static Eigenvalue make(final Access2D typical, final boolean hermitian) { + static > Eigenvalue make(final Access2D typical, final boolean hermitian) { final N tmpNumber = typical.get(0L, 0L); @@ -353,7 +353,7 @@ static Eigenvalue make(final Access2D typical, final bo * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final Eigenvalue decomposition) { + static > MatrixStore reconstruct(final Eigenvalue decomposition) { return decomposition.reconstruct(); } @@ -461,7 +461,7 @@ default MatrixStore getEigenvectors() { final long tmpDimension = this.getV().countColumns(); - final GenericDenseStore retVal = GenericDenseStore.COMPLEX.makeZero(tmpDimension, tmpDimension); + final GenericStore retVal = GenericStore.COMPLEX.makeZero(tmpDimension, tmpDimension); for (int j = 0; j < tmpDimension; j++) { this.copyEigenvector(j, retVal.sliceColumn(0, j)); diff --git a/src/org/ojalgo/matrix/decomposition/EigenvalueDecomposition.java b/src/org/ojalgo/matrix/decomposition/EigenvalueDecomposition.java index fe3e0582c..e4728cc7d 100644 --- a/src/org/ojalgo/matrix/decomposition/EigenvalueDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/EigenvalueDecomposition.java @@ -30,7 +30,7 @@ import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Access2D.Collectable; -abstract class EigenvalueDecomposition extends GenericDecomposition implements Eigenvalue { +abstract class EigenvalueDecomposition> extends GenericDecomposition implements Eigenvalue { /** * Sort eigenvalues and corresponding vectors. diff --git a/src/org/ojalgo/matrix/decomposition/GeneralEvD.java b/src/org/ojalgo/matrix/decomposition/GeneralEvD.java index 42ee6affe..61f8cc2a3 100644 --- a/src/org/ojalgo/matrix/decomposition/GeneralEvD.java +++ b/src/org/ojalgo/matrix/decomposition/GeneralEvD.java @@ -29,11 +29,11 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.structure.Access2D.Collectable; -abstract class GeneralEvD extends EigenvalueDecomposition { +abstract class GeneralEvD> extends EigenvalueDecomposition { /** * Eigenvalues and eigenvectors of a real matrix. @@ -51,7 +51,7 @@ abstract class GeneralEvD extends EigenvalueDecomposition { static final class Primitive extends GeneralEvD { Primitive() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } } diff --git a/src/org/ojalgo/matrix/decomposition/GeneralisedEvD.java b/src/org/ojalgo/matrix/decomposition/GeneralisedEvD.java index d229cffd3..10284e4e3 100644 --- a/src/org/ojalgo/matrix/decomposition/GeneralisedEvD.java +++ b/src/org/ojalgo/matrix/decomposition/GeneralisedEvD.java @@ -28,7 +28,7 @@ import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Access2D.Collectable; -final class GeneralisedEvD extends EigenvalueDecomposition implements Eigenvalue.Generalised { +final class GeneralisedEvD> extends EigenvalueDecomposition implements Eigenvalue.Generalised { private final Cholesky myCholesky; private final Eigenvalue myEigenvalue; diff --git a/src/org/ojalgo/matrix/decomposition/GenericDecomposition.java b/src/org/ojalgo/matrix/decomposition/GenericDecomposition.java index 77195d725..18e22696d 100644 --- a/src/org/ojalgo/matrix/decomposition/GenericDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/GenericDecomposition.java @@ -39,7 +39,7 @@ * * @author apete */ -abstract class GenericDecomposition extends AbstractDecomposition { +abstract class GenericDecomposition> extends AbstractDecomposition { private final MatrixStore.Factory myBuilder; private final PhysicalStore.Factory> myFactory; diff --git a/src/org/ojalgo/matrix/decomposition/HermitianEvD.java b/src/org/ojalgo/matrix/decomposition/HermitianEvD.java index 9c98b82a6..6b5921826 100644 --- a/src/org/ojalgo/matrix/decomposition/HermitianEvD.java +++ b/src/org/ojalgo/matrix/decomposition/HermitianEvD.java @@ -35,10 +35,10 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.decomposition.function.ExchangeColumns; import org.ojalgo.matrix.decomposition.function.RotateRight; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; import org.ojalgo.scalar.RationalNumber; @@ -59,12 +59,12 @@ * V may be badly conditioned, or even singular, so the validity of the equation A = V*D*inverse(V) depends * upon V.cond(). **/ -public abstract class HermitianEvD extends EigenvalueDecomposition implements MatrixDecomposition.Solver { +public abstract class HermitianEvD> extends EigenvalueDecomposition implements MatrixDecomposition.Solver { static final class Complex extends HermitianEvD { Complex() { - super(GenericDenseStore.COMPLEX, new DeferredTridiagonal.Complex()); + super(GenericStore.COMPLEX, new DeferredTridiagonal.Complex()); } } @@ -72,7 +72,7 @@ static final class Complex extends HermitianEvD { static final class Quat extends HermitianEvD { Quat() { - super(GenericDenseStore.QUATERNION, new DeferredTridiagonal.Quat()); + super(GenericStore.QUATERNION, new DeferredTridiagonal.Quat()); } } @@ -80,7 +80,7 @@ static final class Quat extends HermitianEvD { static final class Rational extends HermitianEvD { Rational() { - super(GenericDenseStore.RATIONAL, new DeferredTridiagonal.Rational()); + super(GenericStore.RATIONAL, new DeferredTridiagonal.Rational()); } } @@ -88,7 +88,7 @@ static final class Rational extends HermitianEvD { static final class Primitive extends HermitianEvD { Primitive() { - super(PrimitiveDenseStore.FACTORY, new SimultaneousTridiagonal()); + super(Primitive64Store.FACTORY, new SimultaneousTridiagonal()); } } diff --git a/src/org/ojalgo/matrix/decomposition/Hessenberg.java b/src/org/ojalgo/matrix/decomposition/Hessenberg.java index 4424e4e38..41fcb3874 100644 --- a/src/org/ojalgo/matrix/decomposition/Hessenberg.java +++ b/src/org/ojalgo/matrix/decomposition/Hessenberg.java @@ -39,9 +39,9 @@ * * @author apete */ -public interface Hessenberg extends MatrixDecomposition { +public interface Hessenberg> extends MatrixDecomposition { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { } @@ -53,7 +53,7 @@ interface Factory extends MatrixDecomposition.Factory RATIONAL = typical -> new HessenbergDecomposition.Rational(); - static boolean equals(final MatrixStore matrix, final Hessenberg decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final Hessenberg decomposition, final NumberContext context) { final MatrixStore tmpH = decomposition.getH(); final MatrixStore tmpQ = decomposition.getQ(); @@ -70,7 +70,7 @@ static boolean equals(final MatrixStore matrix, final Hess */ @Deprecated @SuppressWarnings("unchecked") - static Hessenberg make(final Access2D typical) { + static > Hessenberg make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -91,7 +91,7 @@ static Hessenberg make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final Hessenberg decomposition) { + static > MatrixStore reconstruct(final Hessenberg decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/HessenbergDecomposition.java b/src/org/ojalgo/matrix/decomposition/HessenbergDecomposition.java index 45aa6d567..58e5a208d 100644 --- a/src/org/ojalgo/matrix/decomposition/HessenbergDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/HessenbergDecomposition.java @@ -21,10 +21,10 @@ */ package org.ojalgo.matrix.decomposition; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.transformation.Householder; import org.ojalgo.matrix.transformation.HouseholderReference; import org.ojalgo.scalar.ComplexNumber; @@ -32,12 +32,12 @@ import org.ojalgo.scalar.RationalNumber; import org.ojalgo.structure.Access2D; -abstract class HessenbergDecomposition extends InPlaceDecomposition implements Hessenberg { +abstract class HessenbergDecomposition> extends InPlaceDecomposition implements Hessenberg { static final class Complex extends HessenbergDecomposition { Complex() { - super(GenericDenseStore.COMPLEX); + super(GenericStore.COMPLEX); } } @@ -45,7 +45,7 @@ static final class Complex extends HessenbergDecomposition { static final class Primitive extends HessenbergDecomposition { Primitive() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } } @@ -53,7 +53,7 @@ static final class Primitive extends HessenbergDecomposition { static final class Quat extends HessenbergDecomposition { Quat() { - super(GenericDenseStore.QUATERNION); + super(GenericStore.QUATERNION); } } @@ -61,7 +61,7 @@ static final class Quat extends HessenbergDecomposition { static final class Rational extends HessenbergDecomposition { Rational() { - super(GenericDenseStore.RATIONAL); + super(GenericStore.RATIONAL); } } diff --git a/src/org/ojalgo/matrix/decomposition/InPlaceDecomposition.java b/src/org/ojalgo/matrix/decomposition/InPlaceDecomposition.java index a8cbdb908..4dada551e 100644 --- a/src/org/ojalgo/matrix/decomposition/InPlaceDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/InPlaceDecomposition.java @@ -26,7 +26,7 @@ import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.structure.Access2D; -abstract class InPlaceDecomposition extends GenericDecomposition { +abstract class InPlaceDecomposition> extends GenericDecomposition { private int myColDim; private DecompositionStore myInPlace; diff --git a/src/org/ojalgo/matrix/decomposition/LDL.java b/src/org/ojalgo/matrix/decomposition/LDL.java index 70b65b470..184684434 100644 --- a/src/org/ojalgo/matrix/decomposition/LDL.java +++ b/src/org/ojalgo/matrix/decomposition/LDL.java @@ -48,9 +48,9 @@ * * @author apete */ -public interface LDL extends LDU, MatrixDecomposition.Hermitian, MatrixDecomposition.Pivoting { +public interface LDL> extends LDU, MatrixDecomposition.Hermitian, MatrixDecomposition.Pivoting { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { } @@ -62,7 +62,7 @@ interface Factory extends MatrixDecomposition.Factory> Factory RATIONAL = typical -> new LDLDecomposition.Rational(); - static boolean equals(final MatrixStore matrix, final LDL decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final LDL decomposition, final NumberContext context) { return Access2D.equals(matrix, decomposition.reconstruct(), context); } @@ -72,7 +72,7 @@ static boolean equals(final MatrixStore matrix, final LDL< */ @Deprecated @SuppressWarnings("unchecked") - static LDL make(final Access2D typical) { + static > LDL make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -93,7 +93,7 @@ static LDL make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final LDL decomposition) { + static > MatrixStore reconstruct(final LDL decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/LDLDecomposition.java b/src/org/ojalgo/matrix/decomposition/LDLDecomposition.java index 503070697..6a391ba27 100644 --- a/src/org/ojalgo/matrix/decomposition/LDLDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/LDLDecomposition.java @@ -29,25 +29,26 @@ import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.MatrixStore.LogicalBuilder; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; import org.ojalgo.scalar.RationalNumber; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Access2D.Collectable; import org.ojalgo.structure.Structure2D; import org.ojalgo.type.context.NumberContext; -abstract class LDLDecomposition extends InPlaceDecomposition implements LDL { +abstract class LDLDecomposition> extends InPlaceDecomposition implements LDL { static class Complex extends LDLDecomposition { Complex() { - super(GenericDenseStore.COMPLEX); + super(GenericStore.COMPLEX); } } @@ -55,7 +56,7 @@ static class Complex extends LDLDecomposition { static class Primitive extends LDLDecomposition { Primitive() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } } @@ -63,7 +64,7 @@ static class Primitive extends LDLDecomposition { static class Quat extends LDLDecomposition { Quat() { - super(GenericDenseStore.QUATERNION); + super(GenericStore.QUATERNION); } } @@ -71,7 +72,7 @@ static class Quat extends LDLDecomposition { static class Rational extends LDLDecomposition { Rational() { - super(GenericDenseStore.RATIONAL); + super(GenericStore.RATIONAL); } } @@ -169,7 +170,7 @@ public double getRankThreshold() { N largest = this.getInPlace().aggregateDiagonal(Aggregator.LARGEST); double epsilon = this.getDimensionalEpsilon(); - return epsilon * Math.max(MACHINE_SMALLEST, largest.doubleValue()); + return epsilon * Math.max(MACHINE_SMALLEST, Scalar.doubleValue(largest)); } public MatrixStore getSolution(final Collectable> rhs) { diff --git a/src/org/ojalgo/matrix/decomposition/LDU.java b/src/org/ojalgo/matrix/decomposition/LDU.java index d4569ef16..d22c602ec 100644 --- a/src/org/ojalgo/matrix/decomposition/LDU.java +++ b/src/org/ojalgo/matrix/decomposition/LDU.java @@ -63,7 +63,7 @@ * * @author apete */ -public interface LDU +public interface LDU> extends MatrixDecomposition, MatrixDecomposition.Solver, MatrixDecomposition.Determinant, MatrixDecomposition.RankRevealing { default boolean isOrdered() { diff --git a/src/org/ojalgo/matrix/decomposition/LU.java b/src/org/ojalgo/matrix/decomposition/LU.java index f39474df1..1b1d07ff1 100644 --- a/src/org/ojalgo/matrix/decomposition/LU.java +++ b/src/org/ojalgo/matrix/decomposition/LU.java @@ -52,9 +52,9 @@ * * @author apete */ -public interface LU extends LDU, MatrixDecomposition.Pivoting { +public interface LU> extends LDU, MatrixDecomposition.Pivoting { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { } @@ -73,7 +73,7 @@ interface Factory extends MatrixDecomposition.Factory> { Factory RATIONAL = typical -> new LUDecomposition.Rational(); - static boolean equals(final MatrixStore matrix, final LU decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final LU decomposition, final NumberContext context) { final MatrixStore tmpL = decomposition.getL(); final MatrixStore tmpU = decomposition.getU(); @@ -88,7 +88,7 @@ static boolean equals(final MatrixStore matrix, final LU LU make(final Access2D typical) { + static > LU make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -109,7 +109,7 @@ static LU make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final LU decomposition) { + static > MatrixStore reconstruct(final LU decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/LUDecomposition.java b/src/org/ojalgo/matrix/decomposition/LUDecomposition.java index b741243e6..284bff495 100644 --- a/src/org/ojalgo/matrix/decomposition/LUDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/LUDecomposition.java @@ -28,24 +28,25 @@ import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; import org.ojalgo.scalar.RationalNumber; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Access2D.Collectable; import org.ojalgo.structure.Structure2D; import org.ojalgo.type.context.NumberContext; -abstract class LUDecomposition extends InPlaceDecomposition implements LU { +abstract class LUDecomposition> extends InPlaceDecomposition implements LU { static final class Complex extends LUDecomposition { Complex() { - super(GenericDenseStore.COMPLEX); + super(GenericStore.COMPLEX); } } @@ -53,7 +54,7 @@ static final class Complex extends LUDecomposition { static final class Primitive extends LUDecomposition { Primitive() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } } @@ -61,7 +62,7 @@ static final class Primitive extends LUDecomposition { static final class Quat extends LUDecomposition { Quat() { - super(GenericDenseStore.QUATERNION); + super(GenericStore.QUATERNION); } } @@ -69,7 +70,7 @@ static final class Quat extends LUDecomposition { static final class Rational extends LUDecomposition { Rational() { - super(GenericDenseStore.RATIONAL); + super(GenericStore.RATIONAL); } } @@ -154,7 +155,7 @@ public double getRankThreshold() { N largest = this.getInPlace().aggregateDiagonal(Aggregator.LARGEST); double epsilon = this.getDimensionalEpsilon(); - return epsilon * Math.max(MACHINE_SMALLEST, largest.doubleValue()); + return epsilon * Math.max(MACHINE_SMALLEST, Scalar.doubleValue(largest)); } public final MatrixStore getSolution(final Collectable> rhs) { diff --git a/src/org/ojalgo/matrix/decomposition/MatrixDecomposition.java b/src/org/ojalgo/matrix/decomposition/MatrixDecomposition.java index 2105052d1..75f377088 100644 --- a/src/org/ojalgo/matrix/decomposition/MatrixDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/MatrixDecomposition.java @@ -56,9 +56,9 @@ * * @author apete */ -public interface MatrixDecomposition extends Structure2D { +public interface MatrixDecomposition> extends Structure2D { - interface Determinant extends MatrixDecomposition, DeterminantTask { + interface Determinant> extends MatrixDecomposition, DeterminantTask { /** *

@@ -79,7 +79,7 @@ interface Determinant extends MatrixDecomposition, Determin * * @author apete */ - interface EconomySize extends MatrixDecomposition { + interface EconomySize> extends MatrixDecomposition { /** * @return True if it will generate a full sized decomposition. @@ -117,7 +117,7 @@ public long countRows() { * * @author apete */ - public interface Hermitian extends MatrixDecomposition { + public interface Hermitian> extends MatrixDecomposition { /** * Absolutely must check if the matrix is hermitian or not. Then, depending on the result differents @@ -151,7 +151,7 @@ default boolean checkAndDecompose(final MatrixStore matrix) { } } - interface Ordered extends MatrixDecomposition { + interface Ordered> extends MatrixDecomposition { /** * This is a property of the algorithm/implementation, not the data. Typically relevant for @@ -187,7 +187,7 @@ interface Ordered extends MatrixDecomposition { * * @author apete */ - interface Pivoting extends MatrixDecomposition { + interface Pivoting> extends MatrixDecomposition { /** * The normal {@link #decompose(Access2D.Collectable)} method must handle cases where pivoting is @@ -230,7 +230,7 @@ default boolean decomposeWithoutPivoting(final Access2D.Collectable */ - interface RankRevealing extends Ordered { + interface RankRevealing> extends Ordered { /** * @param threshold Significance limit @@ -259,7 +259,7 @@ default boolean isFullRank() { } - interface Solver extends MatrixDecomposition, SolverTask, InverterTask { + interface Solver> extends MatrixDecomposition, SolverTask, InverterTask { /** * @param matrix A matrix to decompose @@ -340,7 +340,7 @@ default boolean compute(final Collectable> matrix) { * * @author apete */ - interface Values extends Ordered { + interface Values> extends Ordered { /** * @param matrix The matrix to decompose diff --git a/src/org/ojalgo/matrix/decomposition/QR.java b/src/org/ojalgo/matrix/decomposition/QR.java index 1b37e9448..1980bdb3f 100644 --- a/src/org/ojalgo/matrix/decomposition/QR.java +++ b/src/org/ojalgo/matrix/decomposition/QR.java @@ -51,10 +51,10 @@ * * @author apete */ -public interface QR extends MatrixDecomposition, MatrixDecomposition.Solver, MatrixDecomposition.EconomySize, +public interface QR> extends MatrixDecomposition, MatrixDecomposition.Solver, MatrixDecomposition.EconomySize, MatrixDecomposition.Determinant, MatrixDecomposition.RankRevealing { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { default QR make(final boolean fullSize) { return this.make(TYPICAL, fullSize); @@ -82,7 +82,7 @@ default QR make(final Structure2D typical) { Factory RATIONAL = (typical, fullSize) -> new QRDecomposition.Rational(fullSize); - static boolean equals(final MatrixStore matrix, final QR decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final QR decomposition, final NumberContext context) { final MatrixStore tmpQ = decomposition.getQ(); final MatrixStore tmpR = decomposition.getR(); @@ -98,7 +98,7 @@ static boolean equals(final MatrixStore matrix, final QR QR make(final Access2D typical) { + static > QR make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -119,7 +119,7 @@ static QR make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final QR decomposition) { + static > MatrixStore reconstruct(final QR decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/QRDecomposition.java b/src/org/ojalgo/matrix/decomposition/QRDecomposition.java index ea8a5a093..a004b2c56 100644 --- a/src/org/ojalgo/matrix/decomposition/QRDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/QRDecomposition.java @@ -26,20 +26,21 @@ import org.ojalgo.RecoverableCondition; import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.function.aggregator.AggregatorFunction; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.transformation.Householder; import org.ojalgo.matrix.transformation.HouseholderReference; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; import org.ojalgo.scalar.RationalNumber; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Access2D.Collectable; import org.ojalgo.structure.Structure2D; -abstract class QRDecomposition extends InPlaceDecomposition implements QR { +abstract class QRDecomposition> extends InPlaceDecomposition implements QR { static final class Complex extends QRDecomposition { @@ -48,7 +49,7 @@ static final class Complex extends QRDecomposition { } Complex(final boolean fullSize) { - super(GenericDenseStore.COMPLEX, fullSize); + super(GenericStore.COMPLEX, fullSize); } } @@ -60,7 +61,7 @@ static final class Primitive extends QRDecomposition { } Primitive(final boolean fullSize) { - super(PrimitiveDenseStore.FACTORY, fullSize); + super(Primitive64Store.FACTORY, fullSize); } } @@ -72,7 +73,7 @@ static final class Quat extends QRDecomposition { } Quat(final boolean fullSize) { - super(GenericDenseStore.QUATERNION, fullSize); + super(GenericStore.QUATERNION, fullSize); } } @@ -84,7 +85,7 @@ static final class Rational extends QRDecomposition { } Rational(final boolean fullSize) { - super(GenericDenseStore.RATIONAL, fullSize); + super(GenericStore.RATIONAL, fullSize); } } @@ -192,7 +193,7 @@ public double getRankThreshold() { N largest = this.getInPlace().aggregateDiagonal(Aggregator.LARGEST); double epsilon = this.getDimensionalEpsilon(); - return epsilon * Math.max(MACHINE_SMALLEST, largest.doubleValue()); + return epsilon * Math.max(MACHINE_SMALLEST, Scalar.doubleValue(largest)); } public MatrixStore getSolution(final Collectable> rhs) { diff --git a/src/org/ojalgo/matrix/decomposition/RawDecomposition.java b/src/org/ojalgo/matrix/decomposition/RawDecomposition.java index 63ceb94e8..8d8066d24 100644 --- a/src/org/ojalgo/matrix/decomposition/RawDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/RawDecomposition.java @@ -26,7 +26,7 @@ import org.ojalgo.matrix.store.DiagonalStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.scalar.Scalar; @@ -54,9 +54,9 @@ protected RawDecomposition() { } @Override - protected PrimitiveDenseStore allocate(final long numberOfRows, final long numberOfColumns) { + protected Primitive64Store allocate(final long numberOfRows, final long numberOfColumns) { // TODO Should use RawStore.FACTORY rather than PrimitiveDenseStore.FACTORY - return PrimitiveDenseStore.FACTORY.makeZero(numberOfRows, numberOfColumns); + return Primitive64Store.FACTORY.makeZero(numberOfRows, numberOfColumns); } protected boolean checkSymmetry() { @@ -75,9 +75,9 @@ protected MatrixStore collect(final Access2D.Collectable) source; } else if (source instanceof Access2D) { - return PrimitiveDenseStore.FACTORY.builder().makeWrapper((Access2D) source).get(); + return Primitive64Store.FACTORY.builder().makeWrapper((Access2D) source).get(); } else { - return source.collect(PrimitiveDenseStore.FACTORY); + return source.collect(Primitive64Store.FACTORY); } } @@ -114,7 +114,7 @@ protected final Scalar.Factory scalar() { } protected Collectable> wrap(final Access2D matrix) { - return MatrixStore.PRIMITIVE.makeWrapper(matrix); + return MatrixStore.PRIMITIVE64.makeWrapper(matrix); } double[][] reset(final Structure2D template, final boolean transpose) { diff --git a/src/org/ojalgo/matrix/decomposition/RawLU.java b/src/org/ojalgo/matrix/decomposition/RawLU.java index aa8d58e3a..57a87838b 100644 --- a/src/org/ojalgo/matrix/decomposition/RawLU.java +++ b/src/org/ojalgo/matrix/decomposition/RawLU.java @@ -185,7 +185,7 @@ public MatrixStore solve(final Access2D body, final Access2D rhs, if (this.isSolvable()) { - MatrixStore.PRIMITIVE.makeWrapper(rhs).row(myPivot.getOrder()).supplyTo(preallocated); + MatrixStore.PRIMITIVE64.makeWrapper(rhs).row(myPivot.getOrder()).supplyTo(preallocated); return this.doSolve(preallocated); diff --git a/src/org/ojalgo/matrix/decomposition/RawQR.java b/src/org/ojalgo/matrix/decomposition/RawQR.java index 26d154196..9401a20c8 100644 --- a/src/org/ojalgo/matrix/decomposition/RawQR.java +++ b/src/org/ojalgo/matrix/decomposition/RawQR.java @@ -31,7 +31,7 @@ import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Access2D.Collectable; @@ -69,7 +69,7 @@ public Double calculateDeterminant(final Access2D matrix) { final double[][] retVal = this.reset(matrix, true); - MatrixStore.PRIMITIVE.makeWrapper(matrix).transpose().supplyTo(this.getInternalStore()); + MatrixStore.PRIMITIVE64.makeWrapper(matrix).transpose().supplyTo(this.getInternalStore()); this.doDecompose(retVal); @@ -124,7 +124,7 @@ public MatrixStore getInverse() { } public MatrixStore getInverse(final PhysicalStore preallocated) { - return this.doGetInverse((PrimitiveDenseStore) preallocated); + return this.doGetInverse((Primitive64Store) preallocated); } /** @@ -211,15 +211,15 @@ public MatrixStore getSolution(final Collectable invert(final Access2D original, final PhysicalStore preallocated) throws RecoverableCondition { - final double[][] tmpData = this.reset(MatrixStore.PRIMITIVE.makeWrapper(original), true); + final double[][] tmpData = this.reset(MatrixStore.PRIMITIVE64.makeWrapper(original), true); - MatrixStore.PRIMITIVE.makeWrapper(original).transpose().supplyTo(this.getInternalStore()); + MatrixStore.PRIMITIVE64.makeWrapper(original).transpose().supplyTo(this.getInternalStore()); this.doDecompose(tmpData); @@ -259,7 +259,7 @@ public MatrixStore solve(final Access2D body, final Access2D rhs, final double[][] tmpData = this.reset(body, true); - MatrixStore.PRIMITIVE.makeWrapper(body).transpose().supplyTo(this.getInternalStore()); + MatrixStore.PRIMITIVE64.makeWrapper(body).transpose().supplyTo(this.getInternalStore()); this.doDecompose(tmpData); @@ -267,7 +267,7 @@ public MatrixStore solve(final Access2D body, final Access2D rhs, preallocated.fillMatching(rhs); - return this.doSolve((PrimitiveDenseStore) preallocated); + return this.doSolve((Primitive64Store) preallocated); } else { @@ -324,14 +324,14 @@ private boolean doDecompose(final double[][] data) { /** * Makes no use of preallocated at all. Simply delegates to {@link #getInverse()}. */ - private MatrixStore doGetInverse(final PrimitiveDenseStore preallocated) { + private MatrixStore doGetInverse(final Primitive64Store preallocated) { - MatrixStore.PRIMITIVE.makeIdentity(this.getRowDim()).supplyTo(preallocated); + MatrixStore.PRIMITIVE64.makeIdentity(this.getRowDim()).supplyTo(preallocated); return this.doSolve(preallocated); } - private MatrixStore doSolve(final PrimitiveDenseStore preallocated) { + private MatrixStore doSolve(final Primitive64Store preallocated) { final double[] tmpRHSdata = preallocated.data; diff --git a/src/org/ojalgo/matrix/decomposition/RawSingularValue.java b/src/org/ojalgo/matrix/decomposition/RawSingularValue.java index c306db5e9..b522a0505 100644 --- a/src/org/ojalgo/matrix/decomposition/RawSingularValue.java +++ b/src/org/ojalgo/matrix/decomposition/RawSingularValue.java @@ -32,7 +32,7 @@ import org.ojalgo.matrix.decomposition.function.RotateRight; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; @@ -62,7 +62,7 @@ final class RawSingularValue extends RawDecomposition implements SingularValue getInverse() { } public MatrixStore getInverse(final PhysicalStore preallocated) { - return this.doGetInverse((PrimitiveDenseStore) preallocated); + return this.doGetInverse((Primitive64Store) preallocated); } public double getKyFanNorm(final int k) { @@ -527,7 +527,7 @@ public void negateColumn(final int col) { return this.computed(true); } - MatrixStore doGetInverse(final PrimitiveDenseStore preallocated) { + MatrixStore doGetInverse(final Primitive64Store preallocated) { if (myPseudoinverse == null) { diff --git a/src/org/ojalgo/matrix/decomposition/SimultaneousTridiagonal.java b/src/org/ojalgo/matrix/decomposition/SimultaneousTridiagonal.java index 6d458185b..e239443e5 100644 --- a/src/org/ojalgo/matrix/decomposition/SimultaneousTridiagonal.java +++ b/src/org/ojalgo/matrix/decomposition/SimultaneousTridiagonal.java @@ -25,7 +25,7 @@ import org.ojalgo.array.Primitive64Array; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; /** @@ -39,7 +39,7 @@ class SimultaneousTridiagonal extends TridiagonalDecomposition { private BasicArray myDiagE; SimultaneousTridiagonal() { - super(PrimitiveDenseStore.FACTORY); + super(Primitive64Store.FACTORY); } public boolean decompose(final Access2D.Collectable> matrix) { diff --git a/src/org/ojalgo/matrix/decomposition/SingularValue.java b/src/org/ojalgo/matrix/decomposition/SingularValue.java index 382f0ebfe..24b1c1418 100644 --- a/src/org/ojalgo/matrix/decomposition/SingularValue.java +++ b/src/org/ojalgo/matrix/decomposition/SingularValue.java @@ -50,10 +50,10 @@ * * @author apete */ -public interface SingularValue extends MatrixDecomposition, MatrixDecomposition.Solver, MatrixDecomposition.EconomySize, +public interface SingularValue> extends MatrixDecomposition, MatrixDecomposition.Solver, MatrixDecomposition.EconomySize, MatrixDecomposition.RankRevealing, MatrixDecomposition.Values { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { default SingularValue make(final boolean fullSize) { return this.make(TYPICAL, fullSize); @@ -81,7 +81,7 @@ default SingularValue make(final Structure2D typical) { Factory RATIONAL = (typical, fullSize) -> new SingularValueDecomposition.Rational(fullSize); - static boolean equals(final MatrixStore matrix, final SingularValue decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final SingularValue decomposition, final NumberContext context) { final int tmpRowDim = (int) matrix.countRows(); final int tmpColDim = (int) matrix.countColumns(); @@ -151,7 +151,7 @@ static boolean equals(final MatrixStore matrix, final Sing */ @Deprecated @SuppressWarnings("unchecked") - static SingularValue make(final Access2D typical) { + static > SingularValue make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -172,7 +172,7 @@ static SingularValue make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final SingularValue decomposition) { + static > MatrixStore reconstruct(final SingularValue decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/SingularValueDecomposition.java b/src/org/ojalgo/matrix/decomposition/SingularValueDecomposition.java index d73f512d8..ca7633bbb 100644 --- a/src/org/ojalgo/matrix/decomposition/SingularValueDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/SingularValueDecomposition.java @@ -31,10 +31,10 @@ import org.ojalgo.matrix.decomposition.function.NegateColumn; import org.ojalgo.matrix.decomposition.function.RotateRight; import org.ojalgo.matrix.store.DiagonalStore; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; @@ -46,7 +46,7 @@ import org.ojalgo.structure.Structure2D; import org.ojalgo.type.context.NumberContext; -abstract class SingularValueDecomposition> extends GenericDecomposition implements SingularValue { +abstract class SingularValueDecomposition> extends GenericDecomposition implements SingularValue { static final class Complex extends SingularValueDecomposition { @@ -55,7 +55,7 @@ static final class Complex extends SingularValueDecomposition { } Complex(final boolean fullSize) { - super(GenericDenseStore.COMPLEX, new BidiagonalDecomposition.Complex(fullSize), fullSize); + super(GenericStore.COMPLEX, new BidiagonalDecomposition.Complex(fullSize), fullSize); } } @@ -67,7 +67,7 @@ static final class Primitive extends SingularValueDecomposition { } Primitive(final boolean fullSize) { - super(PrimitiveDenseStore.FACTORY, new BidiagonalDecomposition.Primitive(fullSize), fullSize); + super(Primitive64Store.FACTORY, new BidiagonalDecomposition.Primitive(fullSize), fullSize); } } @@ -79,7 +79,7 @@ static final class Quat extends SingularValueDecomposition { } Quat(final boolean fullSize) { - super(GenericDenseStore.QUATERNION, new BidiagonalDecomposition.Quat(fullSize), fullSize); + super(GenericStore.QUATERNION, new BidiagonalDecomposition.Quat(fullSize), fullSize); } } @@ -91,7 +91,7 @@ static final class Rational extends SingularValueDecomposition { } Rational(final boolean fullSize) { - super(GenericDenseStore.RATIONAL, new BidiagonalDecomposition.Rational(fullSize), fullSize); + super(GenericStore.RATIONAL, new BidiagonalDecomposition.Rational(fullSize), fullSize); } } diff --git a/src/org/ojalgo/matrix/decomposition/Tridiagonal.java b/src/org/ojalgo/matrix/decomposition/Tridiagonal.java index cac043ce3..6bd96b416 100644 --- a/src/org/ojalgo/matrix/decomposition/Tridiagonal.java +++ b/src/org/ojalgo/matrix/decomposition/Tridiagonal.java @@ -37,9 +37,9 @@ * * @author apete */ -public interface Tridiagonal extends MatrixDecomposition { +public interface Tridiagonal> extends MatrixDecomposition { - interface Factory extends MatrixDecomposition.Factory> { + interface Factory> extends MatrixDecomposition.Factory> { } @@ -51,7 +51,7 @@ interface Factory extends MatrixDecomposition.Factory RATIONAL = typical -> new DeferredTridiagonal.Rational(); - static boolean equals(final MatrixStore matrix, final Tridiagonal decomposition, final NumberContext context) { + static > boolean equals(final MatrixStore matrix, final Tridiagonal decomposition, final NumberContext context) { boolean retVal = true; @@ -78,7 +78,7 @@ static boolean equals(final MatrixStore matrix, final Trid */ @Deprecated @SuppressWarnings("unchecked") - static Tridiagonal make(final Access2D typical) { + static > Tridiagonal make(final Access2D typical) { final N tmpNumber = typical.get(0, 0); @@ -99,7 +99,7 @@ static Tridiagonal make(final Access2D typical) { * @deprecated v48 Use {@link #reconstruct()} instead */ @Deprecated - static MatrixStore reconstruct(final Tridiagonal decomposition) { + static > MatrixStore reconstruct(final Tridiagonal decomposition) { return decomposition.reconstruct(); } diff --git a/src/org/ojalgo/matrix/decomposition/TridiagonalDecomposition.java b/src/org/ojalgo/matrix/decomposition/TridiagonalDecomposition.java index 238f53672..b65d95d13 100644 --- a/src/org/ojalgo/matrix/decomposition/TridiagonalDecomposition.java +++ b/src/org/ojalgo/matrix/decomposition/TridiagonalDecomposition.java @@ -24,7 +24,7 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -abstract class TridiagonalDecomposition extends InPlaceDecomposition implements Tridiagonal { +abstract class TridiagonalDecomposition> extends InPlaceDecomposition implements Tridiagonal { private transient MatrixStore myD = null; private transient DecompositionStore myQ = null; diff --git a/src/org/ojalgo/matrix/geometry/GeometryMatrix.java b/src/org/ojalgo/matrix/geometry/GeometryMatrix.java index d53a03e23..3778b61dd 100644 --- a/src/org/ojalgo/matrix/geometry/GeometryMatrix.java +++ b/src/org/ojalgo/matrix/geometry/GeometryMatrix.java @@ -23,7 +23,7 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; interface GeometryMatrix> extends MatrixStore { @@ -64,8 +64,8 @@ default MT newInstance() { } } - default PhysicalStore.Factory physical() { - return PrimitiveDenseStore.FACTORY; + default PhysicalStore.Factory physical() { + return Primitive64Store.FACTORY; } @SuppressWarnings("unchecked") diff --git a/src/org/ojalgo/matrix/geometry/GeometryVector.java b/src/org/ojalgo/matrix/geometry/GeometryVector.java index a5cd2af7c..573234295 100644 --- a/src/org/ojalgo/matrix/geometry/GeometryVector.java +++ b/src/org/ojalgo/matrix/geometry/GeometryVector.java @@ -24,6 +24,7 @@ import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.matrix.store.TransformableRegion; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Structure1D; import org.ojalgo.structure.Structure2D; @@ -44,12 +45,12 @@ public final void add(final long row, final long col, final double addend) { this.add(Structure2D.index(this.structure(), row, col), addend); } - public final void add(final long row, final long col, final Number addend) { - this.add(Structure2D.index(this.structure(), row, col), addend.doubleValue()); + public final void add(final long row, final long col, final Comparable addend) { + this.add(Structure2D.index(this.structure(), row, col), Scalar.doubleValue(addend)); } - public final void add(final long index, final Number addend) { - this.add(Structure1D.index(index), addend.doubleValue()); + public final void add(final long index, final Comparable addend) { + this.add(Structure1D.index(index), Scalar.doubleValue(addend)); } public final long count() { @@ -90,11 +91,11 @@ public final void fillOne(final long row, final long col, final Double value) { this.set(Structure2D.index(this.structure(), row, col), value.doubleValue()); } - public final void fillOne(final long row, final long col, final NullaryFunction supplier) { + public final void fillOne(final long row, final long col, final NullaryFunction supplier) { this.set(Structure2D.index(this.structure(), row, col), supplier.doubleValue()); } - public final void fillOne(final long index, final NullaryFunction supplier) { + public final void fillOne(final long index, final NullaryFunction supplier) { this.set(Structure1D.index(index), supplier.doubleValue()); } @@ -126,12 +127,12 @@ public final void set(final long row, final long col, final double value) { this.set(Structure2D.index(this.structure(), row, col), value); } - public final void set(final long row, final long col, final Number value) { - this.set(Structure2D.index(this.structure(), row, col), value.doubleValue()); + public final void set(final long row, final long col, final Comparable value) { + this.set(Structure2D.index(this.structure(), row, col), Scalar.doubleValue(value)); } - public final void set(final long index, final Number addend) { - this.set(Structure1D.index(index), addend.doubleValue()); + public final void set(final long index, final Comparable value) { + this.set(Structure1D.index(index), Scalar.doubleValue(value)); } public final int size() { diff --git a/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java b/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java index 9ab43d8b8..eb137a775 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java +++ b/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java @@ -11,7 +11,7 @@ public class Primitive32Vector2 extends GeometryVector { public float v0, v1; public Primitive32Vector2() { - super(MultiplyBoth.getPrimitive(2L, 1L), 2L, 1L); + super(MultiplyBoth.newPrimitive64(2L, 1L), 2L, 1L); } public Primitive32Vector2(final float v0, final float v1) { diff --git a/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java b/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java index 1937ed0f7..5f0da8978 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java +++ b/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java @@ -11,7 +11,7 @@ public class Primitive32Vector3 extends GeometryVector { public float v0, v1, v2; public Primitive32Vector3() { - super(MultiplyBoth.getPrimitive(3L, 1L), 3L, 1L); + super(MultiplyBoth.newPrimitive64(3L, 1L), 3L, 1L); } public Primitive32Vector3(final float v0, final float v1, final float v2) { diff --git a/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java b/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java index adcb42ae6..050ae7727 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java +++ b/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java @@ -11,7 +11,7 @@ public class Primitive32Vector4 extends GeometryVector { public float v0, v1, v2, v3; public Primitive32Vector4() { - super(MultiplyBoth.getPrimitive(4L, 1L), 4L, 1L); + super(MultiplyBoth.newPrimitive64(4L, 1L), 4L, 1L); } @Override diff --git a/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java b/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java index 2888db3fa..5df871e73 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java +++ b/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java @@ -11,7 +11,7 @@ public class Primitive64Vector2 extends GeometryVector { public double v0, v1; public Primitive64Vector2() { - super(MultiplyBoth.getPrimitive(2L, 1L), 2L, 1L); + super(MultiplyBoth.newPrimitive64(2L, 1L), 2L, 1L); } public Primitive64Vector2(final double v0, final double v1) { diff --git a/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java b/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java index f4bd8198d..df553679c 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java +++ b/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java @@ -11,7 +11,7 @@ public class Primitive64Vector3 extends GeometryVector { public double v0, v1, v2; public Primitive64Vector3() { - super(MultiplyBoth.getPrimitive(3L, 1L), 3L, 1L); + super(MultiplyBoth.newPrimitive64(3L, 1L), 3L, 1L); } public Primitive64Vector3(final double v0, final double v1, final double v2) { diff --git a/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java b/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java index e759b2de6..ca7325f01 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java +++ b/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java @@ -11,7 +11,7 @@ public class Primitive64Vector4 extends GeometryVector { public double v0, v1, v2, v3; public Primitive64Vector4() { - super(MultiplyBoth.getPrimitive(4L, 1L), 4L, 1L); + super(MultiplyBoth.newPrimitive64(4L, 1L), 4L, 1L); } public Primitive64Vector4(final double v0, final double v1, final double v2, final double v3) { diff --git a/src/org/ojalgo/matrix/store/AboveBelowStore.java b/src/org/ojalgo/matrix/store/AboveBelowStore.java index 74681e634..ee9012d7f 100644 --- a/src/org/ojalgo/matrix/store/AboveBelowStore.java +++ b/src/org/ojalgo/matrix/store/AboveBelowStore.java @@ -34,7 +34,7 @@ * * @author apete */ -final class AboveBelowStore extends ComposingStore { +final class AboveBelowStore> extends ComposingStore { private final MatrixStore myBelow; private final int mySplit; diff --git a/src/org/ojalgo/matrix/store/AbstractStore.java b/src/org/ojalgo/matrix/store/AbstractStore.java index c26674fdc..a0a63c96c 100644 --- a/src/org/ojalgo/matrix/store/AbstractStore.java +++ b/src/org/ojalgo/matrix/store/AbstractStore.java @@ -27,7 +27,7 @@ import org.ojalgo.structure.Access2D; import org.ojalgo.type.context.NumberContext; -abstract class AbstractStore implements MatrixStore { +abstract class AbstractStore> implements MatrixStore { private final int myColDim; private transient Class myComponentType = null; diff --git a/src/org/ojalgo/matrix/store/ColumnsStore.java b/src/org/ojalgo/matrix/store/ColumnsStore.java index 8836cf439..93c056693 100644 --- a/src/org/ojalgo/matrix/store/ColumnsStore.java +++ b/src/org/ojalgo/matrix/store/ColumnsStore.java @@ -29,7 +29,7 @@ * * @author apete */ -final class ColumnsStore extends SelectingStore { +final class ColumnsStore> extends SelectingStore { private final int[] myColumns; diff --git a/src/org/ojalgo/matrix/store/ColumnsSupplier.java b/src/org/ojalgo/matrix/store/ColumnsSupplier.java index 68e87f4cc..cae7f893e 100644 --- a/src/org/ojalgo/matrix/store/ColumnsSupplier.java +++ b/src/org/ojalgo/matrix/store/ColumnsSupplier.java @@ -12,9 +12,9 @@ import org.ojalgo.structure.ElementView1D; import org.ojalgo.structure.Mutate1D; -public final class ColumnsSupplier implements Access2D, ElementsSupplier { +public final class ColumnsSupplier> implements Access2D, ElementsSupplier { - static final class ItemView extends ColumnView { + static final class ItemView> extends ColumnView { private final ColumnsSupplier mySupplier; @@ -111,7 +111,7 @@ public void add(final long index, final double addend) { receiver.add(index, col, addend); } - public void add(final long index, final Number addend) { + public void add(final long index, final Comparable addend) { receiver.add(index, col, addend); } @@ -123,7 +123,7 @@ public void set(final long index, final double value) { receiver.set(index, col, value); } - public void set(final long index, final Number value) { + public void set(final long index, final Comparable value) { receiver.set(index, col, value); } diff --git a/src/org/ojalgo/matrix/store/ComposingStore.java b/src/org/ojalgo/matrix/store/ComposingStore.java index 4a4fa8429..21654359d 100644 --- a/src/org/ojalgo/matrix/store/ComposingStore.java +++ b/src/org/ojalgo/matrix/store/ComposingStore.java @@ -21,7 +21,7 @@ */ package org.ojalgo.matrix.store; -abstract class ComposingStore extends LogicalStore { +abstract class ComposingStore> extends LogicalStore { protected ComposingStore(final MatrixStore base, final int rowsCount, final int columnsCount) { super(base, rowsCount, columnsCount); diff --git a/src/org/ojalgo/matrix/store/ConjugatedStore.java b/src/org/ojalgo/matrix/store/ConjugatedStore.java index 34f9a5ef3..1e700f587 100644 --- a/src/org/ojalgo/matrix/store/ConjugatedStore.java +++ b/src/org/ojalgo/matrix/store/ConjugatedStore.java @@ -28,7 +28,7 @@ * * @author apete */ -final class ConjugatedStore extends TransjugatedStore { +final class ConjugatedStore> extends TransjugatedStore { ConjugatedStore(final MatrixStore base) { super(base); diff --git a/src/org/ojalgo/matrix/store/DiagonalStore.java b/src/org/ojalgo/matrix/store/DiagonalStore.java index 06415d98c..3a26e2134 100644 --- a/src/org/ojalgo/matrix/store/DiagonalStore.java +++ b/src/org/ojalgo/matrix/store/DiagonalStore.java @@ -30,9 +30,9 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; -public final class DiagonalStore> extends FactoryStore { +public final class DiagonalStore, D extends Access1D> extends FactoryStore { - public static class Builder> implements Supplier> { + public static class Builder, D extends Access1D> implements Supplier> { private final PhysicalStore.Factory myFactory; private final D myMainDiagonal; @@ -74,7 +74,7 @@ private int dimension() { } - public static > Builder builder(final PhysicalStore.Factory factory, final D mainDiagonal) { + public static , D extends Access1D> Builder builder(final PhysicalStore.Factory factory, final D mainDiagonal) { return new Builder<>(factory, mainDiagonal); } diff --git a/src/org/ojalgo/matrix/store/ElementsSupplier.java b/src/org/ojalgo/matrix/store/ElementsSupplier.java index f4ff45ba1..8bafeb470 100644 --- a/src/org/ojalgo/matrix/store/ElementsSupplier.java +++ b/src/org/ojalgo/matrix/store/ElementsSupplier.java @@ -43,7 +43,8 @@ * * @author apete */ -public interface ElementsSupplier extends Stream2D, TransformableRegion, ElementsSupplier>, Supplier> { +public interface ElementsSupplier> + extends Stream2D, TransformableRegion, ElementsSupplier>, Supplier> { default MatrixStore get() { return this.collect(this.physical()); diff --git a/src/org/ojalgo/matrix/store/FactoryStore.java b/src/org/ojalgo/matrix/store/FactoryStore.java index 87be25e50..11077794b 100644 --- a/src/org/ojalgo/matrix/store/FactoryStore.java +++ b/src/org/ojalgo/matrix/store/FactoryStore.java @@ -23,7 +23,7 @@ import org.ojalgo.scalar.Scalar; -abstract class FactoryStore extends AbstractStore { +abstract class FactoryStore> extends AbstractStore { private final PhysicalStore.Factory myFactory; private final Scalar myOne; diff --git a/src/org/ojalgo/matrix/store/GenericDenseStore.java b/src/org/ojalgo/matrix/store/GenericStore.java similarity index 83% rename from src/org/ojalgo/matrix/store/GenericDenseStore.java rename to src/org/ojalgo/matrix/store/GenericStore.java index a9d0395bb..7bf8967da 100644 --- a/src/org/ojalgo/matrix/store/GenericDenseStore.java +++ b/src/org/ojalgo/matrix/store/GenericStore.java @@ -54,31 +54,9 @@ * * @author apete */ -public final class GenericDenseStore> extends ScalarArray implements PhysicalStore, DecompositionStore { +public final class GenericStore> extends ScalarArray implements PhysicalStore, DecompositionStore { - public interface GenericMultiplyBoth> extends TransformableRegion.FillByMultiplying { - - } - - public interface GenericMultiplyLeft> { - - void invoke(N[] product, Access1D left, int complexity, N[] right, Scalar.Factory scalar); - - } - - public interface GenericMultiplyNeither> { - - void invoke(N[] product, N[] left, int complexity, N[] right, Scalar.Factory scalar); - - } - - public interface GenericMultiplyRight> { - - void invoke(N[] product, N[] left, int complexity, Access1D right, Scalar.Factory scalar); - - } - - static final class Factory> implements PhysicalStore.Factory> { + static final class Factory> implements PhysicalStore.Factory> { private final DenseArray.Factory myDenseArrayFactory; @@ -99,33 +77,33 @@ public MatrixStore.Factory builder() { return new MatrixStore.Factory() { public > Builder makeDiagonal(final D mainDiagonal) { - return DiagonalStore.builder(GenericDenseStore.Factory.this, mainDiagonal); + return DiagonalStore.builder(GenericStore.Factory.this, mainDiagonal); } public LogicalBuilder makeIdentity(final int dimension) { - return new LogicalBuilder<>(new IdentityStore<>(GenericDenseStore.Factory.this, dimension)); + return new LogicalBuilder<>(new IdentityStore<>(GenericStore.Factory.this, dimension)); } public LogicalBuilder makeSingle(final N element) { - return new LogicalBuilder<>(new SingleStore<>(GenericDenseStore.Factory.this, element)); + return new LogicalBuilder<>(new SingleStore<>(GenericStore.Factory.this, element)); } public SparseStore makeSparse(final int rowsCount, final int columnsCount) { - return new SparseStore<>(GenericDenseStore.Factory.this, rowsCount, columnsCount); + return new SparseStore<>(GenericStore.Factory.this, rowsCount, columnsCount); } public LogicalBuilder makeWrapper(final Access2D access) { - return new LogicalBuilder<>(new WrapperStore<>(GenericDenseStore.Factory.this, access)); + return new LogicalBuilder<>(new WrapperStore<>(GenericStore.Factory.this, access)); } public LogicalBuilder makeZero(final int rowsCount, final int columnsCount) { - return new LogicalBuilder<>(new ZeroStore<>(GenericDenseStore.Factory.this, rowsCount, columnsCount)); + return new LogicalBuilder<>(new ZeroStore<>(GenericStore.Factory.this, rowsCount, columnsCount)); } }; } - public GenericDenseStore columns(final Access1D... source) { + public GenericStore columns(final Access1D... source) { final int tmpRowDim = (int) source[0].count(); final int tmpColDim = source.length; @@ -140,10 +118,10 @@ public GenericDenseStore columns(final Access1D... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore columns(final double[]... source) { + public GenericStore columns(final double[]... source) { final int tmpRowDim = source[0].length; final int tmpColDim = source.length; @@ -158,17 +136,17 @@ public GenericDenseStore columns(final double[]... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore columns(final List... source) { + public GenericStore columns(final List>... source) { final int tmpRowDim = source[0].size(); final int tmpColDim = source.length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - List tmpColumn; + List> tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { @@ -176,17 +154,17 @@ public GenericDenseStore columns(final List... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore columns(final Number[]... source) { + public GenericStore columns(final Comparable[]... source) { final int tmpRowDim = source[0].length; final int tmpColDim = source.length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - Number[] tmpColumn; + Comparable[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { @@ -194,12 +172,12 @@ public GenericDenseStore columns(final Number[]... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore conjugate(final Access2D source) { + public GenericStore conjugate(final Access2D source) { - final GenericDenseStore retVal = new GenericDenseStore<>(this, (int) source.countColumns(), (int) source.countRows()); + final GenericStore retVal = new GenericStore<>(this, (int) source.countColumns(), (int) source.countRows()); final int tmpRowDim = retVal.getRowDim(); final int tmpColDim = retVal.getColDim(); @@ -225,12 +203,12 @@ public void conquer(final int aFirst, final int aLimit) { return retVal; } - public GenericDenseStore copy(final Access2D source) { + public GenericStore copy(final Access2D source) { final int tmpRowDim = (int) source.countRows(); final int tmpColDim = (int) source.countColumns(); - final GenericDenseStore retVal = new GenericDenseStore<>(this, tmpRowDim, tmpColDim); + final GenericStore retVal = new GenericStore<>(this, tmpRowDim, tmpColDim); if (tmpColDim > FillMatchingSingle.THRESHOLD) { @@ -257,16 +235,16 @@ public FunctionSet function() { return myDenseArrayFactory.function(); } - public GenericDenseStore makeEye(final long rows, final long columns) { + public GenericStore makeEye(final long rows, final long columns) { - final GenericDenseStore retVal = this.makeZero(rows, columns); + final GenericStore retVal = this.makeZero(rows, columns); retVal.myUtility.fillDiagonal(0, 0, myDenseArrayFactory.scalar().one().get()); return retVal; } - public GenericDenseStore makeFilled(final long rows, final long columns, final NullaryFunction supplier) { + public GenericStore makeFilled(final long rows, final long columns, final NullaryFunction supplier) { final int tmpRowDim = (int) rows; final int tmpColDim = (int) columns; @@ -279,7 +257,7 @@ public GenericDenseStore makeFilled(final long rows, final long columns, fina tmpData[i] = myDenseArrayFactory.scalar().cast(supplier.get()); } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } public Householder.Generic makeHouseholder(final int length) { @@ -294,11 +272,11 @@ public Rotation.Generic makeRotation(final int low, final int high, final N c return new Rotation.Generic<>(low, high, cos, sin); } - public GenericDenseStore make(final long rows, final long columns) { - return new GenericDenseStore<>(this, (int) rows, (int) columns); + public GenericStore make(final long rows, final long columns) { + return new GenericStore<>(this, (int) rows, (int) columns); } - public GenericDenseStore rows(final Access1D... source) { + public GenericStore rows(final Access1D... source) { final int tmpRowDim = source.length; final int tmpColDim = (int) source[0].count(); @@ -313,10 +291,10 @@ public GenericDenseStore rows(final Access1D... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore rows(final double[]... source) { + public GenericStore rows(final double[]... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].length; @@ -327,21 +305,21 @@ public GenericDenseStore rows(final double[]... source) { for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { - tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast((Number) tmpRow[j]); + tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpRow[j]); } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore rows(final List... source) { + public GenericStore rows(final List>... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].size(); final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - List tmpRow; + List> tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { @@ -349,17 +327,17 @@ public GenericDenseStore rows(final List... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericDenseStore rows(final Number[]... source) { + public GenericStore rows(final Comparable[]... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - Number[] tmpRow; + Comparable[] tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { @@ -367,16 +345,16 @@ public GenericDenseStore rows(final Number[]... source) { } } - return new GenericDenseStore<>(this, tmpRowDim, tmpColDim, tmpData); + return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } public Scalar.Factory scalar() { return myDenseArrayFactory.scalar(); } - public GenericDenseStore transpose(final Access2D source) { + public GenericStore transpose(final Access2D source) { - final GenericDenseStore retVal = new GenericDenseStore<>(this, (int) source.countColumns(), (int) source.countRows()); + final GenericStore retVal = new GenericStore<>(this, (int) source.countColumns(), (int) source.countRows()); final int tmpRowDim = retVal.getRowDim(); final int tmpColDim = retVal.getColDim(); @@ -404,40 +382,39 @@ public void conquer(final int aFirst, final int aLimit) { } - public static final PhysicalStore.Factory> COMPLEX = new GenericDenseStore.Factory<>(ComplexArray.FACTORY); - public static final PhysicalStore.Factory> QUATERNION = new GenericDenseStore.Factory<>(QuaternionArray.FACTORY); - public static final PhysicalStore.Factory> RATIONAL = new GenericDenseStore.Factory<>( - RationalArray.FACTORY); + public static final PhysicalStore.Factory> COMPLEX = new GenericStore.Factory<>(ComplexArray.FACTORY); + public static final PhysicalStore.Factory> QUATERNION = new GenericStore.Factory<>(QuaternionArray.FACTORY); + public static final PhysicalStore.Factory> RATIONAL = new GenericStore.Factory<>(RationalArray.FACTORY); - public static > GenericDenseStore wrap(final GenericDenseStore.Factory factory, final N... data) { - return new GenericDenseStore<>(factory, data.length, 1, data); + public static > GenericStore wrap(final GenericStore.Factory factory, final N... data) { + return new GenericStore<>(factory, data.length, 1, data); } - public static > GenericDenseStore wrap(final GenericDenseStore.Factory factory, final N[] data, final int structure) { - return new GenericDenseStore<>(factory, structure, data.length / structure, data); + public static > GenericStore wrap(final GenericStore.Factory factory, final N[] data, final int structure) { + return new GenericStore<>(factory, structure, data.length / structure, data); } - private final GenericMultiplyBoth multiplyBoth; - private final GenericMultiplyLeft multiplyLeft; - private final GenericMultiplyNeither multiplyNeither; - private final GenericMultiplyRight multiplyRight; + private final MultiplyBoth.Generic multiplyBoth; + private final MultiplyLeft.Generic multiplyLeft; + private final MultiplyNeither.Generic multiplyNeither; + private final MultiplyRight.Generic multiplyRight; private final int myColDim; - private final GenericDenseStore.Factory myFactory; + private final GenericStore.Factory myFactory; private final int myRowDim; private final Array2D myUtility; private transient N[] myWorkerColumn; @SuppressWarnings("unused") - private GenericDenseStore(final GenericDenseStore.Factory factory, final int numbRows) { + private GenericStore(final GenericStore.Factory factory, final int numbRows) { this(factory, numbRows, 1); } @SuppressWarnings("unused") - private GenericDenseStore(final GenericDenseStore.Factory factory, final N[] dataArray) { + private GenericStore(final GenericStore.Factory factory, final N[] dataArray) { this(factory, dataArray.length, 1, dataArray); } - GenericDenseStore(final GenericDenseStore.Factory factory, final int numbRows, final int numbCols) { + GenericStore(final GenericStore.Factory factory, final int numbRows, final int numbCols) { super(factory.array(), numbRows * numbCols); @@ -448,13 +425,13 @@ private GenericDenseStore(final GenericDenseStore.Factory factory, final N[] myUtility = this.wrapInArray2D(myRowDim); - multiplyBoth = MultiplyBoth.getGeneric(myRowDim, myColDim); - multiplyLeft = MultiplyLeft.getGeneric(myRowDim, myColDim); - multiplyRight = MultiplyRight.getGeneric(myRowDim, myColDim); - multiplyNeither = MultiplyNeither.getGeneric(myRowDim, myColDim); + multiplyBoth = MultiplyBoth.newGeneric(myRowDim, myColDim); + multiplyLeft = MultiplyLeft.newGeneric(myRowDim, myColDim); + multiplyRight = MultiplyRight.newGeneric(myRowDim, myColDim); + multiplyNeither = MultiplyNeither.newGeneric(myRowDim, myColDim); } - GenericDenseStore(final GenericDenseStore.Factory factory, final int numbRows, final int numbCols, final N[] dataArray) { + GenericStore(final GenericStore.Factory factory, final int numbRows, final int numbCols, final N[] dataArray) { super(factory.array(), dataArray); @@ -465,10 +442,10 @@ private GenericDenseStore(final GenericDenseStore.Factory factory, final N[] myUtility = this.wrapInArray2D(myRowDim); - multiplyBoth = MultiplyBoth.getGeneric(myRowDim, myColDim); - multiplyLeft = MultiplyLeft.getGeneric(myRowDim, myColDim); - multiplyRight = MultiplyRight.getGeneric(myRowDim, myColDim); - multiplyNeither = MultiplyNeither.getGeneric(myRowDim, myColDim); + multiplyBoth = MultiplyBoth.newGeneric(myRowDim, myColDim); + multiplyLeft = MultiplyLeft.newGeneric(myRowDim, myColDim); + multiplyRight = MultiplyRight.newGeneric(myRowDim, myColDim); + multiplyNeither = MultiplyNeither.newGeneric(myRowDim, myColDim); } public void accept(final Access2D supplied) { @@ -483,7 +460,7 @@ public void add(final long row, final long col, final double addend) { myUtility.add(row, col, addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myUtility.add(row, col, addend); } @@ -569,8 +546,8 @@ public MatrixStore conjugate() { return new ConjugatedStore<>(this); } - public GenericDenseStore copy() { - return new GenericDenseStore<>(myFactory, myRowDim, myColDim, this.copyOfData()); + public GenericStore copy() { + return new GenericStore<>(myFactory, myRowDim, myColDim, this.copyOfData()); } public long countColumns() { @@ -655,14 +632,14 @@ public void fillByMultiplying(final Access1D left, final Access1D right) { ProgrammingError.throwForMultiplicationNotPossible(); } - if (left instanceof GenericDenseStore) { - if (right instanceof GenericDenseStore) { + if (left instanceof GenericStore) { + if (right instanceof GenericStore) { multiplyNeither.invoke(data, this.cast(left).data, complexity, this.cast(right).data, myFactory.scalar()); } else { multiplyRight.invoke(data, this.cast(left).data, complexity, right, myFactory.scalar()); } } else { - if (right instanceof GenericDenseStore) { + if (right instanceof GenericStore) { multiplyLeft.invoke(data, left, complexity, this.cast(right).data, myFactory.scalar()); } else { multiplyBoth.invoke(this, left, complexity, right); @@ -678,7 +655,7 @@ public void fillColumn(final long row, final long col, final N value) { myUtility.fillColumn(row, col, value); } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { myUtility.fillColumn(row, col, supplier); } @@ -686,7 +663,7 @@ public void fillDiagonal(final long row, final long col, final N value) { myUtility.fillDiagonal(row, col, value); } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { myUtility.fillDiagonal(row, col, supplier); } @@ -797,7 +774,7 @@ public void fillOne(final long row, final long col, final N value) { myUtility.fillOne(row, col, value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myUtility.fillOne(row, col, supplier); } @@ -809,7 +786,7 @@ public void fillRow(final long row, final long col, final N value) { myUtility.fillRow(row, col, value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myUtility.fillRow(row, col, supplier); } @@ -874,7 +851,7 @@ public void modifyAll(final UnaryFunction modifier) { @Override public void conquer(final int aFirst, final int aLimit) { - GenericDenseStore.this.modify(numberOfRows * aFirst, numberOfRows * aLimit, 1, modifier); + GenericStore.this.modify(numberOfRows * aFirst, numberOfRows * aLimit, 1, modifier); } }; @@ -910,9 +887,9 @@ public void modifyRow(final long row, final long col, final UnaryFunction mod public MatrixStore multiply(final MatrixStore right) { - final GenericDenseStore retVal = this.physical().makeZero(myRowDim, right.count() / myColDim); + final GenericStore retVal = this.physical().makeZero(myRowDim, right.count() / myColDim); - if (right instanceof GenericDenseStore) { + if (right instanceof GenericStore) { retVal.multiplyNeither.invoke(retVal.data, data, myColDim, this.cast(right).data, myFactory.scalar()); } else { retVal.multiplyRight.invoke(retVal.data, data, myColDim, right, myFactory.scalar()); @@ -939,7 +916,7 @@ public void negateColumn(final int column) { myUtility.modifyColumn(0, column, myFactory.function().negate()); } - public PhysicalStore.Factory> physical() { + public PhysicalStore.Factory> physical() { return myFactory; } @@ -971,7 +948,7 @@ public void set(final long row, final long col, final double value) { myUtility.set(row, col, value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myUtility.set(row, col, value); } @@ -1007,7 +984,7 @@ public void substituteBackwards(final Access2D body, final boolean unitDiagon @Override public void conquer(final int aFirst, final int aLimit) { - SubstituteBackwards.invoke(GenericDenseStore.this.data, tmpRowDim, aFirst, aLimit, body, unitDiagonal, conjugated, hermitian, + SubstituteBackwards.invoke(GenericStore.this.data, tmpRowDim, aFirst, aLimit, body, unitDiagonal, conjugated, hermitian, myFactory.scalar()); } @@ -1032,8 +1009,7 @@ public void substituteForwards(final Access2D body, final boolean unitDiagona @Override public void conquer(final int aFirst, final int aLimit) { - SubstituteForwards.invoke(GenericDenseStore.this.data, tmpRowDim, aFirst, aLimit, body, unitDiagonal, conjugated, identity, - myFactory.scalar()); + SubstituteForwards.invoke(GenericStore.this.data, tmpRowDim, aFirst, aLimit, body, unitDiagonal, conjugated, identity, myFactory.scalar()); } }; @@ -1187,9 +1163,9 @@ public void visitRow(final long row, final long col, final VoidFunction visit myUtility.visitRow(row, col, visitor); } - private GenericDenseStore cast(final Access1D matrix) { - if (matrix instanceof GenericDenseStore) { - return (GenericDenseStore) matrix; + private GenericStore cast(final Access1D matrix) { + if (matrix instanceof GenericStore) { + return (GenericStore) matrix; } else if (matrix instanceof Access2D) { return myFactory.copy((Access2D) matrix); } else { diff --git a/src/org/ojalgo/matrix/store/IdentityStore.java b/src/org/ojalgo/matrix/store/IdentityStore.java index ef9f0331d..453767ea1 100644 --- a/src/org/ojalgo/matrix/store/IdentityStore.java +++ b/src/org/ojalgo/matrix/store/IdentityStore.java @@ -32,7 +32,7 @@ * * @author apete */ -final class IdentityStore extends FactoryStore { +final class IdentityStore> extends FactoryStore { private IdentityStore(final org.ojalgo.matrix.store.PhysicalStore.Factory factory, final int rowsCount, final int columnsCount) { super(factory, rowsCount, columnsCount); diff --git a/src/org/ojalgo/matrix/store/LeftRightStore.java b/src/org/ojalgo/matrix/store/LeftRightStore.java index c59895cc9..98bab7024 100644 --- a/src/org/ojalgo/matrix/store/LeftRightStore.java +++ b/src/org/ojalgo/matrix/store/LeftRightStore.java @@ -34,7 +34,7 @@ * * @author apete */ -final class LeftRightStore extends ComposingStore { +final class LeftRightStore> extends ComposingStore { private final MatrixStore myRight; private final int mySplit; diff --git a/src/org/ojalgo/matrix/store/LimitStore.java b/src/org/ojalgo/matrix/store/LimitStore.java index 6b925d8fa..cdf0f4e56 100644 --- a/src/org/ojalgo/matrix/store/LimitStore.java +++ b/src/org/ojalgo/matrix/store/LimitStore.java @@ -21,7 +21,7 @@ */ package org.ojalgo.matrix.store; -final class LimitStore extends SelectingStore { +final class LimitStore> extends SelectingStore { LimitStore(final int rowsCount, final int columnsCount, final MatrixStore base) { super(base, rowsCount, columnsCount); diff --git a/src/org/ojalgo/matrix/store/LogicalStore.java b/src/org/ojalgo/matrix/store/LogicalStore.java index 61df12e8f..cb21fc34d 100644 --- a/src/org/ojalgo/matrix/store/LogicalStore.java +++ b/src/org/ojalgo/matrix/store/LogicalStore.java @@ -32,7 +32,7 @@ * * @author apete */ -abstract class LogicalStore extends AbstractStore { +abstract class LogicalStore> extends AbstractStore { private final MatrixStore myBase; private final Scalar myOne; diff --git a/src/org/ojalgo/matrix/store/LowerHermitianStore.java b/src/org/ojalgo/matrix/store/LowerHermitianStore.java index 49320937c..01e2bc52a 100644 --- a/src/org/ojalgo/matrix/store/LowerHermitianStore.java +++ b/src/org/ojalgo/matrix/store/LowerHermitianStore.java @@ -23,7 +23,7 @@ import org.ojalgo.scalar.Scalar; -final class LowerHermitianStore extends ShadingStore { +final class LowerHermitianStore> extends ShadingStore { LowerHermitianStore(final MatrixStore base) { super(base, base.countRows(), Math.min(base.countRows(), base.countColumns())); diff --git a/src/org/ojalgo/matrix/store/LowerHessenbergStore.java b/src/org/ojalgo/matrix/store/LowerHessenbergStore.java index b5c8156c5..22ae30933 100644 --- a/src/org/ojalgo/matrix/store/LowerHessenbergStore.java +++ b/src/org/ojalgo/matrix/store/LowerHessenbergStore.java @@ -30,7 +30,7 @@ * * @author apete */ -final class LowerHessenbergStore extends ShadingStore { +final class LowerHessenbergStore> extends ShadingStore { LowerHessenbergStore(final MatrixStore base) { super(base, base.countRows(), Math.min(base.countRows(), base.countColumns())); diff --git a/src/org/ojalgo/matrix/store/LowerTriangularStore.java b/src/org/ojalgo/matrix/store/LowerTriangularStore.java index a5e015487..ec96b289e 100644 --- a/src/org/ojalgo/matrix/store/LowerTriangularStore.java +++ b/src/org/ojalgo/matrix/store/LowerTriangularStore.java @@ -24,7 +24,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.scalar.Scalar; -final class LowerTriangularStore extends ShadingStore { +final class LowerTriangularStore> extends ShadingStore { private final boolean myUnitDiagonal; diff --git a/src/org/ojalgo/matrix/store/MatrixPipeline.java b/src/org/ojalgo/matrix/store/MatrixPipeline.java index 7d2c035e5..a8a3f20e5 100644 --- a/src/org/ojalgo/matrix/store/MatrixPipeline.java +++ b/src/org/ojalgo/matrix/store/MatrixPipeline.java @@ -28,9 +28,9 @@ import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Transformation2D; -abstract class MatrixPipeline implements ElementsSupplier { +abstract class MatrixPipeline> implements ElementsSupplier { - static final class BinaryOperatorLeft extends MatrixPipeline { + static final class BinaryOperatorLeft> extends MatrixPipeline { private final MatrixStore myLeft; private final BinaryFunction myOperator; @@ -48,7 +48,7 @@ public void supplyTo(final TransformableRegion receiver) { } } - static final class BinaryOperatorRight extends MatrixPipeline { + static final class BinaryOperatorRight> extends MatrixPipeline { private final BinaryFunction myOperator; private final MatrixStore myRight; @@ -66,7 +66,7 @@ public void supplyTo(final TransformableRegion receiver) { } } - static final class ColumnsModifier extends MatrixPipeline { + static final class ColumnsModifier> extends MatrixPipeline { private final BinaryFunction myFunction; private final Access1D myRightArgumnts; @@ -94,7 +94,7 @@ public void supplyTo(final TransformableRegion receiver) { } - static final class ColumnsReducer extends MatrixPipeline { + static final class ColumnsReducer> extends MatrixPipeline { private final Aggregator myAggregator; private final MatrixStore myBase; @@ -117,7 +117,7 @@ public void supplyTo(final TransformableRegion receiver) { } - static final class Multiplication extends MatrixPipeline { + static final class Multiplication> extends MatrixPipeline { private final Access1D myLeft; private final MatrixStore myRight; @@ -147,7 +147,7 @@ public void supplyTo(final TransformableRegion receiver) { } - static final class RowsModifier extends MatrixPipeline { + static final class RowsModifier> extends MatrixPipeline { private final BinaryFunction myFunction; private final Access1D myRightArgumnts; @@ -175,7 +175,7 @@ public void supplyTo(final TransformableRegion receiver) { } - static final class RowsReducer extends MatrixPipeline { + static final class RowsReducer> extends MatrixPipeline { private final Aggregator myAggregator; private final MatrixStore myBase; @@ -198,7 +198,7 @@ public void supplyTo(final TransformableRegion receiver) { } - static final class Transformer extends MatrixPipeline { + static final class Transformer> extends MatrixPipeline { private final Transformation2D myTransformer; @@ -214,7 +214,7 @@ public void supplyTo(final TransformableRegion receiver) { } } - static final class Transpose extends MatrixPipeline { + static final class Transpose> extends MatrixPipeline { Transpose(final ElementsSupplier context) { super(context); @@ -261,7 +261,7 @@ public ElementsSupplier transpose() { } } - static final class UnaryOperator extends MatrixPipeline { + static final class UnaryOperator> extends MatrixPipeline { private final UnaryFunction myOperator; diff --git a/src/org/ojalgo/matrix/store/MatrixStore.java b/src/org/ojalgo/matrix/store/MatrixStore.java index 0855eb106..e7b21f5c7 100644 --- a/src/org/ojalgo/matrix/store/MatrixStore.java +++ b/src/org/ojalgo/matrix/store/MatrixStore.java @@ -62,10 +62,11 @@ * * @author apete */ -public interface MatrixStore extends ElementsSupplier, Access2D, Access2D.Visitable, Access2D.Aggregatable, Access2D.Sliceable, - Access2D.Elements, Structure2D.ReducibleTo1D>, NormedVectorSpace, N>, Operation.Multiplication> { +public interface MatrixStore> + extends ElementsSupplier, Access2D, Access2D.Visitable, Access2D.Aggregatable, Access2D.Sliceable, Access2D.Elements, + Structure2D.ReducibleTo1D>, NormedVectorSpace, N>, Operation.Multiplication> { - public interface Factory { + public interface Factory> { > DiagonalStore.Builder makeDiagonal(D mainDiagonal); @@ -98,10 +99,11 @@ default MatrixStore.LogicalBuilder makeZero(final long rowsCount, final long * * @author apete */ - public static class LogicalBuilder implements ElementsSupplier, Structure2D.Logical, MatrixStore.LogicalBuilder> { + public static class LogicalBuilder> + implements ElementsSupplier, Structure2D.Logical, MatrixStore.LogicalBuilder> { @SafeVarargs - static MatrixStore buildColumn(final long rowsCount, final MatrixStore... columnStores) { + static > MatrixStore buildColumn(final long rowsCount, final MatrixStore... columnStores) { MatrixStore retVal = columnStores[0]; for (int i = 1; i < columnStores.length; i++) { retVal = new AboveBelowStore<>(retVal, columnStores[i]); @@ -113,7 +115,7 @@ static MatrixStore buildColumn(final long rowsCount, final return retVal; } - static MatrixStore buildColumn(final long rowsCount, final MatrixStore columnStore) { + static > MatrixStore buildColumn(final long rowsCount, final MatrixStore columnStore) { MatrixStore retVal = columnStore; long rowsSoFar = retVal.countRows(); if (rowsSoFar < rowsCount) { @@ -123,7 +125,8 @@ static MatrixStore buildColumn(final long rowsCount, final } @SafeVarargs - static MatrixStore buildColumn(final PhysicalStore.Factory factory, final long rowsCount, final N... columnElements) { + static > MatrixStore buildColumn(final PhysicalStore.Factory factory, final long rowsCount, + final N... columnElements) { MatrixStore retVal = factory.columns(columnElements); long rowsSoFar = retVal.countRows(); if (rowsSoFar < rowsCount) { @@ -133,7 +136,7 @@ static MatrixStore buildColumn(final PhysicalStore.Factory } @SafeVarargs - static MatrixStore buildRow(final long colsCount, final MatrixStore... rowStores) { + static > MatrixStore buildRow(final long colsCount, final MatrixStore... rowStores) { MatrixStore retVal = rowStores[0]; for (int j = 1; j < rowStores.length; j++) { retVal = new LeftRightStore<>(retVal, rowStores[j]); @@ -145,7 +148,7 @@ static MatrixStore buildRow(final long colsCount, final Ma return retVal; } - static MatrixStore buildRow(final long colsCount, final MatrixStore rowStore) { + static > MatrixStore buildRow(final long colsCount, final MatrixStore rowStore) { MatrixStore retVal = rowStore; long colsSoFar = retVal.countColumns(); if (colsSoFar < colsCount) { @@ -155,7 +158,7 @@ static MatrixStore buildRow(final long colsCount, final Ma } @SafeVarargs - static MatrixStore buildRow(final PhysicalStore.Factory factory, final long colsCount, final N... rowElements) { + static > MatrixStore buildRow(final PhysicalStore.Factory factory, final long colsCount, final N... rowElements) { MatrixStore retVal = new TransposedStore<>(factory.columns(rowElements)); long colsSoFar = retVal.countColumns(); if (colsSoFar < colsCount) { @@ -498,7 +501,7 @@ public LogicalBuilder superimpose(final int row, final int col, final MatrixS * @deprecated v48 */ @Deprecated - public LogicalBuilder superimpose(final int row, final int col, final Number matrix) { + public LogicalBuilder superimpose(final int row, final int col, final N matrix) { myStore = new SuperimposedStore<>(myStore, row, col, new SingleStore<>(myStore.physical(), matrix)); return this; } @@ -563,15 +566,15 @@ public LogicalBuilder tridiagonal() { Factory COMPLEX = new Factory() { public > DiagonalStore.Builder makeDiagonal(final D mainDiagonal) { - return DiagonalStore.builder(GenericDenseStore.COMPLEX, mainDiagonal); + return DiagonalStore.builder(GenericStore.COMPLEX, mainDiagonal); } public LogicalBuilder makeIdentity(final int dimension) { - return new LogicalBuilder<>(new IdentityStore<>(GenericDenseStore.COMPLEX, dimension)); + return new LogicalBuilder<>(new IdentityStore<>(GenericStore.COMPLEX, dimension)); } public LogicalBuilder makeSingle(final ComplexNumber element) { - return new LogicalBuilder<>(new SingleStore<>(GenericDenseStore.COMPLEX, element)); + return new LogicalBuilder<>(new SingleStore<>(GenericStore.COMPLEX, element)); } public SparseStore makeSparse(final int rowsCount, final int columnsCount) { @@ -579,39 +582,67 @@ public SparseStore makeSparse(final int rowsCount, final int colu } public LogicalBuilder makeWrapper(final Access2D access) { - return new LogicalBuilder<>(new WrapperStore<>(GenericDenseStore.COMPLEX, access)); + return new LogicalBuilder<>(new WrapperStore<>(GenericStore.COMPLEX, access)); } public LogicalBuilder makeZero(final int rowsCount, final int columnsCount) { - return new LogicalBuilder<>(new ZeroStore<>(GenericDenseStore.COMPLEX, rowsCount, columnsCount)); + return new LogicalBuilder<>(new ZeroStore<>(GenericStore.COMPLEX, rowsCount, columnsCount)); } }; - Factory PRIMITIVE = new Factory() { + Factory PRIMITIVE32 = new Factory() { public > Builder makeDiagonal(final D mainDiagonal) { - return DiagonalStore.builder(PrimitiveDenseStore.FACTORY, mainDiagonal); + return DiagonalStore.builder(Primitive32Store.FACTORY, mainDiagonal); } public LogicalBuilder makeIdentity(final int dimension) { - return new LogicalBuilder<>(new IdentityStore<>(PrimitiveDenseStore.FACTORY, dimension)); + return new LogicalBuilder<>(new IdentityStore<>(Primitive32Store.FACTORY, dimension)); } public LogicalBuilder makeSingle(final Double element) { - return new LogicalBuilder<>(new SingleStore<>(PrimitiveDenseStore.FACTORY, element)); + return new LogicalBuilder<>(new SingleStore<>(Primitive32Store.FACTORY, element)); } public SparseStore makeSparse(final int rowsCount, final int columnsCount) { - return SparseStore.PRIMITIVE.make(rowsCount, columnsCount); + return SparseStore.PRIMITIVE32.make(rowsCount, columnsCount); } public LogicalBuilder makeWrapper(final Access2D access) { - return new LogicalBuilder<>(new WrapperStore<>(PrimitiveDenseStore.FACTORY, access)); + return new LogicalBuilder<>(new WrapperStore<>(Primitive32Store.FACTORY, access)); } public LogicalBuilder makeZero(final int rowsCount, final int columnsCount) { - return new LogicalBuilder<>(new ZeroStore<>(PrimitiveDenseStore.FACTORY, rowsCount, columnsCount)); + return new LogicalBuilder<>(new ZeroStore<>(Primitive32Store.FACTORY, rowsCount, columnsCount)); + } + + }; + + Factory PRIMITIVE64 = new Factory() { + + public > Builder makeDiagonal(final D mainDiagonal) { + return DiagonalStore.builder(Primitive64Store.FACTORY, mainDiagonal); + } + + public LogicalBuilder makeIdentity(final int dimension) { + return new LogicalBuilder<>(new IdentityStore<>(Primitive64Store.FACTORY, dimension)); + } + + public LogicalBuilder makeSingle(final Double element) { + return new LogicalBuilder<>(new SingleStore<>(Primitive64Store.FACTORY, element)); + } + + public SparseStore makeSparse(final int rowsCount, final int columnsCount) { + return SparseStore.PRIMITIVE64.make(rowsCount, columnsCount); + } + + public LogicalBuilder makeWrapper(final Access2D access) { + return new LogicalBuilder<>(new WrapperStore<>(Primitive64Store.FACTORY, access)); + } + + public LogicalBuilder makeZero(final int rowsCount, final int columnsCount) { + return new LogicalBuilder<>(new ZeroStore<>(Primitive64Store.FACTORY, rowsCount, columnsCount)); } }; @@ -619,15 +650,15 @@ public LogicalBuilder makeZero(final int rowsCount, final int columnsCou Factory QUATERNION = new Factory() { public > Builder makeDiagonal(final D mainDiagonal) { - return DiagonalStore.builder(GenericDenseStore.QUATERNION, mainDiagonal); + return DiagonalStore.builder(GenericStore.QUATERNION, mainDiagonal); } public LogicalBuilder makeIdentity(final int dimension) { - return new LogicalBuilder<>(new IdentityStore<>(GenericDenseStore.QUATERNION, dimension)); + return new LogicalBuilder<>(new IdentityStore<>(GenericStore.QUATERNION, dimension)); } public LogicalBuilder makeSingle(final Quaternion element) { - return new LogicalBuilder<>(new SingleStore<>(GenericDenseStore.QUATERNION, element)); + return new LogicalBuilder<>(new SingleStore<>(GenericStore.QUATERNION, element)); } public SparseStore makeSparse(final int rowsCount, final int columnsCount) { @@ -635,11 +666,11 @@ public SparseStore makeSparse(final int rowsCount, final int columns } public LogicalBuilder makeWrapper(final Access2D access) { - return new LogicalBuilder<>(new WrapperStore<>(GenericDenseStore.QUATERNION, access)); + return new LogicalBuilder<>(new WrapperStore<>(GenericStore.QUATERNION, access)); } public LogicalBuilder makeZero(final int rowsCount, final int columnsCount) { - return new LogicalBuilder<>(new ZeroStore<>(GenericDenseStore.QUATERNION, rowsCount, columnsCount)); + return new LogicalBuilder<>(new ZeroStore<>(GenericStore.QUATERNION, rowsCount, columnsCount)); } }; @@ -647,15 +678,15 @@ public LogicalBuilder makeZero(final int rowsCount, final int column Factory RATIONAL = new Factory() { public > Builder makeDiagonal(final D mainDiagonal) { - return DiagonalStore.builder(GenericDenseStore.RATIONAL, mainDiagonal); + return DiagonalStore.builder(GenericStore.RATIONAL, mainDiagonal); } public LogicalBuilder makeIdentity(final int dimension) { - return new LogicalBuilder<>(new IdentityStore<>(GenericDenseStore.RATIONAL, dimension)); + return new LogicalBuilder<>(new IdentityStore<>(GenericStore.RATIONAL, dimension)); } public LogicalBuilder makeSingle(final RationalNumber element) { - return new LogicalBuilder<>(new SingleStore<>(GenericDenseStore.RATIONAL, element)); + return new LogicalBuilder<>(new SingleStore<>(GenericStore.RATIONAL, element)); } public SparseStore makeSparse(final int rowsCount, final int columnsCount) { @@ -663,11 +694,11 @@ public SparseStore makeSparse(final int rowsCount, final int col } public LogicalBuilder makeWrapper(final Access2D access) { - return new LogicalBuilder<>(new WrapperStore<>(GenericDenseStore.RATIONAL, access)); + return new LogicalBuilder<>(new WrapperStore<>(GenericStore.RATIONAL, access)); } public LogicalBuilder makeZero(final int rowsCount, final int columnsCount) { - return new LogicalBuilder<>(new ZeroStore<>(GenericDenseStore.RATIONAL, rowsCount, columnsCount)); + return new LogicalBuilder<>(new ZeroStore<>(GenericStore.RATIONAL, rowsCount, columnsCount)); } }; @@ -779,7 +810,7 @@ default PhysicalStore copy() { } default double doubleValue(final long row, final long col) { - return this.get(row, col).doubleValue(); + return Scalar.doubleValue(this.get(row, col)); } default boolean equals(final MatrixStore other, final NumberContext context) { @@ -820,7 +851,7 @@ default boolean isHermitian() { int numberOfRows = Math.toIntExact(this.countRows()); int numberOfColumns = Math.toIntExact(this.countColumns()); - Number element = this.get(0L); + N element = this.get(0L); boolean retVal = numberOfRows == numberOfColumns; @@ -939,14 +970,14 @@ default MatrixStore negate() { default double norm() { - double frobeniusNorm = this.aggregateAll(Aggregator.NORM2).doubleValue(); + double frobeniusNorm = Scalar.doubleValue(this.aggregateAll(Aggregator.NORM2)); if (this.isVector()) { return frobeniusNorm; } else { // Bringing it closer to what the operator norm would be // In case of representing a ComplexNumber or Quaternion as a matrix this will match their norms - return frobeniusNorm / PrimitiveMath.SQRT.invoke(Math.min(this.countRows(), this.countColumns())); + return frobeniusNorm / PrimitiveMath.SQRT.invoke((double) Math.min(this.countRows(), this.countColumns())); } } diff --git a/src/org/ojalgo/matrix/store/OffsetStore.java b/src/org/ojalgo/matrix/store/OffsetStore.java index 61b803a0a..6d8e667cb 100644 --- a/src/org/ojalgo/matrix/store/OffsetStore.java +++ b/src/org/ojalgo/matrix/store/OffsetStore.java @@ -21,7 +21,7 @@ */ package org.ojalgo.matrix.store; -final class OffsetStore extends SelectingStore { +final class OffsetStore> extends SelectingStore { private final int myRowOffset, myColumnOffset; // origin/offset diff --git a/src/org/ojalgo/matrix/store/PhysicalStore.java b/src/org/ojalgo/matrix/store/PhysicalStore.java index 2f2309d93..43d6b33c0 100644 --- a/src/org/ojalgo/matrix/store/PhysicalStore.java +++ b/src/org/ojalgo/matrix/store/PhysicalStore.java @@ -48,9 +48,9 @@ * * @author apete */ -public interface PhysicalStore extends MatrixStore, Access2D.Elements, Access2D.IndexOf, TransformableRegion { +public interface PhysicalStore> extends MatrixStore, Access2D.Elements, Access2D.IndexOf, TransformableRegion { - public interface Factory> extends Factory2D.Dense { + public interface Factory, I extends PhysicalStore> extends Factory2D.Dense { AggregatorSet aggregator(); @@ -88,7 +88,7 @@ default RowsSupplier makeRowsSupplier(final int numberOfColumns) { default I makeSPD(final int dim) { final double[] random = new double[dim]; - final I retVal = this.makeZero(dim, dim); + final I retVal = this.make(dim, dim); for (int i = 0; i < dim; i++) { random[i] = Math.random(); diff --git a/src/org/ojalgo/matrix/store/Primitive32Store.java b/src/org/ojalgo/matrix/store/Primitive32Store.java new file mode 100644 index 000000000..2b5356f66 --- /dev/null +++ b/src/org/ojalgo/matrix/store/Primitive32Store.java @@ -0,0 +1,1024 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.matrix.store; + +import static org.ojalgo.function.constant.PrimitiveMath.*; + +import java.util.Arrays; +import java.util.List; + +import org.ojalgo.ProgrammingError; +import org.ojalgo.array.Array1D; +import org.ojalgo.array.Array2D; +import org.ojalgo.array.DenseArray; +import org.ojalgo.array.Primitive32Array; +import org.ojalgo.array.operation.*; +import org.ojalgo.concurrent.DivideAndConquer; +import org.ojalgo.function.BinaryFunction; +import org.ojalgo.function.NullaryFunction; +import org.ojalgo.function.UnaryFunction; +import org.ojalgo.function.VoidFunction; +import org.ojalgo.function.aggregator.Aggregator; +import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.matrix.transformation.Householder; +import org.ojalgo.matrix.transformation.HouseholderReference; +import org.ojalgo.matrix.transformation.Rotation; +import org.ojalgo.scalar.Scalar; +import org.ojalgo.structure.*; + +/** + * A {@linkplain float} implementation of {@linkplain PhysicalStore}. + * + * @author apete + */ +public final class Primitive32Store extends Primitive32Array implements PhysicalStore { + + public static final PhysicalStore.Factory FACTORY = new PrimitiveFactory() { + + @Override + public DenseArray.Factory array() { + return Primitive32Array.FACTORY; + } + + @Override + public Householder makeHouseholder(final int length) { + return new Householder.Primitive32(length); + } + + @Override + public MatrixStore.Factory builder() { + return MatrixStore.PRIMITIVE32; + } + + public Primitive32Store columns(Access1D... source) { + + final int tmpRowDim = (int) source[0].count(); + final int tmpColDim = source.length; + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + Access1D tmpColumn; + for (int j = 0; j < tmpColDim; j++) { + tmpColumn = source[j]; + for (int i = 0; i < tmpRowDim; i++) { + tmpData[i + (tmpRowDim * j)] = tmpColumn.floatValue(i); + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store columns(Comparable[]... source) { + + final int tmpRowDim = source[0].length; + final int tmpColDim = source.length; + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + Comparable[] tmpColumn; + for (int j = 0; j < tmpColDim; j++) { + tmpColumn = source[j]; + for (int i = 0; i < tmpRowDim; i++) { + tmpData[i + (tmpRowDim * j)] = Scalar.floatValue(tmpColumn[i]); + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store columns(double[]... source) { + + final int tmpRowDim = source[0].length; + final int tmpColDim = source.length; + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + double[] tmpColumn; + for (int j = 0; j < tmpColDim; j++) { + tmpColumn = source[j]; + for (int i = 0; i < tmpRowDim; i++) { + tmpData[i + (tmpRowDim * j)] = (float) tmpColumn[i]; + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store columns(List>... source) { + + final int tmpRowDim = source[0].size(); + final int tmpColDim = source.length; + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + List> tmpColumn; + for (int j = 0; j < tmpColDim; j++) { + tmpColumn = source[j]; + for (int i = 0; i < tmpRowDim; i++) { + tmpData[i + (tmpRowDim * j)] = Scalar.floatValue(tmpColumn.get(i)); + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store copy(Access2D source) { + + final int tmpRowDim = (int) source.countRows(); + final int tmpColDim = (int) source.countColumns(); + + final Primitive32Store retVal = new Primitive32Store(tmpRowDim, tmpColDim); + + if (tmpColDim > FillMatchingSingle.THRESHOLD) { + + final DivideAndConquer tmpConquerer = new DivideAndConquer() { + + @Override + public void conquer(final int aFirst, final int aLimit) { + FillMatchingSingle.copy(retVal.data, tmpRowDim, aFirst, aLimit, source); + } + + }; + + tmpConquerer.invoke(0, tmpColDim, FillMatchingSingle.THRESHOLD); + + } else { + + FillMatchingSingle.copy(retVal.data, tmpRowDim, 0, tmpColDim, source); + } + + return retVal; + } + + public Primitive32Store make(long rows, long columns) { + return new Primitive32Store((int) rows, (int) columns); + } + + public Primitive32Store makeEye(long rows, long columns) { + + final Primitive32Store retVal = this.make(rows, columns); + + retVal.fillDiagonal(ONE); + + return retVal; + } + + public Primitive32Store rows(Access1D... source) { + + final int tmpRowDim = source.length; + final int tmpColDim = (int) source[0].count(); + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + Access1D tmpRow; + for (int i = 0; i < tmpRowDim; i++) { + tmpRow = source[i]; + for (int j = 0; j < tmpColDim; j++) { + tmpData[i + (tmpRowDim * j)] = tmpRow.floatValue(j); + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store rows(Comparable[]... source) { + + final int tmpRowDim = source.length; + final int tmpColDim = source[0].length; + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + Comparable[] tmpRow; + for (int i = 0; i < tmpRowDim; i++) { + tmpRow = source[i]; + for (int j = 0; j < tmpColDim; j++) { + tmpData[i + (tmpRowDim * j)] = Scalar.floatValue(tmpRow[j]); + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store rows(double[]... source) { + + final int tmpRowDim = source.length; + final int tmpColDim = source[0].length; + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + double[] tmpRow; + for (int i = 0; i < tmpRowDim; i++) { + tmpRow = source[i]; + for (int j = 0; j < tmpColDim; j++) { + tmpData[i + (tmpRowDim * j)] = (float) tmpRow[j]; + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store rows(List>... source) { + + final int tmpRowDim = source.length; + final int tmpColDim = source[0].size(); + + final float[] tmpData = new float[tmpRowDim * tmpColDim]; + + List> tmpRow; + for (int i = 0; i < tmpRowDim; i++) { + tmpRow = source[i]; + for (int j = 0; j < tmpColDim; j++) { + tmpData[i + (tmpRowDim * j)] = Scalar.floatValue(tmpRow.get(j)); + } + } + + return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); + } + + public Primitive32Store transpose(Access2D source) { + + final Primitive32Store retVal = new Primitive32Store((int) source.countColumns(), (int) source.countRows()); + + final int tmpRowDim = retVal.getRowDim(); + final int tmpColDim = retVal.getColDim(); + + if (tmpColDim > FillMatchingSingle.THRESHOLD) { + + final DivideAndConquer tmpConquerer = new DivideAndConquer() { + + @Override + public void conquer(final int first, final int limit) { + FillMatchingSingle.transpose(retVal.data, tmpRowDim, first, limit, source); + } + + }; + + tmpConquerer.invoke(0, tmpColDim, FillMatchingSingle.THRESHOLD); + + } else { + + FillMatchingSingle.transpose(retVal.data, tmpRowDim, 0, tmpColDim, source); + } + + return retVal; + } + + }; + + static Primitive32Store cast(final Access1D matrix) { + if (matrix instanceof Primitive32Store) { + return (Primitive32Store) matrix; + } else if (matrix instanceof Access2D) { + return FACTORY.copy((Access2D) matrix); + } else { + return FACTORY.columns(matrix); + } + } + + static Householder.Primitive32 cast(final Householder transformation) { + if (transformation instanceof Householder.Primitive32) { + return (Householder.Primitive32) transformation; + } else if (transformation instanceof HouseholderReference) { + return ((Householder.Primitive32) ((HouseholderReference) transformation).getWorker(FACTORY)).copy(transformation); + } else { + return new Householder.Primitive32(transformation); + } + } + + static Rotation.Primitive cast(final Rotation transformation) { + if (transformation instanceof Rotation.Primitive) { + return (Rotation.Primitive) transformation; + } else { + return new Rotation.Primitive(transformation); + } + } + + private final MultiplyBoth.Primitive multiplyBoth; + private final MultiplyLeft.Primitive32 multiplyLeft; + private final MultiplyNeither.Primitive32 multiplyNeither; + private final MultiplyRight.Primitive32 multiplyRight; + private final int myColDim; + private final int myRowDim; + private final Array2D myUtility; + + private transient float[] myWorkerColumn; + + Primitive32Store(final int numbRows, final int numbCols) { + + super(numbRows * numbCols); + + myRowDim = numbRows; + myColDim = numbCols; + + myUtility = this.wrapInArray2D(myRowDim); + + multiplyBoth = MultiplyBoth.newPrimitive32(myRowDim, myColDim); + multiplyLeft = MultiplyLeft.newPrimitive32(myRowDim, myColDim); + multiplyRight = MultiplyRight.newPrimitive32(myRowDim, myColDim); + multiplyNeither = MultiplyNeither.newPrimitive32(myRowDim, myColDim); + } + + Primitive32Store(final int numbRows, final int numbCols, final float[] dataArray) { + + super(dataArray); + + myRowDim = numbRows; + myColDim = numbCols; + + myUtility = this.wrapInArray2D(myRowDim); + + multiplyBoth = MultiplyBoth.newPrimitive32(myRowDim, myColDim); + multiplyLeft = MultiplyLeft.newPrimitive32(myRowDim, myColDim); + multiplyRight = MultiplyRight.newPrimitive32(myRowDim, myColDim); + multiplyNeither = MultiplyNeither.newPrimitive32(myRowDim, myColDim); + } + + public void accept(Access2D supplied) { + myUtility.accept(supplied); + } + + public void add(long row, long col, Comparable addend) { + myUtility.add(row, col, addend); + } + + public void add(long row, long col, double addend) { + myUtility.add(row, col, addend); + } + + public Double aggregateColumn(long col, Aggregator aggregator) { + return myUtility.aggregateColumn(col, aggregator); + } + + public Double aggregateColumn(long row, long col, Aggregator aggregator) { + return myUtility.aggregateColumn(row, col, aggregator); + } + + public Double aggregateDiagonal(Aggregator aggregator) { + return myUtility.aggregateDiagonal(aggregator); + } + + public Double aggregateDiagonal(long row, long col, Aggregator aggregator) { + return myUtility.aggregateDiagonal(row, col, aggregator); + } + + public Double aggregateRange(long first, long limit, Aggregator aggregator) { + return myUtility.aggregateRange(first, limit, aggregator); + } + + public Double aggregateRow(long row, Aggregator aggregator) { + return myUtility.aggregateRow(row, aggregator); + } + + public Double aggregateRow(long row, long col, Aggregator aggregator) { + return myUtility.aggregateRow(row, col, aggregator); + } + + public , R extends Mutate2D.Receiver> Access2D.Collectable asCollectable2D() { + return myUtility.asCollectable2D(); + } + + public Array1D asList() { + return myUtility.asArray1D(); + } + + public byte byteValue(long row, long col) { + return myUtility.byteValue(row, col); + } + + public ColumnView columns() { + return myUtility.columns(); + } + + public MatrixStore conjugate() { + return this.transpose(); + } + + public long countColumns() { + return myColDim; + } + + public long countRows() { + return myRowDim; + } + + @Override + public double dot(Access1D vector) { + return myUtility.dot(vector); + } + + public double doubleValue(long row, long col) { + return myUtility.doubleValue(row, col); + } + + public ElementView2D elements() { + return myUtility.elements(); + } + + @Override + public boolean equals(Object obj) { + return myUtility.equals(obj); + } + + public void exchangeColumns(long colA, long colB) { + myUtility.exchangeColumns(colA, colB); + } + + public void exchangeRows(long rowA, long rowB) { + myUtility.exchangeRows(rowA, rowB); + } + + public void fillByMultiplying(Access1D left, Access1D right) { + + final int complexity = Math.toIntExact(left.count() / this.countRows()); + if (complexity != Math.toIntExact(right.count() / this.countColumns())) { + ProgrammingError.throwForMultiplicationNotPossible(); + } + + if (left instanceof Primitive32Store) { + if (right instanceof Primitive32Store) { + multiplyNeither.invoke(data, Primitive32Store.cast(left).data, complexity, Primitive32Store.cast(right).data); + } else { + multiplyRight.invoke(data, Primitive32Store.cast(left).data, complexity, right); + } + } else { + if (right instanceof Primitive32Store) { + multiplyLeft.invoke(data, left, complexity, Primitive32Store.cast(right).data); + } else { + multiplyBoth.invoke(this, left, complexity, right); + } + } + } + + public void fillColumn(long col, Access1D values) { + myUtility.fillColumn(col, values); + } + + public void fillColumn(long col, Double value) { + myUtility.fillColumn(col, value); + } + + public void fillColumn(final long row, final long col, final Access1D values) { + myUtility.fillColumn(row, col, values); + } + + public void fillColumn(final long row, final long col, final Double value) { + myUtility.fillColumn(row, col, value); + } + + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + myUtility.fillColumn(row, col, supplier); + } + + public void fillColumn(long col, NullaryFunction supplier) { + myUtility.fillColumn(col, supplier); + } + + public void fillDiagonal(Access1D values) { + myUtility.fillDiagonal(values); + } + + public void fillDiagonal(Double value) { + myUtility.fillDiagonal(value); + } + + public void fillDiagonal(long row, long col, Access1D values) { + myUtility.fillDiagonal(row, col, values); + } + + public void fillDiagonal(final long row, final long col, final Double value) { + myUtility.fillDiagonal(row, col, value); + } + + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + myUtility.fillDiagonal(row, col, supplier); + } + + public void fillDiagonal(NullaryFunction supplier) { + myUtility.fillDiagonal(supplier); + } + + @Override + public void fillMatching(Access1D left, BinaryFunction function, Access1D right) { + myUtility.fillMatching(left, function, right); + } + + @Override + public void fillMatching(UnaryFunction function, Access1D arguments) { + myUtility.fillMatching(function, arguments); + } + + public void fillOne(long row, long col, Access1D values, long valueIndex) { + myUtility.fillOne(row, col, values, valueIndex); + } + + public void fillOne(long row, long col, Double value) { + myUtility.fillOne(row, col, value); + } + + public void fillOne(long row, long col, NullaryFunction supplier) { + myUtility.fillOne(row, col, supplier); + } + + public void fillRow(long row, Access1D values) { + myUtility.fillRow(row, values); + } + + public void fillRow(long row, Double value) { + myUtility.fillRow(row, value); + } + + public void fillRow(long row, long col, Access1D values) { + myUtility.fillRow(row, col, values); + } + + public void fillRow(long row, long col, Double value) { + myUtility.fillRow(row, col, value); + } + + public void fillRow(long row, long col, NullaryFunction supplier) { + myUtility.fillRow(row, col, supplier); + } + + public void fillRow(long row, NullaryFunction supplier) { + myUtility.fillRow(row, supplier); + } + + public float floatValue(long row, long col) { + return myUtility.floatValue(row, col); + } + + public Double get(long row, long col) { + return myUtility.get(row, col); + } + + @Override + public int hashCode() { + return myUtility.hashCode(); + } + + public long indexOfLargestInColumn(long col) { + return myUtility.indexOfLargestInColumn(col); + } + + public long indexOfLargestInColumn(long row, long col) { + return myUtility.indexOfLargestInColumn(row, col); + } + + public long indexOfLargestInRow(long row) { + return myUtility.indexOfLargestInRow(row); + } + + public long indexOfLargestInRow(long row, long col) { + return myUtility.indexOfLargestInRow(row, col); + } + + public long indexOfLargestOnDiagonal() { + return myUtility.indexOfLargestOnDiagonal(); + } + + public long indexOfLargestOnDiagonal(long first) { + return myUtility.indexOfLargestOnDiagonal(first); + } + + public int intValue(long row, long col) { + return myUtility.intValue(row, col); + } + + public boolean isAbsolute(long row, long col) { + return myUtility.isAbsolute(row, col); + } + + public boolean isAcceptable(Structure2D supplier) { + return myUtility.isAcceptable(supplier); + } + + public boolean isAllSmall(double comparedTo) { + return myUtility.isAllSmall(comparedTo); + } + + public boolean isColumnSmall(long col, double comparedTo) { + return myUtility.isColumnSmall(col, comparedTo); + } + + public boolean isColumnSmall(long row, long col, double comparedTo) { + return myUtility.isColumnSmall(row, col, comparedTo); + } + + public boolean isEmpty() { + return myUtility.isEmpty(); + } + + public boolean isFat() { + return myUtility.isFat(); + } + + public boolean isRowSmall(long row, double comparedTo) { + return myUtility.isRowSmall(row, comparedTo); + } + + public boolean isRowSmall(long row, long col, double comparedTo) { + return myUtility.isRowSmall(row, col, comparedTo); + } + + public boolean isScalar() { + return myUtility.isScalar(); + } + + public boolean isSmall(long row, long col, double comparedTo) { + return myUtility.isSmall(row, col, comparedTo); + } + + public boolean isSquare() { + return myUtility.isSquare(); + } + + public boolean isTall() { + return myUtility.isTall(); + } + + public boolean isVector() { + return myUtility.isVector(); + } + + public long longValue(long row, long col) { + return myUtility.longValue(row, col); + } + + @Override + public void modifyAll(UnaryFunction modifier) { + myUtility.modifyAll(modifier); + } + + public void modifyAny(Transformation2D modifier) { + myUtility.modifyAny(modifier); + } + + public void modifyColumn(long row, long col, UnaryFunction modifier) { + myUtility.modifyColumn(row, col, modifier); + } + + public void modifyColumn(long col, UnaryFunction modifier) { + myUtility.modifyColumn(col, modifier); + } + + public void modifyDiagonal(long row, long col, UnaryFunction modifier) { + myUtility.modifyDiagonal(row, col, modifier); + } + + public void modifyDiagonal(UnaryFunction modifier) { + myUtility.modifyDiagonal(modifier); + } + + @Override + public void modifyMatching(Access1D left, BinaryFunction function) { + myUtility.modifyMatching(left, function); + } + + @Override + public void modifyMatching(BinaryFunction function, Access1D right) { + myUtility.modifyMatching(function, right); + } + + public void modifyMatchingInColumns(Access1D left, BinaryFunction function) { + myUtility.modifyMatchingInColumns(left, function); + } + + public void modifyMatchingInColumns(BinaryFunction function, Access1D right) { + myUtility.modifyMatchingInColumns(function, right); + } + + public void modifyMatchingInRows(Access1D left, BinaryFunction function) { + myUtility.modifyMatchingInRows(left, function); + } + + public void modifyMatchingInRows(BinaryFunction function, Access1D right) { + myUtility.modifyMatchingInRows(function, right); + } + + public void modifyOne(long row, long col, UnaryFunction modifier) { + myUtility.modifyOne(row, col, modifier); + } + + public void modifyRow(long row, long col, UnaryFunction modifier) { + myUtility.modifyRow(row, col, modifier); + } + + public void modifyRow(long row, UnaryFunction modifier) { + myUtility.modifyRow(row, modifier); + } + + public ElementView1D nonzeros() { + return myUtility.nonzeros(); + } + + public PhysicalStore.Factory physical() { + return FACTORY; + } + + public void reduceColumns(Aggregator aggregator, Mutate1D receiver) { + myUtility.reduceColumns(aggregator, receiver); + } + + public void reduceRows(Aggregator aggregator, Mutate1D receiver) { + myUtility.reduceRows(aggregator, receiver); + } + + public TransformableRegion regionByColumns(final int... columns) { + return new TransformableRegion.ColumnsRegion<>(this, multiplyBoth, columns); + } + + public TransformableRegion regionByLimits(final int rowLimit, final int columnLimit) { + return new TransformableRegion.LimitRegion<>(this, multiplyBoth, rowLimit, columnLimit); + } + + public TransformableRegion regionByOffsets(final int rowOffset, final int columnOffset) { + return new TransformableRegion.OffsetRegion<>(this, multiplyBoth, rowOffset, columnOffset); + } + + public TransformableRegion regionByRows(final int... rows) { + return new TransformableRegion.RowsRegion<>(this, multiplyBoth, rows); + } + + public TransformableRegion regionByTransposing() { + return new TransformableRegion.TransposedRegion<>(this, multiplyBoth); + } + + public RowView rows() { + return myUtility.rows(); + } + + public void set(long row, long col, Comparable value) { + myUtility.set(row, col, value); + } + + public void set(long row, long col, double value) { + myUtility.set(row, col, value); + } + + public short shortValue(long row, long col) { + return myUtility.shortValue(row, col); + } + + public Array1D sliceColumn(long col) { + return myUtility.sliceColumn(col); + } + + public Array1D sliceColumn(final long row, final long col) { + return myUtility.sliceColumn(row, col); + } + + public Access1D sliceDiagonal() { + return myUtility.sliceDiagonal(); + } + + public Array1D sliceDiagonal(final long row, final long col) { + return myUtility.sliceDiagonal(row, col); + } + + public Array1D sliceRow(long row) { + return myUtility.sliceRow(row); + } + + public Array1D sliceRow(final long row, final long col) { + return myUtility.sliceRow(row, col); + } + + public void substituteBackwards(final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean hermitian) { + + final int tmpRowDim = myRowDim; + final int tmpColDim = myColDim; + + if (tmpColDim > SubstituteBackwards.THRESHOLD) { + + final DivideAndConquer tmpConquerer = new DivideAndConquer() { + + @Override + public void conquer(final int first, final int limit) { + SubstituteBackwards.invoke(Primitive32Store.this.data, tmpRowDim, first, limit, body, unitDiagonal, conjugated, hermitian); + } + + }; + + tmpConquerer.invoke(0, tmpColDim, SubstituteBackwards.THRESHOLD); + + } else { + + SubstituteBackwards.invoke(data, tmpRowDim, 0, tmpColDim, body, unitDiagonal, conjugated, hermitian); + } + } + + public void substituteForwards(final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean identity) { + + final int tmpRowDim = myRowDim; + final int tmpColDim = myColDim; + + if (tmpColDim > SubstituteForwards.THRESHOLD) { + + final DivideAndConquer tmpConquerer = new DivideAndConquer() { + + @Override + public void conquer(final int first, final int limit) { + SubstituteForwards.invoke(Primitive32Store.this.data, tmpRowDim, first, limit, body, unitDiagonal, conjugated, identity); + } + + }; + + tmpConquerer.invoke(0, tmpColDim, SubstituteForwards.THRESHOLD); + + } else { + + SubstituteForwards.invoke(data, tmpRowDim, 0, tmpColDim, body, unitDiagonal, conjugated, identity); + } + } + + public void supplyTo(double[] receiver) { + myUtility.supplyTo(receiver); + } + + public double[] toRawCopy1D() { + return myUtility.toRawCopy1D(); + } + + public double[][] toRawCopy2D() { + return myUtility.toRawCopy2D(); + } + + public void transformLeft(final Householder transformation, final int firstColumn) { + + final Householder.Primitive32 tmpTransf = Primitive32Store.cast(transformation); + + final float[] tmpData = data; + + final int tmpRowDim = myRowDim; + final int tmpColDim = myColDim; + + if ((tmpColDim - firstColumn) > HouseholderLeft.THRESHOLD) { + + final DivideAndConquer tmpConquerer = new DivideAndConquer() { + + @Override + public void conquer(final int first, final int limit) { + HouseholderLeft.invoke(tmpData, tmpRowDim, first, limit, tmpTransf); + } + + }; + + tmpConquerer.invoke(firstColumn, tmpColDim, HouseholderLeft.THRESHOLD); + + } else { + + HouseholderLeft.invoke(tmpData, tmpRowDim, firstColumn, tmpColDim, tmpTransf); + } + } + + public void transformLeft(final Rotation transformation) { + + final Rotation.Primitive tmpTransf = Primitive64Store.cast(transformation); + + final int tmpLow = tmpTransf.low; + final int tmpHigh = tmpTransf.high; + + if (tmpLow != tmpHigh) { + if (!Double.isNaN(tmpTransf.cos) && !Double.isNaN(tmpTransf.sin)) { + RotateLeft.invoke(data, myRowDim, tmpLow, tmpHigh, (float) tmpTransf.cos, (float) tmpTransf.sin); + } else { + myUtility.exchangeRows(tmpLow, tmpHigh); + } + } else { + if (!Double.isNaN(tmpTransf.cos)) { + myUtility.modifyRow(tmpLow, 0L, PrimitiveMath.MULTIPLY.second(tmpTransf.cos)); + } else if (!Double.isNaN(tmpTransf.sin)) { + myUtility.modifyRow(tmpLow, 0L, PrimitiveMath.DIVIDE.second(tmpTransf.sin)); + } else { + myUtility.modifyRow(tmpLow, 0, PrimitiveMath.NEGATE); + } + } + } + + public void transformRight(final Householder transformation, final int firstRow) { + + final Householder.Primitive32 tmpTransf = Primitive32Store.cast(transformation); + + final float[] tmpData = data; + + final int tmpRowDim = myRowDim; + final int tmpColDim = myColDim; + + final float[] tmpWorker = this.getWorkerColumn(); + + if ((tmpRowDim - firstRow) > HouseholderRight.THRESHOLD) { + + final DivideAndConquer tmpConquerer = new DivideAndConquer() { + + @Override + public void conquer(final int first, final int limit) { + HouseholderRight.invoke(tmpData, tmpRowDim, first, limit, tmpColDim, tmpTransf, tmpWorker); + } + + }; + + tmpConquerer.invoke(firstRow, tmpRowDim, HouseholderRight.THRESHOLD); + + } else { + + HouseholderRight.invoke(tmpData, tmpRowDim, firstRow, tmpRowDim, tmpColDim, tmpTransf, tmpWorker); + } + } + + public void transformRight(final Rotation transformation) { + + final Rotation.Primitive tmpTransf = Primitive64Store.cast(transformation); + + final int tmpLow = tmpTransf.low; + final int tmpHigh = tmpTransf.high; + + if (tmpLow != tmpHigh) { + if (!Double.isNaN(tmpTransf.cos) && !Double.isNaN(tmpTransf.sin)) { + RotateRight.invoke(data, myRowDim, tmpLow, tmpHigh, (float) tmpTransf.cos, (float) tmpTransf.sin); + } else { + myUtility.exchangeColumns(tmpLow, tmpHigh); + } + } else { + if (!Double.isNaN(tmpTransf.cos)) { + myUtility.modifyColumn(0L, tmpHigh, PrimitiveMath.MULTIPLY.second(tmpTransf.cos)); + } else if (!Double.isNaN(tmpTransf.sin)) { + myUtility.modifyColumn(0L, tmpHigh, PrimitiveMath.DIVIDE.second(tmpTransf.sin)); + } else { + myUtility.modifyColumn(0, tmpHigh, PrimitiveMath.NEGATE); + } + } + } + + public void visitColumn(final long row, final long col, final VoidFunction visitor) { + myUtility.visitColumn(row, col, visitor); + } + + public void visitColumn(long col, VoidFunction visitor) { + myUtility.visitColumn(col, visitor); + } + + public void visitDiagonal(final long row, final long col, final VoidFunction visitor) { + myUtility.visitDiagonal(row, col, visitor); + } + + public void visitDiagonal(VoidFunction visitor) { + myUtility.visitDiagonal(visitor); + } + + public void visitOne(long row, long col, VoidFunction visitor) { + myUtility.visitOne(row, col, visitor); + } + + public void visitRow(final long row, final long col, final VoidFunction visitor) { + myUtility.visitRow(row, col, visitor); + } + + public void visitRow(long row, VoidFunction visitor) { + myUtility.visitRow(row, visitor); + } + + private float[] getWorkerColumn() { + if (myWorkerColumn != null) { + Arrays.fill(myWorkerColumn, 0F); + } else { + myWorkerColumn = new float[myRowDim]; + } + return myWorkerColumn; + } + + int getColDim() { + return myColDim; + } + + int getMaxDim() { + return Math.max(myRowDim, myColDim); + } + + int getMinDim() { + return Math.min(myRowDim, myColDim); + } + + int getRowDim() { + return myRowDim; + } + +} diff --git a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java b/src/org/ojalgo/matrix/store/Primitive64Store.java similarity index 76% rename from src/org/ojalgo/matrix/store/PrimitiveDenseStore.java rename to src/org/ojalgo/matrix/store/Primitive64Store.java index 5fd315c2b..62ec2be64 100644 --- a/src/org/ojalgo/matrix/store/PrimitiveDenseStore.java +++ b/src/org/ojalgo/matrix/store/Primitive64Store.java @@ -31,18 +31,13 @@ import org.ojalgo.array.Array2D; import org.ojalgo.array.BasicArray; import org.ojalgo.array.ComplexArray; -import org.ojalgo.array.DenseArray; import org.ojalgo.array.Primitive64Array; import org.ojalgo.array.operation.*; import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionSet; import org.ojalgo.function.NullaryFunction; -import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; -import org.ojalgo.function.aggregator.AggregatorSet; -import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; @@ -62,49 +57,15 @@ import org.ojalgo.type.context.NumberContext; /** - * A {@linkplain Double} (actually double) implementation of {@linkplain PhysicalStore}. + * A {@linkplain double} implementation of {@linkplain PhysicalStore}. * * @author apete */ -public final class PrimitiveDenseStore extends Primitive64Array implements PhysicalStore, DecompositionStore { +public final class Primitive64Store extends Primitive64Array implements PhysicalStore, DecompositionStore { - public interface PrimitiveMultiplyBoth extends TransformableRegion.FillByMultiplying { + public static final PhysicalStore.Factory FACTORY = new PrimitiveFactory() { - } - - public interface PrimitiveMultiplyLeft { - - void invoke(double[] product, Access1D left, int complexity, double[] right); - - } - - public interface PrimitiveMultiplyNeither { - - void invoke(double[] product, double[] left, int complexity, double[] right); - - } - - public interface PrimitiveMultiplyRight { - - void invoke(double[] product, double[] left, int complexity, Access1D right); - - } - - public static final PhysicalStore.Factory FACTORY = new PhysicalStore.Factory() { - - public AggregatorSet aggregator() { - return PrimitiveAggregator.getSet(); - } - - public DenseArray.Factory array() { - return Primitive64Array.FACTORY; - } - - public MatrixStore.Factory builder() { - return MatrixStore.PRIMITIVE; - } - - public PrimitiveDenseStore columns(final Access1D... source) { + public Primitive64Store columns(final Access1D... source) { final int tmpRowDim = (int) source[0].count(); final int tmpColDim = source.length; @@ -119,73 +80,69 @@ public PrimitiveDenseStore columns(final Access1D... source) { } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore columns(final double[]... source) { + public Primitive64Store columns(final Comparable[]... source) { final int tmpRowDim = source[0].length; final int tmpColDim = source.length; final double[] tmpData = new double[tmpRowDim * tmpColDim]; - double[] tmpColumn; + Comparable[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - tmpData[i + (tmpRowDim * j)] = tmpColumn[i]; + tmpData[i + (tmpRowDim * j)] = Scalar.doubleValue(tmpColumn[i]); } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore columns(final List... source) { + public Primitive64Store columns(final double[]... source) { - final int tmpRowDim = source[0].size(); + final int tmpRowDim = source[0].length; final int tmpColDim = source.length; final double[] tmpData = new double[tmpRowDim * tmpColDim]; - List tmpColumn; + double[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - tmpData[i + (tmpRowDim * j)] = tmpColumn.get(i).doubleValue(); + tmpData[i + (tmpRowDim * j)] = tmpColumn[i]; } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore columns(final Number[]... source) { + public Primitive64Store columns(final List>... source) { - final int tmpRowDim = source[0].length; + final int tmpRowDim = source[0].size(); final int tmpColDim = source.length; final double[] tmpData = new double[tmpRowDim * tmpColDim]; - Number[] tmpColumn; + List> tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - tmpData[i + (tmpRowDim * j)] = tmpColumn[i].doubleValue(); + tmpData[i + (tmpRowDim * j)] = Scalar.doubleValue(tmpColumn.get(i)); } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); - } - - public PrimitiveDenseStore conjugate(final Access2D source) { - return this.transpose(source); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore copy(final Access2D source) { + public Primitive64Store copy(final Access2D source) { final int tmpRowDim = (int) source.countRows(); final int tmpColDim = (int) source.countColumns(); - final PrimitiveDenseStore retVal = new PrimitiveDenseStore(tmpRowDim, tmpColDim); + final Primitive64Store retVal = new Primitive64Store(tmpRowDim, tmpColDim); if (tmpColDim > FillMatchingSingle.THRESHOLD) { @@ -208,52 +165,20 @@ public void conquer(final int aFirst, final int aLimit) { return retVal; } - public FunctionSet function() { - return PrimitiveFunction.getSet(); + public Primitive64Store make(final long rows, final long columns) { + return new Primitive64Store((int) rows, (int) columns); } - public PrimitiveDenseStore makeEye(final long rows, final long columns) { + public Primitive64Store makeEye(final long rows, final long columns) { - final PrimitiveDenseStore retVal = this.makeZero(rows, columns); + final Primitive64Store retVal = this.make(rows, columns); - retVal.myUtility.fillDiagonal(0, 0, ONE); + retVal.fillDiagonal(ONE); return retVal; } - public PrimitiveDenseStore makeFilled(final long rows, final long columns, final NullaryFunction supplier) { - - final int tmpRowDim = (int) rows; - final int tmpColDim = (int) columns; - - final int tmpLength = tmpRowDim * tmpColDim; - - final double[] tmpData = new double[tmpLength]; - - for (int i = 0; i < tmpLength; i++) { - tmpData[i] = supplier.doubleValue(); - } - - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); - } - - public Householder.Primitive makeHouseholder(final int length) { - return new Householder.Primitive(length); - } - - public Rotation.Primitive makeRotation(final int low, final int high, final double cos, final double sin) { - return new Rotation.Primitive(low, high, cos, sin); - } - - public Rotation.Primitive makeRotation(final int low, final int high, final Double cos, final Double sin) { - return this.makeRotation(low, high, cos != null ? cos.doubleValue() : Double.NaN, sin != null ? sin.doubleValue() : Double.NaN); - } - - public PrimitiveDenseStore make(final long rows, final long columns) { - return new PrimitiveDenseStore((int) rows, (int) columns); - } - - public PrimitiveDenseStore rows(final Access1D... source) { + public Primitive64Store rows(final Access1D... source) { final int tmpRowDim = source.length; final int tmpColDim = (int) source[0].count(); @@ -268,70 +193,66 @@ public PrimitiveDenseStore rows(final Access1D... source) { } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore rows(final double[]... source) { + public Primitive64Store rows(final Comparable[]... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].length; final double[] tmpData = new double[tmpRowDim * tmpColDim]; - double[] tmpRow; + Comparable[] tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { - tmpData[i + (tmpRowDim * j)] = tmpRow[j]; + tmpData[i + (tmpRowDim * j)] = Scalar.doubleValue(tmpRow[j]); } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore rows(final List... source) { + public Primitive64Store rows(final double[]... source) { final int tmpRowDim = source.length; - final int tmpColDim = source[0].size(); + final int tmpColDim = source[0].length; final double[] tmpData = new double[tmpRowDim * tmpColDim]; - List tmpRow; + double[] tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { - tmpData[i + (tmpRowDim * j)] = tmpRow.get(j).doubleValue(); + tmpData[i + (tmpRowDim * j)] = tmpRow[j]; } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public PrimitiveDenseStore rows(final Number[]... source) { + public Primitive64Store rows(final List>... source) { final int tmpRowDim = source.length; - final int tmpColDim = source[0].length; + final int tmpColDim = source[0].size(); final double[] tmpData = new double[tmpRowDim * tmpColDim]; - Number[] tmpRow; + List> tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { - tmpData[i + (tmpRowDim * j)] = tmpRow[j].doubleValue(); + tmpData[i + (tmpRowDim * j)] = Scalar.doubleValue(tmpRow.get(j)); } } - return new PrimitiveDenseStore(tmpRowDim, tmpColDim, tmpData); + return new Primitive64Store(tmpRowDim, tmpColDim, tmpData); } - public Scalar.Factory scalar() { - return PrimitiveScalar.FACTORY; - } + public Primitive64Store transpose(final Access2D source) { - public PrimitiveDenseStore transpose(final Access2D source) { - - final PrimitiveDenseStore retVal = new PrimitiveDenseStore((int) source.countColumns(), (int) source.countRows()); + final Primitive64Store retVal = new Primitive64Store((int) source.countColumns(), (int) source.countRows()); final int tmpRowDim = retVal.getRowDim(); final int tmpColDim = retVal.getColDim(); @@ -361,17 +282,17 @@ public void conquer(final int first, final int limit) { static final long ELEMENT_SIZE = JavaType.DOUBLE.memory(); - static final long SHALLOW_SIZE = MemoryEstimator.estimateObject(PrimitiveDenseStore.class); + static final long SHALLOW_SIZE = MemoryEstimator.estimateObject(Primitive64Store.class); /** * Extracts the argument of the ComplexNumber elements to a new primitive double valued matrix. */ - public static PrimitiveDenseStore getComplexArgument(final Access2D arg) { + public static Primitive64Store getComplexArgument(final Access2D arg) { final long numberOfRows = arg.countRows(); final long numberOfColumns = arg.countColumns(); - final PrimitiveDenseStore retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); + final Primitive64Store retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); Mutate1D.copyComplexArgument(arg, retVal); @@ -381,12 +302,12 @@ public static PrimitiveDenseStore getComplexArgument(final Access2D arg) { + public static Primitive64Store getComplexImaginary(final Access2D arg) { final long numberOfRows = arg.countRows(); final long numberOfColumns = arg.countColumns(); - final PrimitiveDenseStore retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); + final Primitive64Store retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); Mutate1D.copyComplexImaginary(arg, retVal); @@ -396,12 +317,12 @@ public static PrimitiveDenseStore getComplexImaginary(final Access2D arg) { + public static Primitive64Store getComplexModulus(final Access2D arg) { final long numberOfRows = arg.countRows(); final long numberOfColumns = arg.countColumns(); - final PrimitiveDenseStore retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); + final Primitive64Store retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); Mutate1D.copyComplexModulus(arg, retVal); @@ -411,29 +332,29 @@ public static PrimitiveDenseStore getComplexModulus(final Access2D arg) { + public static Primitive64Store getComplexReal(final Access2D arg) { final long numberOfRows = arg.countRows(); final long numberOfColumns = arg.countColumns(); - final PrimitiveDenseStore retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); + final Primitive64Store retVal = FACTORY.makeZero(numberOfRows, numberOfColumns); Mutate1D.copyComplexReal(arg, retVal); return retVal; } - public static PrimitiveDenseStore wrap(final double... data) { - return new PrimitiveDenseStore(data); + public static Primitive64Store wrap(final double... data) { + return new Primitive64Store(data); } - public static PrimitiveDenseStore wrap(final double[] data, final int structure) { - return new PrimitiveDenseStore(structure, data.length / structure, data); + public static Primitive64Store wrap(final double[] data, final int structure) { + return new Primitive64Store(structure, data.length / structure, data); } - static PrimitiveDenseStore cast(final Access1D matrix) { - if (matrix instanceof PrimitiveDenseStore) { - return (PrimitiveDenseStore) matrix; + static Primitive64Store cast(final Access1D matrix) { + if (matrix instanceof Primitive64Store) { + return (Primitive64Store) matrix; } else if (matrix instanceof Access2D) { return FACTORY.copy((Access2D) matrix); } else { @@ -441,13 +362,13 @@ static PrimitiveDenseStore cast(final Access1D matrix) { } } - static Householder.Primitive cast(final Householder transformation) { - if (transformation instanceof Householder.Primitive) { - return (Householder.Primitive) transformation; + static Householder.Primitive64 cast(final Householder transformation) { + if (transformation instanceof Householder.Primitive64) { + return (Householder.Primitive64) transformation; } else if (transformation instanceof HouseholderReference) { - return ((Householder.Primitive) ((HouseholderReference) transformation).getWorker(FACTORY)).copy(transformation); + return ((Householder.Primitive64) ((HouseholderReference) transformation).getWorker(FACTORY)).copy(transformation); } else { - return new Householder.Primitive(transformation); + return new Householder.Primitive64(transformation); } } @@ -459,31 +380,26 @@ static Rotation.Primitive cast(final Rotation transformation) { } } - private final PrimitiveMultiplyBoth multiplyBoth; - private final PrimitiveMultiplyLeft multiplyLeft; - private final PrimitiveMultiplyNeither multiplyNeither; - - private final PrimitiveMultiplyRight multiplyRight; - + private final MultiplyBoth.Primitive multiplyBoth; + private final MultiplyLeft.Primitive64 multiplyLeft; + private final MultiplyNeither.Primitive64 multiplyNeither; + private final MultiplyRight.Primitive64 multiplyRight; private final int myColDim; - private final int myRowDim; - private final Array2D myUtility; - private transient double[] myWorkerColumn; @SuppressWarnings("unused") - private PrimitiveDenseStore(final double[] dataArray) { + private Primitive64Store(final double[] dataArray) { this(dataArray.length, 1, dataArray); } @SuppressWarnings("unused") - private PrimitiveDenseStore(final int numbRows) { + private Primitive64Store(final int numbRows) { this(numbRows, 1); } - PrimitiveDenseStore(final int numbRows, final int numbCols) { + Primitive64Store(final int numbRows, final int numbCols) { super(numbRows * numbCols); @@ -492,13 +408,13 @@ private PrimitiveDenseStore(final int numbRows) { myUtility = this.wrapInArray2D(myRowDim); - multiplyBoth = MultiplyBoth.getPrimitive(myRowDim, myColDim); - multiplyLeft = MultiplyLeft.getPrimitive(myRowDim, myColDim); - multiplyRight = MultiplyRight.getPrimitive(myRowDim, myColDim); - multiplyNeither = MultiplyNeither.getPrimitive(myRowDim, myColDim); + multiplyBoth = MultiplyBoth.newPrimitive64(myRowDim, myColDim); + multiplyLeft = MultiplyLeft.newPrimitive64(myRowDim, myColDim); + multiplyRight = MultiplyRight.newPrimitive64(myRowDim, myColDim); + multiplyNeither = MultiplyNeither.newPrimitive64(myRowDim, myColDim); } - PrimitiveDenseStore(final int numbRows, final int numbCols, final double[] dataArray) { + Primitive64Store(final int numbRows, final int numbCols, final double[] dataArray) { super(dataArray); @@ -507,10 +423,10 @@ private PrimitiveDenseStore(final int numbRows) { myUtility = this.wrapInArray2D(myRowDim); - multiplyBoth = MultiplyBoth.getPrimitive(myRowDim, myColDim); - multiplyLeft = MultiplyLeft.getPrimitive(myRowDim, myColDim); - multiplyRight = MultiplyRight.getPrimitive(myRowDim, myColDim); - multiplyNeither = MultiplyNeither.getPrimitive(myRowDim, myColDim); + multiplyBoth = MultiplyBoth.newPrimitive64(myRowDim, myColDim); + multiplyLeft = MultiplyLeft.newPrimitive64(myRowDim, myColDim); + multiplyRight = MultiplyRight.newPrimitive64(myRowDim, myColDim); + multiplyNeither = MultiplyNeither.newPrimitive64(myRowDim, myColDim); } public void accept(final Access2D supplied) { @@ -521,11 +437,11 @@ public void accept(final Access2D supplied) { } } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myUtility.add(row, col, addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final double addend) { myUtility.add(row, col, addend); } @@ -616,7 +532,7 @@ public Array1D computeInPlaceSchur(final PhysicalStore tr final double[] tmpData = data; - final double[] tmpCollectorData = ((PrimitiveDenseStore) transformationCollector).data; + final double[] tmpCollectorData = ((Primitive64Store) transformationCollector).data; final double[] tmpVctrWork = new double[this.getMinDim()]; EvD1D.orthes(tmpData, tmpCollectorData, tmpVctrWork); @@ -643,8 +559,8 @@ public MatrixStore conjugate() { return this.transpose(); } - public PrimitiveDenseStore copy() { - return new PrimitiveDenseStore(myRowDim, myColDim, this.copyOfData()); + public Primitive64Store copy() { + return new Primitive64Store(myRowDim, myColDim, this.copyOfData()); } public long countColumns() { @@ -730,15 +646,15 @@ public void fillByMultiplying(final Access1D left, final Access1D supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { myUtility.fillColumn(row, col, supplier); } @@ -761,7 +677,7 @@ public void fillDiagonal(final long row, final long col, final Double value) { myUtility.fillDiagonal(row, col, value); } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { myUtility.fillDiagonal(row, col, supplier); } @@ -851,7 +767,7 @@ public void fillOne(final long row, final long col, final Double value) { myUtility.fillOne(row, col, value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myUtility.fillOne(row, col, supplier); } @@ -863,16 +779,16 @@ public void fillRow(final long row, final long col, final Double value) { myUtility.fillRow(row, col, value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myUtility.fillRow(row, col, supplier); } public boolean generateApplyAndCopyHouseholderColumn(final int row, final int column, final Householder destination) { - return GenerateApplyAndCopyHouseholderColumn.invoke(data, myRowDim, row, column, (Householder.Primitive) destination); + return GenerateApplyAndCopyHouseholderColumn.invoke(data, myRowDim, row, column, (Householder.Primitive64) destination); } public boolean generateApplyAndCopyHouseholderRow(final int row, final int column, final Householder destination) { - return GenerateApplyAndCopyHouseholderRow.invoke(data, myRowDim, row, column, (Householder.Primitive) destination); + return GenerateApplyAndCopyHouseholderRow.invoke(data, myRowDim, row, column, (Householder.Primitive64) destination); } public MatrixStore get() { @@ -928,7 +844,7 @@ public void modifyAll(final UnaryFunction modifier) { @Override public void conquer(final int first, final int limit) { - PrimitiveDenseStore.this.modify(numberOfRows * first, numberOfRows * limit, 1, modifier); + Primitive64Store.this.modify(numberOfRows * first, numberOfRows * limit, 1, modifier); } }; @@ -964,10 +880,10 @@ public void modifyRow(final long row, final long col, final UnaryFunction multiply(final MatrixStore right) { - final PrimitiveDenseStore retVal = FACTORY.makeZero(myRowDim, right.count() / myColDim); + final Primitive64Store retVal = FACTORY.makeZero(myRowDim, right.count() / myColDim); - if (right instanceof PrimitiveDenseStore) { - retVal.multiplyNeither.invoke(retVal.data, data, myColDim, PrimitiveDenseStore.cast(right).data); + if (right instanceof Primitive64Store) { + retVal.multiplyNeither.invoke(retVal.data, data, myColDim, Primitive64Store.cast(right).data); } else { retVal.multiplyRight.invoke(retVal.data, data, myColDim, right); } @@ -990,7 +906,7 @@ public void negateColumn(final int column) { myUtility.modifyColumn(0, column, PrimitiveMath.NEGATE); } - public PhysicalStore.Factory physical() { + public PhysicalStore.Factory physical() { return FACTORY; } @@ -1018,11 +934,11 @@ public void rotateRight(final int low, final int high, final double cos, final d RotateRight.invoke(data, myRowDim, low, high, cos, sin); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myUtility.set(row, col, value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final double value) { myUtility.set(row, col, value); } @@ -1058,7 +974,7 @@ public void substituteBackwards(final Access2D body, final boolean unitD @Override public void conquer(final int first, final int limit) { - SubstituteBackwards.invoke(PrimitiveDenseStore.this.data, tmpRowDim, first, limit, body, unitDiagonal, conjugated, hermitian); + SubstituteBackwards.invoke(Primitive64Store.this.data, tmpRowDim, first, limit, body, unitDiagonal, conjugated, hermitian); } }; @@ -1082,7 +998,7 @@ public void substituteForwards(final Access2D body, final boolean unitDi @Override public void conquer(final int first, final int limit) { - SubstituteForwards.invoke(PrimitiveDenseStore.this.data, tmpRowDim, first, limit, body, unitDiagonal, conjugated, identity); + SubstituteForwards.invoke(Primitive64Store.this.data, tmpRowDim, first, limit, body, unitDiagonal, conjugated, identity); } }; @@ -1110,7 +1026,7 @@ public String toString() { public void transformLeft(final Householder transformation, final int firstColumn) { - final Householder.Primitive tmpTransf = PrimitiveDenseStore.cast(transformation); + final Householder.Primitive64 tmpTransf = Primitive64Store.cast(transformation); final double[] tmpData = data; @@ -1138,7 +1054,7 @@ public void conquer(final int first, final int limit) { public void transformLeft(final Rotation transformation) { - final Rotation.Primitive tmpTransf = PrimitiveDenseStore.cast(transformation); + final Rotation.Primitive tmpTransf = Primitive64Store.cast(transformation); final int tmpLow = tmpTransf.low; final int tmpHigh = tmpTransf.high; @@ -1162,7 +1078,7 @@ public void transformLeft(final Rotation transformation) { public void transformRight(final Householder transformation, final int firstRow) { - final Householder.Primitive tmpTransf = PrimitiveDenseStore.cast(transformation); + final Householder.Primitive64 tmpTransf = Primitive64Store.cast(transformation); final double[] tmpData = data; @@ -1192,7 +1108,7 @@ public void conquer(final int first, final int limit) { public void transformRight(final Rotation transformation) { - final Rotation.Primitive tmpTransf = PrimitiveDenseStore.cast(transformation); + final Rotation.Primitive tmpTransf = Primitive64Store.cast(transformation); final int tmpLow = tmpTransf.low; final int tmpHigh = tmpTransf.high; @@ -1215,11 +1131,7 @@ public void transformRight(final Rotation transformation) { } public void transformSymmetric(final Householder transformation) { - HouseholderHermitian.invoke(data, PrimitiveDenseStore.cast(transformation), this.getWorkerColumn()); - } - - public MatrixStore transpose() { - return new TransposedStore<>(this); + HouseholderHermitian.invoke(data, Primitive64Store.cast(transformation), this.getWorkerColumn()); } public void tred2(final BasicArray mainDiagonal, final BasicArray offDiagonal, final boolean yesvecs) { diff --git a/src/org/ojalgo/matrix/store/PrimitiveFactory.java b/src/org/ojalgo/matrix/store/PrimitiveFactory.java new file mode 100644 index 000000000..7c76893d6 --- /dev/null +++ b/src/org/ojalgo/matrix/store/PrimitiveFactory.java @@ -0,0 +1,84 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.matrix.store; + +import org.ojalgo.array.DenseArray; +import org.ojalgo.array.Primitive64Array; +import org.ojalgo.function.FunctionSet; +import org.ojalgo.function.NullaryFunction; +import org.ojalgo.function.PrimitiveFunction; +import org.ojalgo.function.aggregator.AggregatorSet; +import org.ojalgo.function.aggregator.PrimitiveAggregator; +import org.ojalgo.matrix.transformation.Householder; +import org.ojalgo.matrix.transformation.Rotation; +import org.ojalgo.scalar.PrimitiveScalar; +import org.ojalgo.scalar.Scalar; +import org.ojalgo.structure.Access2D; + +abstract class PrimitiveFactory> implements PhysicalStore.Factory { + + public MatrixStore.Factory builder() { + return MatrixStore.PRIMITIVE64; + } + + public final AggregatorSet aggregator() { + return PrimitiveAggregator.getSet(); + } + + public DenseArray.Factory array() { + return Primitive64Array.FACTORY; + } + + public final I conjugate(final Access2D source) { + return this.transpose(source); + } + + public final FunctionSet function() { + return PrimitiveFunction.getSet(); + } + + public Householder makeHouseholder(final int length) { + return new Householder.Primitive64(length); + } + + public final Rotation.Primitive makeRotation(final int low, final int high, final double cos, final double sin) { + return new Rotation.Primitive(low, high, cos, sin); + } + + public final Rotation.Primitive makeRotation(final int low, final int high, final Double cos, final Double sin) { + return this.makeRotation(low, high, cos != null ? cos.doubleValue() : Double.NaN, sin != null ? sin.doubleValue() : Double.NaN); + } + + public final Scalar.Factory scalar() { + return PrimitiveScalar.FACTORY; + } + + public final I makeFilled(long rows, long columns, NullaryFunction supplier) { + + I retVal = this.make(rows, columns); + + retVal.fillAll(supplier); + + return retVal; + } + +} diff --git a/src/org/ojalgo/matrix/store/RawStore.java b/src/org/ojalgo/matrix/store/RawStore.java index 9c6b013e3..7a05fccc0 100644 --- a/src/org/ojalgo/matrix/store/RawStore.java +++ b/src/org/ojalgo/matrix/store/RawStore.java @@ -29,8 +29,6 @@ import java.util.List; import org.ojalgo.ProgrammingError; -import org.ojalgo.array.DenseArray; -import org.ojalgo.array.Primitive64Array; import org.ojalgo.array.operation.COPY; import org.ojalgo.array.operation.FillMatchingDual; import org.ojalgo.array.operation.ModifyAll; @@ -40,14 +38,11 @@ import org.ojalgo.array.operation.SubstituteForwards; import org.ojalgo.array.operation.VisitAll; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.FunctionSet; import org.ojalgo.function.NullaryFunction; -import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.function.aggregator.AggregatorFunction; -import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; @@ -65,21 +60,9 @@ * * @author apete */ -public final class RawStore extends Object implements PhysicalStore { +public final class RawStore implements PhysicalStore { - public static final PhysicalStore.Factory FACTORY = new PhysicalStore.Factory() { - - public AggregatorSet aggregator() { - return PrimitiveAggregator.getSet(); - } - - public DenseArray.Factory array() { - return Primitive64Array.FACTORY; - } - - public MatrixStore.Factory builder() { - return MatrixStore.PRIMITIVE; - } + public static final PhysicalStore.Factory FACTORY = new PrimitiveFactory() { public RawStore columns(final Access1D... source) { @@ -117,46 +100,42 @@ public RawStore columns(final double[]... source) { return new RawStore(retVal); } - public RawStore columns(final List... source) { + public RawStore columns(final List>... source) { int tmpRowDim = source[0].size(); int tmpColDim = source.length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - List tmpColumn; + List> tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - retVal[i][j] = tmpColumn.get(i).doubleValue(); + retVal[i][j] = Scalar.doubleValue(tmpColumn.get(i)); } } return new RawStore(retVal); } - public RawStore columns(final Number[]... source) { + public RawStore columns(final Comparable[]... source) { int tmpRowDim = source[0].length; int tmpColDim = source.length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - Number[] tmpColumn; + Comparable[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - retVal[i][j] = tmpColumn[i].doubleValue(); + retVal[i][j] = Scalar.doubleValue(tmpColumn[i]); } } return new RawStore(retVal); } - public RawStore conjugate(final Access2D source) { - return this.transpose(source); - } - public RawStore copy(final Access2D source) { int numbRows = Math.toIntExact(source.countRows()); @@ -171,10 +150,6 @@ public RawStore copy(final Access2D source) { return new RawStore(retVal, numbRows, numbCols); } - public FunctionSet function() { - return PrimitiveFunction.getSet(); - } - public RawStore make(final long rows, final long columns) { return new RawStore(Math.toIntExact(rows), Math.toIntExact(columns)); } @@ -188,31 +163,6 @@ public RawStore makeEye(final long rows, final long columns) { return retVal; } - public RawStore makeFilled(final long rows, final long columns, final NullaryFunction supplier) { - - double[][] retVal = new double[Math.toIntExact(rows)][Math.toIntExact(columns)]; - - for (int i = 0; i < rows; i++) { - for (int j = 0; j < columns; j++) { - retVal[i][j] = supplier.doubleValue(); - } - } - - return new RawStore(retVal); - } - - public Householder makeHouseholder(final int length) { - return new Householder.Primitive(length); - } - - public Rotation makeRotation(final int low, final int high, final double cos, final double sin) { - return new Rotation.Primitive(low, high, cos, sin); - } - - public Rotation makeRotation(final int low, final int high, final Double cos, final Double sin) { - return new Rotation.Primitive(low, high, cos, sin); - } - public RawStore rows(final Access1D... source) { int tmpRowDim = source.length; @@ -253,50 +203,46 @@ public RawStore rows(final double[]... source) { return new RawStore(retVal); } - public RawStore rows(final List... source) { + public RawStore rows(final List>... source) { int tmpRowDim = source.length; int tmpColDim = source[0].size(); double[][] retVal = new double[tmpRowDim][tmpColDim]; - List tmpSource; + List> tmpSource; double[] tmpDestination; for (int i = 0; i < tmpRowDim; i++) { tmpSource = source[i]; tmpDestination = retVal[i]; for (int j = 0; j < tmpColDim; j++) { - tmpDestination[j] = tmpSource.get(j).doubleValue(); + tmpDestination[j] = Scalar.doubleValue(tmpSource.get(j)); } } return new RawStore(retVal); } - public RawStore rows(final Number[]... source) { + public RawStore rows(final Comparable[]... source) { int tmpRowDim = source.length; int tmpColDim = source[0].length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - Number[] tmpSource; + Comparable[] tmpSource; double[] tmpDestination; for (int i = 0; i < tmpRowDim; i++) { tmpSource = source[i]; tmpDestination = retVal[i]; for (int j = 0; j < tmpColDim; j++) { - tmpDestination[j] = tmpSource[j].doubleValue(); + tmpDestination[j] = Scalar.doubleValue(tmpSource[j]); } } return new RawStore(retVal); } - public Scalar.Factory scalar() { - return PrimitiveScalar.FACTORY; - } - public RawStore transpose(final Access2D source) { int tmpRowDim = (int) source.countColumns(); @@ -678,8 +624,8 @@ public void add(final long row, final long col, final double addend) { data[Math.toIntExact(row)][Math.toIntExact(col)] += addend; } - public void add(final long row, final long col, final Number addend) { - data[Math.toIntExact(row)][Math.toIntExact(col)] += addend.doubleValue(); + public void add(final long row, final long col, final Comparable addend) { + data[Math.toIntExact(row)][Math.toIntExact(col)] += Scalar.doubleValue(addend); } public Double aggregateAll(final Aggregator aggregator) { @@ -766,7 +712,7 @@ public void fillAll(final Double value) { FillMatchingDual.fillAll(data, value); } - public void fillAll(final NullaryFunction supplier) { + public void fillAll(final NullaryFunction supplier) { FillMatchingDual.fillAll(data, supplier); } @@ -787,7 +733,7 @@ public void fillColumn(final long row, final long col, final Double value) { FillMatchingDual.fillColumn(data, Math.toIntExact(row), Math.toIntExact(col), value); } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { FillMatchingDual.fillColumn(data, Math.toIntExact(row), Math.toIntExact(col), supplier); } @@ -795,7 +741,7 @@ public void fillDiagonal(final long row, final long col, final Double value) { FillMatchingDual.fillDiagonal(data, Math.toIntExact(row), Math.toIntExact(col), value); } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { FillMatchingDual.fillDiagonal(data, Math.toIntExact(row), Math.toIntExact(col), supplier); } @@ -885,7 +831,7 @@ public void fillOne(final long row, final long col, final Double value) { data[Math.toIntExact(row)][Math.toIntExact(col)] = value; } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { data[Math.toIntExact(row)][Math.toIntExact(col)] = supplier.doubleValue(); } @@ -893,7 +839,7 @@ public void fillRange(final long first, final long limit, final Double value) { FillMatchingDual.fillRange(data, (int) first, (int) limit, value); } - public void fillRange(final long first, final long limit, final NullaryFunction supplier) { + public void fillRange(final long first, final long limit, final NullaryFunction supplier) { FillMatchingDual.fillRange(data, (int) first, (int) limit, supplier); } @@ -901,7 +847,7 @@ public void fillRow(final long row, final long col, final Double value) { FillMatchingDual.fillRow(data, Math.toIntExact(row), Math.toIntExact(col), value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { FillMatchingDual.fillRow(data, Math.toIntExact(row), Math.toIntExact(col), supplier); } @@ -1140,31 +1086,31 @@ public PhysicalStore.Factory physical() { } public TransformableRegion regionByColumns(final int... columns) { - return new TransformableRegion.ColumnsRegion<>(this, MultiplyBoth.getPrimitive(data.length, myNumberOfColumns), columns); + return new TransformableRegion.ColumnsRegion<>(this, MultiplyBoth.newPrimitive64(data.length, myNumberOfColumns), columns); } public TransformableRegion regionByLimits(final int rowLimit, final int columnLimit) { - return new TransformableRegion.LimitRegion<>(this, MultiplyBoth.getPrimitive(data.length, myNumberOfColumns), rowLimit, columnLimit); + return new TransformableRegion.LimitRegion<>(this, MultiplyBoth.newPrimitive64(data.length, myNumberOfColumns), rowLimit, columnLimit); } public TransformableRegion regionByOffsets(final int rowOffset, final int columnOffset) { - return new TransformableRegion.OffsetRegion<>(this, MultiplyBoth.getPrimitive(data.length, myNumberOfColumns), rowOffset, columnOffset); + return new TransformableRegion.OffsetRegion<>(this, MultiplyBoth.newPrimitive64(data.length, myNumberOfColumns), rowOffset, columnOffset); } public TransformableRegion regionByRows(final int... rows) { - return new TransformableRegion.RowsRegion<>(this, MultiplyBoth.getPrimitive(data.length, myNumberOfColumns), rows); + return new TransformableRegion.RowsRegion<>(this, MultiplyBoth.newPrimitive64(data.length, myNumberOfColumns), rows); } public TransformableRegion regionByTransposing() { - return new TransformableRegion.TransposedRegion<>(this, MultiplyBoth.getPrimitive(data.length, myNumberOfColumns)); + return new TransformableRegion.TransposedRegion<>(this, MultiplyBoth.newPrimitive64(data.length, myNumberOfColumns)); } public void set(final long row, final long col, final double value) { data[Math.toIntExact(row)][Math.toIntExact(col)] = value; } - public void set(final long row, final long col, final Number value) { - data[Math.toIntExact(row)][Math.toIntExact(col)] = value.doubleValue(); + public void set(final long row, final long col, final Comparable value) { + data[Math.toIntExact(row)][Math.toIntExact(col)] = Scalar.doubleValue(value); } public Access1D sliceRow(final long row) { diff --git a/src/org/ojalgo/matrix/store/RowsStore.java b/src/org/ojalgo/matrix/store/RowsStore.java index 15069bfb0..009922b09 100644 --- a/src/org/ojalgo/matrix/store/RowsStore.java +++ b/src/org/ojalgo/matrix/store/RowsStore.java @@ -29,7 +29,7 @@ * * @author apete */ -final class RowsStore extends SelectingStore { +final class RowsStore> extends SelectingStore { private final int[] myRows; diff --git a/src/org/ojalgo/matrix/store/RowsSupplier.java b/src/org/ojalgo/matrix/store/RowsSupplier.java index eef5676c5..721312d19 100644 --- a/src/org/ojalgo/matrix/store/RowsSupplier.java +++ b/src/org/ojalgo/matrix/store/RowsSupplier.java @@ -11,9 +11,9 @@ import org.ojalgo.structure.Mutate1D; import org.ojalgo.structure.RowView; -public final class RowsSupplier implements Access2D, ElementsSupplier { +public final class RowsSupplier> implements Access2D, ElementsSupplier { - static final class ItemView extends RowView { + static final class ItemView> extends RowView { private final RowsSupplier mySupplier; @@ -110,7 +110,7 @@ public void add(final long index, final double addend) { receiver.add(row, index, addend); } - public void add(final long index, final Number addend) { + public void add(final long index, final Comparable addend) { receiver.add(row, index, addend); } @@ -122,7 +122,7 @@ public void set(final long index, final double value) { receiver.set(row, index, value); } - public void set(final long index, final Number value) { + public void set(final long index, final Comparable value) { receiver.set(row, index, value); } diff --git a/src/org/ojalgo/matrix/store/SelectingStore.java b/src/org/ojalgo/matrix/store/SelectingStore.java index 320ab8aa5..bd074644d 100644 --- a/src/org/ojalgo/matrix/store/SelectingStore.java +++ b/src/org/ojalgo/matrix/store/SelectingStore.java @@ -26,7 +26,7 @@ * * @author apete */ -abstract class SelectingStore extends LogicalStore { +abstract class SelectingStore> extends LogicalStore { protected SelectingStore(final MatrixStore base, final int rowsCount, final int columnsCount) { super(base, rowsCount, columnsCount); diff --git a/src/org/ojalgo/matrix/store/ShadingStore.java b/src/org/ojalgo/matrix/store/ShadingStore.java index e1a4b4370..1d430b1ab 100644 --- a/src/org/ojalgo/matrix/store/ShadingStore.java +++ b/src/org/ojalgo/matrix/store/ShadingStore.java @@ -27,7 +27,7 @@ * * @author apete */ -abstract class ShadingStore extends LogicalStore { +abstract class ShadingStore> extends LogicalStore { protected ShadingStore(final MatrixStore base, final int rowsCount, final int columnsCount) { super(base, rowsCount, columnsCount); diff --git a/src/org/ojalgo/matrix/store/SingleStore.java b/src/org/ojalgo/matrix/store/SingleStore.java index dd2d9a5c0..1c59ee669 100644 --- a/src/org/ojalgo/matrix/store/SingleStore.java +++ b/src/org/ojalgo/matrix/store/SingleStore.java @@ -25,7 +25,7 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; -final class SingleStore extends FactoryStore { +final class SingleStore> extends FactoryStore { private final N myNumber; private final double myValue; @@ -37,12 +37,13 @@ private SingleStore(final PhysicalStore.Factory factory, final int rowsCou ProgrammingError.throwForIllegalInvocation(); } - SingleStore(final PhysicalStore.Factory factory, final Number element) { + SingleStore(final PhysicalStore.Factory factory, final Comparable element) { super(factory, 1, 1); - myNumber = factory.scalar().cast(element); - myValue = myNumber.doubleValue(); + Scalar converted = factory.scalar().convert(element); + myNumber = converted.get(); + myValue = converted.doubleValue(); } @Override diff --git a/src/org/ojalgo/matrix/store/SparseStore.java b/src/org/ojalgo/matrix/store/SparseStore.java index a99712514..6bc9c5420 100644 --- a/src/org/ojalgo/matrix/store/SparseStore.java +++ b/src/org/ojalgo/matrix/store/SparseStore.java @@ -45,9 +45,9 @@ import org.ojalgo.structure.Structure2D; import org.ojalgo.type.context.NumberContext; -public final class SparseStore extends FactoryStore implements TransformableRegion { +public final class SparseStore> extends FactoryStore implements TransformableRegion { - public interface Factory { + public interface Factory> { SparseStore make(long rowsCount, long columnsCount); @@ -59,7 +59,9 @@ default SparseStore make(final Structure2D shape) { public static final SparseStore.Factory COMPLEX = (rowsCount, columnsCount) -> SparseStore.makeComplex((int) rowsCount, (int) columnsCount); - public static final SparseStore.Factory PRIMITIVE = (rowsCount, columnsCount) -> SparseStore.makePrimitive((int) rowsCount, (int) columnsCount); + public static final SparseStore.Factory PRIMITIVE64 = (rowsCount, columnsCount) -> SparseStore.makePrimitive((int) rowsCount, (int) columnsCount); + + public static final SparseStore.Factory PRIMITIVE32 = (rowsCount, columnsCount) -> SparseStore.makePrimitive32((int) rowsCount, (int) columnsCount); public static final SparseStore.Factory QUATERNION = (rowsCount, columnsCount) -> SparseStore.makeQuaternion((int) rowsCount, (int) columnsCount); @@ -68,30 +70,35 @@ default SparseStore make(final Structure2D shape) { (int) columnsCount); public static SparseStore makeComplex(final int rowsCount, final int columnsCount) { - return SparseStore.makeSparse(GenericDenseStore.COMPLEX, rowsCount, columnsCount); + return SparseStore.makeSparse(GenericStore.COMPLEX, rowsCount, columnsCount); } public static SparseStore makePrimitive(final int rowsCount, final int columnsCount) { - return SparseStore.makeSparse(PrimitiveDenseStore.FACTORY, rowsCount, columnsCount); + return SparseStore.makeSparse(Primitive64Store.FACTORY, rowsCount, columnsCount); + } + + public static SparseStore makePrimitive32(final int rowsCount, final int columnsCount) { + return SparseStore.makeSparse(Primitive32Store.FACTORY, rowsCount, columnsCount); } public static SparseStore makeQuaternion(final int rowsCount, final int columnsCount) { - return SparseStore.makeSparse(GenericDenseStore.QUATERNION, rowsCount, columnsCount); + return SparseStore.makeSparse(GenericStore.QUATERNION, rowsCount, columnsCount); } public static SparseStore makeRational(final int rowsCount, final int columnsCount) { - return SparseStore.makeSparse(GenericDenseStore.RATIONAL, rowsCount, columnsCount); + return SparseStore.makeSparse(GenericStore.RATIONAL, rowsCount, columnsCount); } - static SparseStore makeSparse(final PhysicalStore.Factory physical, final long numberOfRows, final long numberOfColumns) { + static > SparseStore makeSparse(final PhysicalStore.Factory physical, final long numberOfRows, + final long numberOfColumns) { return new SparseStore<>(physical, Math.toIntExact(numberOfRows), Math.toIntExact(numberOfColumns)); } - static SparseStore makeSparse(final PhysicalStore.Factory physical, final Structure2D shape) { + static > SparseStore makeSparse(final PhysicalStore.Factory physical, final Structure2D shape) { return SparseStore.makeSparse(physical, shape.countRows(), shape.countColumns()); } - static void multiply(final SparseStore left, final SparseStore right, final TransformableRegion target) { + static > void multiply(final SparseStore left, final SparseStore right, final TransformableRegion target) { if (left.isPrimitive()) { @@ -122,11 +129,11 @@ static void multiply(final SparseStore left, final SparseS Arrays.fill(myFirsts, columnsCount); // Arrays.fill(myLimits, 0); // Behövs inte, redan 0 - final Class tmpType = factory.scalar().zero().get().getClass(); + final Class tmpType = factory.scalar().zero().get().getClass(); if (tmpType.equals(Double.class)) { - myMultiplyer = (TransformableRegion.FillByMultiplying) MultiplyBoth.getPrimitive(rowsCount, columnsCount); + myMultiplyer = (TransformableRegion.FillByMultiplying) MultiplyBoth.newPrimitive64(rowsCount, columnsCount); } else if (tmpType.equals(ComplexNumber.class)) { - myMultiplyer = (TransformableRegion.FillByMultiplying) MultiplyBoth.getGeneric(rowsCount, columnsCount); + myMultiplyer = (TransformableRegion.FillByMultiplying) MultiplyBoth.newGeneric(rowsCount, columnsCount); } else { myMultiplyer = null; } @@ -137,7 +144,7 @@ public void add(final long row, final long col, final double addend) { this.updateNonZeros(row, col); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myElements.add(Structure2D.index(myFirsts.length, row, col), addend); this.updateNonZeros(row, col); } @@ -165,7 +172,7 @@ public void fillOne(final long row, final long col, final N value) { this.updateNonZeros(row, col); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myElements.fillOne(Structure2D.index(myFirsts.length, row, col), supplier); this.updateNonZeros(row, col); } @@ -380,7 +387,7 @@ public MatrixStore multiply(final N scalar) { if (this.isPrimitive()) { - final double sclr = scalar.doubleValue(); + final double sclr = Scalar.doubleValue(scalar); for (final ElementView2D nonzero : this.nonzeros()) { retVal.set(nonzero.index(), nonzero.doubleValue() * sclr); @@ -506,7 +513,7 @@ public void set(final long row, final long col, final double value) { this.updateNonZeros(row, col); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myElements.set(Structure2D.index(myFirsts.length, row, col), value); this.updateNonZeros(row, col); } diff --git a/src/org/ojalgo/matrix/store/SuperimposedStore.java b/src/org/ojalgo/matrix/store/SuperimposedStore.java index ab39118d9..cb4c40229 100644 --- a/src/org/ojalgo/matrix/store/SuperimposedStore.java +++ b/src/org/ojalgo/matrix/store/SuperimposedStore.java @@ -29,7 +29,7 @@ * * @author apete */ -final class SuperimposedStore extends ComposingStore { +final class SuperimposedStore> extends ComposingStore { private final int myColFirst; private final int myColLimit; diff --git a/src/org/ojalgo/matrix/store/TransformableRegion.java b/src/org/ojalgo/matrix/store/TransformableRegion.java index 2a42e9eaa..ebf518c88 100644 --- a/src/org/ojalgo/matrix/store/TransformableRegion.java +++ b/src/org/ojalgo/matrix/store/TransformableRegion.java @@ -25,8 +25,6 @@ import org.ojalgo.array.operation.MultiplyBoth; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.UnaryFunction; -import org.ojalgo.matrix.store.GenericDenseStore.GenericMultiplyBoth; -import org.ojalgo.matrix.store.PrimitiveDenseStore.PrimitiveMultiplyBoth; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Mutate2D; @@ -37,9 +35,9 @@ * * @author apete */ -public interface TransformableRegion extends Mutate2D.ModifiableReceiver, Access2D { +public interface TransformableRegion> extends Mutate2D.ModifiableReceiver, Access2D { - class ColumnsRegion extends ReceiverRegion { + class ColumnsRegion> extends ReceiverRegion { private final TransformableRegion myBase; private final int[] myColumns; @@ -59,7 +57,7 @@ public void add(final long row, final long col, final double addend) { myBase.add(row, myColumns[(int) col], addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(row, myColumns[(int) col], addend); } @@ -83,7 +81,7 @@ public void fillColumn(final long row, final long col, final N value) { myBase.fillColumn(row, myColumns[(int) col], value); } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { myBase.fillColumn(row, myColumns[(int) col], supplier); } @@ -95,7 +93,7 @@ public void fillOne(final long row, final long col, final N value) { myBase.fillOne(row, myColumns[(int) col], value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myBase.fillOne(row, myColumns[(int) col], supplier); } @@ -115,19 +113,19 @@ public void set(final long row, final long col, final double value) { myBase.set(row, myColumns[(int) col], value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(row, myColumns[(int) col], value); } } - interface FillByMultiplying { + interface FillByMultiplying> { void invoke(TransformableRegion product, Access1D left, int complexity, Access1D right); } - class LimitRegion extends ReceiverRegion { + class LimitRegion> extends ReceiverRegion { private final TransformableRegion myBase; private final int myRowLimit, myColumnLimit; // limits @@ -143,7 +141,7 @@ public void add(final long row, final long col, final double addend) { myBase.add(row, col, addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(row, col, addend); } @@ -167,7 +165,7 @@ public void fillOne(final long row, final long col, final N value) { myBase.fillOne(row, col, value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myBase.fillOne(row, col, supplier); } @@ -183,13 +181,13 @@ public void set(final long row, final long col, final double value) { myBase.set(row, col, value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(row, col, value); } } - class OffsetRegion extends ReceiverRegion { + class OffsetRegion> extends ReceiverRegion { private final TransformableRegion myBase; private final int myRowOffset, myColumnOffset; // origin/offset @@ -205,7 +203,7 @@ public void add(final long row, final long col, final double addend) { myBase.add(myRowOffset + row, myColumnOffset + col, addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(myRowOffset + row, myColumnOffset + col, addend); } @@ -230,7 +228,7 @@ public void fillAll(final N value) { } @Override - public void fillAll(final NullaryFunction supplier) { + public void fillAll(final NullaryFunction supplier) { final long tmpCountColumns = myBase.countColumns(); for (long j = myColumnOffset; j < tmpCountColumns; j++) { myBase.fillColumn(myRowOffset, j, supplier); @@ -241,7 +239,7 @@ public void fillColumn(final long row, final long col, final N value) { myBase.fillColumn(myRowOffset + row, myColumnOffset + col, value); } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { myBase.fillColumn(myRowOffset + row, myColumnOffset + col, supplier); } @@ -249,7 +247,7 @@ public void fillDiagonal(final long row, final long col, final N value) { myBase.fillDiagonal(myRowOffset + row, myColumnOffset + col, value); } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { myBase.fillDiagonal(myRowOffset + row, myColumnOffset + col, supplier); } @@ -261,7 +259,7 @@ public void fillOne(final long row, final long col, final N value) { myBase.fillOne(myRowOffset + row, myColumnOffset + col, value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myBase.fillOne(myRowOffset + row, myColumnOffset + col, supplier); } @@ -269,7 +267,7 @@ public void fillRow(final long row, final long col, final N value) { myBase.fillRow(myRowOffset + row, myColumnOffset + col, value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myBase.fillRow(myRowOffset + row, myColumnOffset + col, supplier); } @@ -303,13 +301,13 @@ public void set(final long row, final long col, final double value) { myBase.set(myRowOffset + row, myColumnOffset + col, value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(myRowOffset + row, myColumnOffset + col, value); } } - abstract class ReceiverRegion implements TransformableRegion { + abstract class ReceiverRegion> implements TransformableRegion { private final TransformableRegion.FillByMultiplying myMultiplier; @@ -323,10 +321,10 @@ protected ReceiverRegion(final TransformableRegion.FillByMultiplying multipli super(); - if (multiplier instanceof PrimitiveMultiplyBoth) { - myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.getPrimitive(rows, columns); - } else if (multiplier instanceof GenericMultiplyBoth) { - myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.getGeneric(rows, columns); + if (multiplier instanceof MultiplyBoth.Primitive) { + myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.newPrimitive64(rows, columns); + } else if (multiplier instanceof MultiplyBoth.Generic) { + myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.newGeneric(rows, columns); } else { myMultiplier = multiplier; } @@ -369,7 +367,7 @@ public String toString() { } - class RowsRegion extends ReceiverRegion { + class RowsRegion> extends ReceiverRegion { private final TransformableRegion myBase; private final int[] myRows; @@ -384,7 +382,7 @@ public void add(final long row, final long col, final double addend) { myBase.add(myRows[(int) row], col, addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(myRows[(int) row], col, addend); } @@ -408,7 +406,7 @@ public void fillOne(final long row, final long col, final N value) { myBase.fillOne(myRows[(int) row], col, value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myBase.fillOne(myRows[(int) row], col, supplier); } @@ -420,7 +418,7 @@ public void fillRow(final long row, final long col, final N value) { myBase.fillRow(myRows[(int) row], col, value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myBase.fillRow(myRows[(int) row], col, supplier); } @@ -440,13 +438,13 @@ public void set(final long row, final long col, final double value) { myBase.set(myRows[(int) row], col, value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(myRows[(int) row], col, value); } } - class TransposedRegion extends ReceiverRegion { + class TransposedRegion> extends ReceiverRegion { private final TransformableRegion myBase; @@ -459,7 +457,7 @@ public void add(final long row, final long col, final double addend) { myBase.add(col, row, addend); } - public void add(final long row, final long col, final Number addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(col, row, addend); } @@ -479,7 +477,7 @@ public void fillColumn(final long row, final long col, final N value) { myBase.fillRow(col, row, value); } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { myBase.fillRow(col, row, supplier); } @@ -487,7 +485,7 @@ public void fillDiagonal(final long row, final long col, final N value) { myBase.fillDiagonal(col, row, value); } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { myBase.fillRow(col, row, supplier); } @@ -499,7 +497,7 @@ public void fillOne(final long row, final long col, final N value) { myBase.fillOne(col, row, value); } - public void fillOne(final long row, final long col, final NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myBase.fillOne(col, row, supplier); } @@ -507,7 +505,7 @@ public void fillRow(final long row, final long col, final N value) { myBase.fillDiagonal(col, row, value); } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myBase.fillDiagonal(col, row, supplier); } @@ -540,7 +538,7 @@ public void set(final long row, final long col, final double value) { myBase.set(col, row, value); } - public void set(final long row, final long col, final Number value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(col, row, value); } diff --git a/src/org/ojalgo/matrix/store/TransjugatedStore.java b/src/org/ojalgo/matrix/store/TransjugatedStore.java index 4630431bc..fad98402b 100644 --- a/src/org/ojalgo/matrix/store/TransjugatedStore.java +++ b/src/org/ojalgo/matrix/store/TransjugatedStore.java @@ -23,7 +23,7 @@ import org.ojalgo.ProgrammingError; -abstract class TransjugatedStore extends LogicalStore { +abstract class TransjugatedStore> extends LogicalStore { private TransjugatedStore(final MatrixStore base, final int rows, final int columns) { diff --git a/src/org/ojalgo/matrix/store/TransposedStore.java b/src/org/ojalgo/matrix/store/TransposedStore.java index a45aef8ee..d7a5a4287 100644 --- a/src/org/ojalgo/matrix/store/TransposedStore.java +++ b/src/org/ojalgo/matrix/store/TransposedStore.java @@ -26,7 +26,7 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; -final class TransposedStore extends TransjugatedStore { +final class TransposedStore> extends TransjugatedStore { TransposedStore(final MatrixStore base) { super(base); diff --git a/src/org/ojalgo/matrix/store/UnaryOperatoStore.java b/src/org/ojalgo/matrix/store/UnaryOperatoStore.java index 3cd812f5b..a05784617 100644 --- a/src/org/ojalgo/matrix/store/UnaryOperatoStore.java +++ b/src/org/ojalgo/matrix/store/UnaryOperatoStore.java @@ -23,7 +23,7 @@ import org.ojalgo.function.UnaryFunction; -final class UnaryOperatoStore extends LogicalStore { +final class UnaryOperatoStore> extends LogicalStore { private final UnaryFunction myOperator; diff --git a/src/org/ojalgo/matrix/store/UpperHermitianStore.java b/src/org/ojalgo/matrix/store/UpperHermitianStore.java index 3ea18c493..fe2725850 100644 --- a/src/org/ojalgo/matrix/store/UpperHermitianStore.java +++ b/src/org/ojalgo/matrix/store/UpperHermitianStore.java @@ -23,7 +23,7 @@ import org.ojalgo.scalar.Scalar; -final class UpperHermitianStore extends ShadingStore { +final class UpperHermitianStore> extends ShadingStore { UpperHermitianStore(final MatrixStore base) { super(base, Math.min(base.countRows(), base.countColumns()), base.countColumns()); diff --git a/src/org/ojalgo/matrix/store/UpperHessenbergStore.java b/src/org/ojalgo/matrix/store/UpperHessenbergStore.java index eb70d0c0e..5a5034b3c 100644 --- a/src/org/ojalgo/matrix/store/UpperHessenbergStore.java +++ b/src/org/ojalgo/matrix/store/UpperHessenbergStore.java @@ -30,7 +30,7 @@ * * @author apete */ -final class UpperHessenbergStore extends ShadingStore { +final class UpperHessenbergStore> extends ShadingStore { UpperHessenbergStore(final MatrixStore base) { super(base, Math.min(base.countRows(), base.countColumns()), base.countColumns()); diff --git a/src/org/ojalgo/matrix/store/UpperTriangularStore.java b/src/org/ojalgo/matrix/store/UpperTriangularStore.java index cc50d8075..e46056e9a 100644 --- a/src/org/ojalgo/matrix/store/UpperTriangularStore.java +++ b/src/org/ojalgo/matrix/store/UpperTriangularStore.java @@ -24,7 +24,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.scalar.Scalar; -final class UpperTriangularStore extends ShadingStore { +final class UpperTriangularStore> extends ShadingStore { private final boolean myUnitDiagonal; diff --git a/src/org/ojalgo/matrix/store/WrapperStore.java b/src/org/ojalgo/matrix/store/WrapperStore.java index 6adb18afe..e7923bb2b 100644 --- a/src/org/ojalgo/matrix/store/WrapperStore.java +++ b/src/org/ojalgo/matrix/store/WrapperStore.java @@ -28,7 +28,7 @@ /** * @author apete */ -final class WrapperStore extends FactoryStore { +final class WrapperStore> extends FactoryStore { private final Access2D myAccess; diff --git a/src/org/ojalgo/matrix/store/ZeroStore.java b/src/org/ojalgo/matrix/store/ZeroStore.java index 85a2a92c0..6b3288301 100644 --- a/src/org/ojalgo/matrix/store/ZeroStore.java +++ b/src/org/ojalgo/matrix/store/ZeroStore.java @@ -30,7 +30,7 @@ * * @author apete */ -final class ZeroStore extends FactoryStore { +final class ZeroStore> extends FactoryStore { ZeroStore(final PhysicalStore.Factory factory, final int rowsCount, final int columnsCount) { super(factory, rowsCount, columnsCount); diff --git a/src/org/ojalgo/matrix/task/AbstractInverter.java b/src/org/ojalgo/matrix/task/AbstractInverter.java index 46ecd3e68..78ff1faeb 100644 --- a/src/org/ojalgo/matrix/task/AbstractInverter.java +++ b/src/org/ojalgo/matrix/task/AbstractInverter.java @@ -27,7 +27,7 @@ import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure2D; @@ -739,11 +739,11 @@ static void symmetric5X5(final Access2D source, final PhysicalStore destin } public final MatrixStore invert(final Access2D original) throws RecoverableCondition { - return this.invert(original, PrimitiveDenseStore.FACTORY.makeZero(this.dim(), this.dim())); + return this.invert(original, Primitive64Store.FACTORY.makeZero(this.dim(), this.dim())); } public final PhysicalStore preallocate(final Structure2D template) { - return PrimitiveDenseStore.FACTORY.makeZero(this.dim(), this.dim()); + return Primitive64Store.FACTORY.makeZero(this.dim(), this.dim()); } abstract long dim(); diff --git a/src/org/ojalgo/matrix/task/AbstractSolver.java b/src/org/ojalgo/matrix/task/AbstractSolver.java index b86fa3b7f..114393031 100644 --- a/src/org/ojalgo/matrix/task/AbstractSolver.java +++ b/src/org/ojalgo/matrix/task/AbstractSolver.java @@ -25,7 +25,7 @@ import org.ojalgo.function.special.MissingMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure2D; @@ -433,14 +433,14 @@ static void full5X5(final Access2D body, final Access1D rhs, final Physica static void leastSquares(final Access2D body, final Access1D rhs, final PhysicalStore solution) { - final PrimitiveDenseStore tmpTranspBody = PrimitiveDenseStore.FACTORY.transpose(body); + final Primitive64Store tmpTranspBody = Primitive64Store.FACTORY.transpose(body); final int tmpCountRows = (int) tmpTranspBody.countRows(); - final PrimitiveDenseStore tmpBody = PrimitiveDenseStore.FACTORY.makeZero(tmpCountRows, tmpCountRows); + final Primitive64Store tmpBody = Primitive64Store.FACTORY.makeZero(tmpCountRows, tmpCountRows); tmpTranspBody.multiply(tmpTranspBody.transpose(), tmpBody); - final PrimitiveDenseStore tmpRHS = PrimitiveDenseStore.FACTORY.makeZero(tmpCountRows, solution.countColumns()); + final Primitive64Store tmpRHS = Primitive64Store.FACTORY.makeZero(tmpCountRows, solution.countColumns()); tmpTranspBody.multiply((Access1D) rhs, tmpRHS); switch (tmpCountRows) { @@ -706,7 +706,7 @@ static void symmetric5X5(final Access2D body, final Access1D rhs, final Ph } public final PhysicalStore preallocate(final Structure2D templateBody, final Structure2D templateRHS) { - return PrimitiveDenseStore.FACTORY.makeZero(templateBody.countColumns(), 1L); + return Primitive64Store.FACTORY.makeZero(templateBody.countColumns(), 1L); } } diff --git a/src/org/ojalgo/matrix/task/DeterminantTask.java b/src/org/ojalgo/matrix/task/DeterminantTask.java index 0f4433eef..fb27e26ff 100644 --- a/src/org/ojalgo/matrix/task/DeterminantTask.java +++ b/src/org/ojalgo/matrix/task/DeterminantTask.java @@ -31,9 +31,9 @@ import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure2D; -public interface DeterminantTask extends MatrixTask { +public interface DeterminantTask> extends MatrixTask { - public static abstract class Factory { + public static abstract class Factory> { public final DeterminantTask make(final int dim, final boolean symmetric) { diff --git a/src/org/ojalgo/matrix/task/InverterTask.java b/src/org/ojalgo/matrix/task/InverterTask.java index fd34cc8bf..654e1cf29 100644 --- a/src/org/ojalgo/matrix/task/InverterTask.java +++ b/src/org/ojalgo/matrix/task/InverterTask.java @@ -35,9 +35,9 @@ import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure2D; -public interface InverterTask extends MatrixTask { +public interface InverterTask> extends MatrixTask { - public static abstract class Factory { + public static abstract class Factory> { public MatrixStore invert(final Access2D original) throws RecoverableCondition { return this.make(original, false, false).invert(original); diff --git a/src/org/ojalgo/matrix/task/MatrixTask.java b/src/org/ojalgo/matrix/task/MatrixTask.java index 880f479cb..852d2aa3a 100644 --- a/src/org/ojalgo/matrix/task/MatrixTask.java +++ b/src/org/ojalgo/matrix/task/MatrixTask.java @@ -21,6 +21,6 @@ */ package org.ojalgo.matrix.task; -public interface MatrixTask { +public interface MatrixTask> { } diff --git a/src/org/ojalgo/matrix/task/SolverTask.java b/src/org/ojalgo/matrix/task/SolverTask.java index d22086f6e..0f0cba754 100644 --- a/src/org/ojalgo/matrix/task/SolverTask.java +++ b/src/org/ojalgo/matrix/task/SolverTask.java @@ -35,9 +35,9 @@ import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure2D; -public interface SolverTask extends MatrixTask { +public interface SolverTask> extends MatrixTask { - public static abstract class Factory { + public static abstract class Factory> { public SolverTask make(final int numberOfEquations, final int numberOfVariables, final int numberOfSolutions, final boolean symmetric, final boolean positiveDefinite) { diff --git a/src/org/ojalgo/matrix/task/iterative/ConjugateGradientSolver.java b/src/org/ojalgo/matrix/task/iterative/ConjugateGradientSolver.java index 7ba9891fe..a182a72ea 100644 --- a/src/org/ojalgo/matrix/task/iterative/ConjugateGradientSolver.java +++ b/src/org/ojalgo/matrix/task/iterative/ConjugateGradientSolver.java @@ -29,7 +29,7 @@ import org.ojalgo.equation.Equation; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure1D; import org.ojalgo.type.context.NumberContext; @@ -41,10 +41,10 @@ */ public final class ConjugateGradientSolver extends KrylovSubspaceSolver implements IterativeSolverTask.SparseDelegate { - private transient PrimitiveDenseStore myDirection = null; - private transient PrimitiveDenseStore myPreconditioned = null; - private transient PrimitiveDenseStore myResidual = null; - private transient PrimitiveDenseStore myVector = null; + private transient Primitive64Store myDirection = null; + private transient Primitive64Store myPreconditioned = null; + private transient Primitive64Store myResidual = null; + private transient Primitive64Store myVector = null; public ConjugateGradientSolver() { super(); @@ -57,10 +57,10 @@ public double resolve(final List equations, final PhysicalStore solve(final Access2D body, final Access2D rhs, return preallocated; } - private PrimitiveDenseStore direction(final Structure1D structure) { + private Primitive64Store direction(final Structure1D structure) { if ((myDirection == null) || (myDirection.count() != structure.count())) { - myDirection = PrimitiveDenseStore.FACTORY.makeZero(structure.count(), 1L); + myDirection = Primitive64Store.FACTORY.makeZero(structure.count(), 1L); } else { myDirection.fillAll(ZERO); } return myDirection; } - private PrimitiveDenseStore preconditioned(final Structure1D structure) { + private Primitive64Store preconditioned(final Structure1D structure) { if ((myPreconditioned == null) || (myPreconditioned.count() != structure.count())) { - myPreconditioned = PrimitiveDenseStore.FACTORY.makeZero(structure.count(), 1L); + myPreconditioned = Primitive64Store.FACTORY.makeZero(structure.count(), 1L); } else { myPreconditioned.fillAll(ZERO); } return myPreconditioned; } - private PrimitiveDenseStore residual(final Structure1D structure) { + private Primitive64Store residual(final Structure1D structure) { if ((myResidual == null) || (myResidual.count() != structure.count())) { - myResidual = PrimitiveDenseStore.FACTORY.makeZero(structure.count(), 1L); + myResidual = Primitive64Store.FACTORY.makeZero(structure.count(), 1L); } else { myResidual.fillAll(ZERO); } return myResidual; } - private PrimitiveDenseStore vector(final Structure1D structure) { + private Primitive64Store vector(final Structure1D structure) { if ((myVector == null) || (myVector.count() != structure.count())) { - myVector = PrimitiveDenseStore.FACTORY.makeZero(structure.count(), 1L); + myVector = Primitive64Store.FACTORY.makeZero(structure.count(), 1L); } else { myVector.fillAll(ZERO); } diff --git a/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java b/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java index 95b564a89..bb4398427 100644 --- a/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java +++ b/src/org/ojalgo/matrix/task/iterative/IterativeSolverTask.java @@ -33,7 +33,7 @@ import org.ojalgo.equation.Equation; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.task.SolverTask; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.PrimitiveScalar; @@ -134,7 +134,7 @@ public final PhysicalStore preallocate(final Structure2D templateBody, f if (templateRHS.countColumns() != 1L) { throw new IllegalArgumentException("The RHS must have precisely 1 column!"); } - return PrimitiveDenseStore.FACTORY.make(templateBody.countColumns(), 1L); + return Primitive64Store.FACTORY.make(templateBody.countColumns(), 1L); } public final Optional> solve(final MatrixStore body, final MatrixStore rhs) { diff --git a/src/org/ojalgo/matrix/task/iterative/JacobiSolver.java b/src/org/ojalgo/matrix/task/iterative/JacobiSolver.java index 3d7cd6508..15624b1cf 100644 --- a/src/org/ojalgo/matrix/task/iterative/JacobiSolver.java +++ b/src/org/ojalgo/matrix/task/iterative/JacobiSolver.java @@ -27,7 +27,7 @@ import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.TransformableRegion; import org.ojalgo.structure.Access2D; import org.ojalgo.type.context.NumberContext; @@ -45,15 +45,15 @@ public MatrixStore solve(final Access2D body, final Access2D rhs, if ((body instanceof MatrixStore) && (body.get(0L) instanceof Double)) { tmpBody = (MatrixStore) body; } else { - tmpBody = MatrixStore.PRIMITIVE.makeWrapper(body).get(); + tmpBody = MatrixStore.PRIMITIVE64.makeWrapper(body).get(); } - final MatrixStore tmpBodyDiagonal = PrimitiveDenseStore.FACTORY.columns(tmpBody.sliceDiagonal()); + final MatrixStore tmpBodyDiagonal = Primitive64Store.FACTORY.columns(tmpBody.sliceDiagonal()); MatrixStore tmpRHS = null; if ((rhs instanceof MatrixStore) && (rhs.get(0L) instanceof Double)) { tmpRHS = (MatrixStore) rhs; } else { - tmpRHS = MatrixStore.PRIMITIVE.makeWrapper(rhs).get(); + tmpRHS = MatrixStore.PRIMITIVE64.makeWrapper(rhs).get(); } final PhysicalStore tmpIncrement = this.preallocate(body, rhs); diff --git a/src/org/ojalgo/matrix/transformation/Householder.java b/src/org/ojalgo/matrix/transformation/Householder.java index 444d2f624..9a30f6422 100644 --- a/src/org/ojalgo/matrix/transformation/Householder.java +++ b/src/org/ojalgo/matrix/transformation/Householder.java @@ -27,9 +27,9 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; -public interface Householder extends Access1D { +public interface Householder> extends Access1D { - public static final class Generic> extends Object implements Householder { + public static final class Generic> implements Householder { public N beta; public int first; @@ -131,20 +131,20 @@ public String toString() { } - public static final class Primitive extends Object implements Householder { + public static final class Primitive64 implements Householder { public double beta; public int first; public final double[] vector; - public Primitive(final Householder aTransf) { + public Primitive64(final Householder aTransf) { this((int) aTransf.count()); this.copy(aTransf); } - public Primitive(final int aDim) { + public Primitive64(final int aDim) { super(); @@ -153,7 +153,7 @@ public Primitive(final int aDim) { first = 0; } - public Householder.Primitive copy(final Householder source) { + public Householder.Primitive64 copy(final Householder source) { first = source.first(); @@ -171,7 +171,7 @@ public Householder.Primitive copy(final Householder source) { return this; } - public Householder.Primitive copy(final Householder source, final double precalculatedBeta) { + public Householder.Primitive64 copy(final Householder source, final double precalculatedBeta) { first = source.first(); @@ -222,6 +222,97 @@ public String toString() { } + public static final class Primitive32 implements Householder { + + public float beta; + public int first; + public final float[] vector; + + public Primitive32(final Householder aTransf) { + + this((int) aTransf.count()); + + this.copy(aTransf); + } + + public Primitive32(final int aDim) { + + super(); + + vector = new float[aDim]; + beta = (float) PrimitiveMath.ZERO; + first = 0; + } + + public Householder.Primitive32 copy(final Householder source) { + + first = source.first(); + + final float[] tmpVector = vector; + float tmpVal, tmpVal2 = (float) PrimitiveMath.ZERO; + final int tmpSize = (int) source.count(); + for (int i = source.first(); i < tmpSize; i++) { + tmpVal = source.floatValue(i); + tmpVal2 += tmpVal * tmpVal; + tmpVector[i] = tmpVal; + } + + beta = (float) PrimitiveMath.TWO / tmpVal2; + + return this; + } + + public Householder.Primitive32 copy(final Householder source, final float precalculatedBeta) { + + first = source.first(); + + final float[] tmpVector = vector; + + final int tmpSize = (int) source.count(); + for (int i = source.first(); i < tmpSize; i++) { + tmpVector[i] = source.floatValue(i); + } + + beta = precalculatedBeta; + + return this; + } + + public long count() { + return vector.length; + } + + public double doubleValue(final long anInd) { + return vector[(int) anInd]; + } + + public int first() { + return first; + } + + public Double get(final long index) { + return Double.valueOf(vector[(int) index]); + } + + @Override + public String toString() { + + final StringBuilder retVal = new StringBuilder("{ "); + + final int tmpLastIndex = vector.length - 1; + for (int i = 0; i < tmpLastIndex; i++) { + retVal.append(this.get(i)); + retVal.append(", "); + } + retVal.append(this.get(tmpLastIndex)); + + retVal.append(" }"); + + return retVal.toString(); + } + + } + /** * Regardless of what is actually returned by {@linkplain #doubleValue(long)} and/or * {@linkplain #get(long)} vector elements with indeces less than 'first' should be assumed to be, and diff --git a/src/org/ojalgo/matrix/transformation/HouseholderColumn.java b/src/org/ojalgo/matrix/transformation/HouseholderColumn.java index b42d0def8..ddb1d08f2 100644 --- a/src/org/ojalgo/matrix/transformation/HouseholderColumn.java +++ b/src/org/ojalgo/matrix/transformation/HouseholderColumn.java @@ -5,7 +5,7 @@ import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.structure.ColumnView; -final class HouseholderColumn extends ColumnView implements HouseholderReference { +final class HouseholderColumn> extends ColumnView implements HouseholderReference { private int myFirst = 0; private final MatrixStore myStore; diff --git a/src/org/ojalgo/matrix/transformation/HouseholderReference.java b/src/org/ojalgo/matrix/transformation/HouseholderReference.java index 6a4d99838..3fc5793bd 100644 --- a/src/org/ojalgo/matrix/transformation/HouseholderReference.java +++ b/src/org/ojalgo/matrix/transformation/HouseholderReference.java @@ -3,17 +3,17 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -public interface HouseholderReference extends Householder { +public interface HouseholderReference> extends Householder { - static HouseholderReference make(final MatrixStore matrix, final boolean column) { + static > HouseholderReference make(final MatrixStore matrix, final boolean column) { return column ? new HouseholderColumn<>(matrix) : new HouseholderRow<>(matrix); } - static HouseholderReference makeColumn(final MatrixStore matrix) { + static > HouseholderReference makeColumn(final MatrixStore matrix) { return new HouseholderColumn<>(matrix); } - static HouseholderReference makeRow(final MatrixStore matrix) { + static > HouseholderReference makeRow(final MatrixStore matrix) { return new HouseholderRow<>(matrix); } diff --git a/src/org/ojalgo/matrix/transformation/HouseholderRow.java b/src/org/ojalgo/matrix/transformation/HouseholderRow.java index 3f6a3c4b8..beba34d20 100644 --- a/src/org/ojalgo/matrix/transformation/HouseholderRow.java +++ b/src/org/ojalgo/matrix/transformation/HouseholderRow.java @@ -5,7 +5,7 @@ import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.structure.RowView; -final class HouseholderRow extends RowView implements HouseholderReference { +final class HouseholderRow> extends RowView implements HouseholderReference { private int myFirst = 0; private final MatrixStore myStore; diff --git a/src/org/ojalgo/matrix/transformation/Rotation.java b/src/org/ojalgo/matrix/transformation/Rotation.java index eb0024c47..502d87ebf 100644 --- a/src/org/ojalgo/matrix/transformation/Rotation.java +++ b/src/org/ojalgo/matrix/transformation/Rotation.java @@ -28,9 +28,9 @@ import org.ojalgo.scalar.PrimitiveScalar; import org.ojalgo.scalar.Scalar; -public abstract class Rotation { +public abstract class Rotation> { - public static final class Generic> extends Rotation { + public static final class Generic> extends Rotation { public final N cos; public final N sin; @@ -151,8 +151,7 @@ public Primitive invert() { } - public static > Generic makeGeneric(final FunctionSet functions, final int aLowerIndex, final int aHigherIndex, - final N anAngle) { + public static > Generic makeGeneric(final FunctionSet functions, final int aLowerIndex, final int aHigherIndex, final N anAngle) { return new Generic<>(aLowerIndex, aHigherIndex, functions.cos().invoke(anAngle), functions.sin().invoke(anAngle)); } diff --git a/src/org/ojalgo/netio/BasicLogger.java b/src/org/ojalgo/netio/BasicLogger.java index d805e9873..4823bcf1d 100644 --- a/src/org/ojalgo/netio/BasicLogger.java +++ b/src/org/ojalgo/netio/BasicLogger.java @@ -827,7 +827,7 @@ private static void printmtrx(final Printer appender, final Access2D matrix, final String[][] tmpElements = new String[tmpRowDim][tmpColDim]; int tmpWidth = 0; - Number tmpElementNumber; + Comparable tmpElementNumber; String tmpElementString; for (int j = 0; j < tmpColDim; j++) { for (int i = 0; i < tmpRowDim; i++) { @@ -854,18 +854,18 @@ private static void printmtrx(final Printer appender, final Access2D matrix, } - private static String toString(final Number number, final NumberContext context, final boolean plain) { + private static String toString(final Comparable number, final NumberContext context, final boolean plain) { if (plain) { if (number instanceof Scalar) { return ((Scalar) number).toPlainString(context); } else { - return context.enforce(new BigDecimal(number.doubleValue())).toPlainString(); + return context.enforce(new BigDecimal(Scalar.doubleValue(number))).toPlainString(); } } else { if (number instanceof Scalar) { return ((Scalar) number).toString(context); } else { - return context.enforce(new BigDecimal(number.doubleValue())).toString(); + return context.enforce(new BigDecimal(Scalar.doubleValue(number))).toString(); } } } diff --git a/src/org/ojalgo/netio/DelimitedData.java b/src/org/ojalgo/netio/DelimitedData.java index da7f76b7d..aaf316671 100644 --- a/src/org/ojalgo/netio/DelimitedData.java +++ b/src/org/ojalgo/netio/DelimitedData.java @@ -29,7 +29,7 @@ * * @author apete */ -public final class DelimitedData extends Object { +public final class DelimitedData { public static DelimitedData makeCommaDelimited() { return new DelimitedData(ASCII.COMMA, LineTerminator.WINDOWS); diff --git a/src/org/ojalgo/optimisation/Expression.java b/src/org/ojalgo/optimisation/Expression.java index c8f44c778..61ff59d58 100644 --- a/src/org/ojalgo/optimisation/Expression.java +++ b/src/org/ojalgo/optimisation/Expression.java @@ -44,7 +44,7 @@ import org.ojalgo.function.multiary.PureQuadraticFunction; import org.ojalgo.function.multiary.QuadraticFunction; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Structure1D; @@ -63,9 +63,9 @@ *

*

* An expression is turned into a constraint by setting a lower and/or upper limit. Use - * {@linkplain Expression#lower(Number)}, {@linkplain Expression#upper(Number)} or - * {@linkplain Expression#level(Number)}. An expression is made part of (contributing to) the objective - * function by setting a contribution weight. Use {@linkplain Expression#weight(Number)}. The contribution + * {@linkplain Expression#lower(Comparable)}, {@linkplain Expression#upper(Comparable)} or + * {@linkplain Expression#level(Comparable)}. An expression is made part of (contributing to) the objective + * function by setting a contribution weight. Use {@linkplain Expression#weight(Comparable)}. The contribution * weight can be set to anything except zero (0.0). Often you may just want to set it to one (1.0). Other * values can be used to balance multiple expressions contributing to the objective function. *

@@ -128,7 +128,7 @@ protected Expression(final Expression expressionToCopy, final ExpressionsBasedMo ProgrammingError.throwIfNull(myModel, myLinear, myQuadratic); } - public Expression add(final IntIndex key, final Number value) { + public Expression add(final IntIndex key, final Comparable value) { final BigDecimal tmpExisting = myLinear.get(key); @@ -141,7 +141,7 @@ public Expression add(final IntIndex key, final Number value) { return this; } - public Expression add(final IntRowColumn key, final Number value) { + public Expression add(final IntRowColumn key, final Comparable value) { final BigDecimal tmpExisting = myQuadratic.get(key); @@ -295,7 +295,7 @@ public BigDecimal get(final Variable variable) { public MatrixStore getAdjustedGradient(final Access1D point) { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(myModel.countVariables(), 1); + final Primitive64Store retVal = Primitive64Store.FACTORY.makeZero(myModel.countVariables(), 1); final BinaryFunction tmpBaseFunc = PrimitiveMath.ADD; double tmpAdjustedFactor; @@ -320,7 +320,7 @@ public MatrixStore getAdjustedGradient(final Access1D point) { public MatrixStore getAdjustedHessian() { final int tmpCountVariables = myModel.countVariables(); - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(tmpCountVariables, tmpCountVariables); + final Primitive64Store retVal = Primitive64Store.FACTORY.makeZero(tmpCountVariables, tmpCountVariables); final BinaryFunction tmpBaseFunc = PrimitiveMath.ADD; UnaryFunction tmpModFunc; @@ -425,19 +425,19 @@ public boolean isLinearAndAnyInteger() { return (myQuadratic.size() == 0) && (myLinear.size() > 0) && myLinear.keySet().stream().anyMatch(i -> myModel.getVariable(i).isInteger()); } - public Expression set(final int row, final int column, final Number value) { + public Expression set(final int row, final int column, final Comparable value) { return this.set(new IntRowColumn(row, column), value); } - public Expression set(final int index, final Number value) { + public Expression set(final int index, final Comparable value) { return this.set(myModel.getVariable(index), value); } - public Expression set(final IntIndex row, final IntIndex column, final Number value) { + public Expression set(final IntIndex row, final IntIndex column, final Comparable value) { return this.set(new IntRowColumn(row, column), value); } - public Expression set(final IntIndex key, final Number value) { + public Expression set(final IntIndex key, final Comparable value) { if (key != null) { @@ -458,7 +458,7 @@ public Expression set(final IntIndex key, final Number value) { return this; } - public Expression set(final IntRowColumn key, final Number value) { + public Expression set(final IntRowColumn key, final Comparable value) { if (key != null) { @@ -480,11 +480,11 @@ public Expression set(final IntRowColumn key, final Number value) { return this; } - public Expression set(final Variable variable, final Number value) { + public Expression set(final Variable variable, final Comparable value) { return this.set(variable.getIndex(), value); } - public Expression set(final Variable variable1, final Variable variable2, final Number value) { + public Expression set(final Variable variable1, final Variable variable2, final Comparable value) { return this.set(variable1.getIndex().index, variable2.getIndex().index, value); } diff --git a/src/org/ojalgo/optimisation/ExpressionsBasedModel.java b/src/org/ojalgo/optimisation/ExpressionsBasedModel.java index f056db66f..97355d8c5 100644 --- a/src/org/ojalgo/optimisation/ExpressionsBasedModel.java +++ b/src/org/ojalgo/optimisation/ExpressionsBasedModel.java @@ -47,9 +47,9 @@ * Lets you construct optimisation problems by combining (mathematical) expressions in terms of variables. * Each expression or variable can be a constraint and/or contribute to the objective function. An expression * or variable is turned into a constraint by setting a lower and/or upper limit. Use - * {@linkplain Expression#lower(Number)}, {@linkplain Expression#upper(Number)} or - * {@linkplain Expression#level(Number)}. An expression or variable is made part of (contributing to) the - * objective function by setting a contribution weight. Use {@linkplain Expression#weight(Number)}. + * {@linkplain Expression#lower(Comparable)}, {@linkplain Expression#upper(Comparable)} or + * {@linkplain Expression#level(Comparable)}. An expression or variable is made part of (contributing to) the + * objective function by setting a contribution weight. Use {@linkplain Expression#weight(Comparable)}. *

*

* You may think of variables as simple (the simplest possible) expressions, and of expressions as weighted @@ -1063,8 +1063,8 @@ public Optimisation.Result minimise() { /** * This is generated on demend – you should not cache this. More specifically, modifications made to this * expression will not be part of the optimisation model. You define the objective by setting the - * {@link Variable#weight(Number)}/{@link Expression#weight(Number)} on one or more variables and/or - * expressions. + * {@link Variable#weight(Comparable)}/{@link Expression#weight(Comparable)} on one or more variables + * and/or expressions. * * @return The generated/aggregated objective function */ @@ -1097,8 +1097,7 @@ public Expression objective() { tmpOldVal = retVal.get(tmpKey); tmpDiff = tmpExpression.get(tmpKey); tmpNewVal = tmpOldVal.add(tmpNotOne ? tmpContributionWeight.multiply(tmpDiff) : tmpDiff); - final Number value = tmpNewVal; - retVal.set(tmpKey, value); + retVal.set(tmpKey, tmpNewVal); } } @@ -1107,8 +1106,7 @@ public Expression objective() { tmpOldVal = retVal.get(tmpKey); tmpDiff = tmpExpression.get(tmpKey); tmpNewVal = tmpOldVal.add(tmpNotOne ? tmpContributionWeight.multiply(tmpDiff) : tmpDiff); - final Number value = tmpNewVal; - retVal.set(tmpKey, value); + retVal.set(tmpKey, tmpNewVal); } } } diff --git a/src/org/ojalgo/optimisation/GenericSolver.java b/src/org/ojalgo/optimisation/GenericSolver.java index 896cb3f6e..7111be0c3 100644 --- a/src/org/ojalgo/optimisation/GenericSolver.java +++ b/src/org/ojalgo/optimisation/GenericSolver.java @@ -29,7 +29,7 @@ import org.ojalgo.array.SparseArray; import org.ojalgo.function.multiary.MultiaryFunction; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RowsSupplier; import org.ojalgo.matrix.store.SparseStore; import org.ojalgo.netio.BasicLogger; @@ -159,7 +159,7 @@ public B inequalities(final Access2D mtrxAI, final MatrixStore m } else { - myAI = PrimitiveDenseStore.FACTORY.makeRowsSupplier((int) mtrxAI.countColumns()); + myAI = Primitive64Store.FACTORY.makeRowsSupplier((int) mtrxAI.countColumns()); myAI.addRows((int) mtrxAI.countRows()); if (mtrxAI instanceof SparseStore) { diff --git a/src/org/ojalgo/optimisation/MathProgSysModel.java b/src/org/ojalgo/optimisation/MathProgSysModel.java index 9fda0b269..01379967d 100644 --- a/src/org/ojalgo/optimisation/MathProgSysModel.java +++ b/src/org/ojalgo/optimisation/MathProgSysModel.java @@ -70,7 +70,7 @@ enum BoundType { BV(), FR(), FX(), LI(), LO(), MI(), PL(), SC(), UI(), UP(); } - final class Column extends Object { + final class Column { private boolean mySemicontinuous = false; private final Variable myVariable; @@ -217,7 +217,7 @@ enum FileSection { } - final class Row extends Object { + final class Row { private final Expression myExpression; diff --git a/src/org/ojalgo/optimisation/ModelEntity.java b/src/org/ojalgo/optimisation/ModelEntity.java index 842602823..1af6e87c9 100644 --- a/src/org/ojalgo/optimisation/ModelEntity.java +++ b/src/org/ojalgo/optimisation/ModelEntity.java @@ -34,6 +34,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; import org.ojalgo.netio.BasicLogger; +import org.ojalgo.scalar.Scalar; import org.ojalgo.type.TypeUtils; import org.ojalgo.type.context.NumberContext; @@ -199,7 +200,7 @@ public final boolean isUpperLimitSet() { * @see #getLowerLimit() * @see #getUpperLimit() */ - public final ME level(final Number level) { + public final ME level(final Comparable level) { return this.lower(level).upper(level); } @@ -209,12 +210,12 @@ public final ME level(final Number level) { * are always used as they are. */ @SuppressWarnings("unchecked") - public ME lower(final Number lower) { + public ME lower(final Comparable lower) { myLowerLimit = null; if (lower != null) { if (lower instanceof BigDecimal) { myLowerLimit = (BigDecimal) lower; - } else if (Double.isFinite(lower.doubleValue())) { + } else if (Double.isFinite(Scalar.doubleValue(lower))) { BigDecimal limit = TypeUtils.toBigDecimal(lower); final BigDecimal magnitude = limit.abs(); if (magnitude.compareTo(LARGEST) >= 0) { @@ -244,12 +245,12 @@ public final String toString() { * are always used as they are. */ @SuppressWarnings("unchecked") - public ME upper(final Number upper) { + public ME upper(final Comparable upper) { myUpperLimit = null; if (upper != null) { if (upper instanceof BigDecimal) { myUpperLimit = (BigDecimal) upper; - } else if (Double.isFinite(upper.doubleValue())) { + } else if (Double.isFinite(Scalar.doubleValue(upper))) { BigDecimal limit = TypeUtils.toBigDecimal(upper); final BigDecimal magnitude = limit.abs(); if (magnitude.compareTo(LARGEST) >= 0) { @@ -267,13 +268,13 @@ public ME upper(final Number upper) { * @see #getContributionWeight() */ @SuppressWarnings("unchecked") - public final ME weight(final Number weight) { + public final ME weight(final Comparable weight) { myContributionWeight = null; if (weight != null) { BigDecimal tmpWeight = null; if (weight instanceof BigDecimal) { tmpWeight = (BigDecimal) weight; - } else if (Double.isFinite(weight.doubleValue())) { + } else if (Double.isFinite(Scalar.doubleValue(weight))) { tmpWeight = TypeUtils.toBigDecimal(weight); } if ((tmpWeight != null) && (tmpWeight.signum() != 0)) { diff --git a/src/org/ojalgo/optimisation/Variable.java b/src/org/ojalgo/optimisation/Variable.java index 44006a84e..9ec778512 100644 --- a/src/org/ojalgo/optimisation/Variable.java +++ b/src/org/ojalgo/optimisation/Variable.java @@ -171,7 +171,7 @@ public boolean isValueSet() { } @Override - public Variable lower(final Number lower) { + public Variable lower(final Comparable lower) { Variable retVal = super.lower(lower); this.assertFixedValue(); return retVal; @@ -197,7 +197,7 @@ public void setInteger(final boolean integer) { myInteger = integer; } - public void setValue(final Number value) { + public void setValue(final Comparable value) { BigDecimal tmpValue = null; if (value != null) { tmpValue = TypeUtils.toBigDecimal(value); @@ -212,7 +212,7 @@ public void setValue(final Number value) { } @Override - public Variable upper(final Number upper) { + public Variable upper(final Comparable upper) { Variable retVal = super.upper(upper); this.assertFixedValue(); return retVal; diff --git a/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java b/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java index 00b6dbfed..462e9cbe1 100644 --- a/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java +++ b/src/org/ojalgo/optimisation/convex/ActiveSetSolver.java @@ -31,7 +31,7 @@ import org.ojalgo.function.aggregator.PrimitiveAggregator; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RowsSupplier; import org.ojalgo.optimisation.GenericSolver; import org.ojalgo.structure.Access1D; @@ -46,10 +46,10 @@ abstract class ActiveSetSolver extends ConstrainedSolver { private final IndexSelector myActivator; private int myConstraintToInclude = -1; private MatrixStore myInvQC; - private final PrimitiveDenseStore myIterationX; + private final Primitive64Store myIterationX; private boolean myShrinkSwitch = true; - private final PrimitiveDenseStore mySlackI; - private final PrimitiveDenseStore mySolutionL; + private final Primitive64Store mySlackI; + private final Primitive64Store mySolutionL; ActiveSetSolver(final ConvexSolver.Builder matrices, final Options solverOptions) { @@ -61,13 +61,13 @@ abstract class ActiveSetSolver extends ConstrainedSolver { myActivator = new IndexSelector(numberOfInequalityConstraints); - mySolutionL = PrimitiveDenseStore.FACTORY.make(numberOfEqualityConstraints + numberOfInequalityConstraints, 1L); - myIterationX = PrimitiveDenseStore.FACTORY.make(numberOfVariables, 1L); + mySolutionL = Primitive64Store.FACTORY.make(numberOfEqualityConstraints + numberOfInequalityConstraints, 1L); + myIterationX = Primitive64Store.FACTORY.make(numberOfVariables, 1L); - mySlackI = PrimitiveDenseStore.FACTORY.make(numberOfInequalityConstraints, 1L); + mySlackI = Primitive64Store.FACTORY.make(numberOfInequalityConstraints, 1L); } - private void handleIterationSolution(final PrimitiveDenseStore iterX, final int[] excluded) { + private void handleIterationSolution(final Primitive64Store iterX, final int[] excluded) { // Subproblem solved successfully final PhysicalStore soluX = this.getSolutionX(); @@ -207,7 +207,7 @@ private final int suggestUsingLagrangeMagnitude() { final int[] incl = myActivator.getIncluded(); - final PrimitiveDenseStore soluL = this.getSolutionL(); + final Primitive64Store soluL = this.getSolutionL(); final int numbEqus = this.countEqualityConstraints(); int toExclude = incl[0]; @@ -524,7 +524,7 @@ final MatrixStore getIterationA() { final int numbVars = this.countVariables(); final int[] incl = myActivator.getIncluded(); - final PhysicalStore retVal = PrimitiveDenseStore.FACTORY.make(numbEqus + incl.length, numbVars); + final PhysicalStore retVal = Primitive64Store.FACTORY.make(numbEqus + incl.length, numbVars); if (numbEqus > 0) { this.getMatrixAE().supplyTo(retVal.regionByLimits(numbEqus, numbVars)); @@ -542,7 +542,7 @@ final MatrixStore getIterationB() { final int numbEqus = this.countEqualityConstraints(); final int[] incl = myActivator.getIncluded(); - final PhysicalStore retVal = PrimitiveDenseStore.FACTORY.make(numbEqus + incl.length, 1); + final PhysicalStore retVal = Primitive64Store.FACTORY.make(numbEqus + incl.length, 1); for (int i = 0; i < numbEqus; i++) { retVal.set(i, this.getMatrixBE().doubleValue(i)); @@ -576,7 +576,7 @@ MatrixStore getIterationL(final int[] included) { return mySolutionL.logical().limits(tmpCountE, 1).below(tmpLI).get(); } - PrimitiveDenseStore getIterationX() { + Primitive64Store getIterationX() { return myIterationX; } @@ -599,11 +599,11 @@ MatrixStore getSlackI(final int[] rows) { return this.getSlackI().logical().row(rows).get(); } - PrimitiveDenseStore getSolutionL() { + Primitive64Store getSolutionL() { return mySolutionL; } - final void handleIterationResults(final boolean solved, final PrimitiveDenseStore iterX, final int[] included, final int[] excluded) { + final void handleIterationResults(final boolean solved, final Primitive64Store iterX, final int[] included, final int[] excluded) { this.incrementIterationsCount(); @@ -664,7 +664,7 @@ void resetActivator(final boolean useLagrange) { final MatrixStore inqSlack = this.getSlackI(); final int[] excl = this.getExcluded(); - PrimitiveDenseStore lagrange = this.getSolutionL(); + Primitive64Store lagrange = this.getSolutionL(); for (int i = 0; i < excl.length; i++) { double slack = inqSlack.doubleValue(excl[i]); if (ACCURACY.isZero(slack) && (this.countIncluded() < maxToInclude)) { diff --git a/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java b/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java index 3da46303f..a559886ae 100644 --- a/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java +++ b/src/org/ojalgo/optimisation/convex/ConstrainedSolver.java @@ -25,12 +25,12 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D.Collectable; abstract class ConstrainedSolver extends ConvexSolver { - private final PrimitiveDenseStore mySlackE; + private final Primitive64Store mySlackE; protected ConstrainedSolver(final ConvexSolver.Builder matrices, final Options solverOptions) { @@ -38,7 +38,7 @@ protected ConstrainedSolver(final ConvexSolver.Builder matrices, final Options s int numberOfEqualityConstraints = this.countEqualityConstraints(); - mySlackE = PrimitiveDenseStore.FACTORY.make(numberOfEqualityConstraints, 1L); + mySlackE = Primitive64Store.FACTORY.make(numberOfEqualityConstraints, 1L); } @Override diff --git a/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java b/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java index 431af06be..ea5facfc0 100644 --- a/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java +++ b/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java @@ -87,7 +87,7 @@ public Double getConstant() { return myPureQuadratic.getConstant(); } - public void setConstant(final Number constant) { + public void setConstant(final Comparable constant) { myPureQuadratic.setConstant(constant); } diff --git a/src/org/ojalgo/optimisation/convex/ConvexSolver.java b/src/org/ojalgo/optimisation/convex/ConvexSolver.java index f0100d6d5..32e4156d0 100644 --- a/src/org/ojalgo/optimisation/convex/ConvexSolver.java +++ b/src/org/ojalgo/optimisation/convex/ConvexSolver.java @@ -33,14 +33,14 @@ import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.aggregator.Aggregator; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.matrix.decomposition.Cholesky; import org.ojalgo.matrix.decomposition.Eigenvalue; import org.ojalgo.matrix.decomposition.LU; import org.ojalgo.matrix.decomposition.MatrixDecomposition; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RowsSupplier; import org.ojalgo.matrix.store.SparseStore; import org.ojalgo.optimisation.Expression; @@ -187,17 +187,17 @@ public String toString() { final StringBuilder retVal = new StringBuilder("<" + simpleName + ">"); - retVal.append("\n[AE] = " + (this.getAE() != null ? PrimitiveMatrix.FACTORY.copy(this.getAE()) : "?")); + retVal.append("\n[AE] = " + (this.getAE() != null ? Primitive64Matrix.FACTORY.copy(this.getAE()) : "?")); - retVal.append("\n[BE] = " + (this.getBE() != null ? PrimitiveMatrix.FACTORY.copy(this.getBE()) : "?")); + retVal.append("\n[BE] = " + (this.getBE() != null ? Primitive64Matrix.FACTORY.copy(this.getBE()) : "?")); - retVal.append("\n[Q] = " + (myObjective != null ? PrimitiveMatrix.FACTORY.copy(this.getQ()) : "?")); + retVal.append("\n[Q] = " + (myObjective != null ? Primitive64Matrix.FACTORY.copy(this.getQ()) : "?")); - retVal.append("\n[C] = " + (myObjective != null ? PrimitiveMatrix.FACTORY.copy(this.getC()) : "?")); + retVal.append("\n[C] = " + (myObjective != null ? Primitive64Matrix.FACTORY.copy(this.getC()) : "?")); - retVal.append("\n[AI] = " + (this.getAI() != null ? PrimitiveMatrix.FACTORY.copy(this.getAI()) : "?")); + retVal.append("\n[AI] = " + (this.getAI() != null ? Primitive64Matrix.FACTORY.copy(this.getAI()) : "?")); - retVal.append("\n[BI] = " + (this.getBI() != null ? PrimitiveMatrix.FACTORY.copy(this.getBI()) : "?")); + retVal.append("\n[BI] = " + (this.getBI() != null ? Primitive64Matrix.FACTORY.copy(this.getBI()) : "?")); retVal.append("\n"); @@ -214,7 +214,7 @@ private Builder setObjective(final MatrixStore mtrxQ, final MatrixStore< PhysicalStore tmpC = null; if (mtrxQ == null) { - tmpQ = PrimitiveDenseStore.FACTORY.make(mtrxC.count(), mtrxC.count()); + tmpQ = Primitive64Store.FACTORY.make(mtrxC.count(), mtrxC.count()); } else if (mtrxQ instanceof PhysicalStore) { tmpQ = (PhysicalStore) mtrxQ; } else { @@ -222,7 +222,7 @@ private Builder setObjective(final MatrixStore mtrxQ, final MatrixStore< } if (mtrxC == null) { - tmpC = PrimitiveDenseStore.FACTORY.make(mtrxQ.countRows(), 1L); + tmpC = Primitive64Store.FACTORY.make(mtrxQ.countRows(), 1L); } else if (mtrxC instanceof PhysicalStore) { tmpC = (PhysicalStore) mtrxC; } else { @@ -296,8 +296,8 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol if (numbEqExpr > 0) { - final SparseStore mtrxAE = SparseStore.PRIMITIVE.make(numbEqExpr, numbVars); - final PhysicalStore mtrxBE = PrimitiveDenseStore.FACTORY.make(numbEqExpr, 1); + final SparseStore mtrxAE = SparseStore.PRIMITIVE64.make(numbEqExpr, numbVars); + final PhysicalStore mtrxBE = Primitive64Store.FACTORY.make(numbEqExpr, 1); for (int i = 0; i < numbEqExpr; i++) { @@ -321,7 +321,7 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol PhysicalStore mtrxQ = null; if (tmpObjExpr.isAnyQuadraticFactorNonZero()) { - mtrxQ = PrimitiveDenseStore.FACTORY.make(numbVars, numbVars); + mtrxQ = Primitive64Store.FACTORY.make(numbVars, numbVars); final BinaryFunction tmpBaseFunc = sourceModel.isMaximisation() ? SUBTRACT : ADD; UnaryFunction tmpModifier; @@ -338,7 +338,7 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol PhysicalStore mtrxC = null; if (tmpObjExpr.isAnyLinearFactorNonZero()) { - mtrxC = PrimitiveDenseStore.FACTORY.make(numbVars, 1); + mtrxC = Primitive64Store.FACTORY.make(numbVars, 1); if (sourceModel.isMinimisation()) { for (final IntIndex tmpKey : tmpObjExpr.getLinearKeySet()) { final int tmpIndex = sourceModel.indexOfFreeVariable(tmpKey.index); @@ -376,8 +376,8 @@ public static void copy(final ExpressionsBasedModel sourceModel, final ConvexSol if ((numbUpExpr + numbUpVar + numbLoExpr + numbLoVar) > 0) { - final RowsSupplier mtrxAI = PrimitiveDenseStore.FACTORY.makeRowsSupplier(numbVars); - final PhysicalStore mtrxBI = PrimitiveDenseStore.FACTORY.make(numbUpExpr + numbUpVar + numbLoExpr + numbLoVar, 1); + final RowsSupplier mtrxAI = Primitive64Store.FACTORY.makeRowsSupplier(numbVars); + final PhysicalStore mtrxBI = Primitive64Store.FACTORY.make(numbUpExpr + numbUpVar + numbLoExpr + numbLoVar, 1); if (numbUpExpr > 0) { for (int i = 0; i < numbUpExpr; i++) { @@ -438,7 +438,7 @@ public static Builder getBuilder(final MatrixStore Q, final MatrixStore< } private final ConvexSolver.Builder myMatrices; - private final PrimitiveDenseStore mySolutionX; + private final Primitive64Store mySolutionX; private final MatrixDecomposition.Solver mySolverGeneral; private final Cholesky mySolverQ; @@ -453,7 +453,7 @@ protected ConvexSolver(final ConvexSolver.Builder matrices, final Optimisation.O myMatrices = matrices; - mySolutionX = PrimitiveDenseStore.FACTORY.make(this.countVariables(), 1L); + mySolutionX = Primitive64Store.FACTORY.make(this.countVariables(), 1L); mySolverQ = Cholesky.PRIMITIVE.make(this.getMatrixQ()); mySolverGeneral = LU.PRIMITIVE.make(this.getMatrixQ()); diff --git a/src/org/ojalgo/optimisation/convex/DirectASS.java b/src/org/ojalgo/optimisation/convex/DirectASS.java index 66378fad7..6ec5d7375 100644 --- a/src/org/ojalgo/optimisation/convex/DirectASS.java +++ b/src/org/ojalgo/optimisation/convex/DirectASS.java @@ -25,7 +25,7 @@ import org.ojalgo.matrix.store.ElementsSupplier; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Optimisation; /** @@ -63,9 +63,9 @@ protected void performIteration() { final int numbConstr = this.countIterationConstraints(); final int numbVars = this.countVariables(); - final PrimitiveDenseStore iterX = this.getIterationX(); - final PrimitiveDenseStore iterL = PrimitiveDenseStore.FACTORY.makeZero(numbConstr, 1L); - final PrimitiveDenseStore soluL = this.getSolutionL(); + final Primitive64Store iterX = this.getIterationX(); + final Primitive64Store iterL = Primitive64Store.FACTORY.makeZero(numbConstr, 1L); + final Primitive64Store soluL = this.getSolutionL(); if ((numbConstr <= numbVars) && (solved = this.isSolvableQ())) { // Q is SPD @@ -113,7 +113,7 @@ protected void performIteration() { if (!solved) { // The above failed, try solving the full KKT system instaed - final PrimitiveDenseStore tmpXL = PrimitiveDenseStore.FACTORY.makeZero(numbVars + numbConstr, 1L); + final Primitive64Store tmpXL = Primitive64Store.FACTORY.makeZero(numbVars + numbConstr, 1L); if (solved = this.solveFullKKT(tmpXL)) { diff --git a/src/org/ojalgo/optimisation/convex/IterativeASS.java b/src/org/ojalgo/optimisation/convex/IterativeASS.java index 1e961d631..c7981fc7d 100644 --- a/src/org/ojalgo/optimisation/convex/IterativeASS.java +++ b/src/org/ojalgo/optimisation/convex/IterativeASS.java @@ -30,7 +30,7 @@ import org.ojalgo.matrix.store.ElementsSupplier; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.task.iterative.ConjugateGradientSolver; import org.ojalgo.matrix.task.iterative.MutableSolver; import org.ojalgo.optimisation.Optimisation; @@ -75,7 +75,7 @@ final class MyIterativeSolver extends MutableSolver imp myIterationRows = new Equation[myFullDim]; - myColumnE = PrimitiveDenseStore.FACTORY.make(myCountE, 1); + myColumnE = Primitive64Store.FACTORY.make(myCountE, 1); } @Override @@ -173,7 +173,7 @@ void remove(final int i) { super(matrices, solverOptions); myS = new MyIterativeSolver(); - myColumnS = PrimitiveDenseStore.FACTORY.make(this.countVariables(), 1); + myColumnS = Primitive64Store.FACTORY.make(this.countVariables(), 1); } private void addConstraint(final int constrIndex, final Access1D constrBody, final double constrRHS) { @@ -215,7 +215,7 @@ protected void performIteration() { this.addConstraint(constrIndex, constrBody, constrRHS); } - final PrimitiveDenseStore iterX = this.getIterationX(); + final Primitive64Store iterX = this.getIterationX(); if ((this.countIterationConstraints() <= this.countVariables()) && (solved = this.isSolvableQ())) { // Q is SPD @@ -244,7 +244,7 @@ protected void performIteration() { if (!solved) { // The above failed, try solving the full KKT system instaed - final PrimitiveDenseStore tmpXL = PrimitiveDenseStore.FACTORY.make(this.countVariables() + this.countIterationConstraints(), 1L); + final Primitive64Store tmpXL = Primitive64Store.FACTORY.make(this.countVariables() + this.countIterationConstraints(), 1L); if (solved = this.solveFullKKT(tmpXL)) { diff --git a/src/org/ojalgo/optimisation/convex/QPESolver.java b/src/org/ojalgo/optimisation/convex/QPESolver.java index fffb2f568..963ad1433 100644 --- a/src/org/ojalgo/optimisation/convex/QPESolver.java +++ b/src/org/ojalgo/optimisation/convex/QPESolver.java @@ -25,7 +25,7 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.GenericSolver; import org.ojalgo.optimisation.Optimisation; @@ -42,13 +42,13 @@ final class QPESolver extends ConstrainedSolver { private boolean myFeasible = false; - private final PrimitiveDenseStore myIterationX; + private final Primitive64Store myIterationX; QPESolver(final ConvexSolver.Builder matrices, final Optimisation.Options solverOptions) { super(matrices, solverOptions); - myIterationX = PrimitiveDenseStore.FACTORY.makeZero(this.countVariables(), 1L); + myIterationX = Primitive64Store.FACTORY.makeZero(this.countVariables(), 1L); } private boolean isFeasible() { @@ -103,8 +103,8 @@ protected void performIteration() { boolean solved = false; - final PrimitiveDenseStore tmpIterX = myIterationX; - final PrimitiveDenseStore tmpIterL = PrimitiveDenseStore.FACTORY.makeZero(tmpIterA.countRows(), 1L); + final Primitive64Store tmpIterX = myIterationX; + final Primitive64Store tmpIterL = Primitive64Store.FACTORY.makeZero(tmpIterA.countRows(), 1L); if ((tmpIterA.countRows() < tmpIterA.countColumns()) && (solved = this.isSolvableQ())) { // Q is SPD @@ -130,7 +130,7 @@ protected void performIteration() { if (!solved) { // The above failed, try solving the full KKT system instaed - final PrimitiveDenseStore tmpXL = PrimitiveDenseStore.FACTORY.makeZero(this.countVariables() + this.countIterationConstraints(), 1L); + final Primitive64Store tmpXL = Primitive64Store.FACTORY.makeZero(this.countVariables() + this.countIterationConstraints(), 1L); if (solved = this.solveFullKKT(tmpXL)) { tmpIterX.fillMatching(tmpXL.logical().limits(this.countVariables(), 1).get()); @@ -179,7 +179,7 @@ MatrixStore getIterationA() { @Override MatrixStore getIterationB() { if (myFeasible) { - return MatrixStore.PRIMITIVE.makeZero(this.countEqualityConstraints(), 1).get(); + return MatrixStore.PRIMITIVE64.makeZero(this.countEqualityConstraints(), 1).get(); } else { return this.getMatrixBE(); } diff --git a/src/org/ojalgo/optimisation/integer/IntegerSolver.java b/src/org/ojalgo/optimisation/integer/IntegerSolver.java index a60a22acf..3e8a99417 100644 --- a/src/org/ojalgo/optimisation/integer/IntegerSolver.java +++ b/src/org/ojalgo/optimisation/integer/IntegerSolver.java @@ -37,7 +37,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.multiary.MultiaryFunction; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.netio.CharacterRing; import org.ojalgo.netio.CharacterRing.PrinterBuffer; @@ -488,7 +488,7 @@ protected double evaluateFunction(final Access1D solution) { @Override protected MatrixStore extractSolution() { - return PrimitiveDenseStore.FACTORY.columns(this.getBestResultSoFar()); + return Primitive64Store.FACTORY.columns(this.getBestResultSoFar()); } protected Optimisation.Result getBestEstimate() { @@ -507,7 +507,7 @@ protected Optimisation.Result getBestResultSoFar() { final State tmpSate = State.INVALID; final double tmpValue = myMinimisation ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; - final MatrixStore tmpSolution = MatrixStore.PRIMITIVE.makeZero(this.getIntegerModel().countVariables(), 1).get(); + final MatrixStore tmpSolution = MatrixStore.PRIMITIVE64.makeZero(this.getIntegerModel().countVariables(), 1).get(); return new Optimisation.Result(tmpSate, tmpValue, tmpSolution); } diff --git a/src/org/ojalgo/optimisation/linear/LinearSolver.java b/src/org/ojalgo/optimisation/linear/LinearSolver.java index d079046de..43be9ac85 100644 --- a/src/org/ojalgo/optimisation/linear/LinearSolver.java +++ b/src/org/ojalgo/optimisation/linear/LinearSolver.java @@ -29,10 +29,10 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.array.Primitive64Array; import org.ojalgo.function.multiary.LinearFunction; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.ExpressionsBasedModel; import org.ojalgo.optimisation.GenericSolver; import org.ojalgo.optimisation.Optimisation; @@ -106,15 +106,15 @@ public String toString() { final StringBuilder retVal = new StringBuilder("<" + simpleName + ">"); - retVal.append("\n[AE] = " + (this.getAE() != null ? PrimitiveMatrix.FACTORY.copy(this.getAE()) : "?")); + retVal.append("\n[AE] = " + (this.getAE() != null ? Primitive64Matrix.FACTORY.copy(this.getAE()) : "?")); - retVal.append("\n[BE] = " + (this.getBE() != null ? PrimitiveMatrix.FACTORY.copy(this.getBE()) : "?")); + retVal.append("\n[BE] = " + (this.getBE() != null ? Primitive64Matrix.FACTORY.copy(this.getBE()) : "?")); - retVal.append("\n[C] = " + (myObjective != null ? PrimitiveMatrix.FACTORY.copy(this.getC()) : "?")); + retVal.append("\n[C] = " + (myObjective != null ? Primitive64Matrix.FACTORY.copy(this.getC()) : "?")); - retVal.append("\n[AI] = " + (this.getAI() != null ? PrimitiveMatrix.FACTORY.copy(this.getAI()) : "?")); + retVal.append("\n[AI] = " + (this.getAI() != null ? Primitive64Matrix.FACTORY.copy(this.getAI()) : "?")); - retVal.append("\n[BI] = " + (this.getBI() != null ? PrimitiveMatrix.FACTORY.copy(this.getBI()) : "?")); + retVal.append("\n[BI] = " + (this.getBI() != null ? Primitive64Matrix.FACTORY.copy(this.getBI()) : "?")); retVal.append("\n"); @@ -126,7 +126,7 @@ private Builder setObjective(final MatrixStore mtrxC) { PhysicalStore tmpC = null; if (mtrxC == null) { - tmpC = PrimitiveDenseStore.FACTORY.make(this.countVariables(), 1); + tmpC = Primitive64Store.FACTORY.make(this.countVariables(), 1); } else if (mtrxC instanceof PhysicalStore) { tmpC = (PhysicalStore) mtrxC; } else { diff --git a/src/org/ojalgo/optimisation/linear/SimplexSolver.java b/src/org/ojalgo/optimisation/linear/SimplexSolver.java index 61921deb7..0224f5ef7 100644 --- a/src/org/ojalgo/optimisation/linear/SimplexSolver.java +++ b/src/org/ojalgo/optimisation/linear/SimplexSolver.java @@ -31,7 +31,7 @@ import org.ojalgo.array.SparseArray.NonzeroView; import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.aggregator.PrimitiveAggregator; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.ExpressionsBasedModel; import org.ojalgo.optimisation.GenericSolver; import org.ojalgo.optimisation.Optimisation; @@ -211,7 +211,7 @@ protected Access1D extractSolution() { int colRHS = myTableau.countConstraints() + myTableau.countVariables(); - PrimitiveDenseStore solution = PrimitiveDenseStore.FACTORY.makeZero(myTableau.countVariables(), 1); + Primitive64Store solution = Primitive64Store.FACTORY.makeZero(myTableau.countVariables(), 1); int numberOfConstraints = myTableau.countConstraints(); for (int row = 0; row < numberOfConstraints; row++) { diff --git a/src/org/ojalgo/optimisation/linear/SimplexTableau.java b/src/org/ojalgo/optimisation/linear/SimplexTableau.java index 129f04171..8e6d7afb9 100644 --- a/src/org/ojalgo/optimisation/linear/SimplexTableau.java +++ b/src/org/ojalgo/optimisation/linear/SimplexTableau.java @@ -35,9 +35,10 @@ import org.ojalgo.function.UnaryFunction; import org.ojalgo.machine.JavaType; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Optimisation; import org.ojalgo.optimisation.linear.SimplexSolver.AlgorithmStore; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.ElementView1D; @@ -50,7 +51,7 @@ abstract class SimplexTableau implements AlgorithmStore, Access2D { static final class DenseTableau extends SimplexTableau { private final int myStructure; - private final PrimitiveDenseStore myTransposed; + private final Primitive64Store myTransposed; DenseTableau(final int numberOfConstraints, final int numberOfProblemVariables, final int numberOfSlackVariables) { @@ -59,7 +60,7 @@ static final class DenseTableau extends SimplexTableau { final int numbRows = numberOfConstraints + 2; final int numbCols = numberOfProblemVariables + numberOfSlackVariables + numberOfConstraints + 1; - myTransposed = PrimitiveDenseStore.FACTORY.makeZero(numbCols, numbRows); + myTransposed = Primitive64Store.FACTORY.makeZero(numbCols, numbRows); myStructure = (int) myTransposed.countRows(); } @@ -70,14 +71,14 @@ static final class DenseTableau extends SimplexTableau { final int tmpConstraintsCount = this.countConstraints(); final int tmpVariablesCount = this.countVariables(); - final MatrixStore.LogicalBuilder tmpTableauBuilder = MatrixStore.PRIMITIVE.makeZero(1, 1); - tmpTableauBuilder.left(matrices.getC().transpose().logical().right(MatrixStore.PRIMITIVE.makeZero(1, tmpConstraintsCount).get()).get()); + final MatrixStore.LogicalBuilder tmpTableauBuilder = MatrixStore.PRIMITIVE64.makeZero(1, 1); + tmpTableauBuilder.left(matrices.getC().transpose().logical().right(MatrixStore.PRIMITIVE64.makeZero(1, tmpConstraintsCount).get()).get()); if (tmpConstraintsCount >= 1) { - tmpTableauBuilder.above(matrices.getAE(), MatrixStore.PRIMITIVE.makeIdentity(tmpConstraintsCount).get(), matrices.getBE()); + tmpTableauBuilder.above(matrices.getAE(), MatrixStore.PRIMITIVE64.makeIdentity(tmpConstraintsCount).get(), matrices.getBE()); } - tmpTableauBuilder.below(MatrixStore.PRIMITIVE.makeZero(1, tmpVariablesCount).get(), - PrimitiveDenseStore.FACTORY.makeFilled(1, tmpConstraintsCount, new NullaryFunction() { + tmpTableauBuilder.below(MatrixStore.PRIMITIVE64.makeZero(1, tmpVariablesCount).get(), + Primitive64Store.FACTORY.makeFilled(1, tmpConstraintsCount, new NullaryFunction() { public double doubleValue() { return ONE; @@ -89,7 +90,7 @@ public Double invoke() { })); //myTransposedTableau = (PrimitiveDenseStore) tmpTableauBuilder.build().transpose().copy(); - myTransposed = PrimitiveDenseStore.FACTORY.transpose(tmpTableauBuilder.get()); + myTransposed = Primitive64Store.FACTORY.transpose(tmpTableauBuilder.get()); myStructure = (int) myTransposed.countRows(); // myTableau = LinearSolver.make(myTransposedTableau); @@ -304,8 +305,8 @@ public void add(final long row, final long col, final double addend) { myTransposed.add(col, DenseTableau.this.countConstraints() + 1, -addend); } - public void add(final long row, final long col, final Number addend) { - this.add(row, col, addend.doubleValue()); + public void add(final long row, final long col, final Comparable addend) { + this.add(row, col, Scalar.doubleValue(addend)); } public long countColumns() { @@ -323,8 +324,8 @@ public void set(final long row, final long col, final double value) { myTransposed.add(col, DenseTableau.this.countConstraints() + 1, -value); } - public void set(final long row, final long col, final Number value) { - this.set(row, col, value.doubleValue()); + public void set(final long row, final long col, final Comparable value) { + this.set(row, col, Scalar.doubleValue(value)); } }; @@ -349,8 +350,8 @@ public void add(final long index, final double addend) { myTransposed.add(col, numbConstr + 1, -addend); } - public void add(final long index, final Number addend) { - this.add(index, addend.doubleValue()); + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); } public long count() { @@ -366,8 +367,8 @@ public void set(final long index, final double value) { myTransposed.add(col, numbConstr + 1, -value); } - public void set(final long index, final Number value) { - this.set(index, value.doubleValue()); + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); } }; @@ -385,8 +386,8 @@ public void add(final long index, final double addend) { myTransposed.add(index, row, addend); } - public void add(final long index, final Number addend) { - this.add(index, addend.doubleValue()); + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); } public long count() { @@ -398,8 +399,8 @@ public void set(final long index, final double value) { myTransposed.set(index, row, value); } - public void set(final long index, final Number value) { - this.set(index, value.doubleValue()); + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); } }; @@ -776,8 +777,8 @@ public void add(final long row, final long col, final double addend) { myPhase1Weights.add(col, -addend); } - public void add(final long row, final long col, final Number addend) { - this.add(row, col, addend.doubleValue()); + public void add(final long row, final long col, final Comparable addend) { + this.add(row, col, Scalar.doubleValue(addend)); } public long countColumns() { @@ -793,8 +794,8 @@ public void set(final long row, final long col, final double value) { myPhase1Weights.add(col, -value); } - public void set(final long row, final long col, final Number value) { - this.set(row, col, value.doubleValue()); + public void set(final long row, final long col, final Comparable value) { + this.set(row, col, Scalar.doubleValue(value)); } }; @@ -810,8 +811,8 @@ public void add(final long index, final double addend) { myInfeasibility -= addend; } - public void add(final long index, final Number addend) { - this.add(index, addend.doubleValue()); + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); } public long count() { @@ -824,8 +825,8 @@ public void set(final long index, final double value) { myInfeasibility -= value; } - public void set(final long index, final Number value) { - this.set(index, value.doubleValue()); + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); } }; @@ -839,8 +840,8 @@ public void add(final long index, final double addend) { myObjectiveWeights.add(index, addend); } - public void add(final long index, final Number addend) { - this.add(index, addend.doubleValue()); + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); } public long count() { @@ -851,16 +852,16 @@ public void set(final long index, final double value) { myObjectiveWeights.set(index, value); } - public void set(final long index, final Number value) { - this.set(index, value.doubleValue()); + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); } }; } - PrimitiveDenseStore transpose() { + Primitive64Store transpose() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(this.countColumns(), this.countRows()); + final Primitive64Store retVal = Primitive64Store.FACTORY.makeZero(this.countColumns(), this.countRows()); for (int i = 0; i < myRows.length; i++) { for (final NonzeroView nz : myRows[i].nonzeros()) { diff --git a/src/org/ojalgo/random/Binomial.java b/src/org/ojalgo/random/Binomial.java index 1595ff76b..750c063ac 100644 --- a/src/org/ojalgo/random/Binomial.java +++ b/src/org/ojalgo/random/Binomial.java @@ -33,8 +33,6 @@ */ public class Binomial extends AbstractDiscrete { - private static final long serialVersionUID = -3146302867013736326L; - public static Binomial of(final int count, final double probability) { return new Binomial(count, probability); } diff --git a/src/org/ojalgo/random/Deterministic.java b/src/org/ojalgo/random/Deterministic.java index 69cf9d9a5..9eacd33cc 100644 --- a/src/org/ojalgo/random/Deterministic.java +++ b/src/org/ojalgo/random/Deterministic.java @@ -23,13 +23,13 @@ import static org.ojalgo.function.constant.PrimitiveMath.*; +import org.ojalgo.scalar.Scalar; + /** * @author apete */ public class Deterministic extends RandomNumber { - private static final long serialVersionUID = 6544837857838057678L; - private final double myValue; public Deterministic() { @@ -46,11 +46,11 @@ public Deterministic(final double aValue) { myValue = aValue; } - public Deterministic(final Number aValue) { + public Deterministic(final Comparable aValue) { super(); - myValue = aValue.doubleValue(); + myValue = Scalar.doubleValue(aValue); } public double getExpected() { @@ -72,4 +72,8 @@ protected double generate() { return myValue; } + public int compareTo(Deterministic o) { + return Double.compare(myValue, o.myValue); + } + } diff --git a/src/org/ojalgo/random/Erlang.java b/src/org/ojalgo/random/Erlang.java index fc51069f2..ab2162c82 100644 --- a/src/org/ojalgo/random/Erlang.java +++ b/src/org/ojalgo/random/Erlang.java @@ -32,8 +32,6 @@ */ public class Erlang extends RandomNumber { - private static final long serialVersionUID = 6544837857838057678L; - private final int myCount; private final double myRate; diff --git a/src/org/ojalgo/random/Exponential.java b/src/org/ojalgo/random/Exponential.java index a3783f76f..abbe172a8 100644 --- a/src/org/ojalgo/random/Exponential.java +++ b/src/org/ojalgo/random/Exponential.java @@ -34,8 +34,6 @@ */ public class Exponential extends AbstractContinuous { - private static final long serialVersionUID = -720007692511649669L; - public static Exponential of(final double rate) { return new Exponential(rate); } diff --git a/src/org/ojalgo/random/Gamma.java b/src/org/ojalgo/random/Gamma.java index 9627f73e7..cdb9acad3 100644 --- a/src/org/ojalgo/random/Gamma.java +++ b/src/org/ojalgo/random/Gamma.java @@ -32,8 +32,6 @@ */ public class Gamma extends RandomNumber { - private static final long serialVersionUID = 6544837857838057678L; - private final double myShape; private final double myRate; diff --git a/src/org/ojalgo/random/Geometric.java b/src/org/ojalgo/random/Geometric.java index ca5f9fd9c..5007e8a30 100644 --- a/src/org/ojalgo/random/Geometric.java +++ b/src/org/ojalgo/random/Geometric.java @@ -33,8 +33,6 @@ */ public class Geometric extends AbstractDiscrete { - private static final long serialVersionUID = 1324905651790774444L; - public static Geometric of(final double probability) { return new Geometric(probability); } diff --git a/src/org/ojalgo/random/LogNormal.java b/src/org/ojalgo/random/LogNormal.java index ebd7ea062..5bce57371 100644 --- a/src/org/ojalgo/random/LogNormal.java +++ b/src/org/ojalgo/random/LogNormal.java @@ -36,8 +36,6 @@ */ public class LogNormal extends AbstractContinuous { - private static final long serialVersionUID = 2175858399667617840L; - public static LogNormal estimate(final Access1D rawSamples) { final int size = rawSamples.size(); diff --git a/src/org/ojalgo/random/Normal.java b/src/org/ojalgo/random/Normal.java index b62a12c86..d94ea2f45 100644 --- a/src/org/ojalgo/random/Normal.java +++ b/src/org/ojalgo/random/Normal.java @@ -34,8 +34,6 @@ */ public class Normal extends AbstractContinuous { - private static final long serialVersionUID = 7164712313114018919L; - public static Normal of(final double location, final double scale) { return new Normal(location, scale); } diff --git a/src/org/ojalgo/random/Poisson.java b/src/org/ojalgo/random/Poisson.java index be7e5d1a3..786d71ca1 100644 --- a/src/org/ojalgo/random/Poisson.java +++ b/src/org/ojalgo/random/Poisson.java @@ -38,8 +38,6 @@ */ public class Poisson extends AbstractDiscrete { - private static final long serialVersionUID = -5382163736545207782L; - public static Poisson of(final double lambda) { return new Poisson(lambda); } diff --git a/src/org/ojalgo/random/Random1D.java b/src/org/ojalgo/random/Random1D.java index 2f9ecfe4b..b7e64d7dc 100644 --- a/src/org/ojalgo/random/Random1D.java +++ b/src/org/ojalgo/random/Random1D.java @@ -26,7 +26,7 @@ import org.ojalgo.array.Array1D; import org.ojalgo.matrix.decomposition.Cholesky; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; public class Random1D { @@ -41,7 +41,7 @@ public Random1D(final Access2D correlations) { super(); final Cholesky tmpCholesky = Cholesky.PRIMITIVE.make(); - tmpCholesky.decompose(MatrixStore.PRIMITIVE.makeWrapper(correlations)); + tmpCholesky.decompose(MatrixStore.PRIMITIVE64.makeWrapper(correlations)); myCholeskiedCorrelations = tmpCholesky.getL(); tmpCholesky.reset(); @@ -71,14 +71,14 @@ private Random1D() { */ public Array1D nextDouble() { - final PrimitiveDenseStore tmpUncorrelated = PrimitiveDenseStore.FACTORY.make(length, 1); + final Primitive64Store tmpUncorrelated = Primitive64Store.FACTORY.make(length, 1); for (int i = 0; i < length; i++) { tmpUncorrelated.set(i, 0, this.random().nextDouble()); } if (myCholeskiedCorrelations != null) { - return ((PrimitiveDenseStore) myCholeskiedCorrelations.multiply(tmpUncorrelated)).asList(); + return ((Primitive64Store) myCholeskiedCorrelations.multiply(tmpUncorrelated)).asList(); } else { return tmpUncorrelated.asList(); } @@ -89,14 +89,14 @@ public Array1D nextDouble() { */ public Array1D nextGaussian() { - final PrimitiveDenseStore tmpUncorrelated = PrimitiveDenseStore.FACTORY.make(length, 1); + final Primitive64Store tmpUncorrelated = Primitive64Store.FACTORY.make(length, 1); for (int i = 0; i < length; i++) { tmpUncorrelated.set(i, 0, this.random().nextGaussian()); } if (myCholeskiedCorrelations != null) { - return ((PrimitiveDenseStore) myCholeskiedCorrelations.multiply(tmpUncorrelated)).asList(); + return ((Primitive64Store) myCholeskiedCorrelations.multiply(tmpUncorrelated)).asList(); } else { return tmpUncorrelated.asList(); } diff --git a/src/org/ojalgo/random/RandomNumber.java b/src/org/ojalgo/random/RandomNumber.java index 28f7838fb..a28fbd9ea 100644 --- a/src/org/ojalgo/random/RandomNumber.java +++ b/src/org/ojalgo/random/RandomNumber.java @@ -27,15 +27,14 @@ import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.type.ComparableNumber; /** * RandomNumber * * @author apete */ -public abstract class RandomNumber extends Number implements Distribution, NullaryFunction { - - private static final long serialVersionUID = -5871398825698010936L; +public abstract class RandomNumber implements Distribution, NullaryFunction, ComparableNumber { private final Random myRandom = new Random(); @@ -112,4 +111,8 @@ protected void checkProbabilty(final double probabilty) { protected final Random random() { return myRandom; } + + public int compareTo(RandomNumber o) { + return Double.compare(this.getExpected(), o.getExpected()); + } } diff --git a/src/org/ojalgo/random/Uniform.java b/src/org/ojalgo/random/Uniform.java index 6fb34ec05..819ef38e9 100644 --- a/src/org/ojalgo/random/Uniform.java +++ b/src/org/ojalgo/random/Uniform.java @@ -32,8 +32,6 @@ */ public class Uniform extends AbstractContinuous { - private static final long serialVersionUID = -8198257914507986404L; - public static Uniform of(final double lower, final double range) { return new Uniform(lower, range); } diff --git a/src/org/ojalgo/random/Weibull.java b/src/org/ojalgo/random/Weibull.java index 53354f4f3..f5470ea9d 100644 --- a/src/org/ojalgo/random/Weibull.java +++ b/src/org/ojalgo/random/Weibull.java @@ -33,8 +33,6 @@ */ public class Weibull extends RandomNumber { - private static final long serialVersionUID = 7315696913427382955L; - private final double myShape; // beta private final double myRate; // lamda diff --git a/src/org/ojalgo/random/process/GaussianField.java b/src/org/ojalgo/random/process/GaussianField.java index b4b2d294c..f80388bb3 100644 --- a/src/org/ojalgo/random/process/GaussianField.java +++ b/src/org/ojalgo/random/process/GaussianField.java @@ -35,7 +35,7 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Normal1D; import org.ojalgo.type.keyvalue.ComparableToDouble; @@ -70,7 +70,7 @@ public interface Mean> { } - private static final Factory FACTORY = PrimitiveDenseStore.FACTORY; + private static final Factory FACTORY = Primitive64Store.FACTORY; private static > Mean mean() { return new Mean() { @@ -134,13 +134,13 @@ public Normal1D getDistribution(final boolean cleanCovariances, final K... evalu final MatrixStore tmpM1 = this.getM1(evaluationPoint); final MatrixStore tmpM2differenses = this.getM2differenses(); - final PrimitiveDenseStore tmpLocations = FACTORY.makeZero(tmpM1.countRows(), tmpM1.countColumns()); + final Primitive64Store tmpLocations = FACTORY.makeZero(tmpM1.countRows(), tmpM1.countColumns()); tmpLocations.fillMatching(tmpM1, PrimitiveMath.ADD, tmpRegCoef.multiply(tmpM2differenses)); final MatrixStore tmpC11 = this.getC11(evaluationPoint); final MatrixStore tmpC21 = this.getC21(evaluationPoint); - final PrimitiveDenseStore tmpCovariances = FACTORY.makeZero(tmpC11.countRows(), tmpC11.countColumns()); + final Primitive64Store tmpCovariances = FACTORY.makeZero(tmpC11.countRows(), tmpC11.countColumns()); tmpCovariances.fillMatching(tmpC11, PrimitiveMath.SUBTRACT, tmpRegCoef.multiply(tmpC21)); if (cleanCovariances) { @@ -175,7 +175,7 @@ MatrixStore getC11(final K[] args) { final int tmpLength = args.length; - final PrimitiveDenseStore retVal = FACTORY.makeZero(tmpLength, tmpLength); + final Primitive64Store retVal = FACTORY.makeZero(tmpLength, tmpLength); for (int j = 0; j < tmpLength; j++) { for (int i = 0; i < tmpLength; i++) { @@ -193,7 +193,7 @@ MatrixStore getC12(final K[] args) { final int tmpRowDim = args.length; final int tmpColDim = tmpObservations.size(); - final PrimitiveDenseStore retVal = FACTORY.makeZero(tmpRowDim, tmpColDim); + final Primitive64Store retVal = FACTORY.makeZero(tmpRowDim, tmpColDim); for (int j = 0; j < tmpColDim; j++) { for (int i = 0; i < tmpRowDim; i++) { @@ -211,7 +211,7 @@ MatrixStore getC21(final K[] args) { final int tmpRowDim = tmpObservations.size(); final int tmpColDim = args.length; - final PrimitiveDenseStore retVal = FACTORY.makeZero(tmpRowDim, tmpColDim); + final Primitive64Store retVal = FACTORY.makeZero(tmpRowDim, tmpColDim); for (int j = 0; j < tmpColDim; j++) { for (int i = 0; i < tmpRowDim; i++) { @@ -228,7 +228,7 @@ MatrixDecomposition.Solver getC22() { final int tmpSize = tmpObservations.size(); - final PrimitiveDenseStore tmpMatrix = FACTORY.makeZero(tmpSize, tmpSize); + final Primitive64Store tmpMatrix = FACTORY.makeZero(tmpSize, tmpSize); for (int j = 0; j < tmpSize; j++) { final K tmpColumnKey = tmpObservations.get(j).key; @@ -248,7 +248,7 @@ MatrixStore getM1(final K[] args) { final int tmpLength = args.length; - final PrimitiveDenseStore retVal = FACTORY.make(tmpLength, 1); + final Primitive64Store retVal = FACTORY.make(tmpLength, 1); for (int i = 0; i < tmpLength; i++) { retVal.set(i, 0, myMeanFunction.invoke(args[i])); @@ -263,7 +263,7 @@ MatrixStore getM2() { final int tmpSize = tmpObservations.size(); - final PrimitiveDenseStore retVal = FACTORY.make(tmpSize, 1); + final Primitive64Store retVal = FACTORY.make(tmpSize, 1); for (int i = 0; i < tmpSize; i++) { retVal.set(i, 0, myMeanFunction.invoke(tmpObservations.get(i).key)); @@ -278,7 +278,7 @@ MatrixStore getM2differenses() { final int tmpSize = tmpObservations.size(); - final PrimitiveDenseStore retVal = FACTORY.make(tmpSize, 1); + final Primitive64Store retVal = FACTORY.make(tmpSize, 1); ComparableToDouble tmpObservation; double tmpDiff; diff --git a/src/org/ojalgo/scalar/BigScalar.java b/src/org/ojalgo/scalar/BigScalar.java index 01fe6f96e..d0aded276 100644 --- a/src/org/ojalgo/scalar/BigScalar.java +++ b/src/org/ojalgo/scalar/BigScalar.java @@ -34,30 +34,36 @@ * @deprecated v44 In the future there will only be primitives based implementations of the Scalar interface */ @Deprecated -public final class BigScalar extends Number implements Scalar, Enforceable { +public final class BigScalar implements Scalar, Enforceable { public static final Scalar.Factory FACTORY = new Scalar.Factory() { + @Override + public BigDecimal cast(final Comparable number) { + return TypeUtils.toBigDecimal(number); + } + + @Override public BigDecimal cast(final double value) { return new BigDecimal(value); } - public BigDecimal cast(final Number number) { - return TypeUtils.toBigDecimal(number); + @Override + public BigScalar convert(final Comparable number) { + return BigScalar.valueOf(number); } + @Override public BigScalar convert(final double value) { return BigScalar.valueOf(value); } - public BigScalar convert(final Number number) { - return BigScalar.valueOf(number); - } - + @Override public BigScalar one() { return ONE; } + @Override public BigScalar zero() { return ZERO; } @@ -83,11 +89,7 @@ public static BigScalar of(final BigDecimal value) { return new BigScalar(value); } - public static BigScalar valueOf(final double value) { - return new BigScalar(BigDecimal.valueOf(value)); - } - - public static BigScalar valueOf(final Number number) { + public static BigScalar valueOf(final Comparable number) { if (number != null) { @@ -106,6 +108,10 @@ public static BigScalar valueOf(final Number number) { } } + public static BigScalar valueOf(final double value) { + return new BigScalar(BigDecimal.valueOf(value)); + } + private final BigDecimal myNumber; public BigScalar() { @@ -122,56 +128,70 @@ private BigScalar(final BigDecimal number) { myNumber = number; } + @Override public BigScalar add(final BigDecimal arg) { return new BigScalar(myNumber.add(arg)); } + @Override public BigScalar add(final double arg) { return this.add(new BigDecimal(arg)); } + @Override + public BigScalar add(float scalarAddend) { + return this.add((double) scalarAddend); + } + + @Override public int compareTo(final BigDecimal reference) { return myNumber.compareTo(reference); } + @Override public BigScalar conjugate() { return this; } + @Override public BigScalar divide(final BigDecimal arg) { return new BigScalar(myNumber.divide(arg, BigScalar.CONTEXT.getMathContext())); } + @Override public BigScalar divide(final double arg) { return this.divide(new BigDecimal(arg)); } + @Override + public BigScalar divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + @Override public double doubleValue() { return myNumber.doubleValue(); } + @Override public BigScalar enforce(final NumberContext context) { return new BigScalar(context.enforce(myNumber)); } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { + if (!(obj instanceof BigScalar)) { return false; } - if (!(obj instanceof Scalar)) { - return false; - } - final BigDecimal other = ((Scalar) obj).toBigDecimal(); + BigScalar other = (BigScalar) obj; if (myNumber == null) { - if (other != null) { + if (other.myNumber != null) { return false; } - } else if (!myNumber.equals(other)) { + } else if (!myNumber.equals(other.myNumber)) { return false; } return true; @@ -182,6 +202,7 @@ public float floatValue() { return myNumber.floatValue(); } + @Override public BigDecimal get() { return myNumber; } @@ -199,14 +220,17 @@ public int intValue() { return myNumber.intValueExact(); } + @Override public BigScalar invert() { return ONE.divide(myNumber); } + @Override public boolean isAbsolute() { return BigScalar.isAbsolute(myNumber); } + @Override public boolean isSmall(final double comparedTo) { return BigScalar.CONTEXT.isSmall(comparedTo, this.doubleValue()); } @@ -216,22 +240,32 @@ public long longValue() { return myNumber.longValueExact(); } + @Override public BigScalar multiply(final BigDecimal arg) { return new BigScalar(myNumber.multiply(arg)); } + @Override public BigScalar multiply(final double arg) { return this.multiply(new BigDecimal(arg)); } + @Override + public BigScalar multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + + @Override public BigScalar negate() { return new BigScalar(myNumber.negate()); } + @Override public double norm() { return PrimitiveMath.ABS.invoke(myNumber.doubleValue()); } + @Override public BigScalar power(final int power) { BigScalar retVal = ONE; @@ -243,18 +277,27 @@ public BigScalar power(final int power) { return retVal; } + @Override public BigScalar signum() { return new BigScalar(BigMath.SIGNUM.invoke(myNumber)); } + @Override public BigScalar subtract(final BigDecimal arg) { return new BigScalar(myNumber.subtract(arg)); } + @Override public BigScalar subtract(final double arg) { return this.subtract(new BigDecimal(arg)); } + @Override + public BigScalar subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + + @Override public BigDecimal toBigDecimal() { return myNumber; } @@ -264,6 +307,7 @@ public String toString() { return myNumber.toString(); } + @Override public String toString(final NumberContext context) { return context.enforce(myNumber).toString(); } diff --git a/src/org/ojalgo/scalar/ComplexNumber.java b/src/org/ojalgo/scalar/ComplexNumber.java index a45e97b29..e43f75468 100644 --- a/src/org/ojalgo/scalar/ComplexNumber.java +++ b/src/org/ojalgo/scalar/ComplexNumber.java @@ -27,7 +27,7 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Mutate2D; import org.ojalgo.structure.Mutate2D.ModifiableReceiver; @@ -42,96 +42,37 @@ * @author apete * @see org.ojalgo.function.ComplexFunction */ -public class ComplexNumber extends Number implements Scalar, Enforceable, Access2D, Transformation2D, +public final class ComplexNumber implements Scalar, Enforceable, Access2D, Transformation2D, Access2D.Collectable> { - public static final class Normalised extends ComplexNumber { - - Normalised(final double real, final double imaginary) { - super(real, imaginary); - } - - @Override - public double norm() { - return PrimitiveMath.ONE; - } + public static final Scalar.Factory FACTORY = new Scalar.Factory() { @Override - public Normalised signum() { - return this; + public ComplexNumber cast(final Comparable number) { + return ComplexNumber.valueOf(number); } @Override - public & Access2D> void transform(final T transformable) { - - final double s = this.doubleValue(); - - final double ss = s * s; - final double ii = i * i; - - final double r00 = (ii + ss); - final double r11 = (ss - ii); - - if (transformable.count() == 2L) { - - final double x = transformable.doubleValue(0); - final double y = transformable.doubleValue(1); - - transformable.set(0, r00 * x); - transformable.set(1, r11 * y); - - } else if (transformable.countRows() == 2L) { - - for (long c = 0L, limit = transformable.countColumns(); c < limit; c++) { - - final double x = transformable.doubleValue(0, c); - final double y = transformable.doubleValue(1, c); - - transformable.set(0, c, r00 * x); - transformable.set(1, c, r11 * y); - } - - } else if (transformable.countColumns() == 2L) { - - for (long r = 0L, limit = transformable.countRows(); r < limit; r++) { - - final double x = transformable.doubleValue(r, 0); - final double y = transformable.doubleValue(r, 1); - - transformable.set(r, 0, r00 * x); - transformable.set(r, 1, r11 * y); - } - - } else { - - throw new ProgrammingError("Only works for 2D stuff!"); - } - } - - } - - public static final Scalar.Factory FACTORY = new Scalar.Factory() { - public ComplexNumber cast(final double value) { return ComplexNumber.valueOf(value); } - public ComplexNumber cast(final Number number) { + @Override + public ComplexNumber convert(final Comparable number) { return ComplexNumber.valueOf(number); } + @Override public ComplexNumber convert(final double value) { return ComplexNumber.valueOf(value); } - public ComplexNumber convert(final Number number) { - return ComplexNumber.valueOf(number); - } - + @Override public ComplexNumber one() { return ONE; } + @Override public ComplexNumber zero() { return ZERO; } @@ -257,8 +198,8 @@ public static ComplexNumber makePolar(final double norm, final double phase) { } } - public static Normalised makeRotation(final double angle) { - return new Normalised(PrimitiveMath.COS.invoke(angle), PrimitiveMath.SIN.invoke(angle)); + public static ComplexNumber makeRotation(final double angle) { + return new ComplexNumber(PrimitiveMath.COS.invoke(angle), PrimitiveMath.SIN.invoke(angle)); } /** @@ -276,44 +217,39 @@ public static ComplexNumber of(final double real, final double imaginary) { } } - /** - * Static factory method returning a complex number from a real value - * - * @param value the complex number's real part - * @return a complex number Z = ({@code value} + 0.0i) - */ - public static ComplexNumber valueOf(final double value) { - return new ComplexNumber(value); - } - /** * Static factory method returning a complex number from arbitrary number * * @param number a numeric value * @return {@link ComplexNumber#ZERO} if {@code number} is null otherwise the double value of * {@code number} - * @see Number - * @see Number#doubleValue() */ - public static ComplexNumber valueOf(final Number number) { - - if (number != null) { + public static ComplexNumber valueOf(final Comparable number) { - if (number instanceof ComplexNumber) { + if (number == null) { + return ZERO; + } - return (ComplexNumber) number; + if (number instanceof ComplexNumber) { - } else { - - return new ComplexNumber(number.doubleValue()); - } + return (ComplexNumber) number; } else { - return ZERO; + return new ComplexNumber(Scalar.doubleValue(number)); } } + /** + * Static factory method returning a complex number from a real value + * + * @param value the complex number's real part + * @return a complex number Z = ({@code value} + 0.0i) + */ + public static ComplexNumber valueOf(final double value) { + return new ComplexNumber(value); + } + public final double i; private final boolean myRealForSure; @@ -354,6 +290,7 @@ private ComplexNumber(final double real) { * @param arg the complex number to add * @return a complex number {@literal Z = ((Re(this) + Re(arg)) + (Im(this) + Im(arg))i)} */ + @Override public ComplexNumber add(final ComplexNumber arg) { return new ComplexNumber(myRealValue + arg.doubleValue(), i + arg.i); } @@ -364,10 +301,16 @@ public ComplexNumber add(final ComplexNumber arg) { * @param arg the real number to add * @return a complex number {@literal Z = ((Re(this) + arg) + Im(this)i)} */ + @Override public ComplexNumber add(final double arg) { return new ComplexNumber(myRealValue + arg, i); } + @Override + public ComplexNumber add(float scalarAddend) { + return this.add((double) scalarAddend); + } + /** * Compares the specified {@code reference} and this. The numerical comparison uses following order : * {@literal |Z| -> Re(Z) -> Im(Z)}. @@ -377,6 +320,7 @@ public ComplexNumber add(final double arg) { * {@code reference} are numerically equal or a positive value if {@code reference} is numerically * lesser than this. */ + @Override public int compareTo(final ComplexNumber reference) { int retVal = 0; @@ -396,18 +340,22 @@ public int compareTo(final ComplexNumber reference) { * * @return a complex number Z = (Re(this) - Im(this)i) */ + @Override public ComplexNumber conjugate() { return new ComplexNumber(myRealValue, -i); } + @Override public long count() { return 4L; } + @Override public long countColumns() { return 2L; } + @Override public long countRows() { return 2L; } @@ -418,6 +366,7 @@ public long countRows() { * @param arg the complex number to divide by * @return a complex number {@literal Z = this / arg} */ + @Override public ComplexNumber divide(final ComplexNumber arg) { final double tmpRe = arg.doubleValue(); @@ -445,18 +394,22 @@ public ComplexNumber divide(final ComplexNumber arg) { * @param arg the real number to divide by * @return a complex number {@literal Z = ((Re(this) / arg) + (Im(this) / arg)i)} */ + @Override public ComplexNumber divide(final double arg) { return new ComplexNumber(myRealValue / arg, i / arg); } - /** - * @see java.lang.Number#doubleValue() - */ + @Override + public ComplexNumber divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + @Override public double doubleValue() { return myRealValue; } + @Override public double doubleValue(final long index) { switch ((int) index) { case 0: @@ -472,6 +425,7 @@ public double doubleValue(final long index) { } } + @Override public double doubleValue(final long row, final long col) { if (row == col) { return myRealValue; @@ -487,6 +441,7 @@ public double doubleValue(final long row, final long col) { /** * Will call {@linkplain NumberContext#enforce(double)} on the real and imaginary parts separately. */ + @Override public ComplexNumber enforce(final NumberContext context) { final double tmpRe = context.enforce(myRealValue); @@ -496,17 +451,14 @@ public ComplexNumber enforce(final NumberContext context) { } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } if (!(obj instanceof ComplexNumber)) { return false; } - final ComplexNumber other = (ComplexNumber) obj; + ComplexNumber other = (ComplexNumber) obj; if (Double.doubleToLongBits(myRealValue) != Double.doubleToLongBits(other.myRealValue)) { return false; } @@ -516,22 +468,22 @@ public boolean equals(final Object obj) { return true; } - /** - * @see java.lang.Number#floatValue() - */ @Override public float floatValue() { return (float) this.doubleValue(); } + @Override public ComplexNumber get() { return this; } + @Override public Double get(final long index) { return this.doubleValue(index); } + @Override public Double get(final long row, final long col) { return this.doubleValue(row, col); } @@ -557,16 +509,13 @@ public int hashCode() { final int prime = 31; int result = 1; long temp; - temp = Double.doubleToLongBits(myRealValue); - result = (prime * result) + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(i); result = (prime * result) + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(myRealValue); + result = (prime * result) + (int) (temp ^ (temp >>> 32)); return result; } - /** - * @see java.lang.Number#intValue() - */ @Override public int intValue() { return (int) this.doubleValue(); @@ -582,6 +531,7 @@ public ComplexNumber invert() { return ComplexNumber.makePolar(PrimitiveMath.ONE / this.norm(), -this.phase()); } + @Override public boolean isAbsolute() { if (myRealForSure) { return myRealValue >= PrimitiveMath.ZERO; @@ -594,13 +544,11 @@ public boolean isReal() { return myRealForSure || PrimitiveScalar.CONTEXT.isSmall(myRealValue, i); } + @Override public boolean isSmall(final double comparedTo) { return PrimitiveScalar.CONTEXT.isSmall(comparedTo, this.norm()); } - /** - * @see java.lang.Number#longValue() - */ @Override public long longValue() { return (long) this.doubleValue(); @@ -632,6 +580,11 @@ public ComplexNumber multiply(final double arg) { return new ComplexNumber(myRealValue * arg, i * arg); } + @Override + public ComplexNumber multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + /** * Performs the unary operation '-'. * @@ -648,6 +601,7 @@ public ComplexNumber negate() { * * @return the norm of this complex number. */ + @Override public double norm() { return PrimitiveMath.HYPOT.invoke(myRealValue, i); } @@ -662,6 +616,7 @@ public double phase() { return Math.atan2(i, myRealValue); } + @Override public ComplexNumber power(final int power) { double norm = Math.pow(this.norm(), power); @@ -670,7 +625,8 @@ public ComplexNumber power(final int power) { return ComplexNumber.makePolar(norm, phase); } - public ComplexNumber.Normalised signum() { + @Override + public ComplexNumber signum() { if (ComplexNumber.isSmall(PrimitiveMath.ONE, this)) { return ComplexNumber.makeRotation(PrimitiveMath.ZERO); } else { @@ -684,6 +640,7 @@ public ComplexNumber.Normalised signum() { * @param arg the complex number to subtract * @return a complex number Z = this - {@code arg} */ + @Override public ComplexNumber subtract(final ComplexNumber arg) { return new ComplexNumber(myRealValue - arg.doubleValue(), i - arg.i); } @@ -699,6 +656,12 @@ public ComplexNumber subtract(final double arg) { return new ComplexNumber(myRealValue - arg, i); } + @Override + public ComplexNumber subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + + @Override public void supplyTo(final Mutate2D.Receiver receiver) { receiver.set(0L, myRealValue); receiver.set(1L, i); @@ -706,19 +669,20 @@ public void supplyTo(final Mutate2D.Receiver receiver) { receiver.set(3L, myRealValue); } + @Override public BigDecimal toBigDecimal() { return new BigDecimal(this.doubleValue(), MathContext.DECIMAL64); } public MatrixStore toMultiplicationMatrix() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(this); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(this); this.supplyTo(retVal); return retVal; } public MatrixStore toMultiplicationVector() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(2L, 1L); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(2L, 1L); retVal.set(0L, myRealValue); retVal.set(1L, i); @@ -728,7 +692,7 @@ public MatrixStore toMultiplicationVector() { public MatrixStore toRotationMatrix() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(2L, 2L); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(2L, 2L); final double s = myRealValue; @@ -769,6 +733,7 @@ public String toString() { return retVal.append(RIGHT).toString(); } + @Override public String toString(final NumberContext context) { final StringBuilder retVal = new StringBuilder(LEFT); @@ -788,6 +753,7 @@ public String toString(final NumberContext context) { return retVal.append(RIGHT).toString(); } + @Override public & Access2D> void transform(final T transformable) { final double s = myRealValue; @@ -836,4 +802,50 @@ public & Access2D> void transform( } } + & Access2D> void transformWhenUnit(final T transformable) { + + final double s = this.doubleValue(); + + final double ss = s * s; + final double ii = i * i; + + final double r00 = (ii + ss); + final double r11 = (ss - ii); + + if (transformable.count() == 2L) { + + final double x = transformable.doubleValue(0); + final double y = transformable.doubleValue(1); + + transformable.set(0, r00 * x); + transformable.set(1, r11 * y); + + } else if (transformable.countRows() == 2L) { + + for (long c = 0L, limit = transformable.countColumns(); c < limit; c++) { + + final double x = transformable.doubleValue(0, c); + final double y = transformable.doubleValue(1, c); + + transformable.set(0, c, r00 * x); + transformable.set(1, c, r11 * y); + } + + } else if (transformable.countColumns() == 2L) { + + for (long r = 0L, limit = transformable.countRows(); r < limit; r++) { + + final double x = transformable.doubleValue(r, 0); + final double y = transformable.doubleValue(r, 1); + + transformable.set(r, 0, r00 * x); + transformable.set(r, 1, r11 * y); + } + + } else { + + throw new ProgrammingError("Only works for 2D stuff!"); + } + } + } diff --git a/src/org/ojalgo/scalar/ExactDecimal.java b/src/org/ojalgo/scalar/ExactDecimal.java index 796712bb7..dee241281 100644 --- a/src/org/ojalgo/scalar/ExactDecimal.java +++ b/src/org/ojalgo/scalar/ExactDecimal.java @@ -33,7 +33,7 @@ * * @author apete */ -public abstract class ExactDecimal> extends Number implements Scalar, Enforceable { +public abstract class ExactDecimal> implements Scalar, Enforceable { public static final class Descriptor { @@ -106,27 +106,33 @@ protected ExactDecimal(final long numerator) { myNumerator = numerator; } + @Override public final S add(final double scalarAddend) { return this.wrap(myNumerator + Math.round(scalarAddend * this.descriptor().denominator())); } + @Override public final S add(final S scalarAddend) { return this.wrap(myNumerator + scalarAddend.numerator()); } + @Override public final int compareTo(final S reference) { return Long.compare(myNumerator, reference.numerator()); } + @Override @SuppressWarnings("unchecked") public final S conjugate() { return (S) this; } + @Override public final S divide(final double scalarDivisor) { return this.wrap(Math.round(myNumerator / scalarDivisor)); } + @Override public final S divide(final S scalarDivisor) { return this.wrap((myNumerator * this.descriptor().denominator()) / scalarDivisor.numerator()); } @@ -136,6 +142,7 @@ public final double doubleValue() { return myNumerator / this.descriptor().denominator(); } + @Override public final S enforce(final NumberContext context) { BigDecimal decimal = this.toBigDecimal(context); final NumberContext type = this.descriptor().context(); @@ -148,6 +155,7 @@ public final float floatValue() { return (float) this.doubleValue(); } + @Override @SuppressWarnings("unchecked") public final S get() { return (S) this; @@ -158,14 +166,17 @@ public final int intValue() { return (int) this.doubleValue(); } + @Override public final S invert() { return this.wrap(Math.round(this.descriptor().denominator() / this.doubleValue())); } + @Override public final boolean isAbsolute() { return myNumerator >= 0L; } + @Override public final boolean isSmall(final double comparedTo) { return this.descriptor().context().isSmall(comparedTo, this.doubleValue()); } @@ -175,22 +186,27 @@ public final long longValue() { return this.toBigDecimal().longValue(); } + @Override public final S multiply(final double scalarMultiplicand) { return this.wrap(Math.round(myNumerator * scalarMultiplicand)); } + @Override public final S multiply(final S scalarMultiplicand) { return this.wrap((myNumerator * scalarMultiplicand.numerator()) / this.descriptor().denominator()); } + @Override public final S negate() { return this.wrap(-myNumerator); } + @Override public final double norm() { return PrimitiveMath.ABS.invoke(this.doubleValue()); } + @Override @SuppressWarnings("unchecked") public S power(final int power) { @@ -211,6 +227,7 @@ public S power(final int power) { } } + @Override public final S signum() { if (myNumerator == 0L) { return this.wrap(0L); @@ -221,14 +238,17 @@ public final S signum() { } } + @Override public final S subtract(final double scalarSubtrahend) { return this.wrap(myNumerator - Math.round(scalarSubtrahend * this.descriptor().denominator())); } + @Override public final S subtract(final S scalarSubtrahend) { return this.wrap(myNumerator - scalarSubtrahend.numerator()); } + @Override public final BigDecimal toBigDecimal() { if (myDecimal == null) { myDecimal = new BigDecimal(myNumerator).divide(new BigDecimal(this.descriptor().denominator()), this.descriptor().context().getMathContext()); @@ -241,6 +261,7 @@ public final String toString() { return this.toBigDecimal().toPlainString(); } + @Override public final String toString(final NumberContext context) { return this.toBigDecimal(context).toPlainString(); } @@ -257,4 +278,24 @@ final long numerator() { return myNumerator; } + @Override + public S add(float scalarAddend) { + return this.add((double) scalarAddend); + } + + @Override + public S divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + + @Override + public S multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + + @Override + public S subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + } diff --git a/src/org/ojalgo/scalar/Money.java b/src/org/ojalgo/scalar/Money.java index d682d338f..e88870f10 100644 --- a/src/org/ojalgo/scalar/Money.java +++ b/src/org/ojalgo/scalar/Money.java @@ -32,30 +32,37 @@ public final class Money extends ExactDecimal { public static final Scalar.Factory FACTORY = new ExactDecimal.Factory() { + @Override public Money cast(final double value) { return Money.valueOf(value); } - public Money cast(final Number number) { + @Override + public Money cast(final Comparable number) { return Money.valueOf(number); } + @Override public Money convert(final double value) { return Money.valueOf(value); } - public Money convert(final Number number) { + @Override + public Money convert(final Comparable number) { return Money.valueOf(number); } + @Override public Descriptor descriptor() { return DESCRIPTOR; } + @Override public Money one() { return ONE; } + @Override public Money zero() { return ZERO; } @@ -90,7 +97,7 @@ public static Money valueOf(final double value) { return new Money(Math.round(value * DOUBLE_DENOMINATOR)); } - public static Money valueOf(final Number number) { + public static Money valueOf(final Comparable number) { if (number != null) { @@ -100,7 +107,7 @@ public static Money valueOf(final Number number) { } else { - return Money.valueOf(number.doubleValue()); + return Money.valueOf(Scalar.doubleValue(number)); } } else { diff --git a/src/org/ojalgo/scalar/PrimitiveScalar.java b/src/org/ojalgo/scalar/PrimitiveScalar.java index ce513c49f..19b23adb0 100644 --- a/src/org/ojalgo/scalar/PrimitiveScalar.java +++ b/src/org/ojalgo/scalar/PrimitiveScalar.java @@ -28,30 +28,36 @@ import org.ojalgo.type.context.NumberContext; import org.ojalgo.type.context.NumberContext.Enforceable; -public final class PrimitiveScalar extends Number implements Scalar, Enforceable { +public final class PrimitiveScalar implements Scalar, Enforceable { public static final Scalar.Factory FACTORY = new Scalar.Factory() { + @Override + public Double cast(final Comparable number) { + return Scalar.doubleValue(number); + } + + @Override public Double cast(final double value) { return value; } - public Double cast(final Number number) { - return number.doubleValue(); + @Override + public PrimitiveScalar convert(final Comparable number) { + return PrimitiveScalar.valueOf(number); } + @Override public PrimitiveScalar convert(final double value) { return PrimitiveScalar.of(value); } - public PrimitiveScalar convert(final Number number) { - return PrimitiveScalar.valueOf(number); - } - + @Override public PrimitiveScalar one() { return ONE; } + @Override public PrimitiveScalar zero() { return ZERO; } @@ -88,27 +94,12 @@ public static PrimitiveScalar of(final double value) { return new PrimitiveScalar(value); } - public static PrimitiveScalar valueOf(final double value) { - return PrimitiveScalar.of(value); + public static PrimitiveScalar valueOf(final Comparable number) { + return PrimitiveScalar.of(Scalar.doubleValue(number)); } - public static PrimitiveScalar valueOf(final Number number) { - - if (number != null) { - - if (number instanceof PrimitiveScalar) { - - return (PrimitiveScalar) number; - - } else { - - return new PrimitiveScalar(number.doubleValue()); - } - - } else { - - return ZERO; - } + public static PrimitiveScalar valueOf(final double value) { + return PrimitiveScalar.of(value); } private final double myValue; @@ -127,52 +118,66 @@ private PrimitiveScalar(final double value) { myValue = value; } + @Override public PrimitiveScalar add(final double arg) { return new PrimitiveScalar(myValue + arg); } + @Override public PrimitiveScalar add(final Double arg) { return new PrimitiveScalar(myValue + arg); } + @Override + public PrimitiveScalar add(float scalarAddend) { + return this.add((double) scalarAddend); + } + + @Override public int compareTo(final Double reference) { return NumberContext.compare(myValue, reference); } + @Override public PrimitiveScalar conjugate() { return this; } + @Override public PrimitiveScalar divide(final double arg) { return new PrimitiveScalar(myValue / arg); } + @Override public PrimitiveScalar divide(final Double arg) { return new PrimitiveScalar(myValue / arg); } + @Override + public PrimitiveScalar divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + @Override public double doubleValue() { return myValue; } + @Override public PrimitiveScalar enforce(final NumberContext context) { return new PrimitiveScalar(context.enforce(myValue)); } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (!(obj instanceof Number)) { + if (!(obj instanceof PrimitiveScalar)) { return false; } - final double other = ((Number) obj).doubleValue(); - if (Double.doubleToLongBits(myValue) != Double.doubleToLongBits(other)) { + PrimitiveScalar other = (PrimitiveScalar) obj; + if (Double.doubleToLongBits(myValue) != Double.doubleToLongBits(other.myValue)) { return false; } return true; @@ -183,6 +188,7 @@ public float floatValue() { return (float) myValue; } + @Override public Double get() { return myValue; } @@ -202,14 +208,17 @@ public int intValue() { return (int) myValue; } + @Override public PrimitiveScalar invert() { return new PrimitiveScalar(PrimitiveMath.ONE / myValue); } + @Override public boolean isAbsolute() { return PrimitiveScalar.isAbsolute(myValue); } + @Override public boolean isSmall(final double comparedTo) { return PrimitiveScalar.isSmall(comparedTo, myValue); } @@ -219,22 +228,32 @@ public long longValue() { return (long) myValue; } + @Override public PrimitiveScalar multiply(final double arg) { return new PrimitiveScalar(myValue * arg); } + @Override public PrimitiveScalar multiply(final Double arg) { return new PrimitiveScalar(myValue * arg); } + @Override + public PrimitiveScalar multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + + @Override public PrimitiveScalar negate() { return new PrimitiveScalar(-myValue); } + @Override public double norm() { return PrimitiveMath.ABS.invoke(myValue); } + @Override public PrimitiveScalar power(final int power) { double retVal = PrimitiveMath.ONE; @@ -246,18 +265,27 @@ public PrimitiveScalar power(final int power) { return new PrimitiveScalar(retVal); } + @Override public PrimitiveScalar signum() { return new PrimitiveScalar(PrimitiveMath.SIGNUM.invoke(myValue)); } + @Override public PrimitiveScalar subtract(final double arg) { return new PrimitiveScalar(myValue - arg); } + @Override public PrimitiveScalar subtract(final Double arg) { return new PrimitiveScalar(myValue - arg); } + @Override + public PrimitiveScalar subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + + @Override public BigDecimal toBigDecimal() { return new BigDecimal(myValue, PrimitiveScalar.CONTEXT.getMathContext()); } @@ -267,6 +295,7 @@ public String toString() { return Double.toString(myValue); } + @Override public String toString(final NumberContext context) { return context.enforce(this.toBigDecimal()).toString(); } diff --git a/src/org/ojalgo/scalar/Quaternion.java b/src/org/ojalgo/scalar/Quaternion.java index 237e6bd4f..138aa113d 100644 --- a/src/org/ojalgo/scalar/Quaternion.java +++ b/src/org/ojalgo/scalar/Quaternion.java @@ -25,10 +25,10 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; import org.ojalgo.structure.Mutate2D; import org.ojalgo.structure.Mutate2D.ModifiableReceiver; @@ -36,7 +36,7 @@ import org.ojalgo.type.context.NumberContext; import org.ojalgo.type.context.NumberContext.Enforceable; -public class Quaternion extends Number implements Scalar, Enforceable, Access2D, Transformation2D, +public final class Quaternion implements Scalar, Enforceable, Access2D, Transformation2D, Access2D.Collectable> { public enum RotationAxis { @@ -61,188 +61,48 @@ int index() { } - public static final class Versor extends Quaternion { - - Versor(final double scalar) { - super(scalar); - } - - Versor(final double i, final double j, final double k) { - super(i, j, k); - } - - Versor(final double scalar, final double i, final double j, final double k) { - super(scalar, i, j, k); - } - - @Override - public double norm() { - return PrimitiveMath.ONE; - } - - @Override - public MatrixStore toRotationMatrix() { - - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(3L, 3L); - - final double s = this.doubleValue(); - - final double ss = s * s; - final double ii = i * i; - final double jj = j * j; - final double kk = k * k; - - double tmp1; - double tmp2; - - final double r00 = ((ii + ss) - (jj + kk)); - final double r11 = ((jj + ss) - (ii + kk)); - final double r22 = ((kk + ss) - (ii + jj)); - - tmp1 = i * j; - tmp2 = k * s; - final double r10 = 2.0 * (tmp1 + tmp2); - final double r01 = 2.0 * (tmp1 - tmp2); - - tmp1 = i * k; - tmp2 = j * s; - final double r20 = 2.0 * (tmp1 - tmp2); - final double r02 = 2.0 * (tmp1 + tmp2); - - tmp1 = j * k; - tmp2 = i * s; - final double r21 = 2.0 * (tmp1 + tmp2); - final double r12 = 2.0 * (tmp1 - tmp2); - - retVal.set(0L, r00); - retVal.set(1L, r10); - retVal.set(2L, r20); - retVal.set(3L, r01); - retVal.set(4L, r11); - retVal.set(5L, r21); - retVal.set(6L, r02); - retVal.set(7L, r12); - retVal.set(8L, r22); - - return retVal; - } + public static final Scalar.Factory FACTORY = new Scalar.Factory() { @Override - public & Access2D> void transform(final T transformable) { - - final double s = this.doubleValue(); - - final double ss = s * s; - final double ii = i * i; - final double jj = j * j; - final double kk = k * k; - - double tmp1; - double tmp2; - - final double r00 = ((ii + ss) - (jj + kk)); - final double r11 = ((jj + ss) - (ii + kk)); - final double r22 = ((kk + ss) - (ii + jj)); - - tmp1 = i * j; - tmp2 = k * s; - final double r10 = 2.0 * (tmp1 + tmp2); - final double r01 = 2.0 * (tmp1 - tmp2); - - tmp1 = i * k; - tmp2 = j * s; - final double r20 = 2.0 * (tmp1 - tmp2); - final double r02 = 2.0 * (tmp1 + tmp2); - - tmp1 = j * k; - tmp2 = i * s; - final double r21 = 2.0 * (tmp1 + tmp2); - final double r12 = 2.0 * (tmp1 - tmp2); - - if (transformable.count() == 3L) { - - final double x = transformable.doubleValue(0); - final double y = transformable.doubleValue(1); - final double z = transformable.doubleValue(2); - - transformable.set(0, (r00 * x) + (r01 * y) + (r02 * z)); - transformable.set(1, (r10 * x) + (r11 * y) + (r12 * z)); - transformable.set(2, (r20 * x) + (r21 * y) + (r22 * z)); - - } else if (transformable.countRows() == 3L) { - - for (long c = 0L, limit = transformable.countColumns(); c < limit; c++) { - - final double x = transformable.doubleValue(0, c); - final double y = transformable.doubleValue(1, c); - final double z = transformable.doubleValue(2, c); - - transformable.set(0, c, (r00 * x) + (r01 * y) + (r02 * z)); - transformable.set(1, c, (r10 * x) + (r11 * y) + (r12 * z)); - transformable.set(2, c, (r20 * x) + (r21 * y) + (r22 * z)); - } - - } else if (transformable.countColumns() == 3L) { - - for (long r = 0L, limit = transformable.countRows(); r < limit; r++) { - - final double x = transformable.doubleValue(r, 0); - final double y = transformable.doubleValue(r, 1); - final double z = transformable.doubleValue(r, 2); - - transformable.set(r, 0, (r00 * x) + (r01 * y) + (r02 * z)); - transformable.set(r, 1, (r10 * x) + (r11 * y) + (r12 * z)); - transformable.set(r, 2, (r20 * x) + (r21 * y) + (r22 * z)); - } - - } else { - - throw new ProgrammingError("Only works for 3D stuff!"); - } + public Quaternion cast(final Comparable number) { + return Quaternion.valueOf(number); } @Override - public Versor versor() { - return this; - } - - } - - public static final Scalar.Factory FACTORY = new Scalar.Factory() { - public Quaternion cast(final double value) { return Quaternion.valueOf(value); } - public Quaternion cast(final Number number) { + @Override + public Quaternion convert(final Comparable number) { return Quaternion.valueOf(number); } + @Override public Quaternion convert(final double value) { return Quaternion.valueOf(value); } - public Quaternion convert(final Number number) { - return Quaternion.valueOf(number); - } - + @Override public Quaternion one() { return ONE; } + @Override public Quaternion zero() { return ZERO; } }; - public static final Quaternion I = new Versor(PrimitiveMath.ONE, PrimitiveMath.ZERO, PrimitiveMath.ZERO); + public static final Quaternion I = new Quaternion(PrimitiveMath.ONE, PrimitiveMath.ZERO, PrimitiveMath.ZERO); public static final Quaternion IJK = new Quaternion(PrimitiveMath.ONE, PrimitiveMath.ONE, PrimitiveMath.ONE).versor(); public static final Quaternion INFINITY = Quaternion.makePolar(Double.POSITIVE_INFINITY, IJK.vector().toRawCopy1D(), PrimitiveMath.ZERO); - public static final Quaternion J = new Versor(PrimitiveMath.ZERO, PrimitiveMath.ONE, PrimitiveMath.ZERO); - public static final Quaternion K = new Versor(PrimitiveMath.ZERO, PrimitiveMath.ZERO, PrimitiveMath.ONE); - public static final Quaternion NEG = new Versor(PrimitiveMath.NEG); - public static final Quaternion ONE = new Versor(PrimitiveMath.ONE); + public static final Quaternion J = new Quaternion(PrimitiveMath.ZERO, PrimitiveMath.ONE, PrimitiveMath.ZERO); + public static final Quaternion K = new Quaternion(PrimitiveMath.ZERO, PrimitiveMath.ZERO, PrimitiveMath.ONE); + public static final Quaternion NaN = new Quaternion(PrimitiveMath.NaN, PrimitiveMath.NaN, PrimitiveMath.NaN, PrimitiveMath.NaN); + public static final Quaternion NEG = new Quaternion(PrimitiveMath.NEG); + public static final Quaternion ONE = new Quaternion(PrimitiveMath.ONE); public static final Quaternion TWO = new Quaternion(PrimitiveMath.TWO); public static final Quaternion ZERO = new Quaternion(); @@ -313,7 +173,7 @@ public static Quaternion makePolar(final double norm, final double[] unit, final } - public static Versor makeRotation(final RotationAxis axis, final double angle) { + public static Quaternion makeRotation(final RotationAxis axis, final double angle) { final double tmpScalar = PrimitiveMath.COS.invoke(angle); @@ -343,7 +203,7 @@ public static Versor makeRotation(final RotationAxis axis, final double angle) { throw new ProgrammingError("How could this happen?"); } - return new Versor(tmpScalar, tmpI, tmpJ, tmpK); + return new Quaternion(tmpScalar, tmpI, tmpJ, tmpK); } public static Quaternion of(final double i, final double j, final double k) { @@ -354,34 +214,31 @@ public static Quaternion of(final double scalar, final double i, final double j, return new Quaternion(scalar, i, j, k); } - public static Quaternion valueOf(final double value) { - return new Quaternion(value); - } - - public static Quaternion valueOf(final Number number) { - - if (number != null) { - - if (number instanceof Quaternion) { + public static Quaternion valueOf(final Comparable number) { - return (Quaternion) number; + if (number == null) { + return ZERO; + } - } else if (number instanceof ComplexNumber) { + if (number instanceof Quaternion) { - final ComplexNumber tmpComplex = (ComplexNumber) number; - return new Quaternion(tmpComplex.doubleValue(), tmpComplex.i, PrimitiveMath.ZERO, PrimitiveMath.ZERO); + return (Quaternion) number; - } else { + } else if (number instanceof ComplexNumber) { - return new Quaternion(number.doubleValue()); - } + ComplexNumber tmpComplex = (ComplexNumber) number; + return new Quaternion(tmpComplex.doubleValue(), tmpComplex.i, PrimitiveMath.ZERO, PrimitiveMath.ZERO); } else { - return ZERO; + return new Quaternion(Scalar.doubleValue(number)); } } + public static Quaternion valueOf(final double value) { + return new Quaternion(value); + } + public final double i; public final double j; public final double k; @@ -474,6 +331,7 @@ private Quaternion(final double[] vector) { this.k = k; } + @Override public Quaternion add(final double arg) { if (this.isReal()) { @@ -483,6 +341,12 @@ public Quaternion add(final double arg) { } } + @Override + public Quaternion add(float scalarAddend) { + return this.add((double) scalarAddend); + } + + @Override public Quaternion add(final Quaternion arg) { if (this.isReal()) { @@ -504,6 +368,7 @@ public double angle() { return PrimitiveMath.ACOS.invoke(myScalar / this.norm()); } + @Override public int compareTo(final Quaternion reference) { int retVal = 0; @@ -521,6 +386,7 @@ public int compareTo(final Quaternion reference) { return retVal; } + @Override public Quaternion conjugate() { final double tmpScalar = myScalar; @@ -531,18 +397,22 @@ public Quaternion conjugate() { return new Quaternion(tmpScalar, tmpI, tmpJ, tmpK); } + @Override public long count() { return 16L; } + @Override public long countColumns() { return 4L; } + @Override public long countRows() { return 4L; } + @Override public Quaternion divide(final double arg) { if (this.isReal()) { @@ -568,12 +438,16 @@ public Quaternion divide(final double arg) { } } + @Override + public Quaternion divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + /** * Will calculate this * reciprocal(arg) which is not the same as * reciprocal(arg) * this. - * - * @see org.ojalgo.scalar.Scalar#divide(java.lang.Number) */ + @Override public Quaternion divide(final Quaternion arg) { final Quaternion tmpReciprocal = arg.invert(); @@ -586,6 +460,7 @@ public double doubleValue() { return myScalar; } + @Override public double doubleValue(final long index) { switch ((int) index) { case 0: @@ -625,6 +500,7 @@ public double doubleValue(final long index) { } } + @Override public double doubleValue(final long row, final long col) { if (row == col) { return myScalar; @@ -633,6 +509,7 @@ public double doubleValue(final long row, final long col) { } } + @Override public Quaternion enforce(final NumberContext context) { final double tmpScalar = context.enforce(myScalar); @@ -644,17 +521,14 @@ public Quaternion enforce(final NumberContext context) { } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } if (!(obj instanceof Quaternion)) { return false; } - final Quaternion other = (Quaternion) obj; + Quaternion other = (Quaternion) obj; if (Double.doubleToLongBits(myScalar) != Double.doubleToLongBits(other.myScalar)) { return false; } @@ -675,14 +549,17 @@ public float floatValue() { return (float) myScalar; } + @Override public Quaternion get() { return this; } + @Override public Double get(final long index) { return this.doubleValue(index); } + @Override public Double get(final long row, final long col) { return this.doubleValue(row, col); } @@ -719,14 +596,14 @@ public int hashCode() { final int prime = 31; int result = 1; long temp; - temp = Double.doubleToLongBits(myScalar); - result = (prime * result) + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(i); result = (prime * result) + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(j); result = (prime * result) + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(k); result = (prime * result) + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(myScalar); + result = (prime * result) + (int) (temp ^ (temp >>> 32)); return result; } @@ -735,6 +612,7 @@ public int intValue() { return (int) myScalar; } + @Override public Quaternion invert() { final Quaternion tmpConjugate = this.conjugate(); @@ -744,6 +622,7 @@ public Quaternion invert() { return tmpConjugate.divide(tmpSumOfSquares); } + @Override public boolean isAbsolute() { if (myRealForSure) { return myScalar >= PrimitiveMath.ZERO; @@ -761,6 +640,7 @@ public boolean isReal() { return myRealForSure || (cntxt.isSmall(myScalar, i) && cntxt.isSmall(myScalar, j) && cntxt.isSmall(myScalar, k)); } + @Override public boolean isSmall(final double comparedTo) { return PrimitiveScalar.CONTEXT.isSmall(comparedTo, this.norm()); } @@ -770,6 +650,7 @@ public long longValue() { return (long) myScalar; } + @Override public Quaternion multiply(final double arg) { if (this.isReal()) { @@ -795,6 +676,12 @@ public Quaternion multiply(final double arg) { } } + @Override + public Quaternion multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + + @Override public Quaternion multiply(final Quaternion arg) { if (this.isReal()) { @@ -812,6 +699,7 @@ public Quaternion multiply(final Quaternion arg) { } } + @Override public Quaternion negate() { final double tmpScalar = -myScalar; @@ -822,10 +710,12 @@ public Quaternion negate() { return new Quaternion(tmpScalar, tmpI, tmpJ, tmpK); } + @Override public double norm() { return PrimitiveMath.SQRT.invoke(this.calculateSumOfSquaresAll()); } + @Override public Quaternion power(final int power) { Quaternion retVal = ONE; @@ -841,10 +731,12 @@ public double scalar() { return myScalar; } - public Versor signum() { + @Override + public Quaternion signum() { return this.versor(); } + @Override public Quaternion subtract(final double arg) { if (this.isReal()) { @@ -854,6 +746,12 @@ public Quaternion subtract(final double arg) { } } + @Override + public Quaternion subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + + @Override public Quaternion subtract(final Quaternion arg) { final double tmpScalar = myScalar - arg.scalar(); @@ -864,6 +762,7 @@ public Quaternion subtract(final Quaternion arg) { return new Quaternion(tmpScalar, tmpI, tmpJ, tmpK); } + @Override public void supplyTo(final Mutate2D.Receiver receiver) { receiver.set(0L, myScalar); receiver.set(1L, i); @@ -883,13 +782,14 @@ public void supplyTo(final Mutate2D.Receiver receiver) { receiver.set(15L, myScalar); } + @Override public BigDecimal toBigDecimal() { return new BigDecimal(myScalar, PrimitiveScalar.CONTEXT.getMathContext()); } public MatrixStore toComplexMatrix() { - final GenericDenseStore retVal = GenericDenseStore.COMPLEX.make(2L, 2L); + final GenericStore retVal = GenericStore.COMPLEX.make(2L, 2L); retVal.set(0L, ComplexNumber.of(myScalar, i)); retVal.set(1L, ComplexNumber.of(-j, k)); @@ -900,14 +800,14 @@ public MatrixStore toComplexMatrix() { } public MatrixStore toMultiplicationMatrix() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(this); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(this); this.supplyTo(retVal); return retVal; } public MatrixStore toMultiplicationVector() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(4L, 1L); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(4L, 1L); retVal.set(0L, myScalar); retVal.set(1L, i); @@ -919,7 +819,7 @@ public MatrixStore toMultiplicationVector() { public MatrixStore toRotationMatrix() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(3L, 3L); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(3L, 3L); final double s = myScalar; @@ -1002,6 +902,7 @@ public String toString() { return retVal.toString(); } + @Override public String toString(final NumberContext context) { final StringBuilder retVal = new StringBuilder("("); @@ -1040,6 +941,7 @@ public String toString(final NumberContext context) { return retVal.toString(); } + @Override public & Access2D> void transform(final T transformable) { final double s = myScalar; @@ -1126,7 +1028,7 @@ public double[] unit() { public PhysicalStore vector() { - final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.make(3L, 1L); + final Primitive64Store retVal = Primitive64Store.FACTORY.make(3L, 1L); retVal.set(0L, i); retVal.set(1L, j); @@ -1135,16 +1037,16 @@ public PhysicalStore vector() { return retVal; } - public Versor versor() { + public Quaternion versor() { final double norm = this.norm(); if (this.isReal()) { - return new Versor(myScalar / norm); + return new Quaternion(myScalar / norm); } else if (this.isPure()) { - return new Versor(i / norm, j / norm, k / norm); + return new Quaternion(i / norm, j / norm, k / norm); } else { - return new Versor(myScalar / norm, i / norm, j / norm, k / norm); + return new Quaternion(myScalar / norm, i / norm, j / norm, k / norm); } } @@ -1156,4 +1058,123 @@ private double calculateSumOfSquaresVector() { return (i * i) + (j * j) + (k * k); } + MatrixStore toRotationMatrixVersor() { + + final Primitive64Store retVal = Primitive64Store.FACTORY.make(3L, 3L); + + final double s = this.doubleValue(); + + final double ss = s * s; + final double ii = i * i; + final double jj = j * j; + final double kk = k * k; + + double tmp1; + double tmp2; + + final double r00 = ((ii + ss) - (jj + kk)); + final double r11 = ((jj + ss) - (ii + kk)); + final double r22 = ((kk + ss) - (ii + jj)); + + tmp1 = i * j; + tmp2 = k * s; + final double r10 = 2.0 * (tmp1 + tmp2); + final double r01 = 2.0 * (tmp1 - tmp2); + + tmp1 = i * k; + tmp2 = j * s; + final double r20 = 2.0 * (tmp1 - tmp2); + final double r02 = 2.0 * (tmp1 + tmp2); + + tmp1 = j * k; + tmp2 = i * s; + final double r21 = 2.0 * (tmp1 + tmp2); + final double r12 = 2.0 * (tmp1 - tmp2); + + retVal.set(0L, r00); + retVal.set(1L, r10); + retVal.set(2L, r20); + retVal.set(3L, r01); + retVal.set(4L, r11); + retVal.set(5L, r21); + retVal.set(6L, r02); + retVal.set(7L, r12); + retVal.set(8L, r22); + + return retVal; + } + + & Access2D> void transformVersor(final T transformable) { + + final double s = this.doubleValue(); + + final double ss = s * s; + final double ii = i * i; + final double jj = j * j; + final double kk = k * k; + + double tmp1; + double tmp2; + + final double r00 = ((ii + ss) - (jj + kk)); + final double r11 = ((jj + ss) - (ii + kk)); + final double r22 = ((kk + ss) - (ii + jj)); + + tmp1 = i * j; + tmp2 = k * s; + final double r10 = 2.0 * (tmp1 + tmp2); + final double r01 = 2.0 * (tmp1 - tmp2); + + tmp1 = i * k; + tmp2 = j * s; + final double r20 = 2.0 * (tmp1 - tmp2); + final double r02 = 2.0 * (tmp1 + tmp2); + + tmp1 = j * k; + tmp2 = i * s; + final double r21 = 2.0 * (tmp1 + tmp2); + final double r12 = 2.0 * (tmp1 - tmp2); + + if (transformable.count() == 3L) { + + final double x = transformable.doubleValue(0); + final double y = transformable.doubleValue(1); + final double z = transformable.doubleValue(2); + + transformable.set(0, (r00 * x) + (r01 * y) + (r02 * z)); + transformable.set(1, (r10 * x) + (r11 * y) + (r12 * z)); + transformable.set(2, (r20 * x) + (r21 * y) + (r22 * z)); + + } else if (transformable.countRows() == 3L) { + + for (long c = 0L, limit = transformable.countColumns(); c < limit; c++) { + + final double x = transformable.doubleValue(0, c); + final double y = transformable.doubleValue(1, c); + final double z = transformable.doubleValue(2, c); + + transformable.set(0, c, (r00 * x) + (r01 * y) + (r02 * z)); + transformable.set(1, c, (r10 * x) + (r11 * y) + (r12 * z)); + transformable.set(2, c, (r20 * x) + (r21 * y) + (r22 * z)); + } + + } else if (transformable.countColumns() == 3L) { + + for (long r = 0L, limit = transformable.countRows(); r < limit; r++) { + + final double x = transformable.doubleValue(r, 0); + final double y = transformable.doubleValue(r, 1); + final double z = transformable.doubleValue(r, 2); + + transformable.set(r, 0, (r00 * x) + (r01 * y) + (r02 * z)); + transformable.set(r, 1, (r10 * x) + (r11 * y) + (r12 * z)); + transformable.set(r, 2, (r20 * x) + (r21 * y) + (r22 * z)); + } + + } else { + + throw new ProgrammingError("Only works for 3D stuff!"); + } + } + } diff --git a/src/org/ojalgo/scalar/RationalNumber.java b/src/org/ojalgo/scalar/RationalNumber.java index 1ba9be190..ed73a6e16 100644 --- a/src/org/ojalgo/scalar/RationalNumber.java +++ b/src/org/ojalgo/scalar/RationalNumber.java @@ -30,30 +30,36 @@ import org.ojalgo.type.context.NumberContext; import org.ojalgo.type.context.NumberContext.Enforceable; -public final class RationalNumber extends Number implements Scalar, Enforceable { +public final class RationalNumber implements Scalar, Enforceable { public static final Scalar.Factory FACTORY = new Scalar.Factory() { + @Override + public RationalNumber cast(final Comparable number) { + return RationalNumber.valueOf(number); + } + + @Override public RationalNumber cast(final double value) { return RationalNumber.valueOf(value); } - public RationalNumber cast(final Number number) { + @Override + public RationalNumber convert(final Comparable number) { return RationalNumber.valueOf(number); } + @Override public RationalNumber convert(final double value) { return RationalNumber.valueOf(value); } - public RationalNumber convert(final Number number) { - return RationalNumber.valueOf(number); - } - + @Override public RationalNumber one() { return ONE; } + @Override public RationalNumber zero() { return ZERO; } @@ -73,7 +79,6 @@ public RationalNumber zero() { private static final String DIVIDE = " / "; private static final String LEFT = "("; private static final int MAX_BITS = BigInteger.valueOf(Long.MAX_VALUE).bitLength(); - private static final RationalNumber MINUS_ONE = ONE.negate(); private static final String RIGHT = ")"; private static final long SAFE_LIMIT = Math.round(Math.sqrt(Long.MAX_VALUE / 2L)); @@ -123,6 +128,59 @@ public static RationalNumber rational(final double d) { } } + public static RationalNumber valueOf(final Comparable number) { + + if (number == null) { + return ZERO; + } + + if (number instanceof RationalNumber) { + + return (RationalNumber) number; + + } else { + + BigDecimal tmpBigD = TypeUtils.toBigDecimal(number); + + BigInteger retNumer; + BigInteger retDenom; + + int scale = tmpBigD.scale(); + + if (scale < 0) { + + retNumer = tmpBigD.unscaledValue().multiply(BigInteger.TEN.pow(-scale)); + retDenom = BigInteger.ONE; + + } else { + + retNumer = tmpBigD.unscaledValue(); + retDenom = BigInteger.TEN.pow(scale); + + BigInteger gcd = retNumer.gcd(retDenom); + if (gcd.compareTo(BigInteger.ONE) == 1) { + retNumer = retNumer.divide(gcd); + retDenom = retDenom.divide(gcd); + } + } + + int bits = Math.max(retNumer.bitLength(), retDenom.bitLength()); + + if (bits > MAX_BITS) { + int shift = bits - MAX_BITS; + retNumer = retNumer.shiftRight(shift); + retDenom = retDenom.shiftRight(shift); + } + + // final BigDecimal recreated = BigFunction.DIVIDE.invoke(new BigDecimal(retNumer), new BigDecimal(retDenom)); + // if (recreated.plus(MathContext.DECIMAL32).compareTo(tmpBigDecimal.plus(MathContext.DECIMAL32)) != 0) { + // BasicLogger.debug("{} != {}", tmpBigDecimal, recreated); + // } + + return new RationalNumber(retNumer.longValue(), retDenom.longValue()); + } + } + public static RationalNumber valueOf(final double value) { if (Double.isNaN(value)) { @@ -173,66 +231,6 @@ public static RationalNumber valueOf(final long value) { return RationalNumber.fromLong(value); } - public static RationalNumber valueOf(final Number number) { - - if (number != null) { - - if (number instanceof RationalNumber) { - - return (RationalNumber) number; - - } else if (number instanceof Double) { - - return RationalNumber.valueOf(number.doubleValue()); - - } else { - - final BigDecimal tmpBigDecimal = TypeUtils.toBigDecimal(number); - - BigInteger retNumer; - BigInteger retDenom; - - final int scale = tmpBigDecimal.scale(); - - if (scale < 0) { - - retNumer = tmpBigDecimal.unscaledValue().multiply(BigInteger.TEN.pow(-scale)); - retDenom = BigInteger.ONE; - - } else { - - retNumer = tmpBigDecimal.unscaledValue(); - retDenom = BigInteger.TEN.pow(scale); - - final BigInteger gcd = retNumer.gcd(retDenom); - if (gcd.compareTo(BigInteger.ONE) == 1) { - retNumer = retNumer.divide(gcd); - retDenom = retDenom.divide(gcd); - } - } - - final int bits = Math.max(retNumer.bitLength(), retDenom.bitLength()); - - if (bits > MAX_BITS) { - final int shift = bits - MAX_BITS; - retNumer = retNumer.shiftRight(shift); - retDenom = retDenom.shiftRight(shift); - } - - // final BigDecimal recreated = BigFunction.DIVIDE.invoke(new BigDecimal(retNumer), new BigDecimal(retDenom)); - // if (recreated.plus(MathContext.DECIMAL32).compareTo(tmpBigDecimal.plus(MathContext.DECIMAL32)) != 0) { - // BasicLogger.debug("{} != {}", tmpBigDecimal, recreated); - // } - - return new RationalNumber(retNumer.longValue(), retDenom.longValue()); - } - - } else { - - return ZERO; - } - } - private static RationalNumber add(final RationalNumber arg1, final RationalNumber arg2) { final BigInteger numer1 = BigInteger.valueOf(arg1.getNumerator()); @@ -388,10 +386,17 @@ private RationalNumber(final long numerator, final long denominator) { } } + @Override public RationalNumber add(final double arg) { return this.add(RationalNumber.valueOf(arg)); } + @Override + public RationalNumber add(float scalarAddend) { + return this.add((double) scalarAddend); + } + + @Override public RationalNumber add(final RationalNumber arg) { if (this.isNaN() || arg.isNaN()) { return NaN; @@ -425,6 +430,7 @@ public RationalNumber add(final RationalNumber arg) { } } + @Override public int compareTo(final RationalNumber reference) { final long refNumer = reference.getNumerator(); @@ -449,14 +455,22 @@ public int compareTo(final RationalNumber reference) { } } + @Override public RationalNumber conjugate() { return this; } + @Override public RationalNumber divide(final double arg) { return this.divide(RationalNumber.valueOf(arg)); } + @Override + public RationalNumber divide(float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + + @Override public RationalNumber divide(final RationalNumber arg) { if (this.isNaN() || arg.isNaN()) { return NaN; @@ -498,22 +512,20 @@ public double doubleValue() { return this.toBigDecimal().doubleValue(); } + @Override public RationalNumber enforce(final NumberContext context) { return RationalNumber.valueOf(this.toBigDecimal(context.getMathContext())); } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } if (!(obj instanceof RationalNumber)) { return false; } - final RationalNumber other = (RationalNumber) obj; + RationalNumber other = (RationalNumber) obj; if (myDenominator != other.myDenominator) { return false; } @@ -528,6 +540,7 @@ public float floatValue() { return this.toBigDecimal().floatValue(); } + @Override public RationalNumber get() { return this; } @@ -546,14 +559,17 @@ public int intValue() { return this.toBigDecimal().intValue(); } + @Override public RationalNumber invert() { return this.sign() >= 0 ? new RationalNumber(myDenominator, myNumerator) : new RationalNumber(-myDenominator, -myNumerator); } + @Override public boolean isAbsolute() { return myNumerator >= 0L; } + @Override public boolean isSmall(final double comparedTo) { return BigScalar.CONTEXT.isSmall(comparedTo, this.doubleValue()); } @@ -563,10 +579,17 @@ public long longValue() { return this.toBigDecimal().longValue(); } + @Override public RationalNumber multiply(final double arg) { return this.multiply(RationalNumber.valueOf(arg)); } + @Override + public RationalNumber multiply(float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + + @Override public RationalNumber multiply(final RationalNumber arg) { if (this.isNaN() || arg.isNaN()) { return NaN; @@ -589,14 +612,17 @@ public RationalNumber multiply(final RationalNumber arg) { } } + @Override public RationalNumber negate() { return new RationalNumber(-myNumerator, myDenominator); } + @Override public double norm() { return PrimitiveMath.ABS.invoke(this.doubleValue()); } + @Override public RationalNumber power(final int power) { RationalNumber retVal = ONE; @@ -608,20 +634,28 @@ public RationalNumber power(final int power) { return retVal; } + @Override public RationalNumber signum() { if (!this.isInfinite() && RationalNumber.isSmall(PrimitiveMath.ONE, this)) { return ZERO; } else if (this.sign() == -1) { - return MINUS_ONE; + return NEG; } else { return ONE; } } + @Override public RationalNumber subtract(final double arg) { return this.subtract(RationalNumber.valueOf(arg)); } + @Override + public RationalNumber subtract(float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + + @Override public RationalNumber subtract(final RationalNumber arg) { if (this.isNaN() || arg.isNaN()) { return NaN; @@ -655,6 +689,7 @@ public RationalNumber subtract(final RationalNumber arg) { } } + @Override public BigDecimal toBigDecimal() { if (myDecimal == null) { myDecimal = this.toBigDecimal(BigScalar.CONTEXT.getMathContext()); @@ -667,6 +702,7 @@ public String toString() { return RationalNumber.toString(this); } + @Override public String toString(final NumberContext context) { return RationalNumber.toString(this.enforce(context)); } diff --git a/src/org/ojalgo/scalar/Scalar.java b/src/org/ojalgo/scalar/Scalar.java index d4e57cee1..25dedf4ce 100644 --- a/src/org/ojalgo/scalar/Scalar.java +++ b/src/org/ojalgo/scalar/Scalar.java @@ -27,7 +27,9 @@ import org.ojalgo.algebra.Field; import org.ojalgo.algebra.NormedVectorSpace; import org.ojalgo.algebra.ScalarOperation; +import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.structure.AccessScalar; +import org.ojalgo.type.NumberDefinition; import org.ojalgo.type.context.NumberContext; /** @@ -36,31 +38,31 @@ *

*
    *
  1. An abstraction of a vector/matrix element.
  2. - *
  3. A {@linkplain Number} decorator, increasing the number of things you can do with them.
  4. + *
  5. A {@linkplain Comparable} decorator, increasing the number of things you can do with them.
  6. *
*

* Theoretically it is a Field or at least a Division ring. *

*

- * The intention is that implementors should be final immutable subclasses of {@link Number} and that they + * The intention is that implementors should be final immutable subclasses of {@link Comparable} and that they * should be inline with the requirements for ValueBased classes. *

* * @author apete */ -public interface Scalar extends AccessScalar, Field>, NormedVectorSpace, N>, ScalarOperation.Addition, N>, - ScalarOperation.Division, N>, ScalarOperation.Subtraction, N>, Comparable { +public interface Scalar> extends AccessScalar, Field>, NormedVectorSpace, N>, + ScalarOperation.Addition, N>, ScalarOperation.Division, N>, ScalarOperation.Subtraction, N>, Comparable { - public interface Factory { + public interface Factory> { + + N cast(Comparable number); N cast(double value); - N cast(Number number); + Scalar convert(Comparable number); Scalar convert(double value); - Scalar convert(Number number); - @SuppressWarnings("unchecked") default N[] newArrayInstance(final int length) { return (N[]) Array.newInstance(this.zero().get().getClass(), length); @@ -78,10 +80,72 @@ default N[] newArrayInstance(final int length) { } + static double doubleValue(final Comparable number) { + + if (number == null) { + return PrimitiveMath.ZERO; + } + + if (number instanceof NumberDefinition) { + return ((NumberDefinition) number).doubleValue(); + } else if (number instanceof Number) { + return ((Number) number).doubleValue(); + } else { + return PrimitiveMath.NaN; + } + } + + static float floatValue(final Comparable number) { + + if (number == null) { + return 0F; + } + + if (number instanceof NumberDefinition) { + return ((NumberDefinition) number).floatValue(); + } else if (number instanceof Number) { + return ((Number) number).floatValue(); + } else { + return Float.NaN; + } + } + + static int intValue(final Comparable number) { + + if (number == null) { + return 0; + } + + if (number instanceof NumberDefinition) { + return ((NumberDefinition) number).intValue(); + } else if (number instanceof Number) { + return ((Number) number).intValue(); + } else { + return Integer.MIN_VALUE; + } + } + + static long longValue(final Comparable number) { + + if (number == null) { + return 0L; + } + + if (number instanceof NumberDefinition) { + return ((NumberDefinition) number).longValue(); + } else if (number instanceof Number) { + return ((Number) number).longValue(); + } else { + return Long.MIN_VALUE; + } + } + + @Override default Scalar add(final Scalar addend) { return this.add(addend.get()); } + @Override default Scalar divide(final Scalar divisor) { return this.divide(divisor.get()); } @@ -93,10 +157,12 @@ default Scalar divide(final Scalar divisor) { */ boolean isAbsolute(); + @Override default Scalar multiply(final Scalar multiplicand) { return this.multiply(multiplicand.get()); } + @Override default Scalar subtract(final Scalar subtrahend) { return this.subtract(subtrahend.get()); } diff --git a/src/org/ojalgo/series/BasicSeries.java b/src/org/ojalgo/series/BasicSeries.java index f45960720..8378b4531 100644 --- a/src/org/ojalgo/series/BasicSeries.java +++ b/src/org/ojalgo/series/BasicSeries.java @@ -61,7 +61,7 @@ * * @author apete */ -public interface BasicSeries, V extends Number> extends SortedMap { +public interface BasicSeries, V extends Comparable> extends SortedMap { /** * A series with naturally sequenced keys - given any key there is a natural "next" key, e.g. with a @@ -70,7 +70,7 @@ public interface BasicSeries, V extends Number> * * @author apete */ - interface NaturallySequenced, V extends Number> extends BasicSeries, Access1D { + interface NaturallySequenced, V extends Comparable> extends BasicSeries, Access1D { default PrimitiveSeries asPrimitive() { return PrimitiveSeries.wrap(this); @@ -139,12 +139,12 @@ public static final class TimeSeriesBuilder> { myTimeIndex = timeIndex; } - public BasicSeries.NaturallySequenced build(final DenseArray.Factory denseArrayFactory) { + public > BasicSeries.NaturallySequenced build(final DenseArray.Factory denseArrayFactory) { ProgrammingError.throwIfNull(denseArrayFactory); return this.doBuild(denseArrayFactory, null); } - public BasicSeries.NaturallySequenced build(final DenseArray.Factory denseArrayFactory, + public > BasicSeries.NaturallySequenced build(final DenseArray.Factory denseArrayFactory, final BinaryFunction accumularor) { ProgrammingError.throwIfNull(denseArrayFactory, accumularor); return this.doBuild(denseArrayFactory, accumularor); @@ -160,7 +160,8 @@ public TimeSeriesBuilder resolution(final CalendarDate.Resolution resolution) return this; } - private BasicSeries.NaturallySequenced doBuild(final DenseArray.Factory arrayFactory, final BinaryFunction accumularor) { + private > BasicSeries.NaturallySequenced doBuild(final DenseArray.Factory arrayFactory, + final BinaryFunction accumularor) { if (myReference != null) { if (myResolution != null) { return new MappedIndexSeries<>(arrayFactory, myTimeIndex.from(myReference, myResolution), accumularor); @@ -264,13 +265,12 @@ static BasicSeries make(final DenseArray.Factory arrayFa return new MappedIndexSeries<>(arrayFactory, MappedIndexSeries.MAPPER, accumulator); } - static > BasicSeries make(final DenseArray.Factory arrayFactory, - final Structure1D.IndexMapper indexMapper) { + static > BasicSeries make(final DenseArray.Factory arrayFactory, final Structure1D.IndexMapper indexMapper) { return new MappedIndexSeries<>(arrayFactory, indexMapper, null); } - static > BasicSeries make(final DenseArray.Factory arrayFactory, - final Structure1D.IndexMapper indexMapper, final BinaryFunction accumulator) { + static > BasicSeries make(final DenseArray.Factory arrayFactory, final Structure1D.IndexMapper indexMapper, + final BinaryFunction accumulator) { return new MappedIndexSeries<>(arrayFactory, indexMapper, accumulator); } diff --git a/src/org/ojalgo/series/CalendarDateSeries.java b/src/org/ojalgo/series/CalendarDateSeries.java index e2cf2cfa7..08363a0eb 100644 --- a/src/org/ojalgo/series/CalendarDateSeries.java +++ b/src/org/ojalgo/series/CalendarDateSeries.java @@ -29,12 +29,13 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.netio.ASCII; +import org.ojalgo.scalar.Scalar; import org.ojalgo.series.primitive.ExplicitTimeSeries; import org.ojalgo.type.CalendarDate; import org.ojalgo.type.CalendarDate.Resolution; import org.ojalgo.type.CalendarDateUnit; -public final class CalendarDateSeries extends TreeSeries> +public final class CalendarDateSeries> extends TreeSeries> implements BasicSeries.NaturallySequenced { private final IndexMapper myMapper; @@ -171,7 +172,7 @@ public double put(final CalendarDate key, final double value) { final Double tmpValue = Double.valueOf(value); final N tmpOldValue = super.put(key.filter(myResolution), (N) tmpValue); if (tmpOldValue != null) { - return tmpOldValue.doubleValue(); + return Scalar.doubleValue(tmpOldValue); } else { return Double.NaN; } diff --git a/src/org/ojalgo/series/CoordinationSet.java b/src/org/ojalgo/series/CoordinationSet.java index 0af2fde09..8b92bf2d9 100644 --- a/src/org/ojalgo/series/CoordinationSet.java +++ b/src/org/ojalgo/series/CoordinationSet.java @@ -38,7 +38,7 @@ * * @author apete */ -public class CoordinationSet extends HashMap> { +public class CoordinationSet> extends HashMap> { private CalendarDateUnit myResolution = null; diff --git a/src/org/ojalgo/series/MappedIndexSeries.java b/src/org/ojalgo/series/MappedIndexSeries.java index ee6c7c352..7dfdcd583 100644 --- a/src/org/ojalgo/series/MappedIndexSeries.java +++ b/src/org/ojalgo/series/MappedIndexSeries.java @@ -39,7 +39,8 @@ import org.ojalgo.type.ColourData; import org.ojalgo.type.TypeUtils; -final class MappedIndexSeries, N extends Number> extends AbstractMap implements BasicSeries.NaturallySequenced { +final class MappedIndexSeries, N extends Comparable> extends AbstractMap + implements BasicSeries.NaturallySequenced { static final Structure1D.IndexMapper MAPPER = new Structure1D.IndexMapper() { diff --git a/src/org/ojalgo/series/NumberSeries.java b/src/org/ojalgo/series/NumberSeries.java index e582885ae..421dda887 100644 --- a/src/org/ojalgo/series/NumberSeries.java +++ b/src/org/ojalgo/series/NumberSeries.java @@ -27,9 +27,10 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; -public final class NumberSeries> extends TreeSeries> { +public final class NumberSeries> extends TreeSeries> { public NumberSeries() { super(); @@ -73,7 +74,7 @@ public double put(final N key, final double value) { final Double tmpValue = Double.valueOf(value); final N tmpOldValue = super.put(key, (N) tmpValue); if (tmpOldValue != null) { - return tmpOldValue.doubleValue(); + return Scalar.doubleValue(tmpOldValue); } else { return Double.NaN; } diff --git a/src/org/ojalgo/series/SeriesInterpolator.java b/src/org/ojalgo/series/SeriesInterpolator.java index da370e23b..ddcb0898a 100644 --- a/src/org/ojalgo/series/SeriesInterpolator.java +++ b/src/org/ojalgo/series/SeriesInterpolator.java @@ -47,7 +47,7 @@ public SeriesInterpolator(final NumberContext context) { myContext = context; } - public void addSeries(final Number key, final CalendarDateSeries series) { + public void addSeries(final Comparable key, final CalendarDateSeries series) { final BigDecimal tmpKey = TypeUtils.toBigDecimal(key, myContext); @@ -56,7 +56,7 @@ public void addSeries(final Number key, final CalendarDateSeries series) myCoordinatedSet = null; } - public CalendarDateSeries getCombination(final Number inputKey) { + public CalendarDateSeries getCombination(final Comparable inputKey) { final BigDecimal tmpInputKey = TypeUtils.toBigDecimal(inputKey, myContext); diff --git a/src/org/ojalgo/series/TreeSeries.java b/src/org/ojalgo/series/TreeSeries.java index 7c40af00f..7e2830723 100644 --- a/src/org/ojalgo/series/TreeSeries.java +++ b/src/org/ojalgo/series/TreeSeries.java @@ -28,12 +28,14 @@ import java.util.UUID; import org.ojalgo.netio.ASCII; +import org.ojalgo.scalar.Scalar; import org.ojalgo.series.primitive.DataSeries; import org.ojalgo.series.primitive.PrimitiveSeries; import org.ojalgo.type.ColourData; import org.ojalgo.type.TypeUtils; -abstract class TreeSeries, N extends Number, I extends TreeSeries> extends TreeMap implements BasicSeries { +abstract class TreeSeries, N extends Comparable, I extends TreeSeries> extends TreeMap + implements BasicSeries { private ColourData myColour = null; private String myName = null; @@ -61,7 +63,7 @@ public PrimitiveSeries asPrimitive() { int i = 0; for (final N tmpValue : this.values()) { - retVal[i] = tmpValue.doubleValue(); + retVal[i] = Scalar.doubleValue(tmpValue); i++; } @@ -75,7 +77,7 @@ public I colour(final ColourData colour) { } public final double doubleValue(final K key) { - return this.get(key).doubleValue(); + return Scalar.doubleValue(this.get(key)); } public N firstValue() { diff --git a/src/org/ojalgo/series/function/SeriesExtrapolator.java b/src/org/ojalgo/series/function/SeriesExtrapolator.java index 3ab0cf0f1..e349dbb62 100644 --- a/src/org/ojalgo/series/function/SeriesExtrapolator.java +++ b/src/org/ojalgo/series/function/SeriesExtrapolator.java @@ -32,11 +32,11 @@ */ public abstract class SeriesExtrapolator> extends SeriesFunction { - protected SeriesExtrapolator(final BasicSeries data) { + protected SeriesExtrapolator(final BasicSeries> data) { super(data); } - protected SeriesExtrapolator(final Map> data) { + protected SeriesExtrapolator(final Map>> data) { super(data); } diff --git a/src/org/ojalgo/series/function/SeriesForecaster.java b/src/org/ojalgo/series/function/SeriesForecaster.java index 79efb91fc..78c380e91 100644 --- a/src/org/ojalgo/series/function/SeriesForecaster.java +++ b/src/org/ojalgo/series/function/SeriesForecaster.java @@ -50,7 +50,7 @@ private SeriesForecaster(final BasicSeries data) myResolution = null; } - private SeriesForecaster(final Map> data) { + private SeriesForecaster(final Map>> data) { super(data); @@ -58,7 +58,7 @@ private SeriesForecaster(final Map data) { + protected SeriesForecaster(final CalendarDateSeries> data) { super(data); @@ -66,7 +66,7 @@ protected SeriesForecaster(final CalendarDateSeries data) { myResolution = data.getResolution(); } - protected SeriesForecaster(final CoordinationSet coordinatedHistoricalData) { + protected SeriesForecaster(final CoordinationSet> coordinatedHistoricalData) { super(coordinatedHistoricalData); diff --git a/src/org/ojalgo/series/function/SeriesFunction.java b/src/org/ojalgo/series/function/SeriesFunction.java index 0a5f0cf5f..fb30738ff 100644 --- a/src/org/ojalgo/series/function/SeriesFunction.java +++ b/src/org/ojalgo/series/function/SeriesFunction.java @@ -38,7 +38,7 @@ */ public abstract class SeriesFunction> { - private final Map> myData; + private final Map>> myData; @SuppressWarnings("unused") private SeriesFunction() { @@ -48,14 +48,14 @@ private SeriesFunction() { myData = null; } - protected SeriesFunction(final BasicSeries data) { + protected SeriesFunction(final BasicSeries> data) { super(); myData = Collections.singletonMap(data.getName(), data); } - protected SeriesFunction(final Map> data) { + protected SeriesFunction(final Map>> data) { super(); @@ -73,7 +73,7 @@ protected List getAllSeriesNames() { return new ArrayList<>(myData.keySet()); } - protected BasicSeries getSeries(final String name) { + protected BasicSeries> getSeries(final String name) { return myData.get(name); } diff --git a/src/org/ojalgo/series/function/SeriesInterpolator.java b/src/org/ojalgo/series/function/SeriesInterpolator.java index 2ee22e4c1..82be5551a 100644 --- a/src/org/ojalgo/series/function/SeriesInterpolator.java +++ b/src/org/ojalgo/series/function/SeriesInterpolator.java @@ -32,11 +32,11 @@ */ public abstract class SeriesInterpolator> extends SeriesExtrapolator { - protected SeriesInterpolator(final BasicSeries data) { + protected SeriesInterpolator(final BasicSeries> data) { super(data); } - protected SeriesInterpolator(final Map> data) { + protected SeriesInterpolator(final Map>> data) { super(data); } diff --git a/src/org/ojalgo/series/primitive/CoordinatedSet.java b/src/org/ojalgo/series/primitive/CoordinatedSet.java index df064c794..24b1f2e5f 100644 --- a/src/org/ojalgo/series/primitive/CoordinatedSet.java +++ b/src/org/ojalgo/series/primitive/CoordinatedSet.java @@ -30,7 +30,7 @@ import java.util.function.UnaryOperator; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.series.BasicSeries; public class CoordinatedSet> { @@ -126,7 +126,7 @@ public K getLastKey() { } public MatrixStore getSamples() { - return PrimitiveDenseStore.FACTORY.columns(myCoordinated); + return Primitive64Store.FACTORY.columns(myCoordinated); } public MatrixStore getSamples(final UnaryOperator operator) { @@ -134,7 +134,7 @@ public MatrixStore getSamples(final UnaryOperator opera for (int i = 0; i < operated.length; i++) { operated[i] = operator.apply(myCoordinated[i]); } - return PrimitiveDenseStore.FACTORY.columns(operated); + return Primitive64Store.FACTORY.columns(operated); } public PrimitiveSeries getSeries(final int index) { diff --git a/src/org/ojalgo/structure/Access1D.java b/src/org/ojalgo/structure/Access1D.java index 75190c293..ad77650cf 100644 --- a/src/org/ojalgo/structure/Access1D.java +++ b/src/org/ojalgo/structure/Access1D.java @@ -38,7 +38,7 @@ * * @author apete */ -public interface Access1D extends Structure1D { +public interface Access1D> extends Structure1D { /** * This interface complements {@linkplain Visitable} but does not extend it. It's a feature to be able to @@ -46,7 +46,7 @@ public interface Access1D extends Structure1D { * * @author apete */ - public interface Aggregatable extends Structure1D { + public interface Aggregatable> extends Structure1D { default N aggregateAll(final Aggregator aggregator) { return this.aggregateRange(0L, this.count(), aggregator); @@ -56,7 +56,7 @@ default N aggregateAll(final Aggregator aggregator) { } - public interface Collectable> extends Structure1D { + public interface Collectable, R extends Mutate1D.Receiver> extends Structure1D { default I collect(final Factory1D factory) { @@ -106,7 +106,7 @@ default boolean isAllSmall(final double comparedTo) { } - public static final class ElementView implements ElementView1D> { + public static final class ElementView> implements ElementView1D> { private long myCursor; private final long myLastCursor; @@ -208,13 +208,13 @@ default long indexOfLargest() { } - public interface Sliceable extends Structure1D { + public interface Sliceable> extends Structure1D { Access1D sliceRange(long first, long limit); } - public interface Visitable extends Structure1D { + public interface Visitable> extends Structure1D { default void visitAll(final VoidFunction visitor) { this.visitRange(0L, this.count(), visitor); @@ -330,7 +330,7 @@ public String toString() { }; } - static Access1D wrap(final List target) { + static > Access1D wrap(final List target) { return new Access1D() { public long count() { @@ -338,7 +338,7 @@ public long count() { } public double doubleValue(final long index) { - return target.get((int) index).doubleValue(); + return Scalar.doubleValue(target.get((int) index)); } public N get(final long index) { @@ -353,7 +353,7 @@ public String toString() { }; } - static Access1D wrap(final N[] target) { + static > Access1D wrap(final N[] target) { return new Access1D() { public long count() { @@ -361,7 +361,7 @@ public long count() { } public double doubleValue(final long index) { - return target[(int) index].doubleValue(); + return Scalar.doubleValue(target[(int) index]); } public N get(final long index) { @@ -377,9 +377,10 @@ public String toString() { } /** - * Transforms this {@link Access1D} to a {@link Access1D.Collectable} of a different {@link Number} type. + * Transforms this {@link Access1D} to a {@link Access1D.Collectable} of a different {@link Comparable} + * type. */ - default > Collectable asCollectable1D() { + default , R extends Mutate1D.Receiver> Collectable asCollectable1D() { return new Collectable() { public long count() { diff --git a/src/org/ojalgo/structure/Access2D.java b/src/org/ojalgo/structure/Access2D.java index a3c4fb331..40319ffb3 100644 --- a/src/org/ojalgo/structure/Access2D.java +++ b/src/org/ojalgo/structure/Access2D.java @@ -32,9 +32,9 @@ * @see Access1D * @author apete */ -public interface Access2D extends Structure2D, Access1D { +public interface Access2D> extends Structure2D, Access1D { - public interface Aggregatable extends Structure2D, Access1D.Aggregatable { + public interface Aggregatable> extends Structure2D, Access1D.Aggregatable { default N aggregateColumn(final long col, final Aggregator aggregator) { return this.aggregateColumn(0L, col, aggregator); @@ -68,7 +68,7 @@ default void reduceRows(final Aggregator aggregator, final Mutate1D receiver) { } - public interface Collectable> extends Structure2D { + public interface Collectable, R extends Mutate2D.Receiver> extends Structure2D { default I collect(final Factory2D factory) { @@ -169,7 +169,7 @@ default boolean isSmall(final long index, final double comparedTo) { } - public static final class ElementView implements ElementView2D> { + public static final class ElementView> implements ElementView2D> { private final ElementView1D myDelegate; private final long myStructure; @@ -308,7 +308,7 @@ default long indexOfLargestOnDiagonal() { } - public interface Sliceable extends Structure2D, Access1D.Sliceable { + public interface Sliceable> extends Structure2D, Access1D.Sliceable { default Access1D sliceColumn(final long col) { return this.sliceColumn(0L, col); @@ -331,7 +331,7 @@ default Access1D sliceRow(final long row) { } - public interface Visitable extends Structure2D, Access1D.Visitable { + public interface Visitable> extends Structure2D, Access1D.Visitable { default void visitColumn(final long row, final long col, final VoidFunction visitor) { this.loopColumn(row, col, (r, c) -> this.visitOne(r, c, visitor)); @@ -517,7 +517,7 @@ public final String toString() { }; } - static Access2D wrap(final N[][] target) { + static > Access2D wrap(final N[][] target) { return new Access2D() { public long count() { @@ -533,11 +533,11 @@ public long countRows() { } public double doubleValue(final long index) { - return this.get(index).doubleValue(); + return Scalar.doubleValue(this.get(index)); } public double doubleValue(final long row, final long col) { - return this.get(row, col).doubleValue(); + return Scalar.doubleValue(this.get(row, col)); } public N get(final long row, final long col) { @@ -552,7 +552,7 @@ public final String toString() { }; } - default > Collectable asCollectable2D() { + default , R extends Mutate2D.Receiver> Collectable asCollectable2D() { return new Collectable() { public long countColumns() { diff --git a/src/org/ojalgo/structure/AccessAnyD.java b/src/org/ojalgo/structure/AccessAnyD.java index 5dbe1be71..75476a839 100644 --- a/src/org/ojalgo/structure/AccessAnyD.java +++ b/src/org/ojalgo/structure/AccessAnyD.java @@ -32,13 +32,13 @@ * @see Access1D * @author apete */ -public interface AccessAnyD extends StructureAnyD, Access1D { +public interface AccessAnyD> extends StructureAnyD, Access1D { - public interface Aggregatable extends StructureAnyD, Access1D.Aggregatable { + public interface Aggregatable> extends StructureAnyD, Access1D.Aggregatable { - Number aggregateSet(int dimension, long dimensionalIndex, Aggregator aggregator); + N aggregateSet(int dimension, long dimensionalIndex, Aggregator aggregator); - Number aggregateSet(long[] initial, int dimension, Aggregator aggregator); + N aggregateSet(long[] initial, int dimension, Aggregator aggregator); default void reduce(final int dimension, final Aggregator aggregator, final Mutate1D receiver) { final long count1 = this.count(dimension); @@ -50,7 +50,7 @@ default void reduce(final int dimension, final Aggregator aggregator, final Muta } - public interface Collectable> extends StructureAnyD { + public interface Collectable, R extends MutateAnyD.Receiver> extends StructureAnyD { default I collect(final FactoryAnyD factory) { @@ -95,13 +95,13 @@ public interface IndexOf extends StructureAnyD, Access1D.IndexOf { } - public interface Sliceable extends StructureAnyD, Access1D.Sliceable { + public interface Sliceable> extends StructureAnyD, Access1D.Sliceable { Access1D sliceSet(final long[] initial, final int dimension); } - public interface Visitable extends StructureAnyD, Access1D.Visitable { + public interface Visitable> extends StructureAnyD, Access1D.Visitable { void visitOne(long[] reference, VoidFunction visitor); @@ -160,7 +160,7 @@ static boolean equals(final AccessAnyD accessA, final AccessAnyD accessB, return retVal && Access1D.equals(accessA, accessB, context); } - default > Collectable asCollectableAnyD() { + default , R extends MutateAnyD.Receiver> Collectable asCollectableAnyD() { return new Collectable() { public long count(final int dimension) { diff --git a/src/org/ojalgo/structure/AccessScalar.java b/src/org/ojalgo/structure/AccessScalar.java index 6b0ac8898..ef8bb26c2 100644 --- a/src/org/ojalgo/structure/AccessScalar.java +++ b/src/org/ojalgo/structure/AccessScalar.java @@ -21,43 +21,28 @@ */ package org.ojalgo.structure; -import org.ojalgo.type.PrimitiveNumber; +import org.ojalgo.type.NumberDefinition; -public interface AccessScalar extends PrimitiveNumber { +public interface AccessScalar extends NumberDefinition { - /** - * @see Number#byteValue() - */ default byte byteValue() { return (byte) this.shortValue(); } - /** - * @see Number#floatValue() - */ default float floatValue() { return (float) this.doubleValue(); } N get(); - /** - * @see Number#intValue() - */ default int intValue() { return (int) this.longValue(); } - /** - * @see Number#longValue() - */ default long longValue() { return Math.round(this.doubleValue()); } - /** - * @see Number#shortValue() - */ default short shortValue() { return (short) this.intValue(); } diff --git a/src/org/ojalgo/structure/ColumnView.java b/src/org/ojalgo/structure/ColumnView.java index 4d40b2149..4f4c5906c 100644 --- a/src/org/ojalgo/structure/ColumnView.java +++ b/src/org/ojalgo/structure/ColumnView.java @@ -29,7 +29,7 @@ import org.ojalgo.ProgrammingError; -public class ColumnView +public class ColumnView> implements Access1D, Iterable>, Iterator>, Spliterator>, Comparable> { static final int CHARACTERISTICS = Spliterator.CONCURRENT | Spliterator.DISTINCT | Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED diff --git a/src/org/ojalgo/structure/ElementView1D.java b/src/org/ojalgo/structure/ElementView1D.java index 56662e36c..5dba216e4 100644 --- a/src/org/ojalgo/structure/ElementView1D.java +++ b/src/org/ojalgo/structure/ElementView1D.java @@ -30,7 +30,7 @@ import org.ojalgo.ProgrammingError; -public interface ElementView1D> +public interface ElementView1D, V extends ElementView1D> extends AccessScalar, Iterable, Iterator, Spliterator, Comparable { int CHARACTERISTICS = Spliterator.CONCURRENT | Spliterator.DISTINCT | Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED | Spliterator.SIZED diff --git a/src/org/ojalgo/structure/ElementView2D.java b/src/org/ojalgo/structure/ElementView2D.java index da8a02c94..9f06eea9f 100644 --- a/src/org/ojalgo/structure/ElementView2D.java +++ b/src/org/ojalgo/structure/ElementView2D.java @@ -21,7 +21,7 @@ */ package org.ojalgo.structure; -public interface ElementView2D> extends ElementView1D { +public interface ElementView2D, V extends ElementView2D> extends ElementView1D { long column(); diff --git a/src/org/ojalgo/structure/Factory1D.java b/src/org/ojalgo/structure/Factory1D.java index 36788245e..6b7009b2d 100644 --- a/src/org/ojalgo/structure/Factory1D.java +++ b/src/org/ojalgo/structure/Factory1D.java @@ -27,15 +27,20 @@ public interface Factory1D extends FactorySupplement { + /** + * Should only be implemented by factories that always produce dense structures. + * + * @author apete + */ interface Dense extends Factory1D { I copy(Access1D source); I copy(double... source); - I copy(List source); + I copy(List> source); - I copy(Number... source); + I copy(Comparable... source); I makeFilled(long count, NullaryFunction supplier); @@ -45,10 +50,31 @@ default I makeFilled(final Structure1D shape, final NullaryFunction supplier) } + /** + * For when the structures can be either dense or sparse. + * + * @author apete + */ + interface MayBeSparse, SR extends Mutate1D.ModifiableReceiver> extends Factory1D { + + I makeDense(long count); + + default I makeDense(final Structure1D shape) { + return this.make(shape.count()); + } + + I makeSparse(long count); + + default I makeSparse(final Structure1D shape) { + return this.make(shape.count()); + } + + } + I make(long count); default I make(final Structure1D shape) { - return this.makeZero(shape.count()); + return this.make(shape.count()); } /** diff --git a/src/org/ojalgo/structure/Factory2D.java b/src/org/ojalgo/structure/Factory2D.java index 7b71a1bd5..c594c62d9 100644 --- a/src/org/ojalgo/structure/Factory2D.java +++ b/src/org/ojalgo/structure/Factory2D.java @@ -27,6 +27,11 @@ public interface Factory2D extends FactorySupplement { + /** + * Should only be implemented by factories that always produce dense structures. + * + * @author apete + */ interface Dense extends Factory2D { default I column(final double... elements) { @@ -38,9 +43,9 @@ default I column(final double... elements) { I columns(double[]... source); @SuppressWarnings("unchecked") - I columns(List... source); + I columns(List>... source); - I columns(Number[]... source); + I columns(Comparable[]... source); I copy(Access2D source); @@ -59,9 +64,30 @@ default I row(final double... elements) { I rows(double[]... source); @SuppressWarnings("unchecked") - I rows(List... source); + I rows(List>... source); - I rows(Number[]... source); + I rows(Comparable[]... source); + + } + + /** + * For when the structures can be either dense or sparse. + * + * @author apete + */ + interface MayBeSparse, SR extends Mutate2D.ModifiableReceiver> extends Factory2D { + + DR makeDense(long rows, long columns); + + default DR makeDense(final Structure2D shape) { + return this.makeDense(shape.countRows(), shape.countColumns()); + } + + SR makeSparse(long rows, long columns); + + default SR makeSparse(final Structure2D shape) { + return this.makeSparse(shape.countRows(), shape.countColumns()); + } } diff --git a/src/org/ojalgo/structure/FactoryAnyD.java b/src/org/ojalgo/structure/FactoryAnyD.java index de54893d7..92478e309 100644 --- a/src/org/ojalgo/structure/FactoryAnyD.java +++ b/src/org/ojalgo/structure/FactoryAnyD.java @@ -25,6 +25,11 @@ public interface FactoryAnyD extends FactorySupplement { + /** + * Should only be implemented by factories that always produce dense structures. + * + * @author apete + */ interface Dense extends FactoryAnyD { I copy(AccessAnyD source); @@ -37,6 +42,28 @@ default I makeFilled(final StructureAnyD shape, final NullaryFunction supplie } + /** + * For when the structures can be either dense or sparse. + * + * @author apete + */ + interface MayBeSparse, SR extends MutateAnyD.ModifiableReceiver> + extends FactoryAnyD { + + I makeDense(long... structure); + + default I makeDense(final StructureAnyD shape) { + return this.make(shape.shape()); + } + + I makeSparse(long... structure); + + default I makeSparse(final StructureAnyD shape) { + return this.make(shape.shape()); + } + + } + I make(long... structure); default I make(final StructureAnyD shape) { diff --git a/src/org/ojalgo/structure/Iterator1D.java b/src/org/ojalgo/structure/Iterator1D.java index 65fdc32ab..8a5ac1d6b 100644 --- a/src/org/ojalgo/structure/Iterator1D.java +++ b/src/org/ojalgo/structure/Iterator1D.java @@ -25,7 +25,7 @@ import org.ojalgo.ProgrammingError; -public final class Iterator1D implements ListIterator { +public final class Iterator1D> implements ListIterator { private final Access1D myAccess; private final long myCount; diff --git a/src/org/ojalgo/structure/MatrixView.java b/src/org/ojalgo/structure/MatrixView.java index ac4c08087..c258625f3 100644 --- a/src/org/ojalgo/structure/MatrixView.java +++ b/src/org/ojalgo/structure/MatrixView.java @@ -25,7 +25,7 @@ import org.ojalgo.ProgrammingError; -public class MatrixView implements Access2D, Iterable>, Iterator>, Comparable> { +public class MatrixView> implements Access2D, Iterable>, Iterator>, Comparable> { private final long myColumnsCount; private final long myCount; diff --git a/src/org/ojalgo/structure/Mutate1D.java b/src/org/ojalgo/structure/Mutate1D.java index 195343b39..1cfda6fda 100644 --- a/src/org/ojalgo/structure/Mutate1D.java +++ b/src/org/ojalgo/structure/Mutate1D.java @@ -42,13 +42,13 @@ public interface Mutate1D extends Structure1D { * * @author apete */ - interface Fillable extends Structure1D { + interface Fillable> extends Structure1D { default void fillAll(final N value) { this.fillRange(0L, this.count(), value); } - default void fillAll(final NullaryFunction supplier) { + default void fillAll(final NullaryFunction supplier) { this.fillRange(0L, this.count(), supplier); } @@ -75,13 +75,13 @@ default void fillMatching(final UnaryFunction function, final Access1D arg void fillOne(long index, N value); - void fillOne(long index, NullaryFunction supplier); + void fillOne(long index, NullaryFunction supplier); default void fillRange(final long first, final long limit, final N value) { Structure1D.loopRange(first, limit, i -> this.fillOne(i, value)); } - default void fillRange(final long first, final long limit, final NullaryFunction supplier) { + default void fillRange(final long first, final long limit, final NullaryFunction supplier) { Structure1D.loopRange(first, limit, i -> this.fillOne(i, supplier)); } } @@ -93,7 +93,7 @@ default void fillRange(final long first, final long limit, final NullaryFunction * * @author apete */ - interface Mixable extends Structure1D { + interface Mixable> extends Structure1D { /** * @return The new/mixed value @@ -104,7 +104,7 @@ interface Mixable extends Structure1D { } - interface Modifiable extends Structure1D { + interface Modifiable> extends Structure1D { default void modifyAll(final UnaryFunction modifier) { this.modifyRange(0L, this.count(), modifier); @@ -131,7 +131,7 @@ default void modifyRange(final long first, final long limit, final UnaryFunction * * @author apete */ - interface ModifiableReceiver extends Modifiable, Receiver { + interface ModifiableReceiver> extends Modifiable, Receiver { void modifyAny(Transformation1D modifier); @@ -142,8 +142,9 @@ interface ModifiableReceiver extends Modifiable, Receiver extends Mutate1D, Mutate1D.Fillable, Consumer> { + interface Receiver> extends Mutate1D, Mutate1D.Fillable, Consumer> { + @Override default void accept(final Access1D supplied) { if (this.isAcceptable(supplied)) { supplied.loopAll(i -> this.set(i, supplied.get(i))); @@ -218,7 +219,11 @@ static void copyComplexRealAndImaginary(final Access1D source, fi void add(long index, double addend); - void add(long index, Number addend); + default void add(long index, float addend) { + this.add(index, (double) addend); + } + + void add(long index, Comparable addend); /** * Reset this mutable structure to some standard (all zeros) initial state. It must still be usuable after @@ -230,6 +235,10 @@ default void reset() { void set(long index, double value); - void set(long index, Number value); + default void set(long index, float value) { + this.set(index, (double) value); + } + + void set(long index, Comparable value); } diff --git a/src/org/ojalgo/structure/Mutate2D.java b/src/org/ojalgo/structure/Mutate2D.java index c75b18863..231b36458 100644 --- a/src/org/ojalgo/structure/Mutate2D.java +++ b/src/org/ojalgo/structure/Mutate2D.java @@ -48,7 +48,7 @@ interface Exchangeable extends Structure2D { } - interface Fillable extends Structure2D, Mutate1D.Fillable { + interface Fillable> extends Structure2D, Mutate1D.Fillable { default void fillColumn(final long col, final Access1D values) { this.fillColumn(0L, col, values); @@ -62,7 +62,7 @@ default void fillColumn(final long row, final long col, final N value) { this.loopColumn(row, col, (r, c) -> this.fillOne(r, c, value)); } - default void fillColumn(final long row, final long col, final NullaryFunction supplier) { + default void fillColumn(final long row, final long col, final NullaryFunction supplier) { this.loopColumn(row, col, (r, c) -> this.fillOne(r, c, supplier)); } @@ -70,7 +70,7 @@ default void fillColumn(final long col, final N value) { this.fillColumn(0L, col, value); } - default void fillColumn(final long col, final NullaryFunction supplier) { + default void fillColumn(final long col, final NullaryFunction supplier) { this.fillColumn(0L, col, supplier); } @@ -86,7 +86,7 @@ default void fillDiagonal(final long row, final long col, final N value) { this.loopDiagonal(row, col, (r, c) -> this.fillOne(r, c, value)); } - default void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + default void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { this.loopDiagonal(row, col, (r, c) -> this.fillOne(r, c, supplier)); } @@ -94,29 +94,32 @@ default void fillDiagonal(final N value) { this.fillDiagonal(0L, 0L, value); } - default void fillDiagonal(final NullaryFunction supplier) { + default void fillDiagonal(final NullaryFunction supplier) { this.fillDiagonal(0L, 0L, supplier); } + @Override default void fillOne(final long index, final Access1D values, final long valueIndex) { - long tmpStructure = this.countRows(); - this.fillOne(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), values, valueIndex); + long structure = this.countRows(); + this.fillOne(Structure2D.row(index, structure), Structure2D.column(index, structure), values, valueIndex); } void fillOne(long row, long col, Access1D values, long valueIndex); void fillOne(long row, long col, N value); - void fillOne(long row, long col, NullaryFunction supplier); + void fillOne(long row, long col, NullaryFunction supplier); + @Override default void fillOne(final long index, final N value) { - long tmpStructure = this.countRows(); - this.fillOne(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), value); + long structure = this.countRows(); + this.fillOne(Structure2D.row(index, structure), Structure2D.column(index, structure), value); } - default void fillOne(final long index, final NullaryFunction supplier) { - long tmpStructure = this.countRows(); - this.fillOne(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), supplier); + @Override + default void fillOne(final long index, final NullaryFunction supplier) { + long structure = this.countRows(); + this.fillOne(Structure2D.row(index, structure), Structure2D.column(index, structure), supplier); } default void fillRow(final long row, final Access1D values) { @@ -131,7 +134,7 @@ default void fillRow(final long row, final long col, final N value) { this.loopRow(row, col, (r, c) -> this.fillOne(r, c, value)); } - default void fillRow(final long row, final long col, final NullaryFunction supplier) { + default void fillRow(final long row, final long col, final NullaryFunction supplier) { this.loopRow(row, col, (r, c) -> this.fillOne(r, c, supplier)); } @@ -139,19 +142,21 @@ default void fillRow(final long row, final N value) { this.fillRow(row, 0L, value); } - default void fillRow(final long row, final NullaryFunction supplier) { + default void fillRow(final long row, final NullaryFunction supplier) { this.fillRow(row, 0L, supplier); } } - interface Mixable extends Structure2D, Mutate1D.Mixable { + interface Mixable> extends Structure2D, Mutate1D.Mixable { + @Override default double mix(final long index, final BinaryFunction mixer, final double addend) { long structure = this.countRows(); return this.mix(Structure2D.row(index, structure), Structure2D.column(index, structure), mixer, addend); } + @Override default N mix(final long index, final BinaryFunction mixer, final N addend) { long structure = this.countRows(); return this.mix(Structure2D.row(index, structure), Structure2D.column(index, structure), mixer, addend); @@ -162,7 +167,7 @@ default N mix(final long index, final BinaryFunction mixer, final N addend) { N mix(long row, long col, BinaryFunction mixer, N addend); } - interface Modifiable extends Structure2D, Mutate1D.Modifiable { + interface Modifiable> extends Structure2D, Mutate1D.Modifiable { default void modifyColumn(final long row, final long col, final UnaryFunction modifier) { this.loopColumn(row, col, (r, c) -> this.modifyOne(r, c, modifier)); @@ -198,9 +203,10 @@ default void modifyMatchingInRows(final BinaryFunction function, final Access void modifyOne(long row, long col, UnaryFunction modifier); + @Override default void modifyOne(final long index, final UnaryFunction modifier) { - long tmpStructure = this.countRows(); - this.modifyOne(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), modifier); + long structure = this.countRows(); + this.modifyOne(Structure2D.row(index, structure), Structure2D.column(index, structure), modifier); } default void modifyRow(final long row, final long col, final UnaryFunction modifier) { @@ -218,14 +224,15 @@ default void modifyRow(final long row, final UnaryFunction modifier) { * * @author apete */ - interface ModifiableReceiver extends Modifiable, Receiver, Exchangeable { + interface ModifiableReceiver> extends Modifiable, Receiver, Exchangeable { void modifyAny(Transformation2D modifier); } - interface Receiver extends Mutate2D, Fillable, Consumer> { + interface Receiver> extends Mutate2D, Fillable, Consumer> { + @Override default void accept(final Access2D supplied) { if (this.isAcceptable(supplied)) { supplied.loopAll((r, c) -> this.set(r, c, supplied.get(r, c))); @@ -240,32 +247,56 @@ default boolean isAcceptable(final Structure2D supplier) { } + @Override + default void add(final long index, final Comparable addend) { + long structure = this.countRows(); + this.add(Structure2D.row(index, structure), Structure2D.column(index, structure), addend); + } + + @Override default void add(final long index, final double addend) { long structure = this.countRows(); this.add(Structure2D.row(index, structure), Structure2D.column(index, structure), addend); } + @Override + default void add(final long index, final float addend) { + long structure = this.countRows(); + this.add(Structure2D.row(index, structure), Structure2D.column(index, structure), addend); + } + + void add(long row, long col, Comparable addend); + void add(long row, long col, double addend); - void add(long row, long col, Number addend); + default void add(long row, long col, float addend) { + this.add(row, col, (double) addend); + } - default void add(final long index, final Number addend) { - long tmpStructure = this.countRows(); - this.add(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), addend); + @Override + default void set(final long index, final Comparable addend) { + long structure = this.countRows(); + this.set(Structure2D.row(index, structure), Structure2D.column(index, structure), addend); } + @Override default void set(final long index, final double addend) { - long tmpStructure = this.countRows(); - this.set(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), addend); + long structure = this.countRows(); + this.set(Structure2D.row(index, structure), Structure2D.column(index, structure), addend); } - void set(long row, long col, double value); + @Override + default void set(final long index, final float addend) { + long structure = this.countRows(); + this.set(Structure2D.row(index, structure), Structure2D.column(index, structure), addend); + } - void set(long row, long col, Number value); + void set(long row, long col, Comparable value); + + void set(long row, long col, double value); - default void set(final long index, final Number addend) { - long tmpStructure = this.countRows(); - this.set(Structure2D.row(index, tmpStructure), Structure2D.column(index, tmpStructure), addend); + default void set(long row, long col, float value) { + this.set(row, col, (double) value); } } diff --git a/src/org/ojalgo/structure/MutateAnyD.java b/src/org/ojalgo/structure/MutateAnyD.java index 37b8f5a7b..c4098934d 100644 --- a/src/org/ojalgo/structure/MutateAnyD.java +++ b/src/org/ojalgo/structure/MutateAnyD.java @@ -36,28 +36,30 @@ */ public interface MutateAnyD extends StructureAnyD, Mutate1D { - interface Fillable extends StructureAnyD, Mutate1D.Fillable { + interface Fillable> extends StructureAnyD, Mutate1D.Fillable { void fillOne(long[] reference, N value); - void fillOne(long[] reference, NullaryFunction supplier); + void fillOne(long[] reference, NullaryFunction supplier); void fillSet(int dimension, long dimensionalIndex, N value); - void fillSet(int dimension, long dimensionalIndex, NullaryFunction supplier); + void fillSet(int dimension, long dimensionalIndex, NullaryFunction supplier); void fillSet(long[] initial, int dimension, N value); - void fillSet(long[] initial, int dimension, NullaryFunction supplier); + void fillSet(long[] initial, int dimension, NullaryFunction supplier); } - interface Mixable extends StructureAnyD, Mutate1D.Mixable { + interface Mixable> extends StructureAnyD, Mutate1D.Mixable { + @Override default double mix(final long index, final BinaryFunction mixer, final double addend) { return this.mix(StructureAnyD.reference(index, this.shape()), mixer, addend); } + @Override default N mix(final long index, final BinaryFunction mixer, final N addend) { return this.mix(StructureAnyD.reference(index, this.shape()), mixer, addend); } @@ -68,7 +70,7 @@ default N mix(final long index, final BinaryFunction mixer, final N addend) { } - interface Modifiable extends StructureAnyD, Mutate1D.Modifiable { + interface Modifiable> extends StructureAnyD, Mutate1D.Modifiable { void modifyOne(long[] reference, UnaryFunction modifier); @@ -83,14 +85,15 @@ interface Modifiable extends StructureAnyD, Mutate1D.Modifiabl * * @author apete */ - interface ModifiableReceiver extends Modifiable, Receiver { + interface ModifiableReceiver> extends Modifiable, Receiver { void modifyAny(TransformationAnyD modifier); } - interface Receiver extends MutateAnyD, Fillable, Consumer> { + interface Receiver> extends MutateAnyD, Fillable, Consumer> { + @Override default void accept(final AccessAnyD supplied) { if (this.isAcceptable(supplied)) { supplied.loopAll((final long[] ref) -> this.set(ref, supplied.get(ref))); @@ -114,28 +117,50 @@ default boolean isAcceptable(final StructureAnyD supplier) { } + @Override + default void add(final long index, final Comparable addend) { + this.add(StructureAnyD.reference(index, this.shape()), addend); + } + + @Override default void add(final long index, final double addend) { this.add(StructureAnyD.reference(index, this.shape()), addend); } - default void add(final long index, final Number addend) { + @Override + default void add(final long index, final float addend) { this.add(StructureAnyD.reference(index, this.shape()), addend); } + void add(long[] reference, Comparable addend); + void add(long[] reference, double addend); - void add(long[] reference, Number addend); + default void add(long[] reference, float addend) { + this.add(reference, (double) addend); + } + + @Override + default void set(final long index, final Comparable value) { + this.set(StructureAnyD.reference(index, this.shape()), value); + } + @Override default void set(final long index, final double value) { this.set(StructureAnyD.reference(index, this.shape()), value); } - default void set(final long index, final Number value) { + @Override + default void set(final long index, final float value) { this.set(StructureAnyD.reference(index, this.shape()), value); } + void set(long[] reference, Comparable value); + void set(long[] reference, double value); - void set(long[] reference, Number value); + default void set(long[] reference, float value) { + this.set(reference, (double) value); + } } diff --git a/src/org/ojalgo/structure/RowView.java b/src/org/ojalgo/structure/RowView.java index db537a653..29579137e 100644 --- a/src/org/ojalgo/structure/RowView.java +++ b/src/org/ojalgo/structure/RowView.java @@ -29,7 +29,8 @@ import org.ojalgo.ProgrammingError; -public class RowView implements Access1D, Iterable>, Iterator>, Spliterator>, Comparable> { +public class RowView> + implements Access1D, Iterable>, Iterator>, Spliterator>, Comparable> { static final int CHARACTERISTICS = Spliterator.CONCURRENT | Spliterator.DISTINCT | Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SORTED | Spliterator.SUBSIZED; diff --git a/src/org/ojalgo/structure/Stream1D.java b/src/org/ojalgo/structure/Stream1D.java index 8877eb5e7..a232f3daf 100644 --- a/src/org/ojalgo/structure/Stream1D.java +++ b/src/org/ojalgo/structure/Stream1D.java @@ -4,7 +4,7 @@ import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.UnaryFunction; -public interface Stream1D, R extends Mutate1D.Receiver, P extends Stream1D> +public interface Stream1D, A extends Access1D, R extends Mutate1D.Receiver, P extends Stream1D> extends Access1D.Collectable { default P operateOnAll(final BinaryFunction operator, final double right) { diff --git a/src/org/ojalgo/structure/Stream2D.java b/src/org/ojalgo/structure/Stream2D.java index 59f7e9d5a..aa2448d96 100644 --- a/src/org/ojalgo/structure/Stream2D.java +++ b/src/org/ojalgo/structure/Stream2D.java @@ -4,7 +4,7 @@ import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.UnaryFunction; -public interface Stream2D, R extends Mutate2D.Receiver, P extends Stream2D> +public interface Stream2D, A extends Access2D, R extends Mutate2D.Receiver, P extends Stream2D> extends Access2D.Collectable { default P operateOnAll(final BinaryFunction operator, final double right) { diff --git a/src/org/ojalgo/structure/StreamAnyD.java b/src/org/ojalgo/structure/StreamAnyD.java index d0fe2e932..30fcf4949 100644 --- a/src/org/ojalgo/structure/StreamAnyD.java +++ b/src/org/ojalgo/structure/StreamAnyD.java @@ -4,7 +4,7 @@ import org.ojalgo.function.ParameterFunction; import org.ojalgo.function.UnaryFunction; -public interface StreamAnyD, R extends MutateAnyD.Receiver, P extends StreamAnyD> +public interface StreamAnyD, A extends AccessAnyD, R extends MutateAnyD.Receiver, P extends StreamAnyD> extends AccessAnyD.Collectable { default P operateOnAll(final BinaryFunction operator, final double right) { diff --git a/src/org/ojalgo/structure/Transformation1D.java b/src/org/ojalgo/structure/Transformation1D.java index a8309bcd3..c6dddf2d1 100644 --- a/src/org/ojalgo/structure/Transformation1D.java +++ b/src/org/ojalgo/structure/Transformation1D.java @@ -27,7 +27,7 @@ * @author apete */ @FunctionalInterface -public interface Transformation1D { +public interface Transformation1D> { & Access1D> void transform(T transformable); diff --git a/src/org/ojalgo/structure/Transformation2D.java b/src/org/ojalgo/structure/Transformation2D.java index 6573c960b..27deab31f 100644 --- a/src/org/ojalgo/structure/Transformation2D.java +++ b/src/org/ojalgo/structure/Transformation2D.java @@ -27,7 +27,7 @@ * @author apete */ @FunctionalInterface -public interface Transformation2D { +public interface Transformation2D> { & Access2D> void transform(T transformable); diff --git a/src/org/ojalgo/structure/TransformationAnyD.java b/src/org/ojalgo/structure/TransformationAnyD.java index f44c30730..0a0da5b3b 100644 --- a/src/org/ojalgo/structure/TransformationAnyD.java +++ b/src/org/ojalgo/structure/TransformationAnyD.java @@ -27,7 +27,7 @@ * @author apete */ @FunctionalInterface -public interface TransformationAnyD { +public interface TransformationAnyD> { & AccessAnyD> void transform(T transformable); diff --git a/src/org/ojalgo/tensor/AnyTensor.java b/src/org/ojalgo/tensor/AnyTensor.java index 34d06bed7..120f2a175 100644 --- a/src/org/ojalgo/tensor/AnyTensor.java +++ b/src/org/ojalgo/tensor/AnyTensor.java @@ -28,7 +28,7 @@ import org.ojalgo.function.aggregator.AggregatorFunction; import org.ojalgo.function.constant.PrimitiveMath; -final class AnyTensor implements Tensor { +final class AnyTensor> implements Tensor { private final ArrayAnyD myArray; private final DenseArray.Factory myArrayFactory; diff --git a/src/org/ojalgo/tensor/Tensor.java b/src/org/ojalgo/tensor/Tensor.java index 0223fce11..36887a43f 100644 --- a/src/org/ojalgo/tensor/Tensor.java +++ b/src/org/ojalgo/tensor/Tensor.java @@ -27,9 +27,9 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.AccessAnyD; -public interface Tensor extends AccessAnyD, NormedVectorSpace, N> { +public interface Tensor> extends AccessAnyD, NormedVectorSpace, N> { - static > Tensor make(final DenseArray.Factory arrayFactory, final int rank, final int dimensions) { + static > Tensor make(final DenseArray.Factory arrayFactory, final int rank, final int dimensions) { return new AnyTensor<>(rank, dimensions, arrayFactory); } diff --git a/src/org/ojalgo/type/CalendarDateDuration.java b/src/org/ojalgo/type/CalendarDateDuration.java index c595cf98e..367929a09 100644 --- a/src/org/ojalgo/type/CalendarDateDuration.java +++ b/src/org/ojalgo/type/CalendarDateDuration.java @@ -42,7 +42,7 @@ * @see CalendarDateUnit * @author apete */ -public final class CalendarDateDuration extends Number implements TemporalAmount, CalendarDate.Resolution, Comparable { +public final class CalendarDateDuration implements TemporalAmount, CalendarDate.Resolution, ComparableNumber { static CalendarDateDuration of(final long nanos) { return new CalendarDateDuration(nanos, CalendarDateUnit.NANOS); diff --git a/src/org/ojalgo/type/ColourData.java b/src/org/ojalgo/type/ColourData.java index f6ab63bf2..92c32d1ce 100755 --- a/src/org/ojalgo/type/ColourData.java +++ b/src/org/ojalgo/type/ColourData.java @@ -26,7 +26,7 @@ /** * @author apete */ -public class ColourData extends Object { +public class ColourData { public static final ColourData BLACK = new ColourData(0, 0, 0); public static final ColourData WHITE = new ColourData(255, 255, 255); diff --git a/src/org/ojalgo/type/ComparableNumber.java b/src/org/ojalgo/type/ComparableNumber.java new file mode 100644 index 000000000..be6ee0e75 --- /dev/null +++ b/src/org/ojalgo/type/ComparableNumber.java @@ -0,0 +1,26 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.type; + +public interface ComparableNumber> extends NumberDefinition, Comparable { + +} diff --git a/src/org/ojalgo/type/NumberDefinition.java b/src/org/ojalgo/type/NumberDefinition.java new file mode 100644 index 000000000..1f8f7ff82 --- /dev/null +++ b/src/org/ojalgo/type/NumberDefinition.java @@ -0,0 +1,47 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.type; + +/** + * An interface that defines what is already in {@link java.lang.Number}. Hopefully Java itself will one day + * get an interface similar to this. When/if that happens this interface, and possibly some additional usage + * of extends java.lang.Number, will be replaced by that new interface. + */ +public interface NumberDefinition { + + default byte byteValue() { + return (byte) this.intValue(); + } + + double doubleValue(); + + float floatValue(); + + int intValue(); + + long longValue(); + + default short shortValue() { + return (short) this.intValue(); + } + +} diff --git a/src/org/ojalgo/type/PrimitiveNumber.java b/src/org/ojalgo/type/PrimitiveNumber.java index e5b086435..6c3d144e9 100644 --- a/src/org/ojalgo/type/PrimitiveNumber.java +++ b/src/org/ojalgo/type/PrimitiveNumber.java @@ -22,22 +22,8 @@ package org.ojalgo.type; /** - * An interface that defines what is in {@link java.lang.Number}. Hopefully Java itself will one day get an - * interface that does this. When/if that happens then this interface AND any/all usage of - * extends java.lang.Number will be replaced by that new interface. + * Intended as a "boxed" version of any/all primitive numeric types. */ -public interface PrimitiveNumber { - - byte byteValue(); - - double doubleValue(); - - float floatValue(); - - int intValue(); - - long longValue(); - - short shortValue(); +public interface PrimitiveNumber extends ComparableNumber { } diff --git a/src/org/ojalgo/type/StandardType.java b/src/org/ojalgo/type/StandardType.java index f67912fc8..0bb125ad7 100644 --- a/src/org/ojalgo/type/StandardType.java +++ b/src/org/ojalgo/type/StandardType.java @@ -204,7 +204,7 @@ protected StandardType() { /** * {@linkplain #getQuantity()} * {@linkplain #getPrice()} = {@linkplain #getAmount()} */ - public TypeContext getAmount() { + public TypeContext> getAmount() { return AMOUNT; } @@ -216,27 +216,27 @@ public TypeContext getDate() { return DATE; } - public TypeContext getDecimal032() { + public TypeContext> getDecimal032() { return DECIMAL_032; } - public TypeContext getDecimal064() { + public TypeContext> getDecimal064() { return DECIMAL_064; } - public TypeContext getDecimal128() { + public TypeContext> getDecimal128() { return DECIMAL_128; } - public TypeContext getMath032() { + public TypeContext> getMath032() { return MATH_032; } - public TypeContext getMath064() { + public TypeContext> getMath064() { return MATH_064; } - public TypeContext getMath128() { + public TypeContext> getMath128() { return MATH_128; } @@ -244,29 +244,29 @@ public TypeContext getMoment() { return DATETIME; } - public TypeContext getMoney() { + public TypeContext> getMoney() { return AMOUNT; } - public TypeContext getParameter() { + public TypeContext> getParameter() { return DECIMAL_064; } - public TypeContext getPercent() { + public TypeContext> getPercent() { return PERCENT; } /** * {@linkplain #getQuantity()} * {@linkplain #getPrice()} = {@linkplain #getAmount()} */ - public TypeContext getPrice() { + public TypeContext> getPrice() { return PRICE; } /** * {@linkplain #getQuantity()} * {@linkplain #getPrice()} = {@linkplain #getAmount()} */ - public TypeContext getQuantity() { + public TypeContext> getQuantity() { return QUANTITY; } diff --git a/src/org/ojalgo/type/TypeUtils.java b/src/org/ojalgo/type/TypeUtils.java index b1fbf430b..917399d9c 100644 --- a/src/org/ojalgo/type/TypeUtils.java +++ b/src/org/ojalgo/type/TypeUtils.java @@ -117,53 +117,55 @@ public static final GregorianCalendar getThousandYearsFromNow() { } /** - * If the input {@linkplain java.lang.Number} is a {@linkplain java.math.BigDecimal} it is passed through - * unaltered. Otherwise an equivalent BigDecimal is created. + * If the input {@linkplain java.lang.Comparale} is a {@linkplain java.math.BigDecimal} it is passed + * through unaltered. Otherwise an equivalent BigDecimal is created. * * @param number Any Number * @return A corresponding BigDecimal */ - public static BigDecimal toBigDecimal(final Number number) { + public static BigDecimal toBigDecimal(final Comparable number) { - BigDecimal retVal = BigMath.ZERO; - - if (number != null) { + if (number == null) { + return BigMath.ZERO; + } - if (number instanceof BigDecimal) { + if (number instanceof BigDecimal) { - retVal = (BigDecimal) number; + return (BigDecimal) number; - } else if (number instanceof Scalar) { + } else if (number instanceof Scalar) { - retVal = ((Scalar) number).toBigDecimal(); + return ((Scalar) number).toBigDecimal(); - } else { + } else { - try { + try { - retVal = new BigDecimal(number.toString()); + return new BigDecimal(number.toString()); - } catch (final NumberFormatException exception) { + } catch (final NumberFormatException exception) { - final double tmpVal = number.doubleValue(); + double tmpVal = PrimitiveMath.NaN; + if (number instanceof NumberDefinition) { + tmpVal = ((NumberDefinition) number).doubleValue(); + } else if (number instanceof Number) { + tmpVal = ((Number) number).doubleValue(); + } - if (Double.isNaN(tmpVal)) { - retVal = BigMath.ZERO; - } else if (Double.isInfinite(tmpVal) && (tmpVal > PrimitiveMath.ZERO)) { - retVal = BigMath.VERY_POSITIVE; - } else if (Double.isInfinite(tmpVal) && (tmpVal < PrimitiveMath.ZERO)) { - retVal = BigMath.VERY_NEGATIVE; - } else { - retVal = BigDecimal.valueOf(tmpVal); - } + if (Double.isNaN(tmpVal)) { + return BigMath.ZERO; + } else if (Double.isInfinite(tmpVal) && (tmpVal > PrimitiveMath.ZERO)) { + return BigMath.VERY_POSITIVE; + } else if (Double.isInfinite(tmpVal) && (tmpVal < PrimitiveMath.ZERO)) { + return BigMath.VERY_NEGATIVE; + } else { + return BigDecimal.valueOf(tmpVal); } } } - - return retVal; } - public static BigDecimal toBigDecimal(final Number number, final NumberContext context) { + public static BigDecimal toBigDecimal(final Comparable number, final NumberContext context) { return context.enforce(TypeUtils.toBigDecimal(number)); } diff --git a/src/org/ojalgo/type/context/NumberContext.java b/src/org/ojalgo/type/context/NumberContext.java index 8fc5d3a4c..72114926d 100644 --- a/src/org/ojalgo/type/context/NumberContext.java +++ b/src/org/ojalgo/type/context/NumberContext.java @@ -34,6 +34,7 @@ import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.constant.BigMath; import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.scalar.Scalar; import org.ojalgo.type.format.NumberStyle; /** @@ -52,7 +53,7 @@ * * @author apete */ -public final class NumberContext extends FormatContext { +public final class NumberContext extends FormatContext, NumberFormat> { public interface Enforceable { @@ -286,13 +287,13 @@ public double enforce(final double number) { } @Override - public Number enforce(final Number object) { + public Comparable enforce(final Comparable object) { if (object instanceof BigDecimal) { return this.enforce((BigDecimal) object); } else if (object instanceof Enforceable) { - return (Number) ((Enforceable) object).enforce(this); + return (Comparable) ((Enforceable) object).enforce(this); } else { - return this.enforce(object.doubleValue()); + return this.enforce(Scalar.doubleValue(object)); } } @@ -346,7 +347,7 @@ public String format(final long number) { return this.format().format(number); } - public UnaryFunction getFunction(final FunctionSet functions) { + public > UnaryFunction getFunction(final FunctionSet functions) { return functions.enforce(this); } @@ -562,7 +563,7 @@ protected String handleFormatException(final NumberFormat format, final Object o } @Override - protected Number handleParseException(final NumberFormat format, final String string) { + protected Comparable handleParseException(final NumberFormat format, final String string) { return BigMath.ZERO; } diff --git a/src/org/ojalgo/type/format/TransformationFormat.java b/src/org/ojalgo/type/format/TransformationFormat.java index 9c9711f90..d56950d8f 100644 --- a/src/org/ojalgo/type/format/TransformationFormat.java +++ b/src/org/ojalgo/type/format/TransformationFormat.java @@ -27,7 +27,7 @@ import org.ojalgo.function.UnaryFunction; -public class TransformationFormat extends NumberFormat { +public class TransformationFormat> extends NumberFormat { private final UnaryFunction myTransfoFunc; private final UnaryFunction myInverseFunc; diff --git a/src/org/ojalgo/type/keyvalue/ComparableToObject.java b/src/org/ojalgo/type/keyvalue/ComparableToObject.java index 74761e6ec..100e430d5 100644 --- a/src/org/ojalgo/type/keyvalue/ComparableToObject.java +++ b/src/org/ojalgo/type/keyvalue/ComparableToObject.java @@ -23,7 +23,7 @@ import org.ojalgo.netio.ASCII; -public final class ComparableToObject, V extends Object> implements KeyValue { +public final class ComparableToObject, V> implements KeyValue { public final K key; public final V value; diff --git a/src/org/ojalgo/type/keyvalue/IntToObject.java b/src/org/ojalgo/type/keyvalue/IntToObject.java index 1d05d173a..14a12b723 100755 --- a/src/org/ojalgo/type/keyvalue/IntToObject.java +++ b/src/org/ojalgo/type/keyvalue/IntToObject.java @@ -23,7 +23,7 @@ import org.ojalgo.netio.ASCII; -public final class IntToObject implements KeyValue { +public final class IntToObject implements KeyValue { public final int key; public final V value; diff --git a/src/org/ojalgo/type/keyvalue/KeyValue.java b/src/org/ojalgo/type/keyvalue/KeyValue.java index 4015b580c..abfc0dcc9 100644 --- a/src/org/ojalgo/type/keyvalue/KeyValue.java +++ b/src/org/ojalgo/type/keyvalue/KeyValue.java @@ -36,7 +36,7 @@ * * @author apete */ -public interface KeyValue extends Comparable> { +public interface KeyValue extends Comparable> { K getKey(); diff --git a/src/org/ojalgo/type/keyvalue/LongToObject.java b/src/org/ojalgo/type/keyvalue/LongToObject.java index cb6e524a4..e8c1095b1 100755 --- a/src/org/ojalgo/type/keyvalue/LongToObject.java +++ b/src/org/ojalgo/type/keyvalue/LongToObject.java @@ -23,7 +23,7 @@ import org.ojalgo.netio.ASCII; -public final class LongToObject implements KeyValue { +public final class LongToObject implements KeyValue { public final long key; public final V value; diff --git a/src/org/ojalgo/type/keyvalue/MapEntry.java b/src/org/ojalgo/type/keyvalue/MapEntry.java index 147b39237..9203bf1de 100644 --- a/src/org/ojalgo/type/keyvalue/MapEntry.java +++ b/src/org/ojalgo/type/keyvalue/MapEntry.java @@ -31,7 +31,7 @@ * * @author apete */ -public final class MapEntry, V extends Object> implements Map.Entry, KeyValue { +public final class MapEntry, V> implements Map.Entry, KeyValue { private final K myKey; private final Map myMap; diff --git a/src/org/ojalgo/type/keyvalue/StringToObject.java b/src/org/ojalgo/type/keyvalue/StringToObject.java index e95596bc1..75df87242 100755 --- a/src/org/ojalgo/type/keyvalue/StringToObject.java +++ b/src/org/ojalgo/type/keyvalue/StringToObject.java @@ -23,7 +23,7 @@ import org.ojalgo.netio.ASCII; -public final class StringToObject implements KeyValue { +public final class StringToObject implements KeyValue { public final String key; public final V value; diff --git a/test/org/ojalgo/SymmetricEigenvalueProfiling.java b/test/org/ojalgo/SymmetricEigenvalueProfiling.java index ec8f3edc1..1e890649a 100644 --- a/test/org/ojalgo/SymmetricEigenvalueProfiling.java +++ b/test/org/ojalgo/SymmetricEigenvalueProfiling.java @@ -23,13 +23,13 @@ import org.ojalgo.matrix.MatrixUtils; import org.ojalgo.matrix.decomposition.Eigenvalue; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; public class SymmetricEigenvalueProfiling { public static void main(final String[] args) { - final PrimitiveDenseStore tmpOrg = MatrixUtils.makeSPD(200); + final Primitive64Store tmpOrg = MatrixUtils.makeSPD(200); //final Eigenvalue tmpEvD = new RawEigenvalue.Symmetric(); final Eigenvalue tmpEvD = Eigenvalue.PRIMITIVE.make(tmpOrg, true); diff --git a/test/org/ojalgo/TestUtils.java b/test/org/ojalgo/TestUtils.java index 498a6ccfb..eecc54dab 100644 --- a/test/org/ojalgo/TestUtils.java +++ b/test/org/ojalgo/TestUtils.java @@ -37,7 +37,7 @@ import org.ojalgo.matrix.decomposition.QR; import org.ojalgo.matrix.decomposition.SingularValue; import org.ojalgo.matrix.decomposition.Tridiagonal; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.netio.BasicLogger; @@ -47,6 +47,7 @@ import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; +import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.ElementView1D; import org.ojalgo.structure.Structure2D; @@ -66,13 +67,13 @@ public abstract class TestUtils { private static NumberContext EQUALS = new NumberContext(12, 14, RoundingMode.HALF_EVEN); - public static void assertBounds(final Number lower, final Access1D values, final Number upper, final NumberContext precision) { + public static void assertBounds(final Comparable lower, final Access1D values, final Comparable upper, final NumberContext precision) { for (ElementView1D tmpValue : values.elements()) { TestUtils.assertBounds(lower, tmpValue.get(), upper, precision); } } - public static void assertBounds(final Number lower, final Number value, final Number upper, final NumberContext precision) { + public static void assertBounds(final Comparable lower, final Comparable value, final Comparable upper, final NumberContext precision) { BigDecimal tmpLower = TypeUtils.toBigDecimal(lower, precision); BigDecimal tmpValue = TypeUtils.toBigDecimal(value, precision); @@ -142,19 +143,19 @@ public static void assertEquals(final long[] expected, final long[] actual) { TestUtils.assertEquals(Arrays.toString(expected) + " != " + Arrays.toString(actual), expected, actual); } - public static void assertEquals(final MatrixStore expected, final Bidiagonal actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final Bidiagonal actual, final NumberContext context) { if (!Bidiagonal.equals(expected, actual, context)) { Assertions.fail(() -> "Bidiagonal failed for " + expected); } } - public static void assertEquals(final MatrixStore expected, final Cholesky actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final Cholesky actual, final NumberContext context) { if (!Cholesky.equals(expected, actual, context)) { Assertions.fail(() -> "Cholesky failed for " + expected); } } - public static void assertEquals(final MatrixStore expected, final Eigenvalue actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final Eigenvalue actual, final NumberContext context) { if (!Eigenvalue.equals(expected, actual, context)) { Assertions.fail(() -> "Eigenvalue failed for " + expected); } @@ -171,41 +172,41 @@ public static void assertEquals(final MatrixStore expected } } - public static void assertEquals(final MatrixStore expected, final Hessenberg actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final Hessenberg actual, final NumberContext context) { if (!Hessenberg.equals(expected, actual, context)) { Assertions.fail(() -> "Hessenberg failed for " + expected); } } - public static void assertEquals(final MatrixStore expected, final LU actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final LU actual, final NumberContext context) { if (!LU.equals(expected, actual, context)) { Assertions.fail(() -> "LU failed for " + expected); } } - public static void assertEquals(final MatrixStore expected, final QR actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final QR actual, final NumberContext context) { if (!QR.equals(expected, actual, context)) { Assertions.fail(() -> "QR failed for " + expected); } } - public static void assertEquals(final MatrixStore expected, final SingularValue actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final SingularValue actual, final NumberContext context) { if (!SingularValue.equals(expected, actual, context)) { Assertions.fail(() -> "SingularValue failed for " + expected); } } - public static void assertEquals(final MatrixStore expected, final Tridiagonal actual, final NumberContext context) { + public static > void assertEquals(final MatrixStore expected, final Tridiagonal actual, final NumberContext context) { if (!Tridiagonal.equals(expected, actual, context)) { Assertions.fail(() -> "Tridiagonal failed for " + expected); } } - public static void assertEquals(final Number expected, final Number actual) { + public static void assertEquals(final Comparable expected, final Comparable actual) { TestUtils.assertEquals(expected, actual, EQUALS); } - public static void assertEquals(final Number expected, final Number actual, final NumberContext context) { + public static void assertEquals(final Comparable expected, final Comparable actual, final NumberContext context) { TestUtils.assertEquals("Number != Number", expected, actual, context); } @@ -250,7 +251,7 @@ public static void assertEquals(final String message, final ComplexNumber expect } public static void assertEquals(final String message, final ComplexNumber expected, final ComplexNumber actual, final NumberContext context) { - TestUtils.assertEquals(message, (Number) expected, (Number) actual, context); + TestUtils.assertEquals(message, (Comparable) expected, (Comparable) actual, context); TestUtils.assertEquals(message, (Access1D) expected, (Access1D) actual, context); } @@ -287,11 +288,11 @@ public static void assertEquals(final String message, final long[] expected, fin TestUtils.assertTrue(message, Arrays.equals(expected, actual)); } - public static void assertEquals(final String message, final Number expected, final Number actual) { + public static void assertEquals(final String message, final Comparable expected, final Comparable actual) { TestUtils.assertEquals(message, expected, actual, EQUALS); } - public static void assertEquals(final String message, final Number expected, final Number actual, final NumberContext precision) { + public static void assertEquals(final String message, final Comparable expected, final Comparable actual, final NumberContext precision) { if ((expected instanceof Quaternion) || (actual instanceof Quaternion)) { @@ -320,18 +321,18 @@ public static void assertEquals(final String message, final Number expected, fin ComplexNumber tmpExpected = ComplexNumber.valueOf(expected); ComplexNumber tmpActual = ComplexNumber.valueOf(actual); - if (!!precision.isDifferent(tmpExpected.getReal(), tmpActual.getReal())) { + if (precision.isDifferent(tmpExpected.getReal(), tmpActual.getReal())) { // Assertions.fail(() -> message + " (real)" + ": " + expected + " != " + actual); Assertions.assertEquals(expected, actual, () -> message + " (real)" + ": " + expected + " != " + actual); } - if (!!precision.isDifferent(tmpExpected.getImaginary(), tmpActual.getImaginary())) { + if (precision.isDifferent(tmpExpected.getImaginary(), tmpActual.getImaginary())) { // Assertions.fail(() -> message + " (imaginary)" + ": " + expected + " != " + actual); Assertions.assertEquals(expected, actual, () -> message + " (imaginary)" + ": " + expected + " != " + actual); } } else { - if (precision.isDifferent(expected.doubleValue(), actual.doubleValue())) { + if (precision.isDifferent(Scalar.doubleValue(expected), Scalar.doubleValue(actual))) { // Assertions.fail(() -> message + ": " + expected + " != " + actual); Assertions.assertEquals(expected, actual, () -> message + ": " + expected + " != " + actual); } @@ -348,7 +349,7 @@ public static void assertEquals(final String message, final Quaternion expected, } public static void assertEquals(final String message, final Quaternion expected, final Quaternion actual, final NumberContext context) { - TestUtils.assertEquals(message, (Number) expected, (Number) actual, context); + TestUtils.assertEquals(message, (Comparable) expected, (Comparable) actual, context); TestUtils.assertEquals(message, (Access1D) expected, (Access1D) actual, context); } @@ -462,7 +463,7 @@ public static void fail(final Throwable problem) { public static PhysicalStore makeRandomComplexStore(final int numberOfRows, final int numberOfColumns) { - PhysicalStore retVal = GenericDenseStore.COMPLEX.makeZero(numberOfRows, numberOfColumns); + PhysicalStore retVal = GenericStore.COMPLEX.makeZero(numberOfRows, numberOfColumns); Uniform tmpArgGen = new Uniform(PrimitiveMath.ZERO, PrimitiveMath.TWO_PI); @@ -514,7 +515,7 @@ static void assertOptimisationResult(final String message, final Optimisation.Re } if (solution && expectedState.isFeasible()) { - TestUtils.assertEquals(message + " – Solution", expected, actual, context); + TestUtils.assertEquals(message + " – Solution", (Access1D) expected, (Access1D) actual, context); } if (multipliers && expected.getMultipliers().isPresent()) { diff --git a/test/org/ojalgo/ann/BackPropagationExample.java b/test/org/ojalgo/ann/BackPropagationExample.java index 0601ff33e..937a88fea 100644 --- a/test/org/ojalgo/ann/BackPropagationExample.java +++ b/test/org/ojalgo/ann/BackPropagationExample.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.structure.Structure2D; import org.ojalgo.type.context.NumberContext; @@ -35,10 +35,10 @@ abstract class BackPropagationExample extends ANNTest { static final class Data { - PrimitiveDenseStore expected = null; - PrimitiveDenseStore input = null; + Primitive64Store expected = null; + Primitive64Store input = null; final double rate; - PrimitiveDenseStore target = null; + Primitive64Store target = null; Data() { this(1.0); @@ -50,17 +50,17 @@ static final class Data { } Data expected(final double... row) { - expected = PrimitiveDenseStore.FACTORY.rows(row); + expected = Primitive64Store.FACTORY.rows(row); return this; } Data input(final double... row) { - input = PrimitiveDenseStore.FACTORY.rows(row); + input = Primitive64Store.FACTORY.rows(row); return this; } Data target(final double... row) { - target = PrimitiveDenseStore.FACTORY.rows(row); + target = Primitive64Store.FACTORY.rows(row); return this; } @@ -123,13 +123,13 @@ protected void deriveTheHardWay(final NetworkBuilder builder, final Data triplet Structure2D[] structure = builder.structure(); - PrimitiveDenseStore[] weights = new PrimitiveDenseStore[structure.length]; - PrimitiveDenseStore[] bias = new PrimitiveDenseStore[structure.length]; + Primitive64Store[] weights = new Primitive64Store[structure.length]; + Primitive64Store[] bias = new Primitive64Store[structure.length]; for (int layer = 0, limit = structure.length; layer < limit; layer++) { - PrimitiveDenseStore newWeights = weights[layer] = PrimitiveDenseStore.FACTORY.make(structure[layer]); - PrimitiveDenseStore newBias = bias[layer] = PrimitiveDenseStore.FACTORY.make(1, structure[layer].countColumns()); + Primitive64Store newWeights = weights[layer] = Primitive64Store.FACTORY.make(structure[layer]); + Primitive64Store newBias = bias[layer] = Primitive64Store.FACTORY.make(1, structure[layer].countColumns()); for (int output = 0; output < structure[layer].countColumns(); output++) { for (int input = 0; input < structure[layer].countRows(); input++) { @@ -192,7 +192,7 @@ protected void deriveTheHardWay(final NetworkBuilder builder, final Data triplet for (int layer = 0, limit = structure.length; layer < limit; layer++) { for (int output = 0; output < structure[layer].countColumns(); output++) { for (int input = 0; input < structure[layer].countRows(); input++) { - final PrimitiveDenseStore expectedWeights = weights[layer]; + final Primitive64Store expectedWeights = weights[layer]; TestUtils.assertEquals(builder.toString(), expectedWeights.doubleValue(input, output), builder.getWeight(layer, input, output), precision); } TestUtils.assertEquals(builder.toString(), bias[layer].doubleValue(output), builder.getBias(layer, output), precision); diff --git a/test/org/ojalgo/ann/DesignTestANN.java b/test/org/ojalgo/ann/DesignTestANN.java index e6627618b..8b44122a7 100644 --- a/test/org/ojalgo/ann/DesignTestANN.java +++ b/test/org/ojalgo/ann/DesignTestANN.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.function.PrimitiveFunction.Unary; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; public class DesignTestANN extends ANNTest { @@ -38,8 +38,8 @@ public void testSoftmaxWikipediaCase() { NumberContext precision = new NumberContext(7, 8); - PrimitiveDenseStore arguments = PrimitiveDenseStore.FACTORY.row(1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0); - PrimitiveDenseStore results = PrimitiveDenseStore.FACTORY.row(0.02364054, 0.06426166, 0.1746813, 0.474833, 0.02364054, 0.06426166, 0.1746813); + Primitive64Store arguments = Primitive64Store.FACTORY.row(1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0); + Primitive64Store results = Primitive64Store.FACTORY.row(0.02364054, 0.06426166, 0.1746813, 0.474833, 0.02364054, 0.06426166, 0.1746813); Unary function = ArtificialNeuralNetwork.Activator.SOFTMAX.getFunction(arguments); diff --git a/test/org/ojalgo/ann/NeuralNetworkWorkedExample.java b/test/org/ojalgo/ann/NeuralNetworkWorkedExample.java index 5bb7e91ce..9beb38722 100644 --- a/test/org/ojalgo/ann/NeuralNetworkWorkedExample.java +++ b/test/org/ojalgo/ann/NeuralNetworkWorkedExample.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.LineSplittingParser; import org.ojalgo.structure.Access1D; import org.ojalgo.type.context.NumberContext; @@ -73,8 +73,8 @@ public void testTraining() { double R2C2 = Double.parseDouble(columns[4]); int IsStairs = Integer.parseInt(columns[5]); - PrimitiveDenseStore input_csv = PrimitiveDenseStore.FACTORY.row(R1C1 / _255_0, R1C2 / _255_0, R2C1 / _255_0, R2C2 / _255_0); - PrimitiveDenseStore output_csv = PrimitiveDenseStore.FACTORY.row(IsStairs, ONE - IsStairs); + Primitive64Store input_csv = Primitive64Store.FACTORY.row(R1C1 / _255_0, R1C2 / _255_0, R2C1 / _255_0, R2C2 / _255_0); + Primitive64Store output_csv = Primitive64Store.FACTORY.row(IsStairs, ONE - IsStairs); builder.rate(0.01).train(input_csv, output_csv); }); @@ -94,7 +94,7 @@ public void testTraining() { double R2C2 = Double.parseDouble(columns[4]); int IsStairs = Integer.parseInt(columns[5]); - PrimitiveDenseStore input_csv = PrimitiveDenseStore.FACTORY.row(R1C1 / _255_0, R1C2 / _255_0, R2C1 / _255_0, R2C2 / _255_0); + Primitive64Store input_csv = Primitive64Store.FACTORY.row(R1C1 / _255_0, R1C2 / _255_0, R2C1 / _255_0, R2C2 / _255_0); Access1D output_net = network.invoke(input_csv); diff --git a/test/org/ojalgo/ann/NeuralNetworksDemystified.java b/test/org/ojalgo/ann/NeuralNetworksDemystified.java index 976df7d01..abb178efe 100644 --- a/test/org/ojalgo/ann/NeuralNetworksDemystified.java +++ b/test/org/ojalgo/ann/NeuralNetworksDemystified.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; import org.ojalgo.type.context.NumberContext; @@ -94,9 +94,9 @@ private double[] getErrors(final NetworkBuilder builder) { for (int i = 0; i < errors.length; i++) { final Data data = examples.get(i); - final PrimitiveDenseStore input = data.input; + final Primitive64Store input = data.input; final Access1D actual = network.invoke(input); - final PrimitiveDenseStore expected = data.target; + final Primitive64Store expected = data.target; double error = builder.error(expected, actual); errors[i] = error; } diff --git a/test/org/ojalgo/ann/StepByStepBackpropagationExample.java b/test/org/ojalgo/ann/StepByStepBackpropagationExample.java index 8a802c825..e881a5b8e 100644 --- a/test/org/ojalgo/ann/StepByStepBackpropagationExample.java +++ b/test/org/ojalgo/ann/StepByStepBackpropagationExample.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access1D; import org.ojalgo.type.context.NumberContext; @@ -53,7 +53,7 @@ public StepByStepBackpropagationExample() { public void testStepByStepBackpropagationExample() { NumberContext precision = this.precision(); - Factory factory = PrimitiveDenseStore.FACTORY; + Factory factory = Primitive64Store.FACTORY; ArtificialNeuralNetwork.Error errorMeassure = HALF_SQUARED_DIFFERENCE; @@ -63,8 +63,8 @@ public void testStepByStepBackpropagationExample() { Data testCase = this.getTestCases().get(0); - PrimitiveDenseStore givenInput = testCase.input; - PrimitiveDenseStore targetOutput = testCase.target; + Primitive64Store givenInput = testCase.input; + Primitive64Store targetOutput = testCase.target; Access1D expectedOutput = testCase.expected; Access1D actualOutput = network.invoke(givenInput); diff --git a/test/org/ojalgo/array/operation/SubstitutionTest.java b/test/org/ojalgo/array/operation/SubstitutionTest.java index 4f17f9bcf..870066ecb 100644 --- a/test/org/ojalgo/array/operation/SubstitutionTest.java +++ b/test/org/ojalgo/array/operation/SubstitutionTest.java @@ -24,9 +24,9 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.Cholesky; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.random.Uniform; import org.ojalgo.scalar.RationalNumber; @@ -39,14 +39,14 @@ public void testSubstituteBackwards() { int numbEquations = 4; int numbSolutions = 3; - MatrixStore primitiveBody = MatrixStore.PRIMITIVE.makeIdentity(numbEquations).get(); + MatrixStore primitiveBody = MatrixStore.PRIMITIVE64.makeIdentity(numbEquations).get(); MatrixStore rationalBody = MatrixStore.RATIONAL.makeIdentity(numbEquations).get(); - PrimitiveDenseStore denseRHS = PrimitiveDenseStore.FACTORY.makeFilled(numbEquations, numbSolutions, new Uniform()); + Primitive64Store denseRHS = Primitive64Store.FACTORY.makeFilled(numbEquations, numbSolutions, new Uniform()); RawStore rawRHS = RawStore.FACTORY.copy(denseRHS); - GenericDenseStore rationalRHS = GenericDenseStore.RATIONAL.copy(denseRHS); + GenericStore rationalRHS = GenericStore.RATIONAL.copy(denseRHS); - PrimitiveDenseStore expected = PrimitiveDenseStore.FACTORY.copy(denseRHS); + Primitive64Store expected = Primitive64Store.FACTORY.copy(denseRHS); SubstituteBackwards.invoke(denseRHS.data, numbEquations, 0, numbSolutions, primitiveBody, false, false, false); SubstituteBackwards.invoke(rawRHS.data, primitiveBody, false, false, false); @@ -57,10 +57,10 @@ public void testSubstituteBackwards() { TestUtils.assertEquals(expected, rationalRHS); Cholesky cholesky = Cholesky.PRIMITIVE.make(numbEquations, numbEquations); - cholesky.decompose(PrimitiveDenseStore.FACTORY.makeSPD(numbEquations)); + cholesky.decompose(Primitive64Store.FACTORY.makeSPD(numbEquations)); primitiveBody = cholesky.getR(); - rationalBody = GenericDenseStore.RATIONAL.copy(primitiveBody); + rationalBody = GenericStore.RATIONAL.copy(primitiveBody); SubstituteBackwards.invoke(denseRHS.data, numbEquations, 0, numbSolutions, primitiveBody, true, true, false); SubstituteBackwards.invoke(rawRHS.data, primitiveBody, true, true, false); @@ -84,14 +84,14 @@ public void testSubstituteForwards() { int numbEquations = 4; int numbSolutions = 3; - MatrixStore primitiveBody = MatrixStore.PRIMITIVE.makeIdentity(numbEquations).get(); + MatrixStore primitiveBody = MatrixStore.PRIMITIVE64.makeIdentity(numbEquations).get(); MatrixStore rationalBody = MatrixStore.RATIONAL.makeIdentity(numbEquations).get(); - PrimitiveDenseStore denseRHS = PrimitiveDenseStore.FACTORY.makeFilled(numbEquations, numbSolutions, new Uniform()); + Primitive64Store denseRHS = Primitive64Store.FACTORY.makeFilled(numbEquations, numbSolutions, new Uniform()); RawStore rawRHS = RawStore.FACTORY.copy(denseRHS); - GenericDenseStore rationalRHS = GenericDenseStore.RATIONAL.copy(denseRHS); + GenericStore rationalRHS = GenericStore.RATIONAL.copy(denseRHS); - PrimitiveDenseStore expected = PrimitiveDenseStore.FACTORY.copy(denseRHS); + Primitive64Store expected = Primitive64Store.FACTORY.copy(denseRHS); SubstituteForwards.invoke(denseRHS.data, numbEquations, 0, numbSolutions, primitiveBody, false, false, false); SubstituteForwards.invoke(rawRHS.data, primitiveBody, false, false, false); @@ -102,10 +102,10 @@ public void testSubstituteForwards() { TestUtils.assertEquals(expected, rationalRHS); Cholesky cholesky = Cholesky.PRIMITIVE.make(numbEquations, numbEquations); - cholesky.decompose(PrimitiveDenseStore.FACTORY.makeSPD(numbEquations)); + cholesky.decompose(Primitive64Store.FACTORY.makeSPD(numbEquations)); primitiveBody = cholesky.getL(); - rationalBody = GenericDenseStore.RATIONAL.copy(primitiveBody); + rationalBody = GenericStore.RATIONAL.copy(primitiveBody); SubstituteForwards.invoke(denseRHS.data, numbEquations, 0, numbSolutions, primitiveBody, true, true, false); SubstituteForwards.invoke(rawRHS.data, primitiveBody, true, true, false); diff --git a/test/org/ojalgo/function/multiary/ApproximationCase.java b/test/org/ojalgo/function/multiary/ApproximationCase.java index 39c5bede4..99f2d07d0 100644 --- a/test/org/ojalgo/function/multiary/ApproximationCase.java +++ b/test/org/ojalgo/function/multiary/ApproximationCase.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Uniform; import org.ojalgo.type.context.NumberContext; @@ -37,14 +37,14 @@ public void testFirstOrderApproximation() { for (int arity = 1; arity < 10; arity++) { - PhysicalStore linear = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); + PhysicalStore linear = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); - PhysicalStore zero = PrimitiveDenseStore.FACTORY.make(arity, 1); - PhysicalStore point = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); + PhysicalStore zero = Primitive64Store.FACTORY.make(arity, 1); + PhysicalStore point = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); AffineFunction orgFunc = AffineFunction.makePrimitive(linear); - PhysicalStore arg = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); + PhysicalStore arg = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); Double expected = orgFunc.invoke(arg); @@ -66,15 +66,15 @@ public void testSecondOrderApproximation() { for (int arity = 1; arity < 10; arity++) { - PhysicalStore quadratic = PrimitiveDenseStore.FACTORY.makeFilled(arity, arity, new Uniform()); - PhysicalStore linear = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); + PhysicalStore quadratic = Primitive64Store.FACTORY.makeFilled(arity, arity, new Uniform()); + PhysicalStore linear = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); - PhysicalStore zero = PrimitiveDenseStore.FACTORY.make(arity, 1); - PhysicalStore point = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); + PhysicalStore zero = Primitive64Store.FACTORY.make(arity, 1); + PhysicalStore point = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); QuadraticFunction orgFunc = QuadraticFunction.makePrimitive(quadratic, linear); - PhysicalStore arg = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); + PhysicalStore arg = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-10, 20)); Double expected = orgFunc.invoke(arg); diff --git a/test/org/ojalgo/function/multiary/LinearCase.java b/test/org/ojalgo/function/multiary/LinearCase.java index 8829f672e..0ed4a314d 100644 --- a/test/org/ojalgo/function/multiary/LinearCase.java +++ b/test/org/ojalgo/function/multiary/LinearCase.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Uniform; public class LinearCase extends MultiaryFunctionTests { @@ -46,8 +46,8 @@ public void setup() { int arity = 9; - PhysicalStore quadratic = PrimitiveDenseStore.FACTORY.make(arity, arity); - PhysicalStore linear = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); + PhysicalStore quadratic = Primitive64Store.FACTORY.make(arity, arity); + PhysicalStore linear = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); myLinearFunction1 = LinearFunction.makePrimitive(linear); myAffineFunction1 = AffineFunction.makePrimitive(linear); @@ -57,7 +57,7 @@ public void setup() { myAffineFunction2 = AffineFunction.makePrimitive(linear.transpose()); myQuadraticFunction2 = QuadraticFunction.makePrimitive(quadratic, linear.transpose()); - myArg = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); + myArg = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); } @Test diff --git a/test/org/ojalgo/function/multiary/QuadraticCase.java b/test/org/ojalgo/function/multiary/QuadraticCase.java index 0db913dde..b4c5e982e 100644 --- a/test/org/ojalgo/function/multiary/QuadraticCase.java +++ b/test/org/ojalgo/function/multiary/QuadraticCase.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Uniform; public class QuadraticCase extends MultiaryFunctionTests { @@ -42,13 +42,13 @@ public void setupL() { int arity = 9; - PhysicalStore quadratic = PrimitiveDenseStore.FACTORY.makeFilled(arity, arity, new Uniform()); - PhysicalStore linear = PrimitiveDenseStore.FACTORY.make(arity, 1); + PhysicalStore quadratic = Primitive64Store.FACTORY.makeFilled(arity, arity, new Uniform()); + PhysicalStore linear = Primitive64Store.FACTORY.make(arity, 1); myPureQuadraticFunction = PureQuadraticFunction.makePrimitive(quadratic); myQuadraticFunction = QuadraticFunction.makePrimitive(quadratic, linear); - myArg1 = PrimitiveDenseStore.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); + myArg1 = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); myArg2 = myArg1.transpose(); } diff --git a/test/org/ojalgo/matrix/BasicMatrixTest.java b/test/org/ojalgo/matrix/BasicMatrixTest.java index bc69647b0..77ba17cea 100644 --- a/test/org/ojalgo/matrix/BasicMatrixTest.java +++ b/test/org/ojalgo/matrix/BasicMatrixTest.java @@ -37,9 +37,9 @@ import org.ojalgo.matrix.decomposition.Eigenvalue.Eigenpair; import org.ojalgo.matrix.decomposition.MatrixDecompositionTests; import org.ojalgo.matrix.decomposition.SingularValue; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Uniform; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.Quaternion; @@ -47,7 +47,6 @@ import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.ColumnView; import org.ojalgo.structure.RowView; -import org.ojalgo.type.TypeUtils; import org.ojalgo.type.context.NumberContext; /** @@ -55,6 +54,8 @@ */ public abstract class BasicMatrixTest extends MatrixTests { + protected static final NumberContext ACCURACY = new NumberContext(7, 7); + public static RationalMatrix getIdentity(final long rows, final long columns, final NumberContext context) { final RationalMatrix tmpMtrx = RationalMatrix.FACTORY.makeEye(Math.toIntExact(rows), Math.toIntExact(columns)); return tmpMtrx.enforce(context); @@ -65,129 +66,147 @@ public static RationalMatrix getSafe(final long rows, final long columns, final return tmpMtrx.enforce(context); } - protected NumberContext evaluation = NumberContext.getGeneral(9); - - boolean actBoolean; - int actInt; - BasicMatrix actMtrx; - Number actNumber; - Scalar actScalar; - double actValue; - BigDecimal bigNumber; - ComplexMatrix complexAA; - ComplexMatrix complexAB; - ComplexMatrix complexAX; - ComplexMatrix complexI; - ComplexMatrix complexSafe; - boolean expBoolean; - int expInt; - BasicMatrix expMtrx; - Number expNumber; - Scalar expScalar; - double expValue; - PrimitiveMatrix primitiveAA; - PrimitiveMatrix primitiveAB; - PrimitiveMatrix primitiveAX; - PrimitiveMatrix primitiveI; - PrimitiveMatrix primitiveSafe; - QuaternionMatrix quaternionAA; - QuaternionMatrix quaternionAB; - QuaternionMatrix quaternionAX; - QuaternionMatrix quaternionI; - QuaternionMatrix quaternionSafe; - RationalMatrix rationalAA; - RationalMatrix rationalAB; - RationalMatrix rationalAX; - RationalMatrix rationalSafe; - RationalMatrix rationlI; + ComplexMatrix cAA; + ComplexMatrix cAB; + ComplexMatrix cAX; + ComplexMatrix cI; + ComplexMatrix cSafe; + + Primitive32Matrix p32AA; + Primitive32Matrix p32AB; + Primitive32Matrix p32AX; + Primitive32Matrix p32I; + Primitive32Matrix p32Safe; + + Primitive64Matrix p64AA; + Primitive64Matrix p64AB; + Primitive64Matrix p64AX; + Primitive64Matrix p64I; + Primitive64Matrix p64Safe; + + QuaternionMatrix qAA; + QuaternionMatrix qAB; + QuaternionMatrix qAX; + QuaternionMatrix qI; + QuaternionMatrix qSafe; + + RationalMatrix rAA; + RationalMatrix rAB; + RationalMatrix rAX; + RationalMatrix rI; + RationalMatrix rSafe; + + BigDecimal scalar; @BeforeEach - public void setUp() { + public void doBeforeEach() { TestUtils.minimiseAllBranchLimits(); - primitiveAA = PrimitiveMatrix.FACTORY.copy(rationalAA); - primitiveAX = PrimitiveMatrix.FACTORY.copy(rationalAX); - primitiveAB = PrimitiveMatrix.FACTORY.copy(rationalAB); - primitiveI = PrimitiveMatrix.FACTORY.copy(rationlI); - primitiveSafe = PrimitiveMatrix.FACTORY.copy(rationalSafe); - - complexAA = ComplexMatrix.FACTORY.copy(rationalAA); - complexAX = ComplexMatrix.FACTORY.copy(rationalAX); - complexAB = ComplexMatrix.FACTORY.copy(rationalAB); - complexI = ComplexMatrix.FACTORY.copy(rationlI); - complexSafe = ComplexMatrix.FACTORY.copy(rationalSafe); - - quaternionAA = QuaternionMatrix.FACTORY.copy(rationalAA); - quaternionAX = QuaternionMatrix.FACTORY.copy(rationalAX); - quaternionAB = QuaternionMatrix.FACTORY.copy(rationalAB); - quaternionI = QuaternionMatrix.FACTORY.copy(rationlI); - quaternionSafe = QuaternionMatrix.FACTORY.copy(rationalSafe); - - bigNumber = new BigDecimal(Math.random()); + p32AA = Primitive32Matrix.FACTORY.copy(rAA); + p32AX = Primitive32Matrix.FACTORY.copy(rAX); + p32AB = Primitive32Matrix.FACTORY.copy(rAB); + p32I = Primitive32Matrix.FACTORY.copy(rI); + p32Safe = Primitive32Matrix.FACTORY.copy(rSafe); + + p64AA = Primitive64Matrix.FACTORY.copy(rAA); + p64AX = Primitive64Matrix.FACTORY.copy(rAX); + p64AB = Primitive64Matrix.FACTORY.copy(rAB); + p64I = Primitive64Matrix.FACTORY.copy(rI); + p64Safe = Primitive64Matrix.FACTORY.copy(rSafe); + + cAA = ComplexMatrix.FACTORY.copy(rAA); + cAX = ComplexMatrix.FACTORY.copy(rAX); + cAB = ComplexMatrix.FACTORY.copy(rAB); + cI = ComplexMatrix.FACTORY.copy(rI); + cSafe = ComplexMatrix.FACTORY.copy(rSafe); + + qAA = QuaternionMatrix.FACTORY.copy(rAA); + qAX = QuaternionMatrix.FACTORY.copy(rAX); + qAB = QuaternionMatrix.FACTORY.copy(rAB); + qI = QuaternionMatrix.FACTORY.copy(rI); + qSafe = QuaternionMatrix.FACTORY.copy(rSafe); + + scalar = new BigDecimal(Math.random()); } @AfterEach - public void tearDown() { - evaluation = NumberContext.getGeneral(9); + public void doAfterEach() { + // ACCURACY = NumberContext.getGeneral(9); } /** - * @see org.ojalgo.matrix.BasicMatrix#add(org.ojalgo.matrix.BasicMatrix) + * @see BasicMatrix.PhysicalReceiver#add(long, long, Comparable) */ @Test - public void testAddBasicMatrix() { + public void testAddElement() { + + BasicMatrix actual; + BasicMatrix expected; - expMtrx = rationalAA.add(rationalSafe); + long row = Uniform.randomInteger(rAA.countRows()); + long col = Uniform.randomInteger(rAA.countColumns()); - actMtrx = complexAA.add(complexSafe); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + BasicMatrix.PhysicalReceiver rBuilder = rAA.copy(); + rBuilder.add(row, col, scalar); + expected = rBuilder.build(); - actMtrx = primitiveAA.add(primitiveSafe); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + BasicMatrix.PhysicalReceiver cBuilder = cAA.copy(); + cBuilder.add(row, col, scalar); + actual = cBuilder.build(); + TestUtils.assertEquals(expected, actual, ACCURACY); + BasicMatrix.PhysicalReceiver p64Builder = p64AA.copy(); + p64Builder.add(row, col, scalar); + actual = p64Builder.build(); + TestUtils.assertEquals(expected, actual, ACCURACY); + + BasicMatrix.PhysicalReceiver p32Builder = p32AA.copy(); + p32Builder.add(row, col, scalar); + actual = p32Builder.build(); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** - * @see BasicMatrix.PhysicalReceiver#add(long, long, Number) + * @see org.ojalgo.matrix.BasicMatrix#add(org.ojalgo.matrix.BasicMatrix) */ @Test - public void testAddIntIntNumber() { - - final int tmpRow = Uniform.randomInteger((int) rationalAA.countRows()); - final int tmpCol = Uniform.randomInteger((int) rationalAA.countColumns()); + public void testAddMatrix() { - final BasicMatrix.PhysicalReceiver tmpBigBuilder = rationalAA.copy(); - tmpBigBuilder.add(tmpRow, tmpCol, bigNumber); - expMtrx = tmpBigBuilder.build(); + BasicMatrix actual; + BasicMatrix expected; - final BasicMatrix.PhysicalReceiver tmpComplexBuilder = complexAA.copy(); - tmpComplexBuilder.add(tmpRow, tmpCol, bigNumber); - actMtrx = tmpComplexBuilder.build(); + expected = rAA.add(rSafe); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.add(cSafe); + TestUtils.assertEquals(expected, actual, ACCURACY); - final BasicMatrix.PhysicalReceiver tmpPrimitiveBuilder = primitiveAA.copy(); - tmpPrimitiveBuilder.add(tmpRow, tmpCol, bigNumber); - actMtrx = tmpPrimitiveBuilder.build(); + actual = p64AA.add(p64Safe); + TestUtils.assertEquals(expected, actual, ACCURACY); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p32AA.add(p32Safe); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** - * @see org.ojalgo.matrix.BasicMatrix#add(java.lang.Number) + * @see org.ojalgo.matrix.BasicMatrix#add(Comparable) */ @Test - public void testAddNumber() { + public void testAddScalar() { - expMtrx = rationalAA.add(bigNumber); + BasicMatrix actual; + BasicMatrix expected; - actMtrx = complexAA.add(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + expected = rAA.add(RationalNumber.valueOf(scalar)); - actMtrx = primitiveAA.add(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.add(ComplexNumber.valueOf(scalar)); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p64AA.add(scalar.doubleValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p32AA.add(scalar.floatValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** @@ -196,67 +215,83 @@ public void testAddNumber() { @Test public void testConjugate() { - expMtrx = rationalAA.conjugate(); + BasicMatrix actual; + BasicMatrix expected; + + expected = rAA.conjugate(); - actMtrx = complexAA.conjugate(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.conjugate(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.conjugate(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.conjugate(); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.conjugate(); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testDivideElementsBasicMatrix() { - PhysicalReceiver copyRational = rationalAA.copy(); - copyRational.modifyMatching(RationalMath.DIVIDE, rationalSafe); - expMtrx = copyRational.get(); + BasicMatrix actual; + BasicMatrix expected; + + PhysicalReceiver copyRational = rAA.copy(); + copyRational.modifyMatching(RationalMath.DIVIDE, rSafe); + expected = copyRational.get(); - PhysicalReceiver copyPrimitive = primitiveAA.copy(); - copyPrimitive.modifyMatching(PrimitiveMath.DIVIDE, primitiveSafe); - actMtrx = copyPrimitive.get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + PhysicalReceiver copyPrimitive = p64AA.copy(); + copyPrimitive.modifyMatching(PrimitiveMath.DIVIDE, p64Safe); + actual = copyPrimitive.get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - PhysicalReceiver copyComplex = complexAA.copy(); - copyComplex.modifyMatching(ComplexMath.DIVIDE, complexSafe); - actMtrx = copyComplex.get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + PhysicalReceiver copyComplex = cAA.copy(); + copyComplex.modifyMatching(ComplexMath.DIVIDE, cSafe); + actual = copyComplex.get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - PhysicalReceiver copyQuaternion = quaternionAA.copy(); - copyQuaternion.modifyMatching(QuaternionMath.DIVIDE, quaternionSafe); - actMtrx = copyQuaternion.get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + PhysicalReceiver copyQuaternion = qAA.copy(); + copyQuaternion.modifyMatching(QuaternionMath.DIVIDE, qSafe); + actual = copyQuaternion.get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** - * @see org.ojalgo.matrix.BasicMatrix#divide(java.lang.Number) + * @see org.ojalgo.matrix.BasicMatrix#divide(Comparable) */ @Test - public void testDivideNumber() { + public void testDivideScalar() { - expMtrx = rationalAA.divide(bigNumber); + BasicMatrix actual; + BasicMatrix expected; - actMtrx = complexAA.divide(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + expected = rAA.divide(RationalNumber.valueOf(scalar)); - actMtrx = primitiveAA.divide(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.divide(ComplexNumber.valueOf(scalar)); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p64AA.divide(scalar.doubleValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p32AA.divide(scalar.floatValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testDotAccess1D() { - final int[] tmpCol = new int[] { (int) Uniform.randomInteger(rationalAA.countColumns()) }; + Comparable actual; + Comparable expected; + + final int[] tmpCol = new int[] { (int) Uniform.randomInteger(rAA.countColumns()) }; - expNumber = rationalAA.logical().column(tmpCol).get().dot(rationalSafe.logical().column(tmpCol).get()); + expected = rAA.logical().column(tmpCol).get().dot(rSafe.logical().column(tmpCol).get()); - actNumber = complexAA.logical().column(tmpCol).get().dot(complexSafe.logical().column(tmpCol).get()); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = cAA.logical().column(tmpCol).get().dot(cSafe.logical().column(tmpCol).get()); + TestUtils.assertEquals(expected, actual, ACCURACY); - actNumber = primitiveAA.logical().column(tmpCol).get().dot(primitiveSafe.logical().column(tmpCol).get()); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = p64AA.logical().column(tmpCol).get().dot(p64Safe.logical().column(tmpCol).get()); + TestUtils.assertEquals(expected, actual, ACCURACY); } @@ -266,16 +301,19 @@ public void testDotAccess1D() { @Test public void testDoubleValueIntInt() { - final int tmpRow = (int) Uniform.randomInteger(rationalAA.countRows()); - final int tmpCol = (int) Uniform.randomInteger(rationalAA.countColumns()); + Comparable actual; + Comparable expected; + + final int tmpRow = (int) Uniform.randomInteger(rAA.countRows()); + final int tmpCol = (int) Uniform.randomInteger(rAA.countColumns()); - expNumber = rationalAA.doubleValue(tmpRow, tmpCol); + expected = rAA.doubleValue(tmpRow, tmpCol); - actNumber = complexAA.doubleValue(tmpRow, tmpCol); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = cAA.doubleValue(tmpRow, tmpCol); + TestUtils.assertEquals(expected, actual, ACCURACY); - actNumber = primitiveAA.doubleValue(tmpRow, tmpCol); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = p64AA.doubleValue(tmpRow, tmpCol); + TestUtils.assertEquals(expected, actual, ACCURACY); } @@ -283,34 +321,40 @@ public void testDoubleValueIntInt() { * @see org.ojalgo.matrix.BasicMatrix#countColumns() */ @Test - public void testGetColDim() { + public void testCountColumns() { - expInt = (int) rationalAA.countColumns(); + long expected = rAA.countColumns(); + long actual; - actInt = (int) complexAA.countColumns(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.countColumns(); + TestUtils.assertEquals(expected, actual); - actInt = (int) primitiveAA.countColumns(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.countColumns(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.countColumns(); + TestUtils.assertEquals(expected, actual); } @Test public void testGetColumnsIntArray() { - final int[] tmpArr = new int[(int) (1 + Uniform.randomInteger(rationalAA.countColumns()))]; + BasicMatrix actual; + BasicMatrix expected; + + final int[] tmpArr = new int[(int) (1 + Uniform.randomInteger(rAA.countColumns()))]; for (int i = 0; i < tmpArr.length; i++) { - tmpArr[i] = (int) Uniform.randomInteger(rationalAA.countColumns()); + tmpArr[i] = (int) Uniform.randomInteger(rAA.countColumns()); } - expMtrx = rationalAA.logical().column(tmpArr).get(); + expected = rAA.logical().column(tmpArr).get(); - actMtrx = complexAA.logical().column(tmpArr).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.logical().column(tmpArr).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.logical().column(tmpArr).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.logical().column(tmpArr).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } @@ -320,17 +364,17 @@ public void testGetColumnsIntArray() { @Test public void testGetCondition() { - if (rationalAA.isFullRank()) { + if (rAA.isFullRank()) { // Difficult to test numerically // Will only check that they are the same order of magnitude - final int tmpExpCondMag = (int) Math.round(PrimitiveMath.LOG10.invoke(rationalAA.getCondition().doubleValue())); + final int tmpExpCondMag = (int) Math.round(PrimitiveMath.LOG10.invoke(rAA.getCondition().doubleValue())); - int tmpActCondMag = (int) Math.round(PrimitiveMath.LOG10.invoke(primitiveAA.getCondition().doubleValue())); + int tmpActCondMag = (int) Math.round(PrimitiveMath.LOG10.invoke(p64AA.getCondition().doubleValue())); TestUtils.assertEquals(tmpExpCondMag, tmpActCondMag); - tmpActCondMag = (int) Math.round(PrimitiveMath.LOG10.invoke(complexAA.getCondition().doubleValue())); + tmpActCondMag = (int) Math.round(PrimitiveMath.LOG10.invoke(cAA.getCondition().doubleValue())); TestUtils.assertEquals(tmpExpCondMag, tmpActCondMag); } } @@ -341,15 +385,18 @@ public void testGetCondition() { @Test public void testGetDeterminant() { - if (rationalAA.isSquare()) { + if (rAA.isSquare()) { + + Comparable actual; + Comparable expected; - expNumber = rationalAA.getDeterminant().get(); + expected = rAA.getDeterminant().get(); - actNumber = complexAA.getDeterminant().get(); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = cAA.getDeterminant().get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actNumber = primitiveAA.getDeterminant().get(); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = p64AA.getDeterminant().get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } } @@ -357,19 +404,24 @@ public void testGetDeterminant() { @Test public void testGetEigenvalues() { - if (rationalAA.isSquare() && MatrixUtils.isHermitian(rationalAA)) { + if (rAA.isSquare() && rAA.isHermitian()) { - final List expected = primitiveAA.getEigenpairs(); + final List expected = rAA.getEigenpairs(); List actual; - actual = rationalAA.getEigenpairs(); + actual = cAA.getEigenpairs(); for (int i = 0; i < expected.size(); i++) { - TestUtils.assertEquals("Scalar != Scalar", expected.get(i).value, actual.get(i).value, evaluation); + TestUtils.assertEquals("Scalar != Scalar", expected.get(i).value, actual.get(i).value, ACCURACY); } - actual = complexAA.getEigenpairs(); + actual = p64AA.getEigenpairs(); for (int i = 0; i < expected.size(); i++) { - TestUtils.assertEquals("Scalar != Scalar", expected.get(i).value, actual.get(i).value, evaluation); + TestUtils.assertEquals("Scalar != Scalar", expected.get(i).value, actual.get(i).value, ACCURACY); + } + + actual = p32AA.getEigenpairs(); + for (int i = 0; i < expected.size(); i++) { + TestUtils.assertEquals("Scalar != Scalar", expected.get(i).value, actual.get(i).value, ACCURACY); } } } @@ -377,25 +429,34 @@ public void testGetEigenvalues() { @Test public void testGetInfinityNorm() { - expValue = BasicMatrix.calculateInfinityNorm(rationalAA); + double actual; + double expected; + + expected = BasicMatrix.calculateInfinityNorm(rAA); - actValue = BasicMatrix.calculateInfinityNorm(complexAA); - TestUtils.assertEquals(expValue, actValue, evaluation); + actual = BasicMatrix.calculateInfinityNorm(cAA); + TestUtils.assertEquals(expected, actual, ACCURACY); - actValue = BasicMatrix.calculateInfinityNorm(primitiveAA); - TestUtils.assertEquals(expValue, actValue, evaluation); + actual = BasicMatrix.calculateInfinityNorm(p64AA); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testGetOneNorm() { - expValue = BasicMatrix.calculateOneNorm(rationalAA); + double actual; + double expected; + + expected = BasicMatrix.calculateOneNorm(rAA); + + actual = BasicMatrix.calculateOneNorm(cAA); + TestUtils.assertEquals(expected, actual, ACCURACY); - actValue = BasicMatrix.calculateOneNorm(complexAA); - TestUtils.assertEquals(expValue, actValue, evaluation); + actual = BasicMatrix.calculateOneNorm(p64AA); + TestUtils.assertEquals(expected, actual, ACCURACY); - actValue = BasicMatrix.calculateOneNorm(primitiveAA); - TestUtils.assertEquals(expValue, actValue, evaluation); + actual = BasicMatrix.calculateOneNorm(p32AA); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** @@ -404,73 +465,82 @@ public void testGetOneNorm() { @Test public void testGetRank() { - expInt = rationalAA.getRank(); + int expected = rAA.getRank(); + int actual; - actInt = complexAA.getRank(); - TestUtils.assertEquals(expInt, actInt); + actual = cAA.getRank(); + TestUtils.assertEquals(expected, actual); - actInt = primitiveAA.getRank(); - TestUtils.assertEquals(expInt, actInt); + actual = p64AA.getRank(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.getRank(); + TestUtils.assertEquals(expected, actual); } /** * @see org.ojalgo.matrix.BasicMatrix#countRows() */ @Test - public void testGetRowDim() { + public void testCountRows() { - expInt = (int) rationalAA.countRows(); + long expected = rAA.countRows(); + long actual; - actInt = (int) complexAA.countRows(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.countRows(); + TestUtils.assertEquals(expected, actual); - actInt = (int) primitiveAA.countRows(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.countRows(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.countRows(); + TestUtils.assertEquals(expected, actual); } @Test public void testGetRowsIntArray() { - final int[] tmpArr = new int[(int) (1 + Uniform.randomInteger(rationalAA.countRows()))]; + BasicMatrix actual; + BasicMatrix expected; + + final int[] tmpArr = new int[(int) (1 + Uniform.randomInteger(rAA.countRows()))]; for (int i = 0; i < tmpArr.length; i++) { - tmpArr[i] = (int) Uniform.randomInteger(rationalAA.countRows()); + tmpArr[i] = (int) Uniform.randomInteger(rAA.countRows()); } - expMtrx = rationalAA.logical().row(tmpArr).get(); + expected = rAA.logical().row(tmpArr).get(); - actMtrx = complexAA.logical().row(tmpArr).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.logical().row(tmpArr).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.logical().row(tmpArr).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.logical().row(tmpArr).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testGetSingularValues() { - SingularValue rationalSVD = SingularValue.RATIONAL.make(rationalAA); - rationalSVD.compute(rationalAA); - TestUtils.assertEquals(GenericDenseStore.RATIONAL.copy(rationalAA), rationalSVD, evaluation); + SingularValue rationalSVD = SingularValue.RATIONAL.make(rAA); + rationalSVD.compute(rAA); + TestUtils.assertEquals(GenericStore.RATIONAL.copy(rAA), rationalSVD, ACCURACY); Array1D expected = rationalSVD.getSingularValues(); - SingularValue complexSVD = SingularValue.COMPLEX.make(complexAA); - complexSVD.compute(complexAA); - TestUtils.assertEquals(GenericDenseStore.COMPLEX.copy(complexAA), complexSVD, evaluation); - TestUtils.assertEquals(expected, complexSVD.getSingularValues(), evaluation); + SingularValue complexSVD = SingularValue.COMPLEX.make(cAA); + complexSVD.compute(cAA); + TestUtils.assertEquals(GenericStore.COMPLEX.copy(cAA), complexSVD, ACCURACY); + TestUtils.assertEquals(expected, complexSVD.getSingularValues(), ACCURACY); - SingularValue quaternionSVD = SingularValue.QUATERNION.make(quaternionAA); - quaternionSVD.compute(quaternionAA); - TestUtils.assertEquals(GenericDenseStore.QUATERNION.copy(quaternionAA), quaternionSVD, evaluation); - TestUtils.assertEquals(expected, quaternionSVD.getSingularValues(), evaluation); + SingularValue quaternionSVD = SingularValue.QUATERNION.make(qAA); + quaternionSVD.compute(qAA); + TestUtils.assertEquals(GenericStore.QUATERNION.copy(qAA), quaternionSVD, ACCURACY); + TestUtils.assertEquals(expected, quaternionSVD.getSingularValues(), ACCURACY); for (SingularValue primitiveSVD : MatrixDecompositionTests.getPrimitiveSingularValue()) { - primitiveSVD.compute(primitiveAA); - TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(primitiveAA), primitiveSVD, evaluation); - TestUtils.assertEquals(expected, primitiveSVD.getSingularValues(), evaluation); + primitiveSVD.compute(p64AA); + TestUtils.assertEquals(Primitive64Store.FACTORY.copy(p64AA), primitiveSVD, ACCURACY); + TestUtils.assertEquals(expected, primitiveSVD.getSingularValues(), ACCURACY); } } @@ -480,13 +550,16 @@ public void testGetSingularValues() { @Test public void testGetTrace() { - expNumber = rationalAA.getTrace().get(); + Comparable actual; + Comparable expected; + + expected = rAA.getTrace().get(); - actNumber = complexAA.getTrace().get(); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = cAA.getTrace().get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actNumber = primitiveAA.getTrace().get(); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = p64AA.getTrace().get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } @@ -496,16 +569,19 @@ public void testGetTrace() { @Test public void testInvert() { - if (rationalAA.isSquare() && (rationalAA.getRank() >= rationalAA.countColumns())) { + if (rAA.isSquare() && (rAA.getRank() >= rAA.countColumns())) { - expMtrx = rationalAA.invert(); + BasicMatrix expected = rAA.invert(); + BasicMatrix actual; - actMtrx = complexAA.invert(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.invert(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.invert(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.invert(); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.invert(); + TestUtils.assertEquals(expected, actual, ACCURACY); } } @@ -515,14 +591,17 @@ public void testInvert() { @Test public void testIsEmpty() { - expBoolean = rationalAA.isEmpty(); + boolean expected = rAA.isEmpty(); + boolean actual; - actBoolean = complexAA.isEmpty(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isEmpty(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isEmpty(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isEmpty(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isEmpty(); + TestUtils.assertEquals(expected, actual); } /** @@ -531,14 +610,17 @@ public void testIsEmpty() { @Test public void testIsFat() { - expBoolean = rationalAA.isFat(); + boolean expected = rAA.isFat(); + boolean actual; - actBoolean = complexAA.isFat(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isFat(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isFat(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isFat(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isFat(); + TestUtils.assertEquals(expected, actual); } /** @@ -547,14 +629,17 @@ public void testIsFat() { @Test public void testIsFullRank() { - expBoolean = rationalAA.isFullRank(); + boolean expected = rAA.isFullRank(); + boolean actual; - actBoolean = complexAA.isFullRank(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isFullRank(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isFullRank(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isFullRank(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isFullRank(); + TestUtils.assertEquals(expected, actual); } /** @@ -563,14 +648,17 @@ public void testIsFullRank() { @Test public void testIsHermitian() { - expBoolean = rationalAA.isHermitian(); + boolean expected = rAA.isHermitian(); + boolean actual; - actBoolean = complexAA.isHermitian(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isHermitian(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isHermitian(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isHermitian(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isHermitian(); + TestUtils.assertEquals(expected, actual); } /** @@ -579,14 +667,17 @@ public void testIsHermitian() { @Test public void testIsSquare() { - expBoolean = rationalAA.isSquare(); + boolean expected = rAA.isSquare(); + boolean actual; - actBoolean = complexAA.isSquare(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isSquare(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isSquare(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isSquare(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isSquare(); + TestUtils.assertEquals(expected, actual); } /** @@ -595,14 +686,17 @@ public void testIsSquare() { @Test public void testIsSymmetric() { - expBoolean = rationalAA.isSymmetric(); + boolean expected = rAA.isSymmetric(); + boolean actual; - actBoolean = complexAA.isSymmetric(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isSymmetric(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isSymmetric(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isSymmetric(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isSymmetric(); + TestUtils.assertEquals(expected, actual); } /** @@ -611,14 +705,17 @@ public void testIsSymmetric() { @Test public void testIsTall() { - expBoolean = rationalAA.isTall(); + boolean expected = rAA.isTall(); + boolean actual; - actBoolean = complexAA.isTall(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isTall(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isTall(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isTall(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isTall(); + TestUtils.assertEquals(expected, actual); } /** @@ -627,99 +724,121 @@ public void testIsTall() { @Test public void testIsVector() { - expBoolean = rationalAA.isVector(); + boolean expected = rAA.isVector(); + boolean actual; - actBoolean = complexAA.isVector(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = cAA.isVector(); + TestUtils.assertEquals(expected, actual); - actBoolean = primitiveAA.isVector(); - TestUtils.assertEquals(expBoolean, actBoolean); + actual = p64AA.isVector(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.isVector(); + TestUtils.assertEquals(expected, actual); } @Test public void testMergeColumnsBasicMatrix() { - expMtrx = rationalAA.logical().below(rationalSafe).get(); + BasicMatrix actual; + BasicMatrix expected; + + expected = rAA.logical().below(rSafe).get(); - actMtrx = primitiveAA.logical().below(primitiveSafe).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.logical().below(p64Safe).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = complexAA.logical().below(complexSafe).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.logical().below(cSafe).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = quaternionAA.logical().below(quaternionSafe).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = qAA.logical().below(qSafe).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testMergeRowsBasicMatrix() { - expMtrx = rationalAA.logical().right(rationalSafe).get(); + BasicMatrix actual; + BasicMatrix expected; - actMtrx = primitiveAA.logical().right(primitiveSafe).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + expected = rAA.logical().right(rSafe).get(); - actMtrx = complexAA.logical().right(complexSafe).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.logical().right(p64Safe).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = quaternionAA.logical().right(quaternionSafe).get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.logical().right(cSafe).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = qAA.logical().right(qSafe).get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** * @see org.ojalgo.matrix.BasicMatrix#multiply(org.ojalgo.matrix.BasicMatrix) */ @Test - public void testMultiplyBasicMatrix() { + public void testMultiplyMatrix() { + + BasicMatrix actual; + BasicMatrix expected; - expMtrx = rationalAA.multiply(rationalAX); + expected = rAA.multiply(rAX); - actMtrx = complexAA.multiply(complexAX); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.multiply(cAX); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.multiply(primitiveAX); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.multiply(p64AX); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.multiply(p32AX); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testMultiplyElementsBasicMatrix() { - PhysicalReceiver copyRational = rationalAA.copy(); - copyRational.modifyMatching(RationalMath.MULTIPLY, rationalSafe); - expMtrx = copyRational.get(); + BasicMatrix actual; + BasicMatrix expected; + + PhysicalReceiver copyRational = rAA.copy(); + copyRational.modifyMatching(RationalMath.MULTIPLY, rSafe); + expected = copyRational.get(); - PhysicalReceiver copyPrimitive = primitiveAA.copy(); - copyPrimitive.modifyMatching(PrimitiveMath.MULTIPLY, primitiveSafe); - actMtrx = copyPrimitive.get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + PhysicalReceiver copyPrimitive = p64AA.copy(); + copyPrimitive.modifyMatching(PrimitiveMath.MULTIPLY, p64Safe); + actual = copyPrimitive.get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - PhysicalReceiver copyComplex = complexAA.copy(); - copyComplex.modifyMatching(ComplexMath.MULTIPLY, complexSafe); - actMtrx = copyComplex.get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + PhysicalReceiver copyComplex = cAA.copy(); + copyComplex.modifyMatching(ComplexMath.MULTIPLY, cSafe); + actual = copyComplex.get(); + TestUtils.assertEquals(expected, actual, ACCURACY); - PhysicalReceiver copyQuaternion = quaternionAA.copy(); - copyQuaternion.modifyMatching(QuaternionMath.MULTIPLY, quaternionSafe); - actMtrx = copyQuaternion.get(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + PhysicalReceiver copyQuaternion = qAA.copy(); + copyQuaternion.modifyMatching(QuaternionMath.MULTIPLY, qSafe); + actual = copyQuaternion.get(); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** * @see org.ojalgo.matrix.BasicMatrix#multiply(java.lang.Number) */ @Test - public void testMultiplyNumber() { + public void testMultiplyScalar() { - expMtrx = rationalAA.multiply(bigNumber); + BasicMatrix actual; + BasicMatrix expected; - actMtrx = complexAA.multiply(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + expected = rAA.multiply(RationalNumber.valueOf(scalar)); - actMtrx = primitiveAA.multiply(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.multiply(ComplexNumber.valueOf(scalar)); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p64AA.multiply(scalar.doubleValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p32AA.multiply(scalar.floatValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** @@ -728,14 +847,17 @@ public void testMultiplyNumber() { @Test public void testNegate() { - expMtrx = rationalAA.negate(); + BasicMatrix expected = rAA.negate(); + BasicMatrix actual; - actMtrx = complexAA.negate(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.negate(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.negate(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.negate(); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.negate(); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** @@ -744,149 +866,159 @@ public void testNegate() { @Test public void testNorm() { - expValue = rationalAA.norm(); + double expected = rAA.norm(); + double actual; - actValue = complexAA.norm(); - TestUtils.assertEquals(expValue, actValue, evaluation); + actual = cAA.norm(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actValue = primitiveAA.norm(); - TestUtils.assertEquals(expValue, actValue, evaluation); + actual = p64AA.norm(); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.norm(); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** * @see BasicMatrix.PhysicalReceiver#set(long, long, Number) */ @Test - public void testSetIntIntNumber() { - - final int tmpRow = Uniform.randomInteger((int) rationalAA.countRows()); - final int tmpCol = Uniform.randomInteger((int) rationalAA.countColumns()); - - final BasicMatrix.PhysicalReceiver tmpBigBuilder = rationalAA.copy(); - tmpBigBuilder.set(tmpRow, tmpCol, bigNumber); - expMtrx = tmpBigBuilder.build(); - - final BasicMatrix.PhysicalReceiver tmpComplexBuilder = complexAA.copy(); - tmpComplexBuilder.set(tmpRow, tmpCol, bigNumber); - actMtrx = tmpComplexBuilder.build(); - - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); - - final BasicMatrix.PhysicalReceiver tmpPrimitiveBuilder = primitiveAA.copy(); - tmpPrimitiveBuilder.set(tmpRow, tmpCol, bigNumber); - actMtrx = tmpPrimitiveBuilder.build(); - - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + public void testSetElement() { + + long tmpRow = Uniform.randomInteger(rAA.countRows()); + long tmpCol = Uniform.randomInteger(rAA.countColumns()); + + BasicMatrix.PhysicalReceiver rBuilder = rAA.copy(); + rBuilder.set(tmpRow, tmpCol, scalar); + BasicMatrix expected = rBuilder.build(); + BasicMatrix actual; + + BasicMatrix.PhysicalReceiver cBuilder = cAA.copy(); + cBuilder.set(tmpRow, tmpCol, scalar); + actual = cBuilder.build(); + TestUtils.assertEquals(expected, actual, ACCURACY); + + BasicMatrix.PhysicalReceiver p64Builder = p64AA.copy(); + p64Builder.set(tmpRow, tmpCol, scalar); + actual = p64Builder.build(); + TestUtils.assertEquals(expected, actual, ACCURACY); + + BasicMatrix.PhysicalReceiver p32Builder = p32AA.copy(); + p32Builder.set(tmpRow, tmpCol, scalar); + actual = p32Builder.build(); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test - public void testSize() { + public void testCount() { - expInt = (int) rationalAA.count(); + long expected = rAA.count(); + long actual; - actInt = (int) complexAA.count(); - TestUtils.assertEquals(expInt, actInt); + actual = cAA.count(); + TestUtils.assertEquals(expected, actual); - actInt = (int) primitiveAA.count(); - TestUtils.assertEquals(expInt, actInt); + actual = p64AA.count(); + TestUtils.assertEquals(expected, actual); + actual = p32AA.count(); + TestUtils.assertEquals(expected, actual); } /** * @see org.ojalgo.matrix.BasicMatrix#solve(org.ojalgo.structure.Access2D) */ @Test - public void testSolveBasicMatrix() { + public void testSolveMatrix() { - if (rationalAA.isSquare() && (rationalAA.getRank() >= rationalAA.countColumns())) { + if (rAA.isSquare() && (rAA.getRank() >= rAA.countColumns())) { - expMtrx = rationalAA.solve(rationalAB); + BasicMatrix expected = rAA.solve(rAB); + BasicMatrix actual; - actMtrx = complexAA.solve(complexAB); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.solve(cAB); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.solve(primitiveAB); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.solve(p64AB); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.solve(p64AB); + TestUtils.assertEquals(expected, actual, ACCURACY); } } /** - * @see org.ojalgo.matrix.BasicMatrix#subtract(org.ojalgo.matrix.BasicMatrix) + * @see org.ojalgo.matrix.BasicMatrix#subtract(BasicMatrix) */ @Test - public void testSubtractBasicMatrix() { + public void testSubtractMatrix() { + + BasicMatrix actual; + BasicMatrix expected; - expMtrx = rationalAA.subtract(rationalSafe); + expected = rAA.subtract(rSafe); - actMtrx = complexAA.subtract(complexSafe); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.subtract(cSafe); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.subtract(primitiveSafe); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.subtract(p64Safe); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.subtract(p32Safe); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** - * @see org.ojalgo.matrix.BasicMatrix#subtract(java.lang.Number) + * @see org.ojalgo.matrix.BasicMatrix#subtract(Comparable) */ @Test - public void testSubtractNumber() { - - expMtrx = rationalAA.subtract(bigNumber); + public void testSubtractScalar() { - actMtrx = complexAA.subtract(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + BasicMatrix actual; + BasicMatrix expected; - actMtrx = primitiveAA.subtract(bigNumber); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + expected = rAA.subtract(RationalNumber.valueOf(scalar)); - } - - @Test - public void testToBigDecimalIntInt() { + actual = cAA.subtract(ComplexNumber.valueOf(scalar)); + TestUtils.assertEquals(expected, actual, ACCURACY); - final int tmpRow = (int) Uniform.randomInteger(rationalAA.countRows()); - final int tmpCol = (int) Uniform.randomInteger(rationalAA.countColumns()); - - expNumber = TypeUtils.toBigDecimal(rationalAA.get(tmpRow, tmpCol)); - - actNumber = TypeUtils.toBigDecimal(complexAA.get(tmpRow, tmpCol)); - TestUtils.assertEquals(expNumber, actNumber, evaluation); - - actNumber = TypeUtils.toBigDecimal(primitiveAA.get(tmpRow, tmpCol)); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = p64AA.subtract(scalar.doubleValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.subtract(scalar.floatValue()); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testToComplexNumberIntInt() { - final int tmpRow = (int) Uniform.randomInteger(rationalAA.countRows()); - final int tmpCol = (int) Uniform.randomInteger(rationalAA.countColumns()); + Comparable actual; + Comparable expected; - expNumber = ComplexNumber.valueOf(rationalAA.get(tmpRow, tmpCol)); + final int tmpRow = (int) Uniform.randomInteger(rAA.countRows()); + final int tmpCol = (int) Uniform.randomInteger(rAA.countColumns()); - actNumber = ComplexNumber.valueOf(complexAA.get(tmpRow, tmpCol)); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + expected = ComplexNumber.valueOf(rAA.get(tmpRow, tmpCol)); - actNumber = ComplexNumber.valueOf(primitiveAA.get(tmpRow, tmpCol)); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = ComplexNumber.valueOf(cAA.get(tmpRow, tmpCol)); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = ComplexNumber.valueOf(p64AA.get(tmpRow, tmpCol)); + TestUtils.assertEquals(expected, actual, ACCURACY); } @Test public void testToComplexStore() { - final PhysicalStore tmpExpStore = GenericDenseStore.COMPLEX.copy(rationalAA); + final PhysicalStore tmpExpStore = GenericStore.COMPLEX.copy(rAA); PhysicalStore tmpActStore; - tmpActStore = GenericDenseStore.COMPLEX.copy(complexAA); - TestUtils.assertEquals(tmpExpStore, tmpActStore, evaluation); + tmpActStore = GenericStore.COMPLEX.copy(cAA); + TestUtils.assertEquals(tmpExpStore, tmpActStore, ACCURACY); - tmpActStore = GenericDenseStore.COMPLEX.copy(primitiveAA); - TestUtils.assertEquals(tmpExpStore, tmpActStore, evaluation); + tmpActStore = GenericStore.COMPLEX.copy(p64AA); + TestUtils.assertEquals(tmpExpStore, tmpActStore, ACCURACY); } @@ -896,13 +1028,13 @@ public void testToComplexStore() { @Test public void testToListOfColumns() { - final Iterable> tmpColumns = rationalAA.columns(); + final Iterable> tmpColumns = rAA.columns(); for (final ColumnView tmpColumnView : tmpColumns) { final long j = tmpColumnView.column(); for (long i = 0L; i < tmpColumnView.count(); i++) { - TestUtils.assertEquals(tmpColumnView.get(i), complexAA.get(i, j), evaluation); - TestUtils.assertEquals(tmpColumnView.get(i), primitiveAA.get(i, j), evaluation); + TestUtils.assertEquals(tmpColumnView.get(i), cAA.get(i, j), ACCURACY); + TestUtils.assertEquals(tmpColumnView.get(i), p64AA.get(i, j), ACCURACY); } } } @@ -913,13 +1045,13 @@ public void testToListOfColumns() { @Test public void testToListOfRows() { - final Iterable> tmpRows = rationalAA.rows(); + final Iterable> tmpRows = rAA.rows(); for (final RowView tmpRowView : tmpRows) { final long i = tmpRowView.row(); for (long j = 0L; j < tmpRowView.count(); j++) { - TestUtils.assertEquals(tmpRowView.get(j), complexAA.get(i, j), evaluation); - TestUtils.assertEquals(tmpRowView.get(j), primitiveAA.get(i, j), evaluation); + TestUtils.assertEquals(tmpRowView.get(j), cAA.get(i, j), ACCURACY); + TestUtils.assertEquals(tmpRowView.get(j), p64AA.get(i, j), ACCURACY); } } } @@ -927,28 +1059,28 @@ public void testToListOfRows() { @Test public void testToPrimitiveStore() { - final PhysicalStore tmpExpStore = PrimitiveDenseStore.FACTORY.copy(rationalAA); + final PhysicalStore tmpExpStore = Primitive64Store.FACTORY.copy(rAA); PhysicalStore tmpActStore; - tmpActStore = PrimitiveDenseStore.FACTORY.copy(complexAA); - TestUtils.assertEquals(tmpExpStore, tmpActStore, evaluation); + tmpActStore = Primitive64Store.FACTORY.copy(cAA); + TestUtils.assertEquals(tmpExpStore, tmpActStore, ACCURACY); - tmpActStore = PrimitiveDenseStore.FACTORY.copy(primitiveAA); - TestUtils.assertEquals(tmpExpStore, tmpActStore, evaluation); + tmpActStore = Primitive64Store.FACTORY.copy(p64AA); + TestUtils.assertEquals(tmpExpStore, tmpActStore, ACCURACY); } @Test public void testToRationalStore() { - final PhysicalStore tmpExpStore = GenericDenseStore.RATIONAL.copy(rationalAA); + final PhysicalStore tmpExpStore = GenericStore.RATIONAL.copy(rAA); PhysicalStore tmpActStore; - tmpActStore = GenericDenseStore.RATIONAL.copy(complexAA); - TestUtils.assertEquals(tmpExpStore, tmpActStore, evaluation); + tmpActStore = GenericStore.RATIONAL.copy(cAA); + TestUtils.assertEquals(tmpExpStore, tmpActStore, ACCURACY); - tmpActStore = GenericDenseStore.RATIONAL.copy(primitiveAA); - TestUtils.assertEquals(tmpExpStore, tmpActStore, evaluation); + tmpActStore = GenericStore.RATIONAL.copy(p64AA); + TestUtils.assertEquals(tmpExpStore, tmpActStore, ACCURACY); } @@ -958,27 +1090,27 @@ public void testToRationalStore() { @Test public void testToRawCopy1D() { - final double[] tmpExpStore = rationalAA.toRawCopy1D(); + final double[] tmpExpStore = rAA.toRawCopy1D(); double[] tmpActStore; final int tmpFirstIndex = 0; - final int tmpLastIndex = (int) (rationalAA.count() - 1); + final int tmpLastIndex = (int) (rAA.count() - 1); - tmpActStore = complexAA.toRawCopy1D(); - TestUtils.assertEquals(tmpExpStore[tmpFirstIndex], tmpActStore[tmpFirstIndex], evaluation); - TestUtils.assertEquals(tmpExpStore[tmpLastIndex], tmpActStore[tmpLastIndex], evaluation); - if (rationalAA.isVector()) { + tmpActStore = cAA.toRawCopy1D(); + TestUtils.assertEquals(tmpExpStore[tmpFirstIndex], tmpActStore[tmpFirstIndex], ACCURACY); + TestUtils.assertEquals(tmpExpStore[tmpLastIndex], tmpActStore[tmpLastIndex], ACCURACY); + if (rAA.isVector()) { for (int i = 0; i < tmpExpStore.length; i++) { - TestUtils.assertEquals(tmpExpStore[i], tmpActStore[i], evaluation); + TestUtils.assertEquals(tmpExpStore[i], tmpActStore[i], ACCURACY); } } - tmpActStore = primitiveAA.toRawCopy1D(); - TestUtils.assertEquals(tmpExpStore[tmpFirstIndex], tmpActStore[tmpFirstIndex], evaluation); - TestUtils.assertEquals(tmpExpStore[tmpLastIndex], tmpActStore[tmpLastIndex], evaluation); - if (rationalAA.isVector()) { + tmpActStore = p64AA.toRawCopy1D(); + TestUtils.assertEquals(tmpExpStore[tmpFirstIndex], tmpActStore[tmpFirstIndex], ACCURACY); + TestUtils.assertEquals(tmpExpStore[tmpLastIndex], tmpActStore[tmpLastIndex], ACCURACY); + if (rAA.isVector()) { for (int i = 0; i < tmpExpStore.length; i++) { - TestUtils.assertEquals(tmpExpStore[i], tmpActStore[i], evaluation); + TestUtils.assertEquals(tmpExpStore[i], tmpActStore[i], ACCURACY); } } @@ -990,17 +1122,20 @@ public void testToRawCopy1D() { @Test public void testToScalarIntInt() { - final int tmpRow = Uniform.randomInteger((int) rationalAA.countRows()); - final int tmpCol = Uniform.randomInteger((int) rationalAA.countColumns()); + long tmpRow = Uniform.randomInteger(rAA.countRows()); + long tmpCol = Uniform.randomInteger(rAA.countColumns()); - expNumber = rationalAA.toScalar(tmpRow, tmpCol).get(); + Scalar expected = rAA.toScalar(tmpRow, tmpCol); + Scalar actual; - actNumber = complexAA.toScalar(tmpRow, tmpCol).get(); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = cAA.toScalar(tmpRow, tmpCol); + TestUtils.assertEquals(expected, actual, ACCURACY); - actNumber = primitiveAA.toScalar(tmpRow, tmpCol).get(); - TestUtils.assertEquals(expNumber, actNumber, evaluation); + actual = p64AA.toScalar(tmpRow, tmpCol); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.toScalar(tmpRow, tmpCol); + TestUtils.assertEquals(expected, actual, ACCURACY); } /** @@ -1009,14 +1144,19 @@ public void testToScalarIntInt() { @Test public void testTranspose() { - expMtrx = rationalAA.transpose(); + BasicMatrix actual; + BasicMatrix expected; + + expected = rAA.transpose(); - actMtrx = complexAA.transpose(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = cAA.transpose(); + TestUtils.assertEquals(expected, actual, ACCURACY); - actMtrx = primitiveAA.transpose(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + actual = p64AA.transpose(); + TestUtils.assertEquals(expected, actual, ACCURACY); + actual = p32AA.transpose(); + TestUtils.assertEquals(expected, actual, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/LargerCholeskyCase.java b/test/org/ojalgo/matrix/LargerCholeskyCase.java index d2bfb6aac..d2df079d3 100644 --- a/test/org/ojalgo/matrix/LargerCholeskyCase.java +++ b/test/org/ojalgo/matrix/LargerCholeskyCase.java @@ -25,10 +25,10 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.Cholesky; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.type.context.NumberContext; @@ -51,28 +51,28 @@ public static RationalMatrix getOriginal() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 3); + // ACCURACY = new NumberContext(7, 3); - rationalAB = LargerCholeskyCase.getOriginal(); + rAB = LargerCholeskyCase.getOriginal(); final Cholesky tmpCholesky = Cholesky.RATIONAL.make(); - tmpCholesky.decompose(GenericDenseStore.RATIONAL.copy(rationalAB)); + tmpCholesky.decompose(GenericStore.RATIONAL.copy(rAB)); - rationalAA = RationalMatrix.FACTORY.copy(tmpCholesky.getL()); - rationalAX = rationalAA.transpose(); + rAA = RationalMatrix.FACTORY.copy(tmpCholesky.getL()); + rAX = rAA.transpose(); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { - final MatrixStore tmpMtrx = PrimitiveDenseStore.FACTORY.copy(LargerCholeskyCase.getOriginal()); + final MatrixStore tmpMtrx = Primitive64Store.FACTORY.copy(LargerCholeskyCase.getOriginal()); final Cholesky tmpDecomp = Cholesky.PRIMITIVE.make(); tmpDecomp.decompose(tmpMtrx); TestUtils.assertEquals(true, tmpDecomp.isSolvable()); @@ -83,9 +83,9 @@ public void testProblem() { final RationalMatrix tmpMtrx = LargerCholeskyCase.getOriginal(); final Cholesky tmpDecomp = Cholesky.PRIMITIVE.make(); - tmpDecomp.decompose(PrimitiveDenseStore.FACTORY.copy(tmpMtrx)); + tmpDecomp.decompose(Primitive64Store.FACTORY.copy(tmpMtrx)); - TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(tmpMtrx), tmpDecomp, evaluation); + TestUtils.assertEquals(Primitive64Store.FACTORY.copy(tmpMtrx), tmpDecomp, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/NormTest.java b/test/org/ojalgo/matrix/NormTest.java index ffe4b9be7..cda60aca6 100644 --- a/test/org/ojalgo/matrix/NormTest.java +++ b/test/org/ojalgo/matrix/NormTest.java @@ -45,7 +45,8 @@ public void testCompareComplexNumber() { final double actual1 = svd.getOperatorNorm(); TestUtils.assertEquals(expected, actual1); - final double actual2 = PrimitiveMatrix.FACTORY.copy(cmplx).norm(); + Primitive64Matrix copied = Primitive64Matrix.FACTORY.copy(cmplx); + final double actual2 = copied.norm(); TestUtils.assertEquals(expected, actual2); } @@ -63,7 +64,8 @@ public void testCompareQuaternion() { final double actual1 = svd.getOperatorNorm(); TestUtils.assertEquals(expected, actual1); - final double actual2 = PrimitiveMatrix.FACTORY.copy(quat).norm(); + Primitive64Matrix copied = Primitive64Matrix.FACTORY.copy(quat); + final double actual2 = copied.norm(); TestUtils.assertEquals(expected, actual2); } diff --git a/test/org/ojalgo/matrix/P20030422Case.java b/test/org/ojalgo/matrix/P20030422Case.java index 305262b4e..86579e488 100644 --- a/test/org/ojalgo/matrix/P20030422Case.java +++ b/test/org/ojalgo/matrix/P20030422Case.java @@ -51,28 +51,70 @@ public static RationalMatrix getProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 3); + // ACCURACY = new NumberContext(7, 3); - rationalAA = P20030422Case.getProblematic(); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = P20030422Case.getProblematic(); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); + } + + @Override + @Test + public void testInvert() { + + if (rAA.isSquare() && (rAA.getRank() >= rAA.countColumns())) { + + BasicMatrix expected = rAA.invert(); + BasicMatrix actual; + + actual = cAA.invert(); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p64AA.invert(); + TestUtils.assertEquals(expected, actual, ACCURACY); + + // TODO Probably ok that this doesn't work in this case + // actual = p32AA.invert(); + // TestUtils.assertEquals(expected, actual, ACCURACY); + } } @Test public void testProblem() { - expMtrx = P20030422Case.getProblematic(); - actMtrx = expMtrx.invert().invert(); + RationalMatrix expected = P20030422Case.getProblematic(); + RationalMatrix actual = expected.invert().invert(); // The RationalMatrix implementation can do this do 6 decimals, but not the others - TestUtils.assertEquals(expMtrx, actMtrx, DEFINITION); + TestUtils.assertEquals(expected, actual, DEFINITION); + } + + @Override + @Test + public void testSolveMatrix() { + + if (rAA.isSquare() && (rAA.getRank() >= rAA.countColumns())) { + + BasicMatrix expected = rAA.solve(rAB); + BasicMatrix actual; + + actual = cAA.solve(cAB); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p64AA.solve(p64AB); + TestUtils.assertEquals(expected, actual, ACCURACY); + + // TODO Probably ok that this doesn't work in this case + // actual = p32AA.solve(p64AB); + // TestUtils.assertEquals(expected, actual, ACCURACY); + } } } diff --git a/test/org/ojalgo/matrix/P20030512Case.java b/test/org/ojalgo/matrix/P20030512Case.java index 98d2ed6f7..a8914a018 100644 --- a/test/org/ojalgo/matrix/P20030512Case.java +++ b/test/org/ojalgo/matrix/P20030512Case.java @@ -61,27 +61,66 @@ public static RationalMatrix getProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(8, 6); + // ACCURACY = new NumberContext(8, 6); - rationalAA = P20030512Case.getProblematic(); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = P20030512Case.getProblematic(); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); + } + + @Override + @Test + public void testGetRank() { + + int expected = rAA.getRank(); + int actual; + + actual = cAA.getRank(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.getRank(); + TestUtils.assertEquals(expected, actual); + + // TODO Why doesn't this work? + // actual = p32AA.getRank(); + // TestUtils.assertEquals(expected, actual); + } + + @Override + @Test + public void testIsFullRank() { + + boolean expected = rAA.isFullRank(); + boolean actual; + + actual = cAA.isFullRank(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.isFullRank(); + TestUtils.assertEquals(expected, actual); + + // TODO Why doesn't this work? + // actual = p32AA.isFullRank(); + // TestUtils.assertEquals(expected, actual); } @Test public void testProblem() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + expMtrx = P20030512Case.getProblematic(); actMtrx = expMtrx.invert().invert(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/P20030528Case.java b/test/org/ojalgo/matrix/P20030528Case.java index d2dcf5a44..c134d232e 100644 --- a/test/org/ojalgo/matrix/P20030528Case.java +++ b/test/org/ojalgo/matrix/P20030528Case.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.SingularValue; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; /** @@ -48,18 +48,18 @@ public static RationalMatrix getProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 9); + // ACCURACY = new NumberContext(7, 9); - rationalAA = P20030528Case.getProblematic(); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = P20030528Case.getProblematic(); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test @@ -74,13 +74,13 @@ public void testData() { @Test public void testProblem() { - final PhysicalStore tmpA = PrimitiveDenseStore.FACTORY.copy(P20030528Case.getProblematic()); + final PhysicalStore tmpA = Primitive64Store.FACTORY.copy(P20030528Case.getProblematic()); final SingularValue tmpSVD = SingularValue.make(tmpA); tmpSVD.decompose(tmpA); // tmpSVD.equals(tmpA, EVALUATION); - TestUtils.assertEquals(tmpA, tmpSVD, evaluation); + TestUtils.assertEquals(tmpA, tmpSVD, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/P20050125Case.java b/test/org/ojalgo/matrix/P20050125Case.java index 839c8bcc9..94c88c761 100644 --- a/test/org/ojalgo/matrix/P20050125Case.java +++ b/test/org/ojalgo/matrix/P20050125Case.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.Cholesky; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.random.Uniform; import org.ojalgo.scalar.RationalNumber; @@ -49,47 +49,47 @@ public static RationalMatrix getProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 6); + // ACCURACY = new NumberContext(7, 6); - rationalAA = P20050125Case.getProblematic(); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = P20050125Case.getProblematic(); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { final Cholesky tmpDelegate = Cholesky.RATIONAL.make(); - tmpDelegate.decompose(GenericDenseStore.RATIONAL.copy(rationalAA)); + tmpDelegate.decompose(GenericStore.RATIONAL.copy(rAA)); - TestUtils.assertEquals(GenericDenseStore.RATIONAL.copy(rationalAA), tmpDelegate, evaluation); + TestUtils.assertEquals(GenericStore.RATIONAL.copy(rAA), tmpDelegate, ACCURACY); } @Test public void testProblem() { final Cholesky tmpDelegate = Cholesky.RATIONAL.make(); - tmpDelegate.decompose(GenericDenseStore.RATIONAL.copy(rationalAA)); + tmpDelegate.decompose(GenericStore.RATIONAL.copy(rAA)); - final MatrixStore tmpInv = tmpDelegate.getSolution(GenericDenseStore.RATIONAL.copy(rationlI)); + final MatrixStore tmpInv = tmpDelegate.getSolution(GenericStore.RATIONAL.copy(rI)); - final MatrixStore tmpExpMtrx = GenericDenseStore.RATIONAL.copy(rationlI); - final MatrixStore tmpActMtrx = GenericDenseStore.RATIONAL.copy(rationalAA).multiply(tmpInv); + final MatrixStore tmpExpMtrx = GenericStore.RATIONAL.copy(rI); + final MatrixStore tmpActMtrx = GenericStore.RATIONAL.copy(rAA).multiply(tmpInv); - TestUtils.assertEquals(tmpExpMtrx, tmpActMtrx, evaluation); + TestUtils.assertEquals(tmpExpMtrx, tmpActMtrx, ACCURACY); } @Override @Test - public void testSolveBasicMatrix() { - super.testSolveBasicMatrix(); + public void testSolveMatrix() { + super.testSolveMatrix(); } } diff --git a/test/org/ojalgo/matrix/P20050827Case.java b/test/org/ojalgo/matrix/P20050827Case.java index efa48b48b..4ed3b9d5b 100644 --- a/test/org/ojalgo/matrix/P20050827Case.java +++ b/test/org/ojalgo/matrix/P20050827Case.java @@ -66,18 +66,18 @@ public static ComplexMatrix getProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = NumberContext.getGeneral(6).withPrecision(12); + // ACCURACY = NumberContext.getGeneral(6).withPrecision(12); - rationalAA = RationalMatrix.FACTORY.copy(P20050827Case.getProblematic()); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = RationalMatrix.FACTORY.copy(P20050827Case.getProblematic()); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test @@ -109,7 +109,7 @@ public void testData() { TestUtils.assertTrue(tmpBig.toScalar(ij, ij).toString(), tmpBig.get(ij, ij).isReal()); } - TestUtils.assertEquals("Scalar != Scalar", tmpBigTrace.get(), tmpSmallTrace.get(), evaluation); + TestUtils.assertEquals("Scalar != Scalar", tmpBigTrace.get(), tmpSmallTrace.get(), ACCURACY); } @Test @@ -122,8 +122,8 @@ public void testProblem() { final ComplexNumber tmpExpected = ComplexMath.ROOT.invoke(tmpVal, 2); final ComplexNumber tmpActual = ComplexNumber.valueOf(tmpProblematic.aggregateAll(Aggregator.NORM2)); - TestUtils.assertEquals(tmpExpected.norm(), tmpActual.norm(), evaluation); - TestUtils.assertEquals(tmpExpected, tmpActual, evaluation); + TestUtils.assertEquals(tmpExpected.norm(), tmpActual.norm(), ACCURACY); + TestUtils.assertEquals(tmpExpected, tmpActual, ACCURACY); } diff --git a/test/org/ojalgo/matrix/P20061119Case.java b/test/org/ojalgo/matrix/P20061119Case.java index e4437a611..8ee23b80b 100644 --- a/test/org/ojalgo/matrix/P20061119Case.java +++ b/test/org/ojalgo/matrix/P20061119Case.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.Eigenvalue; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; /** @@ -61,18 +61,18 @@ public static RationalMatrix getProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = NumberContext.getGeneral(8).withPrecision(14); + // evaluation = NumberContext.getGeneral(8).withPrecision(14); - rationalAA = P20061119Case.getProblematic(); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = P20061119Case.getProblematic(); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test @@ -80,16 +80,52 @@ public void testData() { TestUtils.assertEquals(true, P20061119Case.getProblematic().isSquare()); } + @Override + @Test + public void testGetRank() { + + int expected = rAA.getRank(); + int actual; + + actual = cAA.getRank(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.getRank(); + TestUtils.assertEquals(expected, actual); + + // TODO Why doesn't this work? + // actual = p32AA.getRank(); + // TestUtils.assertEquals(expected, actual); + } + + @Override + @Test + public void testIsFullRank() { + + boolean expected = rAA.isFullRank(); + boolean actual; + + actual = cAA.isFullRank(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.isFullRank(); + TestUtils.assertEquals(expected, actual); + + // TODO Why doesn't this work? + // actual = p32AA.isFullRank(); + // TestUtils.assertEquals(expected, actual); + } + @Test public void testProblem() { final RationalMatrix tmpMatrix = P20061119Case.getProblematic(); final Eigenvalue tmpEigenvalue = Eigenvalue.PRIMITIVE.make(); - final PhysicalStore tmpPrimitiveStore = PrimitiveDenseStore.FACTORY.copy(tmpMatrix); + final PhysicalStore tmpPrimitiveStore = Primitive64Store.FACTORY.copy(tmpMatrix); tmpEigenvalue.decompose(tmpPrimitiveStore); - TestUtils.assertEquals(tmpPrimitiveStore, tmpEigenvalue, evaluation); + TestUtils.assertEquals(tmpPrimitiveStore, tmpEigenvalue, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/P20071019Case.java b/test/org/ojalgo/matrix/P20071019Case.java index a01342d94..e6333f4f1 100644 --- a/test/org/ojalgo/matrix/P20071019Case.java +++ b/test/org/ojalgo/matrix/P20071019Case.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.LU; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; /** @@ -49,18 +49,18 @@ public static RationalMatrix getTallProblematic() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = evaluation.withPrecision(14); + // ACCURACY = ACCURACY.withPrecision(14); - rationalAA = P20071019Case.getFatProblematic().multiply(P20071019Case.getTallProblematic()).enforce(DEFINITION); - rationalAX = BasicMatrixTest.getIdentity(rationalAA.countColumns(), rationalAA.countColumns(), DEFINITION); - rationalAB = rationalAA; + rAA = P20071019Case.getFatProblematic().multiply(P20071019Case.getTallProblematic()).enforce(DEFINITION); + rAX = BasicMatrixTest.getIdentity(rAA.countColumns(), rAA.countColumns(), DEFINITION); + rAB = rAA; - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test @@ -77,21 +77,21 @@ public void testProblem() { final LU tmpJamaLU = LU.PRIMITIVE.make(); final LU tmpDenseLU = LU.PRIMITIVE.make(); - MatrixStore tmpOriginal = PrimitiveDenseStore.FACTORY.copy(P20071019Case.getFatProblematic()); + MatrixStore tmpOriginal = Primitive64Store.FACTORY.copy(P20071019Case.getFatProblematic()); tmpJamaLU.decompose(tmpOriginal); - TestUtils.assertEquals(tmpOriginal, tmpJamaLU, evaluation); + TestUtils.assertEquals(tmpOriginal, tmpJamaLU, ACCURACY); tmpDenseLU.decompose(tmpOriginal); - TestUtils.assertEquals(tmpOriginal, tmpDenseLU, evaluation); + TestUtils.assertEquals(tmpOriginal, tmpDenseLU, ACCURACY); - tmpOriginal = PrimitiveDenseStore.FACTORY.copy(P20071019Case.getTallProblematic()); + tmpOriginal = Primitive64Store.FACTORY.copy(P20071019Case.getTallProblematic()); tmpJamaLU.decompose(tmpOriginal); - TestUtils.assertEquals(tmpOriginal, tmpJamaLU, evaluation); + TestUtils.assertEquals(tmpOriginal, tmpJamaLU, ACCURACY); tmpDenseLU.decompose(tmpOriginal); - TestUtils.assertEquals(tmpOriginal, tmpDenseLU, evaluation); + TestUtils.assertEquals(tmpOriginal, tmpDenseLU, ACCURACY); } diff --git a/test/org/ojalgo/matrix/ReductionTest.java b/test/org/ojalgo/matrix/ReductionTest.java index 2912db51a..8d08a921a 100644 --- a/test/org/ojalgo/matrix/ReductionTest.java +++ b/test/org/ojalgo/matrix/ReductionTest.java @@ -19,17 +19,17 @@ public ReductionTest() { @Test public void testReduction() { - BasicMatrix.PhysicalReceiver builder = PrimitiveMatrix.FACTORY.makeDense(2, 3); + BasicMatrix.PhysicalReceiver builder = Primitive64Matrix.FACTORY.makeDense(2, 3); builder.set(0, 0, 1.0); builder.set(0, 1, 2.0); builder.set(0, 2, 3.0); builder.set(1, 0, 4.0); builder.set(1, 1, 5.0); builder.set(1, 2, 6.0); - PrimitiveMatrix matrix = builder.get(); + Primitive64Matrix matrix = builder.get(); - PrimitiveMatrix reducedRows = matrix.reduceRows(AVERAGE); - PrimitiveMatrix reducedColumns = matrix.reduceColumns(AVERAGE); + Primitive64Matrix reducedRows = matrix.reduceRows(AVERAGE); + Primitive64Matrix reducedColumns = matrix.reduceColumns(AVERAGE); TestUtils.assertEquals(2, reducedRows.count()); TestUtils.assertEquals(2, reducedRows.countRows()); diff --git a/test/org/ojalgo/matrix/SimpleCholeskyCase.java b/test/org/ojalgo/matrix/SimpleCholeskyCase.java index aa97bd0f1..849fb9655 100644 --- a/test/org/ojalgo/matrix/SimpleCholeskyCase.java +++ b/test/org/ojalgo/matrix/SimpleCholeskyCase.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.Cholesky; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.type.context.NumberContext; @@ -57,36 +57,39 @@ private static RationalMatrix getFactorR() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(4, 3); + rAA = SimpleCholeskyCase.getFactorL(); + rAX = SimpleCholeskyCase.getFactorR(); + rAB = SimpleCholeskyCase.getOriginal(); - rationalAA = SimpleCholeskyCase.getFactorL(); - rationalAX = SimpleCholeskyCase.getFactorR(); - rationalAB = SimpleCholeskyCase.getOriginal(); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { + NumberContext accuracy = new NumberContext(4, 3); + final RationalMatrix tmpA = SimpleCholeskyCase.getOriginal(); final RationalMatrix tmpL = SimpleCholeskyCase.getFactorL(); final RationalMatrix tmpR = SimpleCholeskyCase.getFactorR(); + BasicMatrix actMtrx; + BasicMatrix expMtrx; + expMtrx = tmpL; actMtrx = tmpR.transpose(); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, accuracy); expMtrx = tmpA; actMtrx = tmpL.multiply(tmpR); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, accuracy); } // @Test @@ -115,9 +118,9 @@ public void testProblem() { final RationalMatrix tmpMtrx = SimpleCholeskyCase.getOriginal(); final Cholesky tmpDecomp = Cholesky.RATIONAL.make(); - tmpDecomp.decompose(GenericDenseStore.RATIONAL.copy(tmpMtrx)); + tmpDecomp.decompose(GenericStore.RATIONAL.copy(tmpMtrx)); - TestUtils.assertEquals(GenericDenseStore.RATIONAL.copy(tmpMtrx), tmpDecomp, evaluation); + TestUtils.assertEquals(GenericStore.RATIONAL.copy(tmpMtrx), tmpDecomp, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/SimpleEigenvalueCase.java b/test/org/ojalgo/matrix/SimpleEigenvalueCase.java index 9b980d00a..f8890d3eb 100644 --- a/test/org/ojalgo/matrix/SimpleEigenvalueCase.java +++ b/test/org/ojalgo/matrix/SimpleEigenvalueCase.java @@ -28,7 +28,7 @@ import org.ojalgo.matrix.BasicMatrix.PhysicalReceiver; import org.ojalgo.matrix.decomposition.Eigenvalue; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.type.context.NumberContext; @@ -58,43 +58,49 @@ private static RationalMatrix getMatrixV() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 3); + // ACCURACY = new NumberContext(7, 3); - rationalAA = SimpleEigenvalueCase.getOriginal(); - rationalAX = SimpleEigenvalueCase.getMatrixV(); - rationalAB = SimpleEigenvalueCase.getMatrixV().multiply(SimpleEigenvalueCase.getMatrixD()); + rAA = SimpleEigenvalueCase.getOriginal(); + rAX = SimpleEigenvalueCase.getMatrixV(); + rAB = SimpleEigenvalueCase.getMatrixV().multiply(SimpleEigenvalueCase.getMatrixD()); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + expMtrx = SimpleEigenvalueCase.getOriginal().multiply(SimpleEigenvalueCase.getMatrixV()); actMtrx = SimpleEigenvalueCase.getMatrixV().multiply(SimpleEigenvalueCase.getMatrixD()); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); } @Test public void testProblem() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + final Eigenvalue tmpEigen = Eigenvalue.PRIMITIVE.make(); - tmpEigen.decompose(PrimitiveDenseStore.FACTORY.copy(SimpleEigenvalueCase.getOriginal())); + tmpEigen.decompose(Primitive64Store.FACTORY.copy(SimpleEigenvalueCase.getOriginal())); final MatrixStore tmpV = tmpEigen.getV(); final MatrixStore tmpD = tmpEigen.getD(); expMtrx = SimpleEigenvalueCase.getMatrixD(); - actMtrx = PrimitiveMatrix.FACTORY.copy(tmpD); + actMtrx = Primitive64Matrix.FACTORY.copy(tmpD); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); final RationalMatrix tmpExpV = SimpleEigenvalueCase.getMatrixV(); final RationalMatrix tmpActV = RationalMatrix.FACTORY.copy(tmpV); @@ -108,11 +114,11 @@ public void testProblem() { tmpExp = tmpMtrx.doubleValue(0, j); for (int i = 0; i < tmpMtrx.countRows(); i++) { tmpAct = tmpMtrx.doubleValue(i, j); - TestUtils.assertEquals(tmpExp, tmpAct, evaluation); + TestUtils.assertEquals(tmpExp, tmpAct, ACCURACY); } } - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/SimpleEquationCase.java b/test/org/ojalgo/matrix/SimpleEquationCase.java index be50489c6..715f49a23 100644 --- a/test/org/ojalgo/matrix/SimpleEquationCase.java +++ b/test/org/ojalgo/matrix/SimpleEquationCase.java @@ -48,18 +48,18 @@ public static RationalMatrix getSolution() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 9); + // ACCURACY = new NumberContext(7, 9); - rationalAA = SimpleEquationCase.getBody(); - rationalAX = SimpleEquationCase.getSolution(); - rationalAB = SimpleEquationCase.getRHS(); + rAA = SimpleEquationCase.getBody(); + rAX = SimpleEquationCase.getSolution(); + rAB = SimpleEquationCase.getRHS(); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } } diff --git a/test/org/ojalgo/matrix/SimpleLUCase.java b/test/org/ojalgo/matrix/SimpleLUCase.java index 10115616c..46e9c7739 100644 --- a/test/org/ojalgo/matrix/SimpleLUCase.java +++ b/test/org/ojalgo/matrix/SimpleLUCase.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.matrix.decomposition.LU; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.type.context.NumberContext; @@ -55,27 +55,30 @@ private static RationalMatrix getMtrxU() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 9); + // ACCURACY = new NumberContext(7, 9); - rationalAA = SimpleLUCase.getMtrxL(); - rationalAX = SimpleLUCase.getMtrxU(); - rationalAB = SimpleLUCase.getOrginal(); + rAA = SimpleLUCase.getMtrxL(); + rAX = SimpleLUCase.getMtrxU(); + rAB = SimpleLUCase.getOrginal(); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + expMtrx = SimpleLUCase.getOrginal(); actMtrx = SimpleLUCase.getMtrxL().multiply(SimpleLUCase.getMtrxU()); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); } @Test @@ -84,9 +87,9 @@ public void testProblem() { // PLDU final LU tmpLU = LU.RATIONAL.make(); - tmpLU.decompose(GenericDenseStore.RATIONAL.copy(SimpleLUCase.getOrginal())); + tmpLU.decompose(GenericStore.RATIONAL.copy(SimpleLUCase.getOrginal())); - TestUtils.assertEquals(GenericDenseStore.RATIONAL.copy(SimpleLUCase.getOrginal()), tmpLU, evaluation); + TestUtils.assertEquals(GenericStore.RATIONAL.copy(SimpleLUCase.getOrginal()), tmpLU, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/SimpleLeastSquaresCase.java b/test/org/ojalgo/matrix/SimpleLeastSquaresCase.java index 72526affa..4987bd7c0 100644 --- a/test/org/ojalgo/matrix/SimpleLeastSquaresCase.java +++ b/test/org/ojalgo/matrix/SimpleLeastSquaresCase.java @@ -65,38 +65,46 @@ private static RationalMatrix getTransformedRHS() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(4, 4); // TODO Something must be wrong here! + // ACCURACY = new NumberContext(4, 4); // TODO Something must be wrong here! - rationalAA = SimpleLeastSquaresCase.getFactorR(); - rationalAX = SimpleLeastSquaresCase.getSolution(); - rationalAB = SimpleLeastSquaresCase.getTransformedRHS(); + rAA = SimpleLeastSquaresCase.getFactorR(); + rAX = SimpleLeastSquaresCase.getSolution(); + rAB = SimpleLeastSquaresCase.getTransformedRHS(); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + + NumberContext accuracy = new NumberContext(4, 4); // TODO Something must be wrong here! + expMtrx = SimpleLeastSquaresCase.getTransformedRHS(); actMtrx = SimpleLeastSquaresCase.getFactorR().multiply(SimpleLeastSquaresCase.getSolution()); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, accuracy); } @Test public void testProblem() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + // Solve expMtrx = SimpleLeastSquaresCase.getSolution(); actMtrx = SimpleLeastSquaresCase.getBody().solve(SimpleLeastSquaresCase.getRHS()); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/SimpleQRCase.java b/test/org/ojalgo/matrix/SimpleQRCase.java index 743398fbf..22acd11df 100644 --- a/test/org/ojalgo/matrix/SimpleQRCase.java +++ b/test/org/ojalgo/matrix/SimpleQRCase.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.decomposition.QR; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.scalar.RationalNumber; import org.ojalgo.type.context.NumberContext; @@ -58,38 +58,44 @@ private static RationalMatrix getFactorR() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = evaluation.withScale(9).withPrecision(15); + // ACCURACY = ACCURACY.withScale(9).withPrecision(15); - rationalAA = SimpleQRCase.getFactorQ(); - rationalAX = SimpleQRCase.getFactorR(); - rationalAB = SimpleQRCase.getOriginal(); + rAA = SimpleQRCase.getFactorQ(); + rAX = SimpleQRCase.getFactorR(); + rAB = SimpleQRCase.getOriginal(); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), evaluation); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), evaluation); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), ACCURACY); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), ACCURACY); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + expMtrx = SimpleQRCase.getOriginal(); final RationalMatrix tmpFactorQ = SimpleQRCase.getFactorQ(); final RationalMatrix tmpFactorR = SimpleQRCase.getFactorR(); actMtrx = tmpFactorQ.multiply(tmpFactorR); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); } @Test public void testProblem() { + BasicMatrix actMtrx; + BasicMatrix expMtrx; + // QR final QR tmpQR = QR.RATIONAL.make(); - tmpQR.decompose(GenericDenseStore.RATIONAL.copy(SimpleQRCase.getOriginal())); + tmpQR.decompose(GenericStore.RATIONAL.copy(SimpleQRCase.getOriginal())); final MatrixStore tmpQ = tmpQR.getQ(); final MatrixStore tmpR = tmpQR.getR(); @@ -97,7 +103,7 @@ public void testProblem() { expMtrx = SimpleQRCase.getOriginal(); actMtrx = RationalMatrix.FACTORY.copy(tmpQ.multiply(tmpR)); - TestUtils.assertEquals(expMtrx, actMtrx, evaluation); + TestUtils.assertEquals(expMtrx, actMtrx, ACCURACY); // Q diff --git a/test/org/ojalgo/matrix/SimpleSingularValueCase.java b/test/org/ojalgo/matrix/SimpleSingularValueCase.java index c2014d815..084b2c39f 100644 --- a/test/org/ojalgo/matrix/SimpleSingularValueCase.java +++ b/test/org/ojalgo/matrix/SimpleSingularValueCase.java @@ -27,7 +27,7 @@ import org.ojalgo.matrix.decomposition.SingularValue; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; /** @@ -61,42 +61,42 @@ private static RationalMatrix getMatrixQ2() { @Override @BeforeEach - public void setUp() { + public void doBeforeEach() { - evaluation = new NumberContext(7, 9); + // ACCURACY = new NumberContext(7, 9); - rationalAA = SimpleSingularValueCase.getMatrixQ1(); - rationalAX = SimpleSingularValueCase.getMatrixD(); - rationalAB = SimpleSingularValueCase.getOriginal(); + rAA = SimpleSingularValueCase.getMatrixQ1(); + rAX = SimpleSingularValueCase.getMatrixD(); + rAB = SimpleSingularValueCase.getOriginal(); - rationlI = BasicMatrixTest.getIdentity(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); - rationalSafe = BasicMatrixTest.getSafe(rationalAA.countRows(), rationalAA.countColumns(), DEFINITION); + rI = BasicMatrixTest.getIdentity(rAA.countRows(), rAA.countColumns(), DEFINITION); + rSafe = BasicMatrixTest.getSafe(rAA.countRows(), rAA.countColumns(), DEFINITION); - super.setUp(); + super.doBeforeEach(); } @Test public void testData() { - final PhysicalStore tmpExp = PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getOriginal()) - .multiply(PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getMatrixQ2())).copy(); + final PhysicalStore tmpExp = Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getOriginal()) + .multiply(Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getMatrixQ2())).copy(); - final PhysicalStore tmpAct = PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getMatrixQ1()) - .multiply(PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getMatrixD())).copy(); + final PhysicalStore tmpAct = Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getMatrixQ1()) + .multiply(Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getMatrixD())).copy(); - TestUtils.assertEquals(tmpExp, tmpAct, evaluation); + TestUtils.assertEquals(tmpExp, tmpAct, ACCURACY); } @Test public void testProblem() { - final MatrixStore tmpA = PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getOriginal()); + final MatrixStore tmpA = Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getOriginal()); final SingularValue tmpSVD = SingularValue.make(tmpA); tmpSVD.decompose(tmpA); //tmpSVD.equals(tmpA, EVALUATION); - TestUtils.assertEquals(tmpA, tmpSVD, evaluation); + TestUtils.assertEquals(tmpA, tmpSVD, ACCURACY); } } diff --git a/test/org/ojalgo/matrix/SpecialTest.java b/test/org/ojalgo/matrix/SpecialTest.java new file mode 100644 index 000000000..a7e8587d9 --- /dev/null +++ b/test/org/ojalgo/matrix/SpecialTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.matrix; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; + +public class SpecialTest extends MatrixTests { + + @Test + public void testDenseReceiver() { + + RationalMatrix.DenseReceiver rDR = RationalMatrix.FACTORY.makeDense(5, 7); + Primitive32Matrix.DenseReceiver p32DR = Primitive32Matrix.FACTORY.makeDense(5, 7); + + rDR.set(1, 1, 1D); + p32DR.set(1, 1, 1D); + + rDR.set(3, 5, 1D); + p32DR.set(3, 5, 1D); + + rDR.set(4, 2, 1D); + p32DR.set(4, 2, 1D); + + TestUtils.assertEquals(rDR.build(), p32DR.build()); + } + + @Test + public void testSparseReceiver() { + + RationalMatrix.SparseReceiver rSR = RationalMatrix.FACTORY.makeSparse(5, 7); + Primitive32Matrix.SparseReceiver p32SR = Primitive32Matrix.FACTORY.makeSparse(5, 7); + + rSR.set(1, 1, 1D); + p32SR.set(1, 1, 1D); + + rSR.set(3, 5, 1D); + p32SR.set(3, 5, 1D); + + rSR.set(4, 2, 1D); + p32SR.set(4, 2, 1D); + + TestUtils.assertEquals(rSR.build(), p32SR.build()); + } + +} diff --git a/test/org/ojalgo/matrix/decomposition/CaseBidiagonal.java b/test/org/ojalgo/matrix/decomposition/CaseBidiagonal.java index f85c6465e..88ea0d4d6 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseBidiagonal.java +++ b/test/org/ojalgo/matrix/decomposition/CaseBidiagonal.java @@ -25,7 +25,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.structure.Access2D; @@ -39,7 +39,7 @@ public class CaseBidiagonal extends MatrixDecompositionTests { @Test public void testCaseFromMatrixComputations() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.rows(new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }); this.doTestCorrect(tmpMatrix); } @@ -79,7 +79,7 @@ public void testComplexSquareCase() { @Test public void testFatEye() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.makeEye(4, 6); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.makeEye(4, 6); this.doTestCorrect(tmpMatrix); } @@ -87,7 +87,7 @@ public void testFatEye() { @Test public void testFatRandom() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(4, 6)); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(4, 6)); this.doTestCorrect(tmpMatrix); } @@ -95,7 +95,7 @@ public void testFatRandom() { @Test public void testSquareBidiagonal() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY .rows(new double[][] { { 1, 4, 0, 0 }, { 0, 4, 1, 0 }, { 0, 0, 3, 4 }, { 0, 0, 0, 3 } }); this.doTestCorrect(tmpMatrix); @@ -104,7 +104,7 @@ public void testSquareBidiagonal() { @Test public void testSquareEye() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.makeEye(5, 5); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.makeEye(5, 5); this.doTestCorrect(tmpMatrix); } @@ -112,7 +112,7 @@ public void testSquareEye() { @Test public void testSquareRandom() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(5, 5)); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(5, 5)); this.doTestCorrect(tmpMatrix); } @@ -120,7 +120,7 @@ public void testSquareRandom() { @Test public void testTallEye() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.makeEye(6, 4); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.makeEye(6, 4); this.doTestCorrect(tmpMatrix); } @@ -128,7 +128,7 @@ public void testTallEye() { @Test public void testTallRandom() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(6, 4)); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(6, 4)); this.doTestCorrect(tmpMatrix); } @@ -167,8 +167,8 @@ private void doTestCorrect(final PhysicalStore aMatrix) { TestUtils.assertEquals(aMatrix, tmpDecomposition, new NumberContext(7, 6)); } - private PrimitiveDenseStore makeEye(final int aRowDim, final int aColDim) { - return PrimitiveDenseStore.FACTORY.makeEye(aRowDim, aColDim); + private Primitive64Store makeEye(final int aRowDim, final int aColDim) { + return Primitive64Store.FACTORY.makeEye(aRowDim, aColDim); } } diff --git a/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java b/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java index 580dcf581..6103cc781 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java +++ b/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java @@ -39,10 +39,10 @@ import org.ojalgo.matrix.P20061119Case; import org.ojalgo.matrix.decomposition.Eigenvalue.Generalisation; import org.ojalgo.matrix.store.DiagonalStore; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.task.SolverTask; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.ComplexNumber; @@ -71,7 +71,7 @@ public void minimiseAllBranchLimits() { @Test public void testP20050125Case() { - PhysicalStore tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.copy(P20050125Case.getProblematic()); + PhysicalStore tmpOriginalMatrix = Primitive64Store.FACTORY.copy(P20050125Case.getProblematic()); TestUtils.assertTrue(tmpOriginalMatrix.isHermitian()); @@ -89,12 +89,12 @@ public void testP20050125Case() { BasicLogger.debug("D"); for (Eigenvalue tmpDecomp : tmpDecomps) { - BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + PrimitiveDenseStore.FACTORY.copy(tmpDecomp.getD())); + BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + Primitive64Store.FACTORY.copy(tmpDecomp.getD())); } BasicLogger.debug("V"); for (Eigenvalue tmpDecomp : tmpDecomps) { - BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + PrimitiveDenseStore.FACTORY.copy(tmpDecomp.getV())); + BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + Primitive64Store.FACTORY.copy(tmpDecomp.getV())); } } @@ -106,7 +106,7 @@ public void testP20050125Case() { @Test public void testP20061119Case() { - PhysicalStore tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.copy(P20061119Case.getProblematic()); + PhysicalStore tmpOriginalMatrix = Primitive64Store.FACTORY.copy(P20061119Case.getProblematic()); ComplexNumber tmp00 = ComplexNumber.valueOf(26.14421883828456); ComplexNumber tmp11 = ComplexNumber.of(2.727890580857718, 3.6223578444417908); @@ -152,7 +152,7 @@ public void testP20061119Case() { public void testPaulsMathNote() { double[][] tmpData = new double[][] { { 3, -9 }, { 4, -3 } }; - PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData); + Primitive64Store tmpA = Primitive64Store.FACTORY.rows(tmpData); int tmpLength = tmpData.length; Array1D tmpExpVals = Array1D.COMPLEX.makeZero(2); @@ -184,15 +184,15 @@ public void testPaulsMathNote() { TestUtils.assertEquals(tmpSliceColumn.get(1).multiply(tmpFactor), tmpActual.get(1)); } - GenericDenseStore tmpCmplA = GenericDenseStore.COMPLEX.copy(tmpA); - GenericDenseStore tmpCmplD = GenericDenseStore.COMPLEX.copy(tmpD); - GenericDenseStore tmpCmplV = GenericDenseStore.COMPLEX.copy(tmpV); + GenericStore tmpCmplA = GenericStore.COMPLEX.copy(tmpA); + GenericStore tmpCmplD = GenericStore.COMPLEX.copy(tmpD); + GenericStore tmpCmplV = GenericStore.COMPLEX.copy(tmpV); MatrixStore tmpExp1 = tmpCmplA.multiply(tmpCmplV); MatrixStore tmpAct1 = tmpCmplV.multiply(tmpCmplD); TestUtils.assertEquals(tmpExp1, tmpAct1); - GenericDenseStore tmpComplexD = GenericDenseStore.COMPLEX.makeZero(tmpLength, tmpLength); + GenericStore tmpComplexD = GenericStore.COMPLEX.makeZero(tmpLength, tmpLength); for (int j = 0; j < tmpLength; j++) { tmpComplexD.set(j, j, tmpValues.get(j)); } @@ -211,7 +211,7 @@ public void testPaulsMathNote() { public void testPrimitiveAsComplex() { double[][] tmpData = new double[][] { { 1, 0, 3 }, { 0, 4, 1 }, { -5, 1, 0 } }; - PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData); + Primitive64Store tmpA = Primitive64Store.FACTORY.rows(tmpData); int tmpLength = tmpData.length; @@ -225,15 +225,15 @@ public void testPrimitiveAsComplex() { Array1D tmpValues = tmpEvD.getEigenvalues(); MatrixStore tmpVectors = tmpEvD.getEigenvectors(); - GenericDenseStore tmpCmplA = GenericDenseStore.COMPLEX.copy(tmpA); - GenericDenseStore tmpCmplD = GenericDenseStore.COMPLEX.copy(tmpD); - GenericDenseStore tmpCmplV = GenericDenseStore.COMPLEX.copy(tmpV); + GenericStore tmpCmplA = GenericStore.COMPLEX.copy(tmpA); + GenericStore tmpCmplD = GenericStore.COMPLEX.copy(tmpD); + GenericStore tmpCmplV = GenericStore.COMPLEX.copy(tmpV); MatrixStore tmpExp1 = tmpCmplA.multiply(tmpCmplV); MatrixStore tmpAct1 = tmpCmplV.multiply(tmpCmplD); TestUtils.assertEquals(tmpExp1, tmpAct1); - GenericDenseStore tmpAltD = GenericDenseStore.COMPLEX.makeZero(tmpLength, tmpLength); + GenericStore tmpAltD = GenericStore.COMPLEX.makeZero(tmpLength, tmpLength); MatrixStore tmpAltV = tmpVectors; for (int j = 0; j < tmpLength; j++) { @@ -255,7 +255,7 @@ public void testPrimitiveAsComplex() { @Test public void testProblemFoundInTheWild() { - PrimitiveDenseStore matrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, 0, 0 }, { 0.01, 0, -1 }, { 0.01, 1, 0 } }); + Primitive64Store matrix = Primitive64Store.FACTORY.rows(new double[][] { { 1, 0, 0 }, { 0.01, 0, -1 }, { 0.01, 1, 0 } }); for (Eigenvalue tmpEigenvalue : MatrixDecompositionTests.getPrimitiveEigenvalueGeneral()) { @@ -279,8 +279,8 @@ public void testRandomGeneralisedA_B() throws RecoverableCondition { for (int dim = 2; dim < 10; dim++) { - PrimitiveDenseStore mtrxA = PrimitiveDenseStore.FACTORY.makeSPD(dim); - PrimitiveDenseStore mtrxB = PrimitiveDenseStore.FACTORY.makeSPD(dim); + Primitive64Store mtrxA = Primitive64Store.FACTORY.makeSPD(dim); + Primitive64Store mtrxB = Primitive64Store.FACTORY.makeSPD(dim); Cholesky cholesky = Cholesky.PRIMITIVE.make(mtrxB); cholesky.decompose(mtrxB); @@ -326,8 +326,8 @@ public void testRandomGeneralisedAB() throws RecoverableCondition { for (int dim = 2; dim < 10; dim++) { - PrimitiveDenseStore mtrxA = PrimitiveDenseStore.FACTORY.makeSPD(dim); - PrimitiveDenseStore mtrxB = PrimitiveDenseStore.FACTORY.makeSPD(dim); + Primitive64Store mtrxA = Primitive64Store.FACTORY.makeSPD(dim); + Primitive64Store mtrxB = Primitive64Store.FACTORY.makeSPD(dim); Cholesky cholesky = Cholesky.PRIMITIVE.make(mtrxB); cholesky.decompose(mtrxB); @@ -377,8 +377,8 @@ public void testRandomGeneralisedBA() throws RecoverableCondition { for (int dim = 2; dim < 10; dim++) { - PrimitiveDenseStore mtrxA = PrimitiveDenseStore.FACTORY.makeSPD(dim); - PrimitiveDenseStore mtrxB = PrimitiveDenseStore.FACTORY.makeSPD(dim); + Primitive64Store mtrxA = Primitive64Store.FACTORY.makeSPD(dim); + Primitive64Store mtrxB = Primitive64Store.FACTORY.makeSPD(dim); Cholesky cholesky = Cholesky.PRIMITIVE.make(mtrxB); cholesky.decompose(mtrxB); @@ -424,7 +424,7 @@ public void testRandomGeneralisedUnprepared() throws RecoverableCondition { for (int dim = 2; dim < 10; dim++) { - PrimitiveDenseStore mtrxA = PrimitiveDenseStore.FACTORY.makeSPD(dim); + Primitive64Store mtrxA = Primitive64Store.FACTORY.makeSPD(dim); Eigenvalue eigenvalue = Eigenvalue.PRIMITIVE.make(mtrxA, true); eigenvalue.decompose(mtrxA); @@ -447,7 +447,7 @@ public void testRandomSymmetricValuesOnly() { for (int dim = 1; dim < 10; dim++) { - PrimitiveDenseStore matrix = MatrixUtils.makeSPD(dim); + Primitive64Store matrix = MatrixUtils.makeSPD(dim); for (Eigenvalue decomp : MatrixDecompositionTests.getPrimitiveEigenvalueSymmetric()) { diff --git a/test/org/ojalgo/matrix/decomposition/CaseHessenberg.java b/test/org/ojalgo/matrix/decomposition/CaseHessenberg.java index ddc46ea3e..7a6dbd024 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseHessenberg.java +++ b/test/org/ojalgo/matrix/decomposition/CaseHessenberg.java @@ -26,7 +26,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.structure.Access2D; import org.ojalgo.type.context.NumberContext; @@ -45,7 +45,7 @@ public void minimiseAllBranchLimits() { @Test public void testSquareEye() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.makeEye(5, 5); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.makeEye(5, 5); this.doTestCorrect(tmpMatrix); } @@ -53,7 +53,7 @@ public void testSquareEye() { @Test public void testSquareRandom() { - final PhysicalStore tmpMatrix = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(5, 5)); + final PhysicalStore tmpMatrix = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(5, 5)); this.doTestCorrect(tmpMatrix); } @@ -94,8 +94,8 @@ private void doTestCorrect(final PhysicalStore aMatrix) { TestUtils.assertEquals(aMatrix, tmpDecomposition, new NumberContext(7, 6)); } - private PrimitiveDenseStore makeEye(final int aRowDim, final int aColDim) { - return PrimitiveDenseStore.FACTORY.makeEye(aRowDim, aColDim); + private Primitive64Store makeEye(final int aRowDim, final int aColDim) { + return Primitive64Store.FACTORY.makeEye(aRowDim, aColDim); } } diff --git a/test/org/ojalgo/matrix/decomposition/CaseLDL.java b/test/org/ojalgo/matrix/decomposition/CaseLDL.java index 67793be4e..030e8a5f0 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseLDL.java +++ b/test/org/ojalgo/matrix/decomposition/CaseLDL.java @@ -88,7 +88,7 @@ public void testWikipediaCasePrePivoted() { private void doTest(final MatrixStore mtrxA, final RawStore mtrxL, final RawStore mtrxD) { - MatrixStore mtrxIdentity = MatrixStore.PRIMITIVE.makeIdentity((int) mtrxA.countRows()).get(); + MatrixStore mtrxIdentity = MatrixStore.PRIMITIVE64.makeIdentity((int) mtrxA.countRows()).get(); RawStore reconstructed = mtrxL.multiply(mtrxD.multiply(mtrxL.transpose())); TestUtils.assertEquals(mtrxA, reconstructed); diff --git a/test/org/ojalgo/matrix/decomposition/CaseLU.java b/test/org/ojalgo/matrix/decomposition/CaseLU.java index 7da836888..94a582fa7 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseLU.java +++ b/test/org/ojalgo/matrix/decomposition/CaseLU.java @@ -26,8 +26,8 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.P20061119Case; import org.ojalgo.matrix.RationalMatrix; -import org.ojalgo.matrix.store.GenericDenseStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.GenericStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; @@ -50,16 +50,16 @@ public void testP20061119Case() { final RationalMatrix tmpProblematic = P20061119Case.getProblematic(); final LU tmpBig = LU.RATIONAL.make(); - tmpBig.decompose(GenericDenseStore.RATIONAL.copy(tmpProblematic)); + tmpBig.decompose(GenericStore.RATIONAL.copy(tmpProblematic)); final LU tmpComplex = LU.COMPLEX.make(); - tmpComplex.decompose(GenericDenseStore.COMPLEX.copy(tmpProblematic)); + tmpComplex.decompose(GenericStore.COMPLEX.copy(tmpProblematic)); final LU tmpPrimitive = LU.PRIMITIVE.make(); - tmpPrimitive.decompose(PrimitiveDenseStore.FACTORY.copy(tmpProblematic)); + tmpPrimitive.decompose(Primitive64Store.FACTORY.copy(tmpProblematic)); final LU tmpJama = new RawLU(); - tmpJama.decompose(PrimitiveDenseStore.FACTORY.copy(tmpProblematic)); + tmpJama.decompose(Primitive64Store.FACTORY.copy(tmpProblematic)); final NumberContext tmpPrintContext = NumberContext.getGeneral(20); @@ -78,7 +78,7 @@ public void testP20061119Case() { } final SingularValue tmpSVD = new RawSingularValue(); - tmpSVD.decompose(PrimitiveDenseStore.FACTORY.copy(tmpProblematic)); + tmpSVD.decompose(Primitive64Store.FACTORY.copy(tmpProblematic)); TestUtils.assertEquals("LU.rank SVD vs Big", tmpSVD.getRank(), tmpBig.getRank()); TestUtils.assertEquals("LU.rank SVD vs Complex", tmpSVD.getRank(), tmpComplex.getRank()); diff --git a/test/org/ojalgo/matrix/decomposition/CaseQR.java b/test/org/ojalgo/matrix/decomposition/CaseQR.java index d131efc7a..2c6c6355c 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseQR.java +++ b/test/org/ojalgo/matrix/decomposition/CaseQR.java @@ -29,10 +29,10 @@ import org.ojalgo.matrix.MatrixUtils; import org.ojalgo.matrix.P20030422Case; import org.ojalgo.matrix.RationalMatrix; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.transformation.Householder; import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.ComplexNumber; @@ -64,7 +64,7 @@ public void minimiseAllBranchLimits() { @Test public void testDiagonalCase() { - final PhysicalStore tmpOriginalMatrix = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpOriginalMatrix = Primitive64Store.FACTORY .rows(new double[][] { { 4.0, 3.0, 2.0, 1.0 }, { 0.0, 3.0, 2.0, 1.0 }, { 0.0, 0.0, 2.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 } }); final QR tmpDecomp = QR.PRIMITIVE.make(); @@ -96,15 +96,15 @@ public void testHermitian() { final MatrixStore tmpDecompQ = tmpDecomposition.getQ(); final MatrixStore tmpDecompR = tmpDecomposition.getR(); - final DecompositionStore tmpInPlace = GenericDenseStore.COMPLEX.copy(tmpOriginal); + final DecompositionStore tmpInPlace = GenericStore.COMPLEX.copy(tmpOriginal); - final DecompositionStore tmpNowQ = GenericDenseStore.COMPLEX.makeEye(DIMENSION, DIMENSION); - final DecompositionStore tmpNowR = GenericDenseStore.COMPLEX.copy(tmpOriginal); + final DecompositionStore tmpNowQ = GenericStore.COMPLEX.makeEye(DIMENSION, DIMENSION); + final DecompositionStore tmpNowR = GenericStore.COMPLEX.copy(tmpOriginal); - final DecompositionStore tmpForwardQ = GenericDenseStore.COMPLEX.makeEye(DIMENSION, DIMENSION); - final DecompositionStore tmpForwardR = GenericDenseStore.COMPLEX.copy(tmpOriginal); + final DecompositionStore tmpForwardQ = GenericStore.COMPLEX.makeEye(DIMENSION, DIMENSION); + final DecompositionStore tmpForwardR = GenericStore.COMPLEX.copy(tmpOriginal); - final DecompositionStore tmpReverseQ = GenericDenseStore.COMPLEX.makeEye(DIMENSION, DIMENSION); + final DecompositionStore tmpReverseQ = GenericStore.COMPLEX.makeEye(DIMENSION, DIMENSION); final Householder.Generic[] tmpHouseholders = new Householder.Generic[tmpLim]; @@ -164,7 +164,7 @@ public void testLeastSquaresInvert() { ArrayOperation.setThresholdsMinValue(100000); final int tmpDim = 3; - final MatrixStore tmpA = MatrixUtils.makeSPD(tmpDim).logical().below(MatrixStore.PRIMITIVE.makeIdentity(tmpDim).get()).get(); + final MatrixStore tmpA = MatrixUtils.makeSPD(tmpDim).logical().below(MatrixStore.PRIMITIVE64.makeIdentity(tmpDim).get()).get(); final QR tmpDenseQR = new QRDecomposition.Primitive(); final QR tmpRawQR = new RawQR(); @@ -179,7 +179,7 @@ public void testLeastSquaresInvert() { TestUtils.assertEquals(tmpDenseInv, tmpRawInv); - final MatrixStore tmpIdentity = MatrixStore.PRIMITIVE.makeIdentity(tmpDim).get(); + final MatrixStore tmpIdentity = MatrixStore.PRIMITIVE64.makeIdentity(tmpDim).get(); TestUtils.assertEquals(tmpIdentity, tmpDenseInv.multiply(tmpA)); TestUtils.assertEquals(tmpIdentity, tmpRawInv.multiply(tmpA)); @@ -199,9 +199,9 @@ public void testP20030422Case() { final QR tmpComplexDecomp = QR.COMPLEX.make(); final QR tmpPrimitiveDecomp = QR.PRIMITIVE.make(); - tmpBigDecomp.decompose(GenericDenseStore.RATIONAL.copy(tmpOriginal)); - tmpComplexDecomp.decompose(GenericDenseStore.COMPLEX.copy(tmpOriginal)); - tmpPrimitiveDecomp.decompose(PrimitiveDenseStore.FACTORY.copy(tmpOriginal)); + tmpBigDecomp.decompose(GenericStore.RATIONAL.copy(tmpOriginal)); + tmpComplexDecomp.decompose(GenericStore.COMPLEX.copy(tmpOriginal)); + tmpPrimitiveDecomp.decompose(Primitive64Store.FACTORY.copy(tmpOriginal)); final MatrixStore tmpBigQ = tmpBigDecomp.getQ(); final MatrixStore tmpComplexQ = tmpComplexDecomp.getQ(); @@ -223,9 +223,9 @@ public void testP20030422Case() { BasicLogger.debug("Primitive R", tmpPrimitiveR); } - TestUtils.assertEquals(GenericDenseStore.RATIONAL.copy(tmpOriginal), tmpBigDecomp, new NumberContext(7, 14)); - TestUtils.assertEquals(GenericDenseStore.COMPLEX.copy(tmpOriginal), tmpComplexDecomp, new NumberContext(7, 14)); - TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(tmpOriginal), tmpPrimitiveDecomp, new NumberContext(7, 14)); + TestUtils.assertEquals(GenericStore.RATIONAL.copy(tmpOriginal), tmpBigDecomp, new NumberContext(7, 14)); + TestUtils.assertEquals(GenericStore.COMPLEX.copy(tmpOriginal), tmpComplexDecomp, new NumberContext(7, 14)); + TestUtils.assertEquals(Primitive64Store.FACTORY.copy(tmpOriginal), tmpPrimitiveDecomp, new NumberContext(7, 14)); } } diff --git a/test/org/ojalgo/matrix/decomposition/CaseSingularValue.java b/test/org/ojalgo/matrix/decomposition/CaseSingularValue.java index 2ee956041..e2748dae4 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseSingularValue.java +++ b/test/org/ojalgo/matrix/decomposition/CaseSingularValue.java @@ -37,10 +37,10 @@ import org.ojalgo.matrix.P20061119Case; import org.ojalgo.matrix.P20071019Case; import org.ojalgo.matrix.RationalMatrix; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.random.Normal; import org.ojalgo.scalar.ComplexNumber; @@ -116,7 +116,7 @@ public void testBasicMatrixP20071019TallCase() { @Test public void testComplexNumberVersionOfWikipediaCase() { - PhysicalStore tmpBaseMtrx = PrimitiveDenseStore.FACTORY + PhysicalStore tmpBaseMtrx = Primitive64Store.FACTORY .rows(new double[][] { { 1.0, 0.0, 0.0, 0.0, 2.0 }, { 0.0, 0.0, 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 4.0, 0.0, 0.0, 0.0 } }); Array1D tmpExpectedSingularValues = Array1D.PRIMITIVE64.copy(new double[] { 4.0, 3.0, PrimitiveMath.SQRT.invoke(5.0), 0.0 }); @@ -130,7 +130,7 @@ public void testComplexNumberVersionOfWikipediaCase() { for (ComplexNumber tmpScale : tmpScales) { - PhysicalStore tmpOriginalMtrx = GenericDenseStore.COMPLEX.transpose(tmpBaseMtrx); + PhysicalStore tmpOriginalMtrx = GenericStore.COMPLEX.transpose(tmpBaseMtrx); tmpOriginalMtrx.modifyAll(ComplexMath.MULTIPLY.first(tmpScale)); tmpBidiagonal.decompose(tmpOriginalMtrx); @@ -154,7 +154,7 @@ public void testComplexNumberVersionOfWikipediaCase() { BasicLogger.debug("Scale = {}", tmpScale); } - PhysicalStore tmpOriginalMtrx = GenericDenseStore.COMPLEX.copy(tmpBaseMtrx); + PhysicalStore tmpOriginalMtrx = GenericStore.COMPLEX.copy(tmpBaseMtrx); tmpOriginalMtrx.modifyAll(ComplexMath.MULTIPLY.first(tmpScale)); tmpBidiagonal.decompose(tmpOriginalMtrx.conjugate()); @@ -180,7 +180,7 @@ public void testComplexNumberVersionOfWikipediaCase() { @Test public void testGetCovariance() { - PrimitiveDenseStore original = PrimitiveDenseStore.FACTORY.makeFilled(9, 3, new Normal()); + Primitive64Store original = Primitive64Store.FACTORY.makeFilled(9, 3, new Normal()); for (SingularValue decomp : MatrixDecompositionTests.getPrimitiveSingularValue()) { @@ -213,13 +213,13 @@ public void testPseudoinverseSolve() { { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0 } }; - PrimitiveDenseStore body = PrimitiveDenseStore.FACTORY.rows(olsColumns); + Primitive64Store body = Primitive64Store.FACTORY.rows(olsColumns); double[] observationVector = { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - PrimitiveDenseStore rhs = PrimitiveDenseStore.FACTORY.column(observationVector); + Primitive64Store rhs = Primitive64Store.FACTORY.column(observationVector); double expected = 0.0161290322580645; MatrixStore actual; @@ -317,7 +317,7 @@ public void testRandomTallCase() { @Test public void testRecreationFat() { - PhysicalStore tmpOriginal = PrimitiveDenseStore.FACTORY.copy(MTRX_FAT); + PhysicalStore tmpOriginal = Primitive64Store.FACTORY.copy(MTRX_FAT); this.testRecreation(tmpOriginal); } @@ -325,7 +325,7 @@ public void testRecreationFat() { @Test public void testRecreationSquare() { - PhysicalStore tmpOriginal = PrimitiveDenseStore.FACTORY.copy(MTRX_SQUARE); + PhysicalStore tmpOriginal = Primitive64Store.FACTORY.copy(MTRX_SQUARE); this.testRecreation(tmpOriginal); } @@ -333,21 +333,21 @@ public void testRecreationSquare() { @Test public void testRecreationTall() { - PhysicalStore tmpOriginal = PrimitiveDenseStore.FACTORY.copy(MTRX_TALL); + PhysicalStore tmpOriginal = Primitive64Store.FACTORY.copy(MTRX_TALL); this.testRecreation(tmpOriginal); } private void doTestTypes(final RationalMatrix original) { - PhysicalStore tmpBigStore = GenericDenseStore.RATIONAL.copy(original); - PhysicalStore tmpComplexStore = GenericDenseStore.COMPLEX.copy(original); - PhysicalStore tmpPrimitiveStore = PrimitiveDenseStore.FACTORY.copy(original); + PhysicalStore tmpBigStore = GenericStore.RATIONAL.copy(original); + PhysicalStore tmpComplexStore = GenericStore.COMPLEX.copy(original); + PhysicalStore tmpPrimitiveStore = Primitive64Store.FACTORY.copy(original); - IMPL_BIG.decompose(GenericDenseStore.RATIONAL.copy(original)); - IMPL_COMPLEX.decompose(GenericDenseStore.COMPLEX.copy(original)); - IMPL_RAW.decompose(PrimitiveDenseStore.FACTORY.copy(original)); - IMPL_PRIMITIVE.decompose(PrimitiveDenseStore.FACTORY.copy(original)); + IMPL_BIG.decompose(GenericStore.RATIONAL.copy(original)); + IMPL_COMPLEX.decompose(GenericStore.COMPLEX.copy(original)); + IMPL_RAW.decompose(Primitive64Store.FACTORY.copy(original)); + IMPL_PRIMITIVE.decompose(Primitive64Store.FACTORY.copy(original)); Array1D tmpBigSingularValues = IMPL_BIG.getSingularValues(); Array1D tmpComplexSingularValues = IMPL_COMPLEX.getSingularValues(); diff --git a/test/org/ojalgo/matrix/decomposition/CaseTridiagonal.java b/test/org/ojalgo/matrix/decomposition/CaseTridiagonal.java index cac54e154..d84071c39 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseTridiagonal.java +++ b/test/org/ojalgo/matrix/decomposition/CaseTridiagonal.java @@ -25,11 +25,11 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.matrix.PrimitiveMatrix; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.Primitive64Matrix; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.random.Normal; import org.ojalgo.scalar.ComplexNumber; @@ -55,9 +55,9 @@ public void minimiseAllBranchLimits() { @Test public void testFullertonExample1and2() { - final PhysicalStore tmpMtrxA = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMtrxA = Primitive64Store.FACTORY .rows(new double[][] { { 4.0, 2.0, 2.0, 1.0 }, { 2.0, -3.0, 1.0, 1.0 }, { 2.0, 1.0, 3.0, 1.0 }, { 1.0, 1.0, 1.0, 2.0 } }); - final PhysicalStore tmpMtrxD = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMtrxD = Primitive64Store.FACTORY .rows(new double[][] { { 4.0, -3.0, 0.0, 0.0 }, { -3.0, 2.0, 3.16227766, 0.0 }, { 0.0, 3.16227766, -1.4, -0.2 }, { 0.0, 0.0, -0.2, 1.4 } }); this.doTheTest(tmpMtrxA, tmpMtrxD); @@ -70,9 +70,9 @@ public void testFullertonExample1and2() { @Test public void testFullertonExercise3() { - final PhysicalStore tmpMtrxA = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5.0, 1.0, 2.0, 2.0, 4.0 }, { 1.0, 1.0, 2.0, 1.0, 0.0 }, + final PhysicalStore tmpMtrxA = Primitive64Store.FACTORY.rows(new double[][] { { 5.0, 1.0, 2.0, 2.0, 4.0 }, { 1.0, 1.0, 2.0, 1.0, 0.0 }, { 2.0, 2.0, 0.0, 2.0, 1.0 }, { 2.0, 1.0, 2.0, 1.0, 2.0 }, { 4.0, 0.0, 1.0, 2.0, 4.0 } }); - final PhysicalStore tmpMtrxD = PrimitiveDenseStore.FACTORY.rows( + final PhysicalStore tmpMtrxD = Primitive64Store.FACTORY.rows( new double[][] { { 5.0, -5.0, 0.0, 0.0, 0.0 }, { -5.0, 5.8, -0.8246211251, 0.0, 0.0 }, { 0.0, -0.8246211251, -0.8823529412, -1.577874704, 0.0 }, { 0.0, 0.0, -1.577874704, 1.373213515, 1.279015421 }, { 0.0, 0.0, 0.0, 1.279015421, -0.2908605737 } }); @@ -87,10 +87,10 @@ public void testFullertonExercise3() { @Test public void testFullertonExercise4and5() { - final PhysicalStore tmpMtrxA = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMtrxA = Primitive64Store.FACTORY .rows(new double[][] { { 4.0, 1.0, 2.0, -5.0, 1.0, 4.0 }, { 1.0, 2.0, 0.0, 4.0, 5.0, 3.0 }, { 2.0, 0.0, 3.0, -1.0, 2.0, 1.0 }, { -5.0, 4.0, -1.0, 1.0, 5.0, 2.0 }, { 1.0, 5.0, 2.0, 5.0, -2.0, 4.0 }, { 4.0, 3.0, 1.0, 2.0, 4.0, 1.0 } }); - final PhysicalStore tmpMtrxD = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMtrxD = Primitive64Store.FACTORY .rows(new double[][] { { 4.0, -6.8556546, 0.0, 0.0, 0.0, 0.0 }, { -6.8556546, -0.1489361702, 2.924429193, 0.0, 0.0, 0.0 }, { 0.0, 2.924429193, 1.268510593, 4.758239905, 0.0, 0.0 }, { 0.0, 0.0, 4.758239905, 2.664908905, -7.994421195, 0.0 }, { 0.0, 0.0, 0.0, -7.994421195, 3.358186868, 1.759360415 }, { 0.0, 0.0, 0.0, 0.0, 1.759360415, -2.142670196 } }); @@ -102,12 +102,12 @@ public void testFullertonExercise4and5() { @Tag("unstable") public void testTypesWithRandom() { - PrimitiveMatrix tmpSymmetricRandoml = PrimitiveMatrix.FACTORY.makeFilled(9, 9, new Normal()); + Primitive64Matrix tmpSymmetricRandoml = Primitive64Matrix.FACTORY.makeFilled(9, 9, new Normal()); tmpSymmetricRandoml = tmpSymmetricRandoml.add(tmpSymmetricRandoml.transpose()); - final MatrixStore primitiveA = PrimitiveDenseStore.FACTORY.copy(tmpSymmetricRandoml); - final MatrixStore complexA = GenericDenseStore.COMPLEX.copy(tmpSymmetricRandoml); - final MatrixStore rationalA = GenericDenseStore.RATIONAL.copy(tmpSymmetricRandoml); + final MatrixStore primitiveA = Primitive64Store.FACTORY.copy(tmpSymmetricRandoml); + final MatrixStore complexA = GenericStore.COMPLEX.copy(tmpSymmetricRandoml); + final MatrixStore rationalA = GenericStore.RATIONAL.copy(tmpSymmetricRandoml); final Tridiagonal primitiveDecomp = Tridiagonal.PRIMITIVE.make(); final Tridiagonal complexDecomp = Tridiagonal.COMPLEX.make(); @@ -150,9 +150,9 @@ public void testTypesWithRandom() { @Test public void testWikipediaExample() { - final PhysicalStore tmpMtrxA = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMtrxA = Primitive64Store.FACTORY .rows(new double[][] { { 4.0, 1.0, -2.0, 2.0 }, { 1.0, 2.0, 0.0, 1.0 }, { -2.0, 0.0, 3.0, -2.0 }, { 2.0, 1.0, -2.0, -1.0 } }); - final PhysicalStore tmpMtrxD = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0, -3.0, 0.0, 0.0 }, { -3.0, 10.0 / 3.0, -5.0 / 3.0, 0.0 }, + final PhysicalStore tmpMtrxD = Primitive64Store.FACTORY.rows(new double[][] { { 4.0, -3.0, 0.0, 0.0 }, { -3.0, 10.0 / 3.0, -5.0 / 3.0, 0.0 }, { 0.0, -5.0 / 3.0, -33.0 / 25.0, 68.0 / 75.0 }, { 0.0, 0.0, 68.0 / 75.0, 149.0 / 75.0 } }); this.doTheTest(tmpMtrxA, tmpMtrxD); diff --git a/test/org/ojalgo/matrix/decomposition/CompareJamaAndPrimitive.java b/test/org/ojalgo/matrix/decomposition/CompareJamaAndPrimitive.java index c481f1c95..b97d3e778 100644 --- a/test/org/ojalgo/matrix/decomposition/CompareJamaAndPrimitive.java +++ b/test/org/ojalgo/matrix/decomposition/CompareJamaAndPrimitive.java @@ -31,7 +31,7 @@ import org.ojalgo.matrix.SimpleQRCase; import org.ojalgo.matrix.SimpleSingularValueCase; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; public class CompareJamaAndPrimitive extends MatrixDecompositionTests { @@ -58,7 +58,7 @@ public void minimiseAllBranchLimits() { @Test public void testSimpleCholeskyCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleCholeskyCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleCholeskyCase.getOriginal()); TestUtils.assertEquals(JAMA_CHOLESKY.decompose(tmpMtrxA), PRIMITIVE_CHOLESKY.decompose(tmpMtrxA)); @@ -78,7 +78,7 @@ public void testSimpleCholeskyCase() { @Test public void testSimpleEigenvalueCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleEigenvalueCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleEigenvalueCase.getOriginal()); TestUtils.assertEquals(JAMA_EvD.decompose(tmpMtrxA), PRIMITIVE_EvD.decompose(tmpMtrxA)); @@ -99,7 +99,7 @@ public void testSimpleLUCase() { // Dense - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleLUCase.getOrginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleLUCase.getOrginal()); TestUtils.assertEquals(JAMA_LU.decompose(tmpMtrxA), PRIMITIVE_DENSE_LU.decompose(tmpMtrxA)); @@ -137,7 +137,7 @@ public void testSimpleLUCase() { @Test public void testSimpleQRCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleQRCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleQRCase.getOriginal()); final int tmpMinDim = (int) Math.min(tmpMtrxA.countRows(), tmpMtrxA.countColumns()); TestUtils.assertEquals(JAMA_QR.decompose(tmpMtrxA), PRIMITIVE_QR.decompose(tmpMtrxA)); @@ -159,7 +159,7 @@ public void testSimpleQRCase() { @Test public void testSimpleSingularValueCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getOriginal()); TestUtils.assertEquals(JAMA_SVD.decompose(tmpMtrxA), PRIMITIVE_SVD.decompose(tmpMtrxA)); diff --git a/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java b/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java index def2e2d4f..1710e53bc 100644 --- a/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java +++ b/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java @@ -27,12 +27,12 @@ import org.ojalgo.RecoverableCondition; import org.ojalgo.TestUtils; import org.ojalgo.array.Array1D; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver; -import org.ojalgo.matrix.store.GenericDenseStore; +import org.ojalgo.matrix.store.GenericStore; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.random.Normal; import org.ojalgo.random.Uniform; @@ -85,7 +85,7 @@ static void fullQR(final MatrixStore matrix) { MatrixStore product = matrix.multiply(q); int kernelCount = 0; for (int i = 0; i < product.countColumns(); i++) { - double norm = PrimitiveDenseStore.FACTORY.columns(product.sliceColumn(i)).norm(); + double norm = Primitive64Store.FACTORY.columns(product.sliceColumn(i)).norm(); if (norm < ZERO) { if (DEBUG) { System.out.println(String.format("Column %d of Q belongs to the " + "kernel of A.", i)); @@ -134,7 +134,7 @@ static void fullSVD(final MatrixStore matrix) { MatrixStore product = matrix.multiply(q2); int kernelCount = 0; for (int i = 0; i < product.countColumns(); i++) { - double norm = PrimitiveDenseStore.FACTORY.columns(product.sliceColumn(i)).norm(); + double norm = Primitive64Store.FACTORY.columns(product.sliceColumn(i)).norm(); if (norm < ZERO) { if (DEBUG) { System.out.println(String.format("Column %d of Q2 belongs to the " + "kernel of A.", i)); @@ -165,10 +165,10 @@ public void testGitHubIssue214() { double[] observationVector = { 26.0, 12.0, 9.0, 18.0, 16.0, 17.0, 24.0, 32.0, 30.0, 21.0, 16.0, 12.0, 21.0, 16.0 }; - final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(olsColumns); + final Primitive64Store tmpOriginal = Primitive64Store.FACTORY.rows(olsColumns); SingularValue tmpSVD = SingularValue.PRIMITIVE.make(tmpOriginal); tmpSVD.decompose(tmpOriginal); - PrimitiveDenseStore rhs = PrimitiveDenseStore.FACTORY.column(observationVector); + Primitive64Store rhs = Primitive64Store.FACTORY.column(observationVector); MatrixStore solution = tmpSVD.getSolution(rhs, tmpSVD.preallocate(tmpOriginal, rhs)); // Simply test that we can run this program without getting an exception @@ -180,7 +180,7 @@ public void testGitHubIssue214() { @Test public void testP20090923() { - PhysicalStore tmpA = PrimitiveDenseStore.FACTORY + PhysicalStore tmpA = Primitive64Store.FACTORY .rows(new double[][] { { 1.0, 0.0, 0.0, 0.0, 2.0 }, { 0.0, 0.0, 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 4.0, 0.0, 0.0, 0.0 } }); SingularValue tmpSVD = SingularValue.PRIMITIVE.make(); @@ -201,7 +201,7 @@ public void testP20090923() { @Test public void testP20091012() { - PhysicalStore tmpA = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(5, 9)); + PhysicalStore tmpA = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(5, 9)); QR tmpQR = QR.PRIMITIVE.make(tmpA); tmpQR.decompose(tmpA); @@ -215,7 +215,7 @@ public void testP20091012() { @Test public void testP20091012fixed() { - PhysicalStore tmpA = PrimitiveDenseStore.FACTORY + PhysicalStore tmpA = Primitive64Store.FACTORY .rows(new double[][] { { 1.5686711899234411, 5.857030526629094, 2.1798778832593637, 1.4901137152515287, 5.640993583029061 }, { 4.890945865607895, 4.2576454398997265, 1.0251822439318778, 0.8623492557631138, 5.7457253685285545 }, { 1.6397137349990025, 0.6795594856277076, 4.7101325736711095, 2.0823473021899517, 2.2159317240940233 } }); @@ -229,7 +229,7 @@ public void testP20091012fixed() { @Test public void testP20100512() { - PhysicalStore tmpA = PrimitiveDenseStore.FACTORY + PhysicalStore tmpA = Primitive64Store.FACTORY .rows(new double[][] { { 0.2845, 0.3597, 0.9544 }, { 0.3597, 0.6887, 0.0782 }, { 0.9544, 0.0782, 0.1140 } }); Eigenvalue tmpPrimitive = Eigenvalue.PRIMITIVE.make(); @@ -243,8 +243,8 @@ public void testP20110126() { int tmpDim = 5; - PhysicalStore tmpA = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); - PhysicalStore tmpI = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim); + PhysicalStore tmpA = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); + PhysicalStore tmpI = Primitive64Store.FACTORY.makeEye(tmpDim, tmpDim); LU tmpDecomp = LU.PRIMITIVE.make(); @@ -271,8 +271,8 @@ public void testP20110223() { NumberContext tmpEqualsNumberContext = new NumberContext(7, 11); int tmpDim = 99; - PhysicalStore tmpRandom = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); - PhysicalStore tmpIdentity = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim); + PhysicalStore tmpRandom = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); + PhysicalStore tmpIdentity = Primitive64Store.FACTORY.makeEye(tmpDim, tmpDim); LU tmpRefDecomps = new RawLU(); tmpRefDecomps.decompose(tmpRandom); @@ -307,7 +307,7 @@ public void testP20111213square() { PhysicalStore tmpSquare = TestUtils.makeRandomComplexStore(tmpDim, tmpDim); MatrixStore tmpHermitian = tmpSquare.conjugate().multiply(tmpSquare); - PhysicalStore tmpExpected = GenericDenseStore.COMPLEX.makeEye(tmpDim, tmpDim); + PhysicalStore tmpExpected = GenericStore.COMPLEX.makeEye(tmpDim, tmpDim); MatrixStore tmpActual; @SuppressWarnings("unchecked") @@ -348,7 +348,7 @@ public void testP20111213tall() { int tmpDim = Uniform.randomInteger(2, 6); PhysicalStore original = TestUtils.makeRandomComplexStore(tmpDim + tmpDim, tmpDim); - PhysicalStore identity = GenericDenseStore.COMPLEX.makeEye(tmpDim, tmpDim); + PhysicalStore identity = GenericStore.COMPLEX.makeEye(tmpDim, tmpDim); MatrixStore solution; @SuppressWarnings("unchecked") @@ -384,7 +384,7 @@ public void testP20111213tall() { @Tag("slow") public void testP20160419() { - PrimitiveDenseStore tmpOrg = PrimitiveDenseStore.FACTORY.makeFilled(2000, 2000, new Normal()); + Primitive64Store tmpOrg = Primitive64Store.FACTORY.makeFilled(2000, 2000, new Normal()); SingularValue tmpRaw = new RawSingularValue(); @@ -416,7 +416,7 @@ public void testP20160510InvertLargeMatrix() { } data[0][1] = 1.01; - PrimitiveMatrix input = PrimitiveMatrix.FACTORY.rows(data); + Primitive64Matrix input = Primitive64Matrix.FACTORY.rows(data); try { // SingularValue svd = SingularValue.make(input); SingularValue svd = new SingularValueDecomposition.Primitive(); @@ -442,7 +442,7 @@ public void testP20180614() { // We start by creating a 5 x 7 matrix with rank 4. double[][] data = new double[][] { { 3, -6, 6, 9, 1, 3, 2 }, { -2, 4, 5, 3, 2, 7, 5 }, { -7, 14, 3, -4, 0, 0, 0 }, { 0, 0, -2, -2, 3, -5, -8 }, { -1, 2, 7, 6, 2, 0, -2 } }; - MatrixStore matrixA = PrimitiveDenseStore.FACTORY.rows(data); + MatrixStore matrixA = Primitive64Store.FACTORY.rows(data); // Print the matrix to verify it. if (DEBUG) { System.out.println("A matrix:\n" + matrixA); @@ -456,7 +456,7 @@ public void testP20180614() { // Repeat this with a square matrix (padding with rows of zeros). int rows = data.length; int cols = data[0].length; - MatrixStore zeros = PrimitiveDenseStore.FACTORY.makeZero(cols - rows, cols); + MatrixStore zeros = Primitive64Store.FACTORY.makeZero(cols - rows, cols); MatrixStore matrixB = matrixA.logical().below(zeros).copy(); if (DEBUG) { // Print B to verify it. @@ -492,7 +492,7 @@ public void testP20180617() { NumberContext precision = new NumberContext(12, 8); - PrimitiveDenseStore matrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.730967787376657, 0.24053641567148587, 0.6374174253501083 }, + Primitive64Store matrix = Primitive64Store.FACTORY.rows(new double[][] { { 0.730967787376657, 0.24053641567148587, 0.6374174253501083 }, { 0.24053641567148587, 0.5975452777972018, 0.3332183994766498 }, { 0.6374174253501083, 0.3332183994766498, 0.8791825178724801 } }); for (Eigenvalue evd : MatrixDecompositionTests.getPrimitiveEigenvalue()) { diff --git a/test/org/ojalgo/matrix/decomposition/DegenerateLUCase.java b/test/org/ojalgo/matrix/decomposition/DegenerateLUCase.java index 8111dfc1a..606b599ad 100644 --- a/test/org/ojalgo/matrix/decomposition/DegenerateLUCase.java +++ b/test/org/ojalgo/matrix/decomposition/DegenerateLUCase.java @@ -26,8 +26,8 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.RationalMatrix; import org.ojalgo.matrix.SimpleEquationCase; -import org.ojalgo.matrix.store.GenericDenseStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.GenericStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.scalar.ComplexNumber; import org.ojalgo.scalar.RationalNumber; @@ -55,7 +55,7 @@ public void testBig() { final LU decomp = LU.RATIONAL.make(); decomp.decompose(degenerate); - TestUtils.assertEquals(GenericDenseStore.RATIONAL.copy(degenerate), decomp, evaluation); + TestUtils.assertEquals(GenericStore.RATIONAL.copy(degenerate), decomp, evaluation); } @Test @@ -67,9 +67,9 @@ public void testComplex() { final RationalMatrix degenerate = RationalMatrix.FACTORY.make(square).logical().below(square).below(square).get(); final LU decomp = LU.COMPLEX.make(); - decomp.decompose(GenericDenseStore.COMPLEX.copy(degenerate)); + decomp.decompose(GenericStore.COMPLEX.copy(degenerate)); - TestUtils.assertEquals(GenericDenseStore.COMPLEX.copy(degenerate), decomp, evaluation); + TestUtils.assertEquals(GenericStore.COMPLEX.copy(degenerate), decomp, evaluation); } @Test @@ -81,9 +81,9 @@ public void testDensePrimitive() { final RationalMatrix degenerate = RationalMatrix.FACTORY.make(square).logical().below(square).below(square).get(); final LU decomp = LU.PRIMITIVE.make(); - decomp.decompose(PrimitiveDenseStore.FACTORY.copy(degenerate)); + decomp.decompose(Primitive64Store.FACTORY.copy(degenerate)); - TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(degenerate), decomp, evaluation); + TestUtils.assertEquals(Primitive64Store.FACTORY.copy(degenerate), decomp, evaluation); } @Test diff --git a/test/org/ojalgo/matrix/decomposition/DesignCase.java b/test/org/ojalgo/matrix/decomposition/DesignCase.java index d34a11143..c329c696b 100644 --- a/test/org/ojalgo/matrix/decomposition/DesignCase.java +++ b/test/org/ojalgo/matrix/decomposition/DesignCase.java @@ -34,7 +34,7 @@ import org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.random.Normal; import org.ojalgo.random.Uniform; @@ -57,7 +57,7 @@ public void minimiseAllBranchLimits() { public void testCholeskySolveInverse() { PhysicalStore randomComplexStore = TestUtils.makeRandomComplexStore(4, 9); - PhysicalStore vctrs = PrimitiveDenseStore.FACTORY.copy(randomComplexStore); + PhysicalStore vctrs = Primitive64Store.FACTORY.copy(randomComplexStore); MatrixStore mtrx = vctrs.multiply(vctrs.transpose()); for (Cholesky decomp : MatrixDecompositionTests.getPrimitiveCholesky()) { @@ -70,8 +70,8 @@ public void testFullSize() { NumberContext precision = new NumberContext(12, 8); - MatrixStore tall = PrimitiveDenseStore.FACTORY.makeFilled(7, 5, new Uniform()); - MatrixStore fat = PrimitiveDenseStore.FACTORY.makeFilled(5, 7, new Uniform()); + MatrixStore tall = Primitive64Store.FACTORY.makeFilled(7, 5, new Uniform()); + MatrixStore fat = Primitive64Store.FACTORY.makeFilled(5, 7, new Uniform()); @SuppressWarnings("unchecked") EconomySize[] all = (EconomySize[]) new EconomySize[] { new BidiagonalDecomposition.Primitive(true), @@ -157,8 +157,8 @@ public void testFullSize() { @Test public void testRandomUnderdetermined() { - PhysicalStore tmpA = PrimitiveDenseStore.FACTORY.makeFilled(3, 9, new Normal()); - PhysicalStore tmpB = PrimitiveDenseStore.FACTORY.makeFilled(3, 1, new Normal()); + PhysicalStore tmpA = Primitive64Store.FACTORY.makeFilled(3, 9, new Normal()); + PhysicalStore tmpB = Primitive64Store.FACTORY.makeFilled(3, 1, new Normal()); QR tmpQR = QR.PRIMITIVE.make(tmpA); tmpQR.decompose(tmpA); @@ -174,7 +174,7 @@ public void testRandomUnderdetermined() { @Test public void testSolvable() { - PhysicalStore matrix = PrimitiveDenseStore.FACTORY.makeSPD(9); + PhysicalStore matrix = Primitive64Store.FACTORY.makeSPD(9); List> all = MatrixDecompositionTests.getPrimitiveMatrixDecompositionSolver(); for (MatrixDecomposition.Solver decomposition : all) { @@ -188,8 +188,8 @@ public void testSolvable() { @Test public void testSolveIdentity() { - Access2D identity = MatrixStore.PRIMITIVE.makeIdentity(9).get(); - Access2D random = PrimitiveDenseStore.FACTORY.makeFilled(9, 1, new Uniform()); + Access2D identity = MatrixStore.PRIMITIVE64.makeIdentity(9).get(); + Access2D random = Primitive64Store.FACTORY.makeFilled(9, 1, new Uniform()); List> all = MatrixDecompositionTests.getPrimitiveMatrixDecompositionSolver(); for (Solver solver : all) { @@ -205,7 +205,7 @@ public void testSolveIdentity() { public void testSolveInverse() { PhysicalStore randomComplexStore = TestUtils.makeRandomComplexStore(4, 9); - PhysicalStore vectors = PrimitiveDenseStore.FACTORY.copy(randomComplexStore); + PhysicalStore vectors = Primitive64Store.FACTORY.copy(randomComplexStore); MatrixStore matrix = vectors.multiply(vectors.transpose()); List> all = MatrixDecompositionTests.getPrimitiveMatrixDecompositionSolver(); @@ -220,7 +220,7 @@ public void testTridiagonal() { Tridiagonal tmpDecomposition = Tridiagonal.PRIMITIVE.make(); // Tridiagonal tmpDecomposition = new TridiagonalAltDecomp(); - PhysicalStore tmpOriginalMatrix = PrimitiveDenseStore.FACTORY + PhysicalStore tmpOriginalMatrix = Primitive64Store.FACTORY .rows(new double[][] { { 4, 2, 2, 1 }, { 2, -3, 1, 1 }, { 2, 1, 3, 1 }, { 1, 1, 1, 2 } }); tmpDecomposition.decompose(tmpOriginalMatrix); @@ -234,7 +234,7 @@ public void testTridiagonal() { @Test public void testWikipediaNullspace() { - PhysicalStore mtrxA = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2, 3, 5 }, { -4, 2, 3 } }); + PhysicalStore mtrxA = Primitive64Store.FACTORY.rows(new double[][] { { 2, 3, 5 }, { -4, 2, 3 } }); MatrixStore mtrxAt = mtrxA.transpose(); NumberContext precision = new NumberContext(14, 8); @@ -260,7 +260,7 @@ public void testWikipediaNullspace() { double scalePriSVD = PrimitiveMath.ABS.invoke(nullspacePriSVD.doubleValue(0)); nullspacePriSVD.modifyAll(PrimitiveMath.DIVIDE.second(scalePriSVD)); - PrimitiveDenseStore nullspace = PrimitiveDenseStore.FACTORY.columns(new double[] { -1, -26, 16 }); + Primitive64Store nullspace = Primitive64Store.FACTORY.columns(new double[] { -1, -26, 16 }); TestUtils.assertEquals(nullspace, nullspacePriQR, precision); TestUtils.assertEquals(nullspace, nullspacePriSVD, precision); @@ -272,7 +272,7 @@ public void testWikipediaNullspace() { @Test public void testWikipediaSVD() { - PhysicalStore tmpOriginalMatrix = PrimitiveDenseStore.FACTORY + PhysicalStore tmpOriginalMatrix = Primitive64Store.FACTORY .rows(new double[][] { { 1.0, 0.0, 0.0, 0.0, 2.0 }, { 0.0, 0.0, 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 4.0, 0.0, 0.0, 0.0 } }); Array1D.PRIMITIVE64.copy(new double[] { 4.0, 3.0, PrimitiveMath.SQRT.invoke(5.0), 0.0 }); @@ -305,7 +305,7 @@ private void doTestSolveInverse(final MatrixDecomposition.Solver solver, TestUtils.assertTrue("Decomposition not solvable", solver.isSolvable()); int dim = MissingMath.toMinIntExact(matrix.countRows(), matrix.countColumns()); - PhysicalStore tmpEye = PrimitiveDenseStore.FACTORY.makeEye(dim, dim); + PhysicalStore tmpEye = Primitive64Store.FACTORY.makeEye(dim, dim); MatrixStore tmpDirInv = solver.getInverse(); MatrixStore tmpSolInv = solver.getSolution(tmpEye); diff --git a/test/org/ojalgo/matrix/decomposition/ExtremeElementsCase.java b/test/org/ojalgo/matrix/decomposition/ExtremeElementsCase.java index cbdee6127..ac1e31bcf 100644 --- a/test/org/ojalgo/matrix/decomposition/ExtremeElementsCase.java +++ b/test/org/ojalgo/matrix/decomposition/ExtremeElementsCase.java @@ -34,7 +34,7 @@ import org.ojalgo.matrix.decomposition.HermitianEvD.Primitive; import org.ojalgo.matrix.decomposition.MatrixDecomposition.RankRevealing; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.task.InverterTask; import org.ojalgo.matrix.task.SolverTask; import org.ojalgo.netio.BasicLogger; @@ -53,13 +53,13 @@ public class ExtremeElementsCase extends MatrixDecompositionTests { */ static NumberContext ACCURACY = new NumberContext(12, 146); - private static void performInvertTest(final PrimitiveDenseStore original, final InverterTask task, final NumberContext context) { + private static void performInvertTest(final Primitive64Store original, final InverterTask task, final NumberContext context) { try { MatrixStore tmpInverse = task.invert(original); - MatrixStore tmpExpected = MatrixStore.PRIMITIVE.makeIdentity((int) original.countRows()).get(); + MatrixStore tmpExpected = MatrixStore.PRIMITIVE64.makeIdentity((int) original.countRows()).get(); MatrixStore tmpActual = original.multiply(tmpInverse); TestUtils.assertEquals(task.getClass().toString(), tmpExpected, tmpActual, context); @@ -70,8 +70,7 @@ private static void performInvertTest(final PrimitiveDenseStore original, final } - private static void performSolveTest(final PrimitiveDenseStore body, final PrimitiveDenseStore rhs, final SolverTask task, - final NumberContext context) { + private static void performSolveTest(final Primitive64Store body, final Primitive64Store rhs, final SolverTask task, final NumberContext context) { try { @@ -99,7 +98,7 @@ static void doTestInvert(final boolean large) { for (int exp = 0; exp < 308; exp++) { double tmpScale = POWER.invoke(TEN, large ? exp : -exp); - PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.makeSPD(dim); + Primitive64Store tmpOriginal = Primitive64Store.FACTORY.makeSPD(dim); if (DEBUG) { BasicLogger.debug("Scale exp={} => factor={} and context={}", exp, tmpScale, tmpContext); BasicLogger.debug("Original (unscaled) {}", tmpOriginal.toString()); @@ -132,7 +131,7 @@ static void doTestRank(final boolean large) { for (int exp = 0; exp < 308; exp++) { double scale = POWER.invoke(TEN, large ? exp : -exp); - PrimitiveDenseStore matrix = PrimitiveDenseStore.FACTORY.makeSPD(dim); + Primitive64Store matrix = Primitive64Store.FACTORY.makeSPD(dim); matrix.modifyAll(MULTIPLY.by(scale)); SingularValue reference = SingularValue.PRIMITIVE.make(matrix); @@ -173,8 +172,8 @@ static void doTestSolve(final boolean large) { for (int exp = 0; exp < 308; exp++) { double tmpScale = POWER.invoke(TEN, large ? exp : -exp); - PrimitiveDenseStore tmpBody = PrimitiveDenseStore.FACTORY.makeSPD(dim); - PrimitiveDenseStore tmpRHS = PrimitiveDenseStore.FACTORY.makeFilled(dim, 1, new Uniform()); + Primitive64Store tmpBody = Primitive64Store.FACTORY.makeSPD(dim); + Primitive64Store tmpRHS = Primitive64Store.FACTORY.makeFilled(dim, 1, new Uniform()); if (DEBUG) { BasicLogger.debug("Scale exp={} => factor={} and context={}", exp, tmpScale, tmpContext); BasicLogger.debug("Body (unscaled) {}", tmpBody.toString()); @@ -205,7 +204,7 @@ static MatrixStore getVerySmall() { long tmpDim = 5L; - PrimitiveDenseStore tmpRndm = PrimitiveDenseStore.FACTORY.makeZero(tmpDim, tmpDim); + Primitive64Store tmpRndm = Primitive64Store.FACTORY.makeZero(tmpDim, tmpDim); for (long j = 0L; j < tmpDim; j++) { for (long i = 0L; i < tmpDim; i++) { @@ -270,7 +269,7 @@ public void testEvD() { @Test public void testInvertEvD_10_307_1() { - PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { + Primitive64Store tmpOriginal = Primitive64Store.FACTORY.rows(new double[][] { { 1.488828119167862, 0.42210916029401624, 0.3090339419657017, 0.31968488522727556, 0.32307269871880584, 0.46899580731023627, 0.12091920407255509, 0.03795763520492966, 0.17470282114825963, 0.3946701200769135 }, { 0.42210916029401624, 1.8635124366670595, 0.545906918558408, 0.5647217567560566, 0.570706312407284, 0.8284787565954789, 0.21360317145069477, @@ -303,7 +302,7 @@ public void testInvertEvD_10_307_1() { @Test public void testInvertEvD_3_155_1() { - PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.509726074514643, 0.6439543946598099, 1.2096354379603502 }, + Primitive64Store tmpOriginal = Primitive64Store.FACTORY.rows(new double[][] { { 1.509726074514643, 0.6439543946598099, 1.2096354379603502 }, { 0.6439543946598099, 1.134228320145167, 0.8341376835908743 }, { 1.2096354379603502, 0.8341376835908743, 1.6999093634457072 } }); tmpOriginal.modifyAll(MULTIPLY.second(POWER.invoke(TEN, 155))); @@ -317,7 +316,7 @@ public void testInvertEvD_3_155_1() { @Test public void testInvertSVD_6_307_2() { - PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows( + Primitive64Store tmpOriginal = Primitive64Store.FACTORY.rows( new double[][] { { 1.7951923814808213, 0.659451350679988, 0.7107146253894259, 0.5763579411022435, 0.7199441830503458, 0.6356947473097578 }, { 0.659451350679988, 1.829297873115869, 0.7411968989569697, 0.6010777087922337, 0.7508223087524556, 0.6629594475153139 }, { 0.7107146253894259, 0.7411968989569697, 1.8937643794649044, 0.6478032355134435, 0.8091884190528792, 0.7144954285155056 }, @@ -336,7 +335,7 @@ public void testInvertSVD_6_307_2() { @Test public void testInvertSVD_7_307_1() { - PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { + Primitive64Store tmpOriginal = Primitive64Store.FACTORY.rows(new double[][] { { 1.6630365629391541, 0.5725332799439422, 0.6293312306387542, 0.3255116741968718, 0.16197060952553563, 0.38338065513999414, 0.45947212690705896 }, { 0.5725332799439422, 1.8635018216883505, 0.8196058776803916, 0.42392824070490653, 0.2109414837777316, 0.4992935723573937, 0.5983908592318098 }, @@ -360,7 +359,7 @@ public void testInvertSVD_7_307_1() { @Test public void testInvertTask_2_155_1() { - PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY + Primitive64Store tmpOriginal = Primitive64Store.FACTORY .rows(new double[][] { { 1.7755876870972727, 0.5243083105843722 }, { 0.5243083105843722, 1.6760142267686806 } }); tmpOriginal.modifyAll(MULTIPLY.second(POWER.invoke(TEN, 155))); @@ -476,8 +475,8 @@ public void testQR() { @Test public void testSolveLU_1_16_1() { - PrimitiveDenseStore tmpBody = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.7259687987824925 } }); - PrimitiveDenseStore tmpRHS = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.6533251061005759 } }); + Primitive64Store tmpBody = Primitive64Store.FACTORY.rows(new double[][] { { 1.7259687987824925 } }); + Primitive64Store tmpRHS = Primitive64Store.FACTORY.rows(new double[][] { { 0.6533251061005759 } }); UnaryFunction tmpSecond = MULTIPLY.second(POWER.invoke(TEN, -16)); tmpBody.modifyAll(tmpSecond); diff --git a/test/org/ojalgo/matrix/decomposition/SVDbyEvD.java b/test/org/ojalgo/matrix/decomposition/SVDbyEvD.java index ea4884993..5fff57d58 100644 --- a/test/org/ojalgo/matrix/decomposition/SVDbyEvD.java +++ b/test/org/ojalgo/matrix/decomposition/SVDbyEvD.java @@ -28,7 +28,7 @@ import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.type.context.NumberContext; @@ -51,7 +51,7 @@ public void minimiseAllBranchLimits() { @Test public void testHeath() { - final PhysicalStore tmpMtrx = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }); + final PhysicalStore tmpMtrx = Primitive64Store.FACTORY.rows(new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }); final Array1D tmpSingularValues = Array1D.PRIMITIVE64.copy(new double[] { 25.4624074360364, 1.29066167576123, 0.0 }); @@ -65,7 +65,7 @@ public void testHeath() { @Test public void testSmall2x2() { - final PhysicalStore tmpMtrx = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0, 0.0 }, { 3.0, -5.0 } }); + final PhysicalStore tmpMtrx = Primitive64Store.FACTORY.rows(new double[][] { { 4.0, 0.0 }, { 3.0, -5.0 } }); final Array1D tmpSingularValues = Array1D.PRIMITIVE64.copy(new double[] { 6.324555320336759, 3.1622776601683795 }); @@ -78,7 +78,7 @@ public void testSmall2x2() { @Test public void testWikipedia() { - final PhysicalStore tmpMtrx = PrimitiveDenseStore.FACTORY + final PhysicalStore tmpMtrx = Primitive64Store.FACTORY .rows(new double[][] { { 1.0, 0.0, 0.0, 0.0, 2.0 }, { 0.0, 0.0, 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 4.0, 0.0, 0.0, 0.0 } }); final Array1D tmpSingularValues = Array1D.PRIMITIVE64.copy(new double[] { 4.0, 3.0, PrimitiveMath.SQRT.invoke(5.0), 0.0 }); diff --git a/test/org/ojalgo/matrix/decomposition/TestJama.java b/test/org/ojalgo/matrix/decomposition/TestJama.java index f4177c95d..327324bbb 100755 --- a/test/org/ojalgo/matrix/decomposition/TestJama.java +++ b/test/org/ojalgo/matrix/decomposition/TestJama.java @@ -30,7 +30,7 @@ import org.ojalgo.matrix.SimpleQRCase; import org.ojalgo.matrix.SimpleSingularValueCase; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.type.context.NumberContext; /** @@ -56,7 +56,7 @@ public void minimiseAllBranchLimits() { @Test public void testSimpleCholeskyCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleCholeskyCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleCholeskyCase.getOriginal()); this.computeAndTest(tmpMtrxA); } @@ -64,7 +64,7 @@ public void testSimpleCholeskyCase() { @Test public void testSimpleEigenvalueCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleEigenvalueCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleEigenvalueCase.getOriginal()); this.computeAndTest(tmpMtrxA); } @@ -72,7 +72,7 @@ public void testSimpleEigenvalueCase() { @Test public void testSimpleLUCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleLUCase.getOrginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleLUCase.getOrginal()); this.computeAndTest(tmpMtrxA); } @@ -80,7 +80,7 @@ public void testSimpleLUCase() { @Test public void testSimpleQRCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleQRCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleQRCase.getOriginal()); this.computeAndTest(tmpMtrxA); } @@ -88,7 +88,7 @@ public void testSimpleQRCase() { @Test public void testSimpleSingularValueCase() { - final MatrixStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(SimpleSingularValueCase.getOriginal()); + final MatrixStore tmpMtrxA = Primitive64Store.FACTORY.copy(SimpleSingularValueCase.getOriginal()); this.computeAndTest(tmpMtrxA); } diff --git a/test/org/ojalgo/matrix/decomposition/TestSolveAndInvert.java b/test/org/ojalgo/matrix/decomposition/TestSolveAndInvert.java index 090bda1fd..1b18131ec 100644 --- a/test/org/ojalgo/matrix/decomposition/TestSolveAndInvert.java +++ b/test/org/ojalgo/matrix/decomposition/TestSolveAndInvert.java @@ -27,7 +27,7 @@ import org.ojalgo.matrix.SimpleEquationCase; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.type.context.NumberContext; @@ -53,8 +53,8 @@ public void testInverseOfRandomCase() { final NumberContext tmpEqualsNumberContext = new NumberContext(7, 10); final int tmpDim = 99; - final PhysicalStore tmpRandom = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); - final PhysicalStore tmpIdentity = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim); + final PhysicalStore tmpRandom = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); + final PhysicalStore tmpIdentity = Primitive64Store.FACTORY.makeEye(tmpDim, tmpDim); final MatrixDecomposition.Solver[] tmpAllDecomps = TestSolveAndInvert.getAllSquare(); @@ -82,9 +82,9 @@ public void testInverseOfRandomCase() { @Test public void testSimpleEquationCase() { - final MatrixStore tmpBody = PrimitiveDenseStore.FACTORY.copy(SimpleEquationCase.getBody()); - final MatrixStore tmpRHS = PrimitiveDenseStore.FACTORY.copy(SimpleEquationCase.getRHS()); - final MatrixStore tmpSolution = PrimitiveDenseStore.FACTORY.copy(SimpleEquationCase.getSolution()); + final MatrixStore tmpBody = Primitive64Store.FACTORY.copy(SimpleEquationCase.getBody()); + final MatrixStore tmpRHS = Primitive64Store.FACTORY.copy(SimpleEquationCase.getRHS()); + final MatrixStore tmpSolution = Primitive64Store.FACTORY.copy(SimpleEquationCase.getSolution()); for (final MatrixDecomposition.Solver tmpDecomp : TestSolveAndInvert.getAllSquare()) { this.doTest(tmpDecomp, tmpBody, tmpRHS, tmpSolution, new NumberContext(7, 6)); diff --git a/test/org/ojalgo/matrix/store/AboveBelowCase.java b/test/org/ojalgo/matrix/store/AboveBelowCase.java index fbbc717c3..ec206f75d 100644 --- a/test/org/ojalgo/matrix/store/AboveBelowCase.java +++ b/test/org/ojalgo/matrix/store/AboveBelowCase.java @@ -37,9 +37,9 @@ public void setUp() { MatrixStore above = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); MatrixStore below = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new AboveBelowStore<>(GenericDenseStore.RATIONAL.copy(above), GenericDenseStore.RATIONAL.copy(below)); - complexStore = new AboveBelowStore<>(GenericDenseStore.COMPLEX.copy(above), GenericDenseStore.COMPLEX.copy(below)); - primitiveStore = new AboveBelowStore<>(PrimitiveDenseStore.FACTORY.copy(above), PrimitiveDenseStore.FACTORY.copy(below)); + rationalStore = new AboveBelowStore<>(GenericStore.RATIONAL.copy(above), GenericStore.RATIONAL.copy(below)); + complexStore = new AboveBelowStore<>(GenericStore.COMPLEX.copy(above), GenericStore.COMPLEX.copy(below)); + primitiveStore = new AboveBelowStore<>(Primitive64Store.FACTORY.copy(above), Primitive64Store.FACTORY.copy(below)); numberOfRows = tmpRowDim + tmpRowDim; numberOfColumns = tmpColDim; diff --git a/test/org/ojalgo/matrix/store/ColumnsCase.java b/test/org/ojalgo/matrix/store/ColumnsCase.java index 775a239c9..95f04ae08 100644 --- a/test/org/ojalgo/matrix/store/ColumnsCase.java +++ b/test/org/ojalgo/matrix/store/ColumnsCase.java @@ -41,9 +41,9 @@ public void setUp() { tmpCols[i] = Uniform.randomInteger(tmpColDim); } - rationalStore = new ColumnsStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), tmpCols); - complexStore = new ColumnsStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), tmpCols); - primitiveStore = new ColumnsStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), tmpCols); + rationalStore = new ColumnsStore<>(GenericStore.RATIONAL.copy(tmpBase), tmpCols); + complexStore = new ColumnsStore<>(GenericStore.COMPLEX.copy(tmpBase), tmpCols); + primitiveStore = new ColumnsStore<>(Primitive64Store.FACTORY.copy(tmpBase), tmpCols); numberOfRows = tmpRowDim; numberOfColumns = tmpCols.length; diff --git a/test/org/ojalgo/matrix/store/ComposingStoreTest.java b/test/org/ojalgo/matrix/store/ComposingStoreTest.java index 4daa2bf86..157d61392 100644 --- a/test/org/ojalgo/matrix/store/ComposingStoreTest.java +++ b/test/org/ojalgo/matrix/store/ComposingStoreTest.java @@ -54,7 +54,7 @@ private MatrixStore filledMatrix(final int rowCount, final int colCount) } private MatrixStore filledMatrix(final int rowCount, final int colCount, final double value) { - PhysicalStore.Factory storeFactory = PrimitiveDenseStore.FACTORY; + PhysicalStore.Factory storeFactory = Primitive64Store.FACTORY; return storeFactory.makeFilled(rowCount, colCount, new NullaryFunction() { public double doubleValue() { diff --git a/test/org/ojalgo/matrix/store/ConjugatedCase.java b/test/org/ojalgo/matrix/store/ConjugatedCase.java index 252d3458a..72122e5ae 100644 --- a/test/org/ojalgo/matrix/store/ConjugatedCase.java +++ b/test/org/ojalgo/matrix/store/ConjugatedCase.java @@ -36,9 +36,9 @@ public void setUp() { MatrixStore base = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new ConjugatedStore<>(GenericDenseStore.RATIONAL.copy(base)); - complexStore = new ConjugatedStore<>(GenericDenseStore.COMPLEX.copy(base)); - primitiveStore = new ConjugatedStore<>(PrimitiveDenseStore.FACTORY.copy(base)); + rationalStore = new ConjugatedStore<>(GenericStore.RATIONAL.copy(base)); + complexStore = new ConjugatedStore<>(GenericStore.COMPLEX.copy(base)); + primitiveStore = new ConjugatedStore<>(Primitive64Store.FACTORY.copy(base)); numberOfRows = tmpColDim; numberOfColumns = tmpRowDim; diff --git a/test/org/ojalgo/matrix/store/IdentityCase.java b/test/org/ojalgo/matrix/store/IdentityCase.java index f9bf107a2..b56a57b07 100644 --- a/test/org/ojalgo/matrix/store/IdentityCase.java +++ b/test/org/ojalgo/matrix/store/IdentityCase.java @@ -32,9 +32,9 @@ public void setUp() { int dim = Uniform.randomInteger(1, 9); - rationalStore = new IdentityStore<>(GenericDenseStore.RATIONAL, dim); - complexStore = new IdentityStore<>(GenericDenseStore.COMPLEX, dim); - primitiveStore = new IdentityStore<>(PrimitiveDenseStore.FACTORY, dim); + rationalStore = new IdentityStore<>(GenericStore.RATIONAL, dim); + complexStore = new IdentityStore<>(GenericStore.COMPLEX, dim); + primitiveStore = new IdentityStore<>(Primitive64Store.FACTORY, dim); numberOfRows = dim; numberOfColumns = dim; diff --git a/test/org/ojalgo/matrix/store/LeftRightCase.java b/test/org/ojalgo/matrix/store/LeftRightCase.java index f6d933bae..c60d42dd2 100644 --- a/test/org/ojalgo/matrix/store/LeftRightCase.java +++ b/test/org/ojalgo/matrix/store/LeftRightCase.java @@ -37,9 +37,9 @@ public void setUp() { MatrixStore left = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); MatrixStore right = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new LeftRightStore<>(GenericDenseStore.RATIONAL.copy(left), GenericDenseStore.RATIONAL.copy(right)); - complexStore = new LeftRightStore<>(GenericDenseStore.COMPLEX.copy(left), GenericDenseStore.COMPLEX.copy(right)); - primitiveStore = new LeftRightStore<>(PrimitiveDenseStore.FACTORY.copy(left), PrimitiveDenseStore.FACTORY.copy(right)); + rationalStore = new LeftRightStore<>(GenericStore.RATIONAL.copy(left), GenericStore.RATIONAL.copy(right)); + complexStore = new LeftRightStore<>(GenericStore.COMPLEX.copy(left), GenericStore.COMPLEX.copy(right)); + primitiveStore = new LeftRightStore<>(Primitive64Store.FACTORY.copy(left), Primitive64Store.FACTORY.copy(right)); numberOfRows = tmpRowDim; numberOfColumns = tmpColDim + tmpColDim; diff --git a/test/org/ojalgo/matrix/store/MultiplicationTest.java b/test/org/ojalgo/matrix/store/MultiplicationTest.java index 936a64856..08c717009 100644 --- a/test/org/ojalgo/matrix/store/MultiplicationTest.java +++ b/test/org/ojalgo/matrix/store/MultiplicationTest.java @@ -37,10 +37,10 @@ public MultiplicationTest() { @Test public void testPower() { - Factory factory = PrimitiveDenseStore.FACTORY; + Factory factory = Primitive64Store.FACTORY; int dim = 9; - PrimitiveDenseStore random = factory.makeSPD(dim); + Primitive64Store random = factory.makeSPD(dim); MatrixStore expected = factory.makeEye(dim, dim); for (int p = 0; p < 20; p++) { @@ -59,21 +59,21 @@ public void testRepeatedMultiplications() { for (int s = 0; s < sizes.length; s++) { int dim = sizes[s]; - PrimitiveDenseStore result = PrimitiveDenseStore.FACTORY.makeZero(dim, dim); - MatrixStore matA = PrimitiveDenseStore.FACTORY.makeFilled(dim, dim, new Normal()); - MatrixStore matB = PrimitiveDenseStore.FACTORY.makeFilled(dim, dim, new Uniform()); + Primitive64Store result = Primitive64Store.FACTORY.makeZero(dim, dim); + MatrixStore matA = Primitive64Store.FACTORY.makeFilled(dim, dim, new Normal()); + MatrixStore matB = Primitive64Store.FACTORY.makeFilled(dim, dim, new Uniform()); result.fillByMultiplying(matA, matB); - PrimitiveDenseStore pp = result.copy(); + Primitive64Store pp = result.copy(); result.fillByMultiplying(matA, matB.transpose()); - PrimitiveDenseStore pt = result.copy(); + Primitive64Store pt = result.copy(); result.fillByMultiplying(matA.transpose(), matB); - PrimitiveDenseStore tp = result.copy(); + Primitive64Store tp = result.copy(); result.fillByMultiplying(matA.transpose(), matB.transpose()); - PrimitiveDenseStore tt = result.copy(); + Primitive64Store tt = result.copy(); for (long i = 0; i < 3; i++) { diff --git a/test/org/ojalgo/matrix/store/NonPhysicalTest.java b/test/org/ojalgo/matrix/store/NonPhysicalTest.java index d5a4e3cb2..b676be1e9 100644 --- a/test/org/ojalgo/matrix/store/NonPhysicalTest.java +++ b/test/org/ojalgo/matrix/store/NonPhysicalTest.java @@ -36,7 +36,7 @@ public abstract class NonPhysicalTest extends MatrixStoreTests { private static final NumberContext ACCURACY = StandardType.DECIMAL_032; - private static void testAggregation(final MatrixStore anyStore) { + private static > void testAggregation(final MatrixStore anyStore) { final PhysicalStore copied = anyStore.copy(); @@ -45,8 +45,8 @@ private static void testAggregation(final MatrixStore anyS BasicLogger.debug("Copy", copied); } - Number expected; - Number actual; + N expected; + N actual; for (final Aggregator aggregator : Aggregator.values()) { @@ -75,17 +75,17 @@ private static void testAggregation(final MatrixStore anyS } } - private static void testCopy(final MatrixStore anyStore) { + private static > void testCopy(final MatrixStore anyStore) { TestUtils.assertEquals(anyStore, anyStore.copy(), ACCURACY); } - private static void testDimensions(final MatrixStore anyStore, final int numberOfRows, final int numberOfColumns) { + private static > void testDimensions(final MatrixStore anyStore, final int numberOfRows, final int numberOfColumns) { TestUtils.assertEquals(numberOfRows, anyStore.countRows()); TestUtils.assertEquals(numberOfColumns, anyStore.countColumns()); TestUtils.assertEquals(numberOfRows * numberOfColumns, anyStore.count()); } - private static void testMultiplication(final MatrixStore anyStore) { + private static > void testMultiplication(final MatrixStore anyStore) { final PhysicalStore tmpCopy = anyStore.copy(); diff --git a/test/org/ojalgo/matrix/store/RowsCase.java b/test/org/ojalgo/matrix/store/RowsCase.java index 84c7aa494..b84897c7f 100644 --- a/test/org/ojalgo/matrix/store/RowsCase.java +++ b/test/org/ojalgo/matrix/store/RowsCase.java @@ -41,9 +41,9 @@ public void setUp() { tmpRows[i] = Uniform.randomInteger(tmpRowDim); } - rationalStore = new RowsStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), tmpRows); - complexStore = new RowsStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), tmpRows); - primitiveStore = new RowsStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), tmpRows); + rationalStore = new RowsStore<>(GenericStore.RATIONAL.copy(tmpBase), tmpRows); + complexStore = new RowsStore<>(GenericStore.COMPLEX.copy(tmpBase), tmpRows); + primitiveStore = new RowsStore<>(Primitive64Store.FACTORY.copy(tmpBase), tmpRows); numberOfRows = tmpRows.length; numberOfColumns = tmpColDim; diff --git a/test/org/ojalgo/matrix/store/SparseCase.java b/test/org/ojalgo/matrix/store/SparseCase.java index 7bef9e417..9a1ba9c46 100644 --- a/test/org/ojalgo/matrix/store/SparseCase.java +++ b/test/org/ojalgo/matrix/store/SparseCase.java @@ -37,7 +37,7 @@ public void setUp() { rationalStore = SparseStore.RATIONAL.make(dim, dim); complexStore = SparseStore.COMPLEX.make(dim, dim); - primitiveStore = SparseStore.PRIMITIVE.make(dim, dim); + primitiveStore = SparseStore.PRIMITIVE64.make(dim, dim); for (int ij = 0; ij < dim; ij++) { ((SparseStore) rationalStore).set(ij, ij, 1.0); @@ -84,7 +84,7 @@ public void testOneFullColumn() { int ind = Uniform.randomInteger(0, 10); - SparseStore store = SparseStore.PRIMITIVE.make(10, 10); + SparseStore store = SparseStore.PRIMITIVE64.make(10, 10); store.fillColumn(ind, 1.0); for (int i = 0; i < 10; i++) { @@ -112,7 +112,7 @@ public void testOneFullRow() { int ind = Uniform.randomInteger(0, 10); - SparseStore store = SparseStore.PRIMITIVE.make(10, 10); + SparseStore store = SparseStore.PRIMITIVE64.make(10, 10); store.fillRow(ind, 1.0); for (int i = 0; i < 10; i++) { diff --git a/test/org/ojalgo/matrix/store/SparsePerformance.java b/test/org/ojalgo/matrix/store/SparsePerformance.java index 21e0d10c1..f248549dd 100644 --- a/test/org/ojalgo/matrix/store/SparsePerformance.java +++ b/test/org/ojalgo/matrix/store/SparsePerformance.java @@ -56,8 +56,8 @@ public void testElementwiseMultiplication() { int n = 100_000; - SparseStore mtrxA = SparseStore.PRIMITIVE.make(n, n); - SparseStore mtrxB = SparseStore.PRIMITIVE.make(n, n); + SparseStore mtrxA = SparseStore.PRIMITIVE64.make(n, n); + SparseStore mtrxB = SparseStore.PRIMITIVE64.make(n, n); Stopwatch clock = new Stopwatch(); @@ -76,7 +76,7 @@ public void testElementwiseMultiplication() { SparsePerformance.touchNonzeros(mtrxA); - TestUtils.assertFasterThan(5, CalendarDateUnit.MILLIS, clock); + TestUtils.assertFasterThan(10, CalendarDateUnit.MILLIS, clock); } @Test @@ -85,8 +85,8 @@ public void testMatrixMultiplication() { int n = 100_000; - SparseStore mtrxA = SparseStore.PRIMITIVE.make(n, n); - SparseStore mtrxB = SparseStore.PRIMITIVE.make(n, n); + SparseStore mtrxA = SparseStore.PRIMITIVE64.make(n, n); + SparseStore mtrxB = SparseStore.PRIMITIVE64.make(n, n); Stopwatch clock = new Stopwatch(); @@ -109,9 +109,9 @@ public void testMultiplyByOneVector() { int n = 100_000; - SparseStore mtrx = SparseStore.PRIMITIVE.make(n, n); + SparseStore mtrx = SparseStore.PRIMITIVE64.make(n, n); - PrimitiveDenseStore ones = PrimitiveDenseStore.FACTORY.makeZero(n, 1); + Primitive64Store ones = Primitive64Store.FACTORY.make(n, 1); ones.fillAll(ONE); Stopwatch clock = new Stopwatch(); @@ -126,7 +126,7 @@ public void testMultiplyByOneVector() { SparsePerformance.touchNonzeros(mtrx.multiply(ones)); - TestUtils.assertFasterThan(100, CalendarDateUnit.MILLIS, clock); + TestUtils.assertFasterThan(110, CalendarDateUnit.MILLIS, clock); clock.reset(); @@ -140,8 +140,8 @@ public void testReduceColumns() { int n = 100_000; - SparseStore mtrx = SparseStore.PRIMITIVE.make(n, n); - PrimitiveDenseStore vctr = PrimitiveDenseStore.FACTORY.makeZero(1, n); + SparseStore mtrx = SparseStore.PRIMITIVE64.make(n, n); + Primitive64Store vctr = Primitive64Store.FACTORY.makeZero(1, n); Stopwatch clock = new Stopwatch(); @@ -165,8 +165,8 @@ public void testReduceRows() { int n = 100_000; - SparseStore mtrx = SparseStore.PRIMITIVE.make(n, n); - PrimitiveDenseStore vctr = PrimitiveDenseStore.FACTORY.makeZero(n, 1); + SparseStore mtrx = SparseStore.PRIMITIVE64.make(n, n); + Primitive64Store vctr = Primitive64Store.FACTORY.makeZero(n, 1); Stopwatch clock = new Stopwatch(); diff --git a/test/org/ojalgo/matrix/store/StoreProblems.java b/test/org/ojalgo/matrix/store/StoreProblems.java index b9ca65628..e0689f821 100644 --- a/test/org/ojalgo/matrix/store/StoreProblems.java +++ b/test/org/ojalgo/matrix/store/StoreProblems.java @@ -25,7 +25,7 @@ import org.ojalgo.OjAlgoUtils; import org.ojalgo.TestUtils; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.netio.BasicLogger; import org.ojalgo.type.context.NumberContext; @@ -39,21 +39,21 @@ public class StoreProblems extends MatrixStoreTests { @Test public void testP20071210() { - PrimitiveMatrix A, Bu, K, sx, currentState; + Primitive64Matrix A, Bu, K, sx, currentState; final double[][] a = { { 1, 2 }, { 3, 4 } }; - A = PrimitiveMatrix.FACTORY.rows(a); + A = Primitive64Matrix.FACTORY.rows(a); final double[][] bu = { { 1, 0 }, { 0, 1 } }; - Bu = PrimitiveMatrix.FACTORY.rows(bu); - PrimitiveMatrix.FACTORY.makeEye(2, 2); - K = PrimitiveMatrix.FACTORY.makeEye(2, 2); + Bu = Primitive64Matrix.FACTORY.rows(bu); + Primitive64Matrix.FACTORY.makeEye(2, 2); + K = Primitive64Matrix.FACTORY.makeEye(2, 2); final int hp = 2 * OjAlgoUtils.ENVIRONMENT.threads; - final PrimitiveMatrix eye = PrimitiveMatrix.FACTORY.makeEye(A); - final PrimitiveMatrix Aprime = A.subtract(Bu.multiply(K)); - PrimitiveMatrix Apow = PrimitiveMatrix.FACTORY.copy(Aprime); - final PrimitiveMatrix tmp = Aprime.subtract(eye); - sx = PrimitiveMatrix.FACTORY.copy(eye); + final Primitive64Matrix eye = Primitive64Matrix.FACTORY.makeEye(A); + final Primitive64Matrix Aprime = A.subtract(Bu.multiply(K)); + Primitive64Matrix Apow = Primitive64Matrix.FACTORY.copy(Aprime); + final Primitive64Matrix tmp = Aprime.subtract(eye); + sx = Primitive64Matrix.FACTORY.copy(eye); sx = sx.logical().below(tmp).get(); //loop runs hp-2 times, which means the first elements of the matrices must be "hardcoded" @@ -61,7 +61,7 @@ public void testP20071210() { sx = sx.logical().below(tmp.multiply(Apow)).get(); Apow = Apow.multiply(Apow); } - currentState = PrimitiveMatrix.FACTORY.makeZero(A.countRows(), 1); + currentState = Primitive64Matrix.FACTORY.makeZero(A.countRows(), 1); currentState = currentState.add(1.0); sx.multiply(currentState); } @@ -75,9 +75,9 @@ public void testP20110223() { final int tmpDim = 9; - final PhysicalStore tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); - final PhysicalStore tmpMtrxB = PrimitiveDenseStore.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); - final PhysicalStore tmpMtrxC = PrimitiveDenseStore.FACTORY.makeZero(tmpDim, tmpDim); + final PhysicalStore tmpMtrxA = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); + final PhysicalStore tmpMtrxB = Primitive64Store.FACTORY.copy(TestUtils.makeRandomComplexStore(tmpDim, tmpDim)); + final PhysicalStore tmpMtrxC = Primitive64Store.FACTORY.makeZero(tmpDim, tmpDim); PhysicalStore tmpExpected; PhysicalStore tmpActual; @@ -107,11 +107,11 @@ public void testP20110223() { @Test public void testP20180121() { - final SparseStore m = SparseStore.PRIMITIVE.make(3, 2); - final PrimitiveDenseStore mAdd = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }); + final SparseStore m = SparseStore.PRIMITIVE64.make(3, 2); + final Primitive64Store mAdd = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }); final MatrixStore n = m.add(mAdd); - final SparseStore eye = SparseStore.PRIMITIVE.make(2, 2); + final SparseStore eye = SparseStore.PRIMITIVE64.make(2, 2); eye.set(0, 0, 1.0); eye.set(1, 1, 1.0); @@ -119,20 +119,20 @@ public void testP20180121() { TestUtils.assertEquals(mAdd, prod); - final SparseStore m2 = SparseStore.PRIMITIVE.make(3, 2); + final SparseStore m2 = SparseStore.PRIMITIVE64.make(3, 2); m2.set(0, 0, 1.0); TestUtils.assertEquals(mAdd, m2.multiply(eye)); TestUtils.assertEquals(mAdd, eye.premultiply(m2).get()); - final SparseStore a = SparseStore.PRIMITIVE.make(3, 3); + final SparseStore a = SparseStore.PRIMITIVE64.make(3, 3); a.set(1, 1, 1.0); - final SparseStore b = SparseStore.PRIMITIVE.make(3, 5); + final SparseStore b = SparseStore.PRIMITIVE64.make(3, 5); b.set(1, 1, 1.0); b.set(0, 3, 1.0); - final SparseStore c = SparseStore.PRIMITIVE.make(3, 5); + final SparseStore c = SparseStore.PRIMITIVE64.make(3, 5); c.set(1, 1, 1.0); if (DEBUG) { @@ -154,14 +154,14 @@ public void testTransposeElementsSupplier() { double[][] _y = { { 0, 0, 0 }, { 1, 1, 1 }, { 2, 2, 2 } }; double[][] exp = { { 1.0, 2.0, 3.0 }, { 3.0, 4.0, 5.0 }, { 5.0, 6.0, 7.0 } }; - PrimitiveDenseStore x = PrimitiveDenseStore.FACTORY.rows(_x); - PrimitiveDenseStore y = PrimitiveDenseStore.FACTORY.rows(_y); + Primitive64Store x = Primitive64Store.FACTORY.rows(_x); + Primitive64Store y = Primitive64Store.FACTORY.rows(_y); ElementsSupplier diff = y.operateOnMatching(x, PrimitiveMath.SUBTRACT); ElementsSupplier transp = diff.transpose(); - TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.rows(exp), diff.get()); - TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.columns(exp), transp.get()); + TestUtils.assertEquals(Primitive64Store.FACTORY.rows(exp), diff.get()); + TestUtils.assertEquals(Primitive64Store.FACTORY.columns(exp), transp.get()); } } diff --git a/test/org/ojalgo/matrix/store/SuperimposedColumnCase.java b/test/org/ojalgo/matrix/store/SuperimposedColumnCase.java index 27d54ed17..b1e37ab73 100644 --- a/test/org/ojalgo/matrix/store/SuperimposedColumnCase.java +++ b/test/org/ojalgo/matrix/store/SuperimposedColumnCase.java @@ -38,9 +38,9 @@ public void setUp() { MatrixStore tmpColumn = NonPhysicalTest.makeRandomMatrix(tmpRowDim, 1); int tmpIndex = Uniform.randomInteger(tmpColDim); - rationalStore = new SuperimposedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), 0, tmpIndex, GenericDenseStore.RATIONAL.copy(tmpColumn)); - complexStore = new SuperimposedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), 0, tmpIndex, GenericDenseStore.COMPLEX.copy(tmpColumn)); - primitiveStore = new SuperimposedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), 0, tmpIndex, PrimitiveDenseStore.FACTORY.copy(tmpColumn)); + rationalStore = new SuperimposedStore<>(GenericStore.RATIONAL.copy(tmpBase), 0, tmpIndex, GenericStore.RATIONAL.copy(tmpColumn)); + complexStore = new SuperimposedStore<>(GenericStore.COMPLEX.copy(tmpBase), 0, tmpIndex, GenericStore.COMPLEX.copy(tmpColumn)); + primitiveStore = new SuperimposedStore<>(Primitive64Store.FACTORY.copy(tmpBase), 0, tmpIndex, Primitive64Store.FACTORY.copy(tmpColumn)); numberOfRows = tmpRowDim; numberOfColumns = tmpColDim; diff --git a/test/org/ojalgo/matrix/store/SuperimposedElementCase.java b/test/org/ojalgo/matrix/store/SuperimposedElementCase.java index d93759d81..0dd496407 100644 --- a/test/org/ojalgo/matrix/store/SuperimposedElementCase.java +++ b/test/org/ojalgo/matrix/store/SuperimposedElementCase.java @@ -21,8 +21,6 @@ */ package org.ojalgo.matrix.store; -import java.math.BigDecimal; - import org.junit.jupiter.api.BeforeEach; import org.ojalgo.function.constant.BigMath; import org.ojalgo.random.Uniform; @@ -41,18 +39,18 @@ public void setUp() { MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); int tmpRowIndex = Uniform.randomInteger(tmpRowDim); int tmpColumnIndex = Uniform.randomInteger(tmpColDim); - BigDecimal tmpElement = BigMath.PI; - MatrixStore aBase = GenericDenseStore.RATIONAL.copy(tmpBase); + RationalNumber tmpElement = RationalNumber.valueOf(BigMath.PI); + MatrixStore aBase = GenericStore.RATIONAL.copy(tmpBase); // myBigStore = new SuperimposedMatrixStore(BigDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, tmpColumnIndex, tmpElement); // myComplexStore = new SuperimposedMatrixStore(ComplexDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, tmpColumnIndex, ComplexNumber.makeReal(tmpElement.doubleValue())); // myPrimitiveStore = new SuperimposedMatrixStore(PrimitiveDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, tmpColumnIndex, tmpElement.doubleValue()); rationalStore = new SuperimposedStore<>(aBase, tmpRowIndex, tmpColumnIndex, new SingleStore<>(aBase.physical(), tmpElement)); - MatrixStore aBase1 = GenericDenseStore.COMPLEX.copy(tmpBase); + MatrixStore aBase1 = GenericStore.COMPLEX.copy(tmpBase); complexStore = new SuperimposedStore<>(aBase1, tmpRowIndex, tmpColumnIndex, new SingleStore<>(aBase1.physical(), ComplexNumber.valueOf(tmpElement.doubleValue()))); - MatrixStore aBase2 = PrimitiveDenseStore.FACTORY.copy(tmpBase); + MatrixStore aBase2 = Primitive64Store.FACTORY.copy(tmpBase); primitiveStore = new SuperimposedStore<>(aBase2, tmpRowIndex, tmpColumnIndex, new SingleStore<>(aBase2.physical(), tmpElement.doubleValue())); numberOfRows = tmpRowDim; diff --git a/test/org/ojalgo/matrix/store/SuperimposedRowCase.java b/test/org/ojalgo/matrix/store/SuperimposedRowCase.java index 403a24a3f..3da570248 100644 --- a/test/org/ojalgo/matrix/store/SuperimposedRowCase.java +++ b/test/org/ojalgo/matrix/store/SuperimposedRowCase.java @@ -38,9 +38,9 @@ public void setUp() { MatrixStore tmpRow = NonPhysicalTest.makeRandomMatrix(1, tmpColDim); int tmpIndex = Uniform.randomInteger(tmpRowDim); - rationalStore = new SuperimposedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase), tmpIndex, 0, GenericDenseStore.RATIONAL.copy(tmpRow)); - complexStore = new SuperimposedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase), tmpIndex, 0, GenericDenseStore.COMPLEX.copy(tmpRow)); - primitiveStore = new SuperimposedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase), tmpIndex, 0, PrimitiveDenseStore.FACTORY.copy(tmpRow)); + rationalStore = new SuperimposedStore<>(GenericStore.RATIONAL.copy(tmpBase), tmpIndex, 0, GenericStore.RATIONAL.copy(tmpRow)); + complexStore = new SuperimposedStore<>(GenericStore.COMPLEX.copy(tmpBase), tmpIndex, 0, GenericStore.COMPLEX.copy(tmpRow)); + primitiveStore = new SuperimposedStore<>(Primitive64Store.FACTORY.copy(tmpBase), tmpIndex, 0, Primitive64Store.FACTORY.copy(tmpRow)); numberOfRows = tmpRowDim; numberOfColumns = tmpColDim; diff --git a/test/org/ojalgo/matrix/store/SuppliersAndConsumers.java b/test/org/ojalgo/matrix/store/SuppliersAndConsumers.java index fd0101819..e0ffd9f47 100644 --- a/test/org/ojalgo/matrix/store/SuppliersAndConsumers.java +++ b/test/org/ojalgo/matrix/store/SuppliersAndConsumers.java @@ -29,10 +29,10 @@ public class SuppliersAndConsumers extends MatrixStoreTests { @Test public void testMultiplyingAndTransposing() { - final PrimitiveDenseStore tmpMtrxA = PrimitiveDenseStore.FACTORY.makeZero(10, 5); - final MatrixStore tmpMtrxB = PrimitiveDenseStore.FACTORY.makeEye(5, 5).multiply(2.0); - final PrimitiveDenseStore tmpMtrxC = PrimitiveDenseStore.FACTORY.makeZero(5, 10); - final PrimitiveDenseStore tmpMtrxD = PrimitiveDenseStore.FACTORY.makeZero(5, 10); + final Primitive64Store tmpMtrxA = Primitive64Store.FACTORY.makeZero(10, 5); + final MatrixStore tmpMtrxB = Primitive64Store.FACTORY.makeEye(5, 5).multiply(2.0); + final Primitive64Store tmpMtrxC = Primitive64Store.FACTORY.makeZero(5, 10); + final Primitive64Store tmpMtrxD = Primitive64Store.FACTORY.makeZero(5, 10); for (int j = 0; j < 5; j++) { tmpMtrxA.fillColumn(0L, j, j + 1.0); diff --git a/test/org/ojalgo/matrix/store/TransposedCase.java b/test/org/ojalgo/matrix/store/TransposedCase.java index 514391fd4..8d0dfa2fb 100644 --- a/test/org/ojalgo/matrix/store/TransposedCase.java +++ b/test/org/ojalgo/matrix/store/TransposedCase.java @@ -36,9 +36,9 @@ public void setUp() { MatrixStore tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); - rationalStore = new TransposedStore<>(GenericDenseStore.RATIONAL.copy(tmpBase)); - complexStore = new TransposedStore<>(GenericDenseStore.COMPLEX.copy(tmpBase)); - primitiveStore = new TransposedStore<>(PrimitiveDenseStore.FACTORY.copy(tmpBase)); + rationalStore = new TransposedStore<>(GenericStore.RATIONAL.copy(tmpBase)); + complexStore = new TransposedStore<>(GenericStore.COMPLEX.copy(tmpBase)); + primitiveStore = new TransposedStore<>(Primitive64Store.FACTORY.copy(tmpBase)); numberOfRows = tmpColDim; numberOfColumns = tmpRowDim; diff --git a/test/org/ojalgo/matrix/store/ZeroCase.java b/test/org/ojalgo/matrix/store/ZeroCase.java index 42ec3f455..fe9afef37 100644 --- a/test/org/ojalgo/matrix/store/ZeroCase.java +++ b/test/org/ojalgo/matrix/store/ZeroCase.java @@ -33,9 +33,9 @@ public void setUp() { int tmpRowDim = Uniform.randomInteger(1, 9); int tmpColDim = Uniform.randomInteger(1, 9); - rationalStore = new ZeroStore<>(GenericDenseStore.RATIONAL, tmpRowDim, tmpColDim); - complexStore = new ZeroStore<>(GenericDenseStore.COMPLEX, tmpRowDim, tmpColDim); - primitiveStore = new ZeroStore<>(PrimitiveDenseStore.FACTORY, tmpRowDim, tmpColDim); + rationalStore = new ZeroStore<>(GenericStore.RATIONAL, tmpRowDim, tmpColDim); + complexStore = new ZeroStore<>(GenericStore.COMPLEX, tmpRowDim, tmpColDim); + primitiveStore = new ZeroStore<>(Primitive64Store.FACTORY, tmpRowDim, tmpColDim); numberOfRows = tmpRowDim; numberOfColumns = tmpColDim; diff --git a/test/org/ojalgo/matrix/task/DeterminantTest.java b/test/org/ojalgo/matrix/task/DeterminantTest.java index ccb4a4f08..c9b598522 100644 --- a/test/org/ojalgo/matrix/task/DeterminantTest.java +++ b/test/org/ojalgo/matrix/task/DeterminantTest.java @@ -27,7 +27,7 @@ import org.ojalgo.TestUtils; import org.ojalgo.matrix.MatrixUtils; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Uniform; public final class DeterminantTest extends MatrixTaskTests { @@ -104,7 +104,7 @@ void doSymmetric(final DeterminantTask fixed, final int dimension) { } MatrixStore makeGeneral(final int dim) { - return PrimitiveDenseStore.FACTORY.makeFilled(dim, dim, new Uniform()); + return Primitive64Store.FACTORY.makeFilled(dim, dim, new Uniform()); } MatrixStore makeSymmetric(final int dim) { diff --git a/test/org/ojalgo/matrix/task/InverterTest.java b/test/org/ojalgo/matrix/task/InverterTest.java index e3461834c..46c8b3274 100644 --- a/test/org/ojalgo/matrix/task/InverterTest.java +++ b/test/org/ojalgo/matrix/task/InverterTest.java @@ -29,7 +29,7 @@ import org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver; import org.ojalgo.matrix.decomposition.MatrixDecompositionTests; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; public class InverterTest extends MatrixTaskTests { @@ -82,7 +82,7 @@ private void doCompare(final InverterTask fixed, final int dimension) { try { - MatrixStore matrix = PrimitiveDenseStore.FACTORY.makeSPD(dimension); + MatrixStore matrix = Primitive64Store.FACTORY.makeSPD(dimension); MatrixStore expInv = fixed.invert(matrix); diff --git a/test/org/ojalgo/matrix/task/SolverTest.java b/test/org/ojalgo/matrix/task/SolverTest.java index 6dddd5a33..37805006e 100644 --- a/test/org/ojalgo/matrix/task/SolverTest.java +++ b/test/org/ojalgo/matrix/task/SolverTest.java @@ -30,7 +30,7 @@ import org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver; import org.ojalgo.matrix.decomposition.MatrixDecompositionTests; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.task.iterative.ConjugateGradientSolver; import org.ojalgo.matrix.task.iterative.GaussSeidelSolver; import org.ojalgo.matrix.task.iterative.JacobiSolver; @@ -41,10 +41,10 @@ public class SolverTest extends MatrixTaskTests { @Test public void testExampleWikipediA() { - MatrixStore tmpA = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4, 1 }, { 1, 3 } }); - MatrixStore tmpB = PrimitiveDenseStore.FACTORY.columns(new double[] { 1, 2 }); + MatrixStore tmpA = Primitive64Store.FACTORY.rows(new double[][] { { 4, 1 }, { 1, 3 } }); + MatrixStore tmpB = Primitive64Store.FACTORY.columns(new double[] { 1, 2 }); - MatrixStore tmpExpected = PrimitiveDenseStore.FACTORY.columns(new double[] { 1.0 / 11.0, 7.0 / 11.0 }); + MatrixStore tmpExpected = Primitive64Store.FACTORY.columns(new double[] { 1.0 / 11.0, 7.0 / 11.0 }); JacobiSolver tmpJacobiSolver = new JacobiSolver(); TestUtils.assertEquals(tmpExpected, tmpJacobiSolver.solve(tmpA, tmpB).get()); @@ -79,10 +79,10 @@ public void testFull5X5() { @Test public void testLinAlg34PDF() { - MatrixStore tmpA = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4, 2, 3 }, { 3, -5, 2 }, { -2, 3, 8 } }); - MatrixStore tmpB = PrimitiveDenseStore.FACTORY.columns(new double[] { 8, -14, 27 }); + MatrixStore tmpA = Primitive64Store.FACTORY.rows(new double[][] { { 4, 2, 3 }, { 3, -5, 2 }, { -2, 3, 8 } }); + MatrixStore tmpB = Primitive64Store.FACTORY.columns(new double[] { 8, -14, 27 }); - MatrixStore tmpExpected = PrimitiveDenseStore.FACTORY.columns(new double[] { -1, 3, 2 }); + MatrixStore tmpExpected = Primitive64Store.FACTORY.columns(new double[] { -1, 3, 2 }); JacobiSolver tmpJacobiSolver = new JacobiSolver(); TestUtils.assertEquals(tmpExpected, tmpJacobiSolver.solve(tmpA, tmpB).get()); @@ -123,10 +123,10 @@ public void testUnderdeterminedIterative() { int numEqs = 2; int numVars = 5; - PrimitiveDenseStore body = PrimitiveDenseStore.FACTORY.makeZero(numEqs, numVars); - PrimitiveDenseStore rhs = PrimitiveDenseStore.FACTORY.makeZero(numEqs, 1); + Primitive64Store body = Primitive64Store.FACTORY.makeZero(numEqs, numVars); + Primitive64Store rhs = Primitive64Store.FACTORY.makeZero(numEqs, 1); - PrimitiveDenseStore expected = PrimitiveDenseStore.FACTORY.makeZero(numVars, 1); + Primitive64Store expected = Primitive64Store.FACTORY.makeZero(numVars, 1); Random tmpRandom = new Random(); for (int i = 0; i < numEqs; i++) { @@ -153,8 +153,8 @@ private void doCompare(final SolverTask fixed, final int dimension) { try { - MatrixStore body = PrimitiveDenseStore.FACTORY.makeSPD(dimension); - MatrixStore rhs = PrimitiveDenseStore.FACTORY.makeFilled(dimension, 1L, new Uniform()); + MatrixStore body = Primitive64Store.FACTORY.makeSPD(dimension); + MatrixStore rhs = Primitive64Store.FACTORY.makeFilled(dimension, 1L, new Uniform()); MatrixStore expSol = fixed.solve(body, rhs); diff --git a/test/org/ojalgo/netio/NetioTests.java b/test/org/ojalgo/netio/NetioTests.java new file mode 100644 index 000000000..ec7ff3547 --- /dev/null +++ b/test/org/ojalgo/netio/NetioTests.java @@ -0,0 +1,28 @@ +/* + * Copyright 1997-2016 Optimatika (www.optimatika.se) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.netio; + +public abstract class NetioTests { + + static final boolean DEBUG = false; + +} diff --git a/test/org/ojalgo/netio/TestCSV.java b/test/org/ojalgo/netio/TestCSV.java new file mode 100644 index 000000000..128753258 --- /dev/null +++ b/test/org/ojalgo/netio/TestCSV.java @@ -0,0 +1,131 @@ +/* + * Copyright 1997-2016 Optimatika (www.optimatika.se) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.netio; + +import java.io.File; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.jupiter.api.Test; +import org.ojalgo.TestUtils; + +public class TestCSV extends NetioTests { + + static final String[][] EXPECTED = new String[][] { { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }, + { "", "B", "C", "D", "E", "F", "G", "H", "I", "J" }, { "A", "", "C", "D", "E", "F", "G", "H", "I", "J" }, + { "A", "B", "", "D", "E", "F", "G", "H", "I", "J" }, { "A", "B", "C", "", "E", "F", "G", "H", "I", "J" }, + { "A", "B", "C", "D", "", "F", "G", "H", "I", "J" }, { "A", "B", "C", "D", "E", "", "G", "H", "I", "J" }, + { "A", "B", "C", "D", "E", "F", "", "H", "I", "J" }, { "A", "B", "C", "D", "E", "F", "G", "", "I", "J" }, + { "A", "B", "C", "D", "E", "F", "G", "H", "", "J" }, { "A", "B", "C", "D", "E", "F", "G", "H", "I", "" }, + { "", "", "", "", "", "", "", "", "", "" }, { "A", "", "", "", "", "", "", "", "", "" }, { "", "B", "", "", "", "", "", "", "", "" }, + { "", "", "C", "", "", "", "", "", "", "" }, { "", "", "", "D", "", "", "", "", "", "" }, { "", "", "", "", "E", "", "", "", "", "" }, + { "", "", "", "", "", "F", "", "", "", "" }, { "", "", "", "", "", "", "G", "", "", "" }, { "", "", "", "", "", "", "", "H", "", "" }, + { "", "", "", "", "", "", "", "", "I", "" }, { "", "", "", "", "", "", "", "", "", "J" } }; + + public TestCSV() { + super(); + } + + @Test + public void testRFC4180() { + + final AtomicInteger tmpCounter = new AtomicInteger(0); + + final EnumeratedColumnsParser tmpParserFast = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.RFC4180) + .get(); + final EnumeratedColumnsParser tmpParserQuoted = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.RFC4180) + .get(); + final EnumeratedColumnsParser tmpParserRFC4180 = EnumeratedColumnsParser.make(5).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.RFC4180) + .get(); + + final File tmpFileFast = new File("./rsrc/csv/fast.csv"); + final File tmpFileQuoted = new File("./rsrc/csv/quoted.csv"); + final File tmpFileExample = new File("./rsrc/csv/example.csv"); + + tmpCounter.set(0); + tmpParserFast.parse(tmpFileFast, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + final String[] tmpStrings = EXPECTED[tmpRowIndex]; + for (int i = 0; i < 10; i++) { + final String tmpExpected = tmpStrings[i]; + final String tmpActual = t.get(i); + TestUtils.assertEquals(tmpExpected, tmpActual); + } + }); + TestUtils.assertEquals(22, tmpCounter.get()); + + tmpCounter.set(0); + tmpParserQuoted.parse(tmpFileQuoted, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + for (int i = 0; i < 10; i++) { + TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); + } + }); + TestUtils.assertEquals(22, tmpCounter.get()); + + final String[][] tmpExpected = new String[][] { { "Year", "Make", "Model", "Description", "Price" }, + { "1997", "Ford", "E350", "ac, abs, moon", "3000.00" }, { "1999", "Chevy", "Venture \"Extended Edition\"", "", "4900.00" }, + { "1996", "Jeep", "Grand Cherokee", "MUST SELL!\nair, moon roof, loaded", "4799.00" }, + { "1999", "Chevy", "Venture \"Extended Edition, Very Large\"", "", "5000.00" }, { "", "", "Venture \"Extended Edition\"", "", "4900.00" } }; + + tmpCounter.set(0); + tmpParserRFC4180.parse(tmpFileExample, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + for (int i = 0; i < 5; i++) { + TestUtils.assertEquals(tmpExpected[tmpRowIndex][i], t.get(i)); + } + }); + TestUtils.assertEquals(6, tmpCounter.get()); + } + + @Test + public void testFast() { + + final File tmpFile = new File("./rsrc/csv/fast.csv"); + final EnumeratedColumnsParser tmpParser = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.FAST).get(); + + final AtomicInteger tmpCounter = new AtomicInteger(0); + tmpParser.parse(tmpFile, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + for (int i = 0; i < 5; i++) { + TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); + } + }); + TestUtils.assertEquals(22, tmpCounter.get()); + } + + @Test + public void testQuoted() { + + final File tmpFile = new File("./rsrc/csv/quoted.csv"); + final EnumeratedColumnsParser tmpParser = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.QUOTED).get(); + + final AtomicInteger tmpCounter = new AtomicInteger(0); + tmpParser.parse(tmpFile, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + for (int i = 0; i < 5; i++) { + TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); + } + }); + TestUtils.assertEquals(22, tmpCounter.get()); + } + +} diff --git a/test/org/ojalgo/optimisation/convex/ConvexProblems.java b/test/org/ojalgo/optimisation/convex/ConvexProblems.java index 2a76ee5e3..75044cf74 100644 --- a/test/org/ojalgo/optimisation/convex/ConvexProblems.java +++ b/test/org/ojalgo/optimisation/convex/ConvexProblems.java @@ -36,11 +36,11 @@ import org.ojalgo.function.constant.BigMath; import org.ojalgo.function.multiary.MultiaryFunction.TwiceDifferentiable; import org.ojalgo.function.multiary.QuadraticFunction; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.matrix.RationalMatrix; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.matrix.store.RawStore; import org.ojalgo.netio.BasicLogger; import org.ojalgo.optimisation.Expression; @@ -60,12 +60,12 @@ public class ConvexProblems extends OptimisationConvexTests { public static ExpressionsBasedModel buildP20080117() { // create expected returns matrix - PrimitiveMatrix tmpReturns = PrimitiveMatrix.FACTORY.rows(new double[][] { { -0.007155942261937039 }, { -0.003665887902733331 }, + Primitive64Matrix tmpReturns = Primitive64Matrix.FACTORY.rows(new double[][] { { -0.007155942261937039 }, { -0.003665887902733331 }, { -0.004130184341000032 }, { -0.005639860515211043 }, { 0.0007211966666666817 }, { 0.0003258225000000077 }, { -0.005754291666666666 }, { -0.004264291666666667 }, { -0.0017500000000000003 } }); // create covariance matrix - PrimitiveMatrix tmpCovariances = PrimitiveMatrix.FACTORY.rows(new double[][] { + Primitive64Matrix tmpCovariances = Primitive64Matrix.FACTORY.rows(new double[][] { { 0.001561410465201063, 0.00006366128201274021, -0.0001323096896759724, 0.0000909074052724909, 0.00003172000033558704, 0.00001955483223848944, -0.00013771504482647386, -0.00004858457275314645, -0.000012954723060403266 }, { 0.00006366128201274021, 0.00016419786524761803, -0.00001566288911558343, -0.00008688646089751923, 0.0000027349925543017186, @@ -118,15 +118,15 @@ public static ExpressionsBasedModel buildP20080117() { return model; } - private static void builAndTestModel(final PrimitiveDenseStore[] matrices, final double[] expectedSolution, final NumberContext modelValidationContext, + private static void builAndTestModel(final Primitive64Store[] matrices, final double[] expectedSolution, final NumberContext modelValidationContext, final boolean testSolverDirectly) { - PrimitiveDenseStore tmpExpectedSolution = PrimitiveDenseStore.FACTORY.columns(expectedSolution); + Primitive64Store tmpExpectedSolution = Primitive64Store.FACTORY.columns(expectedSolution); ConvexProblems.builAndTestModel(matrices, tmpExpectedSolution, modelValidationContext, testSolverDirectly); } - static void builAndTestModel(final PrimitiveDenseStore[] matrices, final PrimitiveDenseStore expectedSolution, final NumberContext modelValidationContext, + static void builAndTestModel(final Primitive64Store[] matrices, final Primitive64Store expectedSolution, final NumberContext modelValidationContext, final boolean testSolverDirectly) { MatrixStore partQ = expectedSolution.transpose().multiply(matrices[2].multiply(expectedSolution)); @@ -149,7 +149,7 @@ static void builAndTestModel(final PrimitiveDenseStore[] matrices, final Primiti // When/if the correct/optimal solution is used to kickStart ojAlgo should return that solution Result initialisedModelResult = initialisedModel.minimise(); TestUtils.assertStateNotLessThanOptimal(initialisedModelResult); - TestUtils.assertEquals(expectedResult, initialisedModelResult, modelValidationContext); + TestUtils.assertStateAndSolution(expectedResult, initialisedModelResult, modelValidationContext); TestUtils.assertEquals(expectedValue, initialisedModelResult.getValue(), modelValidationContext); TestUtils.assertEquals(expectedValue, initialisedModel.objective().evaluate(initialisedModelResult).doubleValue(), modelValidationContext); TestUtils.assertEquals(expectedValue, initialisedModel.objective().toFunction().invoke(expectedSolution).doubleValue(), modelValidationContext); @@ -166,7 +166,7 @@ static void builAndTestModel(final PrimitiveDenseStore[] matrices, final Primiti Result uninitialisedModelResult = uninitialisedModel.minimise(); TestUtils.assertStateNotLessThanOptimal(uninitialisedModelResult); - TestUtils.assertEquals(expectedResult, uninitialisedModelResult, modelValidationContext); + TestUtils.assertEquals((Access1D) expectedResult, (Access1D) uninitialisedModelResult, modelValidationContext); TestUtils.assertEquals(expectedValue, uninitialisedModelResult.getValue(), modelValidationContext); TestUtils.assertEquals(expectedValue, uninitialisedModel.objective().evaluate(uninitialisedModelResult).doubleValue(), modelValidationContext); TestUtils.assertEquals(expectedValue, uninitialisedModel.objective().toFunction().invoke(expectedSolution).doubleValue(), modelValidationContext); @@ -180,7 +180,7 @@ static void builAndTestModel(final PrimitiveDenseStore[] matrices, final Primiti Optimisation.Result tmpResult = tmpSolver.solve(); TestUtils.assertStateNotLessThanOptimal(tmpResult); - TestUtils.assertEquals(expectedResult, tmpResult, NumberContext.getGeneral(2, 4)); + TestUtils.assertEquals((Access1D) expectedResult, (Access1D) tmpResult, NumberContext.getGeneral(2, 4)); TestUtils.assertEquals(expectedValue, uninitialisedModel.objective().evaluate(tmpResult).doubleValue(), NumberContext.getGeneral(4, 8)); } } @@ -188,7 +188,7 @@ static void builAndTestModel(final PrimitiveDenseStore[] matrices, final Primiti /** * Build model, and initialise variable values to the expected solution */ - static ExpressionsBasedModel buildModel(final PrimitiveDenseStore[] matrices, final PrimitiveDenseStore expectedSolution) { + static ExpressionsBasedModel buildModel(final Primitive64Store[] matrices, final Primitive64Store expectedSolution) { ExpressionsBasedModel retVal = new ExpressionsBasedModel(); @@ -339,11 +339,11 @@ public void testP20080117() { public void testP20080118() { // create expected returns matrix - PrimitiveMatrix expectedReturnsMatrix = PrimitiveMatrix.FACTORY.rows(new double[][] { { 10.003264 }, { 9.989771 }, { 9.987513 }, { 9.988449 }, + Primitive64Matrix expectedReturnsMatrix = Primitive64Matrix.FACTORY.rows(new double[][] { { 10.003264 }, { 9.989771 }, { 9.987513 }, { 9.988449 }, { 9.996579 }, { 9.990690 }, { 9.994904 }, { 9.994514 }, { 9.984064 }, { 9.987534 } }); // create covariance matrix - PrimitiveMatrix covarianceMatrix = PrimitiveMatrix.FACTORY.rows(new double[][] { + Primitive64Matrix covarianceMatrix = Primitive64Matrix.FACTORY.rows(new double[][] { { 6.483565230120298E-4, -1.3344603795915894E-4, -4.610345510893708E-4, -7.334405624030001E-4, 1.1551383115707195E-5, -0.00104145662863434, -1.0725896685568462E-4, -1.221384153392056E-4, -4.173413644389791E-4, -2.4861043894946935E-4 }, { -1.3344603795915894E-4, 0.0026045957224784455, 0.0012394355327235707, 9.243919166568456E-4, -8.653805945112411E-5, 8.100239312410631E-4, @@ -420,10 +420,10 @@ public void testP20080118() { @Test public void testP20080124() { // create expected returns matrix - PrimitiveMatrix expectedReturnsMatrix = PrimitiveMatrix.FACTORY.rows(new double[][] { { 10.012158 }, { 9.996046 }, { 10.000744 }, { 9.990585 }, + Primitive64Matrix expectedReturnsMatrix = Primitive64Matrix.FACTORY.rows(new double[][] { { 10.012158 }, { 9.996046 }, { 10.000744 }, { 9.990585 }, { 9.998392 }, { 9.996614 }, { 10.010531 }, { 10.001401 }, { 9.997447 }, { 9.993817 }, { 9.998537 }, { 9.995741 }, { 9.987224 }, { 9.992392 } }); // create covariance matrix - PrimitiveMatrix covarianceMatrix = PrimitiveMatrix.FACTORY.rows(new double[][] { + Primitive64Matrix covarianceMatrix = Primitive64Matrix.FACTORY.rows(new double[][] { { 0.0013191354374342357, 7.786471466322114E-5, -3.810886655309235E-5, -2.28102405899103E-4, -1.2589115740653127E-4, -1.3247692268411991E-5, 1.422624656557158E-4, -2.7176361887359125E-5, 8.675127894495302E-5, -8.116577287090551E-5, -8.468380774247271E-6, 4.930080166695193E-5, -2.774138231533918E-4, -3.148322898570031E-5 }, @@ -526,10 +526,10 @@ public void testP20080124() { public void testP20080204() { // create expected returns matrix - PrimitiveMatrix tmpExpectedReturns = PrimitiveMatrix.FACTORY.rows(new double[][] { { 9.994620 }, { 10.011389 }, { 10.004353 }, { 9.998293 }, + Primitive64Matrix tmpExpectedReturns = Primitive64Matrix.FACTORY.rows(new double[][] { { 9.994620 }, { 10.011389 }, { 10.004353 }, { 9.998293 }, { 10.056851 }, { 9.997920 }, { 9.999011 }, { 10.050971 }, { 9.989124 }, { 9.989912 } }); // create covariance matrix - PrimitiveMatrix tmpCovariances = PrimitiveMatrix.FACTORY.rows(new double[][] { + Primitive64Matrix tmpCovariances = Primitive64Matrix.FACTORY.rows(new double[][] { { 0.014531344652473037, 4.444675045533674E-4, 0.007234717654072837, -9.455312097865225E-4, 0.0016345464996349748, 1.5256808879495097E-4, 0.00226325818749439, 0.003534367267672946, -4.2669306842991344E-5, 6.902267133060073E-5 }, { 4.444675045533674E-4, 0.008511422662647488, 0.0039821105759899845, 5.543408872612397E-4, -0.0015797828516888929, 1.3505400134130176E-4, @@ -608,11 +608,11 @@ public void testP20080204() { public void testP20080208() { // create expected returns matrix - PrimitiveMatrix tmpExpectedReturns = PrimitiveMatrix.FACTORY.rows(new double[][] { { 9.997829 }, { 10.008909 }, { 10.010849 }, { 9.998919 }, + Primitive64Matrix tmpExpectedReturns = Primitive64Matrix.FACTORY.rows(new double[][] { { 9.997829 }, { 10.008909 }, { 10.010849 }, { 9.998919 }, { 10.055549 }, { 9.999127 }, { 9.999720 }, { 10.049002 }, { 9.988769 }, { 9.990095 } }); // create covariance matrix - PrimitiveMatrix tmpCovariances = PrimitiveMatrix.FACTORY.rows(new double[][] { + Primitive64Matrix tmpCovariances = Primitive64Matrix.FACTORY.rows(new double[][] { { 0.014661954677318977, 3.459112088561122E-4, 0.007798752920910871, 0.0020921425081866503, 0.001846944297640248, 1.0531906931335766E-4, -2.7515614291198E-4, 0.0034083900074454894, 1.1859491261103433E-4, -0.0027421673864628264 }, { 3.459112088561122E-4, 0.008695862475003915, 0.004154360841751649, -2.661685231819661E-4, -0.0015999007544258263, 3.590680217774603E-4, @@ -695,10 +695,10 @@ public void testP20080208() { @Test public void testP20080819() { - PrimitiveMatrix.Factory tmpMtrxFact = PrimitiveMatrix.FACTORY; + Primitive64Matrix.Factory tmpMtrxFact = Primitive64Matrix.FACTORY; NumberContext tmpEvalCntxt = StandardType.DECIMAL_032; - PrimitiveMatrix[] tmpMatrices = new PrimitiveMatrix[8]; + Primitive64Matrix[] tmpMatrices = new Primitive64Matrix[8]; tmpMatrices[0] = tmpMtrxFact.rows(new double[][] { { 1.0, 1.0, 1.0, 1.0 } }); tmpMatrices[1] = tmpMtrxFact.rows(new double[][] { { 1.0 } }); @@ -719,9 +719,9 @@ public void testP20080819() { for (int i = 0; i < retVal.length; i++) { if (tmpMatrices[i] != null) { if (i == 3) { - retVal[i] = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[i].negate()); + retVal[i] = Primitive64Store.FACTORY.copy(tmpMatrices[i].negate()); } else { - retVal[i] = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[i]); + retVal[i] = Primitive64Store.FACTORY.copy(tmpMatrices[i]); } } } @@ -768,9 +768,9 @@ public void testP20080819() { @Test public void testP20081014() { - PhysicalStore.Factory tmpFactory = PrimitiveDenseStore.FACTORY; + PhysicalStore.Factory tmpFactory = Primitive64Store.FACTORY; - PrimitiveDenseStore[] tmpSystem = new PrimitiveDenseStore[6]; + Primitive64Store[] tmpSystem = new Primitive64Store[6]; // {[AE], [BE], [Q], [C], [AI], [BI]} tmpSystem[0] = tmpFactory.rows(new double[][] { @@ -780,7 +780,7 @@ public void testP20081014() { { -7.646043242556307E-15, -107.21808503782593, -97.434268076846, 30.0, -11.54276933307617, 7.647488207332634, 0.0, 0, 1.0 } }); // AE tmpSystem[1] = tmpFactory.rows(new double[][] { { 10.461669614447484 }, { -0.5328532701990767 }, { 15.782527136201711 } }); // BE - PrimitiveDenseStore tmpQ = tmpFactory.makeEye(9, 9); + Primitive64Store tmpQ = tmpFactory.makeEye(9, 9); tmpQ.set(3, 3, 10); tmpQ.set(4, 4, 10); tmpQ.set(5, 5, 10); @@ -801,7 +801,7 @@ public void testP20081014() { tmpSystem[5] = tmpFactory.rows(new double[][] { { 0 }, { 0.0175 }, { 0.0175 }, { 5 }, { 5 }, { 5 }, { 100000 }, { 100000 }, { 100000 }, { 0 }, { 0.0175 }, { 0.0175 }, { 5 }, { 5 }, { 5 }, { 100000 }, { 100000 }, { 100000 } }); // BI - PrimitiveDenseStore tmpMatlabSolution = tmpFactory.columns(new double[] { 0.00000000000000, -0.01750000000000, -0.01750000000000, 0.88830035195990, + Primitive64Store tmpMatlabSolution = tmpFactory.columns(new double[] { 0.00000000000000, -0.01750000000000, -0.01750000000000, 0.88830035195990, 4.56989525276369, 5.00000000000000, 0.90562154243124, -1.91718419629399, 0.06390614020590 }); // Compare to MatLab using 2 digits and 6 decimal places @@ -825,9 +825,9 @@ public void testP20081014() { @Test public void testP20081015() { - PhysicalStore.Factory tmpFactory = PrimitiveDenseStore.FACTORY; + PhysicalStore.Factory tmpFactory = Primitive64Store.FACTORY; - PrimitiveDenseStore[] tmpSystem = new PrimitiveDenseStore[6]; + Primitive64Store[] tmpSystem = new Primitive64Store[6]; // {[AE], [BE], [Q], [C], [AI], [BI]} tmpSystem[0] = tmpFactory.rows(new double[][] { @@ -854,7 +854,7 @@ public void testP20081015() { tmpSystem[5] = tmpFactory.rows(new double[][] { { 0 }, { 0.0175 }, { 0.0175 }, { 0.5 }, { 0.5 }, { 0.5 }, { 100000 }, { 100000 }, { 100000 }, { 0 }, { 0.0175 }, { 0.0175 }, { 0.5 }, { 0.5 }, { 0.5 }, { 100000 }, { 100000 }, { 100000 } }); // BI - PrimitiveDenseStore tmpMatlabSolution = tmpFactory.columns(new double[] { -0.00000000000000, -0.01750000000000, 0.01750000000000, 0.13427356981778, + Primitive64Store tmpMatlabSolution = tmpFactory.columns(new double[] { -0.00000000000000, -0.01750000000000, 0.01750000000000, 0.13427356981778, 0.50000000000000, -0.14913060410765, 0.06986475572103, -0.08535020176844, 0.00284500680371 }); // Compare to MatLab using 2 digits and 6 decimal places @@ -879,9 +879,9 @@ public void testP20081015() { @Test public void testP20081119() { - PhysicalStore.Factory tmpFactory = PrimitiveDenseStore.FACTORY; + PhysicalStore.Factory tmpFactory = Primitive64Store.FACTORY; - PrimitiveDenseStore[] tmpSystem = new PrimitiveDenseStore[6]; + Primitive64Store[] tmpSystem = new Primitive64Store[6]; // {[AE], [BE], [Q], [C], [AI], [BI]} tmpSystem[0] = tmpFactory.rows(new double[][] { @@ -909,7 +909,7 @@ public void testP20081119() { tmpSystem[5] = tmpFactory.rows(new double[][] { { 0 }, { 0.0175 }, { 0.0175 }, { 5 }, { 5 }, { 5 }, { 100000 }, { 100000 }, { 100000 }, { 0 }, { 0.0175 }, { 0.0175 }, { 5 }, { 5 }, { 5 }, { 100000 }, { 100000 }, { 100000 } }); // BI - PrimitiveDenseStore tmpMatlabSolution = tmpFactory.columns(new double[] { 0.00000000000000, 0.01750000000000, -0.01750000000000, 1.46389524463679, + Primitive64Store tmpMatlabSolution = tmpFactory.columns(new double[] { 0.00000000000000, 0.01750000000000, -0.01750000000000, 1.46389524463679, 5.00000000000000, 4.87681260745493, 4.45803387299108, -6.77235264210831, 0.22574508859158 }); ConvexProblems.builAndTestModel(tmpSystem, tmpMatlabSolution, NumberContext.getGeneral(2, 14), false); @@ -925,9 +925,9 @@ public void testP20090115() { MatrixStore[] tmpMtrxs = new MatrixStore[6]; - tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 } }); - tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 } }); - tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { + tmpMtrxs[0] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 } }); + tmpMtrxs[1] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 } }); + tmpMtrxs[2] = Primitive64Store.FACTORY.rows(new double[][] { { 3.048907897157133E-4, 1.6671472561019247E-4, 4.4500080981934345E-4, -5.389129745055723E-4, -2.6090705011393183E-4, -1.2633284900760366E-4, -6.485428846447651E-7 }, { 1.6671472561019247E-4, 2.341985572849691E-4, 2.9113916450678265E-4, -4.5760873539850514E-4, 1.3078636134987255E-5, -2.354289901013046E-5, @@ -942,17 +942,17 @@ public void testP20090115() { -7.02099350897589E-8 }, { -6.485428846447651E-7, -7.578030042426654E-7, -8.293698990696063E-7, 1.0252846778608953E-7, 2.4953495129362833E-8, -7.02099350897589E-8, 8.367244992498656E-9 } }); - tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -0.010638291263564232 }, { -0.013500370827906071 }, { -0.011390037735101773 }, + tmpMtrxs[3] = Primitive64Store.FACTORY.rows(new double[][] { { -0.010638291263564232 }, { -0.013500370827906071 }, { -0.011390037735101773 }, { -0.010385042339767682 }, { -3.812208389845893E-4 }, { -0.002315505853720011 }, { -0.0 } }); - tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, + tmpMtrxs[4] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 } }).transpose(); - tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 0.0 }, { 0.0 }, - { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); + tmpMtrxs[5] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 0.0 }, { 0.0 }, { 0.0 }, + { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs); @@ -960,7 +960,7 @@ public void testP20090115() { Optimisation.Result tmpResult = tmpSolver.solve(); - TestUtils.assertBounds(BigMath.ZERO, tmpResult, BigMath.ONE, StandardType.PERCENT); + TestUtils.assertBounds(BigMath.ZERO, (Access1D) tmpResult, BigMath.ONE, StandardType.PERCENT); OptimisationConvexTests.assertDirectAndIterativeEquals(tmpBuilder, null, null); } @@ -978,12 +978,12 @@ public void testP20090202() { tmpMtrxs[0] = null; tmpMtrxs[1] = null; - tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 }, + tmpMtrxs[2] = Primitive64Store.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 }, { 5.429710780966787, 23.181215288234903, 27.883770791602895 }, { 5.910932781021423, 27.883770791602895, 34.37266787775051 } }); - tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } }); - tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 }, + tmpMtrxs[3] = Primitive64Store.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } }); + tmpMtrxs[4] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 }, { -1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, -1.0 } }); - tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { 0.0 }, { 0.0 }, { 0.0 } }); + tmpMtrxs[5] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { 0.0 }, { 0.0 }, { 0.0 } }); ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs); @@ -1013,18 +1013,18 @@ public void testP20090924() { MatrixStore[] tmpMtrxs = new MatrixStore[6]; - tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } }); - tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 0.7027946085029227 } }); - tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, + tmpMtrxs[0] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } }); + tmpMtrxs[1] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 }, { 0.7027946085029227 } }); + tmpMtrxs[2] = Primitive64Store.FACTORY.rows(new double[][] { { 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0 } }); - tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -0.0 }, { 0.5 }, { 0.25 }, { 0.25 }, { 0.3 }, { -0.0 }, { 0.62 } }); - tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, { 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 }, + tmpMtrxs[3] = Primitive64Store.FACTORY.rows(new double[][] { { -0.0 }, { 0.5 }, { 0.25 }, { 0.25 }, { 0.3 }, { -0.0 }, { 0.62 } }); + tmpMtrxs[4] = Primitive64Store.FACTORY.rows(new double[][] { { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, { 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }, { 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 } }); - tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.17 }, { 0.52 }, { 0.3 }, { 0.3 }, { 0.3 }, { 0.15 }, { 1.0 }, { 0.31 }, + tmpMtrxs[5] = Primitive64Store.FACTORY.rows(new double[][] { { 0.17 }, { 0.52 }, { 0.3 }, { 0.3 }, { 0.3 }, { 0.15 }, { 1.0 }, { 0.31 }, { -0.05960220972942152 }, { -0.1144024630877301 }, { -0.12289286964304823 }, { 0.0 }, { -0.02 }, { 0.0 } }); ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs); @@ -1049,14 +1049,14 @@ public void testP20091102a() { MatrixStore[] tmpMtrxs = new MatrixStore[6]; - tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0 } }); - tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 } }); - tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 }, + tmpMtrxs[0] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0 } }); + tmpMtrxs[1] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 } }); + tmpMtrxs[2] = Primitive64Store.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 }, { 5.429710780966787, 23.181215288234903, 27.883770791602895 }, { 5.910932781021423, 27.883770791602895, 34.37266787775051 } }); - tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } }); - tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 }, + tmpMtrxs[3] = Primitive64Store.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } }); + tmpMtrxs[4] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 }, { -1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, -1.0 } }); - tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { 0.0 }, { 0.0 }, { 0.0 } }); + tmpMtrxs[5] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { 0.0 }, { 0.0 }, { 0.0 } }); // Solve the same problem several times for (int i = 0; i < 20; i++) { @@ -1069,7 +1069,7 @@ public void testP20091102a() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - TestUtils.assertEquals(PrimitiveMatrix.FACTORY.rows(new double[][] { { 0.68888888888888888 }, { 0.311111111111111111 }, { 0.0 } }), + TestUtils.assertEquals(Primitive64Matrix.FACTORY.rows(new double[][] { { 0.68888888888888888 }, { 0.311111111111111111 }, { 0.0 } }), RationalMatrix.FACTORY.columns(tmpResult)); } } @@ -1083,14 +1083,14 @@ public void testP20091102b() { MatrixStore[] tmpMtrxs = new MatrixStore[6]; - tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0 } }); - tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 } }); - tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 }, + tmpMtrxs[0] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0 } }); + tmpMtrxs[1] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 } }); + tmpMtrxs[2] = Primitive64Store.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 }, { 5.429710780966787, 23.181215288234903, 27.883770791602895 }, { 5.910932781021423, 27.883770791602895, 34.37266787775051 } }); - tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } }); - tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 }, + tmpMtrxs[3] = Primitive64Store.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } }); + tmpMtrxs[4] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 }, { -1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, -1.0 } }); - tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { -0.8 }, { 0.0 }, { 0.0 } }); + tmpMtrxs[5] = Primitive64Store.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { -0.8 }, { 0.0 }, { 0.0 } }); ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs); @@ -1190,10 +1190,10 @@ public void testP20111129() { @Test public void testP20111205() { - PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0 }, + Primitive64Store tmpAE = Primitive64Store.FACTORY.rows(new double[][] { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0 }, { 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 0.0 } }); - PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 } }); - PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][] { + Primitive64Store tmpBE = Primitive64Store.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 } }); + Primitive64Store tmpQ = Primitive64Store.FACTORY.rows(new double[][] { { 42.58191012032541, -42.58191012032541, 0.0, 0.0, 0.029666091804595635, -0.029666091804595635, 0.0, 0.0, 9.954580659495097, -9.954580659495097, 0.0, 0.0 }, { -42.58191012032541, 42.58191012032541, 0.0, 0.0, -0.029666091804595635, 0.029666091804595635, 0.0, 0.0, -9.954580659495097, 9.954580659495097, @@ -1209,24 +1209,24 @@ public void testP20111205() { { -9.954580659495097, 9.954580659495097, 0.0, 0.0, 3.537087573378497, -3.537087573378497, 0.0, 0.0, -153.76101274121527, 153.76101274121527, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } }); - PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows( + Primitive64Store tmpC = Primitive64Store.FACTORY.rows( new double[][] { { 185.8491751747291 }, { -192.3021967647291 }, { -6.45302159 }, { -6.45302159 }, { 406.4118818820076 }, { -409.5778277520076 }, { -3.16594587 }, { -3.16594587 }, { -352.0970015985486 }, { 339.11043506854867 }, { -12.986566530000001 }, { -12.986566530000001 } }); - PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, + Primitive64Store tmpAI = Primitive64Store.FACTORY.rows(new double[][] { { -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 } }); - PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY + Primitive64Store tmpBI = Primitive64Store.FACTORY .rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); // Optimisation.Result from CPLEX (via ExpressionsBasedModel) double[] tmpExpected = new double[] { 1.7856570552, 1.216415374E-5, 1.78565097263, 6.08157995E-6, 495.426247828, 2.478968927E-5, 495.426235433, 1.239483719E-5, 8.90673094088, 6.04347562E-6, 8.90672791911, 3.02171321E-6 }; - PrimitiveDenseStore[] tmpMatrices = new PrimitiveDenseStore[6]; + Primitive64Store[] tmpMatrices = new Primitive64Store[6]; tmpMatrices[0] = tmpAE; tmpMatrices[1] = tmpBE; tmpMatrices[2] = tmpQ; @@ -1256,14 +1256,14 @@ public void testP20111205() { @Test public void testP20140109() { - PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, 0 }, { 0, 1 } }); - PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0, 0 } }); + Primitive64Store tmpQ = Primitive64Store.FACTORY.rows(new double[][] { { 1, 0 }, { 0, 1 } }); + Primitive64Store tmpC = Primitive64Store.FACTORY.rows(new double[][] { { 0, 0 } }); - PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, 1 } }); - PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1 } }); + Primitive64Store tmpAE = Primitive64Store.FACTORY.rows(new double[][] { { 1, 1 } }); + Primitive64Store tmpBE = Primitive64Store.FACTORY.rows(new double[][] { { 1 } }); - PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -1, 0 }, { 0, -1 } }); - PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0 }, { 0 } }); + Primitive64Store tmpAI = Primitive64Store.FACTORY.rows(new double[][] { { -1, 0 }, { 0, -1 } }); + Primitive64Store tmpBI = Primitive64Store.FACTORY.rows(new double[][] { { 0 }, { 0 } }); try { @@ -1349,8 +1349,8 @@ public void testP20140522() { tmpObj.invoke(Access1D.wrap(expectedSolution)); tmpObj.invoke(Access1D.asPrimitive1D(result)); - JamaBI.subtract(JamaAI.multiply(PrimitiveDenseStore.FACTORY.columns(expectedSolution))); - JamaBI.subtract(JamaAI.multiply(PrimitiveDenseStore.FACTORY.columns(result))); + JamaBI.subtract(JamaAI.multiply(Primitive64Store.FACTORY.columns(expectedSolution))); + JamaBI.subtract(JamaAI.multiply(Primitive64Store.FACTORY.columns(result))); for (int i = 0; i < numElm; i++) { TestUtils.assertEquals(expectedSolution[i], result.doubleValue(i), 1e-4); @@ -1409,7 +1409,7 @@ public void testP20150720() { TestUtils.assertEquals("Model 1 State @" + l, baseResult1.getState(), tmpResult1.getState()); TestUtils.assertEquals("Model 1 Value @" + l, baseResult1.getValue(), tmpResult1.getValue()); - TestUtils.assertEquals("Model 1 Solution @" + l, baseResult1, tmpResult1); + TestUtils.assertStateAndSolution("Model 1 Solution @" + l, baseResult1, tmpResult1); Result tmpResult2 = model2.maximise(); @@ -1424,7 +1424,7 @@ public void testP20150720() { TestUtils.assertEquals("Model 2 State @" + l, baseResult2.getState(), tmpResult2.getState()); TestUtils.assertEquals("Model 2 Value @" + l, baseResult2.getValue(), tmpResult2.getValue()); - TestUtils.assertEquals("Model 2 Solution @" + l, baseResult2, tmpResult2); + TestUtils.assertStateAndSolution("Model 2 Solution @" + l, baseResult2, tmpResult2); Result tmpResult3 = model3.maximise(); @@ -1439,7 +1439,8 @@ public void testP20150720() { TestUtils.assertEquals("Model 3 State @" + l, baseResult3.getState(), tmpResult3.getState()); TestUtils.assertEquals("Model 3 Value @" + l, baseResult3.getValue(), tmpResult3.getValue()); - TestUtils.assertEquals("Model 3 Solution @" + l, baseResult3, tmpResult3); + TestUtils.assertEquals("Model 3 Solution @" + l, (Access1D) baseResult3, (Access1D) tmpResult3); + } } @@ -1484,20 +1485,20 @@ public void testP20150809() { @Test public void testP20150908() { - PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2, 0 }, { 0, 2 } }); - PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.columns(new double[] { 0, 0 }); - PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -1, -1 } }); - PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.columns(new double[] { -1 }); + Primitive64Store tmpQ = Primitive64Store.FACTORY.rows(new double[][] { { 2, 0 }, { 0, 2 } }); + Primitive64Store tmpC = Primitive64Store.FACTORY.columns(new double[] { 0, 0 }); + Primitive64Store tmpAI = Primitive64Store.FACTORY.rows(new double[][] { { -1, -1 } }); + Primitive64Store tmpBI = Primitive64Store.FACTORY.columns(new double[] { -1 }); Builder tmpBuilder = new ConvexSolver.Builder(tmpQ, tmpC).inequalities(tmpAI, tmpBI); ConvexSolver tmpSolver = tmpBuilder.build(); Optimisation.Result tmpResult = tmpSolver.solve(); - PrimitiveDenseStore tmpExpectedSolution = PrimitiveDenseStore.FACTORY.columns(new double[] { 0.5, 0.5 }); + Primitive64Store tmpExpectedSolution = Primitive64Store.FACTORY.columns(new double[] { 0.5, 0.5 }); Optimisation.Result tmpExpectedResult = new Optimisation.Result(Optimisation.State.OPTIMAL, 0.5, tmpExpectedSolution); TestUtils.assertStateNotLessThanOptimal(tmpResult); - TestUtils.assertEquals(tmpExpectedResult, tmpResult); + TestUtils.assertStateAndSolution(tmpExpectedResult, tmpResult); OptimisationConvexTests.assertDirectAndIterativeEquals(tmpBuilder, null, null); } @@ -1517,13 +1518,13 @@ public void testP20150908() { @Test public void testP20150922() { - PrimitiveDenseStore Q = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0 }, { 0, 1.0 } }); - PrimitiveDenseStore C = PrimitiveDenseStore.FACTORY.columns(new double[] { 0, 0 }); + Primitive64Store Q = Primitive64Store.FACTORY.rows(new double[][] { { 1.0, 0 }, { 0, 1.0 } }); + Primitive64Store C = Primitive64Store.FACTORY.columns(new double[] { 0, 0 }); ConvexSolver.Builder myBuilderI = new ConvexSolver.Builder(Q, C); - PrimitiveDenseStore AI = PrimitiveDenseStore.FACTORY.rows(new double[] { 1, 1 }); - PrimitiveDenseStore BI = PrimitiveDenseStore.FACTORY.columns(new double[] { 1 }); + Primitive64Store AI = Primitive64Store.FACTORY.rows(new double[] { 1, 1 }); + Primitive64Store BI = Primitive64Store.FACTORY.columns(new double[] { 1 }); myBuilderI.inequalities(AI, BI); @@ -1534,8 +1535,8 @@ public void testP20150922() { BasicLogger.debug(solved); } - PrimitiveDenseStore AI2 = PrimitiveDenseStore.FACTORY.rows(new double[] { 1, 1 }); - PrimitiveDenseStore BI2 = PrimitiveDenseStore.FACTORY.columns(new double[] { 2 }); + Primitive64Store AI2 = Primitive64Store.FACTORY.rows(new double[] { 1, 1 }); + Primitive64Store BI2 = Primitive64Store.FACTORY.columns(new double[] { 2 }); // Discovered that you got (fixed now) a problem if you modify a builder after it has been used to build a solver myBuilderI.inequalities(AI2, BI2); diff --git a/test/org/ojalgo/optimisation/convex/FinancePortfolioProblem.java b/test/org/ojalgo/optimisation/convex/FinancePortfolioProblem.java index a26afa3fa..72dcf9824 100644 --- a/test/org/ojalgo/optimisation/convex/FinancePortfolioProblem.java +++ b/test/org/ojalgo/optimisation/convex/FinancePortfolioProblem.java @@ -29,7 +29,7 @@ import org.ojalgo.ProgrammingError; import org.ojalgo.TestUtils; import org.ojalgo.function.constant.BigMath; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.netio.BasicLogger; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; @@ -41,21 +41,21 @@ public class FinancePortfolioProblem extends OptimisationConvexTests { public static final class P20170508 { - static final PrimitiveMatrix COVARIANCES; - static final PrimitiveMatrix RETURNS; + static final Primitive64Matrix COVARIANCES; + static final Primitive64Matrix RETURNS; static { - PrimitiveMatrix.DenseReceiver mtrxBuilder; + Primitive64Matrix.DenseReceiver mtrxBuilder; - mtrxBuilder = PrimitiveMatrix.FACTORY.makeDense(2, 2); + mtrxBuilder = Primitive64Matrix.FACTORY.makeDense(2, 2); mtrxBuilder.add(0, 0, 0.040000); mtrxBuilder.add(0, 1, 0.1000); mtrxBuilder.add(1, 0, 0.1000); mtrxBuilder.add(1, 1, 0.250000); COVARIANCES = mtrxBuilder.build(); - mtrxBuilder = PrimitiveMatrix.FACTORY.makeDense(2); + mtrxBuilder = Primitive64Matrix.FACTORY.makeDense(2); mtrxBuilder.add(0, 0.20000); mtrxBuilder.add(1, 0.40000); RETURNS = mtrxBuilder.build(); @@ -64,7 +64,7 @@ public static final class P20170508 { } - private static ExpressionsBasedModel buildModel(final PrimitiveMatrix covariances, final PrimitiveMatrix returns, final BigDecimal riskAversion) { + private static ExpressionsBasedModel buildModel(final Primitive64Matrix covariances, final Primitive64Matrix returns, final BigDecimal riskAversion) { ProgrammingError.throwIfNotSquare(covariances); ProgrammingError.throwIfNotEqualRowDimensions(covariances, returns); diff --git a/test/org/ojalgo/optimisation/convex/GenericQPSolverTest.java b/test/org/ojalgo/optimisation/convex/GenericQPSolverTest.java index 7cde552cf..feb6a66ad 100644 --- a/test/org/ojalgo/optimisation/convex/GenericQPSolverTest.java +++ b/test/org/ojalgo/optimisation/convex/GenericQPSolverTest.java @@ -28,7 +28,7 @@ import org.ojalgo.matrix.RationalMatrix; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.structure.Access2D; import org.ojalgo.type.context.NumberContext; @@ -39,15 +39,15 @@ */ public abstract class GenericQPSolverTest extends OptimisationConvexTests { - private PrimitiveDenseStore myAE; - private PrimitiveDenseStore myAI; - private PrimitiveDenseStore myBE; - private PrimitiveDenseStore myBI; - private PrimitiveDenseStore myC; + private Primitive64Store myAE; + private Primitive64Store myAI; + private Primitive64Store myBE; + private Primitive64Store myBI; + private Primitive64Store myC; private final NumberContext myEvaluationContext = new NumberContext(7, 8); - private PrimitiveDenseStore myQ; - private PrimitiveDenseStore myXE; - private PrimitiveDenseStore myXI; + private Primitive64Store myQ; + private Primitive64Store myXE; + private Primitive64Store myXI; public final MatrixStore getSolutionE() { return myXE.copy(); @@ -63,42 +63,42 @@ public void setUp() { final RationalMatrix[] tmpMatrices = this.getMatrices(); if (tmpMatrices[0] != null) { - myAE = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[0]); + myAE = Primitive64Store.FACTORY.copy(tmpMatrices[0]); } else { myAE = null; } if (tmpMatrices[1] != null) { - myBE = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[1]); + myBE = Primitive64Store.FACTORY.copy(tmpMatrices[1]); } else { myBE = null; } if (tmpMatrices[2] != null) { - myQ = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[2]); + myQ = Primitive64Store.FACTORY.copy(tmpMatrices[2]); } else { myQ = null; } if (tmpMatrices[3] != null) { - myC = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[3].negate()); + myC = Primitive64Store.FACTORY.copy(tmpMatrices[3].negate()); } else { myC = null; } if (tmpMatrices[4] != null) { - myAI = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[4]); + myAI = Primitive64Store.FACTORY.copy(tmpMatrices[4]); } else { myAI = null; } if (tmpMatrices[5] != null) { - myBI = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[5]); + myBI = Primitive64Store.FACTORY.copy(tmpMatrices[5]); } else { myBI = null; } if (tmpMatrices[6] != null) { - myXE = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[6]); + myXE = Primitive64Store.FACTORY.copy(tmpMatrices[6]); } else { myXE = null; } if (tmpMatrices[7] != null) { - myXI = PrimitiveDenseStore.FACTORY.copy(tmpMatrices[7]); + myXI = Primitive64Store.FACTORY.copy(tmpMatrices[7]); } else { myXI = null; } @@ -130,11 +130,11 @@ public void testCaseData() { @Test public void testSolverResults() { - final PrimitiveDenseStore[] tmpMatricesI = new PrimitiveDenseStore[] { myAE, myBE, myQ, myC, myAI, myBI }; + final Primitive64Store[] tmpMatricesI = new Primitive64Store[] { myAE, myBE, myQ, myC, myAI, myBI }; ConvexProblems.builAndTestModel(tmpMatricesI, myXI, myEvaluationContext, false); - final PrimitiveDenseStore[] tmpMatricesE = new PrimitiveDenseStore[] { myAE, myBE, myQ, myC, null, null }; + final Primitive64Store[] tmpMatricesE = new Primitive64Store[] { myAE, myBE, myQ, myC, null, null }; ConvexProblems.builAndTestModel(tmpMatricesE, myXE, myEvaluationContext, false); } diff --git a/test/org/ojalgo/optimisation/convex/P20150720.java b/test/org/ojalgo/optimisation/convex/P20150720.java index ee6503243..f9cb29209 100644 --- a/test/org/ojalgo/optimisation/convex/P20150720.java +++ b/test/org/ojalgo/optimisation/convex/P20150720.java @@ -7,7 +7,7 @@ import java.util.Map; import java.util.stream.Collectors; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; @@ -16,13 +16,12 @@ public abstract class P20150720 { - public static PrimitiveDenseStore SOL_1_CPLEX = PrimitiveDenseStore.FACTORY - .columns(new double[] { 399.999999654, 249.999999654, 149.999999654, 0.0, 0.0, 0.0, 0.0, 49.9999996543, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - -0.564712643687, -0.564712643692, -0.564712643701, -0.564712643747, -0.574712643678 }); - public static PrimitiveDenseStore SOL_2_CPLEX = PrimitiveDenseStore.FACTORY + public static Primitive64Store SOL_1_CPLEX = Primitive64Store.FACTORY.columns(new double[] { 399.999999654, 249.999999654, 149.999999654, 0.0, 0.0, 0.0, + 0.0, 49.9999996543, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.564712643687, -0.564712643692, -0.564712643701, -0.564712643747, -0.574712643678 }); + public static Primitive64Store SOL_2_CPLEX = Primitive64Store.FACTORY .columns(new double[] { 22988.5054745, 14367.8158165, 8620.68937468, 0.0, 0.0, 0.0, 0.0, 2873.56291279, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }); - public static PrimitiveDenseStore SOL_3_CPLEX = PrimitiveDenseStore.FACTORY.columns(new double[] { 74542.7288388, 48961.3064461, 13408.93322, 40061.705994, - 0.0, 40061.705994, 13408.93322, 0.0, 7.04812228046, 2773.81908243, 2773.81908243, 0.0, 0.0, 0.0, 11604.5308488, 12395.4691449, 4339.53410099, + public static Primitive64Store SOL_3_CPLEX = Primitive64Store.FACTORY.columns(new double[] { 74542.7288388, 48961.3064461, 13408.93322, 40061.705994, 0.0, + 40061.705994, 13408.93322, 0.0, 7.04812228046, 2773.81908243, 2773.81908243, 0.0, 0.0, 0.0, 11604.5308488, 12395.4691449, 4339.53410099, 7660.46589271, 78.8113907425, 221.188602961, 11604.5308488, 12395.4691449, 10813.3798123, 0.0, 9186.62018135, 0.0, 11999.9999937, 0.0, 0.0, 4339.53410099, 7660.46589271, 0.0, 0.0, 47953.0468934, 24046.9531003, 0.0, 0.0, 14244.4816129, 13755.5183808, 12395.4691449, 0.0, 11604.5308488, 0.0, 0.0, 0.0, 6679.71873106, 9320.28126264, 12395.4691449, 0.0, 11604.5308488, 0.0, 55999.9999937 }); diff --git a/test/org/ojalgo/optimisation/integer/MarketShareCase.java b/test/org/ojalgo/optimisation/integer/MarketShareCase.java index c7204975f..39b55faa2 100644 --- a/test/org/ojalgo/optimisation/integer/MarketShareCase.java +++ b/test/org/ojalgo/optimisation/integer/MarketShareCase.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.netio.BasicLogger; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; @@ -267,7 +267,7 @@ public void testRelaxedButIntegerConstrainedToOptimal() { @Disabled("Underscored before JUnit 5") public void testSpecificBranch_20_25() { - final PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][] { + final Primitive64Store tmpAE = Primitive64Store.FACTORY.rows(new double[][] { { 0.88, 0.59, 1.0, 0.16, 0.7, 0.7, 0.12, 0.66, 0.85, 0.68, 0.97, 0.33, 0.87, 0.01, 0.6, 0.5, 0.85, 0.09, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 3.0, 0.7, 3.6, 7.3, 1.9, 1.5, 8.1, 5.5, 3.2, 5.3, 4.3, 2.1, 5.9, 5.7, 4.8, 2.8, 9.7, 4.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, @@ -315,13 +315,13 @@ public void testSpecificBranch_20_25() { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 } }); - final PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY + final Primitive64Store tmpBE = Primitive64Store.FACTORY .rows(new double[][] { { 4.49 }, { 18.5 }, { 41.5 }, { 3.44 }, { 33.2 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 } }); - final PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, + final Primitive64Store tmpC = Primitive64Store.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, - { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); + { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); final LinearSolver.Builder tmpBuilder = new LinearSolver.Builder(tmpC); tmpBuilder.equalities(tmpAE, tmpBE); @@ -345,7 +345,7 @@ public void testSpecificBranch_20_25() { @Test public void testSpecificBranch_37_8() { - final PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY + final Primitive64Store tmpAE = Primitive64Store.FACTORY .rows(new double[][] { { 0.87, 0.01, 0.6, 0.5, 0.85, 0.86, 0.09, 0.86, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 5.9, 5.7, 4.8, 2.8, 9.7, 5.8, 4.4, 3.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 1.9, 4.6, 3.1, 2.4, 8.5, 8.5, 7.4, 1.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, @@ -360,11 +360,11 @@ public void testSpecificBranch_37_8() { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 } }); - final PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows( + final Primitive64Store tmpBE = Primitive64Store.FACTORY.rows( new double[][] { { 2.24 }, { 20.2 }, { 17.4 }, { 0.73 }, { 25.2 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 } }); - final PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, - { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); + final Primitive64Store tmpC = Primitive64Store.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, + { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); final LinearSolver.Builder tmpBuilder = new LinearSolver.Builder(tmpC); tmpBuilder.equalities(tmpAE, tmpBE); diff --git a/test/org/ojalgo/optimisation/integer/NextGenSysModTest.java b/test/org/ojalgo/optimisation/integer/NextGenSysModTest.java index a05a4bfab..505fc725e 100644 --- a/test/org/ojalgo/optimisation/integer/NextGenSysModTest.java +++ b/test/org/ojalgo/optimisation/integer/NextGenSysModTest.java @@ -31,7 +31,7 @@ import org.ojalgo.function.aggregator.Aggregator; import org.ojalgo.function.constant.BigMath; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.matrix.decomposition.Eigenvalue; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; @@ -1208,16 +1208,16 @@ public int numberOfAssets() { return myCovarianceMtrx.length; } - public PrimitiveMatrix toCleanedCovariances() { + public Primitive64Matrix toCleanedCovariances() { return NextGenSysModTest.toCovariances(this.toVolatilities(), this.toCorrelations()); } - public PrimitiveMatrix toCorrelations() { - return NextGenSysModTest.toCorrelations(PrimitiveMatrix.FACTORY.rows(myCovarianceMtrx), true); + public Primitive64Matrix toCorrelations() { + return NextGenSysModTest.toCorrelations(Primitive64Matrix.FACTORY.rows(myCovarianceMtrx), true); } - public PrimitiveMatrix toVolatilities() { - return NextGenSysModTest.toVolatilities(PrimitiveMatrix.FACTORY.rows(myCovarianceMtrx), true); + public Primitive64Matrix toVolatilities() { + return NextGenSysModTest.toVolatilities(Primitive64Matrix.FACTORY.rows(myCovarianceMtrx), true); } } @@ -1248,7 +1248,7 @@ public static void assertSolution(final ExpressionsBasedModel model, final doubl public static ExpressionsBasedModel buildModel(final CaseData data) { - PrimitiveMatrix covar = data.toCleanedCovariances(); + Primitive64Matrix covar = data.toCleanedCovariances(); ExpressionsBasedModel retVal = new ExpressionsBasedModel(); @@ -1303,7 +1303,7 @@ public static ExpressionsBasedModel buildModel(final CaseData data) { public static Optimisation.Result solveSequentially(final CaseData data) { - PrimitiveMatrix covar = data.toCleanedCovariances(); + Primitive64Matrix covar = data.toCleanedCovariances(); int numberOfAssets = data.numberOfAssets(); @@ -1385,11 +1385,11 @@ public static Optimisation.Result solveSequentially(final CaseData data) { * Copied from ojAlgo-finance v2.1.1-SNAPSHOT (2019-05-23) org.ojalgo.finance.FinanceUtils. *

*/ - static PrimitiveMatrix toCorrelations(final Access2D covariances, final boolean clean) { + static Primitive64Matrix toCorrelations(final Access2D covariances, final boolean clean) { int size = Math.toIntExact(Math.min(covariances.countRows(), covariances.countColumns())); - MatrixStore covarianceMtrx = MatrixStore.PRIMITIVE.makeWrapper(covariances).get(); + MatrixStore covarianceMtrx = MatrixStore.PRIMITIVE64.makeWrapper(covariances).get(); if (clean) { @@ -1411,7 +1411,7 @@ static PrimitiveMatrix toCorrelations(final Access2D covariances, final boole covarianceMtrx = mtrxV.multiply(mtrxD).multiply(mtrxV.transpose()); } - PrimitiveMatrix.DenseReceiver retVal = PrimitiveMatrix.FACTORY.makeDense(size, size); + Primitive64Matrix.DenseReceiver retVal = Primitive64Matrix.FACTORY.makeDense(size, size); double[] volatilities = new double[size]; for (int ij = 0; ij < size; ij++) { @@ -1454,11 +1454,11 @@ static PrimitiveMatrix toCorrelations(final Access2D covariances, final boole * Copied from ojAlgo-finance v2.1.1-SNAPSHOT (2019-05-23) org.ojalgo.finance.FinanceUtils. *

*/ - static PrimitiveMatrix toCovariances(final Access1D volatilities, final Access2D correlations) { + static Primitive64Matrix toCovariances(final Access1D volatilities, final Access2D correlations) { int tmpSize = (int) volatilities.count(); - PrimitiveMatrix.DenseReceiver retVal = PrimitiveMatrix.FACTORY.makeDense(tmpSize, tmpSize); + Primitive64Matrix.DenseReceiver retVal = Primitive64Matrix.FACTORY.makeDense(tmpSize, tmpSize); for (int j = 0; j < tmpSize; j++) { double tmpColumnVolatility = volatilities.doubleValue(j); @@ -1482,15 +1482,15 @@ static PrimitiveMatrix toCovariances(final Access1D volatilities, final Acces * Copied from ojAlgo-finance v2.1.1-SNAPSHOT (2019-05-23) org.ojalgo.finance.FinanceUtils. *

*/ - static PrimitiveMatrix toVolatilities(final Access2D covariances, final boolean clean) { + static Primitive64Matrix toVolatilities(final Access2D covariances, final boolean clean) { int size = Math.toIntExact(Math.min(covariances.countRows(), covariances.countColumns())); - PrimitiveMatrix.DenseReceiver retVal = PrimitiveMatrix.FACTORY.makeDense(size); + Primitive64Matrix.DenseReceiver retVal = Primitive64Matrix.FACTORY.makeDense(size); if (clean) { - MatrixStore covarianceMtrx = MatrixStore.PRIMITIVE.makeWrapper(covariances).get(); + MatrixStore covarianceMtrx = MatrixStore.PRIMITIVE64.makeWrapper(covariances).get(); double largest = covarianceMtrx.aggregateDiagonal(Aggregator.LARGEST); double limit = largest * size * PrimitiveMath.RELATIVELY_SMALL; diff --git a/test/org/ojalgo/optimisation/integer/UCLAee236aCase.java b/test/org/ojalgo/optimisation/integer/UCLAee236aCase.java index 6ea3afe93..15db96b4b 100644 --- a/test/org/ojalgo/optimisation/integer/UCLAee236aCase.java +++ b/test/org/ojalgo/optimisation/integer/UCLAee236aCase.java @@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; import org.ojalgo.optimisation.Optimisation; @@ -80,7 +80,7 @@ public void testFullMIP() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); } @@ -100,7 +100,7 @@ public void testRelaxedButConstrainedToOptimalMIP() { //TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); TestUtils.assertStateNotLessThanOptimal(tmpResult); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); } @@ -117,7 +117,7 @@ public void testRelaxedNodeP00() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.17 }, { 2.07 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 2.17 }, { 2.07 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -138,7 +138,7 @@ public void testRelaxedNodeP01() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.00 }, { 2.14 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 2.00 }, { 2.14 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -158,7 +158,7 @@ public void testRelaxedNodeP02() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.00 }, { 1.33 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 3.00 }, { 1.33 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -179,7 +179,7 @@ public void testRelaxedNodeP03() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.00 }, { 2.00 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 2.00 }, { 2.00 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -204,7 +204,7 @@ public void testRelaxedNodeP04() { TestUtils.assertStateNotLessThanOptimal(tmpResult); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.00 }, { 3.00 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 0.00 }, { 3.00 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -225,7 +225,7 @@ public void testRelaxedNodeP05() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.38 }, { 1.00 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 3.38 }, { 1.00 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -262,7 +262,7 @@ public void testRelaxedNodeP07() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.00 }, { 1.00 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 3.00 }, { 1.00 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -284,7 +284,7 @@ public void testRelaxedNodeP08() { TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.00 }, { 0.44 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 4.00 }, { 0.44 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -315,7 +315,7 @@ public void testRelaxedNodeP09() { //TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); TestUtils.assertStateNotLessThanOptimal(tmpResult); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.50 }, { 0.00 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 4.50 }, { 0.00 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); @@ -357,7 +357,7 @@ public void testRelaxedNodeP11() { //TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState()); TestUtils.assertStateNotLessThanOptimal(tmpResult); - final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.00 }, { 0.00 } }); + final Primitive64Store tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 4.00 }, { 0.00 } }); TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION); diff --git a/test/org/ojalgo/optimisation/linear/BurkardtDatasetsMps.java b/test/org/ojalgo/optimisation/linear/BurkardtDatasetsMps.java index 5a9a802a3..4edf77872 100644 --- a/test/org/ojalgo/optimisation/linear/BurkardtDatasetsMps.java +++ b/test/org/ojalgo/optimisation/linear/BurkardtDatasetsMps.java @@ -150,7 +150,7 @@ public void testMPStestprob() { TestUtils.assertEquals(tmpVariables.length, tmpExpMinRes.count()); TestUtils.assertEquals(tmpVariables.length, tmpActMinRes.count()); - TestUtils.assertEquals(tmpExpMinRes, tmpActMinRes, BurkardtDatasetsMps.PRECISION); + TestUtils.assertStateAndSolution(tmpExpMinRes, tmpActMinRes, BurkardtDatasetsMps.PRECISION); for (int i = 0; i < tmpVariables.length; i++) { TestUtils.assertEquals(tmpVariables[i].getName(), tmpExpMinRes.doubleValue(i), tmpActMinRes.doubleValue(i), BurkardtDatasetsMps.PRECISION); diff --git a/test/org/ojalgo/optimisation/linear/ComPictetPamBamTest.java b/test/org/ojalgo/optimisation/linear/ComPictetPamBamTest.java index d60d9d2f3..fbd0f700d 100644 --- a/test/org/ojalgo/optimisation/linear/ComPictetPamBamTest.java +++ b/test/org/ojalgo/optimisation/linear/ComPictetPamBamTest.java @@ -28,7 +28,7 @@ import org.ojalgo.function.constant.BigMath; import org.ojalgo.matrix.RationalMatrix; import org.ojalgo.matrix.store.MatrixStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; import org.ojalgo.optimisation.Optimisation; @@ -94,7 +94,7 @@ MatrixStore solveLinear() { final String message = "State: " + tmpResult.getState() + ", validated: " + validated; TestUtils.assertTrue(message, validated); if (validated) { - return PrimitiveDenseStore.FACTORY.copy(RationalMatrix.FACTORY.columns(tmpResult)); + return Primitive64Store.FACTORY.copy(RationalMatrix.FACTORY.columns(tmpResult)); } } else { final String message = "State: " + tmpResult.getState() + ", validated: " + validated; diff --git a/test/org/ojalgo/optimisation/linear/LinearDesignTestCases.java b/test/org/ojalgo/optimisation/linear/LinearDesignTestCases.java index a67d4654d..45e71270f 100644 --- a/test/org/ojalgo/optimisation/linear/LinearDesignTestCases.java +++ b/test/org/ojalgo/optimisation/linear/LinearDesignTestCases.java @@ -34,7 +34,7 @@ import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PhysicalStore.Factory; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; import org.ojalgo.optimisation.Optimisation; @@ -78,8 +78,8 @@ public void test1LinearModelCase() { final Optimisation.Result tmpResult = tmpModel.maximise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final PhysicalStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5.0 }, { 4.0 }, { 0.0 } }); - final PhysicalStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2 }).get()); + final PhysicalStore tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 5.0 }, { 4.0 }, { 0.0 } }); + final PhysicalStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } @@ -110,8 +110,8 @@ public void test2LinearModelCase() { final Optimisation.Result tmpResult = tmpModel.maximise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final PhysicalStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 8.0 }, { 1.0 }, { 0.0 } }); - final PhysicalStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2 }).get()); + final PhysicalStore tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 8.0 }, { 1.0 }, { 0.0 } }); + final PhysicalStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } @@ -147,8 +147,8 @@ public void test3LinearModelCase() { final Optimisation.Result tmpResult = tmpModel.maximise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final PhysicalStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } }); - final PhysicalStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1 }).get()); + final PhysicalStore tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } }); + final PhysicalStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } @@ -185,8 +185,8 @@ public void test4LinearModelCase() { final Optimisation.Result tmpResult = tmpModel.minimise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final PhysicalStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.74 }, { 0.45 }, { 1.0 } }); - final PhysicalStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2 }).get()); + final PhysicalStore tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 1.74 }, { 0.45 }, { 1.0 } }); + final PhysicalStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2 }).get()); tmpActX.modifyAll(new NumberContext(7, 2).getFunction(PrimitiveFunction.getSet())); TestUtils.assertEquals(tmpExpX, tmpActX); @@ -223,8 +223,8 @@ public void test5LinearModelCase() { final Optimisation.Result tmpResult = tmpModel.minimise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final PhysicalStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5.0 }, { 5.0 } }); - final PhysicalStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1 }).get()); + final PhysicalStore tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 5.0 }, { 5.0 } }); + final PhysicalStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } @@ -276,8 +276,8 @@ public void test7LinearModelCase() { final Optimisation.Result tmpResult = tmpModel.minimise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final PhysicalStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0 }, { 4.0 } }); - final PhysicalStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1 }).get()); + final PhysicalStore tmpExpX = Primitive64Store.FACTORY.rows(new double[][] { { 4.0 }, { 4.0 } }); + final PhysicalStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } @@ -323,16 +323,16 @@ public void test8LinearModelCase() { @Test public void testDuality() { - final Factory factory = PrimitiveDenseStore.FACTORY; + final Factory factory = Primitive64Store.FACTORY; - final PrimitiveDenseStore expPrimSol = factory.rows(new double[] { 36.0, 0.0, 6.0 }); - final PrimitiveDenseStore expDualSol = factory.rows(new double[] { 11.0, 0.5 }); + final Primitive64Store expPrimSol = factory.rows(new double[] { 36.0, 0.0, 6.0 }); + final Primitive64Store expDualSol = factory.rows(new double[] { 11.0, 0.5 }); final double expOptVal = 294.0; final LinearSolver.Builder primal = LinearSolver.getBuilder(); // Negated since actual problem is max and algorithm expects min - final PrimitiveDenseStore pC = factory.makeZero(5, 1); + final Primitive64Store pC = factory.makeZero(5, 1); pC.set(0, -6.0); pC.set(1, -14.0); pC.set(2, -13.0); @@ -341,7 +341,7 @@ public void testDuality() { primal.objective(pC); - final PrimitiveDenseStore pAE = factory.makeZero(2, 5); + final Primitive64Store pAE = factory.makeZero(2, 5); pAE.set(0, 0, 0.5); pAE.set(0, 1, 2.0); pAE.set(0, 2, 1.0); @@ -353,7 +353,7 @@ public void testDuality() { pAE.set(1, 3, 0.0); pAE.set(1, 4, 1.0); - final PrimitiveDenseStore pBE = factory.makeZero(2, 1); + final Primitive64Store pBE = factory.makeZero(2, 1); pBE.set(0, 24.0); pBE.set(1, 60.0); @@ -377,7 +377,7 @@ public void testDuality() { final LinearSolver.Builder dual = LinearSolver.getBuilder(); - final PrimitiveDenseStore dC = factory.makeZero(5, 1); + final Primitive64Store dC = factory.makeZero(5, 1); dC.set(0, 24.0); dC.set(1, 60.0); dC.set(2, 0.0); @@ -386,7 +386,7 @@ public void testDuality() { dual.objective(dC); - final PrimitiveDenseStore dAE = factory.makeZero(3, 5); + final Primitive64Store dAE = factory.makeZero(3, 5); dAE.set(0, 0, 0.5); dAE.set(0, 1, 1.0); dAE.set(0, 2, -1.0); @@ -403,7 +403,7 @@ public void testDuality() { dAE.set(2, 3, 0.0); dAE.set(2, 4, -1.0); - final PrimitiveDenseStore dBE = factory.makeZero(3, 1); + final Primitive64Store dBE = factory.makeZero(3, 1); dBE.set(0, 6.0); dBE.set(1, 14.0); dBE.set(2, 13.0); @@ -453,9 +453,9 @@ public void testMaxOldKnapsackTestModel() { final Optimisation.Result tmpResult = tmpModel.maximise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final MatrixStore tmpExpX = PrimitiveDenseStore.FACTORY + final MatrixStore tmpExpX = Primitive64Store.FACTORY .rows(new double[][] { { 0.0 }, { 0.0 }, { 0.1846 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.8154 }, { 0.0 } }); - final MatrixStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }).get()); + final MatrixStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } @@ -468,9 +468,9 @@ public void testMinOldKnapsackTestModel() { final Optimisation.Result tmpResult = tmpModel.minimise(); final RationalMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult); - final MatrixStore tmpExpX = PrimitiveDenseStore.FACTORY + final MatrixStore tmpExpX = Primitive64Store.FACTORY .rows(new double[][] { { 0.0 }, { 0.8154 }, { 0.1846 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } }); - final MatrixStore tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }).get()); + final MatrixStore tmpActX = Primitive64Store.FACTORY.copy(tmpSolution.logical().rows(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }).get()); TestUtils.assertEquals(tmpExpX, tmpActX); } diff --git a/test/org/ojalgo/optimisation/linear/LinearProblems.java b/test/org/ojalgo/optimisation/linear/LinearProblems.java index c1d601928..94fef211b 100644 --- a/test/org/ojalgo/optimisation/linear/LinearProblems.java +++ b/test/org/ojalgo/optimisation/linear/LinearProblems.java @@ -29,9 +29,9 @@ import org.ojalgo.TestUtils; import org.ojalgo.array.BigArray; import org.ojalgo.function.constant.BigMath; -import org.ojalgo.matrix.PrimitiveMatrix; +import org.ojalgo.matrix.Primitive64Matrix; import org.ojalgo.matrix.RationalMatrix; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.ExpressionsBasedModel; import org.ojalgo.optimisation.Optimisation; @@ -158,18 +158,18 @@ public void testMath286() { // A valid solution of 25.8 can be produced with: // X1=10, X2=0, X3=8, X4=0, X5=5, X6=23 BigDecimal tmpClaimedValue = new BigDecimal("25.8"); - PrimitiveMatrix.DenseReceiver tmpBuilder = PrimitiveMatrix.FACTORY.makeDense(6, 1); + Primitive64Matrix.DenseReceiver tmpBuilder = Primitive64Matrix.FACTORY.makeDense(6, 1); tmpBuilder.set(0, 0, 10); tmpBuilder.set(2, 0, 8); tmpBuilder.set(4, 0, 5); tmpBuilder.set(5, 0, 23); - PrimitiveMatrix tmpFullSolution = tmpBuilder.build(); + Primitive64Matrix tmpFullSolution = tmpBuilder.build(); int[] someRows = { 0, 2, 4 }; - PrimitiveMatrix tmpOddSolution = tmpFullSolution.logical().rows(someRows).get(); + Primitive64Matrix tmpOddSolution = tmpFullSolution.logical().rows(someRows).get(); int[] someRows1 = { 1, 3, 5 }; - PrimitiveMatrix tmpEvenSolution = tmpFullSolution.logical().rows(someRows1).get(); + Primitive64Matrix tmpEvenSolution = tmpFullSolution.logical().rows(someRows1).get(); TestUtils.assertEquals("Claimed solution not valid!", true, tmpFullModel.validate(BigArray.FACTORY.copy(tmpFullSolution), new NumberContext(7, 6))); - Double tmpActualValue = tmpFullObjective.toFunction().invoke(PrimitiveDenseStore.FACTORY.copy(tmpFullSolution)); + Double tmpActualValue = tmpFullObjective.toFunction().invoke(Primitive64Store.FACTORY.copy(tmpFullSolution)); // BigDecimal tmpActualValue = TypeUtils.toBigDecimal(tmpObjectiveValue); //JUnitUtils.assertEquals("Claimed objective value wrong!", 0, tmpClaimedValue.compareTo(tmpActualValue)); TestUtils.assertEquals(tmpClaimedValue, tmpActualValue, new NumberContext(7, 6)); @@ -193,13 +193,13 @@ public void testMath286() { int[] someRows5 = { 0, 1, 2 }; BigDecimal tmpEvenValue = new NumberContext(7, 6).enforce(TypeUtils.toBigDecimal(tmpEvenObjective.toFunction() - .invoke(PrimitiveDenseStore.FACTORY.copy(PrimitiveMatrix.FACTORY.columns(tmpEvenResult).logical().rows(someRows5).get())))); + .invoke(Primitive64Store.FACTORY.copy(Primitive64Matrix.FACTORY.columns(tmpEvenResult).logical().rows(someRows5).get())))); int[] someRows6 = { 0, 1, 2 }; BigDecimal tmpOddValue = new NumberContext(7, 6).enforce(TypeUtils.toBigDecimal(tmpOddObjective.toFunction() - .invoke(PrimitiveDenseStore.FACTORY.copy(PrimitiveMatrix.FACTORY.columns(tmpOddResult).logical().rows(someRows6).get())))); + .invoke(Primitive64Store.FACTORY.copy(Primitive64Matrix.FACTORY.columns(tmpOddResult).logical().rows(someRows6).get())))); int[] someRows7 = { 0, 1, 2, 3, 4, 5 }; BigDecimal tmpFullValue = new NumberContext(7, 6).enforce(TypeUtils.toBigDecimal(tmpFullObjective.toFunction() - .invoke(PrimitiveDenseStore.FACTORY.copy(PrimitiveMatrix.FACTORY.columns(tmpFullResult).logical().rows(someRows7).get())))); + .invoke(Primitive64Store.FACTORY.copy(Primitive64Matrix.FACTORY.columns(tmpFullResult).logical().rows(someRows7).get())))); TestUtils.assertEquals(0, tmpFullValue.compareTo(tmpEvenValue.add(tmpOddValue))); TestUtils.assertEquals(0, tmpClaimedValue.compareTo(tmpFullValue)); @@ -245,7 +245,7 @@ public void testP20111010() { tmpExprC3.set(0, ONE); tmpExprC3.set(2, NEG); - PrimitiveMatrix tmpExpectedSolution = PrimitiveMatrix.FACTORY.makeZero(3, 1); + Primitive64Matrix tmpExpectedSolution = Primitive64Matrix.FACTORY.makeZero(3, 1); Optimisation.Result tmpResult11 = tmpModel.minimise(); //TestUtils.assertEquals(tmpExpectedState, tmpResult11.getState()); diff --git a/test/org/ojalgo/optimisation/linear/SpecialSituations.java b/test/org/ojalgo/optimisation/linear/SpecialSituations.java index 497d90ee7..49d4c0acf 100644 --- a/test/org/ojalgo/optimisation/linear/SpecialSituations.java +++ b/test/org/ojalgo/optimisation/linear/SpecialSituations.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.optimisation.Optimisation; import org.ojalgo.optimisation.Optimisation.Result; import org.ojalgo.optimisation.linear.LinearSolver.Builder; @@ -44,11 +44,11 @@ public SpecialSituations() { @Test public void testDegeneracy() { - PrimitiveDenseStore c = PrimitiveDenseStore.FACTORY.columns(new double[] { -2, -1, 0, 0, 0 }); - PrimitiveDenseStore A = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4, 3, 1, 0, 0 }, { 4, 1, 0, 1, 0 }, { 4, 2, 0, 0, 1 } }); - PrimitiveDenseStore b = PrimitiveDenseStore.FACTORY.columns(new double[] { 12, 8, 8 }); + Primitive64Store c = Primitive64Store.FACTORY.columns(new double[] { -2, -1, 0, 0, 0 }); + Primitive64Store A = Primitive64Store.FACTORY.rows(new double[][] { { 4, 3, 1, 0, 0 }, { 4, 1, 0, 1, 0 }, { 4, 2, 0, 0, 1 } }); + Primitive64Store b = Primitive64Store.FACTORY.columns(new double[] { 12, 8, 8 }); - PrimitiveDenseStore x = PrimitiveDenseStore.FACTORY.columns(new double[] { 2, 0, 4, 0, 0 }); + Primitive64Store x = Primitive64Store.FACTORY.columns(new double[] { 2, 0, 4, 0, 0 }); final Builder builder = LinearSolver.getBuilder(c).equalities(A, b); LinearSolver lp = builder.build(); @@ -112,11 +112,11 @@ public void testDegeneracy() { @Test public void testMultipleOptimalSolutions() { - PrimitiveDenseStore c = PrimitiveDenseStore.FACTORY.columns(new double[] { -4, -14, 0, 0 }); - PrimitiveDenseStore A = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2, 7, 1, 0 }, { 7, 2, 0, 1 } }); - PrimitiveDenseStore b = PrimitiveDenseStore.FACTORY.columns(new double[] { 21, 21 }); + Primitive64Store c = Primitive64Store.FACTORY.columns(new double[] { -4, -14, 0, 0 }); + Primitive64Store A = Primitive64Store.FACTORY.rows(new double[][] { { 2, 7, 1, 0 }, { 7, 2, 0, 1 } }); + Primitive64Store b = Primitive64Store.FACTORY.columns(new double[] { 21, 21 }); - PrimitiveDenseStore x = PrimitiveDenseStore.FACTORY.columns(new double[] { 7.0 / 3.0, 7.0 / 3.0, 0, 0 }); + Primitive64Store x = Primitive64Store.FACTORY.columns(new double[] { 7.0 / 3.0, 7.0 / 3.0, 0, 0 }); final Builder builder = LinearSolver.getBuilder(c).equalities(A, b); LinearSolver lp = builder.build(); @@ -152,11 +152,11 @@ public void testMultipleOptimalSolutions() { @Test public void testUnboundedness() { - PrimitiveDenseStore c = PrimitiveDenseStore.FACTORY.columns(new double[] { -2, -1, 0, 0 }); - PrimitiveDenseStore A = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, -1, 1, 0 }, { 2, -1, 0, 1 } }); - PrimitiveDenseStore b = PrimitiveDenseStore.FACTORY.columns(new double[] { 10, 40 }); + Primitive64Store c = Primitive64Store.FACTORY.columns(new double[] { -2, -1, 0, 0 }); + Primitive64Store A = Primitive64Store.FACTORY.rows(new double[][] { { 1, -1, 1, 0 }, { 2, -1, 0, 1 } }); + Primitive64Store b = Primitive64Store.FACTORY.columns(new double[] { 10, 40 }); - PrimitiveDenseStore x = PrimitiveDenseStore.FACTORY.columns(new double[] { 30, 20, 0, 0 }); + Primitive64Store x = Primitive64Store.FACTORY.columns(new double[] { 30, 20, 0, 0 }); final Builder builder = LinearSolver.getBuilder(c).equalities(A, b); LinearSolver lp = builder.build(); diff --git a/test/org/ojalgo/random/process/GaussianProcessTest.java b/test/org/ojalgo/random/process/GaussianProcessTest.java index ce431626c..0370f4a6f 100644 --- a/test/org/ojalgo/random/process/GaussianProcessTest.java +++ b/test/org/ojalgo/random/process/GaussianProcessTest.java @@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test; import org.ojalgo.TestUtils; import org.ojalgo.function.constant.PrimitiveMath; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; import org.ojalgo.random.Normal; import org.ojalgo.random.process.GaussianField.Mean; import org.ojalgo.type.context.NumberContext; @@ -77,7 +77,7 @@ public double invoke(final Double anArg1, final Double anArg2) { tmpProc.addObservation(-0.25, 0.5); tmpProc.addObservation(0.0, 0.8); - final PrimitiveDenseStore tmpExpected = PrimitiveDenseStore.FACTORY + final Primitive64Store tmpExpected = Primitive64Store.FACTORY .rows(new double[][] { { 1.7029, 1.423379254178694, 1.2174807940480699, 0.8807634427271873, 0.7384394292014367, 0.5236319646022823 }, { 1.423379254178694, 1.7029, 1.5632762838868954, 1.3472073239852407, 1.2174807940480699, 0.9782733010505065 }, { 1.2174807940480699, 1.5632762838868954, 1.7029, 1.5170744874003474, 1.423379254178694, 1.2174807940480699 }, diff --git a/test/org/ojalgo/scalar/QuaternionTest.java b/test/org/ojalgo/scalar/QuaternionTest.java index 59e39bbd6..2fb30d49b 100644 --- a/test/org/ojalgo/scalar/QuaternionTest.java +++ b/test/org/ojalgo/scalar/QuaternionTest.java @@ -28,7 +28,7 @@ import org.ojalgo.function.constant.QuaternionMath; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.PhysicalStore; -import org.ojalgo.matrix.store.PrimitiveDenseStore; +import org.ojalgo.matrix.store.Primitive64Store; public class QuaternionTest extends ScalarTests { @@ -287,7 +287,7 @@ public void testRotationMatrixMathWorksExample() { final Quaternion rotQuat = Quaternion.of(nmbr, nmbr, 0.0, 0.0); - final PrimitiveDenseStore expected = PrimitiveDenseStore.FACTORY.columns(new double[][] { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 } }); + final Primitive64Store expected = Primitive64Store.FACTORY.columns(new double[][] { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 } }); final MatrixStore actual = rotQuat.toRotationMatrix(); From 246a4507923491d8b97c0cdd0f1d9a3c63789d7d Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 3 Nov 2019 13:32:39 +0100 Subject: [PATCH 24/29] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 890c0908c..45502fe4e 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,15 @@ ojAlgo is available at [The Central (Maven) Repository](https://search.maven.org ### Documentation and Support -User documentation wiki with examples is here at GitHub: https://github.com/optimatika/ojAlgo/wiki +User documentation is available in the form of blog posts at the ojAlgo web site: http://ojalgo.org/ + +The wiki here at GitHub is in the process of being migrated to the ojAlgo site, but still contains info not available elsewhere: https://github.com/optimatika/ojAlgo/wiki Programming questions related to ojAlgo are best asked at [stack overflow](https://stackoverflow.com/search?tab=relevance&q=ojalgo). Just remember to actually mention ojAlgo and tag the question using 'ojalgo' and whatever other tags you find suitable. -Bug reports and to some extent feature requests should be posted here at GitHub: https://github.com/optimatika/ojAlgo/issues +Bug reports, and to some extent feature requests, should be posted here at GitHub: https://github.com/optimatika/ojAlgo/issues (Please do not use GitHub Issues for general discussions or user support requests!) -The [ojAlgo-user mailing list](https://sourceforge.net/p/ojalgo/mailman/ojalgo-user/) can be used for just about anything as long as it relates to ojAlgo. (Note that you have to be a member to post to that list!) - ojAlgo is Open Source, and you are strongly encouraged to clone or fork this repository and work directly with the source code. The source code is (part of) the documentation, and you should read it. ### Enterprise-Grade Support @@ -36,5 +36,5 @@ Available as part of the Tidelift Subscription The maintainers of ojAlgo and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/maven-org-ojalgo-ojalgo?utm_source=maven-org-ojalgo-ojalgo&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) -Tidelift Subscription +Tidelift Subscription From 85f901302883f1a5441fdfc5d3458d95b45b1010 Mon Sep 17 00:00:00 2001 From: Anders Peterson Date: Thu, 14 Nov 2019 15:27:41 +0100 Subject: [PATCH 25/29] Refactoring (#234) --- src/org/ojalgo/array/Primitive32Array.java | 297 ++---------------- src/org/ojalgo/array/Primitive64Array.java | 297 ++---------------- src/org/ojalgo/array/ReferenceTypeArray.java | 109 ++----- .../array/operation/ArrayOperation.java | 10 + .../operation/CorePrimitiveOperation.java | 188 +++++++++++ src/org/ojalgo/array/operation/Exchange.java | 86 +++++ src/org/ojalgo/array/operation/FillAll.java | 62 ++++ .../ojalgo/array/operation/MultiplyBoth.java | 36 +-- .../array/operation/OperationBinary.java | 227 +++++++++++++ .../array/operation/OperationParameter.java | 55 ++++ .../array/operation/OperationUnary.java | 109 +++++++ .../ojalgo/array/operation/OperationVoid.java | 52 +++ .../ojalgo/array/operation/package-info.java | 4 +- src/org/ojalgo/function/BinaryFunction.java | 8 + src/org/ojalgo/matrix/BasicMatrix.java | 2 +- src/org/ojalgo/matrix/MatrixFactory.java | 4 +- .../matrix/geometry/Primitive32Vector2.java | 6 +- .../matrix/geometry/Primitive32Vector3.java | 8 +- .../matrix/geometry/Primitive32Vector4.java | 10 +- .../matrix/geometry/Primitive64Vector2.java | 2 +- .../matrix/geometry/Primitive64Vector3.java | 2 +- .../matrix/geometry/Primitive64Vector4.java | 2 +- src/org/ojalgo/matrix/store/GenericStore.java | 21 +- .../ojalgo/matrix/store/PhysicalStore.java | 9 + .../ojalgo/matrix/store/Primitive32Store.java | 14 +- .../ojalgo/matrix/store/Primitive64Store.java | 12 +- src/org/ojalgo/matrix/store/RawStore.java | 4 - .../matrix/store/TransformableRegion.java | 4 +- src/org/ojalgo/structure/AccessScalar.java | 20 -- src/org/ojalgo/type/NumberDefinition.java | 16 +- 30 files changed, 937 insertions(+), 739 deletions(-) create mode 100644 src/org/ojalgo/array/operation/CorePrimitiveOperation.java create mode 100644 src/org/ojalgo/array/operation/Exchange.java create mode 100644 src/org/ojalgo/array/operation/OperationBinary.java create mode 100644 src/org/ojalgo/array/operation/OperationParameter.java create mode 100644 src/org/ojalgo/array/operation/OperationUnary.java create mode 100644 src/org/ojalgo/array/operation/OperationVoid.java diff --git a/src/org/ojalgo/array/Primitive32Array.java b/src/org/ojalgo/array/Primitive32Array.java index 6164f85c3..f36704665 100644 --- a/src/org/ojalgo/array/Primitive32Array.java +++ b/src/org/ojalgo/array/Primitive32Array.java @@ -25,22 +25,16 @@ import java.util.Arrays; -import org.ojalgo.array.operation.AMAX; -import org.ojalgo.array.operation.AXPY; -import org.ojalgo.array.operation.COPY; +import org.ojalgo.array.operation.*; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.BinaryFunction.FixedFirst; -import org.ojalgo.function.BinaryFunction.FixedSecond; import org.ojalgo.function.FunctionSet; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; -import org.ojalgo.function.ParameterFunction.FixedParameter; import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; -import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.scalar.PrimitiveScalar; @@ -94,259 +88,6 @@ public static Primitive32Array wrap(final float... data) { return new Primitive32Array(data); } - private static void add(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left + right[i]; - } - } - - private static void add(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] + right; - } - } - - private static void add(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] + right[i]; - } - } - - private static void divide(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left / right[i]; - } - } - - private static void divide(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] / right; - } - } - - private static void divide(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] / right[i]; - } - } - - private static void multiply(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left * right[i]; - } - } - - private static void multiply(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] * right; - } - } - - private static void multiply(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] * right[i]; - } - } - - private static void negate(final float[] data, final int first, final int limit, final int step, final float[] values) { - for (int i = first; i < limit; i += step) { - data[i] = -values[i]; - } - } - - private static void subtract(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left - right[i]; - } - } - - private static void subtract(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] - right; - } - } - - private static void subtract(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] - right[i]; - } - } - - protected static void exchange(final float[] data, final int firstA, final int firstB, final int step, final int count) { - - int tmpIndexA = firstA; - int tmpIndexB = firstB; - - float tmpVal; - - for (int i = 0; i < count; i++) { - - tmpVal = data[tmpIndexA]; - data[tmpIndexA] = data[tmpIndexB]; - data[tmpIndexB] = tmpVal; - - tmpIndexA += step; - tmpIndexB += step; - } - } - - protected static void fill(final float[] data, final Access1D values) { - final int tmpLimit = (int) Math.min(data.length, values.count()); - for (int i = 0; i < tmpLimit; i++) { - data[i] = (float) values.doubleValue(i); - } - } - - protected static void fill(final float[] data, final int first, final int limit, final int step, final float value) { - for (int i = first; i < limit; i += step) { - data[i] = value; - } - } - - protected static void fill(final float[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { - for (int i = first; i < limit; i += step) { - data[i] = (float) supplier.doubleValue(); - } - } - - protected static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D left, - final BinaryFunction function, final Access1D right) { - if ((left instanceof Primitive32Array) && (right instanceof Primitive32Array)) { - Primitive32Array.invoke(data, first, limit, step, ((Primitive32Array) left).data, function, ((Primitive32Array) right).data); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(left.doubleValue(i), right.doubleValue(i)); - } - } - } - - protected static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D left, - final BinaryFunction function, final double right) { - if (left instanceof Primitive32Array) { - Primitive32Array.invoke(data, first, limit, step, ((Primitive32Array) left).data, function, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(left.doubleValue(i), right); - } - } - } - - protected static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D values, - final ParameterFunction function, final int aParam) { - if (values instanceof Primitive32Array) { - Primitive32Array.invoke(data, first, limit, step, ((Primitive32Array) values).data, function, aParam); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(values.doubleValue(i), aParam); - } - } - } - - protected static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D values, - final UnaryFunction function) { - if (values instanceof Primitive32Array) { - Primitive32Array.invoke(data, first, limit, step, ((Primitive32Array) values).data, function); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(values.doubleValue(i)); - } - } - } - - protected static void invoke(final float[] data, final int first, final int limit, final int step, final double left, final BinaryFunction function, - final Access1D right) { - if (right instanceof Primitive32Array) { - Primitive32Array.invoke(data, first, limit, step, left, function, ((Primitive32Array) right).data); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(left, right.doubleValue(i)); - } - } - } - - protected static void invoke(final float[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { - for (int i = first; i < limit; i += step) { - aVisitor.invoke(data[i]); - } - } - - static void invoke(final float[] data, final int first, final int limit, final int step, final double left, final BinaryFunction function, - final float[] right) { - if (function == PrimitiveMath.ADD) { - Primitive32Array.add(data, first, limit, step, (float) left, right); - } else if (function == PrimitiveMath.DIVIDE) { - Primitive32Array.divide(data, first, limit, step, (float) left, right); - } else if (function == PrimitiveMath.MULTIPLY) { - Primitive32Array.multiply(data, first, limit, step, (float) left, right); - } else if (function == PrimitiveMath.SUBTRACT) { - Primitive32Array.subtract(data, first, limit, step, (float) left, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(left, right[i]); - } - } - } - - static void invoke(final float[] data, final int first, final int limit, final int step, final float[] left, final BinaryFunction function, - final double right) { - if (function == PrimitiveMath.ADD) { - Primitive32Array.add(data, first, limit, step, left, (float) right); - } else if (function == PrimitiveMath.DIVIDE) { - Primitive32Array.divide(data, first, limit, step, left, (float) right); - } else if (function == PrimitiveMath.MULTIPLY) { - Primitive32Array.multiply(data, first, limit, step, left, (float) right); - } else if (function == PrimitiveMath.SUBTRACT) { - Primitive32Array.subtract(data, first, limit, step, left, (float) right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = (float) function.invoke(left[i], right); - } - } - } - - static void invoke(final float[] data, final int first, final int limit, final int step, final float[] left, final BinaryFunction function, - final float[] right) { - if (function == PrimitiveMath.ADD) { - Primitive32Array.add(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.DIVIDE) { - Primitive32Array.divide(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.MULTIPLY) { - Primitive32Array.multiply(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.SUBTRACT) { - Primitive32Array.subtract(data, first, limit, step, left, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left[i], right[i]); - } - } - } - - static void invoke(final float[] data, final int first, final int limit, final int step, final float[] values, final ParameterFunction function, - final int aParam) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(values[i], aParam); - } - } - - static void invoke(final float[] data, final int first, final int limit, final int step, final float[] values, final UnaryFunction function) { - if (function == PrimitiveMath.NEGATE) { - Primitive32Array.negate(data, first, limit, step, values); - } else if (function instanceof FixedFirst) { - final FixedFirst tmpFunc = (FixedFirst) function; - Primitive32Array.invoke(data, first, limit, step, tmpFunc.doubleValue(), tmpFunc.getFunction(), values); - } else if (function instanceof FixedSecond) { - final FixedSecond tmpFunc = (FixedSecond) function; - Primitive32Array.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.doubleValue()); - } else if (function instanceof FixedParameter) { - final FixedParameter tmpFunc = (FixedParameter) function; - Primitive32Array.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.getParameter()); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(values[i]); - } - } - } - public final float[] data; /** @@ -394,19 +135,19 @@ public boolean equals(final Object anObj) { @Override public void fillMatching(final Access1D values) { - Primitive32Array.fill(data, values); + FillAll.fill(data, values); } @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); - Primitive32Array.invoke(data, 0, limit, 1, left, function, right); + OperationBinary.invoke(data, 0, limit, 1, left, function, right); } @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); - Primitive32Array.invoke(data, 0, limit, 1, arguments, function); + OperationUnary.invoke(data, 0, limit, 1, arguments, function); } @Override @@ -426,9 +167,9 @@ public final void sortAscending() { @Override public void sortDescending() { - Primitive32Array.negate(data, 0, data.length, 1, data); + CorePrimitiveOperation.negate(data, 0, data.length, 1, data); Arrays.parallelSort(data); - Primitive32Array.negate(data, 0, data.length, 1, data); + CorePrimitiveOperation.negate(data, 0, data.length, 1, data); } @Override @@ -457,33 +198,33 @@ protected final double doubleValue(final int index) { @Override protected final void exchange(final int firstA, final int firstB, final int step, final int count) { - Primitive32Array.exchange(data, firstA, firstB, step, count); + Exchange.exchange(data, firstA, firstB, step, count); } @Override protected final void fill(final int first, final int limit, final Access1D left, final BinaryFunction function, final Access1D right) { - Primitive32Array.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override protected final void fill(final int first, final int limit, final Access1D left, final BinaryFunction function, final Double right) { - Primitive32Array.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right.floatValue()); } @Override protected final void fill(final int first, final int limit, final Double left, final BinaryFunction function, final Access1D right) { - Primitive32Array.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left.floatValue(), function, right); } @Override protected final void fill(final int first, final int limit, final int step, final Double value) { - Primitive32Array.fill(data, first, limit, step, value.floatValue()); + FillAll.fill(data, first, limit, step, value.floatValue()); } @Override protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { - Primitive32Array.fill(data, first, limit, step, supplier); + FillAll.fill(data, first, limit, step, supplier); } @Override @@ -523,32 +264,32 @@ protected boolean isSmall(final int index, final double comparedTo) { @Override protected final void modify(final int first, final int limit, final int step, final Access1D left, final BinaryFunction function) { - Primitive32Array.invoke(data, first, limit, step, left, function, this); + OperationBinary.invoke(data, first, limit, step, left, function, this); } @Override protected final void modify(final int first, final int limit, final int step, final BinaryFunction function, final Access1D right) { - Primitive32Array.invoke(data, first, limit, step, this, function, right); + OperationBinary.invoke(data, first, limit, step, this, function, right); } @Override protected final void modify(final int first, final int limit, final int step, final BinaryFunction function, final Double right) { - Primitive32Array.invoke(data, first, limit, step, data, function, right); + OperationBinary.invoke(data, first, limit, step, data, function, right.floatValue()); } @Override protected final void modify(final int first, final int limit, final int step, final Double left, final BinaryFunction function) { - Primitive32Array.invoke(data, first, limit, step, left, function, data); + OperationBinary.invoke(data, first, limit, step, left.floatValue(), function, data); } @Override protected final void modify(final int first, final int limit, final int step, final ParameterFunction function, final int parameter) { - Primitive32Array.invoke(data, first, limit, step, data, function, parameter); + OperationParameter.invoke(data, first, limit, step, data, function, parameter); } @Override protected final void modify(final int first, final int limit, final int step, final UnaryFunction function) { - Primitive32Array.invoke(data, first, limit, step, this, function); + OperationUnary.invoke(data, first, limit, step, this, function); } @Override @@ -578,7 +319,7 @@ protected final void set(final int index, final Comparable value) { @Override protected final void visit(final int first, final int limit, final int step, final VoidFunction visitor) { - Primitive32Array.invoke(data, first, limit, step, visitor); + OperationVoid.invoke(data, first, limit, step, visitor); } @Override diff --git a/src/org/ojalgo/array/Primitive64Array.java b/src/org/ojalgo/array/Primitive64Array.java index fece33a8c..39c81a0e5 100644 --- a/src/org/ojalgo/array/Primitive64Array.java +++ b/src/org/ojalgo/array/Primitive64Array.java @@ -29,22 +29,16 @@ import java.util.stream.DoubleStream; import java.util.stream.StreamSupport; -import org.ojalgo.array.operation.AMAX; -import org.ojalgo.array.operation.AXPY; -import org.ojalgo.array.operation.COPY; +import org.ojalgo.array.operation.*; import org.ojalgo.function.BinaryFunction; -import org.ojalgo.function.BinaryFunction.FixedFirst; -import org.ojalgo.function.BinaryFunction.FixedSecond; import org.ojalgo.function.FunctionSet; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; -import org.ojalgo.function.ParameterFunction.FixedParameter; import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.function.VoidFunction; import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.function.aggregator.PrimitiveAggregator; -import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; import org.ojalgo.machine.JavaType; import org.ojalgo.scalar.PrimitiveScalar; @@ -98,259 +92,6 @@ public static Primitive64Array wrap(final double... data) { return new Primitive64Array(data); } - private static void add(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left + right[i]; - } - } - - private static void add(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] + right; - } - } - - private static void add(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] + right[i]; - } - } - - private static void divide(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left / right[i]; - } - } - - private static void divide(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] / right; - } - } - - private static void divide(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] / right[i]; - } - } - - private static void multiply(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left * right[i]; - } - } - - private static void multiply(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] * right; - } - } - - private static void multiply(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] * right[i]; - } - } - - private static void negate(final double[] data, final int first, final int limit, final int step, final double[] values) { - for (int i = first; i < limit; i += step) { - data[i] = -values[i]; - } - } - - private static void subtract(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left - right[i]; - } - } - - private static void subtract(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] - right; - } - } - - private static void subtract(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { - for (int i = first; i < limit; i += step) { - data[i] = left[i] - right[i]; - } - } - - protected static void exchange(final double[] data, final int firstA, final int firstB, final int step, final int count) { - - int tmpIndexA = firstA; - int tmpIndexB = firstB; - - double tmpVal; - - for (int i = 0; i < count; i++) { - - tmpVal = data[tmpIndexA]; - data[tmpIndexA] = data[tmpIndexB]; - data[tmpIndexB] = tmpVal; - - tmpIndexA += step; - tmpIndexB += step; - } - } - - protected static void fill(final double[] data, final Access1D values) { - final int tmpLimit = (int) Math.min(data.length, values.count()); - for (int i = 0; i < tmpLimit; i++) { - data[i] = values.doubleValue(i); - } - } - - protected static void fill(final double[] data, final int first, final int limit, final int step, final double value) { - for (int i = first; i < limit; i += step) { - data[i] = value; - } - } - - protected static void fill(final double[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { - for (int i = first; i < limit; i += step) { - data[i] = supplier.doubleValue(); - } - } - - protected static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D left, - final BinaryFunction function, final Access1D right) { - if ((left instanceof Primitive64Array) && (right instanceof Primitive64Array)) { - Primitive64Array.invoke(data, first, limit, step, ((Primitive64Array) left).data, function, ((Primitive64Array) right).data); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left.doubleValue(i), right.doubleValue(i)); - } - } - } - - protected static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D left, - final BinaryFunction function, final double right) { - if (left instanceof Primitive64Array) { - Primitive64Array.invoke(data, first, limit, step, ((Primitive64Array) left).data, function, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left.doubleValue(i), right); - } - } - } - - protected static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D values, - final ParameterFunction function, final int aParam) { - if (values instanceof Primitive64Array) { - Primitive64Array.invoke(data, first, limit, step, ((Primitive64Array) values).data, function, aParam); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(values.doubleValue(i), aParam); - } - } - } - - protected static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D values, - final UnaryFunction function) { - if (values instanceof Primitive64Array) { - Primitive64Array.invoke(data, first, limit, step, ((Primitive64Array) values).data, function); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(values.doubleValue(i)); - } - } - } - - protected static void invoke(final double[] data, final int first, final int limit, final int step, final double left, - final BinaryFunction function, final Access1D right) { - if (right instanceof Primitive64Array) { - Primitive64Array.invoke(data, first, limit, step, left, function, ((Primitive64Array) right).data); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left, right.doubleValue(i)); - } - } - } - - protected static void invoke(final double[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { - for (int i = first; i < limit; i += step) { - aVisitor.invoke(data[i]); - } - } - - static void invoke(final double[] data, final int first, final int limit, final int step, final double left, final BinaryFunction function, - final double[] right) { - if (function == PrimitiveMath.ADD) { - Primitive64Array.add(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.DIVIDE) { - Primitive64Array.divide(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.MULTIPLY) { - Primitive64Array.multiply(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.SUBTRACT) { - Primitive64Array.subtract(data, first, limit, step, left, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left, right[i]); - } - } - } - - static void invoke(final double[] data, final int first, final int limit, final int step, final double[] left, final BinaryFunction function, - final double right) { - if (function == PrimitiveMath.ADD) { - Primitive64Array.add(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.DIVIDE) { - Primitive64Array.divide(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.MULTIPLY) { - Primitive64Array.multiply(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.SUBTRACT) { - Primitive64Array.subtract(data, first, limit, step, left, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left[i], right); - } - } - } - - static void invoke(final double[] data, final int first, final int limit, final int step, final double[] left, final BinaryFunction function, - final double[] right) { - if (function == PrimitiveMath.ADD) { - Primitive64Array.add(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.DIVIDE) { - Primitive64Array.divide(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.MULTIPLY) { - Primitive64Array.multiply(data, first, limit, step, left, right); - } else if (function == PrimitiveMath.SUBTRACT) { - Primitive64Array.subtract(data, first, limit, step, left, right); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left[i], right[i]); - } - } - } - - static void invoke(final double[] data, final int first, final int limit, final int step, final double[] values, final ParameterFunction function, - final int aParam) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(values[i], aParam); - } - } - - static void invoke(final double[] data, final int first, final int limit, final int step, final double[] values, final UnaryFunction function) { - if (function == PrimitiveMath.NEGATE) { - Primitive64Array.negate(data, first, limit, step, values); - } else if (function instanceof FixedFirst) { - final FixedFirst tmpFunc = (FixedFirst) function; - Primitive64Array.invoke(data, first, limit, step, tmpFunc.doubleValue(), tmpFunc.getFunction(), values); - } else if (function instanceof FixedSecond) { - final FixedSecond tmpFunc = (FixedSecond) function; - Primitive64Array.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.doubleValue()); - } else if (function instanceof FixedParameter) { - final FixedParameter tmpFunc = (FixedParameter) function; - Primitive64Array.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.getParameter()); - } else { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(values[i]); - } - } - } - public final double[] data; /** @@ -398,19 +139,19 @@ public boolean equals(final Object anObj) { @Override public void fillMatching(final Access1D values) { - Primitive64Array.fill(data, values); + FillAll.fill(data, values); } @Override public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { int limit = MissingMath.toMinIntExact(this.count(), left.count(), right.count()); - Primitive64Array.invoke(data, 0, limit, 1, left, function, right); + OperationBinary.invoke(data, 0, limit, 1, left, function, right); } @Override public void fillMatching(final UnaryFunction function, final Access1D arguments) { int limit = MissingMath.toMinIntExact(this.count(), arguments.count()); - Primitive64Array.invoke(data, 0, limit, 1, arguments, function); + OperationUnary.invoke(data, 0, limit, 1, arguments, function); } @Override @@ -430,9 +171,9 @@ public final void sortAscending() { @Override public void sortDescending() { - Primitive64Array.negate(data, 0, data.length, 1, data); + CorePrimitiveOperation.negate(data, 0, data.length, 1, data); Arrays.parallelSort(data); - Primitive64Array.negate(data, 0, data.length, 1, data); + CorePrimitiveOperation.negate(data, 0, data.length, 1, data); } public OfDouble spliterator() { @@ -469,33 +210,33 @@ protected final double doubleValue(final int index) { @Override protected final void exchange(final int firstA, final int firstB, final int step, final int count) { - Primitive64Array.exchange(data, firstA, firstB, step, count); + Exchange.exchange(data, firstA, firstB, step, count); } @Override protected final void fill(final int first, final int limit, final Access1D left, final BinaryFunction function, final Access1D right) { - Primitive64Array.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override protected final void fill(final int first, final int limit, final Access1D left, final BinaryFunction function, final Double right) { - Primitive64Array.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override protected final void fill(final int first, final int limit, final Double left, final BinaryFunction function, final Access1D right) { - Primitive64Array.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override protected final void fill(final int first, final int limit, final int step, final Double value) { - Primitive64Array.fill(data, first, limit, step, value); + FillAll.fill(data, first, limit, step, value); } @Override protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { - Primitive64Array.fill(data, first, limit, step, supplier); + FillAll.fill(data, first, limit, step, supplier); } @Override @@ -535,32 +276,32 @@ protected boolean isSmall(final int index, final double comparedTo) { @Override protected final void modify(final int first, final int limit, final int step, final Access1D left, final BinaryFunction function) { - Primitive64Array.invoke(data, first, limit, step, left, function, this); + OperationBinary.invoke(data, first, limit, step, left, function, this); } @Override protected final void modify(final int first, final int limit, final int step, final BinaryFunction function, final Access1D right) { - Primitive64Array.invoke(data, first, limit, step, this, function, right); + OperationBinary.invoke(data, first, limit, step, this, function, right); } @Override protected final void modify(final int first, final int limit, final int step, final BinaryFunction function, final Double right) { - Primitive64Array.invoke(data, first, limit, step, data, function, right); + OperationBinary.invoke(data, first, limit, step, data, function, right); } @Override protected final void modify(final int first, final int limit, final int step, final Double left, final BinaryFunction function) { - Primitive64Array.invoke(data, first, limit, step, left, function, data); + OperationBinary.invoke(data, first, limit, step, left, function, data); } @Override protected final void modify(final int first, final int limit, final int step, final ParameterFunction function, final int parameter) { - Primitive64Array.invoke(data, first, limit, step, data, function, parameter); + OperationParameter.invoke(data, first, limit, step, data, function, parameter); } @Override protected final void modify(final int first, final int limit, final int step, final UnaryFunction function) { - Primitive64Array.invoke(data, first, limit, step, this, function); + OperationUnary.invoke(data, first, limit, step, this, function); } @Override @@ -590,7 +331,7 @@ protected final void set(final int index, final Comparable value) { @Override protected final void visit(final int first, final int limit, final int step, final VoidFunction visitor) { - Primitive64Array.invoke(data, first, limit, step, visitor); + OperationVoid.invoke(data, first, limit, step, visitor); } @Override diff --git a/src/org/ojalgo/array/ReferenceTypeArray.java b/src/org/ojalgo/array/ReferenceTypeArray.java index d741df824..d02505be2 100644 --- a/src/org/ojalgo/array/ReferenceTypeArray.java +++ b/src/org/ojalgo/array/ReferenceTypeArray.java @@ -26,6 +26,12 @@ import java.util.Spliterators; import org.ojalgo.array.operation.COPY; +import org.ojalgo.array.operation.Exchange; +import org.ojalgo.array.operation.FillAll; +import org.ojalgo.array.operation.OperationBinary; +import org.ojalgo.array.operation.OperationParameter; +import org.ojalgo.array.operation.OperationUnary; +import org.ojalgo.array.operation.OperationVoid; import org.ojalgo.function.BinaryFunction; import org.ojalgo.function.NullaryFunction; import org.ojalgo.function.ParameterFunction; @@ -33,7 +39,6 @@ import org.ojalgo.function.VoidFunction; import org.ojalgo.function.constant.PrimitiveMath; import org.ojalgo.function.special.MissingMath; -import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Mutate1D; @@ -44,78 +49,6 @@ */ public abstract class ReferenceTypeArray> extends PlainArray implements Mutate1D.Sortable { - protected static > void exchange(final N[] data, final int firstA, final int firstB, final int step, final int aCount) { - - int tmpIndexA = firstA; - int tmpIndexB = firstB; - - N tmpVal; - - for (int i = 0; i < aCount; i++) { - - tmpVal = data[tmpIndexA]; - data[tmpIndexA] = data[tmpIndexB]; - data[tmpIndexB] = tmpVal; - - tmpIndexA += step; - tmpIndexB += step; - } - } - - protected static > void fill(final N[] data, final int first, final int limit, final int step, final N value) { - for (int i = first; i < limit; i += step) { - data[i] = value; - } - } - - protected static > void fill(final N[] data, final int first, final int limit, final int step, final NullaryFunction supplier, - Scalar.Factory scalar) { - for (int i = first; i < limit; i += step) { - data[i] = scalar.cast(supplier.invoke()); - } - } - - protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, - final BinaryFunction function, final Access1D right) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left.get(i), right.get(i)); - } - } - - protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, - final BinaryFunction function, final N right) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left.get(i), right); - } - } - - protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, - final ParameterFunction function, final int aParam) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(value.get(i), aParam); - } - } - - protected static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, - final UnaryFunction function) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(value.get(i)); - } - } - - protected static > void invoke(final N[] data, final int first, final int limit, final int step, final N left, - final BinaryFunction function, final Access1D right) { - for (int i = first; i < limit; i += step) { - data[i] = function.invoke(left, right.get(i)); - } - } - - protected static > void invoke(final N[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { - for (int i = first; i < limit; i += step) { - aVisitor.invoke(data[i]); - } - } - public final N[] data; ReferenceTypeArray(final DenseArray.Factory factory, final int length) { @@ -145,9 +78,7 @@ public boolean equals(final Object anObj) { @Override public void fillMatching(final Access1D values) { - for (int i = 0, limit = (int) Math.min(this.count(), values.count()); i < limit; i++) { - data[i] = this.factory().scalar().cast(values.get(i)); - } + FillAll.fill(data, values, this.factory().scalar()); } @Override @@ -191,32 +122,32 @@ protected final N[] copyOfData() { @Override protected final void exchange(final int firstA, final int firstB, final int step, final int count) { - ReferenceTypeArray.exchange(data, firstA, firstB, step, count); + Exchange.exchange(data, firstA, firstB, step, count); } @Override protected final void fill(final int first, final int limit, final Access1D left, final BinaryFunction function, final Access1D right) { - ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override protected final void fill(final int first, final int limit, final Access1D left, final BinaryFunction function, final N right) { - ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override protected final void fill(final int first, final int limit, final int step, final N value) { - ReferenceTypeArray.fill(data, first, limit, step, value); + FillAll.fill(data, first, limit, step, value); } @Override protected final void fill(final int first, final int limit, final int step, final NullaryFunction supplier) { - ReferenceTypeArray.fill(data, first, limit, step, supplier, this.factory().scalar()); + FillAll.fill(data, first, limit, step, supplier, this.factory().scalar()); } @Override protected final void fill(final int first, final int limit, final N left, final BinaryFunction function, final Access1D right) { - ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } @Override @@ -237,32 +168,32 @@ protected final N get(final int index) { @Override protected final void modify(final int first, final int limit, final int step, final Access1D left, final BinaryFunction function) { - ReferenceTypeArray.invoke(data, first, limit, step, left, function, this); + OperationBinary.invoke(data, first, limit, step, left, function, this); } @Override protected final void modify(final int first, final int limit, final int step, final BinaryFunction function, final Access1D right) { - ReferenceTypeArray.invoke(data, first, limit, step, this, function, right); + OperationBinary.invoke(data, first, limit, step, this, function, right); } @Override protected final void modify(final int first, final int limit, final int step, final BinaryFunction function, final N right) { - ReferenceTypeArray.invoke(data, first, limit, step, this, function, right); + OperationBinary.invoke(data, first, limit, step, this, function, right); } @Override protected final void modify(final int first, final int limit, final int step, final N left, final BinaryFunction function) { - ReferenceTypeArray.invoke(data, first, limit, step, left, function, this); + OperationBinary.invoke(data, first, limit, step, left, function, this); } @Override protected final void modify(final int first, final int limit, final int step, final ParameterFunction function, final int parameter) { - ReferenceTypeArray.invoke(data, first, limit, step, this, function, parameter); + OperationParameter.invoke(data, first, limit, step, data, function, parameter); } @Override protected final void modify(final int first, final int limit, final int step, final UnaryFunction function) { - ReferenceTypeArray.invoke(data, first, limit, step, this, function); + OperationUnary.invoke(data, first, limit, step, this, function); } @Override @@ -292,7 +223,7 @@ protected final void set(final int index, final Comparable value) { @Override protected final void visit(final int first, final int limit, final int step, final VoidFunction visitor) { - ReferenceTypeArray.invoke(data, first, limit, step, visitor); + OperationVoid.invoke(data, first, limit, step, visitor); } @Override diff --git a/src/org/ojalgo/array/operation/ArrayOperation.java b/src/org/ojalgo/array/operation/ArrayOperation.java index 991902374..28ec423a8 100644 --- a/src/org/ojalgo/array/operation/ArrayOperation.java +++ b/src/org/ojalgo/array/operation/ArrayOperation.java @@ -51,6 +51,7 @@ static void setThresholdsMaxValue(final int value) { ApplyLU.THRESHOLD = Math.min(value, ApplyLU.THRESHOLD); ASUM.THRESHOLD = Math.min(value, ASUM.THRESHOLD); AXPY.THRESHOLD = Math.min(value, AXPY.THRESHOLD); + CorePrimitiveOperation.THRESHOLD = Math.min(value, CorePrimitiveOperation.THRESHOLD); CABS1.THRESHOLD = Math.min(value, CABS1.THRESHOLD); COPY.THRESHOLD = Math.min(value, COPY.THRESHOLD); DOT.THRESHOLD = Math.min(value, DOT.THRESHOLD); @@ -73,6 +74,10 @@ static void setThresholdsMaxValue(final int value) { MultiplyNeither.THRESHOLD = Math.min(value, MultiplyNeither.THRESHOLD); MultiplyRight.THRESHOLD = Math.min(value, MultiplyRight.THRESHOLD); NRM2.THRESHOLD = Math.min(value, NRM2.THRESHOLD); + OperationBinary.THRESHOLD = Math.min(value, OperationBinary.THRESHOLD); + OperationParameter.THRESHOLD = Math.min(value, OperationParameter.THRESHOLD); + OperationUnary.THRESHOLD = Math.min(value, OperationUnary.THRESHOLD); + OperationVoid.THRESHOLD = Math.min(value, OperationVoid.THRESHOLD); ROT.THRESHOLD = Math.min(value, ROT.THRESHOLD); RotateLeft.THRESHOLD = Math.min(value, RotateLeft.THRESHOLD); RotateRight.THRESHOLD = Math.min(value, RotateRight.THRESHOLD); @@ -103,6 +108,7 @@ static void setThresholdsMinValue(final int value) { ApplyLU.THRESHOLD = Math.max(value, ApplyLU.THRESHOLD); ASUM.THRESHOLD = Math.max(value, ASUM.THRESHOLD); AXPY.THRESHOLD = Math.max(value, AXPY.THRESHOLD); + CorePrimitiveOperation.THRESHOLD = Math.max(value, CorePrimitiveOperation.THRESHOLD); CABS1.THRESHOLD = Math.max(value, CABS1.THRESHOLD); COPY.THRESHOLD = Math.max(value, COPY.THRESHOLD); DOT.THRESHOLD = Math.max(value, DOT.THRESHOLD); @@ -125,6 +131,10 @@ static void setThresholdsMinValue(final int value) { MultiplyNeither.THRESHOLD = Math.max(value, MultiplyNeither.THRESHOLD); MultiplyRight.THRESHOLD = Math.max(value, MultiplyRight.THRESHOLD); NRM2.THRESHOLD = Math.max(value, NRM2.THRESHOLD); + OperationBinary.THRESHOLD = Math.max(value, OperationBinary.THRESHOLD); + OperationParameter.THRESHOLD = Math.max(value, OperationParameter.THRESHOLD); + OperationUnary.THRESHOLD = Math.max(value, OperationUnary.THRESHOLD); + OperationVoid.THRESHOLD = Math.max(value, OperationVoid.THRESHOLD); ROT.THRESHOLD = Math.max(value, ROT.THRESHOLD); RotateLeft.THRESHOLD = Math.max(value, RotateLeft.THRESHOLD); RotateRight.THRESHOLD = Math.max(value, RotateRight.THRESHOLD); diff --git a/src/org/ojalgo/array/operation/CorePrimitiveOperation.java b/src/org/ojalgo/array/operation/CorePrimitiveOperation.java new file mode 100644 index 000000000..b813bad79 --- /dev/null +++ b/src/org/ojalgo/array/operation/CorePrimitiveOperation.java @@ -0,0 +1,188 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array.operation; + +public final class CorePrimitiveOperation implements ArrayOperation { + + public static int THRESHOLD = 256; + + public static void negate(final double[] data, final int first, final int limit, final int step, final double[] values) { + for (int i = first; i < limit; i += step) { + data[i] = -values[i]; + } + } + + public static void negate(final float[] data, final int first, final int limit, final int step, final float[] values) { + for (int i = first; i < limit; i += step) { + data[i] = -values[i]; + } + } + + static void add(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left + right[i]; + } + } + + static void add(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] + right; + } + } + + static void add(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] + right[i]; + } + } + + static void add(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left + right[i]; + } + } + + static void add(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] + right; + } + } + + static void add(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] + right[i]; + } + } + + static void divide(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left / right[i]; + } + } + + static void divide(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] / right; + } + } + + static void divide(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] / right[i]; + } + } + + static void divide(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left / right[i]; + } + } + + static void divide(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] / right; + } + } + + static void divide(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] / right[i]; + } + } + + static void multiply(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left * right[i]; + } + } + + static void multiply(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] * right; + } + } + + static void multiply(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] * right[i]; + } + } + + static void multiply(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left * right[i]; + } + } + + static void multiply(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] * right; + } + } + + static void multiply(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] * right[i]; + } + } + + static void subtract(final double[] data, final int first, final int limit, final int step, final double left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left - right[i]; + } + } + + static void subtract(final double[] data, final int first, final int limit, final int step, final double[] left, final double right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] - right; + } + } + + static void subtract(final double[] data, final int first, final int limit, final int step, final double[] left, final double[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] - right[i]; + } + } + + static void subtract(final float[] data, final int first, final int limit, final int step, final float left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left - right[i]; + } + } + + static void subtract(final float[] data, final int first, final int limit, final int step, final float[] left, final float right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] - right; + } + } + + static void subtract(final float[] data, final int first, final int limit, final int step, final float[] left, final float[] right) { + for (int i = first; i < limit; i += step) { + data[i] = left[i] - right[i]; + } + } + + public int threshold() { + return THRESHOLD; + } + +} diff --git a/src/org/ojalgo/array/operation/Exchange.java b/src/org/ojalgo/array/operation/Exchange.java new file mode 100644 index 000000000..b963cb861 --- /dev/null +++ b/src/org/ojalgo/array/operation/Exchange.java @@ -0,0 +1,86 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array.operation; + +public final class Exchange implements BLAS1 { + + public static int THRESHOLD = 256; + + public static void exchange(final double[] data, final int firstA, final int firstB, final int step, final int count) { + + int indexA = firstA; + int indexB = firstB; + + double tmpVal; + + for (int i = 0; i < count; i++) { + + tmpVal = data[indexA]; + data[indexA] = data[indexB]; + data[indexB] = tmpVal; + + indexA += step; + indexB += step; + } + } + + public static void exchange(final float[] data, final int firstA, final int firstB, final int step, final int count) { + + int indexA = firstA; + int indexB = firstB; + + float tmpVal; + + for (int i = 0; i < count; i++) { + + tmpVal = data[indexA]; + data[indexA] = data[indexB]; + data[indexB] = tmpVal; + + indexA += step; + indexB += step; + } + } + + public static > void exchange(final N[] data, final int firstA, final int firstB, final int step, final int count) { + + int indexA = firstA; + int indexB = firstB; + + N tmpVal; + + for (int i = 0; i < count; i++) { + + tmpVal = data[indexA]; + data[indexA] = data[indexB]; + data[indexB] = tmpVal; + + indexA += step; + indexB += step; + } + } + + public int threshold() { + return THRESHOLD; + } + +} diff --git a/src/org/ojalgo/array/operation/FillAll.java b/src/org/ojalgo/array/operation/FillAll.java index 3782a521d..d86710f28 100644 --- a/src/org/ojalgo/array/operation/FillAll.java +++ b/src/org/ojalgo/array/operation/FillAll.java @@ -21,10 +21,72 @@ */ package org.ojalgo.array.operation; +import org.ojalgo.function.NullaryFunction; +import org.ojalgo.scalar.Scalar; +import org.ojalgo.structure.Access1D; + public final class FillAll implements ArrayOperation { public static int THRESHOLD = 128; + public static void fill(final double[] data, final Access1D values) { + final int limit = Math.min(data.length, values.size()); + for (int i = 0; i < limit; i++) { + data[i] = values.doubleValue(i); + } + } + + public static void fill(final double[] data, final int first, final int limit, final int step, final double value) { + for (int i = first; i < limit; i += step) { + data[i] = value; + } + } + + public static void fill(final double[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { + for (int i = first; i < limit; i += step) { + data[i] = supplier.doubleValue(); + } + } + + public static void fill(final float[] data, final Access1D values) { + final int limit = Math.min(data.length, values.size()); + for (int i = 0; i < limit; i++) { + data[i] = values.floatValue(i); + } + } + + public static void fill(final float[] data, final int first, final int limit, final int step, final float value) { + for (int i = first; i < limit; i += step) { + data[i] = value; + } + } + + public static void fill(final float[] data, final int first, final int limit, final int step, final NullaryFunction supplier) { + for (int i = first; i < limit; i += step) { + data[i] = supplier.floatValue(); + } + } + + public static > void fill(final N[] data, final Access1D values, Scalar.Factory scalar) { + final int limit = Math.min(data.length, values.size()); + for (int i = 0; i < limit; i++) { + data[i] = scalar.cast(values.get(i)); + } + } + + public static > void fill(final N[] data, final int first, final int limit, final int step, final N value) { + for (int i = first; i < limit; i += step) { + data[i] = value; + } + } + + public static > void fill(final N[] data, final int first, final int limit, final int step, final NullaryFunction supplier, + Scalar.Factory scalar) { + for (int i = first; i < limit; i += step) { + data[i] = scalar.cast(supplier.invoke()); + } + } + @Override public int threshold() { return THRESHOLD; diff --git a/src/org/ojalgo/array/operation/MultiplyBoth.java b/src/org/ojalgo/array/operation/MultiplyBoth.java index 7fd360ec5..96f6e0e2c 100644 --- a/src/org/ojalgo/array/operation/MultiplyBoth.java +++ b/src/org/ojalgo/array/operation/MultiplyBoth.java @@ -561,7 +561,7 @@ public void conquer(final int first, final int limit) { tmpConquerer.invoke(0, ((int) left.count()) / complexity, THRESHOLD); }; - public static > MultiplyBoth.Generic newGeneric(final long rows, final long columns) { + public static > MultiplyBoth.Generic newGeneric(final int rows, final int columns) { if (rows > THRESHOLD) { @@ -584,7 +584,11 @@ public void conquer(final int first, final int limit) { } } - public static MultiplyBoth.Primitive newPrimitive64(final long rows, final long columns) { + public static MultiplyBoth.Primitive newPrimitive32(final int rows, final int columns) { + return MultiplyBoth.newPrimitive64(rows, columns); + } + + public static MultiplyBoth.Primitive newPrimitive64(final int rows, final int columns) { if (rows > THRESHOLD) { return PRIMITIVE_MT; } else if (rows == 10) { @@ -612,10 +616,6 @@ public static MultiplyBoth.Primitive newPrimitive64(final long rows, final long } } - public static MultiplyBoth.Primitive newPrimitive32(final int rows, final int columns) { - return MultiplyBoth.newPrimitive64(rows, columns); - } - static void invoke(final double[] product, final int firstColumn, final int columnLimit, final Access1D left, final int complexity, final Access1D right) { @@ -688,14 +688,14 @@ static > void invokeGeneric(final TransformableRegion pro } } - static void invokePrimitive64(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, + static void invokePrimitive32(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, final int complexity, final Access1D right) { final int tmpRowDim = (int) product.countRows(); final int tmpColDim = (int) product.countColumns(); - final double[] tmpLeftRow = new double[complexity]; - double tmpVal; + final float[] tmpLeftRow = new float[complexity]; + float tmpVal; int tmpFirst = 0; int tmpLimit = complexity; @@ -706,7 +706,7 @@ static void invokePrimitive64(final TransformableRegion product, final i final int tmpLimitOfRow = MatrixStore.limitOfRow(left, i, complexity); for (int c = tmpFirstInRow; c < tmpLimitOfRow; c++) { - tmpLeftRow[c] = left.doubleValue(Structure2D.index(tmpRowDim, i, c)); + tmpLeftRow[c] = left.floatValue(Structure2D.index(tmpRowDim, i, c)); } for (int j = 0; j < tmpColDim; j++) { @@ -715,23 +715,23 @@ static void invokePrimitive64(final TransformableRegion product, final i tmpFirst = MatrixStore.firstInColumn(right, j, tmpFirstInRow); tmpLimit = MatrixStore.limitOfColumn(right, j, tmpLimitOfRow); - tmpVal = PrimitiveMath.ZERO; + tmpVal = 0F; for (int c = tmpFirst; c < tmpLimit; c++) { - tmpVal += tmpLeftRow[c] * right.doubleValue(c + tmpColBase); + tmpVal += tmpLeftRow[c] * right.floatValue(c + tmpColBase); } product.set(i, j, tmpVal); } } } - static void invokePrimitive32(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, + static void invokePrimitive64(final TransformableRegion product, final int firstRow, final int rowLimit, final Access1D left, final int complexity, final Access1D right) { final int tmpRowDim = (int) product.countRows(); final int tmpColDim = (int) product.countColumns(); - final float[] tmpLeftRow = new float[complexity]; - float tmpVal; + final double[] tmpLeftRow = new double[complexity]; + double tmpVal; int tmpFirst = 0; int tmpLimit = complexity; @@ -742,7 +742,7 @@ static void invokePrimitive32(final TransformableRegion product, final i final int tmpLimitOfRow = MatrixStore.limitOfRow(left, i, complexity); for (int c = tmpFirstInRow; c < tmpLimitOfRow; c++) { - tmpLeftRow[c] = left.floatValue(Structure2D.index(tmpRowDim, i, c)); + tmpLeftRow[c] = left.doubleValue(Structure2D.index(tmpRowDim, i, c)); } for (int j = 0; j < tmpColDim; j++) { @@ -751,9 +751,9 @@ static void invokePrimitive32(final TransformableRegion product, final i tmpFirst = MatrixStore.firstInColumn(right, j, tmpFirstInRow); tmpLimit = MatrixStore.limitOfColumn(right, j, tmpLimitOfRow); - tmpVal = 0F; + tmpVal = PrimitiveMath.ZERO; for (int c = tmpFirst; c < tmpLimit; c++) { - tmpVal += tmpLeftRow[c] * right.floatValue(c + tmpColBase); + tmpVal += tmpLeftRow[c] * right.doubleValue(c + tmpColBase); } product.set(i, j, tmpVal); } diff --git a/src/org/ojalgo/array/operation/OperationBinary.java b/src/org/ojalgo/array/operation/OperationBinary.java new file mode 100644 index 000000000..8eb59a916 --- /dev/null +++ b/src/org/ojalgo/array/operation/OperationBinary.java @@ -0,0 +1,227 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array.operation; + +import org.ojalgo.array.Primitive32Array; +import org.ojalgo.array.Primitive64Array; +import org.ojalgo.function.BinaryFunction; +import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.structure.Access1D; + +public final class OperationBinary implements ArrayOperation { + + public static int THRESHOLD = 256; + + public static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D left, + final BinaryFunction function, final Access1D right) { + if ((left instanceof Primitive64Array) && (right instanceof Primitive64Array)) { + OperationBinary.invoke(data, first, limit, step, ((Primitive64Array) left).data, function, ((Primitive64Array) right).data); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left.doubleValue(i), right.doubleValue(i)); + } + } + } + + public static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D left, + final BinaryFunction function, final double right) { + if (left instanceof Primitive64Array) { + OperationBinary.invoke(data, first, limit, step, ((Primitive64Array) left).data, function, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left.doubleValue(i), right); + } + } + } + + public static void invoke(final double[] data, final int first, final int limit, final int step, final double left, final BinaryFunction function, + final Access1D right) { + if (right instanceof Primitive64Array) { + OperationBinary.invoke(data, first, limit, step, left, function, ((Primitive64Array) right).data); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left, right.doubleValue(i)); + } + } + } + + public static void invoke(final double[] data, final int first, final int limit, final int step, final double left, final BinaryFunction function, + final double[] right) { + if (function == PrimitiveMath.ADD) { + CorePrimitiveOperation.add(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.DIVIDE) { + CorePrimitiveOperation.divide(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.MULTIPLY) { + CorePrimitiveOperation.multiply(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.SUBTRACT) { + CorePrimitiveOperation.subtract(data, first, limit, step, left, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left, right[i]); + } + } + } + + public static void invoke(final double[] data, final int first, final int limit, final int step, final double[] left, final BinaryFunction function, + final double right) { + if (function == PrimitiveMath.ADD) { + CorePrimitiveOperation.add(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.DIVIDE) { + CorePrimitiveOperation.divide(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.MULTIPLY) { + CorePrimitiveOperation.multiply(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.SUBTRACT) { + CorePrimitiveOperation.subtract(data, first, limit, step, left, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left[i], right); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D left, + final BinaryFunction function, final Access1D right) { + if ((left instanceof Primitive32Array) && (right instanceof Primitive32Array)) { + OperationBinary.invoke(data, first, limit, step, ((Primitive32Array) left).data, function, ((Primitive32Array) right).data); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left.floatValue(i), right.floatValue(i)); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D left, + final BinaryFunction function, final float right) { + if (left instanceof Primitive32Array) { + OperationBinary.invoke(data, first, limit, step, ((Primitive32Array) left).data, function, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left.floatValue(i), right); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final float left, final BinaryFunction function, + final Access1D right) { + if (right instanceof Primitive32Array) { + OperationBinary.invoke(data, first, limit, step, left, function, ((Primitive32Array) right).data); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left, right.floatValue(i)); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final float left, final BinaryFunction function, + final float[] right) { + if (function == PrimitiveMath.ADD) { + CorePrimitiveOperation.add(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.DIVIDE) { + CorePrimitiveOperation.divide(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.MULTIPLY) { + CorePrimitiveOperation.multiply(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.SUBTRACT) { + CorePrimitiveOperation.subtract(data, first, limit, step, left, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left, right[i]); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final float[] left, final BinaryFunction function, + final float right) { + if (function == PrimitiveMath.ADD) { + CorePrimitiveOperation.add(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.DIVIDE) { + CorePrimitiveOperation.divide(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.MULTIPLY) { + CorePrimitiveOperation.multiply(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.SUBTRACT) { + CorePrimitiveOperation.subtract(data, first, limit, step, left, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left[i], right); + } + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, + final BinaryFunction function, final Access1D right) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left.get(i), right.get(i)); + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D left, + final BinaryFunction function, final N right) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left.get(i), right); + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int step, final N left, + final BinaryFunction function, final Access1D right) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left, right.get(i)); + } + } + + static void invoke(final double[] data, final int first, final int limit, final int step, final double[] left, final BinaryFunction function, + final double[] right) { + if (function == PrimitiveMath.ADD) { + CorePrimitiveOperation.add(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.DIVIDE) { + CorePrimitiveOperation.divide(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.MULTIPLY) { + CorePrimitiveOperation.multiply(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.SUBTRACT) { + CorePrimitiveOperation.subtract(data, first, limit, step, left, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left[i], right[i]); + } + } + } + + static void invoke(final float[] data, final int first, final int limit, final int step, final float[] left, final BinaryFunction function, + final float[] right) { + if (function == PrimitiveMath.ADD) { + CorePrimitiveOperation.add(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.DIVIDE) { + CorePrimitiveOperation.divide(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.MULTIPLY) { + CorePrimitiveOperation.multiply(data, first, limit, step, left, right); + } else if (function == PrimitiveMath.SUBTRACT) { + CorePrimitiveOperation.subtract(data, first, limit, step, left, right); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(left[i], right[i]); + } + } + } + + public int threshold() { + return THRESHOLD; + } + +} diff --git a/src/org/ojalgo/array/operation/OperationParameter.java b/src/org/ojalgo/array/operation/OperationParameter.java new file mode 100644 index 000000000..272bbf7e2 --- /dev/null +++ b/src/org/ojalgo/array/operation/OperationParameter.java @@ -0,0 +1,55 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array.operation; + +import org.ojalgo.function.ParameterFunction; + +public final class OperationParameter implements ArrayOperation { + + public static int THRESHOLD = 256; + + public static void invoke(final double[] data, final int first, final int limit, final int step, final double[] values, + final ParameterFunction function, final int param) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values[i], param); + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final float[] values, + final ParameterFunction function, final int param) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values[i], param); + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int step, final N[] values, + final ParameterFunction function, final int param) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values[i], param); + } + } + + public int threshold() { + return THRESHOLD; + } + +} diff --git a/src/org/ojalgo/array/operation/OperationUnary.java b/src/org/ojalgo/array/operation/OperationUnary.java new file mode 100644 index 000000000..2aa2f230b --- /dev/null +++ b/src/org/ojalgo/array/operation/OperationUnary.java @@ -0,0 +1,109 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array.operation; + +import org.ojalgo.array.Primitive32Array; +import org.ojalgo.array.Primitive64Array; +import org.ojalgo.function.BinaryFunction.FixedFirst; +import org.ojalgo.function.BinaryFunction.FixedSecond; +import org.ojalgo.function.ParameterFunction.FixedParameter; +import org.ojalgo.function.UnaryFunction; +import org.ojalgo.function.constant.PrimitiveMath; +import org.ojalgo.structure.Access1D; + +public final class OperationUnary implements ArrayOperation { + + public static int THRESHOLD = 256; + + public static void invoke(final double[] data, final int first, final int limit, final int step, final Access1D values, + final UnaryFunction function) { + if (values instanceof Primitive64Array) { + OperationUnary.invoke(data, first, limit, step, ((Primitive64Array) values).data, function); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values.doubleValue(i)); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final Access1D values, + final UnaryFunction function) { + if (values instanceof Primitive32Array) { + OperationUnary.invoke(data, first, limit, step, ((Primitive32Array) values).data, function); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values.floatValue(i)); + } + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final float[] values, + final UnaryFunction function) { + if (function == PrimitiveMath.NEGATE) { + CorePrimitiveOperation.negate(data, first, limit, step, values); + } else if (function instanceof FixedFirst) { + final FixedFirst tmpFunc = (FixedFirst) function; + OperationBinary.invoke(data, first, limit, step, tmpFunc.floatValue(), tmpFunc.getFunction(), values); + } else if (function instanceof FixedSecond) { + final FixedSecond tmpFunc = (FixedSecond) function; + OperationBinary.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.floatValue()); + } else if (function instanceof FixedParameter) { + final FixedParameter tmpFunc = (FixedParameter) function; + OperationParameter.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.getParameter()); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values[i]); + } + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int step, final Access1D value, + final UnaryFunction function) { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(value.get(i)); + } + } + + static void invoke(final double[] data, final int first, final int limit, final int step, final double[] values, final UnaryFunction function) { + if (function == PrimitiveMath.NEGATE) { + CorePrimitiveOperation.negate(data, first, limit, step, values); + } else if (function instanceof FixedFirst) { + final FixedFirst tmpFunc = (FixedFirst) function; + OperationBinary.invoke(data, first, limit, step, tmpFunc.doubleValue(), tmpFunc.getFunction(), values); + } else if (function instanceof FixedSecond) { + final FixedSecond tmpFunc = (FixedSecond) function; + OperationBinary.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.doubleValue()); + } else if (function instanceof FixedParameter) { + final FixedParameter tmpFunc = (FixedParameter) function; + OperationParameter.invoke(data, first, limit, step, values, tmpFunc.getFunction(), tmpFunc.getParameter()); + } else { + for (int i = first; i < limit; i += step) { + data[i] = function.invoke(values[i]); + } + } + } + + public int threshold() { + return THRESHOLD; + } + +} diff --git a/src/org/ojalgo/array/operation/OperationVoid.java b/src/org/ojalgo/array/operation/OperationVoid.java new file mode 100644 index 000000000..ae86b59e6 --- /dev/null +++ b/src/org/ojalgo/array/operation/OperationVoid.java @@ -0,0 +1,52 @@ +/* + * Copyright 1997-2019 Optimatika + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.ojalgo.array.operation; + +import org.ojalgo.function.VoidFunction; + +public final class OperationVoid implements ArrayOperation { + + public static int THRESHOLD = 256; + + public static void invoke(final double[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { + for (int i = first; i < limit; i += step) { + aVisitor.invoke(data[i]); + } + } + + public static void invoke(final float[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { + for (int i = first; i < limit; i += step) { + aVisitor.invoke(data[i]); + } + } + + public static > void invoke(final N[] data, final int first, final int limit, final int step, final VoidFunction aVisitor) { + for (int i = first; i < limit; i += step) { + aVisitor.invoke(data[i]); + } + } + + public int threshold() { + return THRESHOLD; + } + +} diff --git a/src/org/ojalgo/array/operation/package-info.java b/src/org/ojalgo/array/operation/package-info.java index 7938817cb..023780e0c 100644 --- a/src/org/ojalgo/array/operation/package-info.java +++ b/src/org/ojalgo/array/operation/package-info.java @@ -1,8 +1,6 @@ /** - *

* Everythinng in this package should be considered library-private – it should only be used by other parts of - * ojAlgo! - *

+ * ojAlgo! Code in this package is often refactored (api-breaking) without even a notice in the changelog. * * @author apete */ diff --git a/src/org/ojalgo/function/BinaryFunction.java b/src/org/ojalgo/function/BinaryFunction.java index 827aec0d3..212084593 100644 --- a/src/org/ojalgo/function/BinaryFunction.java +++ b/src/org/ojalgo/function/BinaryFunction.java @@ -61,6 +61,10 @@ public static final class FixedFirst> implements UnaryFu myValue = Scalar.doubleValue(arg1); } + public float floatValue() { + return (float) myValue; + } + public double doubleValue() { return myValue; } @@ -119,6 +123,10 @@ public static final class FixedSecond> implements UnaryF myValue = Scalar.doubleValue(arg2); } + public float floatValue() { + return (float) myValue; + } + public double doubleValue() { return myValue; } diff --git a/src/org/ojalgo/matrix/BasicMatrix.java b/src/org/ojalgo/matrix/BasicMatrix.java index 1f2880774..0a24d73f9 100644 --- a/src/org/ojalgo/matrix/BasicMatrix.java +++ b/src/org/ojalgo/matrix/BasicMatrix.java @@ -656,7 +656,7 @@ public M subtract(final N scalarSubtrahend) { return this.getFactory().instantiate(retVal); } - public void supplyTo(final PhysicalStore receiver) { + public final void supplyTo(final PhysicalStore receiver) { myStore.supplyTo(receiver); } diff --git a/src/org/ojalgo/matrix/MatrixFactory.java b/src/org/ojalgo/matrix/MatrixFactory.java index e93a79c91..83f0d7af0 100644 --- a/src/org/ojalgo/matrix/MatrixFactory.java +++ b/src/org/ojalgo/matrix/MatrixFactory.java @@ -294,7 +294,7 @@ public B superimpose(final M matrix) { return this.self(); } - public void supplyTo(final PhysicalStore receiver) { + public final void supplyTo(final PhysicalStore receiver) { myDelegate.supplyTo(receiver); } @@ -850,7 +850,7 @@ public void set(final long index, final Comparable value) { } } - public void supplyTo(final PhysicalStore receiver) { + public final void supplyTo(final PhysicalStore receiver) { myDelegate.supplyTo(receiver); } } diff --git a/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java b/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java index eb137a775..6e7bc2729 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java +++ b/src/org/ojalgo/matrix/geometry/Primitive32Vector2.java @@ -11,7 +11,7 @@ public class Primitive32Vector2 extends GeometryVector { public float v0, v1; public Primitive32Vector2() { - super(MultiplyBoth.newPrimitive64(2L, 1L), 2L, 1L); + super(MultiplyBoth.newPrimitive64(2, 1), 2L, 1L); } public Primitive32Vector2(final float v0, final float v1) { @@ -80,10 +80,10 @@ public final int hashCode() { public final void modifyOne(final int row, final UnaryFunction modifier) { switch (row) { case 0: - v0 = (float) modifier.invoke(v0); + v0 = modifier.invoke(v0); break; case 1: - v1 = (float) modifier.invoke(v1); + v1 = modifier.invoke(v1); break; default: throw new IllegalArgumentException(); diff --git a/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java b/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java index 5f0da8978..00684e2ce 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java +++ b/src/org/ojalgo/matrix/geometry/Primitive32Vector3.java @@ -11,7 +11,7 @@ public class Primitive32Vector3 extends GeometryVector { public float v0, v1, v2; public Primitive32Vector3() { - super(MultiplyBoth.newPrimitive64(3L, 1L), 3L, 1L); + super(MultiplyBoth.newPrimitive64(3, 1), 3L, 1L); } public Primitive32Vector3(final float v0, final float v1, final float v2) { @@ -90,13 +90,13 @@ public final int hashCode() { public final void modifyOne(final int row, final UnaryFunction modifier) { switch (row) { case 0: - v0 = (float) modifier.invoke(v0); + v0 = modifier.invoke(v0); break; case 1: - v1 = (float) modifier.invoke(v1); + v1 = modifier.invoke(v1); break; case 2: - v2 = (float) modifier.invoke(v2); + v2 = modifier.invoke(v2); break; default: throw new IllegalArgumentException(); diff --git a/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java b/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java index 050ae7727..a472fad9d 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java +++ b/src/org/ojalgo/matrix/geometry/Primitive32Vector4.java @@ -11,7 +11,7 @@ public class Primitive32Vector4 extends GeometryVector { public float v0, v1, v2, v3; public Primitive32Vector4() { - super(MultiplyBoth.newPrimitive64(4L, 1L), 4L, 1L); + super(MultiplyBoth.newPrimitive64(4, 1), 4L, 1L); } @Override @@ -92,16 +92,16 @@ public final int hashCode() { public final void modifyOne(final int row, final UnaryFunction modifier) { switch (row) { case 0: - v0 = (float) modifier.invoke(v0); + v0 = modifier.invoke(v0); break; case 1: - v1 = (float) modifier.invoke(v1); + v1 = modifier.invoke(v1); break; case 2: - v2 = (float) modifier.invoke(v2); + v2 = modifier.invoke(v2); break; case 3: - v3 = (float) modifier.invoke(v3); + v3 = modifier.invoke(v3); break; default: throw new IllegalArgumentException(); diff --git a/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java b/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java index 5df871e73..5ab3f8a6e 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java +++ b/src/org/ojalgo/matrix/geometry/Primitive64Vector2.java @@ -11,7 +11,7 @@ public class Primitive64Vector2 extends GeometryVector { public double v0, v1; public Primitive64Vector2() { - super(MultiplyBoth.newPrimitive64(2L, 1L), 2L, 1L); + super(MultiplyBoth.newPrimitive64(2, 1), 2L, 1L); } public Primitive64Vector2(final double v0, final double v1) { diff --git a/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java b/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java index df553679c..1aab1728e 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java +++ b/src/org/ojalgo/matrix/geometry/Primitive64Vector3.java @@ -11,7 +11,7 @@ public class Primitive64Vector3 extends GeometryVector { public double v0, v1, v2; public Primitive64Vector3() { - super(MultiplyBoth.newPrimitive64(3L, 1L), 3L, 1L); + super(MultiplyBoth.newPrimitive64(3, 1), 3L, 1L); } public Primitive64Vector3(final double v0, final double v1, final double v2) { diff --git a/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java b/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java index ca7325f01..cc184dddb 100644 --- a/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java +++ b/src/org/ojalgo/matrix/geometry/Primitive64Vector4.java @@ -11,7 +11,7 @@ public class Primitive64Vector4 extends GeometryVector { public double v0, v1, v2, v3; public Primitive64Vector4() { - super(MultiplyBoth.newPrimitive64(4L, 1L), 4L, 1L); + super(MultiplyBoth.newPrimitive64(4, 1), 4L, 1L); } public Primitive64Vector4(final double v0, final double v1, final double v2, final double v3) { diff --git a/src/org/ojalgo/matrix/store/GenericStore.java b/src/org/ojalgo/matrix/store/GenericStore.java index 7bf8967da..d51aa7097 100644 --- a/src/org/ojalgo/matrix/store/GenericStore.java +++ b/src/org/ojalgo/matrix/store/GenericStore.java @@ -25,7 +25,14 @@ import java.util.List; import org.ojalgo.ProgrammingError; -import org.ojalgo.array.*; +import org.ojalgo.array.Array1D; +import org.ojalgo.array.Array2D; +import org.ojalgo.array.BasicArray; +import org.ojalgo.array.ComplexArray; +import org.ojalgo.array.DenseArray; +import org.ojalgo.array.QuaternionArray; +import org.ojalgo.array.RationalArray; +import org.ojalgo.array.ScalarArray; import org.ojalgo.array.operation.*; import org.ojalgo.concurrent.DivideAndConquer; import org.ojalgo.function.BinaryFunction; @@ -729,7 +736,7 @@ public void fillMatching(final Access1D left, final BinaryFunction functio @Override protected void conquer(final int first, final int limit) { - ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right); + OperationBinary.invoke(data, first, limit, 1, left, function, right); } }; @@ -738,7 +745,7 @@ protected void conquer(final int first, final int limit) { } else { - ReferenceTypeArray.invoke(data, 0, matchingCount, 1, left, function, right); + OperationBinary.invoke(data, 0, matchingCount, 1, left, function, right); } } @@ -753,7 +760,7 @@ public void fillMatching(final UnaryFunction function, final Access1D argu @Override protected void conquer(final int first, final int limit) { - ReferenceTypeArray.invoke(data, first, limit, 1, arguments, function); + OperationUnary.invoke(data, first, limit, 1, arguments, function); } }; @@ -762,7 +769,7 @@ protected void conquer(final int first, final int limit) { } else { - ReferenceTypeArray.invoke(data, 0, matchingCount, 1, arguments, function); + OperationUnary.invoke(data, 0, matchingCount, 1, arguments, function); } } @@ -1022,10 +1029,6 @@ public void conquer(final int aFirst, final int aLimit) { } } - public void supplyTo(final TransformableRegion receiver) { - receiver.fillMatching(this); - } - public Scalar toScalar(final long row, final long column) { return myUtility.get(row, column); } diff --git a/src/org/ojalgo/matrix/store/PhysicalStore.java b/src/org/ojalgo/matrix/store/PhysicalStore.java index 43d6b33c0..889a33a51 100644 --- a/src/org/ojalgo/matrix/store/PhysicalStore.java +++ b/src/org/ojalgo/matrix/store/PhysicalStore.java @@ -30,6 +30,7 @@ import org.ojalgo.function.aggregator.AggregatorSet; import org.ojalgo.matrix.transformation.Householder; import org.ojalgo.matrix.transformation.Rotation; +import org.ojalgo.netio.BasicLogger; import org.ojalgo.scalar.Scalar; import org.ojalgo.structure.Access1D; import org.ojalgo.structure.Access2D; @@ -180,4 +181,12 @@ default void modifyAny(final Transformation2D modifier) { */ void transformRight(Rotation transformation); + default void supplyTo(TransformableRegion receiver) { + if (this != receiver) { + receiver.fillMatching(this); + } else { + BasicLogger.error("Why do you this!"); + } + } + } diff --git a/src/org/ojalgo/matrix/store/Primitive32Store.java b/src/org/ojalgo/matrix/store/Primitive32Store.java index 2b5356f66..cca833bbc 100644 --- a/src/org/ojalgo/matrix/store/Primitive32Store.java +++ b/src/org/ojalgo/matrix/store/Primitive32Store.java @@ -59,11 +59,6 @@ public DenseArray.Factory array() { return Primitive32Array.FACTORY; } - @Override - public Householder makeHouseholder(final int length) { - return new Householder.Primitive32(length); - } - @Override public MatrixStore.Factory builder() { return MatrixStore.PRIMITIVE32; @@ -182,6 +177,11 @@ public Primitive32Store makeEye(long rows, long columns) { return retVal; } + @Override + public Householder makeHouseholder(final int length) { + return new Householder.Primitive32(length); + } + public Primitive32Store rows(Access1D... source) { final int tmpRowDim = source.length; @@ -850,10 +850,6 @@ public void conquer(final int first, final int limit) { } } - public void supplyTo(double[] receiver) { - myUtility.supplyTo(receiver); - } - public double[] toRawCopy1D() { return myUtility.toRawCopy1D(); } diff --git a/src/org/ojalgo/matrix/store/Primitive64Store.java b/src/org/ojalgo/matrix/store/Primitive64Store.java index 62ec2be64..4437eb9c3 100644 --- a/src/org/ojalgo/matrix/store/Primitive64Store.java +++ b/src/org/ojalgo/matrix/store/Primitive64Store.java @@ -722,7 +722,7 @@ public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D receiver) { - receiver.fillMatching(this); - } - public PrimitiveScalar toScalar(final long row, final long column) { return PrimitiveScalar.of(this.doubleValue(row, column)); } diff --git a/src/org/ojalgo/matrix/store/RawStore.java b/src/org/ojalgo/matrix/store/RawStore.java index 7a05fccc0..6a7f0e3be 100644 --- a/src/org/ojalgo/matrix/store/RawStore.java +++ b/src/org/ojalgo/matrix/store/RawStore.java @@ -1125,10 +1125,6 @@ public void substituteForwards(final Access2D body, final boolean unitDi SubstituteForwards.invoke(data, body, unitDiagonal, conjugated, identity); } - public void supplyTo(final TransformableRegion receiver) { - receiver.fillMatching(this); - } - public PrimitiveScalar toScalar(final long row, final long column) { return PrimitiveScalar.of(this.doubleValue(row, column)); } diff --git a/src/org/ojalgo/matrix/store/TransformableRegion.java b/src/org/ojalgo/matrix/store/TransformableRegion.java index ebf518c88..49eddbed6 100644 --- a/src/org/ojalgo/matrix/store/TransformableRegion.java +++ b/src/org/ojalgo/matrix/store/TransformableRegion.java @@ -322,9 +322,9 @@ protected ReceiverRegion(final TransformableRegion.FillByMultiplying multipli super(); if (multiplier instanceof MultiplyBoth.Primitive) { - myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.newPrimitive64(rows, columns); + myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.newPrimitive64(Math.toIntExact(rows), Math.toIntExact(columns)); } else if (multiplier instanceof MultiplyBoth.Generic) { - myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.newGeneric(rows, columns); + myMultiplier = (TransformableRegion.FillByMultiplying) MultiplyBoth.newGeneric(Math.toIntExact(rows), Math.toIntExact(columns)); } else { myMultiplier = multiplier; } diff --git a/src/org/ojalgo/structure/AccessScalar.java b/src/org/ojalgo/structure/AccessScalar.java index ef8bb26c2..3d4e78dd2 100644 --- a/src/org/ojalgo/structure/AccessScalar.java +++ b/src/org/ojalgo/structure/AccessScalar.java @@ -25,26 +25,6 @@ public interface AccessScalar extends NumberDefinition { - default byte byteValue() { - return (byte) this.shortValue(); - } - - default float floatValue() { - return (float) this.doubleValue(); - } - N get(); - default int intValue() { - return (int) this.longValue(); - } - - default long longValue() { - return Math.round(this.doubleValue()); - } - - default short shortValue() { - return (short) this.intValue(); - } - } diff --git a/src/org/ojalgo/type/NumberDefinition.java b/src/org/ojalgo/type/NumberDefinition.java index 1f8f7ff82..25804b8f2 100644 --- a/src/org/ojalgo/type/NumberDefinition.java +++ b/src/org/ojalgo/type/NumberDefinition.java @@ -28,17 +28,27 @@ */ public interface NumberDefinition { + default boolean booleanValue() { + return this.intValue() != 0; + } + default byte byteValue() { return (byte) this.intValue(); } double doubleValue(); - float floatValue(); + default float floatValue() { + return (float) this.doubleValue(); + } - int intValue(); + default int intValue() { + return Math.round(this.floatValue()); + } - long longValue(); + default long longValue() { + return Math.round(this.doubleValue()); + } default short shortValue() { return (short) this.intValue(); From 55ff50909431b0246e1b7d59bad3c230b5407a86 Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 24 Nov 2019 16:30:49 +0100 Subject: [PATCH 26/29] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 687199c71..2927c3775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ Added / Changed / Deprecated / Removed / Fixed / Security #### org.ojalgo.matrix -- PrimitiveDenseStore has been renamed Primitive64Store (and there is now also a Primitive32Store). GenericDenseStore was also renamed GenericStore. +- PrimitiveDenseStore has been renamed Primitive64Store (and there is now also a Primitive32Store). GenericDenseStore was also renamed GenericStore. Likewise PrimitiveMatrix is repalced by Primitive64Matrix and Primitive32Matrix. #### org.ojalgo.scalar From e112d5ba3a7ad9ec92df943ac9e51b7954358429 Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 24 Nov 2019 16:46:51 +0100 Subject: [PATCH 27/29] Cleanup --- src/org/ojalgo/algebra/ScalarOperation.java | 8 +- src/org/ojalgo/array/Array1D.java | 8 +- src/org/ojalgo/array/Array2D.java | 8 +- src/org/ojalgo/array/ArrayAnyD.java | 42 ++-- src/org/ojalgo/array/ArrayFactory.java | 26 +-- src/org/ojalgo/array/BigArray.java | 24 +-- src/org/ojalgo/array/BufferArray.java | 10 +- src/org/ojalgo/array/NumberList.java | 12 +- src/org/ojalgo/array/PlainArray.java | 24 +-- src/org/ojalgo/array/Primitive32Array.java | 20 +- src/org/ojalgo/array/Primitive64Array.java | 20 +- src/org/ojalgo/array/ReferenceTypeArray.java | 14 +- src/org/ojalgo/array/ScalarArray.java | 24 +-- src/org/ojalgo/array/SegmentedArray.java | 12 +- src/org/ojalgo/array/SparseArray.java | 32 ++-- src/org/ojalgo/array/operation/FillAll.java | 4 +- .../ojalgo/array/operation/MultiplyLeft.java | 8 +- .../array/operation/MultiplyNeither.java | 16 +- .../ojalgo/array/operation/MultiplyRight.java | 8 +- .../array/operation/SubstituteBackwards.java | 58 +++--- .../array/operation/SubstituteForwards.java | 56 +++--- src/org/ojalgo/equation/Equation.java | 16 +- src/org/ojalgo/function/BinaryFunction.java | 16 +- .../ojalgo/function/PredicateFunction.java | 8 +- src/org/ojalgo/function/UnaryFunction.java | 4 +- .../ojalgo/function/special/BetaFunction.java | 18 +- .../special/CombinatorialFunctions.java | 2 +- .../function/special/GammaFunction.java | 34 ++-- src/org/ojalgo/function/special/PowerOf2.java | 22 +-- src/org/ojalgo/matrix/MatrixFactory.java | 76 ++++---- .../matrix/decomposition/GeneralEvD.java | 8 +- .../matrix/decomposition/HermitianEvD.java | 16 +- .../matrix/geometry/GeometryVector.java | 24 +-- .../ojalgo/matrix/store/ColumnsSupplier.java | 8 +- src/org/ojalgo/matrix/store/GenericStore.java | 56 +++--- .../ojalgo/matrix/store/PhysicalStore.java | 16 +- .../ojalgo/matrix/store/Primitive32Store.java | 180 +++++++++--------- .../ojalgo/matrix/store/PrimitiveFactory.java | 26 +-- src/org/ojalgo/matrix/store/RawStore.java | 60 +++--- src/org/ojalgo/matrix/store/RowsSupplier.java | 8 +- src/org/ojalgo/matrix/store/SparseStore.java | 8 +- .../matrix/store/TransformableRegion.java | 40 ++-- .../matrix/transformation/Householder.java | 64 +++---- src/org/ojalgo/optimisation/Expression.java | 18 +- .../ojalgo/optimisation/GenericSolver.java | 8 +- src/org/ojalgo/optimisation/Optimisation.java | 2 +- .../convex/ConvexObjectiveFunction.java | 8 +- .../optimisation/linear/SimplexTableau.java | 96 +++++----- src/org/ojalgo/random/Deterministic.java | 16 +- src/org/ojalgo/random/RandomNumber.java | 8 +- src/org/ojalgo/scalar/BigScalar.java | 10 +- src/org/ojalgo/scalar/ComplexNumber.java | 10 +- src/org/ojalgo/scalar/ExactDecimal.java | 40 ++-- src/org/ojalgo/scalar/Money.java | 20 +- src/org/ojalgo/scalar/PrimitiveScalar.java | 10 +- src/org/ojalgo/scalar/Quaternion.java | 10 +- src/org/ojalgo/scalar/RationalNumber.java | 10 +- src/org/ojalgo/structure/ColumnView.java | 8 +- src/org/ojalgo/structure/ElementView1D.java | 8 +- src/org/ojalgo/structure/Factory1D.java | 4 +- src/org/ojalgo/structure/Factory2D.java | 8 +- src/org/ojalgo/structure/Mutate1D.java | 12 +- src/org/ojalgo/structure/Mutate2D.java | 4 +- src/org/ojalgo/structure/MutateAnyD.java | 4 +- src/org/ojalgo/structure/RowView.java | 8 +- .../ojalgo/type/context/NumberContext.java | 18 +- test/org/ojalgo/TestUtils.java | 100 +++++----- test/org/ojalgo/array/SparseTest.java | 46 ++--- .../ojalgo/function/multiary/LinearCase.java | 24 +-- .../function/special/BetaFunctionTest.java | 12 +- .../special/PochhammerSymbolTest.java | 8 +- test/org/ojalgo/matrix/BasicMatrixTest.java | 160 ++++++++-------- .../matrix/decomposition/CaseEigenvalue.java | 2 +- .../decomposition/DecompositionProblems.java | 2 +- test/org/ojalgo/netio/TestCSV.java | 64 +++---- .../linear/CommonsMathSimplexSolverTest.java | 2 +- .../optimisation/linear/PrimalDualTest.java | 108 +++++------ test/org/ojalgo/random/TDistributionTest.java | 4 +- 78 files changed, 1008 insertions(+), 1008 deletions(-) diff --git a/src/org/ojalgo/algebra/ScalarOperation.java b/src/org/ojalgo/algebra/ScalarOperation.java index 06b8c1212..ef9985c55 100644 --- a/src/org/ojalgo/algebra/ScalarOperation.java +++ b/src/org/ojalgo/algebra/ScalarOperation.java @@ -36,7 +36,7 @@ public interface Addition> extends ScalarOperation { /** * @return this + scalarAddend. */ - default T add(float scalarAddend) { + default T add(final float scalarAddend) { return this.add((double) scalarAddend); } @@ -57,7 +57,7 @@ public interface Division> extends ScalarOperation { /** * @return this / scalarDivisor. */ - default T divide(float scalarDivisor) { + default T divide(final float scalarDivisor) { return this.divide((double) scalarDivisor); } @@ -78,7 +78,7 @@ public interface Multiplication> extends ScalarOperat /** * @return this * scalarMultiplicand. */ - default T multiply(float scalarMultiplicand) { + default T multiply(final float scalarMultiplicand) { return this.multiply((double) scalarMultiplicand); } @@ -99,7 +99,7 @@ public interface Subtraction> extends ScalarOperation /** * @return this - scalarSubtrahend. */ - default T subtract(float scalarSubtrahend) { + default T subtract(final float scalarSubtrahend) { return this.subtract((double) scalarSubtrahend); } diff --git a/src/org/ojalgo/array/Array1D.java b/src/org/ojalgo/array/Array1D.java index aecb6d4b9..b32f44946 100644 --- a/src/org/ojalgo/array/Array1D.java +++ b/src/org/ojalgo/array/Array1D.java @@ -89,6 +89,10 @@ public Array1D make(final long count) { return this.makeDense(count); } + public Array1D makeDense(final long count) { + return myDelegate.makeToBeFilled(count).wrapInArray1D(); + } + public Array1D makeFilled(final long count, final NullaryFunction supplier) { return myDelegate.makeFilled(count, supplier).wrapInArray1D(); } @@ -106,10 +110,6 @@ public Array1D wrap(final BasicArray array) { return array.wrapInArray1D(); } - public Array1D makeDense(long count) { - return myDelegate.makeToBeFilled(count).wrapInArray1D(); - } - } static final class QuickAscendingSorter extends RecursiveAction { diff --git a/src/org/ojalgo/array/Array2D.java b/src/org/ojalgo/array/Array2D.java index e64269ced..4a3cd4cfd 100644 --- a/src/org/ojalgo/array/Array2D.java +++ b/src/org/ojalgo/array/Array2D.java @@ -156,6 +156,10 @@ public Array2D make(final long rows, final long columns) { return this.makeDense(rows, columns); } + public Array2D makeDense(final long rows, final long columns) { + return myDelegate.makeToBeFilled(rows, columns).wrapInArray2D(rows); + } + public Array2D makeFilled(final long rows, final long columns, final NullaryFunction supplier) { final BasicArray tmpDelegate = myDelegate.makeToBeFilled(rows, columns); @@ -257,10 +261,6 @@ public Scalar.Factory scalar() { return myDelegate.scalar(); } - public Array2D makeDense(long rows, long columns) { - return myDelegate.makeToBeFilled(rows, columns).wrapInArray2D(rows); - } - } public static final Factory BIG = new Factory<>(BigArray.FACTORY); diff --git a/src/org/ojalgo/array/ArrayAnyD.java b/src/org/ojalgo/array/ArrayAnyD.java index a376d245f..657518102 100644 --- a/src/org/ojalgo/array/ArrayAnyD.java +++ b/src/org/ojalgo/array/ArrayAnyD.java @@ -75,6 +75,15 @@ public FunctionSet function() { return myDelegate.function(); } + @Override + public ArrayAnyD make(final long... structure) { + return this.makeDense(structure); + } + + public ArrayAnyD makeDense(final long... structure) { + return myDelegate.makeToBeFilled(structure).wrapInArrayAnyD(structure); + } + /** * @deprecated v48 Use {@link ArrayAnyD#fillAll(NullaryFunction)} */ @@ -87,20 +96,11 @@ public ArrayAnyD makeSparse(final long... structure) { return myDelegate.makeStructuredZero(structure).wrapInArrayAnyD(structure); } - @Override - public ArrayAnyD make(final long... structure) { - return this.makeDense(structure); - } - @Override public Scalar.Factory scalar() { return myDelegate.scalar(); } - public ArrayAnyD makeDense(long... structure) { - return myDelegate.makeToBeFilled(structure).wrapInArrayAnyD(structure); - } - } public static final Factory BIG = new Factory<>(BigArray.FACTORY); @@ -133,32 +133,32 @@ private ArrayAnyD() { } @Override - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { myDelegate.add(index, addend); } @Override - public void add(final long index, final float addend) { + public void add(final long index, final double addend) { myDelegate.add(index, addend); } @Override - public void add(final long index, final Comparable addend) { + public void add(final long index, final float addend) { myDelegate.add(index, addend); } @Override - public void add(final long[] reference, final double addend) { + public void add(final long[] reference, final Comparable addend) { myDelegate.add(StructureAnyD.index(myStructure, reference), addend); } @Override - public void add(final long[] reference, final float addend) { + public void add(final long[] reference, final double addend) { myDelegate.add(StructureAnyD.index(myStructure, reference), addend); } @Override - public void add(final long[] reference, final Comparable addend) { + public void add(final long[] reference, final float addend) { myDelegate.add(StructureAnyD.index(myStructure, reference), addend); } @@ -456,32 +456,32 @@ public Array2D reduce(final int rowDimension, final int columnDimension, fina } @Override - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { myDelegate.set(index, value); } @Override - public void set(final long index, final float value) { + public void set(final long index, final double value) { myDelegate.set(index, value); } @Override - public void set(final long index, final Comparable value) { + public void set(final long index, final float value) { myDelegate.set(index, value); } @Override - public void set(final long[] reference, final double value) { + public void set(final long[] reference, final Comparable value) { myDelegate.set(StructureAnyD.index(myStructure, reference), value); } @Override - public void set(final long[] reference, final float value) { + public void set(final long[] reference, final double value) { myDelegate.set(StructureAnyD.index(myStructure, reference), value); } @Override - public void set(final long[] reference, final Comparable value) { + public void set(final long[] reference, final float value) { myDelegate.set(StructureAnyD.index(myStructure, reference), value); } diff --git a/src/org/ojalgo/array/ArrayFactory.java b/src/org/ojalgo/array/ArrayFactory.java index 8b30a8de5..a7f36f0e5 100644 --- a/src/org/ojalgo/array/ArrayFactory.java +++ b/src/org/ojalgo/array/ArrayFactory.java @@ -44,6 +44,15 @@ public final I copy(final Access1D source) { return retVal; } + public final I copy(final Comparable... source) { + final int length = source.length; + final I retVal = this.makeToBeFilled(length); + for (int i = 0; i < length; i++) { + retVal.set(i, source[i]); + } + return retVal; + } + public final I copy(final double... source) { final int length = source.length; final I retVal = this.makeToBeFilled(length); @@ -62,17 +71,12 @@ public final I copy(final List> source) { return retVal; } - public final I copy(final Comparable... source) { - final int length = source.length; - final I retVal = this.makeToBeFilled(length); - for (int i = 0; i < length; i++) { - retVal.set(i, source[i]); - } - return retVal; - } - public abstract FunctionSet function(); + public final I make(final long count) { + return this.makeStructuredZero(count); + } + public final I makeFilled(final long count, final NullaryFunction supplier) { final I retVal = this.makeToBeFilled(count); if (retVal.isPrimitive()) { @@ -87,10 +91,6 @@ public final I makeFilled(final long count, final NullaryFunction supplier) { return retVal; } - public final I make(final long count) { - return this.makeStructuredZero(count); - } - public abstract Scalar.Factory scalar(); abstract long getCapacityLimit(); diff --git a/src/org/ojalgo/array/BigArray.java b/src/org/ojalgo/array/BigArray.java index 551f342f9..8f292252d 100644 --- a/src/org/ojalgo/array/BigArray.java +++ b/src/org/ojalgo/array/BigArray.java @@ -120,6 +120,11 @@ public void sortDescending() { Arrays.parallelSort(data, Comparator.reverseOrder()); } + @Override + protected final void add(final int index, final Comparable addend) { + this.fillOne(index, this.get(index).add(this.valueOf(addend))); + } + @Override protected final void add(final int index, final double addend) { this.fillOne(index, this.get(index).add(this.valueOf(addend))); @@ -131,8 +136,13 @@ protected final void add(final int index, final float addend) { } @Override - protected final void add(final int index, final Comparable addend) { - this.fillOne(index, this.get(index).add(this.valueOf(addend))); + protected final double doubleValue(final int index) { + return data[index].doubleValue(); + } + + @Override + protected final void fillOne(final int index, final Access1D values, final long valueIndex) { + data[index] = this.valueOf(values.get(valueIndex)); } @Override @@ -150,14 +160,4 @@ protected boolean isSmall(final int index, final double comparedTo) { return BigScalar.isSmall(comparedTo, data[index]); } - @Override - protected final double doubleValue(final int index) { - return data[index].doubleValue(); - } - - @Override - protected final void fillOne(final int index, final Access1D values, final long valueIndex) { - data[index] = this.valueOf(values.get(valueIndex)); - } - } diff --git a/src/org/ojalgo/array/BufferArray.java b/src/org/ojalgo/array/BufferArray.java index 97203313f..54e472243 100644 --- a/src/org/ojalgo/array/BufferArray.java +++ b/src/org/ojalgo/array/BufferArray.java @@ -388,6 +388,11 @@ public int size() { return myBuffer.capacity(); } + @Override + protected void add(final int index, final Comparable addend) { + this.set(index, this.doubleValue(index) + Scalar.doubleValue(addend)); + } + @Override protected void add(final int index, final double addend) { this.set(index, this.doubleValue(index) + addend); @@ -398,11 +403,6 @@ protected void add(final int index, final float addend) { this.set(index, this.floatValue(index) + addend); } - @Override - protected void add(final int index, final Comparable addend) { - this.set(index, this.doubleValue(index) + Scalar.doubleValue(addend)); - } - @Override protected void exchange(final int firstA, final int firstB, final int step, final int count) { diff --git a/src/org/ojalgo/array/NumberList.java b/src/org/ojalgo/array/NumberList.java index 8ffd0a4a4..2c52fce4c 100644 --- a/src/org/ojalgo/array/NumberList.java +++ b/src/org/ojalgo/array/NumberList.java @@ -126,7 +126,7 @@ public void add(final int index, final N element) { } @Override - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -135,7 +135,7 @@ public void add(final long index, final double addend) { } @Override - public void add(final long index, final float addend) { + public void add(final long index, final double addend) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -144,7 +144,7 @@ public void add(final long index, final float addend) { } @Override - public void add(final long index, final Comparable addend) { + public void add(final long index, final float addend) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -403,7 +403,7 @@ public N set(final int index, final N element) { } @Override - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -412,7 +412,7 @@ public void set(final long index, final double value) { } @Override - public void set(final long index, final float value) { + public void set(final long index, final double value) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { @@ -421,7 +421,7 @@ public void set(final long index, final float value) { } @Override - public void set(final long index, final Comparable value) { + public void set(final long index, final float value) { if (index >= myActualCount) { throw new ArrayIndexOutOfBoundsException(); } else { diff --git a/src/org/ojalgo/array/PlainArray.java b/src/org/ojalgo/array/PlainArray.java index b98849285..e3ec90e51 100644 --- a/src/org/ojalgo/array/PlainArray.java +++ b/src/org/ojalgo/array/PlainArray.java @@ -54,17 +54,17 @@ abstract class PlainArray> extends DenseArray impleme } @Override - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { this.add((int) index, addend); } @Override - public void add(final long index, final float addend) { + public void add(final long index, final double addend) { this.add((int) index, addend); } @Override - public void add(final long index, final Comparable addend) { + public void add(final long index, final float addend) { this.add((int) index, addend); } @@ -140,18 +140,18 @@ public final void modifyOne(final long index, final UnaryFunction modifier) { } @Override - public final void set(final long index, final double value) { - this.set((int) index, value); + public final void set(final long index, final Comparable number) { + this.set((int) index, number); } @Override - public final void set(final long index, final float value) { + public final void set(final long index, final double value) { this.set((int) index, value); } @Override - public final void set(final long index, final Comparable number) { - this.set((int) index, number); + public final void set(final long index, final float value) { + this.set((int) index, value); } @Override @@ -170,12 +170,12 @@ private final boolean isSmall(final int first, final int limit, final int step, return retVal; } + protected abstract void add(int index, Comparable addend); + protected abstract void add(int index, double addend); protected abstract void add(int index, float addend); - protected abstract void add(int index, Comparable addend); - protected abstract double doubleValue(final int index); protected abstract void exchange(int firstA, int firstB, int step, int count); @@ -266,12 +266,12 @@ protected final void modify(final long first, final long limit, final long step, protected abstract int searchAscending(final N number); + protected abstract void set(final int index, final Comparable number); + protected abstract void set(final int index, final double value); protected abstract void set(final int index, final float value); - protected abstract void set(final int index, final Comparable number); - protected abstract void sortAscending(); protected abstract void sortDescending(); diff --git a/src/org/ojalgo/array/Primitive32Array.java b/src/org/ojalgo/array/Primitive32Array.java index f36704665..7c7d307e3 100644 --- a/src/org/ojalgo/array/Primitive32Array.java +++ b/src/org/ojalgo/array/Primitive32Array.java @@ -172,6 +172,11 @@ public void sortDescending() { CorePrimitiveOperation.negate(data, 0, data.length, 1, data); } + @Override + protected void add(final int index, final Comparable addend) { + data[index] += Scalar.floatValue(addend); + } + @Override protected void add(final int index, final double addend) { data[index] += (float) addend; @@ -182,11 +187,6 @@ protected void add(final int index, final float addend) { data[index] += addend; } - @Override - protected void add(final int index, final Comparable addend) { - data[index] += Scalar.floatValue(addend); - } - protected final float[] copyOfData() { return COPY.copyOf(data); } @@ -302,6 +302,11 @@ protected final int searchAscending(final Double number) { return Arrays.binarySearch(data, number.floatValue()); } + @Override + protected final void set(final int index, final Comparable value) { + data[index] = Scalar.floatValue(value); + } + @Override protected final void set(final int index, final double value) { data[index] = (float) value; @@ -312,11 +317,6 @@ protected final void set(final int index, final float value) { data[index] = value; } - @Override - protected final void set(final int index, final Comparable value) { - data[index] = Scalar.floatValue(value); - } - @Override protected final void visit(final int first, final int limit, final int step, final VoidFunction visitor) { OperationVoid.invoke(data, first, limit, step, visitor); diff --git a/src/org/ojalgo/array/Primitive64Array.java b/src/org/ojalgo/array/Primitive64Array.java index 39c81a0e5..85569209c 100644 --- a/src/org/ojalgo/array/Primitive64Array.java +++ b/src/org/ojalgo/array/Primitive64Array.java @@ -185,18 +185,18 @@ public DoubleStream stream(final boolean parallel) { } @Override - protected void add(final int index, final double addend) { - data[index] += addend; + protected void add(final int index, final Comparable addend) { + data[index] += Scalar.doubleValue(addend); } @Override - protected void add(final int index, final float addend) { + protected void add(final int index, final double addend) { data[index] += addend; } @Override - protected void add(final int index, final Comparable addend) { - data[index] += Scalar.doubleValue(addend); + protected void add(final int index, final float addend) { + data[index] += addend; } protected final double[] copyOfData() { @@ -315,18 +315,18 @@ protected final int searchAscending(final Double number) { } @Override - protected final void set(final int index, final double value) { - data[index] = value; + protected final void set(final int index, final Comparable value) { + data[index] = Scalar.doubleValue(value); } @Override - protected final void set(final int index, final float value) { + protected final void set(final int index, final double value) { data[index] = value; } @Override - protected final void set(final int index, final Comparable value) { - data[index] = Scalar.doubleValue(value); + protected final void set(final int index, final float value) { + data[index] = value; } @Override diff --git a/src/org/ojalgo/array/ReferenceTypeArray.java b/src/org/ojalgo/array/ReferenceTypeArray.java index d02505be2..d8741727a 100644 --- a/src/org/ojalgo/array/ReferenceTypeArray.java +++ b/src/org/ojalgo/array/ReferenceTypeArray.java @@ -207,17 +207,17 @@ protected final int searchAscending(final N value) { } @Override - protected final void set(final int index, final double value) { + protected final void set(final int index, final Comparable value) { data[index] = this.valueOf(value); } @Override - protected final void set(final int index, final float value) { + protected final void set(final int index, final double value) { data[index] = this.valueOf(value); } @Override - protected final void set(final int index, final Comparable value) { + protected final void set(final int index, final float value) { data[index] = this.valueOf(value); } @@ -251,6 +251,10 @@ final void modify(final long extIndex, final int intIndex, final UnaryFunction number) { + return this.factory().scalar().cast(number); + } + final N valueOf(final double value) { return this.factory().scalar().cast(value); } @@ -259,8 +263,4 @@ final N valueOf(final float value) { return this.factory().scalar().cast(value); } - final N valueOf(final Comparable number) { - return this.factory().scalar().cast(number); - } - } diff --git a/src/org/ojalgo/array/ScalarArray.java b/src/org/ojalgo/array/ScalarArray.java index 1f0e86b57..4bc3f7655 100644 --- a/src/org/ojalgo/array/ScalarArray.java +++ b/src/org/ojalgo/array/ScalarArray.java @@ -60,6 +60,11 @@ public final void sortDescending() { Arrays.parallelSort(data, Comparator.reverseOrder()); } + @Override + protected final void add(final int index, final Comparable addend) { + this.fillOne(index, this.get(index).add(this.valueOf(addend)).get()); + } + @Override protected final void add(final int index, final double addend) { this.fillOne(index, this.get(index).add(this.valueOf(addend)).get()); @@ -71,8 +76,13 @@ protected final void add(final int index, final float addend) { } @Override - protected final void add(final int index, final Comparable addend) { - this.fillOne(index, this.get(index).add(this.valueOf(addend)).get()); + protected final double doubleValue(final int index) { + return data[index].doubleValue(); + } + + @Override + protected final void fillOne(final int index, final Access1D values, final long valueIndex) { + data[index] = this.valueOf(values.get(valueIndex)); } @Override @@ -90,14 +100,4 @@ protected final boolean isSmall(final int index, final double comparedTo) { return data[index].isSmall(comparedTo); } - @Override - protected final double doubleValue(final int index) { - return data[index].doubleValue(); - } - - @Override - protected final void fillOne(final int index, final Access1D values, final long valueIndex) { - data[index] = this.valueOf(values.get(valueIndex)); - } - } diff --git a/src/org/ojalgo/array/SegmentedArray.java b/src/org/ojalgo/array/SegmentedArray.java index 3104353a0..0271b1a39 100644 --- a/src/org/ojalgo/array/SegmentedArray.java +++ b/src/org/ojalgo/array/SegmentedArray.java @@ -107,17 +107,17 @@ final class SegmentedArray> extends BasicArray { } @Override - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { mySegments[(int) (index >> myIndexBits)].add(index & myIndexMask, addend); } @Override - public void add(final long index, final float addend) { + public void add(final long index, final double addend) { mySegments[(int) (index >> myIndexBits)].add(index & myIndexMask, addend); } @Override - public void add(final long index, final Comparable addend) { + public void add(final long index, final float addend) { mySegments[(int) (index >> myIndexBits)].add(index & myIndexMask, addend); } @@ -260,17 +260,17 @@ public void reset() { } @Override - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { mySegments[(int) (index >> myIndexBits)].set(index & myIndexMask, value); } @Override - public void set(final long index, final float value) { + public void set(final long index, final double value) { mySegments[(int) (index >> myIndexBits)].set(index & myIndexMask, value); } @Override - public void set(final long index, final Comparable value) { + public void set(final long index, final float value) { mySegments[(int) (index >> myIndexBits)].set(index & myIndexMask, value); } diff --git a/src/org/ojalgo/array/SparseArray.java b/src/org/ojalgo/array/SparseArray.java index 4d331bf39..269e38042 100644 --- a/src/org/ojalgo/array/SparseArray.java +++ b/src/org/ojalgo/array/SparseArray.java @@ -264,7 +264,7 @@ public static > SparseFactory factory(final DenseArra } @Override - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { myValues.add(tmpIndex, addend); @@ -274,7 +274,7 @@ public void add(final long index, final double addend) { } @Override - public void add(final long index, final float addend) { + public void add(final long index, final double addend) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { myValues.add(tmpIndex, addend); @@ -284,7 +284,7 @@ public void add(final long index, final float addend) { } @Override - public void add(final long index, final Comparable addend) { + public void add(final long index, final float addend) { final int tmpIndex = this.index(index); if (tmpIndex >= 0) { myValues.add(tmpIndex, addend); @@ -491,7 +491,7 @@ public void reset() { } @Override - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { final int internalIndex = this.index(index); @@ -499,7 +499,7 @@ public void set(final long index, final double value) { } @Override - public void set(final long index, final float value) { + public void set(final long index, final double value) { final int internalIndex = this.index(index); @@ -507,7 +507,7 @@ public void set(final long index, final float value) { } @Override - public void set(final long index, final Comparable value) { + public void set(final long index, final float value) { final int internalIndex = this.index(index); @@ -591,14 +591,14 @@ public void visitReferenceTypeNonzerosInRange(final long first, final long limit /** * Will never remove anything - just insert or update */ - private void update(final long externalIndex, final int internalIndex, final double value, final boolean shouldStoreZero) { + private void update(final long externalIndex, final int internalIndex, final Comparable value, final boolean shouldStoreZero) { if (internalIndex >= 0) { // Existing value, just update myValues.set(internalIndex, value); - } else if (shouldStoreZero || (NumberContext.compare(value, PrimitiveMath.ZERO) != 0)) { + } else if (shouldStoreZero || !value.equals(myZeroNumber)) { // Not existing value, insert new final int tmpInsInd = -(internalIndex + 1); @@ -607,7 +607,7 @@ private void update(final long externalIndex, final int internalIndex, final dou for (int i = myActualLength; i > tmpInsInd; i--) { myIndices[i] = myIndices[i - 1]; - myValues.set(i, myValues.doubleValue(i - 1)); + myValues.set(i, myValues.get(i - 1)); } myIndices[tmpInsInd] = externalIndex; myValues.set(tmpInsInd, value); @@ -623,13 +623,13 @@ private void update(final long externalIndex, final int internalIndex, final dou for (int i = 0; i < tmpInsInd; i++) { tmpIndices[i] = myIndices[i]; - tmpValues.set(i, myValues.doubleValue(i)); + tmpValues.set(i, myValues.get(i)); } tmpIndices[tmpInsInd] = externalIndex; tmpValues.set(tmpInsInd, value); for (int i = tmpInsInd; i < myIndices.length; i++) { tmpIndices[i + 1] = myIndices[i]; - tmpValues.set(i + 1, myValues.doubleValue(i)); + tmpValues.set(i + 1, myValues.get(i)); } for (int i = myIndices.length + 1; i < tmpIndices.length; i++) { tmpIndices[i] = Long.MAX_VALUE; @@ -645,14 +645,14 @@ private void update(final long externalIndex, final int internalIndex, final dou /** * Will never remove anything - just insert or update */ - private void update(final long externalIndex, final int internalIndex, final Comparable value, final boolean shouldStoreZero) { + private void update(final long externalIndex, final int internalIndex, final double value, final boolean shouldStoreZero) { if (internalIndex >= 0) { // Existing value, just update myValues.set(internalIndex, value); - } else if (shouldStoreZero || !value.equals(myZeroNumber)) { + } else if (shouldStoreZero || (NumberContext.compare(value, PrimitiveMath.ZERO) != 0)) { // Not existing value, insert new final int tmpInsInd = -(internalIndex + 1); @@ -661,7 +661,7 @@ private void update(final long externalIndex, final int internalIndex, final Com for (int i = myActualLength; i > tmpInsInd; i--) { myIndices[i] = myIndices[i - 1]; - myValues.set(i, myValues.get(i - 1)); + myValues.set(i, myValues.doubleValue(i - 1)); } myIndices[tmpInsInd] = externalIndex; myValues.set(tmpInsInd, value); @@ -677,13 +677,13 @@ private void update(final long externalIndex, final int internalIndex, final Com for (int i = 0; i < tmpInsInd; i++) { tmpIndices[i] = myIndices[i]; - tmpValues.set(i, myValues.get(i)); + tmpValues.set(i, myValues.doubleValue(i)); } tmpIndices[tmpInsInd] = externalIndex; tmpValues.set(tmpInsInd, value); for (int i = tmpInsInd; i < myIndices.length; i++) { tmpIndices[i + 1] = myIndices[i]; - tmpValues.set(i + 1, myValues.get(i)); + tmpValues.set(i + 1, myValues.doubleValue(i)); } for (int i = myIndices.length + 1; i < tmpIndices.length; i++) { tmpIndices[i] = Long.MAX_VALUE; diff --git a/src/org/ojalgo/array/operation/FillAll.java b/src/org/ojalgo/array/operation/FillAll.java index d86710f28..065a0bb07 100644 --- a/src/org/ojalgo/array/operation/FillAll.java +++ b/src/org/ojalgo/array/operation/FillAll.java @@ -67,7 +67,7 @@ public static void fill(final float[] data, final int first, final int limit, fi } } - public static > void fill(final N[] data, final Access1D values, Scalar.Factory scalar) { + public static > void fill(final N[] data, final Access1D values, final Scalar.Factory scalar) { final int limit = Math.min(data.length, values.size()); for (int i = 0; i < limit; i++) { data[i] = scalar.cast(values.get(i)); @@ -81,7 +81,7 @@ public static > void fill(final N[] data, final int firs } public static > void fill(final N[] data, final int first, final int limit, final int step, final NullaryFunction supplier, - Scalar.Factory scalar) { + final Scalar.Factory scalar) { for (int i = first; i < limit; i += step) { data[i] = scalar.cast(supplier.invoke()); } diff --git a/src/org/ojalgo/array/operation/MultiplyLeft.java b/src/org/ojalgo/array/operation/MultiplyLeft.java index a7d4d4647..6226f99d9 100644 --- a/src/org/ojalgo/array/operation/MultiplyLeft.java +++ b/src/org/ojalgo/array/operation/MultiplyLeft.java @@ -38,15 +38,15 @@ public interface Generic> { } - public interface Primitive64 { + public interface Primitive32 { - void invoke(double[] product, Access1D left, int complexity, double[] right); + void invoke(float[] product, Access1D left, int complexity, float[] right); } - public interface Primitive32 { + public interface Primitive64 { - void invoke(float[] product, Access1D left, int complexity, float[] right); + void invoke(double[] product, Access1D left, int complexity, double[] right); } diff --git a/src/org/ojalgo/array/operation/MultiplyNeither.java b/src/org/ojalgo/array/operation/MultiplyNeither.java index c8faa420b..6d6581ce5 100644 --- a/src/org/ojalgo/array/operation/MultiplyNeither.java +++ b/src/org/ojalgo/array/operation/MultiplyNeither.java @@ -35,15 +35,15 @@ public interface Generic> { } - public interface Primitive64 { + public interface Primitive32 { - void invoke(double[] product, double[] left, int complexity, double[] right); + void invoke(float[] product, float[] left, int complexity, float[] right); } - public interface Primitive32 { + public interface Primitive64 { - void invoke(float[] product, float[] left, int complexity, float[] right); + void invoke(double[] product, double[] left, int complexity, double[] right); } @@ -600,6 +600,10 @@ public void conquer(final int first, final int limit) { } } + public static MultiplyNeither.Primitive32 newPrimitive32(final long rows, final long columns) { + return PRIMITIVE32; + } + public static MultiplyNeither.Primitive64 newPrimitive64(final long rows, final long columns) { if (rows > THRESHOLD) { return PRIMITIVE_MT; @@ -628,10 +632,6 @@ public static MultiplyNeither.Primitive64 newPrimitive64(final long rows, final } } - public static MultiplyNeither.Primitive32 newPrimitive32(final long rows, final long columns) { - return PRIMITIVE32; - } - static void invoke(final double[] product, final int firstColumn, final int columnLimit, final double[] left, final int complexity, final double[] right) { final int structure = left.length / complexity; diff --git a/src/org/ojalgo/array/operation/MultiplyRight.java b/src/org/ojalgo/array/operation/MultiplyRight.java index 9e8bea7c3..15c8e26ff 100644 --- a/src/org/ojalgo/array/operation/MultiplyRight.java +++ b/src/org/ojalgo/array/operation/MultiplyRight.java @@ -38,15 +38,15 @@ public interface Generic> { } - public interface Primitive64 { + public interface Primitive32 { - void invoke(double[] product, double[] left, int complexity, Access1D right); + void invoke(float[] product, float[] left, int complexity, Access1D right); } - public interface Primitive32 { + public interface Primitive64 { - void invoke(float[] product, float[] left, int complexity, Access1D right); + void invoke(double[] product, double[] left, int complexity, Access1D right); } diff --git a/src/org/ojalgo/array/operation/SubstituteBackwards.java b/src/org/ojalgo/array/operation/SubstituteBackwards.java index 7ecaa63e5..4f5c42697 100644 --- a/src/org/ojalgo/array/operation/SubstituteBackwards.java +++ b/src/org/ojalgo/array/operation/SubstituteBackwards.java @@ -74,69 +74,69 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static void invoke(final float[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, - final boolean conjugated, final boolean hermitian) { + /** + * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) + */ + public static void invoke(final double[][] data, final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean hermitian) { + + int limit = data[0].length; int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); - float[] bodyRow = new float[diagDim]; - float tmpVal; - int colBaseIndex; + double[] bodyRow = new double[diagDim]; + double tmpVal; - int firstRow = hermitian ? first : 0; - for (int i = diagDim - 1; i >= firstRow; i--) { + for (int i = diagDim - 1; i >= 0; i--) { for (int j = i; j < diagDim; j++) { - bodyRow[j] = conjugated ? body.floatValue(j, i) : body.floatValue(i, j); + bodyRow[j] = conjugated ? body.doubleValue(j, i) : body.doubleValue(i, j); } int columnLimit = hermitian ? Math.min(i + 1, limit) : limit; - for (int s = first; s < columnLimit; s++) { - colBaseIndex = s * structure; + for (int s = 0; s < columnLimit; s++) { - tmpVal = 0F; + tmpVal = PrimitiveMath.ZERO; for (int j = i + 1; j < diagDim; j++) { - tmpVal += bodyRow[j] * data[j + colBaseIndex]; + tmpVal += bodyRow[j] * data[j][s]; } - tmpVal = data[i + colBaseIndex] - tmpVal; + tmpVal = data[i][s] - tmpVal; if (!unitDiagonal) { tmpVal /= bodyRow[i]; } - data[i + colBaseIndex] = tmpVal; + data[i][s] = tmpVal; } } } - /** - * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) - */ - public static void invoke(final double[][] data, final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean hermitian) { - - int limit = data[0].length; + public static void invoke(final float[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, + final boolean conjugated, final boolean hermitian) { int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); - double[] bodyRow = new double[diagDim]; - double tmpVal; + float[] bodyRow = new float[diagDim]; + float tmpVal; + int colBaseIndex; - for (int i = diagDim - 1; i >= 0; i--) { + int firstRow = hermitian ? first : 0; + for (int i = diagDim - 1; i >= firstRow; i--) { for (int j = i; j < diagDim; j++) { - bodyRow[j] = conjugated ? body.doubleValue(j, i) : body.doubleValue(i, j); + bodyRow[j] = conjugated ? body.floatValue(j, i) : body.floatValue(i, j); } int columnLimit = hermitian ? Math.min(i + 1, limit) : limit; - for (int s = 0; s < columnLimit; s++) { + for (int s = first; s < columnLimit; s++) { + colBaseIndex = s * structure; - tmpVal = PrimitiveMath.ZERO; + tmpVal = 0F; for (int j = i + 1; j < diagDim; j++) { - tmpVal += bodyRow[j] * data[j][s]; + tmpVal += bodyRow[j] * data[j + colBaseIndex]; } - tmpVal = data[i][s] - tmpVal; + tmpVal = data[i + colBaseIndex] - tmpVal; if (!unitDiagonal) { tmpVal /= bodyRow[i]; } - data[i][s] = tmpVal; + data[i + colBaseIndex] = tmpVal; } } } diff --git a/src/org/ojalgo/array/operation/SubstituteForwards.java b/src/org/ojalgo/array/operation/SubstituteForwards.java index 423041409..8fa258690 100644 --- a/src/org/ojalgo/array/operation/SubstituteForwards.java +++ b/src/org/ojalgo/array/operation/SubstituteForwards.java @@ -77,76 +77,76 @@ public static void invoke(final double[] data, final int structure, final int fi } } - public static void invoke(final float[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, - final boolean conjugated, final boolean identity) { + /** + * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) + */ + public static void invoke(final double[][] data, final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean identity) { + + int limit = data[0].length; int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); - float[] bodyRow = new float[diagDim]; - float tmpVal; - int colBaseIndex; + double[] bodyRow = new double[diagDim]; + double tmpVal; for (int i = 0; i < diagDim; i++) { for (int j = 0; j <= i; j++) { - bodyRow[j] = conjugated ? body.floatValue(j, i) : body.floatValue(i, j); + bodyRow[j] = conjugated ? body.doubleValue(j, i) : body.doubleValue(i, j); } - for (int s = first; s < limit; s++) { - colBaseIndex = s * structure; + for (int s = 0; s < limit; s++) { - tmpVal = 0F; + tmpVal = PrimitiveMath.ZERO; for (int j = identity ? s : 0; j < i; j++) { - tmpVal += bodyRow[j] * data[j + colBaseIndex]; + tmpVal += bodyRow[j] * data[j][s]; } if (identity) { - tmpVal = i == s ? 1F - tmpVal : -tmpVal; + tmpVal = i == s ? PrimitiveMath.ONE - tmpVal : -tmpVal; } else { - tmpVal = data[i + colBaseIndex] - tmpVal; + tmpVal = data[i][s] - tmpVal; } if (!unitDiagonal) { tmpVal /= bodyRow[i]; } - data[i + colBaseIndex] = tmpVal; + data[i][s] = tmpVal; } } } - /** - * @see #invoke(double[], int, int, int, Access2D, boolean, boolean, boolean) - */ - public static void invoke(final double[][] data, final Access2D body, final boolean unitDiagonal, final boolean conjugated, final boolean identity) { - - int limit = data[0].length; + public static void invoke(final float[] data, final int structure, final int first, final int limit, final Access2D body, final boolean unitDiagonal, + final boolean conjugated, final boolean identity) { int diagDim = MissingMath.toMinIntExact(body.countRows(), body.countColumns()); - double[] bodyRow = new double[diagDim]; - double tmpVal; + float[] bodyRow = new float[diagDim]; + float tmpVal; + int colBaseIndex; for (int i = 0; i < diagDim; i++) { for (int j = 0; j <= i; j++) { - bodyRow[j] = conjugated ? body.doubleValue(j, i) : body.doubleValue(i, j); + bodyRow[j] = conjugated ? body.floatValue(j, i) : body.floatValue(i, j); } - for (int s = 0; s < limit; s++) { + for (int s = first; s < limit; s++) { + colBaseIndex = s * structure; - tmpVal = PrimitiveMath.ZERO; + tmpVal = 0F; for (int j = identity ? s : 0; j < i; j++) { - tmpVal += bodyRow[j] * data[j][s]; + tmpVal += bodyRow[j] * data[j + colBaseIndex]; } if (identity) { - tmpVal = i == s ? PrimitiveMath.ONE - tmpVal : -tmpVal; + tmpVal = i == s ? 1F - tmpVal : -tmpVal; } else { - tmpVal = data[i][s] - tmpVal; + tmpVal = data[i + colBaseIndex] - tmpVal; } if (!unitDiagonal) { tmpVal /= bodyRow[i]; } - data[i][s] = tmpVal; + data[i + colBaseIndex] = tmpVal; } } } diff --git a/src/org/ojalgo/equation/Equation.java b/src/org/ojalgo/equation/Equation.java index 4cd032bb2..4055da664 100644 --- a/src/org/ojalgo/equation/Equation.java +++ b/src/org/ojalgo/equation/Equation.java @@ -57,6 +57,10 @@ public Equation(final int row, final long numberOfColumns, final double rhs, fin myRHS = rhs; } + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); + } + public void add(final long index, final double addend) { myElements.add(index, addend); if (index == this.index) { @@ -64,10 +68,6 @@ public void add(final long index, final double addend) { } } - public void add(final long index, final Comparable addend) { - this.add(index, Scalar.doubleValue(addend)); - } - /** * Will perform a (relaxed) GaussSeidel update. * @@ -143,6 +143,10 @@ public void initialise(final PhysicalStore x) { this.calculate(x, ZERO, ONE); } + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); + } + public void set(final long index, final double value) { myElements.set(index, value); if (index == this.index) { @@ -150,10 +154,6 @@ public void set(final long index, final double value) { } } - public void set(final long index, final Comparable value) { - this.set(index, Scalar.doubleValue(value)); - } - @Override public String toString() { return index + ": " + myElements.toString(); diff --git a/src/org/ojalgo/function/BinaryFunction.java b/src/org/ojalgo/function/BinaryFunction.java index 212084593..27260a7f1 100644 --- a/src/org/ojalgo/function/BinaryFunction.java +++ b/src/org/ojalgo/function/BinaryFunction.java @@ -61,14 +61,14 @@ public static final class FixedFirst> implements UnaryFu myValue = Scalar.doubleValue(arg1); } - public float floatValue() { - return (float) myValue; - } - public double doubleValue() { return myValue; } + public float floatValue() { + return (float) myValue; + } + public BinaryFunction getFunction() { return myFunction; } @@ -123,14 +123,14 @@ public static final class FixedSecond> implements UnaryF myValue = Scalar.doubleValue(arg2); } - public float floatValue() { - return (float) myValue; - } - public double doubleValue() { return myValue; } + public float floatValue() { + return (float) myValue; + } + public BinaryFunction getFunction() { return myFunction; } diff --git a/src/org/ojalgo/function/PredicateFunction.java b/src/org/ojalgo/function/PredicateFunction.java index bf196a6e5..a187196d1 100644 --- a/src/org/ojalgo/function/PredicateFunction.java +++ b/src/org/ojalgo/function/PredicateFunction.java @@ -26,10 +26,10 @@ public interface PredicateFunction> extends BasicFunction, Predicate, DoublePredicate { - boolean invoke(float arg); - boolean invoke(double arg); + boolean invoke(float arg); + boolean invoke(N arg); default PredicateFunction negate() { @@ -39,11 +39,11 @@ public boolean invoke(final double arg) { return !PredicateFunction.this.invoke(arg); } - public boolean invoke(final N arg) { + public boolean invoke(final float arg) { return !PredicateFunction.this.invoke(arg); } - public boolean invoke(float arg) { + public boolean invoke(final N arg) { return !PredicateFunction.this.invoke(arg); } diff --git a/src/org/ojalgo/function/UnaryFunction.java b/src/org/ojalgo/function/UnaryFunction.java index 3e1eac527..d3a290151 100644 --- a/src/org/ojalgo/function/UnaryFunction.java +++ b/src/org/ojalgo/function/UnaryFunction.java @@ -69,11 +69,11 @@ public double invoke(final double arg) { return UnaryFunction.this.invoke(before.invoke(arg)); } - public N invoke(final N arg) { + public float invoke(final float arg) { return UnaryFunction.this.invoke(before.invoke(arg)); } - public float invoke(float arg) { + public N invoke(final N arg) { return UnaryFunction.this.invoke(before.invoke(arg)); } diff --git a/src/org/ojalgo/function/special/BetaFunction.java b/src/org/ojalgo/function/special/BetaFunction.java index 52f80c23a..2e5be8379 100644 --- a/src/org/ojalgo/function/special/BetaFunction.java +++ b/src/org/ojalgo/function/special/BetaFunction.java @@ -29,12 +29,12 @@ public abstract class BetaFunction { public static abstract class Incomplete extends BetaFunction { - public static ComplexNumber beta(double limit, ComplexNumber a, ComplexNumber b) { + public static ComplexNumber beta(final double limit, final ComplexNumber a, final ComplexNumber b) { // TODO Implement it! return ComplexNumber.NaN; } - public static double beta(double limit, double a, double b) { + public static double beta(final double limit, final double a, final double b) { double tmp = ONE; double sum = tmp / a; @@ -50,7 +50,7 @@ public static double beta(double limit, double a, double b) { return Math.exp((a * Math.log(limit)) + Math.log(sum)); } - public static double beta(double limit, int a, int b) { + public static double beta(final double limit, final int a, final int b) { return Incomplete.beta(limit, (double) a, (double) b); } @@ -58,29 +58,29 @@ public static double beta(double limit, int a, int b) { public static abstract class Regularized extends BetaFunction { - public static ComplexNumber beta(double limit, ComplexNumber a, ComplexNumber b) { + public static ComplexNumber beta(final double limit, final ComplexNumber a, final ComplexNumber b) { return BetaFunction.Incomplete.beta(limit, a, b).divide(BetaFunction.beta(a, b)); } - public static double beta(double limit, double a, double b) { + public static double beta(final double limit, final double a, final double b) { return BetaFunction.Incomplete.beta(limit, a, b) / BetaFunction.beta(a, b); } - public static double beta(double limit, int a, int b) { + public static double beta(final double limit, final int a, final int b) { return BetaFunction.Incomplete.beta(limit, a, b) / BetaFunction.beta(a, b); } } - public static ComplexNumber beta(ComplexNumber a, ComplexNumber b) { + public static ComplexNumber beta(final ComplexNumber a, final ComplexNumber b) { return GammaFunction.gamma(a).multiply(GammaFunction.gamma(b)).divide(GammaFunction.gamma(a.add(b))); } - public static double beta(double a, double b) { + public static double beta(final double a, final double b) { return (GammaFunction.gamma(a) * GammaFunction.gamma(b)) / GammaFunction.gamma(a + b); } - public static double beta(int a, int b) { + public static double beta(final int a, final int b) { return (GammaFunction.gamma(a) * GammaFunction.gamma(b)) / GammaFunction.gamma(a + b); } diff --git a/src/org/ojalgo/function/special/CombinatorialFunctions.java b/src/org/ojalgo/function/special/CombinatorialFunctions.java index ece847f1c..42fbe0f9e 100644 --- a/src/org/ojalgo/function/special/CombinatorialFunctions.java +++ b/src/org/ojalgo/function/special/CombinatorialFunctions.java @@ -31,7 +31,7 @@ public abstract class CombinatorialFunctions { /** * 13! does not fit in an int, and 21! does not fit in a long - that's why this * method returns a double. - * + * * @deprecated v48 Use {@link MissingMath#factorial(int)} instead */ @Deprecated diff --git a/src/org/ojalgo/function/special/GammaFunction.java b/src/org/ojalgo/function/special/GammaFunction.java index 729d3dc9b..ebac07b00 100644 --- a/src/org/ojalgo/function/special/GammaFunction.java +++ b/src/org/ojalgo/function/special/GammaFunction.java @@ -30,17 +30,17 @@ public abstract class GammaFunction { public static abstract class Incomplete extends GammaFunction { - public static ComplexNumber lower(final ComplexNumber z, double limit) { + public static ComplexNumber lower(final ComplexNumber z, final double limit) { // TODO Implement it! return ComplexNumber.NaN; } - public static double lower(final double x, double limit) { + public static double lower(final double x, final double limit) { // TODO Implement it! return NaN; } - public static double lower(final int n, double limit) { + public static double lower(final int n, final double limit) { double incr = ONE, sum = ONE; for (int k = 1; k < n; k++) { @@ -51,17 +51,17 @@ public static double lower(final int n, double limit) { return (ONE - (sum * Math.exp(-limit))) * MissingMath.factorial(n - 1); } - public static ComplexNumber upper(final ComplexNumber z, double limit) { + public static ComplexNumber upper(final ComplexNumber z, final double limit) { // TODO Implement it! return ComplexNumber.NaN; } - public static double upper(final double x, double limit) { + public static double upper(final double x, final double limit) { // TODO Implement it! return NaN; } - public static double upper(final int n, double limit) { + public static double upper(final int n, final double limit) { double incr = ONE, sum = ONE; for (int k = 1; k < n; k++) { @@ -76,15 +76,15 @@ public static double upper(final int n, double limit) { public static abstract class Logarithmic extends GammaFunction { - public static ComplexNumber gamma(ComplexNumber z) { + public static ComplexNumber gamma(final ComplexNumber z) { return GammaFunction.LanczosApproximation.logarithmic(z); } - public static double gamma(double x) { + public static double gamma(final double x) { return GammaFunction.LanczosApproximation.logarithmic(x); } - public static double gamma(int n) { + public static double gamma(final int n) { return Math.log(GammaFunction.gamma(n)); } @@ -92,27 +92,27 @@ public static double gamma(int n) { public static abstract class Regularized extends GammaFunction { - public static ComplexNumber lower(final ComplexNumber z, double limit) { + public static ComplexNumber lower(final ComplexNumber z, final double limit) { return GammaFunction.Incomplete.lower(z, limit).divide(GammaFunction.gamma(z)); } - public static double lower(final double x, double limit) { + public static double lower(final double x, final double limit) { return GammaFunction.Incomplete.lower(x, limit) / GammaFunction.gamma(x); } - public static double lower(final int n, double limit) { + public static double lower(final int n, final double limit) { return GammaFunction.Incomplete.lower(n, limit) / GammaFunction.gamma(n); } - public static ComplexNumber upper(final ComplexNumber z, double limit) { + public static ComplexNumber upper(final ComplexNumber z, final double limit) { return GammaFunction.Incomplete.upper(z, limit).divide(GammaFunction.gamma(z)); } - public static double upper(final double x, double limit) { + public static double upper(final double x, final double limit) { return GammaFunction.Incomplete.upper(x, limit) / GammaFunction.gamma(x); } - public static double upper(final int n, double limit) { + public static double upper(final int n, final double limit) { return GammaFunction.Incomplete.upper(n, limit) / GammaFunction.gamma(n); } @@ -197,7 +197,7 @@ static double gamma(final double x) { } } - static ComplexNumber logarithmic(ComplexNumber z) { + static ComplexNumber logarithmic(final ComplexNumber z) { final ComplexNumber z1 = z.subtract(ONE); final ComplexNumber za = z1.add(A + HALF); @@ -210,7 +210,7 @@ static ComplexNumber logarithmic(ComplexNumber z) { return z1.add(HALF).multiply(ComplexMath.LOG.invoke(za)).add(LOG_SQRT_TWO_PI).subtract(za).add(ComplexMath.LOG.invoke(zs)); } - static double logarithmic(double x) { + static double logarithmic(final double x) { final double x1 = x - ONE; final double xa = x1 + (A + HALF); diff --git a/src/org/ojalgo/function/special/PowerOf2.java b/src/org/ojalgo/function/special/PowerOf2.java index 03e6cd728..445429774 100644 --- a/src/org/ojalgo/function/special/PowerOf2.java +++ b/src/org/ojalgo/function/special/PowerOf2.java @@ -32,13 +32,13 @@ public static final class IntPower extends PowerOf2 { public final int value; private final int myModuloMask; - IntPower(int exponent, int value) { + IntPower(final int exponent, final int value) { super(exponent); this.value = value; myModuloMask = value - 1; } - public int divide(int dividend) { + public int divide(final int dividend) { return dividend >> exponent; } @@ -46,7 +46,7 @@ public int getModuloMask() { return myModuloMask; } - public int modulo(int dividend) { + public int modulo(final int dividend) { return dividend & myModuloMask; } @@ -57,13 +57,13 @@ public static final class LongPower extends PowerOf2 { public final long value; private final long myModuloMask; - LongPower(int exponent, long value) { + LongPower(final int exponent, final long value) { super(exponent); this.value = value; myModuloMask = value - 1L; } - public long divide(long dividend) { + public long divide(final long dividend) { return dividend >> exponent; } @@ -71,7 +71,7 @@ public long getModuloMask() { return myModuloMask; } - public long modulo(long dividend) { + public long modulo(final long dividend) { return dividend & myModuloMask; } @@ -112,11 +112,11 @@ public static int find(final long value) { return Arrays.binarySearch(LONG_POWERS, value); } - public static IntPower getIntPower(int exponent) { + public static IntPower getIntPower(final int exponent) { return new IntPower(exponent, INT_POWERS[exponent]); } - public static LongPower getLongPower(int exponent) { + public static LongPower getLongPower(final int exponent) { return new LongPower(exponent, LONG_POWERS[exponent]); } @@ -160,17 +160,17 @@ public static int powerOf2Smaller(final long value) { return index >= 0 ? index : Math.max(-(index + 2), 0); } - public static int powerOfInt2(int exponent) { + public static int powerOfInt2(final int exponent) { return INT_POWERS[exponent]; } - public static long powerOfLong2(int exponent) { + public static long powerOfLong2(final int exponent) { return LONG_POWERS[exponent]; } public final int exponent; - PowerOf2(int exponent) { + PowerOf2(final int exponent) { super(); this.exponent = exponent; } diff --git a/src/org/ojalgo/matrix/MatrixFactory.java b/src/org/ojalgo/matrix/MatrixFactory.java index 83f0d7af0..f713a9b18 100644 --- a/src/org/ojalgo/matrix/MatrixFactory.java +++ b/src/org/ojalgo/matrix/MatrixFactory.java @@ -360,7 +360,7 @@ public void accept(final Access2D supplied) { } } - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { if (mySafe) { myDelegate.add(index, addend); } else { @@ -368,9 +368,9 @@ public void add(final long index, final double addend) { } } - public void add(final long row, final long col, final double value) { + public void add(final long index, final double addend) { if (mySafe) { - myDelegate.add(row, col, value); + myDelegate.add(index, addend); } else { throw new IllegalStateException(); } @@ -384,9 +384,9 @@ public void add(final long row, final long col, final Comparable value) { } } - public void add(final long index, final Comparable addend) { + public void add(final long row, final long col, final double value) { if (mySafe) { - myDelegate.add(index, addend); + myDelegate.add(row, col, value); } else { throw new IllegalStateException(); } @@ -420,17 +420,17 @@ public void exchangeRows(final long rowA, final long rowB) { } } - public void fillAll(final NullaryFunction supplier) { + public void fillAll(final N value) { if (mySafe) { - myDelegate.fillAll(supplier); + myDelegate.fillAll(myDelegate.physical().scalar().cast(value)); } else { throw new IllegalStateException(); } } - public void fillAll(final N value) { + public void fillAll(final NullaryFunction supplier) { if (mySafe) { - myDelegate.fillAll(myDelegate.physical().scalar().cast(value)); + myDelegate.fillAll(supplier); } else { throw new IllegalStateException(); } @@ -452,17 +452,17 @@ public void fillColumn(final long row, final long col, final Access1D values) } } - public void fillColumn(final long row, final long col, final NullaryFunction supplier) { + public void fillColumn(final long row, final long column, final N value) { if (mySafe) { - myDelegate.fillColumn(row, col, supplier); + myDelegate.fillColumn((int) row, (int) column, myDelegate.physical().scalar().cast(value)); } else { throw new IllegalStateException(); } } - public void fillColumn(final long row, final long column, final N value) { + public void fillColumn(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { - myDelegate.fillColumn((int) row, (int) column, myDelegate.physical().scalar().cast(value)); + myDelegate.fillColumn(row, col, supplier); } else { throw new IllegalStateException(); } @@ -500,17 +500,17 @@ public void fillDiagonal(final long row, final long col, final Access1D value } } - public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final long row, final long column, final N value) { if (mySafe) { - myDelegate.fillDiagonal(row, col, supplier); + myDelegate.fillDiagonal((int) row, (int) column, myDelegate.physical().scalar().cast(value)); } else { throw new IllegalStateException(); } } - public void fillDiagonal(final long row, final long column, final N value) { + public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { - myDelegate.fillDiagonal((int) row, (int) column, myDelegate.physical().scalar().cast(value)); + myDelegate.fillDiagonal(row, col, supplier); } else { throw new IllegalStateException(); } @@ -636,17 +636,17 @@ public void fillRow(final long row, final long col, final Access1D values) { } } - public void fillRow(final long row, final long col, final NullaryFunction supplier) { + public void fillRow(final long row, final long column, final N value) { if (mySafe) { - myDelegate.fillRow(row, col, supplier); + myDelegate.fillRow((int) row, (int) column, myDelegate.physical().scalar().cast(value)); } else { throw new IllegalStateException(); } } - public void fillRow(final long row, final long column, final N value) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { if (mySafe) { - myDelegate.fillRow((int) row, (int) column, myDelegate.physical().scalar().cast(value)); + myDelegate.fillRow(row, col, supplier); } else { throw new IllegalStateException(); } @@ -818,17 +818,17 @@ public void reset() { } } - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { if (mySafe) { - myDelegate.set(index, value); + myDelegate.set(index, myDelegate.physical().scalar().cast(value)); } else { throw new IllegalStateException(); } } - public void set(final long row, final long col, final double value) { + public void set(final long index, final double value) { if (mySafe) { - myDelegate.set(row, col, value); + myDelegate.set(index, value); } else { throw new IllegalStateException(); } @@ -842,9 +842,9 @@ public void set(final long row, final long col, final Comparable value) { } } - public void set(final long index, final Comparable value) { + public void set(final long row, final long col, final double value) { if (mySafe) { - myDelegate.set(index, myDelegate.physical().scalar().cast(value)); + myDelegate.set(row, col, value); } else { throw new IllegalStateException(); } @@ -889,16 +889,16 @@ public M columns(final Access1D... source) { return this.instantiate(myPhysicalFactory.columns(source)); } - public M columns(final double[]... source) { + public M columns(final Comparable[]... source) { return this.instantiate(myPhysicalFactory.columns(source)); } - @SafeVarargs - public final M columns(final List>... source) { + public M columns(final double[]... source) { return this.instantiate(myPhysicalFactory.columns(source)); } - public M columns(final Comparable[]... source) { + @SafeVarargs + public final M columns(final List>... source) { return this.instantiate(myPhysicalFactory.columns(source)); } @@ -927,6 +927,10 @@ public DR getBuilder(final int rows, final int columns) { return this.makeDense(rows, columns); } + public M make(final long rows, final long columns) { + return this.instantiate(myPhysicalFactory.builder().makeZero((int) rows, (int) columns).get()); + } + public DR makeDense(final int count) { return this.makeDense(count, 1); } @@ -978,11 +982,11 @@ public M makeWrapper(final Access2D elements) { return this.instantiate(myPhysicalFactory.builder().makeWrapper(elements).get()); } - public M make(final long rows, final long columns) { - return this.instantiate(myPhysicalFactory.builder().makeZero((int) rows, (int) columns).get()); + public M rows(final Access1D... source) { + return this.instantiate(myPhysicalFactory.rows(source)); } - public M rows(final Access1D... source) { + public M rows(final Comparable[]... source) { return this.instantiate(myPhysicalFactory.rows(source)); } @@ -995,10 +999,6 @@ public M rows(final List>... source) { return this.instantiate(myPhysicalFactory.rows(source)); } - public M rows(final Comparable[]... source) { - return this.instantiate(myPhysicalFactory.rows(source)); - } - @Override public Scalar.Factory scalar() { return myPhysicalFactory.scalar(); diff --git a/src/org/ojalgo/matrix/decomposition/GeneralEvD.java b/src/org/ojalgo/matrix/decomposition/GeneralEvD.java index 61f8cc2a3..7dafdfe13 100644 --- a/src/org/ojalgo/matrix/decomposition/GeneralEvD.java +++ b/src/org/ojalgo/matrix/decomposition/GeneralEvD.java @@ -60,6 +60,10 @@ protected GeneralEvD(final DecompositionStore.Factory matrix) { + return this.decompose(matrix); + } + public final N getDeterminant() { final AggregatorFunction tmpVisitor = ComplexAggregator.getSet().product(); @@ -69,10 +73,6 @@ public final N getDeterminant() { return this.scalar().cast(tmpVisitor.get()); } - public boolean checkAndDecompose(final MatrixStore matrix) { - return this.decompose(matrix); - } - public MatrixStore getInverse() { ProgrammingError.throwForUnsupportedOptionalOperation(); return null; diff --git a/src/org/ojalgo/matrix/decomposition/HermitianEvD.java b/src/org/ojalgo/matrix/decomposition/HermitianEvD.java index 6b5921826..0dd74540c 100644 --- a/src/org/ojalgo/matrix/decomposition/HermitianEvD.java +++ b/src/org/ojalgo/matrix/decomposition/HermitianEvD.java @@ -69,6 +69,14 @@ static final class Complex extends HermitianEvD { } + static final class Primitive extends HermitianEvD { + + Primitive() { + super(Primitive64Store.FACTORY, new SimultaneousTridiagonal()); + } + + } + static final class Quat extends HermitianEvD { Quat() { @@ -85,14 +93,6 @@ static final class Rational extends HermitianEvD { } - static final class Primitive extends HermitianEvD { - - Primitive() { - super(Primitive64Store.FACTORY, new SimultaneousTridiagonal()); - } - - } - static void tql2(final double[] d, final double[] e, final RotateRight mtrxV) { final int size = d.length; diff --git a/src/org/ojalgo/matrix/geometry/GeometryVector.java b/src/org/ojalgo/matrix/geometry/GeometryVector.java index 573234295..dfd0b5ede 100644 --- a/src/org/ojalgo/matrix/geometry/GeometryVector.java +++ b/src/org/ojalgo/matrix/geometry/GeometryVector.java @@ -37,20 +37,20 @@ abstract class GeometryVector extends TransformableRegion.ReceiverRegion public abstract void add(int row, double addend); - public final void add(final long index, final double addend) { - this.add(Structure1D.index(index), addend); + public final void add(final long index, final Comparable addend) { + this.add(Structure1D.index(index), Scalar.doubleValue(addend)); } - public final void add(final long row, final long col, final double addend) { - this.add(Structure2D.index(this.structure(), row, col), addend); + public final void add(final long index, final double addend) { + this.add(Structure1D.index(index), addend); } public final void add(final long row, final long col, final Comparable addend) { this.add(Structure2D.index(this.structure(), row, col), Scalar.doubleValue(addend)); } - public final void add(final long index, final Comparable addend) { - this.add(Structure1D.index(index), Scalar.doubleValue(addend)); + public final void add(final long row, final long col, final double addend) { + this.add(Structure2D.index(this.structure(), row, col), addend); } public final long count() { @@ -119,20 +119,20 @@ public final void modifyOne(final long index, final UnaryFunction modifi public abstract void set(int row, double value); - public final void set(final long index, final double addend) { - this.set(Structure1D.index(index), addend); + public final void set(final long index, final Comparable value) { + this.set(Structure1D.index(index), Scalar.doubleValue(value)); } - public final void set(final long row, final long col, final double value) { - this.set(Structure2D.index(this.structure(), row, col), value); + public final void set(final long index, final double addend) { + this.set(Structure1D.index(index), addend); } public final void set(final long row, final long col, final Comparable value) { this.set(Structure2D.index(this.structure(), row, col), Scalar.doubleValue(value)); } - public final void set(final long index, final Comparable value) { - this.set(Structure1D.index(index), Scalar.doubleValue(value)); + public final void set(final long row, final long col, final double value) { + this.set(Structure2D.index(this.structure(), row, col), value); } public final int size() { diff --git a/src/org/ojalgo/matrix/store/ColumnsSupplier.java b/src/org/ojalgo/matrix/store/ColumnsSupplier.java index cae7f893e..3b30761d6 100644 --- a/src/org/ojalgo/matrix/store/ColumnsSupplier.java +++ b/src/org/ojalgo/matrix/store/ColumnsSupplier.java @@ -107,11 +107,11 @@ public void supplyTo(final TransformableRegion receiver) { myColumns.get(j).supplyNonZerosTo(new Mutate1D() { - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { receiver.add(index, col, addend); } - public void add(final long index, final Comparable addend) { + public void add(final long index, final double addend) { receiver.add(index, col, addend); } @@ -119,11 +119,11 @@ public long count() { return receiver.countRows(); } - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { receiver.set(index, col, value); } - public void set(final long index, final Comparable value) { + public void set(final long index, final double value) { receiver.set(index, col, value); } diff --git a/src/org/ojalgo/matrix/store/GenericStore.java b/src/org/ojalgo/matrix/store/GenericStore.java index d51aa7097..ddc74aebf 100644 --- a/src/org/ojalgo/matrix/store/GenericStore.java +++ b/src/org/ojalgo/matrix/store/GenericStore.java @@ -128,14 +128,14 @@ public GenericStore columns(final Access1D... source) { return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericStore columns(final double[]... source) { + public GenericStore columns(final Comparable[]... source) { final int tmpRowDim = source[0].length; final int tmpColDim = source.length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - double[] tmpColumn; + Comparable[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { @@ -146,36 +146,36 @@ public GenericStore columns(final double[]... source) { return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericStore columns(final List>... source) { + public GenericStore columns(final double[]... source) { - final int tmpRowDim = source[0].size(); + final int tmpRowDim = source[0].length; final int tmpColDim = source.length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - List> tmpColumn; + double[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpColumn.get(i)); + tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpColumn[i]); } } return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericStore columns(final Comparable[]... source) { + public GenericStore columns(final List>... source) { - final int tmpRowDim = source[0].length; + final int tmpRowDim = source[0].size(); final int tmpColDim = source.length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - Comparable[] tmpColumn; + List> tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpColumn[i]); + tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpColumn.get(i)); } } @@ -242,6 +242,10 @@ public FunctionSet function() { return myDenseArrayFactory.function(); } + public GenericStore make(final long rows, final long columns) { + return new GenericStore<>(this, (int) rows, (int) columns); + } + public GenericStore makeEye(final long rows, final long columns) { final GenericStore retVal = this.makeZero(rows, columns); @@ -279,10 +283,6 @@ public Rotation.Generic makeRotation(final int low, final int high, final N c return new Rotation.Generic<>(low, high, cos, sin); } - public GenericStore make(final long rows, final long columns) { - return new GenericStore<>(this, (int) rows, (int) columns); - } - public GenericStore rows(final Access1D... source) { final int tmpRowDim = source.length; @@ -301,14 +301,14 @@ public GenericStore rows(final Access1D... source) { return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericStore rows(final double[]... source) { + public GenericStore rows(final Comparable[]... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - double[] tmpRow; + Comparable[] tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { @@ -319,36 +319,36 @@ public GenericStore rows(final double[]... source) { return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericStore rows(final List>... source) { + public GenericStore rows(final double[]... source) { final int tmpRowDim = source.length; - final int tmpColDim = source[0].size(); + final int tmpColDim = source[0].length; final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - List> tmpRow; + double[] tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { - tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpRow.get(j)); + tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpRow[j]); } } return new GenericStore<>(this, tmpRowDim, tmpColDim, tmpData); } - public GenericStore rows(final Comparable[]... source) { + public GenericStore rows(final List>... source) { final int tmpRowDim = source.length; - final int tmpColDim = source[0].length; + final int tmpColDim = source[0].size(); final N[] tmpData = myDenseArrayFactory.scalar().newArrayInstance(tmpRowDim * tmpColDim); - Comparable[] tmpRow; + List> tmpRow; for (int i = 0; i < tmpRowDim; i++) { tmpRow = source[i]; for (int j = 0; j < tmpColDim; j++) { - tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpRow[j]); + tmpData[i + (tmpRowDim * j)] = myDenseArrayFactory.scalar().cast(tmpRow.get(j)); } } @@ -463,11 +463,11 @@ public void accept(final Access2D supplied) { } } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myUtility.add(row, col, addend); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myUtility.add(row, col, addend); } @@ -951,11 +951,11 @@ public void rotateRight(final int low, final int high, final double cos, final d RotateRight.invoke(data, myRowDim, low, high, myFactory.scalar().cast(cos), myFactory.scalar().cast(sin)); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myUtility.set(row, col, value); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myUtility.set(row, col, value); } diff --git a/src/org/ojalgo/matrix/store/PhysicalStore.java b/src/org/ojalgo/matrix/store/PhysicalStore.java index 889a33a51..1e484ea3c 100644 --- a/src/org/ojalgo/matrix/store/PhysicalStore.java +++ b/src/org/ojalgo/matrix/store/PhysicalStore.java @@ -143,6 +143,14 @@ default void modifyAny(final Transformation2D modifier) { */ void substituteForwards(Access2D body, boolean unitDiagonal, boolean conjugated, boolean identity); + default void supplyTo(final TransformableRegion receiver) { + if (this != receiver) { + receiver.fillMatching(this); + } else { + BasicLogger.error("Why do you this!"); + } + } + void transformLeft(Householder transformation, int firstColumn); /** @@ -181,12 +189,4 @@ default void modifyAny(final Transformation2D modifier) { */ void transformRight(Rotation transformation); - default void supplyTo(TransformableRegion receiver) { - if (this != receiver) { - receiver.fillMatching(this); - } else { - BasicLogger.error("Why do you this!"); - } - } - } diff --git a/src/org/ojalgo/matrix/store/Primitive32Store.java b/src/org/ojalgo/matrix/store/Primitive32Store.java index cca833bbc..0362af7a7 100644 --- a/src/org/ojalgo/matrix/store/Primitive32Store.java +++ b/src/org/ojalgo/matrix/store/Primitive32Store.java @@ -64,7 +64,7 @@ public MatrixStore.Factory builder() { return MatrixStore.PRIMITIVE32; } - public Primitive32Store columns(Access1D... source) { + public Primitive32Store columns(final Access1D... source) { final int tmpRowDim = (int) source[0].count(); final int tmpColDim = source.length; @@ -82,7 +82,7 @@ public Primitive32Store columns(Access1D... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store columns(Comparable[]... source) { + public Primitive32Store columns(final Comparable[]... source) { final int tmpRowDim = source[0].length; final int tmpColDim = source.length; @@ -100,7 +100,7 @@ public Primitive32Store columns(Comparable[]... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store columns(double[]... source) { + public Primitive32Store columns(final double[]... source) { final int tmpRowDim = source[0].length; final int tmpColDim = source.length; @@ -118,7 +118,7 @@ public Primitive32Store columns(double[]... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store columns(List>... source) { + public Primitive32Store columns(final List>... source) { final int tmpRowDim = source[0].size(); final int tmpColDim = source.length; @@ -136,7 +136,7 @@ public Primitive32Store columns(List>... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store copy(Access2D source) { + public Primitive32Store copy(final Access2D source) { final int tmpRowDim = (int) source.countRows(); final int tmpColDim = (int) source.countColumns(); @@ -164,11 +164,11 @@ public void conquer(final int aFirst, final int aLimit) { return retVal; } - public Primitive32Store make(long rows, long columns) { + public Primitive32Store make(final long rows, final long columns) { return new Primitive32Store((int) rows, (int) columns); } - public Primitive32Store makeEye(long rows, long columns) { + public Primitive32Store makeEye(final long rows, final long columns) { final Primitive32Store retVal = this.make(rows, columns); @@ -182,7 +182,7 @@ public Householder makeHouseholder(final int length) { return new Householder.Primitive32(length); } - public Primitive32Store rows(Access1D... source) { + public Primitive32Store rows(final Access1D... source) { final int tmpRowDim = source.length; final int tmpColDim = (int) source[0].count(); @@ -200,7 +200,7 @@ public Primitive32Store rows(Access1D... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store rows(Comparable[]... source) { + public Primitive32Store rows(final Comparable[]... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].length; @@ -218,7 +218,7 @@ public Primitive32Store rows(Comparable[]... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store rows(double[]... source) { + public Primitive32Store rows(final double[]... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].length; @@ -236,7 +236,7 @@ public Primitive32Store rows(double[]... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store rows(List>... source) { + public Primitive32Store rows(final List>... source) { final int tmpRowDim = source.length; final int tmpColDim = source[0].size(); @@ -254,7 +254,7 @@ public Primitive32Store rows(List>... source) { return new Primitive32Store(tmpRowDim, tmpColDim, tmpData); } - public Primitive32Store transpose(Access2D source) { + public Primitive32Store transpose(final Access2D source) { final Primitive32Store retVal = new Primitive32Store((int) source.countColumns(), (int) source.countRows()); @@ -352,43 +352,43 @@ static Rotation.Primitive cast(final Rotation transformation) { multiplyNeither = MultiplyNeither.newPrimitive32(myRowDim, myColDim); } - public void accept(Access2D supplied) { + public void accept(final Access2D supplied) { myUtility.accept(supplied); } - public void add(long row, long col, Comparable addend) { + public void add(final long row, final long col, final Comparable addend) { myUtility.add(row, col, addend); } - public void add(long row, long col, double addend) { + public void add(final long row, final long col, final double addend) { myUtility.add(row, col, addend); } - public Double aggregateColumn(long col, Aggregator aggregator) { + public Double aggregateColumn(final long col, final Aggregator aggregator) { return myUtility.aggregateColumn(col, aggregator); } - public Double aggregateColumn(long row, long col, Aggregator aggregator) { + public Double aggregateColumn(final long row, final long col, final Aggregator aggregator) { return myUtility.aggregateColumn(row, col, aggregator); } - public Double aggregateDiagonal(Aggregator aggregator) { + public Double aggregateDiagonal(final Aggregator aggregator) { return myUtility.aggregateDiagonal(aggregator); } - public Double aggregateDiagonal(long row, long col, Aggregator aggregator) { + public Double aggregateDiagonal(final long row, final long col, final Aggregator aggregator) { return myUtility.aggregateDiagonal(row, col, aggregator); } - public Double aggregateRange(long first, long limit, Aggregator aggregator) { + public Double aggregateRange(final long first, final long limit, final Aggregator aggregator) { return myUtility.aggregateRange(first, limit, aggregator); } - public Double aggregateRow(long row, Aggregator aggregator) { + public Double aggregateRow(final long row, final Aggregator aggregator) { return myUtility.aggregateRow(row, aggregator); } - public Double aggregateRow(long row, long col, Aggregator aggregator) { + public Double aggregateRow(final long row, final long col, final Aggregator aggregator) { return myUtility.aggregateRow(row, col, aggregator); } @@ -400,7 +400,7 @@ public Array1D asList() { return myUtility.asArray1D(); } - public byte byteValue(long row, long col) { + public byte byteValue(final long row, final long col) { return myUtility.byteValue(row, col); } @@ -421,11 +421,11 @@ public long countRows() { } @Override - public double dot(Access1D vector) { + public double dot(final Access1D vector) { return myUtility.dot(vector); } - public double doubleValue(long row, long col) { + public double doubleValue(final long row, final long col) { return myUtility.doubleValue(row, col); } @@ -434,19 +434,19 @@ public double doubleValue(long row, long col) { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { return myUtility.equals(obj); } - public void exchangeColumns(long colA, long colB) { + public void exchangeColumns(final long colA, final long colB) { myUtility.exchangeColumns(colA, colB); } - public void exchangeRows(long rowA, long rowB) { + public void exchangeRows(final long rowA, final long rowB) { myUtility.exchangeRows(rowA, rowB); } - public void fillByMultiplying(Access1D left, Access1D right) { + public void fillByMultiplying(final Access1D left, final Access1D right) { final int complexity = Math.toIntExact(left.count() / this.countRows()); if (complexity != Math.toIntExact(right.count() / this.countColumns())) { @@ -468,11 +468,11 @@ public void fillByMultiplying(Access1D left, Access1D right) { } } - public void fillColumn(long col, Access1D values) { + public void fillColumn(final long col, final Access1D values) { myUtility.fillColumn(col, values); } - public void fillColumn(long col, Double value) { + public void fillColumn(final long col, final Double value) { myUtility.fillColumn(col, value); } @@ -488,19 +488,19 @@ public void fillColumn(final long row, final long col, final NullaryFunction myUtility.fillColumn(row, col, supplier); } - public void fillColumn(long col, NullaryFunction supplier) { + public void fillColumn(final long col, final NullaryFunction supplier) { myUtility.fillColumn(col, supplier); } - public void fillDiagonal(Access1D values) { + public void fillDiagonal(final Access1D values) { myUtility.fillDiagonal(values); } - public void fillDiagonal(Double value) { + public void fillDiagonal(final Double value) { myUtility.fillDiagonal(value); } - public void fillDiagonal(long row, long col, Access1D values) { + public void fillDiagonal(final long row, final long col, final Access1D values) { myUtility.fillDiagonal(row, col, values); } @@ -512,61 +512,61 @@ public void fillDiagonal(final long row, final long col, final NullaryFunction supplier) { + public void fillDiagonal(final NullaryFunction supplier) { myUtility.fillDiagonal(supplier); } @Override - public void fillMatching(Access1D left, BinaryFunction function, Access1D right) { + public void fillMatching(final Access1D left, final BinaryFunction function, final Access1D right) { myUtility.fillMatching(left, function, right); } @Override - public void fillMatching(UnaryFunction function, Access1D arguments) { + public void fillMatching(final UnaryFunction function, final Access1D arguments) { myUtility.fillMatching(function, arguments); } - public void fillOne(long row, long col, Access1D values, long valueIndex) { + public void fillOne(final long row, final long col, final Access1D values, final long valueIndex) { myUtility.fillOne(row, col, values, valueIndex); } - public void fillOne(long row, long col, Double value) { + public void fillOne(final long row, final long col, final Double value) { myUtility.fillOne(row, col, value); } - public void fillOne(long row, long col, NullaryFunction supplier) { + public void fillOne(final long row, final long col, final NullaryFunction supplier) { myUtility.fillOne(row, col, supplier); } - public void fillRow(long row, Access1D values) { + public void fillRow(final long row, final Access1D values) { myUtility.fillRow(row, values); } - public void fillRow(long row, Double value) { + public void fillRow(final long row, final Double value) { myUtility.fillRow(row, value); } - public void fillRow(long row, long col, Access1D values) { + public void fillRow(final long row, final long col, final Access1D values) { myUtility.fillRow(row, col, values); } - public void fillRow(long row, long col, Double value) { + public void fillRow(final long row, final long col, final Double value) { myUtility.fillRow(row, col, value); } - public void fillRow(long row, long col, NullaryFunction supplier) { + public void fillRow(final long row, final long col, final NullaryFunction supplier) { myUtility.fillRow(row, col, supplier); } - public void fillRow(long row, NullaryFunction supplier) { + public void fillRow(final long row, final NullaryFunction supplier) { myUtility.fillRow(row, supplier); } - public float floatValue(long row, long col) { + public float floatValue(final long row, final long col) { return myUtility.floatValue(row, col); } - public Double get(long row, long col) { + public Double get(final long row, final long col) { return myUtility.get(row, col); } @@ -575,19 +575,19 @@ public int hashCode() { return myUtility.hashCode(); } - public long indexOfLargestInColumn(long col) { + public long indexOfLargestInColumn(final long col) { return myUtility.indexOfLargestInColumn(col); } - public long indexOfLargestInColumn(long row, long col) { + public long indexOfLargestInColumn(final long row, final long col) { return myUtility.indexOfLargestInColumn(row, col); } - public long indexOfLargestInRow(long row) { + public long indexOfLargestInRow(final long row) { return myUtility.indexOfLargestInRow(row); } - public long indexOfLargestInRow(long row, long col) { + public long indexOfLargestInRow(final long row, final long col) { return myUtility.indexOfLargestInRow(row, col); } @@ -595,31 +595,31 @@ public long indexOfLargestOnDiagonal() { return myUtility.indexOfLargestOnDiagonal(); } - public long indexOfLargestOnDiagonal(long first) { + public long indexOfLargestOnDiagonal(final long first) { return myUtility.indexOfLargestOnDiagonal(first); } - public int intValue(long row, long col) { + public int intValue(final long row, final long col) { return myUtility.intValue(row, col); } - public boolean isAbsolute(long row, long col) { + public boolean isAbsolute(final long row, final long col) { return myUtility.isAbsolute(row, col); } - public boolean isAcceptable(Structure2D supplier) { + public boolean isAcceptable(final Structure2D supplier) { return myUtility.isAcceptable(supplier); } - public boolean isAllSmall(double comparedTo) { + public boolean isAllSmall(final double comparedTo) { return myUtility.isAllSmall(comparedTo); } - public boolean isColumnSmall(long col, double comparedTo) { + public boolean isColumnSmall(final long col, final double comparedTo) { return myUtility.isColumnSmall(col, comparedTo); } - public boolean isColumnSmall(long row, long col, double comparedTo) { + public boolean isColumnSmall(final long row, final long col, final double comparedTo) { return myUtility.isColumnSmall(row, col, comparedTo); } @@ -631,11 +631,11 @@ public boolean isFat() { return myUtility.isFat(); } - public boolean isRowSmall(long row, double comparedTo) { + public boolean isRowSmall(final long row, final double comparedTo) { return myUtility.isRowSmall(row, comparedTo); } - public boolean isRowSmall(long row, long col, double comparedTo) { + public boolean isRowSmall(final long row, final long col, final double comparedTo) { return myUtility.isRowSmall(row, col, comparedTo); } @@ -643,7 +643,7 @@ public boolean isScalar() { return myUtility.isScalar(); } - public boolean isSmall(long row, long col, double comparedTo) { + public boolean isSmall(final long row, final long col, final double comparedTo) { return myUtility.isSmall(row, col, comparedTo); } @@ -659,70 +659,70 @@ public boolean isVector() { return myUtility.isVector(); } - public long longValue(long row, long col) { + public long longValue(final long row, final long col) { return myUtility.longValue(row, col); } @Override - public void modifyAll(UnaryFunction modifier) { + public void modifyAll(final UnaryFunction modifier) { myUtility.modifyAll(modifier); } - public void modifyAny(Transformation2D modifier) { + public void modifyAny(final Transformation2D modifier) { myUtility.modifyAny(modifier); } - public void modifyColumn(long row, long col, UnaryFunction modifier) { + public void modifyColumn(final long row, final long col, final UnaryFunction modifier) { myUtility.modifyColumn(row, col, modifier); } - public void modifyColumn(long col, UnaryFunction modifier) { + public void modifyColumn(final long col, final UnaryFunction modifier) { myUtility.modifyColumn(col, modifier); } - public void modifyDiagonal(long row, long col, UnaryFunction modifier) { + public void modifyDiagonal(final long row, final long col, final UnaryFunction modifier) { myUtility.modifyDiagonal(row, col, modifier); } - public void modifyDiagonal(UnaryFunction modifier) { + public void modifyDiagonal(final UnaryFunction modifier) { myUtility.modifyDiagonal(modifier); } @Override - public void modifyMatching(Access1D left, BinaryFunction function) { + public void modifyMatching(final Access1D left, final BinaryFunction function) { myUtility.modifyMatching(left, function); } @Override - public void modifyMatching(BinaryFunction function, Access1D right) { + public void modifyMatching(final BinaryFunction function, final Access1D right) { myUtility.modifyMatching(function, right); } - public void modifyMatchingInColumns(Access1D left, BinaryFunction function) { + public void modifyMatchingInColumns(final Access1D left, final BinaryFunction function) { myUtility.modifyMatchingInColumns(left, function); } - public void modifyMatchingInColumns(BinaryFunction function, Access1D right) { + public void modifyMatchingInColumns(final BinaryFunction function, final Access1D right) { myUtility.modifyMatchingInColumns(function, right); } - public void modifyMatchingInRows(Access1D left, BinaryFunction function) { + public void modifyMatchingInRows(final Access1D left, final BinaryFunction function) { myUtility.modifyMatchingInRows(left, function); } - public void modifyMatchingInRows(BinaryFunction function, Access1D right) { + public void modifyMatchingInRows(final BinaryFunction function, final Access1D right) { myUtility.modifyMatchingInRows(function, right); } - public void modifyOne(long row, long col, UnaryFunction modifier) { + public void modifyOne(final long row, final long col, final UnaryFunction modifier) { myUtility.modifyOne(row, col, modifier); } - public void modifyRow(long row, long col, UnaryFunction modifier) { + public void modifyRow(final long row, final long col, final UnaryFunction modifier) { myUtility.modifyRow(row, col, modifier); } - public void modifyRow(long row, UnaryFunction modifier) { + public void modifyRow(final long row, final UnaryFunction modifier) { myUtility.modifyRow(row, modifier); } @@ -734,11 +734,11 @@ public void modifyRow(long row, UnaryFunction modifier) { return FACTORY; } - public void reduceColumns(Aggregator aggregator, Mutate1D receiver) { + public void reduceColumns(final Aggregator aggregator, final Mutate1D receiver) { myUtility.reduceColumns(aggregator, receiver); } - public void reduceRows(Aggregator aggregator, Mutate1D receiver) { + public void reduceRows(final Aggregator aggregator, final Mutate1D receiver) { myUtility.reduceRows(aggregator, receiver); } @@ -766,19 +766,19 @@ public RowView rows() { return myUtility.rows(); } - public void set(long row, long col, Comparable value) { + public void set(final long row, final long col, final Comparable value) { myUtility.set(row, col, value); } - public void set(long row, long col, double value) { + public void set(final long row, final long col, final double value) { myUtility.set(row, col, value); } - public short shortValue(long row, long col) { + public short shortValue(final long row, final long col) { return myUtility.shortValue(row, col); } - public Array1D sliceColumn(long col) { + public Array1D sliceColumn(final long col) { return myUtility.sliceColumn(col); } @@ -794,7 +794,7 @@ public Array1D sliceDiagonal(final long row, final long col) { return myUtility.sliceDiagonal(row, col); } - public Array1D sliceRow(long row) { + public Array1D sliceRow(final long row) { return myUtility.sliceRow(row); } @@ -968,7 +968,7 @@ public void visitColumn(final long row, final long col, final VoidFunction visitor) { + public void visitColumn(final long col, final VoidFunction visitor) { myUtility.visitColumn(col, visitor); } @@ -976,11 +976,11 @@ public void visitDiagonal(final long row, final long col, final VoidFunction visitor) { + public void visitDiagonal(final VoidFunction visitor) { myUtility.visitDiagonal(visitor); } - public void visitOne(long row, long col, VoidFunction visitor) { + public void visitOne(final long row, final long col, final VoidFunction visitor) { myUtility.visitOne(row, col, visitor); } @@ -988,7 +988,7 @@ public void visitRow(final long row, final long col, final VoidFunction myUtility.visitRow(row, col, visitor); } - public void visitRow(long row, VoidFunction visitor) { + public void visitRow(final long row, final VoidFunction visitor) { myUtility.visitRow(row, visitor); } diff --git a/src/org/ojalgo/matrix/store/PrimitiveFactory.java b/src/org/ojalgo/matrix/store/PrimitiveFactory.java index 7c76893d6..ca456422a 100644 --- a/src/org/ojalgo/matrix/store/PrimitiveFactory.java +++ b/src/org/ojalgo/matrix/store/PrimitiveFactory.java @@ -36,10 +36,6 @@ abstract class PrimitiveFactory> implements PhysicalStore.Factory { - public MatrixStore.Factory builder() { - return MatrixStore.PRIMITIVE64; - } - public final AggregatorSet aggregator() { return PrimitiveAggregator.getSet(); } @@ -48,6 +44,10 @@ public DenseArray.Factory array() { return Primitive64Array.FACTORY; } + public MatrixStore.Factory builder() { + return MatrixStore.PRIMITIVE64; + } + public final I conjugate(final Access2D source) { return this.transpose(source); } @@ -56,6 +56,15 @@ public final FunctionSet function() { return PrimitiveFunction.getSet(); } + public final I makeFilled(final long rows, final long columns, final NullaryFunction supplier) { + + I retVal = this.make(rows, columns); + + retVal.fillAll(supplier); + + return retVal; + } + public Householder makeHouseholder(final int length) { return new Householder.Primitive64(length); } @@ -72,13 +81,4 @@ public final Scalar.Factory scalar() { return PrimitiveScalar.FACTORY; } - public final I makeFilled(long rows, long columns, NullaryFunction supplier) { - - I retVal = this.make(rows, columns); - - retVal.fillAll(supplier); - - return retVal; - } - } diff --git a/src/org/ojalgo/matrix/store/RawStore.java b/src/org/ojalgo/matrix/store/RawStore.java index 6a7f0e3be..b9ef666f0 100644 --- a/src/org/ojalgo/matrix/store/RawStore.java +++ b/src/org/ojalgo/matrix/store/RawStore.java @@ -82,54 +82,54 @@ public RawStore columns(final Access1D... source) { return new RawStore(retVal); } - public RawStore columns(final double[]... source) { + public RawStore columns(final Comparable[]... source) { int tmpRowDim = source[0].length; int tmpColDim = source.length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - double[] tmpColumn; + Comparable[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - retVal[i][j] = tmpColumn[i]; + retVal[i][j] = Scalar.doubleValue(tmpColumn[i]); } } return new RawStore(retVal); } - public RawStore columns(final List>... source) { + public RawStore columns(final double[]... source) { - int tmpRowDim = source[0].size(); + int tmpRowDim = source[0].length; int tmpColDim = source.length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - List> tmpColumn; + double[] tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - retVal[i][j] = Scalar.doubleValue(tmpColumn.get(i)); + retVal[i][j] = tmpColumn[i]; } } return new RawStore(retVal); } - public RawStore columns(final Comparable[]... source) { + public RawStore columns(final List>... source) { - int tmpRowDim = source[0].length; + int tmpRowDim = source[0].size(); int tmpColDim = source.length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - Comparable[] tmpColumn; + List> tmpColumn; for (int j = 0; j < tmpColDim; j++) { tmpColumn = source[j]; for (int i = 0; i < tmpRowDim; i++) { - retVal[i][j] = Scalar.doubleValue(tmpColumn[i]); + retVal[i][j] = Scalar.doubleValue(tmpColumn.get(i)); } } @@ -183,60 +183,60 @@ public RawStore rows(final Access1D... source) { return new RawStore(retVal); } - public RawStore rows(final double[]... source) { + public RawStore rows(final Comparable[]... source) { int tmpRowDim = source.length; int tmpColDim = source[0].length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - double[] tmpSource; + Comparable[] tmpSource; double[] tmpDestination; for (int i = 0; i < tmpRowDim; i++) { tmpSource = source[i]; tmpDestination = retVal[i]; for (int j = 0; j < tmpColDim; j++) { - tmpDestination[j] = tmpSource[j]; + tmpDestination[j] = Scalar.doubleValue(tmpSource[j]); } } return new RawStore(retVal); } - public RawStore rows(final List>... source) { + public RawStore rows(final double[]... source) { int tmpRowDim = source.length; - int tmpColDim = source[0].size(); + int tmpColDim = source[0].length; double[][] retVal = new double[tmpRowDim][tmpColDim]; - List> tmpSource; + double[] tmpSource; double[] tmpDestination; for (int i = 0; i < tmpRowDim; i++) { tmpSource = source[i]; tmpDestination = retVal[i]; for (int j = 0; j < tmpColDim; j++) { - tmpDestination[j] = Scalar.doubleValue(tmpSource.get(j)); + tmpDestination[j] = tmpSource[j]; } } return new RawStore(retVal); } - public RawStore rows(final Comparable[]... source) { + public RawStore rows(final List>... source) { int tmpRowDim = source.length; - int tmpColDim = source[0].length; + int tmpColDim = source[0].size(); double[][] retVal = new double[tmpRowDim][tmpColDim]; - Comparable[] tmpSource; + List> tmpSource; double[] tmpDestination; for (int i = 0; i < tmpRowDim; i++) { tmpSource = source[i]; tmpDestination = retVal[i]; for (int j = 0; j < tmpColDim; j++) { - tmpDestination[j] = Scalar.doubleValue(tmpSource[j]); + tmpDestination[j] = Scalar.doubleValue(tmpSource.get(j)); } } @@ -620,14 +620,14 @@ public void accept(final Access2D supplied) { } } - public void add(final long row, final long col, final double addend) { - data[Math.toIntExact(row)][Math.toIntExact(col)] += addend; - } - public void add(final long row, final long col, final Comparable addend) { data[Math.toIntExact(row)][Math.toIntExact(col)] += Scalar.doubleValue(addend); } + public void add(final long row, final long col, final double addend) { + data[Math.toIntExact(row)][Math.toIntExact(col)] += addend; + } + public Double aggregateAll(final Aggregator aggregator) { AggregatorFunction tmpVisitor = aggregator.getFunction(PrimitiveAggregator.getSet()); @@ -1105,14 +1105,14 @@ public TransformableRegion regionByTransposing() { return new TransformableRegion.TransposedRegion<>(this, MultiplyBoth.newPrimitive64(data.length, myNumberOfColumns)); } - public void set(final long row, final long col, final double value) { - data[Math.toIntExact(row)][Math.toIntExact(col)] = value; - } - public void set(final long row, final long col, final Comparable value) { data[Math.toIntExact(row)][Math.toIntExact(col)] = Scalar.doubleValue(value); } + public void set(final long row, final long col, final double value) { + data[Math.toIntExact(row)][Math.toIntExact(col)] = value; + } + public Access1D sliceRow(final long row) { return Access1D.wrap(data[Math.toIntExact(row)]); } diff --git a/src/org/ojalgo/matrix/store/RowsSupplier.java b/src/org/ojalgo/matrix/store/RowsSupplier.java index 721312d19..2d1a6467f 100644 --- a/src/org/ojalgo/matrix/store/RowsSupplier.java +++ b/src/org/ojalgo/matrix/store/RowsSupplier.java @@ -106,11 +106,11 @@ public void supplyTo(final TransformableRegion receiver) { myRows.get(i).supplyNonZerosTo(new Mutate1D() { - public void add(final long index, final double addend) { + public void add(final long index, final Comparable addend) { receiver.add(row, index, addend); } - public void add(final long index, final Comparable addend) { + public void add(final long index, final double addend) { receiver.add(row, index, addend); } @@ -118,11 +118,11 @@ public long count() { return receiver.countColumns(); } - public void set(final long index, final double value) { + public void set(final long index, final Comparable value) { receiver.set(row, index, value); } - public void set(final long index, final Comparable value) { + public void set(final long index, final double value) { receiver.set(row, index, value); } diff --git a/src/org/ojalgo/matrix/store/SparseStore.java b/src/org/ojalgo/matrix/store/SparseStore.java index 6bc9c5420..4bf98c626 100644 --- a/src/org/ojalgo/matrix/store/SparseStore.java +++ b/src/org/ojalgo/matrix/store/SparseStore.java @@ -139,12 +139,12 @@ static > void multiply(final SparseStore left, final } } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myElements.add(Structure2D.index(myFirsts.length, row, col), addend); this.updateNonZeros(row, col); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myElements.add(Structure2D.index(myFirsts.length, row, col), addend); this.updateNonZeros(row, col); } @@ -508,12 +508,12 @@ public void reset() { Arrays.fill(myLimits, 0); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myElements.set(Structure2D.index(myFirsts.length, row, col), value); this.updateNonZeros(row, col); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myElements.set(Structure2D.index(myFirsts.length, row, col), value); this.updateNonZeros(row, col); } diff --git a/src/org/ojalgo/matrix/store/TransformableRegion.java b/src/org/ojalgo/matrix/store/TransformableRegion.java index 49eddbed6..b22e3c4db 100644 --- a/src/org/ojalgo/matrix/store/TransformableRegion.java +++ b/src/org/ojalgo/matrix/store/TransformableRegion.java @@ -53,11 +53,11 @@ protected ColumnsRegion(final TransformableRegion base, final TransformableRe myColumns = columns; } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(row, myColumns[(int) col], addend); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myBase.add(row, myColumns[(int) col], addend); } @@ -109,11 +109,11 @@ public void modifyOne(final long row, final long col, final UnaryFunction mod myBase.modifyOne(row, myColumns[(int) col], modifier); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(row, myColumns[(int) col], value); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myBase.set(row, myColumns[(int) col], value); } @@ -137,11 +137,11 @@ protected LimitRegion(final TransformableRegion base, final FillByMultiplying myColumnLimit = columnLimit; } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(row, col, addend); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myBase.add(row, col, addend); } @@ -177,11 +177,11 @@ public void modifyOne(final long row, final long col, final UnaryFunction mod myBase.modifyOne(row, col, modifier); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(row, col, value); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myBase.set(row, col, value); } @@ -199,11 +199,11 @@ protected OffsetRegion(final TransformableRegion base, final FillByMultiplyin myColumnOffset = columnOffset; } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(myRowOffset + row, myColumnOffset + col, addend); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myBase.add(myRowOffset + row, myColumnOffset + col, addend); } @@ -297,11 +297,11 @@ public void modifyRow(final long row, final long col, final UnaryFunction mod myBase.modifyRow(myRowOffset + row, myColumnOffset + col, modifier); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(myRowOffset + row, myColumnOffset + col, value); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myBase.set(myRowOffset + row, myColumnOffset + col, value); } @@ -378,11 +378,11 @@ protected RowsRegion(final TransformableRegion base, final FillByMultiplying< myRows = rows; } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(myRows[(int) row], col, addend); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myBase.add(myRows[(int) row], col, addend); } @@ -434,11 +434,11 @@ public void modifyRow(final long row, final long col, final UnaryFunction mod myBase.modifyRow(myRows[(int) row], col, modifier); } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(myRows[(int) row], col, value); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myBase.set(myRows[(int) row], col, value); } @@ -453,11 +453,11 @@ protected TransposedRegion(final TransformableRegion base, final FillByMultip myBase = base; } - public void add(final long row, final long col, final double addend) { + public void add(final long row, final long col, final Comparable addend) { myBase.add(col, row, addend); } - public void add(final long row, final long col, final Comparable addend) { + public void add(final long row, final long col, final double addend) { myBase.add(col, row, addend); } @@ -534,11 +534,11 @@ public TransformableRegion regionByTransposing() { return myBase; } - public void set(final long row, final long col, final double value) { + public void set(final long row, final long col, final Comparable value) { myBase.set(col, row, value); } - public void set(final long row, final long col, final Comparable value) { + public void set(final long row, final long col, final double value) { myBase.set(col, row, value); } diff --git a/src/org/ojalgo/matrix/transformation/Householder.java b/src/org/ojalgo/matrix/transformation/Householder.java index 9a30f6422..4fddb1b1b 100644 --- a/src/org/ojalgo/matrix/transformation/Householder.java +++ b/src/org/ojalgo/matrix/transformation/Householder.java @@ -131,55 +131,55 @@ public String toString() { } - public static final class Primitive64 implements Householder { + public static final class Primitive32 implements Householder { - public double beta; + public float beta; public int first; - public final double[] vector; + public final float[] vector; - public Primitive64(final Householder aTransf) { + public Primitive32(final Householder aTransf) { this((int) aTransf.count()); this.copy(aTransf); } - public Primitive64(final int aDim) { + public Primitive32(final int aDim) { super(); - vector = new double[aDim]; - beta = PrimitiveMath.ZERO; + vector = new float[aDim]; + beta = (float) PrimitiveMath.ZERO; first = 0; } - public Householder.Primitive64 copy(final Householder source) { + public Householder.Primitive32 copy(final Householder source) { first = source.first(); - final double[] tmpVector = vector; - double tmpVal, tmpVal2 = PrimitiveMath.ZERO; + final float[] tmpVector = vector; + float tmpVal, tmpVal2 = (float) PrimitiveMath.ZERO; final int tmpSize = (int) source.count(); for (int i = source.first(); i < tmpSize; i++) { - tmpVal = source.doubleValue(i); + tmpVal = source.floatValue(i); tmpVal2 += tmpVal * tmpVal; tmpVector[i] = tmpVal; } - beta = PrimitiveMath.TWO / tmpVal2; + beta = (float) PrimitiveMath.TWO / tmpVal2; return this; } - public Householder.Primitive64 copy(final Householder source, final double precalculatedBeta) { + public Householder.Primitive32 copy(final Householder source, final float precalculatedBeta) { first = source.first(); - final double[] tmpVector = vector; + final float[] tmpVector = vector; final int tmpSize = (int) source.count(); for (int i = source.first(); i < tmpSize; i++) { - tmpVector[i] = source.doubleValue(i); + tmpVector[i] = source.floatValue(i); } beta = precalculatedBeta; @@ -200,7 +200,7 @@ public int first() { } public Double get(final long index) { - return vector[(int) index]; + return Double.valueOf(vector[(int) index]); } @Override @@ -222,55 +222,55 @@ public String toString() { } - public static final class Primitive32 implements Householder { + public static final class Primitive64 implements Householder { - public float beta; + public double beta; public int first; - public final float[] vector; + public final double[] vector; - public Primitive32(final Householder aTransf) { + public Primitive64(final Householder aTransf) { this((int) aTransf.count()); this.copy(aTransf); } - public Primitive32(final int aDim) { + public Primitive64(final int aDim) { super(); - vector = new float[aDim]; - beta = (float) PrimitiveMath.ZERO; + vector = new double[aDim]; + beta = PrimitiveMath.ZERO; first = 0; } - public Householder.Primitive32 copy(final Householder source) { + public Householder.Primitive64 copy(final Householder source) { first = source.first(); - final float[] tmpVector = vector; - float tmpVal, tmpVal2 = (float) PrimitiveMath.ZERO; + final double[] tmpVector = vector; + double tmpVal, tmpVal2 = PrimitiveMath.ZERO; final int tmpSize = (int) source.count(); for (int i = source.first(); i < tmpSize; i++) { - tmpVal = source.floatValue(i); + tmpVal = source.doubleValue(i); tmpVal2 += tmpVal * tmpVal; tmpVector[i] = tmpVal; } - beta = (float) PrimitiveMath.TWO / tmpVal2; + beta = PrimitiveMath.TWO / tmpVal2; return this; } - public Householder.Primitive32 copy(final Householder source, final float precalculatedBeta) { + public Householder.Primitive64 copy(final Householder source, final double precalculatedBeta) { first = source.first(); - final float[] tmpVector = vector; + final double[] tmpVector = vector; final int tmpSize = (int) source.count(); for (int i = source.first(); i < tmpSize; i++) { - tmpVector[i] = source.floatValue(i); + tmpVector[i] = source.doubleValue(i); } beta = precalculatedBeta; @@ -291,7 +291,7 @@ public int first() { } public Double get(final long index) { - return Double.valueOf(vector[(int) index]); + return vector[(int) index]; } @Override diff --git a/src/org/ojalgo/optimisation/Expression.java b/src/org/ojalgo/optimisation/Expression.java index 61ff59d58..f3858b525 100644 --- a/src/org/ojalgo/optimisation/Expression.java +++ b/src/org/ojalgo/optimisation/Expression.java @@ -381,6 +381,10 @@ public boolean isAnyQuadraticFactorNonZero() { return myQuadratic.size() > 0; } + public boolean isFunctionConstant() { + return !this.isAnyQuadraticFactorNonZero() && !this.isAnyLinearFactorNonZero(); + } + public boolean isFunctionLinear() { return !this.isAnyQuadraticFactorNonZero() && this.isAnyLinearFactorNonZero(); } @@ -393,10 +397,6 @@ public boolean isFunctionQuadratic() { return this.isAnyQuadraticFactorNonZero() && this.isAnyLinearFactorNonZero(); } - public boolean isFunctionConstant() { - return !this.isAnyQuadraticFactorNonZero() && !this.isAnyLinearFactorNonZero(); - } - /** * @return Are all the (linear) variables binary */ @@ -425,15 +425,11 @@ public boolean isLinearAndAnyInteger() { return (myQuadratic.size() == 0) && (myLinear.size() > 0) && myLinear.keySet().stream().anyMatch(i -> myModel.getVariable(i).isInteger()); } - public Expression set(final int row, final int column, final Comparable value) { - return this.set(new IntRowColumn(row, column), value); - } - public Expression set(final int index, final Comparable value) { return this.set(myModel.getVariable(index), value); } - public Expression set(final IntIndex row, final IntIndex column, final Comparable value) { + public Expression set(final int row, final int column, final Comparable value) { return this.set(new IntRowColumn(row, column), value); } @@ -458,6 +454,10 @@ public Expression set(final IntIndex key, final Comparable value) { return this; } + public Expression set(final IntIndex row, final IntIndex column, final Comparable value) { + return this.set(new IntRowColumn(row, column), value); + } + public Expression set(final IntRowColumn key, final Comparable value) { if (key != null) { diff --git a/src/org/ojalgo/optimisation/GenericSolver.java b/src/org/ojalgo/optimisation/GenericSolver.java index 7111be0c3..0eb23d0f9 100644 --- a/src/org/ojalgo/optimisation/GenericSolver.java +++ b/src/org/ojalgo/optimisation/GenericSolver.java @@ -117,10 +117,6 @@ public RowsSupplier getAI() { return myAI; } - protected SparseArray getAI(final int row) { - return myAI.getRow(row); - } - /** * [AE][X] == [BE] */ @@ -250,6 +246,10 @@ protected double evaluate(final Access1D arg) { return myObjective.invoke(arg); } + protected SparseArray getAI(final int row) { + return myAI.getRow(row); + } + protected void setObjective(final MultiaryFunction.TwiceDifferentiable objective) { myObjective = objective; } diff --git a/src/org/ojalgo/optimisation/Optimisation.java b/src/org/ojalgo/optimisation/Optimisation.java index 3c1eeee1b..b6ee3efe4 100644 --- a/src/org/ojalgo/optimisation/Optimisation.java +++ b/src/org/ojalgo/optimisation/Optimisation.java @@ -517,7 +517,7 @@ public enum State implements Optimisation { */ VALID(4); - private final int myValue; + private int myValue; State(final int aValue) { myValue = aValue; diff --git a/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java b/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java index ea5facfc0..82e6a32e4 100644 --- a/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java +++ b/src/org/ojalgo/optimisation/convex/ConvexObjectiveFunction.java @@ -56,6 +56,10 @@ public int arity() { return myLinear.arity(); } + public Double getConstant() { + return myPureQuadratic.getConstant(); + } + public MatrixStore getGradient(final Access1D point) { return myPureQuadratic.getGradient(point).operateOnMatching(SUBTRACT, myLinear.getGradient(point)).get(); } @@ -83,10 +87,6 @@ public PhysicalStore quadratic() { return myPureQuadratic.quadratic(); } - public Double getConstant() { - return myPureQuadratic.getConstant(); - } - public void setConstant(final Comparable constant) { myPureQuadratic.setConstant(constant); } diff --git a/src/org/ojalgo/optimisation/linear/SimplexTableau.java b/src/org/ojalgo/optimisation/linear/SimplexTableau.java index 8e6d7afb9..65e7e3158 100644 --- a/src/org/ojalgo/optimisation/linear/SimplexTableau.java +++ b/src/org/ojalgo/optimisation/linear/SimplexTableau.java @@ -298,6 +298,10 @@ protected DenseTableau toDense() { Mutate2D newConstraintsBody() { return new Mutate2D() { + public void add(final long row, final long col, final Comparable addend) { + this.add(row, col, Scalar.doubleValue(addend)); + } + public void add(final long row, final long col, final double addend) { // myRows[(int) row].add(col, addend); // myPhase1Weights.add(col, -addend); @@ -305,10 +309,6 @@ public void add(final long row, final long col, final double addend) { myTransposed.add(col, DenseTableau.this.countConstraints() + 1, -addend); } - public void add(final long row, final long col, final Comparable addend) { - this.add(row, col, Scalar.doubleValue(addend)); - } - public long countColumns() { return DenseTableau.this.countVariables(); } @@ -317,6 +317,10 @@ public long countRows() { return DenseTableau.this.countConstraints(); } + public void set(final long row, final long col, final Comparable value) { + this.set(row, col, Scalar.doubleValue(value)); + } + public void set(final long row, final long col, final double value) { // myRows[(int) row].set(col, value); // myPhase1Weights.add(col, -value); @@ -324,10 +328,6 @@ public void set(final long row, final long col, final double value) { myTransposed.add(col, DenseTableau.this.countConstraints() + 1, -value); } - public void set(final long row, final long col, final Comparable value) { - this.set(row, col, Scalar.doubleValue(value)); - } - }; } @@ -341,6 +341,10 @@ Mutate1D newConstraintsRHS() { return new Mutate1D() { + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); + } + public void add(final long index, final double addend) { // myRows[(int) index].set(SparseTableau.this.countVariables() + index, ONE); // myRHS.add(index, addend); @@ -350,14 +354,14 @@ public void add(final long index, final double addend) { myTransposed.add(col, numbConstr + 1, -addend); } - public void add(final long index, final Comparable addend) { - this.add(index, Scalar.doubleValue(addend)); - } - public long count() { return DenseTableau.this.countConstraints(); } + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); + } + public void set(final long index, final double value) { // myRows[(int) index].set(SparseTableau.this.countVariables() + index, ONE); // myRHS.set(index, value); @@ -367,10 +371,6 @@ public void set(final long index, final double value) { myTransposed.add(col, numbConstr + 1, -value); } - public void set(final long index, final Comparable value) { - this.set(index, Scalar.doubleValue(value)); - } - }; } @@ -381,28 +381,28 @@ Mutate1D newObjective() { return new Mutate1D() { + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); + } + public void add(final long index, final double addend) { // myObjectiveWeights.add(index, addend); myTransposed.add(index, row, addend); } - public void add(final long index, final Comparable addend) { - this.add(index, Scalar.doubleValue(addend)); - } - public long count() { return DenseTableau.this.countVariables(); } + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); + } + public void set(final long index, final double value) { // myObjectiveWeights.set(index, value); myTransposed.set(index, row, value); } - public void set(final long index, final Comparable value) { - this.set(index, Scalar.doubleValue(value)); - } - }; } @@ -772,15 +772,15 @@ protected DenseTableau toDense() { Mutate2D newConstraintsBody() { return new Mutate2D() { + public void add(final long row, final long col, final Comparable addend) { + this.add(row, col, Scalar.doubleValue(addend)); + } + public void add(final long row, final long col, final double addend) { myRows[(int) row].add(col, addend); myPhase1Weights.add(col, -addend); } - public void add(final long row, final long col, final Comparable addend) { - this.add(row, col, Scalar.doubleValue(addend)); - } - public long countColumns() { return SparseTableau.this.countVariables(); } @@ -789,15 +789,15 @@ public long countRows() { return SparseTableau.this.countConstraints(); } + public void set(final long row, final long col, final Comparable value) { + this.set(row, col, Scalar.doubleValue(value)); + } + public void set(final long row, final long col, final double value) { myRows[(int) row].set(col, value); myPhase1Weights.add(col, -value); } - public void set(final long row, final long col, final Comparable value) { - this.set(row, col, Scalar.doubleValue(value)); - } - }; } @@ -805,30 +805,30 @@ public void set(final long row, final long col, final Comparable value) { Mutate1D newConstraintsRHS() { return new Mutate1D() { + public void add(final long index, final Comparable addend) { + this.add(index, Scalar.doubleValue(addend)); + } + public void add(final long index, final double addend) { myRows[(int) index].set(SparseTableau.this.countVariables() + index, ONE); myRHS.add(index, addend); myInfeasibility -= addend; } - public void add(final long index, final Comparable addend) { - this.add(index, Scalar.doubleValue(addend)); - } - public long count() { return SparseTableau.this.countConstraints(); } + public void set(final long index, final Comparable value) { + this.set(index, Scalar.doubleValue(value)); + } + public void set(final long index, final double value) { myRows[(int) index].set(SparseTableau.this.countVariables() + index, ONE); myRHS.set(index, value); myInfeasibility -= value; } - public void set(final long index, final Comparable value) { - this.set(index, Scalar.doubleValue(value)); - } - }; } @@ -836,26 +836,26 @@ public void set(final long index, final Comparable value) { Mutate1D newObjective() { return new Mutate1D() { - public void add(final long index, final double addend) { - myObjectiveWeights.add(index, addend); - } - public void add(final long index, final Comparable addend) { this.add(index, Scalar.doubleValue(addend)); } - public long count() { - return SparseTableau.this.countVariables(); + public void add(final long index, final double addend) { + myObjectiveWeights.add(index, addend); } - public void set(final long index, final double value) { - myObjectiveWeights.set(index, value); + public long count() { + return SparseTableau.this.countVariables(); } public void set(final long index, final Comparable value) { this.set(index, Scalar.doubleValue(value)); } + public void set(final long index, final double value) { + myObjectiveWeights.set(index, value); + } + }; } diff --git a/src/org/ojalgo/random/Deterministic.java b/src/org/ojalgo/random/Deterministic.java index 9eacd33cc..f01e39fd6 100644 --- a/src/org/ojalgo/random/Deterministic.java +++ b/src/org/ojalgo/random/Deterministic.java @@ -39,18 +39,22 @@ public Deterministic() { myValue = ZERO; } - public Deterministic(final double aValue) { + public Deterministic(final Comparable aValue) { super(); - myValue = aValue; + myValue = Scalar.doubleValue(aValue); } - public Deterministic(final Comparable aValue) { + public Deterministic(final double aValue) { super(); - myValue = Scalar.doubleValue(aValue); + myValue = aValue; + } + + public int compareTo(final Deterministic o) { + return Double.compare(myValue, o.myValue); } public double getExpected() { @@ -72,8 +76,4 @@ protected double generate() { return myValue; } - public int compareTo(Deterministic o) { - return Double.compare(myValue, o.myValue); - } - } diff --git a/src/org/ojalgo/random/RandomNumber.java b/src/org/ojalgo/random/RandomNumber.java index a28fbd9ea..d7e7b027e 100644 --- a/src/org/ojalgo/random/RandomNumber.java +++ b/src/org/ojalgo/random/RandomNumber.java @@ -42,6 +42,10 @@ protected RandomNumber() { super(); } + public int compareTo(final RandomNumber o) { + return Double.compare(this.getExpected(), o.getExpected()); + } + @Override public final double doubleValue() { return this.generate(); @@ -111,8 +115,4 @@ protected void checkProbabilty(final double probabilty) { protected final Random random() { return myRandom; } - - public int compareTo(RandomNumber o) { - return Double.compare(this.getExpected(), o.getExpected()); - } } diff --git a/src/org/ojalgo/scalar/BigScalar.java b/src/org/ojalgo/scalar/BigScalar.java index d0aded276..499d16a2b 100644 --- a/src/org/ojalgo/scalar/BigScalar.java +++ b/src/org/ojalgo/scalar/BigScalar.java @@ -139,7 +139,7 @@ public BigScalar add(final double arg) { } @Override - public BigScalar add(float scalarAddend) { + public BigScalar add(final float scalarAddend) { return this.add((double) scalarAddend); } @@ -164,7 +164,7 @@ public BigScalar divide(final double arg) { } @Override - public BigScalar divide(float scalarDivisor) { + public BigScalar divide(final float scalarDivisor) { return this.divide((double) scalarDivisor); } @@ -179,7 +179,7 @@ public BigScalar enforce(final NumberContext context) { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -251,7 +251,7 @@ public BigScalar multiply(final double arg) { } @Override - public BigScalar multiply(float scalarMultiplicand) { + public BigScalar multiply(final float scalarMultiplicand) { return this.multiply((double) scalarMultiplicand); } @@ -293,7 +293,7 @@ public BigScalar subtract(final double arg) { } @Override - public BigScalar subtract(float scalarSubtrahend) { + public BigScalar subtract(final float scalarSubtrahend) { return this.subtract((double) scalarSubtrahend); } diff --git a/src/org/ojalgo/scalar/ComplexNumber.java b/src/org/ojalgo/scalar/ComplexNumber.java index e43f75468..18e445e47 100644 --- a/src/org/ojalgo/scalar/ComplexNumber.java +++ b/src/org/ojalgo/scalar/ComplexNumber.java @@ -307,7 +307,7 @@ public ComplexNumber add(final double arg) { } @Override - public ComplexNumber add(float scalarAddend) { + public ComplexNumber add(final float scalarAddend) { return this.add((double) scalarAddend); } @@ -400,7 +400,7 @@ public ComplexNumber divide(final double arg) { } @Override - public ComplexNumber divide(float scalarDivisor) { + public ComplexNumber divide(final float scalarDivisor) { return this.divide((double) scalarDivisor); } @@ -451,7 +451,7 @@ public ComplexNumber enforce(final NumberContext context) { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -581,7 +581,7 @@ public ComplexNumber multiply(final double arg) { } @Override - public ComplexNumber multiply(float scalarMultiplicand) { + public ComplexNumber multiply(final float scalarMultiplicand) { return this.multiply((double) scalarMultiplicand); } @@ -657,7 +657,7 @@ public ComplexNumber subtract(final double arg) { } @Override - public ComplexNumber subtract(float scalarSubtrahend) { + public ComplexNumber subtract(final float scalarSubtrahend) { return this.subtract((double) scalarSubtrahend); } diff --git a/src/org/ojalgo/scalar/ExactDecimal.java b/src/org/ojalgo/scalar/ExactDecimal.java index dee241281..88e6294d5 100644 --- a/src/org/ojalgo/scalar/ExactDecimal.java +++ b/src/org/ojalgo/scalar/ExactDecimal.java @@ -111,6 +111,11 @@ public final S add(final double scalarAddend) { return this.wrap(myNumerator + Math.round(scalarAddend * this.descriptor().denominator())); } + @Override + public S add(final float scalarAddend) { + return this.add((double) scalarAddend); + } + @Override public final S add(final S scalarAddend) { return this.wrap(myNumerator + scalarAddend.numerator()); @@ -132,6 +137,11 @@ public final S divide(final double scalarDivisor) { return this.wrap(Math.round(myNumerator / scalarDivisor)); } + @Override + public S divide(final float scalarDivisor) { + return this.divide((double) scalarDivisor); + } + @Override public final S divide(final S scalarDivisor) { return this.wrap((myNumerator * this.descriptor().denominator()) / scalarDivisor.numerator()); @@ -191,6 +201,11 @@ public final S multiply(final double scalarMultiplicand) { return this.wrap(Math.round(myNumerator * scalarMultiplicand)); } + @Override + public S multiply(final float scalarMultiplicand) { + return this.multiply((double) scalarMultiplicand); + } + @Override public final S multiply(final S scalarMultiplicand) { return this.wrap((myNumerator * scalarMultiplicand.numerator()) / this.descriptor().denominator()); @@ -243,6 +258,11 @@ public final S subtract(final double scalarSubtrahend) { return this.wrap(myNumerator - Math.round(scalarSubtrahend * this.descriptor().denominator())); } + @Override + public S subtract(final float scalarSubtrahend) { + return this.subtract((double) scalarSubtrahend); + } + @Override public final S subtract(final S scalarSubtrahend) { return this.wrap(myNumerator - scalarSubtrahend.numerator()); @@ -278,24 +298,4 @@ final long numerator() { return myNumerator; } - @Override - public S add(float scalarAddend) { - return this.add((double) scalarAddend); - } - - @Override - public S divide(float scalarDivisor) { - return this.divide((double) scalarDivisor); - } - - @Override - public S multiply(float scalarMultiplicand) { - return this.multiply((double) scalarMultiplicand); - } - - @Override - public S subtract(float scalarSubtrahend) { - return this.subtract((double) scalarSubtrahend); - } - } diff --git a/src/org/ojalgo/scalar/Money.java b/src/org/ojalgo/scalar/Money.java index e88870f10..2c601ee84 100644 --- a/src/org/ojalgo/scalar/Money.java +++ b/src/org/ojalgo/scalar/Money.java @@ -32,18 +32,13 @@ public final class Money extends ExactDecimal { public static final Scalar.Factory FACTORY = new ExactDecimal.Factory() { - @Override - public Money cast(final double value) { - return Money.valueOf(value); - } - @Override public Money cast(final Comparable number) { return Money.valueOf(number); } @Override - public Money convert(final double value) { + public Money cast(final double value) { return Money.valueOf(value); } @@ -52,6 +47,11 @@ public Money convert(final Comparable number) { return Money.valueOf(number); } + @Override + public Money convert(final double value) { + return Money.valueOf(value); + } + @Override public Descriptor descriptor() { return DESCRIPTOR; @@ -93,10 +93,6 @@ public static boolean isSmall(final double comparedTo, final Money value) { return value.isSmall(comparedTo); } - public static Money valueOf(final double value) { - return new Money(Math.round(value * DOUBLE_DENOMINATOR)); - } - public static Money valueOf(final Comparable number) { if (number != null) { @@ -116,6 +112,10 @@ public static Money valueOf(final Comparable number) { } } + public static Money valueOf(final double value) { + return new Money(Math.round(value * DOUBLE_DENOMINATOR)); + } + public Money() { super(0L); } diff --git a/src/org/ojalgo/scalar/PrimitiveScalar.java b/src/org/ojalgo/scalar/PrimitiveScalar.java index 19b23adb0..c95083dba 100644 --- a/src/org/ojalgo/scalar/PrimitiveScalar.java +++ b/src/org/ojalgo/scalar/PrimitiveScalar.java @@ -129,7 +129,7 @@ public PrimitiveScalar add(final Double arg) { } @Override - public PrimitiveScalar add(float scalarAddend) { + public PrimitiveScalar add(final float scalarAddend) { return this.add((double) scalarAddend); } @@ -154,7 +154,7 @@ public PrimitiveScalar divide(final Double arg) { } @Override - public PrimitiveScalar divide(float scalarDivisor) { + public PrimitiveScalar divide(final float scalarDivisor) { return this.divide((double) scalarDivisor); } @@ -169,7 +169,7 @@ public PrimitiveScalar enforce(final NumberContext context) { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -239,7 +239,7 @@ public PrimitiveScalar multiply(final Double arg) { } @Override - public PrimitiveScalar multiply(float scalarMultiplicand) { + public PrimitiveScalar multiply(final float scalarMultiplicand) { return this.multiply((double) scalarMultiplicand); } @@ -281,7 +281,7 @@ public PrimitiveScalar subtract(final Double arg) { } @Override - public PrimitiveScalar subtract(float scalarSubtrahend) { + public PrimitiveScalar subtract(final float scalarSubtrahend) { return this.subtract((double) scalarSubtrahend); } diff --git a/src/org/ojalgo/scalar/Quaternion.java b/src/org/ojalgo/scalar/Quaternion.java index 138aa113d..13f87d560 100644 --- a/src/org/ojalgo/scalar/Quaternion.java +++ b/src/org/ojalgo/scalar/Quaternion.java @@ -342,7 +342,7 @@ public Quaternion add(final double arg) { } @Override - public Quaternion add(float scalarAddend) { + public Quaternion add(final float scalarAddend) { return this.add((double) scalarAddend); } @@ -439,7 +439,7 @@ public Quaternion divide(final double arg) { } @Override - public Quaternion divide(float scalarDivisor) { + public Quaternion divide(final float scalarDivisor) { return this.divide((double) scalarDivisor); } @@ -521,7 +521,7 @@ public Quaternion enforce(final NumberContext context) { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -677,7 +677,7 @@ public Quaternion multiply(final double arg) { } @Override - public Quaternion multiply(float scalarMultiplicand) { + public Quaternion multiply(final float scalarMultiplicand) { return this.multiply((double) scalarMultiplicand); } @@ -747,7 +747,7 @@ public Quaternion subtract(final double arg) { } @Override - public Quaternion subtract(float scalarSubtrahend) { + public Quaternion subtract(final float scalarSubtrahend) { return this.subtract((double) scalarSubtrahend); } diff --git a/src/org/ojalgo/scalar/RationalNumber.java b/src/org/ojalgo/scalar/RationalNumber.java index ed73a6e16..abae6234f 100644 --- a/src/org/ojalgo/scalar/RationalNumber.java +++ b/src/org/ojalgo/scalar/RationalNumber.java @@ -392,7 +392,7 @@ public RationalNumber add(final double arg) { } @Override - public RationalNumber add(float scalarAddend) { + public RationalNumber add(final float scalarAddend) { return this.add((double) scalarAddend); } @@ -466,7 +466,7 @@ public RationalNumber divide(final double arg) { } @Override - public RationalNumber divide(float scalarDivisor) { + public RationalNumber divide(final float scalarDivisor) { return this.divide((double) scalarDivisor); } @@ -518,7 +518,7 @@ public RationalNumber enforce(final NumberContext context) { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -585,7 +585,7 @@ public RationalNumber multiply(final double arg) { } @Override - public RationalNumber multiply(float scalarMultiplicand) { + public RationalNumber multiply(final float scalarMultiplicand) { return this.multiply((double) scalarMultiplicand); } @@ -651,7 +651,7 @@ public RationalNumber subtract(final double arg) { } @Override - public RationalNumber subtract(float scalarSubtrahend) { + public RationalNumber subtract(final float scalarSubtrahend) { return this.subtract((double) scalarSubtrahend); } diff --git a/src/org/ojalgo/structure/ColumnView.java b/src/org/ojalgo/structure/ColumnView.java index 4f4c5906c..063cd6e55 100644 --- a/src/org/ojalgo/structure/ColumnView.java +++ b/src/org/ojalgo/structure/ColumnView.java @@ -115,6 +115,10 @@ public final void remove() { ProgrammingError.throwForUnsupportedOptionalOperation(); } + public Stream> stream() { + return StreamSupport.stream(this, false); + } + /** * @deprecated v48 Use {@link #stream()} instead */ @@ -123,10 +127,6 @@ public Stream> stream(final boolean parallel) { return this.stream(); } - public Stream> stream() { - return StreamSupport.stream(this, false); - } - @Override public final String toString() { return Access1D.toString(this); diff --git a/src/org/ojalgo/structure/ElementView1D.java b/src/org/ojalgo/structure/ElementView1D.java index 5dba216e4..4574fc515 100644 --- a/src/org/ojalgo/structure/ElementView1D.java +++ b/src/org/ojalgo/structure/ElementView1D.java @@ -81,6 +81,10 @@ default boolean step() { } } + default Stream stream() { + return StreamSupport.stream(this, false); + } + /** * @deprecated v48 Use {@link #stream()} instead */ @@ -89,10 +93,6 @@ default Stream stream(final boolean parallel) { return this.stream(); } - default Stream stream() { - return StreamSupport.stream(this, false); - } - default boolean tryAdvance(final Consumer action) { if (this.hasNext()) { action.accept(this.next()); diff --git a/src/org/ojalgo/structure/Factory1D.java b/src/org/ojalgo/structure/Factory1D.java index 6b7009b2d..d69e2a9f7 100644 --- a/src/org/ojalgo/structure/Factory1D.java +++ b/src/org/ojalgo/structure/Factory1D.java @@ -36,12 +36,12 @@ interface Dense extends Factory1D { I copy(Access1D source); + I copy(Comparable... source); + I copy(double... source); I copy(List> source); - I copy(Comparable... source); - I makeFilled(long count, NullaryFunction supplier); default I makeFilled(final Structure1D shape, final NullaryFunction supplier) { diff --git a/src/org/ojalgo/structure/Factory2D.java b/src/org/ojalgo/structure/Factory2D.java index c594c62d9..c5bd1b6b5 100644 --- a/src/org/ojalgo/structure/Factory2D.java +++ b/src/org/ojalgo/structure/Factory2D.java @@ -40,13 +40,13 @@ default I column(final double... elements) { I columns(Access1D... source); + I columns(Comparable[]... source); + I columns(double[]... source); @SuppressWarnings("unchecked") I columns(List>... source); - I columns(Comparable[]... source); - I copy(Access2D source); I makeFilled(long rows, long columns, NullaryFunction supplier); @@ -61,13 +61,13 @@ default I row(final double... elements) { I rows(Access1D... source); + I rows(Comparable[]... source); + I rows(double[]... source); @SuppressWarnings("unchecked") I rows(List>... source); - I rows(Comparable[]... source); - } /** diff --git a/src/org/ojalgo/structure/Mutate1D.java b/src/org/ojalgo/structure/Mutate1D.java index 1cfda6fda..db76f1c22 100644 --- a/src/org/ojalgo/structure/Mutate1D.java +++ b/src/org/ojalgo/structure/Mutate1D.java @@ -217,14 +217,14 @@ static void copyComplexRealAndImaginary(final Access1D source, fi }); } + void add(long index, Comparable addend); + void add(long index, double addend); - default void add(long index, float addend) { + default void add(final long index, final float addend) { this.add(index, (double) addend); } - void add(long index, Comparable addend); - /** * Reset this mutable structure to some standard (all zeros) initial state. It must still be usuable after * this call, and the structure/size/shape must not change. @@ -233,12 +233,12 @@ default void reset() { this.loopAll(i -> this.set(i, PrimitiveMath.ZERO)); } + void set(long index, Comparable value); + void set(long index, double value); - default void set(long index, float value) { + default void set(final long index, final float value) { this.set(index, (double) value); } - void set(long index, Comparable value); - } diff --git a/src/org/ojalgo/structure/Mutate2D.java b/src/org/ojalgo/structure/Mutate2D.java index 231b36458..e39c82ae2 100644 --- a/src/org/ojalgo/structure/Mutate2D.java +++ b/src/org/ojalgo/structure/Mutate2D.java @@ -269,7 +269,7 @@ default void add(final long index, final float addend) { void add(long row, long col, double addend); - default void add(long row, long col, float addend) { + default void add(final long row, final long col, final float addend) { this.add(row, col, (double) addend); } @@ -295,7 +295,7 @@ default void set(final long index, final float addend) { void set(long row, long col, double value); - default void set(long row, long col, float value) { + default void set(final long row, final long col, final float value) { this.set(row, col, (double) value); } diff --git a/src/org/ojalgo/structure/MutateAnyD.java b/src/org/ojalgo/structure/MutateAnyD.java index c4098934d..0167cbc74 100644 --- a/src/org/ojalgo/structure/MutateAnyD.java +++ b/src/org/ojalgo/structure/MutateAnyD.java @@ -136,7 +136,7 @@ default void add(final long index, final float addend) { void add(long[] reference, double addend); - default void add(long[] reference, float addend) { + default void add(final long[] reference, final float addend) { this.add(reference, (double) addend); } @@ -159,7 +159,7 @@ default void set(final long index, final float value) { void set(long[] reference, double value); - default void set(long[] reference, float value) { + default void set(final long[] reference, final float value) { this.set(reference, (double) value); } diff --git a/src/org/ojalgo/structure/RowView.java b/src/org/ojalgo/structure/RowView.java index 29579137e..793c9e0e4 100644 --- a/src/org/ojalgo/structure/RowView.java +++ b/src/org/ojalgo/structure/RowView.java @@ -115,6 +115,10 @@ public long row() { return myRow; } + public Stream> stream() { + return StreamSupport.stream(this, false); + } + /** * @deprecated v48 Use {@link #stream()} instead */ @@ -123,10 +127,6 @@ public Stream> stream(final boolean parallel) { return this.stream(); } - public Stream> stream() { - return StreamSupport.stream(this, false); - } - @Override public final String toString() { return Access1D.toString(this); diff --git a/src/org/ojalgo/type/context/NumberContext.java b/src/org/ojalgo/type/context/NumberContext.java index 72114926d..c4ee62a58 100644 --- a/src/org/ojalgo/type/context/NumberContext.java +++ b/src/org/ojalgo/type/context/NumberContext.java @@ -277,15 +277,6 @@ public BigDecimal enforce(final BigDecimal number) { return this.scale(tmpDecimal); } - /** - * Does not enforce the precision and does not use the specified rounding mode. The precision is given by - * the type double and the rounding mode is always "half even" as given by - * {@linkplain StrictMath#rint(double)}. - */ - public double enforce(final double number) { - return PrimitiveMath.RINT.invoke(myRoundingFactor * number) / myRoundingFactor; - } - @Override public Comparable enforce(final Comparable object) { if (object instanceof BigDecimal) { @@ -297,6 +288,15 @@ public Comparable enforce(final Comparable object) { } } + /** + * Does not enforce the precision and does not use the specified rounding mode. The precision is given by + * the type double and the rounding mode is always "half even" as given by + * {@linkplain StrictMath#rint(double)}. + */ + public double enforce(final double number) { + return PrimitiveMath.RINT.invoke(myRoundingFactor * number) / myRoundingFactor; + } + /** * @return the epsilon */ diff --git a/test/org/ojalgo/TestUtils.java b/test/org/ojalgo/TestUtils.java index eecc54dab..ecf39ac3b 100644 --- a/test/org/ojalgo/TestUtils.java +++ b/test/org/ojalgo/TestUtils.java @@ -96,6 +96,14 @@ public static void assertEquals(final boolean expected, final boolean actual) { Assertions.assertEquals(expected, actual); } + public static void assertEquals(final Comparable expected, final Comparable actual) { + TestUtils.assertEquals(expected, actual, EQUALS); + } + + public static void assertEquals(final Comparable expected, final Comparable actual, final NumberContext context) { + TestUtils.assertEquals("Number != Number", expected, actual, context); + } + public static void assertEquals(final ComplexNumber expected, final ComplexNumber actual) { TestUtils.assertEquals(expected, actual, EQUALS); } @@ -202,14 +210,6 @@ public static > void assertEquals(final MatrixStore e } } - public static void assertEquals(final Comparable expected, final Comparable actual) { - TestUtils.assertEquals(expected, actual, EQUALS); - } - - public static void assertEquals(final Comparable expected, final Comparable actual, final NumberContext context) { - TestUtils.assertEquals("Number != Number", expected, actual, context); - } - public static void assertEquals(final Object expected, final Object actual) { Assertions.assertEquals(expected, actual); } @@ -246,48 +246,6 @@ public static void assertEquals(final String message, final Access1D expected context.isSmall(tmpFrobNormExpt, tmpFrobNormDiff)); } - public static void assertEquals(final String message, final ComplexNumber expected, final ComplexNumber actual) { - TestUtils.assertEquals(message, expected, actual, EQUALS); - } - - public static void assertEquals(final String message, final ComplexNumber expected, final ComplexNumber actual, final NumberContext context) { - TestUtils.assertEquals(message, (Comparable) expected, (Comparable) actual, context); - TestUtils.assertEquals(message, (Access1D) expected, (Access1D) actual, context); - } - - public static void assertEquals(final String message, final double expected, final double actual) { - TestUtils.assertEquals(message, expected, actual, EQUALS); - } - - public static void assertEquals(final String message, final double expected, final double actual, final double delta) { - Assertions.assertEquals(expected, actual, delta, message); - } - - public static void assertEquals(final String message, final double expected, final double actual, final NumberContext context) { - // TestUtils.assertEquals(message, Double.valueOf(expected), Double.valueOf(actual), context); - if (Double.isNaN(expected) && Double.isNaN(actual)) { - - } else if (context.isDifferent(expected, actual)) { - Assertions.fail(() -> message + ": " + expected + " != " + actual); - } - } - - public static void assertEquals(final String message, final int expected, final int actual) { - Assertions.assertEquals(expected, actual, message); - } - - public static void assertEquals(final String message, final int[] expected, final int[] actual) { - TestUtils.assertTrue(message, Arrays.equals(expected, actual)); - } - - public static void assertEquals(final String message, final long expected, final long actual) { - Assertions.assertEquals(expected, actual, message); - } - - public static void assertEquals(final String message, final long[] expected, final long[] actual) { - TestUtils.assertTrue(message, Arrays.equals(expected, actual)); - } - public static void assertEquals(final String message, final Comparable expected, final Comparable actual) { TestUtils.assertEquals(message, expected, actual, EQUALS); } @@ -339,6 +297,48 @@ public static void assertEquals(final String message, final Comparable expect } } + public static void assertEquals(final String message, final ComplexNumber expected, final ComplexNumber actual) { + TestUtils.assertEquals(message, expected, actual, EQUALS); + } + + public static void assertEquals(final String message, final ComplexNumber expected, final ComplexNumber actual, final NumberContext context) { + TestUtils.assertEquals(message, (Comparable) expected, (Comparable) actual, context); + TestUtils.assertEquals(message, (Access1D) expected, (Access1D) actual, context); + } + + public static void assertEquals(final String message, final double expected, final double actual) { + TestUtils.assertEquals(message, expected, actual, EQUALS); + } + + public static void assertEquals(final String message, final double expected, final double actual, final double delta) { + Assertions.assertEquals(expected, actual, delta, message); + } + + public static void assertEquals(final String message, final double expected, final double actual, final NumberContext context) { + // TestUtils.assertEquals(message, Double.valueOf(expected), Double.valueOf(actual), context); + if (Double.isNaN(expected) && Double.isNaN(actual)) { + + } else if (context.isDifferent(expected, actual)) { + Assertions.fail(() -> message + ": " + expected + " != " + actual); + } + } + + public static void assertEquals(final String message, final int expected, final int actual) { + Assertions.assertEquals(expected, actual, message); + } + + public static void assertEquals(final String message, final int[] expected, final int[] actual) { + TestUtils.assertTrue(message, Arrays.equals(expected, actual)); + } + + public static void assertEquals(final String message, final long expected, final long actual) { + Assertions.assertEquals(expected, actual, message); + } + + public static void assertEquals(final String message, final long[] expected, final long[] actual) { + TestUtils.assertTrue(message, Arrays.equals(expected, actual)); + } + public static void assertEquals(final String message, final Object expected, final Object actual) { Assertions.assertEquals(expected, actual, message); diff --git a/test/org/ojalgo/array/SparseTest.java b/test/org/ojalgo/array/SparseTest.java index e13adaf76..3354e22f3 100644 --- a/test/org/ojalgo/array/SparseTest.java +++ b/test/org/ojalgo/array/SparseTest.java @@ -29,29 +29,6 @@ public class SparseTest extends ArrayTests { - @Test - @Tag("slow") - @Tag("unstable") - public void testRandomAccess() { - - long dim = 100_000L; - - SparseArray array = SparseArray.factory(Primitive64Array.FACTORY).make(dim * dim); - - for (long i = 0L; i < dim; i++) { - array.set(Uniform.randomInteger(dim * dim), 1.0); - } - - double sumOfAll = 0D; - for (long i = 0L, limit = array.count(); i < limit; i++) { - sumOfAll += array.doubleValue(i); - } - - // There is of course a chanse the same random index was generated more - // than once (when setting the values). In that case the test will fail. - TestUtils.assertEquals(dim, sumOfAll); - } - @Test public void testAggregateSumDifferentWays() { @@ -81,4 +58,27 @@ public void testAggregateSumDifferentWays() { TestUtils.assertEquals(expected, array2D.aggregateAll(Aggregator.SUM).doubleValue()); } + @Test + @Tag("slow") + @Tag("unstable") + public void testRandomAccess() { + + long dim = 100_000L; + + SparseArray array = SparseArray.factory(Primitive64Array.FACTORY).make(dim * dim); + + for (long i = 0L; i < dim; i++) { + array.set(Uniform.randomInteger(dim * dim), 1.0); + } + + double sumOfAll = 0D; + for (long i = 0L, limit = array.count(); i < limit; i++) { + sumOfAll += array.doubleValue(i); + } + + // There is of course a chanse the same random index was generated more + // than once (when setting the values). In that case the test will fail. + TestUtils.assertEquals(dim, sumOfAll); + } + } diff --git a/test/org/ojalgo/function/multiary/LinearCase.java b/test/org/ojalgo/function/multiary/LinearCase.java index 0ed4a314d..c26380277 100644 --- a/test/org/ojalgo/function/multiary/LinearCase.java +++ b/test/org/ojalgo/function/multiary/LinearCase.java @@ -60,18 +60,6 @@ public void setup() { myArg = Primitive64Store.FACTORY.makeFilled(arity, 1, new Uniform(-1, 2)); } - @Test - public void testInvoke() { - - TestUtils.assertEquals(myLinearFunction1.invoke(myArg), myLinearFunction2.invoke(myArg)); - TestUtils.assertEquals(myAffineFunction1.invoke(myArg), myAffineFunction2.invoke(myArg)); - TestUtils.assertEquals(myQuadraticFunction1.invoke(myArg), myQuadraticFunction2.invoke(myArg)); - - TestUtils.assertEquals(myLinearFunction1.invoke(myArg), myAffineFunction1.invoke(myArg)); - TestUtils.assertEquals(myAffineFunction2.invoke(myArg), myQuadraticFunction2.invoke(myArg)); - TestUtils.assertEquals(myQuadraticFunction1.invoke(myArg), myLinearFunction2.invoke(myArg)); - } - @Test public void testGetGradient() { @@ -108,4 +96,16 @@ public void testGetLinearFactors() { TestUtils.assertEquals(myQuadraticFunction1.getLinearFactors(), myLinearFunction2.getLinearFactors()); } + @Test + public void testInvoke() { + + TestUtils.assertEquals(myLinearFunction1.invoke(myArg), myLinearFunction2.invoke(myArg)); + TestUtils.assertEquals(myAffineFunction1.invoke(myArg), myAffineFunction2.invoke(myArg)); + TestUtils.assertEquals(myQuadraticFunction1.invoke(myArg), myQuadraticFunction2.invoke(myArg)); + + TestUtils.assertEquals(myLinearFunction1.invoke(myArg), myAffineFunction1.invoke(myArg)); + TestUtils.assertEquals(myAffineFunction2.invoke(myArg), myQuadraticFunction2.invoke(myArg)); + TestUtils.assertEquals(myQuadraticFunction1.invoke(myArg), myLinearFunction2.invoke(myArg)); + } + } diff --git a/test/org/ojalgo/function/special/BetaFunctionTest.java b/test/org/ojalgo/function/special/BetaFunctionTest.java index 99e315675..c87205421 100644 --- a/test/org/ojalgo/function/special/BetaFunctionTest.java +++ b/test/org/ojalgo/function/special/BetaFunctionTest.java @@ -72,21 +72,21 @@ public void testIncompleteReducesToTheUsualBetaFunction() { } @Test - public void testRegularizedReducesToTheUsualBetaFunction() { - int lim = 15; + public void testIncompleteZeroIntegral() { + int lim = 50; for (int a = 1; a < lim; a++) { for (int b = 1; b < lim; b++) { - TestUtils.assertEquals("a=" + a + ", b=" + b, ONE, BetaFunction.Regularized.beta(ONE, a, b), StandardType.MATH_032); + TestUtils.assertEquals("a=" + a + ", b=" + b, ZERO, BetaFunction.Incomplete.beta(ZERO, a, b)); } } } @Test - public void testIncompleteZeroIntegral() { - int lim = 50; + public void testRegularizedReducesToTheUsualBetaFunction() { + int lim = 15; for (int a = 1; a < lim; a++) { for (int b = 1; b < lim; b++) { - TestUtils.assertEquals("a=" + a + ", b=" + b, ZERO, BetaFunction.Incomplete.beta(ZERO, a, b)); + TestUtils.assertEquals("a=" + a + ", b=" + b, ONE, BetaFunction.Regularized.beta(ONE, a, b), StandardType.MATH_032); } } } diff --git a/test/org/ojalgo/function/special/PochhammerSymbolTest.java b/test/org/ojalgo/function/special/PochhammerSymbolTest.java index 2024ee432..5ff769ab3 100644 --- a/test/org/ojalgo/function/special/PochhammerSymbolTest.java +++ b/test/org/ojalgo/function/special/PochhammerSymbolTest.java @@ -31,11 +31,11 @@ public class PochhammerSymbolTest { private static final Random RANDOM = new Random(); - private static void compareToGammaImplementation(double x, int n) { + private static void compareToGammaImplementation(final double x, final int n) { TestUtils.assertEquals("x=" + x + ", n=" + n, GammaFunction.gamma(x + n) / GammaFunction.gamma(x), PochhammerSymbol.pochhammer(x, n)); } - static void doTestDefinition(double x) { + static void doTestDefinition(final double x) { PochhammerSymbolTest.compareToGammaImplementation(x, 0); PochhammerSymbolTest.compareToGammaImplementation(x, 1); PochhammerSymbolTest.compareToGammaImplementation(x, 2); @@ -45,7 +45,7 @@ static void doTestDefinition(double x) { PochhammerSymbolTest.compareToGammaImplementation(x, 50); } - static void doTestImplementation(double x) { + static void doTestImplementation(final double x) { TestUtils.assertEquals(1.0, PochhammerSymbol.pochhammer(x, 0)); TestUtils.assertEquals(x, PochhammerSymbol.pochhammer(x, 1)); TestUtils.assertEquals((x * x) + x, PochhammerSymbol.pochhammer(x, 2)); @@ -53,7 +53,7 @@ static void doTestImplementation(double x) { TestUtils.assertEquals((x * x * x * x) + (6.0 * x * x * x) + (11.0 * x * x) + (6 * x), PochhammerSymbol.pochhammer(x, 4)); } - static void performTest(DoubleConsumer testFunction) { + static void performTest(final DoubleConsumer testFunction) { RANDOM.doubles(10, -1.0, 1.0).forEach(testFunction); RANDOM.doubles(10, -2.0, 2.0).forEach(testFunction); RANDOM.doubles(10, -5.0, 5.0).forEach(testFunction); diff --git a/test/org/ojalgo/matrix/BasicMatrixTest.java b/test/org/ojalgo/matrix/BasicMatrixTest.java index 77ba17cea..31afe86ba 100644 --- a/test/org/ojalgo/matrix/BasicMatrixTest.java +++ b/test/org/ojalgo/matrix/BasicMatrixTest.java @@ -98,6 +98,11 @@ public static RationalMatrix getSafe(final long rows, final long columns, final BigDecimal scalar; + @AfterEach + public void doAfterEach() { + // ACCURACY = NumberContext.getGeneral(9); + } + @BeforeEach public void doBeforeEach() { @@ -130,11 +135,6 @@ public void doBeforeEach() { scalar = new BigDecimal(Math.random()); } - @AfterEach - public void doAfterEach() { - // ACCURACY = NumberContext.getGeneral(9); - } - /** * @see BasicMatrix.PhysicalReceiver#add(long, long, Comparable) */ @@ -230,6 +230,60 @@ public void testConjugate() { TestUtils.assertEquals(expected, actual, ACCURACY); } + @Test + public void testCount() { + + long expected = rAA.count(); + long actual; + + actual = cAA.count(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.count(); + TestUtils.assertEquals(expected, actual); + + actual = p32AA.count(); + TestUtils.assertEquals(expected, actual); + } + + /** + * @see org.ojalgo.matrix.BasicMatrix#countColumns() + */ + @Test + public void testCountColumns() { + + long expected = rAA.countColumns(); + long actual; + + actual = cAA.countColumns(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.countColumns(); + TestUtils.assertEquals(expected, actual); + + actual = p32AA.countColumns(); + TestUtils.assertEquals(expected, actual); + } + + /** + * @see org.ojalgo.matrix.BasicMatrix#countRows() + */ + @Test + public void testCountRows() { + + long expected = rAA.countRows(); + long actual; + + actual = cAA.countRows(); + TestUtils.assertEquals(expected, actual); + + actual = p64AA.countRows(); + TestUtils.assertEquals(expected, actual); + + actual = p32AA.countRows(); + TestUtils.assertEquals(expected, actual); + } + @Test public void testDivideElementsBasicMatrix() { @@ -317,25 +371,6 @@ public void testDoubleValueIntInt() { } - /** - * @see org.ojalgo.matrix.BasicMatrix#countColumns() - */ - @Test - public void testCountColumns() { - - long expected = rAA.countColumns(); - long actual; - - actual = cAA.countColumns(); - TestUtils.assertEquals(expected, actual); - - actual = p64AA.countColumns(); - TestUtils.assertEquals(expected, actual); - - actual = p32AA.countColumns(); - TestUtils.assertEquals(expected, actual); - } - @Test public void testGetColumnsIntArray() { @@ -478,25 +513,6 @@ public void testGetRank() { TestUtils.assertEquals(expected, actual); } - /** - * @see org.ojalgo.matrix.BasicMatrix#countRows() - */ - @Test - public void testCountRows() { - - long expected = rAA.countRows(); - long actual; - - actual = cAA.countRows(); - TestUtils.assertEquals(expected, actual); - - actual = p64AA.countRows(); - TestUtils.assertEquals(expected, actual); - - actual = p32AA.countRows(); - TestUtils.assertEquals(expected, actual); - } - @Test public void testGetRowsIntArray() { @@ -773,27 +789,6 @@ public void testMergeRowsBasicMatrix() { TestUtils.assertEquals(expected, actual, ACCURACY); } - /** - * @see org.ojalgo.matrix.BasicMatrix#multiply(org.ojalgo.matrix.BasicMatrix) - */ - @Test - public void testMultiplyMatrix() { - - BasicMatrix actual; - BasicMatrix expected; - - expected = rAA.multiply(rAX); - - actual = cAA.multiply(cAX); - TestUtils.assertEquals(expected, actual, ACCURACY); - - actual = p64AA.multiply(p64AX); - TestUtils.assertEquals(expected, actual, ACCURACY); - - actual = p32AA.multiply(p32AX); - TestUtils.assertEquals(expected, actual, ACCURACY); - } - @Test public void testMultiplyElementsBasicMatrix() { @@ -820,6 +815,27 @@ public void testMultiplyElementsBasicMatrix() { TestUtils.assertEquals(expected, actual, ACCURACY); } + /** + * @see org.ojalgo.matrix.BasicMatrix#multiply(org.ojalgo.matrix.BasicMatrix) + */ + @Test + public void testMultiplyMatrix() { + + BasicMatrix actual; + BasicMatrix expected; + + expected = rAA.multiply(rAX); + + actual = cAA.multiply(cAX); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p64AA.multiply(p64AX); + TestUtils.assertEquals(expected, actual, ACCURACY); + + actual = p32AA.multiply(p32AX); + TestUtils.assertEquals(expected, actual, ACCURACY); + } + /** * @see org.ojalgo.matrix.BasicMatrix#multiply(java.lang.Number) */ @@ -909,22 +925,6 @@ public void testSetElement() { TestUtils.assertEquals(expected, actual, ACCURACY); } - @Test - public void testCount() { - - long expected = rAA.count(); - long actual; - - actual = cAA.count(); - TestUtils.assertEquals(expected, actual); - - actual = p64AA.count(); - TestUtils.assertEquals(expected, actual); - - actual = p32AA.count(); - TestUtils.assertEquals(expected, actual); - } - /** * @see org.ojalgo.matrix.BasicMatrix#solve(org.ojalgo.structure.Access2D) */ diff --git a/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java b/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java index 6103cc781..0431cbdaf 100644 --- a/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java +++ b/test/org/ojalgo/matrix/decomposition/CaseEigenvalue.java @@ -384,7 +384,7 @@ public void testRandomGeneralisedBA() throws RecoverableCondition { cholesky.decompose(mtrxB); MatrixStore compL = cholesky.getL(); - MatrixStore compU = cholesky.getR(); + cholesky.getR(); MatrixStore mtrxC = compL.transpose().multiply(mtrxA).multiply(compL); diff --git a/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java b/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java index 1710e53bc..6a8898c1e 100644 --- a/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java +++ b/test/org/ojalgo/matrix/decomposition/DecompositionProblems.java @@ -169,7 +169,7 @@ public void testGitHubIssue214() { SingularValue tmpSVD = SingularValue.PRIMITIVE.make(tmpOriginal); tmpSVD.decompose(tmpOriginal); Primitive64Store rhs = Primitive64Store.FACTORY.column(observationVector); - MatrixStore solution = tmpSVD.getSolution(rhs, tmpSVD.preallocate(tmpOriginal, rhs)); + tmpSVD.getSolution(rhs, tmpSVD.preallocate(tmpOriginal, rhs)); // Simply test that we can run this program without getting an exception } diff --git a/test/org/ojalgo/netio/TestCSV.java b/test/org/ojalgo/netio/TestCSV.java index 128753258..7dd96a517 100644 --- a/test/org/ojalgo/netio/TestCSV.java +++ b/test/org/ojalgo/netio/TestCSV.java @@ -44,6 +44,38 @@ public TestCSV() { super(); } + @Test + public void testFast() { + + final File tmpFile = new File("./rsrc/csv/fast.csv"); + final EnumeratedColumnsParser tmpParser = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.FAST).get(); + + final AtomicInteger tmpCounter = new AtomicInteger(0); + tmpParser.parse(tmpFile, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + for (int i = 0; i < 5; i++) { + TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); + } + }); + TestUtils.assertEquals(22, tmpCounter.get()); + } + + @Test + public void testQuoted() { + + final File tmpFile = new File("./rsrc/csv/quoted.csv"); + final EnumeratedColumnsParser tmpParser = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.QUOTED).get(); + + final AtomicInteger tmpCounter = new AtomicInteger(0); + tmpParser.parse(tmpFile, t -> { + final int tmpRowIndex = tmpCounter.getAndIncrement(); + for (int i = 0; i < 5; i++) { + TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); + } + }); + TestUtils.assertEquals(22, tmpCounter.get()); + } + @Test public void testRFC4180() { @@ -96,36 +128,4 @@ public void testRFC4180() { TestUtils.assertEquals(6, tmpCounter.get()); } - @Test - public void testFast() { - - final File tmpFile = new File("./rsrc/csv/fast.csv"); - final EnumeratedColumnsParser tmpParser = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.FAST).get(); - - final AtomicInteger tmpCounter = new AtomicInteger(0); - tmpParser.parse(tmpFile, t -> { - final int tmpRowIndex = tmpCounter.getAndIncrement(); - for (int i = 0; i < 5; i++) { - TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); - } - }); - TestUtils.assertEquals(22, tmpCounter.get()); - } - - @Test - public void testQuoted() { - - final File tmpFile = new File("./rsrc/csv/quoted.csv"); - final EnumeratedColumnsParser tmpParser = EnumeratedColumnsParser.make(10).delimiter(',').strategy(EnumeratedColumnsParser.ParseStrategy.QUOTED).get(); - - final AtomicInteger tmpCounter = new AtomicInteger(0); - tmpParser.parse(tmpFile, t -> { - final int tmpRowIndex = tmpCounter.getAndIncrement(); - for (int i = 0; i < 5; i++) { - TestUtils.assertEquals(EXPECTED[tmpRowIndex][i], t.get(i)); - } - }); - TestUtils.assertEquals(22, tmpCounter.get()); - } - } diff --git a/test/org/ojalgo/optimisation/linear/CommonsMathSimplexSolverTest.java b/test/org/ojalgo/optimisation/linear/CommonsMathSimplexSolverTest.java index db26b610d..22692f5ae 100644 --- a/test/org/ojalgo/optimisation/linear/CommonsMathSimplexSolverTest.java +++ b/test/org/ojalgo/optimisation/linear/CommonsMathSimplexSolverTest.java @@ -645,7 +645,7 @@ public static float round(final float x, final int scale) { */ public static float round(final float x, final int scale, final int roundingMethod) { final float sign = Math.copySign(1f, x); - final float factor = (float) PrimitiveMath.POW.invoke(10.0f, scale) * sign; + final float factor = PrimitiveMath.POW.invoke(10.0f, scale) * sign; return (float) Precision.roundUnscaled(x * factor, sign, roundingMethod) / factor; } diff --git a/test/org/ojalgo/optimisation/linear/PrimalDualTest.java b/test/org/ojalgo/optimisation/linear/PrimalDualTest.java index fa270833d..7b6567b20 100644 --- a/test/org/ojalgo/optimisation/linear/PrimalDualTest.java +++ b/test/org/ojalgo/optimisation/linear/PrimalDualTest.java @@ -41,38 +41,31 @@ public PrimalDualTest() { super(); } + /** + * https://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15859-f11/www/notes/lecture05.pdf + */ @Test - public void testP20080117() { - - ExpressionsBasedModel model = ConvexProblems.buildP20080117(); - - this.doEvaluate(model, true); - } - - private void doEvaluate(final ExpressionsBasedModel model, final boolean minimise) { - - Result modResult = minimise ? model.minimise() : model.maximise(); - - ConvexSolver.Builder convex = ConvexSolver.getBuilder(); - ConvexSolver.copy(model, convex); - - Result primResult = PrimalSimplex.solve(convex, model.options); - Result dualResult = DualSimplex.solve(convex, model.options); - - if (DEBUG) { + public void testCaseCMU() { - BasicLogger.debug(modResult); - BasicLogger.debug(primResult); - BasicLogger.debug(dualResult); + ExpressionsBasedModel primModel = new ExpressionsBasedModel(); + Variable x1 = primModel.addVariable("X1").lower(0).weight(2); + Variable x2 = primModel.addVariable("X2").lower(0).weight(3); + primModel.addExpression().set(x1, 4).set(x2, 8).upper(12); + primModel.addExpression().set(x1, 2).set(x2, 1).upper(3); + primModel.addExpression().set(x1, 3).set(x2, 2).upper(4); - BasicLogger.debug(primResult.getMultipliers().get()); - BasicLogger.debug(dualResult.getMultipliers().get()); - } + ExpressionsBasedModel dualModel = new ExpressionsBasedModel(); + Variable y1 = dualModel.addVariable("Y1").lower(0).weight(12); + Variable y2 = dualModel.addVariable("Y2").lower(0).weight(3); + Variable y3 = dualModel.addVariable("Y3").lower(0).weight(4); + dualModel.addExpression().set(y1, 4).set(y2, 2).set(y3, 3).lower(2); + dualModel.addExpression().set(y1, 8).set(y2, 1).set(y3, 2).lower(3); - TestUtils.assertStateAndSolution(modResult, primResult); - TestUtils.assertStateAndSolution(modResult, dualResult); + double optimalValue = 4.75; + DenseArray optimalX = Primitive64Array.FACTORY.copy(new double[] { 0.5, 1.25 }); + DenseArray optimalY = Primitive64Array.FACTORY.copy(new double[] { 5.0 / 16.0, 0.0, 0.25 }); - TestUtils.assertEquals(primResult.getMultipliers().get(), dualResult.getMultipliers().get()); + this.doCompare(primModel, dualModel, optimalValue, optimalX, optimalY); } /** @@ -102,33 +95,6 @@ public void testCaseLIU() { this.doCompare(primModel, dualModel, optimalValue, optimalX, optimalY); } - /** - * https://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15859-f11/www/notes/lecture05.pdf - */ - @Test - public void testCaseCMU() { - - ExpressionsBasedModel primModel = new ExpressionsBasedModel(); - Variable x1 = primModel.addVariable("X1").lower(0).weight(2); - Variable x2 = primModel.addVariable("X2").lower(0).weight(3); - primModel.addExpression().set(x1, 4).set(x2, 8).upper(12); - primModel.addExpression().set(x1, 2).set(x2, 1).upper(3); - primModel.addExpression().set(x1, 3).set(x2, 2).upper(4); - - ExpressionsBasedModel dualModel = new ExpressionsBasedModel(); - Variable y1 = dualModel.addVariable("Y1").lower(0).weight(12); - Variable y2 = dualModel.addVariable("Y2").lower(0).weight(3); - Variable y3 = dualModel.addVariable("Y3").lower(0).weight(4); - dualModel.addExpression().set(y1, 4).set(y2, 2).set(y3, 3).lower(2); - dualModel.addExpression().set(y1, 8).set(y2, 1).set(y3, 2).lower(3); - - double optimalValue = 4.75; - DenseArray optimalX = Primitive64Array.FACTORY.copy(new double[] { 0.5, 1.25 }); - DenseArray optimalY = Primitive64Array.FACTORY.copy(new double[] { 5.0 / 16.0, 0.0, 0.25 }); - - this.doCompare(primModel, dualModel, optimalValue, optimalX, optimalY); - } - /** * http://web.mit.edu/15.053/www/AMP-Chapter-04.pdf */ @@ -156,6 +122,14 @@ public void testCaseMIT() { this.doCompare(primModel, dualModel, optimalValue, optimalX, optimalY); } + @Test + public void testP20080117() { + + ExpressionsBasedModel model = ConvexProblems.buildP20080117(); + + this.doEvaluate(model, true); + } + @Test public void testWikipediaExample() { @@ -244,4 +218,30 @@ private void doCompare(final ExpressionsBasedModel primModel, final ExpressionsB TestUtils.assertEquals(dualModelPrimSolver.getMultipliers().get(), dualModelDualSolver.getMultipliers().get()); } + private void doEvaluate(final ExpressionsBasedModel model, final boolean minimise) { + + Result modResult = minimise ? model.minimise() : model.maximise(); + + ConvexSolver.Builder convex = ConvexSolver.getBuilder(); + ConvexSolver.copy(model, convex); + + Result primResult = PrimalSimplex.solve(convex, model.options); + Result dualResult = DualSimplex.solve(convex, model.options); + + if (DEBUG) { + + BasicLogger.debug(modResult); + BasicLogger.debug(primResult); + BasicLogger.debug(dualResult); + + BasicLogger.debug(primResult.getMultipliers().get()); + BasicLogger.debug(dualResult.getMultipliers().get()); + } + + TestUtils.assertStateAndSolution(modResult, primResult); + TestUtils.assertStateAndSolution(modResult, dualResult); + + TestUtils.assertEquals(primResult.getMultipliers().get(), dualResult.getMultipliers().get()); + } + } diff --git a/test/org/ojalgo/random/TDistributionTest.java b/test/org/ojalgo/random/TDistributionTest.java index 39558df31..4d161569f 100644 --- a/test/org/ojalgo/random/TDistributionTest.java +++ b/test/org/ojalgo/random/TDistributionTest.java @@ -41,8 +41,8 @@ public void testAgainstSpecificVariants() { TDistribution s4 = new TDistribution.Degree4(); TDistribution g4 = new TDistribution(4); - TDistribution sInf = new TDistribution.DegreeInfinity(); - TDistribution gInf = new TDistribution(Integer.MAX_VALUE); + new TDistribution.DegreeInfinity(); + new TDistribution(Integer.MAX_VALUE); for (int x = -5; x <= 5; x++) { From 9270c2f57e55eb812aa68c8a2cab482a127d710a Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 24 Nov 2019 16:53:47 +0100 Subject: [PATCH 28/29] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2927c3775..f46a78e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ Added / Changed / Deprecated / Removed / Fixed / Security > Corresponds to changes in the `develop` branch since the last release + +## [48.0.0] – 2019-11-24 + ### Added - Improved support for float throughout the library, and specifically added matrices with float elements. From 805d259faabd3dcb1ea8c97da9a80b6ce38da9fe Mon Sep 17 00:00:00 2001 From: apete Date: Sun, 24 Nov 2019 17:08:02 +0100 Subject: [PATCH 29/29] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 91e16ebe9..12ff91364 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.ojalgo ojalgo - 48.0.0-SNAPSHOT + 48.0.0 jar ojAlgo http://ojalgo.org