1 | using System;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
4 | public static class BatchOperations {
|
---|
5 | public const int BATCHSIZE = 64;
|
---|
6 |
|
---|
7 | public static void Load(double[] a, double[] b) {
|
---|
8 | Array.Copy(b, a, BATCHSIZE);
|
---|
9 | }
|
---|
10 |
|
---|
11 | public static void Add(double[] a, double[] b) {
|
---|
12 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
13 | a[i] += b[i];
|
---|
14 | }
|
---|
15 | }
|
---|
16 |
|
---|
17 | public static void Sub(double[] a, double[] b) {
|
---|
18 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
19 | a[i] -= b[i];
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public static void Div(double[] a, double[] b) {
|
---|
24 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
25 | a[i] /= b[i];
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public static void Mul(double[] a, double[] b) {
|
---|
30 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
31 | a[i] *= b[i];
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static void Neg(double[] a, double[] b) {
|
---|
36 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
37 | a[i] = -b[i];
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public static void Inv(double[] a, double[] b) {
|
---|
42 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
43 | a[i] = 1 / b[i];
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public static void Log(double[] a, double[] b) {
|
---|
48 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
49 | a[i] = Math.Log(b[i]);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public static void Exp(double[] a, double[] b) {
|
---|
53 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
54 | a[i] = Math.Exp(b[i]);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public static void Sin(double[] a, double[] b) {
|
---|
58 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
59 | a[i] = Math.Sin(b[i]);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public static void Cos(double[] a, double[] b) {
|
---|
63 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
64 | a[i] = Math.Cos(b[i]);
|
---|
65 | }
|
---|
66 |
|
---|
67 | public static void Tan(double[] a, double[] b) {
|
---|
68 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
69 | a[i] = Math.Tan(b[i]);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public static void Pow(double[] a, double[] b) {
|
---|
73 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
74 | a[i] = Math.Pow(a[i], Math.Round(b[i]));
|
---|
75 | }
|
---|
76 |
|
---|
77 | public static void Root(double[] a, double[] b) {
|
---|
78 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
79 | a[i] = Math.Pow(a[i], 1 / Math.Round(b[i]));
|
---|
80 | }
|
---|
81 |
|
---|
82 | public static void Square(double[] a, double[] b) {
|
---|
83 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
84 | a[i] = Math.Pow(b[i], 2d);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public static void Sqrt(double[] a, double[] b) {
|
---|
88 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
89 | a[i] = Math.Sqrt(b[i]);
|
---|
90 | }
|
---|
91 |
|
---|
92 | public static void Cube(double[] a, double[] b) {
|
---|
93 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
94 | a[i] = Math.Pow(b[i], 3d);
|
---|
95 | }
|
---|
96 |
|
---|
97 | public static void CubeRoot(double[] a, double[] b) {
|
---|
98 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
99 | a[i] = Math.Pow(b[i], 1d / 3d);
|
---|
100 | }
|
---|
101 |
|
---|
102 | public static void Absolute(double[] a, double[] b) {
|
---|
103 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
104 | a[i] = Math.Abs(b[i]);
|
---|
105 | }
|
---|
106 |
|
---|
107 | public static void AnalyticQuotient(double[] a, double[] b) {
|
---|
108 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
109 | a[i] = a[i] / Math.Sqrt(1d + b[i] * b[i]);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|