All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tensorics.core.lang.TensoricExpressionSupport Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 0.0.81
Show newest version
// @formatter:off
 /*******************************************************************************
 *
 * This file is part of tensorics.
 * 
 * Copyright (c) 2008-2011, CERN. All rights reserved.
 *
 * Licensed 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.
 * 
 ******************************************************************************/
// @formatter:on

package org.tensorics.core.lang;

import java.util.Comparator;

import org.tensorics.core.commons.operations.Conversion;
import org.tensorics.core.commons.options.ManipulationOption;
import org.tensorics.core.function.DiscreteFunction;
import org.tensorics.core.function.lang.FunctionExpressionSupport;
import org.tensorics.core.function.lang.FunctionExpressionSupportWithConversionAndComparator;
import org.tensorics.core.function.lang.OngoingDeferredDiscreteFunctionBinaryOperation;
import org.tensorics.core.iterable.lang.OngoingDeferredIterableBinaryPredicate;
import org.tensorics.core.quantity.QuantifiedValue;
import org.tensorics.core.quantity.lang.OngoingDeferredQuantifiedScalarOperation;
import org.tensorics.core.scalar.lang.OngoingDeferredBinaryOperation;
import org.tensorics.core.scalar.lang.OngoingDeferredBinaryPredicate;
import org.tensorics.core.tensor.Shape;
import org.tensorics.core.tensor.Tensor;
import org.tensorics.core.tensor.lang.OngoingDeferredQuantifiedTensorOperation;
import org.tensorics.core.tensor.lang.OngoingDeferredTensorOperation;
import org.tensorics.core.tensor.lang.QuantityTensorExpressionSupport;
import org.tensorics.core.tensor.lang.TensorExpressionSupport;
import org.tensorics.core.tensorbacked.Tensorbacked;
import org.tensorics.core.tensorbacked.lang.OngoingDeferredQuantifiedTensorBackedOperation;
import org.tensorics.core.tensorbacked.lang.OngoingDeferredTensorBackedOperation;
import org.tensorics.core.tensorbacked.lang.QuantityTensorbackedExpressionSupport;
import org.tensorics.core.tensorbacked.lang.TensorbackedExpressionSupport;
import org.tensorics.core.tree.domain.Expression;
import org.tensorics.core.units.Unit;

/**
 * Mixes together the quantified versions of the operations and the basic tensor operations. Contains delegation methods
 * only!
 * 
 * @author kfuchsbe
 * @param  The type of the values of the tensors
 */
@SuppressWarnings("PMD.TooManyMethods")
public class TensoricExpressionSupport {

    private final TensorExpressionSupport tensoricFieldUsage;
    private final TensorbackedExpressionSupport tensorbackedExpressionSupport;
    private final QuantityTensorExpressionSupport quantifiedTensoricFieldUsage;
    private final QuantityTensorbackedExpressionSupport quantityTensorbackedExpressionSupport;
    private final FunctionExpressionSupport functionExpressionSupport;

    private final EnvironmentImpl environment;

    public TensoricExpressionSupport(EnvironmentImpl environment) {
        this.tensoricFieldUsage = new TensorExpressionSupport<>(environment);
        this.tensorbackedExpressionSupport = new TensorbackedExpressionSupport<>(environment);
        this.quantifiedTensoricFieldUsage = new QuantityTensorExpressionSupport<>(environment);
        this.quantityTensorbackedExpressionSupport = new QuantityTensorbackedExpressionSupport<>(environment);
        this.functionExpressionSupport = new FunctionExpressionSupport<>(environment);
        this.environment = environment;
    }

    public TensoricExpressionSupport with(ManipulationOption newOption) {
        return new TensoricExpressionSupport<>(environment.with(newOption));
    }

    public final Expression negativeOf(V element) {
        return tensoricFieldUsage.negativeOf(element);
    }

    public final Expression negativeOf(Expression element) {
        return tensoricFieldUsage.negativeOf(element);
    }

    public final Expression inverseOf(V element) {
        return tensoricFieldUsage.inverseOf(element);
    }

    public final Expression averageOf(Iterable iterable) {
        return tensoricFieldUsage.averageOf(iterable);
    }

    public final Expression inverseOf(Expression element) {
        return tensoricFieldUsage.inverseOf(element);
    }

    public final Expression averageOf(Expression> iterableExpression) {
        return tensoricFieldUsage.averageOf(iterableExpression);
    }

    public final V zero() {
        return tensoricFieldUsage.zero();
    }

    public final Expression sizeOf(Iterable iterable) {
        return tensoricFieldUsage.sizeOf(iterable);
    }

    public final V two() {
        return tensoricFieldUsage.two();
    }

    public final V one() {
        return tensoricFieldUsage.one();
    }

    public final Expression sizeOf(Expression> iterableExpression) {
        return tensoricFieldUsage.sizeOf(iterableExpression);
    }

    public Expression squareRootOf(V value) {
        return tensoricFieldUsage.squareRootOf(value);
    }

