Caffe2 - C++ API
A deep learning, cross platform ML framework
sparse_matrix_reshape_op.cc
1 
17 #include "caffe2/experiments/operators/sparse_matrix_reshape_op.h"
18 
19 namespace caffe2 {
20 namespace {
21 
22 REGISTER_CPU_OPERATOR(SparseMatrixReshape, SparseMatrixReshapeOp<CPUContext>);
23 
24 OPERATOR_SCHEMA(SparseMatrixReshape)
25  .NumInputs(2)
26  .NumOutputs(2)
27  .AllowInplace({{0, 0}, {1, 1}})
28  .SetDoc(R"DOC(
29 Compute the indices of the reshaped sparse matrix.
30 
31 It takes two 1D tensors as input: the column indices (in int64) and
32 the row indices (in int), which correspond to `INDICES` and `SEGMENT_IDS`
33 in `SparseSortedSegment` family.
34 It outputs the corresponding reshaped column and row indices.
35 
36 Two arguments are required:
37 an argument `old_shape` specifies the original shape of the matrix,
38 and `new_shape` specifies the new shape.
39 One of the dimension in `old_shape` and `new_shape` can be -1.
40 The valid combinations are listed below, where p, q, r, s are
41 strictly positive integers.
42 
43 old_shape=(p, q)
44 new_shape=(r, s)
45 
46 old_shape=(p, q)
47 new_shape=(-1, s)
48 
49 old_shape=(p, q)
50 new_shape=(r, -1)
51 
52 old_shape=(-1, q)
53 new_shape=(-1, s)
54 
55 Note that only the first dimension in `old_shape` can be -1. In that case
56 the second dimension in `new_shape` must NOT be -1.
57 )DOC")
58  .Arg("old_shape", "Old shape.")
59  .Arg("new_shape", "New shape.")
60  .Input(0, "old_col", "Original column indices.")
61  .Input(1, "old_row", "Original row indices.")
62  .Output(0, "new_col", "New column indices.")
63  .Output(1, "new_row", "New row indices.");
64 
65 SHOULD_NOT_DO_GRADIENT(SparseMatrixReshape);
66 
67 } // namespace
68 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.