reminisce opened a new pull request #14361: [numpy] Add a global switch to turn 
on/off numpy compatibility
URL: https://github.com/apache/incubator-mxnet/pull/14361
 
 
   This PR is implemented based upon the discussion with @eric-haibin-lin. It 
provides two APIs and NumPy-compatible NDArray indexing behavior, i.e. `y = 
x[i]`.
   
   1. `set_numpy_comp(enable)`
   This is a thread-safe utility function for users to enable or disable 
NumPy-compatible behaviors in MXNet. This will generally affect the behavior of 
the following two operations:
       1. NDArray indexing. When `enable=False`, NDArray indexing always 
returns a tensor with `ndim >= 1`, which is the default behavior of MXNet kept 
for backward compatibility. When `enable=True`, NDArray indexing will return a 
tensor with `ndim >= 0`, which is consistent with NumPy's indexing behavior. 
The result tensor with `ndim = 0` is actually a scalar whose shape is `()`. For 
example:
   
       >>> from mxnet.base import set_numpy_comp
       >>> x = mx.nd.arange(6)
       >>> x
       [0. 1. 2. 3. 4. 5.]
       <NDArray 6 @cpu(0)>
       >>> x[1]
       [1.]
       <NDArray 1 @cpu(0)>
       >>> set_numpy_comp(enable=True)
       >>> x[1]
       1.0
       <NDArray  @cpu(0)>
       >>> set_numpy_comp(enable=False)
       >>> x[1]
       [1.]
       <NDArray 1 @cpu(0)>
   
       
       2. NDArray's convenience fluent methods. When `enable=True`, the 
convenience fluent methods will dispatch the calls to NumPy operators if 
implemented in MXNet. For example, given an NDArray `data`, `data.sum()` will 
call `mxnet.ndarray.sum(data)` when `enable=False` (default behavior), and 
mxnet.numpy.sum(data)` when `enable=True`.
   
   
   2. `_is_numpy_comp()`
   This is a thread-safe utility function for checking whether 
NumPy-compatibility has been enabled or disabled. This is implemented for 
developers to use. Users are not expected to call this function.
   
   @junrushao1994 @eric-haibin-lin @szha @zheng-da @yzhliu 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to