jasonyu1996 commented on a change in pull request #12430: [MXNET-882] Support
for N-d arrays added to diag op.
URL: https://github.com/apache/incubator-mxnet/pull/12430#discussion_r215471766
##########
File path: src/operator/tensor/diag_op-inl.h
##########
@@ -30,33 +30,46 @@
#include <dmlc/parameter.h>
#include <vector>
#include <algorithm>
+#include <utility>
#include "../mxnet_op.h"
#include "../operator_common.h"
#include "../elemwise_op_common.h"
+#include "./broadcast_reduce_op.h"
namespace mxnet {
namespace op {
struct DiagParam : public dmlc::Parameter<DiagParam> {
dmlc::optional<int> k;
+ dmlc::optional<int> axis1;
+ dmlc::optional<int> axis2;
DMLC_DECLARE_PARAMETER(DiagParam) {
DMLC_DECLARE_FIELD(k)
.set_default(dmlc::optional<int>(0))
.describe("Diagonal in question. The default is 0. "
"Use k>0 for diagonals above the main diagonal, "
"and k<0 for diagonals below the main diagonal. "
"If input has shape (S0 S1) k must be between -S0 and S1");
+ DMLC_DECLARE_FIELD(axis1)
+ .set_default(dmlc::optional<int>(0))
+ .describe("The first axis of the sub-arrays of interest. "
+ "Ignored when the input is a 1-D array.");
+ DMLC_DECLARE_FIELD(axis2)
+ .set_default(dmlc::optional<int>(1))
+ .describe("The second axis of the sub-arrays of interest. "
+ "Ignored when the input is a 1-D array.");
}
};
-inline TShape DiagShapeImpl(const TShape& ishape, const nnvm::dim_t k) {
+inline TShape DiagShapeImpl(const TShape& ishape, const nnvm::dim_t k,
+ const nnvm::dim_t axis1, const nnvm::dim_t axis2) {
if (ishape.ndim() == 1) {
auto s = ishape[0] + std::abs(k);
return TShape({s, s});
}
- auto h = ishape[0];
- auto w = ishape[1];
+ auto h = ishape[axis1];
Review comment:
I think you are right. These checks should be done first before using axis1
and axis2. Also I find it necessary to add some tests testing cases with
negative axes.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services