Skip to content

Commit

Permalink
Base.LinAlg to new LinearAlgebra stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jan 17, 2018
1 parent 3d84bbb commit 8b73a98
Show file tree
Hide file tree
Showing 126 changed files with 2,515 additions and 2,429 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,9 @@ Deprecated or removed

* Sparse array functionality has moved to the `SparseArrays` standard library module ([#25249]).

* Linear algebra functionality, and specifically the `LinAlg` module has moved to the
`LinearAlgebra` standard library module ([#25571]).

* `@printf` and `@sprintf` have been moved to the `Printf` standard library ([#23929],[#25056]).

* The aliases `Complex32`, `Complex64` and `Complex128` have been deprecated in favor of `ComplexF16`,
Expand Down
7 changes: 6 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,12 @@ end
function _one(unit::T, x::AbstractMatrix) where T
m,n = size(x)
m==n || throw(DimensionMismatch("multiplicative identity defined only for square matrices"))
Matrix{T}(I, m, m)
# Matrix{T}(I, m, m)
I = zeros(T, m, m)
for i in 1:m
I[i,i] = 1
end
I
end

one(x::AbstractMatrix{T}) where {T} = _one(one(T), x)
Expand Down
1,525 changes: 147 additions & 1,378 deletions base/deprecated.jl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ julia> sizeof(ComplexF64)
If `T` does not have a specific size, an error is thrown.
```jldoctest
julia> sizeof(Base.LinAlg.LU)
julia> sizeof(Base.SubArray)
ERROR: argument is an abstract type; size is indeterminate
Stacktrace:
[...]
Expand Down
98 changes: 1 addition & 97 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export
StackTraces,
Sys,
Libc,
LinAlg,
BLAS,
LAPACK,
Serializer,
Docs,
Markdown,
Expand All @@ -29,7 +26,6 @@ export
AbstractVecOrMat,
Array,
AbstractDict,
Bidiagonal,
BigFloat,
BigInt,
BitArray,
Expand All @@ -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,
Expand All @@ -70,7 +60,6 @@ export
IOBuffer,
IOStream,
LinSpace,
LowerTriangular,
Irrational,
Matrix,
MergeSort,
Expand All @@ -94,8 +83,6 @@ export
RoundNearestTiesUp,
RoundToZero,
RoundUp,
Adjoint,
Transpose,
AbstractSerializer,
SerializationState,
Set,
Expand All @@ -108,12 +95,8 @@ export
StridedVector,
SubArray,
SubString,
Symmetric,
SymTridiagonal,
Timer,
Tridiagonal,
UnitRange,
UpperTriangular,
Val,
VecOrMat,
Vector,
Expand Down Expand Up @@ -178,7 +161,6 @@ export
im,
π, pi,
ℯ,
I,

# Operators
!,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ function versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
println(io)
end
println(io, " WORD_SIZE: ", Sys.WORD_SIZE)
if Base.libblas_name == "libopenblas" || BLAS.vendor() == :openblas || BLAS.vendor() == :openblas64
openblas_config = BLAS.openblas_get_config()
println(io, " BLAS: libopenblas (", openblas_config, ")")
else
println(io, " BLAS: ",libblas_name)
end
println(io, " LAPACK: ",liblapack_name)
# if Base.libblas_name == "libopenblas" || BLAS.vendor() == :openblas || BLAS.vendor() == :openblas64
# openblas_config = BLAS.openblas_get_config()
# println(io, " BLAS: libopenblas (", openblas_config, ")")
# else
# println(io, " BLAS: ",libblas_name)
# end
# println(io, " LAPACK: ",liblapack_name)
println(io, " LIBM: ",libm_name)
println(io, " LLVM: libLLVM-",libllvm_version," (", Sys.JIT, ", ", Sys.CPU_NAME, ")")

Expand Down
2 changes: 1 addition & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

"""
atan2(y, x)
Expand Down
2 changes: 1 addition & 1 deletion base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ precompile(Tuple{typeof(Base.join), Base.GenericIOBuffer{Array{UInt8, 1}}, Tuple
precompile(Tuple{typeof(Base.setindex!), Base.Dict{Int64, Nothing}, Nothing, Int64})
precompile(Tuple{Type{Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}}, Tuple{Int64}})
precompile(Tuple{typeof(Base.eachindex), Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}})
precompile(Tuple{typeof(Base.LinAlg.BLAS.set_num_threads), Int64})
# precompile(Tuple{typeof(Base.LinearAlgebra.BLAS.set_num_threads), Int64})
precompile(Tuple{typeof(Base.eltype), Type{Base.Union{IO, Nothing}}})
precompile(Tuple{Type{Base.Union{IO, Nothing}}})
precompile(Tuple{typeof(Base.eltype), Type{Base.Union{AbstractString, Nothing}}})
Expand Down
8 changes: 4 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Get the name of a `Module` as a `Symbol`.
# Examples
```jldoctest
julia> module_name(Base.LinAlg)
:LinAlg
julia> module_name(Base.Broadcast)
:Broadcast
```
"""
module_name(m::Module) = ccall(:jl_module_name, Ref{Symbol}, (Any,), m)
Expand All @@ -25,8 +25,8 @@ Get a module's enclosing `Module`. `Main` is its own parent.
julia> module_parent(Main)
Main
julia> module_parent(Base.LinAlg.BLAS)
Base.LinAlg
julia> module_parent(Base.Broadcast)
Base
```
"""
module_parent(m::Module) = ccall(:jl_module_parent, Ref{Module}, (Any,), m)
Expand Down
20 changes: 14 additions & 6 deletions base/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
return R
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
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) =
Expand All @@ -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)
Expand Down Expand Up @@ -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)...)))
end
corzm(x::AbstractVector, y::AbstractMatrix, vardim::Int=1) =
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sum(abs2, x)), sqrt!(sum(abs2, y, vardim)))
Expand Down
12 changes: 5 additions & 7 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,6 @@ import Base64

INCLUDE_STATE = 2

# dense linear algebra
include("linalg/linalg.jl")
using .LinAlg
const = dot
const × = cross

include("asyncmap.jl")

include("multimedia.jl")
Expand Down Expand Up @@ -520,6 +514,7 @@ Base.require(:FileWatching)
Base.require(:Future)
Base.require(:IterativeEigensolvers)
Base.require(:Libdl)
Base.require(:LinearAlgebra)
Base.require(:Logging)
Base.require(:Mmap)
Base.require(:Printf)
Expand Down Expand Up @@ -551,10 +546,13 @@ Base.require(:Unicode)
", run `using SparseArrays` to load sparse array functionality")
@deprecate_binding(SparseVector, root_module(:SparseArrays).SparseVector, true,
", run `using SparseArrays` to load sparse array functionality")

# PR #25571
@deprecate_binding LinAlg root_module(:LinearAlgebra) true ", run `using LinearAlgebra` instead"
end

empty!(LOAD_PATH)

Base.isfile("userimg.jl") && Base.include(Main, "userimg.jl")

Base.include(Base, "precompile.jl")
# Base.include(Base, "precompile.jl")
6 changes: 3 additions & 3 deletions doc/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Compat 0.39.0 0.39.0+
DocStringExtensions 0.4.1 0.4.1+
Documenter 0.12.4 0.12.4+
Compat
DocStringExtensions
Documenter
6 changes: 4 additions & 2 deletions doc/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Pkg.init()
cp(joinpath(@__DIR__, "REQUIRE"), Pkg.dir("REQUIRE"); remove_destination = true)
Pkg.update()
Pkg.resolve()
Pkg.checkout("Documenter")
# Pkg.checkout("Documenter", "fe/deprecations") # can't push my branch to JuliaDocs...
Pkg.checkout("Compat")
Pkg.checkout("Compat", "fe/linalg") # to make Compat load

using Documenter

Expand Down Expand Up @@ -68,7 +72,6 @@ const PAGES = [
"manual/documentation.md",
"manual/metaprogramming.md",
"manual/arrays.md",
"manual/linear-algebra.md",
"manual/missing.md",
"manual/networking-and-streams.md",
"manual/parallel-computing.md",
Expand Down Expand Up @@ -98,7 +101,6 @@ const PAGES = [
"base/arrays.md",
"base/parallel.md",
"base/multi-threading.md",
"base/linalg.md",
"base/constants.md",
"base/file.md",
"base/io-network.md",
Expand Down
Loading

0 comments on commit 8b73a98

Please sign in to comment.