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

org.tensorics.core.reduction.InterpolatedSlicing 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
/**
 * Copyright (c) 2015 European Organisation for Nuclear Research (CERN), All Rights Reserved.
 */

package org.tensorics.core.reduction;

import java.util.Map;

import org.tensorics.core.lang.Tensorics;
import org.tensorics.core.tensor.Position;
import org.tensorics.core.tensor.Tensor;

/**
 * The extended slicing strategy that involves the possibility to interpolate over the specified, comparable coordinate
 * 
 * @author agorzaws
 * @param  the type of the hold values
 * @param  the type of the interpolation direction, must be Comparable
 */
public class InterpolatedSlicing, E> extends Slicing {

    private final InterpolationStrategy strategy;
    private final Tensor tensor;

    public InterpolatedSlicing(C slicePosition, InterpolationStrategy strategy, Tensor tensor) {
        super(slicePosition);
        this.strategy = strategy;
        this.tensor = tensor;
    }

    @Override
    public E reduce(Map inputValues, Position position) {
        if (inputValues.get(slicePosition) == null) {
            Tensor extractedToInterpolate = Tensorics.from(tensor).extract(position);
            return strategy.getInterpolatedValue(extractedToInterpolate, slicePosition);
        } else {
            return inputValues.get(slicePosition);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy