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

Boolean OR, AND, XOR, BitCount: Reduction operators over integers #7200

Open
KrishnaPG opened this issue Dec 24, 2022 · 6 comments
Open

Boolean OR, AND, XOR, BitCount: Reduction operators over integers #7200

KrishnaPG opened this issue Dec 24, 2022 · 6 comments
Assignees

Comments

@KrishnaPG
Copy link

KrishnaPG commented Dec 24, 2022

Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template

System information

  • TensorFlow.js version (you are using): 4.1.0
  • Are you willing to contribute it (Yes/No): Would be glad to but do not have the expertise

Describe the feature and the current behavior/state.
Kindly add boolean AND, OR, XOR , bitCount as reduction operators over integer typed tensors.

For example, for a 2-dimensional matrix, column-wise boolean AND/OR/XOR reduction should result in a 1-dimensional tensor etc. Similarly row-wise etc.

Will this change the current api? How?
New reduction operators may need to be added in addition to the existing sum, prod etc. operators.

These below new reduction operators may have to be added for the integer dType:

  • boolean reduction operators: AND, OR, XOR
  • bitCount reduction operator that returns the total number of bits that are 1 in the given axis

Who will benefit with this feature?

  • Boolean operators enable bit-packing, which will vastly reduce the memory requirement in boolean matrix manipulation senarios. For example, boolean matrix multiplication currently forces us to use "int32" dType, (the bool type is mostly restricted to just logical operators currently it seems). Enabling boolean reduction operators allows extending the boolean operations further into arithmetic, than just logical.

Any Other info.

@KrishnaPG KrishnaPG added the type:feature New feature or request label Dec 24, 2022
@KrishnaPG KrishnaPG changed the title Boolean OR, AND, XOR: Reduction operators over integers Boolean OR, AND, XOR, BitCount: Reduction operators over integers Dec 24, 2022
@Linchenn
Copy link
Collaborator

Hi @KrishnaPG , do you have use cases for these ops, especially some well-known models?

Have you found similar APIs from TensorFlow's API? I just found TensorFlow's bitwise ops.

@Linchenn Linchenn self-assigned this Dec 27, 2022
@KrishnaPG
Copy link
Author

KrishnaPG commented Dec 28, 2022

Thank you @Linchenn The tf.bitwise from the link you have suggested is exactly what is needed - but for some reason I could not find the tf.bitwise in the JS version (documentation), though.

Is it available in the JS version internally (but not documented?)

@Linchenn
Copy link
Collaborator

No, it has not been implemented in TensorFlow.js. It makes sense to implement this.

Do you have use cases for this, or have you seen any popular or well known models that have these ops? It would be appreciated.

@KrishnaPG
Copy link
Author

KrishnaPG commented Dec 28, 2022

I am not sure of ML Models that use these, @Linchenn . I was testing the tf for general vector arithmetic over bool (scientific computing) and it became very difficult without the boolean operators (Shift, AND, OR, bitCount ...). Since the bool logical operators were already present (ANY, ALL ...), I felt these other operators were missing and hence thought of asking to see if they can be added.

@Linchenn
Copy link
Collaborator

Got it. Thank you for spotting it out!

@lcrh
Copy link

lcrh commented Aug 24, 2023

This would be great for hashing data, e.g., for bucketing. I'm currently encountering this while trying to work around missing XLA_JIT support for tf.fingerprint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants