deepakkumar1984 / MxNet.Sharp

.NET Standard bindings for Apache MxNet with Imperative, Symbolic and Gluon Interface for developing, training and deploying Machine Learning models in C#. https://mxnet.tech-quantum.com/
Apache License 2.0
149 stars 8 forks source link

nd.Array Yielding Unexpected Results #4

Closed tk4218 closed 4 years ago

tk4218 commented 4 years ago

I am trying to create an NDArray by using nd.Array(), however if I pass in Int32 values for the array, it is giving me unexpected results.

For example, if I create: var ndArray = nd.Array(new int[] {0, 0, 15, 15})

It creates the NDArray with DType = float32, when I am expecting DType = int32 The underlying ArrayData for the object becomes {0, 0, 2.101948E-44, 2.101948E-44}, when it should be {0, 0, 15, 15}

Additionally, calling nd.Array() and passing in the array as a NumpyDotNet NDArray also creates unexpected results. In this case, it appears to be creating the NDArray as it does in the first scenario, then casting to int32, which results in ArrayData being {0, 0, 0, 0}

I believe if nd.Array() used NativeMethods.MXNDArrayCreateEx() instead of NativeMethods.MXNDArrayCreate(), the DType could be determined from the passed in array and passed to the function to set the NDArray properly.

deepakkumar1984 commented 4 years ago

MXNDArrayCreateEx let you pass dtype to define the type of data. Looking into the issue.

On Fri, Jul 3, 2020 at 7:34 AM tk4218 notifications@github.com wrote:

I am trying to create an NDArray by using nd.Array(), however if I pass in Int32 values for the array, it is giving me unexpected results.

For example, if I create: var ndArray = nd.Array(new int[] {0, 0, 15, 15})

It creates the NDArray with DType = float32, when I am expecting DType = int32 The underlying ArrayData for the object becomes {0, 0, 2.101948E-44, 2.101948E-44}, when it should be {0, 0, 15, 15}

Additionally, calling nd.Array() and passing in the array as a NumpyDotNet NDArray also creates unexpected results. In this case, it appears to be creating the NDArray as it does in the first scenario, then casting to int32, which results in ArrayData being {0, 0, 0, 0}

I believe if nd.Array() used NativeMethods.MXNDArrayCreateEx() instead of NativeMethods.MXNDArrayCreate(), the DType could be determined from the passed in array and passed to the function to set the NDArray properly.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tech-quantum/MxNet.Sharp/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQJAKOPM5OCLFUITLTKFITRZT75ZANCNFSM4OPI2KBQ .

-- Regards, Deepak

deepakkumar1984 commented 4 years ago

Fixed and nuget updated. Please check

On Fri, Jul 3, 2020 at 9:40 AM Deepak Battini deepakkumar1984@gmail.com wrote:

MXNDArrayCreateEx let you pass dtype to define the type of data. Looking into the issue.

On Fri, Jul 3, 2020 at 7:34 AM tk4218 notifications@github.com wrote:

I am trying to create an NDArray by using nd.Array(), however if I pass in Int32 values for the array, it is giving me unexpected results.

For example, if I create: var ndArray = nd.Array(new int[] {0, 0, 15, 15})

It creates the NDArray with DType = float32, when I am expecting DType = int32 The underlying ArrayData for the object becomes {0, 0, 2.101948E-44, 2.101948E-44}, when it should be {0, 0, 15, 15}

Additionally, calling nd.Array() and passing in the array as a NumpyDotNet NDArray also creates unexpected results. In this case, it appears to be creating the NDArray as it does in the first scenario, then casting to int32, which results in ArrayData being {0, 0, 0, 0}

I believe if nd.Array() used NativeMethods.MXNDArrayCreateEx() instead of NativeMethods.MXNDArrayCreate(), the DType could be determined from the passed in array and passed to the function to set the NDArray properly.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tech-quantum/MxNet.Sharp/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQJAKOPM5OCLFUITLTKFITRZT75ZANCNFSM4OPI2KBQ .

-- Regards, Deepak

-- Regards, Deepak