Skip to content

Commit 3ac0699

Browse files
dbruegjohanmon
authored andcommitted
Add scal!(a,X) (JuliaLang#40446)
1 parent ffbb1a4 commit 3ac0699

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

stdlib/LinearAlgebra/src/blas.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,21 @@ end
218218

219219
"""
220220
scal!(n, a, X, incx)
221+
scal!(a, X)
221222
222223
Overwrite `X` with `a*X` for the first `n` elements of array `X` with stride `incx`. Returns `X`.
224+
225+
If `n` and `incx` are not provided, `length(X)` and `stride(X,1)` are used.
223226
"""
224227
function scal! end
225228

226229
"""
227230
scal(n, a, X, incx)
231+
scal(a, X)
228232
229233
Return `X` scaled by `a` for the first `n` elements of array `X` with stride `incx`.
234+
235+
If `n` and `incx` are not provided, `length(X)` and `stride(X,1)` are used.
230236
"""
231237
function scal end
232238

@@ -242,9 +248,12 @@ for (fname, elty) in ((:dscal_,:Float64),
242248
n, DA, DX, incx)
243249
DX
244250
end
251+
252+
scal!(DA::$elty, DX::AbstractArray{$elty}) = scal!(length(DX),DA,DX,stride(DX,1))
245253
end
246254
end
247255
scal(n, DA, DX, incx) = scal!(n, DA, copy(DX), incx)
256+
scal(DA, DX) = scal!(DA, copy(DX))
248257

249258
## dot
250259

stdlib/LinearAlgebra/test/blas.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ end
514514
BLAS.axpby!(elty(2), x, elty(3), y)
515515
@test y == WrappedArray(elty[19, 50, 30, 56])
516516
@test BLAS.iamax(x) == 2
517+
518+
M = fill(elty(1.0), 3, 3)
519+
BLAS.scal!(elty(2), view(M,:,2))
520+
BLAS.scal!(elty(3), view(M,3,:))
521+
@test M == elty[1. 2. 1.; 1. 2. 1.; 3. 6. 3.]
517522
# Level 2
518523
A = WrappedArray(elty[1 2; 3 4])
519524
x = WrappedArray(elty[1, 2])

0 commit comments

Comments
 (0)