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

Bit-wise AND OR XOR #366

Merged
merged 24 commits into from Oct 10, 2019
Merged

Bit-wise AND OR XOR #366

merged 24 commits into from Oct 10, 2019

Conversation

mtar
Copy link
Collaborator

@mtar mtar commented Aug 29, 2019

Description

Fixes: #226

Changes proposed:

  • bitwise_and, bitwise_or, bitwise_xor in arithmetics
  • operator overloading of the methods in DNDArray

Type of change

The added functions call the new binary_bit_op function giving the method name.
Quite similar to binary_op, but calls the respective operator in torch.array and checks for same integer or boolean types in both tensors.

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Have you handled and tested all split configurations?
No

@@ -11,6 +11,127 @@

__all__ = []

def __binary_bit_op(method, t1, t2):
Copy link
Member

Choose a reason for hiding this comment

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

I am not 100% sure it is necessary to have this as a separate function in contrast to __binary_op(). It also seems that it is almost a verbatim copy of the function below. Why would we needs this except the type checking and casting purposes? It would be more meaningful from a SE perspective to factor out the common parts from __binary_op and __bitwise_binary_op

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. It is mostly a copy of the function and I am reluctant because of that, too. However, I couldn't find a really satisfying solution at the moment.
What's different is the not desired type casting at the end of each of the if branches at the first half of the function. It still may be not be the best solution, but I'll try to factor each branch out for instance, scalar and mixed pairs to reduce some code redundancy.
Also, the function calls at the end uses the overloaded operators of the torch.tensor class. I don't think I can do much there.

elif t2.split is None:
t2 = factories.array(t2, split=t1.split, copy=False, comm=t2.comm, device=t2.device, ndmin=-t1.numdims)
elif t1.split != t2.split:
# It is NOT possible to perform binary operations on tensors with different splits, e.g. split=0
Copy link
Member

Choose a reason for hiding this comment

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

Have an issue documenting the fact that we need to do something here still as soon as resplit is implemented (soon done)

@codecov
Copy link

codecov bot commented Aug 29, 2019

Codecov Report

Merging #366 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
+ Coverage   97.41%   97.48%   +0.07%     
==========================================
  Files          53       53              
  Lines       10586    10793     +207     
==========================================
+ Hits        10312    10522     +210     
+ Misses        274      271       -3
Impacted Files Coverage Δ
heat/core/tests/test_arithmetics.py 99.53% <100%> (+0.15%) ⬆️
heat/core/tests/test_operations.py 100% <100%> (ø) ⬆️
heat/core/operations.py 97.15% <100%> (+2.67%) ⬆️
heat/core/dndarray.py 95.33% <100%> (+0.05%) ⬆️
heat/core/arithmetics.py 98.85% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update deb70fc...9f250d1. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 29, 2019

Codecov Report

Merging #366 into master will decrease coverage by 0.16%.
The diff coverage is 87.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
- Coverage    97.1%   96.93%   -0.17%     
==========================================
  Files          53       53              
  Lines        9468     9508      +40     
==========================================
+ Hits         9194     9217      +23     
- Misses        274      291      +17
Impacted Files Coverage Δ
heat/core/tests/test_arithmetics.py 99.24% <100%> (+0.18%) ⬆️
heat/core/arithmetics.py 100% <100%> (ø) ⬆️
heat/core/dndarray.py 95.04% <50%> (-0.53%) ⬇️
heat/core/operations.py 88.13% <81.92%> (-7.07%) ⬇️
heat/core/tests/test_factories.py 100% <0%> (ø) ⬆️
heat/core/factories.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae4a413...7041eba. Read the comment docs.

@Markus-Goetz
Copy link
Member

Minor remark for the future. Please have you branchname of the form:

feature/<issue_number>-short-description
or
bug/<issue_number>-short description

No worries right now. Will make it easier for us in the future to maybe get statistics across the branches. Thanks

@mtar mtar closed this Sep 9, 2019
@mtar mtar reopened this Sep 9, 2019
@Markus-Goetz
Copy link
Member

So what is the status on this one? Do you think there is a way to refactor the respective methods or not?

@mtar
Copy link
Collaborator Author

mtar commented Oct 10, 2019

I rearranged it. The separate branches are put in respective functions now.

@Markus-Goetz Markus-Goetz merged commit 238546e into master Oct 10, 2019
@Markus-Goetz Markus-Goetz deleted the iss226 branch October 10, 2019 08:26
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.

Implement bitwise binary operations
2 participants