org.tensorics.core.lang.TensoricExpressions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tensorics-core Show documentation
Show all versions of tensorics-core Show documentation
Tensorics is a java framework which uses a tensor as a central object. A tensor represents a set of values placed in an N-dimensional space. Wherever you are tempted to use maps of maps, a tensor might be a good choice ;-) Tensorics provides methods to create, transform and performing calculations with those tensors.
/**
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
*/
package org.tensorics.core.lang;
import static java.lang.String.format;
import java.util.List;
import org.tensorics.core.functional.FiniteArgumentFunction;
import org.tensorics.core.functional.Func1;
import org.tensorics.core.functional.Func2;
import org.tensorics.core.functional.Func3;
import org.tensorics.core.functional.Func4;
import org.tensorics.core.functional.Func5;
import org.tensorics.core.functional.Func6;
import org.tensorics.core.functional.Func7;
import org.tensorics.core.functional.Func8;
import org.tensorics.core.functional.Func9;
import org.tensorics.core.functional.FuncN;
import org.tensorics.core.functional.expressions.FunctionalExpression;
import org.tensorics.core.tree.domain.Expression;
import com.google.common.collect.ImmutableList;
public final class TensoricExpressions {
private TensoricExpressions() {
/* Only static methods */
}
// TODO zero argument case?
// TODO N argument case?
public static OngoingLambdaExpressionCreation> use(Expression t1) {
return new OngoingLambdaExpressionCreation<>(t1);
}
public static OngoingLambdaExpressionCreation> use(Expression t1, Expression t2) {
return new OngoingLambdaExpressionCreation<>(t1, t2);
}
public static OngoingLambdaExpressionCreation> use(Expression t1,
Expression t2, Expression t3) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3);
}
public static OngoingLambdaExpressionCreation> use(Expression t1,
Expression t2, Expression t3, Expression t4) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3, t4);
}
public static OngoingLambdaExpressionCreation> use(
Expression t1, Expression t2, Expression t3, Expression t4, Expression t5) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3, t4, t5);
}
public static OngoingLambdaExpressionCreation> use(
Expression t1, Expression t2, Expression t3, Expression t4, Expression t5,
Expression t6) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3, t4, t5, t6);
}
public static OngoingLambdaExpressionCreation> use(
Expression t1, Expression t2, Expression t3, Expression t4, Expression t5,
Expression t6, Expression t7) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3, t4, t5, t6, t7);
}
public static OngoingLambdaExpressionCreation> use(
Expression t1, Expression t2, Expression t3, Expression t4, Expression t5,
Expression t6, Expression t7, Expression t8) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3, t4, t5, t6, t7, t8);
}
public static OngoingLambdaExpressionCreation> use(
Expression t1, Expression t2, Expression t3, Expression t4, Expression t5,
Expression t6, Expression t7, Expression t8, Expression t9) {
return new OngoingLambdaExpressionCreation<>(t1, t2, t3, t4, t5, t6, t7, t8, t9);
}
public static class OngoingLambdaExpressionCreation> {
private final List> arguments;
public OngoingLambdaExpressionCreation(Expression... arguments) {
this.arguments = ImmutableList.copyOf(arguments);
}
@SuppressWarnings("unchecked")
public Expression in(F function) {
if (arguments.size() != function.numberOfArgs()) {
throw new IllegalStateException(format(
"The number of arguments for the function '%s' does not match the given arguments. "
+ "Required %s but was %s. "
+ "This should never happen, do not instantiate this class directly.",
function, function.numberOfArgs(), arguments.size()));
}
return new FunctionalExpression<>(arguments, (FuncN) function.toFuncN());
}
}
}