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

org.tensorics.core.lang.TensoricSupport 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 org.tensorics.core.commons.lang.OngoingBinaryOperation;
import org.tensorics.core.commons.options.ManipulationOption;
import org.tensorics.core.iterable.lang.OngoingQuantityIterableValueExtraction;
import org.tensorics.core.math.operations.BinaryFunction;
import org.tensorics.core.math.operations.BinaryOperation;
import org.tensorics.core.quantity.QuantifiedValue;
import org.tensorics.core.quantity.lang.OngoingQuantifiedScalarBinaryPredicate;
import org.tensorics.core.quantity.lang.OngoingQuantifiedScalarConversion;
import org.tensorics.core.quantity.lang.OngoingQuantifiedScalarOperation;
import org.tensorics.core.quantity.lang.OngoingQuantityValueExtraction;
import org.tensorics.core.quantity.options.ConfidenceLevel;
import org.tensorics.core.quantity.options.ImmutableConfidenceLevel;
import org.tensorics.core.scalar.lang.OngoingScalarBinaryPredicate;
import org.tensorics.core.tensor.Shape;
import org.tensorics.core.tensor.Tensor;
import org.tensorics.core.tensor.lang.OngoingQuantifiedTensorOperation;
import org.tensorics.core.tensor.lang.OngoingTensorOperation;
import org.tensorics.core.tensor.lang.QuantityTensorSupport;
import org.tensorics.core.tensor.lang.TensorSupport;
import org.tensorics.core.tensorbacked.Tensorbacked;
import org.tensorics.core.tensorbacked.lang.OngoingQuantifiedTensorBackedOperation;
import org.tensorics.core.tensorbacked.lang.OngoingTensorBackedOperation;
import org.tensorics.core.tensorbacked.lang.QuantityTensorbackedSupport;
import org.tensorics.core.tensorbacked.lang.TensorbackedSupport;
import org.tensorics.core.units.Unit;

