Skip to content

Commit 9d2a40b

Browse files
authored
Merge pull request #16972 from JuliaLang/sb/sub2view
rename sub/slice -> view
2 parents 9840b23 + 9ab7c8f commit 9d2a40b

Some content is hidden

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

62 files changed

+280
-362
lines changed

base/abstractarray.jl

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5383,14 +5383,14 @@ is raised as an exception in the woken tasks.
53835383
notify
53845384

53855385
"""
5386-
sub(A, inds...)
5386+
view(A, inds...)
53875387
53885388
Like [`getindex`](:func:`getindex`), but returns a view into the parent array `A` with the
53895389
given indices instead of making a copy. Calling [`getindex`](:func:`getindex`) or
53905390
[`setindex!`](:func:`setindex!`) on the returned [`SubArray`](:obj:`SubArray`) computes the
53915391
indices to the parent array on the fly without checking bounds.
53925392
"""
5393-
sub
5393+
view
53945394

53955395
"""
53965396
expanduser(path::AbstractString) -> AbstractString
@@ -7408,14 +7408,6 @@ julia> "Hello " * "world"
74087408
"""
74097409
Base.:(*)(s::AbstractString, t::AbstractString)
74107410

7411-
"""
7412-
slice(A, inds...)
7413-
7414-
Returns a view of array `A` with the given indices like [`sub`](:func:`sub`), but drops all
7415-
dimensions indexed with scalars.
7416-
"""
7417-
slice
7418-
74197411
"""
74207412
time()
74217413

base/exports.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ export
587587
shuffle,
588588
shuffle!,
589589
size,
590-
slice,
591590
slicedim,
592591
sort!,
593592
sort,
@@ -601,7 +600,6 @@ export
601600
step,
602601
stride,
603602
strides,
604-
sub,
605603
sub2ind,
606604
sum!,
607605
sum,
@@ -612,6 +610,7 @@ export
612610
sum_kbn,
613611
vcat,
614612
vec,
613+
view,
615614
zeros,
616615

617616
# linear algebra

base/iterator.jl

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ end
303303

304304
function A_mul_B!{T,S}(u::StridedVector{T}, s::SVDOperator{T,S}, v::StridedVector{T})
305305
a, b = s.m, length(v)
306-
A_mul_B!(sub(u,1:a), s.X, sub(v,a+1:b)) # left singular vector
307-
Ac_mul_B!(sub(u,a+1:b), s.X, sub(v,1:a)) # right singular vector
306+
A_mul_B!(view(u,1:a), s.X, view(v,a+1:b)) # left singular vector
307+
Ac_mul_B!(view(u,a+1:b), s.X, view(v,1:a)) # right singular vector
308308
u
309309
end
310310
size(s::SVDOperator) = s.m + s.n, s.m + s.n

base/linalg/arpack.jl

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)