SciSharp / NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.
https://github.com/SciSharp
Apache License 2.0
1.34k stars 188 forks source link

"System.NotImplementedException: '' --> someArray = np.frombuffer(byteBuffer.ToArray<byte>(), np.uint32); #423

Open mehmetcanbalci-Notrino opened 3 years ago

mehmetcanbalci-Notrino commented 3 years ago

Hello, i got this execption "System.NotImplementedException: ''" when i use this code ; someArray = np.frombuffer(byteBuffer.ToArray(), np.uint32);

if I will use np.int32, it is working as expected.

ghost commented 3 years ago

Hello @mehmetcanbalci-Notrino ,

You got an exception because data type "uint32" is not yet being implemented, only "int32" and "byte".

        public static NDArray frombuffer(byte[] bytes, Type dtype)
        {

            //TODO! all types
            if (dtype.Name == "Int32")
            {
                var size = bytes.Length / InfoOf<int>.Size;
                var ints = new int[size];
                for (var index = 0; index < size; index++)
                {
                    ints[index] = BitConverter.ToInt32(bytes, index * InfoOf<int>.Size);
                }

                return new NDArray(ints);
            }
            else if (dtype.Name == "Byte")
            {
                var size = bytes.Length / InfoOf<byte>.Size;
                var ints = bytes;
                return new NDArray(bytes);
            }

            throw new NotImplementedException("");
        }