From 14bba2f22b0e787ae106402eb84114f9907e8798 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Mon, 20 Jul 2020 18:59:03 -0400 Subject: [PATCH] Added maximum(abs, x). --- src/miscellaneous.jl | 9 +++++++++ test/misc.jl | 9 +++++++++ test/runtests.jl | 1 + 3 files changed, 19 insertions(+) create mode 100644 src/miscellaneous.jl create mode 100644 test/misc.jl diff --git a/src/miscellaneous.jl b/src/miscellaneous.jl new file mode 100644 index 0000000..f38b940 --- /dev/null +++ b/src/miscellaneous.jl @@ -0,0 +1,9 @@ + +function maximum(::typeof(abs), A::AbstractStrideArray{S,T}) where {S,T} + s = typemin(T) + @avx for i ∈ eachindex(A) + s = max(s, abs(A[i])) + end + s +end + diff --git a/test/misc.jl b/test/misc.jl new file mode 100644 index 0000000..1bb9a7b --- /dev/null +++ b/test/misc.jl @@ -0,0 +1,9 @@ + + +@testset "Miscellaneous" begin + x = @FixedSize rand(127); + @test maximum(abs, x) == maximum(abs, Array(x)) + y = @FixedSize rand(3); + @test maximum(abs, y) == maximum(abs, Array(y)) +end + diff --git a/test/runtests.jl b/test/runtests.jl index 91a588c..3f02f24 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,4 +11,5 @@ using Test @test isempty(detect_unbound_args(PaddedMatrices)) @time include("matmul_tests.jl") @time include("broadcast_tests.jl") + @time include("misc.jl") end