Skip to content

Conversation

@Hamiltonian-Action
Copy link
Contributor

The ⊻ operation is associative, commutative, and has a well-defined neutral element. Surprisingly, this was missing from the pre-existing list.

@vchuravy
Copy link
Member

vchuravy commented Jul 1, 2025

Could you also add a test?

@Hamiltonian-Action
Copy link
Contributor Author

Hamiltonian-Action commented Jul 1, 2025

Uncovered another issue with neutral_element(::typeof(Base.:(&)), T) = one(T), which should actually read ~zero(T). Modified accordingly. Test have been augmented and ran successfully on my machine.

Edit: I would disregard the style complaints below. Better to keep the file uniform as it originally were.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2025

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic master) to apply these changes.

Click here to view the suggested changes.
diff --git a/test/testsuite/reductions.jl b/test/testsuite/reductions.jl
index a1bdc83..cf705b8 100644
--- a/test/testsuite/reductions.jl
+++ b/test/testsuite/reductions.jl
@@ -67,9 +67,9 @@ end
             @test compare(A->reduce(+, A; dims=dims, init=zero(ET)), AT, rand(range, sz))
             @test compare(A->reduce(*, A; dims=dims, init=one(ET)), AT, rand(range, sz))
             if ET <: Integer
-                @test compare(A->reduce(&, A; dims=dims, init=~zero(ET)), AT, rand(range, sz))
-                @test compare(A->reduce(|, A; dims=dims, init=zero(ET)), AT, rand(range, sz))
-                @test compare(A->reduce(⊻, A; dims=dims, init=zero(ET)), AT, rand(range, sz))
+                @test compare(A -> reduce(&, A; dims = dims, init = ~zero(ET)), AT, rand(range, sz))
+                @test compare(A -> reduce(|, A; dims = dims, init = zero(ET)), AT, rand(range, sz))
+                @test compare(A -> reduce(⊻, A; dims = dims, init = zero(ET)), AT, rand(range, sz))
             end
         end
     end

@Hamiltonian-Action Hamiltonian-Action changed the title Defining neutral_element for xor (⊻). Defining neutral_element for xor (⊻) and fixing it for and (&). Jul 1, 2025
@maleadt
Copy link
Member

maleadt commented Jul 2, 2025

Yeah don't worry about the formatter, they're just a suggestion.

@christiangnrd
Copy link
Member

Is this good to go?

Copy link
Member

@maleadt maleadt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failures seem unrelated.

@maleadt maleadt merged commit 4b5f6cb into JuliaGPU:master Jul 14, 2025
13 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants