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) {
}
}
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));
}
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) {
}
}
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;
}
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());
}
}
Aggregations