Skip to content

Commit

Permalink
Merge pull request #17895 from JuliaLang/teh/unaryneg_cartind
Browse files Browse the repository at this point in the history
Support negation for CartesianIndex
  • Loading branch information
timholy authored Aug 8, 2016
2 parents 33c7554 + 6ed3bb8 commit 2037464
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ one{N}(::CartesianIndex{N}) = one(CartesianIndex{N})
one{N}(::Type{CartesianIndex{N}}) = CartesianIndex(ntuple(x -> 1, Val{N}))

# arithmetic, min/max
(-){N}(index::CartesianIndex{N}) = CartesianIndex{N}(map(-, index.I))
(+){N}(index1::CartesianIndex{N}, index2::CartesianIndex{N}) = CartesianIndex{N}(map(+, index1.I, index2.I))
(-){N}(index1::CartesianIndex{N}, index2::CartesianIndex{N}) = CartesianIndex{N}(map(-, index1.I, index2.I))
min{N}(index1::CartesianIndex{N}, index2::CartesianIndex{N}) = CartesianIndex{N}(map(min, index1.I, index2.I))
Expand Down
2 changes: 1 addition & 1 deletion base/permuteddimsarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ immutable PermutedDimsArray{T,N,perm,iperm,AA<:AbstractArray} <: AbstractArray{T
end

function PermutedDimsArray{T,N}(data::AbstractArray{T,N}, perm)
length(perm) == N || throw(ArgumentError(string(p, " is not a valid permutation of dimensions 1:", N)))
length(perm) == N || throw(ArgumentError(string(perm, " is not a valid permutation of dimensions 1:", N)))
iperm = invperm(perm)
PermutedDimsArray{T,N,(perm...,),(iperm...,),typeof(data)}(data)
end
Expand Down
6 changes: 6 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ s = view(a,:,[1,2,4],[1,5])
c = convert(Array, s)
for p in ([1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1])
@test permutedims(s, p) == permutedims(c, p)
@test Base.PermutedDimsArrays.PermutedDimsArray(s, p) == permutedims(c, p)
end
@test_throws ArgumentError permutedims(a, (1,1,1))
@test_throws ArgumentError permutedims(s, (1,1,1))
@test_throws ArgumentError Base.PermutedDimsArrays.PermutedDimsArray(a, (1,1,1))
@test_throws ArgumentError Base.PermutedDimsArrays.PermutedDimsArray(s, (1,1,1))

## ipermutedims ##

Expand Down Expand Up @@ -1252,6 +1257,7 @@ end

I1 = CartesianIndex((2,3,0))
I2 = CartesianIndex((-1,5,2))
@test -I1 == CartesianIndex((-2,-3,0))
@test I1 + I2 == CartesianIndex((1,8,2))
@test I2 + I1 == CartesianIndex((1,8,2))
@test I1 - I2 == CartesianIndex((3,-2,-2))
Expand Down

3 comments on commit 2037464

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something went wrong when running your job: error
cc @jrevels

@jrevels
Copy link
Member

@jrevels jrevels commented on 2037464 Aug 9, 2016

Choose a reason for hiding this comment

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

A testament to the poor test coverage in Nanosoldier.jl...

The latest Nanosoldier update improved error reporting, but featured a typo, which is why the error message is wonky. Similarly, report generation for daily builds broke in some code shuffling related to the update. I'm about to merge the fix here, then I'll restart the Nanosoldier server with these patches.

Please sign in to comment.