-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
63 lines (45 loc) · 1.53 KB
/
util.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
from __future__ import annotations # Delayed parsing of type annotations
import mitsuba as mi
import drjit as dr
def concat_gather(arrays: list):
final_width = 0
for array in arrays:
final_width += dr.width(array)
index = dr.arange(mi.UInt, final_width)
final_array = None
for i in range(len(arrays)):
array = arrays[i]
gathered_array = dr.gather(
type(array), array, index, index < dr.width(array)
) # relies on wrapping behaviour of UInt
if final_array is None:
final_array = gathered_array
else:
final_array = dr.select(
index < dr.width(array), gathered_array, final_array
)
index = index - dr.width(array)
return final_array
def concat_scatter(arrays: list):
final_width = 0
for array in arrays:
final_width += dr.width(array)
dst = dr.zeros(type(arrays[0]), shape=final_width)
count = 0
for array in arrays:
n = dr.shape(array)[-1]
i = dr.arange(mi.UInt32, count, count + n)
dr.scatter(dst, array, i, i < final_width)
count += n
return dst
if __name__ == "__main__":
mi.set_variant("cuda_ad_rgb")
sampler1: mi.Sampler = mi.load_dict({"type": "independent"})
sampler1.seed(0, 126)
sampler2: mi.Sampler = mi.load_dict({"type": "independent"})
sampler2.seed(1, 2)
a = sampler1.next_1d()
b = sampler2.next_1d()
result = concat([a, b])
result2 = concat_scatter([a, b])
assert dr.all(result == result2)