@@ -40,22 +40,8 @@ julia> ArrayInterface.map_tuple_type(sqrt, Tuple{1,4,16})
4040```
4141"""
4242function map_tuple_type end
43- if VERSION >= v " 1.8"
44- @inline function map_tuple_type (f, @nospecialize (T:: Type ))
45- ntuple (i -> f (fieldtype (T, i)), Val {fieldcount(T)} ())
46- end
47- else
48- function map_tuple_type (f:: F , :: Type{T} ) where {F, T <: Tuple }
49- if @generated
50- t = Expr (:tuple )
51- for i in 1 : fieldcount (T)
52- push! (t. args, :(f ($ (fieldtype (T, i)))))
53- end
54- Expr (:block , Expr (:meta , :inline ), t)
55- else
56- Tuple (f (fieldtype (T, i)) for i in 1 : fieldcount (T))
57- end
58- end
43+ @inline function map_tuple_type (f, @nospecialize (T:: Type ))
44+ ntuple (i -> f (fieldtype (T, i)), Val {fieldcount(T)} ())
5945end
6046
6147"""
@@ -78,50 +64,22 @@ julia> ArrayInterface.flatten_tuples((1, (2, (3,))))
7864```
7965"""
8066function flatten_tuples end
81- if VERSION >= v " 1.8"
82- function flatten_tuples (t:: Tuple )
83- fields = _new_field_positions (t)
84- ntuple (Val {nfields(fields)} ()) do k
85- i, j = getfield (fields, k)
86- i = length (t) - i
87- @inbounds j === 0 ? getfield (t, i) : getfield (getfield (t, i), j)
88- end
89- end
90- _new_field_positions (:: Tuple{} ) = ()
91- @nospecialize
92- function _new_field_positions (x:: Tuple )
93- (_fl1 (x, x[1 ])... , _new_field_positions (Base. tail (x))... )
94- end
95- _fl1 (x:: Tuple , x1:: Tuple ) = ntuple (Base. Fix1 (tuple, length (x) - 1 ), Val (length (x1)))
96- _fl1 (x:: Tuple , x1) = ((length (x) - 1 , 0 ),)
97- @specialize
98- else
99- @inline function flatten_tuples (t:: Tuple )
100- if @generated
101- texpr = Expr (:tuple )
102- for i in 1 : fieldcount (t)
103- p = fieldtype (t, i)
104- if p <: Tuple
105- for j in 1 : fieldcount (p)
106- push! (texpr. args, :(@inbounds (getfield (getfield (t, $ i), $ j))))
107- end
108- else
109- push! (texpr. args, :(@inbounds (getfield (t, $ i))))
110- end
111- end
112- Expr (:block , Expr (:meta , :inline ), texpr)
113- else
114- _flatten (t)
115- end
116- end
117- _flatten (:: Tuple{} ) = ()
118- @inline function _flatten (t:: Tuple{Any, Vararg{Any}} )
119- (getfield (t, 1 ), _flatten (Base. tail (t))... )
120- end
121- @inline function _flatten (t:: Tuple{Tuple, Vararg{Any}} )
122- (getfield (t, 1 )... , _flatten (Base. tail (t))... )
67+ function flatten_tuples (t:: Tuple )
68+ fields = _new_field_positions (t)
69+ ntuple (Val {nfields(fields)} ()) do k
70+ i, j = getfield (fields, k)
71+ i = length (t) - i
72+ @inbounds j === 0 ? getfield (t, i) : getfield (getfield (t, i), j)
12373 end
12474end
75+ _new_field_positions (:: Tuple{} ) = ()
76+ @nospecialize
77+ function _new_field_positions (x:: Tuple )
78+ (_fl1 (x, x[1 ])... , _new_field_positions (Base. tail (x))... )
79+ end
80+ _fl1 (x:: Tuple , x1:: Tuple ) = ntuple (Base. Fix1 (tuple, length (x) - 1 ), Val (length (x1)))
81+ _fl1 (x:: Tuple , x1) = ((length (x) - 1 , 0 ),)
82+ @specialize
12583
12684"""
12785 parent_type(::Type{T}) -> Type
@@ -299,11 +257,7 @@ ismutable(::Type{BigFloat}) = false
299257ismutable (:: Type{BigInt} ) = false
300258function ismutable (:: Type{T} ) where {T}
301259 if parent_type (T) <: T
302- @static if VERSION ≥ v " 1.7.0-DEV.1208"
303- return Base. ismutabletype (T)
304- else
305- return T. mutable
306- end
260+ return Base. ismutabletype (T)
307261 else
308262 return ismutable (parent_type (T))
309263 end
@@ -440,32 +394,17 @@ matrix_colors(A::Bidiagonal) = _cycle(1:2, Base.size(A, 2))
440394matrix_colors (A:: Union{Tridiagonal, SymTridiagonal} ) = _cycle (1 : 3 , Base. size (A, 2 ))
441395_cycle (repetend, len) = repeat (repetend, div (len, length (repetend)) + 1 )[1 : len]
442396
443- @static if VERSION > v " 1.9-"
444- """
445- bunchkaufman_instance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufman_factorization_instance
397+ """
398+ bunchkaufman_instance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufman_factorization_instance
446399
447- Returns an instance of the Bunch-Kaufman factorization object with the correct type
448- cheaply.
449- """
450- function bunchkaufman_instance (A:: Matrix{T} ) where T
451- return bunchkaufman (similar (A, 0 , 0 ), check = false )
452- end
453- function bunchkaufman_instance (A:: SparseMatrixCSC )
454- bunchkaufman (sparse (similar (A, 1 , 1 )), check = false )
455- end
456- else
457- """
458- bunchkaufman_instance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufman_factorization_instance
459-
460- Returns an instance of the Bunch-Kaufman factorization object with the correct type
461- cheaply.
462- """
463- function bunchkaufman_instance (A:: Matrix{T} ) where T
464- return bunchkaufman (similar (A, 0 , 0 ))
465- end
466- function bunchkaufman_instance (A:: SparseMatrixCSC )
467- bunchkaufman (sparse (similar (A, 1 , 1 )))
468- end
400+ Returns an instance of the Bunch-Kaufman factorization object with the correct type
401+ cheaply.
402+ """
403+ function bunchkaufman_instance (A:: Matrix{T} ) where T
404+ return bunchkaufman (similar (A, 0 , 0 ), check = false )
405+ end
406+ function bunchkaufman_instance (A:: SparseMatrixCSC )
407+ bunchkaufman (sparse (similar (A, 1 , 1 )), check = false )
469408end
470409
471410"""
@@ -482,32 +421,16 @@ Returns the number.
482421"""
483422bunchkaufman_instance (a:: Any ) = bunchkaufman (a, check = false )
484423
485- @static if VERSION < v " 1.8beta"
486- const DEFAULT_CHOLESKY_PIVOT = Val (false )
487- else
488- const DEFAULT_CHOLESKY_PIVOT = LinearAlgebra. NoPivot ()
489- end
424+ const DEFAULT_CHOLESKY_PIVOT = Val (false )
490425
491- @static if VERSION > v " 1.9-"
492- """
493- cholesky_instance(A, pivot = LinearAlgebra.RowMaximum()) -> cholesky_factorization_instance
426+ """
427+ cholesky_instance(A, pivot = LinearAlgebra.RowMaximum()) -> cholesky_factorization_instance
494428
495- Returns an instance of the Cholesky factorization object with the correct type
496- cheaply.
497- """
498- function cholesky_instance (A:: Matrix{T} , pivot = DEFAULT_CHOLESKY_PIVOT) where {T}
499- return cholesky (similar (A, 0 , 0 ), pivot, check = false )
500- end
501- else
502- """
503- cholesky_instance(A, pivot = LinearAlgebra.RowMaximum()) -> cholesky_factorization_instance
504-
505- Returns an instance of the Cholesky factorization object with the correct type
506- cheaply.
507- """
508- function cholesky_instance (A:: Matrix{T} , pivot = DEFAULT_CHOLESKY_PIVOT) where {T}
509- return cholesky (similar (A, 0 , 0 ), pivot)
510- end
429+ Returns an instance of the Cholesky factorization object with the correct type
430+ cheaply.
431+ """
432+ function cholesky_instance (A:: Matrix{T} , pivot = DEFAULT_CHOLESKY_PIVOT) where {T}
433+ return cholesky (similar (A, 0 , 0 ), pivot, check = false )
511434end
512435
513436function cholesky_instance (A:: Union{SparseMatrixCSC,Symmetric{<:Number,<:SparseMatrixCSC}} , pivot = DEFAULT_CHOLESKY_PIVOT)
@@ -521,23 +444,13 @@ Returns the number.
521444"""
522445cholesky_instance (a:: Number , pivot = DEFAULT_CHOLESKY_PIVOT) = a
523446
524- @static if VERSION > v " 1.9-"
525- """
526- cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) -> cholesky(a, check=false)
527-
528- Slow fallback which gets the instance via factorization. Should get
529- specialized for new matrix types.
530- """
531- cholesky_instance (a:: Any , pivot = DEFAULT_CHOLESKY_PIVOT) = cholesky (a, pivot, check = false )
532- else
533- """
534- cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) -> cholesky(a, check=false)
535-
536- Slow fallback which gets the instance via factorization. Should get
537- specialized for new matrix types.
538- """
539- cholesky_instance (a:: Any , pivot = DEFAULT_CHOLESKY_PIVOT) = cholesky (a, pivot)
540- end
447+ """
448+ cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) -> cholesky(a, check=false)
449+
450+ Slow fallback which gets the instance via factorization. Should get
451+ specialized for new matrix types.
452+ """
453+ cholesky_instance (a:: Any , pivot = DEFAULT_CHOLESKY_PIVOT) = cholesky (a, pivot, check = false )
541454
542455"""
543456ldlt_instance(A) -> ldlt_factorization_instance
@@ -586,18 +499,29 @@ function lu_instance(A::Matrix{T}) where {T}
586499 return LU {luT} (similar (A, 0 , 0 ), ipiv, info)
587500end
588501function lu_instance (jac_prototype:: SparseMatrixCSC )
589- @static if VERSION < v " 1.9.0-DEV.1622"
590- SuiteSparse. UMFPACK. UmfpackLU (Ptr {Cvoid} (),
591- Ptr {Cvoid} (),
592- 1 ,
593- 1 ,
594- jac_prototype. colptr[1 : 1 ],
595- jac_prototype. rowval[1 : 1 ],
596- jac_prototype. nzval[1 : 1 ],
597- 0 )
598- else
599- SuiteSparse. UMFPACK. UmfpackLU (similar (jac_prototype, 1 , 1 ))
600- end
502+ SuiteSparse. UMFPACK. UmfpackLU (similar (jac_prototype, 1 , 1 ))
503+ end
504+
505+ function lu_instance (A:: Symmetric{T} ) where {T}
506+ noUnitT = typeof (zero (T))
507+ luT = LinearAlgebra. lutype (noUnitT)
508+ ipiv = Vector {LinearAlgebra.BlasInt} (undef, 0 )
509+ info = zero (LinearAlgebra. BlasInt)
510+ return LU {luT} (similar (A, 0 , 0 ), ipiv, info)
511+ end
512+
513+ noalloc_diag (A:: Diagonal ) = A. diag
514+ noalloc_diag (A:: Tridiagonal ) = A. d
515+ noalloc_diag (A:: SymTridiagonal ) = A. dv
516+
517+ function lu_instance (A:: Union{Tridiagonal{T},Diagonal{T},SymTridiagonal{T}} ) where {T}
518+ noUnitT = typeof (zero (T))
519+ luT = LinearAlgebra. lutype (noUnitT)
520+ ipiv = Vector {LinearAlgebra.BlasInt} (undef, 0 )
521+ info = zero (LinearAlgebra. BlasInt)
522+ vectype = similar (noalloc_diag (A), 0 )
523+ newA = Tridiagonal (vectype, vectype, vectype)
524+ return LU {luT} (newA, ipiv, info)
601525end
602526
603527"""
@@ -607,23 +531,13 @@ Returns the number.
607531"""
608532lu_instance (a:: Number ) = a
609533
610- @static if VERSION > v " 1.9-"
611- """
612- lu_instance(a::Any) -> lu(a, check=false)
613-
614- Slow fallback which gets the instance via factorization. Should get
615- specialized for new matrix types.
616- """
617- lu_instance (a:: Any ) = lu (a, check = false )
618- else
619- """
534+ """
620535 lu_instance(a::Any) -> lu(a, check=false)
621536
622- Slow fallback which gets the instance via factorization. Should get
623- specialized for new matrix types.
624- """
625- lu_instance (a:: Any ) = lu (a)
626- end
537+ Slow fallback which gets the instance via factorization. Should get
538+ specialized for new matrix types.
539+ """
540+ lu_instance (a:: Any ) = lu (a, check = false )
627541
628542"""
629543 qr_instance(A, pivot = NoPivot()) -> qr_factorization_instance
0 commit comments