File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 519
519
520
520
@inline function to_rarray (@nospecialize (x); track_numbers:: Union{Bool,Tuple} = ())
521
521
track_numbers isa Bool && (track_numbers = track_numbers ? (Number,) : ())
522
+ return to_rarray_internal (x, track_numbers)
523
+ end
524
+
525
+ @inline function to_rarray_internal (@nospecialize (x), track_numbers:: Tuple )
522
526
return make_tracer (OrderedIdDict (), x, (), Reactant. ArrayToConcrete; track_numbers)
523
527
end
524
528
525
- to_rarray (x:: ReactantPrimitive ) = ConcreteRArray (x)
529
+ function to_rarray_internal (@nospecialize (:: TracedRArray ), :: Tuple )
530
+ error (" Cannot convert TracedRArray to ConcreteRArray" )
531
+ end
532
+ @inline to_rarray_internal (@nospecialize (x:: ConcreteRArray ), :: Tuple ) = x
533
+ @inline function to_rarray_internal (
534
+ @nospecialize (x:: AbstractArray{<:ReactantPrimitive} ), :: Tuple
535
+ )
536
+ return ConcreteRArray (x)
537
+ end
538
+
539
+ @inline to_rarray_internal (@nospecialize (x:: ConcreteRNumber ), :: Tuple ) = x
540
+ @inline function to_rarray_internal (
541
+ @nospecialize (x:: ReactantPrimitive ), track_numbers:: Tuple
542
+ )
543
+ for T in track_numbers
544
+ typeof (x) <: T && return ConcreteRNumber (x)
545
+ end
546
+ return x
547
+ end
Original file line number Diff line number Diff line change @@ -100,4 +100,18 @@ using Test
100
100
end
101
101
end
102
102
end
103
+
104
+ @testset " specialized dispatches" begin
105
+ @test @inferred Union{Float64,ConcreteRArray{Float64}} Reactant. to_rarray (
106
+ 1.0 ; track_numbers= (Number,)
107
+ ) isa ConcreteRNumber
108
+ @test @inferred Reactant. to_rarray (1.0 ) isa Float64
109
+ @test @inferred Reactant. to_rarray (rand (3 )) isa ConcreteRArray
110
+
111
+ x_ra = Reactant. to_rarray (rand (3 ))
112
+ @test @inferred Reactant. to_rarray (x_ra) isa ConcreteRArray
113
+
114
+ x_ra = Reactant. to_rarray (1.0 ; track_numbers= (Number,))
115
+ @test @inferred Reactant. to_rarray (x_ra) isa ConcreteRNumber
116
+ end
103
117
end
You can’t perform that action at this time.
0 commit comments