forked from SciSharp/Numpy.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDtype.cs
More file actions
84 lines (77 loc) · 3.16 KB
/
Dtype.cs
File metadata and controls
84 lines (77 loc) · 3.16 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Text;
using Python.Runtime;
namespace Numpy
{
public partial class Dtype : PythonObject
{
public Dtype(PyObject pyobj) : base(pyobj)
{
}
public Dtype(Dtype t) : base((PyObject)t.PyObject)
{
}
}
public static class DtypeExtensions
{
public static Dtype GetDtype(this object obj)
{
switch (obj)
{
case bool o: return np.bool8;
case sbyte o: return np.int8;
case byte o: return np.uint8;
case short o: return np.int16;
case ushort o: return np.uint16;
case int o: return np.int32;
case uint o: return np.uint32;
case long o: return np.int64;
case ulong o: return np.uint64;
case float o: return np.float32;
case double o: return np.float64;
case string o: return np.unicode_;
case char o: return np.unicode_;
case bool[] o: return np.bool8;
case byte[] o: return np.@byte;
case short[] o: return np.int16;
case int[] o: return np.int32;
case long[] o: return np.int64;
case float[] o: return np.float32;
case double[] o: return np.float64;
case string[] o: return np.unicode_;
case char[] o: return np.unicode_;
case bool[,] o: return np.bool8;
case byte[,] o: return np.uint8;
case short[,] o: return np.int16;
case int[,] o: return np.int32;
case long[,] o: return np.int64;
case float[,] o: return np.float32;
case double[,] o: return np.float64;
case string[,] o: return np.unicode_;
case char[,] o: return np.unicode_;
case bool[,,] o: return np.bool8;
case byte[,,] o: return np.uint8;
case short[,,] o: return np.int16;
case int[,,] o: return np.int32;
case long[,,] o: return np.int64;
case float[,,] o: return np.float32;
case double[,,] o: return np.float64;
case string[,,] o: return np.unicode_;
case char[,,] o: return np.unicode_;
default: throw new ArgumentException("Can not convert type of given object to dtype: " + obj.GetType());
}
}
//public static dtype ToDtype(this Type t)
//{
// if (t == typeof(byte)) return dtype.UInt8;
// if (t == typeof(short)) return dtype.Int16;
// if (t == typeof(int)) return dtype.Int32;
// if (t == typeof(long)) return dtype.Int64;
// if (t == typeof(float)) return dtype.Float32;
// if (t == typeof(double)) return dtype.Float64;
// throw new ArgumentException("Can not convert given type to dtype: " + t);
//}
}
}