Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,7 @@ Instead of a vector, `rows` and `cols` can also be:
* an integer `i`, which is interpreted as `i:i`, or
* `:`, which is interpreted as `1:nrows(M)` or `1:ncols(M)` respectively.
"""
function getindex(M::MatElem, rows::AbstractVector{Int}, cols::AbstractVector{Int})
_checkbounds(M, rows, cols)
A = similar(M, length(rows), length(cols))
for i in 1:length(rows)
for j in 1:length(cols)
A[i, j] = deepcopy(M[rows[i], cols[j]])
end
end
return A
end
getindex(M::MatElem, r::AbstractVector{<:Integer}, c::AbstractVector{<:Integer}) = sub(M, r, c)

function getindex(M::MatElem, i::Int, cols::AbstractVector{Int})
_checkbounds(M, i, cols)
Expand All @@ -472,8 +463,16 @@ getindex(M::MatElem, rows, ::Colon) = getindex(M, rows, 1:ncols(M))

getindex(M::MatElem, ::Colon, ::Colon) = getindex(M, 1:nrows(M), 1:ncols(M))


sub(M::MatElem, r::AbstractVector{<:Integer}, c::AbstractVector{<:Integer}) = M[r, c]
function sub(M::MatElem, rows::AbstractVector{Int}, cols::AbstractVector{Int})
_checkbounds(M, rows, cols)
A = similar(M, length(rows), length(cols))
for i in 1:length(rows)
for j in 1:length(cols)
A[i, j] = deepcopy(M[rows[i], cols[j]])
end
end
return A
end

# fallback method that converts Colons to UnitRanges
function Base.view(M::MatElem, rows, cols)
Expand Down
Loading