diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 4e1c3e2d86dec..b55d3c0e773e5 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -935,6 +935,12 @@ function copyto!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::A return B end +function copyto_axcheck!(dest, src) + @noinline checkaxs(axd, axs) = axd == axs || throw(DimensionMismatch("axes must agree, got $axd and $axs")) + + checkaxs(axes(dest), axes(src)) + copyto!(dest, src) +end """ copymutable(a) @@ -996,7 +1002,14 @@ end pointer(x::AbstractArray{T}) where {T} = unsafe_convert(Ptr{T}, x) function pointer(x::AbstractArray{T}, i::Integer) where T @_inline_meta - unsafe_convert(Ptr{T}, x) + (i - first(LinearIndices(x)))*elsize(x) + unsafe_convert(Ptr{T}, x) + _memory_offset(x, i) +end + +# The distance from pointer(x) to the element at x[I...] in bytes +_memory_offset(x::DenseArray, I...) = (_to_linear_index(x, I...) - first(LinearIndices(x)))*elsize(x) +function _memory_offset(x::AbstractArray, I...) + J = _to_subscript_indices(x, I...) + return sum(map((i, s, o)->s*(i-o), J, strides(x), Tuple(first(CartesianIndices(x)))))*elsize(x) end ## Approach: @@ -1066,10 +1079,10 @@ function _getindex(::IndexLinear, A::AbstractArray, I::Vararg{Int,M}) where M @inbounds r = getindex(A, _to_linear_index(A, I...)) r end -_to_linear_index(A::AbstractArray, i::Int) = i -_to_linear_index(A::AbstractVector, i::Int, I::Int...) = i +_to_linear_index(A::AbstractArray, i::Integer) = i +_to_linear_index(A::AbstractVector, i::Integer, I::Integer...) = i _to_linear_index(A::AbstractArray) = 1 -_to_linear_index(A::AbstractArray, I::Int...) = (@_inline_meta; _sub2ind(A, I...)) +_to_linear_index(A::AbstractArray, I::Integer...) = (@_inline_meta; _sub2ind(A, I...)) ## IndexCartesian Scalar indexing: Canonical method is full dimensionality of Ints function _getindex(::IndexCartesian, A::AbstractArray, I::Vararg{Int,M}) where M @@ -1082,12 +1095,12 @@ function _getindex(::IndexCartesian, A::AbstractArray{T,N}, I::Vararg{Int, N}) w @_propagate_inbounds_meta getindex(A, I...) end -_to_subscript_indices(A::AbstractArray, i::Int) = (@_inline_meta; _unsafe_ind2sub(A, i)) +_to_subscript_indices(A::AbstractArray, i::Integer) = (@_inline_meta; _unsafe_ind2sub(A, i)) _to_subscript_indices(A::AbstractArray{T,N}) where {T,N} = (@_inline_meta; fill_to_length((), 1, Val(N))) _to_subscript_indices(A::AbstractArray{T,0}) where {T} = () -_to_subscript_indices(A::AbstractArray{T,0}, i::Int) where {T} = () -_to_subscript_indices(A::AbstractArray{T,0}, I::Int...) where {T} = () -function _to_subscript_indices(A::AbstractArray{T,N}, I::Int...) where {T,N} +_to_subscript_indices(A::AbstractArray{T,0}, i::Integer) where {T} = () +_to_subscript_indices(A::AbstractArray{T,0}, I::Integer...) where {T} = () +function _to_subscript_indices(A::AbstractArray{T,N}, I::Integer...) where {T,N} @_inline_meta J, Jrem = IteratorsMD.split(I, Val(N)) _to_subscript_indices(A, J, Jrem) diff --git a/base/array.jl b/base/array.jl index bd6807853c93e..f1830b7c23b41 100644 --- a/base/array.jl +++ b/base/array.jl @@ -561,8 +561,8 @@ promote_rule(a::Type{Array{T,n}}, b::Type{Array{S,n}}) where {T,n,S} = el_same(p if nameof(@__MODULE__) === :Base # avoid method overwrite # constructors should make copies -Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto!(Array{T,N}(undef, size(x)), x) -AbstractArray{T,N}(A::AbstractArray{S,N}) where {T,N,S} = copyto!(similar(A,T), A) +Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto_axcheck!(Array{T,N}(undef, size(x)), x) +AbstractArray{T,N}(A::AbstractArray{S,N}) where {T,N,S} = copyto_axcheck!(similar(A,T), A) end ## copying iterators to containers diff --git a/base/bitarray.jl b/base/bitarray.jl index 42b299f3b65ec..4cbb13a1c54bf 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -967,11 +967,11 @@ function deleteat!(B::BitVector, inds) n = new_l = length(B) y = iterate(inds) y === nothing && return B - n == 0 && throw(BoundsError(B, inds)) Bc = B.chunks (p, s) = y + checkbounds(B, p) q = p+1 new_l -= 1 y = iterate(inds, s) diff --git a/base/math.jl b/base/math.jl index 06458f0ca2766..3730f5cf32a15 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1000,7 +1000,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero}) ax = abs(x) ax <= 2*Float64(pi,RoundDown) && return x - n,y = rem_pio2_kernel(x) + n,y = rem_pio2_kernel(ax) if iseven(n) if n & 2 == 2 # n % 4 == 2: add pi diff --git a/base/permuteddimsarray.jl b/base/permuteddimsarray.jl index 348d4ad449a53..7ac87df0ad687 100644 --- a/base/permuteddimsarray.jl +++ b/base/permuteddimsarray.jl @@ -64,6 +64,7 @@ function Base.strides(A::PermutedDimsArray{T,N,perm}) where {T,N,perm} s = strides(parent(A)) ntuple(d->s[perm[d]], Val(N)) end +Base.elsize(::Type{<:PermutedDimsArray{<:Any, <:Any, <:Any, <:Any, P}}) where {P} = Base.elsize(P) @inline function Base.getindex(A::PermutedDimsArray{T,N,perm,iperm}, I::Vararg{Int,N}) where {T,N,perm,iperm} @boundscheck checkbounds(A, I...) diff --git a/base/subarray.jl b/base/subarray.jl index ba891183924bb..a4cd5920157ad 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -398,23 +398,12 @@ find_extended_inds(::ScalarIndex, I...) = (@_inline_meta; find_extended_inds(I.. find_extended_inds(i1, I...) = (@_inline_meta; (i1, find_extended_inds(I...)...)) find_extended_inds() = () -unsafe_convert(::Type{Ptr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}}) where {T,N,P} = - unsafe_convert(Ptr{T}, V.parent) + (first_index(V)-1)*sizeof(T) +function unsafe_convert(::Type{Ptr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}}) where {T,N,P} + return unsafe_convert(Ptr{T}, V.parent) + _memory_offset(V.parent, map(first, V.indices)...) +end pointer(V::FastSubArray, i::Int) = pointer(V.parent, V.offset1 + V.stride1*i) pointer(V::FastContiguousSubArray, i::Int) = pointer(V.parent, V.offset1 + i) -pointer(V::SubArray, i::Int) = _pointer(V, i) -_pointer(V::SubArray{<:Any,1}, i::Int) = pointer(V, (i,)) -_pointer(V::SubArray, i::Int) = pointer(V, Base._ind2sub(axes(V), i)) - -function pointer(V::SubArray{T,N,<:Array,<:Tuple{Vararg{RangeIndex}}}, is::Tuple{Vararg{Int}}) where {T,N} - index = first_index(V) - strds = strides(V) - for d = 1:length(is) - index += (is[d]-1)*strds[d] - end - return pointer(V.parent, index) -end # indices are taken from the range/vector # Since bounds-checking is performance-critical and uses diff --git a/deps/checksums/Pkg-dd7f762630b88a64a89ceaaadd3914bfcfb768dc.tar.gz/md5 b/deps/checksums/Pkg-dd7f762630b88a64a89ceaaadd3914bfcfb768dc.tar.gz/md5 new file mode 100644 index 0000000000000..ade4acee84543 --- /dev/null +++ b/deps/checksums/Pkg-dd7f762630b88a64a89ceaaadd3914bfcfb768dc.tar.gz/md5 @@ -0,0 +1 @@ +33090e964c34e70ca5b2723fad2f8414 diff --git a/deps/checksums/Pkg-dd7f762630b88a64a89ceaaadd3914bfcfb768dc.tar.gz/sha512 b/deps/checksums/Pkg-dd7f762630b88a64a89ceaaadd3914bfcfb768dc.tar.gz/sha512 new file mode 100644 index 0000000000000..c2d2c4b95398e --- /dev/null +++ b/deps/checksums/Pkg-dd7f762630b88a64a89ceaaadd3914bfcfb768dc.tar.gz/sha512 @@ -0,0 +1 @@ +e0519d62fc23cb1fd9d8f0da50a8187672d8269b48ac07668a197f04c8c72c7abdae5e9dac16f18c508f75f8e5d7eab83295361201542ea6d159ecc57f70afc8 diff --git a/deps/checksums/Pkg-e364c897b349d48372df4425cbb6f982a00b214d.tar.gz/md5 b/deps/checksums/Pkg-e364c897b349d48372df4425cbb6f982a00b214d.tar.gz/md5 deleted file mode 100644 index 2e73b619d19d5..0000000000000 --- a/deps/checksums/Pkg-e364c897b349d48372df4425cbb6f982a00b214d.tar.gz/md5 +++ /dev/null @@ -1 +0,0 @@ -afa660cd84edd7ed6ef7ebf71846320f diff --git a/deps/checksums/Pkg-e364c897b349d48372df4425cbb6f982a00b214d.tar.gz/sha512 b/deps/checksums/Pkg-e364c897b349d48372df4425cbb6f982a00b214d.tar.gz/sha512 deleted file mode 100644 index 08461f451f5a9..0000000000000 --- a/deps/checksums/Pkg-e364c897b349d48372df4425cbb6f982a00b214d.tar.gz/sha512 +++ /dev/null @@ -1 +0,0 @@ -6685c021761fd5bd656d88f404d34d95dab931d47bf3600debf09a19dc331a31beb6e39494aac7252aae37247c15c7666e10eb15564ac0ef2ab73bef8e80cee5 diff --git a/doc/make.jl b/doc/make.jl index 77dd9c159883d..8b6d3e650a31c 100644 --- a/doc/make.jl +++ b/doc/make.jl @@ -41,6 +41,9 @@ cd(joinpath(@__DIR__, "src")) do end end +# Check if we are building a PDF +const render_pdf = "pdf" in ARGS + # Generate a suitable markdown file from NEWS.md and put it in src str = read(joinpath(@__DIR__, "..", "NEWS.md"), String) splitted = split(str, "") @@ -48,105 +51,123 @@ splitted = split(str, "") replaced_links = replace(splitted[1], r"\[\#([0-9]*?)\]" => s"[#\g<1>](https://github.com/JuliaLang/julia/issues/\g<1>)") write(joinpath(@__DIR__, "src", "NEWS.md"), replaced_links) +Manual = [ + "manual/getting-started.md", + "manual/variables.md", + "manual/integers-and-floating-point-numbers.md", + "manual/mathematical-operations.md", + "manual/complex-and-rational-numbers.md", + "manual/strings.md", + "manual/functions.md", + "manual/control-flow.md", + "manual/variables-and-scoping.md", + "manual/types.md", + "manual/methods.md", + "manual/constructors.md", + "manual/conversion-and-promotion.md", + "manual/interfaces.md", + "manual/modules.md", + "manual/documentation.md", + "manual/metaprogramming.md", + "manual/arrays.md", + "manual/missing.md", + "manual/networking-and-streams.md", + "manual/parallel-computing.md", + "manual/asynchronous-programming.md", + "manual/multi-threading.md", + "manual/distributed-computing.md", + "manual/running-external-programs.md", + "manual/calling-c-and-fortran-code.md", + "manual/handling-operating-system-variation.md", + "manual/environment-variables.md", + "manual/embedding.md", + "manual/code-loading.md", + "manual/profile.md", + "manual/stacktraces.md", + "manual/performance-tips.md", + "manual/workflow-tips.md", + "manual/style-guide.md", + "manual/faq.md", + "manual/noteworthy-differences.md", + "manual/unicode-input.md", +] + +BaseDocs = [ + "base/base.md", + "base/collections.md", + "base/math.md", + "base/numbers.md", + "base/strings.md", + "base/arrays.md", + "base/parallel.md", + "base/multi-threading.md", + "base/constants.md", + "base/file.md", + "base/io-network.md", + "base/punctuation.md", + "base/sort.md", + "base/iterators.md", + "base/c.md", + "base/libc.md", + "base/stacktraces.md", + "base/simd-types.md", +] + +StdlibDocs = [stdlib.targetfile for stdlib in STDLIB_DOCS] + +DevDocs = [ + "devdocs/reflection.md", + "Documentation of Julia's Internals" => [ + "devdocs/init.md", + "devdocs/ast.md", + "devdocs/types.md", + "devdocs/object.md", + "devdocs/eval.md", + "devdocs/callconv.md", + "devdocs/compiler.md", + "devdocs/functions.md", + "devdocs/cartesian.md", + "devdocs/meta.md", + "devdocs/subarrays.md", + "devdocs/isbitsunionarrays.md", + "devdocs/sysimg.md", + "devdocs/llvm.md", + "devdocs/stdio.md", + "devdocs/boundscheck.md", + "devdocs/locks.md", + "devdocs/offset-arrays.md", + "devdocs/require.md", + "devdocs/inference.md", + "devdocs/ssair.md", + "devdocs/gc-sa.md", + ], + "Developing/debugging Julia's C code" => [ + "devdocs/backtraces.md", + "devdocs/debuggingtips.md", + "devdocs/valgrind.md", + "devdocs/sanitizers.md", + ] +] + + +if render_pdf const PAGES = [ - "Home" => "index.md", + "Manual" => ["index.md", Manual...], + "Base" => BaseDocs, + "Standard Library" => StdlibDocs, + "Developer Documentation" => DevDocs, hide("NEWS.md"), - "Manual" => [ - "manual/getting-started.md", - "manual/variables.md", - "manual/integers-and-floating-point-numbers.md", - "manual/mathematical-operations.md", - "manual/complex-and-rational-numbers.md", - "manual/strings.md", - "manual/functions.md", - "manual/control-flow.md", - "manual/variables-and-scoping.md", - "manual/types.md", - "manual/methods.md", - "manual/constructors.md", - "manual/conversion-and-promotion.md", - "manual/interfaces.md", - "manual/modules.md", - "manual/documentation.md", - "manual/metaprogramming.md", - "manual/arrays.md", - "manual/missing.md", - "manual/networking-and-streams.md", - "manual/parallel-computing.md", - "manual/asynchronous-programming.md", - "manual/multi-threading.md", - "manual/distributed-computing.md", - "manual/running-external-programs.md", - "manual/calling-c-and-fortran-code.md", - "manual/handling-operating-system-variation.md", - "manual/environment-variables.md", - "manual/embedding.md", - "manual/code-loading.md", - "manual/profile.md", - "manual/stacktraces.md", - "manual/performance-tips.md", - "manual/workflow-tips.md", - "manual/style-guide.md", - "manual/faq.md", - "manual/noteworthy-differences.md", - "manual/unicode-input.md", - ], - "Base" => [ - "base/base.md", - "base/collections.md", - "base/math.md", - "base/numbers.md", - "base/strings.md", - "base/arrays.md", - "base/parallel.md", - "base/multi-threading.md", - "base/constants.md", - "base/file.md", - "base/io-network.md", - "base/punctuation.md", - "base/sort.md", - "base/iterators.md", - "base/c.md", - "base/libc.md", - "base/stacktraces.md", - "base/simd-types.md", - ], - "Standard Library" => - [stdlib.targetfile for stdlib in STDLIB_DOCS], - "Developer Documentation" => [ - "devdocs/reflection.md", - "Documentation of Julia's Internals" => [ - "devdocs/init.md", - "devdocs/ast.md", - "devdocs/types.md", - "devdocs/object.md", - "devdocs/eval.md", - "devdocs/callconv.md", - "devdocs/compiler.md", - "devdocs/functions.md", - "devdocs/cartesian.md", - "devdocs/meta.md", - "devdocs/subarrays.md", - "devdocs/isbitsunionarrays.md", - "devdocs/sysimg.md", - "devdocs/llvm.md", - "devdocs/stdio.md", - "devdocs/boundscheck.md", - "devdocs/locks.md", - "devdocs/offset-arrays.md", - "devdocs/require.md", - "devdocs/inference.md", - "devdocs/ssair.md", - "devdocs/gc-sa.md", - ], - "Developing/debugging Julia's C code" => [ - "devdocs/backtraces.md", - "devdocs/debuggingtips.md", - "devdocs/valgrind.md", - "devdocs/sanitizers.md", - ] - ], ] +else +const PAGES = [ + "Julia Documentation" => "index.md", + hide("NEWS.md"), + "Manual" => Manual, + "Base" => BaseDocs, + "Standard Library" => StdlibDocs, + "Developer Documentation" => DevDocs, +] +end for stdlib in STDLIB_DOCS @eval using $(stdlib.stdlib) @@ -160,7 +181,6 @@ DocMeta.setdocmeta!(UUIDs, :DocTestSetup, :(using UUIDs, Random), recursive=true DocMeta.setdocmeta!(Pkg, :DocTestSetup, :(using Pkg, Pkg.Artifacts), recursive=true, warn=false) DocMeta.setdocmeta!(Pkg.BinaryPlatforms, :DocTestSetup, :(using Pkg, Pkg.BinaryPlatforms), recursive=true, warn=false) -const render_pdf = "pdf" in ARGS let r = r"buildroot=(.+)", i = findfirst(x -> occursin(r, x), ARGS) global const buildroot = i === nothing ? (@__DIR__) : first(match(r, ARGS[i]).captures) end diff --git a/stdlib/LinearAlgebra/src/adjtrans.jl b/stdlib/LinearAlgebra/src/adjtrans.jl index e3952d0261836..458beea92604e 100644 --- a/stdlib/LinearAlgebra/src/adjtrans.jl +++ b/stdlib/LinearAlgebra/src/adjtrans.jl @@ -208,6 +208,9 @@ Base.strides(A::Transpose{<:Any, <:StridedMatrix}) = reverse(strides(A.parent)) Base.unsafe_convert(::Type{Ptr{T}}, A::Adjoint{<:Real, <:StridedVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent) Base.unsafe_convert(::Type{Ptr{T}}, A::Transpose{<:Any, <:StridedVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent) +Base.elsize(::Type{<:Adjoint{<:Real, P}}) where {P<:StridedVecOrMat} = Base.elsize(P) +Base.elsize(::Type{<:Transpose{<:Any, P}}) where {P<:StridedVecOrMat} = Base.elsize(P) + # for vectors, the semantics of the wrapped and unwrapped types differ # so attempt to maintain both the parent and wrapper type insofar as possible similar(A::AdjOrTransAbsVec) = wrapperop(A)(similar(A.parent)) diff --git a/stdlib/Pkg.version b/stdlib/Pkg.version index 77217c8bd7f08..7fbf5df6e9a41 100644 --- a/stdlib/Pkg.version +++ b/stdlib/Pkg.version @@ -1,2 +1,2 @@ PKG_BRANCH = master -PKG_SHA1 = e364c897b349d48372df4425cbb6f982a00b214d +PKG_SHA1 = dd7f762630b88a64a89ceaaadd3914bfcfb768dc diff --git a/stdlib/REPL/src/docview.jl b/stdlib/REPL/src/docview.jl index 89451e80023e0..1dab4c187e79b 100644 --- a/stdlib/REPL/src/docview.jl +++ b/stdlib/REPL/src/docview.jl @@ -108,6 +108,8 @@ function Markdown.term(io::IO, msg::Message, columns) printstyled(io, msg.msg; msg.fmt...) end +trimdocs(doc, brief::Bool) = doc + function trimdocs(md::Markdown.MD, brief::Bool) brief || return md md, trimmed = _trimdocs(md, brief) diff --git a/stdlib/REPL/test/repl.jl b/stdlib/REPL/test/repl.jl index 57b0be33c823f..4bbbeb509854a 100644 --- a/stdlib/REPL/test/repl.jl +++ b/stdlib/REPL/test/repl.jl @@ -1093,13 +1093,31 @@ Short docs Long docs """ f() = nothing +@doc text""" + f_plain() + +Plain text docs +""" +f_plain() = nothing +@doc html""" +

f_html()

+

HTML docs.

+""" +f_html() = nothing end # module BriefExtended + buf = IOBuffer() md = Base.eval(REPL._helpmode(buf, "$(@__MODULE__).BriefExtended.f")) @test length(md.content) == 2 && isa(md.content[2], REPL.Message) buf = IOBuffer() md = Base.eval(REPL._helpmode(buf, "?$(@__MODULE__).BriefExtended.f")) @test length(md.content) == 1 && length(md.content[1].content[1].content) == 4 +buf = IOBuffer() +txt = Base.eval(REPL._helpmode(buf, "$(@__MODULE__).BriefExtended.f_plain")) +@test !isempty(sprint(show, txt)) +buf = IOBuffer() +html = Base.eval(REPL._helpmode(buf, "$(@__MODULE__).BriefExtended.f_html")) +@test !isempty(sprint(show, html)) # PR #27562 fake_repl() do stdin_write, stdout_read, repl diff --git a/test/abstractarray.jl b/test/abstractarray.jl index f7018fe29d6b4..837cfe62bf6ae 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -974,3 +974,144 @@ end @test Core.sizeof(arrayOfUInt48) == 24 end end + +struct Strider{T,N} <: AbstractArray{T,N} + data::Vector{T} + offset::Int + strides::NTuple{N,Int} + size::NTuple{N,Int} +end +function Strider{T}(strides::NTuple{N}, size::NTuple{N}) where {T,N} + offset = 1-sum(strides .* (strides .< 0) .* (size .- 1)) + data = Array{T}(undef, sum(abs.(strides) .* (size .- 1)) + 1) + return Strider{T, N, Vector{T}}(data, offset, strides, size) +end +function Strider(vec::AbstractArray{T}, strides::NTuple{N}, size::NTuple{N}) where {T,N} + offset = 1-sum(strides .* (strides .< 0) .* (size .- 1)) + @assert length(vec) >= sum(abs.(strides) .* (size .- 1)) + 1 + return Strider{T, N}(vec, offset, strides, size) +end +Base.size(S::Strider) = S.size +function Base.getindex(S::Strider{<:Any,N}, I::Vararg{Int,N}) where {N} + return S.data[sum(S.strides .* (I .- 1)) + S.offset] +end +Base.strides(S::Strider) = S.strides +Base.elsize(::Type{<:Strider{T}}) where {T} = Base.elsize(Vector{T}) +Base.unsafe_convert(::Type{Ptr{T}}, S::Strider{T}) where {T} = pointer(S.data, S.offset) + +@testset "Simple 3d strided views and permutes" for sz in ((5, 3, 2), (7, 11, 13)) + A = collect(reshape(1:prod(sz), sz)) + S = Strider(vec(A), strides(A), sz) + @test pointer(A) == pointer(S) + for i in 1:prod(sz) + @test pointer(A, i) == pointer(S, i) + @test A[i] == S[i] + end + for idxs in ((1:sz[1], 1:sz[2], 1:sz[3]), + (1:sz[1], 2:2:sz[2], sz[3]:-1:1), + (2:2:sz[1]-1, sz[2]:-1:1, sz[3]:-2:2), + (sz[1]:-1:1, sz[2]:-1:1, sz[3]:-1:1), + (sz[1]-1:-3:1, sz[2]:-2:3, 1:sz[3]),) + Ai = A[idxs...] + Av = view(A, idxs...) + Sv = view(S, idxs...) + Ss = Strider{Int, 3}(vec(A), sum((first.(idxs).-1).*strides(A))+1, strides(Av), length.(idxs)) + @test pointer(Av) == pointer(Sv) == pointer(Ss) + for i in 1:length(Av) + @test pointer(Av, i) == pointer(Sv, i) == pointer(Ss, i) + @test Ai[i] == Av[i] == Sv[i] == Ss[i] + end + for perm in ((3, 2, 1), (2, 1, 3), (3, 1, 2)) + P = permutedims(A, perm) + Ap = Base.PermutedDimsArray(A, perm) + Sp = Base.PermutedDimsArray(S, perm) + Ps = Strider{Int, 3}(vec(A), 1, strides(A)[collect(perm)], sz[collect(perm)]) + @test pointer(Ap) == pointer(Sp) == pointer(Ps) + for i in 1:length(Ap) + # This is intentionally disabled due to ambiguity + @test_broken pointer(Ap, i) == pointer(Sp, i) == pointer(Ps, i) + @test P[i] == Ap[i] == Sp[i] == Ps[i] + end + Pv = view(P, idxs[collect(perm)]...) + Pi = P[idxs[collect(perm)]...] + Apv = view(Ap, idxs[collect(perm)]...) + Spv = view(Sp, idxs[collect(perm)]...) + Pvs = Strider{Int, 3}(vec(A), sum((first.(idxs).-1).*strides(A))+1, strides(Apv), size(Apv)) + @test pointer(Apv) == pointer(Spv) == pointer(Pvs) + for i in 1:length(Apv) + @test pointer(Apv, i) == pointer(Spv, i) == pointer(Pvs, i) + @test Pi[i] == Pv[i] == Apv[i] == Spv[i] == Pvs[i] + end + Vp = permutedims(Av, perm) + Ip = permutedims(Ai, perm) + Avp = Base.PermutedDimsArray(Av, perm) + Svp = Base.PermutedDimsArray(Sv, perm) + @test pointer(Avp) == pointer(Svp) + for i in 1:length(Avp) + # This is intentionally disabled due to ambiguity + @test_broken pointer(Avp, i) == pointer(Svp, i) + @test Ip[i] == Vp[i] == Avp[i] == Svp[i] + end + end + end +end + +@testset "simple 2d strided views, permutes, transposes" for sz in ((5, 3), (7, 11)) + A = collect(reshape(1:prod(sz), sz)) + S = Strider(vec(A), strides(A), sz) + @test pointer(A) == pointer(S) + for i in 1:prod(sz) + @test pointer(A, i) == pointer(S, i) + @test A[i] == S[i] + end + for idxs in ((1:sz[1], 1:sz[2]), + (1:sz[1], 2:2:sz[2]), + (2:2:sz[1]-1, sz[2]:-1:1), + (sz[1]:-1:1, sz[2]:-1:1), + (sz[1]-1:-3:1, sz[2]:-2:3),) + Av = view(A, idxs...) + Sv = view(S, idxs...) + Ss = Strider{Int, 2}(vec(A), sum((first.(idxs).-1).*strides(A))+1, strides(Av), length.(idxs)) + @test pointer(Av) == pointer(Sv) == pointer(Ss) + for i in 1:length(Av) + @test pointer(Av, i) == pointer(Sv, i) == pointer(Ss, i) + @test Av[i] == Sv[i] == Ss[i] + end + perm = (2, 1) + P = permutedims(A, perm) + Ap = Base.PermutedDimsArray(A, perm) + At = transpose(A) + Aa = adjoint(A) + Sp = Base.PermutedDimsArray(S, perm) + Ps = Strider{Int, 2}(vec(A), 1, strides(A)[collect(perm)], sz[collect(perm)]) + @test pointer(Ap) == pointer(Sp) == pointer(Ps) == pointer(At) == pointer(Aa) + for i in 1:length(Ap) + # This is intentionally disabled due to ambiguity + @test_broken pointer(Ap, i) == pointer(Sp, i) == pointer(Ps, i) == pointer(At, i) == pointer(Aa, i) + @test pointer(Ps, i) == pointer(At, i) == pointer(Aa, i) + @test P[i] == Ap[i] == Sp[i] == Ps[i] == At[i] == Aa[i] + end + Pv = view(P, idxs[collect(perm)]...) + Apv = view(Ap, idxs[collect(perm)]...) + Atv = view(At, idxs[collect(perm)]...) + Ata = view(Aa, idxs[collect(perm)]...) + Spv = view(Sp, idxs[collect(perm)]...) + Pvs = Strider{Int, 2}(vec(A), sum((first.(idxs).-1).*strides(A))+1, strides(Apv), size(Apv)) + @test pointer(Apv) == pointer(Spv) == pointer(Pvs) == pointer(Atv) == pointer(Ata) + for i in 1:length(Apv) + @test pointer(Apv, i) == pointer(Spv, i) == pointer(Pvs, i) == pointer(Atv, i) == pointer(Ata, i) + @test Pv[i] == Apv[i] == Spv[i] == Pvs[i] == Atv[i] == Ata[i] + end + Vp = permutedims(Av, perm) + Avp = Base.PermutedDimsArray(Av, perm) + Avt = transpose(Av) + Ava = adjoint(Av) + Svp = Base.PermutedDimsArray(Sv, perm) + @test pointer(Avp) == pointer(Svp) == pointer(Avt) == pointer(Ava) + for i in 1:length(Avp) + # This is intentionally disabled due to ambiguity + @test_broken pointer(Avp, i) == pointer(Svp, i) == pointer(Avt, i) == pointer(Ava, i) + @test Vp[i] == Avp[i] == Svp[i] == Avt[i] == Ava[i] + end + end +end diff --git a/test/bitarray.jl b/test/bitarray.jl index a12d93cbef5b0..16a7700f91f28 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -666,6 +666,8 @@ timesofar("indexing") b1 = bitrand(v1) @test_throws ArgumentError deleteat!(b1, [1, 1, 2]) @test_throws BoundsError deleteat!(b1, [1, length(b1)+1]) + @test_throws BoundsError deleteat!(b1, [length(b1)+rand(1:100)]) + @test_throws BoundsError deleteat!(bitrand(1), [-1, 0, 1]) @test_throws BoundsError deleteat!(BitVector(), 1) @test_throws BoundsError deleteat!(BitVector(), [1]) diff --git a/test/hashing.jl b/test/hashing.jl index fa9b2bc4fdde0..c2b3ed27f6a51 100644 --- a/test/hashing.jl +++ b/test/hashing.jl @@ -111,10 +111,12 @@ end for a in vals a isa AbstractArray || continue - if keys(a) == keys(Array(a)) - @test hash(a) == hash(Array(a)) == hash(Array{Any}(a)) + aa = copyto!(Array{eltype(a)}(undef, size(a)), a) + aaa = copyto!(Array{Any}(undef, size(a)), a) + if keys(a) == keys(aa) + @test hash(a) == hash(aa) == hash(aaa) else - @test hash(a) == hash(OffsetArray(Array(a), (first.(axes(a)).-1)...)) == hash(OffsetArray(Array{Any}(a), (first.(axes(a)).-1)...)) + @test hash(a) == hash(OffsetArray(aa, (first.(axes(a)).-1)...)) == hash(OffsetArray(aaa, (first.(axes(a)).-1)...)) end end diff --git a/test/numbers.jl b/test/numbers.jl index bbe97017bde68..546c262e31e8c 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2506,6 +2506,14 @@ end @test rem2pi(T(-4), RoundNearest) ≈ 2pi-4 @test rem2pi(T(-4), RoundDown) ≈ 2pi-4 @test rem2pi(T(-4), RoundUp) == -4 + @test rem2pi(T(8), RoundToZero) ≈ 8-2pi + @test rem2pi(T(8), RoundNearest) ≈ 8-2pi + @test rem2pi(T(8), RoundDown) ≈ 8-2pi + @test rem2pi(T(8), RoundUp) ≈ 8-4pi + @test rem2pi(T(-8), RoundToZero) ≈ -8+2pi + @test rem2pi(T(-8), RoundNearest) ≈ -8+2pi + @test rem2pi(T(-8), RoundDown) ≈ -8+4pi + @test rem2pi(T(-8), RoundUp) ≈ -8+2pi end import Base.^ diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 7479821be8268..e284371cb12cf 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -21,6 +21,7 @@ h = OffsetArray([-1,1,-2,2,0], (-3,)) @test axes(v) == (-2:1,) @test size(v) == (4,) @test size(v, 1) == 4 +@test_throws DimensionMismatch Array(v) A0 = [1 3; 2 4] A = OffsetArray(A0, (-1,2)) # IndexLinear