@@ -500,14 +500,13 @@ rdiv!(A::AbstractMatrix{T}, transD::Transpose{<:Any,<:Diagonal{T}}) where {T} =
500
500
invoke (\ , Tuple{Union{QR,QRCompactWY,QRPivoted}, AbstractVecOrMat}, A, B)
501
501
502
502
503
- @inline function kron! (C:: AbstractMatrix{T} , A:: Diagonal , B:: Diagonal ) where T
504
- fill! (C, zero (T))
503
+ @inline function kron! (C:: AbstractMatrix , A:: Diagonal , B:: Diagonal )
505
504
valA = A. diag; nA = length (valA)
506
505
valB = B. diag; nB = length (valB)
507
506
nC = checksquare (C)
508
507
@boundscheck nC == nA* nB ||
509
508
throw (DimensionMismatch (" expect C to be a $(nA* nB) x$(nA* nB) matrix, got size $(nC) x$(nC) " ))
510
-
509
+ isempty (A) || isempty (B) || fill! (C, zero (A[ 1 , 1 ] * B[ 1 , 1 ]))
511
510
@inbounds for i = 1 : nA, j = 1 : nB
512
511
idx = (i- 1 )* nB+ j
513
512
C[idx, idx] = valA[i] * valB[j]
525
524
526
525
@inline function kron! (C:: AbstractMatrix , A:: Diagonal , B:: AbstractMatrix )
527
526
Base. require_one_based_indexing (B)
528
- (mA, nA) = size (A); (mB, nB) = size (B); (mC, nC) = size (C);
527
+ (mA, nA) = size (A)
528
+ (mB, nB) = size (B)
529
+ (mC, nC) = size (C)
529
530
@boundscheck (mC, nC) == (mA * mB, nA * nB) ||
530
531
throw (DimensionMismatch (" expect C to be a $(mA * mB) x$(nA * nB) matrix, got size $(mC) x$(nC) " ))
532
+ isempty (A) || isempty (B) || fill! (C, zero (A[1 ,1 ] * B[1 ,1 ]))
531
533
m = 1
532
534
@inbounds for j = 1 : nA
533
535
A_jj = A[j,j]
545
547
546
548
@inline function kron! (C:: AbstractMatrix , A:: AbstractMatrix , B:: Diagonal )
547
549
require_one_based_indexing (A)
548
- (mA, nA) = size (A); (mB, nB) = size (B); (mC, nC) = size (C);
550
+ (mA, nA) = size (A)
551
+ (mB, nB) = size (B)
552
+ (mC, nC) = size (C)
549
553
@boundscheck (mC, nC) == (mA * mB, nA * nB) ||
550
554
throw (DimensionMismatch (" expect C to be a $(mA * mB) x$(nA * nB) matrix, got size $(mC) x$(nC) " ))
555
+ isempty (A) || isempty (B) || fill! (C, zero (A[1 ,1 ] * B[1 ,1 ]))
551
556
m = 1
552
557
@inbounds for j = 1 : nA
553
558
for l = 1 : mB
563
568
return C
564
569
end
565
570
566
- function kron (A:: Diagonal{T} , B:: AbstractMatrix{S} ) where {T<: Number , S<: Number }
567
- (mA, nA) = size (A); (mB, nB) = size (B)
568
- R = zeros (Base. promote_op (* , T, S), mA * mB, nA * nB)
569
- return @inbounds kron! (R, A, B)
570
- end
571
-
572
- function kron (A:: AbstractMatrix{T} , B:: Diagonal{S} ) where {T<: Number , S<: Number }
573
- (mA, nA) = size (A); (mB, nB) = size (B)
574
- R = zeros (promote_op (* , T, S), mA * mB, nA * nB)
575
- return @inbounds kron! (R, A, B)
576
- end
577
-
578
571
conj (D:: Diagonal ) = Diagonal (conj (D. diag))
579
572
transpose (D:: Diagonal{<:Number} ) = D
580
573
transpose (D:: Diagonal ) = Diagonal (transpose .(D. diag))
0 commit comments