Skip to content

Commit 80ba457

Browse files
Jay-sanjaydkarraschViralBShahmikmooreIanButterworth
authored
BLAS.geru! added (#51951)
Closes JuliaLang/LinearAlgebra.jl#12. **PR Checklist** - [x] added BLAS.geru! function in stdlib/LinearAlgebra/src/blas.jl - [x] also added test cases for it in stdlib/LinearAlgebra/test/blas.jl --------- Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de> Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com> Co-authored-by: mikmoore <95002244+mikmoore@users.noreply.github.com> Co-authored-by: Ian Butterworth <i.r.butterworth@gmail.com>
1 parent cfc4289 commit 80ba457

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

stdlib/LinearAlgebra/src/blas.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export
5252
# xTBSV
5353
# xTPSV
5454
ger!,
55+
geru!,
5556
# xGERU
5657
# xGERC
5758
her!,
@@ -1417,6 +1418,41 @@ for (fname, elty) in ((:dger_,:Float64),
14171418
end
14181419
end
14191420

1421+
### geru
1422+
1423+
"""
1424+
geru!(alpha, x, y, A)
1425+
1426+
Rank-1 update of the matrix `A` with vectors `x` and `y` as `alpha*x*transpose(y) + A`.
1427+
"""
1428+
function geru! end
1429+
1430+
for (fname, elty) in ((:zgeru_,:ComplexF64), (:cgeru_,:ComplexF32))
1431+
@eval begin
1432+
function geru!::$elty, x::AbstractVector{$elty}, y::AbstractVector{$elty}, A::AbstractMatrix{$elty})
1433+
require_one_based_indexing(A, x, y)
1434+
m, n = size(A)
1435+
if m != length(x) || n != length(y)
1436+
throw(DimensionMismatch(lazy"A has size ($m,$n), x has length $(length(x)), y has length $(length(y))"))
1437+
end
1438+
px, stx = vec_pointer_stride(x, ArgumentError("input vector with 0 stride is not allowed"))
1439+
py, sty = vec_pointer_stride(y, ArgumentError("input vector with 0 stride is not allowed"))
1440+
GC.@preserve x y ccall((@blasfunc($fname), libblastrampoline), Cvoid,
1441+
(Ref{BlasInt}, Ref{BlasInt}, Ref{$elty}, Ptr{$elty},
1442+
Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{$elty},
1443+
Ref{BlasInt}),
1444+
m, n, α, px, stx, py, sty, A, max(1,stride(A,2)))
1445+
A
1446+
end
1447+
end
1448+
end
1449+
for elty in (:Float64, :Float32)
1450+
@eval begin
1451+
geru!::$elty, x::AbstractVector{$elty}, y::AbstractVector{$elty}, A::AbstractMatrix{$elty}) =
1452+
ger!(α, x, y, A)
1453+
end
1454+
end
1455+
14201456
### syr
14211457

14221458
"""

stdlib/LinearAlgebra/test/blas.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Random.seed!(100)
135135
end
136136
end
137137

138-
@testset "ger, her, syr" for x in (rand(elty, n), view(rand(elty,2n), 1:2:2n), view(rand(elty,n), n:-1:1)),
138+
@testset "ger, geru, her, syr" for x in (rand(elty, n), view(rand(elty,2n), 1:2:2n), view(rand(elty,n), n:-1:1)),
139139
y in (rand(elty,n), view(rand(elty,3n), 1:3:3n), view(rand(elty,2n), 2n:-2:2))
140140

141141
A = rand(elty,n,n)
@@ -144,6 +144,9 @@ Random.seed!(100)
144144
@test BLAS.ger!(α,x,y,copy(A)) A + α*x*y'
145145
@test_throws DimensionMismatch BLAS.ger!(α,Vector{elty}(undef,n+1),y,copy(A))
146146

147+
@test BLAS.geru!(α,x,y,copy(A)) A + α*x*transpose(y)
148+
@test_throws DimensionMismatch BLAS.geru!(α,Vector{elty}(undef,n+1),y,copy(A))
149+
147150
A = rand(elty,n,n)
148151
A = A + transpose(A)
149152
@test issymmetric(A)

0 commit comments

Comments
 (0)