forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnp.frombuffer.cs
More file actions
50 lines (43 loc) · 1.4 KB
/
np.frombuffer.cs
File metadata and controls
50 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using NumSharp.Utilities;
namespace NumSharp
{
public static partial class np
{
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("");
}
public static NDArray frombuffer(byte[] bytes, string dtype)
{
if (dtype == ">u4")
{
var size = bytes.Length / InfoOf<uint>.Size;
var ints = new uint[size];
for (var index = 0; index < size; index++)
{
ints[index] = (uint)(bytes[0] * 256 + bytes[1] + bytes[2] * 256 + bytes[3]);
}
return new NDArray(ints);
}
throw new NotImplementedException("");
}
}
}