Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fits mask merge behaviour #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix fits mask merge behaviour #24

wants to merge 1 commit into from

Conversation

bennahugo
Copy link
Collaborator

  • Fixes Merge does not work #23 -- switch to logical operations
  • Creates switch to make ever more restrictive masks during merging by logical_and vs default of logical_or

- Fixes #23 -- switch to logical operations
- Creates switch to make ever more restrictive masks during merging
by logical_and vs default of logical_or
@bennahugo bennahugo requested a review from o-smirnov March 1, 2023 22:16
@@ -145,6 +147,8 @@ def main():
help='Merge in one or more masks or region files')
parser.add_argument('--subtract', dest='subtract', metavar="MASK(s)|REG(s)", nargs='+',
help='Subract one or more masks or region files')
parser.add_argument('--merge_and', dest='mergeand', action='store_true',
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, I would prefer --merge-and over --merge_and -- but thinking about it another minute, it's not really a "merge" operation, it's an "intersect"... I think the CLI would be cleaner if this was defined as a separate top-level operation rather than a flag on top of "merge":

  parser.add_argument('--merge', dest='merge', metavar="MASK(s)|REG(s)", nargs='+',
                        help='Merge in one or more masks or region files')
  parser.add_argument('--subtract', dest='subtract', metavar="MASK(s)|REG(s)", nargs='+',
                        help='Subract one or more masks or region files')
  parser.add_argument('--intersect', dest='intersect', metavar="MASK(s)|REG(s)", nargs='+',
                        help='Intersect with one or more masks or region files')

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we just implement explicit, top level logical OR / AND / XOR operations? I think the meaning of "intersect" is less clear. Wrote a simple script for this ages ago and have used it more times than I can count, so it's probably worth adding this general functionality to breizorro...

https://github.com/IanHeywood/oxkat/blob/master/tools/image_logic.py

Copy link
Contributor

@o-smirnov o-smirnov Mar 2, 2023

Choose a reason for hiding this comment

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

Set theory language vs. boolean logic language, take your pick...

But then add_argument does allow multiple option names, so why not have it both ways:

parser.add_argument('--merge', '--or', dest='merge', metavar="MASK(s)|REG(s)", nargs='+',
                        help='Merge (logical-OR) one or more masks or region files')
parser.add_argument('--intersect', '--and', dest='intersect', metavar="MASK(s)|REG(s)", nargs='+',
                        help='Intersect (logical-AND) one or more masks or region files')

Just not sure what --subtract is in boolean language? It's not XOR (and is XOR conceivably useful for masks anyway?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think subtract is subtract...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just not sure what --subtract is in boolean language?

NAND? 🤔

is XOR conceivably useful for masks anyway?

Probably not (that's not not NOT) actually.

@bennahugo
Copy link
Collaborator Author

bennahugo commented Mar 2, 2023

My two cents on this is that masks are boolean in general usage. Add and subtract of masks makes no sense to me... I vote +1 on the boolean operator definitions

@o-smirnov
Copy link
Contributor

My two cents on this is that masks are boolean in general usage. Add and subtract of masks makes no sense to me... I vote +1 on the boolean operator definitions

Well what we call "subtract" now is "subtract" or "difference" in set theory terms, and the equivalent of A&~B in boolean. But there's no simple English word for "&~" (well I suppose "and-not", but that's way too confusing!) So maybe "subtract" is not such a bad way to call it after all?

@IanHeywood
Copy link
Collaborator

well I suppose "and-not",

== NAND, no?

@o-smirnov
Copy link
Contributor

well I suppose "and-not",

== NAND, no?

NOT (~) to split hairs, but not quite. NAND is defined as ~A&~B, we have A&~B.

@IanHeywood
Copy link
Collaborator

I've also just realised that NAND would give us an ocean of 1s wherever both masks were 0...!

@o-smirnov
Copy link
Contributor

I've also just realised that NAND would give us an ocean of 1s wherever both masks were 0...!

Precisely my point! Incidentally, {NAND} forms a complete basis set for boolean algebra, in the sense that you can express any boolean function in terms of NANDs and NANDs only. Which makes it great for chip manufacturers, but not necessarily great for breizorro..

@IanHeywood
Copy link
Collaborator

Yup, you can build anything with enough 7400 ICs.

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.

Merge does not work
3 participants