Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports for 1.10.6 #55746

Open
wants to merge 7 commits into
base: release-1.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ endif
cp -R -L $(JULIAHOME)/base/* $(DESTDIR)$(datarootdir)/julia/base
cp -R -L $(JULIAHOME)/test/* $(DESTDIR)$(datarootdir)/julia/test
cp -R -L $(build_datarootdir)/julia/* $(DESTDIR)$(datarootdir)/julia

# Set .jl sources as read-only to match package directories
find $(DESTDIR)$(datarootdir)/julia/base -type f -name \*.jl -exec chmod 0444 '{}' \;
find $(DESTDIR)$(datarootdir)/julia/test -type f -name \*.jl -exec chmod 0444 '{}' \;

# Copy documentation
cp -R -L $(BUILDROOT)/doc/_build/html $(DESTDIR)$(docdir)/
# Remove various files which should not be installed
Expand Down
17 changes: 7 additions & 10 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1028,24 +1028,22 @@ end
function atanh(z::Complex{T}) where T
z = float(z)
Tf = float(T)
Ω = prevfloat(typemax(Tf))
θ = sqrt(Ω)/4
ρ = 1/θ
x, y = reim(z)
ax = abs(x)
ay = abs(y)
θ = sqrt(floatmax(Tf))/4
if ax > θ || ay > θ #Prevent overflow
if isnan(y)
if isinf(x)
return Complex(copysign(zero(x),x), y)
else
return Complex(real(1/z), y)
return Complex(real(inv(z)), y)
end
end
if isinf(y)
return Complex(copysign(zero(x),x), copysign(oftype(y,pi)/2, y))
end
return Complex(real(1/z), copysign(oftype(y,pi)/2, y))
return Complex(real(inv(z)), copysign(oftype(y,pi)/2, y))
end
β = copysign(one(Tf), x)
z *= β
Expand All @@ -1055,16 +1053,15 @@ function atanh(z::Complex{T}) where T
ξ = oftype(x, Inf)
η = y
else
ym = ay+ρ
ξ = log(sqrt(sqrt(4+y*y))/sqrt(ym))
η = copysign(oftype(y,pi)/2 + atan(ym/2), y)/2
ξ = log(sqrt(sqrt(muladd(y, y, 4)))/sqrt(ay))
η = copysign(oftype(y,pi)/2 + atan(ay/2), y)/2
end
else #Normal case
ysq = (ay+ρ)^2
ysq = ay^2
if x == 0
ξ = x
else
ξ = log1p(4x/((1-x)^2 + ysq))/4
ξ = log1p(4x/(muladd(1-x, 1-x, ysq)))/4
end
η = angle(Complex((1-x)*(1+x)-ysq, 2y))/2
end
Expand Down
10 changes: 5 additions & 5 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,11 @@ function mapreduce_impl(f, op::Union{typeof(max), typeof(min)},
start = first + 1
simdstop = start + chunk_len - 4
while simdstop <= last - 3
@inbounds for i in start:4:simdstop
v1 = _fast(op, v1, f(A[i+0]))
v2 = _fast(op, v2, f(A[i+1]))
v3 = _fast(op, v3, f(A[i+2]))
v4 = _fast(op, v4, f(A[i+3]))
for i in start:4:simdstop
v1 = _fast(op, v1, f(@inbounds(A[i+0])))
v2 = _fast(op, v2, f(@inbounds(A[i+1])))
v3 = _fast(op, v3, f(@inbounds(A[i+2])))
v4 = _fast(op, v4, f(@inbounds(A[i+3])))
end
checkbounds(A, simdstop+3)
start += chunk_len
Expand Down
37 changes: 19 additions & 18 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,20 @@ function _mapreducedim!(f, op, R::AbstractArray, A::AbstractArrayOrBroadcasted)
if reducedim1(R, A)
# keep the accumulator as a local variable when reducing along the first dimension
i1 = first(axes1(R))
@inbounds for IA in CartesianIndices(indsAt)
for IA in CartesianIndices(indsAt)
IR = Broadcast.newindex(IA, keep, Idefault)
r = R[i1,IR]
@inbounds r = R[i1,IR]
@simd for i in axes(A, 1)
r = op(r, f(A[i, IA]))
r = op(r, f(@inbounds(A[i, IA])))
end
R[i1,IR] = r
@inbounds R[i1,IR] = r
end
else
@inbounds for IA in CartesianIndices(indsAt)
for IA in CartesianIndices(indsAt)
IR = Broadcast.newindex(IA, keep, Idefault)
@simd for i in axes(A, 1)
R[i,IR] = op(R[i,IR], f(A[i,IA]))
v = op(@inbounds(R[i,IR]), f(@inbounds(A[i,IA])))
@inbounds R[i,IR] = v
end
end
end
Expand Down Expand Up @@ -1058,33 +1059,33 @@ function findminmax!(f, op, Rval, Rind, A::AbstractArray{T,N}) where {T,N}
zi = zero(eltype(ks))
if reducedim1(Rval, A)
i1 = first(axes1(Rval))
@inbounds for IA in CartesianIndices(indsAt)
for IA in CartesianIndices(indsAt)
IR = Broadcast.newindex(IA, keep, Idefault)
tmpRv = Rval[i1,IR]
tmpRi = Rind[i1,IR]
@inbounds tmpRv = Rval[i1,IR]
@inbounds tmpRi = Rind[i1,IR]
for i in axes(A,1)
k, kss = y::Tuple
tmpAv = f(A[i,IA])
tmpAv = f(@inbounds(A[i,IA]))
if tmpRi == zi || op(tmpRv, tmpAv)
tmpRv = tmpAv
tmpRi = k
end
y = iterate(ks, kss)
end
Rval[i1,IR] = tmpRv
Rind[i1,IR] = tmpRi
@inbounds Rval[i1,IR] = tmpRv
@inbounds Rind[i1,IR] = tmpRi
end
else
@inbounds for IA in CartesianIndices(indsAt)
for IA in CartesianIndices(indsAt)
IR = Broadcast.newindex(IA, keep, Idefault)
for i in axes(A, 1)
k, kss = y::Tuple
tmpAv = f(A[i,IA])
tmpRv = Rval[i,IR]
tmpRi = Rind[i,IR]
tmpAv = f(@inbounds(A[i,IA]))
@inbounds tmpRv = Rval[i,IR]
@inbounds tmpRi = Rind[i,IR]
if tmpRi == zi || op(tmpRv, tmpAv)
Rval[i,IR] = tmpAv
Rind[i,IR] = k
@inbounds Rval[i,IR] = tmpAv
@inbounds Rind[i,IR] = k
end
y = iterate(ks, kss)
end
Expand Down
2 changes: 0 additions & 2 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,8 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
return o;
}
}
jl_gc_count_freed(jl_array_nbytes(a));
a->nrows = 0;
a->length = 0;
a->maxsize = 0;
return jl_pchar_to_string((const char*)jl_array_data(a), len);
}

Expand Down
7 changes: 0 additions & 7 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,13 +1128,6 @@ void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + sz);
}

void jl_gc_count_freed(size_t sz) JL_NOTSAFEPOINT
{
jl_ptls_t ptls = jl_current_task->ptls;
jl_atomic_store_relaxed(&ptls->gc_num.freed,
jl_atomic_load_relaxed(&ptls->gc_num.freed) + sz);
}

static void combine_thread_gc_counts(jl_gc_num_t *dest) JL_NOTSAFEPOINT
{
int gc_n_threads;
Expand Down
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3385,7 +3385,7 @@ static int sort_mlmatches(jl_array_t *t, size_t idx, arraylist_t *visited, array
int msp2 = !msp && jl_type_morespecific((jl_value_t*)m2->sig, (jl_value_t*)m->sig);
if (!msp) {
if (subt || !include_ambiguous || (lim != -1 && msp2)) {
if (subt2 || jl_subtype((jl_value_t*)ti, m2->sig)) {
if (subt2 || ((lim != -1 || (!include_ambiguous && !msp2)) && jl_subtype((jl_value_t*)ti, m2->sig))) {
// this may be filtered out as fully intersected, if applicable later
mayexclude = 1;
}
Expand Down
1 change: 0 additions & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT;
void jl_gc_track_malloced_array(jl_ptls_t ptls, jl_array_t *a) JL_NOTSAFEPOINT;
size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT;
void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT;
void jl_gc_count_freed(size_t sz) JL_NOTSAFEPOINT;
void jl_gc_run_all_finalizers(jl_task_t *ct);
void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task);
void jl_gc_add_finalizer_(jl_ptls_t ptls, void *v, void *f) JL_NOTSAFEPOINT;
Expand Down
18 changes: 9 additions & 9 deletions stdlib/Dates/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,9 @@ value in the days field is uncertain.
See the [API reference](@ref stdlib-dates-api) for additional information
on methods exported from the `Dates` module.

# [API reference](@id stdlib-dates-api)
## [API reference](@id stdlib-dates-api)

## Dates and Time Types
### Dates and Time Types

```@docs
Dates.Period
Expand All @@ -705,7 +705,7 @@ Dates.TimeZone
Dates.UTC
```

## Dates Functions
### Dates Functions

```@docs
Dates.DateTime(::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64)
Expand Down Expand Up @@ -734,7 +734,7 @@ Dates.now(::Type{Dates.UTC})
Base.eps(::Union{Type{DateTime}, Type{Date}, Type{Time}, TimeType})
```

### Accessor Functions
#### Accessor Functions

```@docs
Dates.year
Expand Down Expand Up @@ -762,7 +762,7 @@ Dates.monthday
Dates.yearmonthday
```

### Query Functions
#### Query Functions

```@docs
Dates.dayname
Expand All @@ -781,7 +781,7 @@ Dates.quarterofyear
Dates.dayofquarter
```

### Adjuster Functions
#### Adjuster Functions

```@docs
Base.trunc(::Dates.TimeType, ::Type{Dates.Period})
Expand All @@ -801,7 +801,7 @@ Dates.tonext(::Function, ::Dates.TimeType)
Dates.toprev(::Function, ::Dates.TimeType)
```

### Periods
#### Periods

```@docs
Dates.Period(::Any)
Expand All @@ -812,7 +812,7 @@ Dates.default
Dates.periods
```

### Rounding Functions
#### Rounding Functions

`Date` and `DateTime` values can be rounded to a specified resolution (e.g., 1 month or 15 minutes)
with `floor`, `ceil`, or `round`.
Expand Down Expand Up @@ -841,7 +841,7 @@ Dates.date2epochdays
Dates.datetime2epochms
```

### Conversion Functions
#### Conversion Functions

```@docs
Dates.today
Expand Down
12 changes: 6 additions & 6 deletions stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
end
end
"""
Symmetric(A, uplo=:U)
Symmetric(A::AbstractMatrix, uplo::Symbol=:U)

Construct a `Symmetric` view of the upper (if `uplo = :U`) or lower (if `uplo = :L`)
triangle of the matrix `A`.
Expand Down Expand Up @@ -63,7 +63,7 @@ function Symmetric(A::AbstractMatrix, uplo::Symbol=:U)
end

"""
symmetric(A, uplo=:U)
symmetric(A, uplo::Symbol=:U)

Construct a symmetric view of `A`. If `A` is a matrix, `uplo` controls whether the upper
(if `uplo = :U`) or lower (if `uplo = :L`) triangle of `A` is used to implicitly fill the
Expand Down Expand Up @@ -105,7 +105,7 @@ struct Hermitian{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
end
end
"""
Hermitian(A, uplo=:U)
Hermitian(A::AbstractMatrix, uplo::Symbol=:U)

Construct a `Hermitian` view of the upper (if `uplo = :U`) or lower (if `uplo = :L`)
triangle of the matrix `A`.
Expand Down Expand Up @@ -153,7 +153,7 @@ function Hermitian(A::AbstractMatrix, uplo::Symbol=:U)
end

"""
hermitian(A, uplo=:U)
hermitian(A, uplo::Symbol=:U)

Construct a hermitian view of `A`. If `A` is a matrix, `uplo` controls whether the upper
(if `uplo = :U`) or lower (if `uplo = :L`) triangle of `A` is used to implicitly fill the
Expand Down Expand Up @@ -812,7 +812,7 @@ for func in (:log, :sqrt)
end

"""
hermitianpart(A, uplo=:U) -> Hermitian
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian

Return the Hermitian part of the square matrix `A`, defined as `(A + A') / 2`, as a
[`Hermitian`](@ref) matrix. For real matrices `A`, this is also known as the symmetric part
Expand All @@ -828,7 +828,7 @@ See also [`hermitianpart!`](@ref) for the corresponding in-place operation.
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(_hermitianpart(A), uplo)

"""
hermitianpart!(A, uplo=:U) -> Hermitian
hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian

Overwrite the square matrix `A` in-place with its Hermitian part `(A + A') / 2`, and return
[`Hermitian(A, uplo)`](@ref). For real matrices `A`, this is also known as the symmetric
Expand Down
16 changes: 16 additions & 0 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,20 @@ cc46601(::Type{T}, x::Int) where {T<:AbstractString} = 7
@test length(methods(cc46601, Tuple{Type{<:Integer}, Integer})) == 2
@test length(Base.methods_including_ambiguous(cc46601, Tuple{Type{<:Integer}, Integer})) == 7

# Issue #55231
struct U55231{P} end
struct V55231{P} end
U55231(::V55231) = nothing
(::Type{T})(::V55231) where {T<:U55231} = nothing
@test length(methods(U55231)) == 2
U55231(a, b) = nothing
@test length(methods(U55231)) == 3
struct S55231{P} end
struct T55231{P} end
(::Type{T})(::T55231) where {T<:S55231} = nothing
S55231(::T55231) = nothing
@test length(methods(S55231)) == 2
S55231(a, b) = nothing
@test length(methods(S55231)) == 3

nothing
6 changes: 6 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,9 @@ end
@test !iseven(7+0im) && isodd(7+0im)
@test !iseven(6+1im) && !isodd(7+1im)
end

@testset "issue #55266" begin
for T in (Float16, Float32, Float64)
@test isapprox(atanh(1+im*floatmin(T)), Complex{T}(atanh(1+im*big(floatmin(T)))))
end
end
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7542,7 +7542,7 @@ end
# issue #31696
foo31696(x::Int8, y::Int8) = 1
foo31696(x::T, y::T) where {T <: Int8} = 2
@test length(methods(foo31696)) == 1
@test length(methods(foo31696)) == 2
let T1 = Tuple{Int8}, T2 = Tuple{T} where T<:Int8, a = T1[(1,)], b = T2[(1,)]
b .= a
@test b[1] == (1,)
Expand Down
24 changes: 24 additions & 0 deletions test/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,30 @@ end
@test B[argmin(B, dims=[2, 3])] == @inferred(minimum(B, dims=[2, 3]))
end

@testset "careful with @inbounds" begin
Base.@propagate_inbounds f(x) = x == 2 ? x[-10000] : x
Base.@propagate_inbounds op(x,y) = x[-10000] + y[-10000]
for (arr, dims) in (([1,1,2], 1), ([1 1 2], 2), ([ones(Int,256);2], 1))
@test_throws BoundsError mapreduce(f, +, arr)
@test_throws BoundsError mapreduce(f, +, arr; dims)
@test_throws BoundsError mapreduce(f, +, arr; dims, init=0)
@test_throws BoundsError mapreduce(identity, op, arr)
try
#=@test_throws BoundsError=# mapreduce(identity, op, arr; dims)
catch ex
@test_broken ex isa BoundsError
end
@test_throws BoundsError mapreduce(identity, op, arr; dims, init=0)

@test_throws BoundsError findmin(f, arr)
@test_throws BoundsError findmin(f, arr; dims)

@test_throws BoundsError mapreduce(f, max, arr)
@test_throws BoundsError mapreduce(f, max, arr; dims)
@test_throws BoundsError mapreduce(f, max, arr; dims, init=0)
end
end

@testset "in-place reductions with mismatched dimensionalities" begin
B = reshape(1:24, 4, 3, 2)
for R in (fill(0, 4), fill(0, 4, 1), fill(0, 4, 1, 1))
Expand Down