/**
 * The main start point for expressions of the tensoric eDSL. Gives access to the quantified versions of the operations
 * and the basic tensor operations. 
* NOTE!
* Contains delegation methods only! * * @author kfuchsbe, agorzaws * @param The type of the values of the scalars (elements of the field on which all the operations are based on) */ @SuppressWarnings("PMD.TooManyMethods") public class TensoricSupport { private final TensorSupport tensoricFieldUsage; private final QuantityTensorSupport quantifiedTensoricFieldUsage; private final QuantityTensorbackedSupport quantifiedTensorbackedSupport; private final TensorbackedSupport tensorbackedSupport; private final EnvironmentImpl environment; public TensoricSupport(EnvironmentImpl environment) { this.environment = environment; this.tensoricFieldUsage = new TensorSupport<>(environment); this.quantifiedTensoricFieldUsage = new QuantityTensorSupport<>(environment); this.tensorbackedSupport = new TensorbackedSupport<>(environment); this.quantifiedTensorbackedSupport = new QuantityTensorbackedSupport<>(environment); } public OngoingBinaryOperation calculate(V operand) { return tensoricFieldUsage.calculate(operand); } public final V avarageOf(Iterable values) { return tensoricFieldUsage.averageOf(values); } public final V negativeOf(V element) { return tensoricFieldUsage.negativeOf(element); } public final V inverseOf(V element) { return tensoricFieldUsage.inverseOf(element); } public final V sizeOf(Iterable values) { return tensoricFieldUsage.sizeOf(values); } public final V zero() { return tensoricFieldUsage.zero(); } public final V two() { return tensoricFieldUsage.two(); } public final V one() { return tensoricFieldUsage.one(); } public V countOf(int number) { return tensoricFieldUsage.countOf(number); } public final V sumOf(Iterable values) { return tensoricFieldUsage.sumOf(values); } public V rmsOf(Iterable values) { return tensoricFieldUsage.rmsOf(values); } public V squareRootOf(V value) { return tensoricFieldUsage.squareRootOf(value); } public V squareOf(V value) { return tensoricFieldUsage.squareOf(value); } public final OngoingTensorOperation calculate(Tensor tensoric) { return tensoricFieldUsage.calculate(tensoric); } public V sumOfSquaresOf(Iterable values) { return tensoricFieldUsage.sumOfSquaresOf(values); } public Tensor zeros(Shape shape) { return tensoricFieldUsage.zeros(shape); } public Tensor ones(Shape shape) { return tensoricFieldUsage.ones(shape); } public Tensor elementInverseOf(Tensor tensor) { return tensoricFieldUsage.elementInverseOf(tensor); } public Tensor negativeOf(Tensor tensor) { return tensoricFieldUsage.negativeOf(tensor); } public final QuantifiedValue averageOfQ(Iterable> values) { return quantifiedTensoricFieldUsage.averageOf(values); } public final QuantifiedValue rmsOfQ(Iterable> values) { return quantifiedTensoricFieldUsage.rmsOf(values); } public final QuantifiedValue varOfQ(Iterable> values) { return quantifiedTensoricFieldUsage.varOf(values); } public final QuantifiedValue stdOfQ(Iterable> values) { return quantifiedTensoricFieldUsage.stdOf(values); } public OngoingQuantifiedTensorOperation calculateQ(Tensor> left) { return quantifiedTensoricFieldUsage.calculate(left); } public QuantifiedValue valueOf(V value, Unit unit) { return quantifiedTensoricFieldUsage.valueOf(value, unit); } public OngoingQuantifiedScalarOperation calculate(V value, javax.measure.unit.Unit unit) { return quantifiedTensoricFieldUsage.calculate(value, unit); } public OngoingQuantifiedScalarOperation calculate(QuantifiedValue scalar) { return quantifiedTensoricFieldUsage.calculate(scalar); } public QuantifiedValue negativeOf(QuantifiedValue element) { return quantifiedTensoricFieldUsage.negativeOf(element); } public QuantifiedValue inverseOf(QuantifiedValue element) { return quantifiedTensoricFieldUsage.inverseOf(element); } public QuantifiedValue valueOf(V value, javax.measure.unit.Unit unit) { return quantifiedTensoricFieldUsage.valueOf(value, unit); } public > TB negativeOf(TB tensorBacked) { return tensorbackedSupport.negativeOf(tensorBacked); } public final > OngoingTensorBackedOperation calculate(TB tensorBacked) { return tensorbackedSupport.calculate(tensorBacked); } public >> TB negativeOfQ(TB tensorBacked) { return quantifiedTensorbackedSupport.negativeOf(tensorBacked); } public >> OngoingQuantifiedTensorBackedOperation calculateQ( QTB left) { return quantifiedTensorbackedSupport.calculate(left); } public OngoingScalarBinaryPredicate testIf(V left) { return tensoricFieldUsage.testIf(left); } public OngoingQuantifiedScalarBinaryPredicate testIf(QuantifiedValue left) { return quantifiedTensoricFieldUsage.testIf(left); } public V absoluteValueOf(V value) { return tensoricFieldUsage.absoluteValueOf(value); } public Tensor elementwise(BinaryFunction operation, Tensor left, Tensor right) { return tensoricFieldUsage.elementwise(operation, left, right); } public Tensor elementwise(BinaryOperation operation, Tensor left, Tensor right) { return tensoricFieldUsage.elementwise(operation, left, right); } public OngoingQuantityValueExtraction valueOf(QuantifiedValue quantity) { return quantifiedTensoricFieldUsage.valueOf(quantity); } public final OngoingQuantityIterableValueExtraction valuesOfI(Iterable> quantities) { return quantifiedTensoricFieldUsage.valuesOf(quantities); } public final QuantifiedValue sizeOfQ(Iterable> values) { return quantifiedTensoricFieldUsage.sizeOf(values); } public final QuantifiedValue sumOfQ(Iterable> values) { return quantifiedTensoricFieldUsage.sumOf(values); } public final OngoingQuantityIterableValueExtraction valuesOf(Iterable> quantities) { return quantifiedTensoricFieldUsage.valuesOf(quantities); } public OngoingQuantifiedScalarConversion convert(QuantifiedValue value) { return quantifiedTensoricFieldUsage.convert(value); } public TensoricSupport with(ManipulationOption newOption) { return new TensoricSupport<>(environment.with(newOption)); } public ConfidenceLevel confidenceLevelOf(V confidenceLevel) { return new ImmutableConfidenceLevel(confidenceLevel); } }