forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.Division.cs
More file actions
119 lines (113 loc) · 4.52 KB
/
NdArray.Division.cs
File metadata and controls
119 lines (113 loc) · 4.52 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Numerics;
using NumSharp.Core.Shared;
namespace NumSharp.Core
{
public partial class NDArray<T>
{
public static NDArray<T> operator /(NDArray<T> np1, NDArray<T> np2)
{
NDArray<T> sum = new NDArray<T>();
sum.Shape = np1.Shape;
sum.Data = new T[np1.Data.Length];
switch (sum.Data)
{
case double[] sumArray :
{
double[] np1Array = np1.Data as double[];
double[] np2Array = np2.Data as double[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / np2Array[idx];
break;
}
case float[] sumArray :
{
float[] np1Array = np1.Data as float[];
float[] np2Array = np2.Data as float[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / np2Array[idx];
break;
}
case Complex[] sumArray :
{
Complex[] np1Array = np1.Data as Complex[];
Complex[] np2Array = np2.Data as Complex[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / np2Array[idx];
break;
}
case Quaternion[] sumArray :
{
Quaternion[] np1Array = np1.Data as Quaternion[];
Quaternion[] np2Array = np2.Data as Quaternion[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / np2Array[idx];
break;
}
default :
{
throw new Exception("The operation is not implemented for the " + typeof(T).Name);
}
}
return (NDArray<T>) sum;
}
public static NDArray<T> operator /(NDArray<T> np1, T scalar)
{
NDArray<T> sum = new NDArray<T>();
sum.Shape = np1.Shape;
sum.Data = new T[np1.Data.Length];
switch (scalar)
{
case double scalarDouble :
{
double[] np1Array = np1.Data as double[];
double[] sumArray = sum.Data as double[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / scalarDouble;
break;
}
case float scalarFloat :
{
float[] np1Array = np1.Data as float[];
float[] sumArray = sum.Data as float[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / scalarFloat;
break;
}
case Complex scalarComplex :
{
Complex[] np1Array = np1.Data as Complex[];
Complex[] sumArray = sum.Data as Complex[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / scalarComplex;
break;
}
case Quaternion scalarQuaternion :
{
Quaternion[] np1Array = np1.Data as Quaternion[];
Quaternion[] sumArray = sum.Data as Quaternion[];
// for is faster than linq
for (int idx = 0; idx < sumArray.Length;idx++)
sumArray[idx] = np1Array[idx] / scalarQuaternion;
break;
}
default :
{
throw new Exception("The operation is not implemented for the " + typeof(T).Name);
}
}
return (NDArray<T>) sum;
}
}
}