Skip to content

Commit

Permalink
Merge branch 'master' into os-memorynew-light
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith authored Dec 16, 2024
2 parents d77bb2a + b4c5e58 commit 5fe154b
Show file tree
Hide file tree
Showing 32 changed files with 106 additions and 49 deletions.
2 changes: 1 addition & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ kw"new"
"""
where
The `where` keyword creates a type that is an iterated union of other types, over all
The `where` keyword creates a [`UnionAll`](@ref) type, which may be thought of as an iterated union of other types, over all
values of some variable. For example `Vector{T} where T<:Real` includes all [`Vector`](@ref)s
where the element type is some kind of `Real` number.
Expand Down
12 changes: 9 additions & 3 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ using .Base:
AbstractRange, AbstractUnitRange, UnitRange, LinearIndices, TupleOrBottom,
(:), |, +, -, *, !==, !, ==, !=, <=, <, >, >=, =>, missing,
any, _counttuple, eachindex, ntuple, zero, prod, reduce, in, firstindex, lastindex,
tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString
tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString,
afoldl
using Core: @doc

using .Base:
Expand Down Expand Up @@ -1202,8 +1203,13 @@ julia> [(x,y) for x in 0:1 for y in 'a':'c'] # collects generators involving It
flatten(itr) = Flatten(itr)

eltype(::Type{Flatten{I}}) where {I} = eltype(eltype(I))
eltype(::Type{Flatten{I}}) where {I<:Union{Tuple,NamedTuple}} = promote_typejoin(map(eltype, fieldtypes(I))...)
eltype(::Type{Flatten{Tuple{}}}) = eltype(Tuple{})

# For tuples, we statically know the element type of each index, so we can compute
# this at compile time.
function eltype(::Type{Flatten{I}}) where {I<:Union{Tuple,NamedTuple}}
afoldl((T, i) -> promote_typejoin(T, eltype(i)), Union{}, fieldtypes(I)...)
end

IteratorEltype(::Type{Flatten{I}}) where {I} = _flatteneltype(I, IteratorEltype(I))
IteratorEltype(::Type{Flatten{Tuple{}}}) = IteratorEltype(Tuple{})
_flatteneltype(I, ::HasEltype) = IteratorEltype(eltype(I))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3209f45b8ea01a22ac7e9b265e3b84f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
314981eee11356f14b6dc9e07389c51432e7862d6c767d87d6679385f5a36faef34902954a5dfa6b37d8f3f25eaa4f23ba9431cc78acd3513377955e7d73f210

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9dbfa6c0a76d20b2ca8de844d08f3af4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f5d2469419f4a083f84c1f23e6e528f4115804e45bdfdbd897110bb346aaa70afc57c24f9166ae20fb4305c1d40f5a77de4cfed7b69aef93f09d0d4eff183e3d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e52615827242aae56422a4f73a8c6878
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7b1df257616aaa9067f822a88dddf52bc10f9f61e3a0728e33e595455bd7167e680c50371c41cb25f8c8a9fb9cf40225847df1523a6c6f3571a471f7163f563c

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
308e26cc6171656caaa7f6ba07e83d1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
62b94ad0dca0d62e5753f50aef806ebdb5c8b56b241a285957190845be21fc6b8c8f93089b6f627795f6d7f2b1b01118bcff87c21102a3f3bae6d4c408362681

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
411277f3701cc3e286ec8a84ccdf6f11
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
95a7e92389f6fd02d3bec17ec0201ba41316aa2d7c321b14af88ccce8246fd0000ed2c0cc818f87cb81f7134304233db897f656426a00caac1bc7635056260c2
2 changes: 1 addition & 1 deletion stdlib/ArgTools.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARGTOOLS_BRANCH = master
ARGTOOLS_SHA1 = 997089b9cd56404b40ff766759662e16dc1aab4b
ARGTOOLS_SHA1 = 1314758ad02ff5e9e5ca718920c6c633b467a84a
ARGTOOLS_GIT_URL := https://github.com/JuliaIO/ArgTools.jl.git
ARGTOOLS_TAR_URL = https://api.github.com/repos/JuliaIO/ArgTools.jl/tarball/$1
2 changes: 1 addition & 1 deletion stdlib/Downloads.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOWNLOADS_BRANCH = master
DOWNLOADS_SHA1 = 89d3c7dded535a77551e763a437a6d31e4d9bf84
DOWNLOADS_SHA1 = afd04be8aa94204c075c8aec83fca040ebb4ff98
DOWNLOADS_GIT_URL := https://github.com/JuliaLang/Downloads.jl.git
DOWNLOADS_TAR_URL = https://api.github.com/repos/JuliaLang/Downloads.jl/tarball/$1
2 changes: 1 addition & 1 deletion stdlib/SHA.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SHA_BRANCH = master
SHA_SHA1 = aaf2df61ff8c3898196587a375d3cf213bd40b41
SHA_SHA1 = 8fa221ddc8f3b418d9929084f1644f4c32c9a27e
SHA_GIT_URL := https://github.com/JuliaCrypto/SHA.jl.git
SHA_TAR_URL = https://api.github.com/repos/JuliaCrypto/SHA.jl/tarball/$1
2 changes: 1 addition & 1 deletion stdlib/SparseArrays.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SPARSEARRAYS_BRANCH = main
SPARSEARRAYS_SHA1 = 1b4933ccc7b1f97427ff88bd7ba58950021f2c60
SPARSEARRAYS_SHA1 = 4fd3aad5735e3b80eefe7b068f3407d7dd0c0924
SPARSEARRAYS_GIT_URL := https://github.com/JuliaSparse/SparseArrays.jl.git
SPARSEARRAYS_TAR_URL = https://api.github.com/repos/JuliaSparse/SparseArrays.jl/tarball/$1
2 changes: 1 addition & 1 deletion stdlib/StyledStrings.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
STYLEDSTRINGS_BRANCH = main
STYLEDSTRINGS_SHA1 = 056e843b2d428bb9735b03af0cff97e738ac7e14
STYLEDSTRINGS_SHA1 = 8985a37ac054c37d084a03ad2837208244824877
STYLEDSTRINGS_GIT_URL := https://github.com/JuliaLang/StyledStrings.jl.git
STYLEDSTRINGS_TAR_URL = https://api.github.com/repos/JuliaLang/StyledStrings.jl/tarball/$1
21 changes: 21 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2206,3 +2206,24 @@ end
@test b.ref === a.ref
end
end
@testset "AbstractArrayMath" begin
@testset "IsReal" begin
A = [1, 2, 3, 4]
@test isreal(A) == true
B = [1.1, 2.2, 3.3, 4.4]
@test isreal(B) == true
C = [1, 2.2, 3]
@test isreal(C) == true
D = Real[]
@test isreal(D) == true
E = [1 + 1im, 2 - 2im]
@test isreal(E) == false
struct MyReal <: Real
value::Float64
end
F = [MyReal(1.0), MyReal(2.0)]
@test isreal(F) == true
G = ["a", "b", "c"]
@test_throws MethodError isreal(G)
end
end
62 changes: 34 additions & 28 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,34 +307,40 @@ end
@test_throws ArgumentError dropdims(a, dims=3)
@test_throws ArgumentError dropdims(a, dims=4)
@test_throws ArgumentError dropdims(a, dims=6)


a = rand(8, 7)
@test @inferred(insertdims(a, dims=1)) == @inferred(insertdims(a, dims=(1,))) == reshape(a, (1, 8, 7))
@test @inferred(insertdims(a, dims=3)) == @inferred(insertdims(a, dims=(3,))) == reshape(a, (8, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3))) == reshape(a, (1, 8, 1, 7))
@test @inferred(insertdims(a, dims=(1, 2, 3))) == reshape(a, (1, 1, 1, 8, 7))
@test @inferred(insertdims(a, dims=(1, 4))) == reshape(a, (1, 8, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3, 5))) == reshape(a, (1, 8, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 2, 4, 6))) == reshape(a, (1, 1, 8, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3, 4, 6))) == reshape(a, (1, 8, 1, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 4, 6, 3))) == reshape(a, (1, 8, 1, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3, 5, 6))) == reshape(a, (1, 8, 1, 7, 1, 1))

@test_throws ArgumentError insertdims(a, dims=(1, 1, 2, 3))
@test_throws ArgumentError insertdims(a, dims=(1, 2, 2, 3))
@test_throws ArgumentError insertdims(a, dims=(1, 2, 3, 3))
@test_throws UndefKeywordError insertdims(a)
@test_throws ArgumentError insertdims(a, dims=0)
@test_throws ArgumentError insertdims(a, dims=(1, 2, 1))
@test_throws ArgumentError insertdims(a, dims=4)
@test_throws ArgumentError insertdims(a, dims=6)

# insertdims and dropdims are inverses
b = rand(1,1,1,5,1,1,7)
for dims in [1, (1,), 2, (2,), 3, (3,), (1,3), (1,2,3), (1,2), (1,3,5), (1,2,5,6), (1,3,5,6), (1,3,5,6), (1,6,5,3)]
@test dropdims(insertdims(a; dims); dims) == a
@test insertdims(dropdims(b; dims); dims) == b
@testset "insertdims" begin
a = rand(8, 7)
@test @inferred(insertdims(a, dims=1)) == @inferred(insertdims(a, dims=(1,))) == reshape(a, (1, 8, 7))
@test @inferred(insertdims(a, dims=3)) == @inferred(insertdims(a, dims=(3,))) == reshape(a, (8, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3))) == reshape(a, (1, 8, 1, 7))
@test @inferred(insertdims(a, dims=(1, 2, 3))) == reshape(a, (1, 1, 1, 8, 7))
@test @inferred(insertdims(a, dims=(1, 4))) == reshape(a, (1, 8, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3, 5))) == reshape(a, (1, 8, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 2, 4, 6))) == reshape(a, (1, 1, 8, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3, 4, 6))) == reshape(a, (1, 8, 1, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 4, 6, 3))) == reshape(a, (1, 8, 1, 1, 7, 1))
@test @inferred(insertdims(a, dims=(1, 3, 5, 6))) == reshape(a, (1, 8, 1, 7, 1, 1))
@test_throws ArgumentError insertdims(a, dims=(1, 1, 2, 3))
@test_throws ArgumentError insertdims(a, dims=(1, 2, 2, 3))
@test_throws ArgumentError insertdims(a, dims=(1, 2, 3, 3))
@test_throws UndefKeywordError insertdims(a)
@test_throws ArgumentError insertdims(a, dims=0)
@test_throws ArgumentError insertdims(a, dims=(1, 2, 1))
@test_throws ArgumentError insertdims(a, dims=4)
@test_throws ArgumentError insertdims(a, dims=6)
A = reshape(1:6, 2, 3)
@test_throws ArgumentError insertdims(A, dims=(2, 2))
D = insertdims(A, dims=())
@test size(D) == size(A)
@test D == A
E = ones(2, 3, 4)
F = insertdims(E, dims=(2, 4, 6))
@test size(F) == (2, 1, 3, 1, 4, 1)
# insertdims and dropdims are inverses
b = rand(1,1,1,5,1,1,7)
for dims in [1, (1,), 2, (2,), 3, (3,), (1,3), (1,2,3), (1,2), (1,3,5), (1,2,5,6), (1,3,5,6), (1,3,5,6), (1,6,5,3)]
@test dropdims(insertdims(a; dims); dims) == a
@test insertdims(dropdims(b; dims); dims) == b
end
end

sz = (5,8,7)
Expand Down
18 changes: 16 additions & 2 deletions test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,22 @@ backtrace()
@test occursin("g28442", output[3])
@test lstrip(output[5])[1:3] == "[2]"
@test occursin("f28442", output[5])
@test occursin("the above 2 lines are repeated 5000 more times", output[7])
@test lstrip(output[8])[1:7] == "[10003]"
is_windows_32_bit = Sys.iswindows() && (Sys.WORD_SIZE == 32)
if is_windows_32_bit
# These tests are currently broken (intermittently/non-determistically) on 32-bit Windows.
# https://github.com/JuliaLang/julia/issues/55900
# Instead of skipping them entirely, we skip one, and we loosen the other.

# Broken test: @test occursin("the above 2 lines are repeated 5000 more times", output[7])
@test occursin("the above 2 lines are repeated ", output[7])
@test occursin(" more times", output[7])

# Broken test: @test lstrip(output[8])[1:7] == "[10003]"
@test_broken false
else
@test occursin("the above 2 lines are repeated 5000 more times", output[7])
@test lstrip(output[8])[1:7] == "[10003]"
end
end

@testset "Line number correction" begin
Expand Down
8 changes: 8 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ end
@test eltype(flatten(UnitRange{Int8}[1:2, 3:4])) == Int8
@test eltype(flatten(([1, 2], [3.0, 4.0]))) == Real
@test eltype(flatten((a = [1, 2], b = Int8[3, 4]))) == Signed
@test eltype(flatten((Int[], Nothing[], Int[]))) == Union{Int, Nothing}
@test eltype(flatten((String[],))) == String
@test eltype(flatten((Int[], UInt[], Int8[],))) == Integer
@test eltype(flatten((; a = Int[], b = Nothing[], c = Int[]))) == Union{Int, Nothing}
@test eltype(flatten((; a = String[],))) == String
@test eltype(flatten((; a = Int[], b = UInt[], c = Int8[],))) == Integer
@test eltype(flatten(())) == Union{}
@test eltype(flatten((;))) == Union{}
@test length(flatten(zip(1:3, 4:6))) == 6
@test length(flatten(1:6)) == 6
@test collect(flatten(Any[])) == Any[]
Expand Down
2 changes: 2 additions & 0 deletions test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ end
@test !isempty(A)
A = empty!(A)
@test isempty(A)
@test isnothing(sizehint!(A, 10))
@test Base.copymutable(A) == copy(A)
end

@testset "⊊, ⊋" begin
Expand Down

0 comments on commit 5fe154b

Please sign in to comment.