Skip to content

Commit d86b66e

Browse files
committed
add neg-stride support to spr!
test added
1 parent 871cc22 commit d86b66e

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

stdlib/LinearAlgebra/src/blas.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,16 +1167,16 @@ for (fname, elty) in ((:dspr_, :Float64),
11671167
end
11681168

11691169
function spr!(uplo::AbstractChar,
1170-
α::Real, x::Union{DenseArray{T}, AbstractVector{T}},
1171-
AP::Union{DenseArray{T}, AbstractVector{T}}) where {T <: BlasReal}
1170+
α::Real, x::AbstractArray{T},
1171+
AP::AbstractArray{T}) where {T <: BlasReal}
11721172
chkuplo(uplo)
11731173
require_one_based_indexing(AP, x)
11741174
N = length(x)
11751175
if 2*length(AP) < N*(N + 1)
11761176
throw(DimensionMismatch("Packed symmetric matrix A has size smaller than length(x) = $(N)."))
11771177
end
11781178
chkstride1(AP)
1179-
return spr!(uplo, N, convert(T, α), x, stride(x, 1), AP)
1179+
return GC.@preserve x spr!(uplo, N, T(α), vec_pointer_stride(x)..., AP)
11801180
end
11811181

11821182
"""

stdlib/LinearAlgebra/test/blas.jl

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ end
291291
M = rand(elty, n, n)
292292
AL = Symmetric(M, :L)
293293
AU = Symmetric(M, :U)
294-
x = rand(elty, n)
295-
296294
function pack(A, uplo)
297295
AP = elty[]
298296
for j in 1:n
@@ -302,28 +300,29 @@ end
302300
end
303301
return AP
304302
end
305-
306-
ALP_result_julia_lower = pack*x*x' + AL, :L)
307-
ALP_result_blas_lower = pack(AL, :L)
308-
BLAS.spr!('L', α, x, ALP_result_blas_lower)
309-
@test ALP_result_julia_lower ALP_result_blas_lower
310-
ALP_result_blas_lower = append!(pack(AL, :L), ones(elty, 10))
311-
BLAS.spr!('L', α, x, ALP_result_blas_lower)
312-
@test ALP_result_julia_lower ALP_result_blas_lower[1:end-10]
313-
ALP_result_blas_lower = reshape(pack(AL, :L), 1, length(ALP_result_julia_lower), 1)
314-
BLAS.spr!('L', α, x, ALP_result_blas_lower)
315-
@test ALP_result_julia_lower vec(ALP_result_blas_lower)
316-
317-
AUP_result_julia_upper = pack*x*x' + AU, :U)
318-
AUP_result_blas_upper = pack(AU, :U)
319-
BLAS.spr!('U', α, x, AUP_result_blas_upper)
320-
@test AUP_result_julia_upper AUP_result_blas_upper
321-
AUP_result_blas_upper = append!(pack(AU, :U), ones(elty, 10))
322-
BLAS.spr!('U', α, x, AUP_result_blas_upper)
323-
@test AUP_result_julia_upper AUP_result_blas_upper[1:end-10]
324-
AUP_result_blas_upper = reshape(pack(AU, :U), 1, length(AUP_result_julia_upper), 1)
325-
BLAS.spr!('U', α, x, AUP_result_blas_upper)
326-
@test AUP_result_julia_upper vec(AUP_result_blas_upper)
303+
for x in (rand(elty, n), view(rand(elty, n), n:-1:1))
304+
ALP_result_julia_lower = pack*x*x' + AL, :L)
305+
ALP_result_blas_lower = pack(AL, :L)
306+
BLAS.spr!('L', α, x, ALP_result_blas_lower)
307+
@test ALP_result_julia_lower ALP_result_blas_lower
308+
ALP_result_blas_lower = append!(pack(AL, :L), ones(elty, 10))
309+
BLAS.spr!('L', α, x, ALP_result_blas_lower)
310+
@test ALP_result_julia_lower ALP_result_blas_lower[1:end-10]
311+
ALP_result_blas_lower = reshape(pack(AL, :L), 1, length(ALP_result_julia_lower), 1)
312+
BLAS.spr!('L', α, x, ALP_result_blas_lower)
313+
@test ALP_result_julia_lower vec(ALP_result_blas_lower)
314+
315+
AUP_result_julia_upper = pack*x*x' + AU, :U)
316+
AUP_result_blas_upper = pack(AU, :U)
317+
BLAS.spr!('U', α, x, AUP_result_blas_upper)
318+
@test AUP_result_julia_upper AUP_result_blas_upper
319+
AUP_result_blas_upper = append!(pack(AU, :U), ones(elty, 10))
320+
BLAS.spr!('U', α, x, AUP_result_blas_upper)
321+
@test AUP_result_julia_upper AUP_result_blas_upper[1:end-10]
322+
AUP_result_blas_upper = reshape(pack(AU, :U), 1, length(AUP_result_julia_upper), 1)
323+
BLAS.spr!('U', α, x, AUP_result_blas_upper)
324+
@test AUP_result_julia_upper vec(AUP_result_blas_upper)
325+
end
327326
end
328327
end
329328

0 commit comments

Comments
 (0)