-
Notifications
You must be signed in to change notification settings - Fork 2
/
Function.py
93 lines (69 loc) · 1.32 KB
/
Function.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
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
92
93
import taichi as ti
@ti.func
def Normalize(mv):
mv_normalize = ti.Vector([0., 0., 0.])
if not mv.norm() == 0:
mv_normalize = mv.normalized()
return mv_normalize
@ti.func
def sign(x):
a = -1
if x >= 0:
a = 1
return a
@ti.func
def SIGN(vector):
for i in ti.static(range(vector.n)):
if vector[i] > 0:
vector[i] = vector[i]
elif vector[i] < 0:
vector[i] = -vector[i]
elif vector[i] == 0:
vector[i] = 0
return vector
@ti.func
def Zero2One(x):
k = 1
if x == 1:
k = 0
return k
@ti.func
def Zero2OneVector(x):
for i in ti.static(range(x.n)):
if x[i] == 1:
x[i] = 0
else:
x[i] = 1
return x
@ti.func
def Max(i, j):
m = j
if i > j:
m = i
return m
@ti.func
def Min(i, j):
m = j
if i < j:
m = i
return m
@ti.func
def Diagonal(vec):
return ti.Matrix([[vec[0], 0, 0], [0, vec[1], 0], [0, 0, vec[2]]])
def GreatestPowderOfTwo(length):
k, q= 1, 0
while k < length:
k *= 2
q += 1
return int(k), int(q)
@ti.func
def EffectiveValue(x, y):
return x * y / (x + y)
def NonNegative(x):
if x <= 0:
return 1
else:
return int(x)
@ti.func
def xor(a, b):
return (a + b) & 1