Skip to content

Commit

Permalink
chore(dev): add devtests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Aug 26, 2024
1 parent 55a386d commit c424965
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions devtests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Manifest.toml
2 changes: 2 additions & 0 deletions devtests/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
TypedMatrices = "a0429a07-0388-4c37-a18a-23d110f8915c"
40 changes: 40 additions & 0 deletions devtests/performance/inbounds.jl
Original file line number Diff line number Diff line change
@@ -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()
43 changes: 43 additions & 0 deletions devtests/test.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c424965

Please sign in to comment.