10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H 23 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
28 typename RhsXprType::Scalar>::ret
Scalar;
42 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
48 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
57 template<
typename Axis,
typename LhsXprType,
typename RhsXprType>
70 : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_axis(axis) {}
80 EIGEN_DEVICE_FUNC
const Axis&
axis()
const {
return m_axis; }
86 Assign assign(*
this, other);
91 template<
typename OtherDerived>
96 Assign assign(*
this, other);
109 template<
typename Axis,
typename LeftArgType,
typename RightArgType,
typename Device>
128 : m_leftImpl(op.lhsExpression(), device), m_rightImpl(op.rhsExpression(), device), m_axis(op.axis())
135 const Dimensions& lhs_dims = m_leftImpl.dimensions();
136 const Dimensions& rhs_dims = m_rightImpl.dimensions();
139 for (; i < m_axis; ++i) {
142 m_dimensions[i] = lhs_dims[i];
146 m_dimensions[i] = lhs_dims[i] + rhs_dims[i];
147 for (++i; i < NumDims; ++i) {
150 m_dimensions[i] = lhs_dims[i];
154 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
155 m_leftStrides[0] = 1;
156 m_rightStrides[0] = 1;
157 m_outputStrides[0] = 1;
159 for (
int j = 1; j < NumDims; ++j) {
160 m_leftStrides[j] = m_leftStrides[j-1] * lhs_dims[j-1];
161 m_rightStrides[j] = m_rightStrides[j-1] * rhs_dims[j-1];
162 m_outputStrides[j] = m_outputStrides[j-1] * m_dimensions[j-1];
165 m_leftStrides[NumDims - 1] = 1;
166 m_rightStrides[NumDims - 1] = 1;
167 m_outputStrides[NumDims - 1] = 1;
169 for (
int j = NumDims - 2; j >= 0; --j) {
170 m_leftStrides[j] = m_leftStrides[j+1] * lhs_dims[j+1];
171 m_rightStrides[j] = m_rightStrides[j+1] * rhs_dims[j+1];
172 m_outputStrides[j] = m_outputStrides[j+1] * m_dimensions[j+1];
182 m_leftImpl.evalSubExprsIfNeeded(NULL);
183 m_rightImpl.evalSubExprsIfNeeded(NULL);
189 m_leftImpl.cleanup();
190 m_rightImpl.cleanup();
199 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
200 for (
int i = NumDims - 1; i > 0; --i) {
201 subs[i] = index / m_outputStrides[i];
202 index -= subs[i] * m_outputStrides[i];
206 for (
int i = 0; i < NumDims - 1; ++i) {
207 subs[i] = index / m_outputStrides[i];
208 index -= subs[i] * m_outputStrides[i];
210 subs[NumDims - 1] = index;
213 const Dimensions& left_dims = m_leftImpl.dimensions();
214 if (subs[m_axis] < left_dims[m_axis]) {
216 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
217 left_index = subs[0];
218 for (
int i = 1; i < NumDims; ++i) {
219 left_index += (subs[i] % left_dims[i]) * m_leftStrides[i];
222 left_index = subs[NumDims - 1];
223 for (
int i = NumDims - 2; i >= 0; --i) {
224 left_index += (subs[i] % left_dims[i]) * m_leftStrides[i];
227 return m_leftImpl.coeff(left_index);
229 subs[m_axis] -= left_dims[m_axis];
230 const Dimensions& right_dims = m_rightImpl.dimensions();
232 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
233 right_index = subs[0];
234 for (
int i = 1; i < NumDims; ++i) {
235 right_index += (subs[i] % right_dims[i]) * m_rightStrides[i];
238 right_index = subs[NumDims - 1];
239 for (
int i = NumDims - 2; i >= 0; --i) {
240 right_index += (subs[i] % right_dims[i]) * m_rightStrides[i];
243 return m_rightImpl.coeff(right_index);
248 template<
int LoadMode>
253 eigen_assert(index + packetSize - 1 < dimensions().TotalSize());
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) +
278 EIGEN_DEVICE_FUNC Scalar*
data()
const {
return NULL; }
291 template<
typename Axis,
typename LeftArgType,
typename RightArgType,
typename Device>
293 :
public TensorEvaluator<const TensorConcatenationOp<Axis, LeftArgType, RightArgType>, Device>
320 for (
int i = Base::NumDims - 1; i > 0; --i) {
321 subs[i] = index / this->m_outputStrides[i];
322 index -= subs[i] * this->m_outputStrides[i];
326 const Dimensions& left_dims = this->m_leftImpl.dimensions();
327 if (subs[this->m_axis] < left_dims[this->m_axis]) {
328 Index left_index = subs[0];
329 for (
int i = 1; i < Base::NumDims; ++i) {
330 left_index += (subs[i] % left_dims[i]) * this->m_leftStrides[i];
332 return this->m_leftImpl.coeffRef(left_index);
334 subs[this->m_axis] -= left_dims[this->m_axis];
335 const Dimensions& right_dims = this->m_rightImpl.dimensions();
336 Index right_index = subs[0];
337 for (
int i = 1; i < Base::NumDims; ++i) {
338 right_index += (subs[i] % right_dims[i]) * this->m_rightStrides[i];
340 return this->m_rightImpl.coeffRef(right_index);
349 eigen_assert(index + packetSize - 1 < this->dimensions().TotalSize());
352 internal::pstore<CoeffReturnType, PacketReturnType>(values, x);
353 for (
int i = 0; i < packetSize; ++i) {
354 coeffRef(index+i) = values[i];
361 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H internal::traits< TensorConcatenationOp >::Index Index
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
remove_reference< LhsNested >::type _LhsNested
TensorEvaluator< RightArgType, Device > m_rightImpl
#define EIGEN_STRONG_INLINE
LhsXprType::Nested LhsNested
TensorEvaluator< const TensorConcatenationOp< Axis, LeftArgType, RightArgType >, Device > Base
std::vector< double > values
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
LhsXprType::Nested m_lhs_xpr
A cost model used to limit the number of threads used for evaluating tensor expression.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(XprType &op, const Device &device)
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 cleanup()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x)
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC const Axis & axis() const
array< Index, NumDims > m_rightStrides
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConcatenationOp(const LhsXprType &lhs, const RhsXprType &rhs, Axis axis)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
remove_reference< RhsNested >::type _RhsNested
promote_storage_type< typename LhsXprType::Scalar, typename RhsXprType::Scalar >::ret Scalar
internal::nested< TensorConcatenationOp >::type Nested
DSizes< Index, NumDims > Dimensions
array< Index, NumDims > m_leftStrides
TensorEvaluator< LeftArgType, Device > m_leftImpl
NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
static EIGEN_DEVICE_FUNC void run(const Expression &expr, const Device &device=Device())
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
EIGEN_DEVICE_FUNC const internal::remove_all< typename RhsXprType::Nested >::type & rhsExpression() const
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar *)
PacketType< CoeffReturnType, Device >::type PacketReturnType
EIGEN_DEVICE_FUNC Scalar * data() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
array< Index, NumDims > m_outputStrides
TensorConcatenationOp< Axis, LhsXprType, RhsXprType > type
promote_index_type< typename traits< LhsXprType >::Index, typename traits< RhsXprType >::Index >::type Index
const TensorConcatenationOp< Axis, LhsXprType, RhsXprType > & type
EIGEN_DEVICE_FUNC const internal::remove_all< typename LhsXprType::Nested >::type & lhsExpression() const
Tensor concatenation class.
internal::packet_traits< Scalar >::type type
TensorConcatenationOp< Axis, LeftArgType, RightArgType > XprType