Author: erans Date: Fri Nov 26 15:24:28 2010 New Revision: 1039411 URL: http://svn.apache.org/viewvc?rev=1039411&view=rev Log: MATH-430 Removed redundant "mapXxx" methods. Upgraded tests to Junit4 (MATH-423). Some test used "assertEquals" without a tolerance (strict equality between floating point numbers); this failed with Junit4.
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ceil.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Floor.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Rint.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Signum.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ulp.java (with props) Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/AbstractRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ceil.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ceil.java?rev=1039411&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ceil.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ceil.java Fri Nov 26 15:24:28 2010 @@ -0,0 +1,34 @@ +/* + * 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.function; + +import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.FastMath; + +/** + * {...@code ceil} function. + * + * @version $Revision$ $Date$ + * @since 3.0 + */ +public class Ceil implements UnivariateRealFunction { + /** {...@inheritdoc} */ + public double value(double x) { + return FastMath.ceil(x); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ceil.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Floor.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Floor.java?rev=1039411&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Floor.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Floor.java Fri Nov 26 15:24:28 2010 @@ -0,0 +1,34 @@ +/* + * 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.function; + +import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.FastMath; + +/** + * {...@code floor} function. + * + * @version $Revision$ $Date$ + * @since 3.0 + */ +public class Floor implements UnivariateRealFunction { + /** {...@inheritdoc} */ + public double value(double x) { + return FastMath.floor(x); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Floor.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Rint.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Rint.java?rev=1039411&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Rint.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Rint.java Fri Nov 26 15:24:28 2010 @@ -0,0 +1,34 @@ +/* + * 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.function; + +import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.FastMath; + +/** + * {...@code rint} function. + * + * @version $Revision$ $Date$ + * @since 3.0 + */ +public class Rint implements UnivariateRealFunction { + /** {...@inheritdoc} */ + public double value(double x) { + return FastMath.rint(x); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Rint.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Signum.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Signum.java?rev=1039411&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Signum.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Signum.java Fri Nov 26 15:24:28 2010 @@ -0,0 +1,34 @@ +/* + * 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.function; + +import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.FastMath; + +/** + * {...@code signum} function. + * + * @version $Revision$ $Date$ + * @since 3.0 + */ +public class Signum implements UnivariateRealFunction { + /** {...@inheritdoc} */ + public double value(double x) { + return FastMath.signum(x); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Signum.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ulp.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ulp.java?rev=1039411&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ulp.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ulp.java Fri Nov 26 15:24:28 2010 @@ -0,0 +1,34 @@ +/* + * 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.function; + +import org.apache.commons.math.analysis.UnivariateRealFunction; +import org.apache.commons.math.util.FastMath; + +/** + * {...@code ulp} function. + * + * @version $Revision$ $Date$ + * @since 3.0 + */ +public class Ulp implements UnivariateRealFunction { + /** {...@inheritdoc} */ + public double value(double x) { + return FastMath.ulp(x); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Ulp.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java?rev=1039411&r1=1039410&r2=1039411&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java Fri Nov 26 15:24:28 2010 @@ -24,7 +24,6 @@ import org.apache.commons.math.exception import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.analysis.BinaryFunction; -import org.apache.commons.math.analysis.ComposableFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; @@ -342,165 +341,6 @@ public abstract class AbstractRealVector return maxIndex < 0 ? Double.NaN : getEntry(maxIndex); } - /** {...@inheritdoc} */ - public RealVector mapAbs() { - return copy().mapAbsToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapAbsToSelf() { - return mapToSelf(ComposableFunction.ABS); - } - - /** {...@inheritdoc} */ - public RealVector mapAcos() { - return copy().mapAcosToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapAcosToSelf() { - return mapToSelf(ComposableFunction.ACOS); - } - - /** {...@inheritdoc} */ - public RealVector mapAsin() { - return copy().mapAsinToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapAsinToSelf() { - return mapToSelf(ComposableFunction.ASIN); - } - - /** {...@inheritdoc} */ - public RealVector mapAtan() { - return copy().mapAtanToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapAtanToSelf() { - return mapToSelf(ComposableFunction.ATAN); - } - - /** {...@inheritdoc} */ - public RealVector mapCbrt() { - return copy().mapCbrtToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapCbrtToSelf() { - return mapToSelf(ComposableFunction.CBRT); - } - - /** {...@inheritdoc} */ - public RealVector mapCeil() { - return copy().mapCeilToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapCeilToSelf() { - return mapToSelf(ComposableFunction.CEIL); - } - - /** {...@inheritdoc} */ - public RealVector mapCos() { - return copy().mapCosToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapCosToSelf() { - return mapToSelf(ComposableFunction.COS); - } - - /** {...@inheritdoc} */ - public RealVector mapCosh() { - return copy().mapCoshToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapCoshToSelf() { - return mapToSelf(ComposableFunction.COSH); - } - - /** {...@inheritdoc} */ - public RealVector mapDivide(double d) { - return copy().mapDivideToSelf(d); - } - - /** {...@inheritdoc} */ - public RealVector mapDivideToSelf(double d){ - return mapToSelf(BinaryFunction.DIVIDE.fix2ndArgument(d)); - } - - /** {...@inheritdoc} */ - public RealVector mapExp() { - return copy().mapExpToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapExpToSelf() { - return mapToSelf(ComposableFunction.EXP); - } - - /** {...@inheritdoc} */ - public RealVector mapExpm1() { - return copy().mapExpm1ToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapExpm1ToSelf() { - return mapToSelf(ComposableFunction.EXPM1); - } - - /** {...@inheritdoc} */ - public RealVector mapFloor() { - return copy().mapFloorToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapFloorToSelf() { - return mapToSelf(ComposableFunction.FLOOR); - } - - /** {...@inheritdoc} */ - public RealVector mapInv() { - return copy().mapInvToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapInvToSelf() { - return mapToSelf(ComposableFunction.INVERT); - } - - /** {...@inheritdoc} */ - public RealVector mapLog() { - return copy().mapLogToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapLogToSelf() { - return mapToSelf(ComposableFunction.LOG); - } - - /** {...@inheritdoc} */ - public RealVector mapLog10() { - return copy().mapLog10ToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapLog10ToSelf() { - return mapToSelf(ComposableFunction.LOG10); - } - - /** {...@inheritdoc} */ - public RealVector mapLog1p() { - return copy().mapLog1pToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapLog1pToSelf() { - return mapToSelf(ComposableFunction.LOG1P); - } /** {...@inheritdoc} */ public RealVector mapMultiply(double d) { @@ -513,66 +353,6 @@ public abstract class AbstractRealVector } /** {...@inheritdoc} */ - public RealVector mapPow(double d) { - return copy().mapPowToSelf(d); - } - - /** {...@inheritdoc} */ - public RealVector mapPowToSelf(double d){ - return mapToSelf(BinaryFunction.POW.fix2ndArgument(d)); - } - - /** {...@inheritdoc} */ - public RealVector mapRint() { - return copy().mapRintToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapRintToSelf() { - return mapToSelf(ComposableFunction.RINT); - } - - /** {...@inheritdoc} */ - public RealVector mapSignum() { - return copy().mapSignumToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapSignumToSelf() { - return mapToSelf(ComposableFunction.SIGNUM); - } - - /** {...@inheritdoc} */ - public RealVector mapSin() { - return copy().mapSinToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapSinToSelf() { - return mapToSelf(ComposableFunction.SIN); - } - - /** {...@inheritdoc} */ - public RealVector mapSinh() { - return copy().mapSinhToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapSinhToSelf() { - return mapToSelf(ComposableFunction.SINH); - } - - /** {...@inheritdoc} */ - public RealVector mapSqrt() { - return copy().mapSqrtToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapSqrtToSelf() { - return mapToSelf(ComposableFunction.SQRT); - } - - /** {...@inheritdoc} */ public RealVector mapSubtract(double d) { return copy().mapSubtractToSelf(d); } @@ -583,33 +363,23 @@ public abstract class AbstractRealVector } /** {...@inheritdoc} */ - public RealVector mapTan() { - return copy().mapTanToSelf(); - } - - /** {...@inheritdoc} */ - public RealVector mapTanToSelf() { - return mapToSelf(ComposableFunction.TAN); - } - - /** {...@inheritdoc} */ - public RealVector mapTanh() { - return copy().mapTanhToSelf(); + public RealVector mapDivide(double d) { + return copy().mapDivideToSelf(d); } /** {...@inheritdoc} */ - public RealVector mapTanhToSelf() { - return mapToSelf(ComposableFunction.TANH); + public RealVector mapDivideToSelf(double d){ + return mapToSelf(BinaryFunction.DIVIDE.fix2ndArgument(d)); } /** {...@inheritdoc} */ - public RealVector mapUlp() { - return copy().mapUlpToSelf(); + public RealVector mapPow(double d) { + return copy().mapPowToSelf(d); } /** {...@inheritdoc} */ - public RealVector mapUlpToSelf() { - return mapToSelf(ComposableFunction.ULP); + public RealVector mapPowToSelf(double d){ + return mapToSelf(BinaryFunction.POW.fix2ndArgument(d)); } /** {...@inheritdoc} */ @@ -718,11 +488,13 @@ public abstract class AbstractRealVector } /** {...@inheritdoc} */ + @Override public RealVector map(UnivariateRealFunction function) { return copy().mapToSelf(function); } /** {...@inheritdoc} */ + @Override public RealVector mapToSelf(UnivariateRealFunction function) { Iterator<Entry> it = (function.value(0) == 0) ? sparseIterator() : iterator(); Entry e; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java?rev=1039411&r1=1039410&r2=1039411&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java Fri Nov 26 15:24:28 2010 @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Arrays; import java.util.Iterator; +import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.NumberIsTooLargeException; @@ -280,7 +281,7 @@ public class ArrayRealVector extends Abs /** {...@inheritdoc} */ @Override - public AbstractRealVector copy() { + public ArrayRealVector copy() { return new ArrayRealVector(this, true); } @@ -366,252 +367,51 @@ public class ArrayRealVector extends Abs /** {...@inheritdoc} */ @Override - public RealVector mapAddToSelf(double d) { - for (int i = 0; i < data.length; i++) { - data[i] = data[i] + d; - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapSubtractToSelf(double d) { - for (int i = 0; i < data.length; i++) { - data[i] = data[i] - d; - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapMultiplyToSelf(double d) { - for (int i = 0; i < data.length; i++) { - data[i] = data[i] * d; - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapDivideToSelf(double d) { - for (int i = 0; i < data.length; i++) { - data[i] = data[i] / d; - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapPowToSelf(double d) { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.pow(data[i], d); - } - return this; + public ArrayRealVector map(UnivariateRealFunction function) { + return copy().mapToSelf(function); } /** {...@inheritdoc} */ @Override - public RealVector mapExpToSelf() { + public ArrayRealVector mapToSelf(UnivariateRealFunction function) { for (int i = 0; i < data.length; i++) { - data[i] = FastMath.exp(data[i]); + data[i] = function.value(data[i]); } return this; } /** {...@inheritdoc} */ @Override - public RealVector mapExpm1ToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.expm1(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapLogToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.log(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapLog10ToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.log10(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapLog1pToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.log1p(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapCoshToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.cosh(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapSinhToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.sinh(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapTanhToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.tanh(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapCosToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.cos(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapSinToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.sin(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapTanToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.tan(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapAcosToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.acos(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapAsinToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.asin(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapAtanToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.atan(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapInvToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = 1.0 / data[i]; - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapAbsToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.abs(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapSqrtToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.sqrt(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapCbrtToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.cbrt(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapCeilToSelf() { - for (int i = 0; i < data.length; i++) { - data[i] = FastMath.ceil(data[i]); - } - return this; - } - - /** {...@inheritdoc} */ - @Override - public RealVector mapFloorToSelf() { + public RealVector mapAddToSelf(double d) { for (int i = 0; i < data.length; i++) { - data[i] = FastMath.floor(data[i]); + data[i] = data[i] + d; } return this; } /** {...@inheritdoc} */ @Override - public RealVector mapRintToSelf() { + public RealVector mapSubtractToSelf(double d) { for (int i = 0; i < data.length; i++) { - data[i] = FastMath.rint(data[i]); + data[i] = data[i] - d; } return this; } /** {...@inheritdoc} */ @Override - public RealVector mapSignumToSelf() { + public RealVector mapMultiplyToSelf(double d) { for (int i = 0; i < data.length; i++) { - data[i] = FastMath.signum(data[i]); + data[i] = data[i] * d; } return this; } /** {...@inheritdoc} */ @Override - public RealVector mapUlpToSelf() { + public RealVector mapDivideToSelf(double d) { for (int i = 0; i < data.length; i++) { - data[i] = FastMath.ulp(data[i]); + data[i] = data[i] / d; } return this; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java?rev=1039411&r1=1039410&r2=1039411&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java Fri Nov 26 15:24:28 2010 @@ -271,491 +271,6 @@ public interface RealVector { RealVector mapPowToSelf(double d); /** - * Map the {...@link Math#exp(double)} function to each entry. - * - * @return a mapped copy of the vector. - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapExp(); - - /** - * Map {...@link Math#exp(double)} operation to each entry. - * The instance is changed in-place. - * - * @return the mapped vector. - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapExpToSelf(); - - /** - * Map the {...@link Math#expm1(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapExpm1(); - - /** - * Map the {...@link Math#expm1(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapExpm1ToSelf(); - - /** - * Map the {...@link Math#log(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapLog(); - - /** - * Map the {...@link Math#log(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapLogToSelf(); - - /** - * Map the {...@link Math#log10(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapLog10(); - - /** - * Map the {...@link Math#log10(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapLog10ToSelf(); - - /** - * Map the {...@link Math#log1p(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapLog1p(); - - /** - * Map the {...@link Math#log1p(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapLog1pToSelf(); - - /** - * Map the {...@link Math#cosh(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCosh(); - - /** - * Map the {...@link Math#cosh(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCoshToSelf(); - - /** - * Map the {...@link Math#sinh(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSinh(); - - /** - * Map the {...@link Math#sinh(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSinhToSelf(); - - /** - * Map the {...@link Math#tanh(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapTanh(); - - /** - * Map the {...@link Math#tanh(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapTanhToSelf(); - - /** - * Map the {...@link Math#cos(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCos(); - - /** - * Map the {...@link Math#cos(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCosToSelf(); - - /** - * Map the {...@link Math#sin(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSin(); - - /** - * Map the {...@link Math#sin(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSinToSelf(); - - /** - * Map the {...@link Math#tan(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapTan(); - - /** - * Map the {...@link Math#tan(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapTanToSelf(); - - /** - * Map the {...@link Math#acos(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAcos(); - - /** - * Map the {...@link Math#acos(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAcosToSelf(); - - /** - * Map the {...@link Math#asin(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAsin(); - - /** - * Map the {...@link Math#asin(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAsinToSelf(); - - /** - * Map the {...@link Math#atan(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAtan(); - - /** - * Map the {...@link Math#atan(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAtanToSelf(); - - /** - * Map the 1/x function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapInv(); - - /** - * Map the 1/x function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapInvToSelf(); - - /** - * Map the {...@link Math#abs(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAbs(); - - /** - * Map the {...@link Math#abs(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapAbsToSelf(); - - /** - * Map the {...@link Math#sqrt(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSqrt(); - - /** - * Map the {...@link Math#sqrt(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSqrtToSelf(); - - /** - * Map the {...@link Math#cbrt(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCbrt(); - - /** - * Map the {...@link Math#cbrt(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCbrtToSelf(); - - /** - * Map the {...@link Math#ceil(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCeil(); - - /** - * Map the {...@link Math#ceil(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapCeilToSelf(); - - /** - * Map the {...@link Math#floor(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapFloor(); - - /** - * Map the {...@link Math#floor(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapFloorToSelf(); - - /** - * Map the {...@link Math#rint(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapRint(); - - /** - * Map the {...@link Math#rint(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapRintToSelf(); - - /** - * Map the {...@link Math#signum(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSignum(); - - /** - * Map the {...@link Math#signum(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapSignumToSelf(); - - /** - * Map the {...@link Math#ulp(double)} function to each entry. - * @return a vector containing the result of applying the function to each entry - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #map(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapUlp(); - - /** - * Map the {...@link Math#ulp(double)} function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return this - * @deprecated in 2.2 (to be removed in 3.0). Please use - * {...@link #mapToSelf(UnivariateRealFunction)} directly with - * the function classes in package - * {...@link org.apache.commons.math.analysis.function}. - */ - RealVector mapUlpToSelf(); - - /** * Element-by-element multiplication. * @param v vector by which instance elements must be multiplied * @return a vector containing this[i] * v[i] for all i Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/AbstractRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/AbstractRealVectorTest.java?rev=1039411&r1=1039410&r2=1039411&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/AbstractRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/AbstractRealVectorTest.java Fri Nov 26 15:24:28 2010 @@ -17,7 +17,8 @@ package org.apache.commons.math.linear; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.Assert; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.linear.RealVector.Entry; import org.apache.commons.math.util.FastMath; @@ -28,7 +29,7 @@ import java.util.Random; /** * */ -public class AbstractRealVectorTest extends TestCase { +public class AbstractRealVectorTest { private double[] vec1 = { 1d, 2d, 3d, 4d, 5d }; private double[] vec2 = { -3d, 0d, 0d, 2d, 1d }; @@ -104,13 +105,6 @@ public class AbstractRealVectorTest exte return this; } - @Override - public RealVector mapInvToSelf() { - for(int i=0; i<values.length; i++) { - values[i] = 1/values[i]; - } - return this; - } public RealVector ebeMultiply(RealVector v) { throw unsupported(); @@ -182,10 +176,11 @@ public class AbstractRealVectorTest exte } private static void assertEquals(double[] d1, double[] d2) { - assertEquals(d1.length, d2.length); - for(int i=0; i<d1.length; i++) assertEquals(d1[i], d2[i]); + Assert.assertEquals(d1.length, d2.length); + for(int i=0; i<d1.length; i++) Assert.assertEquals(d1[i], d2[i], 0); } + @Test public void testMap() throws Exception { double[] vec1Squared = { 1d, 4d, 9d, 16d, 25d }; RealVector v = new TestVectorImpl(vec1.clone()); @@ -193,41 +188,44 @@ public class AbstractRealVectorTest exte assertEquals(vec1Squared, w.getData()); } + @Test public void testIterator() throws Exception { RealVector v = new TestVectorImpl(vec2.clone()); Entry e; int i = 0; for(Iterator<Entry> it = v.iterator(); it.hasNext() && (e = it.next()) != null; i++) { - assertEquals(vec2[i], e.getValue()); + Assert.assertEquals(vec2[i], e.getValue(), 0); } } + @Test public void testSparseIterator() throws Exception { RealVector v = new TestVectorImpl(vec2.clone()); Entry e; int i = 0; double[] nonDefaultV2 = { -3d, 2d, 1d }; for(Iterator<Entry> it = v.sparseIterator(); it.hasNext() && (e = it.next()) != null; i++) { - assertEquals(nonDefaultV2[i], e.getValue()); + Assert.assertEquals(nonDefaultV2[i], e.getValue(), 0); } double [] onlyOne = {0d, 1.0, 0d}; v = new TestVectorImpl(onlyOne); for(Iterator<Entry> it = v.sparseIterator(); it.hasNext() && (e = it.next()) != null; ) { - assertEquals(onlyOne[1], e.getValue()); + Assert.assertEquals(onlyOne[1], e.getValue(), 0); } } + @Test public void testClone() throws Exception { double[] d = new double[1000000]; Random r = new Random(1234); for(int i=0;i<d.length; i++) d[i] = r.nextDouble(); - assertTrue(new ArrayRealVector(d).getNorm() > 0); + Assert.assertTrue(new ArrayRealVector(d).getNorm() > 0); double[] c = d.clone(); c[0] = 1; - assertNotSame(c[0], d[0]); + Assert.assertNotSame(c[0], d[0]); d[0] = 1; - assertEquals(new ArrayRealVector(d).getNorm(), new ArrayRealVector(c).getNorm()); + Assert.assertEquals(new ArrayRealVector(d).getNorm(), new ArrayRealVector(c).getNorm(), 0); long cloneTime = 0; long setAndAddTime = 0; for(int i=0; i<10; i++) {