MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / PrepareDataForSparseCooTensor

Function PrepareDataForSparseCooTensor

paddle/phi/api/lib/data_transform.cc:575–600  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573}
574
575std::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
602paddle::optional<phi::SparseCooTensor> PrepareDataForSparseCooTensor(
603 const paddle::optional<Tensor>& input) {

Callers

nothing calls this directly

Calls 6

Trans2ContiguousFunction · 0.85
metaMethod · 0.80
implMethod · 0.45
getMethod · 0.45
is_contiguousMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected