-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
32 lines (27 loc) · 752 Bytes
/
example.py
File metadata and controls
32 lines (27 loc) · 752 Bytes
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
import tensorswift
# constructor
# a tensor of (2,2) shape with uninitialized entries
a=tensorswift.SwiftTensor([2,2])
# a tensor of (2,2) shape with initialized entries [[1,4][8,0]]
b=tensorswift.SwiftTensor([1,4,8,0],[2,2])
# empty contstructor, creates a tensor with empty buffer
c=tensorswift.SwiftTensor()
# item can be assigned at particular index
a[1,1]=4
# create different view
# view different but d and a will have same storage
d = a.view([4,1])
# to view shape
print(a.shape)
# to view size
print(a.size())
# operator overloading is done for operations
# return tensor with new storage
print(a+b)
print(a-b)
print(a*b)
print(a/b)
# return a new tensor with appropriate shape
print(a.matmul(b))
# sum of all element of a
print(b.sum())