From 514a7248c5acbf193042ade3fa5e964904f31f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 19 Nov 2019 12:19:27 +0100 Subject: [PATCH] Run rewrite tests for Float64 --- .travis.yml | 3 +++ src/MutableArithmetics.jl | 2 ++ src/bigint.jl | 3 +++ src/linear_algebra.jl | 2 -- test/rewrite.jl | 48 +++++++++++++++++++++++---------------- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index e0fa795..148ae10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,10 @@ os: - linux - osx julia: + - 1.0 - 1.1 + - 1.2 + - 1.3 - nightly matrix: allow_failures: diff --git a/src/MutableArithmetics.jl b/src/MutableArithmetics.jl index a818c53..122e256 100644 --- a/src/MutableArithmetics.jl +++ b/src/MutableArithmetics.jl @@ -6,6 +6,8 @@ module MutableArithmetics +import LinearAlgebra + # Performance note: # We use `Vararg` instead of splatting `...` as using `where N` forces Julia to # specialize in the number of arguments `N`. Otherwise, we get allocations and diff --git a/src/bigint.jl b/src/bigint.jl index 64b43be..caa1554 100644 --- a/src/bigint.jl +++ b/src/bigint.jl @@ -13,6 +13,9 @@ promote_operation(::typeof(+), ::Vararg{Type{BigInt}, N}) where {N} = BigInt function mutable_operate_to!(output::BigInt, ::typeof(+), a::BigInt, b::BigInt) return Base.GMP.MPZ.add!(output, a, b) end +function mutable_operate_to!(output::BigInt, op::typeof(+), a::BigInt, b::LinearAlgebra.UniformScaling) + return mutable_operate_to!(output, op, a, b.λ) +end # * promote_operation(::typeof(*), ::Vararg{Type{BigInt}, N}) where {N} = BigInt diff --git a/src/linear_algebra.jl b/src/linear_algebra.jl index 96f19b4..6e01539 100644 --- a/src/linear_algebra.jl +++ b/src/linear_algebra.jl @@ -1,5 +1,3 @@ -import LinearAlgebra - mutability(::Type{<:Array}) = IsMutable() # Sum diff --git a/test/rewrite.jl b/test/rewrite.jl index d65ce32..2bcab9e 100644 --- a/test/rewrite.jl +++ b/test/rewrite.jl @@ -434,11 +434,14 @@ function non_array_test(x, x2) if !MA._one_indexed(x2) @test_throws DimensionMismatch x + x2 end - @testset "diagm" begin - if !MA._one_indexed(x2) && eltype(x2) isa MA.AbstractMutable - @test_throws AssertionError diagm(x2) - else - @test diagm(x) == diagm(x2) + # `diagm` not defined for Int before Julia v1.2 + if !(eltype(x2) <: Integer) || VERSION >= v"1.2" + @testset "diagm" begin + if !MA._one_indexed(x2) && eltype(x2) isa MA.AbstractMutable + @test_throws AssertionError diagm(x2) + else + @test diagm(x) == diagm(x2) + end end end end @@ -484,22 +487,29 @@ end using LinearAlgebra using OffsetArrays -@testset "@rewrite with Int" begin - basic_operators_test(1, 2, 3, 4) - sum_test(rand(Int, 3, 3)) - dot_test(rand(Int, 3), rand(Int, 2, 2), rand(Int, 2, 2, 2)) - issue_656(3) - transpose_test(rand(Int, 3), rand(Int, 2, 3), rand(Int, 5)) - vectorized_test([3, 2, 6], 4, 5, [8 1 9; 4 3 1; 2 0 8]) - broadcast_test([2 4; 1 3]) - x = [2, 4, 3] +@testset "@rewrite with $T" for T in [ + Int, + Float64 + #, BigInt + ] + basic_operators_test(T(1), T(2), T(3), T(4)) + sum_test(T[5 1 9; -7 2 4; -2 -7 5]) + S = zeros(T, 2, 2, 2) + S[1, :, :] = T[5 -8; 3 -7] + S[2, :, :] = T[-2 8; 8 -1] + dot_test(T[-7, 1, 4], T[0 -4; 6 -5], S) + issue_656(T(3)) + transpose_test(T[9, -3, 8], T[-4 4 1; 4 -8 -6], T[6, 9, 2, 4, -3]) + vectorized_test(T[3, 2, 6], T(4), T(5), T[8 1 9; 4 3 1; 2 0 8]) + broadcast_test(T[2 4; 1 3]) + x = T[2, 4, 3] non_array_test(x, x) non_array_test(x, OffsetArray(x, -length(x))) non_array_test(x, view(x, :)) non_array_test(x, sparse(x)) - unary_matrix([1 2; 3 4]) - unary_matrix(Symmetric([1 2; 2 4])) - scalar_uniform_scaling(3) - matrix_uniform_scaling([1 2; 3 4]) - matrix_uniform_scaling(Symmetric([1 2; 2 4])) + unary_matrix(T[1 2; 3 4]) + unary_matrix(Symmetric(T[1 2; 2 4])) + scalar_uniform_scaling(T(3)) + matrix_uniform_scaling(T[1 2; 3 4]) + matrix_uniform_scaling(Symmetric(T[1 2; 2 4])) end