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

Add boolean dtype #12

Merged
merged 6 commits into from
Mar 25, 2019
Merged

Add boolean dtype #12

merged 6 commits into from
Mar 25, 2019

Conversation

Uditgulati
Copy link
Member

Issue: #10

VALUE <-> bool conversion reference: https://ruby.fandom.com/wiki/C_API/Boolean_values

@prasunanand
Copy link
Member

what does adding bool dtypes return ?

Can you add tests ?

@prasunanand prasunanand self-assigned this Mar 18, 2019
@Uditgulati
Copy link
Member Author

@prasunanand I've not added bool dtype to addition function as I think that adding won't return bool. Or if we treat 'true' + 'true' as 'true' or maybe 'false' (I'm not sure if either one is correct or not).

I've added tests for bool dtype initialisation, get_dimension, get_elements. Let me know if more tests are to be added.

@Uditgulati
Copy link
Member Author

Numpy gives answer as True if any of the operands in True. https://pastebin.com/0uZ928eX

@prasunanand
Copy link
Member

Check how Ruby treats boolean add .

@Uditgulati
Copy link
Member Author

Ruby does not support boolean addition. https://pastebin.com/ke0KRcWY

@Uditgulati
Copy link
Member Author

@prasunanand Should I implement boolean add then?

@prasunanand
Copy link
Member

Yeah

Copy link
Member

@prasunanand prasunanand left a comment

Choose a reason for hiding this comment

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

Also add test for nm + true

@Uditgulati
Copy link
Member Author

I'm sorry, but what is nm + true?

@prasunanand
Copy link
Member

nm = NMatrix.new([2,2], [true, false, true, true])
nm + true

@Uditgulati
Copy link
Member Author

Got it. Thanks for clarifying.

@Uditgulati
Copy link
Member Author

@prasunanand I've made changes and now nm_bool + bool works. I've added tests for it too.

Also, I've noticed that subtract operation doesn't give right answer when some constant is subtracted from matrix, like

n = NMatrix.new [2,2], [1,2,3,4]
m = n - 1

gives m = [2,3,4,5].

I'm still going through code to see how subtraction is implemented. Please have a look and let me know if this is a bug or not.

@prasunanand prasunanand merged commit a6b5b5e into SciRuby:master Mar 25, 2019
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