|
| 1 | +using MatrixAlgebraKit: |
| 2 | + MatrixAlgebraKit, |
| 3 | + left_orth!, |
| 4 | + left_polar!, |
| 5 | + lq_compact!, |
| 6 | + qr_compact!, |
| 7 | + right_orth!, |
| 8 | + right_polar!, |
| 9 | + select_algorithm, |
| 10 | + svd_compact! |
| 11 | + |
| 12 | +function MatrixAlgebraKit.initialize_output( |
| 13 | + ::typeof(left_orth!), A::AbstractBlockSparseMatrix |
| 14 | +) |
| 15 | + return nothing |
| 16 | +end |
| 17 | +function MatrixAlgebraKit.check_input(::typeof(left_orth!), A::AbstractBlockSparseMatrix, F) |
| 18 | + !isnothing(F) && throw( |
| 19 | + ArgumentError( |
| 20 | + "`left_orth!` on block sparse matrices does not support specifying the output" |
| 21 | + ), |
| 22 | + ) |
| 23 | + return nothing |
| 24 | +end |
| 25 | + |
| 26 | +function MatrixAlgebraKit.left_orth_qr!(A::AbstractBlockSparseMatrix, F, alg) |
| 27 | + !isnothing(F) && throw( |
| 28 | + ArgumentError( |
| 29 | + "`left_orth!` on block sparse matrices does not support specifying the output" |
| 30 | + ), |
| 31 | + ) |
| 32 | + alg′ = select_algorithm(qr_compact!, A, alg) |
| 33 | + return qr_compact!(A, alg′) |
| 34 | +end |
| 35 | +function MatrixAlgebraKit.left_orth_polar!(A::AbstractBlockSparseMatrix, F, alg) |
| 36 | + !isnothing(F) && throw( |
| 37 | + ArgumentError( |
| 38 | + "`left_orth!` on block sparse matrices does not support specifying the output" |
| 39 | + ), |
| 40 | + ) |
| 41 | + alg′ = select_algorithm(left_polar!, A, alg) |
| 42 | + return left_polar!(A, alg′) |
| 43 | +end |
| 44 | +function MatrixAlgebraKit.left_orth_svd!( |
| 45 | + A::AbstractBlockSparseMatrix, F, alg, trunc::Nothing=nothing |
| 46 | +) |
| 47 | + !isnothing(F) && throw( |
| 48 | + ArgumentError( |
| 49 | + "`left_orth!` on block sparse matrices does not support specifying the output" |
| 50 | + ), |
| 51 | + ) |
| 52 | + alg′ = select_algorithm(svd_compact!, A, alg) |
| 53 | + U, S, Vᴴ = svd_compact!(A, alg′) |
| 54 | + return U, S * Vᴴ |
| 55 | +end |
| 56 | +function MatrixAlgebraKit.left_orth_svd!(A::AbstractBlockSparseMatrix, F, alg, trunc) |
| 57 | + !isnothing(F) && throw( |
| 58 | + ArgumentError( |
| 59 | + "`left_orth!` on block sparse matrices does not support specifying the output" |
| 60 | + ), |
| 61 | + ) |
| 62 | + alg′ = select_algorithm(svd_compact!, A, alg) |
| 63 | + alg_trunc = select_algorithm(svd_trunc!, A, alg′; trunc) |
| 64 | + U, S, Vᴴ = svd_trunc!(A, alg_trunc) |
| 65 | + return U, S * Vᴴ |
| 66 | +end |
| 67 | + |
| 68 | +function MatrixAlgebraKit.initialize_output( |
| 69 | + ::typeof(right_orth!), A::AbstractBlockSparseMatrix |
| 70 | +) |
| 71 | + return nothing |
| 72 | +end |
| 73 | +function MatrixAlgebraKit.check_input( |
| 74 | + ::typeof(right_orth!), A::AbstractBlockSparseMatrix, F::Nothing |
| 75 | +) |
| 76 | + !isnothing(F) && throw( |
| 77 | + ArgumentError( |
| 78 | + "`right_orth!` on block sparse matrices does not support specifying the output" |
| 79 | + ), |
| 80 | + ) |
| 81 | + return nothing |
| 82 | +end |
| 83 | + |
| 84 | +function MatrixAlgebraKit.right_orth_lq!(A::AbstractBlockSparseMatrix, F, alg) |
| 85 | + !isnothing(F) && throw( |
| 86 | + ArgumentError( |
| 87 | + "`right_orth!` on block sparse matrices does not support specifying the output" |
| 88 | + ), |
| 89 | + ) |
| 90 | + alg′ = select_algorithm(lq_compact!, A, alg) |
| 91 | + return lq_compact!(A, alg′) |
| 92 | +end |
| 93 | +function MatrixAlgebraKit.right_orth_polar!(A::AbstractBlockSparseMatrix, F, alg) |
| 94 | + !isnothing(F) && throw( |
| 95 | + ArgumentError( |
| 96 | + "`right_orth!` on block sparse matrices does not support specifying the output" |
| 97 | + ), |
| 98 | + ) |
| 99 | + alg′ = select_algorithm(right_polar!, A, alg) |
| 100 | + return right_polar!(A, alg′) |
| 101 | +end |
| 102 | +function MatrixAlgebraKit.right_orth_svd!( |
| 103 | + A::AbstractBlockSparseMatrix, F, alg, trunc::Nothing=nothing |
| 104 | +) |
| 105 | + !isnothing(F) && throw( |
| 106 | + ArgumentError( |
| 107 | + "`right_orth!` on block sparse matrices does not support specifying the output" |
| 108 | + ), |
| 109 | + ) |
| 110 | + alg′ = select_algorithm(svd_compact!, A, alg) |
| 111 | + U, S, Vᴴ = svd_compact!(A, alg′) |
| 112 | + return U * S, Vᴴ |
| 113 | +end |
| 114 | +function MatrixAlgebraKit.right_orth_svd!(A::AbstractBlockSparseMatrix, F, alg, trunc) |
| 115 | + !isnothing(F) && throw( |
| 116 | + ArgumentError( |
| 117 | + "`right_orth!` on block sparse matrices does not support specifying the output" |
| 118 | + ), |
| 119 | + ) |
| 120 | + alg′ = select_algorithm(svd_compact!, A, alg) |
| 121 | + alg_trunc = select_algorithm(svd_trunc!, A, alg′; trunc) |
| 122 | + U, S, Vᴴ = svd_trunc!(A, alg_trunc) |
| 123 | + return U * S, Vᴴ |
| 124 | +end |
0 commit comments