-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Base.LinAlg to LinearAlgebra stdlib #25571
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,6 @@ export | |
StackTraces, | ||
Sys, | ||
Libc, | ||
LinAlg, | ||
BLAS, | ||
LAPACK, | ||
Serializer, | ||
Docs, | ||
Markdown, | ||
|
@@ -29,7 +26,6 @@ export | |
AbstractVecOrMat, | ||
Array, | ||
AbstractDict, | ||
Bidiagonal, | ||
BigFloat, | ||
BigInt, | ||
BitArray, | ||
|
@@ -46,22 +42,16 @@ export | |
ComplexF64, | ||
ComplexF32, | ||
ComplexF16, | ||
ConjVector, | ||
ConjMatrix, | ||
DenseMatrix, | ||
DenseVecOrMat, | ||
DenseVector, | ||
DevNull, | ||
Diagonal, | ||
Dict, | ||
Dims, | ||
EachLine, | ||
Enum, | ||
Enumerate, | ||
ExponentialBackOff, | ||
Factorization, | ||
Hermitian, | ||
UniformScaling, | ||
IndexCartesian, | ||
IndexLinear, | ||
IndexStyle, | ||
|
@@ -70,7 +60,6 @@ export | |
IOBuffer, | ||
IOStream, | ||
LinSpace, | ||
LowerTriangular, | ||
Irrational, | ||
Matrix, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we want to define these aliases in |
||
MergeSort, | ||
|
@@ -94,8 +83,6 @@ export | |
RoundNearestTiesUp, | ||
RoundToZero, | ||
RoundUp, | ||
Adjoint, | ||
Transpose, | ||
AbstractSerializer, | ||
SerializationState, | ||
Set, | ||
|
@@ -108,12 +95,8 @@ export | |
StridedVector, | ||
SubArray, | ||
SubString, | ||
Symmetric, | ||
SymTridiagonal, | ||
Timer, | ||
Tridiagonal, | ||
UnitRange, | ||
UpperTriangular, | ||
Val, | ||
VecOrMat, | ||
Vector, | ||
|
@@ -178,7 +161,6 @@ export | |
im, | ||
π, pi, | ||
ℯ, | ||
I, | ||
|
||
# Operators | ||
!, | ||
|
@@ -501,87 +483,9 @@ export | |
startswith, | ||
|
||
# linear algebra | ||
bkfact!, | ||
bkfact, | ||
chol, | ||
cholfact!, | ||
cholfact, | ||
cond, | ||
condskeel, | ||
cross, | ||
adjoint!, | ||
adjoint, | ||
det, | ||
diag, | ||
diagind, | ||
diagm, | ||
diff, | ||
dot, | ||
eig, | ||
eigfact!, | ||
eigfact, | ||
eigmax, | ||
eigmin, | ||
eigvals, | ||
eigvals!, | ||
eigvecs, | ||
factorize, | ||
givens, | ||
hessfact!, | ||
hessfact, | ||
isdiag, | ||
ishermitian, | ||
isposdef!, | ||
isposdef, | ||
issymmetric, | ||
istril, | ||
istriu, | ||
kron, | ||
ldltfact, | ||
ldltfact!, | ||
linreg, | ||
logabsdet, | ||
logdet, | ||
lu, | ||
lufact!, | ||
lufact, | ||
lyap, | ||
norm, | ||
normalize, | ||
normalize!, | ||
nullspace, | ||
ordschur!, | ||
ordschur, | ||
peakflops, | ||
pinv, | ||
qr, | ||
qrfact!, | ||
qrfact, | ||
lq, | ||
lqfact!, | ||
lqfact, | ||
rank, | ||
scale!, | ||
schur, | ||
schurfact!, | ||
schurfact, | ||
svd, | ||
svdfact!, | ||
svdfact, | ||
svdvals!, | ||
svdvals, | ||
sylvester, | ||
trace, | ||
transpose!, | ||
transpose, | ||
tril!, | ||
tril, | ||
triu!, | ||
triu, | ||
vecdot, | ||
vecnorm, | ||
⋅, | ||
×, | ||
kron, | ||
|
||
# bitarrays | ||
falses, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,7 +506,7 @@ end | |
|
||
Compute the hypotenuse ``\\sqrt{\\sum x_i^2}`` avoiding overflow and underflow. | ||
""" | ||
hypot(x::Number...) = vecnorm(x) | ||
hypot(x::Number...) = sqrt(sum(abs2(y) for y in x)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of two places which uses a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should consider deprecating this function or just move it since the raison d'être of |
||
|
||
""" | ||
atan2(y, x) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,8 @@ julia> mean!([1. 1.], v) | |
""" | ||
function mean!(R::AbstractArray, A::AbstractArray) | ||
sum!(R, A; init=true) | ||
scale!(R, max(1, _length(R)) // _length(A)) | ||
x = max(1, _length(R)) // _length(A) | ||
R .= R .* x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this could |
||
return R | ||
end | ||
|
||
|
@@ -175,7 +176,8 @@ function varm!(R::AbstractArray{S}, A::AbstractArray, m::AbstractArray; correcte | |
fill!(R, convert(S, NaN)) | ||
else | ||
rn = div(_length(A), _length(R)) - Int(corrected) | ||
scale!(centralize_sumabs2!(R, A, m), 1//rn) | ||
centralize_sumabs2!(R, A, m) | ||
R .= R .* (1 // rn) | ||
end | ||
return R | ||
end | ||
|
@@ -328,7 +330,7 @@ unscaled_covzm(x::AbstractVector{<:Number}) = sum(abs2, x) | |
unscaled_covzm(x::AbstractVector) = sum(t -> t*t', x) | ||
unscaled_covzm(x::AbstractMatrix, vardim::Int) = (vardim == 1 ? _conj(x'x) : x * x') | ||
|
||
unscaled_covzm(x::AbstractVector, y::AbstractVector) = dot(y, x) | ||
unscaled_covzm(x::AbstractVector, y::AbstractVector) = sum(conj(y[i])*x[i] for i in eachindex(y, x)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second place where a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not equivalent for all element types. Should we move statistics to stdlib first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This indeed turned out to be a problem in some cases. See https://github.com/JuliaLang/Statistics.jl/pull/85. |
||
unscaled_covzm(x::AbstractVector, y::AbstractMatrix, vardim::Int) = | ||
(vardim == 1 ? *(transpose(x), _conj(y)) : *(transpose(x), transpose(_conj(y)))) | ||
unscaled_covzm(x::AbstractMatrix, y::AbstractVector, vardim::Int) = | ||
|
@@ -342,14 +344,20 @@ covzm(x::AbstractVector; corrected::Bool=true) = unscaled_covzm(x) / (_length(x) | |
function covzm(x::AbstractMatrix, vardim::Int=1; corrected::Bool=true) | ||
C = unscaled_covzm(x, vardim) | ||
T = promote_type(typeof(first(C) / 1), eltype(C)) | ||
return scale!(convert(AbstractMatrix{T}, C), 1//(size(x, vardim) - corrected)) | ||
A = convert(AbstractMatrix{T}, C) | ||
b = 1//(size(x, vardim) - corrected) | ||
A .= A .* b | ||
return A | ||
end | ||
covzm(x::AbstractVector, y::AbstractVector; corrected::Bool=true) = | ||
unscaled_covzm(x, y) / (_length(x) - Int(corrected)) | ||
function covzm(x::AbstractVecOrMat, y::AbstractVecOrMat, vardim::Int=1; corrected::Bool=true) | ||
C = unscaled_covzm(x, y, vardim) | ||
T = promote_type(typeof(first(C) / 1), eltype(C)) | ||
return scale!(convert(AbstractArray{T}, C), 1//(_getnobs(x, y, vardim) - corrected)) | ||
A = convert(AbstractArray{T}, C) | ||
b = 1//(_getnobs(x, y, vardim) - corrected) | ||
A .= A .* b | ||
return A | ||
end | ||
|
||
# covm (with provided mean) | ||
|
@@ -467,7 +475,7 @@ end | |
corzm(x::AbstractVector{T}) where {T} = one(real(T)) | ||
function corzm(x::AbstractMatrix, vardim::Int=1) | ||
c = unscaled_covzm(x, vardim) | ||
return cov2cor!(c, sqrt!(diag(c))) | ||
return cov2cor!(c, collect(sqrt(c[i,i]) for i in 1:min(size(c)...))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that work for a generator? I get: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, not implemented yet :). |
||
end | ||
corzm(x::AbstractVector, y::AbstractMatrix, vardim::Int=1) = | ||
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sum(abs2, x)), sqrt!(sum(abs2, y, vardim))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should probably be moved too, but can stay for now.