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.



git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1039411 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2010-11-26 15:24:28 +00:00
parent 44eff7b3e8
commit ae78e16c8b
11 changed files with 599 additions and 1692 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -24,7 +24,6 @@ import org.apache.commons.math.exception.MathUnsupportedOperationException;
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 implements RealVector {
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) {
@ -512,66 +352,6 @@ public abstract class AbstractRealVector implements RealVector {
return mapToSelf(BinaryFunction.MULTIPLY.fix1stArgument(d));
}
/** {@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 implements RealVector {
}
/** {@inheritDoc} */
public RealVector mapTan() {
return copy().mapTanToSelf();
public RealVector mapDivide(double d) {
return copy().mapDivideToSelf(d);
}
/** {@inheritDoc} */
public RealVector mapTanToSelf() {
return mapToSelf(ComposableFunction.TAN);
public RealVector mapDivideToSelf(double d){
return mapToSelf(BinaryFunction.DIVIDE.fix2ndArgument(d));
}
/** {@inheritDoc} */
public RealVector mapTanh() {
return copy().mapTanhToSelf();
public RealVector mapPow(double d) {
return copy().mapPowToSelf(d);
}
/** {@inheritDoc} */
public RealVector mapTanhToSelf() {
return mapToSelf(ComposableFunction.TANH);
}
/** {@inheritDoc} */
public RealVector mapUlp() {
return copy().mapUlpToSelf();
}
/** {@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 implements RealVector {
}
/** {@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;

View File

@ -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 AbstractRealVector implements Serializable
/** {@inheritDoc} */
@Override
public AbstractRealVector copy() {
public ArrayRealVector copy() {
return new ArrayRealVector(this, true);
}
@ -364,6 +365,21 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
return (ArrayRealVector) subtract(v.data);
}
/** {@inheritDoc} */
@Override
public ArrayRealVector map(UnivariateRealFunction function) {
return copy().mapToSelf(function);
}
/** {@inheritDoc} */
@Override
public ArrayRealVector mapToSelf(UnivariateRealFunction function) {
for (int i = 0; i < data.length; i++) {
data[i] = function.value(data[i]);
}
return this;
}
/** {@inheritDoc} */
@Override
public RealVector mapAddToSelf(double d) {
@ -400,222 +416,6 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
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;
}
/** {@inheritDoc} */
@Override
public RealVector mapExpToSelf() {
for (int i = 0; i < data.length; i++) {
data[i] = FastMath.exp(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() {
for (int i = 0; i < data.length; i++) {
data[i] = FastMath.floor(data[i]);
}
return this;
}
/** {@inheritDoc} */
@Override
public RealVector mapRintToSelf() {
for (int i = 0; i < data.length; i++) {
data[i] = FastMath.rint(data[i]);
}
return this;
}
/** {@inheritDoc} */
@Override
public RealVector mapSignumToSelf() {
for (int i = 0; i < data.length; i++) {
data[i] = FastMath.signum(data[i]);
}
return this;
}
/** {@inheritDoc} */
@Override
public RealVector mapUlpToSelf() {
for (int i = 0; i < data.length; i++) {
data[i] = FastMath.ulp(data[i]);
}
return this;
}
/** {@inheritDoc} */
public RealVector ebeMultiply(RealVector v) {
if (v instanceof ArrayRealVector) {

View File

@ -270,491 +270,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

View File

@ -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 extends TestCase {
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 extends TestCase {
}
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 extends TestCase {
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++) {

View File

@ -18,20 +18,47 @@ package org.apache.commons.math.linear;
import java.io.Serializable;
import java.util.Iterator;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.analysis.function.Abs;
import org.apache.commons.math.analysis.function.Acosh;
import org.apache.commons.math.analysis.function.Acos;
import org.apache.commons.math.analysis.function.Asinh;
import org.apache.commons.math.analysis.function.Asin;
import org.apache.commons.math.analysis.function.Atanh;
import org.apache.commons.math.analysis.function.Atan;
import org.apache.commons.math.analysis.function.Cbrt;
import org.apache.commons.math.analysis.function.Cosh;
import org.apache.commons.math.analysis.function.Cos;
import org.apache.commons.math.analysis.function.Exp;
import org.apache.commons.math.analysis.function.Expm1;
import org.apache.commons.math.analysis.function.Inverse;
import org.apache.commons.math.analysis.function.Log10;
import org.apache.commons.math.analysis.function.Log1p;
import org.apache.commons.math.analysis.function.Log;
import org.apache.commons.math.analysis.function.Pow;
import org.apache.commons.math.analysis.function.Sinh;
import org.apache.commons.math.analysis.function.Sin;
import org.apache.commons.math.analysis.function.Sqrt;
import org.apache.commons.math.analysis.function.Tanh;
import org.apache.commons.math.analysis.function.Tan;
import org.apache.commons.math.analysis.function.Floor;
import org.apache.commons.math.analysis.function.Ceil;
import org.apache.commons.math.analysis.function.Rint;
import org.apache.commons.math.analysis.function.Signum;
import org.apache.commons.math.analysis.function.Ulp;
/**
* Test cases for the {@link OpenMapRealVector} class.
*
* @version $Revision$ $Date$
*/
public class SparseRealVectorTest extends TestCase {
public class SparseRealVectorTest {
//
protected double[][] ma1 = {{1d, 2d, 3d}, {4d, 5d, 6d}, {7d, 8d, 9d}};
@ -158,236 +185,6 @@ public class SparseRealVectorTest extends TestCase {
throw unsupported();
}
@Override
public RealVector mapExp() {
throw unsupported();
}
@Override
public RealVector mapExpToSelf() {
throw unsupported();
}
@Override
public RealVector mapExpm1() {
throw unsupported();
}
@Override
public RealVector mapExpm1ToSelf() {
throw unsupported();
}
@Override
public RealVector mapLog() {
throw unsupported();
}
@Override
public RealVector mapLogToSelf() {
throw unsupported();
}
@Override
public RealVector mapLog10() {
throw unsupported();
}
@Override
public RealVector mapLog10ToSelf() {
throw unsupported();
}
@Override
public RealVector mapLog1p() {
throw unsupported();
}
@Override
public RealVector mapLog1pToSelf() {
throw unsupported();
}
@Override
public RealVector mapCosh() {
throw unsupported();
}
@Override
public RealVector mapCoshToSelf() {
throw unsupported();
}
@Override
public RealVector mapSinh() {
throw unsupported();
}
@Override
public RealVector mapSinhToSelf() {
throw unsupported();
}
@Override
public RealVector mapTanh() {
throw unsupported();
}
@Override
public RealVector mapTanhToSelf() {
throw unsupported();
}
@Override
public RealVector mapCos() {
throw unsupported();
}
@Override
public RealVector mapCosToSelf() {
throw unsupported();
}
@Override
public RealVector mapSin() {
throw unsupported();
}
@Override
public RealVector mapSinToSelf() {
throw unsupported();
}
@Override
public RealVector mapTan() {
throw unsupported();
}
@Override
public RealVector mapTanToSelf() {
throw unsupported();
}
@Override
public RealVector mapAcos() {
throw unsupported();
}
@Override
public RealVector mapAcosToSelf() {
throw unsupported();
}
@Override
public RealVector mapAsin() {
throw unsupported();
}
@Override
public RealVector mapAsinToSelf() {
throw unsupported();
}
@Override
public RealVector mapAtan() {
throw unsupported();
}
@Override
public RealVector mapAtanToSelf() {
throw unsupported();
}
@Override
public RealVector mapInv() {
throw unsupported();
}
@Override
public RealVector mapInvToSelf() {
throw unsupported();
}
@Override
public RealVector mapAbs() {
throw unsupported();
}
@Override
public RealVector mapAbsToSelf() {
throw unsupported();
}
@Override
public RealVector mapSqrt() {
throw unsupported();
}
@Override
public RealVector mapSqrtToSelf() {
throw unsupported();
}
@Override
public RealVector mapCbrt() {
throw unsupported();
}
@Override
public RealVector mapCbrtToSelf() {
throw unsupported();
}
@Override
public RealVector mapCeil() {
throw unsupported();
}
@Override
public RealVector mapCeilToSelf() {
throw unsupported();
}
@Override
public RealVector mapFloor() {
throw unsupported();
}
@Override
public RealVector mapFloorToSelf() {
throw unsupported();
}
@Override
public RealVector mapRint() {
throw unsupported();
}
@Override
public RealVector mapRintToSelf() {
throw unsupported();
}
@Override
public RealVector mapSignum() {
throw unsupported();
}
@Override
public RealVector mapSignumToSelf() {
throw unsupported();
}
@Override
public RealVector mapUlp() {
throw unsupported();
}
@Override
public RealVector mapUlpToSelf() {
throw unsupported();
}
public RealVector ebeMultiply(RealVector v) {
throw unsupported();
}
@ -561,53 +358,55 @@ public class SparseRealVectorTest extends TestCase {
}
@Test
public void testConstructors() {
OpenMapRealVector v0 = new OpenMapRealVector();
assertEquals("testData len", 0, v0.getDimension());
Assert.assertEquals("testData len", 0, v0.getDimension());
OpenMapRealVector v1 = new OpenMapRealVector(7);
assertEquals("testData len", 7, v1.getDimension());
assertEquals("testData is 0.0 ", 0.0, v1.getEntry(6));
Assert.assertEquals("testData len", 7, v1.getDimension());
Assert.assertEquals("testData is 0.0 ", 0.0, v1.getEntry(6), 0);
OpenMapRealVector v3 = new OpenMapRealVector(vec1);
assertEquals("testData len", 3, v3.getDimension());
assertEquals("testData is 2.0 ", 2.0, v3.getEntry(1));
Assert.assertEquals("testData len", 3, v3.getDimension());
Assert.assertEquals("testData is 2.0 ", 2.0, v3.getEntry(1), 0);
//SparseRealVector v4 = new SparseRealVector(vec4, 3, 2);
//assertEquals("testData len", 2, v4.getDimension());
//assertEquals("testData is 4.0 ", 4.0, v4.getEntry(0));
//Assert.assertEquals("testData len", 2, v4.getDimension());
//Assert.assertEquals("testData is 4.0 ", 4.0, v4.getEntry(0));
//try {
// new SparseRealVector(vec4, 8, 3);
// fail("IllegalArgumentException expected");
// Assert.fail("IllegalArgumentException expected");
//} catch (IllegalArgumentException ex) {
// expected behavior
//}
RealVector v5_i = new OpenMapRealVector(dvec1);
assertEquals("testData len", 9, v5_i.getDimension());
assertEquals("testData is 9.0 ", 9.0, v5_i.getEntry(8));
Assert.assertEquals("testData len", 9, v5_i.getDimension());
Assert.assertEquals("testData is 9.0 ", 9.0, v5_i.getEntry(8), 0);
OpenMapRealVector v5 = new OpenMapRealVector(dvec1);
assertEquals("testData len", 9, v5.getDimension());
assertEquals("testData is 9.0 ", 9.0, v5.getEntry(8));
Assert.assertEquals("testData len", 9, v5.getDimension());
Assert.assertEquals("testData is 9.0 ", 9.0, v5.getEntry(8), 0);
OpenMapRealVector v7 = new OpenMapRealVector(v1);
assertEquals("testData len", 7, v7.getDimension());
assertEquals("testData is 0.0 ", 0.0, v7.getEntry(6));
Assert.assertEquals("testData len", 7, v7.getDimension());
Assert.assertEquals("testData is 0.0 ", 0.0, v7.getEntry(6), 0);
SparseRealVectorTestImpl v7_i = new SparseRealVectorTestImpl(vec1);
OpenMapRealVector v7_2 = new OpenMapRealVector(v7_i);
assertEquals("testData len", 3, v7_2.getDimension());
assertEquals("testData is 0.0 ", 2.0d, v7_2.getEntry(1));
Assert.assertEquals("testData len", 3, v7_2.getDimension());
Assert.assertEquals("testData is 0.0 ", 2.0d, v7_2.getEntry(1), 0);
OpenMapRealVector v8 = new OpenMapRealVector(v1);
assertEquals("testData len", 7, v8.getDimension());
assertEquals("testData is 0.0 ", 0.0, v8.getEntry(6));
Assert.assertEquals("testData len", 7, v8.getDimension());
Assert.assertEquals("testData is 0.0 ", 0.0, v8.getEntry(6), 0);
}
@Test
public void testDataInOut() {
OpenMapRealVector v1 = new OpenMapRealVector(vec1);
@ -616,70 +415,70 @@ public class SparseRealVectorTest extends TestCase {
SparseRealVectorTestImpl v2_t = new SparseRealVectorTestImpl(vec2);
RealVector v_append_1 = v1.append(v2);
assertEquals("testData len", 6, v_append_1.getDimension());
assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3));
Assert.assertEquals("testData len", 6, v_append_1.getDimension());
Assert.assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3), 0);
RealVector v_append_2 = v1.append(2.0);
assertEquals("testData len", 4, v_append_2.getDimension());
assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3));
Assert.assertEquals("testData len", 4, v_append_2.getDimension());
Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0);
RealVector v_append_3 = v1.append(vec2);
assertEquals("testData len", 6, v_append_3.getDimension());
assertEquals("testData is ", 4.0, v_append_3.getEntry(3));
Assert.assertEquals("testData len", 6, v_append_3.getDimension());
Assert.assertEquals("testData is ", 4.0, v_append_3.getEntry(3), 0);
RealVector v_append_4 = v1.append(v2_t);
assertEquals("testData len", 6, v_append_4.getDimension());
assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3));
Assert.assertEquals("testData len", 6, v_append_4.getDimension());
Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0);
RealVector vout5 = v4.getSubVector(3, 3);
assertEquals("testData len", 3, vout5.getDimension());
assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1));
Assert.assertEquals("testData len", 3, vout5.getDimension());
Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0);
try {
v4.getSubVector(3, 7);
fail("OutOfRangeException expected");
Assert.fail("OutOfRangeException expected");
} catch (OutOfRangeException ex) {
// expected behavior
}
OpenMapRealVector v_set1 = v1.copy();
v_set1.setEntry(1, 11.0);
assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1));
Assert.assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1), 0);
try {
v_set1.setEntry(3, 11.0);
fail("OutOfRangeException expected");
Assert.fail("OutOfRangeException expected");
} catch (OutOfRangeException ex) {
// expected behavior
}
OpenMapRealVector v_set2 = v4.copy();
v_set2.setSubVector(3, v1);
assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3));
assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6));
Assert.assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3), 0);
Assert.assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6), 0);
try {
v_set2.setSubVector(7, v1);
fail("OutOfRangeException expected");
Assert.fail("OutOfRangeException expected");
} catch (OutOfRangeException ex) {
// expected behavior
}
OpenMapRealVector v_set3 = v1.copy();
v_set3.set(13.0);
assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2));
Assert.assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2), 0);
try {
v_set3.getEntry(23);
fail("OutOfRangeException expected");
Assert.fail("OutOfRangeException expected");
} catch (OutOfRangeException ex) {
// expected behavior
}
OpenMapRealVector v_set4 = v4.copy();
v_set4.setSubVector(3, v2_t);
assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3));
assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6));
Assert.assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3), 0);
Assert.assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6), 0);
try {
v_set4.setSubVector(7, v2_t);
fail("OutOfRangeException expected");
Assert.fail("OutOfRangeException expected");
} catch (OutOfRangeException ex) {
// expected behavior
}
@ -687,6 +486,7 @@ public class SparseRealVectorTest extends TestCase {
}
@Test
public void testMapFunctions() {
OpenMapRealVector v1 = new OpenMapRealVector(vec1);
@ -746,124 +546,124 @@ public class SparseRealVectorTest extends TestCase {
assertClose("compare vectors" ,result_mapPowToSelf,v_mapPowToSelf.getData(),normTolerance);
//octave = exp(v1)
RealVector v_mapExp = v1.mapExp();
RealVector v_mapExp = v1.map(new Exp());
double[] result_mapExp = {2.718281828459045e+00d,7.389056098930650e+00d, 2.008553692318767e+01d};
assertClose("compare vectors" ,result_mapExp,v_mapExp.getData(),normTolerance);
//octave = exp(v1)
RealVector v_mapExpToSelf = v1.copy();
v_mapExpToSelf.mapExpToSelf();
v_mapExpToSelf.mapToSelf(new Exp());
double[] result_mapExpToSelf = {2.718281828459045e+00d,7.389056098930650e+00d, 2.008553692318767e+01d};
assertClose("compare vectors" ,result_mapExpToSelf,v_mapExpToSelf.getData(),normTolerance);
//octave = ???
RealVector v_mapExpm1 = v1.mapExpm1();
RealVector v_mapExpm1 = v1.map(new Expm1());
double[] result_mapExpm1 = {1.718281828459045d,6.38905609893065d, 19.085536923187668d};
assertClose("compare vectors" ,result_mapExpm1,v_mapExpm1.getData(),normTolerance);
//octave = ???
RealVector v_mapExpm1ToSelf = v1.copy();
v_mapExpm1ToSelf.mapExpm1ToSelf();
v_mapExpm1ToSelf.mapToSelf(new Expm1());
double[] result_mapExpm1ToSelf = {1.718281828459045d,6.38905609893065d, 19.085536923187668d};
assertClose("compare vectors" ,result_mapExpm1ToSelf,v_mapExpm1ToSelf.getData(),normTolerance);
//octave = log(v1)
RealVector v_mapLog = v1.mapLog();
RealVector v_mapLog = v1.map(new Log());
double[] result_mapLog = {0d,6.931471805599453e-01d, 1.098612288668110e+00d};
assertClose("compare vectors" ,result_mapLog,v_mapLog.getData(),normTolerance);
//octave = log(v1)
RealVector v_mapLogToSelf = v1.copy();
v_mapLogToSelf.mapLogToSelf();
v_mapLogToSelf.mapToSelf(new Log());
double[] result_mapLogToSelf = {0d,6.931471805599453e-01d, 1.098612288668110e+00d};
assertClose("compare vectors" ,result_mapLogToSelf,v_mapLogToSelf.getData(),normTolerance);
//octave = log10(v1)
RealVector v_mapLog10 = v1.mapLog10();
RealVector v_mapLog10 = v1.map(new Log10());
double[] result_mapLog10 = {0d,3.010299956639812e-01d, 4.771212547196624e-01d};
assertClose("compare vectors" ,result_mapLog10,v_mapLog10.getData(),normTolerance);
//octave = log(v1)
RealVector v_mapLog10ToSelf = v1.copy();
v_mapLog10ToSelf.mapLog10ToSelf();
v_mapLog10ToSelf.mapToSelf(new Log10());
double[] result_mapLog10ToSelf = {0d,3.010299956639812e-01d, 4.771212547196624e-01d};
assertClose("compare vectors" ,result_mapLog10ToSelf,v_mapLog10ToSelf.getData(),normTolerance);
//octave = ???
RealVector v_mapLog1p = v1.mapLog1p();
RealVector v_mapLog1p = v1.map(new Log1p());
double[] result_mapLog1p = {0.6931471805599453d,1.0986122886681096d,1.3862943611198906d};
assertClose("compare vectors" ,result_mapLog1p,v_mapLog1p.getData(),normTolerance);
//octave = ???
RealVector v_mapLog1pToSelf = v1.copy();
v_mapLog1pToSelf.mapLog1pToSelf();
v_mapLog1pToSelf.mapToSelf(new Log1p());
double[] result_mapLog1pToSelf = {0.6931471805599453d,1.0986122886681096d,1.3862943611198906d};
assertClose("compare vectors" ,result_mapLog1pToSelf,v_mapLog1pToSelf.getData(),normTolerance);
//octave = cosh(v1)
RealVector v_mapCosh = v1.mapCosh();
RealVector v_mapCosh = v1.map(new Cosh());
double[] result_mapCosh = {1.543080634815244e+00d,3.762195691083631e+00d, 1.006766199577777e+01d};
assertClose("compare vectors" ,result_mapCosh,v_mapCosh.getData(),normTolerance);
//octave = cosh(v1)
RealVector v_mapCoshToSelf = v1.copy();
v_mapCoshToSelf.mapCoshToSelf();
v_mapCoshToSelf.mapToSelf(new Cosh());
double[] result_mapCoshToSelf = {1.543080634815244e+00d,3.762195691083631e+00d, 1.006766199577777e+01d};
assertClose("compare vectors" ,result_mapCoshToSelf,v_mapCoshToSelf.getData(),normTolerance);
//octave = sinh(v1)
RealVector v_mapSinh = v1.mapSinh();
RealVector v_mapSinh = v1.map(new Sinh());
double[] result_mapSinh = {1.175201193643801e+00d,3.626860407847019e+00d, 1.001787492740990e+01d};
assertClose("compare vectors" ,result_mapSinh,v_mapSinh.getData(),normTolerance);
//octave = sinh(v1)
RealVector v_mapSinhToSelf = v1.copy();
v_mapSinhToSelf.mapSinhToSelf();
v_mapSinhToSelf.mapToSelf(new Sinh());
double[] result_mapSinhToSelf = {1.175201193643801e+00d,3.626860407847019e+00d, 1.001787492740990e+01d};
assertClose("compare vectors" ,result_mapSinhToSelf,v_mapSinhToSelf.getData(),normTolerance);
//octave = tanh(v1)
RealVector v_mapTanh = v1.mapTanh();
RealVector v_mapTanh = v1.map(new Tanh());
double[] result_mapTanh = {7.615941559557649e-01d,9.640275800758169e-01d,9.950547536867305e-01d};
assertClose("compare vectors" ,result_mapTanh,v_mapTanh.getData(),normTolerance);
//octave = tanh(v1)
RealVector v_mapTanhToSelf = v1.copy();
v_mapTanhToSelf.mapTanhToSelf();
v_mapTanhToSelf.mapToSelf(new Tanh());
double[] result_mapTanhToSelf = {7.615941559557649e-01d,9.640275800758169e-01d,9.950547536867305e-01d};
assertClose("compare vectors" ,result_mapTanhToSelf,v_mapTanhToSelf.getData(),normTolerance);
//octave = cos(v1)
RealVector v_mapCos = v1.mapCos();
RealVector v_mapCos = v1.map(new Cos());
double[] result_mapCos = {5.403023058681398e-01d,-4.161468365471424e-01d, -9.899924966004454e-01d};
assertClose("compare vectors" ,result_mapCos,v_mapCos.getData(),normTolerance);
//octave = cos(v1)
RealVector v_mapCosToSelf = v1.copy();
v_mapCosToSelf.mapCosToSelf();
v_mapCosToSelf.mapToSelf(new Cos());
double[] result_mapCosToSelf = {5.403023058681398e-01d,-4.161468365471424e-01d, -9.899924966004454e-01d};
assertClose("compare vectors" ,result_mapCosToSelf,v_mapCosToSelf.getData(),normTolerance);
//octave = sin(v1)
RealVector v_mapSin = v1.mapSin();
RealVector v_mapSin = v1.map(new Sin());
double[] result_mapSin = {8.414709848078965e-01d,9.092974268256817e-01d,1.411200080598672e-01d};
assertClose("compare vectors" ,result_mapSin,v_mapSin.getData(),normTolerance);
//octave = sin(v1)
RealVector v_mapSinToSelf = v1.copy();
v_mapSinToSelf.mapSinToSelf();
v_mapSinToSelf.mapToSelf(new Sin());
double[] result_mapSinToSelf = {8.414709848078965e-01d,9.092974268256817e-01d,1.411200080598672e-01d};
assertClose("compare vectors" ,result_mapSinToSelf,v_mapSinToSelf.getData(),normTolerance);
//octave = tan(v1)
RealVector v_mapTan = v1.mapTan();
RealVector v_mapTan = v1.map(new Tan());
double[] result_mapTan = {1.557407724654902e+00d,-2.185039863261519e+00d,-1.425465430742778e-01d};
assertClose("compare vectors" ,result_mapTan,v_mapTan.getData(),normTolerance);
//octave = tan(v1)
RealVector v_mapTanToSelf = v1.copy();
v_mapTanToSelf.mapTanToSelf();
v_mapTanToSelf.mapToSelf(new Tan());
double[] result_mapTanToSelf = {1.557407724654902e+00d,-2.185039863261519e+00d,-1.425465430742778e-01d};
assertClose("compare vectors" ,result_mapTanToSelf,v_mapTanToSelf.getData(),normTolerance);
@ -871,46 +671,46 @@ public class SparseRealVectorTest extends TestCase {
OpenMapRealVector vat = new OpenMapRealVector(vat_a);
//octave = acos(vat)
RealVector v_mapAcos = vat.mapAcos();
RealVector v_mapAcos = vat.map(new Acos());
double[] result_mapAcos = {1.570796326794897e+00d,1.047197551196598e+00d, 0.0d};
assertClose("compare vectors" ,result_mapAcos,v_mapAcos.getData(),normTolerance);
//octave = acos(vat)
RealVector v_mapAcosToSelf = vat.copy();
v_mapAcosToSelf.mapAcosToSelf();
v_mapAcosToSelf.mapToSelf(new Acos());
double[] result_mapAcosToSelf = {1.570796326794897e+00d,1.047197551196598e+00d, 0.0d};
assertClose("compare vectors" ,result_mapAcosToSelf,v_mapAcosToSelf.getData(),normTolerance);
//octave = asin(vat)
RealVector v_mapAsin = vat.mapAsin();
RealVector v_mapAsin = vat.map(new Asin());
double[] result_mapAsin = {0.0d,5.235987755982989e-01d,1.570796326794897e+00d};
assertClose("compare vectors" ,result_mapAsin,v_mapAsin.getData(),normTolerance);
//octave = asin(vat)
RealVector v_mapAsinToSelf = vat.copy();
v_mapAsinToSelf.mapAsinToSelf();
v_mapAsinToSelf.mapToSelf(new Asin());
double[] result_mapAsinToSelf = {0.0d,5.235987755982989e-01d,1.570796326794897e+00d};
assertClose("compare vectors" ,result_mapAsinToSelf,v_mapAsinToSelf.getData(),normTolerance);
//octave = atan(vat)
RealVector v_mapAtan = vat.mapAtan();
RealVector v_mapAtan = vat.map(new Atan());
double[] result_mapAtan = {0.0d,4.636476090008061e-01d,7.853981633974483e-01d};
assertClose("compare vectors" ,result_mapAtan,v_mapAtan.getData(),normTolerance);
//octave = atan(vat)
RealVector v_mapAtanToSelf = vat.copy();
v_mapAtanToSelf.mapAtanToSelf();
v_mapAtanToSelf.mapToSelf(new Atan());
double[] result_mapAtanToSelf = {0.0d,4.636476090008061e-01d,7.853981633974483e-01d};
assertClose("compare vectors" ,result_mapAtanToSelf,v_mapAtanToSelf.getData(),normTolerance);
//octave = v1 .^-1
RealVector v_mapInv = v1.mapInv();
RealVector v_mapInv = v1.map(new Inverse());
double[] result_mapInv = {1d,0.5d,3.333333333333333e-01d};
assertClose("compare vectors" ,result_mapInv,v_mapInv.getData(),normTolerance);
//octave = v1 .^-1
RealVector v_mapInvToSelf = v1.copy();
v_mapInvToSelf.mapInvToSelf();
v_mapInvToSelf.mapToSelf(new Inverse());
double[] result_mapInvToSelf = {1d,0.5d,3.333333333333333e-01d};
assertClose("compare vectors" ,result_mapInvToSelf,v_mapInvToSelf.getData(),normTolerance);
@ -918,24 +718,24 @@ public class SparseRealVectorTest extends TestCase {
OpenMapRealVector abs_v = new OpenMapRealVector(abs_a);
//octave = abs(abs_v)
RealVector v_mapAbs = abs_v.mapAbs();
RealVector v_mapAbs = abs_v.map(new Abs());
double[] result_mapAbs = {1d,0d,1d};
assertClose("compare vectors" ,result_mapAbs,v_mapAbs.getData(),normTolerance);
//octave = abs(abs_v)
RealVector v_mapAbsToSelf = abs_v.copy();
v_mapAbsToSelf.mapAbsToSelf();
v_mapAbsToSelf.mapToSelf(new Abs());
double[] result_mapAbsToSelf = {1d,0d,1d};
assertClose("compare vectors" ,result_mapAbsToSelf,v_mapAbsToSelf.getData(),normTolerance);
//octave = sqrt(v1)
RealVector v_mapSqrt = v1.mapSqrt();
RealVector v_mapSqrt = v1.map(new Sqrt());
double[] result_mapSqrt = {1d,1.414213562373095e+00d,1.732050807568877e+00d};
assertClose("compare vectors" ,result_mapSqrt,v_mapSqrt.getData(),normTolerance);
//octave = sqrt(v1)
RealVector v_mapSqrtToSelf = v1.copy();
v_mapSqrtToSelf.mapSqrtToSelf();
v_mapSqrtToSelf.mapToSelf(new Sqrt());
double[] result_mapSqrtToSelf = {1d,1.414213562373095e+00d,1.732050807568877e+00d};
assertClose("compare vectors" ,result_mapSqrtToSelf,v_mapSqrtToSelf.getData(),normTolerance);
@ -943,13 +743,13 @@ public class SparseRealVectorTest extends TestCase {
OpenMapRealVector cbrt_v = new OpenMapRealVector(cbrt_a);
//octave = ???
RealVector v_mapCbrt = cbrt_v.mapCbrt();
RealVector v_mapCbrt = cbrt_v.map(new Cbrt());
double[] result_mapCbrt = {-1.2599210498948732d,0d,1.2599210498948732d};
assertClose("compare vectors" ,result_mapCbrt,v_mapCbrt.getData(),normTolerance);
//octave = ???
RealVector v_mapCbrtToSelf = cbrt_v.copy();
v_mapCbrtToSelf.mapCbrtToSelf();
v_mapCbrtToSelf.mapToSelf(new Cbrt());
double[] result_mapCbrtToSelf = {-1.2599210498948732d,0d,1.2599210498948732d};
assertClose("compare vectors" ,result_mapCbrtToSelf,v_mapCbrtToSelf.getData(),normTolerance);
@ -957,64 +757,64 @@ public class SparseRealVectorTest extends TestCase {
OpenMapRealVector ceil_v = new OpenMapRealVector(ceil_a);
//octave = ceil(ceil_v)
RealVector v_mapCeil = ceil_v.mapCeil();
RealVector v_mapCeil = ceil_v.map(new Ceil());
double[] result_mapCeil = {-1d,1d,2d};
assertClose("compare vectors" ,result_mapCeil,v_mapCeil.getData(),normTolerance);
//octave = ceil(ceil_v)
RealVector v_mapCeilToSelf = ceil_v.copy();
v_mapCeilToSelf.mapCeilToSelf();
v_mapCeilToSelf.mapToSelf(new Ceil());
double[] result_mapCeilToSelf = {-1d,1d,2d};
assertClose("compare vectors" ,result_mapCeilToSelf,v_mapCeilToSelf.getData(),normTolerance);
//octave = floor(ceil_v)
RealVector v_mapFloor = ceil_v.mapFloor();
RealVector v_mapFloor = ceil_v.map(new Floor());
double[] result_mapFloor = {-2d,0d,1d};
assertClose("compare vectors" ,result_mapFloor,v_mapFloor.getData(),normTolerance);
//octave = floor(ceil_v)
RealVector v_mapFloorToSelf = ceil_v.copy();
v_mapFloorToSelf.mapFloorToSelf();
v_mapFloorToSelf.mapToSelf(new Floor());
double[] result_mapFloorToSelf = {-2d,0d,1d};
assertClose("compare vectors" ,result_mapFloorToSelf,v_mapFloorToSelf.getData(),normTolerance);
//octave = ???
RealVector v_mapRint = ceil_v.mapRint();
RealVector v_mapRint = ceil_v.map(new Rint());
double[] result_mapRint = {-1d,1d,1d};
assertClose("compare vectors" ,result_mapRint,v_mapRint.getData(),normTolerance);
//octave = ???
RealVector v_mapRintToSelf = ceil_v.copy();
v_mapRintToSelf.mapRintToSelf();
v_mapRintToSelf.mapToSelf(new Rint());
double[] result_mapRintToSelf = {-1d,1d,1d};
assertClose("compare vectors" ,result_mapRintToSelf,v_mapRintToSelf.getData(),normTolerance);
//octave = ???
RealVector v_mapSignum = ceil_v.mapSignum();
RealVector v_mapSignum = ceil_v.map(new Signum());
double[] result_mapSignum = {-1d,1d,1d};
assertClose("compare vectors" ,result_mapSignum,v_mapSignum.getData(),normTolerance);
//octave = ???
RealVector v_mapSignumToSelf = ceil_v.copy();
v_mapSignumToSelf.mapSignumToSelf();
v_mapSignumToSelf.mapToSelf(new Signum());
double[] result_mapSignumToSelf = {-1d,1d,1d};
assertClose("compare vectors" ,result_mapSignumToSelf,v_mapSignumToSelf.getData(),normTolerance);
// Is with the used resolutions of limited value as test
//octave = ???
RealVector v_mapUlp = ceil_v.mapUlp();
RealVector v_mapUlp = ceil_v.map(new Ulp());
double[] result_mapUlp = {2.220446049250313E-16d,1.1102230246251565E-16d,2.220446049250313E-16d};
assertClose("compare vectors" ,result_mapUlp,v_mapUlp.getData(),normTolerance);
//octave = ???
RealVector v_mapUlpToSelf = ceil_v.copy();
v_mapUlpToSelf.mapUlpToSelf();
v_mapUlpToSelf.mapToSelf(new Ulp());
double[] result_mapUlpToSelf = {2.220446049250313E-16d,1.1102230246251565E-16d,2.220446049250313E-16d};
assertClose("compare vectors" ,result_mapUlpToSelf,v_mapUlpToSelf.getData(),normTolerance);
}
@Test
public void testBasicFunctions() {
OpenMapRealVector v1 = new OpenMapRealVector(vec1);
OpenMapRealVector v2 = new OpenMapRealVector(vec2);
@ -1025,37 +825,37 @@ public class SparseRealVectorTest extends TestCase {
// emacs calc: [-4, 0, 3, 1, -6, 3] A --> 8.4261497731763586307
double d_getNorm = v5.getNorm();
assertEquals("compare values ", 8.4261497731763586307, d_getNorm);
Assert.assertEquals("compare values ", 8.4261497731763586307, d_getNorm, normTolerance);
// emacs calc: [-4, 0, 3, 1, -6, 3] vN --> 17
double d_getL1Norm = v5.getL1Norm();
assertEquals("compare values ", 17.0, d_getL1Norm);
Assert.assertEquals("compare values ", 17.0, d_getL1Norm, normTolerance);
// emacs calc: [-4, 0, 3, 1, -6, 3] vn --> 6
double d_getLInfNorm = v5.getLInfNorm();
assertEquals("compare values ", 6.0, d_getLInfNorm);
Assert.assertEquals("compare values ", 6.0, d_getLInfNorm, normTolerance);
//octave = sqrt(sumsq(v1-v2))
double dist = v1.getDistance(v2);
assertEquals("compare values ",v1.subtract(v2).getNorm(), dist );
Assert.assertEquals("compare values ",v1.subtract(v2).getNorm(), dist, normTolerance);
//octave = sqrt(sumsq(v1-v2))
double dist_2 = v1.getDistance(v2_t);
assertEquals("compare values ", v1.subtract(v2).getNorm(),dist_2 );
Assert.assertEquals("compare values ", v1.subtract(v2).getNorm(),dist_2, normTolerance);
//octave = ???
double d_getL1Distance = v1. getL1Distance(v2);
assertEquals("compare values ",9d, d_getL1Distance );
Assert.assertEquals("compare values ", 9d, d_getL1Distance, normTolerance);
double d_getL1Distance_2 = v1. getL1Distance(v2_t);
assertEquals("compare values ",9d, d_getL1Distance_2 );
Assert.assertEquals("compare values ", 9d, d_getL1Distance_2, normTolerance);
//octave = ???
double d_getLInfDistance = v1. getLInfDistance(v2);
assertEquals("compare values ",3d, d_getLInfDistance );
Assert.assertEquals("compare values ", 3d, d_getLInfDistance, normTolerance);
double d_getLInfDistance_2 = v1. getLInfDistance(v2_t);
assertEquals("compare values ",3d, d_getLInfDistance_2 );
Assert.assertEquals("compare values ", 3d, d_getLInfDistance_2, normTolerance);
//octave = v1 + v2
OpenMapRealVector v_add = v1.add(v2);
@ -1096,17 +896,17 @@ public class SparseRealVectorTest extends TestCase {
// octave dot(v1,v2)
double dot = v1.dotProduct(v2);
assertEquals("compare val ",32d, dot);
Assert.assertEquals("compare val ",32d, dot, normTolerance);
// octave dot(v1,v2_t)
double dot_2 = v1.dotProduct(v2_t);
assertEquals("compare val ",32d, dot_2);
Assert.assertEquals("compare val ",32d, dot_2, normTolerance);
RealMatrix m_outerProduct = v1.outerProduct(v2);
assertEquals("compare val ",4d, m_outerProduct.getEntry(0,0));
Assert.assertEquals("compare val ",4d, m_outerProduct.getEntry(0,0), normTolerance);
RealMatrix m_outerProduct_2 = v1.outerProduct(v2_t);
assertEquals("compare val ",4d, m_outerProduct_2.getEntry(0,0));
Assert.assertEquals("compare val ",4d, m_outerProduct_2.getEntry(0,0), normTolerance);
RealVector v_unitVector = v1.unitVector();
RealVector v_unitVector_2 = v1.mapDivide(v1.getNorm());
@ -1114,7 +914,7 @@ public class SparseRealVectorTest extends TestCase {
try {
v_null.unitVector();
fail("Expecting ArithmeticException");
Assert.fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {
// expected behavior
}
@ -1124,7 +924,7 @@ public class SparseRealVectorTest extends TestCase {
assertClose("compare vect" ,v_unitVector_2.getData(),v_unitize.getData(),normTolerance);
try {
v_null.unitize();
fail("Expecting ArithmeticException");
Assert.fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {
// expected behavior
}
@ -1139,14 +939,15 @@ public class SparseRealVectorTest extends TestCase {
}
@Test
public void testMisc() {
OpenMapRealVector v1 = new OpenMapRealVector(vec1);
String out1 = v1.toString();
assertTrue("some output ", out1.length()!=0);
Assert.assertTrue("some output ", out1.length()!=0);
try {
v1.checkVectorDimensions(2);
fail("IllegalArgumentException expected");
Assert.fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected behavior
}
@ -1154,41 +955,42 @@ public class SparseRealVectorTest extends TestCase {
}
@Test
public void testPredicates() {
OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
assertFalse(v.isNaN());
Assert.assertFalse(v.isNaN());
v.setEntry(1, Double.NaN);
assertTrue(v.isNaN());
Assert.assertTrue(v.isNaN());
assertFalse(v.isInfinite());
Assert.assertFalse(v.isInfinite());
v.setEntry(0, Double.POSITIVE_INFINITY);
assertFalse(v.isInfinite()); // NaN has higher priority than infinity
Assert.assertFalse(v.isInfinite()); // NaN has higher priority than infinity
v.setEntry(1, 1);
assertTrue(v.isInfinite());
Assert.assertTrue(v.isInfinite());
v.setEntry(0, 0);
assertEquals(v, new OpenMapRealVector(new double[] { 0, 1, 2 }));
assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2 + FastMath.ulp(2)}));
assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2, 3 }));
Assert.assertEquals(v, new OpenMapRealVector(new double[] { 0, 1, 2 }));
Assert.assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2 + FastMath.ulp(2)}));
Assert.assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2, 3 }));
}
@Test
public void testSerial() {
OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
assertEquals(v,TestUtils.serializeAndRecover(v));
Assert.assertEquals(v,TestUtils.serializeAndRecover(v));
}
/** verifies that two vectors are close (sup norm) */
protected void assertClose(String msg, double[] m, double[] n,
double tolerance) {
if (m.length != n.length) {
fail("vectors have different lengths");
Assert.fail("vectors have different lengths");
}
for (int i = 0; i < m.length; i++) {
assertEquals(msg + " " + i + " elements differ", m[i],n[i],tolerance);
Assert.assertEquals(msg + " " + i + " elements differ", m[i],n[i],tolerance);
}
}
}