[16285] | 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) {
|
---|
[16287] | 12 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
| 13 | a[i] += b[i];
|
---|
[16285] | 14 | }
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public static void Sub(double[] a, double[] b) {
|
---|
[16287] | 18 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
| 19 | a[i] -= b[i];
|
---|
[16285] | 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public static void Div(double[] a, double[] b) {
|
---|
[16287] | 24 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
| 25 | a[i] /= b[i];
|
---|
[16285] | 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public static void Mul(double[] a, double[] b) {
|
---|
[16287] | 30 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
| 31 | a[i] *= b[i];
|
---|
[16285] | 32 | }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public static void Neg(double[] a, double[] b) {
|
---|
[16287] | 36 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
| 37 | a[i] = -b[i];
|
---|
[16285] | 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public static void Inv(double[] a, double[] b) {
|
---|
[16287] | 42 | for (int i = 0; i < BATCHSIZE; ++i) {
|
---|
| 43 | a[i] = 1 / b[i];
|
---|
[16285] | 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 | }
|
---|
[16293] | 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 | }
|
---|
[16656] | 71 | public static void Tanh(double[] a, double[] b) {
|
---|
| 72 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 73 | a[i] = Math.Tanh(b[i]);
|
---|
| 74 | }
|
---|
[16293] | 75 |
|
---|
| 76 | public static void Pow(double[] a, double[] b) {
|
---|
| 77 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 78 | a[i] = Math.Pow(a[i], Math.Round(b[i]));
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public static void Root(double[] a, double[] b) {
|
---|
| 82 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 83 | a[i] = Math.Pow(a[i], 1 / Math.Round(b[i]));
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public static void Square(double[] a, double[] b) {
|
---|
| 87 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 88 | a[i] = Math.Pow(b[i], 2d);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public static void Sqrt(double[] a, double[] b) {
|
---|
| 92 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 93 | a[i] = Math.Sqrt(b[i]);
|
---|
| 94 | }
|
---|
[16356] | 95 |
|
---|
| 96 | public static void Cube(double[] a, double[] b) {
|
---|
| 97 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 98 | a[i] = Math.Pow(b[i], 3d);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public static void CubeRoot(double[] a, double[] b) {
|
---|
| 102 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
[16905] | 103 | a[i] = b[i] < 0 ? -Math.Pow(-b[i], 1d / 3d) : Math.Pow(b[i], 1d / 3d);
|
---|
[16356] | 104 | }
|
---|
| 105 |
|
---|
| 106 | public static void Absolute(double[] a, double[] b) {
|
---|
| 107 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 108 | a[i] = Math.Abs(b[i]);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | public static void AnalyticQuotient(double[] a, double[] b) {
|
---|
| 112 | for (int i = 0; i < BATCHSIZE; ++i)
|
---|
| 113 | a[i] = a[i] / Math.Sqrt(1d + b[i] * b[i]);
|
---|
| 114 | }
|
---|
[16285] | 115 | }
|
---|
| 116 | }
|
---|