CHER2K performs one of the hermitian rank 2k operations C := alphaABH + conjg( alpha )BAH + betaC, or C := alphaAHB + conjg( alpha )BHA + betaC, where alpha and beta are scalars with beta real, C is an n by n hermitian matrix and A and B are n by k matrices in the first case and k by n matrices in the second case.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=1), | intent(in) | :: | uplo | |||
character(len=1), | intent(in) | :: | trans | |||
integer(kind=ilp), | intent(in) | :: | n | |||
integer(kind=ilp), | intent(in) | :: | k | |||
complex(kind=sp), | intent(in) | :: | alpha | |||
complex(kind=sp), | intent(in) | :: | a(lda,*) | |||
integer(kind=ilp), | intent(in) | :: | lda | |||
complex(kind=sp), | intent(in) | :: | b(ldb,*) | |||
integer(kind=ilp), | intent(in) | :: | ldb | |||
real(kind=sp), | intent(in) | :: | beta | |||
complex(kind=sp), | intent(inout) | :: | c(ldc,*) | |||
integer(kind=ilp), | intent(in) | :: | ldc |
pure subroutine stdlib_cher2k(uplo,trans,n,k,alpha,a,lda,b,ldb,beta,c,ldc) !! CHER2K performs one of the hermitian rank 2k operations !! C := alpha*A*B**H + conjg( alpha )*B*A**H + beta*C, !! or !! C := alpha*A**H*B + conjg( alpha )*B**H*A + beta*C, !! where alpha and beta are scalars with beta real, C is an n by n !! hermitian matrix and A and B are n by k matrices in the first case !! and k by n matrices in the second case. ! -- reference blas level3 routine -- ! -- reference blas is a software package provided by univ. of tennessee, -- ! -- univ. of california berkeley, univ. of colorado denver and nag ltd..-- ! Scalar Arguments complex(sp), intent(in) :: alpha real(sp), intent(in) :: beta integer(ilp), intent(in) :: k, lda, ldb, ldc, n character, intent(in) :: trans, uplo ! Array Arguments complex(sp), intent(in) :: a(lda,*), b(ldb,*) complex(sp), intent(inout) :: c(ldc,*) ! ===================================================================== ! Intrinsic Functions intrinsic :: conjg,max,real ! Local Scalars complex(sp) :: temp1, temp2 integer(ilp) :: i, info, j, l, nrowa logical(lk) :: upper ! test the input parameters. if (stdlib_lsame(trans,'N')) then nrowa = n else nrowa = k end if upper = stdlib_lsame(uplo,'U') info = 0 if ((.not.upper) .and. (.not.stdlib_lsame(uplo,'L'))) then info = 1 else if ((.not.stdlib_lsame(trans,'N')) .and.(.not.stdlib_lsame(trans,'C'))) & then info = 2 else if (n<0) then info = 3 else if (k<0) then info = 4 else if (lda<max(1,nrowa)) then info = 7 else if (ldb<max(1,nrowa)) then info = 9 else if (ldc<max(1,n)) then info = 12 end if if (info/=0) then call stdlib_xerbla('CHER2K',info) return end if ! quick return if possible. if ((n==0) .or. (((alpha==czero).or.(k==0)).and. (beta==one))) return ! and when alpha.eq.czero. if (alpha==czero) then if (upper) then if (beta==real(czero,KIND=sp)) then do j = 1,n do i = 1,j c(i,j) = czero end do end do else do j = 1,n do i = 1,j - 1 c(i,j) = beta*c(i,j) end do c(j,j) = beta*real(c(j,j),KIND=sp) end do end if else if (beta==real(czero,KIND=sp)) then do j = 1,n do i = j,n c(i,j) = czero end do end do else do j = 1,n c(j,j) = beta*real(c(j,j),KIND=sp) do i = j + 1,n c(i,j) = beta*c(i,j) end do end do end if end if return end if ! start the operations. if (stdlib_lsame(trans,'N')) then ! form c := alpha*a*b**h + conjg( alpha )*b*a**h + ! c. if (upper) then do j = 1,n if (beta==real(czero,KIND=sp)) then do i = 1,j c(i,j) = czero end do else if (beta/=one) then do i = 1,j - 1 c(i,j) = beta*c(i,j) end do c(j,j) = beta*real(c(j,j),KIND=sp) else c(j,j) = real(c(j,j),KIND=sp) end if do l = 1,k if ((a(j,l)/=czero) .or. (b(j,l)/=czero)) then temp1 = alpha*conjg(b(j,l)) temp2 = conjg(alpha*a(j,l)) do i = 1,j - 1 c(i,j) = c(i,j) + a(i,l)*temp1 +b(i,l)*temp2 end do c(j,j) = real(c(j,j),KIND=sp) +real(a(j,l)*temp1+b(j,l)*temp2,& KIND=sp) end if end do end do else do j = 1,n if (beta==real(czero,KIND=sp)) then do i = j,n c(i,j) = czero end do else if (beta/=one) then do i = j + 1,n c(i,j) = beta*c(i,j) end do c(j,j) = beta*real(c(j,j),KIND=sp) else c(j,j) = real(c(j,j),KIND=sp) end if do l = 1,k if ((a(j,l)/=czero) .or. (b(j,l)/=czero)) then temp1 = alpha*conjg(b(j,l)) temp2 = conjg(alpha*a(j,l)) do i = j + 1,n c(i,j) = c(i,j) + a(i,l)*temp1 +b(i,l)*temp2 end do c(j,j) = real(c(j,j),KIND=sp) +real(a(j,l)*temp1+b(j,l)*temp2,& KIND=sp) end if end do end do end if else ! form c := alpha*a**h*b + conjg( alpha )*b**h*a + ! c. if (upper) then do j = 1,n do i = 1,j temp1 = czero temp2 = czero do l = 1,k temp1 = temp1 + conjg(a(l,i))*b(l,j) temp2 = temp2 + conjg(b(l,i))*a(l,j) end do if (i==j) then if (beta==real(czero,KIND=sp)) then c(j,j) = real(alpha*temp1+conjg(alpha)*temp2,KIND=sp) else c(j,j) = beta*real(c(j,j),KIND=sp) +real(alpha*temp1+conjg(& alpha)*temp2,KIND=sp) end if else if (beta==real(czero,KIND=sp)) then c(i,j) = alpha*temp1 + conjg(alpha)*temp2 else c(i,j) = beta*c(i,j) + alpha*temp1 +conjg(alpha)*temp2 end if end if end do end do else do j = 1,n do i = j,n temp1 = czero temp2 = czero do l = 1,k temp1 = temp1 + conjg(a(l,i))*b(l,j) temp2 = temp2 + conjg(b(l,i))*a(l,j) end do if (i==j) then if (beta==real(czero,KIND=sp)) then c(j,j) = real(alpha*temp1+conjg(alpha)*temp2,KIND=sp) else c(j,j) = beta*real(c(j,j),KIND=sp) +real(alpha*temp1+conjg(& alpha)*temp2,KIND=sp) end if else if (beta==real(czero,KIND=sp)) then c(i,j) = alpha*temp1 + conjg(alpha)*temp2 else c(i,j) = beta*c(i,j) + alpha*temp1 +conjg(alpha)*temp2 end if end if end do end do end if end if return end subroutine stdlib_cher2k