    public Expression squareRootOf(Expression value) {
        return tensoricFieldUsage.squareRootOf(value);
    }

    public final Expression sumOf(Iterable iterable) {
        return tensoricFieldUsage.sumOf(iterable);
    }

    public Expression squareOf(V value) {
        return tensoricFieldUsage.squareOf(value);
    }

    public final Expression sumOf(Expression> iterableExpression) {
        return tensoricFieldUsage.sumOf(iterableExpression);
    }

    public Expression squareOf(Expression value) {
        return tensoricFieldUsage.squareOf(value);
    }

    public final  OngoingDeferredTensorOperation calculateT(Expression> tensoric) {
        return tensoricFieldUsage.calculateT(tensoric);
    }

    public Expression rmsOf(Iterable iterable) {
        return tensoricFieldUsage.rmsOf(iterable);
    }

    public OngoingDeferredBinaryOperation calculate(V left) {
        return tensoricFieldUsage.calculate(left);
    }

    public Expression rmsOf(Expression> iterableExpression) {
        return tensoricFieldUsage.rmsOf(iterableExpression);
    }

    public OngoingDeferredBinaryOperation calculate(Expression left) {
        return tensoricFieldUsage.calculate(left);
    }

    public Expression sumOfSquaresOf(Iterable iterable) {
        return tensoricFieldUsage.sumOfSquaresOf(iterable);
    }

    public final  Expression> zeros(Shape shape) {
        return tensoricFieldUsage.zeros(shape);
    }

    public Expression sumOfSquaresOf(Expression> iterableExpression) {
        return tensoricFieldUsage.sumOfSquaresOf(iterableExpression);
    }

    public final  Expression> ones(Shape shape) {
        return tensoricFieldUsage.ones(shape);
    }

    public final  Expression> elementInverseOf(Expression> tensor) {
        return tensoricFieldUsage.elementInverseOf(tensor);
    }

    public final  Expression> elementNegativeOf(Expression> tensor) {
        return tensoricFieldUsage.elementNegativeOf(tensor);
    }

    public OngoingDeferredQuantifiedTensorOperation calculate(Tensor> left) {
        return quantifiedTensoricFieldUsage.calculateV(left);
    }

    public Expression> valueOf(V value, Unit unit) {
        return quantifiedTensoricFieldUsage.valueOf(value, unit);
    }

    public OngoingDeferredQuantifiedScalarOperation calculate(V value, javax.measure.unit.Unit unit) {
        return quantifiedTensoricFieldUsage.calculate(value, unit);
    }

    public OngoingDeferredQuantifiedScalarOperation calculateQ(Expression> scalar) {
        return quantifiedTensoricFieldUsage.calculate(scalar);
    }

    public Expression> negativeOf(QuantifiedValue element) {
        return quantifiedTensoricFieldUsage.negativeOf(element);
    }

    public Expression> inverseOf(QuantifiedValue element) {
        return quantifiedTensoricFieldUsage.inverseOf(element);
    }

    public Expression> valueOf(V value, javax.measure.unit.Unit unit) {
        return quantifiedTensoricFieldUsage.valueOf(value, unit);
    }

    public final > Expression elementNegativeOfTB(Expression tensor) {
        return tensorbackedExpressionSupport.elementNegativeOfTB(tensor);
    }

    public final > OngoingDeferredTensorBackedOperation calculateTB(
            Class resultClass, Expression tensoric) {
        return tensorbackedExpressionSupport.calculateTB(resultClass, tensoric);
    }

    public final >> Expression elementNegativeOfQTB(
            Class resultClass, Expression tensor) {
        return quantityTensorbackedExpressionSupport.elementNegativeOfTB(resultClass, tensor);
    }

    public final >> OngoingDeferredQuantifiedTensorBackedOperation //
            calculateQTB(Class resultClass, Expression tensor) {
        return quantityTensorbackedExpressionSupport.calculateTB(resultClass, tensor);
    }

    public final OngoingDeferredBinaryPredicate testIf(Expression expression) {
        return tensoricFieldUsage.testIf(expression);
    }

    public final OngoingDeferredIterableBinaryPredicate testIfIt(Expression> iterableExpression) {
        return tensoricFieldUsage.testIfIt(iterableExpression);
    }

    public  Expression rmsOfF(Expression> functionExpresssion) {
        return functionExpressionSupport.rmsOfF(functionExpresssion);
    }

    public  Expression averageOfF(Expression> functionExpresssion) {
        return functionExpressionSupport.averageOfF(functionExpresssion);
    }

    public  OngoingDeferredDiscreteFunctionBinaryOperation calculateF(
            Expression> functionExpresssion) {
        return ((FunctionExpressionSupport) functionExpressionSupport).calculateF(functionExpresssion);
    }

    public  FunctionExpressionSupportWithConversionAndComparator withConversionAndComparator(Conversion conversion,
            Comparator comparator) {
        return functionExpressionSupport.withConversionAndComparator(conversion, comparator);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy