
cc.redberry.core.parser.ParseTokenExpression Maven / Gradle / Ivy
/*
* Redberry: symbolic tensor computations.
*
* Copyright (c) 2010-2015:
* Stanislav Poslavsky
* Bolotin Dmitriy
*
* This file is part of Redberry.
*
* Redberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Redberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Redberry. If not, see .
*/
package cc.redberry.core.parser;
import cc.redberry.core.context.Context;
import cc.redberry.core.indices.Indices;
import cc.redberry.core.tensor.Tensor;
import cc.redberry.core.tensor.Tensors;
import cc.redberry.core.transformations.Transformation;
/**
* @author Dmitry Bolotin
* @author Stanislav Poslavsky
*/
public class ParseTokenExpression extends ParseToken {
public final boolean preprocess;
public ParseTokenExpression(boolean preprocess, ParseToken lhs, ParseToken rhs) {
super(TokenType.Expression, lhs, rhs);
this.preprocess = preprocess;
}
@Override
public Indices getIndices() {
return content[0].getIndices().getFree();
}
@Override
public Tensor toTensor() {
Tensor expression = Tensors.expression(content[0].toTensor(), content[1].toTensor());
if (preprocess) {
for (Transformation tr : Context.get().getParseManager().defaultTensorPreprocessors)
expression = tr.transform(expression);
Context.get().getParseManager().defaultTensorPreprocessors.add((Transformation) expression);
}
return expression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy