| 608 | } |
| 609 | |
| 610 | std::shared_ptr<phi::SparseCsrTensor> PrepareDataForSparseCsrTensor( |
| 611 | const Tensor& input) { |
| 612 | const auto& tensor_in = input.impl(); |
| 613 | if (tensor_in) { |
| 614 | phi::SparseCsrTensor& sparse_tensor = |
| 615 | *static_cast<phi::SparseCsrTensor*>(tensor_in.get()); |
| 616 | if (sparse_tensor.crows().meta().is_contiguous() && |
| 617 | sparse_tensor.cols().meta().is_contiguous() && |
| 618 | sparse_tensor.values().meta().is_contiguous()) { |
| 619 | return std::static_pointer_cast<phi::SparseCsrTensor>(tensor_in); |
| 620 | } |
| 621 | |
| 622 | if (!sparse_tensor.crows().meta().is_contiguous()) { |
| 623 | *sparse_tensor.mutable_crows() = Trans2Contiguous(sparse_tensor.crows()); |
| 624 | } |
| 625 | |
| 626 | if (!sparse_tensor.cols().meta().is_contiguous()) { |
| 627 | *sparse_tensor.mutable_cols() = Trans2Contiguous(sparse_tensor.cols()); |
| 628 | } |
| 629 | |
| 630 | if (!sparse_tensor.values().meta().is_contiguous()) { |
| 631 | *sparse_tensor.mutable_values() = |
| 632 | Trans2Contiguous(sparse_tensor.values()); |
| 633 | } |
| 634 | return std::static_pointer_cast<phi::SparseCsrTensor>(tensor_in); |
| 635 | } |
| 636 | PADDLE_THROW(common::errors::InvalidArgument( |
| 637 | "The impl() of input tensor is nullptr, it doesn't support for " |
| 638 | "SparseCsrTensor data transform now.")); |
| 639 | } |
| 640 | |
| 641 | paddle::optional<phi::SparseCsrTensor> PrepareDataForSparseCsrTensor( |
| 642 | const paddle::optional<Tensor>& input) { |
nothing calls this directly
no test coverage detected