/** * Copyright (c) 2022 by Contributors * @file sparse/reduction.h * @brief DGL C++ sparse matrix reduction operators. */ #ifndef SPARSE_REDUCTION_H_ #define SPARSE_REDUCTION_H_ #include #include namespace dgl { namespace sparse { /** * @brief Reduces a sparse matrix along the specified sparse dimension. * * @param A The sparse matrix. * @param dim The sparse dimension to reduce along. Must be either 0 (rows) or * 1 (columns). * @param reduce The reduce operator. Must be either "sum", "smin", "smax", * "mean", or "sprod". * * @return Tensor */ torch::Tensor Reduce( const c10::intrusive_ptr& A, const std::string& reduce, const torch::optional& dim = torch::nullopt); inline torch::Tensor ReduceSum( const c10::intrusive_ptr& A, const torch::optional& dim = torch::nullopt) { return Reduce(A, "sum", dim); } inline torch::Tensor ReduceMin( const c10::intrusive_ptr& A, const torch::optional& dim = torch::nullopt) { return Reduce(A, "smin", dim); } inline torch::Tensor ReduceMax( const c10::intrusive_ptr& A, const torch::optional& dim = torch::nullopt) { return Reduce(A, "smax", dim); } inline torch::Tensor ReduceMean( const c10::intrusive_ptr& A, const torch::optional& dim = torch::nullopt) { return Reduce(A, "smean", dim); } inline torch::Tensor ReduceProd( const c10::intrusive_ptr& A, const torch::optional& dim = torch::nullopt) { return Reduce(A, "sprod", dim); } } // namespace sparse } // namespace dgl #endif // SPARSE_REDUCTION_H_