@@ -116,9 +116,6 @@ axes1(A::AbstractArray{<:Any,0}) = OneTo(1)
116116axes1 (A:: AbstractArray ) = (@_inline_meta ; axes (A)[1 ])
117117axes1 (iter) = oneto (length (iter))
118118
119- unsafe_indices (A) = axes (A)
120- unsafe_indices (r:: AbstractRange ) = (oneto (unsafe_length (r)),) # Ranges use checked_sub for size
121-
122119"""
123120 keys(a::AbstractArray)
124121
@@ -580,14 +577,14 @@ end
580577function trailingsize (inds:: Indices , n)
581578 s = 1
582579 for i= n: length (inds)
583- s *= unsafe_length (inds[i])
580+ s *= length (inds[i])
584581 end
585582 return s
586583end
587584# This version is type-stable even if inds is heterogeneous
588585function trailingsize (inds:: Indices )
589586 @_inline_meta
590- prod (map (unsafe_length , inds))
587+ prod (map (length , inds))
591588end
592589
593590# # Bounds checking ##
@@ -688,7 +685,7 @@ function checkbounds_indices(::Type{Bool}, ::Tuple{}, I::Tuple)
688685 @_inline_meta
689686 checkindex (Bool, OneTo (1 ), I[1 ]):: Bool & checkbounds_indices (Bool, (), tail (I))
690687end
691- checkbounds_indices (:: Type{Bool} , IA:: Tuple , :: Tuple{} ) = (@_inline_meta ; all (x-> unsafe_length (x)== 1 , IA))
688+ checkbounds_indices (:: Type{Bool} , IA:: Tuple , :: Tuple{} ) = (@_inline_meta ; all (x-> length (x)== 1 , IA))
692689checkbounds_indices (:: Type{Bool} , :: Tuple{} , :: Tuple{} ) = true
693690
694691throw_boundserror (A, I) = (@_noinline_meta ; throw (BoundsError (A, I)))
@@ -886,7 +883,35 @@ function copy!(dst::AbstractArray, src::AbstractArray)
886883end
887884
888885# # from general iterable to any array
886+
887+ """
888+ copyto!(dest::AbstractArray, src) -> dest
889+
890+ Copy all elements from collection `src` to array `dest`, whose length must be greater than
891+ or equal to the length `n` of `src`. The first `n` elements of `dest` are overwritten,
892+ the other elements are left untouched.
889893
894+ See also [`copy!`](@ref Base.copy!), [`copy`](@ref).
895+
896+ # Examples
897+ ```jldoctest
898+ julia> x = [1., 0., 3., 0., 5.];
899+
900+ julia> y = zeros(7);
901+
902+ julia> copyto!(y, x);
903+
904+ julia> y
905+ 7-element Vector{Float64}:
906+ 1.0
907+ 0.0
908+ 3.0
909+ 0.0
910+ 5.0
911+ 0.0
912+ 0.0
913+ ```
914+ """
890915function copyto! (dest:: AbstractArray , src)
891916 destiter = eachindex (dest)
892917 y = iterate (destiter)
@@ -964,87 +989,6 @@ function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer, n::
964989 return dest
965990end
966991
967- # # copy between abstract arrays - generally more efficient
968- # # since a single index variable can be used.
969-
970- """
971- copyto!(dest::AbstractArray, src) -> dest
972-
973- Copy all elements from collection `src` to array `dest`, whose length must be greater than
974- or equal to the length `n` of `src`. The first `n` elements of `dest` are overwritten,
975- the other elements are left untouched.
976-
977- See also [`copy!`](@ref Base.copy!), [`copy`](@ref).
978-
979- # Examples
980- ```jldoctest
981- julia> x = [1., 0., 3., 0., 5.];
982-
983- julia> y = zeros(7);
984-
985- julia> copyto!(y, x);
986-
987- julia> y
988- 7-element Vector{Float64}:
989- 1.0
990- 0.0
991- 3.0
992- 0.0
993- 5.0
994- 0.0
995- 0.0
996- ```
997- """
998- function copyto! (dest:: AbstractArray , src:: AbstractArray )
999- isempty (src) && return dest
1000- src′ = unalias (dest, src)
1001- copyto_unaliased! (IndexStyle (dest), dest, IndexStyle (src′), src′)
1002- end
1003-
1004- function copyto! (deststyle:: IndexStyle , dest:: AbstractArray , srcstyle:: IndexStyle , src:: AbstractArray )
1005- isempty (src) && return dest
1006- src′ = unalias (dest, src)
1007- copyto_unaliased! (deststyle, dest, srcstyle, src′)
1008- end
1009-
1010- function copyto_unaliased! (deststyle:: IndexStyle , dest:: AbstractArray , srcstyle:: IndexStyle , src:: AbstractArray )
1011- isempty (src) && return dest
1012- length (dest) >= length (src) || throw (BoundsError (dest, LinearIndices (src)))
1013- if deststyle isa IndexLinear
1014- if srcstyle isa IndexLinear
1015- Δi = firstindex (dest) - firstindex (src)
1016- for i in eachindex (src)
1017- @inbounds dest[i + Δi] = src[i]
1018- end
1019- else
1020- j = firstindex (dest) - 1
1021- @inbounds @simd for I in eachindex (src)
1022- dest[j+= 1 ] = src[I]
1023- end
1024- end
1025- else
1026- if srcstyle isa IndexLinear
1027- i = firstindex (src) - 1
1028- @inbounds @simd for J in eachindex (dest)
1029- dest[J] = src[i+= 1 ]
1030- end
1031- else
1032- iterdest, itersrc = eachindex (dest), eachindex (src)
1033- if iterdest == itersrc
1034- # Shared-iterator implementation
1035- @inbounds @simd for I in itersrc
1036- dest[I] = src[I]
1037- end
1038- else
1039- for (I,J) in zip (itersrc, iterdest)
1040- @inbounds dest[J] = src[I]
1041- end
1042- end
1043- end
1044- end
1045- return dest
1046- end
1047-
1048992function copyto! (dest:: AbstractArray , dstart:: Integer , src:: AbstractArray )
1049993 copyto! (dest, dstart, src, first (LinearIndices (src)), length (src))
1050994end
@@ -2497,8 +2441,8 @@ function _sub2ind_recurse(inds, L, ind, i::Integer, I::Integer...)
24972441end
24982442
24992443nextL (L, l:: Integer ) = L* l
2500- nextL (L, r:: AbstractUnitRange ) = L* unsafe_length (r)
2501- nextL (L, r:: Slice ) = L* unsafe_length (r. indices)
2444+ nextL (L, r:: AbstractUnitRange ) = L* length (r)
2445+ nextL (L, r:: Slice ) = L* length (r. indices)
25022446offsetin (i, l:: Integer ) = i- 1
25032447offsetin (i, r:: AbstractUnitRange ) = i- first (r)
25042448
@@ -2524,7 +2468,7 @@ end
25242468_lookup (ind, d:: Integer ) = ind+ 1
25252469_lookup (ind, r:: AbstractUnitRange ) = ind+ first (r)
25262470_div (ind, d:: Integer ) = div (ind, d), 1 , d
2527- _div (ind, r:: AbstractUnitRange ) = (d = unsafe_length (r); (div (ind, d), first (r), d))
2471+ _div (ind, r:: AbstractUnitRange ) = (d = length (r); (div (ind, d), first (r), d))
25282472
25292473# Vectorized forms
25302474function _sub2ind (inds:: Indices{1} , I1:: AbstractVector{T} , I:: AbstractVector{T} ...) where T<: Integer
0 commit comments