-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.py
37 lines (30 loc) · 1.29 KB
/
tests.py
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
import numpysharedarray as sa
import numpy as np
# def test_create_and_remove():
# arr = np.zeros((10,10))
# assert sa.create_mem_sh("/base_share_array_cr", arr) == True
# assert sa.check_mem_sh("/base_share_array_cr") == True
# sa.delete_mem_sh("/base_share_array_cr")
# assert sa.check_mem_sh("/base_share_array_cr") == False
def test_array_int():
arr = np.zeros((1920,1080)).astype(np.int32)
assert sa.create_mem_sh("/base_share_array_int", arr) == True
array_attached = sa.attach_mem_sh("/base_share_array_int")
arr = sa.attach_mem_sh("/base_share_array_int")
assert sa.check_mem_sh("/base_share_array_int") == True
assert array_attached.dtype == np.dtype(np.int32)
#shared numpy array
arr[:50, 50:87] = 5
assert np.all(array_attached[:50, 50:87] == 5)
assert np.all(array_attached[60:, 20:600] == 0)
def test_array_float():
arr = np.zeros((1920,1080)).astype(np.float32)
assert sa.create_mem_sh("/base_share_array_int", arr) == True
array_attached = sa.attach_mem_sh("/base_share_array_int")
arr = sa.attach_mem_sh("/base_share_array_int")
assert sa.check_mem_sh("/base_share_array_int") == True
assert array_attached.dtype == np.dtype(np.float32)
#shared numpy array
arr[:50, 50:87] = 5
assert np.all(array_attached[:50, 50:87] == 5.)
assert np.all(array_attached[60:, 20:600] == 0.)