From c42496520366e98b970c27c8902deef2427a6e6d Mon Sep 17 00:00:00 2001 From: Andy Zhang <37402126+AnzhiZhang@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:04:14 +0100 Subject: [PATCH] chore(dev): add devtests --- devtests/.gitignore | 1 + devtests/Project.toml | 2 ++ devtests/performance/inbounds.jl | 40 +++++++++++++++++++++++++++++ devtests/test.jl | 43 ++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 devtests/.gitignore create mode 100644 devtests/Project.toml create mode 100644 devtests/performance/inbounds.jl create mode 100644 devtests/test.jl diff --git a/devtests/.gitignore b/devtests/.gitignore new file mode 100644 index 0000000..b067edd --- /dev/null +++ b/devtests/.gitignore @@ -0,0 +1 @@ +/Manifest.toml diff --git a/devtests/Project.toml b/devtests/Project.toml new file mode 100644 index 0000000..eb99d99 --- /dev/null +++ b/devtests/Project.toml @@ -0,0 +1,2 @@ +[deps] +TypedMatrices = "a0429a07-0388-4c37-a18a-23d110f8915c" diff --git a/devtests/performance/inbounds.jl b/devtests/performance/inbounds.jl new file mode 100644 index 0000000..0159e8c --- /dev/null +++ b/devtests/performance/inbounds.jl @@ -0,0 +1,40 @@ +using BenchmarkTools + +@inline function f1(A, i) + @boundscheck checkbounds(A, i) + return @inbounds g(1:2, -1) +end + +@inline Base.@propagate_inbounds function f2(A, i) + @boundscheck checkbounds(A, i) + return g(1:2, -1) +end + +@inline function g(A, i) + @boundscheck checkbounds(A, i) + return "g: accessing ($A)[$i]" +end + +function test_f1() + for i = 1:100000 + @inbounds f1(1:2, -1) + end +end + +function test_f2() + for i = 1:100000 + @inbounds f2(1:2, -1) + end +end + +function main() + @inbounds f1(1:2, -1) + @inbounds f2(1:2, -1) + + t1 = @benchmark test_f1() + t2 = @benchmark test_f2() + display(t1) + display(t2) +end + +main() diff --git a/devtests/test.jl b/devtests/test.jl new file mode 100644 index 0000000..f348a8f --- /dev/null +++ b/devtests/test.jl @@ -0,0 +1,43 @@ +using LinearAlgebra +using MatrixDepot +using TypedMatrices + +function compare(name::String, typedT::Type{T}, args...) where {T<:AbstractMatrix} + depot = matrixdepot(name, args...) + typed = typedT(args...) + # display(depot) + # display(typed) + # @show norm(typed - depot) + return typed ≈ depot +end + +function linearalgebra_is_tests(A::AbstractMatrix) + return Dict( + :diag => isdiag(A), + :hermitian => ishermitian(A), + :posdef => isposdef(A), + :symmetric => issymmetric(A), + ) +end + +MT = Clement +name = "clement" + +# linear algebra properties +for i = 1:10 + matrix = MT(i) + test_result_type = linearalgebra_is_tests(matrix) + test_result_matrix = linearalgebra_is_tests(Matrix(matrix)) + if test_result_type != test_result_matrix || true + display(matrix) + @show i, test_result_type, test_result_matrix + end +end + +# compare elements +for i = 1:10 + result = compare(name, MT, i) + if !result || false + @show i, result + end +end