17 lines
658 B
Mojo
17 lines
658 B
Mojo
# probe: SIMD arithmetic, broadcasting, and reductions
|
|
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
|
# expect-stdout: [1.5, 2.0, -3.0, 4.25]
|
|
# expect-stdout: [3.0, 4.0, -6.0, 8.5]
|
|
# expect-stdout: [2.5, 3.0, -2.0, 5.25]
|
|
# expect-stdout: 4.75 4.25 -3.0
|
|
# expect-stdout: [6, 2, 8, 2] 12
|
|
def main():
|
|
var v = SIMD[DType.float32, 4](1.5, 2.0, -3.0, 4.25)
|
|
var w = SIMD[DType.float32, 4](2.0)
|
|
print(v)
|
|
print(v * w)
|
|
print(v + 1.0)
|
|
print(v.reduce_add(), v.reduce_max(), v.reduce_min())
|
|
var k = SIMD[DType.int32, 4](3, 1, 4, 1)
|
|
print(k * 2, k.reduce_mul())
|