-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathlinalg.jl
265 lines (242 loc) · 4.95 KB
/
linalg.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# This file is a part of Julia. License is MIT: http://julialang.org/license
module LinAlg
import Base: \, /, *, ^, +, -, ==, ./, .*
import Base: A_mul_Bt, At_ldiv_Bt, A_rdiv_Bc, At_ldiv_B, Ac_mul_Bc, A_mul_Bc, Ac_mul_B,
Ac_ldiv_B, Ac_ldiv_Bc, At_mul_Bt, A_rdiv_Bt, At_mul_B
import Base: USE_BLAS64, abs, big, ceil, conj, convert, copy, copy!, copy_transpose!,
ctranspose, ctranspose!, eltype, eye, findmax, findmin, fill!, floor, full, getindex,
imag, inv, isapprox, kron, ndims, parent, power_by_squaring, print_matrix,
promote_rule, real, round, setindex!, show, similar, size, transpose, transpose!,
trunc
using Base: promote_op, MulFun
export
# Modules
LAPACK,
BLAS,
# Types
SymTridiagonal,
Tridiagonal,
Bidiagonal,
Factorization,
BunchKaufman,
Cholesky,
CholeskyPivoted,
Eigen,
GeneralizedEigen,
GeneralizedSVD,
GeneralizedSchur,
Hessenberg,
LU,
LDLt,
QR,
QRPivoted,
LQ,
Schur,
SVD,
Hermitian,
Symmetric,
LowerTriangular,
UpperTriangular,
Diagonal,
UniformScaling,
# Functions
axpy!,
bkfact,
bkfact!,
chol,
cholfact,
cholfact!,
cond,
condskeel,
copy!,
cross,
ctranspose,
det,
diag,
diagind,
diagm,
diff,
dot,
eig,
eigfact,
eigfact!,
eigmax,
eigmin,
eigs,
eigvals,
eigvals!,
eigvecs,
expm,
eye,
factorize,
givens,
gradient,
hessfact,
hessfact!,
isdiag,
ishermitian,
isposdef,
isposdef!,
issymmetric,
istril,
istriu,
kron,
ldltfact!,
ldltfact,
linreg,
logabsdet,
logdet,
logm,
lu,
lufact,
lufact!,
lyap,
norm,
normalize,
normalize!,
nullspace,
ordschur!,
ordschur,
peakflops,
pinv,
qr,
qrfact!,
qrfact,
lq,
lqfact!,
lqfact,
rank,
scale,
scale!,
schur,
schurfact!,
schurfact,
sqrtm,
svd,
svdfact!,
svdfact,
svds,
svdvals!,
svdvals,
sylvester,
trace,
transpose,
tril,
triu,
tril!,
triu!,
vecdot,
vecnorm,
# Operators
\,
/,
A_ldiv_B!,
A_ldiv_Bc,
A_ldiv_Bt,
A_mul_B!,
A_mul_Bc,
A_mul_Bc!,
A_mul_Bt,
A_mul_Bt!,
A_rdiv_Bc,
A_rdiv_Bt,
Ac_ldiv_B,
Ac_ldiv_Bc,
Ac_mul_B,
Ac_mul_B!,
Ac_mul_Bc,
Ac_mul_Bc!,
Ac_rdiv_B,
Ac_rdiv_Bc,
At_ldiv_B,
At_ldiv_Bt,
At_mul_B,
At_mul_B!,
At_mul_Bt,
At_mul_Bt!,
At_rdiv_B,
At_rdiv_Bt,
# Constants
I
typealias BlasFloat Union{Float64,Float32,Complex128,Complex64}
typealias BlasReal Union{Float64,Float32}
typealias BlasComplex Union{Complex128,Complex64}
if USE_BLAS64
typealias BlasInt Int64
else
typealias BlasInt Int32
end
# Check that stride of matrix/vector is 1
function chkstride1(A...)
for a in A
stride(a,1)== 1 || error("matrix does not have contiguous columns")
end
end
"""
LinAlg.checksquare(A)
Check that a matrix is square, then return its common dimension. For multiple arguments, return a vector.
"""
function checksquare(A)
m,n = size(A)
m == n || throw(DimensionMismatch("matrix is not square"))
m
end
function checksquare(A...)
sizes = Int[]
for a in A
size(a,1)==size(a,2) || throw(DimensionMismatch("matrix is not square: dimensions are $(size(a))"))
push!(sizes, size(a,1))
end
return sizes
end
function char_uplo(uplo::Symbol)
if uplo == :U
'U'
elseif uplo == :L
'L'
else
throw(ArgumentError("uplo argument must be either :U (upper) or :L (lower)"))
end
end
copy_oftype{T,N}(A::AbstractArray{T,N}, ::Type{T}) = copy(A)
copy_oftype{T,N,S}(A::AbstractArray{T,N}, ::Type{S}) = convert(AbstractArray{S,N}, A)
include("linalg/exceptions.jl")
include("linalg/generic.jl")
include("linalg/blas.jl")
import .BLAS: gemv! # consider renaming gemv! in matmul
include("linalg/matmul.jl")
include("linalg/lapack.jl")
include("linalg/dense.jl")
include("linalg/tridiag.jl")
include("linalg/triangular.jl")
include("linalg/factorization.jl")
include("linalg/qr.jl")
include("linalg/lq.jl")
include("linalg/eigen.jl")
include("linalg/svd.jl")
include("linalg/schur.jl")
include("linalg/cholesky.jl")
include("linalg/lu.jl")
include("linalg/bunchkaufman.jl")
include("linalg/symmetric.jl")
include("linalg/diagonal.jl")
include("linalg/bidiag.jl")
include("linalg/uniformscaling.jl")
include("linalg/givens.jl")
include("linalg/special.jl")
include("linalg/bitarray.jl")
include("linalg/ldlt.jl")
include("linalg/arpack.jl")
include("linalg/arnoldi.jl")
function __init__()
try
Base.check_blas()
if Base.blas_vendor() == :mkl
ccall((:MKL_Set_Interface_Layer, Base.libblas_name), Void, (Cint,), USE_BLAS64 ? 1 : 0)
end
catch ex
Base.showerror_nostdio(ex,
"WARNING: Error during initialization of module LinAlg")
end
end
end # module LinAlg