Skip to content

Commit 34551e7

Browse files
committed
test: add tests
1 parent b0bdce7 commit 34551e7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/ConcreteRArray.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,9 @@ function Base.fill!(a::ConcreteRArray{T,N}, val) where {T,N}
366366
buf = a.data.buffer
367367
GC.@preserve buf begin
368368
ptr = Base.unsafe_convert(Ptr{T}, XLA.UnsafeBufferPointer(buf))
369-
start = 0
370-
for i in 1:N
371-
start *= size(a, N - i + 1)
372-
start += (args[N - i + 1] - 1)
369+
for start in 0:(length(a) - 1)
370+
unsafe_store!(ptr, val, start)
373371
end
374-
start += 1
375-
unsafe_store!(ptr, val, start)
376372
end
377373
return a
378374
end

test/basic.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,15 @@ end
664664
ifelse(ConcreteRNumber(false), ConcreteRNumber(1.0f0), ConcreteRNumber(0.0f0))
665665
) isa ConcreteRNumber{Float32}
666666
end
667+
668+
@testset "fill! and zero on ConcreteRArray" begin
669+
x_ra = Reactant.to_rarray(rand(3, 4))
670+
671+
z = zero(x_ra)
672+
@test z isa ConcreteRArray
673+
@test size(z) == size(x_ra)
674+
@test all(iszero, Array(z))
675+
676+
fill!(z, 1.0)
677+
@test all(==(1.0), Array(z))
678+
end

0 commit comments

Comments
 (0)