Tagged 2.0-RC4
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/tags/MATH_2_0_RC4@800116 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/experimental/org/apache/commons/math/analysis/DerivativeOperatorFactory.java b/src/experimental/org/apache/commons/math/analysis/DerivativeOperatorFactory.java
deleted file mode 100644
index 98006d0..0000000
--- a/src/experimental/org/apache/commons/math/analysis/DerivativeOperatorFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-public class DerivativeOperatorFactory {
-
- public static DerivativeOperatorFactory newInstance() {
- return null;
- }
-
- public FunctionOperator getDefaultDerivativeOperator() {
- return null;
- }
-
- public FunctionOperator getCenteredDifferenceDerivativeOperator(){
- return null;
- }
-
- // and so on for other implementations of numerical deriv's
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/DerivativeOperatorFactoryTest.java b/src/experimental/org/apache/commons/math/analysis/DerivativeOperatorFactoryTest.java
deleted file mode 100644
index f24d9f2..0000000
--- a/src/experimental/org/apache/commons/math/analysis/DerivativeOperatorFactoryTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import junit.framework.TestCase;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class DerivativeOperatorFactoryTest extends TestCase {
-
- /**
- * Constructor for DerivativeOperatorFactoryTest.
- * @param arg0
- */
- public DerivativeOperatorFactoryTest(String arg0) {
- super(arg0);
- }
-
- //UnivariateRealFunction f = new SomeUserDefinedFunction();
- //FunctionOperator derivative =
- // DerivativeOperatorFactory.newInstance().getDefaultDerivativeOperator();
-
- //UnivariateRealFunction g = derivative.evaluate( f );
-
- // to obtain the value of f'(0.0) use
- //double fprime_at_0 = g.value( 0.0 );
-
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/FunctionOperator.java b/src/experimental/org/apache/commons/math/analysis/FunctionOperator.java
deleted file mode 100644
index 2731d85..0000000
--- a/src/experimental/org/apache/commons/math/analysis/FunctionOperator.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-
-public interface FunctionOperator {
-
-
- /**
- * Evaluate the Function Operator for a given real single variable function.
- *
- * @param f the function which should be evaluated
- * @return the resultant function
- * @throws MathException if the function couldn't be evaluated
- */
- public UnivariateRealFunction evaluate(UnivariateRealFunction f) throws MathException;
-
-}
\ No newline at end of file
diff --git a/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionProxy.java b/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionProxy.java
deleted file mode 100644
index 9a14fe7..0000000
--- a/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionProxy.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public abstract class UnivariateRealFunctionProxy
- implements UnivariateRealFunction {
-
- private UnivariateRealFunction function;
-
- /**
- * @todo add javadoc comment
- */
- public UnivariateRealFunctionProxy(UnivariateRealFunction function) {
- super();
- setFunction(function);
- }
-
- /**
- * @todo add javadoc comment
- */
- protected UnivariateRealFunction getFunction() {
- return function;
- }
-
- /**
- * @todo add javadoc comment
- */
- private void setFunction(UnivariateRealFunction function) {
- this.function = function;
- }
-
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionUtils.java b/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionUtils.java
deleted file mode 100644
index 68951c5..0000000
--- a/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionUtils.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.analysis.derivative.BackwardDifferenceDerivative;
-import org.apache.commons.math.analysis.derivative.CenterDifferenceDerivative;
-import org.apache.commons.math.analysis.derivative.ForwardDifferenceDerivative;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public class UnivariateRealFunctionUtils {
-
- /**
- * @todo add javadoc comment
- */
- private UnivariateRealFunctionUtils() {
- super();
- }
-
- public static UnivariateRealFunction backwardDifferenceDerivative(UnivariateRealFunction function, double delta) {
- return BackwardDifferenceDerivative.decorate(function, delta);
- }
-
- public static UnivariateRealFunction centerDifferenceDerivative(UnivariateRealFunction function, double delta) {
- return CenterDifferenceDerivative.decorate(function, delta);
- }
-
- public static UnivariateRealFunction forwardDifferenceDerivative(UnivariateRealFunction function, double delta) {
- return ForwardDifferenceDerivative.decorate(function, delta);
- }
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionUtilsTest.java b/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionUtilsTest.java
deleted file mode 100644
index 4f966cf..0000000
--- a/src/experimental/org/apache/commons/math/analysis/UnivariateRealFunctionUtilsTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis;
-
-import junit.framework.TestCase;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public class UnivariateRealFunctionUtilsTest extends TestCase {
- /**
- *
- */
- public void testLocalMaximumCentered() {
- UnivariateRealFunction function = new SinFunction();
- UnivariateRealFunction derivative = UnivariateRealFunctionUtils.centerDifferenceDerivative(function, 1.0e-5);
- testLocalMaximum(derivative);
- }
-
- /**
- *
- */
- public void testLocalMaximumForward() {
- UnivariateRealFunction function = new SinFunction();
- UnivariateRealFunction derivative = UnivariateRealFunctionUtils.forwardDifferenceDerivative(function, 1.0e-5);
- testLocalMaximum(derivative);
- }
-
- /**
- *
- */
- public void testLocalMaximumBackward() {
- UnivariateRealFunction function = new SinFunction();
- UnivariateRealFunction derivative = UnivariateRealFunctionUtils.backwardDifferenceDerivative(function, 1.0e-5);
- testLocalMaximum(derivative);
- }
-
- /**
- * Find a local extrema, i.e. f'(x) = 0.
- */
- private void testLocalMaximum(UnivariateRealFunction derivative) {
- try {
- double maximum = UnivariateRealSolverUtils.solve(derivative, Math.PI / 3.0, Math.PI * 2.0 / 3.0);
- assertEquals(maximum, Math.PI / 2.0, 1.0e-5);
- } catch (Exception ex) {
- fail(ex.getMessage());
- }
- }
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/derivative/AbstractDifferenceDerivative.java b/src/experimental/org/apache/commons/math/analysis/derivative/AbstractDifferenceDerivative.java
deleted file mode 100644
index 55e9a3f..0000000
--- a/src/experimental/org/apache/commons/math/analysis/derivative/AbstractDifferenceDerivative.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis.derivative;
-
-import org.apache.commons.math.analysis.UnivariateRealFunction;
-import org.apache.commons.math.analysis.UnivariateRealFunctionProxy;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public abstract class AbstractDifferenceDerivative extends UnivariateRealFunctionProxy implements UnivariateRealFunction {
- /** */
- private double delta;
-
- /**
- * @todo add javadoc comment
- */
- public AbstractDifferenceDerivative(UnivariateRealFunction function, double h) {
- super(function);
- setDelta(h);
- }
-
- private void setDelta(double h) {
- this.delta = h;
- }
-
- protected double getDelta() {
- return delta;
- }
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/derivative/BackwardDifferenceDerivative.java b/src/experimental/org/apache/commons/math/analysis/derivative/BackwardDifferenceDerivative.java
deleted file mode 100644
index 8a63cc4..0000000
--- a/src/experimental/org/apache/commons/math/analysis/derivative/BackwardDifferenceDerivative.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis.derivative;
-
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.analysis.UnivariateRealFunction;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public class BackwardDifferenceDerivative extends AbstractDifferenceDerivative {
-
- /**
- * @todo add javadoc comment
- */
- public BackwardDifferenceDerivative(UnivariateRealFunction function, double h) {
- super(function, h);
- }
-
- /**
- * @todo add javadoc comment
- */
- public double value(double x) throws MathException {
- UnivariateRealFunction f = getFunction();
- double h = getDelta();
- return (f.value(x) - f.value(x - h)) / h;
- }
-
- /**
- *
- */
- public static UnivariateRealFunction decorate(UnivariateRealFunction function, double h) {
- return new BackwardDifferenceDerivative(function, h);
- }
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/derivative/CenterDifferenceDerivative.java b/src/experimental/org/apache/commons/math/analysis/derivative/CenterDifferenceDerivative.java
deleted file mode 100644
index 747e189..0000000
--- a/src/experimental/org/apache/commons/math/analysis/derivative/CenterDifferenceDerivative.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis.derivative;
-
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.analysis.UnivariateRealFunction;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public class CenterDifferenceDerivative extends AbstractDifferenceDerivative {
-
- /**
- * @todo add javadoc comment
- */
- public CenterDifferenceDerivative(UnivariateRealFunction function, double h) {
- super(function, h);
- }
-
- /**
- * @todo add javadoc comment
- */
- public double value(double x) throws MathException {
- UnivariateRealFunction f = getFunction();
- double h2 = getDelta();
- double h = h2 * .5;
- return (f.value(x + h) - f.value(x - h)) / h2;
- }
-
- /**
- *
- */
- public static UnivariateRealFunction decorate(UnivariateRealFunction function, double h) {
- return new CenterDifferenceDerivative(function, h);
- }
-}
diff --git a/src/experimental/org/apache/commons/math/analysis/derivative/ForwardDifferenceDerivative.java b/src/experimental/org/apache/commons/math/analysis/derivative/ForwardDifferenceDerivative.java
deleted file mode 100644
index 511b265..0000000
--- a/src/experimental/org/apache/commons/math/analysis/derivative/ForwardDifferenceDerivative.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.analysis.derivative;
-
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.analysis.UnivariateRealFunction;
-
-/**
- * @todo add javadoc comment
- * @version $Revision$ $Date$
- */
-public class ForwardDifferenceDerivative extends AbstractDifferenceDerivative {
-
- /**
- * @todo add javadoc comment
- */
- public ForwardDifferenceDerivative(UnivariateRealFunction function, double h) {
- super(function, h);
- }
-
- /**
- * @todo add javadoc comment
- */
- public double value(double x) throws MathException {
- UnivariateRealFunction f = getFunction();
- double h = getDelta();
- return (f.value(x + h) - f.value(x)) / h;
- }
-
- /**
- *
- */
- public static UnivariateRealFunction decorate(UnivariateRealFunction function, double h) {
- return new ForwardDifferenceDerivative(function, h);
- }
-}
diff --git a/src/experimental/org/apache/commons/math/function/Compilable.java b/src/experimental/org/apache/commons/math/function/Compilable.java
deleted file mode 100644
index b7b6a30..0000000
--- a/src/experimental/org/apache/commons/math/function/Compilable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public interface Compilable {
-
- public abstract Evaluation compile(EvaluationContext context)
- throws EvaluationException;
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/DefaultContext.java b/src/experimental/org/apache/commons/math/function/DefaultContext.java
deleted file mode 100644
index 0d9efed..0000000
--- a/src/experimental/org/apache/commons/math/function/DefaultContext.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class DefaultContext implements EvaluationContext {
-
- /**
- *
- */
- public DefaultContext() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#doubleValue(org.apache.archimedes.Evaluation)
- */
- public double doubleValue(Evaluation argument) throws EvaluationException {
- // TODO Auto-generated method stub
- return ((DefaultValue)argument.evaluate(this)).doubleValue();
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#floatValue(org.apache.archimedes.Evaluation)
- */
- public float floatValue(Evaluation argument) throws EvaluationException {
- // TODO Auto-generated method stub
- return ((DefaultValue)argument.evaluate(this)).floatValue();
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#intValue(org.apache.archimedes.Evaluation)
- */
- public int intValue(Evaluation argument) throws EvaluationException {
- // TODO Auto-generated method stub
- return ((DefaultValue)argument.evaluate(this)).intValue();
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#longValue(org.apache.archimedes.Evaluation)
- */
- public long longValue(Evaluation argument) throws EvaluationException {
- // TODO Auto-generated method stub
- return ((DefaultValue)argument.evaluate(this)).longValue();
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#shortValue(org.apache.archimedes.Evaluation)
- */
- public short shortValue(Evaluation argument) throws EvaluationException {
- // TODO Auto-generated method stub
- return ((DefaultValue)argument.evaluate(this)).shortValue();
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#byteValue(org.apache.archimedes.Evaluation)
- */
- public byte byteValue(Evaluation argument) throws EvaluationException {
- // TODO Auto-generated method stub
- return ((DefaultValue)argument.evaluate(this)).byteValue();
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#evaluate(double)
- */
- public Evaluation evaluate(double d) {
- // TODO Auto-generated method stub
- return new DefaultValue(d);
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#evaluate(float)
- */
- public Evaluation evaluate(float f) {
- // TODO Auto-generated method stub
- return new DefaultValue(f);
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#evaluate(int)
- */
- public Evaluation evaluate(int i) {
- // TODO Auto-generated method stub
- return new DefaultValue(i);
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#evaluate(long)
- */
- public Evaluation evaluate(long l) {
- // TODO Auto-generated method stub
- return new DefaultValue(l);
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#evaluate(short)
- */
- public Evaluation evaluate(short s) {
- // TODO Auto-generated method stub
- return new DefaultValue(s);
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.EvaluationContext#evaluate(byte)
- */
- public Evaluation evaluate(byte b) {
- // TODO Auto-generated method stub
- return new DefaultValue(b);
- }
-
- public class DefaultValue extends Number implements Evaluation {
-
- Number value;
-
- /**
- *
- */
- DefaultValue() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- DefaultValue(Number n) {
- value = n;
- }
-
- DefaultValue(double d) {
- value = Double.valueOf(d);
- }
-
- DefaultValue(float f) {
- value = Float.valueOf(f);
- }
-
- DefaultValue(int i) {
- value = Integer.valueOf(i);
- }
-
- DefaultValue(long l) {
- value = Long.valueOf(l);
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.Evaluation#evaluate(org.apache.archimedes.EvaluationContext)
- */
- public Evaluation evaluate(EvaluationContext context)
- throws EvaluationException {
- return this;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Number#intValue()
- */
- public int intValue() {
- // TODO Auto-generated method stub
- return value.intValue();
- }
-
- /* (non-Javadoc)
- * @see java.lang.Number#longValue()
- */
- public long longValue() {
- // TODO Auto-generated method stub
- return value.longValue();
- }
-
- /* (non-Javadoc)
- * @see java.lang.Number#floatValue()
- */
- public float floatValue() {
- // TODO Auto-generated method stub
- return value.floatValue();
- }
-
- /* (non-Javadoc)
- * @see java.lang.Number#doubleValue()
- */
- public double doubleValue() {
- // TODO Auto-generated method stub
- return value.doubleValue();
- }
-
- /* (non-Javadoc)
- * @see java.lang.Number#byteValue()
- */
- public byte byteValue() {
- // TODO Auto-generated method stub
- return value.byteValue();
- }
-
- /* (non-Javadoc)
- * @see java.lang.Number#shortValue()
- */
- public short shortValue() {
- // TODO Auto-generated method stub
- return value.shortValue();
- }
-
- }
-}
diff --git a/src/experimental/org/apache/commons/math/function/Evaluation.java b/src/experimental/org/apache/commons/math/function/Evaluation.java
deleted file mode 100644
index e29e99a..0000000
--- a/src/experimental/org/apache/commons/math/function/Evaluation.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public interface Evaluation {
-
- public abstract Evaluation evaluate(EvaluationContext context)
- throws EvaluationException;
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/EvaluationContext.java b/src/experimental/org/apache/commons/math/function/EvaluationContext.java
deleted file mode 100644
index bf538f4..0000000
--- a/src/experimental/org/apache/commons/math/function/EvaluationContext.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public interface EvaluationContext {
-
- public abstract double doubleValue(Evaluation argument) throws EvaluationException ;
-
- public abstract float floatValue(Evaluation argument) throws EvaluationException ;
-
- public abstract int intValue(Evaluation argument) throws EvaluationException ;
-
- public abstract long longValue(Evaluation argument) throws EvaluationException ;
-
- public abstract short shortValue(Evaluation argument) throws EvaluationException ;
-
- public abstract byte byteValue(Evaluation argument) throws EvaluationException ;
-
- public abstract Evaluation evaluate(double d);
-
- public abstract Evaluation evaluate(float f);
-
- public abstract Evaluation evaluate(int i);
-
- public abstract Evaluation evaluate(long l);
-
- public abstract Evaluation evaluate(short s);
-
- public abstract Evaluation evaluate(byte b);
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/EvaluationException.java b/src/experimental/org/apache/commons/math/function/EvaluationException.java
deleted file mode 100644
index 2191743..0000000
--- a/src/experimental/org/apache/commons/math/function/EvaluationException.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function;
-
-import org.apache.commons.math.MathException;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class EvaluationException extends MathException {
-
- /**
- *
- */
- public EvaluationException() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- */
- public EvaluationException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
- */
- public EvaluationException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param cause
- */
- public EvaluationException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/Variable.java b/src/experimental/org/apache/commons/math/function/Variable.java
deleted file mode 100644
index c7cc147..0000000
--- a/src/experimental/org/apache/commons/math/function/Variable.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function;
-
-import java.io.Serializable;
-
-/**
-
-
- */
-public class Variable implements Evaluation, Serializable {
-
- public Evaluation evaluate(EvaluationContext context)
- throws EvaluationException {
- return null;
-
- //context.evaluate(value.doubleValue());
- }
-
- public String toString() {
- return "Variable";
- }
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Add.java b/src/experimental/org/apache/commons/math/function/simple/Add.java
deleted file mode 100644
index 190b96c..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Add.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.Compilable;
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationContext;
-import org.apache.commons.math.function.EvaluationException;
-
-/**
-
-
- */
-public class Add implements Evaluation, Serializable {
-
- private Evaluation left;
-
- private Evaluation right;
-
- public void setLeftOperand(Evaluation left) {
- this.left = left;
- }
-
- public void setRightOperand(Evaluation right) {
- this.right = right;
- }
-
- public Evaluation evaluate(EvaluationContext context) throws EvaluationException {
- return context.evaluate(
- context.doubleValue(left) + context.doubleValue(right)
- );
- }
-
-
- public String toString() {
- return "Add";
- }
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Divide.java b/src/experimental/org/apache/commons/math/function/simple/Divide.java
deleted file mode 100644
index 68ea929..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Divide.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.EvaluationContext;
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationException;
-
-/**
-
-
- */
-public class Divide implements Evaluation, Serializable {
-
- private Evaluation left;
-
- private Evaluation right;
-
- public void setLeftOperand(Evaluation left) {
- this.left = left;
- }
-
- public void setRightOperand(Evaluation right) {
- this.right = right;
- }
-
- public Evaluation evaluate(EvaluationContext context) throws EvaluationException {
- return context.evaluate(
- context.doubleValue(left) / context.doubleValue(right)
- );
- }
-
- public String toString() {
- return "Divide";
- }
-
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Equals.java b/src/experimental/org/apache/commons/math/function/simple/Equals.java
deleted file mode 100644
index fa12321..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Equals.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationContext;
-
-
-/**
-
-
- */
-public class Equals implements Evaluation, Serializable {
-
- private Evaluation left;
-
- private Evaluation right;
-
- public void setLeftOperand(Evaluation left) {
- this.left = left;
- }
-
- public void setRightOperand(Evaluation right) {
- this.right = right;
- }
-
- public Evaluation evaluate(EvaluationContext context) {
-
- return null;
- }
-
- public String toString() {
- return "Equals";
- }
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Multiply.java b/src/experimental/org/apache/commons/math/function/simple/Multiply.java
deleted file mode 100644
index 96343cb..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Multiply.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.EvaluationContext;
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationException;
-
-/**
-
-
- */
-public class Multiply implements Evaluation, Serializable {
-
- private Evaluation left;
-
- private Evaluation right;
-
- public void setLeftOperand(Evaluation left) {
- this.left = left;
- }
-
- public void setRightOperand(Evaluation right) {
- this.right = right;
- }
-
- public Evaluation evaluate(EvaluationContext context) throws EvaluationException {
- return context.evaluate(
- context.doubleValue(left) * context.doubleValue(right)
- );
- }
-
- public String toString() {
- return "Multiply";
- }
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Power.java b/src/experimental/org/apache/commons/math/function/simple/Power.java
deleted file mode 100644
index 8ee89ae..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Power.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationContext;
-import org.apache.commons.math.function.EvaluationException;
-
-
-/**
-
-
- */
-public class Power implements Evaluation, Serializable {
-
- private Evaluation argument;
-
- private Evaluation power;
-
- public void setOperand(Evaluation argument) {
- this.argument = argument;
- }
-
- public void setPower(Evaluation power) {
- this.power = power;
- }
-
- public Evaluation evaluate(EvaluationContext context) throws EvaluationException {
- return context.evaluate(
- Math.pow(
- context.doubleValue(argument),
- context.doubleValue(power)
- )
- );
- }
-
- public String toString() {
- return "Power";
- }
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Sqrt.java b/src/experimental/org/apache/commons/math/function/simple/Sqrt.java
deleted file mode 100644
index 25ea585..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Sqrt.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationContext;
-import org.apache.commons.math.function.EvaluationException;
-
-
-/**
-
-
- */
-public class Sqrt implements Evaluation, Serializable {
-
- private Evaluation argument;
-
- public void setOperand(Evaluation argument) {
- this.argument = argument;
- }
-
- /* (non-Javadoc)
- * @see org.apache.archimedes.NumericFunction#evaluate(org.apache.archimedes.EvaluationContext)
- */
- public Evaluation evaluate(EvaluationContext context) throws EvaluationException {
- return context.evaluate(
- Math.sqrt(context.doubleValue(argument)));
-
- }
-
- public String toString() {
- return "Square Root";
- }
-
-}
diff --git a/src/experimental/org/apache/commons/math/function/simple/Subtract.java b/src/experimental/org/apache/commons/math/function/simple/Subtract.java
deleted file mode 100644
index 0cc9e83..0000000
--- a/src/experimental/org/apache/commons/math/function/simple/Subtract.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.function.simple;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.function.EvaluationContext;
-import org.apache.commons.math.function.Evaluation;
-import org.apache.commons.math.function.EvaluationException;
-
-/**
-
-
- */
-public class Subtract implements Evaluation, Serializable {
-
- private Evaluation left;
-
- private Evaluation right;
-
- public void setLeftOperand(Evaluation left) {
- this.left = left;
- }
-
- public void setRightOperand(Evaluation right) {
- this.right = right;
- }
-
- public Evaluation evaluate(EvaluationContext context) throws EvaluationException {
- return context.evaluate(
- context.doubleValue(left) - context.doubleValue(right)
- );
- }
-
- public String toString() {
- return "Subtract";
- }
-}
diff --git a/src/experimental/org/apache/commons/math/linear/CholeskySolver.java b/src/experimental/org/apache/commons/math/linear/CholeskySolver.java
deleted file mode 100644
index 508b77b..0000000
--- a/src/experimental/org/apache/commons/math/linear/CholeskySolver.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.linear;
-
-
-/**
- * Solves a linear equitation with symmetrical, positiv definit
- * coefficient matrix by Cholesky decomposition.
- * <p>
- * For every symmetric, positiv definit matrix <code>M</code> there is a
- * lower triangular matrix <code>L</code> so that <code>L*L^T=M</code>.
- * <code>L</code> is called the <i>Cholesky decomposition</i> of <code>M</code>.
- * For any constant vector <code>c</code> it can be used to solve
- * the linear equitation <code>M*x=L*(L^T*x)=c</code>.<br>
- * Compared to the LU-decompoistion the Cholesky methods requires only half
- * the number of operations.
- * <p>
- * @author Stefan Koeberle, 11/2003
- */
-public class CholeskySolver {
-
- private double numericalZero = 10E-12;
-
- /** The lower triangular matrix */
- private Array2DRowRealMatrix decompMatrix;
-
-
- /**
- * Creates a new instance of CholeskySolver
- */
- public CholeskySolver() {
- }//constructor CholeskySolver
-
-
- /**
- * Every double <code>d</code> satisfying
- * <code>java.lang.Math.abs(d) <= numericalZero</code>
- * is considered equal to <code>0.0d.</code>
- */
- public void setNumericalZero(double numericalZero) {
- this.numericalZero = numericalZero;
- }//setNumericalZero
-
- /**
- * See <code>setNumericalZero</code>
- */
- public double getNumericalZero() {
- return numericalZero;
- }//getNumericalZero
-
-
- /**
- * Calculates the Cholesky-decomposition of the symmetrical, positiv definit
- * matrix <code>M</code>.
- * <p>
- * The decomposition matrix is internally stored.
- * <p>
- * @throws IllegalArgumentException if <code>M</code> ist not square or
- * not positiv definit
- */
- public void decompose(RealMatrix m)
- throws IllegalArgumentException {
-
- decompMatrix = null;
- double[][] mval = m.getData();
- int numRows = m.getRowDimension();
- int numCols = m.getColumnDimension();
- if (numRows != numCols)
- throw new IllegalArgumentException("matrix is not square");
- double[][] decomp = new double[numRows][numCols];
- double sum;
-
- //for all columns
- for (int col=0; col<numCols; col++) {
-
- //diagonal element
- sum = mval[col][col];
- for (int k=0; k<col; k++)
- sum = sum - decomp[col][k]*decomp[col][k];
- if (sum <= numericalZero) {
- throw new IllegalArgumentException(
- "Matrix is not positiv definit");
- }
- decomp[col][col] += Math.sqrt(sum);
-
- //column below diagonal
- for (int row=col+1; row<numRows; row++) {
- sum = mval[row][col];
- for (int k=0; k<col; k++)
- sum = sum - decomp[col][k]*decomp[row][k];
- decomp[row][col] = sum/decomp[col][col];
- }//for
-
- }//for all columns
-
- decompMatrix = new Array2DRowRealMatrix(decomp);
-
- }//decompose
-
-
- /**
- * Returns the last calculated decomposition matrix.
- * <p>
- * Caution: Every call of this Method will return the same object.
- * Decomposing another matrix will generate a new one.
- */
- public Array2DRowRealMatrix getDecomposition() {
- return decompMatrix;
- }//getDecomposition
-
-
- /**
- * Returns the solution for a linear system with constant vector <code>c</code>.
- * <p>
- * This method solves a linear system <code>M*x=c</code> for a symmetrical,
- * positiv definit coefficient matrix <code>M</code>. Before using this
- * method the matrix <code>M</code> must have been decomposed.
- * <p>
- * @throws IllegalStateException if this methode is called before
- * a matrix was decomposed
- * @throws IllegalArgumentException if the dimension of <code>c</code> doesn't
- * match the row dimension of <code>M</code>
- */
- public double[] solve(double[] c)
- throws IllegalStateException, IllegalArgumentException {
-
- if (decompMatrix == null) {
- throw new IllegalStateException("no decomposed matrix available");
- }//if
- if (decompMatrix.getColumnDimension() != c.length)
- throw new IllegalArgumentException("matrix dimension mismatch");
-
- double[][] decomp = decompMatrix.getData();
- double[] x = new double[decomp.length];
- double sum;
-
- //forward elimination
- for (int i=0; i<x.length; i++) {
- sum = c[i];
- for (int k=0; k<i; k++)
- sum = sum - decomp[i][k]*x[k];
- x[i] = sum / decomp[i][i];
- }//forward elimination
-
- //backward elimination
- for (int i=x.length-1; i>=0; i--) {
- sum = x[i];
- for (int k=i+1; k<x.length; k++)
- sum = sum - decomp[k][i]*x[k];
- x[i] = sum / decomp[i][i];
- }//backward elimination
-
- return x;
- }//solve
-
-
- /**
- * Returns the solution for a linear system with a symmetrical,
- * positiv definit coefficient matrix <code>M</code> and
- * constant vector <code>c</code>.
- * <p>
- * As a side effect, the Cholesky-decomposition <code>L*L^T=M</code> is
- * calculated and internally stored.
- * <p>
- * This is a convenience method for <code><pre>
- * solver.decompose(m);
- * solver.solve(c);
- * </pre></code>
- * @throws IllegalArgumentException if M ist not square, not positive definit
- * or the dimensions of <code>M</code> and
- * <code>c</code> don't match.
- */
- public double[] solve(RealMatrix m, double[] c)
- throws IllegalArgumentException {
- decompose(m);
- return solve(c);
- }//solve
-
-
- /**
- * Returns the determinant of the a matrix <code>M</code>.
- * <p>
- * Before using this method the matrix <code>M</code> must
- * have been decomposed.
- * <p>
- * @throws IllegalStateException if this method is called before
- * a matrix was decomposed
- */
- public double getDeterminant() {
-
- if (decompMatrix == null) {
- throw new IllegalStateException("no decomposed matrix available");
- }//if
-
- double[][] data = decompMatrix.getData();
- double res = 1.0d;
- for (int i=0; i<data.length; i++) {
- res *= data[i][i];
- }//for
- res = res*res;
-
- return res;
- }//getDeterminant
-
-}//class CholeskySolver
diff --git a/src/experimental/org/apache/commons/math/linear/CholeskySolverTest.java b/src/experimental/org/apache/commons/math/linear/CholeskySolverTest.java
deleted file mode 100644
index e8bb42a..0000000
--- a/src/experimental/org/apache/commons/math/linear/CholeskySolverTest.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.linear;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * Test cases for the {@link CholeskySolver} class.
- * <p>
- * @author Stefan Koeberle, 11/2003
- */
-public class CholeskySolverTest
-extends TestCase {
-
- private double[][] m1 = {{1}};
- private double m1Det = 1.0d;
-
- private double[][] m2 = {{1, 0} ,
- {0, 2}};
- private double m2Det = 2.0d;
-
- private double[][] m3 = {{1, 0, 0},
- {0, 2, 0},
- {0, 0, 3}};
- private double m3Det = 6.0d;
-
- private double[][] m4 = {{1, 0, 0},
- {2, 3, 0},
- {4, 5, 6}};
- private double m4Det = 18.0d;
-
- private double[][] m5 = {{ 1, 0, 0, 0, 0},
- {-2, 3, 0, 0, 0},
- { 4, -5, 6, 0, 0},
- { 7, 8, -9, 10, 0},
- {11, 12, 13, 14, 15}};
- private double m5Det = 2700.0d;
-
-
- private double[][] m6 = {{1, 0, 0},
- {2, 0, 0},
- {4, 5, 6}};
-
- private double[][] m7 = {{1, 2, 3},
- {4, 5, 6}};
-
- /**
- * Creates a new instance of CholeskySolverTest
- */
- public CholeskySolverTest(String nameOfTest) {
- super(nameOfTest);
- }//constructor CholeskySolverTest
-
- public void setUp()
- throws java.lang.Exception {
- super.setUp();
- }//setUp
-
-
- public void tearDown()
- throws java.lang.Exception {
- super.tearDown();
- }//tearDown
-
- public static Test suite() {
- TestSuite suite = new TestSuite(CholeskySolverTest.class);
- suite.setName("CholeskySolver Tests");
- return suite;
- }//suite
-
-
- /**
- * tests CholeskySolver.setNumericalZero()
- */
- public void testNumericalZero() {
- CholeskySolver solver = new CholeskySolver();
- double numericalZero = 77.77d;
- solver.setNumericalZero(numericalZero);
- assertEquals(solver.getNumericalZero(), numericalZero, 0.0d);
-
- try {
- solver.decompose(
- new Array2DRowRealMatrix(new double[][]{{numericalZero/2, 0},
- {0, numericalZero/2}}));
- fail("testing numericalZero");
- } catch (IllegalArgumentException e) {}
-
- }//testNumericalZero
-
-
- /**
- * tests CholeskySolver.decompose(...)
- */
- public void testDecompose() {
-
- //The following decompositions should succeed.
- testDecompose(m1, "Decomposing matrix m1");
- testDecompose(m2, "Decomposing matrix m2");
- testDecompose(m3, "Decomposing matrix m3");
- testDecompose(m4, "Decomposing matrix m4");
- testDecompose(m5, "Decomposing matrix m5");
-
- //The following decompositions will fail. An IllegalArgumentException
- //should be thrown.
- try {
- testDecompose(m6, "Decomposing matrix m6");
- fail("Decomposing matrix m6");
- } catch (IllegalArgumentException e) {}
-
- try {
- CholeskySolver solver = new CholeskySolver();
- solver.decompose(new Array2DRowRealMatrix(m7));
- fail("Decomposing matrix m7");
- } catch (IllegalArgumentException e) {}
-
- }//testDecomposition
-
-
- /**
- * tests CholeskySolver.solve(...)
- */
- public void testSolve() {
-
- //If there's no matrix, there's no linear euqitation to solve ...
- try {
- CholeskySolver solver = new CholeskySolver();
- solver.solve(new double[] {1,2,3});
- fail("solving a liniar equitation with a missing matrix should fail");
- } catch (IllegalStateException e) {}
-
- //The following operations should succeed.
- testSolve(m1, "Solving matrix m1");
- testSolve(m2, "Solving matrix m2");
- testSolve(m3, "Solving matrix m3");
- testSolve(m4, "Solving matrix m4");
- testSolve(m5, "Solving matrix m5");
-
- //The following operations will fail. An IllegalArgumentException
- //should be thrown.
- try {
- testSolve(m6, "Solving matrix m6");
- fail("Solving matrix m6");
- } catch (IllegalArgumentException e) {}
-
- try {
- CholeskySolver solver = new CholeskySolver();
- solver.solve(new Array2DRowRealMatrix(m3), new double[] {1, 2, 3, 4});
- fail("Solving matrix m3[3x3], v[4]");
- } catch (IllegalArgumentException e) {}
-
- }//testDecomposition
-
-
- /**
- * tests CholeskySolver.getDeterminant(...)
- */
- public void testGetDeterminant() {
-
- //Since no matrix was decomposed, there's no determinant.
- try {
- CholeskySolver solver = new CholeskySolver();
- solver.getDeterminant();
- fail("Calculating determinant of missing matrix should fail");
- } catch (IllegalStateException e) {}
-
- //These test will suceed.
- testGetDeterminant(m1, m1Det, "Calculating determinant of m1");
- testGetDeterminant(m2, m2Det, "Calculating determinant of m2");
- testGetDeterminant(m3, m3Det, "Calculating determinant of m3");
- testGetDeterminant(m4, m4Det, "Calculating determinant of m4");
- testGetDeterminant(m5, m5Det, "Calculating determinant of m5");
- }//test
-
-
- /**
- * Generates the matrix
- * <code>m = lowerTriangularMatrix * lowerTriangularMatrix^T</code>.
- * If alle diagonalelements of <code>lowerTriangularMatrix</code> are
- * positiv, <code>m</code> will be positiv definit.
- * Decomposing <code>m</code> should result in
- * <code>lowerTriangularMatrix</code> again. So there's a simple test ...
- */
- private void testDecompose(double[][] lowerTriangularMatrix, String message)
- throws IllegalArgumentException {
-
- RealMatrix triangularMatrix = new Array2DRowRealMatrix(lowerTriangularMatrix);
- RealMatrix pdMatrix =
- triangularMatrix.multiply(triangularMatrix.transpose());
-
- CholeskySolver solver = new CholeskySolver();
- solver.decompose(pdMatrix);
-
- assertTrue(message,
- areEqual(triangularMatrix, solver.getDecomposition(), 1.0E-10));
-
- }//testDecompose
-
-
- /**
- * Similar to <code> private testDecompose(...)</code>.
- */
- private void testSolve(double[][] lowerTriangularMatrix, String message) {
-
- RealMatrix triangularMatrix =
- new Array2DRowRealMatrix(lowerTriangularMatrix);
- Array2DRowRealMatrix pdMatrix =
- (Array2DRowRealMatrix) triangularMatrix.multiply(triangularMatrix.transpose());
- CholeskySolver solver =
- new CholeskySolver();
-
- double[] c = new double[lowerTriangularMatrix.length];
- for (int i=0; i<c.length; i++)
- for (int j=0; j<lowerTriangularMatrix[0].length; j++)
- c[i] += lowerTriangularMatrix[i][j];
-
- solver.decompose(pdMatrix);
- RealMatrix x = new Array2DRowRealMatrix(solver.solve(c));
-
- assertTrue(message,
- areEqual(pdMatrix.multiply(x), new Array2DRowRealMatrix(c), 1.0E-10));
- }//testSolve
-
-
- /**
- * Similar to <code> private testDecompose(...)</code>.
- */
- private void testGetDeterminant(double[][] lowerTriangularMatrix,
- double determinant,
- String message)
- throws IllegalArgumentException {
-
- RealMatrix triangularMatrix = new Array2DRowRealMatrix(lowerTriangularMatrix);
- RealMatrix pdMatrix =
- triangularMatrix.multiply(triangularMatrix.transpose());
- double pdDeterminant = determinant * determinant;
-
- CholeskySolver solver = new CholeskySolver();
- solver.decompose(pdMatrix);
- assertEquals(message, solver.getDeterminant(), pdDeterminant, 1.0E-10);
- }//testGetDeterminant
-
-
- /**
- * Are <code>m1</code> and <code>m2</code> equal?
- */
- private static boolean areEqual(RealMatrix m1, RealMatrix m2, double delta) {
-
- double[][] mv1 = m1.getData();
- double[][] mv2 = m2.getData();
-
- if (mv1.length != mv1.length ||
- mv1[0].length != mv2[0].length)
- return false;
-
- for (int i=0; i<mv1.length; i++)
- for (int j=0; j<mv1[0].length; j++)
- if (Math.abs(mv1[i][j] -mv2[i][j]) > delta)
- return false;
-
- return true;
- }//isEqual
-
-
- /**
- * Executes all tests of this class
- */
- public static void main(String[] args) {
- System.out.println("Start");
- TestRunner runner = new TestRunner();
- runner.doRun(CholeskySolverTest.suite());
- System.out.println("End");
- }//main
-
-}//class CholeskySolverTest
diff --git a/src/experimental/org/apache/commons/math/linear/Decomposer.java b/src/experimental/org/apache/commons/math/linear/Decomposer.java
deleted file mode 100644
index 1eeafa9..0000000
--- a/src/experimental/org/apache/commons/math/linear/Decomposer.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.linear;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public interface Decomposer {
-
- Decomposition decompose(RealMatrix matrix);
-
-}
diff --git a/src/experimental/org/apache/commons/math/linear/Decomposition.java b/src/experimental/org/apache/commons/math/linear/Decomposition.java
deleted file mode 100644
index c4cb4ac..0000000
--- a/src/experimental/org/apache/commons/math/linear/Decomposition.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.linear;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public interface Decomposition {
-
- // solve A*x=b
- RealVector solve(RealVector b);
-
-
- // solve matrix equation
- RealMatrix solve(RealMatrix b);
-
-
- RealMatrix invert();
-
-}
diff --git a/src/experimental/org/apache/commons/math/linear/DecompositionFactory.java b/src/experimental/org/apache/commons/math/linear/DecompositionFactory.java
deleted file mode 100644
index c17dc50..0000000
--- a/src/experimental/org/apache/commons/math/linear/DecompositionFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.linear;
-
-/**
-
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public abstract class DecompositionFactory {
-
- /*
- * get a matrix specific decomposer factory
- * class RealMatrix {
- * DecompositionFactory getDecompositionFactory();
- * }
- */
-
- // get overall default factory
- public static DecompositionFactory newInstance(){
- return null;
- }
-
- // construct a new default decomposer
- public abstract Decomposer newDecomposer();
-
- // example for a specific decomposer (Householder or QR)
- public abstract Decomposer newQRDecopmposer();
-}
diff --git a/src/experimental/org/apache/commons/math/linear/RealVector.java b/src/experimental/org/apache/commons/math/linear/RealVector.java
deleted file mode 100644
index ccfb60b..0000000
--- a/src/experimental/org/apache/commons/math/linear/RealVector.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.linear;
-
-
-public class RealVector {
-
-
-}
diff --git a/src/experimental/org/apache/commons/math/linear/RecursiveLayoutRealMatrix.java b/src/experimental/org/apache/commons/math/linear/RecursiveLayoutRealMatrix.java
deleted file mode 100644
index 1f17f0c..0000000
--- a/src/experimental/org/apache/commons/math/linear/RecursiveLayoutRealMatrix.java
+++ /dev/null
@@ -1,2051 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.linear;
-
-import java.io.Serializable;
-
-import org.apache.commons.math.MathRuntimeException;
-
-/**
- * Cache-friendly implementation of RealMatrix using recursive array layouts to store
- * the matrix elements.
- * <p>
- * As of 2009-02-13, this implementation does not work! The padding at left and bottom
- * sides of the matrix should be cleared after some operations like scalerAdd
- * and is not. Also there is a limitation in the multiplication that can only
- * process matrices with sizes similar enough to have the same power of two
- * number of tiles in all three matrices A, B and C such that C = A*B. These
- * parts have not been fixed since the performance gain with respect to
- * BlockRealMatrix are not very important, and the numerical stability is not
- * good. This may well be due to a bad implementation. This code has been put
- * in the experimental part for the record, putting it into production would
- * require solving all these issues.
- * </p>
- * <p>
- * This implementation is based on the 2002 paper: <a
- * href="http://www.cs.duke.edu/~alvy/papers/matrix-tpds.pdf">Recursive Array Layouts
- * and Fast Matrix Multiplication</a> by Siddhartha Chatterjee, Alvin R. Lebeck,
- * Praveen K. Patnala and Mithuna Thottethodi.
- * </p>
- * <p>
- * The matrix is split into several rectangular tiles. The tiles are laid out using
- * a space-filling curve in a 2<sup>k</sup>×2<sup>k</sup> square. This
- * implementation uses the Gray-Morton layout which starts as follows for a three-level
- * recursion (i.e. an 8x8 matrix). The tiles size are adjusted in order to have the
- * 2<sup>k</sup>×2<sup>k</sup> square. This may require padding at the right and
- * bottom sides of the matrix (see above paper for a discussion of this padding feature).
- * </p>
- * <pre>
- * |
- * 00 01 | 06 07 | 24 25 | 30 31
- * 03 02 | 05 04 | 27 26 | 29 28
- * ------+------ | -------+-------
- * 12 13 | 10 11 | 20 21 | 18 19
- * 15 14 | 09 08 | 23 22 | 17 16
- * |
- * -------------------+--------------------
- * |
- * 48 49 | 54 55 | 40 41 | 46 47
- * 51 50 | 53 52 | 43 42 | 45 44
- * ------+------ | -------+-------
- * 60 61 | 58 59 | 36 37 | 34 35
- * 63 62 | 57 56 | 39 38 | 33 32
- * |
- * </pre>
- * @version $Revision$ $Date$
- * @since 2.0
- */
-public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Serializable {
-
- /** Serializable version identifier */
- private static final long serialVersionUID = 1607919006739190004L;
-
- /** Maximal allowed tile size in bytes.
- * <p>In order to avoid cache miss during multiplication,
- * a suggested value is cache_size/3.</p>
- */
- private static final int MAX_TILE_SIZE_BYTES = (64 * 1024) / 3;
- //private static final int MAX_TILE_SIZE_BYTES = 32;
-
- /** Storage array for matrix elements. */
- private final double data[];
-
- /** Number of rows of the matrix. */
- private final int rows;
-
- /** Number of columns of the matrix. */
- private final int columns;
-
- /** Number of terminal tiles along rows and columns (guaranteed to be a power of 2). */
- private final int tileNumber;
-
- /** Number of rows in each terminal tile. */
- private final int tileSizeRows;
-
- /** Number of columns in each terminal tile. */
- private final int tileSizeColumns;
-
- /**
- * Create a new matrix with the supplied row and column dimensions.
- *
- * @param rows the number of rows in the new matrix
- * @param columns the number of columns in the new matrix
- * @throws IllegalArgumentException if row or column dimension is not
- * positive
- */
- public RecursiveLayoutRealMatrix(final int rows, final int columns)
- throws IllegalArgumentException {
-
- super(rows, columns);
- this.rows = rows;
- this.columns = columns;
-
- // compute optimal layout
- tileNumber = tilesNumber(rows, columns);
- tileSizeRows = tileSize(rows, tileNumber);
- tileSizeColumns = tileSize(columns, tileNumber);
-
- // create storage array
- data = new double[tileNumber * tileNumber * tileSizeRows * tileSizeColumns];
-
- }
-
- /**
- * Create a new dense matrix copying entries from raw layout data.
- * <p>The input array <em>must</em> be in raw layout.</p>
- * <p>Calling this constructor is equivalent to call:
- * <pre>matrix = new RecursiveLayoutRealMatrix(rawData.length, rawData[0].length,
- * toRecursiveLayout(rawData), false);</pre>
- * </p>
- * @param rawData data for new matrix, in raw layout
- *
- * @exception IllegalArgumentException if <code>rawData</code> shape is
- * inconsistent with tile layout
- * @see #RecursiveLayoutRealMatrix(int, int, double[][], boolean)
- */
- public RecursiveLayoutRealMatrix(final double[][] rawData)
- throws IllegalArgumentException {
- this(rawData.length, rawData[0].length, toRecursiveLayout(rawData), false);
- }
-
- /**
- * Create a new dense matrix copying entries from recursive layout data.
- * <p>The input array <em>must</em> already be in recursive layout.</p>
- * @param rows the number of rows in the new matrix
- * @param columns the number of columns in the new matrix
- * @param data data for new matrix, in recursive layout
- * @param copyArray if true, the input array will be copied, otherwise
- * it will be referenced
- *
- * @exception IllegalArgumentException if <code>data</code> size is
- * inconsistent with matrix size
- * @see #toRecursiveLayout(double[][])
- * @see #RecursiveLayoutRealMatrix(double[][])
- */
- public RecursiveLayoutRealMatrix(final int rows, final int columns,
- final double[] data, final boolean copyArray)
- throws IllegalArgumentException {
-
- super(rows, columns);
- this.rows = rows;
- this.columns = columns;
-
- // compute optimal layout
- tileNumber = tilesNumber(rows, columns);
- tileSizeRows = tileSize(rows, tileNumber);
- tileSizeColumns = tileSize(columns, tileNumber);
-
- // create storage array
- final int expectedLength = tileNumber * tileNumber * tileSizeRows * tileSizeColumns;
- if (data.length != expectedLength) {
- throw MathRuntimeException.createIllegalArgumentException(
- "wrong array size (got {0}, expected {1})",
- data.length, expectedLength);
- }
-
- if (copyArray) {
- // allocate storage array
- this.data = data.clone();
- } else {
- // reference existing array
- this.data = data;
- }
-
- }
-
- /**
- * Convert a data array from raw layout to recursive layout.
- * <p>
- * Raw layout is the straightforward layout where element at row i and
- * column j is in array element <code>rawData[i][j]</code>. Recursive layout
- * is the layout used in {@link RecursiveLayoutRealMatrix} instances, where the matrix
- * is stored in a dimension 1 array using a space-filling curve to spread the matrix
- * elements along the array.
- * </p>
- * @param rawData data array in raw layout
- * @return a new data array containing the same entries but in recursive layout
- * @exception IllegalArgumentException if <code>rawData</code> is not rectangular
- * (not all rows have the same length)
- * @see #RecursiveLayoutRealMatrix(int, int, double[], boolean)
- */
- public static double[] toRecursiveLayout(final double[][] rawData)
- throws IllegalArgumentException {
-
- final int rows = rawData.length;
- final int columns = rawData[0].length;
-
- // compute optimal layout
- final int tileNumber = tilesNumber(rows, columns);
- final int tileSizeRows = tileSize(rows, tileNumber);
- final int tileSizeColumns = tileSize(columns, tileNumber);
-
- // safety checks
- for (int i = 0; i < rawData.length; ++i) {
- final int length = rawData[i].length;
- if (length != columns) {
- throw MathRuntimeException.createIllegalArgumentException(
- "some rows have length {0} while others have length {1}",
- columns, length);
- }
- }
-
- // convert array row after row
- final double[] data = new double[tileNumber * tileNumber * tileSizeRows * tileSizeColumns];
- for (int i = 0; i < rawData.length; ++i) {
- final int iTile = i / tileSizeRows;
- final double[] rawDataI = rawData[i];
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int tileStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns;
- final int dataStart = tileStart + (i - iTile * tileSizeRows) * tileSizeColumns;
- final int jStart = jTile * tileSizeColumns;
- if (jStart < columns) {
- final int jEnd = Math.min(jStart + tileSizeColumns, columns);
- System.arraycopy(rawDataI, jStart, data, dataStart, jEnd - jStart);
- }
- }
- }
-
- return data;
-
- }
-
- /** {@inheritDoc} */
- public RealMatrix createMatrix(final int rowDimension, final int columnDimension)
- throws IllegalArgumentException {
- return new RecursiveLayoutRealMatrix(rowDimension, columnDimension);
- }
-
- /** {@inheritDoc} */
- public RealMatrix copy() {
- return new RecursiveLayoutRealMatrix(rows, columns, data, true);
- }
-
- /** {@inheritDoc} */
- public RealMatrix add(final RealMatrix m)
- throws IllegalArgumentException {
- try {
- return add((RecursiveLayoutRealMatrix) m);
- } catch (ClassCastException cce) {
-
- // safety check
- checkAdditionCompatible(m);
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, columns);
-
- // perform addition tile-wise, to ensure good cache behavior
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
-
- // perform addition on the current tile
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int p = pStart; p < pEnd; ++p) {
- final int kStart = tileStart + (p - pStart) * tileSizeColumns;
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- out.data[k] = data[k] + m.getEntry(p, q);
- }
- }
-
- }
-
- return out;
-
- }
- }
-
- /**
- * Compute the sum of this and <code>m</code>.
- *
- * @param m matrix to be added
- * @return this + m
- * @throws IllegalArgumentException if m is not the same size as this
- */
- public RecursiveLayoutRealMatrix add(final RecursiveLayoutRealMatrix m)
- throws IllegalArgumentException {
-
- // safety check
- checkAdditionCompatible(m);
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, columns);
-
- // streamlined addition
- for (int i = 0; i < data.length; ++i) {
- out.data[i] = data[i] + m.data[i];
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public RealMatrix subtract(final RealMatrix m)
- throws IllegalArgumentException {
- try {
- return subtract((RecursiveLayoutRealMatrix) m);
- } catch (ClassCastException cce) {
-
- // safety check
- checkSubtractionCompatible(m);
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, columns);
-
- // perform subtraction tile-wise, to ensure good cache behavior
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
-
- // perform addition on the current tile
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int p = pStart; p < pEnd; ++p) {
- final int kStart = tileStart + (p - pStart) * tileSizeColumns;
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- out.data[k] = data[k] - m.getEntry(p, q);
- }
- }
-
- }
-
- return out;
-
- }
- }
-
- /**
- * Compute this minus <code>m</code>.
- *
- * @param m matrix to be subtracted
- * @return this - m
- * @throws IllegalArgumentException if m is not the same size as this
- */
- public RecursiveLayoutRealMatrix subtract(final RecursiveLayoutRealMatrix m)
- throws IllegalArgumentException {
-
- // safety check
- checkSubtractionCompatible(m);
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, columns);
-
- // streamlined subtraction
- for (int i = 0; i < data.length; ++i) {
- out.data[i] = data[i] - m.data[i];
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public RealMatrix scalarAdd(final double d)
- throws IllegalArgumentException {
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, columns);
-
- // streamlined addition
- for (int i = 0; i < data.length; ++i) {
- out.data[i] = data[i] + d;
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public RealMatrix scalarMultiply(final double d)
- throws IllegalArgumentException {
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, columns);
-
- // streamlined multiplication
- for (int i = 0; i < data.length; ++i) {
- out.data[i] = data[i] * d;
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public RealMatrix multiply(final RealMatrix m)
- throws IllegalArgumentException {
- try {
- return multiply((RecursiveLayoutRealMatrix) m);
- } catch (ClassCastException cce) {
-
- // safety check
- checkMultiplicationCompatible(m);
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, m.getColumnDimension());
-
- // perform multiplication tile-wise, to ensure good cache behavior
- for (int index = 0; index < out.tileNumber * out.tileNumber; ++index) {
- final int tileStart = index * out.tileSizeRows * out.tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int iStart = iTile * out.tileSizeRows;
- final int iEnd = Math.min(iStart + out.tileSizeRows, out.rows);
- final int jStart = jTile * out.tileSizeColumns;
- final int jEnd = Math.min(jStart + out.tileSizeColumns, out.columns);
-
- // perform multiplication for current tile
- for (int kTile = 0; kTile < tileNumber; ++kTile) {
- final int kTileStart = tileIndex(iTile, kTile) * tileSizeRows * tileSizeColumns;
- for (int i = iStart, lStart = kTileStart, oStart = tileStart;
- i < iEnd;
- ++i, lStart += tileSizeColumns, oStart += out.tileSizeColumns) {
- final int lEnd = Math.min(lStart + tileSizeColumns, columns);
- for (int j = jStart, o = oStart; j < jEnd; ++j, ++o) {
- double sum = 0;
- for (int l = lStart, k = kTile * tileSizeColumns; l < lEnd; ++l, ++k) {
- sum += data[l] * m.getEntry(k, j);
- }
- out.data[o] += sum;
- }
- }
- }
- }
-
- return out;
-
- }
- }
-
- /**
- * Returns the result of postmultiplying this by m.
- * <p>The Strassen matrix multiplication method is used here. This
- * method computes C = A × B recursively by splitting all matrices
- * in four quadrants and computing:</p>
- * <pre>
- * P<sub>1</sub> = (A<sub>1,1</sub> + A<sub>2,2</sub>) × (B<sub>1,1</sub> + B<sub>2,2</sub>)
- * P<sub>2</sub> = (A<sub>2,1</sub> + A<sub>2,2</sub>) × (B<sub>1,1</sub>)
- * P<sub>3</sub> = (A<sub>1,1</sub>) × (B<sub>1,2</sub> - B<sub>2,2</sub>)
- * P<sub>4</sub> = (A<sub>2,2</sub>) × (B<sub>2,1</sub> - B<sub>1,1</sub>)
- * P<sub>5</sub> = (A<sub>1,1</sub> + A<sub>1,2</sub>) × B<sub>2,2</sub>
- * P<sub>6</sub> = (A<sub>2,1</sub> - A<sub>1,1</sub>) × (B<sub>1,1</sub> + B<sub>1,2</sub>)
- * P<sub>7</sub> = (A<sub>1,2</sub> - A<sub>2,2</sub>) × (B<sub>2,1</sub> + B<sub>2,2</sub>)
- *
- * C<sub>1,1</sub> = P<sub>1</sub> + P<sub>4</sub> - P<sub>5</sub> + P<sub>7</sub>
- * C<sub>1,2</sub> = P<sub>3</sub> + P<sub>5</sub>
- * C<sub>2,1</sub> = P<sub>2</sub> + P<sub>4</sub>
- * C<sub>2,2</sub> = P<sub>1</sub> + P<sub>3</sub> - P<sub>2</sub> + P<sub>6</sub>
- * </pre>
- * <p>
- * This implementation is based on the 2002 paper: <a
- * href="http://www.cs.duke.edu/~alvy/papers/matrix-tpds.pdf">Recursive Array Layouts
- * and Fast Matrix Multiplication</a> by Siddhartha Chatterjee, Alvin R. Lebeck,
- * Praveen K. Patnala and Mithuna Thottethodi.
- * </p>
- *
- * @param m matrix to postmultiply by
- * @return this * m
- * @throws IllegalArgumentException
- * if columnDimension(this) != rowDimension(m)
- */
- public RecursiveLayoutRealMatrix multiply(RecursiveLayoutRealMatrix m)
- throws IllegalArgumentException {
-
- // safety check
- checkMultiplicationCompatible(m);
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, m.columns);
- if ((tileNumber != m.tileNumber) || (tileNumber != out.tileNumber)) {
- // TODO get rid of this test
- throw new RuntimeException("multiplication " + rows + "x" + columns + " * " +
- m.rows + "x" + m.columns + " -> left matrix: " + tileNumber +
- " tiles, right matrix: " + m.tileNumber + " tiles, result matrix " +
- out.tileNumber + " tiles");
- }
- strassenMultiply(data, 0, true, m.data, 0, true, out.data, 0, tileNumber,
- tileSizeRows, m.tileSizeColumns, tileSizeColumns);
-
- return out;
-
- }
-
- /**
- * Perform recursive multiplication using Strassen's algorithm.
- * @param a left term of multiplication
- * @param aStart start index in a
- * @param aDirect direct/reversed orientation flag for a
- * @param b right term of multiplication
- * @param bStart start index in b
- * @param bDirect direct/reversed orientation flag for b
- * @param result result array (will have same orientation as b)
- * @param resultStart start index in result
- * @param nTiles number of elements to add
- * @param bsRows number of rows in result tiles
- * @param bsColumns number of columns in result tiles
- * @param bsMultiplicands number of rows/columns in multiplicands
- */
- private static void strassenMultiply(final double[] a, final int aStart, final boolean aDirect,
- final double[] b, final int bStart, final boolean bDirect,
- final double[] result, final int resultStart, final int nTiles,
- final int bsRows, final int bsColumns, final int bsMultiplicands) {
- if (nTiles == 1) {
- // leaf recursion tile: perform traditional multiplication
- final int bsColumns2 = 2 * bsColumns;
- final int bsColumns3 = 3 * bsColumns;
- final int bsColumns4 = 4 * bsColumns;
- for (int i = 0; i < bsRows; ++i) {
- for (int j = 0; j < bsColumns; ++j) {
- double sum = 0;
- int k = 0;
- int aK = aStart + i * bsMultiplicands;
- int bK = bStart + j;
- while (k < bsMultiplicands - 3) {
- sum += a[aK] * b[bK] +
- a[aK + 1] * b[bK + bsColumns] +
- a[aK + 2] * b[bK + bsColumns2] +
- a[aK + 3] * b[bK + bsColumns3];
- k += 4;
- aK += 4;
- bK += bsColumns4;
- }
- while (k < bsMultiplicands) {
- sum += a[aK] * b[bK];
- k += 1;
- aK += 1;
- bK += bsColumns;
- }
- result[resultStart + i * bsColumns + j] = sum;
- }
- }
- } else {
- // regular recursion node: use recursive Strassen implementation
- final int n2 = nTiles / 2;
- final int aQuadrantSize = bsRows * n2 * bsMultiplicands * n2;
- final int bQuadrantSize = bsMultiplicands * n2 * bsColumns * n2;
- final int cQuadrantSize = bsRows * n2 * bsColumns * n2;
- final double[] sA = new double[aQuadrantSize];
- final double[] sB = new double[bQuadrantSize];
- final boolean nonLeafQuadrants = n2 > 1;
-
- // identify A quadrants start indices
- final int a11Start, a12Start, a21Start, a22Start;
- if (aDirect) {
- a11Start = aStart;
- a12Start = aStart + aQuadrantSize;
- a21Start = aStart + 3 * aQuadrantSize;
- a22Start = aStart + 2 * aQuadrantSize;
- } else {
- a11Start = aStart + 2 * aQuadrantSize;
- a12Start = aStart + 3 * aQuadrantSize;
- a21Start = aStart + aQuadrantSize;
- a22Start = aStart;
- }
-
- // identify B and C quadrants start indices
- // (C is constructed with the same orientation as B)
- final int b11Start, b12Start, b21Start, b22Start;
- final int c11Start, c12Start, c21Start, c22Start;
- if (bDirect) {
- b11Start = bStart;
- b12Start = bStart + bQuadrantSize;
- b21Start = bStart + 3 * bQuadrantSize;
- b22Start = bStart + 2 * bQuadrantSize;
- c11Start = resultStart;
- c12Start = resultStart + cQuadrantSize;
- c21Start = resultStart + 3 * cQuadrantSize;
- c22Start = resultStart + 2 * cQuadrantSize;
- } else {
- b11Start = bStart + 2 * bQuadrantSize;
- b12Start = bStart + 3 * bQuadrantSize;
- b21Start = bStart + bQuadrantSize;
- b22Start = bStart;
- c11Start = resultStart + 2 * cQuadrantSize;
- c12Start = resultStart + 3 * cQuadrantSize;
- c21Start = resultStart + cQuadrantSize;
- c22Start = resultStart;
- }
-
- // optimal order for cache efficiency: P3, P6, P2, P1, P5, P7, P4
-
- // P3 = (A11)(B12 - B22)
- // C12 = P3 + ...
- tilesSubtract(b, b12Start, false, b, b22Start, false, sB, 0,
- bQuadrantSize, nonLeafQuadrants);
- strassenMultiply(a, a11Start, true, sB, 0, false, result, c12Start,
- n2, bsRows, bsColumns, bsMultiplicands);
-
- // P6 = (A21 - A11)(B11 + B12)
- // C22 = P3 + P6 + ...
- final double[] p67 = new double[cQuadrantSize];
- tilesSubtract(a, a21Start, true, a, a11Start, true, sA, 0,
- aQuadrantSize, nonLeafQuadrants);
- tilesAdd(b, b11Start, true, b, b12Start, false, sB, 0,
- bQuadrantSize, nonLeafQuadrants);
- strassenMultiply(sA, 0, true, sB, 0, true, p67, 0,
- n2, bsRows, bsColumns, bsMultiplicands);
- tilesAdd(result, c12Start, false, p67, 0, true, result, c22Start,
- cQuadrantSize, nonLeafQuadrants);
-
- // P2 = (A21 + A22)(B11)
- // C21 = P2 + ...
- // C22 = P3 + P6 - P2 + ...
- tilesAdd(a, a21Start, true, a, a22Start, false, sA, 0,
- aQuadrantSize, nonLeafQuadrants);
- strassenMultiply(sA, 0, true, b, b11Start, true, result, c21Start,
- n2, bsRows, bsColumns, bsMultiplicands);
- tilesSelfSubtract(result, c22Start, false, result, c21Start, true,
- cQuadrantSize, nonLeafQuadrants);
-
- // P1 = (A11 + A22)(B11 + B22)
- // C11 = P1 + ...
- // C22 = P3 + P6 - P2 + P1
- tilesAdd(a, a11Start, true, a, a22Start, false, sA, 0,
- aQuadrantSize, nonLeafQuadrants);
- tilesAdd(b, b11Start, true, b, b22Start, false, sB, 0,
- bQuadrantSize, nonLeafQuadrants);
- strassenMultiply(sA, 0, true, sB, 0, true, result, c11Start,
- n2, bsRows, bsColumns, bsMultiplicands);
- tilesSelfAdd(result, c22Start, false, result, c11Start, true,
- cQuadrantSize, nonLeafQuadrants);
-
- // P5 = (A11 + A12)B22
- // beware: there is a sign error here in Chatterjee et al. paper
- // in figure 1, table b they subtract A12 from A11 instead of adding it
- // C12 = P3 + P5
- // C11 = P1 - P5 + ...
- final double[] p45 = new double[cQuadrantSize];
- tilesAdd(a, a11Start, true, a, a12Start, false, sA, 0,
- aQuadrantSize, nonLeafQuadrants);
- strassenMultiply(sA, 0, true, b, b22Start, false, p45, 0,
- n2, bsRows, bsColumns, bsMultiplicands);
- tilesSelfAdd(result, c12Start, false, p45, 0, false,
- cQuadrantSize, nonLeafQuadrants);
- tilesSelfSubtract(result, c11Start, true, p45, 0, false,
- cQuadrantSize, nonLeafQuadrants);
-
- // P7 = (A12 - A22)(B21 + B22)
- // C11 = P1 - P5 + P7 + ...
- tilesSubtract(a, a12Start, false, a, a22Start, false, sA, 0,
- aQuadrantSize, nonLeafQuadrants);
- tilesAdd(b, b21Start, true, b, b22Start, false, sB, 0,
- bQuadrantSize, nonLeafQuadrants);
- strassenMultiply(sA, 0, false, sB, 0, true, p67, 0,
- n2, bsRows, bsColumns, bsMultiplicands);
- tilesSelfAdd(result, c11Start, true, p67, 0, true,
- cQuadrantSize, nonLeafQuadrants);
-
- // P4 = (A22)(B21 - B11)
- // C11 = P1 - P5 + P7 + P4
- // C21 = P2 + P4
- tilesSubtract(b, b21Start, true, b, b11Start, true, sB, 0,
- bQuadrantSize, nonLeafQuadrants);
- strassenMultiply(a, a22Start, false, sB, 0, true, p45, 0,
- n2, bsRows, bsColumns, bsMultiplicands);
- tilesSelfAdd(result, c11Start, true, p45, 0, true,
- cQuadrantSize, nonLeafQuadrants);
- tilesSelfAdd(result, c21Start, true, p45, 0, true,
- cQuadrantSize, nonLeafQuadrants);
-
- }
- }
-
- /**
- * Perform an addition on a few tiles in arrays.
- * @param a left term of addition
- * @param aStart start index in a
- * @param aDirect direct/reversed orientation flag for a
- * @param b right term of addition
- * @param bStart start index in b
- * @param bDirect direct/reversed orientation flag for b
- * @param result result array (will have same orientation as a)
- * @param resultStart start index in result
- * @param n number of elements to add
- * @param nonLeafQuadrants if true the quadrant can be further decomposed
- */
- private static void tilesAdd(final double[] a, final int aStart, final boolean aDirect,
- final double[] b, final int bStart, final boolean bDirect,
- final double[] result, final int resultStart,
- final int n, final boolean nonLeafQuadrants) {
- if ((aDirect ^ bDirect) & nonLeafQuadrants) {
- // a and b have different orientations
- // perform addition in two half
- final int n2 = n / 2;
- addLoop(a, aStart, b, bStart + n2, result, resultStart, n2);
- addLoop(a, aStart + n2, b, bStart, result, resultStart + n2, n2);
- } else {
- // a and b have same orientations
- // perform addition in one loop
- addLoop(a, aStart, b, bStart, result, resultStart, n);
- }
- }
-
- /**
- * Perform an addition loop.
- * @param a left term of addition
- * @param aStart start index in a
- * @param b right term of addition
- * @param bStart start index in b
- * @param result result array (will have same orientation as a)
- * @param resultStart start index in result
- * @param n number of elements to add
- */
- private static void addLoop(final double[] a, final int aStart,
- final double[] b, final int bStart,
- final double[] result, final int resultStart,
- final int n) {
- int i = 0;
- while (i < n - 3) {
- final int r0 = resultStart + i;
- final int a0 = aStart + i;
- final int b0 = bStart + i;
- result[r0] = a[a0] + b[b0];
- result[r0 + 1] = a[a0 + 1] + b[b0 + 1];
- result[r0 + 2] = a[a0 + 2] + b[b0 + 2];
- result[r0 + 3] = a[a0 + 3] + b[b0 + 3];
- i += 4;
- }
- while (i < n) {
- result[resultStart + i] = a[aStart + i] + b[bStart + i];
- ++i;
- }
- }
-
- /**
- * Perform a subtraction on a few tiles in arrays.
- * @param a left term of subtraction
- * @param aStart start index in a
- * @param aDirect direct/reversed orientation flag for a
- * @param b right term of subtraction
- * @param bStart start index in b
- * @param bDirect direct/reversed orientation flag for b
- * @param result result array (will have same orientation as a)
- * @param resultStart start index in result
- * @param n number of elements to subtract
- * @param nonLeafQuadrants if true the quadrant can be further decomposed
- */
- private static void tilesSubtract(final double[] a, final int aStart, final boolean aDirect,
- final double[] b, final int bStart, final boolean bDirect,
- final double[] result, final int resultStart,
- final int n, final boolean nonLeafQuadrants) {
- if ((aDirect ^ bDirect) & nonLeafQuadrants) {
- // a and b have different orientations
- // perform subtraction in two half
- final int n2 = n / 2;
- subtractLoop(a, aStart, b, bStart + n2, result, resultStart, n2);
- subtractLoop(a, aStart + n2, b, bStart, result, resultStart + n2, n2);
- } else {
- // a and b have same orientations
- // perform subtraction in one loop
- subtractLoop(a, aStart, b, bStart, result, resultStart, n);
- }
- }
-
- /**
- * Perform a subtraction loop.
- * @param a left term of subtraction
- * @param aStart start index in a
- * @param b right term of subtraction
- * @param bStart start index in b
- * @param result result array (will have same orientation as a)
- * @param resultStart start index in result
- * @param n number of elements to subtract
- */
- private static void subtractLoop(final double[] a, final int aStart,
- final double[] b, final int bStart,
- final double[] result, final int resultStart,
- final int n) {
- int i = 0;
- while (i < n - 3) {
- final int r0 = resultStart + i;
- final int a0 = aStart + i;
- final int b0 = bStart + i;
- result[r0] = a[a0] - b[b0];
- result[r0 + 1] = a[a0 + 1] - b[b0 + 1];
- result[r0 + 2] = a[a0 + 2] - b[b0 + 2];
- result[r0 + 3] = a[a0 + 3] - b[b0 + 3];
- i += 4;
- }
- while (i < n) {
- result[resultStart + i] = a[aStart + i] - b[bStart + i];
- ++i;
- }
- }
-
- /**
- * Perform a self-addition on a few tiles in arrays.
- * @param a left term of addition (will be overwritten with result)
- * @param aStart start index in a
- * @param aDirect direct/reversed orientation flag for a
- * @param b right term of addition
- * @param bStart start index in b
- * @param bDirect direct/reversed orientation flag for b
- * @param n number of elements to add
- * @param nonLeafQuadrants if true the quadrant can be further decomposed
- */
- private static void tilesSelfAdd(final double[] a, final int aStart, final boolean aDirect,
- final double[] b, final int bStart, final boolean bDirect,
- final int n, final boolean nonLeafQuadrants) {
- if ((aDirect ^ bDirect) & nonLeafQuadrants) {
- // a and b have different orientations
- // perform addition in two half
- final int n2 = n / 2;
- selfAddLoop(a, aStart, b, bStart + n2, n2);
- selfAddLoop(a, aStart + n2, b, bStart, n2);
- } else {
- // a and b have same orientations
- // perform addition in one loop
- selfAddLoop(a, aStart, b, bStart, n);
- }
- }
-
- /**
- * Perform a self-addition loop.
- * @param a left term of addition (will be overwritten with result)
- * @param aStart start index in a
- * @param b right term of addition
- * @param bStart start index in b
- * @param n number of elements to add
- */
- private static void selfAddLoop(final double[] a, final int aStart,
- final double[] b, final int bStart,
- final int n) {
- int i = 0;
- while (i < n - 3) {
- final int a0 = aStart + i;
- final int b0 = bStart + i;
- a[a0] += b[b0];
- a[a0 + 1] += b[b0 + 1];
- a[a0 + 2] += b[b0 + 2];
- a[a0 + 3] += b[b0 + 3];
- i += 4;
- }
- while (i < n) {
- a[aStart + i] += b[bStart + i];
- ++i;
- }
- }
-
- /**
- * Perform a self-subtraction on a few tiles in arrays.
- * @param a left term of subtraction (will be overwritten with result)
- * @param aStart start index in a
- * @param aDirect direct/reversed orientation flag for a
- * @param b right term of subtraction
- * @param bStart start index in b
- * @param bDirect direct/reversed orientation flag for b
- * @param n number of elements to subtract
- * @param nonLeafQuadrants if true the quadrant can be further decomposed
- */
- private static void tilesSelfSubtract(final double[] a, final int aStart, final boolean aDirect,
- final double[] b, final int bStart, final boolean bDirect,
- final int n, final boolean nonLeafQuadrants) {
- if ((aDirect ^ bDirect) & nonLeafQuadrants) {
- // a and b have different orientations
- // perform subtraction in two half
- final int n2 = n / 2;
- selfSubtractLoop(a, aStart, b, bStart + n2, n2);
- selfSubtractLoop(a, aStart + n2, b, bStart, n2);
- } else {
- // a and b have same orientations
- // perform subtraction in one loop
- selfSubtractLoop(a, aStart, b, bStart, n);
- }
- }
-
- /**
- * Perform a self-subtraction loop.
- * @param a left term of subtraction (will be overwritten with result)
- * @param aStart start index in a
- * @param b right term of subtraction
- * @param bStart start index in b
- * @param n number of elements to subtract
- */
- private static void selfSubtractLoop(final double[] a, final int aStart,
- final double[] b, final int bStart,
- final int n) {
- int i = 0;
- while (i < n - 3) {
- final int a0 = aStart + i;
- final int b0 = bStart + i;
- a[a0] -= b[b0];
- a[a0 + 1] -= b[b0 + 1];
- a[a0 + 2] -= b[b0 + 2];
- a[a0 + 3] -= b[b0 + 3];
- i += 4;
- }
- while (i < n) {
- a[aStart + i] -= b[bStart + i];
- ++i;
- }
- }
-
- /** {@inheritDoc} */
- public double[][] getData() {
-
- final double[][] out = new double[rows][columns];
-
- // perform extraction tile-wise, to ensure good cache behavior
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
-
- // perform extraction on the current tile
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int qStart = jTile * tileSizeColumns;
- if (pStart < rows && qStart < columns) {
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- int tileRowStart = tileStart;
- for (int p = pStart; p < pEnd; ++p) {
- System.arraycopy(data, tileRowStart, out[p], qStart, qEnd - qStart);
- tileRowStart += tileSizeColumns;
- }
- }
-
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public double getFrobeniusNorm() {
- double sum2 = 0;
- for (final double entry : data) {
- sum2 += entry * entry;
- }
- return Math.sqrt(sum2);
- }
-
- /** {@inheritDoc} */
- public RealMatrix getSubMatrix(final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException {
-
- // safety checks
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
-
- // create the output matrix
- final RecursiveLayoutRealMatrix out =
- new RecursiveLayoutRealMatrix(endRow - startRow + 1, endColumn - startColumn + 1);
-
- // perform extraction tile-wise, to ensure good cache behavior
- for (int iTile = 0; iTile < out.tileNumber; ++iTile) {
- final int iStart = startRow + iTile * out.tileSizeRows;
- final int iEnd = Math.min(startRow + Math.min((iTile + 1) * out.tileSizeRows, out.rows),
- endRow + 1);
- for (int jTile = 0; jTile < out.tileNumber; ++jTile) {
- final int jStart = startColumn + jTile * out.tileSizeColumns;
- final int jEnd = Math.min(startColumn + Math.min((jTile + 1) * out.tileSizeColumns, out.columns),
- endColumn + 1);
-
- // the current output tile may expand on more than one instance tile
- for (int pTile = iStart / tileSizeRows; pTile * tileSizeRows < iEnd; ++pTile) {
- final int p0 = pTile * tileSizeRows;
- final int pStart = Math.max(p0, iStart);
- final int pEnd = Math.min(Math.min(p0 + tileSizeRows, endRow + 1), iEnd);
- for (int qTile = jStart / tileSizeColumns; qTile * tileSizeColumns < jEnd; ++qTile) {
- final int q0 = qTile * tileSizeColumns;
- final int qStart = Math.max(q0, jStart);
- final int qEnd = Math.min(Math.min(q0 + tileSizeColumns, endColumn + 1), jEnd);
-
- // copy the overlapping part of instance and output tiles
- int outIndex = tileIndex(iTile, jTile) * out.tileSizeRows * out.tileSizeColumns +
- (pStart - iStart) * out.tileSizeColumns + (qStart - jStart);
- int index = tileIndex(pTile, qTile) * tileSizeRows * tileSizeColumns +
- (pStart - p0) * tileSizeColumns + (qStart - q0);
- for (int p = pStart; p < pEnd; ++p) {
- System.arraycopy(data, index, out.data, outIndex, qEnd - qStart);
- outIndex += out.tileSizeColumns;
- index += tileSizeColumns;
- }
-
-
- }
- }
-
- }
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
- throws MatrixIndexException {
-
- // safety checks
- final int refLength = subMatrix[0].length;
- if (refLength < 1) {
- throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column",
- null);
- }
- final int endRow = row + subMatrix.length - 1;
- final int endColumn = column + refLength - 1;
- checkSubMatrixIndex(row, endRow, column, endColumn);
- for (final double[] subRow : subMatrix) {
- if (subRow.length != refLength) {
- throw MathRuntimeException.createIllegalArgumentException(
- "some rows have length {0} while others have length {1}",
- refLength, subRow.length);
- }
- }
-
- // compute tiles bounds
- final int tileStartRow = row / tileSizeRows;
- final int tileEndRow = (endRow + tileSizeRows) / tileSizeRows;
- final int tileStartColumn = column / tileSizeColumns;
- final int tileEndColumn = (endColumn + tileSizeColumns) / tileSizeColumns;
-
- // perform copy tile-wise, to ensure good cache behavior
- for (int iTile = tileStartRow; iTile < tileEndRow; ++iTile) {
- final int firstRow = iTile * tileSizeRows;
- final int iStart = Math.max(row, firstRow);
- final int iEnd = Math.min(endRow + 1, firstRow + tileSizeRows);
-
- for (int jTile = tileStartColumn; jTile < tileEndColumn; ++jTile) {
- final int firstColumn = jTile * tileSizeColumns;
- final int jStart = Math.max(column, firstColumn);
- final int jEnd = Math.min(endColumn + 1, firstColumn + tileSizeColumns);
- final int jLength = jEnd - jStart;
- final int tileStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns;
-
- // handle one tile, row by row
- for (int i = iStart; i < iEnd; ++i) {
- System.arraycopy(subMatrix[i - row], jStart - column,
- data, tileStart + (i - firstRow) * tileSizeColumns + (jStart - firstColumn),
- jLength);
- }
-
- }
- }
- }
-
- /** {@inheritDoc} */
- public RealMatrix getRowMatrix(final int row)
- throws MatrixIndexException {
-
- checkRowIndex(row);
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(1, columns);
-
- // a row matrix has always only one large tile,
- // because a single row cannot be split into 2^k tiles
- // perform copy tile-wise, to ensure good cache behavior
- final int iTile = row / tileSizeRows;
- final int rowOffset = row - iTile * tileSizeRows;
- int outIndex = 0;
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- rowOffset * tileSizeColumns;
- final int length = Math.min(outIndex + tileSizeColumns, columns) - outIndex;
- System.arraycopy(data, kStart, out.data, outIndex, length);
- outIndex += length;
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public void setRowMatrix(final int row, final RealMatrix matrix)
- throws MatrixIndexException, InvalidMatrixException {
- try {
- setRowMatrix(row, (RecursiveLayoutRealMatrix) matrix);
- } catch (ClassCastException cce) {
- super.setRowMatrix(row, matrix);
- }
- }
-
- /**
- * Sets the entries in row number <code>row</code>
- * as a row matrix. Row indices start at 0.
- *
- * @param row the row to be set
- * @param matrix row matrix (must have one row and the same number of columns
- * as the instance)
- * @throws MatrixIndexException if the specified row index is invalid
- * @throws InvalidMatrixException if the matrix dimensions do not match one
- * instance row
- */
- public void setRowMatrix(final int row, final RecursiveLayoutRealMatrix matrix)
- throws MatrixIndexException, InvalidMatrixException {
-
- checkRowIndex(row);
- final int nCols = getColumnDimension();
- if ((matrix.getRowDimension() != 1) ||
- (matrix.getColumnDimension() != nCols)) {
- throw new InvalidMatrixException(
- "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
- matrix.getRowDimension(), matrix.getColumnDimension(),
- 1, nCols);
- }
-
- // a row matrix has always only one large tile,
- // because a single row cannot be split into 2^k tiles
- // perform copy tile-wise, to ensure good cache behavior
- final int iTile = row / tileSizeRows;
- final int rowOffset = row - iTile * tileSizeRows;
- int outIndex = 0;
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- rowOffset * tileSizeColumns;
- final int length = Math.min(outIndex + tileSizeColumns, columns) - outIndex;
- System.arraycopy(matrix.data, outIndex, data, kStart, length);
- outIndex += length;
- }
-
- }
-
- /** {@inheritDoc} */
- public RealMatrix getColumnMatrix(final int column)
- throws MatrixIndexException {
-
- checkColumnIndex(column);
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(rows, 1);
-
- // a column matrix has always only one large tile,
- // because a single column cannot be split into 2^k tiles
- // perform copy tile-wise, to ensure good cache behavior
- final int jTile = column / tileSizeColumns;
- final int columnOffset = column - jTile * tileSizeColumns;
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- columnOffset;
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- out.data[p] = data[k];
- }
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public void setColumnMatrix(final int column, final RealMatrix matrix)
- throws MatrixIndexException, InvalidMatrixException {
- try {
- setColumnMatrix(column, (RecursiveLayoutRealMatrix) matrix);
- } catch (ClassCastException cce) {
- super.setColumnMatrix(column, matrix);
- }
- }
-
- /**
- * Sets the entries in column number <code>column</code>
- * as a column matrix. Column indices start at 0.
- *
- * @param column the column to be set
- * @param matrix column matrix (must have one column and the same number of rows
- * as the instance)
- * @throws MatrixIndexException if the specified column index is invalid
- * @throws InvalidMatrixException if the matrix dimensions do not match one
- * instance column
- */
- void setColumnMatrix(final int column, final RecursiveLayoutRealMatrix matrix)
- throws MatrixIndexException, InvalidMatrixException {
-
- checkColumnIndex(column);
- final int nRows = getRowDimension();
- if ((matrix.getRowDimension() != nRows) ||
- (matrix.getColumnDimension() != 1)) {
- throw new InvalidMatrixException(
- "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
- matrix.getRowDimension(), matrix.getColumnDimension(),
- nRows, 1);
- }
-
- // a column matrix has always only one large tile,
- // because a single column cannot be split into 2^k tiles
- // perform copy tile-wise, to ensure good cache behavior
- final int jTile = column / tileSizeColumns;
- final int columnOffset = column - jTile * tileSizeColumns;
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- columnOffset;
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- data[k] = matrix.data[p];
- }
- }
-
- }
-
- /** {@inheritDoc} */
- public void setRowVector(final int row, final RealVector vector)
- throws MatrixIndexException, InvalidMatrixException {
- try {
- setRow(row, ((RealVectorImpl) vector).getDataRef());
- } catch (ClassCastException cce) {
- checkRowIndex(row);
- if (vector.getDimension() != columns) {
- throw new InvalidMatrixException(
- "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
- 1, vector.getDimension(), 1, columns);
- }
-
- // perform copy tile-wise, to ensure good cache behavior
- final int iTile = row / tileSizeRows;
- final int rowOffset = row - iTile * tileSizeRows;
- int outIndex = 0;
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- rowOffset * tileSizeColumns;
- final int length = Math.min(outIndex + tileSizeColumns, columns) - outIndex;
- for (int l = 0; l < length; ++l) {
- data[kStart + l] = vector.getEntry(outIndex + l);
- }
- outIndex += length;
- }
- }
- }
-
- /** {@inheritDoc} */
- public void setColumnVector(final int column, final RealVector vector)
- throws MatrixIndexException, InvalidMatrixException {
- try {
- setColumn(column, ((RealVectorImpl) vector).getDataRef());
- } catch (ClassCastException cce) {
- checkColumnIndex(column);
- if (vector.getDimension() != rows) {
- throw new InvalidMatrixException(
- "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
- vector.getDimension(), 1, rows, 1);
- }
-
- // perform copy tile-wise, to ensure good cache behavior
- final int jTile = column / tileSizeColumns;
- final int columnOffset = column - jTile * tileSizeColumns;
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- columnOffset;
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- data[k] = vector.getEntry(p);
- }
- }
- }
- }
-
- /** {@inheritDoc} */
- public double[] getRow(final int row)
- throws MatrixIndexException {
-
- checkRowIndex(row);
- final double[] out = new double[columns];
-
- // perform copy tile-wise, to ensure good cache behavior
- final int iTile = row / tileSizeRows;
- final int rowOffset = row - iTile * tileSizeRows;
- int outIndex = 0;
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- rowOffset * tileSizeColumns;
- final int length = Math.min(outIndex + tileSizeColumns, columns) - outIndex;
- System.arraycopy(data, kStart, out, outIndex, length);
- outIndex += length;
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public void setRow(final int row, final double[] array)
- throws MatrixIndexException, InvalidMatrixException {
-
- checkRowIndex(row);
- if (array.length != columns) {
- throw new InvalidMatrixException(
- "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
- 1, array.length, 1, columns);
- }
-
- // perform copy tile-wise, to ensure good cache behavior
- final int iTile = row / tileSizeRows;
- final int rowOffset = row - iTile * tileSizeRows;
- int outIndex = 0;
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- rowOffset * tileSizeColumns;
- final int length = Math.min(outIndex + tileSizeColumns, columns) - outIndex;
- System.arraycopy(array, outIndex, data, kStart, length);
- outIndex += length;
- }
-
- }
-
- /** {@inheritDoc} */
- public double[] getColumn(final int column)
- throws MatrixIndexException {
-
- checkColumnIndex(column);
- final double[] out = new double[rows];
-
- // perform copy tile-wise, to ensure good cache behavior
- final int jTile = column / tileSizeColumns;
- final int columnOffset = column - jTile * tileSizeColumns;
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- columnOffset;
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- out[p] = data[k];
- }
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public void setColumn(final int column, final double[] array)
- throws MatrixIndexException, InvalidMatrixException {
-
- checkColumnIndex(column);
- if (array.length != rows) {
- throw new InvalidMatrixException(
- "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
- array.length, 1, rows, 1);
- }
-
- // perform copy tile-wise, to ensure good cache behavior
- final int jTile = column / tileSizeColumns;
- final int columnOffset = column - jTile * tileSizeColumns;
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int kStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns +
- columnOffset;
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- data[k] = array[p];
- }
- }
-
- }
-
- /** {@inheritDoc} */
- public double getEntry(final int row, final int column)
- throws MatrixIndexException {
- if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
- throw new MatrixIndexException(
- "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
- row, column, getRowDimension(), getColumnDimension());
- }
- return data[index(row, column)];
- }
-
- /** {@inheritDoc} */
- public void setEntry(final int row, final int column, final double value)
- throws MatrixIndexException {
- if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
- throw new MatrixIndexException(
- "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
- row, column, getRowDimension(), getColumnDimension());
- }
- data[index(row, column)] = value;
- }
-
- /** {@inheritDoc} */
- public void addToEntry(final int row, final int column, final double increment)
- throws MatrixIndexException {
- if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
- throw new MatrixIndexException(
- "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
- row, column, getRowDimension(), getColumnDimension());
- }
- data[index(row, column)] += increment;
- }
-
- /** {@inheritDoc} */
- public void multiplyEntry(final int row, final int column, final double factor)
- throws MatrixIndexException {
- if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
- throw new MatrixIndexException(
- "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
- row, column, getRowDimension(), getColumnDimension());
- }
- data[index(row, column)] *= factor;
- }
-
- /** {@inheritDoc} */
- public RealMatrix transpose() {
-
- final RecursiveLayoutRealMatrix out = new RecursiveLayoutRealMatrix(columns, rows);
-
- // perform transpose tile-wise, to ensure good cache behavior
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int outJTile = (int) (indices >> 32); // iTile in the instance
- final int outITile = (int) (indices & 0xffffffff); // jTile in the instance
- final int outIndex = tileIndex(outITile, outJTile);
- final int outTileStart = outIndex * tileSizeRows * tileSizeColumns;
-
- // transpose current tile
- final int outPStart = outITile * tileSizeColumns;
- final int outPEnd = Math.min(outPStart + tileSizeColumns, columns);
- final int outQStart = outJTile * tileSizeRows;
- final int outQEnd = Math.min(outQStart + tileSizeRows, rows);
- for (int outP = outPStart; outP < outPEnd; ++outP) {
- final int dP = outP - outPStart;
- int k = outTileStart + dP * tileSizeRows;
- int l = tileStart + dP;
- for (int outQ = outQStart; outQ < outQEnd; ++outQ) {
- out.data[k++] = data[l];
- l+= tileSizeColumns;
- }
- }
-
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public int getRowDimension() {
- return rows;
- }
-
- /** {@inheritDoc} */
- public int getColumnDimension() {
- return columns;
- }
-
- /** {@inheritDoc} */
- public double[] operate(final double[] v)
- throws IllegalArgumentException {
-
- if (v.length != columns) {
- throw MathRuntimeException.createIllegalArgumentException(
- "vector length mismatch: got {0} but expected {1}",
- v.length, columns);
- }
- final double[] out = new double[rows];
-
- // perform multiplication tile-wise, to ensure good cache behavior
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int p = pStart, k = tileStart; p < pEnd; ++p) {
- double sum = 0;
- int q = qStart;
- while (q < qEnd - 3) {
- sum += data[k] * v[q] +
- data[k + 1] * v[q + 1] +
- data[k + 2] * v[q + 2] +
- data[k + 3] * v[q + 3];
- k += 4;
- q += 4;
- }
- while (q < qEnd) {
- sum += data[k++] * v[q++];
- }
- out[p] += sum;
- }
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public double[] preMultiply(final double[] v)
- throws IllegalArgumentException {
-
- if (v.length != rows) {
- throw MathRuntimeException.createIllegalArgumentException(
- "vector length mismatch: got {0} but expected {1}",
- v.length, rows);
- }
- final double[] out = new double[columns];
-
- final int offset1 = tileSizeColumns;
- final int offset2 = offset1 + offset1;
- final int offset3 = offset2 + offset1;
- final int offset4 = offset3 + offset1;
-
- // perform multiplication tile-wise, to ensure good cache behavior
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int q = qStart; q < qEnd; ++q) {
- int k = tileStart + q - qStart;
- double sum = 0;
- int p = pStart;
- while (p < pEnd - 3) {
- sum += data[k] * v[p] +
- data[k + offset1] * v[p + 1] +
- data[k + offset2] * v[p + 2] +
- data[k + offset3] * v[p + 3];
- k += offset4;
- p += 4;
- }
- while (p < pEnd) {
- sum += data[k] * v[p++];
- k += offset1;
- }
- out[q] += sum;
- }
- }
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- public double walkInRowOrder(final RealMatrixChangingVisitor visitor)
- throws MatrixVisitorException {
- visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- for (int p = pStart; p < pEnd; ++p) {
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (p - pStart) * tileSizeColumns;
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- data[k] = visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInRowOrder(final RealMatrixPreservingVisitor visitor)
- throws MatrixVisitorException {
- visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- for (int p = pStart; p < pEnd; ++p) {
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (p - pStart) * tileSizeColumns;
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException, MatrixVisitorException {
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
- visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
- for (int iTile = startRow / tileSizeRows; iTile < 1 + endRow / tileSizeRows; ++iTile) {
- final int p0 = iTile * tileSizeRows;
- final int pStart = Math.max(startRow, p0);
- final int pEnd = Math.min((iTile + 1) * tileSizeRows, 1 + endRow);
- for (int p = pStart; p < pEnd; ++p) {
- for (int jTile = startColumn / tileSizeColumns; jTile < 1 + endColumn / tileSizeColumns; ++jTile) {
- final int q0 = jTile * tileSizeColumns;
- final int qStart = Math.max(startColumn, q0);
- final int qEnd = Math.min((jTile + 1) * tileSizeColumns, 1 + endColumn);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (p - p0) * tileSizeColumns + (qStart - q0);
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- data[k] = visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException, MatrixVisitorException {
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
- visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
- for (int iTile = startRow / tileSizeRows; iTile < 1 + endRow / tileSizeRows; ++iTile) {
- final int p0 = iTile * tileSizeRows;
- final int pStart = Math.max(startRow, p0);
- final int pEnd = Math.min((iTile + 1) * tileSizeRows, 1 + endRow);
- for (int p = pStart; p < pEnd; ++p) {
- for (int jTile = startColumn / tileSizeColumns; jTile < 1 + endColumn / tileSizeColumns; ++jTile) {
- final int q0 = jTile * tileSizeColumns;
- final int qStart = Math.max(startColumn, q0);
- final int qEnd = Math.min((jTile + 1) * tileSizeColumns, 1 + endColumn);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (p - p0) * tileSizeColumns + (qStart - q0);
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInColumnOrder(final RealMatrixChangingVisitor visitor)
- throws MatrixVisitorException {
- visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int q = qStart; q < qEnd; ++q) {
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (q - qStart);
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- data[k] = visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor)
- throws MatrixVisitorException {
- visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int q = qStart; q < qEnd; ++q) {
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (q - qStart);
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException, MatrixVisitorException {
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
- visitor.start(getRowDimension(), getColumnDimension(),
- startRow, endRow, startColumn, endColumn);
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int q0 = jTile * tileSizeColumns;
- final int qStart = Math.max(startColumn, q0);
- final int qEnd = Math.min((jTile + 1) * tileSizeColumns, 1 + endColumn);
- for (int q = qStart; q < qEnd; ++q) {
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int p0 = iTile * tileSizeRows;
- final int pStart = Math.max(startRow, p0);
- final int pEnd = Math.min((iTile + 1) * tileSizeRows, 1 + endRow);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (pStart - p0) * tileSizeColumns + (q - q0);
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- data[k] = visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException, MatrixVisitorException {
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
- visitor.start(getRowDimension(), getColumnDimension(),
- startRow, endRow, startColumn, endColumn);
- for (int jTile = 0; jTile < tileNumber; ++jTile) {
- final int q0 = jTile * tileSizeColumns;
- final int qStart = Math.max(startColumn, q0);
- final int qEnd = Math.min((jTile + 1) * tileSizeColumns, 1 + endColumn);
- for (int q = qStart; q < qEnd; ++q) {
- for (int iTile = 0; iTile < tileNumber; ++iTile) {
- final int p0 = iTile * tileSizeRows;
- final int pStart = Math.max(startRow, p0);
- final int pEnd = Math.min((iTile + 1) * tileSizeRows, 1 + endRow);
- final int tileStart = tileIndex(iTile, jTile) *
- tileSizeRows * tileSizeColumns;
- final int kStart = tileStart + (pStart - p0) * tileSizeColumns + (q - q0);
- for (int p = pStart, k = kStart; p < pEnd; ++p, k += tileSizeColumns) {
- visitor.visit(p, q, data[k]);
- }
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor)
- throws MatrixVisitorException {
- visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int p = pStart; p < pEnd; ++p) {
- final int kStart = tileStart + (p - pStart) * tileSizeColumns;
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- data[k] = visitor.visit(p, q, data[k]);
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor)
- throws MatrixVisitorException {
- visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int pStart = iTile * tileSizeRows;
- final int pEnd = Math.min(pStart + tileSizeRows, rows);
- final int qStart = jTile * tileSizeColumns;
- final int qEnd = Math.min(qStart + tileSizeColumns, columns);
- for (int p = pStart; p < pEnd; ++p) {
- final int kStart = tileStart + (p - pStart) * tileSizeColumns;
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- visitor.visit(p, q, data[k]);
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException, MatrixVisitorException {
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
- visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int p0 = iTile * tileSizeRows;
- final int pStart = Math.max(startRow, p0);
- final int pEnd = Math.min((iTile + 1) * tileSizeRows, 1 + endRow);
- final int q0 = jTile * tileSizeColumns;
- final int qStart = Math.max(startColumn, q0);
- final int qEnd = Math.min((jTile + 1) * tileSizeColumns, 1 + endColumn);
- for (int p = pStart; p < pEnd; ++p) {
- final int kStart = tileStart + (p - p0) * tileSizeColumns + (qStart - q0);
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- data[k] = visitor.visit(p, q, data[k]);
- }
- }
- }
- return visitor.end();
- }
-
- /** {@inheritDoc} */
- public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn)
- throws MatrixIndexException, MatrixVisitorException {
- checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
- visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
- for (int index = 0; index < tileNumber * tileNumber; ++index) {
- final int tileStart = index * tileSizeRows * tileSizeColumns;
- final long indices = tilesIndices(index);
- final int iTile = (int) (indices >> 32);
- final int jTile = (int) (indices & 0xffffffff);
- final int p0 = iTile * tileSizeRows;
- final int pStart = Math.max(startRow, p0);
- final int pEnd = Math.min((iTile + 1) * tileSizeRows, 1 + endRow);
- final int q0 = jTile * tileSizeColumns;
- final int qStart = Math.max(startColumn, q0);
- final int qEnd = Math.min((jTile + 1) * tileSizeColumns, 1 + endColumn);
- for (int p = pStart; p < pEnd; ++p) {
- final int kStart = tileStart + (p - p0) * tileSizeColumns + (qStart - q0);
- for (int q = qStart, k = kStart; q < qEnd; ++q, ++k) {
- visitor.visit(p, q, data[k]);
- }
- }
- }
- return visitor.end();
- }
-
- /**
- * Get the index of an element.
- * @param row row index of the element
- * @param column column index of the element
- * @return index of the element
- */
- private int index(final int row, final int columns) {
- final int iTile = row / tileSizeRows;
- final int jTile = columns / tileSizeColumns;
- final int tileStart = tileIndex(iTile, jTile) * tileSizeRows * tileSizeColumns;
- final int indexInTile = (row % tileSizeRows) * tileSizeColumns +
- (columns % tileSizeColumns);
- return tileStart + indexInTile;
- }
-
- /**
- * Get the index of a tile.
- * @param iTile row index of the tile
- * @param jTile column index of the tile
- * @return index of the tile
- */
- private static int tileIndex(int iTile, int jTile) {
-
- // compute n = 2^k such that a nxn square contains the indices
- int n = Integer.highestOneBit(Math.max(iTile, jTile)) << 1;
-
- // start recursion by noting the index is somewhere in the nxn
- // square whose lowest index is 0 and which has direct orientation
- int lowIndex = 0;
- boolean direct = true;
-
- // the tail-recursion on the square size is replaced by an iteration here
- while (n > 1) {
-
- // reduce square to 4 quadrants
- n >>= 1;
- final int n2 = n * n;
-
- // check in which quadrant the element is,
- // updating the lowest index of the quadrant and its orientation
- if (iTile < n) {
- if (jTile < n) {
- // the element is in the top-left quadrant
- if (!direct) {
- lowIndex += 2 * n2;
- direct = true;
- }
- } else {
- // the element is in the top-right quadrant
- jTile -= n;
- if (direct) {
- lowIndex += n2;
- direct = false;
- } else {
- lowIndex += 3 * n2;
- }
- }
- } else {
- iTile -= n;
- if (jTile < n) {
- // the element is in the bottom-left quadrant
- if (direct) {
- lowIndex += 3 * n2;
- } else {
- lowIndex += n2;
- direct = true;
- }
- } else {
- // the element is in the bottom-right quadrant
- jTile -= n;
- if (direct) {
- lowIndex += 2 * n2;
- direct = false;
- }
- }
- }
- }
-
- // the lowest index of the remaining 1x1 quadrant is the requested index
- return lowIndex;
-
- }
-
- /**
- * Get the row and column tile indices of a tile.
- * @param index index of the tile in the layout
- * @return row and column indices packed in one long (row tile index
- * in 32 high order bits, column tile index in low order bits)
- */
- private static long tilesIndices(int index) {
-
- // compute n = 2^k such that a nxn square contains the index
- int n = Integer.highestOneBit((int) Math.sqrt(index)) << 1;
-
- // start recursion by noting the index is somewhere in the nxn
- // square whose lowest index is 0 and which has direct orientation
- int iLow = 0;
- int jLow = 0;
- boolean direct = true;
-
- // the tail-recursion on the square size is replaced by an iteration here
- while (n > 1) {
-
- // reduce square to 4 quadrants
- n >>= 1;
- final int n2 = n * n;
-
- // check in which quadrant the element is,
- // updating the low indices of the quadrant and its orientation
- switch (index / n2) {
- case 0 :
- if (!direct) {
- iLow += n;
- jLow += n;
- }
- break;
- case 1 :
- if (direct) {
- jLow += n;
- } else {
- iLow += n;
- }
- index -= n2;
- direct = !direct;
- break;
- case 2 :
- if (direct) {
- iLow += n;
- jLow += n;
- }
- index -= 2 * n2;
- direct = !direct;
- break;
- default :
- if (direct) {
- iLow += n;
- } else {
- jLow += n;
- }
- index -= 3 * n2;
- }
-
- }
-
- // the lowest indices of the remaining 1x1 quadrant are the requested indices
- return (((long) iLow) << 32) | (long) jLow;
-
- }
-
- /**
- * Compute the power of two number of tiles for a matrix.
- * @param rows number of rows
- * @param columns number of columns
- * @return power of two number of tiles
- */
- private static int tilesNumber(final int rows, final int columns) {
-
- // find the minimal number of tiles, given that one double variable is 8 bytes
- final int nbElements = rows * columns;
- final int maxElementsPerTile = MAX_TILE_SIZE_BYTES / 8;
- final int minTiles = nbElements / maxElementsPerTile;
-
- // the number of tiles must be a 2^k x 2^k square
- int twoK = 1;
- for (int nTiles = minTiles; nTiles != 0; nTiles >>= 2) {
- twoK <<= 1;
- }
-
- // make sure the tiles have at least one row and one column each
- // (this may lead to tile sizes greater than MAX_BLOCK_SIZE_BYTES,
- // in degenerate cases like a 3000x1 matrix)
- while (twoK > Math.min(rows, columns)) {
- twoK >>= 1;
- }
-
- return twoK;
-
- }
-
- /**
- * Compute optimal tile size for a row or column count.
- * @param count row or column count
- * @param twoK optimal tile number (must be a power of 2)
- * @return optimal tile size
- */
- private static int tileSize(final int count, final int twoK) {
- return (count + twoK - 1) / twoK;
- }
-
-}
diff --git a/src/experimental/org/apache/commons/math/linear/RecursiveLayoutRealMatrixTest.java b/src/experimental/org/apache/commons/math/linear/RecursiveLayoutRealMatrixTest.java
deleted file mode 100644
index 2e87190..0000000
--- a/src/experimental/org/apache/commons/math/linear/RecursiveLayoutRealMatrixTest.java
+++ /dev/null
@@ -1,1242 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.linear;
-
-import java.util.Arrays;
-import java.util.Random;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test cases for the {@link RecursiveLayoutRealMatrix} class.
- *
- * @version $Revision$ $Date$
- */
-
-public final class RecursiveLayoutRealMatrixTest extends TestCase {
-
- // 3 x 3 identity matrix
- protected double[][] id = { {1d,0d,0d}, {0d,1d,0d}, {0d,0d,1d} };
-
- // Test data for group operations
- protected double[][] testData = { {1d,2d,3d}, {2d,5d,3d}, {1d,0d,8d} };
- protected double[][] testDataLU = {{2d, 5d, 3d}, {.5d, -2.5d, 6.5d}, {0.5d, 0.2d, .2d}};
- protected double[][] testDataPlus2 = { {3d,4d,5d}, {4d,7d,5d}, {3d,2d,10d} };
- protected double[][] testDataMinus = { {-1d,-2d,-3d}, {-2d,-5d,-3d},
- {-1d,0d,-8d} };
- protected double[] testDataRow1 = {1d,2d,3d};
- protected double[] testDataCol3 = {3d,3d,8d};
- protected double[][] testDataInv =
- { {-40d,16d,9d}, {13d,-5d,-3d}, {5d,-2d,-1d} };
- protected double[] preMultTest = {8,12,33};
- protected double[][] testData2 ={ {1d,2d,3d}, {2d,5d,3d}};
- protected double[][] testData2T = { {1d,2d}, {2d,5d}, {3d,3d}};
- protected double[][] testDataPlusInv =
- { {-39d,18d,12d}, {15d,0d,0d}, {6d,-2d,7d} };
-
- // lu decomposition tests
- protected double[][] luData = { {2d,3d,3d}, {0d,5d,7d}, {6d,9d,8d} };
- protected double[][] luDataLUDecomposition = { {6d,9d,8d}, {0d,5d,7d},
- {0.33333333333333,0d,0.33333333333333} };
-
- // singular matrices
- protected double[][] singular = { {2d,3d}, {2d,3d} };
- protected double[][] bigSingular = {{1d,2d,3d,4d}, {2d,5d,3d,4d},
- {7d,3d,256d,1930d}, {3d,7d,6d,8d}}; // 4th row = 1st + 2nd
- protected double[][] detData = { {1d,2d,3d}, {4d,5d,6d}, {7d,8d,10d} };
- protected double[][] detData2 = { {1d, 3d}, {2d, 4d}};
-
- // vectors
- protected double[] testVector = {1,2,3};
- protected double[] testVector2 = {1,2,3,4};
-
- // submatrix accessor tests
- protected double[][] subTestData = {{1, 2, 3, 4}, {1.5, 2.5, 3.5, 4.5},
- {2, 4, 6, 8}, {4, 5, 6, 7}};
- // array selections
- protected double[][] subRows02Cols13 = { {2, 4}, {4, 8}};
- protected double[][] subRows03Cols12 = { {2, 3}, {5, 6}};
- protected double[][] subRows03Cols123 = { {2, 3, 4} , {5, 6, 7}};
- // effective permutations
- protected double[][] subRows20Cols123 = { {4, 6, 8} , {2, 3, 4}};
- protected double[][] subRows31Cols31 = {{7, 5}, {4.5, 2.5}};
- // contiguous ranges
- protected double[][] subRows01Cols23 = {{3,4} , {3.5, 4.5}};
- protected double[][] subRows23Cols00 = {{2} , {4}};
- protected double[][] subRows00Cols33 = {{4}};
- // row matrices
- protected double[][] subRow0 = {{1,2,3,4}};
- protected double[][] subRow3 = {{4,5,6,7}};
- // column matrices
- protected double[][] subColumn1 = {{2}, {2.5}, {4}, {5}};
- protected double[][] subColumn3 = {{4}, {4.5}, {8}, {7}};
-
- // tolerances
- protected double entryTolerance = 10E-16;
- protected double normTolerance = 10E-14;
-
- public RecursiveLayoutRealMatrixTest(String name) {
- super(name);
- }
-
- public void setUp() {
-
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(RecursiveLayoutRealMatrixTest.class);
- suite.setName("RecursiveLayoutRealMatrix Tests");
- return suite;
- }
-
- /** test dimensions */
- public void testDimensions() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(testData2);
- assertEquals("testData row dimension",3,m.getRowDimension());
- assertEquals("testData column dimension",3,m.getColumnDimension());
- assertTrue("testData is square",m.isSquare());
- assertEquals("testData2 row dimension",m2.getRowDimension(),2);
- assertEquals("testData2 column dimension",m2.getColumnDimension(),3);
- assertTrue("testData2 is not square",!m2.isSquare());
- }
-
- /** test copy functions */
- public void testCopyFunctions() {
- Random r = new Random(66636328996002l);
- RecursiveLayoutRealMatrix m1 = createRandomMatrix(r, 47, 83);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(m1.getData());
- assertEquals(m1, m2);
- RecursiveLayoutRealMatrix m3 = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m4 = new RecursiveLayoutRealMatrix(m3.getData());
- assertEquals(m3, m4);
- }
-
- /** test add */
- public void testAdd() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix mInv = new RecursiveLayoutRealMatrix(testDataInv);
- RealMatrix mPlusMInv = m.add(mInv);
- double[][] sumEntries = mPlusMInv.getData();
- for (int row = 0; row < m.getRowDimension(); row++) {
- for (int col = 0; col < m.getColumnDimension(); col++) {
- assertEquals("sum entry entry",
- testDataPlusInv[row][col],sumEntries[row][col],
- entryTolerance);
- }
- }
- }
-
- /** test add failure */
- public void testAddFail() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(testData2);
- try {
- m.add(m2);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ex) {
- ;
- }
- }
-
- /** test norm */
- public void testNorm() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(testData2);
- assertEquals("testData norm",14d,m.getNorm(),entryTolerance);
- assertEquals("testData2 norm",7d,m2.getNorm(),entryTolerance);
- }
-
- /** test Frobenius norm */
- public void testFrobeniusNorm() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(testData2);
- assertEquals("testData Frobenius norm", Math.sqrt(117.0), m.getFrobeniusNorm(), entryTolerance);
- assertEquals("testData2 Frobenius norm", Math.sqrt(52.0), m2.getFrobeniusNorm(), entryTolerance);
- }
-
- /** test m-n = m + -n */
- public void testPlusMinus() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(testDataInv);
- assertClose(m.subtract(m2), m2.scalarMultiply(-1d).add(m), entryTolerance);
- try {
- m.subtract(new RecursiveLayoutRealMatrix(testData2));
- fail("Expecting illegalArgumentException");
- } catch (IllegalArgumentException ex) {
- ;
- }
- }
-
- /** test multiply */
- public void testMultiply() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix mInv = new RecursiveLayoutRealMatrix(testDataInv);
- RecursiveLayoutRealMatrix identity = new RecursiveLayoutRealMatrix(id);
- RecursiveLayoutRealMatrix m2 = new RecursiveLayoutRealMatrix(testData2);
- assertClose(m.multiply(mInv), identity, entryTolerance);
- assertClose(mInv.multiply(m), identity, entryTolerance);
- assertClose(m.multiply(identity), m, entryTolerance);
- assertClose(identity.multiply(mInv), mInv, entryTolerance);
- assertClose(m2.multiply(identity), m2, entryTolerance);
- try {
- m.multiply(new RecursiveLayoutRealMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-
- public void testSeveralBlocks() {
-
- RealMatrix m = new RecursiveLayoutRealMatrix(35, 71);
- for (int i = 0; i < m.getRowDimension(); ++i) {
- for (int j = 0; j < m.getColumnDimension(); ++j) {
- m.setEntry(i, j, i + j / 1024.0);
- }
- }
-
- RealMatrix mT = m.transpose();
- assertEquals(m.getRowDimension(), mT.getColumnDimension());
- assertEquals(m.getColumnDimension(), mT.getRowDimension());
- for (int i = 0; i < mT.getRowDimension(); ++i) {
- for (int j = 0; j < mT.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(j, i), mT.getEntry(i, j), 0);
- }
- }
-
- RealMatrix mPm = m.add(m);
- for (int i = 0; i < mPm.getRowDimension(); ++i) {
- for (int j = 0; j < mPm.getColumnDimension(); ++j) {
- assertEquals(2 * m.getEntry(i, j), mPm.getEntry(i, j), 0);
- }
- }
-
- RealMatrix mPmMm = mPm.subtract(m);
- for (int i = 0; i < mPmMm.getRowDimension(); ++i) {
- for (int j = 0; j < mPmMm.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(i, j), mPmMm.getEntry(i, j), 0);
- }
- }
-
- RealMatrix mTm = mT.multiply(m);
- for (int i = 0; i < mTm.getRowDimension(); ++i) {
- for (int j = 0; j < mTm.getColumnDimension(); ++j) {
- double sum = 0;
- for (int k = 0; k < mT.getColumnDimension(); ++k) {
- sum += (k + i / 1024.0) * (k + j / 1024.0);
- }
- assertEquals(sum, mTm.getEntry(i, j), 0);
- }
- }
-
- RealMatrix mmT = m.multiply(mT);
- for (int i = 0; i < mmT.getRowDimension(); ++i) {
- for (int j = 0; j < mmT.getColumnDimension(); ++j) {
- double sum = 0;
- for (int k = 0; k < m.getColumnDimension(); ++k) {
- sum += (i + k / 1024.0) * (j + k / 1024.0);
- }
- assertEquals(sum, mmT.getEntry(i, j), 0);
- }
- }
-
- RealMatrix sub1 = m.getSubMatrix(2, 9, 5, 20);
- for (int i = 0; i < sub1.getRowDimension(); ++i) {
- for (int j = 0; j < sub1.getColumnDimension(); ++j) {
- assertEquals((i + 2) + (j + 5) / 1024.0, sub1.getEntry(i, j), 0);
- }
- }
-
- RealMatrix sub2 = m.getSubMatrix(10, 12, 3, 70);
- for (int i = 0; i < sub2.getRowDimension(); ++i) {
- for (int j = 0; j < sub2.getColumnDimension(); ++j) {
- assertEquals((i + 10) + (j + 3) / 1024.0, sub2.getEntry(i, j), 0);
- }
- }
-
- RealMatrix sub3 = m.getSubMatrix(30, 34, 0, 5);
- for (int i = 0; i < sub3.getRowDimension(); ++i) {
- for (int j = 0; j < sub3.getColumnDimension(); ++j) {
- assertEquals((i + 30) + (j + 0) / 1024.0, sub3.getEntry(i, j), 0);
- }
- }
-
- RealMatrix sub4 = m.getSubMatrix(30, 32, 62, 65);
- for (int i = 0; i < sub4.getRowDimension(); ++i) {
- for (int j = 0; j < sub4.getColumnDimension(); ++j) {
- assertEquals((i + 30) + (j + 62) / 1024.0, sub4.getEntry(i, j), 0);
- }
- }
-
- }
-
- //Additional Test for RecursiveLayoutRealMatrixTest.testMultiply
-
- private double[][] d3 = new double[][] {{1,2,3,4},{5,6,7,8}};
- private double[][] d4 = new double[][] {{1},{2},{3},{4}};
- private double[][] d5 = new double[][] {{30},{70}};
-
- public void testMultiply2() {
- RealMatrix m3 = new RecursiveLayoutRealMatrix(d3);
- RealMatrix m4 = new RecursiveLayoutRealMatrix(d4);
- RealMatrix m5 = new RecursiveLayoutRealMatrix(d5);
- assertClose(m3.multiply(m4), m5, entryTolerance);
- }
-
- /** test trace */
- public void testTrace() {
- RealMatrix m = new RecursiveLayoutRealMatrix(id);
- assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
- m = new RecursiveLayoutRealMatrix(testData2);
- try {
- m.getTrace();
- fail("Expecting NonSquareMatrixException");
- } catch (NonSquareMatrixException ex) {
- ;
- }
- }
-
- /** test scalarAdd */
- public void testScalarAdd() {
- RealMatrix m = new RecursiveLayoutRealMatrix(testData);
- assertClose(new RecursiveLayoutRealMatrix(testDataPlus2), m.scalarAdd(2d), entryTolerance);
- }
-
- /** test operate */
- public void testOperate() {
- RealMatrix m = new RecursiveLayoutRealMatrix(id);
- assertClose(testVector, m.operate(testVector), entryTolerance);
- assertClose(testVector, m.operate(new RealVectorImpl(testVector)).getData(), entryTolerance);
- m = new RecursiveLayoutRealMatrix(bigSingular);
- try {
- m.operate(testVector);
- fail("Expecting illegalArgumentException");
- } catch (IllegalArgumentException ex) {
- ;
- }
- }
-
- public void testMultiplyMedium() {
- RealMatrix m1 = new RecursiveLayoutRealMatrix(
- new double[][] {
- { 80, 45, 13, 77, -82 },
- { -90, 33, 98, 80, 74 },
- { 24, -37, 36, -8, -69 },
- { -74, 2, 32, -67, -65 },
- { -29, -81, 44, 54, -65 },
- { 17, 58, -36, -98, 25 },
- { 48, -64, -95, -75, 34 }
- });
- RealMatrix m2 = new RecursiveLayoutRealMatrix(
- new double[][] {
- { 81, 58, 70, 18, 5, -57 },
- { -54, 33, 87, 68, -22, 73 },
- { -78, -5, 34, -7, -3, -31 },
- { -16, -82, -68, 7, 10, -47 },
- { 51, 4, 92, 15, 32, -51 }
- });
- RealMatrix m1m2 = m1.multiply(m2);
- RealMatrix reference = new RecursiveLayoutRealMatrix(
- new double[][]{
- { -2378, -582, -2823, 3718, -2483, -1115 },
- { -14222, -10885, 1271, 1608, 1698, -3033 },
- { -2257, 371, -6119, -3427, -1462, -1290 },
- { -10841, 848, -5342, -2864, -3260, 9836 },
- { -5586, -9263, -17233, -6935, -35, -4847 },
- { 3896, 11216, 13976, 4191, -1263, 7712 },
- { 17688, 7433, 2790, -2838, 2271, -2672 }
- });
- assertEquals(0, m1m2.subtract(reference).getNorm(), 0.0);
- }
-
- public void testOperateLarge() {
- int testBlockSize = 64;
- int p = (7 * testBlockSize) / 2;
- int q = (5 * testBlockSize) / 2;
- int r = 3 * testBlockSize;
- Random random = new Random(111007463902334l);
- RealMatrix m1 = createRandomMatrix(random, p, q);
- RealMatrix m2 = createRandomMatrix(random, q, r);
- RealMatrix m1m2 = m1.multiply(m2);
- for (int i = 0; i < r; ++i) {
- checkArrays(m1m2.getColumn(i), m1.operate(m2.getColumn(i)));
- }
- }
-
- public void testOperatePremultiplyLarge() {
- int testBlockSize = 64;
- int p = (7 * testBlockSize) / 2;
- int q = (5 * testBlockSize) / 2;
- int r = 3 * testBlockSize;
- Random random = new Random(111007463902334l);
- RealMatrix m1 = createRandomMatrix(random, p, q);
- RealMatrix m2 = createRandomMatrix(random, q, r);
- RealMatrix m1m2 = m1.multiply(m2);
- for (int i = 0; i < p; ++i) {
- checkArrays(m1m2.getRow(i), m2.preMultiply(m1.getRow(i)));
- }
- }
-
- /** test issue MATH-209 */
- public void testMath209() {
- RealMatrix a = new RecursiveLayoutRealMatrix(new double[][] {
- { 1, 2 }, { 3, 4 }, { 5, 6 }
- });
- double[] b = a.operate(new double[] { 1, 1 });
- assertEquals(a.getRowDimension(), b.length);
- assertEquals( 3.0, b[0], 1.0e-12);
- assertEquals( 7.0, b[1], 1.0e-12);
- assertEquals(11.0, b[2], 1.0e-12);
- }
-
- /** test transpose */
- public void testTranspose() {
- RealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
- RealMatrix mTI = new LUDecompositionImpl(m.transpose()).getSolver().getInverse();
- assertClose(mIT, mTI, normTolerance);
- m = new RecursiveLayoutRealMatrix(testData2);
- RealMatrix mt = new RecursiveLayoutRealMatrix(testData2T);
- assertClose(mt, m.transpose(), normTolerance);
- }
-
- /** test preMultiply by vector */
- public void testPremultiplyVector() {
- RealMatrix m = new RecursiveLayoutRealMatrix(testData);
- assertClose(m.preMultiply(testVector), preMultTest, normTolerance);
- assertClose(m.preMultiply(new RealVectorImpl(testVector).getData()),
- preMultTest, normTolerance);
- m = new RecursiveLayoutRealMatrix(bigSingular);
- try {
- m.preMultiply(testVector);
- fail("expecting IllegalArgumentException");
- } catch (IllegalArgumentException ex) {
- ;
- }
- }
-
- public void testPremultiply() {
- RealMatrix m3 = new RecursiveLayoutRealMatrix(d3);
- RealMatrix m4 = new RecursiveLayoutRealMatrix(d4);
- RealMatrix m5 = new RecursiveLayoutRealMatrix(d5);
- assertClose(m4.preMultiply(m3), m5, entryTolerance);
-
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix mInv = new RecursiveLayoutRealMatrix(testDataInv);
- RecursiveLayoutRealMatrix identity = new RecursiveLayoutRealMatrix(id);
- assertClose(m.preMultiply(mInv), identity, entryTolerance);
- assertClose(mInv.preMultiply(m), identity, entryTolerance);
- assertClose(m.preMultiply(identity), m, entryTolerance);
- assertClose(identity.preMultiply(mInv), mInv, entryTolerance);
- try {
- m.preMultiply(new RecursiveLayoutRealMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
- } catch (IllegalArgumentException ex) {
- ;
- }
- }
-
- public void testGetVectors() {
- RealMatrix m = new RecursiveLayoutRealMatrix(testData);
- assertClose(m.getRow(0), testDataRow1, entryTolerance);
- assertClose(m.getColumn(2), testDataCol3, entryTolerance);
- try {
- m.getRow(10);
- fail("expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- ;
- }
- try {
- m.getColumn(-1);
- fail("expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- ;
- }
- }
-
- public void testGetEntry() {
- RealMatrix m = new RecursiveLayoutRealMatrix(testData);
- assertEquals("get entry",m.getEntry(0,1),2d,entryTolerance);
- try {
- m.getEntry(10, 4);
- fail ("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- /** test examples in user guide */
- public void testExamples() {
- // Create a real matrix with two rows and three columns
- double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
- RealMatrix m = new RecursiveLayoutRealMatrix(matrixData);
- // One more with three rows, two columns
- double[][] matrixData2 = { {1d,2d}, {2d,5d}, {1d, 7d}};
- RealMatrix n = new RecursiveLayoutRealMatrix(matrixData2);
- // Now multiply m by n
- RealMatrix p = m.multiply(n);
- assertEquals(2, p.getRowDimension());
- assertEquals(2, p.getColumnDimension());
- // Invert p
- RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
- assertEquals(2, pInverse.getRowDimension());
- assertEquals(2, pInverse.getColumnDimension());
-
- // Solve example
- double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
- RealMatrix coefficients = new RecursiveLayoutRealMatrix(coefficientsData);
- double[] constants = {1, -2, 1};
- double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
- assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12);
- assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1], 1E-12);
- assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2], 1E-12);
-
- }
-
- // test submatrix accessors
- public void testGetSubMatrix() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false);
- checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false);
- checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false);
- checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false);
- checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false);
- checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false);
- checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false);
- checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false);
- checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false);
- checkGetSubMatrix(m, null, 1, 0, 2, 4, true);
- checkGetSubMatrix(m, null, -1, 1, 2, 2, true);
- checkGetSubMatrix(m, null, 1, 0, 2, 2, true);
- checkGetSubMatrix(m, null, 1, 0, 2, 4, true);
- checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true);
- checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true);
- }
-
- private void checkGetSubMatrix(RealMatrix m, double[][] reference,
- int startRow, int endRow, int startColumn, int endColumn,
- boolean mustFail) {
- try {
- RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
- assertEquals(new RecursiveLayoutRealMatrix(reference), sub);
- if (mustFail) {
- fail("Expecting MatrixIndexException");
- }
- } catch (MatrixIndexException e) {
- if (!mustFail) {
- throw e;
- }
- }
- }
-
- private void checkGetSubMatrix(RealMatrix m, double[][] reference,
- int[] selectedRows, int[] selectedColumns,
- boolean mustFail) {
- try {
- RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
- assertEquals(new RecursiveLayoutRealMatrix(reference), sub);
- if (mustFail) {
- fail("Expecting MatrixIndexException");
- }
- } catch (MatrixIndexException e) {
- if (!mustFail) {
- throw e;
- }
- }
- }
-
- public void testGetSetMatrixLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- RealMatrix sub = new RecursiveLayoutRealMatrix(n - 4, n - 4).scalarAdd(1);
-
- m.setSubMatrix(sub.getData(), 2, 2);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if ((i < 2) || (i > n - 3) || (j < 2) || (j > n - 3)) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- assertEquals(sub, m.getSubMatrix(2, n - 3, 2, n - 3));
-
- }
-
- public void testCopySubMatrix() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false);
- checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false);
- checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false);
- checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false);
- checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false);
- checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false);
- checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false);
- checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false);
- checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false);
-
- checkCopy(m, null, 1, 0, 2, 4, true);
- checkCopy(m, null, -1, 1, 2, 2, true);
- checkCopy(m, null, 1, 0, 2, 2, true);
- checkCopy(m, null, 1, 0, 2, 4, true);
- checkCopy(m, null, new int[] {}, new int[] { 0 }, true);
- checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true);
- }
-
- private void checkCopy(RealMatrix m, double[][] reference,
- int startRow, int endRow, int startColumn, int endColumn,
- boolean mustFail) {
- try {
- double[][] sub = (reference == null) ?
- new double[1][1] :
- new double[reference.length][reference[0].length];
- m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
- assertEquals(new RecursiveLayoutRealMatrix(reference), new RecursiveLayoutRealMatrix(sub));
- if (mustFail) {
- fail("Expecting MatrixIndexException");
- }
- } catch (MatrixIndexException e) {
- if (!mustFail) {
- throw e;
- }
- }
- }
-
- private void checkCopy(RealMatrix m, double[][] reference,
- int[] selectedRows, int[] selectedColumns,
- boolean mustFail) {
- try {
- double[][] sub = (reference == null) ?
- new double[1][1] :
- new double[reference.length][reference[0].length];
- m.copySubMatrix(selectedRows, selectedColumns, sub);
- assertEquals(new RecursiveLayoutRealMatrix(reference), new RecursiveLayoutRealMatrix(sub));
- if (mustFail) {
- fail("Expecting MatrixIndexException");
- }
- } catch (MatrixIndexException e) {
- if (!mustFail) {
- throw e;
- }
- }
- }
-
- public void testGetRowMatrix() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealMatrix mRow0 = new RecursiveLayoutRealMatrix(subRow0);
- RealMatrix mRow3 = new RecursiveLayoutRealMatrix(subRow3);
- assertEquals("Row0", mRow0, m.getRowMatrix(0));
- assertEquals("Row3", mRow3, m.getRowMatrix(3));
- try {
- m.getRowMatrix(-1);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.getRowMatrix(4);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- public void testSetRowMatrix() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealMatrix mRow3 = new RecursiveLayoutRealMatrix(subRow3);
- assertNotSame(mRow3, m.getRowMatrix(0));
- m.setRowMatrix(0, mRow3);
- assertEquals(mRow3, m.getRowMatrix(0));
- try {
- m.setRowMatrix(-1, mRow3);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.setRowMatrix(0, m);
- fail("Expecting InvalidMatrixException");
- } catch (InvalidMatrixException ex) {
- // expected
- }
- }
-
- public void testGetSetRowMatrixLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- RealMatrix sub = new RecursiveLayoutRealMatrix(1, n).scalarAdd(1);
-
- m.setRowMatrix(2, sub);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (i != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- assertEquals(sub, m.getRowMatrix(2));
-
- }
-
- public void testGetColumnMatrix() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealMatrix mColumn1 = new RecursiveLayoutRealMatrix(subColumn1);
- RealMatrix mColumn3 = new RecursiveLayoutRealMatrix(subColumn3);
- assertEquals(mColumn1, m.getColumnMatrix(1));
- assertEquals(mColumn3, m.getColumnMatrix(3));
- try {
- m.getColumnMatrix(-1);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.getColumnMatrix(4);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- public void testSetColumnMatrix() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealMatrix mColumn3 = new RecursiveLayoutRealMatrix(subColumn3);
- assertNotSame(mColumn3, m.getColumnMatrix(1));
- m.setColumnMatrix(1, mColumn3);
- assertEquals(mColumn3, m.getColumnMatrix(1));
- try {
- m.setColumnMatrix(-1, mColumn3);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.setColumnMatrix(0, m);
- fail("Expecting InvalidMatrixException");
- } catch (InvalidMatrixException ex) {
- // expected
- }
- }
-
- public void testGetSetColumnMatrixLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- RealMatrix sub = new RecursiveLayoutRealMatrix(n, 1).scalarAdd(1);
-
- m.setColumnMatrix(2, sub);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (j != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- assertEquals(sub, m.getColumnMatrix(2));
-
- }
-
- public void testGetRowVector() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealVector mRow0 = new RealVectorImpl(subRow0[0]);
- RealVector mRow3 = new RealVectorImpl(subRow3[0]);
- assertEquals(mRow0, m.getRowVector(0));
- assertEquals(mRow3, m.getRowVector(3));
- try {
- m.getRowVector(-1);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.getRowVector(4);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- public void testSetRowVector() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealVector mRow3 = new RealVectorImpl(subRow3[0]);
- assertNotSame(mRow3, m.getRowMatrix(0));
- m.setRowVector(0, mRow3);
- assertEquals(mRow3, m.getRowVector(0));
- try {
- m.setRowVector(-1, mRow3);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.setRowVector(0, new RealVectorImpl(5));
- fail("Expecting InvalidMatrixException");
- } catch (InvalidMatrixException ex) {
- // expected
- }
- }
-
- public void testGetSetRowVectorLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- RealVector sub = new RealVectorImpl(n, 1.0);
-
- m.setRowVector(2, sub);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (i != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- assertEquals(sub, m.getRowVector(2));
-
- }
-
- public void testGetColumnVector() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealVector mColumn1 = columnToVector(subColumn1);
- RealVector mColumn3 = columnToVector(subColumn3);
- assertEquals(mColumn1, m.getColumnVector(1));
- assertEquals(mColumn3, m.getColumnVector(3));
- try {
- m.getColumnVector(-1);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.getColumnVector(4);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- public void testSetColumnVector() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- RealVector mColumn3 = columnToVector(subColumn3);
- assertNotSame(mColumn3, m.getColumnVector(1));
- m.setColumnVector(1, mColumn3);
- assertEquals(mColumn3, m.getColumnVector(1));
- try {
- m.setColumnVector(-1, mColumn3);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.setColumnVector(0, new RealVectorImpl(5));
- fail("Expecting InvalidMatrixException");
- } catch (InvalidMatrixException ex) {
- // expected
- }
- }
-
- public void testGetSetColumnVectorLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- RealVector sub = new RealVectorImpl(n, 1.0);
-
- m.setColumnVector(2, sub);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (j != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- assertEquals(sub, m.getColumnVector(2));
-
- }
-
- private RealVector columnToVector(double[][] column) {
- double[] data = new double[column.length];
- for (int i = 0; i < data.length; ++i) {
- data[i] = column[i][0];
- }
- return new RealVectorImpl(data, false);
- }
-
- public void testGetRow() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- checkArrays(subRow0[0], m.getRow(0));
- checkArrays(subRow3[0], m.getRow(3));
- try {
- m.getRow(-1);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.getRow(4);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- public void testSetRow() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- assertTrue(subRow3[0][0] != m.getRow(0)[0]);
- m.setRow(0, subRow3[0]);
- checkArrays(subRow3[0], m.getRow(0));
- try {
- m.setRow(-1, subRow3[0]);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.setRow(0, new double[5]);
- fail("Expecting InvalidMatrixException");
- } catch (InvalidMatrixException ex) {
- // expected
- }
- }
-
- public void testGetSetRowLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- double[] sub = new double[n];
- Arrays.fill(sub, 1.0);
-
- m.setRow(2, sub);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (i != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- checkArrays(sub, m.getRow(2));
-
- }
-
- public void testGetColumn() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- double[] mColumn1 = columnToArray(subColumn1);
- double[] mColumn3 = columnToArray(subColumn3);
- checkArrays(mColumn1, m.getColumn(1));
- checkArrays(mColumn3, m.getColumn(3));
- try {
- m.getColumn(-1);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.getColumn(4);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- }
-
- public void testSetColumn() {
- RealMatrix m = new RecursiveLayoutRealMatrix(subTestData);
- double[] mColumn3 = columnToArray(subColumn3);
- assertTrue(mColumn3[0] != m.getColumn(1)[0]);
- m.setColumn(1, mColumn3);
- checkArrays(mColumn3, m.getColumn(1));
- try {
- m.setColumn(-1, mColumn3);
- fail("Expecting MatrixIndexException");
- } catch (MatrixIndexException ex) {
- // expected
- }
- try {
- m.setColumn(0, new double[5]);
- fail("Expecting InvalidMatrixException");
- } catch (InvalidMatrixException ex) {
- // expected
- }
- }
-
- public void testGetSetColumnLarge() {
- int n = 3 * 64;
- RealMatrix m = new RecursiveLayoutRealMatrix(n, n);
- double[] sub = new double[n];
- Arrays.fill(sub, 1.0);
-
- m.setColumn(2, sub);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (j != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
- } else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
- }
- }
- }
- checkArrays(sub, m.getColumn(2));
-
- }
-
- private double[] columnToArray(double[][] column) {
- double[] data = new double[column.length];
- for (int i = 0; i < data.length; ++i) {
- data[i] = column[i][0];
- }
- return data;
- }
-
- private void checkArrays(double[] expected, double[] actual) {
- assertEquals(expected.length, actual.length);
- for (int i = 0; i < expected.length; ++i) {
- assertEquals(expected[i], actual[i], 1.0e-9 * Math.abs(expected[i]));
- }
- }
-
- public void testEqualsAndHashCode() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- RecursiveLayoutRealMatrix m1 = (RecursiveLayoutRealMatrix) m.copy();
- RecursiveLayoutRealMatrix mt = (RecursiveLayoutRealMatrix) m.transpose();
- assertTrue(m.hashCode() != mt.hashCode());
- assertEquals(m.hashCode(), m1.hashCode());
- assertEquals(m, m);
- assertEquals(m, m1);
- assertFalse(m.equals(null));
- assertFalse(m.equals(mt));
- assertFalse(m.equals(new RecursiveLayoutRealMatrix(bigSingular)));
- }
-
- public void testToString() {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- assertEquals("RecursiveLayoutRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
- m.toString());
- }
-
- public void testSetSubMatrix() throws Exception {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(testData);
- m.setSubMatrix(detData2,1,1);
- RealMatrix expected = new RecursiveLayoutRealMatrix
- (new double[][] {{1.0,2.0,3.0},{2.0,1.0,3.0},{1.0,2.0,4.0}});
- assertEquals(expected, m);
-
- m.setSubMatrix(detData2,0,0);
- expected = new RecursiveLayoutRealMatrix
- (new double[][] {{1.0,3.0,3.0},{2.0,4.0,3.0},{1.0,2.0,4.0}});
- assertEquals(expected, m);
-
- m.setSubMatrix(testDataPlus2,0,0);
- expected = new RecursiveLayoutRealMatrix
- (new double[][] {{3.0,4.0,5.0},{4.0,7.0,5.0},{3.0,2.0,10.0}});
- assertEquals(expected, m);
-
- // javadoc example
- RecursiveLayoutRealMatrix matrix = new RecursiveLayoutRealMatrix
- (new double[][] {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 0, 1 , 2}});
- matrix.setSubMatrix(new double[][] {{3, 4}, {5, 6}}, 1, 1);
- expected = new RecursiveLayoutRealMatrix
- (new double[][] {{1, 2, 3, 4}, {5, 3, 4, 8}, {9, 5 ,6, 2}});
- assertEquals(expected, matrix);
-
- // dimension overflow
- try {
- m.setSubMatrix(testData,1,1);
- fail("expecting MatrixIndexException");
- } catch (MatrixIndexException e) {
- // expected
- }
- // dimension underflow
- try {
- m.setSubMatrix(testData,-1,1);
- fail("expecting MatrixIndexException");
- } catch (MatrixIndexException e) {
- // expected
- }
- try {
- m.setSubMatrix(testData,1,-1);
- fail("expecting MatrixIndexException");
- } catch (MatrixIndexException e) {
- // expected
- }
-
- // null
- try {
- m.setSubMatrix(null,1,1);
- fail("expecting NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // ragged
- try {
- m.setSubMatrix(new double[][] {{1}, {2, 3}}, 0, 0);
- fail("expecting IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- // empty
- try {
- m.setSubMatrix(new double[][] {{}}, 0, 0);
- fail("expecting IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- }
-
- public void testWalk() {
- int rows = 150;
- int columns = 75;
-
- RealMatrix m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInRowOrder(new SetVisitor());
- GetVisitor getVisitor = new GetVisitor();
- m.walkInOptimizedOrder(getVisitor);
- assertEquals(rows * columns, getVisitor.getCount());
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInRowOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
- getVisitor = new GetVisitor();
- m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
- assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
- for (int i = 0; i < rows; ++i) {
- assertEquals(0.0, m.getEntry(i, 0), 0);
- assertEquals(0.0, m.getEntry(i, columns - 1), 0);
- }
- for (int j = 0; j < columns; ++j) {
- assertEquals(0.0, m.getEntry(0, j), 0);
- assertEquals(0.0, m.getEntry(rows - 1, j), 0);
- }
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInColumnOrder(new SetVisitor());
- getVisitor = new GetVisitor();
- m.walkInOptimizedOrder(getVisitor);
- assertEquals(rows * columns, getVisitor.getCount());
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInColumnOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
- getVisitor = new GetVisitor();
- m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
- assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
- for (int i = 0; i < rows; ++i) {
- assertEquals(0.0, m.getEntry(i, 0), 0);
- assertEquals(0.0, m.getEntry(i, columns - 1), 0);
- }
- for (int j = 0; j < columns; ++j) {
- assertEquals(0.0, m.getEntry(0, j), 0);
- assertEquals(0.0, m.getEntry(rows - 1, j), 0);
- }
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInOptimizedOrder(new SetVisitor());
- getVisitor = new GetVisitor();
- m.walkInRowOrder(getVisitor);
- assertEquals(rows * columns, getVisitor.getCount());
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
- getVisitor = new GetVisitor();
- m.walkInRowOrder(getVisitor, 1, rows - 2, 1, columns - 2);
- assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
- for (int i = 0; i < rows; ++i) {
- assertEquals(0.0, m.getEntry(i, 0), 0);
- assertEquals(0.0, m.getEntry(i, columns - 1), 0);
- }
- for (int j = 0; j < columns; ++j) {
- assertEquals(0.0, m.getEntry(0, j), 0);
- assertEquals(0.0, m.getEntry(rows - 1, j), 0);
- }
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInOptimizedOrder(new SetVisitor());
- getVisitor = new GetVisitor();
- m.walkInColumnOrder(getVisitor);
- assertEquals(rows * columns, getVisitor.getCount());
-
- m = new RecursiveLayoutRealMatrix(rows, columns);
- m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
- getVisitor = new GetVisitor();
- m.walkInColumnOrder(getVisitor, 1, rows - 2, 1, columns - 2);
- assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
- for (int i = 0; i < rows; ++i) {
- assertEquals(0.0, m.getEntry(i, 0), 0);
- assertEquals(0.0, m.getEntry(i, columns - 1), 0);
- }
- for (int j = 0; j < columns; ++j) {
- assertEquals(0.0, m.getEntry(0, j), 0);
- assertEquals(0.0, m.getEntry(rows - 1, j), 0);
- }
-
- }
-
- private static class SetVisitor extends DefaultRealMatrixChangingVisitor {
- private static final long serialVersionUID = 1773444180892369386L;
- public double visit(int i, int j, double value) {
- return i + j / 1024.0;
- }
- }
-
- private static class GetVisitor extends DefaultRealMatrixPreservingVisitor {
- private static final long serialVersionUID = -7745543227178932689L;
- private int count = 0;
- public void visit(int i, int j, double value) {
- ++count;
- assertEquals(i + j / 1024.0, value, 0.0);
- }
- public int getCount() {
- return count;
- }
- };
-
- //--------------- -----------------Protected methods
-
- /** verifies that two matrices are close (1-norm) */
- protected void assertClose(RealMatrix m, RealMatrix n, double tolerance) {
- assertTrue(m.subtract(n).getNorm() < tolerance);
- }
-
- /** verifies that two vectors are close (sup norm) */
- protected void assertClose(double[] m, double[] n, double tolerance) {
- if (m.length != n.length) {
- fail("vectors not same length");
- }
- for (int i = 0; i < m.length; i++) {
- assertEquals(m[i], n[i], tolerance);
- }
- }
-
- private RecursiveLayoutRealMatrix createRandomMatrix(Random r, int rows, int columns) {
- RecursiveLayoutRealMatrix m = new RecursiveLayoutRealMatrix(rows, columns);
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < columns; ++j) {
- m.setEntry(i, j, 200 * r.nextDouble() - 100);
- }
- }
- return m;
- }
-
-}
-
diff --git a/src/experimental/org/apache/commons/math/stat/univariate/BeanListUnivariateImpl.java b/src/experimental/org/apache/commons/math/stat/univariate/BeanListUnivariateImpl.java
deleted file mode 100644
index 8bbd075..0000000
--- a/src/experimental/org/apache/commons/math/stat/univariate/BeanListUnivariateImpl.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.stat.univariate;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.beanutils.DynaBean;
-import org.apache.commons.beanutils.BasicDynaClass;
-import org.apache.commons.beanutils.DynaProperty;
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.util.NumberTransformer;
-
-/**
- * This implementation of DescriptiveStatistics uses commons-beanutils to gather
- * univariate statistics for a List of Java Beans by property. This
- * implementation uses beanutils' PropertyUtils to get a simple, nested,
- * indexed, mapped, or combined property from an element of a List.
- * @version $Revision$ $Date$
- */
-public class BeanListUnivariateImpl extends ListUnivariateImpl implements Serializable {
-
- /** Serializable version identifier */
- static final long serialVersionUID = -6428201899045406285L;
-
- /**
- * propertyName of the property to get from the bean
- */
- private String propertyName;
-
- /**
- * No argument Constructor
- */
- public BeanListUnivariateImpl(){
- this(new ArrayList());
- }
-
- /**
- * Construct a BeanListUnivariate with specified
- * backing list
- * @param list Backing List
- */
- public BeanListUnivariateImpl(List list) {
- this(list, null);
- }
-
- /**
- * Construct a BeanListUnivariate with specified
- * backing list and propertyName
- * @param list Backing List
- * @param propertyName Bean propertyName
- */
- public BeanListUnivariateImpl(List list, String propertyName) {
- super(list);
- setPropertyName(propertyName);
- }
-
- /**
- * @return propertyName
- */
- public String getPropertyName() {
- return propertyName;
- }
-
- /**
- * @param propertyName Name of Property
- */
- public void setPropertyName(String propertyName) {
- this.propertyName = propertyName;
- this.transformer = new NumberTransformer() {
-
- /**
- * @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
- */
- public double transform(final Object o) throws MathException {
- try {
- return (
- (Number) PropertyUtils.getProperty(
- o,
- getPropertyName()))
- .doubleValue();
- } catch (IllegalAccessException e) {
- throw new MathException(
- "IllegalAccessException in Transformation: "
- + e.getMessage(),
- e);
- } catch (InvocationTargetException e) {
- throw new MathException(
- "InvocationTargetException in Transformation: "
- + e.getMessage(),
- e);
- } catch (NoSuchMethodException e) {
- throw new MathException(
- "oSuchMethodException in Transformation: "
- + e.getMessage(),
- e);
- }
- }
- };
- }
-
- /**
- * Creates a {@link org.apache.commons.beanutils.DynaBean} with a
- * {@link org.apache.commons.beanutils.DynaProperty} named
- * <code>propertyName,</code> sets the value of the property to <code>v</code>
- * and adds the DynaBean to the underlying list.
- *
- */
- public void addValue(double v) {
- DynaProperty[] props = new DynaProperty[] {
- new DynaProperty(propertyName, Double.class)
- };
- BasicDynaClass dynaClass = new BasicDynaClass(null, null, props);
- DynaBean dynaBean = null;
- try {
- dynaBean = dynaClass.newInstance();
- } catch (Exception ex) { // InstantiationException, IllegalAccessException
- throw new RuntimeException(ex); // should never happen
- }
- dynaBean.set(propertyName, Double.valueOf(v));
- addObject(dynaBean);
- }
-
- /**
- * Adds a bean to this list.
- *
- * @param bean Bean to add to the list
- */
- public void addObject(Object bean) {
- list.add(bean);
- }
-}
diff --git a/src/experimental/org/apache/commons/math/stat/univariate/BeanListUnivariateImplTest.java b/src/experimental/org/apache/commons/math/stat/univariate/BeanListUnivariateImplTest.java
deleted file mode 100644
index 9e9751b..0000000
--- a/src/experimental/org/apache/commons/math/stat/univariate/BeanListUnivariateImplTest.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.stat.univariate;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.commons.math.TestUtils;
-import org.apache.commons.math.stat.StatUtils;
-
-/**
- * Test cases for the {@link BeanListUnivariateImpl} class.
- *
- * @version $Revision$ $Date$
- */
-
-public final class BeanListUnivariateImplTest extends TestCase {
-
- private double one = 1;
- private float two = 2;
- private int three = 3;
- private double mean = 2;
- private double sumSq = 18;
- private double sum = 8;
- private double var = 0.666666666666666666667;
- private double std = Math.sqrt(var);
- private double n = 4;
- private double min = 1;
- private double max = 3;
- private double skewness = 0;
- private double kurtosis = 0.5;
- private double tolerance = 10E-15;
-
-
- private List patientList = null;
-
- public BeanListUnivariateImplTest(String name) {
- super(name);
- }
-
- public void setUp() {
- patientList = new ArrayList();
-
- // Create and add patient bean 1
- VitalStats vs1 = new VitalStats( Double.valueOf(120.0),
- Double.valueOf(96.4) );
- Patient p1 = new Patient( vs1, Integer.valueOf( 35 ) );
- patientList.add( p1 );
-
- // Create and add patient bean 2
- VitalStats vs2 = new VitalStats( Double.valueOf(70.0),
- Double.valueOf(97.4) );
- Patient p2 = new Patient( vs2, Integer.valueOf( 23 ) );
- patientList.add( p2 );
-
- // Create and add patient bean 3
- VitalStats vs3 = new VitalStats( Double.valueOf(90.0),
- Double.valueOf(98.6) );
- Patient p3 = new Patient( vs3, Integer.valueOf( 42 ) );
- patientList.add( p3 );
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(BeanListUnivariateImplTest.class);
- suite.setName("Frequency Tests");
- return suite;
- }
-
- /** test stats */
- public void testStats() {
- DescriptiveStatistics u = new BeanListUnivariateImpl( patientList, "age" );
- double[] values = {35d, 23d, 42d};
- assertEquals("total count",3,u.getN(),tolerance);
- assertEquals("mean", StatUtils.mean(values), u.getMean(), tolerance);
- assertEquals("min", StatUtils.min(values), u.getMin(), tolerance);
- assertEquals("max", StatUtils.max(values), u.getMax(), tolerance);
- assertEquals("var", StatUtils.variance(values), u.getVariance(), tolerance);
- u.clear();
- assertEquals("total count",0,u.getN(),tolerance);
- }
-
- public void testPropStats() {
-
- DescriptiveStatistics heartU = new BeanListUnivariateImpl( patientList,
- "vitalStats.heartRate" );
-
- assertEquals( "Mean heart rate unexpected", 93.333,
- heartU.getMean(), 0.001 );
- assertEquals( "Max heart rate unexpected", 120.0,
- heartU.getMax(), 0.001 );
-
- DescriptiveStatistics ageU = new BeanListUnivariateImpl( patientList,
- "age" );
-
- assertEquals( "Mean age unexpected", 33.333,
- ageU.getMean(), 0.001 );
- assertEquals( "Max age unexpected", 42.0,
- ageU.getMax(), 0.001 );
-
- }
-
- public void testSetPropertyName(){
- BeanListUnivariateImpl u = new BeanListUnivariateImpl(null);
- String expected = "property";
- u.setPropertyName(expected);
- assertEquals(expected, u.getPropertyName());
- }
-
- public void testAddValue() {
- DescriptiveStatistics u = new BeanListUnivariateImpl( patientList, "age" );
- u.addValue(10);
- double[] values = {35d, 23d, 42d, 10d};
- assertEquals("total count",4,u.getN(),tolerance);
- assertEquals("mean", StatUtils.mean(values), u.getMean(), tolerance);
- assertEquals("min", StatUtils.min(values), u.getMin(), tolerance);
- assertEquals("max", StatUtils.max(values), u.getMax(), tolerance);
- assertEquals("var", StatUtils.variance(values), u.getVariance(), tolerance);
- u.clear();
- assertEquals("total count",0,u.getN(),tolerance);
- }
-
- /** test stats */
- public void testSerialization() {
-
- double[] values = {35d, 23d, 42d};
-
- DescriptiveStatistics u = new BeanListUnivariateImpl( patientList, "age" );
- assertEquals("total count",3,u.getN(),tolerance);
- assertEquals("mean", StatUtils.mean(values), u.getMean(), tolerance);
- assertEquals("min", StatUtils.min(values), u.getMin(), tolerance);
- assertEquals("max", StatUtils.max(values), u.getMax(), tolerance);
- assertEquals("var", StatUtils.variance(values), u.getVariance(), tolerance);
-
-
- DescriptiveStatistics u2 = (DescriptiveStatistics)TestUtils.serializeAndRecover(u);
- assertEquals("total count",3,u2.getN(),tolerance);
- assertEquals("mean", StatUtils.mean(values), u2.getMean(), tolerance);
- assertEquals("min", StatUtils.min(values), u2.getMin(), tolerance);
- assertEquals("max", StatUtils.max(values), u2.getMax(), tolerance);
- assertEquals("var", StatUtils.variance(values), u2.getVariance(), tolerance);
-
- u.clear();
- assertEquals("total count",0,u.getN(),tolerance);
-
- u2.clear();
- assertEquals("total count",0,u2.getN(),tolerance);
-
- }
-
- public class VitalStats {
-
- private Double heartrate;
- private Double temperature;
-
- public VitalStats() {
- }
-
- public VitalStats(Double heartrate, Double temperature) {
- setHeartRate( heartrate );
- setTemperature( temperature );
- }
-
- public Double getHeartRate() {
- return heartrate;
- }
-
- public void setHeartRate(Double heartrate) {
- this.heartrate = heartrate;
- }
-
- public Double getTemperature() {
- return temperature;
- }
-
- public void setTemperature(Double temperature) {
- this.temperature = temperature;
- }
- }
-
- public class Patient {
-
- private VitalStats vitalStats;
- private Integer age;
-
- public Patient() {
- }
-
- public Patient(VitalStats vitalStats, Integer age) {
- setVitalStats( vitalStats );
- setAge( age );
- }
-
- public VitalStats getVitalStats() {
- return( vitalStats );
- }
-
- public void setVitalStats(VitalStats vitalStats) {
- this.vitalStats = vitalStats;
- }
-
- public Integer getAge() {
- return age;
- }
-
- public void setAge(Integer age) {
- this.age = age;
- }
- }
-}
-
diff --git a/src/experimental/org/apache/commons/math/util/BeanTransformer.java b/src/experimental/org/apache/commons/math/util/BeanTransformer.java
deleted file mode 100644
index d6e9f1f..0000000
--- a/src/experimental/org/apache/commons/math/util/BeanTransformer.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.util;
-
-import java.beans.Expression;
-import java.lang.reflect.InvocationTargetException;
-import org.apache.commons.math.MathException;
-
-/**
- * Uses PropertyUtils to map a Bean getter to a double value.
- * @version $Revision$ $Date$
- */
-public class BeanTransformer implements NumberTransformer {
-
- /**
- * The propertyName for this Transformer
- */
- private String propertyName = null;
-
- private String propertyGetter = null;
-
- /**
- * Create a BeanTransformer
- */
- public BeanTransformer() {
- super();
- }
-
- /**
- * Create a BeanTransformer with a specific PropertyName.
- * @param property The property.
- */
- public BeanTransformer(final String property) {
- super();
- setPropertyName(property);
- }
-
- /**
- * Get the property String
- * @return the Property Name String
- */
- public String getPropertyName() {
- return propertyName;
- }
-
- /**
- * Set the propertyString
- * @param string The string to set the property to.
- */
- public void setPropertyName(final String string) {
- this.propertyName = string;
- this.propertyGetter = "get" + string.substring(0,1).toUpperCase() + string.substring(1);
- }
-
-
- /**
- * @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
- */
- public double transform(final Object o) throws MathException {
- Expression expr = new Expression(o, propertyGetter, new Object[0]);
- Object result;
- try {
- expr.execute();
- result = expr.getValue();
- } catch (IllegalAccessException e) {
- throw new MathException("IllegalAccessException in Transformation: " + e.getMessage(), e);
- } catch (InvocationTargetException e) {
- throw new MathException("InvocationTargetException in Transformation: " + e.getMessage(), e);
- } catch (NoSuchMethodException e) {
- throw new MathException("NoSuchMethodException in Transformation: " + e.getMessage(), e);
- } catch (ClassCastException e) {
- throw new MathException("ClassCastException in Transformation: " + e.getMessage(), e);
- } catch (Exception e) {
- throw new MathException("Exception in Transformation: " + e.getMessage(), e);
- }
-
- return ((Number) result).doubleValue();
- }
-}
\ No newline at end of file
diff --git a/src/experimental/org/apache/commons/math/util/BeanTransformerTest.java b/src/experimental/org/apache/commons/math/util/BeanTransformerTest.java
deleted file mode 100644
index a6ca67d..0000000
--- a/src/experimental/org/apache/commons/math/util/BeanTransformerTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math.util;
-
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.TestUtils;
-
-import junit.framework.TestCase;
-
-/**
- * @version $Revision$ $Date$
- */
-public class BeanTransformerTest extends TestCase {
-
- /**
- *
- */
- public void testConstructor(){
- BeanTransformer b = new BeanTransformer();
- assertNull(b.getPropertyName());
- }
-
- /**
- *
- */
- public void testConstructorString(){
- String name = "property";
- BeanTransformer b = new BeanTransformer(name);
- assertEquals(name, b.getPropertyName());
- }
-
- /**
- *
- */
- public void testSetPropertyName(){
- String name = "property";
- BeanTransformer b = new BeanTransformer();
- b.setPropertyName(name);
- assertEquals(name, b.getPropertyName());
- }
-
- /**
- *
- */
- public void testTransformNoSuchMethod(){
- BeanTransformer b = new BeanTransformer("z");
- TestBean target = new TestBean();
- try {
- b.transform(target);
- fail("Expecting MathException");
- } catch (MathException e) {
- // expected
- }
- }
-
- /**
- *
- */
- public void testTransform() throws Exception {
- BeanTransformer b = new BeanTransformer("x");
- TestBean target = new TestBean();
- double value = Double.NaN;
- value = b.transform(target);
- TestUtils.assertEquals(1.0, value, 1.0e-2);
- }
-
- /**
- */
- public void testTransformInvalidType() throws Exception {
- BeanTransformer b = new BeanTransformer("y");
- TestBean target = new TestBean();
- try {
- b.transform(target);
- fail("Expecting ClassCastException");
- } catch(ClassCastException ex){
- // success
- }
- }
-}
diff --git a/src/main/java/org/apache/commons/math/genetics/Chromosome.java b/src/main/java/org/apache/commons/math/genetics/Chromosome.java
index d66333b..21680b8 100644
--- a/src/main/java/org/apache/commons/math/genetics/Chromosome.java
+++ b/src/main/java/org/apache/commons/math/genetics/Chromosome.java
@@ -23,7 +23,7 @@
* therefore it can be cached.
*
* @since 2.0
- * @version $Revision:$ $Date:$
+ * @version $Revision$ $Date$
*/
public abstract class Chromosome implements Comparable<Chromosome>,Fitness {
diff --git a/src/main/java/org/apache/commons/math/genetics/Fitness.java b/src/main/java/org/apache/commons/math/genetics/Fitness.java
index 286e793..618eabc 100644
--- a/src/main/java/org/apache/commons/math/genetics/Fitness.java
+++ b/src/main/java/org/apache/commons/math/genetics/Fitness.java
@@ -19,7 +19,7 @@
/**
* Fitness of a chromosome.
*
- * @version $Revision:$ $Date:$
+ * @version $Revision$ $Date$
* @since 2.0
*/
public interface Fitness {
diff --git a/src/main/java/org/apache/commons/math/genetics/Population.java b/src/main/java/org/apache/commons/math/genetics/Population.java
index 1804242..06c1c87 100644
--- a/src/main/java/org/apache/commons/math/genetics/Population.java
+++ b/src/main/java/org/apache/commons/math/genetics/Population.java
@@ -20,7 +20,7 @@
* A collection of chromosomes that facilitates generational evolution.
*
* @since 2.0
- * @version $Revision:$ $Date:$
+ * @version $Revision$ $Date$
*/
public interface Population extends Iterable<Chromosome> {
/**
diff --git a/src/main/java/org/apache/commons/math/genetics/SelectionPolicy.java b/src/main/java/org/apache/commons/math/genetics/SelectionPolicy.java
index a6a2b90..25e7a28 100644
--- a/src/main/java/org/apache/commons/math/genetics/SelectionPolicy.java
+++ b/src/main/java/org/apache/commons/math/genetics/SelectionPolicy.java
@@ -20,7 +20,7 @@
* Algorithm used to select a chromosome pair from a population.
*
* @since 2.0
- * @version $Revision:$ $Date:$
+ * @version $Revision$ $Date$
*/
public interface SelectionPolicy {
/**
diff --git a/src/main/java/org/apache/commons/math/genetics/StoppingCondition.java b/src/main/java/org/apache/commons/math/genetics/StoppingCondition.java
index d40a52a..4853ed3 100644
--- a/src/main/java/org/apache/commons/math/genetics/StoppingCondition.java
+++ b/src/main/java/org/apache/commons/math/genetics/StoppingCondition.java
@@ -20,7 +20,7 @@
* Algorithm used to determine when to stop evolution.
*
* @since 2.0
- * @version $Revision:$ $Date:$
+ * @version $Revision$ $Date$
*/
public interface StoppingCondition {
/**
diff --git a/src/mantissa/LICENSE-2.0.txt b/src/mantissa/LICENSE-2.0.txt
deleted file mode 100644
index d645695..0000000
--- a/src/mantissa/LICENSE-2.0.txt
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/src/mantissa/NOTICE.txt b/src/mantissa/NOTICE.txt
deleted file mode 100644
index 60eda9a..0000000
--- a/src/mantissa/NOTICE.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-Apache commons-math
-Copyright 2006-2007 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-
-
-This product includes software developed by
-Luc Maisonobe and licensed to the Apache Software Foundation.
diff --git a/src/mantissa/src/org/spaceroots/mantissa/MantissaException.java b/src/mantissa/src/org/spaceroots/mantissa/MantissaException.java
deleted file mode 100644
index 4cf4286..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/MantissaException.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa;
-
-import java.text.MessageFormat;
-import java.util.ResourceBundle;
-import java.util.MissingResourceException;
-
-/** This class is the base class for all specific exceptions thrown by
- * the mantissa classes.
-
- * <p>When the mantissa classes throw exceptions that are specific to
- * the package, these exceptions are always subclasses of
- * MantissaException. When exceptions that are already covered by the
- * standard java API should be thrown, like
- * ArrayIndexOutOfBoundsException or IllegalArgumentException, these
- * standard exceptions are thrown rather than the mantissa specific
- * ones.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class MantissaException
- extends Exception {
-
- private static final long serialVersionUID = 1L;
- private static ResourceBundle resources
- = ResourceBundle.getBundle("org.spaceroots.mantissa.MessagesResources");
-
- /** Translate a string.
- * @param s string to translate
- * @return translated string
- */
- public static String translate(String s) {
- try {
- return resources.getString(s);
- } catch (MissingResourceException mre) {
- return s;
- }
- }
-
- /** Translate a message.
- * @param specifier format specifier (to be translated)
- * @param parts to insert in the format (no translation)
- * @return translated message
- */
- public static String translate(String specifier, String[] parts) {
- return new MessageFormat(translate(specifier)).format(parts);
- }
-
- /** Simple constructor.
- * Build an exception with an empty message
- */
- public MantissaException() {
- super();
- }
-
- /** Simple constructor.
- * Build an exception by translating the specified message
- * @param message message to translate
- */
- public MantissaException(String message) {
- super(translate(message));
- }
-
- /** Simple constructor.
- * Build an exception by translating and formating a message
- * @param specifier format specifier (to be translated)
- * @param parts to insert in the format (no translation)
- */
- public MantissaException(String specifier, String[] parts) {
- super(translate(specifier, parts));
- }
-
- /** Simple constructor.
- * Build an exception from a cause
- * @param cause cause of this exception
- */
- public MantissaException(Throwable cause) {
- super(cause);
- }
-
- /** Simple constructor.
- * Build an exception from a message and a cause
- * @param message message to translate
- * @param cause cause of this exception
- */
- public MantissaException(String message, Throwable cause) {
- super(translate(message), cause);
- }
-
- /** Simple constructor.
- * Build an exception from a message and a cause
- * @param specifier format specifier (to be translated)
- * @param parts to insert in the format (no translation)
- * @param cause cause of this exception
- */
- public MantissaException(String specifier, String[] parts, Throwable cause) {
- super(translate(specifier, parts), cause);
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/MessagesResources.java b/src/mantissa/src/org/spaceroots/mantissa/MessagesResources.java
deleted file mode 100644
index 900650a..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/MessagesResources.java
+++ /dev/null
@@ -1,113 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa;
-
-import java.util.ListResourceBundle;
-
-/** This class gather the message resources for the mantissa library.
- * @version $Id$
- * @author L. Maisonobe
- */
-
-public class MessagesResources
- extends ListResourceBundle {
-
- /** Simple constructor.
- */
- public MessagesResources() {
- }
-
- public Object[][] getContents() {
- return (Object[][]) contents.clone();
- }
-
- static final Object[][] contents = {
-
- // org.spaceroots.mantissa.estimation.GaussNewtonEstimator
- { "unable to converge in {0} iterations",
- "unable to converge in {0} iterations" },
-
- // org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator
- { "cost relative tolerance is too small ({0}), no further reduction in the sum of squares is possible",
- "cost relative tolerance is too small ({0}), no further reduction in the sum of squares is possible" },
- { "parameters relative tolerance is too small ({0}), no further improvement in the approximate solution is possible",
- "parameters relative tolerance is too small ({0}), no further improvement in the approximate solution is possible" },
- { "orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian",
- "orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian" },
- { "maximal number of evaluations exceeded ({0})",
- "maximal number of evaluations exceeded ({0})" },
-
- // org.spaceroots.mantissa.fitting.HarmonicCoefficientsGuesser
- { "unable to guess a first estimate",
- "unable to guess a first estimate" },
-
- // org.spaceroots.mantissa.fitting.HarmonicFitter
- { "sample must contain at least {0} points",
- "sample must contain at least {0} points" },
-
- // org.spaceroots.mantissa.functions.ExhaustedSampleException
- { "sample contains only {0} elements",
- "sample contains only {0} elements" },
-
- // org.spaceroots.mantissa.geometry.CardanEulerSingularityException
- { "Cardan angles singularity",
- "Cardan angles singularity" },
- { "Euler angles singularity",
- "Euler angles singularity" },
-
- // org.spaceroots.mantissa.geometry.Rotation
- { "a {0}x{1} matrix cannot be a rotation matrix",
- "a {0}x{1} matrix cannot be a rotation matrix" },
- { "the closest orthogonal matrix has a negative determinant {0}",
- "the closest orthogonal matrix has a negative determinant {0}" },
- { "unable to orthogonalize matrix in {0} iterations",
- "unable to orthogonalize matrix in {0} iterations" },
-
- // org.spaceroots.mantissa.linalg;.SingularMatrixException
- { "singular matrix",
- "singular matrix" },
-
- // org.spaceroots.mantissa.ode.AdaptiveStepsizeIntegrator
- { "minimal step size ({0}) reached, integration needs {1}",
- "minimal step size ({0}) reached, integration needs {1}" },
-
- // org.spaceroots.mantissa.ode.GraggBulirschStoerIntegrator,
- // org.spaceroots.mantissa.ode.RungeKuttaFehlbergIntegrator,
- // org.spaceroots.mantissa.ode.RungeKuttaIntegrator
- { "dimensions mismatch: ODE problem has dimension {0},"
- + " state vector has dimension {1}",
- "dimensions mismatch: ODE problem has dimension {0},"
- + " state vector has dimension {1}" },
- { "too small integration interval: length = {0}",
- "too small integration interval: length = {0}" },
-
- // org.spaceroots.mantissa.optimization.DirectSearchOptimizer
- { "none of the {0} start points lead to convergence",
- "none of the {0} start points lead to convergence" },
-
- // org.spaceroots.mantissa.random.CorrelatedRandomVectorGenerator
- { "dimension mismatch {0} != {1}",
- "dimension mismatch {0} != {1}" },
-
- // org.spaceroots.mantissa.random.NotPositiveDefiniteMatrixException
- { "not positive definite matrix",
- "not positive definite matrix" }
-
- };
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/MessagesResources_fr.java b/src/mantissa/src/org/spaceroots/mantissa/MessagesResources_fr.java
deleted file mode 100644
index c170be1..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/MessagesResources_fr.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa;
-
-import java.util.ListResourceBundle;
-
-/** This class gather the message resources for the mantissa library.
- * @version $Id$
- * @author L. Maisonobe
- */
-public class MessagesResources_fr
- extends ListResourceBundle {
-
- /** Simple constructor.
- */
- public MessagesResources_fr() {
- }
-
- public Object[][] getContents() {
- return (Object[][]) contents.clone();
- }
-
- static final Object[][] contents = {
-
- // org.spaceroots.mantissa.estimation.GaussNewtonEstimator
- { "unable to converge in {0} iterations",
- "pas de convergence apr\u00e8s {0} it\u00e9rations" },
-
- // org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator
- { "cost relative tolerance is too small ({0}), no further reduction in the sum of squares is possible",
- "trop petite tol\u00e9rance relative sur le co\u00fbt ({0}), aucune r\u00e9duction de la somme des carr\u00e9s n''est possible" },
- { "parameters relative tolerance is too small ({0}), no further improvement in the approximate solution is possible",
- "trop petite tol\u00e9rance relative sur les param\u00e8tres ({0}), aucune am\u00e9lioration de la solution approximative n''est possible" },
- { "orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian",
- "trop petite tol\u00e9rance sur l''orthogonalit\u00e9 ({0}), la solution est orthogonale \u00e0 la jacobienne" },
- { "maximal number of evaluations exceeded ({0})",
- "nombre maximal d''\u00e9valuations d\u00e9pass\u00e9 ({0})" },
-
- // org.spaceroots.mantissa.fitting.HarmonicCoefficientsGuesser
- { "unable to guess a first estimate",
- "impossible de trouver une premi\u00e8re estim\u00e9e" },
-
- // org.spaceroots.mantissa.fitting.HarmonicFitter
- { "sample must contain at least {0} points",
- "l''\u00e9chantillon doit contenir au moins {0} points" },
-
- // org.spaceroots.mantissa.functions.ExhaustedSampleException
- { "sample contains only {0} elements",
- "l''\u00e9chantillon ne contient que {0} points" },
-
- // org.spaceroots.mantissa.geometry.CardanEulerSingularityException
- { "Cardan angles singularity",
- "singularit\u00e9 d''angles de Cardan" },
- { "Euler angles singularity",
- "singularit\u00e9 d''angles d''Euler" },
-
- // org.spaceroots.mantissa.geometry.Rotation
- { "a {0}x{1} matrix cannot be a rotation matrix",
- "une matrice {0}x{1} ne peut pas \u00e9tre une matrice de rotation" },
- { "the closest orthogonal matrix has a negative determinant {0}",
- "la matrice orthogonale la plus proche a un d\u00e9terminant n\u00e9gatif {0}" },
- { "unable to orthogonalize matrix in {0} iterations",
- "impossible de rendre la matrice orthogonale en {0} it\u00e9rations" },
-
- // org.spaceroots.mantissa.linalg;.SingularMatrixException
- { "singular matrix",
- "matrice singuli\u00e8re" },
-
- // org.spaceroots.mantissa.ode.AdaptiveStepsizeIntegrator
- { "minimal step size ({0}) reached, integration needs {1}",
- "pas minimal ({0}) atteint, l''int\u00e9gration n\u00e9cessite {1}" },
-
- // org.spaceroots.mantissa.ode.GraggBulirschStoerIntegrator,
- // org.spaceroots.mantissa.ode.RungeKuttaFehlbergIntegrator,
- // org.spaceroots.mantissa.ode.RungeKuttaIntegrator
- { "dimensions mismatch: ODE problem has dimension {0},"
- + " state vector has dimension {1}",
- "incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0}),"
- + " et le vecteur d''\u00e9tat ({1})" },
- { "too small integration interval: length = {0}",
- "intervalle d''int\u00e9gration trop petit : {0}" },
-
- // org.spaceroots.mantissa.optimization.DirectSearchOptimizer
- { "none of the {0} start points lead to convergence",
- "aucun des {0} points de d\u00e9part n''aboutit \u00e0 une convergence" },
-
- // org.spaceroots.mantissa.random.CorrelatedRandomVectorGenerator
- { "dimension mismatch {0} != {1}",
- "dimensions incompatibles {0} != {1}" },
-
- // org.spaceroots.mantissa.random.NotPositiveDefiniteMatrixException
- { "not positive definite matrix",
- "matrice non d\u00e9finie positive" }
-
- };
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java b/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java
deleted file mode 100644
index 9f81ca1..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java
+++ /dev/null
@@ -1,1014 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.Arrays;
-
-/** This class implements polynomials with one unknown.
-
- * <p>This is an abstract class that only declares general methods but
- * does not hold the coefficients by themselves. Specific subclasses
- * are used to handle exact rational coefficients or approximate real
- * coefficients. This design is taken from the various java.awt.geom
- * classes (Point2D, Rectangle2D ...)</p>
-
- * <p>The methods implemented deal mainly with the polynomials algebra
- * (addition, multiplication ...) but the analysis aspects are also
- * considered (value of the polynom for a given unknown,
- * derivative).</p>
-
- * <p>Instances of this class are immutable.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
-*/
-public abstract class Polynomial implements Serializable {
-
- /** Check if the instance is the null polynomial.
- * @return true if the polynomial is null
- */
- public abstract boolean isZero();
-
- /** Check if the instance is the constant unit polynomial.
- * @return true if the polynomial is the constant unit polynomial
- */
- public abstract boolean isOne();
-
- /** Check if the instance is the identity polynomial.
- * @return true if the polynomial is the identity polynomial
- */
- public abstract boolean isIdentity();
-
- /** Get the polynomial degree.
- * @return degree
- */
- public abstract int getDegree();
-
- /** Negate the instance.
- * @return a new polynomial
- */
- public abstract Polynomial negate();
-
- /** Multiply the instance by a constant.
- * @param r constant to multiply by
- * @return a new polynomial
- */
- public abstract Polynomial multiply(RationalNumber r);
-
- /** Multiply the instance by a constant.
- * @param l constant to multiply by
- * @return a new Polynomial
- */
- public abstract Polynomial multiply(long l);
-
- /** Multiply the instance by a constant.
- * @param i constant to multiply by
- * @return a new Polynomial
- */
- public Polynomial multiply(BigInteger i) {
- return multiply(new RationalNumber(i));
- }
-
- /** Divide the instance by a constant.
- * @param l constant to multiply by
- * @return a new polynomial
- * @exception ArithmeticException if the constant is zero
- */
- public Polynomial divide(long l) {
- return divide(new RationalNumber(l));
- }
-
- /** Divide the instance by a constant.
- * @param r constant to multiply by
- * @return a new polynomial
- * @exception ArithmeticException if the constant is zero
- */
- public Polynomial divide(RationalNumber r) {
- return multiply(r.invert());
- }
-
- /** Divide the instance by a constant.
- * @param i constant to multiply by
- * @return a new polynomial
- * @exception ArithmeticException if the constant is zero
- */
- public Polynomial divide(BigInteger i) {
- return divide(new RationalNumber(i));
- }
-
- /** Get the value of the polynomial for a specified unknown.
- * @param x value of the unknown
- * @return value of the polynomial
- */
- public abstract double valueAt(double x);
-
- /** Get the derivative of the instance with respect to the unknown.
- * The derivative of a n degree polynomial is a n-1 degree polynomial of
- * the same type.
- * @return a new polynomial which is the derivative of the instance
- */
- public abstract Polynomial getDerivative();
-
- /** This class implements polynomials with one unknown and rational
- * coefficients.
-
- * <p>In addition to classical algebra operations, euclidian
- * division and remainder are handled.</p>
-
- */
- public static class Rational extends Polynomial {
-
- /** Simple constructor.
- * Build a null polynomial
- */
- public Rational() {
- a = new RationalNumber[] { RationalNumber.ZERO };
- }
-
- /** Simple constructor.
- * Build a constant polynomial
- * @param value constant value of the polynomial
- */
- public Rational(long value) {
- this(new RationalNumber(value));
- }
-
- /** Simple constructor.
- * Build a constant polynomial
- * @param value constant value of the polynomial
- */
- public Rational(RationalNumber value) {
- a = new RationalNumber[] { value };
- }
-
- /** Simple constructor.
- * Build a first degree polynomial
- * @param a1 leeding degree coefficient
- * @param a0 constant term
- */
- public Rational(long a1, long a0) {
- this(new RationalNumber(a1), new RationalNumber(a0));
- }
-
- /** Simple constructor.
- * Build a first degree polynomial
- * @param a1 leeding degree coefficient
- * @param a0 constant term
- */
- public Rational(RationalNumber a1, RationalNumber a0) {
- if (! a1.isZero()) {
- a = new RationalNumber[] { a0, a1 };
- } else {
- a = new RationalNumber[] { a0 };
- }
- }
-
- /** Simple constructor.
- * Build a second degree polynomial
- * @param a2 leeding degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Rational(long a2, long a1, long a0) {
- this(new RationalNumber(a2),
- new RationalNumber(a1),
- new RationalNumber(a0));
- }
-
- /** Simple constructor.
- * Build a second degree polynomial
- * @param a2 leeding degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Rational(RationalNumber a2, RationalNumber a1, RationalNumber a0) {
- if (! a2.isZero()) {
- a = new RationalNumber[] { a0, a1, a2 };
- } else {
- if (! a1.isZero()) {
- a = new RationalNumber[] { a0, a1 };
- } else {
- a = new RationalNumber[] { a0 };
- }
- }
- }
-
- /** Simple constructor.
- * Build a third degree polynomial
- * @param a3 leeding degree coefficient
- * @param a2 second degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Rational(long a3, long a2, long a1, long a0) {
- this(new RationalNumber(a3),
- new RationalNumber(a2),
- new RationalNumber(a1),
- new RationalNumber(a0));
- }
-
- /** Simple constructor.
- * Build a third degree polynomial
- * @param a3 leeding degree coefficient
- * @param a2 second degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Rational(RationalNumber a3, RationalNumber a2,
- RationalNumber a1, RationalNumber a0) {
- if (! a3.isZero()) {
- a = new RationalNumber[] { a0, a1, a2, a3 };
- } else {
- if (! a2.isZero()) {
- a = new RationalNumber[] { a0, a1, a2 };
- } else {
- if (! a1.isZero()) {
- a = new RationalNumber[] { a0, a1 };
- } else {
- a = new RationalNumber[] { a0 };
- }
- }
- }
- }
-
- /** Simple constructor.
- * Build a polynomial from its coefficients
- * @param a coefficients array, the a[0] array element is the
- * constant term while the a[a.length-1] element is the leeding
- * degree coefficient. The array is copied in a new array, so it
- * can be changed once the constructor as returned.
- */
- public Rational(RationalNumber[] a) {
-
- // remove null high degree coefficients
- int i = a.length - 1;
- while ((i > 0) && (a[i].isZero())) {
- --i;
- }
-
- // copy the remaining coefficients
- this.a = new RationalNumber[i + 1];
- System.arraycopy(a, 0, this.a, 0, i + 1);
-
- }
-
- /** Simple constructor.
- * Build a one term polynomial from one coefficient and the corresponding degree
- * @param c coefficient
- * @param degree degree associated with the coefficient
- */
- public Rational(RationalNumber c, int degree) {
-
- if (c.isZero() || degree < 0) {
- a = new RationalNumber[] { RationalNumber.ZERO };
- } else {
- a = new RationalNumber[degree + 1];
- Arrays.fill(a, 0, degree, RationalNumber.ZERO);
- a[degree] = c;
- }
-
- }
-
- /** Check if the instance is the null polynomial.
- * @return true if the polynomial is null
- */
- public boolean isZero() {
- return (a.length == 1) && a[0].isZero();
- }
-
- /** Check if the instance is the constant unit polynomial.
- * @return true if the polynomial is the constant unit polynomial
- */
- public boolean isOne() {
- return (a.length == 1) && a[0].isOne();
- }
-
- /** Check if the instance is the identity polynomial.
- * @return true if the polynomial is the identity polynomial
- */
- public boolean isIdentity() {
- return (a.length == 2) && a[0].isZero() && a[1].isOne();
- }
-
- /** Get the polynomial degree.
- * @return degree
- */
- public int getDegree() {
- return a.length - 1;
- }
-
- /** Get the coefficients of the polynomial.
- * @return a copy of the coefficients array, the array
- * element at index 0 is the constant term while the element at
- * index a.length-1 is the leading degree coefficient
- */
- public RationalNumber[] getCoefficients() {
- return (RationalNumber[]) a.clone();
- }
-
- /** Add a polynomial to the instance
- * @param p polynomial to add
- * @return a new polynomial which is the sum of the instance and p
- */
- public Rational add(Rational p) {
-
- // identify the lowest degree polynomial
- int lowLength = Math.min(a.length, p.a.length);
- int highLength = Math.max(a.length, p.a.length);
-
- // build the coefficients array
- RationalNumber[] newA = new RationalNumber[highLength];
- for (int i = 0; i < lowLength; ++i) {
- newA[i] = a[i].add(p.a[i]);
- }
- System.arraycopy((a.length < p.a.length) ? p.a : a,
- lowLength, newA, lowLength, highLength - lowLength);
-
- return new Rational(newA);
-
- }
-
- /** Subtract a polynomial from the instance.
- * @param p polynomial to subtract
- * @return a new polynomial which is the difference the instance minus p
- */
- public Rational subtract(Rational p) {
-
- // identify the lowest degree polynomial
- int lowLength = Math.min(a.length, p.a.length);
- int highLength = Math.max(a.length, p.a.length);
-
- // build the coefficients array
- RationalNumber[] newA = new RationalNumber[highLength];
- for (int i = 0; i < lowLength; ++i) {
- newA[i] = a[i].subtract(p.a[i]);
- }
- if (a.length < p.a.length) {
- for (int i = lowLength; i < highLength; ++i) {
- newA[i] = p.a[i].negate();
- }
- } else {
- System.arraycopy(a, lowLength, newA, lowLength, highLength - lowLength);
- }
-
- return new Rational(newA);
-
- }
-
- /** Negate the instance.
- * @return a new polynomial
- */
- public Polynomial negate() {
- RationalNumber[] newA = new RationalNumber[a.length];
- for (int i = 0; i < a.length; ++i) {
- newA[i] = a[i].negate();
- }
- return new Rational(newA);
- }
-
- /** Multiply the instance by a polynomial.
- * @param p polynomial to multiply by
- * @return a new polynomial
- */
- public Rational multiply(Rational p) {
-
- RationalNumber[] newA = new RationalNumber[a.length + p.a.length - 1];
-
- for (int i = 0; i < newA.length; ++i) {
- newA[i] = RationalNumber.ZERO;
- for (int j = Math.max(0, i + 1 - p.a.length);
- j < Math.min(a.length, i + 1);
- ++j) {
- newA[i] = newA[i].add(a[j].multiply(p.a[i-j]));
- }
- }
-
- return new Rational(newA);
-
- }
-
- /** Multiply the instance by a constant.
- * @param l constant to multiply by
- * @return a new polynomial
- */
- public Polynomial multiply(long l) {
- return multiply(new RationalNumber(l));
- }
-
- /** Multiply the instance by a constant.
- * @param r constant to multiply by
- * @return a new polynomial
- */
- public Polynomial multiply(RationalNumber r) {
-
- if (r.isZero()) {
- return new Rational(new RationalNumber[] { RationalNumber.ZERO });
- }
-
- if (r.isOne()) {
- return this;
- }
-
- RationalNumber[] newA = new RationalNumber[a.length];
- for (int i = 0; i < a.length; ++i) {
- newA[i] = a[i].multiply(r);
- }
- return new Rational(newA);
-
- }
-
- /** Get the value of the polynomial for a specified unknown.
- * @param x value of the unknown
- * @return value of the polynomial
- */
- public double valueAt(double x) {
- double y = 0;
- for (int i = a.length - 1; i >= 0; --i) {
- y = y * x + a[i].doubleValue();
- }
- return y;
- }
-
- /** Get the derivative of the instance with respect to the unknown.
- * The derivative of a n degree polynomial is a n-1 degree polynomial of
- * the same type.
- * @return a new polynomial which is the derivative of the instance
- */
- public Polynomial getDerivative() {
- if (a.length == 1) {
- return new Rational();
- }
- RationalNumber[] newA = new RationalNumber[a.length - 1];
- for (int i = 1; i < a.length; ++i) {
- newA[i - 1] = a[i].multiply(i);
- }
- return new Rational(newA);
- }
-
- /** Perform the euclidian division of two polynomials.
- * @param dividend numerator polynomial
- * @param divisor denominator polynomial
- * @return an object containing the quotient and the remainder of the division
- */
- public static DivisionResult euclidianDivision(Rational dividend,
- Rational divisor) {
-
- Rational quotient = new Rational(0l);
- Rational remainder = dividend;
-
- int divisorDegree = divisor.getDegree();
- int remainderDegree = remainder.getDegree();
- while ((! remainder.isZero()) && (remainderDegree >= divisorDegree)) {
-
- RationalNumber c =
- remainder.a[remainderDegree].divide(divisor.a[divisorDegree]);
- Rational monomial = new Rational(c, remainderDegree - divisorDegree);
-
- remainder = remainder.subtract(monomial.multiply(divisor));
- quotient = quotient.add(monomial);
-
- remainderDegree = remainder.getDegree();
-
- }
-
- return new DivisionResult(quotient, remainder);
-
- }
-
- /** Get the Least Common Multiple of the coefficients denominators.
- * This number is the smallest integer by which we should multiply
- * the instance to get a polynomial whose coefficients are all integers.
- * @return the Least Common Multiple of the coefficients denominators
- */
- public BigInteger getDenominatorsLCM() {
-
- BigInteger lcm = BigInteger.ONE;
-
- for (int i = 0; i < a.length; ++i) {
- RationalNumber newCoeff = a[i].multiply(lcm);
- if (! newCoeff.isInteger()) {
- lcm = lcm.multiply(newCoeff.getDenominator());
- }
- }
-
- return lcm;
-
- }
-
- /** Returns a string representation of the polynomial.
-
- * <p>The representation is user oriented. Terms are displayed lowest
- * degrees first. The multiplications signs, coefficients equals to
- * one and null terms are not displayed (except if the polynomial is 0,
- * in which case the 0 constant term is displayed). Addition of terms
- * with negative coefficients are replaced by subtraction of terms
- * with positive coefficients except for the first displayed term
- * (i.e. we display <code>-3</code> for a constant negative polynomial,
- * but <code>1 - 3 x + x^2</code> if the negative coefficient is not
- * the first one displayed).</p>
-
- * @return a string representation of the polynomial
-
- */
- public String toString() {
-
- StringBuffer s = new StringBuffer();
- if (a[0].isZero()) {
- if (a.length == 1) {
- return "0";
- }
- } else {
- s.append(a[0].toString());
- }
-
- for (int i = 1; i < a.length; ++i) {
-
- if (! a[i].isZero()) {
-
- if (s.length() > 0) {
- if (a[i].isNegative()) {
- s.append(" - ");
- } else {
- s.append(" + ");
- }
- } else {
- if (a[i].isNegative()) {
- s.append("-");
- }
- }
-
- RationalNumber absAi = RationalNumber.abs(a[i]);
- if (! absAi.isOne()) {
- s.append(absAi.toString());
- s.append(' ');
- }
-
- s.append("x");
- if (i > 1) {
- s.append('^');
- s.append(Integer.toString(i));
- }
- }
-
- }
-
- return s.toString();
-
- }
-
- /** Coefficients array. */
- protected RationalNumber[] a;
-
- private static final long serialVersionUID = -794133890636181115L;
-
- }
-
- /** This class stores the result of the euclidian division of two polynomials.
- * This class is a simple placeholder, it does not provide any
- * processing method
- * @see Polynomial.Rational#euclidianDivision
- */
- public static class DivisionResult {
-
- /** The quotient of the division. */
- public final Rational quotient;
-
- /** The remainder of the division. */
- public final Rational remainder;
-
- /** Simple constructor. */
- public DivisionResult(Rational quotient, Rational remainder) {
- this.quotient = quotient;
- this.remainder = remainder;
- }
-
- }
-
- /** This class implements polynomials with one unknown and real
- * coefficients.
- */
- public static class Double extends Polynomial {
-
- /** Simple constructor.
- * Build a null polynomial
- */
- public Double() {
- a = new double[] { 0.0 };
- }
-
- /** Simple constructor.
- * Build a constant polynomial
- * @param value constant value of the polynomial
- */
- public Double(long value) {
- this((double) value);
- }
-
- /** Simple constructor.
- * Build a constant polynomial
- * @param value constant value of the polynomial
- */
- public Double(double value) {
- a = new double[] { value };
- }
-
- /** Simple constructor.
- * Build a first degree polynomial
- * @param a1 leeding degree coefficient
- * @param a0 constant term
- */
- public Double(long a1, long a0) {
- this((double) a1, (double) a0);
- }
-
- /** Simple constructor.
- * Build a first degree polynomial
- * @param a1 leeding degree coefficient
- * @param a0 constant term
- */
- public Double(double a1, double a0) {
- if (a1 != 0) {
- a = new double[] { a0, a1 };
- } else {
- a = new double[] { a0 };
- }
- }
-
- /** Simple constructor.
- * Build a second degree polynomial
- * @param a2 leeding degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Double(long a2, long a1, long a0) {
- this((double) a2, (double) a1, (double) a0);
- }
-
- /** Simple constructor.
- * Build a second degree polynomial
- * @param a2 leeding degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Double(double a2, double a1, double a0) {
- if (a2 != 0) {
- a = new double[] { a0, a1, a2 };
- } else {
- if (a1 != 0) {
- a = new double[] { a0, a1 };
- } else {
- a = new double[] { a0 };
- }
- }
- }
-
- /** Simple constructor.
- * Build a third degree polynomial
- * @param a3 leeding degree coefficient
- * @param a2 second degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Double(long a3, long a2, long a1, long a0) {
- this((double) a3, (double) a2, (double) a1, (double) a0);
- }
-
- /** Simple constructor.
- * Build a third degree polynomial
- * @param a3 leeding degree coefficient
- * @param a2 second degree coefficient
- * @param a1 first degree coefficient
- * @param a0 constant term
- */
- public Double(double a3, double a2, double a1, double a0) {
- if (a3 != 0) {
- a = new double[] { a0, a1, a2, a3 };
- } else {
- if (a2 != 0) {
- a = new double[] { a0, a1, a2 };
- } else {
- if (a1 != 0) {
- a = new double[] { a0, a1 };
- } else {
- a = new double[] { a0 };
- }
- }
- }
- }
-
- /** Simple constructor.
- * Build a polynomial from its coefficients
- * @param a coefficients array, the a[0] array element is the
- * constant term while the a[a.length-1] element is the leeding
- * degree coefficient. The array is copied in a new array, so it
- * can be changed once the constructor as returned.
- */
- public Double(double[] a) {
-
- // remove null high degree coefficients
- int i = a.length - 1;
- while ((i > 0) && (a[i] == 0)) {
- --i;
- }
-
- // copy the remaining coefficients
- this.a = new double[i + 1];
- System.arraycopy(a, 0, this.a, 0, i + 1);
-
- }
-
- /** Simple constructor.
- * Build a one term polynomial from one coefficient and the corresponding degree
- * @param c coefficient
- * @param degree degree associated with the coefficient
- */
- public Double(double c, int degree) {
- if ((c == 0) || degree < 0) {
- a = new double[] { 0.0 };
- } else {
- a = new double[degree + 1];
- Arrays.fill(a, 0, degree, 0.0);
- a[degree] = c;
- }
- }
-
- /** Simple constructor.
- * Build a {@link Polynomial.Double Polynomial.Double} from a
- * {@link Polynomial.Rational Polynomial.Rational}
- * @param r a rational polynomial
- */
- public Double(Rational r) {
- // convert the coefficients
- a = new double[r.a.length];
- for (int i = 0; i < a.length; ++i) {
- a[i] = r.a[i].doubleValue();
- }
- }
-
- /** Check if the instance is the null polynomial.
- * @return true if the polynomial is null
- */
- public boolean isZero() {
- return (a.length == 1) && (a[0] == 0);
- }
-
- /** Check if the instance is the constant unit polynomial.
- * @return true if the polynomial is the constant unit polynomial
- */
- public boolean isOne() {
- return (a.length == 1) && ((a[0] - 1.0) == 0);
- }
-
- /** Check if the instance is the identity polynomial.
- * @return true if the polynomial is the identity polynomial
- */
- public boolean isIdentity() {
- return (a.length == 2) && (a[0] == 0) && ((a[1] - 1.0) == 0);
- }
-
- /** Get the polynomial degree.
- * @return degree
- */
- public int getDegree() {
- return a.length - 1;
- }
-
- /** Get the coefficients of the polynomial.
- * @return a copy of the coefficients array, the array
- * element at index 0 is the constant term while the element at
- * index a.length-1 is the leading degree coefficient
- */
- public double[] getCoefficients() {
- return (double[]) a.clone();
- }
-
- /** Add a polynomial to the instance
- * @param p polynomial to add
- * @return a new polynomial which is the sum of the instance and p
- */
- public Double add(Double p) {
-
- // identify the lowest degree polynomial
- int lowLength = Math.min(a.length, p.a.length);
- int highLength = Math.max(a.length, p.a.length);
-
- // build the coefficients array
- double[] newA = new double[highLength];
- for (int i = 0; i < lowLength; ++i) {
- newA[i] = a[i] + p.a[i];
- }
- System.arraycopy((a.length < p.a.length) ? p.a : a,
- lowLength, newA, lowLength, highLength - lowLength);
-
- return Double.valueOf(newA);
-
- }
-
- /** Subtract a polynomial from the instance.
- * @param p polynomial to subtract
- * @return a new polynomial which is the difference the instance minus p
- */
- public Double subtract(Double p) {
-
- // identify the lowest degree polynomial
- int lowLength = Math.min(a.length, p.a.length);
- int highLength = Math.max(a.length, p.a.length);
-
- // build the coefficients array
- double[] newA = new double[highLength];
- for (int i = 0; i < lowLength; ++i) {
- newA[i] = a[i] - p.a[i];
- }
- if (a.length < p.a.length) {
- for (int i = lowLength; i < highLength; ++i) {
- newA[i] = -p.a[i];
- }
- } else {
- System.arraycopy(a, lowLength, newA, lowLength, highLength - lowLength);
- }
-
- return Double.valueOf(newA);
-
- }
-
- /** Negate the instance.
- * @return a new polynomial
- */
- public Polynomial negate() {
- double[] newA = new double[a.length];
- for (int i = 0; i < a.length; ++i) {
- newA[i] = -a[i];
- }
- return Double.valueOf(newA);
- }
-
- /** Multiply the instance by a polynomial.
- * @param p polynomial to multiply by
- * @return a new polynomial
- */
- public Double multiply(Double p) {
-
- double[] newA = new double[a.length + p.a.length - 1];
-
- for (int i = 0; i < newA.length; ++i) {
- newA[i] = 0.0;
- for (int j = Math.max(0, i + 1 - p.a.length);
- j < Math.min(a.length, i + 1);
- ++j) {
- newA[i] += a[j] * p.a[i-j];
- }
- }
-
- return Double.valueOf(newA);
-
- }
-
- /** Multiply the instance by a constant.
- * @param l constant to multiply by
- * @return a new polynomial
- */
- public Polynomial multiply(long l) {
- return multiply((double) l);
- }
-
- /** Multiply the instance by a constant.
- * @param r constant to multiply by
- * @return a new polynomial
- */
- public Polynomial multiply(RationalNumber r) {
- return multiply(r.doubleValue());
- }
-
- /** Multiply the instance by a constant.
- * @param r constant to multiply by
- * @return a new polynomial
- */
- public Polynomial multiply(double r) {
-
- if (r == 0) {
- return Double.valueOf(new double[] { 0.0 });
- }
-
- double[] newA = new double[a.length];
- for (int i = 0; i < a.length; ++i) {
- newA[i] = a[i] * r;
- }
- return Double.valueOf(newA);
-
- }
-
- /** Get the value of the polynomial for a specified unknown.
- * @param x value of the unknown
- * @return value of the polynomial
- */
- public double valueAt(double x) {
- double y = 0;
- for (int i = a.length - 1; i >= 0; --i) {
- y = y * x + a[i];
- }
- return y;
- }
-
- /** Get the derivative of the instance with respect to the unknown.
- * The derivative of a n degree polynomial is a n-1 degree polynomial of
- * the same type.
- * @return a new polynomial which is the derivative of the instance
- */
- public Polynomial getDerivative() {
- if (a.length == 1) {
- return Double.valueOf();
- }
- double[] newA = new double[a.length - 1];
- for (int i = 1; i < a.length; ++i) {
- newA[i - 1] = a[i] * i;
- }
- return Double.valueOf(newA);
- }
-
- /** Returns a string representation of the polynomial.
-
- * <p>The representation is user oriented. Terms are displayed lowest
- * degrees first. The multiplications signs, coefficients equals to
- * one and null terms are not displayed (except if the polynomial is 0,
- * in which case the 0 constant term is displayed). Addition of terms
- * with negative coefficients are replaced by subtraction of terms
- * with positive coefficients except for the first displayed term
- * (i.e. we display <code>-3</code> for a constant negative polynomial,
- * but <code>1 - 3 x + x^2</code> if the negative coefficient is not
- * the first one displayed).</p>
-
- * @return a string representation of the polynomial
-
- */
- public String toString() {
-
- StringBuffer s = new StringBuffer();
- if (a[0] == 0.0) {
- if (a.length == 1) {
- return "0";
- }
- } else {
- s.append(java.lang.Double.toString(a[0]));
- }
-
- for (int i = 1; i < a.length; ++i) {
-
- if (a[i] != 0) {
-
- if (s.length() > 0) {
- if (a[i] < 0) {
- s.append(" - ");
- } else {
- s.append(" + ");
- }
- } else {
- if (a[i] < 0) {
- s.append("-");
- }
- }
-
- double absAi = Math.abs(a[i]);
- if ((absAi - 1) != 0) {
- s.append(java.lang.Double.toString(absAi));
- s.append(' ');
- }
-
- s.append("x");
- if (i > 1) {
- s.append('^');
- s.append(Integer.toString(i));
- }
- }
-
- }
-
- return s.toString();
-
- }
-
- /** Coefficients array. */
- protected double[] a;
-
- private static final long serialVersionUID = -4210522025715687648L;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java b/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java
deleted file mode 100644
index 7399074..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java
+++ /dev/null
@@ -1,346 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import java.io.Serializable;
-import java.math.BigInteger;
-
-/**
- * This class implements fractions of polynomials with one unknown and
- * rational coefficients.
- * <p>Instances of this class are immutable.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class PolynomialFraction implements Serializable {
-
- /**
- * Simple constructor.
- * Build a constant null fraction
- */
- public PolynomialFraction() {
- this(new Polynomial.Rational(RationalNumber.ZERO),
- new Polynomial.Rational(RationalNumber.ONE));
- }
-
- /**
- * Simple constructor.
- * Build a fraction from a numerator and a denominator.
- * @param numerator numerator of the fraction
- * @param denominator denominator of the fraction
- * @exception ArithmeticException if the denominator is null
- */
- public PolynomialFraction(long numerator, long denominator) {
- this(new Polynomial.Rational(numerator),
- new Polynomial.Rational(denominator));
- }
-
- /**
- * Simple constructor.
- * Build a fraction from a numerator and a denominator.
- * @param numerator numerator of the fraction
- * @param denominator denominator of the fraction
- * @exception ArithmeticException if the denominator is null
- */
- public PolynomialFraction(BigInteger numerator, BigInteger denominator) {
- this(new Polynomial.Rational(new RationalNumber(numerator)),
- new Polynomial.Rational(new RationalNumber(denominator)));
- }
-
- /**
- * Simple constructor.
- * Build a fraction from a numerator and a denominator.
- * @param numerator numerator of the fraction
- * @param denominator denominator of the fraction
- * @exception ArithmeticException if the denominator is null
- */
- public PolynomialFraction(RationalNumber numerator,
- RationalNumber denominator) {
- this(new Polynomial.Rational(numerator),
- new Polynomial.Rational(denominator));
- }
-
- /**
- * Simple constructor.
- * Build a fraction from a numerator and a denominator.
- * @param numerator numerator of the fraction
- * @param denominator denominator of the fraction
- * @exception ArithmeticException if the denominator is null
- */
- public PolynomialFraction(Polynomial.Rational numerator,
- Polynomial.Rational denominator) {
-
- if (denominator.isZero()) {
- throw new ArithmeticException("null denominator");
- }
-
- p = numerator;
- q = denominator;
-
- RationalNumber[] a = q.getCoefficients();
- if (a[a.length - 1].isNegative()) {
- p = (Polynomial.Rational) p.negate();
- q = (Polynomial.Rational) q.negate();
- }
-
- simplify();
-
- }
-
- /** Simple constructor.
- * Build a fraction from a single integer
- * @param l value of the fraction
- */
- public PolynomialFraction(long l) {
- this(l, 1l);
- }
-
- /**
- * Simple constructor.
- * Build a fraction from a single integer
- * @param i value of the fraction
- */
- public PolynomialFraction(BigInteger i) {
- this(i, BigInteger.ONE);
- }
-
- /** Simple constructor.
- * Build a fraction from a single rational number
- * @param r value of the fraction
- */
- public PolynomialFraction(RationalNumber r) {
- this(r.getNumerator(), r.getDenominator());
- }
-
- /** Simple constructor.
- * Build a fraction from a single Polynomial
- * @param p value of the fraction
- */
- public PolynomialFraction(Polynomial.Rational p) {
- this(p, new Polynomial.Rational(1l));
- }
-
- /** Negate the instance.
- * @return a new polynomial fraction opposite to the instance
- */
- public PolynomialFraction negate() {
- return new PolynomialFraction((Polynomial.Rational) p.negate(), q);
- }
-
- /** Add a polynomial fraction to the instance.
- * @param f polynomial fraction to add.
- * @return a new polynomial fraction
- */
- public PolynomialFraction add(PolynomialFraction f) {
- return new PolynomialFraction(p.multiply(f.q).add(f.p.multiply(q)),
- q.multiply(f.q));
- }
-
- /** Subtract a fraction from the instance.
- * @param f polynomial fraction to subtract.
- * @return a new polynomial fraction
- */
- public PolynomialFraction subtract(PolynomialFraction f) {
- return new PolynomialFraction(p.multiply(f.q).subtract(f.p.multiply(q)),
- q.multiply(f.q));
- }
-
- /** Multiply the instance by a polynomial fraction.
- * @param f polynomial fraction to multiply by
- * @return a new polynomial fraction
- */
- public PolynomialFraction multiply(PolynomialFraction f) {
- PolynomialFraction product =
- new PolynomialFraction(p.multiply(f.p), q.multiply(f.q));
- product.simplify();
- return product;
- }
-
- /** Divide the instance by a polynomial fraction.
- * @param f polynomial fraction to divide by
- * @return a new polynomial fraction
- * @exception ArithmeticException if f is null
- */
- public PolynomialFraction divide(PolynomialFraction f) {
-
- if (f.p.isZero()) {
- throw new ArithmeticException("divide by zero");
- }
-
- Polynomial.Rational newP = p.multiply(f.q);
- Polynomial.Rational newQ = q.multiply(f.p);
-
- RationalNumber[] a = newQ.getCoefficients();
- if (a[a.length - 1].isNegative()) {
- newP = (Polynomial.Rational) newP.negate();
- newQ = (Polynomial.Rational) newQ.negate();
- }
-
- PolynomialFraction result = new PolynomialFraction(newP, newQ);
- result.simplify();
- return result;
-
- }
-
- /** Invert the instance.
- * @return the inverse of the instance
- * @exception ArithmeticException if the instance is zero
- */
- public PolynomialFraction invert() {
-
- if (p.isZero()) {
- throw new ArithmeticException("divide by zero");
- }
-
- RationalNumber[] a = p.getCoefficients();
- PolynomialFraction inverse =
- (a[a.length - 1].isNegative())
- ? new PolynomialFraction((Polynomial.Rational) q.negate(),
- (Polynomial.Rational) p.negate())
- : new PolynomialFraction(q, p);
- inverse.simplify();
- return inverse;
-
- }
-
- /** Simplify a fraction.
- * If the denominator polynom is a constant polynom, then
- * simplification involves merging this constant in the rational
- * coefficients of the numerator in order to replace the denominator
- * by the constant 1. If the degree of the denominator is non null,
- * then simplification involves both removing common polynomial
- * factors (by euclidian division) and replacing rational
- * coefficients by integer coefficients (multiplying both numerator
- * and denominator by the proper value). The signs of both the
- * numerator and the denominator are adjusted in order to have a
- * positive leeding degree term in the denominator.
- */
- private void simplify() {
-
- Polynomial.Rational a = p;
- Polynomial.Rational b = q;
- if (a.getDegree() < b.getDegree()) {
- Polynomial.Rational tmp = a;
- a = b;
- b = tmp;
- }
-
- Polynomial.DivisionResult res =
- Polynomial.Rational.euclidianDivision(a, b);
- while (res.remainder.getDegree() != 0) {
- a = b;
- b = res.remainder;
- res = Polynomial.Rational.euclidianDivision(a, b);
- }
-
- if (res.remainder.isZero()) {
- // there is a common factor we can remove
- p = Polynomial.Rational.euclidianDivision(p, b).quotient;
- q = Polynomial.Rational.euclidianDivision(q, b).quotient;
- }
-
- if (q.getDegree() == 0) {
- if (! q.isOne()) {
- p = (Polynomial.Rational) p.divide(q.getCoefficients()[0]);
- q = new Polynomial.Rational(1l);
- }
- } else {
-
- BigInteger lcm = p.getDenominatorsLCM();
- if (lcm.compareTo(BigInteger.ONE) != 0) {
- p = (Polynomial.Rational) p.multiply(lcm);
- q = (Polynomial.Rational) q.multiply(lcm);
- }
-
- lcm = q.getDenominatorsLCM();
- if (lcm.compareTo(BigInteger.ONE) != 0) {
- p = (Polynomial.Rational) p.multiply(lcm);
- q = (Polynomial.Rational) q.multiply(lcm);
- }
-
- }
-
- if (q.getCoefficients()[q.getDegree()].isNegative()) {
- p = (Polynomial.Rational) p.negate();
- q = (Polynomial.Rational) q.negate();
- }
-
- }
-
- /**
- * Get the numerator.
- * @return the numerator
- */
- public Polynomial.Rational getNumerator() {
- return p;
- }
-
- /**
- * Get the denominator.
- * @return the denominator (leeding coefficient is always positive)
- */
- public Polynomial.Rational getDenominator() {
- return q;
- }
-
- public String toString() {
- if (p.isZero()) {
- return "0";
- } else if (q.isOne()) {
- return p.toString();
- } else {
-
- StringBuffer s = new StringBuffer();
-
- String pString = p.toString();
- if (pString.indexOf(' ') > 0) {
- s.append('(');
- s.append(pString);
- s.append(')');
- } else {
- s.append(pString);
- }
-
- s.append('/');
-
- String qString = q.toString();
- if (qString.indexOf(' ') > 0) {
- s.append('(');
- s.append(qString);
- s.append(')');
- } else {
- s.append(qString);
- }
-
- return s.toString();
-
- }
- }
-
- /** Numerator. */
- private Polynomial.Rational p;
-
- /** Denominator. */
- private Polynomial.Rational q;
-
- private static final long serialVersionUID = 6033909492898954748L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java b/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java
deleted file mode 100644
index c39848f..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java
+++ /dev/null
@@ -1,373 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import java.io.Serializable;
-import java.math.BigInteger;
-
-/**
- * This class implements reduced rational numbers.
- * <p>Instances of this class are immutable.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class RationalNumber implements Serializable {
-
- /** Zero as a rational numer. */
- public static final RationalNumber ZERO = new RationalNumber(0l);
-
- /** One as a rational numer. */
- public static final RationalNumber ONE = new RationalNumber(1l);
-
- /**
- * Simple constructor.
- * Build a null rational number
- */
- public RationalNumber() {
- p = BigInteger.ZERO;
- q = BigInteger.ONE;
- }
-
- /** Simple constructor.
- * Build a rational number from a numerator and a denominator.
- * @param numerator numerator of the rational number
- * @param denominator denominator of the rational number
- * @exception ArithmeticException if the denominator is zero
- */
- public RationalNumber(long numerator, long denominator) {
-
- if (denominator == 0l) {
- throw new ArithmeticException("divide by zero");
- }
-
- p = BigInteger.valueOf(numerator);
- q = BigInteger.valueOf(denominator);
-
- if (q.signum() < 0) {
- p = p.negate();
- q = q.negate();
- }
-
- simplify();
-
- }
-
- /** Simple constructor.
- * Build a rational number from a numerator and a denominator.
- * @param numerator numerator of the rational number
- * @param denominator denominator of the rational number
- * @exception ArithmeticException if the denominator is zero
- */
- public RationalNumber(BigInteger numerator, BigInteger denominator) {
-
- if (denominator.signum() == 0) {
- throw new ArithmeticException("divide by zero");
- }
-
- p = numerator;
- q = denominator;
-
- if (q.signum() < 0) {
- p = p.negate();
- q = q.negate();
- }
-
- simplify();
-
- }
-
- /** Simple constructor.
- * Build a rational number from a single integer
- * @param l value of the rational number
- */
- public RationalNumber(long l) {
- p = BigInteger.valueOf(l);
- q = BigInteger.ONE;
- }
-
- /** Simple constructor.
- * Build a rational number from a single integer
- * @param i value of the rational number
- */
- public RationalNumber(BigInteger i) {
- p = i;
- q = BigInteger.ONE;
- }
-
- /** Negate the instance.
- * @return a new rational number, opposite to the isntance
- */
- public RationalNumber negate() {
- return new RationalNumber(p.negate(), q);
- }
-
- /** Add an integer to the instance.
- * @param l integer to add
- * @return a new rational number which is the sum of the instance and l
- */
- public RationalNumber add(long l) {
- return add(BigInteger.valueOf(l));
- }
-
- /** Add an integer to the instance.
- * @param l integer to add
- * @return a new rational number which is the sum of the instance and l
- */
- public RationalNumber add(BigInteger l) {
- return new RationalNumber(p.add(q.multiply(l)), q);
- }
-
- /** Add a rational number to the instance.
- * @param r rational number to add
- * @return a new rational number which is the sum of the instance and r
- */
- public RationalNumber add(RationalNumber r) {
- return new RationalNumber(p.multiply(r.q).add(r.p.multiply(q)),
- q.multiply(r.q));
- }
-
- /** Subtract an integer from the instance.
- * @param l integer to subtract
- * @return a new rational number which is the difference the instance minus l
- */
- public RationalNumber subtract(long l) {
- return subtract(BigInteger.valueOf(l));
- }
-
- /** Subtract an integer from the instance.
- * @param l integer to subtract
- * @return a new rational number which is the difference the instance minus l
- */
- public RationalNumber subtract(BigInteger l) {
- return new RationalNumber(p.subtract(q.multiply(l)), q);
- }
-
- /** Subtract a rational number from the instance.
- * @param r rational number to subtract
- * @return a new rational number which is the difference the instance minus r
- */
- public RationalNumber subtract(RationalNumber r) {
- return new RationalNumber(p.multiply(r.q).subtract(r.p.multiply(q)),
- q.multiply(r.q));
- }
-
- /** Multiply the instance by an integer.
- * @param l integer to multiply by
- * @return a new rational number which is the produc of the instance by l
- */
- public RationalNumber multiply(long l) {
- return multiply(BigInteger.valueOf(l));
- }
-
- /** Multiply the instance by an integer.
- * @param l integer to multiply by
- * @return a new rational number which is the produc of the instance by l
- */
- public RationalNumber multiply(BigInteger l) {
- return new RationalNumber(p.multiply(l), q);
- }
-
- /** Multiply the instance by a rational number.
- * @param r rational number to multiply the instance with
- * @return a new rational number which is the product of the instance and r
- */
- public RationalNumber multiply(RationalNumber r) {
- return new RationalNumber(p.multiply(r.p), q.multiply(r.q));
- }
-
- /** Divide the instance by an integer.
- * @param l integer to divide by
- * @return a new rational number which is the quotient of the instance by l
- * @exception ArithmeticException if l is zero
- */
- public RationalNumber divide(long l) {
- return divide(BigInteger.valueOf(l));
- }
-
- /** Divide the instance by an integer.
- * @param l integer to divide by
- * @return a new rational number which is the quotient of the instance by l
- * @exception ArithmeticException if l is zero
- */
- public RationalNumber divide(BigInteger l) {
-
- if (l.signum() == 0) {
- throw new ArithmeticException("divide by zero");
- }
-
- if (l.signum() > 0) {
- return new RationalNumber(p, q.multiply(l));
- }
-
- return new RationalNumber(p.negate(), q.multiply(l.negate()));
-
- }
-
- /** Divide the instance by a rational number.
- * @param r rational number to divide by
- * @return a new rational number which is the quotient of the instance by r
- * @exception ArithmeticException if r is zero
- */
- public RationalNumber divide(RationalNumber r) {
-
- if (r.p.signum() == 0) {
- throw new ArithmeticException("divide by zero");
- }
-
- BigInteger newP = p.multiply(r.q);
- BigInteger newQ = q.multiply(r.p);
-
- return (newQ.signum() < 0) ? new RationalNumber(newP.negate(),
- newQ.negate())
- : new RationalNumber(newP, newQ);
-
- }
-
- /** Invert the instance.
- * @return the inverse of the instance
- * @exception ArithmeticException if the instance is zero
- */
- public RationalNumber invert() {
-
- if (p.signum() == 0) {
- throw new ArithmeticException("divide by zero");
- }
-
- return (q.signum() < 0) ? new RationalNumber(q.negate(), p.negate())
- : new RationalNumber(q, p);
-
- }
-
- /** Simplify a rational number by removing common factors.
- */
- private void simplify() {
- if (p.signum() == 0) {
- q = BigInteger.ONE;
- } else {
- BigInteger gcd = p.gcd(q);
- p = p.divide(gcd);
- q = q.divide(gcd);
- }
- }
-
- /** Get the numerator.
- * @return the signed numerator
- */
- public BigInteger getNumerator() {
- return p;
- }
-
- /** Get the denominator.
- * @return the denominator (always positive)
- */
- public BigInteger getDenominator() {
- return q;
- }
-
- /** Check if the number is zero.
- * @return true if the number is zero
- */
- public boolean isZero() {
- return p.signum() == 0;
- }
-
- /** Check if the number is one.
- * @return true if the number is one
- */
- public boolean isOne() {
- return (p.compareTo(BigInteger.ONE) == 0)
- && (q.compareTo(BigInteger.ONE) == 0);
- }
-
- /** Check if the number is integer.
- * @return true if the number is an integer
- */
- public boolean isInteger() {
- return q.compareTo(BigInteger.ONE) == 0;
- }
-
- /** Check if the number is negative.
- * @return true if the number is negative
- */
- public boolean isNegative() {
- return p.signum() < 0;
- }
-
- /** Get the absolute value of a rational number.
- * @param r rational number from which we want the absolute value
- * @return a new rational number which is the absolute value of r
- */
- public static RationalNumber abs(RationalNumber r) {
- return new RationalNumber(r.p.abs(), r.q);
- }
-
- /** Return the <code>double</code> value of the instance.
- * @return the double value of the instance
- */
- public double doubleValue() {
- BigInteger[] result = p.divideAndRemainder(q);
- return result[0].doubleValue()
- + (result[1].doubleValue() / q.doubleValue());
- }
-
- /** Check if the instance is equal to another rational number.
- * Equality here is having the same value.
- * @return true if the object is a rational number which has the
- * same value as the instance
- */
- public boolean equals(Object o) {
- if (o instanceof RationalNumber) {
- RationalNumber r = (RationalNumber) o;
- return (p.compareTo(r.p) == 0) && (q.compareTo(r.q) == 0);
- }
- return false;
- }
-
- /** Returns a hash code value for the object.
- * The hash code value is computed from the reduced numerator and
- * denominator, hence equal rational numbers have the same hash code,
- * as required by the method specification.
- * @return a hash code value for this object.
- */
- public int hashCode() {
- return p.hashCode() ^ q.hashCode();
- }
-
- /** Returns a string representation of the rational number.
- * The representation is reduced: there is no common factor left
- * between the numerator and the denominator. The '/' character and
- * the denominator are displayed only if the denominator is not
- * one. The sign is on the numerator.
- * @return string representation of the rational number
- */
- public String toString() {
- return p + ((q.compareTo(BigInteger.ONE) == 0) ? "" : ("/" + q));
- }
-
- /** Numerator. */
- private BigInteger p;
-
- /** Denominator. */
- private BigInteger q;
-
- private static final long serialVersionUID = -324954393137577531L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/ExhaustedSampleException.java b/src/mantissa/src/org/spaceroots/mantissa/functions/ExhaustedSampleException.java
deleted file mode 100644
index 0993fed..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/ExhaustedSampleException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions;
-
-import org.spaceroots.mantissa.MantissaException;
-
-/** This class represents exceptions thrown by sample iterators.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class ExhaustedSampleException
- extends MantissaException {
-
- /** Simple constructor.
- * @param size size of the sample
- */
- public ExhaustedSampleException(int size) {
- super("sample contains only {0} elements",
- new String[] { Integer.toString(size) });
- }
-
- private static final long serialVersionUID = -1490493298938282440L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/FunctionException.java b/src/mantissa/src/org/spaceroots/mantissa/functions/FunctionException.java
deleted file mode 100644
index 88daabf..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/FunctionException.java
+++ /dev/null
@@ -1,59 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions;
-
-import org.spaceroots.mantissa.MantissaException;
-
-/** This class represents exceptions thrown by scalar functions.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class FunctionException
- extends MantissaException {
-
- /** Simple constructor.
- * Build an exception by translating and formating a message
- * @param specifier format specifier (to be translated)
- * @param parts to insert in the format (no translation)
- */
- public FunctionException(String specifier, String[] parts) {
- super(specifier, parts);
- }
-
- /** Simple constructor.
- * Build an exception by translating the specified message
- * @param message message to translate
- */
- public FunctionException(String message) {
- super(message);
- }
-
- /** Simple constructor.
- * Build an exception from a cause
- * @param cause cause of this exception
- */
- public FunctionException(Throwable cause) {
- super(cause);
- }
-
- private static final long serialVersionUID = 1455885104381976115L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/BasicSampledFunctionIterator.java b/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/BasicSampledFunctionIterator.java
deleted file mode 100644
index 54efe3b..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/BasicSampledFunctionIterator.java
+++ /dev/null
@@ -1,73 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class is a simple wrapper allowing to iterate over a
- * SampledFunction.
-
- * <p>The basic implementation of the iteration interface does not
- * perform any transformation on the sample, it only handles a loop
- * over the underlying sampled function.</p>
-
- * @see SampledFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public class BasicSampledFunctionIterator
- implements SampledFunctionIterator, Serializable {
-
- /** Underlying sampled function. */
- private final SampledFunction function;
-
- /** Next sample element. */
- private int next;
-
- /** Simple constructor.
- * Build an instance from a SampledFunction
- * @param function smapled function over which we want to iterate
- */
- public BasicSampledFunctionIterator(SampledFunction function) {
- this.function = function;
- next = 0;
- }
-
- public boolean hasNext() {
- return next < function.size();
- }
-
- public ScalarValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
- if (next >= function.size()) {
- throw new ExhaustedSampleException(function.size());
- }
-
- int current = next++;
- return function.samplePointAt(current);
-
- }
-
- private static final long serialVersionUID = -9106690005598356403L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ComputableFunction.java b/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ComputableFunction.java
deleted file mode 100644
index 2ef3108..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ComputableFunction.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represents scalar functions of one real variable.
-
- * <p>This interface should be implemented by all scalar functions
- * that can be evaluated at any point. This does not imply that an
- * explicit definition is available, a function given by an implicit
- * function that should be numerically solved for each point for
- * example is considered a computable function.</p>
-
- * <p>The {@link ComputableFunctionSampler} class can be used to
- * transform classes implementing this interface into classes
- * implementing the {@link SampledFunction} interface.</p>
-
- * <p>Several numerical algorithms (Gauss-Legendre integrators for
- * example) need to choose themselves the evaluation points, so they
- * can handle only objects that implement this interface.</p>
-
- * @see org.spaceroots.mantissa.quadrature.scalar.ComputableFunctionIntegrator
- * @see SampledFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public interface ComputableFunction extends Serializable {
-
- /** Get the value of the function at the specified abscissa.
- * @param x current abscissa
- * @return function value
- * @exception FunctionException if something goes wrong
- */
- public double valueAt(double x)
- throws FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ComputableFunctionSampler.java b/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ComputableFunctionSampler.java
deleted file mode 100644
index e834d5d..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ComputableFunctionSampler.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This class is a wrapper allowing to sample a
- * {@link ComputableFunction}.
-
- * <p>The sample produced is a regular sample. It can be specified by
- * several means :
- * <ul>
- * <li> from an initial point a step and a number of points</li>
- * <li> from a range and a number of points</li>
- * <li> from a range and a step between points.</li>
- * </ul>
- * In the latter case, the step can optionaly be adjusted in order to
- * have the last point exactly at the upper bound of the range.</p>
-
- * <p>The sample points are computed on demand, they are not
- * stored. This allow to use this method for very large sample with
- * little memory overhead. The drawback is that if the same sample
- * points are going to be requested several times, they will be
- * recomputed each time. In this case, the user should consider
- * storing the points by some other means.</p>
-
- * @see ComputableFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public class ComputableFunctionSampler
- implements SampledFunction, Serializable {
-
- /** Underlying computable function. */
- private ComputableFunction function;
-
- /** Beginning abscissa. */
- private double begin;
-
- /** Step between points. */
- private double step;
-
- /** Total number of points. */
- private int n;
-
- /**
- * Constructor.
-
- * Build a sample from an {@link ComputableFunction}. Beware of the
- * classical off-by-one problem ! If you want to have a sample like
- * this : 0.0, 0.1, 0.2 ..., 1.0, then you should specify step = 0.1
- * and n = 11 (not n = 10).
-
- * @param begin beginning of the range (will be the abscissa of the
- * first point)
- * @param step step between points
- * @param n number of points
-
- */
- public ComputableFunctionSampler(ComputableFunction function,
- double begin, double step, int n) {
- this.function = function;
- this.begin = begin;
- this.step = step;
- this.n = n;
- }
-
- /**
- * Constructor.
- * Build a sample from an {@link ComputableFunction}.
-
- * @param range abscissa range (from <code>range [0]</code> to
- * <code>range [1]</code>)
- * @param n number of points
- */
- public ComputableFunctionSampler(ComputableFunction function,
- double[] range, int n) {
- this.function = function;
- begin = range[0];
- step = (range[1] - range[0]) / (n - 1);
- this.n = n;
- }
-
- /**
- * Constructor.
- * Build a sample from an {@link ComputableFunction}.
-
- * @param range abscissa range (from <code>range [0]</code> to
- * <code>range [1]</code>)
- * @param step step between points
- * @param adjustStep if true, the step is reduced in order to have
- * the last point of the sample exactly at <code>range [1]</code>,
- * if false the last point will be between <code>range [1] -
- * step</code> and <code>range [1]</code> */
- public ComputableFunctionSampler(ComputableFunction function,
- double[] range, double step,
- boolean adjustStep) {
- this.function = function;
- begin = range [0];
- if (adjustStep) {
- n = (int) Math.ceil((range[1] - range[0]) / step);
- this.step = (range[1] - range[0]) / (n - 1);
- } else {
- n = (int) Math.floor((range[1] - range[0]) / step);
- this.step = step;
- }
- }
-
- public int size() {
- return n;
- }
-
- public ScalarValuedPair samplePointAt(int index)
- throws ArrayIndexOutOfBoundsException, FunctionException {
-
- if (index < 0 || index >= n) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- double x = begin + index * step;
- return new ScalarValuedPair(x, function.valueAt(x));
-
- }
-
- private static final long serialVersionUID = -5127043442851795719L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/SampledFunction.java b/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/SampledFunction.java
deleted file mode 100644
index 682181a..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/SampledFunction.java
+++ /dev/null
@@ -1,68 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represent sampled scalar functions.
-
- * <p>A function sample is an ordered set of points of the form (x, y)
- * where x is the abscissa of the point and y is the function value at
- * x. It is typically a function that has been computed by external
- * means or the result of measurements.</p>
-
- * <p>The {@link ComputableFunctionSampler} class can be used to
- * transform classes implementing the {@link ComputableFunction}
- * interface into classes implementing this interface.</p>
-
- * <p>Sampled functions cannot be directly handled by integrators
- * implementing the {@link
- * org.spaceroots.mantissa.quadrature.scalar.SampledFunctionIntegrator
- * SampledFunctionIntegrator}. These integrators need a {@link
- * SampledFunctionIterator} object to iterate over the
- * sample.</p>
-
- * @see SampledFunctionIterator
- * @see ComputableFunctionSampler
- * @see ComputableFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public interface SampledFunction extends Serializable {
-
- /** Get the number of points in the sample.
- * @return number of points in the sample
- */
- public int size();
-
- /** Get the abscissa and value of the sample at the specified index.
- * @param index index in the sample, should be between 0 and
- * {@link #size} - 1
- * @return abscissa and value of the sample at the specified index
- * @exception ArrayIndexOutOfBoundsException if the index is wrong
- * @exception FunctionException if an eventual underlying function
- * throws one
- */
- public ScalarValuedPair samplePointAt(int index)
- throws ArrayIndexOutOfBoundsException, FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/SampledFunctionIterator.java b/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/SampledFunctionIterator.java
deleted file mode 100644
index 549a918..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/SampledFunctionIterator.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This interface provides iteration services over scalar functions
- * samples.
-
- * @see SampledFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public interface SampledFunctionIterator {
-
- /** Check if the iterator can provide another point.
- * @return true if the iterator can provide another point.
- */
- public boolean hasNext();
-
- /** Get the next point of a sampled function.
- * @return the next point of the sampled function
- * @exception ExhaustedSampleException if the sample has been exhausted
- * @exception FunctionException if the underlying function throws one
- */
- public ScalarValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ScalarValuedPair.java b/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ScalarValuedPair.java
deleted file mode 100644
index e3c6e2f..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/scalar/ScalarValuedPair.java
+++ /dev/null
@@ -1,97 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import java.io.Serializable;
-
-/** This class represents an (x, f(x)) pair for scalar functions.
-
- * <p>A scalar function is a function of one scalar parameter x whose
- * value is a scalar. This class is used has a simple placeholder to
- * contain both an abscissa and the value of the function at this
- * abscissa.</p>
-
- * @see SampledFunction
- * @see org.spaceroots.mantissa.functions.vectorial.VectorialValuedPair
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public class ScalarValuedPair
- implements Serializable {
-
- /** Simple constructor.
- * Build an instance from its coordinates
- * @param x abscissa
- * @param y ordinate (value of the function)
- */
- public ScalarValuedPair(double x, double y) {
- this.x = x;
- this.y = y;
- }
-
- /** Copy-constructor.
- * @param p point to copy
- */
- public ScalarValuedPair(ScalarValuedPair p) {
- x = p.x;
- y = p.y;
- }
-
- /**
- * Getter for the abscissa.
- * @return value of the abscissa
- */
- public double getX() {
- return x;
- }
-
- /**
- * Getter for the ordinate.
- * @return value of the ordinate
- */
- public double getY() {
- return y;
- }
-
- /**
- * Setter for the abscissa.
- * @param x new value for the abscissa
- */
- public void setX(double x) {
- this.x = x;
- }
-
- /**
- * Setter for the ordinate.
- * @param y new value for the ordinate
- */
- public void setY(double y) {
- this.y = y;
- }
-
- /** Abscissa of the point. */
- private double x;
-
- /** Scalar ordinate of the point, y = f (x). */
- private double y;
-
- private static final long serialVersionUID = 1884346552569300794L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/BasicSampledFunctionIterator.java b/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/BasicSampledFunctionIterator.java
deleted file mode 100644
index 82d832f..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/BasicSampledFunctionIterator.java
+++ /dev/null
@@ -1,78 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class is a wrapper allowing to iterate over a
- * SampledFunction.
-
- * <p>The basic implementation of the iteration interface does not
- * perform any transformation on the sample, it only handles a loop
- * over the underlying sampled function.</p>
-
- * @see SampledFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public class BasicSampledFunctionIterator
- implements SampledFunctionIterator, Serializable {
-
- /** Simple constructor.
- * Build an instance from a SampledFunction
- * @param function smapled function over which we want to iterate
- */
- public BasicSampledFunctionIterator(SampledFunction function) {
- this.function = function;
- next = 0;
- }
-
- public int getDimension() {
- return function.getDimension();
- }
-
- public boolean hasNext() {
- return next < function.size();
- }
-
- public VectorialValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
-
- if (next >= function.size()) {
- throw new ExhaustedSampleException(function.size());
- }
-
- int current = next++;
- return function.samplePointAt(current);
-
- }
-
- /** Underlying sampled function. */
- private final SampledFunction function;
-
- /** Next sample element. */
- private int next;
-
- private static final long serialVersionUID = -4386278658288500627L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/ComputableFunction.java b/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/ComputableFunction.java
deleted file mode 100644
index 65456a3..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/ComputableFunction.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represents vectorial functions of one real variable.
-
- * <p>This interface should be implemented by all vectorial functions
- * that can be evaluated at any point. This does not imply that an
- * explicit definition is available, a function given by an implicit
- * function that should be numerically solved for each point for
- * example is considered a computable function.</p>
-
- * <p>The {@link ComputableFunctionSampler} class can be used to
- * transform classes implementing this interface into classes
- * implementing the {@link SampledFunction} interface.</p>
-
- * <p>Several numerical algorithms (Gauss-Legendre integrators for
- * example) need to choose themselves the evaluation points, so they
- * can handle only objects that implement this interface.</p>
-
- * @see org.spaceroots.mantissa.quadrature.vectorial.ComputableFunctionIntegrator
- * @see SampledFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public interface ComputableFunction extends Serializable {
- /** Get the dimension of the vectorial values of the function.
- * @return dimension
- */
- public int getDimension();
-
- /** Get the value of the function at the specified abscissa.
- * @param x current abscissa
- * @return function value
- * @exception FunctionException if something goes wrong
- */
- public double[] valueAt(double x)
- throws FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/ComputableFunctionSampler.java b/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/ComputableFunctionSampler.java
deleted file mode 100644
index 858622c..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/ComputableFunctionSampler.java
+++ /dev/null
@@ -1,150 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This class is a wrapper allowing to sample a
- * {@link ComputableFunction}.
-
- * <p>The sample produced is a regular sample. It can be specified by
- * several means :
- * <ul>
- * <li> from an initial point a step and a number of points</li>
- * <li> from a range and a number of points</li>
- * <li> from a range and a step between points.</li>
- * </ul>
- * In the latter case, the step can optionaly be adjusted in order to
- * have the last point exactly at the upper bound of the range.</p>
-
- * <p>The sample points are computed on demand, they are not
- * stored. This allow to use this method for very large sample with
- * little memory overhead. The drawback is that if the same sample
- * points are going to be requested several times, they will be
- * recomputed each time. In this case, the user should consider
- * storing the points by some other means.</p>
-
- * @see ComputableFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public class ComputableFunctionSampler
- implements SampledFunction, Serializable {
-
- /**
- * Constructor.
-
- * Build a sample from an {@link ComputableFunction}. Beware of the
- * classical off-by-one problem ! If you want to have a sample like
- * this : 0.0, 0.1, 0.2 ..., 1.0, then you should specify step = 0.1
- * and n = 11 (not n = 10).
-
- * @param begin beginning of the range (will be the abscissa of the
- * first point)
- * @param step step between points
- * @param n number of points
-
- */
- public ComputableFunctionSampler(ComputableFunction function,
- double begin, double step, int n) {
- this.function = function;
- this.begin = begin;
- this.step = step;
- this.n = n;
- }
-
- /**
- * Constructor.
- * Build a sample from an {@link ComputableFunction}.
-
- * @param range abscissa range (from <code>range [0]</code> to
- * <code>range [1]</code>)
- * @param n number of points
- */
- public ComputableFunctionSampler(ComputableFunction function,
- double[] range, int n) {
- this.function = function;
- begin = range[0];
- step = (range[1] - range[0]) / (n - 1);
- this.n = n;
- }
-
- /**
- * Constructor.
- * Build a sample from an {@link ComputableFunction}.
-
- * @param range abscissa range (from <code>range [0]</code> to
- * <code>range [1]</code>)
- * @param step step between points
- * @param adjustStep if true, the step is reduced in order to have
- * the last point of the sample exactly at <code>range [1]</code>,
- * if false the last point will be between <code>range [1] -
- * step</code> and <code>range [1]</code> */
- public ComputableFunctionSampler(ComputableFunction function,
- double[] range, double step,
- boolean adjustStep) {
- this.function = function;
- begin = range[0];
- if (adjustStep) {
- n = (int) Math.ceil((range[1] - range[0]) / step);
- this.step = (range[1] - range[0]) / (n - 1);
- } else {
- n = (int) Math.floor((range[1] - range[0]) / step);
- this.step = step;
- }
- }
-
- public int size() {
- return n;
- }
-
- public int getDimension() {
- return function.getDimension();
- }
-
- public VectorialValuedPair samplePointAt(int index)
- throws ArrayIndexOutOfBoundsException, FunctionException {
-
- if (index < 0 || index >= n) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- double x = begin + index * step;
- return new VectorialValuedPair (x, function.valueAt(x));
-
- }
-
- /** Underlying computable function. */
- private ComputableFunction function;
-
- /** Beginning abscissa. */
- private double begin;
-
- /** Step between points. */
- private double step;
-
- /** Total number of points. */
- private int n;
-
- private static final long serialVersionUID = 1368582688313212821L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/SampledFunction.java b/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/SampledFunction.java
deleted file mode 100644
index f9e2131..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/SampledFunction.java
+++ /dev/null
@@ -1,73 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import java.io.Serializable;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represent sampled vectorial functions.
-
- * <p>A function sample is an ordered set of points of the form (x, y)
- * where x is the abscissa of the point and y is the function value at
- * x. It is typically a function that has been computed by external
- * means or the result of measurements.</p>
-
- * <p>The {@link ComputableFunctionSampler} class can be used to
- * transform classes implementing the {@link ComputableFunction}
- * interface into classes implementing this interface.</p>
-
- * <p>Sampled functions cannot be directly handled by integrators
- * implementing the {@link
- * org.spaceroots.mantissa.quadrature.vectorial.SampledFunctionIntegrator
- * SampledFunctionIntegrator}. These integrators need a {@link
- * SampledFunctionIterator} object to iterate over the
- * sample.</p>
-
- * @see SampledFunctionIterator
- * @see ComputableFunctionSampler
- * @see ComputableFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public interface SampledFunction extends Serializable {
-
- /** Get the number of points in the sample.
- * @return number of points in the sample
- */
- public int size();
-
- /** Get the dimension of the vectorial values of the function.
- * @return dimension
- */
- public int getDimension();
-
- /** Get the abscissa and value of the sample at the specified index.
- * @param index index in the sample, should be between 0 and
- * {@link #size} - 1
- * @return abscissa and value of the sample at the specified index
- * @exception ArrayIndexOutOfBoundsException if the index is wrong
- * @exception FunctionException if an eventual underlying function
- * throws one
- */
- public VectorialValuedPair samplePointAt(int index)
- throws ArrayIndexOutOfBoundsException, FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/SampledFunctionIterator.java b/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/SampledFunctionIterator.java
deleted file mode 100644
index 2f5fd5c..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/SampledFunctionIterator.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This interface provides iteration services over vectorial functions
- * samples.
-
- * @see SampledFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public interface SampledFunctionIterator {
-
- /** Get the dimension of the vectorial values of the function.
- * @return dimension
- */
- public int getDimension();
-
- /** Check if the iterator can provide another point.
- * @return true if the iterator can provide another point.
- */
- public boolean hasNext();
-
- /** Get the next point of a sampled function.
- * @return the next point of the sampled function
- * @exception ExhaustedSampleException if the sample has been exhausted
- * @exception FunctionException if the underlying function throws one
- */
- public VectorialValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPair.java b/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPair.java
deleted file mode 100644
index ed12e47..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPair.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import java.io.Serializable;
-
-/** This class represents an (x, f(x)) pair for vectorial functions.
-
- * <p>A vectorial function is a function of one vectorial parameter x whose
- * value is a vector. This class is used has a simple immutable placeholder to
- * contain both an abscissa and the value of the function at this
- * abscissa.</p>
-
- * @see SampledFunction
- * @see org.spaceroots.mantissa.functions.vectorial.VectorialValuedPair
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-public class VectorialValuedPair
- implements Serializable {
-
- /**
- * Simple constructor.
- * Build an instance from its coordinates
- * @param x abscissa
- * @param y ordinate (value of the function)
- */
- public VectorialValuedPair(double x, double[] y) {
- this.x = x;
- this.y = (double[]) y.clone();
- }
-
- /** Abscissa of the point. */
- public final double x;
-
- /** Vectorial ordinate of the point, y = f (x). */
- public final double[] y;
-
- private static final long serialVersionUID = -7397116933564410103L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/DiagonalMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/DiagonalMatrix.java
deleted file mode 100644
index 803ac6f..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/DiagonalMatrix.java
+++ /dev/null
@@ -1,139 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class implements diagonal matrices of linear algebra.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class DiagonalMatrix
- extends SquareMatrix {
-
- /** Simple constructor.
- * This constructor builds a diagonal matrix of specified order, all
- * elements on the diagonal being ones (so this is an identity matrix).
- * @param order order of the matrix
- */
- public DiagonalMatrix(int order) {
- this(order, 1.0);
- }
-
- /** Simple constructor.
- * This constructor builds a diagonal matrix of specified order and
- * set all diagonal elements to the same value.
- * @param order order of the matrix
- * @param value value for the diagonal elements
- */
- public DiagonalMatrix(int order, double value) {
- super(order);
- for (int index = 0; index < order * order; index += order + 1) {
- data[index] = value;
- }
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param order order of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public DiagonalMatrix(int order, double[] data) {
- super(order, data);
- }
-
- /** Copy constructor.
- * @param d diagonal matrix to copy
- */
- public DiagonalMatrix(DiagonalMatrix d) {
- super(d);
- }
-
- public Matrix duplicate() {
- return new DiagonalMatrix(this);
- }
-
- public void setElement(int i, int j, double value) {
- if (i != j) {
- throw new ArrayIndexOutOfBoundsException("cannot set elements"
- + " out of diagonal in a"
- + " diagonal matrix");
- }
- super.setElement(i, j, value);
- }
-
- public double getDeterminant(double epsilon) {
- double determinant = data[0];
- for (int index = columns + 1; index < columns * columns; index += columns + 1) {
- determinant *= data[index];
- }
- return determinant;
- }
-
- public SquareMatrix getInverse(double epsilon)
- throws SingularMatrixException {
-
- DiagonalMatrix inv = new DiagonalMatrix (columns);
-
- for (int index = 0; index < columns * columns; index += columns + 1) {
- if (Math.abs(data[index]) < epsilon) {
- throw new SingularMatrixException();
- }
- inv.data[index] = 1.0 / data[index];
- }
-
- return inv;
-
- }
-
- public Matrix solve(Matrix b, double epsilon)
- throws SingularMatrixException {
-
- Matrix result = b.duplicate();
-
- for (int i = 0; i < columns; ++i) {
- double diag = data[i * (columns + 1)];
- if (Math.abs(diag) < epsilon) {
- throw new SingularMatrixException();
- }
- double inv = 1.0 / diag;
-
- NonNullRange range = result.getRangeForRow(i);
- for (int index = i * b.columns + range.begin;
- index < i * b.columns + range.end;
- ++index) {
- result.data[index] = inv * b.data[index];
- }
- }
-
- return result;
-
- }
-
- public NonNullRange getRangeForRow(int i) {
- return new NonNullRange(i, i + 1);
- }
-
- public NonNullRange getRangeForColumn(int j) {
- return new NonNullRange(j, j + 1);
- }
-
- private static final long serialVersionUID = -2965166085913895323L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/GeneralMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/GeneralMatrix.java
deleted file mode 100644
index 58779bc..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/GeneralMatrix.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class represents matrices of the most general type.
-
- * <p>This class is the basic implementation of matrices to use when
- * nothing special is known about the structure of the matrix.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class GeneralMatrix
- extends Matrix {
-
- /** Simple constructor.
- * Build a matrix with null elements.
- * @param rows number of rows of the matrix
- * @param columns number of columns of the matrix
- */
- public GeneralMatrix(int rows, int columns) {
- super(rows, columns);
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param rows number of rows of the matrix
- * @param columns number of columns of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public GeneralMatrix(int rows, int columns, double[] data) {
- super(rows, columns, data);
- }
-
- /** Copy constructor.
- * @param m matrix to copy
- */
- public GeneralMatrix(Matrix m) {
- super(m);
- }
-
- public Matrix duplicate() {
- return new GeneralMatrix(this);
- }
-
- /** Add a matrix to the instance.
- * This method adds a matrix to the instance. It does modify the instance.
- * @param m matrix to add
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfAdd(Matrix m) {
-
- // validity check
- if ((rows != m.rows) || (columns != m.columns)) {
- throw new IllegalArgumentException("cannot add a "
- + m.rows + 'x' + m.columns
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // addition loop
- for (int index = 0; index < rows * columns; ++index) {
- data[index] += m.data[index];
- }
-
- }
-
- /** Substract a matrix from the instance.
- * This method substracts a matrix from the instance. It does modify the instance.
- * @param m matrix to substract
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfSub(Matrix m) {
-
- // validity check
- if ((rows != m.rows) || (columns != m.columns)) {
- throw new IllegalArgumentException("cannot substract a "
- + m.rows + 'x' + m.columns
- + " matrix from a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // substraction loop
- for (int index = 0; index < rows * columns; ++index) {
- data[index] -= m.data[index];
- }
-
- }
-
- protected NonNullRange getRangeForRow(int i) {
- return new NonNullRange(0, columns);
- }
-
- protected NonNullRange getRangeForColumn(int j) {
- return new NonNullRange(0, rows);
- }
-
- private static final long serialVersionUID = 4350328622456299819L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/GeneralSquareMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/GeneralSquareMatrix.java
deleted file mode 100644
index f60c68c..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/GeneralSquareMatrix.java
+++ /dev/null
@@ -1,276 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class implements general square matrices of linear algebra.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class GeneralSquareMatrix
- extends SquareMatrix {
-
- /** Simple constructor.
- * This constructor builds a square matrix of specified order, all
- * elements beeing zeros.
- * @param order order of the matrix
- */
- public GeneralSquareMatrix(int order) {
- super(order);
- permutations = null;
- evenPermutations = true;
- lower = null;
- upper = null;
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param order order of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public GeneralSquareMatrix(int order, double[] data) {
- super(order, data);
- permutations = null;
- evenPermutations = true;
- lower = null;
- upper = null;
- }
-
- /** Copy constructor.
- * @param s square matrix to copy
- */
- public GeneralSquareMatrix(GeneralSquareMatrix s) {
- super(s);
-
- if (s.permutations != null) {
- permutations = (int[]) s.permutations.clone();
- evenPermutations = s.evenPermutations;
- lower = new LowerTriangularMatrix(s.lower);
- upper = new UpperTriangularMatrix(s.upper);
- } else {
- permutations = null;
- evenPermutations = true;
- lower = null;
- upper = null;
- }
-
- }
-
- public Matrix duplicate() {
- return new GeneralSquareMatrix(this);
- }
-
- public void setElement(int i, int j, double value) {
- super.setElement(i, j, value);
- permutations = null;
- evenPermutations = true;
- lower = null;
- upper = null;
- }
-
- /** Add a matrix to the instance.
- * This method adds a matrix to the instance. It does modify the instance.
- * @param s square matrix to add
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfAdd(SquareMatrix s) {
-
- // validity check
- if ((rows != s.rows) || (columns != s.columns)) {
- throw new IllegalArgumentException("cannot add a "
- + s.rows + 'x' + s.columns
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // addition loop
- for (int index = 0; index < rows * columns; ++index) {
- data[index] += s.data[index];
- }
-
- }
-
- /** Substract a matrix from the instance.
- * This method substracts a matrix from the instance. It does modify the instance.
- * @param s square matrix to substract
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfSub(SquareMatrix s) {
-
- // validity check
- if ((rows != s.rows) || (columns != s.columns)) {
- throw new IllegalArgumentException("cannot substract a "
- + s.rows + 'x' + s.columns
- + " matrix from a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // substraction loop
- for (int index = 0; index < rows * columns; ++index) {
- data[index] -= s.data[index];
- }
-
- }
-
- public double getDeterminant(double epsilon) {
- try {
- if (permutations == null)
- computeLUFactorization(epsilon);
- double d = upper.getDeterminant(epsilon);
- return evenPermutations ? d : -d;
- } catch (SingularMatrixException e) {
- return 0.0;
- }
- }
-
- public Matrix solve(Matrix b, double epsilon)
- throws SingularMatrixException {
- // validity check
- if (b.getRows() != rows) {
- throw new IllegalArgumentException("dimension mismatch");
- }
-
- if (permutations == null) {
- computeLUFactorization(epsilon);
- }
-
- // apply the permutations to the second member
- double[] permData = new double[b.data.length];
- int bCols = b.getColumns();
- for (int i = 0; i < rows; ++i) {
- NonNullRange range = b.getRangeForRow(permutations[i]);
- for (int j = range.begin; j < range.end; ++j) {
- permData[i * bCols + j] = b.data[permutations[i] * bCols + j];
- }
- }
- Matrix permB = MatrixFactory.buildMatrix(b.getRows(), bCols, permData);
-
- // solve the permuted system
- return upper.solve(lower.solve(permB, epsilon), epsilon);
-
- }
-
- protected NonNullRange getRangeForRow(int i) {
- return new NonNullRange(0, columns);
- }
-
- protected NonNullRange getRangeForColumn(int j) {
- return new NonNullRange(0, rows);
- }
-
- private void computeLUFactorization(double epsilon)
- throws SingularMatrixException {
- // build a working copy of the matrix data
- double[] work = new double[rows * columns];
- for (int index = 0; index < work.length; ++index) {
- work[index] = data[index];
- }
-
- // initialize the permutations table to identity
- permutations = new int[rows];
- for (int i = 0; i < rows; ++i) {
- permutations[i] = i;
- }
- evenPermutations = true;
-
- for (int k = 0; k < rows; ++k) {
-
- // find the maximal element in the column
- double maxElt = Math.abs(work[permutations[k] * columns + k]);
- int jMax = k;
- for (int i = k + 1; i < rows; ++i) {
- double curElt = Math.abs(work[permutations[i] * columns + k]);
- if (curElt > maxElt) {
- maxElt = curElt;
- jMax = i;
- }
- }
-
- if (maxElt < epsilon) {
- throw new SingularMatrixException();
- }
-
- if (k != jMax) {
- // do the permutation to have a large enough diagonal element
- int tmp = permutations[k];
- permutations[k] = permutations[jMax];
- permutations[jMax] = tmp;
- evenPermutations = ! evenPermutations;
- }
-
- double inv = 1.0 / work[permutations[k] * columns + k];
-
- // compute the contribution of the row to the triangular matrices
- for (int i = k + 1; i < rows; ++i) {
- double factor = inv * work[permutations[i] * columns + k];
-
- // lower triangular matrix
- work[permutations[i] * columns + k] = factor;
-
- // upper triangular matrix
- int index1 = permutations[i] * columns + k;
- int index2 = permutations[k] * columns + k;
- for (int j = k + 1; j < columns; ++j) {
- work[++index1] -= factor * work[++index2];
- }
- }
- }
-
- // build the matrices
- double[] lowerData = new double[rows * columns];
- double[] upperData = new double[rows * columns];
-
- int index = 0;
- for (int i = 0; i < rows; ++i) {
- int workIndex = permutations[i] * columns;
- int j = 0;
-
- // lower part
- while (j++ < i) {
- lowerData[index] = work[workIndex++];
- upperData[index++] = 0.0;
- }
-
- // diagonal
- lowerData[index] = 1.0;
- upperData[index++] = work[workIndex++];
-
- // upper part
- while (j++ < columns) {
- lowerData[index] = 0.0;
- upperData[index++] = work[workIndex++];
- }
- }
-
- lower = new LowerTriangularMatrix(rows, lowerData);
- upper = new UpperTriangularMatrix(rows, upperData);
-
- }
-
- private int[] permutations;
- private boolean evenPermutations;
- private LowerTriangularMatrix lower;
- private UpperTriangularMatrix upper;
-
- private static final long serialVersionUID = -506293526695298279L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/LowerTriangularMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/LowerTriangularMatrix.java
deleted file mode 100644
index 7b1dee8..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/LowerTriangularMatrix.java
+++ /dev/null
@@ -1,216 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class implements lower triangular matrices of linear algebra.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class LowerTriangularMatrix
- extends SquareMatrix {
-
- /** Simple constructor.
- * This constructor builds a lower triangular matrix of specified order, all
- * elements being zeros.
- * @param order order of the matrix
- */
- public LowerTriangularMatrix(int order) {
- super(order);
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param order order of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public LowerTriangularMatrix(int order, double[] data) {
- super(order, data);
- }
-
- /** Copy constructor.
- * @param l lower triangular matrix to copy
- */
- public LowerTriangularMatrix(LowerTriangularMatrix l) {
- super(l);
- }
-
- public Matrix duplicate() {
- return new LowerTriangularMatrix(this);
- }
-
- public void setElement(int i, int j, double value) {
- if (i < j) {
- throw new ArrayIndexOutOfBoundsException("cannot set elements"
- + " above diagonal of a"
- + " lower triangular matrix");
- }
- super.setElement(i, j, value);
- }
-
- /** Add a matrix to the instance.
- * This method adds a matrix to the instance. It does modify the instance.
- * @param l lower triangular matrix to add
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfAdd(LowerTriangularMatrix l) {
-
- // validity check
- if ((rows != l.rows) || (columns != l.columns)) {
- throw new IllegalArgumentException("cannot add a "
- + l.rows + 'x' + l.columns
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // addition loop
- for (int i = 0; i < rows; ++i) {
- for (int index = i * columns; index < i * (columns + 1) + 1; ++index) {
- data[index] += l.data[index];
- }
- }
-
- }
-
- /** Substract a matrix from the instance.
- * This method substract a matrix from the instance. It does modify the instance.
- * @param l lower triangular matrix to substract
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfSub(LowerTriangularMatrix l) {
-
- // validity check
- if ((rows != l.rows) || (columns != l.columns)) {
- throw new IllegalArgumentException("cannot substract a "
- + l.rows + 'x' + l.columns
- + " matrix from a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // substraction loop
- for (int i = 0; i < rows; ++i) {
- for (int index = i * columns; index < i * (columns + 1) + 1; ++index) {
- data[index] -= l.data[index];
- }
- }
-
- }
-
- public double getDeterminant(double epsilon) {
- double determinant = data[0];
- for (int index = columns + 1; index < columns * columns; index += columns + 1) {
- determinant *= data[index];
- }
- return determinant;
- }
-
- public Matrix solve(Matrix b, double epsilon)
- throws SingularMatrixException {
- // validity check
- if (b.getRows () != rows) {
- throw new IllegalArgumentException("dimension mismatch");
- }
-
- // prepare the data storage
- int bRows = b.getRows();
- int bCols = b.getColumns();
-
- double[] resultData = new double[bRows * bCols];
- int resultIndex = 0;
- int lowerElements = 0;
- int upperElements = 0;
- int minJ = columns;
- int maxJ = 0;
-
- // solve the linear system
- for (int i = 0; i < rows; ++i) {
- double diag = data[i * (columns + 1)];
- if (Math.abs(diag) < epsilon) {
- throw new SingularMatrixException();
- }
- double inv = 1.0 / diag;
-
- NonNullRange range = b.getRangeForRow(i);
- minJ = Math.min(minJ, range.begin);
- maxJ = Math.max(maxJ, range.end);
-
- int j = 0;
- while (j < minJ) {
- resultData[resultIndex] = 0.0;
- ++resultIndex;
- ++j;
- }
-
- // compute the possibly non null elements
- int bIndex = i * bCols + minJ;
- while (j < maxJ) {
-
- // compute the current element
- int index1 = i * columns;
- int index2 = j;
- double value = b.data[bIndex];
- while (index1 < i * (columns + 1)) {
- value -= data[index1] * resultData[index2];
- ++index1;
- index2 += bCols;
- }
- value *= inv;
- resultData[resultIndex] = value;
-
- // count the affected upper and lower elements
- // (in order to deduce the shape of the resulting matrix)
- if (j < i) {
- ++lowerElements;
- } else if (i < j) {
- ++upperElements;
- }
-
- ++bIndex;
- ++resultIndex;
- ++j;
-
- }
-
- while (j < bCols) {
- resultData[resultIndex] = 0.0;
- ++resultIndex;
- ++j;
- }
-
- }
-
- return MatrixFactory.buildMatrix(bRows, bCols, resultData,
- lowerElements, upperElements);
-
- }
-
- public NonNullRange getRangeForRow(int i) {
- return new NonNullRange(0, i + 1);
- }
-
- public NonNullRange getRangeForColumn(int j) {
- return new NonNullRange(j, rows);
- }
-
- private static final long serialVersionUID = 3592505328858227281L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/Matrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/Matrix.java
deleted file mode 100644
index 8fcefdb..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/Matrix.java
+++ /dev/null
@@ -1,484 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import java.io.Serializable;
-
-/** This class factor all services common to matrices.
-
- * <p>This class is the base class of all matrix implementations, it
- * is also the base class of the {@link SquareMatrix} class which adds
- * methods specific to square matrices.</p>
-
- * <p>This class both handles the storage of matrix elements and
- * implements the classical operations on matrices (addition,
- * substraction, multiplication, transposition). It relies on two
- * protected methods ({@link #getRangeForRow} and {@link
- * #getRangeForColumn}) to get tight loop bounds for matrices with
- * known structures full of zeros. These methods should be
- * implemented by derived classes to provide information about their
- * specific shape to the general algorithms implemented by this
- * abstract class.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public abstract class Matrix
- implements Serializable {
- /** Simple constructor.
- * Build a matrix with null elements.
- * @param rows number of rows of the matrix
- * @param columns number of columns of the matrix
- */
- protected Matrix(int rows, int columns) {
- // sanity check
- if (rows <= 0 || columns <= 0) {
- throw new IllegalArgumentException("cannot build a matrix"
- + " with negative or null dimension");
- }
-
- this.rows = rows;
- this.columns = columns;
- data = new double[rows * columns];
- for (int i = 0; i < data.length; ++i) {
- data[i] = 0.0;
- }
-
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param rows number of rows of the matrix
- * @param columns number of columns of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public Matrix(int rows, int columns, double[] data) {
- // sanity check
- if (rows <= 0 || columns <= 0) {
- throw new IllegalArgumentException("cannot build a matrix"
- + " with negative or null dimension");
- }
-
- this.rows = rows;
- this.columns = columns;
- this.data = (data == null) ? null : (double[]) data.clone();
-
- }
-
- /** Copy constructor.
- * @param m matrix to copy
- */
- protected Matrix(Matrix m) {
- rows = m.rows;
- columns = m.columns;
- data = new double[rows * columns];
- System.arraycopy(m.data, 0, data, 0, m.data.length);
- }
-
- /** Polymorphic copy operator.
- * This method build a new object of the same type of the
- * instance. It is somewhat similar to the {@link Object#clone}
- * method, except that it has public access, it doesn't throw any
- * specific exception and it returns a Matrix.
- *@see Object#clone
- */
- public abstract Matrix duplicate();
-
- /** Get the number of rows of the matrix.
- * @return number of rows
- * @see #getColumns
- */
- public int getRows() {
- return rows;
- }
-
- /** Get the number of columns of the matrix.
- * @return number of columns
- * @see #getRows
- */
- public int getColumns() {
- return columns;
- }
-
- /** Get a matrix element.
- * @param i row index, from 0 to rows - 1
- * @param j column index, from 0 to cols - 1
- * @return value of the element
- * @exception ArrayIndexOutOfBoundsException if the indices are wrong
- * @see #setElement
- */
- public double getElement(int i, int j) {
- if (i < 0 || i >= rows || j < 0 || j >= columns) {
- throw new IllegalArgumentException("cannot get element ("
- + i + ", " + j + ") from a "
- + rows + 'x' + columns
- + " matrix");
- }
- return data[i * columns + j];
- }
-
- /** Set a matrix element.
- * @param i row index, from 0 to rows - 1
- * @param j column index, from 0 to cols - 1
- * @param value value of the element
- * @exception ArrayIndexOutOfBoundsException if the indices are wrong
- * @see #getElement
- */
- public void setElement(int i, int j, double value) {
- if (i < 0 || i >= rows || j < 0 || j >= columns) {
- throw new IllegalArgumentException("cannot set element ("
- + i + ", " + j + ") in a "
- + rows + 'x' + columns
- + " matrix");
- }
- data[i * columns + j] = value;
- }
-
- /** Add a matrix to the instance.
- * This method adds a matrix to the instance. It returns a new
- * matrix and does not modify the instance.
- * @param m matrix to add
- * @return a new matrix containing the result
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public Matrix add(Matrix m) {
-
- // validity check
- if ((rows != m.rows) || (columns != m.columns)) {
- throw new IllegalArgumentException("cannot add a "
- + m.rows + 'x' + m.columns
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- double[] resultData = new double[rows * columns];
- int resultIndex = 0;
- int lowerElements = 0;
- int upperElements = 0;
-
- // external loop through the rows
- for (int i = 0; i < rows; ++i) {
- // compute the indices of the internal loop
- NonNullRange r = NonNullRange.reunion(getRangeForRow(i),
- m.getRangeForRow(i));
-
- // assign the zeros before the non null range
- int j = 0;
- while (j < r.begin) {
- resultData[resultIndex] = 0.0;
- ++resultIndex;
- ++j;
- }
-
- // compute the possibly non null elements
- while (j < r.end) {
-
- // compute the current element
- resultData[resultIndex] = data[resultIndex] + m.data[resultIndex];
-
- // count the affected upper and lower elements
- // (in order to deduce the shape of the resulting matrix)
- if (j < i) {
- ++lowerElements;
- } else if (i < j) {
- ++upperElements;
- }
-
- ++resultIndex;
- ++j;
-
- }
-
- // assign the zeros after the non null range
- while (j < columns) {
- resultData[resultIndex++] = 0.0;
- ++resultIndex;
- ++j;
- }
- }
-
- return MatrixFactory.buildMatrix(rows, columns, resultData,
- lowerElements, upperElements);
-
- }
-
- /** Substract a matrix from the instance.
- * This method substracts a matrix from the instance. It returns a new
- * matrix and does not modify the instance.
- * @param m matrix to substract
- * @return a new matrix containing the result
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public Matrix sub(Matrix m) {
-
- // validity check
- if ((rows != m.rows) || (columns != m.columns)) {
- throw new IllegalArgumentException("cannot substract a "
- + m.rows + 'x' + m.columns
- + " matrix from a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- double[] resultData = new double[rows * columns];
- int resultIndex = 0;
- int lowerElements = 0;
- int upperElements = 0;
-
- // external loop through the rows
- for (int i = 0; i < rows; ++i) {
- // compute the indices of the internal loop
- NonNullRange r = NonNullRange.reunion(getRangeForRow(i),
- m.getRangeForRow(i));
-
- // assign the zeros before the non null range
- int j = 0;
- while (j < r.begin) {
- resultData[resultIndex] = 0.0;
- ++resultIndex;
- ++j;
- }
-
- // compute the possibly non null elements
- while (j < r.end) {
-
- // compute the current element
- resultData[resultIndex] = data[resultIndex] - m.data[resultIndex];
-
- // count the affected upper and lower elements
- // (in order to deduce the shape of the resulting matrix)
- if (j < i) {
- ++lowerElements;
- } else if (i < j) {
- ++upperElements;
- }
-
- ++resultIndex;
- ++j;
-
- }
-
- // assign the zeros after the non null range
- while (j < columns) {
- resultData[resultIndex++] = 0.0;
- ++resultIndex;
- ++j;
- }
- }
-
- return MatrixFactory.buildMatrix(rows, columns, resultData,
- lowerElements, upperElements);
-
- }
-
- /** Multiply the instance by a matrix.
- * This method multiplies the instance by a matrix. It returns a new
- * matrix and does not modify the instance.
- * @param m matrix by which to multiply
- * @return a new matrix containing the result
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public Matrix mul(Matrix m) {
-
- // validity check
- if (columns != m.rows) {
- throw new IllegalArgumentException("cannot multiply a "
- + rows + 'x' + columns
- + " matrix by a "
- + m.rows + 'x' + m.columns
- + " matrix");
- }
-
- double[] resultData = new double[rows * m.columns];
- int resultIndex = 0;
- int lowerElements = 0;
- int upperElements = 0;
-
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < m.columns; ++j) {
- double value = 0.0;
-
- // compute the tighter possible indices of the internal loop
- NonNullRange r = NonNullRange.intersection(getRangeForRow(i),
- m.getRangeForColumn(j));
-
- if (r.begin < r.end) {
- int k = r.begin;
- int idx = i * columns + k;
- int midx = k * m.columns + j;
- while (k++ < r.end) {
- value += data[idx++] * m.data[midx];
- midx += m.columns;
- }
-
- // count the affected upper and lower elements
- // (in order to deduce the shape of the resulting matrix)
- if (j < i) {
- ++lowerElements;
- } else if (i < j) {
- ++upperElements;
- }
-
- }
-
- // store the element value
- resultData[resultIndex++] = value;
-
- }
- }
-
- return MatrixFactory.buildMatrix(rows, m.columns, resultData,
- lowerElements, upperElements);
-
- }
-
- /** Multiply the instance by a scalar.
- * This method multiplies the instance by a scalar. It returns a new
- * matrix and does not modify the instance.
- * @param a scalar by which to multiply
- * @return a new matrix containing the result
- * @see #selfMul(double)
- */
- public Matrix mul(double a) {
- Matrix copy = duplicate();
- copy.selfMul(a);
- return copy;
- }
-
- /** Multiply the instance by a scalar.
- * This method multiplies the instance by a scalar.
- * It does modify the instance.
- * @param a scalar by which to multiply
- * @see #mul(double)
- */
- public void selfMul(double a) {
- for (int i = 0; i < rows; ++i) {
- NonNullRange r = getRangeForRow(i);
- for (int j = r.begin, index = i * columns + r.begin; j < r.end; ++j) {
- data[index++] *= a;
- }
- }
-
- }
-
- /** Compute the transpose of the instance.
- * This method transposes the instance. It returns a new
- * matrix and does not modify the instance.
- * @return a new matrix containing the result
- */
- public Matrix getTranspose() {
-
- double[] resultData = new double[columns * rows];
- int resultIndex = 0;
- int upperElements = 0;
- int lowerElements = 0;
-
- for (int i = 0; i < columns; ++i) {
- // compute the indices of the internal loop
- NonNullRange range = getRangeForColumn(i);
-
- int j = 0;
- int index = i;
-
- // assign the zeros before the non null range
- while (j < range.begin) {
- resultData[resultIndex++] = 0.0;
- index += columns;
- ++j;
- }
-
- // compute the possibly non null elements
- while (j < range.end) {
- resultData[resultIndex] = data[index];
-
- // count the affected upper and lower elements
- // (in order to deduce the shape of the resulting matrix)
- if (j < i) {
- ++lowerElements;
- } else if (i < j) {
- ++upperElements;
- }
-
- index += columns;
- ++resultIndex;
- ++j;
-
- }
-
- // assign the zeros after the non null range
- while (j < rows) {
- resultData[resultIndex] = 0.0;
- ++resultIndex;
- ++j;
- }
-
- }
-
- return MatrixFactory.buildMatrix(columns, rows, resultData,
- lowerElements, upperElements);
-
- }
-
- /** Set a range to the non null part covered by a row.
- * @param i index of the row
- * @return range of non nul elements in the specified row
- * @see #getRangeForColumn
- */
- protected abstract NonNullRange getRangeForRow(int i);
-
- /** Set a range to the non null part covered by a column.
- * @param j index of the column
- * @return range of non nul elements in the specified column
- * @see #getRangeForRow
- */
- protected abstract NonNullRange getRangeForColumn(int j);
-
- public String toString() {
- String separator = System.getProperty("line.separator");
-
- StringBuffer buf = new StringBuffer();
- for (int index = 0; index < rows * columns; ++index) {
- if (index > 0) {
- if (index % columns == 0) {
- buf.append(separator);
- } else {
- buf.append(' ');
- }
- }
- buf.append(Double.toString(data[index]));
- }
-
- return buf.toString();
-
- }
-
- /** number of rows of the matrix. */
- protected final int rows;
-
- /** number of columns of the matrix. */
- protected final int columns;
-
- /** array of the matrix elements.
- * the elements are stored in a one dimensional array, row after row
- */
- protected final double[] data;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/MatrixFactory.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/MatrixFactory.java
deleted file mode 100644
index 4648dea..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/MatrixFactory.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class is a factory for the linear algebra package.
-
- * <p>This class is devoted to building the right type of matrix
- * according to the structure of the non null elements.</p>
-
- * <p>This is a utility class, no instance of this class should be
- * built, so the constructor is explicitly made private.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class MatrixFactory {
- /** Simple constructor.
- * Since the class is a utility class with only static methods, the
- * constructor is made private to prevent creating instances of this
- * class.
- */
- private MatrixFactory() {
- }
-
- /** Build a matrix of the right subtype.
- * Build the right subtype of matrix according to the structure of
- * the non null elements of the instance. Note that the information
- * provided does not allow to build instances of the {@link
- * SymetricalMatrix} class. When the data corresponding to a
- * symetrical matrix is given, this method can only build an
- * instance of the {@link GeneralSquareMatrix} class.
- * @param rows number of row of the matrix
- * @param columns number of columns of the matrix
- * @param data table of the matrix elements (stored row after row)
- * @param lowerElements number of non null elements in the lower triangle
- * @param upperElements number of non null elements in the upper triangle
- * @return a matrix containing the instance
- */
- public static Matrix buildMatrix(int rows, int columns, double[] data,
- int lowerElements, int upperElements) {
- if (rows == columns) {
- if (lowerElements == 0 && upperElements == 0) {
- return new DiagonalMatrix(rows, data);
- } else if (lowerElements == 0) {
- return new UpperTriangularMatrix(rows, data);
- } else if (upperElements == 0) {
- return new LowerTriangularMatrix(rows, data);
- } else {
- return new GeneralSquareMatrix(rows, data);
- }
- }
- return new GeneralMatrix(rows, columns, data);
- }
-
- /** Build a matrix of the right subtype.
- * Build the right subtype of matrix according to the dimensions.
- * @param rows number of row of the matrix
- * @param columns number of columns of the matrix
- * @param data table of the matrix elements (stored row after row)
- * @return a matrix containing the instance
- */
- public static Matrix buildMatrix(int rows, int columns, double[] data) {
- if (rows == columns) {
- return new GeneralSquareMatrix(rows, data);
- }
- return new GeneralMatrix(rows, columns, data);
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/NonNullRange.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/NonNullRange.java
deleted file mode 100644
index 521e0e0..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/NonNullRange.java
+++ /dev/null
@@ -1,103 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import java.io.Serializable;
-
-/** This class represents range of non null elements for rows or
- * columns of matrices.
-
- * <p>This class is used to reduce the computation loops by avoiding
- * using elements that are known to be zeros. For full matrices, the
- * range simply spans from 0 to the order of the matrix. For lower and
- * upper triangular matrices, its width will depend on the index of
- * the row or column considered. For diagonal matrices, the range is
- * reduced to one index.</p>
-
- * <p>The indices provided by the class correspond to the elements
- * that are non-null only according to the <emph>structure</emph> of
- * the matrix. The real value of the element is not
- * considered. Consider for example the following lower triangular
- * matrix :</p>
-
- * <pre>
- * 1 0 0 0
- * 2 8 0 0
- * 0 5 3 0
- * 3 2 4 4
- * </pre>
-
- * <p>The third rows begins with zero, but this is not a consequence
- * of the lower triangular structure, it is only a
- * coincidence. Therefore, the range (in row/columns count)
- * corresponding to third row will span from 0 to 2, not from 1 to 2.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-class NonNullRange
- implements Serializable {
-
- /** Index in row/column count of the first non-null element. */
- public final int begin;
-
- /** Index in row/column count after the last non-null element. */
- public final int end;
-
- /** Simple constructor.
- * @param begin index in row/column count of the first non-null element
- * @param end index in row/column count after the last non-null element
- */
- public NonNullRange(int begin, int end)
- {
- this.begin = begin;
- this.end = end;
- }
-
- /** Copy constructor.
- * @param range range to copy.
- */
- public NonNullRange(NonNullRange range) {
- begin = range.begin;
- end = range.end;
- }
-
- /** Build the intersection of two ranges.
- * @param first first range to consider
- * @param second second range to consider
- */
- public static NonNullRange intersection(NonNullRange first,
- NonNullRange second) {
- return new NonNullRange(Math.max(first.begin, second.begin),
- Math.min(first.end, second.end));
- }
-
- /** Build the reunion of two ranges.
- * @param first first range to consider
- * @param second second range to consider
- */
- public static NonNullRange reunion(NonNullRange first,
- NonNullRange second) {
- return new NonNullRange(Math.min(first.begin, second.begin),
- Math.max(first.end, second.end));
- }
-
- private static final long serialVersionUID = 8175301560126132666L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/SingularMatrixException.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/SingularMatrixException.java
deleted file mode 100644
index 3082889..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/SingularMatrixException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import org.spaceroots.mantissa.MantissaException;
-
-/** This class represent exceptions thrown by some matrix operations.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class SingularMatrixException
- extends MantissaException {
-
- /** Simple constructor.
- * Build an exception with a default message
- */
- public SingularMatrixException() {
- super("singular matrix");
- }
-
- private static final long serialVersionUID = 7531357987468317564L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/SquareMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/SquareMatrix.java
deleted file mode 100644
index 617a3ab..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/SquareMatrix.java
+++ /dev/null
@@ -1,99 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class factor all services common to square matrices of linear algebra.
-
- * <p>This class is the base class of all square matrix
- * implementations. It extends the {@link Matrix} class with methods
- * specific to square matrices.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public abstract class SquareMatrix
- extends Matrix {
- /** Simple constructor.
- * Build a matrix with null elements.
- * @param order order of the matrix
- */
- protected SquareMatrix(int order) {
- super(order, order);
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param order order of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- protected SquareMatrix(int order, double[] data) {
- super(order, order, data);
- }
-
- /** Copy constructor.
- * @param m matrix to copy
- */
- protected SquareMatrix(SquareMatrix m) {
- super(m);
- }
-
- /** Get the determinant of the matrix.
- * @param epsilon threshold on matrix elements below which the
- * matrix is considered singular (this is used by the derived
- * classes that use a factorization to compute the determinant)
- * @return the determinant of the matrix
- */
- public abstract double getDeterminant(double epsilon);
-
- /** Invert the instance.
- * @param epsilon threshold on matrix elements below which the
- * matrix is considered singular
- * @return the inverse matrix of the instance
- * @exception SingularMatrixException if the matrix is singular
- */
- public SquareMatrix getInverse(double epsilon)
- throws SingularMatrixException {
- return solve(new DiagonalMatrix (columns), epsilon);
- }
-
-
- /** Solve the <tt>A.X = B</tt> equation.
- * @param b second term of the equation
- * @param epsilon threshold on matrix elements below which the
- * matrix is considered singular
- * @return a matrix X such that <tt>A.X = B</tt>, where A is the instance
- * @exception SingularMatrixException if the matrix is singular
- */
- public abstract Matrix solve(Matrix b, double epsilon)
- throws SingularMatrixException;
-
- /** Solve the <tt>A.X = B</tt> equation.
- * @param b second term of the equation
- * @param epsilon threshold on matrix elements below which the
- * matrix is considered singular
- * @return a matrix X such that <tt>A.X = B</tt>, where A is the instance
- * @exception SingularMatrixException if the matrix is singular
- */
- public SquareMatrix solve(SquareMatrix b, double epsilon)
- throws SingularMatrixException {
- return (SquareMatrix) solve((Matrix) b, epsilon);
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/SymetricalMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/SymetricalMatrix.java
deleted file mode 100644
index a8d9fcb..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/SymetricalMatrix.java
+++ /dev/null
@@ -1,223 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class implements symetrical matrices of linear algebra.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class SymetricalMatrix
- extends GeneralSquareMatrix {
-
- /** Simple constructor.
- * This constructor builds a symetrical matrix of specified order, all
- * elements beeing zeros.
- * @param order order of the matrix
- */
- public SymetricalMatrix(int order) {
- super(order);
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param order order of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public SymetricalMatrix(int order, double[] data) {
- super(order, data);
- }
-
- /** Copy constructor.
- * @param s square matrix to copy
- */
- public SymetricalMatrix(SymetricalMatrix s) {
- super(s);
- }
-
- /** Build the symetrical matrix resulting from the product w.A.At.
- * @param w multiplicative factor (weight)
- * @param a base vector used to compute the symetrical contribution
- */
- public SymetricalMatrix(double w, double[] a) {
- super(a.length, new double[a.length * a.length]);
-
- for (int i = 0; i < a.length; ++i) {
- int indexU = i * (columns + 1);
- int indexL = indexU;
-
- double factor = w * a[i];
- data[indexU] = factor * a[i];
-
- for (int j = i + 1; j < columns; ++j) {
- ++indexU;
- indexL += columns;
- data[indexU] = factor * a[j];
- data[indexL] = data[indexU];
- }
- }
-
- }
-
- public Matrix duplicate() {
- return new SymetricalMatrix(this);
- }
-
- /** Set a matrix element.
- * On symetrical matrices, setting separately elements outside of
- * the diagonal is forbidden, so this method throws an
- * ArrayIndexOutOfBoundsException in this case. The {@link
- * #setElementAndSymetricalElement} can be used to set both elements
- * simultaneously.
- * @param i row index, from 0 to rows - 1
- * @param j column index, from 0 to cols - 1
- * @param value value of the element
- * @exception ArrayIndexOutOfBoundsException if the indices are wrong
- * @see #setElementAndSymetricalElement
- * @see Matrix#getElement
- */
- public void setElement(int i, int j, double value) {
- if (i != j) {
- throw new ArrayIndexOutOfBoundsException("cannot separately set"
- + " elements out of diagonal"
- + " in a symetrical matrix");
- }
- super.setElement(i, j, value);
- }
-
- /** Set both a matrix element and its symetrical element.
- * @param i row index of first element (column index of second
- * element), from 0 to order - 1
- * @param j column index of first element (row index of second
- * element), from 0 to order - 1
- * @param value value of the elements
- * @exception ArrayIndexOutOfBoundsException if the indices are wrong
- * @see #setElement
- * @see Matrix#getElement
- */
- public void setElementAndSymetricalElement(int i, int j, double value) {
- super.setElement(i, j, value);
- if (i != j) {
- super.setElement(j, i, value);
- }
- }
-
- /** Add a matrix to the instance.
- * This method adds a matrix to the instance. It does modify the instance.
- * @param s symetrical matrix to add
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfAdd(SymetricalMatrix s) {
-
- // validity check
- if ((rows != s.rows) || (columns != s.columns)) {
- throw new IllegalArgumentException("cannot add a "
- + s.rows + 'x' + s.columns
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // addition loop
- for (int i = 0; i < rows; ++i) {
- int indexU = i * (columns + 1);
- int indexL = indexU;
-
- data[indexU] += s.data[indexU];
-
- for (int j = i + 1; j < columns; ++j) {
- ++indexU;
- indexL += columns;
- data[indexU] += s.data[indexU];
- data[indexL] = data[indexU];
- }
- }
-
- }
-
- /** Substract a matrix from the instance.
- * This method substracts a matrix from the instance. It does modify the instance.
- * @param s symetrical matrix to substract
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfSub(SymetricalMatrix s) {
-
- // validity check
- if ((rows != s.rows) || (columns != s.columns)) {
- throw new IllegalArgumentException("cannot substract a "
- + s.rows + 'x' + s.columns
- + " matrix from a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // substraction loop
- for (int i = 0; i < rows; ++i) {
- int indexU = i * (columns + 1);
- int indexL = indexU;
-
- data[indexU] -= s.data[indexU];
-
- for (int j = i + 1; j < columns; ++j) {
- ++indexU;
- indexL += columns;
- data[indexU] -= s.data[indexU];
- data[indexL] = data[indexU];
- }
- }
-
- }
-
- /** Add the symetrical matrix resulting from the product w.A.At to the instance.
- * This method can be used to build progressively the matrices of
- * least square problems. The instance is modified.
- * @param w multiplicative factor (weight)
- * @param a base vector used to compute the symetrical contribution
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfAddWAAt(double w, double[] a) {
- if (rows != a.length) {
- throw new IllegalArgumentException("cannot add a "
- + a.length + 'x' + a.length
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- for (int i = 0; i < rows; ++i) {
- int indexU = i * (columns + 1);
- int indexL = indexU;
-
- double factor = w * a[i];
- data[indexU] += factor * a[i];
-
- for (int j = i + 1; j < columns; ++j) {
- ++indexU;
- indexL += columns;
- data[indexU] += factor * a[j];
- data[indexL] = data[indexU];
- }
- }
-
- }
-
- private static final long serialVersionUID = -2083829252075519221L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/UpperTriangularMatrix.java b/src/mantissa/src/org/spaceroots/mantissa/linalg/UpperTriangularMatrix.java
deleted file mode 100644
index f01cdb3..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/UpperTriangularMatrix.java
+++ /dev/null
@@ -1,216 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-/** This class implements upper triangular matrices of linear algebra.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class UpperTriangularMatrix
- extends SquareMatrix {
-
- /** Simple constructor.
- * This constructor builds a upper triangular matrix of specified order, all
- * elements being zeros.
- * @param order order of the matrix
- */
- public UpperTriangularMatrix(int order) {
- super(order);
- }
-
- /** Simple constructor.
- * Build a matrix with specified elements.
- * @param order order of the matrix
- * @param data table of the matrix elements (stored row after row)
- */
- public UpperTriangularMatrix(int order, double[] data) {
- super(order, data);
- }
-
- /** Copy constructor.
- * @param u upper triangular matrix to copy
- */
- public UpperTriangularMatrix(UpperTriangularMatrix u) {
- super(u);
- }
-
- public Matrix duplicate() {
- return new UpperTriangularMatrix(this);
- }
-
- public void setElement(int i, int j, double value) {
- if (i > j) {
- throw new ArrayIndexOutOfBoundsException("cannot set elements"
- + " below diagonal of a"
- + " upper triangular matrix");
- }
- super.setElement(i, j, value);
- }
-
- /** Add a matrix to the instance.
- * This method adds a matrix to the instance. It does modify the instance.
- * @param u upper triangular matrix to add
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfAdd(UpperTriangularMatrix u) {
-
- // validity check
- if ((rows != u.rows) || (columns != u.columns)) {
- throw new IllegalArgumentException("cannot add a "
- + u.rows + 'x' + u.columns
- + " matrix to a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // addition loop
- for (int i = 0; i < rows; ++i) {
- for (int index = i * (columns + 1); index < (i + 1) * columns; ++index) {
- data[index] += u.data[index];
- }
- }
-
- }
-
- /** Substract a matrix from the instance.
- * This method substract a matrix from the instance. It does modify the instance.
- * @param u upper triangular matrix to substract
- * @exception IllegalArgumentException if there is a dimension mismatch
- */
- public void selfSub(UpperTriangularMatrix u) {
-
- // validity check
- if ((rows != u.rows) || (columns != u.columns)) {
- throw new IllegalArgumentException("cannot substract a "
- + u.rows + 'x' + u.columns
- + " matrix from a "
- + rows + 'x' + columns
- + " matrix");
- }
-
- // substraction loop
- for (int i = 0; i < rows; ++i) {
- for (int index = i * (columns + 1); index < (i + 1) * columns; ++index) {
- data[index] -= u.data[index];
- }
- }
-
- }
-
- public double getDeterminant(double epsilon) {
- double determinant = data[0];
- for (int index = columns + 1; index < columns * columns; index += columns + 1) {
- determinant *= data[index];
- }
- return determinant;
- }
-
- public Matrix solve(Matrix b, double epsilon)
- throws SingularMatrixException {
- // validity check
- if (b.getRows() != rows) {
- throw new IllegalArgumentException("dimension mismatch");
- }
-
- // prepare the data storage
- int bRows = b.getRows();
- int bCols = b.getColumns();
-
- double[] resultData = new double[bRows * bCols];
- int resultIndex = bRows * bCols - 1;
- int lowerElements = 0;
- int upperElements = 0;
- int minJ = columns;
- int maxJ = 0;
-
- // solve the linear system
- for (int i = rows - 1; i >= 0; --i) {
- double diag = data[i * (columns + 1)];
- if (Math.abs(diag) < epsilon) {
- throw new SingularMatrixException();
- }
- double inv = 1.0 / diag;
-
- NonNullRange range = b.getRangeForRow(i);
- minJ = Math.min(minJ, range.begin);
- maxJ = Math.max(maxJ, range.end);
-
- int j = bCols - 1;
- while (j >= maxJ) {
- resultData[resultIndex] = 0.0;
- --resultIndex;
- --j;
- }
-
- // compute the possibly non null elements
- int bIndex = i * bCols + maxJ - 1;
- while (j >= minJ) {
-
- // compute the current element
- int index1 = (i + 1) * columns - 1;
- int index2 = (bRows - 1) * bCols + j;
- double value = b.data[bIndex];
- while (index1 >= i * (columns + 1)) {
- value -= data[index1] * resultData[index2];
- --index1;
- index2 -= bCols;
- }
- value *= inv;
- resultData[resultIndex] = value;
-
- // count the affected upper and lower elements
- // (in order to deduce the shape of the resulting matrix)
- if (j < i) {
- ++lowerElements;
- } else if (i < j) {
- ++upperElements;
- }
-
- --bIndex;
- --resultIndex;
- --j;
-
- }
-
- while (j >= 0) {
- resultData[resultIndex] = 0.0;
- --resultIndex;
- --j;
- }
-
- }
-
- return MatrixFactory.buildMatrix(bRows, bCols, resultData,
- lowerElements, upperElements);
-
- }
-
- public NonNullRange getRangeForRow(int i) {
- return new NonNullRange (i, columns);
- }
-
- public NonNullRange getRangeForColumn(int j) {
- return new NonNullRange (0, j + 1);
- }
-
- private static final long serialVersionUID = -197266611942032237L;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/doc-files/org_spaceroots_mantissa_linalg_classes.png b/src/mantissa/src/org/spaceroots/mantissa/linalg/doc-files/org_spaceroots_mantissa_linalg_classes.png
deleted file mode 100644
index a158cba..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/doc-files/org_spaceroots_mantissa_linalg_classes.png
+++ /dev/null
Binary files differ
diff --git a/src/mantissa/src/org/spaceroots/mantissa/linalg/package.html b/src/mantissa/src/org/spaceroots/mantissa/linalg/package.html
deleted file mode 100644
index e70cb28..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/linalg/package.html
+++ /dev/null
@@ -1,37 +0,0 @@
-<html>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-<body>
-This package provides classes to perform linear algebra computation.
-
-<p>It is by no means a complete linear algebra system, it is
-sufficient to solve least squares problems and linear equations
-systems, but it lacks lots of functionalities and matrices types (for
-example sparse matrices are not supported).</p>
-
-<p>The class diagram for the public classes of this package is
-displayed below. The user will mainly use directly the implementation
-classes rather than the abstract {@link
-org.spaceroots.mantissa.linalg.Matrix} class. The shape of the matrices
-used is often known in the algorithms so there is little need to hide
-this shape behind the general class.</p>
-
-<img src="doc-files/org_spaceroots_mantissa_linalg_classes.png" />
-
-@author L. Maisonobe
-</body>
-</html>
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/ComputableFunctionIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/ComputableFunctionIntegrator.java
deleted file mode 100644
index 51fa6d5..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/ComputableFunctionIntegrator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.scalar.ComputableFunction;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represents an integrator for scalar functions.
-
- * <p>The classes which are devoted to integrate scalar functions
- * should implement this interface. The functions which can be handled
- * should implement the {@link
- * org.spaceroots.mantissa.functions.scalar.ComputableFunction
- * ComputableFunction} interface.</p>
-
- * @see org.spaceroots.mantissa.functions.scalar.ComputableFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public interface ComputableFunctionIntegrator {
- /** Integrate a function over a defined range.
- * @param f function to integrate
- * @param a first bound of the range (can be lesser or greater than b)
- * @param b second bound of the range (can be lesser or greater than a)
- * @return value of the integral over the range
- * @exception FunctionException if the underlying function throws one
- */
- public double integrate(ComputableFunction f, double a, double b)
- throws FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/EnhancedSimpsonIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/EnhancedSimpsonIntegrator.java
deleted file mode 100644
index cdfd505..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/EnhancedSimpsonIntegrator.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.scalar.SampledFunctionIterator;
-
-/** This class implements an enhanced Simpson-like integrator.
-
- * <p>A traditional Simpson integrator is based on a quadratic
- * approximation of the function on three equally spaced points. This
- * integrator does the same thing but can handle non-equally spaced
- * points. If it is used on a regular sample, it behaves exactly as a
- * traditional Simpson integrator.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class EnhancedSimpsonIntegrator
- implements SampledFunctionIntegrator {
- public double integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- EnhancedSimpsonIntegratorSampler sampler
- = new EnhancedSimpsonIntegratorSampler(iter);
- double sum = 0.0;
-
- try {
- while (true) {
- sum = sampler.nextSamplePoint().getY();
- }
- } catch(ExhaustedSampleException e) {
- }
-
- return sum;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/EnhancedSimpsonIntegratorSampler.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/EnhancedSimpsonIntegratorSampler.java
deleted file mode 100644
index 0715b84..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/EnhancedSimpsonIntegratorSampler.java
+++ /dev/null
@@ -1,100 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.scalar.*;
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class implements an enhanced Simpson integrator as a sample.
-
- * <p>A traditional Simpson integrator is based on a quadratic
- * approximation of the function on three equally spaced points. This
- * integrator does the same thing but can handle non-equally spaced
- * points. If it is used on a regular sample, it behaves exactly as a
- * traditional Simpson integrator.</p>
-
- * @see EnhancedSimpsonIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class EnhancedSimpsonIntegratorSampler
- implements SampledFunctionIterator {
-
- /** Underlying sampled function iterator. */
- private SampledFunctionIterator iter;
-
- /** Next point. */
- private ScalarValuedPair next;
-
- /** Current running sum. */
- private double sum;
-
- /** Constructor.
- * Build an integrator from an underlying sample iterator.
- * @param iter iterator over the base function
- */
- public EnhancedSimpsonIntegratorSampler(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- this.iter = iter;
-
- // get the first point
- next = iter.nextSamplePoint();
-
- // initialize the sum
- sum = 0.0;
-
- }
-
- public boolean hasNext() {
- return iter.hasNext();
- }
-
- public ScalarValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
- // performs one step of an enhanced Simpson scheme
- ScalarValuedPair previous = next;
- ScalarValuedPair current = iter.nextSamplePoint();
-
- try {
- next = iter.nextSamplePoint();
-
- double h1 = current.getX() - previous.getX();
- double h2 = next.getX() - current.getX();
- double cP = (h1 + h2) * (2 * h1 - h2) / (6 * h1);
- double cC = (h1 + h2) * (h1 + h2) * (h1 + h2) / (6 * h1 * h2);
- double cN = (h1 + h2) * (2 * h2 - h1) / (6 * h2);
-
- sum += cP * previous.getY() + cC * current.getY() + cN * next.getY();
-
- } catch(ExhaustedSampleException e) {
- // we have an incomplete step at the end of the sample
- // we use a trapezoid scheme for this last step
- sum += 0.5 * (current.getX() - previous.getX()) * (previous.getY() + current.getY());
- return new ScalarValuedPair(current.getX(), sum);
- }
-
- return new ScalarValuedPair(next.getX(), sum);
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/RiemannIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/RiemannIntegrator.java
deleted file mode 100644
index 10489f4..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/RiemannIntegrator.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.scalar.SampledFunctionIterator;
-
-/** This class implements a Riemann integrator.
-
- * <p>A Riemann integrator is a very simple one that assumes the
- * function is constant over the integration step. Since it is very
- * simple, this algorithm needs very small steps to achieve high
- * accuracy, and small steps lead to numerical errors and
- * instabilities.</p>
-
- * <p>This algorithm is almost never used and has been included in
- * this package only as a simple template for more useful
- * integrators.</p>
-
- * @see TrapezoidIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class RiemannIntegrator
- implements SampledFunctionIntegrator {
- public double integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- RiemannIntegratorSampler sampler = new RiemannIntegratorSampler(iter);
- double sum = 0.0;
-
- try {
- while (true) {
- sum = sampler.nextSamplePoint().getY();
- }
- } catch(ExhaustedSampleException e) {
- }
-
- return sum;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/RiemannIntegratorSampler.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/RiemannIntegratorSampler.java
deleted file mode 100644
index 9aa3aa9..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/RiemannIntegratorSampler.java
+++ /dev/null
@@ -1,87 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.scalar.*;
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class implements a Riemann integrator as a sample.
-
- * <p>A Riemann integrator is a very simple one that assumes the
- * function is constant over the integration step. Since it is very
- * simple, this algorithm needs very small steps to achieve high
- * accuracy, and small steps lead to numerical errors and
- * instabilities.</p>
-
- * <p>This algorithm is almost never used and has been included in
- * this package only as a simple template for more useful
- * integrators.</p>
-
- * @see RiemannIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class RiemannIntegratorSampler
- implements SampledFunctionIterator {
-
- /** Underlying sample iterator. */
- private SampledFunctionIterator iter;
-
- /** Current point. */
- private ScalarValuedPair current;
-
- /** Current running sum. */
- private double sum;
-
- /** Constructor.
- * Build an integrator from an underlying sample iterator.
- * @param iter iterator over the base function
- */
- public RiemannIntegratorSampler(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- this.iter = iter;
-
- // get the first point
- current = iter.nextSamplePoint();
-
- // initialize the sum
- sum = 0.0;
-
- }
-
- public boolean hasNext() {
- return iter.hasNext();
- }
-
- public ScalarValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
- // performs one step of a Riemann scheme
- ScalarValuedPair previous = current;
- current = iter.nextSamplePoint();
- sum += (current.getX() - previous.getX()) * previous.getY();
-
- return new ScalarValuedPair(current.getX(), sum);
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/SampledFunctionIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/SampledFunctionIntegrator.java
deleted file mode 100644
index ab7b90d..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/SampledFunctionIntegrator.java
+++ /dev/null
@@ -1,48 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.scalar.SampledFunctionIterator;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represents an integrator for scalar samples.
-
- * <p>The classes which are devoted to integrate scalar samples
- * should implement this interface.</p>
-
- * @see org.spaceroots.mantissa.functions.scalar.SampledFunctionIterator
- * @see ComputableFunctionIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public interface SampledFunctionIntegrator {
- /** Integrate a sample over its overall range
- * @param iter iterator over the sample to integrate
- * @return value of the integral over the sample range
- * @exception ExhaustedSampleException if the sample does not have
- * enough points for the integration scheme
- * @exception FunctionException if the underlying sampled function throws one
- */
- public double integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/TrapezoidIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/TrapezoidIntegrator.java
deleted file mode 100644
index 3c0c0d3..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/TrapezoidIntegrator.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.scalar.SampledFunctionIterator;
-
-/** This class implements a trapezoid integrator.
-
- * <p>A trapezoid integrator is a very simple one that assumes the
- * function is linear over the integration step.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class TrapezoidIntegrator
- implements SampledFunctionIntegrator {
- public double integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- TrapezoidIntegratorSampler sampler = new TrapezoidIntegratorSampler(iter);
- double sum = 0.0;
-
- try {
- while (true) {
- sum = sampler.nextSamplePoint().getY();
- }
- } catch (ExhaustedSampleException e) {
- }
-
- return sum;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/TrapezoidIntegratorSampler.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/TrapezoidIntegratorSampler.java
deleted file mode 100644
index 59572f1..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/scalar/TrapezoidIntegratorSampler.java
+++ /dev/null
@@ -1,89 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import org.spaceroots.mantissa.functions.scalar.*;
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class implements a trapezoid integrator as a sample.
-
- * <p>A trapezoid integrator is a very simple one that assumes the
- * function is constant over the integration step. Since it is very
- * simple, this algorithm needs very small steps to achieve high
- * accuracy, and small steps lead to numerical errors and
- * instabilities.</p>
-
- * <p>This algorithm is almost never used and has been included in
- * this package only as a simple template for more useful
- * integrators.</p>
-
- * @see TrapezoidIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class TrapezoidIntegratorSampler
- implements SampledFunctionIterator {
-
- /** Underlying sample iterator. */
- private SampledFunctionIterator iter;
-
- /** Current point. */
- private ScalarValuedPair current;
-
- /** Current running sum. */
- private double sum;
-
- /** Constructor.
- * Build an integrator from an underlying sample iterator.
- * @param iter iterator over the base function
- */
- public TrapezoidIntegratorSampler(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- this.iter = iter;
-
- // get the first point
- current = iter.nextSamplePoint();
-
- // initialize the sum
- sum = 0.0;
-
- }
-
- public boolean hasNext() {
- return iter.hasNext ();
- }
-
- public ScalarValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
- // performs one step of a trapezoid scheme
- ScalarValuedPair previous = current;
- current = iter.nextSamplePoint();
- sum += 0.5
- * (current.getX() - previous.getX())
- * (previous.getY() + current.getY());
-
- return new ScalarValuedPair(current.getX(), sum);
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/ComputableFunctionIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/ComputableFunctionIntegrator.java
deleted file mode 100644
index 8632531..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/ComputableFunctionIntegrator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.ComputableFunction;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represents an integrator for vectorial functions.
-
- * <p>The classes which are devoted to integrate vectorial functions
- * should implement this interface. The functions which can be handled
- * should implement the {@link
- * org.spaceroots.mantissa.functions.vectorial.ComputableFunction
- * ComputableFunction} interface.</p>
-
- * @see org.spaceroots.mantissa.functions.vectorial.ComputableFunction
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public interface ComputableFunctionIntegrator {
- /** Integrate a function over a defined range.
- * @param f function to integrate
- * @param a first bound of the range (can be lesser or greater than b)
- * @param b second bound of the range (can be lesser or greater than a)
- * @return value of the integral over the range
- * @exception FunctionException if the underlying function throws one
- */
- public double[] integrate(ComputableFunction f, double a, double b)
- throws FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/EnhancedSimpsonIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/EnhancedSimpsonIntegrator.java
deleted file mode 100644
index e228c92..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/EnhancedSimpsonIntegrator.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.vectorial.SampledFunctionIterator;
-
-/** This class implements an enhanced Simpson-like integrator.
-
- * <p>A traditional Simpson integrator is based on a quadratic
- * approximation of the function on three equally spaced points. This
- * integrator does the same thing but can handle non-equally spaced
- * points. If it is used on a regular sample, it behaves exactly as a
- * traditional Simpson integrator.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class EnhancedSimpsonIntegrator
- implements SampledFunctionIntegrator {
- public double[] integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- EnhancedSimpsonIntegratorSampler sampler =
- new EnhancedSimpsonIntegratorSampler(iter);
- double[] sum = null;
-
- try {
- while (true) {
- sum = sampler.nextSamplePoint().y;
- }
- } catch(ExhaustedSampleException e) {
- }
-
- return sum;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/EnhancedSimpsonIntegratorSampler.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/EnhancedSimpsonIntegratorSampler.java
deleted file mode 100644
index 3a6f469..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/EnhancedSimpsonIntegratorSampler.java
+++ /dev/null
@@ -1,117 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.*;
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class implements an enhanced Simpson integrator as a sample.
-
- * <p>A traditional Simpson integrator is based on a quadratic
- * approximation of the function on three equally spaced points. This
- * integrator does the same thing but can handle non-equally spaced
- * points. If it is used on a regular sample, it behaves exactly as a
- * traditional Simpson integrator.</p>
-
- * @see EnhancedSimpsonIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class EnhancedSimpsonIntegratorSampler
- implements SampledFunctionIterator {
-
- /** Underlying sample iterator. */
- private SampledFunctionIterator iter;
-
- /** Next point. */
- private VectorialValuedPair next;
-
- /** Current running sum. */
- private double[] sum;
-
- /** Constructor.
- * Build an integrator from an underlying sample iterator.
- * @param iter iterator over the base function
- */
- public EnhancedSimpsonIntegratorSampler(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- this.iter = iter;
-
- // get the first point
- next = iter.nextSamplePoint();
-
- // initialize the sum
- sum = new double[iter.getDimension()];
- for (int i = 0; i < sum.length; ++i) {
- sum[i] = 0.0;
- }
-
- }
-
- public boolean hasNext() {
- return iter.hasNext();
- }
-
- public int getDimension() {
- return iter.getDimension();
- }
-
- public VectorialValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
- // performs one step of an enhanced Simpson scheme
- VectorialValuedPair previous = next;
- VectorialValuedPair current = iter.nextSamplePoint();
-
- try {
- next = iter.nextSamplePoint();
-
- double h1 = current.x - previous.x;
- double h2 = next.x - current.x;
- double cP = (h1 + h2) * (2 * h1 - h2) / (6 * h1);
- double cC = (h1 + h2) * (h1 + h2) * (h1 + h2) / (6 * h1 * h2);
- double cN = (h1 + h2) * (2 * h2 - h1) / (6 * h2);
-
- double[] pY = previous.y;
- double[] cY = current.y;
- double[] nY = next.y;
- for (int i = 0; i < sum.length; ++i) {
- sum [i] += cP * pY[i] + cC * cY[i] + cN * nY[i];
- }
-
- } catch(ExhaustedSampleException e) {
- // we have an incomplete step at the end of the sample
- // we use a trapezoid scheme for this last step
- double halfDx = 0.5 * (current.x - previous.x);
- double[] pY = previous.y;
- double[] cY = current.y;
- for (int i = 0; i < sum.length; ++i) {
- sum [i] += halfDx * (pY[i] + cY[i]);
- }
- return new VectorialValuedPair(current.x, sum);
- }
-
- return new VectorialValuedPair(next.x, (double[]) sum.clone());
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegrator.java
deleted file mode 100644
index 6d949ac..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegrator.java
+++ /dev/null
@@ -1,162 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.ComputableFunction;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This class implements a Gauss-Legendre integrator.
-
- * <p>Gauss-Legendre integrators are efficient integrators that can
- * accurately integrate functions with few functions evaluations. A
- * Gauss-Legendre integrator using an n-points quadrature formula can
- * integrate exactly 2n-1 degree polynoms.</p>
-
- * <p>These integrators evaluate the function on n carefully chosen
- * points in each step interval. These points are not evenly
- * spaced. The function is <emph>never</emph> evaluated at the
- * boundary points, which means it can be undefined at these
- * points.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class GaussLegendreIntegrator
- implements ComputableFunctionIntegrator {
- /** Build a Gauss-Legendre integrator.
-
- * <p>A Gauss-Legendre integrator is a formula like:
- * <pre>
- * int (f) from -1 to +1 = Sum (ai * f(xi))
- * </pre>
- * </p>
- *
- * <p>The coefficients of the formula are computed as follow:
- * <pre>
- * let n be the desired number of points
- * the xi are the roots of the degree n Legendre polynomial
- * the ai are the integrals int (Li^2) from -1 to +1
- * where Li (x) = Prod (x-xk)/(xi-xk) for k != i
- * </pre>
- * </p>
- *
- * <p>A formula in n points can integrate exactly polynoms of degree
- * up to 2n-1.</p>
- *
- * @param minPoints minimal number of points desired
- * @param rawStep raw integration step (the precise step will be
- * adjusted in order to have an integer number of steps in the
- * integration range).
- * */
- public GaussLegendreIntegrator(int minPoints, double rawStep) {
- if (minPoints <= 2) {
- weightedRoots = new double[][] {
- { 1.0, -1.0 / Math.sqrt (3.0) },
- { 1.0, 1.0 / Math.sqrt (3.0) }
- };
- } else if (minPoints <= 3) {
- weightedRoots = new double[][] {
- { 5.0 / 9.0, -Math.sqrt (0.6) },
- { 8.0 / 9.0, 0.0 },
- { 5.0 / 9.0, Math.sqrt (0.6) }
- };
- } else if (minPoints <= 4) {
- weightedRoots = new double[][] {
- { (90.0 - 5.0 * Math.sqrt (30.0)) / 180.0,
- -Math.sqrt ((15.0 + 2.0 * Math.sqrt (30.0)) / 35.0) },
- { (90.0 + 5.0 * Math.sqrt (30.0)) / 180.0,
- -Math.sqrt ((15.0 - 2.0 * Math.sqrt (30.0)) / 35.0) },
- { (90.0 + 5.0 * Math.sqrt (30.0)) / 180.0,
- Math.sqrt ((15.0 - 2.0 * Math.sqrt (30.0)) / 35.0) },
- { (90.0 - 5.0 * Math.sqrt (30.0)) / 180.0,
- Math.sqrt ((15.0 + 2.0 * Math.sqrt (30.0)) / 35.0) }
- };
- } else {
- weightedRoots = new double[][] {
- { (322.0 - 13.0 * Math.sqrt (70.0)) / 900.0,
- -Math.sqrt ((35.0 + 2.0 * Math.sqrt (70.0)) / 63.0) },
- { (322.0 + 13.0 * Math.sqrt (70.0)) / 900.0,
- -Math.sqrt ((35.0 - 2.0 * Math.sqrt (70.0)) / 63.0) },
- { 128.0 / 225.0,
- 0.0 },
- { (322.0 + 13.0 * Math.sqrt (70.0)) / 900.0,
- Math.sqrt ((35.0 - 2.0 * Math.sqrt (70.0)) / 63.0) },
- { (322.0 - 13.0 * Math.sqrt (70.0)) / 900.0,
- Math.sqrt ((35.0 + 2.0 * Math.sqrt (70.0)) / 63.0) }
- };
- }
-
- this.rawStep = rawStep;
-
- }
-
- /** Get the number of functions evaluation per step.
- * @return number of function evaluation per step
- */
- public int getEvaluationsPerStep() {
- return weightedRoots.length;
- }
-
- public double[] integrate(ComputableFunction f, double a, double b)
- throws FunctionException {
-
- // swap the integration bounds if they are not in ascending order
- if (b < a) {
- double tmp = b;
- b = a;
- a = tmp;
- }
-
- // adjust the integration step according to the bounds
- long n = Math.round(0.5 + (b - a) / rawStep);
- double step = (b - a) / n;
-
- // integrate over all elementary steps
- double halfStep = step / 2.0;
- double midPoint = a + halfStep;
-
- double[] sum = new double[f.getDimension()];
- for (int k = 0; k < sum.length; ++k) {
- sum[k] = 0.0;
- }
-
- for (long i = 0; i < n; ++i) {
- for (int j = 0; j < weightedRoots.length; ++j) {
- double[] value = f.valueAt(midPoint + halfStep * weightedRoots[j][1]);
- for (int k = 0; k < sum.length; ++k) {
- sum[k] += weightedRoots[j][0] * value[k];
- }
- }
- midPoint += step;
- }
-
- for (int k = 0; k < sum.length; ++k) {
- sum [k] *= halfStep;
- }
-
- return sum;
-
- }
-
- double[][] weightedRoots;
-
- double rawStep;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/RiemannIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/RiemannIntegrator.java
deleted file mode 100644
index 96207ee..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/RiemannIntegrator.java
+++ /dev/null
@@ -1,63 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.vectorial.SampledFunctionIterator;
-
-/** This class implements a Riemann integrator.
-
- * <p>A Riemann integrator is a very simple one that assumes the
- * function is constant over the integration step. Since it is very
- * simple, this algorithm needs very small steps to achieve high
- * accuracy, and small steps lead to numerical errors and
- * instabilities.</p>
-
- * <p>This algorithm is almost never used and has been included in
- * this package only as a simple template for more useful
- * integrators.</p>
-
- * @see TrapezoidIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class RiemannIntegrator
- implements SampledFunctionIntegrator {
-
- public double[] integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- RiemannIntegratorSampler sampler = new RiemannIntegratorSampler(iter);
- double[] sum = null;
-
- try {
- while (true) {
- sum = sampler.nextSamplePoint().y;
- }
- } catch(ExhaustedSampleException e) {
- }
-
- return sum;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/RiemannIntegratorSampler.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/RiemannIntegratorSampler.java
deleted file mode 100644
index f0cd6b4..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/RiemannIntegratorSampler.java
+++ /dev/null
@@ -1,99 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.*;
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class implements a Riemann integrator as a sample.
-
- * <p>A Riemann integrator is a very simple one that assumes the
- * function is constant over the integration step. Since it is very
- * simple, this algorithm needs very small steps to achieve high
- * accuracy, and small steps lead to numerical errors and
- * instabilities.</p>
-
- * <p>This algorithm is almost never used and has been included in
- * this package only as a simple template for more useful
- * integrators.</p>
-
- * @see RiemannIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class RiemannIntegratorSampler
- implements SampledFunctionIterator {
-
- /** Underlying sample iterator. */
- private SampledFunctionIterator iter;
-
- /** Current point. */
- private VectorialValuedPair current;
-
- /** Current running sum. */
- private double[] sum;
-
- /** Constructor.
- * Build an integrator from an underlying sample iterator.
- * @param iter iterator over the base function
- */
- public RiemannIntegratorSampler(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- this.iter = iter;
-
- // get the first point
- current = iter.nextSamplePoint();
-
- // initialize the sum
- sum = new double[iter.getDimension()];
- for (int i = 0; i < sum.length; ++i) {
- sum[i] = 0.0;
- }
-
- }
-
- public boolean hasNext() {
- return iter.hasNext();
- }
-
- public int getDimension() {
- return iter.getDimension();
- }
-
- public VectorialValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
-
- // performs one step of a Riemann scheme
- VectorialValuedPair previous = current;
- current = iter.nextSamplePoint();
- double step = (current.x - previous.x);
- double[] pY = previous.y;
- for (int i = 0; i < sum.length; ++i) {
- sum[i] += step * pY[i];
- }
-
- return new VectorialValuedPair (current.x, (double[]) sum.clone());
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/SampledFunctionIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/SampledFunctionIntegrator.java
deleted file mode 100644
index a147240..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/SampledFunctionIntegrator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.SampledFunctionIterator;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface represents an integrator for vectorial samples.
-
- * <p>The classes which are devoted to integrate vectorial samples
- * should implement this interface.</p>
-
- * @see org.spaceroots.mantissa.functions.vectorial.SampledFunctionIterator
- * @see ComputableFunctionIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public interface SampledFunctionIntegrator {
-
- /** Integrate a sample over its overall range
- * @param iter iterator over the sample to integrate
- * @return value of the integral over the sample range
- * @exception ExhaustedSampleException if the sample does not have
- * enough points for the integration scheme
- * @exception FunctionException if the underlying sampled function throws one
- */
- public double[] integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/TrapezoidIntegrator.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/TrapezoidIntegrator.java
deleted file mode 100644
index 83a4cb3..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/TrapezoidIntegrator.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-import org.spaceroots.mantissa.functions.vectorial.SampledFunctionIterator;
-
-/** This class implements a trapezoid integrator.
-
- * <p>A trapezoid integrator is a very simple one that assumes the
- * function is linear over the integration step.</p>
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class TrapezoidIntegrator
- implements SampledFunctionIntegrator {
- public double[] integrate(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- TrapezoidIntegratorSampler sampler =
- new TrapezoidIntegratorSampler(iter);
- double[] sum = null;
-
- try {
- while (true) {
- sum = sampler.nextSamplePoint().y;
- }
- } catch(ExhaustedSampleException e) {
- }
-
- return sum;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/TrapezoidIntegratorSampler.java b/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/TrapezoidIntegratorSampler.java
deleted file mode 100644
index 8526763..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/quadrature/vectorial/TrapezoidIntegratorSampler.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.*;
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-/** This class implements a trapezoid integrator as a sample.
-
- * <p>A trapezoid integrator is a very simple one that assumes the
- * function is constant over the integration step. Since it is very
- * simple, this algorithm needs very small steps to achieve high
- * accuracy, and small steps lead to numerical errors and
- * instabilities.</p>
-
- * <p>This algorithm is almost never used and has been included in
- * this package only as a simple template for more useful
- * integrators.</p>
-
- * @see TrapezoidIntegrator
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class TrapezoidIntegratorSampler
- implements SampledFunctionIterator {
-
- /** Underlying sample iterator. */
- private SampledFunctionIterator iter;
-
- /** Current point. */
- private VectorialValuedPair current;
-
- /** Current running sum. */
- private double[] sum;
-
- /** Constructor.
- * Build an integrator from an underlying sample iterator.
- * @param iter iterator over the base function
- */
- public TrapezoidIntegratorSampler(SampledFunctionIterator iter)
- throws ExhaustedSampleException, FunctionException {
-
- this.iter = iter;
-
- // get the first point
- current = iter.nextSamplePoint();
-
- // initialize the sum
- sum = new double[iter.getDimension()];
- for (int i = 0; i < sum.length; ++i) {
- sum[i] = 0.0;
- }
-
- }
-
- public boolean hasNext() {
- return iter.hasNext();
- }
-
- public int getDimension() {
- return iter.getDimension();
- }
-
- public VectorialValuedPair nextSamplePoint()
- throws ExhaustedSampleException, FunctionException {
-
- // performs one step of a trapezoid scheme
- VectorialValuedPair previous = current;
- current = iter.nextSamplePoint();
-
- double halfDx = 0.5 * (current.x - previous.x);
- double[] pY = previous.y;
- double[] cY = current.y;
- for (int i = 0; i < sum.length; ++i) {
- sum[i] += halfDx * (pY[i] + cY[i]);
- }
-
- return new VectorialValuedPair (current.x, (double[]) sum.clone());
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/random/ScalarSampleStatistics.java b/src/mantissa/src/org/spaceroots/mantissa/random/ScalarSampleStatistics.java
deleted file mode 100644
index 30760ab..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/random/ScalarSampleStatistics.java
+++ /dev/null
@@ -1,161 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.random;
-
-/** This class compute basic statistics on a scalar sample.
- * @version $Id$
- * @author L. Maisonobe
- */
-public class ScalarSampleStatistics {
-
- /** Number of sample points. */
- private int n;
-
- /** Minimal value in the sample. */
- private double min;
-
- /** Maximal value in the sample. */
- private double max;
-
- /** Sum of the sample values. */
- private double sum;
-
- /** Sum of the squares of the sample values. */
- private double sum2;
-
- /** Simple constructor.
- * Build a new empty instance
- */
- public ScalarSampleStatistics() {
- n = 0;
- min = Double.NaN;
- max = min;
- sum = 0;
- sum2 = 0;
- }
-
- /** Add one point to the instance.
- * @param x value of the sample point
- */
- public void add(double x) {
-
- if (n++ == 0) {
- min = x;
- max = x;
- sum = x;
- sum2 = x * x;
- } else {
-
- if (x < min) {
- min = x;
- } else if (x > max) {
- max = x;
- }
-
- sum += x;
- sum2 += x * x;
-
- }
-
- }
-
- /** Add all points of an array to the instance.
- * @param points array of points
- */
- public void add(double[] points) {
- for (int i = 0; i < points.length; ++i) {
- add(points[i]);
- }
- }
-
- /** Add all the points of another sample to the instance.
- * @param s sample to add
- */
- public void add(ScalarSampleStatistics s) {
-
- if (s.n == 0) {
- // nothing to add
- return;
- }
-
- if (n == 0) {
- n = s.n;
- min = s.min;
- max = s.max;
- sum = s.sum;
- sum2 = s.sum2;
- } else {
-
- n += s.n;
-
- if (s.min < min) {
- min = s.min;
- } else if (s.max > max) {
- max = s.max;
- }
-
- sum += s.sum;
- sum2 += s.sum2;
-
- }
-
- }
-
- /** Get the number of points in the sample.
- * @return number of points in the sample
- */
- public int size() {
- return n;
- }
-
- /** Get the minimal value in the sample.
- * @return minimal value in the sample
- */
- public double getMin() {
- return min;
- }
-
- /** Get the maximal value in the sample.
- * @return maximal value in the sample
- */
- public double getMax() {
- return max;
- }
-
- /** Get the mean value of the sample.
- * @return mean value of the sample
- */
- public double getMean() {
- return (n == 0) ? 0 : (sum / n);
- }
-
- /** Get the standard deviation of the underlying probability law.
- * This method estimate the standard deviation considering that the
- * data available are only a <em>sample</em> of all possible
- * values. This value is often called the sample standard deviation
- * (as opposed to the population standard deviation).
- * @return standard deviation of the underlying probability law
- */
- public double getStandardDeviation() {
- if (n < 2) {
- return 0;
- }
- return Math.sqrt((n * sum2 - sum * sum) / (n * (n - 1)));
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/random/VectorialSampleStatistics.java b/src/mantissa/src/org/spaceroots/mantissa/random/VectorialSampleStatistics.java
deleted file mode 100644
index 0e017df..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/random/VectorialSampleStatistics.java
+++ /dev/null
@@ -1,285 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.random;
-
-import org.spaceroots.mantissa.linalg.SymetricalMatrix;
-
-/** This class compute basic statistics on a scalar sample.
- * @version $Id$
- * @author L. Maisonobe
- */
-public class VectorialSampleStatistics {
-
- /** Dimension of the vectors to handle. */
- private int dimension;
-
- /** Number of sample points. */
- private int n;
-
- /** Indices of the minimal values occurrence in the sample. */
- private int[] minIndices;
-
- /** Minimal value in the sample. */
- private double[] min;
-
- /** Maximal value in the sample. */
- private double[] max;
-
- /** Indices of the maximal values occurrence in the sample. */
- private int[] maxIndices;
-
- /** Sum of the sample values. */
- private double[] sum;
-
- /** Sum of the squares of the sample values. */
- private double[] sum2;
-
- /** Simple constructor.
- * Build a new empty instance
- */
- public VectorialSampleStatistics() {
- dimension = -1;
- n = 0;
- min = null;
- minIndices = null;
- max = null;
- maxIndices = null;
- sum = null;
- sum2 = null;
- }
-
- /** Add one point to the instance.
- * @param x value of the sample point
- * @exception IllegalArgumentException if there is a dimension
- * mismatch between this point and the ones already added (this
- * cannot happen when the instance is empty)
- */
- public void add(double[] x) {
-
- if (n == 0) {
-
- dimension = x.length;
- minIndices = new int[dimension];
- maxIndices = new int[dimension];
- min = (double[]) x.clone();
- max = (double[]) x.clone();
- sum = (double[]) x.clone();
- sum2 = new double[dimension * (dimension + 1) / 2];
-
- int k = 0;
- for (int i = 0; i < dimension; ++i) {
- for (int j = 0; j <= i; ++j) {
- sum2[k++] = x[i] * x[j];
- }
- }
-
- } else {
- int k = 0;
- for (int i = 0; i < dimension; ++i) {
-
- if (x[i] < min[i]) {
- min[i] = x[i];
- minIndices[i] = n;
- } else if (x[i] > max[i]) {
- max[i] = x[i];
- maxIndices[i] = n;
- }
-
- sum[i] += x[i];
- for (int j = 0; j <= i; ++j) {
- sum2[k++] += x[i] * x[j];
- }
-
- }
- }
-
- ++n;
-
- }
-
- /** Add all points of an array to the instance.
- * @param points array of points
- * @exception IllegalArgumentException if there is a dimension
- * mismatch between these points and the ones already added (this
- * cannot happen when the instance is empty)
- */
- public void add(double[][] points) {
- for (int i = 0; i < points.length; ++i) {
- add(points[i]);
- }
- }
-
- /** Add all the points of another sample to the instance.
- * @param s samples to add
- * @exception IllegalArgumentException if there is a dimension
- * mismatch between this sample points and the ones already added
- * (this cannot happen when the instance is empty)
- */
- public void add(VectorialSampleStatistics s) {
-
- if (s.n == 0) {
- // nothing to add
- return;
- }
-
- if (n == 0) {
-
- dimension = s.dimension;
- min = (double[]) s.min.clone();
- minIndices = (int[]) s.minIndices.clone();
- max = (double[]) s.max.clone();
- maxIndices = (int[]) s.maxIndices.clone();
- sum = (double[]) s.sum.clone();
- sum2 = (double[]) s.sum2.clone();
-
- } else {
- int k = 0;
-
- for (int i = 0; i < dimension; ++i) {
-
- if (s.min[i] < min[i]) {
- min[i] = s.min[i];
- minIndices[i] = n;
- } else if (s.max[i] > max[i]) {
- max[i] = s.max[i];
- maxIndices[i] = n;
- }
-
- sum[i] += s.sum[i];
- for (int j = 0; j <= i; ++j) {
- sum2[k] += s.sum2[k];
- ++k;
- }
-
- }
-
- }
-
- n += s.n;
-
- }
-
- /** Get the number of points in the sample.
- * @return number of points in the sample
- */
- public int size() {
- return n;
- }
-
- /** Get the minimal value in the sample.
- * <p>Since all components of the sample vector can reach their
- * minimal value at different times, this vector should be
- * considered as gathering all minimas of all components. The index
- * of the sample at which the minimum was encountered can be
- * retrieved with the {@link #getMinIndices getMinIndices}
- * method.</p>
- * @return minimal value in the sample (a new array is created
- * at each call, the caller may do what it wants to with it)
- * @see #getMinIndices
- */
- public double[] getMin() {
- return (double[]) min.clone();
- }
-
- /** Get the indices at which the minimal value occurred in the sample.
- * @return a vector reporting at which occurrence each component of
- * the sample reached its minimal value (a new array is created
- * at each call, the caller may do what it wants to with it)
- * @see #getMin
- */
- public int[] getMinIndices() {
- return (int[]) minIndices.clone();
- }
-
- /** Get the maximal value in the sample.
- * <p>Since all components of the sample vector can reach their
- * maximal value at different times, this vector should be
- * considered as gathering all maximas of all components. The index
- * of the sample at which the maximum was encountered can be
- * retrieved with the {@link #getMaxIndices getMaxIndices}
- * method.</p>
- * @return maximal value in the sample (a new array is created
- * at each call, the caller may do what it wants to with it)
- * @see #getMaxIndices
- */
- public double[] getMax() {
- return (double[]) max.clone();
- }
-
- /** Get the indices at which the maximal value occurred in the sample.
- * @return a vector reporting at which occurrence each component of
- * the sample reached its maximal value (a new array is created
- * at each call, the caller may do what it wants to with it)
- * @see #getMax
- */
- public int[] getMaxIndices() {
- return (int[]) maxIndices.clone();
- }
-
- /** Get the mean value of the sample.
- * @return mean value of the sample or an empty array
- * if the sample is empty (a new array is created
- * at each call, the caller may do what it wants to with it)
- */
- public double[] getMean() {
- if (n == 0) {
- return new double[0];
- }
- double[] mean = new double[dimension];
- for (int i = 0; i < dimension; ++i) {
- mean[i] = sum[i] / n;
- }
- return mean;
- }
-
- /** Get the covariance matrix of the underlying law.
- * This method estimate the covariance matrix considering that the
- * data available are only a <em>sample</em> of all possible
- * values. This value is the sample covariance matrix (as opposed
- * to the population covariance matrix).
- * @param covariance placeholder where to store the matrix, if null
- * a new matrix will be allocated
- * @return covariance matrix of the underlying or null if the
- * sample has less than 2 points (reference to covariance if it was
- * non-null, reference to a new matrix otherwise)
- */
- public SymetricalMatrix getCovarianceMatrix(SymetricalMatrix covariance) {
-
- if (n < 2) {
- return null;
- }
-
- if (covariance == null) {
- covariance = new SymetricalMatrix(dimension);
- }
-
- double c = 1.0 / (n * (n - 1));
- int k = 0;
- for (int i = 0; i < dimension; ++i) {
- for (int j = 0; j <= i; ++j) {
- double e = c * (n * sum2[k] - sum[i] * sum[j]);
- covariance.setElementAndSymetricalElement(i, j, e);
- ++k;
- }
- }
-
- return covariance;
-
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/random/doc-files/org_spaceroots_mantissa_random_classes.png b/src/mantissa/src/org/spaceroots/mantissa/random/doc-files/org_spaceroots_mantissa_random_classes.png
deleted file mode 100644
index 4230606..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/random/doc-files/org_spaceroots_mantissa_random_classes.png
+++ /dev/null
Binary files differ
diff --git a/src/mantissa/src/org/spaceroots/mantissa/random/package.html b/src/mantissa/src/org/spaceroots/mantissa/random/package.html
deleted file mode 100644
index edbeb84..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/random/package.html
+++ /dev/null
@@ -1,49 +0,0 @@
-<html>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-<body>
-This package provides classes to perform some random draws and
-statistical anaysis.
-
-<p>The aim of this package is to provide the basic components needed
-to generate random variables (correlated or not in the case of
-vectorial variables) that could be used in a simulation application
-and to provide some basic statistical classes in order to analyze the
-simulation results.</p>
-
-<p>Vectorial generators are build by embedding a {@link
-org.spaceroots.mantissa.random.NormalizedRandomGenerator normalized}
-scalar generator into the vectorial generator classes {@link
-org.spaceroots.mantissa.random.CorrelatedRandomVectorGenerator
-CorrelatedRandomVectorGenerator} or {@link
-org.spaceroots.mantissa.random.UncorrelatedRandomVectorGenerator
-UncorrelatedRandomVectorGenerator} that will be responsible for
-packaging all numbers into vectors with the specified mean values, standard
-deviations and correlation coefficients. Since most practical problems
-make the assumption the probability distribution is a gaussian one,
-the normalized generator will often be an instance of {@link
-org.spaceroots.mantissa.random.GaussianRandomGenerator
-GaussianRandomGenerator}, but uniform distribution are also available
-using instances of {@link
-org.spaceroots.mantissa.random.UniformRandomGenerator
-UniformRandomGenerator}.</p>
-
-<img src="doc-files/org_spaceroots_mantissa_random_classes.png" />
-
-@author L. Maisonobe
-</body>
-</html>
diff --git a/src/mantissa/src/org/spaceroots/mantissa/roots/BrentSolver.java b/src/mantissa/src/org/spaceroots/mantissa/roots/BrentSolver.java
deleted file mode 100644
index ba84a39..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/roots/BrentSolver.java
+++ /dev/null
@@ -1,188 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.roots;
-
-import org.spaceroots.mantissa.functions.scalar.ComputableFunction;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This class implements the Brent algorithm to compute the roots of
- * a function in an interval.
-
- * This class is basically a translation in Java of a fortran
- * implementation found at netlib (<a
- * href="http://www.netlib.org/fmm/zeroin.f">zeroin.f</a>).
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class BrentSolver implements RootsFinder {
-
- /** IEEE 754 epsilon . */
- private static final double epsilon = Math.pow(2.0, -52);
-
- /** Root found. */
- private double root;
-
- /** Simple constructor.
- * Build a Brent solver
- */
- public BrentSolver() {
- root = Double.NaN;
- }
-
- /** Solve a function in a given interval known to contain a root.
- * @param function function for which a root should be found
- * @param checker checker for the convergence of the function
- * @param maxIter maximal number of iteration allowed
- * @param x0 abscissa of the lower bound of the interval
- * @param f0 value of the function the lower bound of the interval
- * @param x1 abscissa of the higher bound of the interval
- * @param f1 value of the function the higher bound of the interval
- * @return true if a root has been found in the given interval
- */
- public boolean findRoot(ComputableFunction function,
- ConvergenceChecker checker,
- int maxIter,
- double x0, double f0, double x1, double f1)
- throws FunctionException {
-
- double a = x0;
- double fa = f0;
- double b = x1;
- double fb = f1;
-
- double c = a;
- double fc = fa;
-
- double d = b - a;
- double e = d;
-
- double tolS;
- for (int iter = 0; iter < maxIter; ++iter) {
-
- if (Math.abs(fc) < Math.abs(fb)) {
- // invert points
- a = b;
- b = c;
- c = a;
- fa = fb;
- fb = fc;
- fc = fa;
- }
-
- tolS = 2 * epsilon * Math.abs(b);
- double xm = 0.5 * (c - b);
-
- // convergence test
- double xLow, fLow, xHigh, fHigh;
- if (b < c) {
- xLow = b;
- fLow = fb;
- xHigh = c;
- fHigh = fc;
- } else {
- xLow = c;
- fLow = fc;
- xHigh = b;
- fHigh = fb;
- }
-
- switch (checker.converged(xLow, fLow, xHigh, fHigh)) {
- case ConvergenceChecker.LOW :
- root = xLow;
- return true;
- case ConvergenceChecker.HIGH :
- root = xHigh;
- return true;
- default :
- if ((Math.abs(xm) < tolS) || (Math.abs(fb) < Double.MIN_VALUE)) {
- root = b;
- return true;
- }
- }
-
- if ((Math.abs(e) < tolS) || (Math.abs(fa) <= Math.abs(fb))) {
- // use bisection method
- d = xm;
- e = d;
- } else {
- // use secant method
- double p, q, r, s;
- s = fb / fa;
- if (Math.abs(a - c) < epsilon * Math.max(Math.abs(a), Math.abs(c))) {
- // linear interpolation using only b and c points
- p = 2.0 * xm * s;
- q = 1.0 - s;
- } else {
- // inverse quadratic interpolation using a, b and c points
- q = fa / fc;
- r = fb / fc;
- p = s * (2.0 * xm * q * (q - r) - (b - a) * (r - 1.0));
- q = (q - 1.0) * (r - 1.0) * (s - 1.0);
- }
-
- // signs adjustment
- if (p > 0.0) {
- q = -q;
- } else {
- p = -p;
- }
-
- // is interpolation acceptable ?
- if (((2.0 * p) < (3.0 * xm * q - Math.abs(tolS * q)))
- &&
- (p < Math.abs(0.5 * e * q))) {
- e = d;
- d = p / q;
- } else {
- // no, we need to fall back to bisection
- d = xm;
- e = d;
- }
- }
-
- // complete step
- a = b;
- fa = fb;
- b += ((Math.abs(d) > tolS) ? d : (xm > 0.0 ? tolS : -tolS));
- fb = function.valueAt(b);
-
- if (fb * fc > 0) {
- c = a;
- fc = fa;
- d = b - a;
- e = d;
- }
-
- }
-
- // we have exceeded the maximal number of iterations
- return false;
-
- }
-
- /** Get the abscissa of the root.
- * @return abscissa of the root
- */
- public double getRoot() {
- return root;
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/roots/ConvergenceChecker.java b/src/mantissa/src/org/spaceroots/mantissa/roots/ConvergenceChecker.java
deleted file mode 100644
index 30acc07..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/roots/ConvergenceChecker.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.roots;
-
-/** This interface specifies methods to check if a root-finding
- * algorithm has converged.
-
- * Deciding if convergence has been reached is a problem-dependent
- * issue. The user should provide a class implementing this interface
- * to allow the root-finding algorithm to stop its search according to
- * the problem at hand.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public interface ConvergenceChecker {
-
- /** Indicator for no convergence. */
- public static final int NONE = 0;
-
- /** Indicator for convergence on the lower bound of the interval. */
- public static final int LOW = 1;
-
- /** Indicator for convergence on the higher bound of the interval. */
- public static final int HIGH = 2;
-
- /** Check if the root-finding algorithm has converged on the interval.
- * The interval defined by the arguments contains one root (if there
- * was at least one in the initial interval given by the user to the
- * root-finding algorithm, of course)
- * @param xLow abscissa of the lower bound of the interval
- * @param fLow value of the function the lower bound of the interval
- * @param xHigh abscissa of the higher bound of the interval
- * @param fHigh value of the function the higher bound of the interval
- * @return convergence indicator, must be one of {@link #NONE},
- * {@link #LOW} or {@link #HIGH}
- */
- public int converged (double xLow, double fLow, double xHigh, double fHigh);
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/roots/RootsFinder.java b/src/mantissa/src/org/spaceroots/mantissa/roots/RootsFinder.java
deleted file mode 100644
index c8adfca..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/roots/RootsFinder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.roots;
-
-import org.spaceroots.mantissa.functions.scalar.ComputableFunction;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-/** This interface specifies root-finding methods for scalar
- * functions.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public interface RootsFinder {
-
- /** Solve a function in a given interval known to contain a root.
- * @param function function for which a root should be found
- * @param checker checker for the convergence of the function
- * @param maxIter maximal number of iteration allowed
- * @param x0 abscissa of the lower bound of the interval
- * @param f0 value of the function the lower bound of the interval
- * @param x1 abscissa of the higher bound of the interval
- * @param f1 value of the function the higher bound of the interval
- * @return true if a root has been found in the given interval
- */
- public boolean findRoot(ComputableFunction function,
- ConvergenceChecker checker,
- int maxIter,
- double x0, double f0, double x1, double f1)
- throws FunctionException;
-
- /** Get the abscissa of the root.
- * @return abscissa of the root
- */
- public double getRoot();
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapper.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapper.java
deleted file mode 100644
index c4fffe7..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapper.java
+++ /dev/null
@@ -1,141 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-/**
- * This class dispatch data between an array and several domain objects.
-
- * This class handles all the burden of mapping each domain object it
- * handles to a slice of a single array.
-
- * @see ArraySliceMappable
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class ArrayMapper {
-
- /** Simple constructor.
- * Build an empty array mapper
- */
- public ArrayMapper() {
- domainObjects = new ArrayList();
- size = 0;
- internalData = null;
- }
-
- /** Simple constructor.
- * Build an array mapper managing one object. Other objects can be
- * added later using the {@link #manageMappable manageMappable}
- * method. This call is equivalent to build the mapper with the
- * default constructor and adding the object.
- * @param object domain object to handle
- */
- public ArrayMapper(ArraySliceMappable object) {
-
- domainObjects = new ArrayList();
- domainObjects.add(new ArrayMapperEntry(object, 0));
-
- size = object.getStateDimension();
-
- internalData = new double [size];
-
- }
-
- /** Take a new domain object into account.
- * @param object domain object to handle
- */
- public void manageMappable(ArraySliceMappable object) {
-
- domainObjects.add(new ArrayMapperEntry(object, size));
-
- size += object.getStateDimension();
-
- if (internalData != null) {
- internalData = new double [size];
- }
-
- }
-
- /** Get the data array.
- * @return copy of the data array
- */
- public double[] getDataArray() {
- if (internalData == null) {
- internalData = new double [size];
- }
- return (double[]) internalData.clone();
- }
-
- /** Map data from the internal array to the domain objects.
- */
- public void updateObjects() {
- if (internalData == null) {
- internalData = new double [size];
- }
- updateObjects(internalData);
- }
-
- /** Map data from the specified array to the domain objects.
- * @param data flat array holding the data to dispatch
- */
- public void updateObjects(double[] data) {
- for (Iterator iter = domainObjects.iterator(); iter.hasNext();) {
- ArrayMapperEntry entry = (ArrayMapperEntry) iter.next();
- entry.object.mapStateFromArray(entry.offset, data);
- }
- }
-
- /** Map data from the domain objects to the internal array.
- */
- public void updateArray() {
- if (internalData == null) {
- internalData = new double [size];
- }
- updateArray(internalData);
- }
-
- /** Map data from the domain objects to the specified array.
- * @param data flat array where to put the data
- */
- public void updateArray(double[] data) {
- for (Iterator iter = domainObjects.iterator(); iter.hasNext();) {
- ArrayMapperEntry entry = (ArrayMapperEntry) iter.next();
- entry.object.mapStateToArray(entry.offset, data);
- }
- }
-
- /** Container for all handled objects. */
- private ArrayList domainObjects;
-
- /** Total number of scalar elements handled.
- * (size of the array)
- */
- private int size;
-
- /** Flat array holding all data.
- * This is null as long as nobody uses it (lazy creation)
- */
- private double[] internalData;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java
deleted file mode 100644
index db21e95..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-/**
- * This class is a simple container for an offset and an
- * {@link ArraySliceMappable} object.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-class ArrayMapperEntry {
-
- /** Mappable object. */
- public final ArraySliceMappable object;
-
- /** Offset from start of array. */
- public final int offset;
-
- /** Simple constructor.
- * @param object mappable object
- * @param offset offset from start of array
- */
- public ArrayMapperEntry(ArraySliceMappable object, int offset) {
- this.object = object;
- this.offset = offset;
- }
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java
deleted file mode 100644
index 9a3959f..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java
+++ /dev/null
@@ -1,81 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-/** This interface is used to map objects to and from simple arrays.
- *
- * <p> Lots of mathematical algorithms are generic ones which can
- * process the data from domain objects despite they ignore what
- * this data represent. As an example, the same algorithm can
- * integrate either the orbit evolution of a spacecraft under a
- * specified force model or the electrical characteristics of a
- * circuit after a switch is opened. </p>
-
- * <p> The approach of the Mantissa library is to define an interface
- * for each such algorithm to represent the type of problem they can
- * handle ({@link
- * org.spaceroots.mantissa.ode.FirstOrderDifferentialEquations
- * FirstOrderDifferentialEquations} for an ODE integrators, {@link
- * org.spaceroots.mantissa.estimation.EstimationProblem
- * EstimationProblem} for least squares estimators, ...). Furthermore,
- * the state data that is handled by these algorithms is often a
- * mixture of data coming from several domain objects (the orbit,
- * plus the aerodynamical coefficients of the spacecraft, plus the
- * characteristics of the thrusters, plus ...). Therefore, the user
- * needs to gather and dispatch data between different objects
- * representing different levels of abstraction. </p>
-
- * <p> This interface is designed to copy data back and forth between
- * existing objects during the iterative processing of these
- * algorithms and avoid the cost of recreating the objects. </p>
-
- * <p> The nominal way to use this interface is to have the domain
- * objects implement it (either directly or using inheritance to add
- * this feature to already existing objects) and to create one class
- * that implements the problem interface (for example {@link
- * org.spaceroots.mantissa.ode.FirstOrderDifferentialEquations}) and
- * uses the {@link ArrayMapper} class to dispatch the data to and from
- * the domain objects.</p>
-
- * @see ArrayMapper
- *
- * @version $Id$
- * @author L. Maisonobe
- *
- */
-
-public interface ArraySliceMappable {
-
- /** Get the dimension of the object.
- * @return dimension of the object
- */
- public int getStateDimension();
-
- /** Reinitialize internal state from the specified array slice data.
- * @param start start index in the array
- * @param array array holding the data to extract
- */
- public void mapStateFromArray(int start, double[] array);
-
- /** Store internal state data into the specified array slice.
- * @param start start index in the array
- * @param array array where data should be stored
- */
- public void mapStateToArray(int start, double[] array);
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java
deleted file mode 100644
index f8f7d48..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java
+++ /dev/null
@@ -1,166 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-/** This class represents an interval on the real line.
-
- * <p>This class allows to perform simple interval operations like
- * point inclusion tests and intersection operations.</p>
-
- * <p>There is no distinction between open and closed intervals
- * because real numbers cannot be represented exactly.</p>
-
- * @see IntervalsList
- * @author Luc Maisonobe
- * @version $Id$
- */
-public class Interval {
-
- /** Build the [0, 0] interval.
- */
- public Interval() {
- inf = 0;
- sup = 0;
- }
-
- /** Build an interval with the given bounds.
- * <p>The given bounds do not need to be ordered, they will be
- * reordered by the constructor.</p>
- * @param a first bound
- * @param b second bound
- */
- public Interval(double a, double b) {
- if (a <= b) {
- inf = a;
- sup = b;
- } else {
- inf = b;
- sup = a;
- }
- }
-
- /** Copy-constructor.
- * @param i interval to copy
- */
- public Interval(Interval i) {
- inf = i.inf;
- sup = i.sup;
- }
-
- /** Get the lower bound of the interval.
- * @return lower bound of the interval
- */
- public double getInf() {
- return inf;
- }
-
- /** Get the upper bound of the interval.
- * @return upper bound of the interval
- */
- public double getSup() {
- return sup;
- }
-
- /** Get the length of the interval.
- * @return length of the interval
- */
- public double getLength() {
- return sup - inf;
- }
-
- /** Check if the interval contains a point.
- * @param x point to check
- * @return true if the interval contains x
- */
- public boolean contains(double x) {
- return (inf <= x) && (x <= sup);
- }
-
- /** Check if the interval contains another interval.
- * @param i interval to check
- * @return true if i is completely included in the instance
- */
- public boolean contains(Interval i) {
- return (inf <= i.inf) && (i.sup <= sup);
- }
-
- /** Check if an interval intersects the instance.
- * @param i interval to check
- * @return true if i intersects the instance
- */
- public boolean intersects(Interval i) {
- return (inf <= i.sup) && (i.inf <= sup);
- }
-
- /** Add an interval to the instance.
- * <p>This method expands the instance.</p>
- * <p>This operation is <strong>not</strong> a union operation. If
- * the instance and the interval are disjoints (i.e. if {@link
- * #intersects intersects(i)} would return <code>false</code>), then
- * the hole between the intervals is filled in.</p>
- * @param i interval to add to the instance
- */
- public void addToSelf(Interval i) {
- inf = Math.min(inf, i.inf);
- sup = Math.max(sup, i.sup);
- }
-
- /** Add two intervals.
- * <p>This operation is <strong>not</strong> a union operation. If
- * the intervals are disjoints (i.e. if {@link
- * #intersects i1.intersects(i2)} would return <code>false</code>), then
- * the hole between the intervals is filled in.</p>
- * @param i1 first interval
- * @param i2 second interval
- * @return a new interval
- */
- public static Interval add(Interval i1, Interval i2) {
- Interval copy = new Interval(i1);
- copy.addToSelf(i2);
- return copy;
- }
-
- /** Intersects the instance with an interval.
- * <p>This method reduces the instance, it could even become empty
- * if the interval does not intersects the instance.</p>
- * @param i interval with which the instance should be intersected
- */
- public void intersectSelf(Interval i) {
- inf = Math.max(inf, i.inf);
- sup = Math.max(Math.min(sup, i.sup), inf);
- }
-
- /** Intersect two intervals.
- * @param i1 first interval
- * @param i2 second interval
- * @return a new interval which is the intersection of i1 with i2
- */
- public static Interval intersection(Interval i1, Interval i2) {
- Interval copy = new Interval(i1);
- copy.intersectSelf(i2);
- return copy;
- }
-
- /** Lower bound of the interval. */
- private double inf;
-
- /** Upper bound of the interval. */
- private double sup;
-
-}
-
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java
deleted file mode 100644
index 14759cc..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java
+++ /dev/null
@@ -1,362 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Iterator;
-
-/** This class represents an intervals list.
- * <p>An interval list represent a list of contiguous regions on the
- * real line. All intervals of the list are disjoints to each other,
- * they are stored in ascending order.</p>
- * <p>The class supports the main set operations like union and
- * intersection.</p>
- * @see Interval
- * @author Luc Maisonobe
- * @version $Id$
- */
-public class IntervalsList {
-
- /** Build an empty intervals list.
- */
- public IntervalsList() {
- intervals = new ArrayList();
- }
-
- /** Build an intervals list containing only one interval.
- * @param a first bound of the interval
- * @param b second bound of the interval
- */
- public IntervalsList(double a, double b) {
- intervals = new ArrayList();
- intervals.add(new Interval(a, b));
- }
-
- /** Build an intervals list containing only one interval.
- * @param i interval
- */
- public IntervalsList(Interval i) {
- intervals = new ArrayList();
- intervals.add(i);
- }
-
- /** Build an intervals list containing two intervals.
- * @param i1 first interval
- * @param i2 second interval
- */
- public IntervalsList(Interval i1, Interval i2) {
- intervals = new ArrayList();
- if (i1.intersects(i2)) {
- intervals.add(new Interval(Math.min(i1.getInf(), i2.getInf()),
- Math.max(i1.getSup(), i2.getSup())));
- } else if (i1.getSup () < i2.getInf()) {
- intervals.add(i1);
- intervals.add(i2);
- } else {
- intervals.add(i2);
- intervals.add(i1);
- }
- }
-
- /** Copy constructor.
- * <p>The copy operation is a deep copy: the underlying intervals
- * are independant of the instances of the copied list.</p>
- * @param list intervals list to copy
- */
- public IntervalsList(IntervalsList list) {
- intervals = new ArrayList(list.intervals.size());
- for (Iterator iterator = list.intervals.iterator(); iterator.hasNext();) {
- intervals.add(new Interval((Interval) iterator.next()));
- }
- }
-
- /** Check if the instance is empty.
- * @return true if the instance is empty
- */
- public boolean isEmpty() {
- return intervals.isEmpty();
- }
-
- /** Check if the instance is connected.
- * <p>An interval list is connected if it contains only one
- * interval.</p>
- * @return true is the instance is connected
- */
- public boolean isConnex() {
- return intervals.size() == 1;
- }
-
- /** Get the lower bound of the list.
- * @return lower bound of the list or Double.NaN if the list does
- * not contain any interval
- */
- public double getInf() {
- return intervals.isEmpty()
- ? Double.NaN : ((Interval) intervals.get(0)).getInf();
- }
-
- /** Get the upper bound of the list.
- * @return upper bound of the list or Double.NaN if the list does
- * not contain any interval
- */
- public double getSup() {
- return intervals.isEmpty()
- ? Double.NaN : ((Interval) intervals.get(intervals.size() - 1)).getSup();
- }
-
- /** Get the number of intervals of the list.
- * @return number of intervals in the list
- */
- public int getSize() {
- return intervals.size();
- }
-
- /** Get an interval from the list.
- * @param i index of the interval
- * @return interval at index i
- */
- public Interval getInterval(int i) {
- return (Interval) intervals.get(i);
- }
-
- /** Get the ordered list of disjoints intervals.
- * @return list of disjoints intervals in ascending order
- */
- public List getIntervals() {
- return intervals;
- }
-
- /** Check if the list contains a point.
- * @param x point to check
- * @return true if the list contains x
- */
- public boolean contains(double x) {
- for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
- if (((Interval) iterator.next()).contains(x)) {
- return true;
- }
- }
- return false;
- }
-
- /** Check if the list contains an interval.
- * @param i interval to check
- * @return true if i is completely included in the instance
- */
- public boolean contains(Interval i) {
- for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
- if (((Interval) iterator.next()).contains(i)) {
- return true;
- }
- }
- return false;
- }
-
- /** Check if an interval intersects the instance.
- * @param i interval to check
- * @return true if i intersects the instance
- */
- public boolean intersects(Interval i) {
- for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
- if (((Interval) iterator.next()).intersects(i)) {
- return true;
- }
- }
- return false;
- }
-
- /** Add an interval to the instance.
- * <p>This method expands the instance.</p>
- * <p>This operation is a union operation. The number of intervals
- * in the list can decrease if the interval fills some holes between
- * existing intervals in the list.</p>
- * @param i interval to add to the instance
- */
- public void addToSelf(Interval i) {
-
- List newIntervals = new ArrayList();
- double inf = Double.NaN;
- double sup = Double.NaN;
- boolean pending = false;
- boolean processed = false;
- for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
- Interval local = (Interval) iterator.next();
-
- if (local.getSup() < i.getInf()) {
- newIntervals.add(local);
- } else if (local.getInf() < i.getSup()) {
- if (! pending) {
- inf = Math.min(local.getInf(), i.getInf());
- pending = true;
- processed = true;
- }
- sup = Math.max(local.getSup(), i.getSup());
- } else {
- if (pending) {
- newIntervals.add(new Interval(inf, sup));
- pending = false;
- } else if (! processed) {
- newIntervals.add(i);
- }
- processed = true;
- newIntervals.add(local);
- }
- }
-
- if (pending) {
- newIntervals.add(new Interval(inf, sup));
- } else if (! processed) {
- newIntervals.add(i);
- }
-
- intervals = newIntervals;
-
- }
-
- /** Add an intervals list and an interval.
- * @param list intervals list
- * @param i interval
- * @return a new intervals list which is the union of list and i
- */
- public static IntervalsList add(IntervalsList list, Interval i) {
- IntervalsList copy = new IntervalsList(list);
- copy.addToSelf(i);
- return copy;
- }
-
- /** Remove an interval from the list.
- * <p>This method reduces the instance. This operation is defined in
- * terms of points set operation. As an example, if the [2, 3]
- * interval is subtracted from the list containing only the [0, 10]
- * interval, the result will be the [0, 2] U [3, 10] intervals
- * list.</p>
- * @param i interval to remove
- */
- public void subtractFromSelf(Interval i) {
- double a = Math.min(getInf(), i.getInf());
- double b = Math.max(getSup(), i.getSup());
- intersectSelf(new IntervalsList(new Interval(a - 1.0, i.getInf()),
- new Interval(i.getSup(), b + 1.0)));
- }
-
- /** Remove an interval from a list.
- * @param list intervals list
- * @param i interval to remove
- * @return a new intervals list
- */
- public static IntervalsList subtract(IntervalsList list, Interval i) {
- IntervalsList copy = new IntervalsList(list);
- copy.subtractFromSelf(i);
- return copy;
- }
-
- /** Intersects the instance and an interval.
- * @param i interval
- */
- public void intersectSelf(Interval i) {
- List newIntervals = new ArrayList();
- for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
- Interval local = (Interval) iterator.next();
- if (local.intersects(i)) {
- newIntervals.add(Interval.intersection(local, i));
- }
- }
- intervals = newIntervals;
- }
-
- /** Intersect a list and an interval.
- * @param list intervals list
- * @param i interval
- * @return the intersection of list and i
- */
- public static IntervalsList intersection(IntervalsList list, Interval i) {
- IntervalsList copy = new IntervalsList(list);
- copy.intersectSelf(i);
- return copy;
- }
-
- /** Add an intervals list to the instance.
- * <p>This method expands the instance.</p>
- * <p>This operation is a union operation. The number of intervals
- * in the list can decrease if the list fills some holes between
- * existing intervals in the instance.</p>
- * @param list intervals list to add to the instance
- */
- public void addToSelf(IntervalsList list) {
- for (Iterator iterator = list.intervals.iterator(); iterator.hasNext();) {
- addToSelf((Interval) iterator.next());
- }
- }
-
- /** Add two intervals lists.
- * @param list1 first intervals list
- * @param list2 second intervals list
- * @return a new intervals list which is the union of list1 and list2
- */
- public static IntervalsList add(IntervalsList list1, IntervalsList list2) {
- IntervalsList copy = new IntervalsList(list1);
- copy.addToSelf(list2);
- return copy;
- }
-
- /** Remove an intervals list from the instance.
- * @param list intervals list to remove
- */
- public void subtractFromSelf(IntervalsList list) {
- for (Iterator iterator = list.intervals.iterator(); iterator.hasNext();) {
- subtractFromSelf((Interval) iterator.next());
- }
- }
-
- /** Remove an intervals list from another one.
- * @param list1 intervals list
- * @param list2 intervals list to remove
- * @return a new intervals list
- */
- public static IntervalsList subtract(IntervalsList list1, IntervalsList list2) {
- IntervalsList copy = new IntervalsList(list1);
- copy.subtractFromSelf(list2);
- return copy;
- }
-
- /** Intersect the instance and another intervals list.
- * @param list list to intersect with the instance
- */
- public void intersectSelf(IntervalsList list) {
- intervals = intersection(this, list).intervals;
- }
-
- /** Intersect two intervals lists.
- * @param list1 first intervals list
- * @param list2 second intervals list
- * @return a new list which is the intersection of list1 and list2
- */
- public static IntervalsList intersection(IntervalsList list1, IntervalsList list2) {
- IntervalsList list = new IntervalsList();
- for (Iterator iterator = list2.intervals.iterator(); iterator.hasNext();) {
- list.addToSelf(intersection(list1, (Interval) iterator.next()));
- }
- return list;
- }
-
- /** The list of intervals. */
- private List intervals;
-
-}
-
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java
deleted file mode 100644
index 88cc7d1..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java
+++ /dev/null
@@ -1,85 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-/**
- * Wrapper class around an array in order to have it implement the
- * {@link ArraySliceMappable} interface.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class MappableArray
- implements ArraySliceMappable {
-
- /** Simple constructor.
- * Build a mappable array from its dimension
- * @param dimension dimension of the array
- */
- public MappableArray(int dimension) {
- internalArray = new double[dimension];
- for (int i = 0; i < dimension; ++i) {
- internalArray[i] = 0;
- }
- }
-
- /** Simple constructor.
- * Build a mappable array from an existing array
- * @param array array to use
- */
- public MappableArray(double[] array) {
- internalArray = (double[]) array.clone();
- }
-
- /** Get the array stored in the instance.
- * @return array stored in the instance
- */
- public double[] getArray () {
- return (double[]) internalArray.clone();
- }
-
- /** Get the dimension of the internal array.
- * @return dimension of the array
- */
- public int getStateDimension() {
- return internalArray.length;
- }
-
- /** Reinitialize internal state from the specified array slice data.
- * @param start start index in the array
- * @param array array holding the data to extract
- */
- public void mapStateFromArray(int start, double[] array) {
- System.arraycopy(array, start, internalArray, 0, internalArray.length);
- }
-
- /** Store internal state data into the specified array slice.
- * @param start start index in the array
- * @param array array where data should be stored
- */
- public void mapStateToArray(int start, double[] array) {
- System.arraycopy(internalArray, 0, array, start, internalArray.length);
- }
-
- /** Internal array holding all data.
- */
- double[] internalArray;
-
-}
diff --git a/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java b/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java
deleted file mode 100644
index 1ecdb92..0000000
--- a/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-/**
- * Wrapper class around a scalar in order to have it implement the
- * {@link ArraySliceMappable} interface.
-
- * @version $Id$
- * @author L. Maisonobe
-
- */
-
-public class MappableScalar
- implements ArraySliceMappable {
-
- /** Simple constructor.
- * Build a mappable scalar
- */
- public MappableScalar() {
- value = 0;
- }
-
- /** Simple constructor.
- * Build a mappable scalar from its initial value
- * @param value initial value of the scalar
- */
- public MappableScalar(double value) {
- this.value = value;
- }
-
- /** Get the value stored in the instance.
- * @return value stored in the instance
- */
- public double getValue () {
- return value;
- }
-
- /** Set the value stored in the instance.
- * @param value value to store in the instance
- */
- public void setValue (double value) {
- this.value = value;
- }
-
- /** Get the dimension of the internal array.
- * @return dimension of the array (always 1 for this class)
- */
- public int getStateDimension() {
- return 1;
- }
-
- /** Reinitialize internal state from the specified array slice data.
- * @param start start index in the array
- * @param array array holding the data to extract
- */
- public void mapStateFromArray(int start, double[] array) {
- value = array[start];
- }
-
- /** Store internal state data into the specified array slice.
- * @param start start index in the array
- * @param array array where data should be stored
- */
- public void mapStateToArray(int start, double[] array) {
- array[start] = value;
- }
-
- /** Internal scalar.
- */
- double value;
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java
deleted file mode 100644
index 7546d61..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
-
- public static Test suite() {
-
- TestSuite suite= new TestSuite("org.spaceroots.mantissa");
-
- suite.addTest(org.spaceroots.mantissa.linalg.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.functions.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.roots.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.fitting.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.quadrature.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.utilities.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.algebra.AllTests.suite());
-
- return suite;
-
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java
deleted file mode 100644
index 9f7d5be..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.algebra");
-
- suite.addTest(RationalNumberTest.suite());
- suite.addTest(PolynomialRationalTest.suite());
- suite.addTest(PolynomialDoubleTest.suite());
- suite.addTest(PolynomialFractionTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java
deleted file mode 100644
index 2861fac..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import junit.framework.*;
-
-public class PolynomialDoubleTest
- extends TestCase {
-
- public PolynomialDoubleTest(String name) {
- super(name);
- }
-
- public void testConstructors() {
-
- Polynomial.Double p = new Polynomial.Double(1.0, 3.0, -5.0);
- double[] a = p.getCoefficients();
- assertEquals(a.length, 3);
- assertEquals(-5.0, a[0], 1.0e-12);
- assertEquals(3.0, a[1], 1.0e-12);
- assertEquals(1.0, a[2], 1.0e-12);
- assertEquals(p.getDegree(), 2);
-
- assertEquals(1, new Polynomial.Double(0.0, 3.0, 5.0).getDegree());
- assertEquals(0, new Polynomial.Double(0.0, 0.0, 5.0).getDegree());
- assertEquals(0, new Polynomial.Double(0.0, 0.0, 0.0).getDegree());
- assertEquals(1, new Polynomial.Double(3.0, 5.0).getDegree());
- assertEquals(0, new Polynomial.Double(0.0, 5.0).getDegree());
- assertEquals(0, new Polynomial.Double(0.0, 0.0).getDegree());
- assertEquals(0, new Polynomial.Double(5.0).getDegree());
- assertEquals(0, new Polynomial.Double(0.0).getDegree());
-
- }
-
- public void testConversion() {
- Polynomial.Rational r = new Polynomial.Rational(1l, 3l, -5l);
- r = (Polynomial.Rational) r.multiply(new RationalNumber(1l, 2l));
- Polynomial.Double p = new Polynomial.Double(r);
- checkPolynomial(p, "-2.5 + 1.5 x + 0.5 x^2");
- }
-
- public void testString() {
- Polynomial.Double p = new Polynomial.Double(1.0, 3.0, -5.0);
- checkPolynomial(p, "-5.0 + 3.0 x + x^2");
- checkPolynomial(new Polynomial.Double(3.0, -2.0, 0.0),
- "-2.0 x + 3.0 x^2");
- checkPolynomial(new Polynomial.Double(3.0, -2.0, 1.0),
- "1.0 - 2.0 x + 3.0 x^2");
- checkPolynomial(new Polynomial.Double(3.0, 2.0, 0.0),
- "2.0 x + 3.0 x^2");
- checkPolynomial(new Polynomial.Double(3.0, 2.0, 1.0),
- "1.0 + 2.0 x + 3.0 x^2");
- checkPolynomial(new Polynomial.Double(3.0, 0.0, 1.0),
- "1.0 + 3.0 x^2");
- checkPolynomial(new Polynomial.Double(0.0),
- "0");
- }
-
- public void testAddition() {
-
- Polynomial.Double p1 = new Polynomial.Double(1.0, -2.0);
- Polynomial.Double p2 = new Polynomial.Double(0.0, -1.0, 2.0);
- assertTrue(p1.add(p2).isZero());
-
- p2 = p1.add(p1);
- checkPolynomial(p2, "-4.0 + 2.0 x");
-
- p1 = new Polynomial.Double(2.0, -4.0, 1.0);
- p2 = new Polynomial.Double(-2.0, 3.0, -1.0);
- p1 = p1.add(p2);
- assertEquals(1, p1.getDegree());
- checkPolynomial(p1, "-x");
-
- }
-
- public void testSubtraction() {
-
- Polynomial.Double p1 = new Polynomial.Double(1.0, -2.0);
- assertTrue(p1.subtract(p1).isZero());
-
- Polynomial.Double p2 = new Polynomial.Double(6.0, -2.0);
- p2 = p2.subtract(p1);
- checkPolynomial(p2, "5.0 x");
-
- p1 = new Polynomial.Double(2.0, -4.0, 1.0);
- p2 = new Polynomial.Double(2.0, 3.0, -1.0);
- p1 = p1.subtract(p2);
- assertEquals(1, p1.getDegree());
- checkPolynomial(p1, "2.0 - 7.0 x");
-
- }
-
- public void testMultiplication() {
-
- Polynomial.Double p1 = new Polynomial.Double(2.0, -3.0);
- Polynomial.Double p2 = new Polynomial.Double(1.0, 2.0, 3.0);
- checkPolynomial(p1.multiply(p2), "-9.0 + x^2 + 2.0 x^3");
-
- p1 = new Polynomial.Double(1.0, 0.0);
- p2 = p1;
- for (int i = 2; i < 10; ++i) {
- p2 = p2.multiply(p1);
- checkPolynomial(p2, "x^" + i);
- }
-
- }
-
- public void checkPolynomial(Polynomial.Double p, String reference) {
- assertEquals(reference, p.toString());
- }
-
- public static Test suite() {
- return new TestSuite(PolynomialDoubleTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java
deleted file mode 100644
index f23e99c..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java
+++ /dev/null
@@ -1,195 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import junit.framework.*;
-
-public class PolynomialFractionTest
- extends TestCase {
-
- public PolynomialFractionTest(String name) {
- super(name);
- }
-
- public void testNullDenominator() {
- try {
- new PolynomialFraction(1l, 0l);
- fail("an exception should have been thrown");
- } catch (ArithmeticException e) {
- } catch (Exception e) {
- fail("wrong exception caught");
- }
- }
-
- public void testToString() {
- checkValue(new PolynomialFraction(1l, 2l), "1/2");
- checkValue(new PolynomialFraction(-1l, 2l), "-1/2");
- checkValue(new PolynomialFraction(1l, -2l), "-1/2");
- checkValue(new PolynomialFraction(-1l, -2l), "1/2");
- checkValue(new PolynomialFraction(0l, 500l), "0");
- checkValue(new PolynomialFraction(-12l), "-12");
- checkValue(new PolynomialFraction(12l), "12");
- }
-
- public void testSimplification() {
- checkValue(new PolynomialFraction(2l, 4l), "1/2");
- checkValue(new PolynomialFraction(307692l, 999999l), "4/13");
- checkValue(new PolynomialFraction(999999l, 307692l), "13/4");
- }
-
- public void testInvert() {
-
- PolynomialFraction f = new PolynomialFraction(2l, 4l);
- f= f.invert();
- checkValue(f, "2");
- f = f.invert();
- checkValue(f, "1/2");
-
- f = new PolynomialFraction(120l);
- f = f.invert();
- checkValue(f, "1/120");
-
- f = new PolynomialFraction(0l, 4l);
- try {
- f = f.invert();
- fail("an exception should have been thrown");
- } catch (ArithmeticException e) {
- } catch (Exception e) {
- fail("wrong exception caught");
- }
-
- f = new PolynomialFraction(307692l, 999999l);
- PolynomialFraction fInverse = f.invert();
- checkValue(fInverse, "13/4");
- checkValue(f, "4/13");
-
- }
-
- public void testAddition() {
-
- PolynomialFraction f1 = new PolynomialFraction(4l, 6l);
- f1 = f1.add(f1);
- checkValue(f1, "4/3");
-
- checkValue(new PolynomialFraction(17l, 3l).add(new PolynomialFraction(-17l, 3l)),
- "0");
- checkValue(new PolynomialFraction(2l, 3l).add(new PolynomialFraction(3l, 4l)),
- "17/12");
- checkValue(new PolynomialFraction(1l, 6l).add(new PolynomialFraction(2l, 6l)),
- "1/2");
- checkValue(new PolynomialFraction(4l, 5l).add(new PolynomialFraction(-3l, 4l)),
- "1/20");
- checkValue(new PolynomialFraction(-3l, 4l).add(new PolynomialFraction(4l, 5l)),
- "1/20");
-
- }
-
- public void testSubtraction() {
-
- PolynomialFraction f1 = new PolynomialFraction(4l, 6l);
- checkValue(f1.subtract(f1), "0");
-
- checkValue(new PolynomialFraction(7l, 3l).subtract(new PolynomialFraction(-7l, 3l)),
- "14/3");
-
- checkValue(new PolynomialFraction(3l, 4l).subtract(new PolynomialFraction(2l, 3l)),
- "1/12");
- checkValue(new PolynomialFraction(3l, 4l).subtract(new PolynomialFraction(-2l, 3l)),
- "17/12");
- checkValue(new PolynomialFraction(-3l, 4l).subtract(new PolynomialFraction(2l, 3l)),
- "-17/12");
- checkValue(new PolynomialFraction(-3l, 4l).subtract(new PolynomialFraction(-2l, 3l)),
- "-1/12");
-
- checkValue(new PolynomialFraction(2l, 3l).subtract(new PolynomialFraction(3l, 4l)),
- "-1/12");
- checkValue(new PolynomialFraction(-2l, 3l).subtract(new PolynomialFraction(3l, 4l)),
- "-17/12");
- checkValue(new PolynomialFraction(2l, 3l).subtract(new PolynomialFraction(-3l, 4l)),
- "17/12");
- checkValue(new PolynomialFraction(-2l, 3l).subtract(new PolynomialFraction(-3l, 4l)),
- "1/12");
-
- checkValue(new PolynomialFraction(1l, 6l).subtract(new PolynomialFraction(2l, 6l)),
- "-1/6");
- checkValue(new PolynomialFraction(1l, 2l).subtract(new PolynomialFraction(1l, 6l)),
- "1/3");
-
- }
-
- public void testMultiplication() {
-
- PolynomialFraction f = new PolynomialFraction(2l, 3l);
- checkValue(f.multiply(new PolynomialFraction(9l,4l)), "3/2");
-
- checkValue(new PolynomialFraction(1l, 2l).multiply(new PolynomialFraction(0l)),
- "0");
- checkValue(new PolynomialFraction(4l, 15l).multiply(new PolynomialFraction(-5l, 2l)),
- "-2/3");
- checkValue(new PolynomialFraction(-4l, 15l).multiply(new PolynomialFraction(5l, 2l)),
- "-2/3");
- checkValue(new PolynomialFraction(4l, 15l).multiply(new PolynomialFraction(5l, 2l)),
- "2/3");
- checkValue(new PolynomialFraction(-4l, 15l).multiply(new PolynomialFraction(-5l, 2l)),
- "2/3");
-
- }
-
- public void testDivision() {
-
- PolynomialFraction f = new PolynomialFraction(2l, 3l);
- ;
- checkValue(f.divide(new PolynomialFraction(4l,9l)), "3/2");
-
- try {
- new PolynomialFraction(1l, 2l).divide(new PolynomialFraction(0l));
- fail("an exception should have been thrown");
- } catch (ArithmeticException e) {
- } catch (Exception e) {
- fail("wrong exception caught");
- }
-
- checkValue(new PolynomialFraction(4l, 15l).divide(new PolynomialFraction(-2l, 5l)),
- "-2/3");
- checkValue(new PolynomialFraction(-4l, 15l).divide(new PolynomialFraction(2l, 5l)),
- "-2/3");
- checkValue(new PolynomialFraction(4l, 15l).divide(new PolynomialFraction(2l, 5l)),
- "2/3");
- checkValue(new PolynomialFraction(-4l, 15l).divide(new PolynomialFraction(-2l, 5l)),
- "2/3");
-
- }
-
- public void testEuclidianDivision() {
- checkValue(new PolynomialFraction(new Polynomial.Rational(1l, 0l, -1l),
- new Polynomial.Rational(2l, 2l)),
- "-1/2 + 1/2 x");
- checkValue(new PolynomialFraction(new Polynomial.Rational(1l, 3l, 2l),
- new Polynomial.Rational(2l, 10l, 12l)),
- "(1 + x)/(6 + 2 x)");
- }
-
- private void checkValue(PolynomialFraction f, String reference) {
- assertTrue(f.toString().equals(reference));
- }
-
- public static Test suite() {
- return new TestSuite(PolynomialFractionTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java
deleted file mode 100644
index 630d89a..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import java.math.BigInteger;
-
-import junit.framework.*;
-
-public class PolynomialRationalTest
- extends TestCase {
-
- public PolynomialRationalTest(String name) {
- super(name);
- }
-
- public void testZero() {
- assertTrue(new Polynomial.Rational().isZero());
- }
-
- public void testConstructors() {
-
- Polynomial.Rational p = new Polynomial.Rational(1l, 3l, -5l);
- RationalNumber[] a = p.getCoefficients();
- assertEquals(a.length, 3);
- assertEquals(new RationalNumber(-5l), a[0]);
- assertEquals(new RationalNumber(3l), a[1]);
- assertEquals(new RationalNumber(1l), a[2]);
- assertEquals(2, p.getDegree());
-
- assertEquals(1, new Polynomial.Rational(0l, 3l, 5l).getDegree());
- assertEquals(0, new Polynomial.Rational(0l, 0l, 5l).getDegree());
- assertEquals(0, new Polynomial.Rational(0l, 0l, 0l).getDegree());
- assertEquals(1, new Polynomial.Rational(3l, 5l).getDegree());
- assertEquals(0, new Polynomial.Rational(0l, 5l).getDegree());
- assertEquals(0, new Polynomial.Rational(0l, 0l).getDegree());
- assertEquals(0, new Polynomial.Rational(5l).getDegree());
- assertEquals(0, new Polynomial.Rational(0l).getDegree());
-
- }
-
- public void testString() {
-
- Polynomial.Rational p = new Polynomial.Rational(1l, 3l, -5l);
- checkPolynomial(p, "-5 + 3 x + x^2");
-
- checkPolynomial(new Polynomial.Rational(3l, -2l, 0l), "-2 x + 3 x^2");
- checkPolynomial(new Polynomial.Rational(3l, -2l, 1l), "1 - 2 x + 3 x^2");
- checkPolynomial(new Polynomial.Rational(3l, 2l, 0l), "2 x + 3 x^2");
- checkPolynomial(new Polynomial.Rational(3l, 2l, 1l), "1 + 2 x + 3 x^2");
- checkPolynomial(new Polynomial.Rational(3l, 0l, 1l), "1 + 3 x^2");
- checkPolynomial(new Polynomial.Rational(0l), "0");
-
- }
-
- public void testAddition() {
-
- Polynomial.Rational p1 = new Polynomial.Rational(1l, -2l);
- Polynomial.Rational p2 = new Polynomial.Rational(0l, -1l, 2l);
- assertTrue(p1.add(p2).isZero());
-
- p2 = p1.add(p1);
- checkPolynomial(p2, "-4 + 2 x");
-
- p1 = new Polynomial.Rational(2l, -4l, 1l);
- p2 = new Polynomial.Rational(-2l, 3l, -1l);
- p1 = p1.add(p2);
- assertEquals(1, p1.getDegree());
- checkPolynomial(p1, "-x");
-
- }
-
- public void testSubtraction() {
-
- Polynomial.Rational p1 = new Polynomial.Rational(1l, -2l);
- assertTrue(p1.subtract(p1).isZero());
-
- Polynomial.Rational p2 = new Polynomial.Rational(6l, -2l);
- p2 = p2.subtract(p1);
- checkPolynomial(p2, "5 x");
-
- p1 = new Polynomial.Rational(2l, -4l, 1l);
- p2 = new Polynomial.Rational(2l, 3l, -1l);
- p1 = p1.subtract(p2);
- assertEquals(1, p1.getDegree());
- checkPolynomial(p1, "2 - 7 x");
-
- }
-
- public void testMultiplication() {
-
- Polynomial.Rational p1 = new Polynomial.Rational(2l, -3l);
- Polynomial.Rational p2 = new Polynomial.Rational(1l, 2l, 3l);
- checkPolynomial(p1.multiply(p2), "-9 + x^2 + 2 x^3");
-
- p1 = new Polynomial.Rational(1l, 0l);
- p2 = p1;
- for (int i = 2; i < 10; ++i) {
- p2 = p2.multiply(p1);
- checkPolynomial(p2, "x^" + i);
- }
-
- }
-
- public void testLCM() {
- Polynomial.Rational p = new Polynomial.Rational(new RationalNumber(2l, 5l),
- new RationalNumber(-1l, 6l),
- new RationalNumber(3l, 4l));
- checkPolynomial(p, "3/4 - 1/6 x + 2/5 x^2");
- BigInteger lcm = p.getDenominatorsLCM();
- assertEquals(BigInteger.valueOf(60l), lcm);
- p = (Polynomial.Rational) p.multiply(lcm);
- checkPolynomial(p, "45 - 10 x + 24 x^2");
- }
-
- public void testEuclidianDivision() {
- Polynomial.Rational p = new Polynomial.Rational(4l, 6l, -3l);
- Polynomial.Rational q = new Polynomial.Rational(3l, 2l);
- Polynomial.DivisionResult res = Polynomial.Rational.euclidianDivision(p, q);
- checkPolynomial(res.quotient, "10/9 + 4/3 x");
- checkPolynomial(res.remainder, "-47/9");
- }
-
- public void checkPolynomial(Polynomial.Rational p, String reference) {
- assertEquals(reference, p.toString());
- }
-
- public static Test suite() {
- return new TestSuite(PolynomialRationalTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java
deleted file mode 100644
index c76d28f..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.algebra;
-
-import junit.framework.*;
-
-public class RationalNumberTest
- extends TestCase {
-
- public RationalNumberTest(String name) {
- super(name);
- }
-
- public void testNullDenominator() {
- try {
- new RationalNumber(1l, 0l);
- fail("an exception should have been thrown");
- } catch (ArithmeticException e) {
- } catch (Exception e) {
- fail("wrong exception caught");
- }
- }
-
- public void testToString() {
- checkValue(new RationalNumber(1l, 2l), "1/2");
- checkValue(new RationalNumber(-1l, 2l), "-1/2");
- checkValue(new RationalNumber(1l, -2l), "-1/2");
- checkValue(new RationalNumber(-1l, -2l), "1/2");
- checkValue(new RationalNumber(0l, 500l), "0");
- checkValue(new RationalNumber(-12l), "-12");
- checkValue(new RationalNumber(12l), "12");
- }
-
- public void testSimplification() {
- checkValue(new RationalNumber(2l, 4l), "1/2");
- checkValue(new RationalNumber(307692l, 999999l), "4/13");
- checkValue(new RationalNumber(999999l, 307692l), "13/4");
- }
-
- public void testInvert() {
-
- RationalNumber f = new RationalNumber(2l, 4l).invert();
- checkValue(f, "2");
- f = f.invert();
- checkValue(f, "1/2");
-
- f = new RationalNumber(120l).invert();
- checkValue(f, "1/120");
-
- f = new RationalNumber(0l, 4l);
- try {
- f.invert();
- fail("an exception should have been thrown");
- } catch (ArithmeticException e) {
- } catch (Exception e) {
- fail("wrong exception caught");
- }
-
- f = new RationalNumber(307692l, 999999l);
- RationalNumber fInverse = f.invert();
- checkValue(fInverse, "13/4");
- checkValue(f, "4/13");
-
- }
-
- public void testAddition() {
-
- RationalNumber f1 = new RationalNumber(4l, 6l);
- f1 = f1.add(f1);
- checkValue(f1, "4/3");
-
- checkValue(new RationalNumber(17l, 3l).add(new RationalNumber(-17l, 3l)),
- "0");
- checkValue(new RationalNumber(2l, 3l).add(new RationalNumber(3l, 4l)),
- "17/12");
- checkValue(new RationalNumber(1l, 6l).add(new RationalNumber(2l, 6l)),
- "1/2");
- checkValue(new RationalNumber(4l, 5l).add(new RationalNumber(-3l, 4l)),
- "1/20");
- checkValue(new RationalNumber(-3l, 4l).add(new RationalNumber(4l, 5l)),
- "1/20");
-
- }
-
- public void testSubtraction() {
-
- RationalNumber f1 = new RationalNumber(4l, 6l);
- f1 = f1.subtract(f1);
- checkValue(f1, "0");
-
- checkValue(new RationalNumber(7l, 3l).subtract(new RationalNumber(-7l, 3l)),
- "14/3");
-
- checkValue(new RationalNumber(3l, 4l).subtract(new RationalNumber(2l, 3l)),
- "1/12");
- checkValue(new RationalNumber(3l, 4l).subtract(new RationalNumber(-2l, 3l)),
- "17/12");
- checkValue(new RationalNumber(-3l, 4l).subtract(new RationalNumber(2l, 3l)),
- "-17/12");
- checkValue(new RationalNumber(-3l, 4l).subtract(new RationalNumber(-2l, 3l)),
- "-1/12");
-
- checkValue(new RationalNumber(2l, 3l).subtract(new RationalNumber(3l, 4l)),
- "-1/12");
- checkValue(new RationalNumber(-2l, 3l).subtract(new RationalNumber(3l, 4l)),
- "-17/12");
- checkValue(new RationalNumber(2l, 3l).subtract(new RationalNumber(-3l, 4l)),
- "17/12");
- checkValue(new RationalNumber(-2l, 3l).subtract(new RationalNumber(-3l, 4l)),
- "1/12");
-
- checkValue(new RationalNumber(1l, 6l).subtract(new RationalNumber(2l, 6l)),
- "-1/6");
- checkValue(new RationalNumber(1l, 2l).subtract(new RationalNumber(1l, 6l)),
- "1/3");
-
- }
-
- public void testMultiplication() {
-
- RationalNumber f = new RationalNumber(2l, 3l);
- f = f.multiply(new RationalNumber(9l,4l));
- checkValue(f, "3/2");
-
- checkValue(new RationalNumber(1l, 2l).multiply(new RationalNumber(0l)),
- "0");
- checkValue(new RationalNumber(4l, 15l).multiply(new RationalNumber(-5l, 2l)),
- "-2/3");
- checkValue(new RationalNumber(-4l, 15l).multiply(new RationalNumber(5l, 2l)),
- "-2/3");
- checkValue(new RationalNumber(4l, 15l).multiply(new RationalNumber(5l, 2l)),
- "2/3");
- checkValue(new RationalNumber(-4l, 15l).multiply(new RationalNumber(-5l, 2l)),
- "2/3");
-
- }
-
- public void testDivision() {
-
- RationalNumber f = new RationalNumber(2l, 3l);
- f = f.divide(new RationalNumber(4l,9l));
- checkValue(f, "3/2");
-
- try {
- new RationalNumber(1l, 2l).divide(new RationalNumber(0l));
- fail("an exception should have been thrown");
- } catch (ArithmeticException e) {
- } catch (Exception e) {
- fail("wrong exception caught");
- }
-
- checkValue(new RationalNumber(4l, 15l).divide(new RationalNumber(-2l, 5l)),
- "-2/3");
- checkValue(new RationalNumber(-4l, 15l).divide(new RationalNumber(2l, 5l)),
- "-2/3");
- checkValue(new RationalNumber(4l, 15l).divide(new RationalNumber(2l, 5l)),
- "2/3");
- checkValue(new RationalNumber(-4l, 15l).divide(new RationalNumber(-2l, 5l)),
- "2/3");
-
- }
-
- private void checkValue(RationalNumber f, String reference) {
- assertTrue(f.toString().equals(reference));
- }
-
- public static Test suite() {
- return new TestSuite(RationalNumberTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/AllTests.java
deleted file mode 100644
index 07245d7..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/AllTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.functions");
-
- suite.addTest(org.spaceroots.mantissa.functions.scalar.AllTests.suite());
- suite.addTest(org.spaceroots.mantissa.functions.vectorial.AllTests.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/AllTests.java
deleted file mode 100644
index 79a5e88..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/AllTests.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.functions.scalar");
-
- suite.addTest(ScalarValuedPairTest.suite());
- suite.addTest(ComputableFunctionSamplerTest.suite());
- suite.addTest(BasicSampledFunctionIteratorTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/BasicSampledFunctionIteratorTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/BasicSampledFunctionIteratorTest.java
deleted file mode 100644
index e7e4079..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/BasicSampledFunctionIteratorTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-import junit.framework.*;
-
-public class BasicSampledFunctionIteratorTest
- extends TestCase {
-
- public BasicSampledFunctionIteratorTest(String name) {
- super(name);
- }
-
- public void testIteration()
- throws ExhaustedSampleException, FunctionException {
-
- BasicSampledFunctionIterator iter =
- new BasicSampledFunctionIterator(new Function(0.0, 0.1, 10));
-
- for (int i = 0; i < 10; ++i) {
- assertTrue(iter.hasNext());
- ScalarValuedPair pair = iter.nextSamplePoint();
- assertTrue(Math.abs(pair.getX() - 0.1 * i) < 1.0e-10);
- assertTrue(Math.abs(pair.getY() + 0.1 * i) < 1.0e-10);
- }
-
- }
-
- public void testExhausted()
- throws ExhaustedSampleException, FunctionException {
-
- BasicSampledFunctionIterator iter =
- new BasicSampledFunctionIterator(new Function(0.0, 0.1, 10));
-
- for (int i = 0; i < 10; ++i) {
- assertTrue(iter.hasNext());
- iter.nextSamplePoint();
- }
-
- assertTrue(! iter.hasNext());
-
- boolean exceptionOccurred = false;
- try {
- iter.nextSamplePoint();
- } catch(ExhaustedSampleException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public void testUnderlyingException()
- throws ExhaustedSampleException, FunctionException {
-
- BasicSampledFunctionIterator iter =
- new BasicSampledFunctionIterator(new ExceptionGeneratingFunction());
-
- boolean exceptionOccurred = false;
- try {
- iter.nextSamplePoint();
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(! exceptionOccurred);
-
- exceptionOccurred = false;
- try {
- iter.nextSamplePoint();
- } catch (FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public static Test suite() {
- return new TestSuite(BasicSampledFunctionIteratorTest.class);
- }
-
- private static class Function
- implements SampledFunction {
-
- private static final long serialVersionUID = -5071329620086891960L;
- private double begin;
- private double step;
- private int n;
-
- public Function(double begin, double step, int n) {
- this.begin = begin;
- this.step = step;
- this.n = n;
- }
-
- public int size() {
- return n;
- }
-
- public ScalarValuedPair samplePointAt(int i)
- throws FunctionException {
-
- if (i < 0 || i >= n) {
- throw new FunctionException("outside of range");
- }
-
- double x = begin + i * step;
- return new ScalarValuedPair(x, -x);
-
- }
- }
-
- private static class ExceptionGeneratingFunction
- implements SampledFunction {
-
- private static final long serialVersionUID = 1417147976215668305L;
- private boolean fireException = false;
-
- public int size() {
- return 2;
- }
-
- public ScalarValuedPair samplePointAt(int i)
- throws FunctionException {
- if (fireException) {
- throw new FunctionException("boom");
- }
- fireException = true;
- return new ScalarValuedPair(0.0, 0.0);
- }
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/ComputableFunctionSamplerTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/ComputableFunctionSamplerTest.java
deleted file mode 100644
index 87a1d51..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/ComputableFunctionSamplerTest.java
+++ /dev/null
@@ -1,196 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-import junit.framework.*;
-
-public class ComputableFunctionSamplerTest
- extends TestCase {
-
- public ComputableFunctionSamplerTest(String name) {
- super(name);
- }
-
- public void testBeginStepNumber()
- throws FunctionException {
-
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0),
- 0.0, 0.099, 11);
-
- assertTrue(sampler.size() == 11);
- assertTrue(Math.abs(sampler.samplePointAt(0).getX() - 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).getY() - 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).getX() - 0.495) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).getY() + 0.495) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).getX() - 0.990) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).getY() + 0.990) < 1.0e-10);
-
- }
-
- public void testRangeNumber()
- throws FunctionException {
-
- double[] range = new double[2];
- range[0] = 0.0;
- range[1] = 1.0;
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0), range, 11);
-
- assertTrue(sampler.size() == 11);
- assertTrue(Math.abs(sampler.samplePointAt(0).getX() - 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).getY() - 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).getX() - 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).getY() + 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).getX() - 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).getY() + 1.0) < 1.0e-10);
-
- }
-
- public void testRangeStepNoAdjust()
- throws FunctionException {
-
- double[] range = new double[2];
- range[0] = 0.0;
- range[1] = 1.0;
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0),
- range, 0.083, false);
-
- assertTrue(sampler.size() == 12);
- assertTrue(Math.abs(sampler.samplePointAt(0).getX() - 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).getY() - 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).getX() - 0.415) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).getY() + 0.415) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(11).getX() - 0.913) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(11).getY() + 0.913) < 1.0e-10);
-
- }
-
- public void testRangeStepAdjust()
- throws FunctionException {
-
- double[] range = new double[2];
- range[0] = 0.0;
- range[1] = 1.0;
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0),
- range, 0.083, true);
-
- assertTrue(sampler.size() == 13);
- assertTrue(Math.abs(sampler.samplePointAt(0).getX() - 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).getY() - 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(6).getX() - 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(6).getY() + 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(12).getX() - 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(12).getY() + 1.0) < 1.0e-10);
-
- }
-
- public void testOutOfRange()
- throws FunctionException {
-
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0), 0.0, 1.0, 10);
-
- boolean exceptionOccurred = false;
- try {
- sampler.samplePointAt(-1);
- } catch(ArrayIndexOutOfBoundsException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- exceptionOccurred = false;
- try {
- sampler.samplePointAt(10);
- } catch(ArrayIndexOutOfBoundsException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public void testUnderlyingException() {
-
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new ExceptionGeneratingFunction(),
- 0.0, 0.1, 11);
-
- boolean exceptionOccurred = false;
- try {
- sampler.samplePointAt(2);
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(! exceptionOccurred);
-
- exceptionOccurred = false;
- try {
- sampler.samplePointAt(8);
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public static Test suite() {
- return new TestSuite(ComputableFunctionSamplerTest.class);
- }
-
- private static class Function
- implements ComputableFunction {
-
- private static final long serialVersionUID = -7173012970400285826L;
- private double min;
- private double max;
-
- public Function(double min, double max) {
- this.min = min;
- this.max = max;
- }
-
- public double valueAt(double x)
- throws FunctionException {
-
- if (x < min || x > max) {
- throw new FunctionException("outside of range");
- }
-
- return -x;
-
- }
-
- }
-
- private static class ExceptionGeneratingFunction
- implements ComputableFunction {
- private static final long serialVersionUID = 7853080602731012102L;
- public double valueAt(double x)
- throws FunctionException {
- if (x < 0.5) {
- return -x;
- }
- throw new FunctionException("upper half range exception");
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/ScalarValuedPairTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/ScalarValuedPairTest.java
deleted file mode 100644
index c9c09f1..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/scalar/ScalarValuedPairTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.scalar;
-
-import junit.framework.*;
-
-public class ScalarValuedPairTest
- extends TestCase {
-
- public ScalarValuedPairTest(String name) {
- super(name);
- }
-
- public void testConstructor() {
- ScalarValuedPair pair = new ScalarValuedPair(1.2, -8.4);
- assertTrue(Math.abs(pair.getX() - 1.2) < 1.0e-10);
- assertTrue(Math.abs(pair.getY() + 8.4) < 1.0e-10);
- }
-
- public void testCopyConstructor() {
-
- ScalarValuedPair pair1 = new ScalarValuedPair(1.2, -8.4);
- ScalarValuedPair pair2 = new ScalarValuedPair(pair1);
-
- assertTrue(Math.abs(pair2.getX() - pair1.getX()) < 1.0e-10);
- assertTrue(Math.abs(pair2.getY() - pair1.getY()) < 1.0e-10);
- assertTrue(Math.abs(pair2.getX() - 1.2) < 1.0e-10);
- assertTrue(Math.abs(pair2.getY() + 8.4) < 1.0e-10);
-
- }
-
- public static Test suite() {
- return new TestSuite(ScalarValuedPairTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/AllTests.java
deleted file mode 100644
index e14e263..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/AllTests.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.functions.vectorial");
-
- suite.addTest(VectorialValuedPairTest.suite());
- suite.addTest(ComputableFunctionSamplerTest.suite());
- suite.addTest(BasicSampledFunctionIteratorTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/BasicSampledFunctionIteratorTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/BasicSampledFunctionIteratorTest.java
deleted file mode 100644
index 78d4579..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/BasicSampledFunctionIteratorTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-import org.spaceroots.mantissa.functions.ExhaustedSampleException;
-
-import junit.framework.*;
-
-public class BasicSampledFunctionIteratorTest
- extends TestCase {
-
- public BasicSampledFunctionIteratorTest(String name) {
- super(name);
- }
-
- public void testIteration()
- throws ExhaustedSampleException, FunctionException {
-
- BasicSampledFunctionIterator iter =
- new BasicSampledFunctionIterator(new Function(0.0, 0.1, 10));
-
- for (int i = 0; i < 10; ++i) {
- assertTrue(iter.hasNext());
- VectorialValuedPair pair = iter.nextSamplePoint();
- assertTrue(Math.abs(pair.x - 0.1 * i) < 1.0e-10);
- assertTrue(Math.abs(pair.y[0] + 0.1 * i) < 1.0e-10);
- assertTrue(Math.abs(pair.y[1] + 0.2 * i) < 1.0e-10);
- }
-
- }
-
- public void testExhausted()
- throws ExhaustedSampleException, FunctionException {
-
- BasicSampledFunctionIterator iter =
- new BasicSampledFunctionIterator(new Function(0.0, 0.1, 10));
-
- for (int i = 0; i < 10; ++i) {
- assertTrue(iter.hasNext());
- iter.nextSamplePoint();
- }
-
- assertTrue(! iter.hasNext());
-
- boolean exceptionOccurred = false;
- try {
- iter.nextSamplePoint();
- } catch(ExhaustedSampleException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public void testUnderlyingException()
- throws ExhaustedSampleException, FunctionException {
-
- BasicSampledFunctionIterator iter =
- new BasicSampledFunctionIterator(new ExceptionGeneratingFunction());
-
- boolean exceptionOccurred = false;
- try {
- iter.nextSamplePoint();
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(! exceptionOccurred);
-
- exceptionOccurred = false;
- try {
- iter.nextSamplePoint();
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public static Test suite() {
- return new TestSuite(BasicSampledFunctionIteratorTest.class);
- }
-
- private static class Function
- implements SampledFunction {
-
- private static final long serialVersionUID = -6049535144225908344L;
- private double begin;
- private double step;
- private int n;
- private double[] values;
-
- public Function(double begin, double step, int n) {
- this.begin = begin;
- this.step = step;
- this.n = n;
- values = new double[2];
- }
-
- public int size() {
- return n;
- }
-
- public int getDimension() {
- return 2;
- }
-
- public VectorialValuedPair samplePointAt(int i)
- throws FunctionException {
-
- if (i < 0 || i >= n) {
- throw new FunctionException("outside of range");
- }
-
- double x = begin + i * step;
- values[0] = -x;
- values[1] = 2.0 * values[0];
- return new VectorialValuedPair(x, values);
-
- }
- }
-
- private static class ExceptionGeneratingFunction
- implements SampledFunction {
-
- private static final long serialVersionUID = 3750401068561053681L;
- private boolean fireException = false;
-
- public int size() {
- return 2;
- }
-
- public int getDimension() {
- return 2;
- }
-
- public VectorialValuedPair samplePointAt(int i)
- throws FunctionException {
- if (fireException) {
- throw new FunctionException("boom");
- }
- fireException = true;
- return new VectorialValuedPair(0.0, new double[] { 0, 1 });
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/ComputableFunctionSamplerTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/ComputableFunctionSamplerTest.java
deleted file mode 100644
index bafc40d..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/ComputableFunctionSamplerTest.java
+++ /dev/null
@@ -1,229 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-import junit.framework.*;
-
-public class ComputableFunctionSamplerTest
- extends TestCase {
-
- public ComputableFunctionSamplerTest(String name) {
- super(name);
- }
-
- public void testBeginStepNumber()
- throws FunctionException {
-
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0), 0.0, 0.099, 11);
-
- assertTrue(sampler.size() == 11);
- assertTrue(sampler.getDimension() == 2);
- assertTrue(Math.abs(sampler.samplePointAt(0).x - 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[0] + 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[1] + 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).x - 0.495) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).y[0] + 0.495) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).y[1] + 0.990) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).x - 0.990) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).y[0] + 0.990) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).y[1] + 1.980) < 1.0e-10);
-
- }
-
- public void testRangeNumber()
- throws FunctionException {
-
- double[] range = new double[2];
- range[0] = 0.0;
- range[1] = 1.0;
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function (0.0, 1.0), range, 11);
-
- assertTrue(sampler.size() == 11);
- assertTrue(sampler.getDimension() == 2);
- assertTrue(Math.abs(sampler.samplePointAt(0).x - 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[0] + 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[1] + 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).x - 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).y[0] + 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).y[1] + 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).x - 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).y[0] + 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(10).y[1] + 2.0) < 1.0e-10);
-
- }
-
- public void testRangeStepNoAdjust()
- throws FunctionException {
-
- double[] range = new double[2];
- range[0] = 0.0;
- range[1] = 1.0;
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0),
- range, 0.083, false);
-
- assertTrue(sampler.size() == 12);
- assertTrue(sampler.getDimension() == 2);
- assertTrue(Math.abs(sampler.samplePointAt(0).x - 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[0] + 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[1] + 0.000) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).x - 0.415) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).y[0] + 0.415) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(5).y[1] + 0.830) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(11).x - 0.913) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(11).y[0] + 0.913) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(11).y[1] + 1.826) < 1.0e-10);
-
- }
-
- public void testRangeStepAdjust()
- throws FunctionException {
-
- double[] range = new double[2];
- range[0] = 0.0;
- range[1] = 1.0;
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0),
- range, 0.083, true);
-
- assertTrue(sampler.size() == 13);
- assertTrue(sampler.getDimension() == 2);
- assertTrue(Math.abs(sampler.samplePointAt(0).x - 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[0] + 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(0).y[1] + 0.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(6).x - 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(6).y[0] + 0.5) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(6).y[1] + 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(12).x - 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(12).y[0] + 1.0) < 1.0e-10);
- assertTrue(Math.abs(sampler.samplePointAt(12).y[1] + 2.0) < 1.0e-10);
-
- }
-
- public void testOutOfRange()
- throws FunctionException {
-
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new Function(0.0, 1.0), 0.0, 1.0, 10);
-
- boolean exceptionOccurred = false;
- try {
- sampler.samplePointAt(-1);
- } catch(ArrayIndexOutOfBoundsException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- exceptionOccurred = false;
- try {
- sampler.samplePointAt(10);
- } catch(ArrayIndexOutOfBoundsException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public void testUnderlyingException() {
-
- ComputableFunctionSampler sampler =
- new ComputableFunctionSampler(new ExceptionGeneratingFunction(),
- 0.0, 0.1, 11);
-
- boolean exceptionOccurred = false;
- try {
- sampler.samplePointAt(2);
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(! exceptionOccurred);
-
- exceptionOccurred = false;
- try {
- sampler.samplePointAt(8);
- } catch(FunctionException e) {
- exceptionOccurred = true;
- }
- assertTrue(exceptionOccurred);
-
- }
-
- public static Test suite() {
- return new TestSuite(ComputableFunctionSamplerTest.class);
- }
-
- private static class Function
- implements ComputableFunction {
- private double min;
- private double max;
- private double[] values;
-
- public int getDimension() {
- return 2;
- }
-
- public Function(double min, double max) {
- this.min = min;
- this.max = max;
- values = new double[2];
- }
-
- public double[] valueAt(double x)
- throws FunctionException {
-
- if (x < min || x > max) {
- throw new FunctionException("outside of range");
- }
-
- values[0] = -x;
- values[1] = -2.0 * x;
- return values;
-
- }
-
- private static final long serialVersionUID = -1859103913610458563L;
-
- }
-
- private static class ExceptionGeneratingFunction
- implements ComputableFunction {
-
- public int getDimension() {
- return 2;
- }
-
- public double[] valueAt(double x)
- throws FunctionException {
- if (x < 0.5) {
- double[] res = new double[2];
- res[0] = -x;
- res[1] = -2.0 * x;
- return res;
- }
- throw new FunctionException("upper half range exception");
- }
-
- private static final long serialVersionUID = 2849780376767626912L;
-
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java
deleted file mode 100644
index 04908c9..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.functions.vectorial;
-
-import junit.framework.*;
-
-public class VectorialValuedPairTest
- extends TestCase {
-
- public VectorialValuedPairTest(String name) {
- super(name);
- }
-
- public void testConstructor() {
- double[] tab = new double[2];
- tab[0] = -8.4;
- tab[1] = -3.2;
- VectorialValuedPair pair = new VectorialValuedPair(1.2, tab);
- assertTrue(Math.abs(pair.x - 1.2) < 1.0e-10);
- assertTrue(Math.abs(pair.y[0] + 8.4) < 1.0e-10);
- assertTrue(Math.abs(pair.y[1] + 3.2) < 1.0e-10);
- }
-
- public void testCopyConstructor() {
- double[] tab = new double[2];
- tab[0] = -8.4;
- tab[1] = -3.2;
- VectorialValuedPair pair1 = new VectorialValuedPair(1.2, tab);
- VectorialValuedPair pair2 = new VectorialValuedPair(pair1.x,
- pair1.y);
- assertTrue(Math.abs(pair2.x - pair1.x) < 1.0e-10);
- assertTrue(Math.abs(pair2.y[0] - pair1.y[0]) < 1.0e-10);
- assertTrue(Math.abs(pair2.y[1] - pair1.y[1]) < 1.0e-10);
- assertTrue(Math.abs(pair2.x - 1.2) < 1.0e-10);
- assertTrue(Math.abs(pair2.y[0] + 8.4) < 1.0e-10);
- assertTrue(Math.abs(pair2.y[1] + 3.2) < 1.0e-10);
- }
-
- public static Test suite() {
- return new TestSuite(VectorialValuedPairTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/AllTests.java
deleted file mode 100644
index b30bba2..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/AllTests.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.linalg");
-
- suite.addTest(NonNullRangeTest.suite());
- suite.addTest(GeneralMatrixTest.suite());
- suite.addTest(DiagonalMatrixTest.suite());
- suite.addTest(LowerTriangularMatrixTest.suite());
- suite.addTest(UpperTriangularMatrixTest.suite());
- suite.addTest(GeneralSquareMatrixTest.suite());
- suite.addTest(SymetricalMatrixTest.suite());
- suite.addTest(MatrixFactoryTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java
deleted file mode 100644
index 8803f02..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class DiagonalMatrixTest
- extends TestCase {
-
- public DiagonalMatrixTest(String name) {
- super(name);
- }
-
- public void testConstantDiagonal() {
- checkMatrix(new DiagonalMatrix(5, 2.7), 2.7);
- }
-
- public void testNoSetOutsideOfDiagonal() {
-
- DiagonalMatrix d = new DiagonalMatrix(4);
-
- for (int i = 0; i < d.getRows(); ++i) {
- for (int j = 0; j < d.getColumns(); ++j) {
- if (i == j) {
- d.setElement(i, j, 2.7);
- } else {
- boolean gotIt = false;
- try {
- d.setElement(i, j, -1.3);
- } catch (ArrayIndexOutOfBoundsException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
- }
- }
-
- checkMatrix(d, 2.7);
-
- }
-
- public void testCopy() {
- DiagonalMatrix d1 = new DiagonalMatrix(7, 4.3);
- DiagonalMatrix d2 = new DiagonalMatrix(d1);
-
- for (int i = 0; i < d1.getRows(); ++i) {
- d1.setElement(i, i, -1.0);
- }
-
- assertTrue(d2.getRows() == d1.getRows());
- assertTrue(d2.getColumns() == d1.getColumns());
-
- checkMatrix(d2, 4.3);
-
- }
-
- public void testDuplicate() {
- DiagonalMatrix d1 = new DiagonalMatrix(6, -8.8);
-
- Matrix d2 = d1.duplicate();
- assertTrue(d2 instanceof DiagonalMatrix);
-
- for (int i = 0; i < d1.getRows(); ++i) {
- d1.setElement(i, i, -1.0);
- }
-
- assertTrue(d2.getRows() == d1.getRows());
- assertTrue(d2.getColumns() == d1.getColumns());
-
- checkMatrix(d2, -8.8);
-
- }
-
- public void testTranspose() {
-
- DiagonalMatrix d = new DiagonalMatrix(5, 3.4);
-
- Matrix transposed = d.getTranspose();
- assertTrue(transposed instanceof DiagonalMatrix);
-
- checkMatrix(transposed, 3.4);
-
- }
-
- public void testDeterminant() {
-
- double expected;
-
- expected = 1.0;
- for (int k = 1; k < 10; ++k) {
- expected *= 2;
- DiagonalMatrix d = new DiagonalMatrix(k, 2.0);
- assertTrue(Math.abs(d.getDeterminant(1.0e-10) - expected) < 1.0e-10);
- }
-
- expected = 1.0;
- for (int k = 1; k < 10; ++k) {
- expected *= k;
- DiagonalMatrix d = new DiagonalMatrix(k);
- for (int i = 0; i < k; ++i) {
- d.setElement(i, i, i + 1);
- }
- assertTrue(Math.abs(d.getDeterminant(1.0e-10) - expected) < 1.0e-10);
- }
-
- }
-
- public void testSolve()
- throws SingularMatrixException {
-
- DiagonalMatrix d = new DiagonalMatrix(6);
- for (int i = 0; i < d.getRows(); ++i) {
- d.setElement(i, i, i + 1.0);
- }
-
- GeneralMatrix b = new GeneralMatrix(6, 3);
- for (int i = 0; i < b.getRows(); ++i) {
- b.setElement(i, 0, i + 1.0);
- b.setElement(i, 1, (i + 1.0) * (i + 1.0));
- b.setElement(i, 2, 0.0);
- }
-
- Matrix result = d.solve(b, 1.0e-10);
-
- assertTrue(result.getRows() == b.getRows());
- assertTrue(result.getColumns() == b.getColumns());
-
- for (int i = 0; i < result.getRows(); ++i) {
- assertTrue(Math.abs(result.getElement(i, 0) - 1.0) < 1.0e-10);
- assertTrue(Math.abs(result.getElement(i, 1) - (i + 1.0)) < 1.0e-10);
- assertTrue(Math.abs(result.getElement(i, 2) - 0.0) < 1.0e-10);
- }
-
- boolean gotIt = false;
- try {
- d.setElement(3, 3, 0.0);
- d.solve(b, 1.0e-10);
- } catch (SingularMatrixException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testInverse()
- throws SingularMatrixException {
-
- DiagonalMatrix d = new DiagonalMatrix(4);
- for (int i = 0; i < d.getRows (); ++i) {
- d.setElement(i, i, i + 1.0);
- }
-
- Matrix inverse = d.getInverse(1.0e-10);
- assertTrue(inverse instanceof DiagonalMatrix);
-
- for (int i = 0; i < inverse.getRows(); ++i) {
- assertTrue(Math.abs(inverse.getElement(i, i) - 1.0 / (i + 1.0)) < 1.0e-10);
- }
-
- }
-
- public static Test suite() {
- return new TestSuite(DiagonalMatrixTest.class);
- }
-
- public void checkMatrix(Matrix d, double value) {
- for (int i = 0; i < d.getRows(); ++i) {
- for (int j = 0; j < d.getColumns(); ++j) {
- double expected = (i == j) ? value : 0.0;
- assertTrue(Math.abs(d.getElement(i, j) - expected) < 1.0e-10);
- }
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java
deleted file mode 100644
index 781d58b..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java
+++ /dev/null
@@ -1,286 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class GeneralMatrixTest
- extends TestCase {
-
- public GeneralMatrixTest(String name) {
- super(name);
- }
-
- public void testDimensions() {
- GeneralMatrix m = new GeneralMatrix(3, 4);
- assertTrue(m.getRows() == 3);
- assertTrue(m.getColumns() == 4);
- }
-
- public void testInvalidDimensions() {
- boolean gotIt;
-
- gotIt = false;
- try {
- new GeneralMatrix(0, 2);
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- gotIt = false;
- try {
- new GeneralMatrix(1, -3, null);
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testElements() {
- Matrix m = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- checkMatrix(m, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testCopy() {
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- GeneralMatrix m2 = new GeneralMatrix(m1);
-
- for (int i = 0; i < m1.getRows(); ++i) {
- for (int j = 0; j < m1.getColumns(); ++j) {
- m1.setElement(i, j, -1.0);
- }
- }
-
- assertTrue(m2.getRows() == m1.getRows());
- assertTrue(m2.getColumns() == m1.getColumns());
-
- checkMatrix(m2, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testDuplicate() {
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = m1.duplicate();
- assertTrue(m2 instanceof GeneralMatrix);
-
- for (int i = 0; i < m1.getRows(); ++i) {
- for (int j = 0; j < m1.getColumns(); ++j) {
- m1.setElement(i, j, -1.0);
- }
- }
-
- assertTrue(m2.getRows() == m1.getRows());
- assertTrue(m2.getColumns() == m1.getColumns());
-
- checkMatrix (m2, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testAddKO() {
- boolean gotIt = false;
- try {
- new GeneralMatrix(2, 3).add(new GeneralMatrix(3, 2));
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
-
- public void testAddOK() {
-
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = buildMatrix(m1.getRows(),
- m1.getColumns(),
- new BilinearPattern(100, -0.01));
-
- Matrix m3 = m1.add(m2);
-
- checkMatrix(m3, new BilinearPattern(101, 0));
-
- }
-
- public void testSelfAdd() {
-
- GeneralMatrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = buildMatrix(m1.getRows(),
- m1.getColumns(),
- new BilinearPattern(100, -0.01));
-
- m1.selfAdd(m2);
-
- checkMatrix(m1, new BilinearPattern(101, 0));
-
- }
-
- public void testSubKO() {
- boolean gotIt = false;
- try {
- new GeneralMatrix(2, 3).sub(new GeneralMatrix(3, 2));
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
-
- public void testSubOK() {
-
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = buildMatrix(m1.getRows(),
- m1.getColumns(),
- new BilinearPattern(100, -0.01));
-
- Matrix m3 = m1.sub(m2);
-
- checkMatrix(m3, new BilinearPattern(-99, 0.02));
-
- }
-
- public void testSelfSub() {
-
- GeneralMatrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = buildMatrix(m1.getRows(),
- m1.getColumns(),
- new BilinearPattern(100, -0.01));
-
- m1.selfSub(m2);
-
- checkMatrix(m1, new BilinearPattern(-99, 0.02));
-
- }
-
- public void testMulMKO() {
- boolean gotIt = false;
- try {
- new GeneralMatrix(2, 3).mul(new GeneralMatrix(2, 3));
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
-
- public void testMulMOK() {
-
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = buildMatrix(m1.getColumns(), 4, new BilinearPattern(2, -1));
-
- Matrix m3 = m1.mul(m2);
-
- checkMatrix(m3, new ComplexPattern(m1.getColumns()));
-
- }
-
- public void testMulD() {
-
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = m1.mul(2.5);
-
- checkMatrix(m2, new BilinearPattern(2.5, 0.025));
-
- }
-
- public void testSelfMul() {
-
- Matrix m = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- m.selfMul(2.5);
-
- checkMatrix(m, new BilinearPattern(2.5, 0.025));
-
- }
-
- public void testTranspose() {
-
- Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = m1.getTranspose();
-
- assertTrue(m1.getRows() == m2.getColumns());
- assertTrue(m1.getColumns() == m2.getRows());
-
- checkMatrix(m2, new BilinearPattern(0.01, 1.0));
-
- }
-
- public static Test suite() {
- return new TestSuite(GeneralMatrixTest.class);
- }
-
- private interface ElementPattern {
- public double value(int i, int j);
- }
-
- private static class BilinearPattern implements ElementPattern {
- public BilinearPattern(double coeffI, double coeffJ) {
- this.coeffI = coeffI;
- this.coeffJ = coeffJ;
- }
- public double value(int i, int j) {
- return coeffI * i + coeffJ * j;
- }
- private final double coeffI;
- private final double coeffJ;
- }
-
- private static class ComplexPattern implements ElementPattern {
- public ComplexPattern(int p) {
- this.p = p;
- }
- public double value(int i, int j) {
- return p * ((2 * i - 0.01 *j) * (p - 1) / 2.0
- - i* j
- + (p - 1) * (2 * p - 1) / 300.0);
- }
- private final int p;
- }
-
- public GeneralMatrix buildMatrix(int rows, int columns,
- BilinearPattern pattern) {
- GeneralMatrix m = new GeneralMatrix(rows, columns);
-
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j){
- m.setElement(i, j, pattern.value(i, j));
- }
- }
-
- return m;
-
- }
-
- public void checkMatrix(Matrix m, ElementPattern pattern) {
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j) {
- assertTrue(Math.abs(m.getElement(i, j) - pattern.value(i, j))
- < 1.0e-10);
- }
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java
deleted file mode 100644
index 6b779bc..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java
+++ /dev/null
@@ -1,366 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class GeneralSquareMatrixTest
- extends TestCase {
-
- public GeneralSquareMatrixTest(String name) {
- super(name);
- }
-
- public void testDimensions() {
- GeneralSquareMatrix m = new GeneralSquareMatrix(3);
- assertTrue(m.getRows() == 3);
- assertTrue(m.getColumns() == 3);
- }
-
- public void testInvalidDimensions() {
- boolean gotIt;
-
- gotIt = false;
- try {
- new GeneralSquareMatrix(0);
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- gotIt = false;
- try {
- new GeneralSquareMatrix(-3, null);
- } catch(IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testElements() {
- Matrix m = buildMatrix(5, new BilinearPattern(1.0, 0.01));
-
- checkMatrix(m, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testCopy() {
- GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
-
- GeneralSquareMatrix m2 = new GeneralSquareMatrix(m1);
-
- for (int i = 0; i < m1.getRows(); ++i) {
- for (int j = 0; j < m1.getColumns(); ++j) {
- m1.setElement(i, j, -1.0);
- }
- }
-
- assertTrue(m2.getRows() == m1.getRows());
- assertTrue(m2.getColumns() == m1.getColumns());
-
- checkMatrix(m2, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testDuplicate() {
- GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
-
- Matrix m2 = m1.duplicate();
- assertTrue(m2 instanceof GeneralSquareMatrix);
-
- for (int i = 0; i < m1.getRows(); ++i) {
- for (int j = 0; j < m1.getColumns(); ++j) {
- m1.setElement(i, j, -1.0);
- }
- }
-
- assertTrue(m2.getRows() == m1.getRows());
- assertTrue(m2.getColumns() == m1.getColumns());
-
- checkMatrix(m2, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testSelfAdd() {
- GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
-
- GeneralSquareMatrix m2 = buildMatrix(5, new BilinearPattern(2, -0.03));
-
-
- m1.selfAdd(m2);
-
- checkMatrix(m1, new BilinearPattern(3, -0.02));
-
- }
-
- public void testSelfSub() {
- GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
-
- GeneralSquareMatrix m2 = buildMatrix(5, new BilinearPattern(2, -0.03));
-
-
- m1.selfSub(m2);
-
- checkMatrix(m1, new BilinearPattern(-1, 0.04));
-
- }
-
- public void testDeterminant() {
-
- GeneralSquareMatrix m1 = buildProblem1().a;
- assertTrue(Math.abs(m1.getDeterminant(1.0e-10) - 6.0) < 1.0e-10);
-
- GeneralSquareMatrix m2 = buildProblem2().a;
- assertTrue(Math.abs(m2.getDeterminant(1.0e-10) + 0.9999999) < 1.0e-10);
-
- GeneralSquareMatrix m3 = buildProblem3().a;
- assertTrue(Math.abs(m3.getDeterminant(1.0e-10) - 0.0) < 1.0e-10);
-
- }
-
- public void testSolve()
- throws SingularMatrixException {
-
- LinearProblem p;
- Matrix result;
-
- p = buildProblem1();
- result = p.a.solve(p.b, 1.0e-10);
- checkSolve(p, result);
-
- p = buildProblem2();
- result = p.a.solve(p.b, 1.0e-10);
- checkSolve(p, result);
-
- try {
- p = buildProblem3();
- result = p.a.solve(p.b, 1.0e-10);
- fail("got " + result + ", should have caught an exception");
- } catch(SingularMatrixException e) {
- // expected
- } catch(Exception e) {
- fail("wrong exception caught: " + e.getMessage());
- }
-
- }
-
- public void testInverse()
- throws SingularMatrixException {
-
- SquareMatrix a, inverse;
-
- a = buildProblem1().a;
- inverse = a.getInverse(1.0e-10);
- checkMatrix(a.mul(inverse), new IdentityPattern());
-
- a = buildProblem2().a;
- inverse = a.getInverse(1.0e-10);
- checkMatrix(a.mul(inverse), new IdentityPattern());
-
- try {
- a = buildProblem3().a;
- inverse = a.getInverse(1.0e-10);
- fail("got " + inverse + ", should have caught an exception");
- } catch(SingularMatrixException e) {
- // expected
- } catch(Exception e) {
- fail("wrong exception caught: " + e.getMessage());
- }
-
- }
-
- public static Test suite() {
- return new TestSuite(GeneralSquareMatrixTest.class);
- }
-
- private interface ElementPattern {
- public double value(int i, int j);
- }
-
- private static class BilinearPattern implements ElementPattern {
- public BilinearPattern(double coeffI, double coeffJ) {
- this.coeffI = coeffI;
- this.coeffJ = coeffJ;
- }
- public double value(int i, int j) {
- return coeffI * i + coeffJ * j;
- }
- private final double coeffI;
- private final double coeffJ;
- }
-
- private static class IdentityPattern implements ElementPattern {
- public double value(int i, int j) {
- return (i == j) ? 1.0 : 0.0;
- }
- }
-
- public GeneralSquareMatrix buildMatrix(int order,
- ElementPattern pattern) {
- GeneralSquareMatrix m = new GeneralSquareMatrix(order);
-
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j){
- m.setElement(i, j, pattern.value(i, j));
- }
- }
-
- return m;
-
- }
-
- public void checkMatrix(Matrix m, ElementPattern pattern) {
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j) {
- assertTrue(Math.abs(m.getElement(i, j) - pattern.value(i, j))
- < 1.0e-10);
- }
- }
- }
-
- private static class LinearProblem {
- public GeneralSquareMatrix a;
- public Matrix x;
- public Matrix b;
- public LinearProblem(GeneralSquareMatrix a, Matrix x, Matrix b) {
- this.a = a;
- this.x = x;
- this.b = b;
- }
- }
-
- private LinearProblem buildProblem1() {
-
- GeneralSquareMatrix a = new GeneralSquareMatrix(4);
-
- a.setElement(0, 0, 2.0);
- a.setElement(0, 1, 1.0);
- a.setElement(0, 2, 0.0);
- a.setElement(0, 3, 4.0);
-
- a.setElement(1, 0, -4.0);
- a.setElement(1, 1, -2.0);
- a.setElement(1, 2, 3.0);
- a.setElement(1, 3, -7.0);
-
- a.setElement(2, 0, 4.0);
- a.setElement(2, 1, 1.0);
- a.setElement(2, 2, -2.0);
- a.setElement(2, 3, 8.0);
-
- a.setElement(3, 0, 0.0);
- a.setElement(3, 1, -3.0);
- a.setElement(3, 2, -12.0);
- a.setElement(3, 3, -1.0);
-
- GeneralMatrix x = new GeneralMatrix(4, 1);
-
- x.setElement(0, 0, 3.0);
- x.setElement(1, 0, 4.0);
- x.setElement(2, 0, -1.0);
- x.setElement(3, 0, -2.0);
-
- GeneralMatrix b = new GeneralMatrix(4, 1);
-
- b.setElement(0, 0, 2.0);
- b.setElement(1, 0, -9.0);
- b.setElement(2, 0, 2.0);
- b.setElement(3, 0, 2.0);
-
- return new LinearProblem(a, x, b);
-
- }
-
- private LinearProblem buildProblem2()
- {
-
- double epsilon = 1.0e-7;
-
- GeneralSquareMatrix a = new GeneralSquareMatrix(2);
-
- a.setElement(0, 0, epsilon);
- a.setElement(0, 1, 1.0);
-
- a.setElement(1, 0, 1.0);
- a.setElement(1, 1, 1.0);
-
- GeneralMatrix x = new GeneralMatrix(2, 2);
-
- x.setElement(0, 0, 1.0 + epsilon);
- x.setElement(1, 0, 1.0 - epsilon);
-
- x.setElement(0, 1, epsilon);
- x.setElement(1, 1, 1.0);
-
- GeneralMatrix b = new GeneralMatrix(2, 2);
-
- b.setElement(0, 0, 1.0 + epsilon * epsilon);
- b.setElement(1, 0, 2.0);
-
- b.setElement(0, 1, 1.0 + epsilon * epsilon);
- b.setElement(1, 1, 1.0 + epsilon);
-
- return new LinearProblem(a, x, b);
-
- }
-
- private LinearProblem buildProblem3 ()
- {
-
- GeneralSquareMatrix a = new GeneralSquareMatrix(3);
-
- a.setElement(0, 0, 1.0);
- a.setElement(0, 1, 2.0);
- a.setElement(0, 1, -3.0);
-
- a.setElement(1, 0, 2.0);
- a.setElement(1, 1, 1.0);
- a.setElement(1, 1, 3.0);
-
- a.setElement(2, 0, -3.0);
- a.setElement(2, 1, 0.0);
- a.setElement(2, 1, -9.0);
-
- GeneralMatrix x = new GeneralMatrix(3, 1);
- GeneralMatrix b = new GeneralMatrix(3, 1);
-
- return new LinearProblem(a, x, b);
-
- }
-
- private void checkSolve(LinearProblem p, Matrix result)
- {
-
- Matrix residual = p.a.mul(result).sub(p.b);
- for (int i = 0; i < residual.getRows(); ++i) {
- for (int j = 0; j < residual.getColumns(); ++j) {
- assertTrue(Math.abs(residual.getElement(i, j)) < 1.0e-10);
- }
- }
-
- for (int i = 0; i < result.getRows(); ++i) {
- for (int j = 0; j < result.getColumns(); ++j) {
- assertTrue(Math.abs(result.getElement(i, j) - p.x.getElement(i, j))
- < 1.0e-10);
- }
- }
-
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java
deleted file mode 100644
index a78941b..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class LowerTriangularMatrixTest
- extends TestCase {
-
- public LowerTriangularMatrixTest(String name) {
- super(name);
- }
-
- public void testNoSetOutsideOfLowerTriangle() {
-
- LowerTriangularMatrix l = new LowerTriangularMatrix(4);
-
- for (int i = 0; i < l.getRows(); ++i) {
- for (int j = 0; j < l.getColumns(); ++j) {
-
- if (i >= j) {
- l.setElement(i, j, i + 0.1 * j);
- } else {
- boolean gotIt = false;
- try {
- l.setElement(i, j, -1.3);
- } catch(ArrayIndexOutOfBoundsException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
- }
- }
-
- checkMatrix(l, new BilinearPattern(1.0, 0.1));
-
- }
-
- public void testCopy() {
-
- LowerTriangularMatrix l1 = buildMatrix(4, new BilinearPattern(1.0, 0.01));
-
- LowerTriangularMatrix l2 = new LowerTriangularMatrix (l1);
-
- checkMatrix (l2, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testDuplicate() {
-
- LowerTriangularMatrix l1 = buildMatrix(4, new BilinearPattern(1.0, 0.01));
-
- Matrix l2 = l1.duplicate();
- assertTrue(l2 instanceof LowerTriangularMatrix);
-
- checkMatrix(l2, new BilinearPattern(1.0, 0.01));
-
- }
-
- public void testTranspose() {
-
- LowerTriangularMatrix l = buildMatrix(7, new BilinearPattern(1.0, 0.1));
-
- Matrix transposed = l.getTranspose();
- assertTrue(transposed instanceof UpperTriangularMatrix);
-
- for (int i = 0; i < transposed.getRows(); ++i){
- for (int j = 0; j < transposed.getColumns(); ++j) {
- double expected = (i > j) ? 0.0 : (j + 0.1 * i);
- assertTrue(Math.abs(transposed.getElement(i, j) - expected) < 1.0e-10);
- }
- }
-
- }
-
- public void testSelfAdd() {
- LowerTriangularMatrix l1 = buildMatrix(7, new BilinearPattern(3, -0.2));
-
- LowerTriangularMatrix l2 = buildMatrix(7, new BilinearPattern(2, -0.4));
-
- l1.selfAdd(l2);
-
- checkMatrix(l1, new BilinearPattern(5, -0.6));
- }
-
- public void testSelfSub() {
- LowerTriangularMatrix l1 = buildMatrix(7, new BilinearPattern(3, -0.2));
-
- LowerTriangularMatrix l2 = buildMatrix(7, new BilinearPattern(2, -0.4));
-
- l1.selfSub(l2);
-
- checkMatrix(l1, new BilinearPattern(1, 0.2));
- }
-
- public void testDeterminant() {
-
- LowerTriangularMatrix l = buildMatrix(4, new ElementPattern() {
- public double value(int i, int j) {
- return (i == j) ? 2.0 : 1.0;
- }
- });
-
- assertTrue(Math.abs(l.getDeterminant(1.0e-10) - Math.pow(2.0, l.getRows()))
- < 1.0e-10);
-
- }
-
- public void testSolve()
- throws SingularMatrixException {
-
- LowerTriangularMatrix l = buildMatrix(7, new ElementPattern() {
- public double value(int i, int j) {
- return 1.0;
- }
- });
-
- GeneralMatrix b = new GeneralMatrix(l.getRows(), 3);
- for (int i = 0; i < b.getRows(); ++i) {
- b.setElement(i, 0, i + 1.0);
- b.setElement(i, 1, (i + 1.0) * (i + 2.0) / 2.0);
- b.setElement(i, 2, 0.0);
- }
-
- Matrix result = l.solve(b, 1.0e-10);
-
- assertTrue(result.getRows() == b.getRows());
- assertTrue(result.getColumns() == b.getColumns());
-
- for (int i = 0; i < result.getRows(); ++i) {
- assertTrue(Math.abs(result.getElement(i, 0) - 1.0) < 1.0e-10);
- assertTrue(Math.abs(result.getElement(i, 1) - (i + 1.0)) < 1.0e-10);
- assertTrue(Math.abs(result.getElement(i, 2) - 0.0) < 1.0e-10);
- }
-
- boolean gotIt = false;
- try {
- l.setElement(3, 3, 0.0);
- l.solve(b, 1.0e-10);
- } catch(SingularMatrixException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testInverse()
- throws SingularMatrixException {
-
- LowerTriangularMatrix l = buildMatrix(5, new ElementPattern() {
- public double value(int i, int j) {
- return 1.0;
- }
- });
-
- Matrix inverse = l.getInverse(1.0e-10);
- assertTrue(inverse instanceof LowerTriangularMatrix);
-
- checkMatrix(inverse, new ElementPattern() {
- public double value(int i, int j) {
- return (i == j) ? 1.0 : ((i == j + 1) ? -1.0 : 0.0);
- }
- });
-
- }
-
- public static Test suite() {
- return new TestSuite(LowerTriangularMatrixTest.class);
- }
-
- public interface ElementPattern {
- public double value(int i, int j);
- }
-
- private static class BilinearPattern implements ElementPattern {
- public BilinearPattern(double coeffI, double coeffJ) {
- this.coeffI = coeffI;
- this.coeffJ = coeffJ;
- }
- public double value(int i, int j) {
- return coeffI * i + coeffJ * j;
- }
- private final double coeffI;
- private final double coeffJ;
- }
-
- public LowerTriangularMatrix buildMatrix(int order,
- ElementPattern pattern) {
- LowerTriangularMatrix m = new LowerTriangularMatrix(order);
-
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j <= i; ++j) {
- m.setElement(i, j, pattern.value(i, j));
- }
- }
-
- return m;
-
- }
-
- public void checkMatrix(Matrix m, ElementPattern pattern) {
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j) {
- double expected = (j <= i) ? pattern.value(i, j) : 0.0;
- assertTrue(Math.abs(m.getElement(i, j) - expected) < 1.0e-10);
- }
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java
deleted file mode 100644
index f491fb3..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class MatrixFactoryTest
- extends TestCase {
-
- public MatrixFactoryTest(String name) {
- super(name);
- }
-
- public void testInvalidDimensions() {
- boolean gotIt;
-
- gotIt = false;
- try {
- MatrixFactory.buildMatrix(0, 2, null, 1, 1);
- } catch (IllegalArgumentException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testDiagonal() {
- Matrix m = MatrixFactory.buildMatrix(3, 3, null, 0, 0);
- assertTrue(m instanceof DiagonalMatrix);
- }
-
- public void testLowerTriangular() {
- Matrix m = MatrixFactory.buildMatrix(3, 3, null, 1, 0);
- assertTrue(m instanceof LowerTriangularMatrix);
- }
-
- public void testUpperTriangular() {
- Matrix m = MatrixFactory.buildMatrix(3, 3, null, 0, 1);
- assertTrue(m instanceof UpperTriangularMatrix);
- }
-
- public void testSquare() {
- Matrix m = MatrixFactory.buildMatrix(3, 3, null, 1, 1);
- assertTrue(m instanceof GeneralSquareMatrix);
- }
-
- public void testGeneral() {
- Matrix m = MatrixFactory.buildMatrix(3, 4, null, 0, 0);
- assertTrue(m instanceof GeneralMatrix);
- }
-
- public static Test suite() {
- return new TestSuite(MatrixFactoryTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java
deleted file mode 100644
index edd136e..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class NonNullRangeTest
- extends TestCase {
-
- public NonNullRangeTest(String name) {
- super(name);
- }
-
- public void testPublicAttributes() {
- NonNullRange r = new NonNullRange(2, 7);
- assertTrue(r.begin == 2);
- assertTrue(r.end == 7);
- }
-
- public void testCopy() {
- NonNullRange r1 = new NonNullRange(2, 7);
- NonNullRange r2 = new NonNullRange(r1);
- assertTrue(r2.begin == r1.begin);
- assertTrue(r1.end == r1.end);
- }
-
- public void testIntersection() {
- NonNullRange r1 = new NonNullRange(-4, 8);
- NonNullRange r2 = new NonNullRange(3, 12);
- NonNullRange r3 = NonNullRange.intersection(r1, r2);
- assertTrue(r3.begin == 3);
- assertTrue(r3.end == 8);
- }
-
- public void testReunion() {
- NonNullRange r1 = new NonNullRange(-4, 8);
- NonNullRange r2 = new NonNullRange(3, 12);
- NonNullRange r3 = NonNullRange.reunion(r1, r2);
- assertTrue(r3.begin == -4);
- assertTrue(r3.end == 12);
- }
-
- public static Test suite() {
- return new TestSuite(NonNullRangeTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java
deleted file mode 100644
index 9c306bd..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java
+++ /dev/null
@@ -1,272 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class SymetricalMatrixTest
- extends TestCase {
-
- public SymetricalMatrixTest(String name) {
- super(name);
- }
-
- public void testBuildWAAt() {
-
- double[] a = { 1.0, 2.0, 3.0 };
- SymetricalMatrix s = new SymetricalMatrix(0.99, a);
-
- checkMatrix(s, new ElementPattern() {
- public double value(int i, int j) {
- return 0.99 * (i + 1) * (j + 1);
- }
- });
-
- }
-
- public void testNoSetOutsideOfDiagonal() {
-
- SymetricalMatrix s = new SymetricalMatrix(4);
-
- for (int i = 0; i < s.getRows(); ++i) {
- for (int j = 0; j < s.getColumns(); ++j) {
- if (i == j) {
- s.setElement(i, j, 0.5);
- } else {
- boolean gotIt = false;
- try {
- s.setElement
- (i, j, -1.3);
- } catch(ArrayIndexOutOfBoundsException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
- }
- }
-
- checkMatrix(s, new ElementPattern() {
- public double value(int i, int j) {
- return (i == j) ? 0.5 : 0.0;
- }
- });
-
- }
-
- public void testSetElementAndSymetricalElement() {
- SymetricalMatrix s = new SymetricalMatrix(5);
- s.setElementAndSymetricalElement(1, 2, 3.4);
- assertTrue(Math.abs(s.getElement(1, 2) - 3.4) < 1.0e-10);
- assertTrue(Math.abs(s.getElement(2, 1) - 3.4) < 1.0e-10);
- }
-
- public void testCopy() {
- SymetricalMatrix m1 = buildMatrix(5, new ElementPattern() {
- public double value(int i, int j) {
- return i * i + j * j;
- }
- });
-
- SymetricalMatrix m2 = new SymetricalMatrix(m1);
-
- for (int i = 0; i < m1.getRows(); ++i) {
- for (int j = i; j < m1.getColumns(); ++j) {
- m1.setElementAndSymetricalElement(i, j, -1.0);
- }
- }
-
- assertTrue(m2.getRows() == m1.getRows());
- assertTrue(m2.getColumns() == m1.getColumns());
-
- checkMatrix(m2, new ElementPattern() {
- public double value(int i, int j) {
- return i * i + j * j;
- }
- });
-
- }
-
- public void testDuplicate() {
- SymetricalMatrix m1 = buildMatrix(5, new ElementPattern() {
- public double value(int i, int j) {
- return i * j;
- }
- });
-
- Matrix m2 = m1.duplicate();
- assertTrue(m2 instanceof SymetricalMatrix);
-
- for (int i = 0; i < m1.getRows(); ++i) {
- for (int j = i; j < m1.getColumns(); ++j) {
- m1.setElementAndSymetricalElement(i, j, -1.0);
- }
- }
-
- assertTrue(m2.getRows() == m1.getRows());
- assertTrue(m2.getColumns() == m1.getColumns());
-
- checkMatrix(m2, new ElementPattern() {
- public double value(int i, int j) {
- return i * j;
- }
- });
-
- }
-
- public void testSelfAdd() {
- double[] a1 = { 2.0, 4.0, 8.0, 16.0 };
- SymetricalMatrix s1 = new SymetricalMatrix(0.5, a1);
-
- double[] a2 = { 3.0, 9.0, 27.0, 81.0 };
- SymetricalMatrix s2 = new SymetricalMatrix(1.0, a2);
-
- s1.selfAdd(s2);
-
- checkMatrix(s1, new ElementPattern() {
- public double value(int i, int j) {
- return 0.5 * Math.pow(2.0, i + 1) * Math.pow(2.0, j + 1)
- + Math.pow(3.0, i + 1) * Math.pow(3.0, j + 1);
- }
- });
- }
-
- public void testSelfSub() {
- double[] a1 = { 2.0, 4.0, 8.0, 16.0 };
- SymetricalMatrix s1 = new SymetricalMatrix(0.5, a1);
-
- double[] a2 = { 3.0, 9.0, 27.0, 81.0 };
- SymetricalMatrix s2 = new SymetricalMatrix(1.0, a2);
-
- s1.selfSub(s2);
-
- checkMatrix(s1, new ElementPattern() {
- public double value(int i, int j) {
- return 0.5 * Math.pow(2.0, i + 1) * Math.pow(2.0, j + 1)
- - Math.pow(3.0, i + 1) * Math.pow(3.0, j + 1);
- }
- });
- }
-
- public void testSelfAddWAAt() {
-
- SymetricalMatrix s = new SymetricalMatrix(3);
-
- double[] a1 = { 1.0, 2.0, 3.0 };
- s.selfAddWAAt(1.0, a1);
-
- double[] a2 = { 0.1, 0.2, 0.3 };
- s.selfAddWAAt(2.0, a2);
-
- checkMatrix(s, new ElementPattern() {
- public double value(int i, int j) {
- return 1.02 * (i + 1) * (j + 1);
- }
- });
-
- }
-
- public void testSingular()
- throws SingularMatrixException {
- SymetricalMatrix s = new SymetricalMatrix(3);
-
- double[] a1 = { 1.0, 2.0, 3.0 };
- s.selfAddWAAt(1.0, a1);
-
- double[] a2 = { 0.1, 0.2, 0.3 };
- s.selfAddWAAt(2.0, a2);
-
- Matrix b = new GeneralMatrix(3, 1);
- b.setElement(0, 0, 6.12);
- b.setElement(1, 0, 12.24);
- b.setElement(2, 0, 18.36);
-
- boolean gotIt = false;
- try {
- s.solve(b, 1.0e-10);
- } catch(SingularMatrixException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testSolve()
- throws SingularMatrixException {
- SymetricalMatrix s = new SymetricalMatrix(3);
-
- double[] a1 = { 1.0, 2.0, 3.0 };
- s.selfAddWAAt(1.0, a1);
-
- double[] a2 = { 0.1, 0.2, 0.3 };
- s.selfAddWAAt(2.0, a2);
-
- double[] a3 = { 1.2, -3.0, 2.1 };
- s.selfAddWAAt(3.0, a3);
-
- double[] a4 = { 0.4, 0.1, 3.1 };
- s.selfAddWAAt(2.0, a4);
-
- Matrix b = new GeneralMatrix(3, 1);
- b.setElement(0, 0, 10.08);
- b.setElement(1, 0, 10.26);
- b.setElement(2, 0, 42.57);
-
- Matrix x = s.solve(b, 1.0e-10);
-
- checkMatrix (x, new ElementPattern() {
- public double value(int i, int j) {
- return 1.0;
- }
- });
-
- assertTrue(Math.abs(s.getDeterminant(1.0e-10) - 782.846532) < 1.0e-10);
-
- }
-
- public static Test suite() {
- return new TestSuite(SymetricalMatrixTest.class);
- }
-
- public interface ElementPattern {
- public double value(int i, int j);
- }
-
- public SymetricalMatrix buildMatrix(int order,
- ElementPattern pattern) {
- SymetricalMatrix m = new SymetricalMatrix(order);
-
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = i; j < m.getColumns(); ++j) {
- m.setElementAndSymetricalElement(i, j, pattern.value(i, j));
- }
- }
-
- return m;
-
- }
-
- public void checkMatrix(Matrix m, ElementPattern pattern) {
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j) {
- assertTrue(Math.abs(m.getElement(i, j) - pattern.value(i, j))
- < 1.0e-10);
- }
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java
deleted file mode 100644
index b72b5da..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.linalg;
-
-import junit.framework.*;
-
-public class UpperTriangularMatrixTest
- extends TestCase {
-
- public UpperTriangularMatrixTest(String name) {
- super(name);
- }
-
- public void testNoSetOutsideOfUpperTriangle() {
-
- UpperTriangularMatrix u = new UpperTriangularMatrix(4);
-
- for (int i = 0; i < u.getRows(); ++i) {
- for (int j = 0; j < u.getColumns(); ++j) {
- if (i <= j) {
- u.setElement(i, j, i + 0.1 * j);
- } else {
- boolean gotIt = false;
- try {
- u.setElement(i, j, -1.3);
- } catch(ArrayIndexOutOfBoundsException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
- }
- }
- }
-
- checkMatrix(u, new BilinearPattern(1.0, 0.1));
-
- }
-
- public void testCopy() {
-
- UpperTriangularMatrix u1 = buildMatrix(4, new BilinearPattern(1.0, 0.1));
-
- UpperTriangularMatrix u2 = new UpperTriangularMatrix(u1);
-
- checkMatrix(u2, new BilinearPattern(1.0, 0.1));
-
- }
-
- public void testDuplicate() {
-
- UpperTriangularMatrix u1 = buildMatrix(4, new BilinearPattern(1.0, 0.1));
-
- Matrix u2 = u1.duplicate();
- assertTrue(u2 instanceof UpperTriangularMatrix);
-
- checkMatrix(u2, new BilinearPattern(1.0, 0.1));
-
- }
-
- public void testTranspose() {
-
- UpperTriangularMatrix u = buildMatrix(7, new BilinearPattern(1.0, 0.1));
-
- Matrix transposed = u.getTranspose();
- assertTrue(transposed instanceof LowerTriangularMatrix);
-
- for (int i = 0; i < transposed.getRows(); ++i){
- for (int j = 0; j < transposed.getColumns(); ++j) {
- double expected = (i < j) ? 0.0 : (j + 0.1 * i);
- assertTrue(Math.abs(transposed.getElement(i, j) - expected) < 1.0e-10);
- }
- }
-
- }
-
- public void testSelfAdd() {
- UpperTriangularMatrix u1 = buildMatrix(7, new BilinearPattern(3, -0.2));
-
- UpperTriangularMatrix u2 = buildMatrix(7, new BilinearPattern(2, -0.4));
-
- u1.selfAdd(u2);
-
- checkMatrix(u1, new BilinearPattern(5, -0.6));
- }
-
- public void testSelfSub() {
- UpperTriangularMatrix u1 = buildMatrix(7, new BilinearPattern(3, -0.2));
-
- UpperTriangularMatrix u2 = buildMatrix(7, new BilinearPattern(2, -0.4));
-
- u1.selfSub(u2);
-
- checkMatrix(u1, new BilinearPattern(1, 0.2));
- }
-
- public void testDeterminant() {
-
- UpperTriangularMatrix u = buildMatrix(4, new ElementPattern() {
- public double value(int i, int j) {
- return (i == j) ? 2.0 : 1.0;
- }
- });
-
- assertTrue(Math.abs(u.getDeterminant(1.0e-10) - Math.pow(2.0, u.getRows()))
- < 1.0e-10);
-
- }
-
- public void testSolve()
- throws SingularMatrixException {
-
- int rows = 7;
- UpperTriangularMatrix u = buildMatrix(rows, new ElementPattern() {
- public double value(int i, int j) {
- return 1.0;
- }
- });
-
- GeneralMatrix b = new GeneralMatrix(rows, 3);
- for (int i = 0; i < rows; ++i) {
- b.setElement(i, 0, rows - i);
- b.setElement(i, 1, (rows - i) * (rows + 1 - i) / 2.0);
- b.setElement(i, 2, 0.0);
- }
-
- Matrix result = u.solve(b, 1.0e-10);
-
- assertTrue(result.getRows() == b.getRows());
- assertTrue(result.getColumns() == b.getColumns());
-
- for (int i = 0; i < result.getRows(); ++i) {
- assertTrue(Math.abs(result.getElement(i, 0) - 1.0) < 1.0e-10);
- assertTrue(Math.abs(result.getElement(i, 1) - (rows - i)) < 1.0e-10);
- assertTrue(Math.abs(result.getElement(i, 2) - 0.0) < 1.0e-10);
- }
-
- boolean gotIt = false;
- try {
- u.setElement(3, 3, 0.0);
- u.solve(b, 1.0e-10);
- } catch(SingularMatrixException e) {
- gotIt = true;
- }
- assertTrue(gotIt);
-
- }
-
- public void testInverse()
- throws SingularMatrixException {
-
- UpperTriangularMatrix u = buildMatrix(5, new ElementPattern() {
- public double value(int i, int j) {
- return 1.0;
- }
- });
-
- Matrix inverse = u.getInverse(1.0e-10);
- assertTrue(inverse instanceof UpperTriangularMatrix);
-
- checkMatrix(inverse, new ElementPattern() {
- public double value(int i, int j) {
- return (i == j) ? 1.0 : ((i == j - 1) ? -1.0 : 0.0);
- }
- });
-
- }
-
- public static Test suite() {
- return new TestSuite(UpperTriangularMatrixTest.class);
- }
-
- public interface ElementPattern {
- public double value(int i, int j);
- }
-
- private static class BilinearPattern implements ElementPattern {
- public BilinearPattern(double coeffI, double coeffJ) {
- this.coeffI = coeffI;
- this.coeffJ = coeffJ;
- }
- public double value(int i, int j) {
- return coeffI * i + coeffJ * j;
- }
- private final double coeffI;
- private final double coeffJ;
- }
-
- public UpperTriangularMatrix buildMatrix(int order,
- ElementPattern pattern) {
- UpperTriangularMatrix m = new UpperTriangularMatrix (order);
-
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = i; j < m.getColumns(); ++j) {
- m.setElement(i, j, pattern.value(i, j));
- }
- }
-
- return m;
-
- }
-
- public void checkMatrix(Matrix m, ElementPattern pattern) {
- for (int i = 0; i < m.getRows(); ++i) {
- for (int j = 0; j < m.getColumns(); ++j) {
- double expected = (i <= j) ? pattern.value(i, j) : 0.0;
- assertTrue(Math.abs(m.getElement(i, j) - expected) < 1.0e-10);
- }
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/AllTests.java
deleted file mode 100644
index 8d287d3..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/AllTests.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests
-{
- public static Test suite ()
- {
- TestSuite suite= new TestSuite ("org.spaceroots.mantissa.quadrature");
- suite.addTest (org.spaceroots.mantissa.quadrature.scalar.AllTests.suite ());
- suite.addTest (org.spaceroots.mantissa.quadrature.vectorial.AllTests.suite ());
- return suite;
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/scalar/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/scalar/AllTests.java
deleted file mode 100644
index 8c71682..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/scalar/AllTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.scalar;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.quadrature.scalar");
-
- suite.addTest(GaussLegendreIntegratorTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java
deleted file mode 100644
index 8bc3ab1..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.quadrature.vectorial");
-
- suite.addTest(GaussLegendreIntegratorTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java
deleted file mode 100644
index da600bd..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.quadrature.vectorial;
-
-import org.spaceroots.mantissa.functions.vectorial.ComputableFunction;
-import org.spaceroots.mantissa.functions.FunctionException;
-
-import java.util.Random;
-
-import junit.framework.*;
-
-public class GaussLegendreIntegratorTest
- extends TestCase {
-
- public GaussLegendreIntegratorTest(String name) {
- super(name);
- }
-
- public void testExactIntegration()
- throws FunctionException {
- Random random = new Random(86343623467878363l);
- int order = 0;
- while (true) {
- GaussLegendreIntegrator integrator = new GaussLegendreIntegrator(order,
- 7.0);
- int availableOrder = integrator.getEvaluationsPerStep();
- if (availableOrder < order) {
- // we have tested all available orders
- return;
- }
-
- // an order n Gauss-Legendre integrator integrates
- // 2n-1 degree polynoms exactly
- for (int degree = 0; degree <= 2 * availableOrder - 1; ++degree) {
- for (int i = 0; i < 10; ++i) {
- Polynom p = new Polynom(degree, random, 100.0);
- double[] s0 = integrator.integrate(p, -5.0, 15.0);
- double[] s1 = p.exactIntegration(-5.0, 15.0);
- for (int j = 0; j < p.getDimension(); ++j) {
- assertTrue(Math.abs(s0[j] - s1[j]) < 1.0e-12 * (1.0 + Math.abs(s0[j])));
- }
- }
- }
-
- ++order;
-
- }
- }
-
- public static Test suite() {
- return new TestSuite(GaussLegendreIntegratorTest.class);
- }
-
- private static class Polynom implements ComputableFunction {
- public Polynom (int degree, Random random, double max) {
- coeffs0 = new double[degree + 1];
- coeffs1 = new double[degree + 1];
- for (int i = 0; i <= degree; ++i) {
- coeffs0[i] = 2.0 * max * (random.nextDouble() - 0.5);
- coeffs1[i] = 2.0 * max * (random.nextDouble() - 0.5);
- }
- }
-
- public int getDimension() {
- return 2;
- }
-
- public double[] valueAt(double t)
- throws FunctionException {
- double[] y = new double[2];
- y[0] = coeffs0[coeffs0.length - 1];
- for (int i = coeffs0.length - 2; i >= 0; --i) {
- y[0] = y[0] * t + coeffs0[i];
- }
- y[1] = coeffs1 [coeffs1.length - 1];
- for (int i = coeffs1.length - 2; i >= 0; --i) {
- y[1] = y[1] * t + coeffs1[i];
- }
- return y;
- }
-
- public double[] exactIntegration(double a, double b)
- throws FunctionException {
- double[] res = new double[2];
- double yb = coeffs0[coeffs0.length - 1] / coeffs0.length;
- double ya = yb;
- for (int i = coeffs0.length - 2; i >= 0; --i) {
- yb = yb * b + coeffs0[i] / (i + 1);
- ya = ya * a + coeffs0[i] / (i + 1);
- }
- res[0] = yb * b - ya * a;
- yb = coeffs1[coeffs1.length - 1] / coeffs1.length;
- ya = yb;
- for (int i = coeffs1.length - 2; i >= 0; --i) {
- yb = yb * b + coeffs1[i] / (i + 1);
- ya = ya * a + coeffs1[i] / (i + 1);
- }
- res[1] = yb * b - ya * a;
- return res;
- }
-
- private double[] coeffs0;
- private double[] coeffs1;
-
- private static final long serialVersionUID = -8032020368915042278L;
-
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java
deleted file mode 100644
index 8ede25c..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.random;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.random");
-
- suite.addTest(ScalarSampleStatisticsTest.suite());
- suite.addTest(VectorialSampleStatisticsTest.suite());
- suite.addTest(UniformRandomGeneratorTest.suite());
- suite.addTest(GaussianRandomGeneratorTest.suite());
- suite.addTest(UncorrelatedRandomVectorGeneratorTest.suite());
- suite.addTest(CorrelatedRandomVectorGeneratorTest.suite());
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java
deleted file mode 100644
index f33a345..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.random;
-
-import junit.framework.*;
-
-public class ScalarSampleStatisticsTest
- extends TestCase {
-
- public ScalarSampleStatisticsTest(String name) {
- super(name);
- points = null;
- }
-
- public void testBasicStats() {
-
- ScalarSampleStatistics sample = new ScalarSampleStatistics();
- for (int i = 0; i < points.length; ++i) {
- sample.add(points[i]);
- }
-
- assertEquals(points.length, sample.size());
- assertEquals(-5.0, sample.getMin(), 1.0e-12);
- assertEquals(10.4, sample.getMax(), 1.0e-12);
- assertEquals( 3.0, sample.getMean(), 1.0e-12);
- assertEquals( 3.920034013457876, sample.getStandardDeviation(),
- 1.0e-12);
-
- }
-
- public void testAddSample() {
-
- ScalarSampleStatistics all = new ScalarSampleStatistics();
- ScalarSampleStatistics even = new ScalarSampleStatistics();
- ScalarSampleStatistics odd = new ScalarSampleStatistics();
- for (int i = 0; i < points.length; ++i) {
- all.add(points[i]);
- if (i % 2 == 0) {
- even.add(points[i]);
- } else {
- odd.add(points[i]);
- }
- }
-
- even.add(odd);
-
- assertEquals(all.size(), even.size());
- assertEquals(all.getMin(), even.getMin(), 1.0e-12);
- assertEquals(all.getMax(), even.getMax(), 1.0e-12);
- assertEquals(all.getMean(), even.getMean(), 1.0e-12);
- assertEquals(all.getStandardDeviation(), even.getStandardDeviation(),
- 1.0e-12);
-
- }
-
- public void testAddArray() {
-
- ScalarSampleStatistics loop = new ScalarSampleStatistics();
- ScalarSampleStatistics direct = new ScalarSampleStatistics();
- for (int i = 0; i < points.length; ++i) {
- loop.add(points[i]);
- }
- direct.add(points);
-
- assertEquals(loop.size(), direct.size());
- assertEquals(loop.getMin(), direct.getMin(), 1.0e-12);
- assertEquals(loop.getMax(), direct.getMax(), 1.0e-12);
- assertEquals(loop.getMean(), direct.getMean(), 1.0e-12);
- assertEquals(loop.getStandardDeviation(), direct.getStandardDeviation(),
- 1.0e-12);
-
- }
-
- public void setUp() {
- points = new double[] {1.0, 4.2, -5, 4.0, 2.9, 10.4, 0.0, 4.1, 4.2, 4.2};
- }
-
- public void tearDown() {
- points = null;
- }
-
- public static Test suite() {
- return new TestSuite(ScalarSampleStatisticsTest.class);
- }
-
- private double[] points;
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java
deleted file mode 100644
index e5e7654..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.roots;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.roots");
-
- suite.addTest(BrentSolverTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java
deleted file mode 100644
index 7aa0bd2..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.roots;
-
-import org.spaceroots.mantissa.functions.FunctionException;
-
-import junit.framework.*;
-
-public class BrentSolverTest
- extends TestCase {
-
- public BrentSolverTest(String name) {
- super(name);
- }
-
- public void testAlefeldPotraShi()
- throws FunctionException {
-
- TestProblem[] problems = TestProblem.getAPSProblems();
- BrentSolver solver = new BrentSolver();
-
- for (int i = 0; i < problems.length; ++i) {
- TestProblem p = problems[i];
- double tol = 1.0e-10 * Math.abs(p.getExpectedRoot());
- assertTrue(solver.findRoot(p, new Checker(tol), 1000,
- p.getA(), p.valueAt(p.getA()),
- p.getB(), p.valueAt(p.getB())));
- assertTrue(p.checkResult(solver.getRoot(), tol));
- }
-
- }
-
- private static class Checker implements ConvergenceChecker {
-
- private double tolerance;
-
- public Checker (double tolerance) {
- this.tolerance = tolerance;
- }
-
- public int converged (double xLow, double fLow,
- double xHigh, double fHigh) {
- return (Math.abs(xHigh - xLow) <= tolerance)
- ? ((Math.abs(fLow) <= Math.abs(fHigh))
- ? ConvergenceChecker.LOW
- : ConvergenceChecker.HIGH)
- : ConvergenceChecker.NONE;
- }
-
- }
-
- public static Test suite() {
- return new TestSuite(BrentSolverTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java b/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java
deleted file mode 100644
index 25e0c56..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java
+++ /dev/null
@@ -1,433 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.roots;
-
-import org.spaceroots.mantissa.functions.scalar.ComputableFunction;
-
-import java.util.ArrayList;
-
-/** This class implement a reference problem for junit tests. */
-public abstract class TestProblem implements ComputableFunction {
-
- private double a;
- private double b;
- private double expectedRoot;
-
- protected TestProblem(double a, double b, double expectedRoot) {
- this.a = a;
- this.b = b;
- this.expectedRoot = expectedRoot;
- }
-
- public double getA() {
- return a;
- }
-
- public double getB() {
- return b;
- }
-
- public double getExpectedRoot() {
- return expectedRoot;
- }
-
- public boolean checkResult(double foundRoot, double tol) {
- return Math.abs(foundRoot - expectedRoot) <= tol;
- }
-
- /** Get the reference problems from G. E. Alefeld, F. A. Potra and Y. Shi. */
- public static TestProblem[] getAPSProblems() {
-
- ArrayList problems = new ArrayList();
-
- // problem 1
- problems.add(new APSProblem1(Math.PI / 2, Math.PI, 1.8954942670340));
-
- // problems 2 to 11
- double[] roots2To11 = {
- 3.0229153472731, 6.6837535608081, 11.238701655002, 19.676000080623,
- 29.828227326505, 41.906116195289, 55.953595800143, 71.985665586588,
- 90.008868539167, 110.02653274833
- };
- for (int k = 0, n = 1; n <= 10; ++n) {
- problems.add(new APSProblems2To11(1.0e-9 + n * n,
- (n+1) * (n+1) - 1.0e-9,
- roots2To11[k++]));
- }
-
- // problems 12 to 14
- problems.add(new APSProblems12To14( -40, -9.0, 31.0, 0.0));
- problems.add(new APSProblems12To14(-100, -9.0, 31.0, 0.0));
- problems.add(new APSProblems12To14(-200, -9.0, 31.0, 0.0));
-
- // problems 15 to 17
- int[] n15 = { 4, 6, 8, 10, 12 };
- double[] roots15 = {
- 0.66874030497642, 0.76472449133173, 0.81776543395794,
- 0.85133992252078, 0.87448527222117
- };
- for (int k = 0; k < n15.length; ++k) {
- problems.add(new APSProblems15To17(n15[k], 0.2, 0.0, 5.0, roots15[k]));
- }
-
- int[] n16 = { 4, 6, 8, 10, 12 };
- for (int k = 0; k < n16.length; ++k) {
- problems.add(new APSProblems15To17(n16[k], 1.0, 0.0, 5.0, 1.0));
- }
-
- int[] n17 = { 8, 10, 12, 14 };
- for (int k = 0; k < n17.length; ++k) {
- problems.add(new APSProblems15To17(n17[k], 1.0, -0.95, 4.05, 1.0));
- }
-
- // problem 18
- problems.add(new APSProblem18(0.0, 1.5, 0.52359877559830));
-
- // problem 19
- int[] n19 = { 1, 2, 3, 4, 5, 20, 40, 60, 80, 100 };
- double[] roots19 = {
- 0.42247770964124, 0.30669941048320, 0.22370545765466,
- 0.17171914751951, 0.13825715505682, 3.4657359020854e-2,
- 1.7328679513999e-2, 1.1552453009332e-2, 8.6643397569993e-3,
- 6.9314718055995e-3
- };
- for (int k = 0; k < n19.length; ++k) {
- problems.add(new APSProblem19(n19[k], 0.0, 1.0, roots19[k]));
- }
-
- // problem 20
- int[] n20 = { 5, 10, 20 };
- double[] roots20 = {
- 3.8402551840622e-2, 9.9000099980005e-3, 2.4937500390620e-3
- };
- for (int k = 0; k < n20.length; ++k) {
- problems.add(new APSProblem20(n20[k], 0.0, 1.0, roots20[k]));
- }
-
- // problem 21
- int[] n21 = { 2, 5, 10, 15, 20 };
- double[] roots21 = {
- 0.5, 0.34595481584824, 0.24512233375331,
- 0.19554762353657, 0.16492095727644
- };
- for (int k = 0; k < n21.length; ++k) {
- problems.add(new APSProblem21(n21[k], 0.0, 1.0, roots21[k]));
- }
-
- // problem 22
- int[] n22 = { 1, 2, 4, 5, 8, 15, 20 };
- double[] roots22 = {
- 0.27550804099948, 0.13775402049974, 1.0305283778156e-2,
- 3.6171081789041e-3, 4.1087291849640e-4, 2.5989575892908e-5,
- 7.6685951221853e-6
- };
- for (int k = 0; k < n22.length; ++k) {
- problems.add(new APSProblem22(n22[k], 0.0, 1.0, roots22[k]));
- }
-
- // problem 23
- int[] n23 = { 1, 5, 10, 15, 20 };
- double[] roots23 = {
- 0.40105813754155, 0.51615351875793, 0.53952222690842,
- 0.54818229434066, 0.55270466667849
- };
- for (int k = 0; k < n23.length; ++k) {
- problems.add(new APSProblem23(n23[k], 0.0, 1.0, roots23[k]));
- }
-
- // problem 24
- int[] n24 = { 2, 5, 15, 20 };
- for (int k = 0; k < n24.length; ++k) {
- problems.add(new APSProblem24(n24[k], 0.01, 1, 1.0 / n24[k]));
- }
-
- // problem 25
- int[] n25 = {
- 2, 3, 4, 5, 6,
- 7, 9, 11, 13, 15,
- 17, 19, 21, 23, 25,
- 27, 29, 31, 33
- };
- for (int k = 0; k < n25.length; ++k) {
- problems.add(new APSProblem25(n25[k], 1.0, 100.0, n25[k]));
- }
-
- // problem 26
- problems.add(new APSProblem26(-1.0, 4.0, 0.0));
-
- // problem 27
- int[] n27 = {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
- 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
- };
- for (int k = 0; k < n27.length; ++k) {
- problems.add(new APSProblem27(n27[k], -10000.0, Math.PI / 2,
- 0.62380651896161));
- }
-
- // problem 28
- int[] n28 = {
- 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
- double[] roots28 = {
- 5.9051305594220e-5, 5.6367155339937e-5, 5.3916409455592e-5,
- 5.1669892394942e-5, 4.9603096699145e-5, 4.7695285287639e-5,
- 4.5928793239949e-5, 4.4288479195665e-5, 4.2761290257883e-5,
- 4.1335913915954e-5, 4.0002497338020e-5, 3.8752419296207e-5,
- 3.7578103559958e-5, 3.6472865219959e-5, 3.5430783356532e-5,
- 3.4446594929961e-5, 3.3515605877800e-5, 3.2633616249437e-5,
- 3.1796856858426e-5, 3.1001935436965e-5, 3.0245790670210e-5,
- 1.2277994232462e-5, 6.1695393904409e-6, 4.1198585298293e-6,
- 3.0924623877272e-6, 2.4752044261050e-6, 2.0633567678513e-6,
- 1.7690120078154e-6, 1.5481615698859e-6, 1.3763345366022e-6,
- 1.2388385788997e-6
- };
- for (int k = 0; k < n28.length; ++k) {
- problems.add(new APSProblem28(n28[k], -10000.0, 10000.0, roots28[k]));
- }
-
- return (TestProblem[]) problems.toArray(new TestProblem[problems.size()]);
-
- }
-
- private static class APSProblem1 extends TestProblem {
- private static final long serialVersionUID = -186095948802525864L;
- public APSProblem1(double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- }
- public double valueAt(double x) {
- return Math.sin(x) - x / 2;
- }
- }
-
- private static class APSProblems2To11 extends TestProblem {
- private static final long serialVersionUID = -1284328672006328516L;
- public APSProblems2To11(double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- }
- public double valueAt(double x) {
- double f = 0;
- for (int i = 1; i <= 20; ++i) {
- double n = 2.0 * i - 5.0;
- double d = x - i * i;
- f += n * n / (d * d * d);
- }
- return -2 * f;
- }
- }
-
- private static class APSProblems12To14 extends TestProblem {
- private static final long serialVersionUID = 3371996034561221313L;
- private int n;
- public APSProblems12To14(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- }
- public double valueAt(double x) {
- return n * x * Math.exp(-x);
- }
- }
-
- private static class APSProblems15To17 extends TestProblem {
- private static final long serialVersionUID = -5460543876513796612L;
- private int n;
- private double u;
- public APSProblems15To17(int n, double u,
- double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- this.u = u;
- }
- public double valueAt(double x) {
- return Math.pow(x, n) - u;
- }
- }
-
- private static class APSProblem18 extends TestProblem {
- private static final long serialVersionUID = 6762799934117390438L;
- public APSProblem18(double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- }
- public double valueAt(double x) {
- return Math.sin(x) - 0.5;
- }
- }
-
- private static class APSProblem19 extends TestProblem {
- private static final long serialVersionUID = 4962041891152128524L;
- private int n;
- public APSProblem19(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- }
- public double valueAt(double x) {
- return 2.0 * x * Math.exp(-n) - 2.0 *Math.exp(-n * x) + 1.0;
- }
- }
-
- private static class APSProblem20 extends TestProblem {
- private static final long serialVersionUID = -7391954140799812791L;
- private int n;
- private int oPoMn2;
- public APSProblem20(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- int oMn = 1 - n;
- oPoMn2 = 1 + oMn * oMn;
- }
- public double valueAt(double x) {
- double v = 1.0 - n * x;
- return oPoMn2 * x - v * v;
- }
- }
-
- private static class APSProblem21 extends TestProblem {
- private static final long serialVersionUID = -4160028543895639114L;
- private int n;
- public APSProblem21(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- }
- public double valueAt(double x) {
- return x * x - Math.pow(1 - x, n);
- }
- }
-
- private static class APSProblem22 extends TestProblem {
- private static final long serialVersionUID = 3807046732154081146L;
- private int n;
- private int oPoMn4;
- public APSProblem22(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- int oMn = 1 - n;
- int oMn2 = oMn * oMn;
- oPoMn4 = 1 + oMn2 * oMn2;
- }
- public double valueAt(double x) {
- double oMnx = 1 - n * x;
- double oMnx2 = oMnx * oMnx;
- return oPoMn4 * x - oMnx2 * oMnx2;
- }
- }
-
- private static class APSProblem23 extends TestProblem {
- private static final long serialVersionUID = -486669213837396921L;
- private int n;
- public APSProblem23(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- }
- public double valueAt(double x) {
- return (x - 1.0) * Math.exp(-n * x) + Math.pow(x, n);
- }
- }
-
- private static class APSProblem24 extends TestProblem {
- private static final long serialVersionUID = -628275471717968182L;
- private int n;
- public APSProblem24(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- this.n = n;
- }
- public double valueAt(double x) {
- return (n * x - 1.0) / ((n - 1) * x);
- }
- }
-
- private static class APSProblem25 extends TestProblem {
- private static final long serialVersionUID = 5207170686914959073L;
- private double u;
- private double v;;
- public APSProblem25(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- u = 1.0 / n;
- v = Math.pow(n, u);
- }
- public double valueAt(double x) {
- return Math.pow(x, u) - v;
- }
- }
-
- private static class APSProblem26 extends TestProblem {
- private static final long serialVersionUID = 1063884352586457076L;
-
- public APSProblem26(double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- }
- public double valueAt(double x) {
- if (x == 0.0) {
- return 0;
- }
- return x / Math.exp(1 / (x * x));
- }
-
- // this is a very special case since there is a wide range around
- // the true root (which is 0) for which |f(x)| is smaller than the
- // smallest representable positive number (according to IEEE 754):
- // f(0.03762210865...) = 2^-1024
- // f(0.03764056462...) = 2^-1023
- // f(0.03765904777...) = 2^-1022
- // f(0.03767755816...) = 2^-1021
- // any root between -0.03768 and +0.03768 should be considered good
- public boolean checkResult(double foundRoot, double tol) {
- return Math.abs(foundRoot) <= 0.03768;
- }
-
- }
-
- private static class APSProblem27 extends TestProblem {
- private static final long serialVersionUID = -3549158218723499035L;
- private double u;
- public APSProblem27(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- u = n / 20.0;
- }
- public double valueAt(double x) {
- if (x >= 0.0) {
- return (x / 1.5 + Math.sin(x) - 1.0) * u;
- }
- return -u;
- }
- }
-
- private static class APSProblem28 extends TestProblem {
- private static final long serialVersionUID = -8198306839874267863L;
- private double threshold;
- private static final double yHigh= Math.exp(1.0) - 1.859;
- private int u;
- public APSProblem28(int n, double a, double b, double expectedRoot) {
- super(a, b, expectedRoot);
- threshold = 0.002 / (1 + n);
- u = (n + 1) * 500;
- }
- public double valueAt(double x) {
- if (x >= threshold) {
- return yHigh;
- } else if (x >= 0) {
- return Math.exp(u * x) - 1.859;
- } else {
- return -0.859;
- }
- }
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java b/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java
deleted file mode 100644
index d8183cd..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
-
- TestSuite suite = new TestSuite("org.spaceroots.mantissa.utilities");
-
- suite.addTest(ArrayMapperTest.suite());
- suite.addTest(MappableArrayTest.suite());
- suite.addTest(MappableScalarTest.suite());
- suite.addTest(IntervalTest.suite());
- suite.addTest(IntervalsListTest.suite());
-
- return suite;
-
- }
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java
deleted file mode 100644
index a2bf571..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import junit.framework.*;
-
-public class ArrayMapperTest
- extends TestCase {
-
- public ArrayMapperTest(String name) {
- super(name);
- mapper = null;
- b1 = null;
- b2 = null;
- b3 = null;
- }
-
- public void testDimensionCheck() {
- int size = b1.getStateDimension();
- size += b2.getStateDimension();
- size += b3.getStateDimension();
- assertTrue(mapper.getDataArray().length == size);
- }
-
- public void testUpdateObjects() {
-
- double[] data = new double [7];
- for (int i = 0; i < 7; ++i) {
- data [i] = i * 0.1;
- }
-
- mapper.updateObjects(data);
-
- assertTrue(Math.abs(b1.getElement(0) - 0.0) < 1.0e-10);
-
- assertTrue(Math.abs(b2.getElement(0) - 0.4) < 1.0e-10);
- assertTrue(Math.abs(b2.getElement(1) - 0.3) < 1.0e-10);
- assertTrue(Math.abs(b2.getElement(2) - 0.2) < 1.0e-10);
- assertTrue(Math.abs(b2.getElement(3) - 0.1) < 1.0e-10);
-
- assertTrue(Math.abs(b3.getElement(0) - 0.6) < 1.0e-10);
- assertTrue(Math.abs(b3.getElement(1) - 0.5) < 1.0e-10);
-
- }
-
- public void testUpdateArray() {
-
- b1.setElement(0, 0.0);
-
- b2.setElement(0, 40.0);
- b2.setElement(1, 30.0);
- b2.setElement(2, 20.0);
- b2.setElement(3, 10.0);
-
- b3.setElement(0, 60.0);
- b3.setElement(1, 50.0);
-
- mapper.updateArray();
-
- double[] data = mapper.getDataArray();
- for (int i = 0; i < 7; ++i) {
- assertTrue(Math.abs(data [i] - i * 10.0) < 1.0e-10);
- }
-
- }
-
- public void setUp() {
-
- b1 = new DomainObject(1);
- b2 = new DomainObject(4);
- b3 = new DomainObject(2);
-
- mapper = new ArrayMapper();
- mapper.manageMappable(b1);
- mapper.manageMappable(b2);
- mapper.manageMappable(b3);
-
- }
-
- public void tearOff() {
-
- b1 = null;
- b2 = null;
- b3 = null;
-
- mapper = null;
-
- }
-
- public static Test suite() {
- return new TestSuite(ArrayMapperTest.class);
- }
-
- private static class DomainObject implements ArraySliceMappable {
-
- private double[] data;
-
- public DomainObject(int size) {
- data = new double [size];
- }
-
- public int getStateDimension() {
- return data.length;
- }
-
- public void mapStateFromArray(int start, double[] array) {
- for (int i = 0; i < data.length; ++i) {
- data [data.length - 1 - i] = array [start + i];
- }
- }
-
- public void mapStateToArray(int start, double[] array) {
- for (int i = 0; i < data.length; ++i) {
- array [start + i] = data [data.length - 1 - i];
- }
- }
-
- public double getElement(int i) {
- return data [i];
- }
-
- public void setElement(int i, double value) {
- data [i] = value;
- }
-
- }
-
- private DomainObject b1;
- private DomainObject b2;
- private DomainObject b3;
-
- private ArrayMapper mapper;
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java
deleted file mode 100644
index 7a0e228..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import junit.framework.*;
-
-public class IntervalTest
- extends TestCase {
-
- public IntervalTest(String name) {
- super(name);
- }
-
- public void test1() {
- check(new Interval(-10.0, 10.0), new Interval(11.0, 12.0), 2.5,
- true, false, false,
- new Interval(-10.0, 12.0), new Interval(11.0, 11.0));
- }
-
- public void test2() {
- check(new Interval(-10.0, 10.0), new Interval(9.0, 12.0), 50.0,
- false, false, true,
- new Interval(-10.0, 12.0), new Interval(9.0, 10.0));
- }
-
- public void test3() {
- check(new Interval(-10.0, 10.0), new Interval(-12.0, -11.0), 0.0,
- true, false, false,
- new Interval(-12.0, 10.0), new Interval(-10.0, -10.0));
- }
-
- public void test4() {
- check(new Interval(-10.0, 10.0), new Interval(-4.0, 5.0), 0.0,
- true, true, true,
- new Interval(-10.0, 10.0), new Interval(-4.0, 5.0));
- }
-
- public void test5() {
- check(new Interval(-10.0, 10.0), new Interval(-10.0, 10.0), 0.0,
- true, true, true,
- new Interval(-10.0, 10.0), new Interval(-10.0, 10.0));
- }
-
- private void check(Interval i1, Interval i2, double x,
- boolean b1, boolean b2, boolean b3,
- Interval add, Interval inter) {
-
- assertTrue(i1.contains(x) ^ (!b1));
- assertTrue(i1.contains(i2) ^ (!b2));
- assertTrue(i1.intersects(i2) ^ (!b3));
-
- assertEquals(add.getInf(), Interval.add(i1, i2).getInf(), 1.0e-10);
- assertEquals(add.getSup(), Interval.add(i1, i2).getSup(), 1.0e-10);
- assertEquals(inter.getInf(), Interval.intersection(i1, i2).getInf(), 1.0e-10);
- assertEquals(inter.getSup(), Interval.intersection(i1, i2).getSup(), 1.0e-10);
-
- Interval ia = new Interval(i1);
- ia.addToSelf(i2);
- assertEquals(add.getInf(), ia.getInf(), 1.0e-10);
- assertEquals(add.getSup(), ia.getSup(), 1.0e-10);
-
- Interval ib = new Interval(i1);
- ib.intersectSelf(i2);
- assertEquals(inter.getInf(), ib.getInf(), 1.0e-10);
- assertEquals(inter.getSup(), ib.getSup(), 1.0e-10);
-
- }
-
- public static Test suite() {
- return new TestSuite(IntervalTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java
deleted file mode 100644
index 80f1873..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import java.util.Iterator;
-
-import junit.framework.*;
-
-public class IntervalsListTest
- extends TestCase {
-
- public IntervalsListTest(String name) {
- super(name);
- }
-
- public void testAddBetween() {
- IntervalsList il =
- new IntervalsList (new Interval(10, 20), new Interval(50, 60));
- il.addToSelf(new Interval(30, 40));
- checkEquals(new Interval[] {
- new Interval(10, 20),
- new Interval(30, 40),
- new Interval(50, 60)
- }, il);
- }
-
- public void testAddReducingLastHole() {
- IntervalsList il =
- new IntervalsList (new Interval(10, 20), new Interval(50, 60));
- il.addToSelf(new Interval(30, 55));
- checkEquals(new Interval[] {
- new Interval(10, 20),
- new Interval(30, 60)
- }, il);
- }
-
- public void test1() {
-
- IntervalsList list1 = new IntervalsList(-2.0, -1.0);
- IntervalsList list2 = new IntervalsList(new Interval(-0.9, -0.8));
- check(list1, list2, 2.5,
- true, false, 1, true, false, 1, false,
- new Interval[] { new Interval(-2.0, -1.0),
- new Interval(-0.9, -0.8) },
- new Interval[0]);
-
- list2.addToSelf(new Interval(1.0, 3.0));
- check(list1, list2, 2.5,
- true, false, 1, false, false, 2, false,
- new Interval[] { new Interval(-2.0, -1.0),
- new Interval(-0.9, -0.8),
- new Interval( 1.0, 3.0) },
- new Interval[0]);
-
- list1.addToSelf(new Interval(-1.2, 0.0));
- check(list1, list2, -1.1,
- true, false, 1, false, false, 2, true,
- new Interval[] { new Interval(-2.0, 0.0),
- new Interval( 1.0, 3.0) },
- new Interval[] { new Interval(-0.9, -0.8) });
-
- IntervalsList list = new IntervalsList(new Interval(-10.0, -8.0));
- list.addToSelf(new Interval(-6.0, -4.0));
- list.addToSelf(new Interval(-0.85, 1.2));
- list1.addToSelf(list);
- check(list1, list2, 0,
- false, false, 3, false, false, 2, true,
- new Interval[] { new Interval(-10.0, -8.0),
- new Interval( -6.0, -4.0),
- new Interval( -2.0, 3.0) },
- new Interval[] { new Interval( -0.9, -0.8),
- new Interval( 1.0, 1.2) });
-
- }
-
- private void check(IntervalsList l1, IntervalsList l2, double x,
- boolean b1, boolean b2, int i1,
- boolean b3, boolean b4, int i2,
- boolean b5, Interval[] add, Interval[] inter) {
- assertTrue(l1.isConnex() ^ (!b1));
- assertTrue(l1.isEmpty() ^ (!b2));
- assertEquals(i1, l1.getIntervals().size());
- assertTrue(l2.isConnex() ^ (!b3));
- assertTrue(l2.isEmpty() ^ (!b4));
- assertEquals(i2, l2.getIntervals().size());
- assertTrue(l1.contains(x) ^ (!b5));
- checkEquals(add, IntervalsList.add(l1, l2));
- checkEquals(inter, IntervalsList.intersection(l1, l2));
- }
-
- private void checkEquals(Interval[] sa, IntervalsList sb) {
- assertEquals(sa.length, sb.getIntervals().size());
- Iterator iterB = sb.getIntervals().iterator();
- for (int i = 0; i < sa.length; ++i) {
- Interval ib = (Interval) iterB.next();
- assertEquals(sa[i].getInf(), ib.getInf(), 1.0e-10);
- assertEquals(sa[i].getSup(), ib.getSup(), 1.0e-10);
- }
- }
-
- public static Test suite() {
- return new TestSuite(IntervalsListTest.class);
- }
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java
deleted file mode 100644
index 994ee77..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import junit.framework.*;
-
-public class MappableArrayTest
- extends TestCase {
-
- public MappableArrayTest(String name) {
- super(name);
- array1 = null;
- array2 = null;
- array3 = null;
- mapper = null;
- }
-
- public void testDimensionCheck() {
- assertTrue(mapper.getDataArray().length == 9);
- }
-
- public void testUpdateObjects() {
-
- double[] data = new double [mapper.getDataArray().length];
- for (int i = 0; i < data.length; ++i) {
- data [i] = i * 0.1;
- }
-
- mapper.updateObjects(data);
-
- double[] a1 = array1.getArray();
- assertTrue(Math.abs(a1[0] - 0.0) < 1.0e-10);
- assertTrue(Math.abs(a1[1] - 0.1) < 1.0e-10);
- assertTrue(Math.abs(a1[2] - 0.2) < 1.0e-10);
- assertTrue(Math.abs(a1[3] - 0.3) < 1.0e-10);
-
- double[] a2 = array2.getArray();
- assertTrue(Math.abs(a2[0] - 0.4) < 1.0e-10);
- assertTrue(Math.abs(a2[1] - 0.5) < 1.0e-10);
-
- double[] a3 = array3.getArray();
- assertTrue(Math.abs(a3[0] - 0.6) < 1.0e-10);
- assertTrue(Math.abs(a3[1] - 0.7) < 1.0e-10);
- assertTrue(Math.abs(a3[2] - 0.8) < 1.0e-10);
-
- }
-
- public static Test suite() {
- return new TestSuite(MappableArrayTest.class);
- }
-
- public void setUp() {
-
- array1 = new MappableArray(4);
- array2 = new MappableArray(new double[2]);
- array3 = new MappableArray(new double[3]);
-
- mapper = new ArrayMapper();
- mapper.manageMappable(array1);
- mapper.manageMappable(array2);
- mapper.manageMappable(array3);
-
- }
-
- public void tearDown() {
- array1 = null;
- array2 = null;
- array3 = null;
- mapper = null;
- }
-
- private MappableArray array1;
- private MappableArray array2;
- private MappableArray array3;
- private ArrayMapper mapper;
-
-}
diff --git a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java b/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java
deleted file mode 100644
index 7a1ef4a..0000000
--- a/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.utilities;
-
-import junit.framework.*;
-
-public class MappableScalarTest
- extends TestCase {
-
- public MappableScalarTest(String name) {
- super(name);
- mapper = null;
- scalar1 = null;
- scalar2 = null;
- scalar3 = null;
- }
-
- public void testDimensionCheck() {
- assertTrue(mapper.getDataArray().length == 3);
- }
-
- public void testUpdateObjects() {
-
- double[] data = new double [mapper.getDataArray().length];
- for (int i = 0; i < data.length; ++i) {
- data [i] = i * 0.1;
- }
-
- mapper.updateObjects(data);
-
- assertTrue(Math.abs(scalar1.getValue() - 0.0) < 1.0e-10);
- assertTrue(Math.abs(scalar2.getValue() - 0.1) < 1.0e-10);
- assertTrue(Math.abs(scalar3.getValue() - 0.2) < 1.0e-10);
-
- }
-
- public void testUpdateArray() {
-
- scalar1.setValue(00.0);
- scalar2.setValue(10.0);
- scalar3.setValue(20.0);
-
- mapper.updateArray();
-
- double[] data = mapper.getDataArray();
- for (int i = 0; i < data.length; ++i) {
- assertTrue(Math.abs(data [i] - i * 10.0) < 1.0e-10);
- }
-
- }
-
- public static Test suite() {
- return new TestSuite(MappableScalarTest.class);
- }
-
- public void setUp() {
-
- scalar1 = new MappableScalar();
- scalar2 = new MappableScalar(2);
- scalar3 = new MappableScalar(-3);
-
- mapper = new ArrayMapper();
- mapper.manageMappable(scalar1);
- mapper.manageMappable(scalar2);
- mapper.manageMappable(scalar3);
-
- }
-
- public void tearDown() {
-
- scalar1 = null;
- scalar2 = null;
- scalar3 = null;
-
- mapper = null;
-
- }
-
- private MappableScalar scalar1;
- private MappableScalar scalar2;
- private MappableScalar scalar3;
-
- private ArrayMapper mapper;
-
-}