You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ma...@apache.org on 2020/10/25 22:41:59 UTC
[incubator-mxnet] branch master updated: fix (#19376)
This is an automated email from the ASF dual-hosted git repository.
manuseth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new 95f9ea2 fix (#19376)
95f9ea2 is described below
commit 95f9ea2c89a6abd7dee4683bfca330d4d7516333
Author: Zhaoqi Zhu <zh...@gmail.com>
AuthorDate: Sun Oct 25 15:40:40 2020 -0700
fix (#19376)
---
src/api/operator/numpy/np_init_op.cc | 10 ++++++++--
src/operator/numpy/np_init_op.h | 4 ++--
src/operator/tensor/init_op.h | 4 ++--
tests/nightly/test_np_large_array.py | 16 ++++++++++++++++
4 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/api/operator/numpy/np_init_op.cc b/src/api/operator/numpy/np_init_op.cc
index b9ab897..0c61772 100644
--- a/src/api/operator/numpy/np_init_op.cc
+++ b/src/api/operator/numpy/np_init_op.cc
@@ -271,7 +271,10 @@ MXNET_REGISTER_API("_npi.linspace")
op::LinspaceParam param;
param.start = args[0].operator double();
param.stop = args[1].operator double();
- param.num = args[2].operator int();
+ if (features::is_enabled(features::INT64_TENSOR_SIZE))
+ param.num = args[2].operator int64_t();
+ else
+ param.num = args[2].operator int();
if (args[3].type_code() == kNull) {
param.endpoint = true;
} else {
@@ -301,7 +304,10 @@ MXNET_REGISTER_API("_npi.logspace")
op::LogspaceParam param;
param.start = args[0].operator double();
param.stop = args[1].operator double();
- param.num = args[2].operator int();
+ if (features::is_enabled(features::INT64_TENSOR_SIZE))
+ param.num = args[2].operator int64_t();
+ else
+ param.num = args[2].operator int();
if (args[3].type_code() == kNull) {
param.endpoint = true;
} else {
diff --git a/src/operator/numpy/np_init_op.h b/src/operator/numpy/np_init_op.h
index a0f4523..016c889 100644
--- a/src/operator/numpy/np_init_op.h
+++ b/src/operator/numpy/np_init_op.h
@@ -238,7 +238,7 @@ void IdentityCompute(const nnvm::NodeAttrs& attrs,
struct LogspaceParam : public dmlc::Parameter<LogspaceParam> {
double start;
double stop;
- int num;
+ index_t num;
bool endpoint;
double base;
std::string ctx;
@@ -302,7 +302,7 @@ void LogspaceCompute(const nnvm::NodeAttrs& attrs,
const LogspaceParam& param = nnvm::get<LogspaceParam>(attrs.parsed);
if (param.num == 0) return;
MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
- int step_num = param.endpoint ? param.num - 1 : param.num;
+ index_t step_num = param.endpoint ? param.num - 1 : param.num;
double step = step_num > 0 ? (param.stop - param.start) / step_num : 0.0f;
Kernel<logspace_fwd, xpu>::Launch(s, outputs[0].Size(), param.start, param.stop, param.base,
step, req[0], outputs[0].dptr<DType>());
diff --git a/src/operator/tensor/init_op.h b/src/operator/tensor/init_op.h
index 753b4b6..ee1f284 100644
--- a/src/operator/tensor/init_op.h
+++ b/src/operator/tensor/init_op.h
@@ -325,7 +325,7 @@ inline void RangeParamParser(nnvm::NodeAttrs* attrs) {
struct LinspaceParam : public dmlc::Parameter<LinspaceParam> {
double start;
double stop;
- int num;
+ index_t num;
bool endpoint;
std::string ctx;
int dtype;
@@ -749,7 +749,7 @@ void LinspaceCompute(const nnvm::NodeAttrs& attrs,
Stream<xpu> *s = ctx.get_stream<xpu>();
const LinspaceParam& param = nnvm::get<LinspaceParam>(attrs.parsed);
MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
- int step_num = param.endpoint ? param.num - 1 : param.num;
+ index_t step_num = param.endpoint ? param.num - 1 : param.num;
double step = step_num > 0 ? (param.stop - param.start) / step_num : 0.0f;
Kernel<linspace_fwd, xpu>::Launch(s,
outputs[0].Size(),
diff --git a/tests/nightly/test_np_large_array.py b/tests/nightly/test_np_large_array.py
index 3096038..c275a36 100644
--- a/tests/nightly/test_np_large_array.py
+++ b/tests/nightly/test_np_large_array.py
@@ -2112,6 +2112,22 @@ def test_dsplit():
@use_np
+def test_logspace():
+ data = np.logspace(1.0, 10.0, INT_OVERFLOW)
+ assert data.shape == (INT_OVERFLOW, )
+ assert data[0] == 10 and data[-1] == 10000000000
+ assert_almost_equal(data[HALF_INT_OVERFLOW], np.array(10**5.5), \
+ rtol=1e-3, atol=1e-5)
+
+@use_np
+def test_linspace():
+ data = np.linspace(0, 1000, INT_OVERFLOW)
+ assert data.shape == (INT_OVERFLOW, )
+ assert data[0] == 0 and data[-1] == 1000
+ assert data[HALF_INT_OVERFLOW] == 500
+
+
+@use_np
def test_histogram():
inp = np.ones((INT_OVERFLOW, 2))
inp[-1, -1] = 2