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

overload permutedims for OneElement matrices #368

Merged
merged 5 commits into from
Aug 16, 2024

Conversation

max-vassili3v
Copy link
Contributor

overload permutedims for OneElementMatrix to return OneElement

@jishnub
Copy link
Member

jishnub commented Aug 14, 2024

This may be more general, no?

Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.90%. Comparing base (f659d9f) to head (e84270d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #368   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files           8        8           
  Lines        1106     1110    +4     
=======================================
+ Hits         1105     1109    +4     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dlfivefifty
Copy link
Member

@max-vassili3v Can you add this for more general OneElement? At the very least OneElementVector.

@max-vassili3v
Copy link
Contributor Author

Implemented for more general OneElements, I originally excluded the implementation for OneElementVector since permutedims(::AbstractVector) uses reshape which keeps it as a OneElement

test/runtests.jl Outdated
@@ -2670,6 +2670,12 @@ end
@testset "permutedims" begin
v = OneElement(1, (2,3), (2,5))
@test permutedims(v) == OneElement(1, (3,2), (5,2))
w = OneElement(1,3,5)
@test permutedims(w) == OneElement(1, (1,3), (1,5))
Copy link
Member

Choose a reason for hiding this comment

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

These tests should check for ===, and not ==.

permutedims(o::OneElementMatrix) = OneElement(o.val, reverse(o.ind), reverse(o.axes))
permutedims(o::OneElementVector) = OneElement(o.val, (1, o.ind[1]), (1, length(o)))
permutedims(o::OneElement, dims::Tuple) = OneElement(o.val, _permute(o.ind, dims), _permute(o.axes, dims))
Copy link
Member

Choose a reason for hiding this comment

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

Do we need dims to be a Tuple? I think AbstractVectors would also work? Perhaps we may just have permutedims(o::OneElement, dims)?

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for the case where dims is not a Tuple?

@jishnub
Copy link
Member

jishnub commented Aug 14, 2024

Incidentally, the vector case already works on master, although we perhaps need a specialized method anyway. Perhaps we may define the method in terms of the reshape, as in Base. This way, it'll stay consistent.

julia> o = OneElement(1, 1, 2)
2-element OneElement{Int64, 1, Tuple{Int64}, Tuple{Base.OneTo{Int64}}}:
 1
 

julia> permutedims(o)
1×2 OneElement{Int64, 2, Tuple{Int64, Int64}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}:
 1  

@jishnub jishnub merged commit f0f7618 into JuliaArrays:master Aug 16, 2024
18 checks passed
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.

3 participants