Skip to content

Commit

Permalink
multidimensional: migrate all items except BitArray routines to Carte…
Browse files Browse the repository at this point in the history
…sian
  • Loading branch information
timholy committed Jan 13, 2014
1 parent 4ef39e1 commit c6bb39c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 457 deletions.
159 changes: 0 additions & 159 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,58 +305,6 @@ function getindex{T<:Real}(A::Ranges, I::AbstractVector{T})
return [ A[i] for i in to_index(I) ]
end

# 2d indexing
function getindex(A::Array, I::Range1{Int}, j::Real)
j = to_index(j)
checkbounds(A, I, j)
X = similar(A,length(I))
unsafe_copy!(X, 1, A, (j-1)*size(A,1) + first(I), length(I))
return X
end
function getindex(A::Array, I::Range1{Int}, J::Range1{Int})
checkbounds(A, I, J)
X = similar(A, index_shape(I, J))
if length(I) == size(A,1)
unsafe_copy!(X, 1, A, (first(J)-1)*size(A,1) + 1, size(A,1)*length(J))
else
storeoffset = 1
for j = J
unsafe_copy!(X, storeoffset, A, (j-1)*size(A,1) + first(I), length(I))
storeoffset += length(I)
end
end
return X
end
function getindex(A::Array, I::Range1{Int}, J::AbstractVector{Int})
checkbounds(A, I, J)
X = similar(A, index_shape(I, J))
storeoffset = 1
for j = J
unsafe_copy!(X, storeoffset, A, (j-1)*size(A,1) + first(I), length(I))
storeoffset += length(I)
end
return X
end

getindex{T<:Real}(A::Array, I::AbstractVector{T}, j::Real) = [ A[i,j] for i=to_index(I) ]
getindex{T<:Real}(A::Array, I::Real, J::AbstractVector{T}) = [ A[i,j] for i=I,j=to_index(J) ]

# This next is a 2d specialization of the algorithm used for general
# multidimensional indexing
function getindex{T<:Real}(A::Array, I::AbstractVector{T}, J::AbstractVector{T})
checkbounds(A, I, J)
I = to_index(I); J = to_index(J)
X = similar(A, index_shape(I, J))
storeind = 1
for j = J
offset = (convert(Int,j)-1)*size(A,1)
for i = I
X[storeind] = A[convert(Int,i)+offset]
storeind += 1
end
end
return X
end

# logical indexing

Expand Down Expand Up @@ -434,113 +382,6 @@ function setindex!{T<:Real}(A::Array, X::AbstractArray, I::AbstractVector{T})
return A
end

function setindex!{T<:Real}(A::Array, x, i::Real, J::AbstractVector{T})
i = to_index(i)
checkbounds(A, i, J)
m = size(A, 1)
if !isa(x,AbstractArray)
for j in J
A[(j-1)*m + i] = x
end
else
X = x
if length(X) != length(J)
throw_setindex_mismatch(X, (i,J))
end
count = 1
for j in J
A[(j-1)*m + i] = X[count]
count += 1
end
end
return A
end

function setindex!{T<:Real}(A::Array, x, I::AbstractVector{T}, j::Real)
j = to_index(j)
checkbounds(A, I, j)
m = size(A, 1)
offset = (j-1)*m

if !isa(x,AbstractArray)
for i in I
A[offset + i] = x
end
else
X = x
if length(X) != length(I)
throw_setindex_mismatch(X, (I,j))
end
count = 1
for i in I
A[offset + i] = X[count]
count += 1
end
end
return A
end

function setindex!{T}(A::Array{T}, X::Array{T}, I::Range1{Int}, j::Real)
j = to_index(j)
checkbounds(A, I, j)
if length(X) != length(I)
throw_setindex_mismatch(X, (I,j))
end
unsafe_copy!(A, first(I) + (j-1)*size(A,1), X, 1, length(I))
return A
end

function setindex!{T}(A::Array{T}, X::Array{T}, I::Range1{Int}, J::Range1{Int})
checkbounds(A, I, J)
setindex_shape_check(X, I, J)
if length(I) == size(A,1)
unsafe_copy!(A, first(I) + (first(J)-1)*size(A,1), X, 1, size(A,1)*length(J))
else
refoffset = 1
for j = J
unsafe_copy!(A, first(I) + (j-1)*size(A,1), X, refoffset, length(I))
refoffset += length(I)
end
end
return A
end

function setindex!{T}(A::Array{T}, X::Array{T}, I::Range1{Int}, J::AbstractVector{Int})
checkbounds(A, I, J)
setindex_shape_check(X, I, J)
refoffset = 1
for j = J
unsafe_copy!(A, first(I) + (j-1)*size(A,1), X, refoffset, length(I))
refoffset += length(I)
end
return A
end

function setindex!{T<:Real}(A::Array, x, I::AbstractVector{T}, J::AbstractVector{T})
checkbounds(A, I, J)
m = size(A, 1)
if !isa(x,AbstractArray)
for j in J
offset = (j-1)*m
for i in I
A[offset + i] = x
end
end
else
X = x
setindex_shape_check(X, I, J)
count = 1
for j in J
offset = (j-1)*m
for i in I
A[offset + i] = X[count]
count += 1
end
end
end
return A
end


# logical indexing

Expand Down
Loading

0 comments on commit c6bb39c

Please sign in to comment.