samskalicky 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_r217108170
##########
File path: src/operator/tensor/diag_op-inl.h
##########
@@ -104,42 +143,132 @@ inline bool DiagOpType(const nnvm::NodeAttrs& attrs,
return (*out_attrs)[0] != -1;
}
-template<int req>
+template<int ndim, int req, bool back>
struct diag {
template<typename DType>
- MSHADOW_XINLINE static void Map(int i, DType* out, const DType* a,
- mshadow::Shape<2> ishape, int k) {
+ MSHADOW_XINLINE static void Map(index_t i, DType* out, const DType* a,
+ mshadow::Shape<ndim> oshape,
+ mshadow::Shape<ndim> ishape,
+ index_t stride, index_t offset,
+ index_t base) {
using namespace mxnet_op;
- int j = 0;
- if (k > 0) {
- j = ravel(mshadow::Shape2(i, i + k), ishape);
- } else if (k < 0) {
- j = ravel(mshadow::Shape2(i - k, i), ishape);
+ index_t idx = i / base;
+ index_t j = ravel(unravel(idx, oshape), ishape) + offset + stride * (i -
idx * base);
+ if (back) {
+ KERNEL_ASSIGN(out[j], req, a[i]);
} else {
- j = ravel(mshadow::Shape2(i, i), ishape);
+ KERNEL_ASSIGN(out[i], req, a[j]);
}
-
- KERNEL_ASSIGN(out[i], req, a[j]);
}
};
-template<int req>
+template<int req, bool back>
struct diag_gen {
template<typename DType>
- MSHADOW_XINLINE static void Map(int i, DType* out, const DType* a,
+ MSHADOW_XINLINE static void Map(index_t i, DType* out, const DType* a,
mshadow::Shape<2> oshape, int k) {
Review comment:
Should "int k" here be "index_t k" also?
----------------------------------------------------------------
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