| 573 | } |
| 574 | |
| 575 | std::shared_ptr<phi::SparseCooTensor> PrepareDataForSparseCooTensor( |
| 576 | const Tensor& input) { |
| 577 | const auto& tensor_in = input.impl(); |
| 578 | if (tensor_in) { |
| 579 | phi::SparseCooTensor& sparse_tensor = |
| 580 | *static_cast<phi::SparseCooTensor*>(tensor_in.get()); |
| 581 | if (sparse_tensor.indices().meta().is_contiguous() && |
| 582 | sparse_tensor.values().meta().is_contiguous()) { |
| 583 | return std::static_pointer_cast<phi::SparseCooTensor>(tensor_in); |
| 584 | } |
| 585 | |
| 586 | if (!sparse_tensor.indices().meta().is_contiguous()) { |
| 587 | *sparse_tensor.mutable_indices() = |
| 588 | Trans2Contiguous(sparse_tensor.indices()); |
| 589 | } |
| 590 | |
| 591 | if (!sparse_tensor.values().meta().is_contiguous()) { |
| 592 | *sparse_tensor.mutable_values() = |
| 593 | Trans2Contiguous(sparse_tensor.values()); |
| 594 | } |
| 595 | return std::static_pointer_cast<phi::SparseCooTensor>(tensor_in); |
| 596 | } |
| 597 | PADDLE_THROW(common::errors::InvalidArgument( |
| 598 | "The impl() of input tensor is nullptr, it doesn't support for " |
| 599 | "SparseCooTensor data transform now.")); |
| 600 | } |
| 601 | |
| 602 | paddle::optional<phi::SparseCooTensor> PrepareDataForSparseCooTensor( |
| 603 | const paddle::optional<Tensor>& input) { |
nothing calls this directly
no test coverage detected