/** * Copyright (c) 2022 by Contributors * @file elementwise_op.cc * @brief DGL C++ sparse elementwise operator implementation. */ // clang-format off #include // clang-format on #include #include #include #include #include "./utils.h" namespace dgl { namespace sparse { c10::intrusive_ptr SpSpAdd( const c10::intrusive_ptr& A, const c10::intrusive_ptr& B) { ElementwiseOpSanityCheck(A, B); auto torch_A = COOToTorchCOO(A->COOPtr(), A->value()); auto torch_B = COOToTorchCOO(B->COOPtr(), B->value()); auto sum = (torch_A + torch_B).coalesce(); auto indices = sum.indices(); auto row = indices[0]; auto col = indices[1]; return CreateFromCOO(row, col, sum.values(), A->shape()); } } // namespace sparse } // namespace dgl