From 2a89f7dbefab9a03575161ed49e799d25b422960 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 15 Mar 2020 21:08:19 -0400 Subject: [PATCH 01/11] Add rot to BLAS in stdlib/LinearAlgebra --- NEWS.md | 2 +- stdlib/LinearAlgebra/src/blas.jl | 27 +++++++++++++++++++++++++++ stdlib/LinearAlgebra/test/blas.jl | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 936a7c932c7ed..dd7b60fa29ebc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -111,7 +111,7 @@ Standard library changes * `normalize` now supports multidimensional arrays ([#34239]) * `lq` factorizations can now be used to compute the minimum-norm solution to under-determined systems ([#34350]). * The BLAS submodule now supports the level-2 BLAS subroutine `spmv!` ([#34320]). - +* The BLAS submodule now supports the level-1 BLAS subroutine `rot` ([#35124]). #### Markdown diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index b8f86a12c6ea5..901d69da24bd9 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -11,6 +11,7 @@ using Base: require_one_based_indexing export # Level 1 + rot, asum, axpy!, axpby!, @@ -198,6 +199,32 @@ for (fname, elty) in ((:dcopy_,:Float64), end end + +## rot + +""" + rot(n, X, incx, Y, incy, c, s) + +Overwrite `X` with `c*X + s*Y` and `Y` with `-s*X + c*Y` for the first `n` elements of array `X` with stride `incx` and +first `n` elements of array `Y` with stride `incy`. Returns `X` and `Y`. +""" +function rot end + +for (fname, elty, sub_type) in ((:drot_,:Float64,:Float64), + (:srot_,:Float32,:Float32), + (:zdrot_,:ComplexF64,:Float64), + (:csrot_,:ComplexF32,:Float32)) + @eval begin + # SUBROUTINE DROT(N,DX,INCX,DY,INCY,C,S) + function rot(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer, C::$sub_type, S::$sub_type) + ccall((@blasfunc($fname), libblas), Cvoid, + (Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ref{$sub_type}, Ref{$sub_type}), + n, DX, incx, DY, incy, C, S) + DX, DY + end + end +end + ## scal """ diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index dc6bf1f054767..0dfaf9147d677 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -78,6 +78,22 @@ Random.seed!(100) @test BLAS.iamax(z) == argmax(map(x -> abs(real(x)) + abs(imag(x)), z)) end end + @testset "rot" begin + if elty <: Real + sub_type = elty + elseif elty == ComplexF32 + sub_type = Float32 + elseif elty == ComplexF64 + sub_type = Float64 + end + x = randn(elty, n) + y = randn(elty, n) + c = rand(sub_type) + s = rand(sub_type) + x2, y2 = BLAS.rot(n,copy(x),1,copy(y),1,c,s) + @test x2 ≈ c*x + s*y + @test y2 ≈ -s*x + c*y + end @testset "axp(b)y" begin if elty <: Real x1 = convert(Vector{elty}, randn(n)) From 8ff68525a2845cc05c754df0d1d1221857397d6c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 16 Mar 2020 01:29:45 -0400 Subject: [PATCH 02/11] Add zrot and crot variants --- stdlib/LinearAlgebra/src/blas.jl | 18 ++++++++++-------- stdlib/LinearAlgebra/test/blas.jl | 30 ++++++++++++++++++------------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index 901d69da24bd9..62e83b7b88592 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -205,20 +205,22 @@ end """ rot(n, X, incx, Y, incy, c, s) -Overwrite `X` with `c*X + s*Y` and `Y` with `-s*X + c*Y` for the first `n` elements of array `X` with stride `incx` and +Overwrite `X` with `c*X + s*Y` and `Y` with `-conj(s)*X + c*Y` for the first `n` elements of array `X` with stride `incx` and first `n` elements of array `Y` with stride `incy`. Returns `X` and `Y`. """ function rot end -for (fname, elty, sub_type) in ((:drot_,:Float64,:Float64), - (:srot_,:Float32,:Float32), - (:zdrot_,:ComplexF64,:Float64), - (:csrot_,:ComplexF32,:Float32)) +for (fname, elty, cty, sty, lib) in ((:drot_, :Float64, :Float64, :Float64, libblas), + (:srot_, :Float32, :Float32, :Float32, libblas), + (:zdrot_, :ComplexF64, :Float64, :Float64, libblas), + (:csrot_, :ComplexF32, :Float32, :Float32, libblas), + (:zrot_, :ComplexF64, :Float64, :ComplexF64, liblapack), + (:crot_, :ComplexF32, :Float32, :ComplexF32, liblapack)) @eval begin # SUBROUTINE DROT(N,DX,INCX,DY,INCY,C,S) - function rot(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer, C::$sub_type, S::$sub_type) - ccall((@blasfunc($fname), libblas), Cvoid, - (Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ref{$sub_type}, Ref{$sub_type}), + function rot(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer, C::$cty, S::$sty) + ccall((@blasfunc($fname), $lib), Cvoid, + (Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ref{$cty}, Ref{$sty}), n, DX, incx, DY, incy, C, S) DX, DY end diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index 0dfaf9147d677..aeede8614ee2e 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -80,19 +80,25 @@ Random.seed!(100) end @testset "rot" begin if elty <: Real - sub_type = elty - elseif elty == ComplexF32 - sub_type = Float32 - elseif elty == ComplexF64 - sub_type = Float64 + x = convert(Vector{elty}, randn(n)) + y = convert(Vector{elty}, randn(n)) + c = rand(elty) + s = rand(elty) + x2, y2 = BLAS.rot(n,copy(x),1,copy(y),1,c,s) + @test x2 ≈ c*x + s*y + @test y2 ≈ -s*x + c*y + else + x = convert(Vector{elty}, complex.(randn(n),rand(n))) + y = convert(Vector{elty}, complex.(randn(n),rand(n))) + cty = (elty == ComplexF32) ? Float32 : Float64 + c = rand(cty) + for sty in [cty, elty] + s = rand(sty) + x2, y2 = BLAS.rot(n,copy(x),1,copy(y),1,c,s) + @test x2 ≈ c*x + s*y + @test y2 ≈ -conj(s)*x + c*y + end end - x = randn(elty, n) - y = randn(elty, n) - c = rand(sub_type) - s = rand(sub_type) - x2, y2 = BLAS.rot(n,copy(x),1,copy(y),1,c,s) - @test x2 ≈ c*x + s*y - @test y2 ≈ -s*x + c*y end @testset "axp(b)y" begin if elty <: Real From cec3174257c3d0387da5dce6386750752eb4f5a4 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 16 Mar 2020 15:53:31 -0400 Subject: [PATCH 03/11] Use rot! instead of rot --- NEWS.md | 2 +- stdlib/LinearAlgebra/src/blas.jl | 9 ++++++--- stdlib/LinearAlgebra/test/blas.jl | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index dd7b60fa29ebc..04ee12c8a9ebc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -111,7 +111,7 @@ Standard library changes * `normalize` now supports multidimensional arrays ([#34239]) * `lq` factorizations can now be used to compute the minimum-norm solution to under-determined systems ([#34350]). * The BLAS submodule now supports the level-2 BLAS subroutine `spmv!` ([#34320]). -* The BLAS submodule now supports the level-1 BLAS subroutine `rot` ([#35124]). +* The BLAS submodule now supports the level-1 BLAS subroutine `rot!` ([#35124]). #### Markdown diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index 62e83b7b88592..f0b049e71a7c7 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -11,8 +11,8 @@ using Base: require_one_based_indexing export # Level 1 - rot, asum, + rot!, axpy!, axpby!, blascopy!, @@ -203,10 +203,13 @@ end ## rot """ - rot(n, X, incx, Y, incy, c, s) + rot!(n, X, incx, Y, incy, c, s) Overwrite `X` with `c*X + s*Y` and `Y` with `-conj(s)*X + c*Y` for the first `n` elements of array `X` with stride `incx` and first `n` elements of array `Y` with stride `incy`. Returns `X` and `Y`. + +!!! compat "Julia 1.5" + `rot!` requires at least Julia 1.5. """ function rot end @@ -218,7 +221,7 @@ for (fname, elty, cty, sty, lib) in ((:drot_, :Float64, :Float64, :Float64, libb (:crot_, :ComplexF32, :Float32, :ComplexF32, liblapack)) @eval begin # SUBROUTINE DROT(N,DX,INCX,DY,INCY,C,S) - function rot(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer, C::$cty, S::$sty) + function rot!(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer, C::$cty, S::$sty) ccall((@blasfunc($fname), $lib), Cvoid, (Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ref{$cty}, Ref{$sty}), n, DX, incx, DY, incy, C, S) diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index aeede8614ee2e..a0756da4ffaa3 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -84,7 +84,7 @@ Random.seed!(100) y = convert(Vector{elty}, randn(n)) c = rand(elty) s = rand(elty) - x2, y2 = BLAS.rot(n,copy(x),1,copy(y),1,c,s) + x2, y2 = BLAS.rot!(n,copy(x),1,copy(y),1,c,s) @test x2 ≈ c*x + s*y @test y2 ≈ -s*x + c*y else @@ -94,7 +94,7 @@ Random.seed!(100) c = rand(cty) for sty in [cty, elty] s = rand(sty) - x2, y2 = BLAS.rot(n,copy(x),1,copy(y),1,c,s) + x2, y2 = BLAS.rot!(n,copy(x),1,copy(y),1,c,s) @test x2 ≈ c*x + s*y @test y2 ≈ -conj(s)*x + c*y end From 777fb718e25ff5b661e8d72f1eb676ec5863a571 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 16 Mar 2020 16:24:04 -0400 Subject: [PATCH 04/11] Update test for rot! --- NEWS.md | 1 + stdlib/LinearAlgebra/test/blas.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 04ee12c8a9ebc..463a6c249eb34 100644 --- a/NEWS.md +++ b/NEWS.md @@ -112,6 +112,7 @@ Standard library changes * `lq` factorizations can now be used to compute the minimum-norm solution to under-determined systems ([#34350]). * The BLAS submodule now supports the level-2 BLAS subroutine `spmv!` ([#34320]). * The BLAS submodule now supports the level-1 BLAS subroutine `rot!` ([#35124]). + #### Markdown diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index a0756da4ffaa3..e5c2cf8442791 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -78,7 +78,7 @@ Random.seed!(100) @test BLAS.iamax(z) == argmax(map(x -> abs(real(x)) + abs(imag(x)), z)) end end - @testset "rot" begin + @testset "rot!" begin if elty <: Real x = convert(Vector{elty}, randn(n)) y = convert(Vector{elty}, randn(n)) From 844f75f2c1c143a7c7032168728eaa9b7b22a240 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 17 Mar 2020 14:37:05 -0400 Subject: [PATCH 05/11] Test that x and y are overwritten with rot! --- stdlib/LinearAlgebra/test/blas.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index e5c2cf8442791..23c6d68cdc997 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -84,9 +84,11 @@ Random.seed!(100) y = convert(Vector{elty}, randn(n)) c = rand(elty) s = rand(elty) - x2, y2 = BLAS.rot!(n,copy(x),1,copy(y),1,c,s) - @test x2 ≈ c*x + s*y - @test y2 ≈ -s*x + c*y + x2 = copy(x) + y2 = copy(y) + BLAS.rot!(n, x, 1, y, 1, c, s) + @test x ≈ c*x2 + s*y2 + @test y ≈ -s*x2 + c*y2 else x = convert(Vector{elty}, complex.(randn(n),rand(n))) y = convert(Vector{elty}, complex.(randn(n),rand(n))) @@ -94,9 +96,11 @@ Random.seed!(100) c = rand(cty) for sty in [cty, elty] s = rand(sty) - x2, y2 = BLAS.rot!(n,copy(x),1,copy(y),1,c,s) - @test x2 ≈ c*x + s*y - @test y2 ≈ -conj(s)*x + c*y + x2 = copy(x) + y2 = copy(y) + BLAS.rot!(n, x, 1, y, 1, c, s) + @test x ≈ c*x2 + s*y2 + @test y ≈ -conj(s)*x2 + c*y2 end end end From 643fba59f564ddea5dfd941241557e8aeae3b423 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 25 Mar 2020 21:38:31 -0400 Subject: [PATCH 06/11] Fix rot -> rot! in blas.jl --- stdlib/LinearAlgebra/src/blas.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index f0b049e71a7c7..f34b795ba4e75 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -211,7 +211,7 @@ first `n` elements of array `Y` with stride `incy`. Returns `X` and `Y`. !!! compat "Julia 1.5" `rot!` requires at least Julia 1.5. """ -function rot end +function rot! end for (fname, elty, cty, sty, lib) in ((:drot_, :Float64, :Float64, :Float64, libblas), (:srot_, :Float32, :Float32, :Float32, libblas), From 6507e0a21dc8e8a708c65e9581f97af342853ec8 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 25 Mar 2020 21:39:00 -0400 Subject: [PATCH 07/11] Add ref! and rot! functions --- stdlib/LinearAlgebra/src/LinearAlgebra.jl | 2 ++ stdlib/LinearAlgebra/src/generic.jl | 43 +++++++++++++++++++++++ stdlib/LinearAlgebra/test/generic.jl | 19 ++++++++++ 3 files changed, 64 insertions(+) diff --git a/stdlib/LinearAlgebra/src/LinearAlgebra.jl b/stdlib/LinearAlgebra/src/LinearAlgebra.jl index 30002837f8398..86d3269da24b0 100644 --- a/stdlib/LinearAlgebra/src/LinearAlgebra.jl +++ b/stdlib/LinearAlgebra/src/LinearAlgebra.jl @@ -124,6 +124,8 @@ export opnorm, rank, rdiv!, + ref!, + rot!, schur, schur!, svd, diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index b90928c967c81..5b179d76c0546 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -1416,6 +1416,49 @@ function axpby!(α, x::AbstractArray, β, y::AbstractArray) y end +""" + rot!(x, y, c, s) + +Overwrite `x` with `c*x + s*y` and `y` with `-conj(s)*x + c*y`. +Returns `x` and `y`. + +!!! compat "Julia 1.5" + `rot!` requires at least Julia 1.5. +""" +function rot!(x::AbstractVector, y::AbstractVector, c, s) + n = length(x) + if n != length(y) + throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) + end + @inbounds for i = 1:n + xi, yi = x[i], y[i] + x[i] = c *xi + s*yi + y[i] = -conj(s)*xi + c*yi + end + return x, y +end + +""" + ref!(x, y, c, s) + +Overwrite `x` with `c*x + s*y` and `y` with `conj(s)*x - c*y`. +Returns `x` and `y`. + +!!! compat "Julia 1.5" + `rot!` requires at least Julia 1.5. +""" +function ref!(x::AbstractVector, y::AbstractVector, c, s) + n = length(x) + if n != length(y) + throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) + end + @inbounds for i = 1:n + xi, yi = x[i], y[i] + x[i] = c *xi + s*yi + y[i] = conj(s)*xi - c*yi + end + return x, y +end # Elementary reflection similar to LAPACK. The reflector is not Hermitian but # ensures that tridiagonalization of Hermitian matrices become real. See lawn72 diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index eb747b185afa3..12cb6f5c9596c 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -217,6 +217,25 @@ end @test norm(x, 3) ≈ cbrt(5^3 +sqrt(5)^3) end +@testset "rot! and ref!" begin + x = rand(1000) + y = rand(1000) + c = rand() + s = rand(ComplexF64) + + x2 = copy(x) + y2 = copy(y) + rot!(n, x, y, c, s) + @test x ≈ c*x2 + s*y2 + @test y ≈ -conj(s)*x2 + c*y2 + + x3 = copy(x) + y3 = copy(y) + ref!(n, x, y, c, s) + @test x ≈ c*x3 + s*y3 + @test y ≈ conj(s)*x3 - c*y3 +end + @testset "LinearAlgebra.axp(b)y! for element type without commutative multiplication" begin α = [1 2; 3 4] β = [5 6; 7 8] From 620297cdf14c3f1cd722e9e091570d63f2d91618 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 25 Mar 2020 21:40:53 -0400 Subject: [PATCH 08/11] Export rot! at the right place --- stdlib/LinearAlgebra/src/blas.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index f34b795ba4e75..eb55e7d5fd3ab 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -12,12 +12,12 @@ using Base: require_one_based_indexing export # Level 1 asum, - rot!, axpy!, axpby!, blascopy!, dotc, dotu, + rot!, scal!, scal, nrm2, From 2a1e0f6754ceddf8f71b4be9c32e8d44ab3b941d Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sat, 28 Mar 2020 19:44:13 -0400 Subject: [PATCH 09/11] Update rotate! and reflect! functions --- stdlib/LinearAlgebra/src/LinearAlgebra.jl | 4 ++-- stdlib/LinearAlgebra/src/generic.jl | 14 ++++++++------ stdlib/LinearAlgebra/test/generic.jl | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/stdlib/LinearAlgebra/src/LinearAlgebra.jl b/stdlib/LinearAlgebra/src/LinearAlgebra.jl index 86d3269da24b0..bb1dcb3c17ea7 100644 --- a/stdlib/LinearAlgebra/src/LinearAlgebra.jl +++ b/stdlib/LinearAlgebra/src/LinearAlgebra.jl @@ -124,8 +124,8 @@ export opnorm, rank, rdiv!, - ref!, - rot!, + reflect!, + rotate!, schur, schur!, svd, diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index 5b179d76c0546..e5555da909d10 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -1417,15 +1417,16 @@ function axpby!(α, x::AbstractArray, β, y::AbstractArray) end """ - rot!(x, y, c, s) + rotate!(x, y, c, s) Overwrite `x` with `c*x + s*y` and `y` with `-conj(s)*x + c*y`. Returns `x` and `y`. !!! compat "Julia 1.5" - `rot!` requires at least Julia 1.5. + `rotate!` requires at least Julia 1.5. """ -function rot!(x::AbstractVector, y::AbstractVector, c, s) +function rotate!(x::AbstractVector, y::AbstractVector, c, s) + require_one_based_indexing(x, y) n = length(x) if n != length(y) throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) @@ -1439,15 +1440,16 @@ function rot!(x::AbstractVector, y::AbstractVector, c, s) end """ - ref!(x, y, c, s) + reflect!(x, y, c, s) Overwrite `x` with `c*x + s*y` and `y` with `conj(s)*x - c*y`. Returns `x` and `y`. !!! compat "Julia 1.5" - `rot!` requires at least Julia 1.5. + `reflect!` requires at least Julia 1.5. """ -function ref!(x::AbstractVector, y::AbstractVector, c, s) +function reflect!(x::AbstractVector, y::AbstractVector, c, s) + require_one_based_indexing(x, y) n = length(x) if n != length(y) throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index 12cb6f5c9596c..b4f25d255e880 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -217,7 +217,7 @@ end @test norm(x, 3) ≈ cbrt(5^3 +sqrt(5)^3) end -@testset "rot! and ref!" begin +@testset "rotate! and reflect!" begin x = rand(1000) y = rand(1000) c = rand() @@ -225,13 +225,13 @@ end x2 = copy(x) y2 = copy(y) - rot!(n, x, y, c, s) + rotate!(x, y, c, s) @test x ≈ c*x2 + s*y2 @test y ≈ -conj(s)*x2 + c*y2 x3 = copy(x) y3 = copy(y) - ref!(n, x, y, c, s) + reflect!(x, y, c, s) @test x ≈ c*x3 + s*y3 @test y ≈ conj(s)*x3 - c*y3 end From 1bce5d36d7fb8ad6cb3f0d2c6ec2d1b2c8cd5627 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sat, 28 Mar 2020 19:44:35 -0400 Subject: [PATCH 10/11] Add rotate! and reflect! in NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 463a6c249eb34..d50d3395f9ad0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -112,6 +112,7 @@ Standard library changes * `lq` factorizations can now be used to compute the minimum-norm solution to under-determined systems ([#34350]). * The BLAS submodule now supports the level-2 BLAS subroutine `spmv!` ([#34320]). * The BLAS submodule now supports the level-1 BLAS subroutine `rot!` ([#35124]). +* New generic `rotate!(x, y, c, s)` and `reflect!(x, y, c, s)` functions ([#35124]). #### Markdown From d494b11108493f3c49d4e1b7536b01b51d3e93a1 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sat, 28 Mar 2020 23:20:00 -0400 Subject: [PATCH 11/11] Update tests for rotate! and reflect! --- stdlib/LinearAlgebra/test/generic.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index b4f25d255e880..9ca508d9a9908 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -218,9 +218,9 @@ end end @testset "rotate! and reflect!" begin - x = rand(1000) - y = rand(1000) - c = rand() + x = rand(ComplexF64, 10) + y = rand(ComplexF64, 10) + c = rand(Float64) s = rand(ComplexF64) x2 = copy(x)