Skip to content

Commit 1f72668

Browse files
committed
rename sub/slice -> view
1 parent 4accf8a commit 1f72668

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+268
-315
lines changed

base/abstractarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
14161416
idx[d] = Colon()
14171417
end
14181418

1419-
r1 = f(slice(A, idx...))
1419+
r1 = f(view(A, idx...))
14201420

14211421
# determine result size and allocate
14221422
Rsize = copy(dimsA)
@@ -1448,7 +1448,7 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
14481448
for i in 1:nidx
14491449
idx[otherdims[i]] = ridx[otherdims[i]] = I.I[i]
14501450
end
1451-
R[ridx...] = f(slice(A, idx...))
1451+
R[ridx...] = f(view(A, idx...))
14521452
end
14531453
end
14541454

base/deprecated.jl

+3
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ function first(::Colon)
756756
1
757757
end
758758

759+
@deprecate slice view
760+
@deprecate sub view
761+
759762
# During the 0.5 development cycle, do not add any deprecations below this line
760763
# To be deprecated in 0.6
761764

base/docs/helpdb/Base.jl

+2-10
Original file line numberDiff line numberDiff line change
@@ -5402,14 +5402,14 @@ is raised as an exception in the woken tasks.
54025402
notify
54035403

54045404
"""
5405-
sub(A, inds...)
5405+
view(A, inds...)
54065406
54075407
Like [`getindex`](:func:`getindex`), but returns a view into the parent array `A` with the
54085408
given indices instead of making a copy. Calling [`getindex`](:func:`getindex`) or
54095409
[`setindex!`](:func:`setindex!`) on the returned [`SubArray`](:obj:`SubArray`) computes the
54105410
indices to the parent array on the fly without checking bounds.
54115411
"""
5412-
sub
5412+
view
54135413

54145414
"""
54155415
expanduser(path::AbstractString) -> AbstractString
@@ -7443,14 +7443,6 @@ julia> "Hello " * "world"
74437443
"""
74447444
Base.:(*)(s::AbstractString, t::AbstractString)
74457445

