Caffe2 - C++ API
A deep learning, cross platform ML framework
sparse_matrix_reshape_op.cc
1 #include "caffe2/experiments/operators/sparse_matrix_reshape_op.h"
2 
3 namespace caffe2 {
4 namespace {
5 
6 REGISTER_CPU_OPERATOR(SparseMatrixReshape, SparseMatrixReshapeOp<CPUContext>);
7 
8 OPERATOR_SCHEMA(SparseMatrixReshape)
9  .NumInputs(2)
10  .NumOutputs(2)
11  .AllowInplace({{0, 0}, {1, 1}})
12  .SetDoc(R"DOC(
13 Compute the indices of the reshaped sparse matrix.
14 
15 It takes two 1D tensors as input: the column indices (in int64) and
16 the row indices (in int), which correspond to `INDICES` and `SEGMENT_IDS`
17 in `SparseSortedSegment` family.
18 It outputs the corresponding reshaped column and row indices.
19 
20 Two arguments are required:
21 an argument `old_shape` specifies the original shape of the matrix,
22 and `new_shape` specifies the new shape.
23 One of the dimension in `old_shape` and `new_shape` can be -1.
24 The valid combinations are listed below, where p, q, r, s are
25 strictly positive integers.
26 
27 old_shape=(p, q)
28 new_shape=(r, s)
29 
30 old_shape=(p, q)
31 new_shape=(-1, s)
32 
33 old_shape=(p, q)
34 new_shape=(r, -1)
35 
36 old_shape=(-1, q)
37 new_shape=(-1, s)
38 
39 Note that only the first dimension in `old_shape` can be -1. In that case
40 the second dimension in `new_shape` must NOT be -1.
41 )DOC")
42  .Arg("old_shape", "Old shape.")
43  .Arg("new_shape", "New shape.")
44  .Input(0, "old_col", "Original column indices.")
45  .Input(1, "old_row", "Original row indices.")
46  .Output(0, "new_col", "New column indices.")
47  .Output(1, "new_row", "New row indices.");
48 
49 SHOULD_NOT_DO_GRADIENT(SparseMatrixReshape);
50 
51 } // namespace
52 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...