Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions src/operator/nn/moments-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ inline bool MomentsType(const nnvm::NodeAttrs& attrs,

struct VarBroadcastKernel {
template<typename DType>
MSHADOW_XINLINE static void Map(int i,
MSHADOW_XINLINE static void Map(index_t i,
DType *out,
const DType *data,
const DType *mean,

@access2rohit access2rohit Oct 13, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you change index variables inside the kernel to index_t from size_t

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed

mshadow::Shape<6> data_shape,
mshadow::Shape<6> mean_shape) {
size_t data_idx = i;
size_t mean_idx = i;
size_t data_stride = 1;
size_t mean_stride = 1;
index_t data_idx = i;
index_t mean_idx = i;
index_t data_stride = 1;
index_t mean_stride = 1;
for (int axis = 5; axis >= 0; --axis) {
size_t axis_idx = data_idx % data_shape[axis];
index_t axis_idx = data_idx % data_shape[axis];
mean_idx -= axis_idx * data_stride;
if (mean_shape[axis] != 1) {
mean_idx += axis_idx * mean_stride;
Expand Down
34 changes: 33 additions & 1 deletion tests/nightly/test_np_large_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def test_diagflat():
assert inp.grad.shape == inp.shape
assert inp.grad[-1, -1] == 1


@use_np
def test_diagonal():
inp = np.zeros((2, INT_OVERFLOW+2))
Expand Down Expand Up @@ -1967,6 +1967,38 @@ def test_array_split():
assert out[1][-1][-1] == 2


@use_np
def test_std():
N = 2*20
inp = np.zeros((2, INT_OVERFLOW))
inp[-1, -1] = N
inp.attach_grad()
with mx.autograd.record():
out = np.std(inp, axis=1)
out.backward()
assert out.shape == (2, )

@access2rohit access2rohit Oct 13, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we directly comapre the outputs with actual numpy's operators ? call import numpy as _np
Then we probably don't have to worry about correctness of the formula used? @Zha0q1 wdyt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried that first but it would take too long to run on large tensors so I instead derived a analytical formula. The correctness has been verified with small tensor size first then I switched to large tenosr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ref = ((float(N)/INT_OVERFLOW)**2 * (INT_OVERFLOW-1))**0.5
assert_almost_equal(out[1], ref, rtol=1e-5, atol=1e-5)
assert inp.grad.shape == inp.shape
assert inp.grad[-1, -1] == 0


@use_np
def test_var():
N = 2*20
inp = np.zeros((2, INT_OVERFLOW))
inp[-1, -1] = N
inp.attach_grad()
with mx.autograd.record():
out = np.var(inp, axis=1)
out.backward()
assert out.shape == (2, )
ref = (float(N)/INT_OVERFLOW)**2 * (INT_OVERFLOW-1)
assert_almost_equal(out[1], ref, rtol=1e-5, atol=1e-5)

assert inp.grad.shape == inp.shape
assert inp.grad[-1, -1] == 0

@use_np
def test_rollaxis():
inp = np.zeros((1, 1, 2, INT_OVERFLOW, 1))
Expand Down