On Sunday, February 09, 2014 09:22:55 PM Jason Pries wrote:
> but this isn't ideal since (I assume) it involves allocating 
> additional memory for A[!I,!J] as an intermediate step.

In Matlab, it allocates new memory for the array, too:

>> format debug
>> A = zeros(5,3)

A =


Structure address = 7fccf46e9a60 
m = 5
n = 3
pr = 7fcd7732c520 
pi = 0
     0     0     0
     0     0     0
     0     0     0
     0     0     0
     0     0     0

>> A(4,:) = []

A =


Structure address = 7fccf46e9a60 
m = 4
n = 3
pr = 7fcd772719a0 
pi = 0
     0     0     0
     0     0     0
     0     0     0
     0     0     0



Note that pr changed. (The "Structure address" simply holds the pointers to 
the real and imaginary portions of the array, so that doesn't change.)

Consequently, compared to Matlab you have nothing to lose by defining a 
function

function delete_slices(A::AbstractMatrix, I::Union(Real, AbstractVector), 
J::Union(Real, AbstractVector))
   keepI = trues(size(A,1)); keepI[I] = false
   keepJ = trues(size(A,2)); keepJ[J] = false
   A[keepI, keepJ] 
end

julia> A = reshape(1:15, 5, 3)
5x3 Array{Int64,2}:
 1   6  11
 2   7  12
 3   8  13
 4   9  14
 5  10  15

julia> delete_slices(A, 2:3, 2)
3x2 Array{Int64,2}:
 1  11
 4  14
 5  15


--Tim

Reply via email to