From f45e36c0904056aa203884921aae3d4cb822cb63 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 13 Oct 2016 16:04:51 -0400 Subject: [PATCH] Fix BLAS.syr/her! by checking stride of x --- base/linalg/blas.jl | 4 ++-- test/blas.jl | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/base/linalg/blas.jl b/base/linalg/blas.jl index 3e022375fb4b3..88f372f05cf43 100644 --- a/base/linalg/blas.jl +++ b/base/linalg/blas.jl @@ -896,7 +896,7 @@ for (fname, elty, lib) in ((:dsyr_,:Float64,libblas), (Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}), &uplo, &n, &α, x, - &1, A, &max(1,stride(A,2))) + &stride(x, 1), A, &max(1,stride(A, 2))) A end end @@ -925,7 +925,7 @@ for (fname, elty, relty) in ((:zher_,:Complex128, :Float64), (Ptr{UInt8}, Ptr{BlasInt}, Ptr{$relty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}), &uplo, &n, &α, x, - &1, A, &max(1,stride(A,2))) + &stride(x, 1), A, &max(1,stride(A,2))) A end end diff --git a/test/blas.jl b/test/blas.jl index 3f6b87821da98..d0d6ce31d55f9 100644 --- a/test/blas.jl +++ b/test/blas.jl @@ -299,3 +299,19 @@ for elty in [Float32, Float64, Complex64, Complex128] @test_throws DimensionMismatch BLAS.syrk!('L','N',one(elty),eye(elty,5),one(elty),eye(elty,6)) end end + +@testset "syr for eltype $elty" for elty in (Float32, Float64, Complex{Float32}, Complex{Float64}) + A = rand(elty, 5, 5) + @test triu(A[1,:] * A[1,:].') ≈ BLAS.syr!('U', one(elty), A[1,:], zeros(elty, 5, 5)) + @test tril(A[1,:] * A[1,:].') ≈ BLAS.syr!('L', one(elty), A[1,:], zeros(elty, 5, 5)) + @test triu(A[1,:] * A[1,:].') ≈ BLAS.syr!('U', one(elty), view(A, 1, :), zeros(elty, 5, 5)) + @test tril(A[1,:] * A[1,:].') ≈ BLAS.syr!('L', one(elty), view(A, 1, :), zeros(elty, 5, 5)) +end + +@testset "her for eltype $elty" for elty in (Complex{Float32}, Complex{Float64}) + A = rand(elty, 5, 5) + @test triu(A[1,:] * A[1,:]') ≈ BLAS.her!('U', one(real(elty)), A[1,:], zeros(elty, 5, 5)) + @test tril(A[1,:] * A[1,:]') ≈ BLAS.her!('L', one(real(elty)), A[1,:], zeros(elty, 5, 5)) + @test triu(A[1,:] * A[1,:]') ≈ BLAS.her!('U', one(real(elty)), view(A, 1, :), zeros(elty, 5, 5)) + @test tril(A[1,:] * A[1,:]') ≈ BLAS.her!('L', one(real(elty)), view(A, 1, :), zeros(elty, 5, 5)) +end