-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbitwise_left_shift.py
More file actions
33 lines (24 loc) · 895 Bytes
/
bitwise_left_shift.py
File metadata and controls
33 lines (24 loc) · 895 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
33
import functools
from ninetoothed import Tensor
import ninetoothed.language as ntl
from ntops.kernels.element_wise import arrangement
def application(input, other, output):
if input.dtype == ntl.int32:
mask = (other > 31) | (other < 0)
elif input.dtype == ntl.int64:
mask = (other > 63) | (other < 0)
elif input.dtype == ntl.uint8:
mask = (other > 7) | (other < 0)
else:
mask = ntl.zeros_like(other)
shift = ntl.where(mask, ntl.zeros_like(other), other)
input = ntl.where(mask, ntl.zeros_like(input), input)
output = input << shift
def premake(ndim, dtype=None, block_size=None):
arrangement_ = functools.partial(arrangement, block_size=block_size)
tensors = (
Tensor(ndim, dtype=dtype),
Tensor(ndim, dtype=dtype),
Tensor(ndim, dtype=dtype),
)
return arrangement_, application, tensors