forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNDArrayTester2D.cs
More file actions
94 lines (81 loc) · 2.82 KB
/
NDArrayTester2D.cs
File metadata and controls
94 lines (81 loc) · 2.82 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
using System;
using System.Numerics;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using NumSharp;
namespace NumSharp.Benchmark
{
//[RPlotExporter, RankColumn]
[SimpleJob(RunStrategy.ColdStart, targetCount: 20)]
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
[HtmlExporter]
public class NDArrayTester2D
{
public NDArray np1Matrix;
public NDArray np2Matrix;
public NDArray np3Matrix;
public double[][] np1DoubleMatrix;
public double[][] np2DoubleMatrix;
public double[][] np3DoubleMatrix;
[GlobalSetup]
public void Setup()
{
// first array
np1Matrix = np.arange(2, 100 * 100 + 2).reshape(100, 100);
np1DoubleMatrix = (double[][])np1Matrix.ToJaggedArray<double>();
// second array
np2Matrix = np.arange(1, 100 * 100 + 1).reshape(100, 100);
np2DoubleMatrix = (double[][])np2Matrix.ToJaggedArray<double>();
}
[Benchmark]
public void DirectAddition1D()
{
for (int idx = 0; idx < np1DoubleMatrix.Length; idx++)
for (int jdx = 0; jdx < np1DoubleMatrix[0].Length; jdx++)
np3DoubleMatrix[idx][jdx] = np1DoubleMatrix[idx][jdx] + np2DoubleMatrix[idx][jdx];
}
[Benchmark]
public void NDArrayAddition1D()
{
np3Matrix = np1Matrix + np2Matrix;
}
[Benchmark]
public void DirectSubstration1D()
{
for (int idx = 0; idx < np1DoubleMatrix.Length; idx++)
for (int jdx = 0; jdx < np1DoubleMatrix[0].Length; jdx++)
np3DoubleMatrix[idx][jdx] = np1DoubleMatrix[idx][jdx] - np2DoubleMatrix[idx][jdx];
}
[Benchmark]
public void NDArraySubstraction1D()
{
np3Matrix = np1Matrix - np2Matrix;
}
[Benchmark]
public void DirectMatrixMultiplication()
{
np3DoubleMatrix = new double[np1DoubleMatrix.Length][];
for (int idx = 0; idx < np3DoubleMatrix.Length; idx++)
{
np3DoubleMatrix[idx] = new double[np1DoubleMatrix[0].Length];
}
for (int idx = 0; idx < np1DoubleMatrix.Length; idx++)
{
for (int jdx = 0; jdx < np1DoubleMatrix[0].Length; jdx++)
{
np3DoubleMatrix[idx][jdx] = 0;
for (int kdx = 0; kdx < np2DoubleMatrix.Length; kdx++)
{
np3DoubleMatrix[idx][jdx] += np1DoubleMatrix[idx][kdx] * np2DoubleMatrix[kdx][jdx];
}
}
}
}
[Benchmark]
public void NDArrayMatrixMultilication()
{
//np3Matrix = np1Matrix.dot(np2Matrix);
}
}
}