"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "a17d6d685870bd5b2b20d9c16498994fc945c7fd"
array_op.h 8.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*!
 *  Copyright (c) 2019 by Contributors
 * \file array/array_op.h
 * \brief Array operator templates
 */
#ifndef DGL_ARRAY_ARRAY_OP_H_
#define DGL_ARRAY_ARRAY_OP_H_

#include <dgl/array.h>
10
#include <dgl/graph_traversal.h>
11
#include <vector>
12
13
#include <tuple>
#include <utility>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

namespace dgl {
namespace aten {
namespace impl {

template <DLDeviceType XPU, typename IdType>
IdArray Full(IdType val, int64_t length, DLContext ctx);

template <DLDeviceType XPU, typename IdType>
IdArray Range(IdType low, IdType high, DLContext ctx);

template <DLDeviceType XPU, typename IdType>
IdArray AsNumBits(IdArray arr, uint8_t bits);

template <DLDeviceType XPU, typename IdType, typename Op>
IdArray BinaryElewise(IdArray lhs, IdArray rhs);

template <DLDeviceType XPU, typename IdType, typename Op>
IdArray BinaryElewise(IdArray lhs, IdType rhs);

template <DLDeviceType XPU, typename IdType, typename Op>
IdArray BinaryElewise(IdType lhs, IdArray rhs);

37
38
39
template <DLDeviceType XPU, typename IdType, typename Op>
IdArray UnaryElewise(IdArray array);

40
41
42
template <DLDeviceType XPU, typename IdType>
IdArray HStack(IdArray arr1, IdArray arr2);

43
44
template <DLDeviceType XPU, typename DType, typename IdType>
NDArray IndexSelect(NDArray array, IdArray index);
45

46
template <DLDeviceType XPU, typename DType>
47
DType IndexSelect(NDArray array, int64_t index);
48

49
50
51
52
53
54
template <DLDeviceType XPU, typename DType, typename IdType>
NDArray Scatter(NDArray array, IdArray indices);

template <DLDeviceType XPU, typename DType, typename IdType>
NDArray Repeat(NDArray array, IdArray repeats);

55
56
57
template <DLDeviceType XPU, typename IdType>
IdArray Relabel_(const std::vector<IdArray>& arrays);

58
59
60
template <DLDeviceType XPU, typename IdType>
NDArray Concat(const std::vector<IdArray>& arrays);

61
62
63
64
65
66
template <DLDeviceType XPU, typename DType>
std::tuple<NDArray, IdArray, IdArray> Pack(NDArray array, DType pad_value);

template <DLDeviceType XPU, typename DType, typename IdType>
std::pair<NDArray, IdArray> ConcatSlices(NDArray array, IdArray lengths);

67
68
69
template <DLDeviceType XPU, typename IdType>
IdArray CumSum(IdArray array, bool prepend_zero);

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// sparse arrays

template <DLDeviceType XPU, typename IdType>
bool CSRIsNonZero(CSRMatrix csr, int64_t row, int64_t col);

template <DLDeviceType XPU, typename IdType>
runtime::NDArray CSRIsNonZero(CSRMatrix csr, runtime::NDArray row, runtime::NDArray col);

template <DLDeviceType XPU, typename IdType>
bool CSRHasDuplicate(CSRMatrix csr);

template <DLDeviceType XPU, typename IdType>
int64_t CSRGetRowNNZ(CSRMatrix csr, int64_t row);

template <DLDeviceType XPU, typename IdType>
runtime::NDArray CSRGetRowNNZ(CSRMatrix csr, runtime::NDArray row);

template <DLDeviceType XPU, typename IdType>
runtime::NDArray CSRGetRowColumnIndices(CSRMatrix csr, int64_t row);

90
template <DLDeviceType XPU, typename IdType>
91
92
runtime::NDArray CSRGetRowData(CSRMatrix csr, int64_t row);

93
94
95
template <DLDeviceType XPU, typename IdType>
bool CSRIsSorted(CSRMatrix csr);

96
template <DLDeviceType XPU, typename IdType>
97
98
runtime::NDArray CSRGetData(CSRMatrix csr, int64_t row, int64_t col);

99
template <DLDeviceType XPU, typename IdType>
100
101
runtime::NDArray CSRGetData(CSRMatrix csr, runtime::NDArray rows, runtime::NDArray cols);

102
template <DLDeviceType XPU, typename IdType>
103
104
105
std::vector<runtime::NDArray> CSRGetDataAndIndices(
    CSRMatrix csr, runtime::NDArray rows, runtime::NDArray cols);

106
template <DLDeviceType XPU, typename IdType>
107
108
109
110
111
112
113
114
115
116
CSRMatrix CSRTranspose(CSRMatrix csr);

// Convert CSR to COO
template <DLDeviceType XPU, typename IdType>
COOMatrix CSRToCOO(CSRMatrix csr);

// Convert CSR to COO using data array as order
template <DLDeviceType XPU, typename IdType>
COOMatrix CSRToCOODataAsOrder(CSRMatrix csr);

117
template <DLDeviceType XPU, typename IdType>
118
119
CSRMatrix CSRSliceRows(CSRMatrix csr, int64_t start, int64_t end);

120
template <DLDeviceType XPU, typename IdType>
121
122
CSRMatrix CSRSliceRows(CSRMatrix csr, runtime::NDArray rows);

123
template <DLDeviceType XPU, typename IdType>
124
125
CSRMatrix CSRSliceMatrix(CSRMatrix csr, runtime::NDArray rows, runtime::NDArray cols);

126
127
128
template <DLDeviceType XPU, typename IdType>
void CSRSort_(CSRMatrix* csr);

Da Zheng's avatar
Da Zheng committed
129
130
131
132
133
134
template <DLDeviceType XPU, typename IdType>
CSRMatrix CSRReorder(CSRMatrix csr, runtime::NDArray new_row_ids, runtime::NDArray new_col_ids);

template <DLDeviceType XPU, typename IdType>
COOMatrix COOReorder(COOMatrix coo, runtime::NDArray new_row_ids, runtime::NDArray new_col_ids);

135
136
137
template <DLDeviceType XPU, typename IdType>
CSRMatrix CSRRemove(CSRMatrix csr, IdArray entries);

138
139
140
141
142
143
144
145
146
147
// FloatType is the type of probability data.
template <DLDeviceType XPU, typename IdType, typename FloatType>
COOMatrix CSRRowWiseSampling(
    CSRMatrix mat, IdArray rows, int64_t num_samples, FloatArray prob, bool replace);

template <DLDeviceType XPU, typename IdType>
COOMatrix CSRRowWiseSamplingUniform(
    CSRMatrix mat, IdArray rows, int64_t num_samples, bool replace);

// FloatType is the type of weight data.
148
template <DLDeviceType XPU, typename IdType, typename DType>
149
COOMatrix CSRRowWiseTopk(
150
    CSRMatrix mat, IdArray rows, int64_t k, NDArray weight, bool ascending);
151

152

153
///////////////////////////////////////////////////////////////////////////////////////////
Da Zheng's avatar
Da Zheng committed
154

155
156
157
158
159
160
template <DLDeviceType XPU, typename IdType>
bool COOIsNonZero(COOMatrix coo, int64_t row, int64_t col);

template <DLDeviceType XPU, typename IdType>
runtime::NDArray COOIsNonZero(COOMatrix coo, runtime::NDArray row, runtime::NDArray col);

161
162
163
template <DLDeviceType XPU, typename IdType>
bool COOHasDuplicate(COOMatrix coo);

164
165
166
167
168
169
template <DLDeviceType XPU, typename IdType>
int64_t COOGetRowNNZ(COOMatrix coo, int64_t row);

template <DLDeviceType XPU, typename IdType>
runtime::NDArray COOGetRowNNZ(COOMatrix coo, runtime::NDArray row);

170
template <DLDeviceType XPU, typename IdType>
171
172
173
std::pair<runtime::NDArray, runtime::NDArray>
COOGetRowDataAndIndices(COOMatrix coo, int64_t row);

174
template <DLDeviceType XPU, typename IdType>
175
176
runtime::NDArray COOGetData(COOMatrix coo, int64_t row, int64_t col);

177
template <DLDeviceType XPU, typename IdType>
178
179
180
std::vector<runtime::NDArray> COOGetDataAndIndices(
    COOMatrix coo, runtime::NDArray rows, runtime::NDArray cols);

181
template <DLDeviceType XPU, typename IdType>
182
183
COOMatrix COOTranspose(COOMatrix coo);

184
template <DLDeviceType XPU, typename IdType>
185
186
CSRMatrix COOToCSR(COOMatrix coo);

187
template <DLDeviceType XPU, typename IdType>
188
189
COOMatrix COOSliceRows(COOMatrix coo, int64_t start, int64_t end);

190
template <DLDeviceType XPU, typename IdType>
191
192
COOMatrix COOSliceRows(COOMatrix coo, runtime::NDArray rows);

193
template <DLDeviceType XPU, typename IdType>
194
195
COOMatrix COOSliceMatrix(COOMatrix coo, runtime::NDArray rows, runtime::NDArray cols);

196
197
198
template <DLDeviceType XPU, typename IdType>
std::pair<COOMatrix, IdArray> COOCoalesce(COOMatrix coo);

199
template <DLDeviceType XPU, typename IdType>
200
201
202
203
void COOSort_(COOMatrix* mat, bool sort_column);

template <DLDeviceType XPU, typename IdType>
std::pair<bool, bool> COOIsSorted(COOMatrix coo);
204

205
206
207
template <DLDeviceType XPU, typename IdType>
COOMatrix COORemove(COOMatrix coo, IdArray entries);

208
209
210
211
212
213
214
215
216
217
218
219
220
// FloatType is the type of probability data.
template <DLDeviceType XPU, typename IdType, typename FloatType>
COOMatrix COORowWiseSampling(
    COOMatrix mat, IdArray rows, int64_t num_samples, FloatArray prob, bool replace);

template <DLDeviceType XPU, typename IdType>
COOMatrix COORowWiseSamplingUniform(
    COOMatrix mat, IdArray rows, int64_t num_samples, bool replace);

// FloatType is the type of weight data.
template <DLDeviceType XPU, typename IdType, typename FloatType>
COOMatrix COORowWiseTopk(
    COOMatrix mat, IdArray rows, int64_t k, FloatArray weight, bool ascending);
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
template <DLDeviceType XPU, typename IdType>
Frontiers BFSNodesFrontiers(const CSRMatrix& csr, IdArray source);

template <DLDeviceType XPU, typename IdType>
Frontiers BFSEdgesFrontiers(const CSRMatrix& csr, IdArray source);

template <DLDeviceType XPU, typename IdType>
Frontiers TopologicalNodesFrontiers(const CSRMatrix& csr);

template <DLDeviceType XPU, typename IdType>
Frontiers DGLDFSEdges(const CSRMatrix& csr, IdArray source);

template <DLDeviceType XPU, typename IdType>
Frontiers DGLDFSLabeledEdges(const CSRMatrix& csr,
                             IdArray source,
                             const bool has_reverse_edge,
                             const bool has_nontree_edge,
                             const bool return_labels);

241
242


243
244
245
246
247
}  // namespace impl
}  // namespace aten
}  // namespace dgl

#endif  // DGL_ARRAY_ARRAY_OP_H_