pfor/src/pfor/algorithm.h

60 lines
2.1 KiB
C++

#ifndef PFOR_PFOR_ALGORITHM_H
#define PFOR_PFOR_ALGORITHM_H
#include "index/properties.h"
#include "expression/expression.h"
namespace pfor {
/**
*/
template<typename I, index::Value a, index::Value b, typename=void>
struct SubstituteVariableInLinIndexSlopeImpl {
using type = I;
};
template<typename I, index::Value a, index::Value b>
struct SubstituteVariableInLinIndexSlopeImpl<I, a, b, std::enable_if_t<index::isLinear<I>>> {
using type = index::LinearIndex<a * index::linearSlope<I>, index::linearSlope<I>*b + index::linearOffset<I>>;
};
template<typename I, index::Value a, index::Value b>
using SubstituteVariableInLinIndexSlope = typename SubstituteVariableInLinIndexSlopeImpl<I, a, b>::type;
/**
*/
template<typename, index::Value, index::Value> struct SubstituteVariableInExpressionImpl;
template<typename Op, typename... Args, index::Value a, index::Value b>
struct SubstituteVariableInExpressionImpl<expr::Expression<Op, Args...>, a, b> {
using type = expr::Expression<Op, typename SubstituteVariableInExpressionImpl<Args, a, b>::type...>;
};
template<typename T, typename Id, typename Index, index::Value a, index::Value b>
struct SubstituteVariableInExpressionImpl<expr::Expression<T*, Id, Index>, a, b> {
using type = expr::Expression<T*, Id, SubstituteVariableInLinIndexSlope<Index, a, b>>;
};
template<typename T, std::size_t n, typename Id, typename Index, index::Value a, index::Value b>
struct SubstituteVariableInExpressionImpl<expr::Expression<std::array<T, n>, Id, Index>, a, b> {
using type = expr::Expression<std::array<T, n>, Id, SubstituteVariableInLinIndexSlope<Index, a, b>>;
};
template<typename T, index::Value a, index::Value b>
struct SubstituteVariableInExpressionImpl<expr::Constant<T>, a, b> {
using type = expr::Constant<T>;
};
template<typename E, index::Value a, index::Value b>
using SubstituteVariableInExpression = typename SubstituteVariableInExpressionImpl<E, a, b>::type;
template<index::Value a, index::Value b>
struct GenSubstituteVariableInExpression {
template<typename E>
using type = SubstituteVariableInExpression<E, a, b>;
};
}
#endif