Skip to content

Commit

Permalink
Add tests for utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
michakraus committed Nov 7, 2024
1 parent c912907 commit 8dacfc6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ KernelAbstractions = "0.9"
julia = "1.6"

[extras]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Random", "SafeTestsets", "Test"]
test = ["Random", "LinearAlgebra", "SafeTestsets", "Test"]
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SafeTestsets

@safetestset "Utilities " begin include("utils_tests.jl") end
@safetestset "Abstract Layer " begin include("layers/abstract_layer_tests.jl") end
@safetestset "Dense Layer " begin include("layers/dense_layer_tests.jl") end
@safetestset "Linear Layer " begin include("layers/linear_layer_tests.jl") end
Expand Down
60 changes: 60 additions & 0 deletions test/utils_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using AbstractNeuralNetworks: add!
using AbstractNeuralNetworks: ZeroVector
using LinearAlgebra
using Random
using Test


a = rand(3)
b = rand(3)
x = zeros(3)

add!(x, a, b)

@test x == a + b

b .= x

add!(x, a)

@test x == a + b



a = rand(3,4)
b = rand(3,4)
x = zeros(3,4)

add!(x, a, b)

@test x == a + b

b .= x

add!(x, a)

@test x == a + b


x = rand(5)
y = copy(x)
z = ZeroVector(x)

@test z == ZeroVector(Float64, 5)

@test eltype(z) == Float64
@test length(z) == 5
@test size(z) == (5,)
@test axes(z) == (1:5,)

@test z[1] == 0
@test z[5] == 0

@test_throws AssertionError z[0] == 0
@test_throws AssertionError z[6] == 0

@test add!(x,z) == y

mul!(x, rand(5,5), z)

@test x == zero(x)

0 comments on commit 8dacfc6

Please sign in to comment.