ExpressionsΒΆ

Expressions inside of simdy kernels are almost the same as Python expressions but there are few important differences that programmer must be aware of. All conversions between data types must be done explicitly, python annotations to declare data type in function arguments.

Here it will be shown how to write expressions inside of simdy kernels. When mixin data types all conversions must be done explicit.

In below example you can see how to create simple scalar and vector variables.

p1 = int32(3)  # p1 = 3
p2 = float64() # p2 = 0.0

# literal constants can also be used
p3 = 4            # p3 - int32 type
p4 = 2.2          # p4 - float64 type
p5 = float32(1.1) # - you can't use literal constant to create float32

# creation of vector types is also easy
p6 = float64x2(1, 2)     # p6 = 1, 2
p7 = int64x4(4, 4, 5, 6) # p7 = 4, 4, 5, 6
p8 = float32x8(3.2)      # p8 = 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2

Doing arithmetic expressions is also straightforward.

p1 = 5 + 6                            # p1 = 11: int32
p2 = float32(2.2) + float32(1.1)      # p2 = 3.3: float32
p3 = float64x2(1, 2) + float64x2(3, 4)# p3 = 4, 6: float64x2

p4 = float64x4(1, 2, 3, 4)
p5 = float64x4(5, 5, 5, 5)
p6 = p4 * p5 + p5 * float64x4(2.2)    # p6 = 16, 21, 26, 31: float64x4

# Literal constants can also be used in expressions
p7 = float64(3) * 2 + 3               # p7 = 9.0: float64

When you mix data types all conversions must be done explicit.

p1 = 3    # p1 = 3: int32
p2 = 4.4  # p2 = 4.4: float64

p3 = p1 + p2          # Error you can't mix data types
p4 = float64(p1) + p2 # OK

p5 = float32x4(3)
p6 = float64x4(2)
p7 = p5 + p6            # Error
p8 = float64x4(p5) + p6 # OK

Some arithmetic operations are defined for some data types and not for others. In DataType section you can find for each datatype what operations are supported.