Skip to content

Commit 2bf3aec

Browse files
committed
test: update semantically incorrest cosine tests
1 parent e0c671f commit 2bf3aec

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

test/basic.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ end
9494
@test f_res r_res
9595
end
9696

97+
bcast_cos(x) = cos.(x)
98+
9799
@testset "Basic cos" begin
98100
x = rand(3, 2)
99101
c = Reactant.ConcreteRArray(x)
100102

101-
f = @compile cos(c)
103+
f = @compile bcast_cos(c)
102104
r = f(c)
103105
@test r cos.(x)
104106
end
@@ -137,7 +139,7 @@ end
137139
function mul(A, B)
138140
return A * B
139141
end
140-
@testset "Basic grad cos" begin
142+
@testset "matmul" begin
141143
c = Reactant.ConcreteRArray(ones(50, 70))
142144
d = Reactant.ConcreteRArray(ones(70, 30))
143145

test/struct.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ MockTensor(data::A, inds) where {T,N,A<:AbstractArray{T,N}} = MockTensor{T,N,A}(
1111
Base.parent(t::MockTensor) = t.data
1212
Base.size(t::MockTensor) = size(parent(t))
1313

14-
Base.cos(x::MockTensor) = MockTensor(cos(parent(x)), x.inds)
14+
Base.cos(x::MockTensor) = MockTensor(cos.(parent(x)), x.inds)
15+
bcast_cos(x::MockTensor) = cos(x)
1516

1617
mutable struct MutableMockTensor{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N}
1718
data::A
@@ -24,7 +25,10 @@ end
2425
Base.parent(t::MutableMockTensor) = t.data
2526
Base.size(t::MutableMockTensor) = size(parent(t))
2627

27-
Base.cos(x::MutableMockTensor) = MutableMockTensor(cos(parent(x)), x.inds)
28+
Base.cos(x::MutableMockTensor) = MutableMockTensor(cos.(parent(x)), x.inds)
29+
30+
bcast_cos(x) = cos.(x)
31+
bcast_cos(x::MutableMockTensor) = cos(x)
2832

2933
# modified from JuliaCollections/DataStructures.jl
3034
# NOTE original uses abstract type instead of union, which is not supported
@@ -55,25 +59,25 @@ end
5559
x = MockTensor(rand(4, 4), [:i, :j])
5660
x2 = MockTensor(Reactant.ConcreteRArray(parent(x)), x.inds)
5761

58-
f = @compile cos(x2)
62+
f = @compile bcast_cos(x2)
5963
y = f(x2)
6064

6165
@test y isa MockTensor{Float64,2,Reactant.ConcreteRArray{Float64,2}}
6266
@test size(y) == (4, 4)
63-
@test isapprox(parent(y), cos.(parent(x)))
67+
@test isapprox(parent(y), bcast_cos(parent(x)))
6468
@test x.inds == [:i, :j]
6569
end
6670

6771
@testset "mutable" begin
6872
x = MutableMockTensor(rand(4, 4), [:i, :j])
6973
x2 = MutableMockTensor(Reactant.ConcreteRArray(parent(x)), x.inds)
7074

71-
f = @compile cos(x2)
75+
f = @compile bcast_cos(x2)
7276
y = f(x2)
7377

7478
@test y isa MutableMockTensor{Float64,2,Reactant.ConcreteRArray{Float64,2}}
7579
@test size(y) == (4, 4)
76-
@test isapprox(parent(y), cos.(parent(x)))
80+
@test isapprox(parent(y), bcast_cos(parent(x)))
7781
@test x.inds == [:i, :j]
7882
end
7983
end

0 commit comments

Comments
 (0)