@@ -100,8 +100,9 @@ imag(x::AbstractArray{<:Real}) = zero(x)
100100""" 
101101    selectdim(A, d::Integer, i) 
102102
103- Return all the data of `A` where the index for dimension `d` equals `i`. Equivalent to 
104- `A[:,:,...,i,:,:,...]` where `i` is in position `d`. 
103+ Return a view of all the data of `A` where the index for dimension `d` equals `i`. 
104+ 
105+ Equivalent to `view(A,:,:,...,i,:,:,...)` where `i` is in position `d`. 
105106
106107# Examples 
107108```jldoctest 
@@ -110,17 +111,18 @@ julia> A = [1 2 3 4; 5 6 7 8]
110111 1  2  3  4 
111112 5  6  7  8 
112113
113- julia> selectdim(A,2, 3) 
114- 2-element Array{Int64,1} : 
114+ julia> selectdim(A, 2,  3) 
115+ 2-element view(:: Array{Int64,2}, Base.OneTo(2), 3) with eltype Int64 : 
115116 3 
116117 7 
117118``` 
118119""" 
119- function  selectdim (A:: AbstractArray , d:: Integer , i)
120+ @inline  selectdim (A:: AbstractArray , d:: Integer , i) =  _selectdim (A, d, i, setindex (axes (A), i, d))
121+ @noinline  function  _selectdim (A, d, i, idxs)
120122    d >=  1  ||  throw (ArgumentError (" dimension must be ≥ 1"  ))
121123    nd =  ndims (A)
122-     d >  nd &&  (i ==  1  ||  throw_boundserror ( A, (ntuple (k-> Colon (),nd) ... ,  ntuple (k -> 1 , d- 1 - nd )... , i)))
123-     A[ setindex ( axes (A), i, d) ... ] 
124+     d >  nd &&  (i ==  1  ||  throw ( BoundsError ( A, (ntuple (k-> Colon (),d- 1 )... , i) )))
125+     return   view (A, idxs ... ) 
124126end 
125127
126128""" 
0 commit comments