| 360 | */ |
| 361 | template<typename _Child> |
| 362 | class AsDiagonalOp : public CwiseOp<AsDiagonalOp<_Child> > |
| 363 | { |
| 364 | public: |
| 365 | typedef CwiseOp<AsDiagonalOp<_Child> > Base; |
| 366 | typedef AsDiagonalOp<_Child> Type; |
| 367 | CUMAT_PUBLIC_API |
| 368 | using VectorType = typename internal::traits<Type>::VectorType; |
| 369 | enum |
| 370 | { |
| 371 | Size = internal::traits<Type>::Size, |
| 372 | IsRowVector = internal::traits<_Child>::RowsAtCompileTime == 1, |
| 373 | }; |
| 374 | |
| 375 | protected: |
| 376 | typedef typename MatrixReadWrapper<_Child, AccessFlags::ReadCwise>::type child_wrapped_t; |
| 377 | const child_wrapped_t child_; |
| 378 | const Index size_; |
| 379 | |
| 380 | public: |
| 381 | explicit AsDiagonalOp(const MatrixBase<_Child>& child) |
| 382 | : child_(child.derived()) |
| 383 | , size_(child.rows()==1 ? child.cols() : child.rows()) |
| 384 | { |
| 385 | CUMAT_STATIC_ASSERT(internal::traits<_Child>::RowsAtCompileTime == 1 || internal::traits<_Child>::ColsAtCompileTime == 1, |
| 386 | "The child expression must be a compile-time row or column vector"); |
| 387 | } |
| 388 | |
| 389 | __host__ __device__ CUMAT_STRONG_INLINE Index rows() const { return size_; } |
| 390 | __host__ __device__ CUMAT_STRONG_INLINE Index cols() const { return size_; } |
| 391 | __host__ __device__ CUMAT_STRONG_INLINE Index batches() const { return child_.batches(); } |
| 392 | |
| 393 | __device__ CUMAT_STRONG_INLINE Scalar coeff(Index row, Index col, Index batch, Index index) const |
| 394 | { |
| 395 | using Functor = typename internal::AsDiagonalFunctor<VectorType>; |
| 396 | if (row == col) |
| 397 | { |
| 398 | if (IsRowVector) |
| 399 | return Functor::asDiagonal(child_.derived().coeff(0, col, batch, -1)); |
| 400 | else |
| 401 | return Functor::asDiagonal(child_.derived().coeff(row, 0, batch, -1)); |
| 402 | } else |
| 403 | { |
| 404 | return typename Functor::MatrixType(0); |
| 405 | } |
| 406 | } |
| 407 | }; |
| 408 | |
| 409 | |
| 410 | namespace internal { |
nothing calls this directly
no outgoing calls
no test coverage detected