From ddf14b01dcdafaafc82ef9eb523e43aeafff9e40 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 25 Mar 2019 22:54:17 +0000 Subject: [PATCH] fix shape index bug --- src/c_api/c_api.cc | 2 +- src/operator/tensor/matrix_op-inl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index 70ba84b5f94b..3d9301348443 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -791,7 +791,7 @@ int MXDataIterGetLabel(DataIterHandle handle, NDArrayHandle *out) { // temp hack to make label 1D // TODO(tianjun) make label 1D when label_width=0 mxnet::TShape shape = db.data[1].shape(); - if (shape[1] == 1) { + if (shape.ndim() > 1 && shape[1] == 1) { *pndarray = db.data[1].Reshape(mshadow::Shape1(shape[0])); } else { *pndarray = db.data[1]; diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h index 5eecda622729..53fe9d4d723d 100644 --- a/src/operator/tensor/matrix_op-inl.h +++ b/src/operator/tensor/matrix_op-inl.h @@ -589,7 +589,7 @@ void SliceCsrImpl(const SliceParam ¶m, const OpContext& ctx, mxnet::TShape begin(N), end(N); for (uint32_t i = 0; i < N; ++i) { int s = 0; - if (param.begin[i]) { + if (i < param.begin.ndim() && param.begin[i]) { s = *param.begin[i]; if (s < 0) s += ishape[i]; }