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

Function PrepareDataForSparseCsrTensor

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

Source from the content-addressed store, hash-verified

608}
609
610std::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
641paddle::optional<phi::SparseCsrTensor> PrepareDataForSparseCsrTensor(
642 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