-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex1.ts
91 lines (79 loc) · 1.43 KB
/
ex1.ts
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
import t from '@/webgpu-tensors';
await t.init();
let x = t.rand([5, 3]);
await t.print(x);
x = t.ones([5, 3]);
await t.print(x);
x = t.rand([5, 3]);
await t.print(x);
x = t.tensor([0, 1, 2, 3]);
await t.print(x);
x = t.tensor([
[0, 1, 2, 3],
[3, 4, 5, 6],
]);
await t.print(x);
x = t.tensor([
[
[0, 1],
[2, 3],
],
[
[3, 4],
[5, 6],
],
]);
await t.print(x);
x = t.tensor([
[
[[0], [1]],
[[2], [3]],
],
[
[[3], [4]],
[[5], [6]],
],
]);
await t.print(x);
const tensor = t.rand([3, 4]);
t.print(`Shape of tensor: ${tensor.shape}`);
t.print(`Datatype of tensor: ${tensor.dtype}`);
t.print(`Device tensor is stored on: ${tensor.device}`);
await t.print('tensor', tensor, x);
x = t.empty([3, 4, 5]);
t.print(x.size());
t.print(x.size(1));
t.reset();
x = t.tensor([
[0, 0, 0, 0],
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3],
]);
const y = t.tensor([
[0, 0, 0, 0],
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3],
]);
await t.print('matmul', x, y);
const result = t.matmul(x, y);
t.print('matmul', result);
x = t.tensor([
[-3, -2, -1, 0],
[0, 1, 2, 3],
[0, 1, 2, 3],
[0, 1, 2, 3],
]);
const max = t.maximum(x, 0);
await t.print('maximum=', max);
// Test for maximum function
const testTensor = t.tensor([
[-3, -2, -1, 0],
[0, 1, 2, 3],
[0, 1, 2, 3],
[0, 1, 2, 3],
]);
const mul = t.matmul(testTensor, x);
const maxResult = t.maximum(mul, 0);
await t.print('Test maximum=', maxResult);