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 563
563
564
564
@inline function to_rarray (@nospecialize (x); track_numbers:: Union{Bool,Tuple} = ())
565
565
track_numbers isa Bool && (track_numbers = track_numbers ? (Number,) : ())
566
+ return to_rarray_internal (x, track_numbers)
567
+ end
568
+
569
+ @inline function to_rarray_internal (@nospecialize (x), track_numbers:: Tuple )
566
570
return make_tracer (OrderedIdDict (), x, (), Reactant. ArrayToConcrete; track_numbers)
567
571
end
568
572
569
- to_rarray (x:: ReactantPrimitive ) = ConcreteRArray (x)
573
+ function to_rarray_internal (@nospecialize (:: TracedRArray ), :: Tuple )
574
+ return error (" Cannot convert TracedRArray to ConcreteRArray" )
575
+ end
576
+ @inline to_rarray_internal (@nospecialize (x:: ConcreteRArray ), :: Tuple ) = x
577
+ @inline function to_rarray_internal (
578
+ @nospecialize (x:: AbstractArray{<:ReactantPrimitive} ), :: Tuple
579
+ )
580
+ return ConcreteRArray (x)
581
+ end
582
+
583
+ @inline to_rarray_internal (@nospecialize (x:: ConcreteRNumber ), :: Tuple ) = x
584
+ @inline function to_rarray_internal (
585
+ @nospecialize (x:: ReactantPrimitive ), track_numbers:: Tuple
586
+ )
587
+ for T in track_numbers
588
+ typeof (x) <: T && return ConcreteRNumber (x)
589
+ end
590
+ return x
591
+ 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