Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Test large vector mean operator and fix a few bugs #16079

Merged
merged 8 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/common/tensor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <vector>
#include <fstream>
#include "../../3rdparty/mshadow/mshadow/base.h"
#include "../../tests/cpp/include/test_util.h"
apeforest marked this conversation as resolved.
Show resolved Hide resolved

namespace mxnet {

Expand Down
2 changes: 1 addition & 1 deletion src/operator/mshadow_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ MXNET_UNARY_MATH_OP(identity_grad, 1);

struct identity_with_cast {
template<typename DTypeIn, typename DTypeOut>
MSHADOW_XINLINE static void Map(int i, DTypeOut *out, DTypeIn *in) {
MSHADOW_XINLINE static void Map(index_t i, DTypeOut *out, DTypeIn *in) {
out[i] = DTypeOut(in[i]);
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/operator/tensor/broadcast_reduce-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ MSHADOW_XINLINE int diff(const Shape<ndim>& small, const Shape<ndim>& big, Shape
mdim += small[i] != big[i];
(*dims)[i] = (*stride)[i] = 1;
}

index_t s = 1;
#pragma unroll
for (int i = ndim-1, j = mdim, s = 1; i >= 0; --i) {
Copy link
Contributor

@access2rohit access2rohit Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch ! :)

for (int i = ndim-1, j = mdim; i >= 0; --i) {
if (small[i] != big[i]) {
--j;
(*stride)[j] = s;
Expand Down
6 changes: 6 additions & 0 deletions tests/nightly/test_large_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def test_topk():
val = nd.topk(b, k=1, axis=0, dtype=np.int64, ret_typ="value")
assert val.sum() == (LARGE_X - 1)


def test_mean():
a = nd.arange(-LARGE_X / 2, LARGE_X / 2 + 1, dtype=np.int64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: even though LARGE_X is divisible by 2 but can we use integer division here LARGE_X//2

b = nd.mean(a, axis=0)
assert b == 0


def test_shape():
b = create_vector(size=LARGE_X)
Expand Down