Skip to content

Commit

Permalink
Add unit tests for the SIMD __rfloordiv__() method
Browse files Browse the repository at this point in the history
The support for __rfloordiv__() with SIMD types was added in the following commit:
f5aee40

This commit includes:
  - Unit tests for __rfloordiv__() in SIMD types.
  - The missing constraint added to the method's implementation.
  • Loading branch information
peymanbr committed May 7, 2024
1 parent 80f0774 commit 8c71759
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/src/builtin/simd.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ struct SIMD[type: DType, size: Int = simdwidthof[type]()](
Returns:
`floor(rhs / self)` value.
"""
constrained[type.is_numeric(), "the type must be numeric"]()
return rhs // self

@always_inline("nodebug")
Expand Down
18 changes: 18 additions & 0 deletions stdlib/test/builtin/test_simd.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ def test_floordiv():
assert_equal(Float32(2) // Float32(-2), -1)
assert_equal(Float32(99) // Float32(-2), -50)

assert_equal(
Int32(2) // SIMD[DType.int32, 4](2, 4, -2, -4),
SIMD[DType.int32, 4](1, 0, -1, -1),
)
assert_equal(
2 // SIMD[DType.int32, 4](2, 4, -2, -4),
SIMD[DType.int32, 4](1, 0, -1, -1),
)

assert_equal(
Float32(3) // SIMD[DType.float32, 4](3, -4, 1, 5),
SIMD[DType.float32, 4](1, -1, 3, 0),
)
assert_equal(
3 // SIMD[DType.float32, 4](3, -4, 1, 5),
SIMD[DType.float32, 4](1, -1, 3, 0),
)


def test_mod():
assert_equal(Int32(99) % Int32(1), 0)
Expand Down

0 comments on commit 8c71759

Please sign in to comment.