-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (39 loc) · 1.41 KB
/
Program.cs
File metadata and controls
49 lines (39 loc) · 1.41 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
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Numpy;
using Python.Runtime;
namespace MatmulExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Efficient matrix multiplication with NumPy:");
// before starting the measurement, let us call numpy once to get the setup checks done.
np.arange(1);
var stopwatch = Stopwatch.StartNew();
var a1 = np.arange(60000).reshape(300, 200);
var a2 = np.arange(80000).reshape(200, 400);
var result = np.matmul(a1, a2);
stopwatch.Stop();
Console.WriteLine($"execution time with NumPy: {stopwatch.Elapsed.TotalMilliseconds}ms\n");
Console.WriteLine("Result:\n" + result.repr);
Console.WriteLine("executing on bg thread");
var a = np.arange(1000);
var b = np.arange(1000);
// https://github.com/pythonnet/pythonnet/issues/109
PythonEngine.BeginAllowThreads();
Task.Run(() =>
{
using (Py.GIL())
{
np.matmul(a, b);
Console.WriteLine("matmul on bg thread is done");
}
}).Wait();
Console.WriteLine("Press key");
Console.ReadKey();
}
}
}