7446-
"""
7447-
slice(A, inds...)
7448-
7449-
Returns a view of array `A` with the given indices like [`sub`](:func:`sub`), but drops all
7450-
dimensions indexed with scalars.
7451-
"""
7452-
slice
7453-
74547446
"""
74557447
time()
74567448

base/iterator.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ done(itr::PartitionIterator, state) = done(itr.c, state)
547547
function next{T<:Vector}(itr::PartitionIterator{T}, state)
548548
l = state
549549
r = min(state + itr.n-1, length(itr.c))
550-
return sub(itr.c, l:r), r + 1
550+
return view(itr.c, l:r), r + 1
551551
end
552552

553553
function next(itr::PartitionIterator, state)

base/linalg/arnoldi.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ end
296296

297297
function A_mul_B!{T,S}(u::StridedVector{T}, s::SVDOperator{T,S}, v::StridedVector{T})
298298
a, b = s.m, length(v)
299-
A_mul_B!(sub(u,1:a), s.X, sub(v,a+1:b)) # left singular vector
300-
Ac_mul_B!(sub(u,a+1:b), s.X, sub(v,1:a)) # right singular vector
299+
A_mul_B!(view(u,1:a), s.X, view(v,a+1:b)) # left singular vector
300+
Ac_mul_B!(view(u,a+1:b), s.X, view(v,1:a)) # right singular vector
301301
u
302302
end
303303
size(s::SVDOperator) = s.m + s.n, s.m + s.n

base/linalg/arpack.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function aupd_wrapper(T, matvecA!::Function, matvecB::Function, solveSI::Functio
5353
throw(ARPACKException(info[1]))
5454
end
5555

56-
x = sub(workd, ipntr[1]+zernm1)
57-
y = sub(workd, ipntr[2]+zernm1)
56+
x = view(workd, ipntr[1]+zernm1)
57+
y = view(workd, ipntr[2]+zernm1)
5858
if mode == 1 # corresponds to dsdrv1, dndrv1 or zndrv1
5959
if ido[1] == 1
6060
matvecA!(y, x)
@@ -89,7 +89,7 @@ function aupd_wrapper(T, matvecA!::Function, matvecB::Function, solveSI::Functio
8989
if ido[1] == -1
9090
y[:] = solveSI(matvecB(x))
9191
elseif ido[1] == 1
92-
y[:] = solveSI(sub(workd,ipntr[3]+zernm1))
92+
y[:] = solveSI(view(workd,ipntr[3]+zernm1))
9393
elseif ido[1] == 2
9494
y[:] = matvecB(x)
9595
elseif ido[1] == 99

base/linalg/cholesky.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ function A_ldiv_B!{T<:BlasFloat}(C::CholeskyPivoted{T}, B::StridedMatrix{T})
379379
chkfullrank(C)
380380
n = size(C, 1)
381381
for i=1:size(B, 2)
382-
permute!(sub(B, 1:n, i), C.piv)
382+
permute!(view(B, 1:n, i), C.piv)
383383
end
384384
LAPACK.potrs!(C.uplo, C.factors, B)
385385
for i=1:size(B, 2)
386-
ipermute!(sub(B, 1:n, i), C.piv)
386+
ipermute!(view(B, 1:n, i), C.piv)
387387
end
388388
B
389389
end

base/linalg/eigen.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function eigfact!{T<:BlasReal}(A::StridedMatrix{T}; permute::Bool=true, scale::B
3535
j = 1
3636
while j <= n
3737
if WI[j] == 0
38-
evec[:,j] = slice(VR, :, j)
38+
evec[:,j] = view(VR, :, j)
3939
else
4040
for i = 1:n
4141
evec[i,j] = VR[i,j] + im*VR[i,j+1]
@@ -131,7 +131,7 @@ function eigfact!{T<:BlasReal}(A::StridedMatrix{T}, B::StridedMatrix{T})
131131
j = 1
132132
while j <= n
133133
if alphai[j] == 0
134-
vecs[:,j] = slice(vr, :, j)
134+
vecs[:,j] = view(vr, :, j)
135135
else
136136
for i = 1:n
137137
vecs[i,j ] = vr[i,j] + im*vr[i,j+1]

base/linalg/lapack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ for (gglse, elty) in ((:dgglse_, :Float64),
14371437
work = Array{$elty}(lwork)
14381438
end
14391439
end
1440-
X, dot(sub(c, n - p + 1:m), sub(c, n - p + 1:m))
1440+
X, dot(view(c, n - p + 1:m), view(c, n - p + 1:m))
14411441
end
14421442
end
14431443
end

base/linalg/qr.jl

+19-19
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ function qrfactUnblocked!{T}(A::AbstractMatrix{T})
2828
m, n = size(A)
2929
τ = zeros(T, min(m,n))
3030
for k = 1:min(m - 1 + !(T<:Real), n)
31-
x = slice(A, k:m, k)
31+
x = view(A, k:m, k)
3232
τk = reflector!(x)
3333
τ[k] = τk
34-
reflectorApply!(x, τk, slice(A, k:m, k + 1:n))
34+
reflectorApply!(x, τk, view(A, k:m, k + 1:n))
3535
end
3636
QR(A, τ)
3737
end
3838

3939
# Find index for columns with largest two norm
4040
function indmaxcolumn(A::StridedMatrix)
41-
mm = norm(slice(A, :, 1))
41+
mm = norm(view(A, :, 1))
4242
ii = 1
4343
for i = 2:size(A, 2)
44-
mi = norm(slice(A, :, i))
44+
mi = norm(view(A, :, i))
4545
if abs(mi) > mm
4646
mm = mi
4747
ii = i
@@ -57,7 +57,7 @@ function qrfactPivotedUnblocked!(A::StridedMatrix)
5757
for j = 1:min(m,n)
5858

5959
# Find column with maximum norm in trailing submatrix
60-
jm = indmaxcolumn(slice(A, j:m, j:n)) + j - 1
60+
jm = indmaxcolumn(view(A, j:m, j:n)) + j - 1
6161

6262
if jm != j
6363
# Flip elements in pivoting vector
@@ -74,12 +74,12 @@ function qrfactPivotedUnblocked!(A::StridedMatrix)
7474
end
7575

7676
# Compute reflector of columns j
77-
x = slice(A, j:m, j)
77+
x = view(A, j:m, j)
7878
τj = LinAlg.reflector!(x)
7979
τ[j] = τj
8080

8181
# Update trailing submatrix with reflector
82-
LinAlg.reflectorApply!(x, τj, sub(A, j:m, j+1:n))
82+
LinAlg.reflectorApply!(x, τj, view(A, j:m, j+1:n))
8383
end
8484
return LinAlg.QRPivoted{eltype(A), typeof(A)}(A, τ, piv)
8585
end
@@ -451,8 +451,8 @@ for (f1, f2) in ((:Ac_mul_B, :A_mul_B!),
451451
end
452452
end
453453

454-
A_ldiv_B!{T<:BlasFloat}(A::QRCompactWY{T}, b::StridedVector{T}) = (A_ldiv_B!(UpperTriangular(A[:R]), sub(Ac_mul_B!(A[:Q], b), 1:size(A, 2))); b)
455-
A_ldiv_B!{T<:BlasFloat}(A::QRCompactWY{T}, B::StridedMatrix{T}) = (A_ldiv_B!(UpperTriangular(A[:R]), sub(Ac_mul_B!(A[:Q], B), 1:size(A, 2), 1:size(B, 2))); B)
454+
A_ldiv_B!{T<:BlasFloat}(A::QRCompactWY{T}, b::StridedVector{T}) = (A_ldiv_B!(UpperTriangular(A[:R]), view(Ac_mul_B!(A[:Q], b), 1:size(A, 2))); b)
455+
A_ldiv_B!{T<:BlasFloat}(A::QRCompactWY{T}, B::StridedMatrix{T}) = (A_ldiv_B!(UpperTriangular(A[:R]), view(Ac_mul_B!(A[:Q], B), 1:size(A, 2), 1:size(B, 2))); B)
456456

457457
# Julia implementation similarly to xgelsy
458458
function A_ldiv_B!{T<:BlasFloat}(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Real)
@@ -467,8 +467,8 @@ function A_ldiv_B!{T<:BlasFloat}(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Re
467467
xmax = ones(T, 1)
468468
tmin = tmax = ar
469469
while rnk < nr
470-
tmin, smin, cmin = LAPACK.laic1!(2, xmin, tmin, sub(A.factors, 1:rnk, rnk + 1), A.factors[rnk + 1, rnk + 1])
471-
tmax, smax, cmax = LAPACK.laic1!(1, xmax, tmax, sub(A.factors, 1:rnk, rnk + 1), A.factors[rnk + 1, rnk + 1])
470+
tmin, smin, cmin = LAPACK.laic1!(2, xmin, tmin, view(A.factors, 1:rnk, rnk + 1), A.factors[rnk + 1, rnk + 1])
471+
tmax, smax, cmax = LAPACK.laic1!(1, xmax, tmax, view(A.factors, 1:rnk, rnk + 1), A.factors[rnk + 1, rnk + 1])
472472
tmax*rcond > tmin && break
473473
push!(xmin, cmin)
474474
push!(xmax, cmax)
@@ -479,10 +479,10 @@ function A_ldiv_B!{T<:BlasFloat}(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Re
479479
rnk += 1
480480
end
481481
C, τ = LAPACK.tzrzf!(A.factors[1:rnk,:])
482-
A_ldiv_B!(UpperTriangular(C[1:rnk,1:rnk]),sub(Ac_mul_B!(getq(A),sub(B, 1:mA, 1:nrhs)),1:rnk,1:nrhs))
482+
A_ldiv_B!(UpperTriangular(C[1:rnk,1:rnk]),view(Ac_mul_B!(getq(A),view(B, 1:mA, 1:nrhs)),1:rnk,1:nrhs))
483483
B[rnk+1:end,:] = zero(T)
484-
LAPACK.ormrz!('L', eltype(B)<:Complex ? 'C' : 'T', C, τ, sub(B,1:nA,1:nrhs))
485-
B[1:nA,:] = sub(B, 1:nA, :)[invperm(A[:p]::Vector{BlasInt}),:]
484+
LAPACK.ormrz!('L', eltype(B)<:Complex ? 'C' : 'T', C, τ, view(B,1:nA,1:nrhs))
485+
B[1:nA,:] = view(B, 1:nA, :)[invperm(A[:p]::Vector{BlasInt}),:]
486486
return B, rnk
487487
end
488488
A_ldiv_B!{T<:BlasFloat}(A::QRPivoted{T}, B::StridedVector{T}) = vec(A_ldiv_B!(A,reshape(B,length(B),1)))
@@ -491,13 +491,13 @@ function A_ldiv_B!{T}(A::QR{T}, B::StridedMatrix{T})
491491
m, n = size(A)
492492
minmn = min(m,n)
493493
mB, nB = size(B)
494-
Ac_mul_B!(A[:Q], sub(B, 1:m, :))
494+
Ac_mul_B!(A[:Q], view(B, 1:m, :))
495495
R = A[:R]
496496
@inbounds begin
497497
if n > m # minimum norm solution
498498
τ = zeros(T,m)
499499
for k = m:-1:1 # Trapezoid to triangular by elementary operation
500-
x = slice(R, k, [k; m + 1:n])
500+
x = view(R, k, [k; m + 1:n])
501501
τk = reflector!(x)
502502
τ[k] = τk'
503503
for i = 1:k - 1
@@ -513,7 +513,7 @@ function A_ldiv_B!{T}(A::QR{T}, B::StridedMatrix{T})
513513
end
514514
end
515515
end
516-
Base.A_ldiv_B!(UpperTriangular(sub(R, :, 1:minmn)), sub(B, 1:minmn, :))
516+
Base.A_ldiv_B!(UpperTriangular(view(R, :, 1:minmn)), view(B, 1:minmn, :))
517517
if n > m # Apply elementary transformation to solution
518518
B[m + 1:mB,1:nB] = zero(T)
519519
for j = 1:nB
@@ -536,12 +536,12 @@ end
536536
A_ldiv_B!(A::QR, B::StridedVector) = A_ldiv_B!(A, reshape(B, length(B), 1))[:]
537537
function A_ldiv_B!(A::QRPivoted, b::StridedVector)
538538
A_ldiv_B!(QR(A.factors,A.τ), b)
539-
b[1:size(A.factors, 2)] = sub(b, 1:size(A.factors, 2))[invperm(A.jpvt)]
539+
b[1:size(A.factors, 2)] = view(b, 1:size(A.factors, 2))[invperm(A.jpvt)]
540540
b
541541
end
542542
function A_ldiv_B!(A::QRPivoted, B::StridedMatrix)
543543
A_ldiv_B!(QR(A.factors, A.τ), B)
544-
B[1:size(A.factors, 2),:] = sub(B, 1:size(A.factors, 2), :)[invperm(A.jpvt),:]
544+
B[1:size(A.factors, 2),:] = view(B, 1:size(A.factors, 2), :)[invperm(A.jpvt),:]
545545
B
546546
end
547547

base/linalg/svd.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ svdvals{T, Tr}(S::SVD{T, Tr}) = (S[:S])::Vector{Tr}
9595
# SVD least squares
9696
function A_ldiv_B!{Ta,Tb}(A::SVD{Ta}, B::StridedVecOrMat{Tb})
9797
k = searchsortedlast(A.S, eps(real(Ta))*A.S[1], rev=true)
98-
sub(A.Vt,1:k,:)' * (sub(A.S,1:k) .\ (sub(A.U,:,1:k)' * B))
98+
view(A.Vt,1:k,:)' * (view(A.S,1:k) .\ (view(A.U,:,1:k)' * B))
9999
end
100100

101101
# Generalized svd

base/loading.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ elseif is_apple()
6060
continue
6161
end
6262
casepreserved_basename =
63-
sub(buf, (header_size+1):(header_size+filename_length-1))
63+
view(buf, (header_size+1):(header_size+filename_length-1))
6464
break
6565
end
6666
# Hack to compensate for inability to create a string from a subarray with no allocations.

base/poll.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type _FDWatcher
102102
if fd.fd+1 > length(FDWatchers)
103103
old_len = length(FDWatchers)
104104
resize!(FDWatchers, fd.fd+1)
105-
fill!(sub(FDWatchers, old_len+1:fd.fd+1), nothing)
105+
fill!(view(FDWatchers, old_len+1:fd.fd+1), nothing)
106106
elseif FDWatchers[fd.fd + 1] !== nothing
107107
this = FDWatchers[fd.fd + 1]::_FDWatcher
108108
this.refcount = (this.refcount[1] + Int(readable), this.refcount[2] + Int(writable))

base/sharedarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function range_1dim(S::SharedArray, pidx)
327327
end
328328
end
329329

330-
sub_1dim(S::SharedArray, pidx) = sub(S.s, range_1dim(S, pidx))
330+
sub_1dim(S::SharedArray, pidx) = view(S.s, range_1dim(S, pidx))
331331

332332
function init_loc_flds{T,N}(S::SharedArray{T,N})
333333
if myid() in S.pids
@@ -342,7 +342,7 @@ function init_loc_flds{T,N}(S::SharedArray{T,N})
342342
S.loc_subarr_1d = sub_1dim(S, S.pidx)
343343
else
344344
S.pidx = 0
345-
S.loc_subarr_1d = sub(Array{T}(ntuple(d->0,N)), 1:0)
345+
S.loc_subarr_1d = view(Array{T}(ntuple(d->0,N)), 1:0)
346346
end
347347
end
348348

base/show.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ function show_nd(io::IO, a::AbstractArray, print_matrix, label_slices)
14381438
for i = 1:(nd-1); print(io, "$(idxs[i]), "); end
14391439
println(io, idxs[end], "] =")
14401440
end
1441-
slice = sub(a, indices(a,1), indices(a,2), idxs...)
1441+
slice = view(a, indices(a,1), indices(a,2), idxs...)
14421442
print_matrix(io, slice)
14431443
print(io, idxs == map(last,tail) ? "" : "\n\n")
14441444
@label skip

base/sort.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function sortrows(A::AbstractMatrix; kws...)
509509
T = slicetypeof(A, inds, :)
510510
rows = allocate_for(Vector{T}, A, shape(A, 1))
511511
for i in inds
512-
rows[i] = slice(A, i, :)
512+
rows[i] = view(A, i, :)
513513
end
514514
p = sortperm(rows; kws..., order=Lexicographic)
515515
A[p,:]
@@ -520,7 +520,7 @@ function sortcols(A::AbstractMatrix; kws...)
520520
T = slicetypeof(A, :, inds)
521521
cols = allocate_for(Vector{T}, A, shape(A, 2))
522522
for i in inds
523-
cols[i] = slice(A, :, i)
523+
cols[i] = view(A, :, i)
524524
end
525525
p = sortperm(cols; kws..., order=Lexicographic)
526526
A[:,p]

base/sparse/cholmod.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ function (::Type{Sparse}){Tv<:VTypes}(m::Integer, n::Integer,
830830
# check if columns are sorted
831831
iss = true
832832
for i = 2:length(colptr)
833-
if !issorted(sub(rowval, colptr[i - 1] + 1:colptr[i]))
833+
if !issorted(view(rowval, colptr[i - 1] + 1:colptr[i]))
834834
iss = false
835835
break
836836
end

base/sparse/linalg.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ function normestinv{T}(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A)
588588
X[1:n,1] = 1
589589
for j = 2:t
590590
while true
591-
_rand_pm1!(slice(X,1:n,j))
591+
_rand_pm1!(view(X,1:n,j))
592592
yaux = X[1:n,j]' * X[1:n,1:j-1]
593593
if !_any_abs_eq(yaux,n)
594594
break
@@ -649,7 +649,7 @@ function normestinv{T}(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A)
649649
end
650650
end
651651
if repeated
652-
_rand_pm1!(slice(S,1:n,j))
652+
_rand_pm1!(view(S,1:n,j))
653653
else
654654
break
655655
end

base/sparse/sparsematrix.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ function spdiagm_internal(B, d)
31103110
range = 1+i:numel+i
31113111
I[range] = row+1:row+numel
31123112
J[range] = col+1:col+numel
3113-
copy!(sub(V, range), vec)
3113+
copy!(view(V, range), vec)
31143114
i += numel
31153115
end
31163116

base/sparse/sparsevector.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1550,8 +1550,8 @@ for isunittri in (true, false), islowertri in (true, false)
15501550
nzrange = $( (islowertri && !istrans) || (!islowertri && istrans) ?
15511551
:(b.nzind[1]:b.n) :
15521552
:(1:b.nzind[end]) )
1553-
nzrangeviewr = sub(r, nzrange)
1554-
nzrangeviewA = $tritype(sub(A.data, nzrange, nzrange))
1553+
nzrangeviewr = view(r, nzrange)
1554+
nzrangeviewA = $tritype(view(A.data, nzrange, nzrange))
15551555
($ipfunc)(convert(AbstractArray{TAb}, nzrangeviewA), nzrangeviewr)
15561556
end
15571557
r
@@ -1586,8 +1586,8 @@ for isunittri in (true, false), islowertri in (true, false)
15861586
nzrange = $( (islowertri && !istrans) || (!islowertri && istrans) ?
15871587
:(b.nzind[1]:b.n) :
15881588
:(1:b.nzind[end]) )
1589-
nzrangeviewbnz = sub(b.nzval, nzrange - b.nzind[1] + 1)
1590-
nzrangeviewA = $tritype(sub(A.data, nzrange, nzrange))
1589+
nzrangeviewbnz = view(b.nzval, nzrange - b.nzind[1] + 1)
1590+
nzrangeviewA = $tritype(view(A.data, nzrange, nzrange))
15911591
($func)(nzrangeviewA, nzrangeviewbnz)
15921592
# could strip any miraculous zeros here perhaps
15931593
end

0 commit comments

Comments
 (0)