You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/10/30 16:47:16 UTC
[GitHub] piiswrong closed pull request #8472: Fix arange bug on ARM
piiswrong closed pull request #8472: Fix arange bug on ARM
URL: https://github.com/apache/incubator-mxnet/pull/8472
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/src/operator/tensor/init_op.h b/src/operator/tensor/init_op.h
index b2bd15ceec..bb6d3c129f 100644
--- a/src/operator/tensor/init_op.h
+++ b/src/operator/tensor/init_op.h
@@ -378,9 +378,17 @@ void RangeCompute(const nnvm::NodeAttrs& attrs,
Stream<xpu> *s = ctx.get_stream<xpu>();
const RangeParam& param = nnvm::get<RangeParam>(attrs.parsed);
MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
- Kernel<range_fwd, xpu>::Launch(s, outputs[0].Size(),
- static_cast<int>(param.repeat), static_cast<DType>(param.start),
- static_cast<DType>(param.step), req[0], outputs[0].dptr<DType>());
+ // Force unsigned params to take two's complement form on ARM to ensure consistency with x86
+ // results. Casting negative floats to unsigned types is undefined in the CPP standard.
+ auto step = std::is_signed<DType>() ? param.step : static_cast<int>(param.step);
+ auto start = std::is_signed<DType>() ? param.start : static_cast<int>(param.start);
+ Kernel<range_fwd, xpu>::Launch(s,
+ outputs[0].Size(),
+ static_cast<int>(param.repeat),
+ static_cast<DType>(start),
+ static_cast<DType>(step),
+ req[0],
+ outputs[0].dptr<DType>());
});
}
diff --git a/tests/python/unittest/test_operator.py b/tests/python/unittest/test_operator.py
index 5fd2cdc53c..1ad10c8abe 100644
--- a/tests/python/unittest/test_operator.py
+++ b/tests/python/unittest/test_operator.py
@@ -2555,6 +2555,7 @@ def test_arange():
(0, 10),
(5, 100, 4),
(50, -50, -2),
+ (-100, 100, 1),
(1.3, 456.6, 1.3)]
for dtype in dtype_list:
for config in config_list:
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services