@@ -472,14 +472,13 @@ rdiv!(A::AbstractMatrix{T}, transD::Transpose{<:Any,<:Diagonal{T}}) where {T} =
472
472
invoke (\ , Tuple{Union{QR,QRCompactWY,QRPivoted}, AbstractVecOrMat}, A, B)
473
473
474
474
475
- @inline function kron! (C:: AbstractMatrix{T} , A:: Diagonal , B:: Diagonal ) where T
476
- fill! (C, zero (T))
475
+ @inline function kron! (C:: AbstractMatrix , A:: Diagonal , B:: Diagonal )
477
476
valA = A. diag; nA = length (valA)
478
477
valB = B. diag; nB = length (valB)
479
478
nC = checksquare (C)
480
479
@boundscheck nC == nA* nB ||
481
480
throw (DimensionMismatch (" expect C to be a $(nA* nB) x$(nA* nB) matrix, got size $(nC) x$(nC) " ))
482
-
481
+ isempty (A) || isempty (B) || fill! (C, zero (A[ 1 , 1 ] * B[ 1 , 1 ]))
483
482
@inbounds for i = 1 : nA, j = 1 : nB
484
483
idx = (i- 1 )* nB+ j
485
484
C[idx, idx] = valA[i] * valB[j]
497
496
498
497
@inline function kron! (C:: AbstractMatrix , A:: Diagonal , B:: AbstractMatrix )
499
498
Base. require_one_based_indexing (B)
500
- (mA, nA) = size (A); (mB, nB) = size (B); (mC, nC) = size (C);
499
+ (mA, nA) = size (A)
500
+ (mB, nB) = size (B)
501
+ (mC, nC) = size (C)
501
502
@boundscheck (mC, nC) == (mA * mB, nA * nB) ||
502
503
throw (DimensionMismatch (" expect C to be a $(mA * mB) x$(nA * nB) matrix, got size $(mC) x$(nC) " ))
504
+ isempty (A) || isempty (B) || fill! (C, zero (A[1 ,1 ] * B[1 ,1 ]))
503
505
m = 1
504
506
@inbounds for j = 1 : nA
505
507
A_jj = A[j,j]
517
519
518
520
@inline function kron! (C:: AbstractMatrix , A:: AbstractMatrix , B:: Diagonal )
519
521
require_one_based_indexing (A)
520
- (mA, nA) = size (A); (mB, nB) = size (B); (mC, nC) = size (C);
522
+ (mA, nA) = size (A)
523
+ (mB, nB) = size (B)
524
+ (mC, nC) = size (C)
521
525
@boundscheck (mC, nC) == (mA * mB, nA * nB) ||
522
526
throw (DimensionMismatch (" expect C to be a $(mA * mB) x$(nA * nB) matrix, got size $(mC) x$(nC) " ))
527
+ isempty (A) || isempty (B) || fill! (C, zero (A[1 ,1 ] * B[1 ,1 ]))
523
528
m = 1
524
529
@inbounds for j = 1 : nA
525
530
for l = 1 : mB
535
540
return C
536
541
end
537
542
538
- function kron (A:: Diagonal{T} , B:: AbstractMatrix{S} ) where {T<: Number , S<: Number }
539
- (mA, nA) = size (A); (mB, nB) = size (B)
540
- R = zeros (Base. promote_op (* , T, S), mA * mB, nA * nB)
541
- return @inbounds kron! (R, A, B)
542
- end
543
-
544
- function kron (A:: AbstractMatrix{T} , B:: Diagonal{S} ) where {T<: Number , S<: Number }
545
- (mA, nA) = size (A); (mB, nB) = size (B)
546
- R = zeros (promote_op (* , T, S), mA * mB, nA * nB)
547
- return @inbounds kron! (R, A, B)
548
- end
549
-
550
543
conj (D:: Diagonal ) = Diagonal (conj (D. diag))
551
544
transpose (D:: Diagonal{<:Number} ) = D
552
545
transpose (D:: Diagonal ) = Diagonal (transpose .(D. diag))
0 commit comments