Search in sources :

Example 1 with DoubleUnaryOperator

use of java.util.function.DoubleUnaryOperator in project j2objc by google.

the class DoubleUnaryOperatorTest method testAndThen_null.

public void testAndThen_null() throws Exception {
    DoubleUnaryOperator plusOne = x -> x + 1.0d;
    try {
        plusOne.andThen(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : TestCase(junit.framework.TestCase) Comparator(java.util.Comparator) BinaryOperator(java.util.function.BinaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 2 with DoubleUnaryOperator

use of java.util.function.DoubleUnaryOperator in project j2objc by google.

the class DoubleUnaryOperatorTest method testAndThen.

public void testAndThen() throws Exception {
    DoubleUnaryOperator plusOne = x -> x + 1.0d;
    DoubleUnaryOperator twice = x -> 2 * x;
    assertEquals(12.0d, plusOne.andThen(twice).applyAsDouble(5.0d));
}
Also used : TestCase(junit.framework.TestCase) Comparator(java.util.Comparator) BinaryOperator(java.util.function.BinaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 3 with DoubleUnaryOperator

use of java.util.function.DoubleUnaryOperator in project j2objc by google.

the class DoubleUnaryOperatorTest method testCompose_null.

public void testCompose_null() throws Exception {
    DoubleUnaryOperator plusOne = x -> x + 1.0d;
    try {
        plusOne.compose(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : TestCase(junit.framework.TestCase) Comparator(java.util.Comparator) BinaryOperator(java.util.function.BinaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 4 with DoubleUnaryOperator

use of java.util.function.DoubleUnaryOperator in project symja_android_library by axkr.

the class EvalEngine method evalASTArg1.

/**
	 * Evaluate an AST with only one argument (i.e. <code>head[arg1]</code>). The evaluation steps are controlled by the
	 * header attributes.
	 * 
	 * @param ast
	 * @return
	 */
private IExpr evalASTArg1(final IAST ast) {
    // special case ast.isAST1()
    // head == ast[0] --- arg1 == ast[1]
    IExpr result = ast.head().evaluateHead(ast, this);
    if (result.isPresent()) {
        return result;
    }
    final ISymbol symbol = ast.topHead();
    final int attr = symbol.getAttributes();
    if ((result = flattenSequences(ast)).isPresent()) {
        return result;
    }
    if ((ISymbol.FLAT & attr) == ISymbol.FLAT) {
        final IExpr arg1 = ast.arg1();
        if (arg1.topHead().equals(symbol)) {
            // associative
            return arg1;
        }
    }
    if ((result = evalArgs(ast, attr)).isPresent()) {
        return result;
    }
    if ((ISymbol.LISTABLE & attr) == ISymbol.LISTABLE) {
        final IExpr arg1 = ast.arg1();
        if (arg1.isRealVector() && ((IAST) arg1).size() > 1) {
            if (symbol.isBuiltInSymbol()) {
                final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
                if (module instanceof DoubleUnaryOperator) {
                    DoubleUnaryOperator oper = (DoubleUnaryOperator) module;
                    return ASTRealVector.map((IAST) arg1, oper);
                }
            }
        } else if (arg1.isRealMatrix()) {
            if (symbol.isBuiltInSymbol()) {
                final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
                if (module instanceof DoubleUnaryOperator) {
                    DoubleUnaryOperator oper = (DoubleUnaryOperator) module;
                    return ASTRealMatrix.map((IAST) arg1, oper);
                }
            }
        }
        if (arg1.isList()) {
            // thread over the list
            return EvalAttributes.threadList(ast, F.List, ast.head(), ((IAST) arg1).size() - 1);
        }
    }
    if ((ISymbol.NUMERICFUNCTION & attr) == ISymbol.NUMERICFUNCTION) {
        if (ast.arg1().isIndeterminate()) {
            return F.Indeterminate;
        }
    }
    if (!(ast.arg1() instanceof IPatternObject)) {
        final IExpr arg1 = ast.arg1();
        ISymbol lhsSymbol = null;
        if (arg1.isSymbol()) {
            lhsSymbol = (ISymbol) arg1;
        } else {
            lhsSymbol = arg1.topHead();
        }
        if ((result = lhsSymbol.evalUpRule(this, ast)).isPresent()) {
            return result;
        }
    }
    return F.NIL;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) ISymbol(org.matheclipse.core.interfaces.ISymbol) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 5 with DoubleUnaryOperator

use of java.util.function.DoubleUnaryOperator in project gatk by broadinstitute.

the class MathUtilsUnitTest method testApplyToArrayInPlace.

@Test
public void testApplyToArrayInPlace() {
    for (final double[] array : testArrays) {
        final double[] copy = Arrays.copyOf(array, array.length);
        final DoubleUnaryOperator func = Math::exp;
        final double[] result = MathUtils.applyToArrayInPlace(copy, func);
        Assert.assertTrue(result == copy);
        //make sure original array WAS affected
        Assert.assertEquals(copy, Arrays.stream(array).map(func).toArray());
    }
}
Also used : DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

DoubleUnaryOperator (java.util.function.DoubleUnaryOperator)9 Comparator (java.util.Comparator)4 BinaryOperator (java.util.function.BinaryOperator)4 TestCase (junit.framework.TestCase)4 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 DoubleStream (java.util.stream.DoubleStream)2 Stream (java.util.stream.Stream)2 ArrayUtils (org.apache.commons.lang3.ArrayUtils)2 Pair (org.apache.commons.math3.util.Pair)2 GATKProtectedMathUtils (org.broadinstitute.hellbender.utils.GATKProtectedMathUtils)2 Utils (org.broadinstitute.hellbender.utils.Utils)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 Test (org.testng.annotations.Test)2 IAST (org.matheclipse.core.interfaces.IAST)1 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)1 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1