-
Notifications
You must be signed in to change notification settings - Fork 38
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
overload permutedims for OneElement matrices #368
Conversation
This may be more general, no? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
@max-vassili3v Can you add this for more general |
Implemented for more general |
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)) |
There was a problem hiding this comment.
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 ==
.
src/oneelement.jl
Outdated
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)) |
There was a problem hiding this comment.
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 AbstractVector
s would also work? Perhaps we may just have permutedims(o::OneElement, dims)
?
There was a problem hiding this comment.
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
?
Incidentally, the vector case already works on 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 ⋅ |
overload permutedims for OneElementMatrix to return OneElement