moble / quaternionic

Interpret numpy arrays as quaternionic arrays with numba acceleration
MIT License
84 stars 7 forks source link

Support `np.ones_like()` #25

Closed mhostetter closed 3 years ago

mhostetter commented 3 years ago

I added the ability to override np.ones_like() to return [1,0,0,0] in the last dimension, as pointed out in issue #12. Also, discussed in #24.

Before:

In [1]: import numpy as np                                                                                                              

In [2]: import quaternionic                                                                                                             

In [3]: q = quaternionic.array([[1.2, 2.3, 3.4, 4.5], [10.2, 20.3, 30.4, 40.5]]); q                                                     
Out[3]: 
quaternionic.array([[ 1.2,  2.3,  3.4,  4.5],
       [10.2, 20.3, 30.4, 40.5]])

In [4]: np.ones_like(q)                                                                                                                 
Out[4]: 
quaternionic.array([[1., 1., 1., 1.],
       [1., 1., 1., 1.]])

After:

In [1]: import numpy as np                                                                                                              

In [2]: import quaternionic                                                                                                             

In [3]: q = quaternionic.array([[1.2, 2.3, 3.4, 4.5], [10.2, 20.3, 30.4, 40.5]]); q                                                     
Out[3]: 
quaternionic.array([[ 1.2,  2.3,  3.4,  4.5],
       [10.2, 20.3, 30.4, 40.5]])

In [4]: np.ones_like(q)                                                                                                                 
Out[4]: 
quaternionic.array([[1., 0., 0., 0.],
       [1., 0., 0., 0.]])
codecov[bot] commented 3 years ago

Codecov Report

Merging #25 (416376f) into main (23abff6) will decrease coverage by 0.19%. The diff coverage is 60.00%.

:exclamation: Current head 416376f differs from pull request most recent head bd2503e. Consider uploading reports for the commit bd2503e to get more accurate results Impacted file tree graph

@@             Coverage Diff             @@
##              main      #25      +/-   ##
===========================================
- Coverage   100.00%   99.80%   -0.20%     
===========================================
  Files            8        8              
  Lines         1025     1030       +5     
  Branches       107      108       +1     
===========================================
+ Hits          1025     1028       +3     
- Misses           0        1       +1     
- Partials         0        1       +1     
Impacted Files Coverage Δ
quaternionic/arrays.py 98.56% <60.00%> (-1.44%) :arrow_down:

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 159ba7c...bd2503e. Read the comment docs.

moble commented 3 years ago

Thanks!