Skip to content

Add missing, basic bool operations - #154

Open
benikm91 wants to merge 1 commit into
dimwit-dev:mainfrom
benikm91:bool-operators
Open

Add missing, basic bool operations#154
benikm91 wants to merge 1 commit into
dimwit-dev:mainfrom
benikm91:bool-operators

Conversation

@benikm91

Copy link
Copy Markdown
Collaborator

Add missing basic Boolean operations. However, we must decide how to do this. I propose that there must be exactly one way to do it, so we must pick one of the following:

t and t2 // Notation proposed in this PR
t.and(t2) // Alternative A
t && t2 // Alternative B
t & t2 // Alternative C
t + t2 // Alternative D

Why not Alternative A: I think and is an operator, so infix seems correct to me.
Why not Alternative B: && means short-circuiting, which is wrong in tensorland.
Why not Alternative C: & valid alternative for me. I like "and" just better
Why not Alternative D: + is not that clear; e.g., true + true could also be false to me (finite space).

Broadcasting would look like this; note and! is impossible due to Scala syntax constraints:

t and_! t2 // Notation proposed in this PR
t &! t2 // Alternative C

Here is an overview of the PR and Alternative C for all boolean operations (broadcasted):

 // Notation proposed in this PR
t and_! t2
t or_! t2
t xor_! t2

// Alternative C (not supported)
t &! t2 
t |! t2 
t ^! t2 

Note: I see the _! not as a disadvantage, as I envision similar broadcasting for e.g. where in the future:

// current
val maskedScores = where(attentionMask, attentionScores, Tensor.like(attentionScores).fill(Float.NegativeInfinity))
// future
val maskedScores = where_!(attentionMask, attentionScores, Float.NegativeInfinity)

But this will be a separate PR, let's not discuss where here.

@benikm91
benikm91 requested a review from marcelluethi August 21, 2026 11:42

@marcelluethi marcelluethi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the syntax for both the logical operations and the broadcasting.
Let's try it.

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.

2 participants