chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:35:51 +08:00
commit c36a561cd8
2172 changed files with 455595 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
/**
* 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 <sparse/sparse_matrix.h>
#include <string>
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<SparseMatrix>& A, const std::string& reduce,
const torch::optional<int64_t>& dim = torch::nullopt);
inline torch::Tensor ReduceSum(
const c10::intrusive_ptr<SparseMatrix>& A,
const torch::optional<int64_t>& dim = torch::nullopt) {
return Reduce(A, "sum", dim);
}
inline torch::Tensor ReduceMin(
const c10::intrusive_ptr<SparseMatrix>& A,
const torch::optional<int64_t>& dim = torch::nullopt) {
return Reduce(A, "smin", dim);
}
inline torch::Tensor ReduceMax(
const c10::intrusive_ptr<SparseMatrix>& A,
const torch::optional<int64_t>& dim = torch::nullopt) {
return Reduce(A, "smax", dim);
}
inline torch::Tensor ReduceMean(
const c10::intrusive_ptr<SparseMatrix>& A,
const torch::optional<int64_t>& dim = torch::nullopt) {
return Reduce(A, "smean", dim);
}
inline torch::Tensor ReduceProd(
const c10::intrusive_ptr<SparseMatrix>& A,
const torch::optional<int64_t>& dim = torch::nullopt) {
return Reduce(A, "sprod", dim);
}
} // namespace sparse
} // namespace dgl
#endif // SPARSE_REDUCTION_H_