Skip to content

Commit

Permalink
CUDA tests only if CUDA is functional
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuebel committed Apr 23, 2024
1 parent 16bcc27 commit fcd5deb
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions test/math.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @license BSD-3 https://opensource.org/licenses/BSD-3-Clause
# Copyright (c) 2023, Institute of Automatic Control - RWTH Aachen University
# All rights reserved.
# All rights reserved.

@testset "add_logdensity scalar" begin
y = @inferred add_logdensity(1, 2)
Expand All @@ -9,26 +9,32 @@
@test y == [3]
y = @inferred add_logdensity([1, 2], 1)
@test y == [2, 3]
y = @inferred add_logdensity(1, CuArray([1, 2]))
@test y == CuArray([2, 3])
y = @inferred add_logdensity(CuArray([1, 2]), 1)
@test y == CuArray([2, 3])
if CUDA.functional()
y = @inferred add_logdensity(1, CuArray([1, 2]))
@test y == CuArray([2, 3])
y = @inferred add_logdensity(CuArray([1, 2]), 1)
@test y == CuArray([2, 3])
end
end

@testset "add_logdensity same array type" begin
y = @inferred add_logdensity([1 2; 3 4; 5 6], [1 2])
@test y == [2 4; 4 6; 6 8]
y = @inferred add_logdensity([1 2], [1 2; 3 4; 5 6])
@test y == [2 4; 4 6; 6 8]
y = @inferred add_logdensity(CuArray([1 2; 3 4; 5 6]), CuArray([1 2]))
@test y == CuArray([2 4; 4 6; 6 8])
y = @inferred add_logdensity(CuArray([1 2]), CuArray([1 2; 3 4; 5 6]))
@test y == CuArray([2 4; 4 6; 6 8])
if CUDA.functional()
y = @inferred add_logdensity(CuArray([1 2; 3 4; 5 6]), CuArray([1 2]))
@test y == CuArray([2 4; 4 6; 6 8])
y = @inferred add_logdensity(CuArray([1 2]), CuArray([1 2; 3 4; 5 6]))
@test y == CuArray([2 4; 4 6; 6 8])
end
end

@testset "add_logdensity different array type" begin
y = @inferred add_logdensity([1 2; 3 4; 5 6], CuArray([1 2]))
@test y == [2 4; 4 6; 6 8]
y = @inferred add_logdensity([1 2], CuArray([1 2; 3 4; 5 6]))
@test y == [2 4; 4 6; 6 8]
if CUDA.functional()
@testset "add_logdensity different array type" begin
y = @inferred add_logdensity([1 2; 3 4; 5 6], CuArray([1 2]))
@test y == [2 4; 4 6; 6 8]
y = @inferred add_logdensity([1 2], CuArray([1 2; 3 4; 5 6]))
@test y == [2 4; 4 6; 6 8]
end
end

0 comments on commit fcd5deb

Please sign in to comment.