For functions like dot and norm, its also good to check out all the existing 
methods in base, via e.g. methods(norm). You'll get this response:

# 9 methods for generic function "norm":
norm{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},TI<:Integer}(x::Union{Base.ReshapedArray{T,1,A<:DenseArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N<:Any}}},DenseArray{T,1},SubArray{T,1,A<:Union{Base.ReshapedArray{T<:Any,N<:Any,A<:DenseArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N<:Any}}},DenseArray},I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex,Colon,Int64,Range{Int64}},N<:Any}},L<:Any}},
 rx::Union{Range{TI},UnitRange{TI}}) at linalg/dense.jl:44
norm(A::SparseMatrixCSC) at sparse/linalg.jl:497
norm(A::SparseMatrixCSC, p::Real) at sparse/linalg.jl:497
norm(x::AbstractArray{T<:Any,1}) at linalg/generic.jl:201
norm(x::AbstractArray{T<:Any,1}, p::Real) at linalg/generic.jl:201
norm{T}(A::AbstractArray{T,2}) at linalg/generic.jl:242
norm{T}(A::AbstractArray{T,2}, p::Real) at linalg/generic.jl:242
norm(x::Number) at linalg/generic.jl:253
norm(x::Number, p::Real) at linalg/generic.jl:253

While the first one hard to process because of all the unions and parametric 
types, it is important to note the second range argument. Delving into 
base/linalg/dense.jl shows that this is exactly what you need, compute the norm 
over a small part of the vector as indicated by the range, without having to 
create a view or a copy that allocates memory. The output of methods(dot) is 
even harder to read, but a similar method exists.

Reply via email to