10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H 23 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
44 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
50 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
59 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
73 : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_axis(axis) {}
94 template<
typename Axis,
typename LeftArgType,
typename RightArgType,
typename Device>
123 : m_leftImpl(op.lhsExpression(), device), m_rightImpl(op.rhsExpression(), device), m_axis(op.axis())
130 const Dimensions& lhs_dims = m_leftImpl.dimensions();
131 const Dimensions& rhs_dims = m_rightImpl.dimensions();
134 for (; i < m_axis; ++
i) {
137 m_dimensions[
i] = lhs_dims[
i];
141 m_dimensions[
i] = lhs_dims[
i] + rhs_dims[
i];
142 for (++i; i < NumDims; ++
i) {
145 m_dimensions[
i] = lhs_dims[
i];
149 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
150 m_leftStrides[0] = 1;
151 m_rightStrides[0] = 1;
152 m_outputStrides[0] = 1;
154 for (
int j = 1;
j < NumDims; ++
j) {
155 m_leftStrides[
j] = m_leftStrides[
j-1] * lhs_dims[
j-1];
156 m_rightStrides[
j] = m_rightStrides[
j-1] * rhs_dims[
j-1];
157 m_outputStrides[
j] = m_outputStrides[
j-1] * m_dimensions[
j-1];
160 m_leftStrides[NumDims - 1] = 1;
161 m_rightStrides[NumDims - 1] = 1;
162 m_outputStrides[NumDims - 1] = 1;
164 for (
int j = NumDims - 2;
j >= 0; --
j) {
165 m_leftStrides[
j] = m_leftStrides[
j+1] * lhs_dims[
j+1];
166 m_rightStrides[
j] = m_rightStrides[
j+1] * rhs_dims[
j+1];
167 m_outputStrides[
j] = m_outputStrides[
j+1] * m_dimensions[
j+1];
177 m_leftImpl.evalSubExprsIfNeeded(
NULL);
178 m_rightImpl.evalSubExprsIfNeeded(
NULL);
184 m_leftImpl.cleanup();
185 m_rightImpl.cleanup();
194 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
195 for (
int i = NumDims - 1;
i > 0; --
i) {
196 subs[
i] = index / m_outputStrides[
i];
197 index -= subs[
i] * m_outputStrides[
i];
201 for (
int i = 0;
i < NumDims - 1; ++
i) {
202 subs[
i] = index / m_outputStrides[
i];
203 index -= subs[
i] * m_outputStrides[
i];
205 subs[NumDims - 1] = index;
208 const Dimensions& left_dims = m_leftImpl.dimensions();
209 if (subs[m_axis] < left_dims[m_axis]) {
211 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
212 left_index = subs[0];
214 for (
int i = 1;
i < NumDims; ++
i) {
215 left_index += (subs[
i] % left_dims[
i]) * m_leftStrides[
i];
218 left_index = subs[NumDims - 1];
220 for (
int i = NumDims - 2;
i >= 0; --
i) {
221 left_index += (subs[
i] % left_dims[
i]) * m_leftStrides[
i];
224 return m_leftImpl.coeff(left_index);
226 subs[m_axis] -= left_dims[m_axis];
227 const Dimensions& right_dims = m_rightImpl.dimensions();
229 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
230 right_index = subs[0];
232 for (
int i = 1;
i < NumDims; ++
i) {
233 right_index += (subs[
i] % right_dims[
i]) * m_rightStrides[
i];
236 right_index = subs[NumDims - 1];
238 for (
int i = NumDims - 2;
i >= 0; --
i) {
239 right_index += (subs[
i] % right_dims[
i]) * m_rightStrides[
i];
242 return m_rightImpl.coeff(right_index);
247 template<
int LoadMode>
256 for (
int i = 0;
i < packetSize; ++
i) {
257 values[
i] = coeff(index+
i);
259 PacketReturnType rslt = internal::pload<PacketReturnType>(
values);
265 const double compute_cost = NumDims * (2 * TensorOpCost::AddCost<Index>() +
266 2 * TensorOpCost::MulCost<Index>() +
267 TensorOpCost::DivCost<Index>() +
268 TensorOpCost::ModCost<Index>());
269 const double lhs_size = m_leftImpl.dimensions().TotalSize();
270 const double rhs_size = m_rightImpl.dimensions().TotalSize();
271 return (lhs_size / (lhs_size + rhs_size)) *
272 m_leftImpl.costPerCoeff(vectorized) +
273 (rhs_size / (lhs_size + rhs_size)) *
274 m_rightImpl.costPerCoeff(vectorized) +
280 #ifdef EIGEN_USE_SYCL 283 m_leftImpl.bind(cgh);
284 m_rightImpl.bind(cgh);
299 template<
typename Axis,
typename LeftArgType,
typename RightArgType,
typename Device>
301 :
public TensorEvaluator<const TensorConcatenationOp<Axis, LeftArgType, RightArgType>, Device>
336 for (
int i = Base::NumDims - 1;
i > 0; --
i) {
337 subs[
i] = index / this->m_outputStrides[
i];
338 index -= subs[
i] * this->m_outputStrides[
i];
342 const Dimensions& left_dims = this->m_leftImpl.dimensions();
343 if (subs[this->m_axis] < left_dims[this->m_axis]) {
344 Index left_index = subs[0];
345 for (
int i = 1;
i < Base::NumDims; ++
i) {
346 left_index += (subs[
i] % left_dims[
i]) * this->m_leftStrides[
i];
348 return this->m_leftImpl.coeffRef(left_index);
350 subs[this->m_axis] -= left_dims[this->m_axis];
351 const Dimensions& right_dims = this->m_rightImpl.dimensions();
352 Index right_index = subs[0];
353 for (
int i = 1;
i < Base::NumDims; ++
i) {
354 right_index += (subs[
i] % right_dims[
i]) * this->m_rightStrides[
i];
356 return this->m_rightImpl.coeffRef(right_index);
368 internal::pstore<CoeffReturnType, PacketReturnType>(
values,
x);
369 for (
int i = 0;
i < packetSize; ++
i) {
370 coeffRef(index+
i) = values[
i];
377 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H internal::traits< TensorConcatenationOp >::Index Index
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
conditional< Pointer_type_promotion< typename LhsXprType::Scalar, Scalar >::val, typename traits< LhsXprType >::PointerType, typename traits< RhsXprType >::PointerType >::type PointerType
remove_reference< LhsNested >::type _LhsNested
TensorEvaluator< RightArgType, Device > m_rightImpl
#define EIGEN_STRONG_INLINE
LhsXprType::Nested LhsNested
EIGEN_STRONG_INLINE void cleanup()
TensorEvaluator< const TensorConcatenationOp< Axis, LeftArgType, RightArgType >, Device > Base
EIGEN_DEVICE_FUNC const internal::remove_all< typename RhsXprType::Nested >::type & rhsExpression() const
internal::traits< TensorConcatenationOp >::Scalar Scalar
RhsXprType::Nested RhsNested
PacketType< CoeffReturnType, Device >::type PacketReturnType
TensorConcatenationOp< Axis, LeftArgType, RightArgType > XprType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType & coeffRef(Index index)
Base::Dimensions Dimensions
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Namespace containing all symbols from the Eigen library.
LhsXprType::Nested m_lhs_xpr
A cost model used to limit the number of threads used for evaluating tensor expression.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
RhsXprType::Nested m_rhs_xpr
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x)
XprType::CoeffReturnType CoeffReturnType
array< Index, NumDims > m_rightStrides
EIGEN_DEVICE_FUNC const internal::remove_all< typename LhsXprType::Nested >::type & lhsExpression() const
EIGEN_DEVICE_FUNC const Axis & axis() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConcatenationOp(const LhsXprType &lhs, const RhsXprType &rhs, Axis axis)
remove_reference< RhsNested >::type _RhsNested
promote_storage_type< typename LhsXprType::Scalar, typename RhsXprType::Scalar >::ret Scalar
internal::TensorBlockNotImplemented TensorBlock
internal::nested< TensorConcatenationOp >::type Nested
DSizes< Index, NumDims > Dimensions
TensorBase< TensorConcatenationOp< Axis, LhsXprType, RhsXprType >, WriteAccessors > Base
array< Index, NumDims > m_leftStrides
TensorEvaluator< LeftArgType, Device > m_leftImpl
NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
promote_storage_type< typename traits< LhsXprType >::StorageKind, typename traits< RhsXprType >::StorageKind >::ret StorageKind
internal::traits< TensorConcatenationOp >::StorageKind StorageKind
internal::promote_storage_type< typename LhsXprType::CoeffReturnType, typename RhsXprType::CoeffReturnType >::ret CoeffReturnType
#define EIGEN_DEVICE_FUNC
XprType::CoeffReturnType CoeffReturnType
StorageMemory< CoeffReturnType, Device > Storage
#define EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(Derived)
PacketType< CoeffReturnType, Device >::type PacketReturnType
Storage::Type EvaluatorPointerType
array< Index, NumDims > m_outputStrides
EIGEN_STRONG_INLINE TensorEvaluator(XprType &op, const Device &device)
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
TensorConcatenationOp< Axis, LhsXprType, RhsXprType > type
promote_index_type< typename traits< LhsXprType >::Index, typename traits< RhsXprType >::Index >::type Index
Generic expression where a coefficient-wise unary operator is applied to an expression.
const TensorConcatenationOp< Axis, LhsXprType, RhsXprType > & type
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
const std::vector< size_t > dimensions
Tensor concatenation class.
internal::TensorBlockNotImplemented TensorBlock
#define EIGEN_UNROLL_LOOP
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
TensorConcatenationOp< Axis, LeftArgType, RightArgType > XprType