You could implement:

Base.getindex(U::UniformScaling, I::AbstractArray, j::Int) = [U[i,j] for i 
in I]
Base.getindex(U::UniformScaling, i::Int, J::AbstractArray) = [U[i,j] for j 
in J]
Base.getindex(U::UniformScaling, I::AbstractArray, J::AbstractArray) = [U[i,
j] for i in I, j in J]

Then:

julia> I[1:4, 2]
4-element Array{Int64,1}:
 0
 1
 0
 0


On Friday, September 9, 2016 at 11:58:44 AM UTC-5, Steven G. Johnson wrote:
>
> On Friday, September 9, 2016 at 11:56:58 AM UTC-4, Christoph Ortner wrote:
>>
>> I predict that - right now - somebody is writing an answer explaining why 
>> this is terrible and you need an abstract array type with lazy evaluation. 
>> ;)
>
>
> Well, we already have the built-in constant I.   I[i,j] is the j-th 
> element of the i-th unit vector, computed lazily, i.e. the Kronecker delta 
> function.
>
> But yes, if you need unit vectors a lot you may be doing something wrong. 
>

Reply via email to