Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export default defineConfig({
{ text: "Profiling", link: "/tutorials/profiling" },
{ text: "Distributed", link: "/tutorials/multihost" },
{ text: "Local build", link: "/tutorials/local-build" },
{ text: "Control Flow", link: "/tutorials/control-flow" },
],
}
],
Expand Down
26 changes: 21 additions & 5 deletions lib/ReactantCore/src/ReactantCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@
$(cond_fn_sym),
$(body_fn_sym),
$(args_sym);
track_numbers=$(track_numbers),
verify_arg_names=$(verify_arg_names_sym),
track_numbers=($(track_numbers)),
verify_arg_names=($(verify_arg_names_sym)),
)
end
end
Expand Down Expand Up @@ -289,10 +289,26 @@
end
end

quote
return quote
local $start_sym, $limit_sym, $step_sym
$bounds_defs
local $counter = 0

if $(within_compile)()
$start_sym = Reactant.TracedUtils.promote_to(
Reactant.TracedRNumber{Reactant.unwrapped_eltype(typeof($start_sym))},
$start_sym,
)
$limit_sym = Reactant.TracedUtils.promote_to(
Reactant.TracedRNumber{Reactant.unwrapped_eltype(typeof($limit_sym))},
$limit_sym,

Check warning on line 303 in lib/ReactantCore/src/ReactantCore.jl

View check run for this annotation

Codecov / codecov/patch

lib/ReactantCore/src/ReactantCore.jl#L303

Added line #L303 was not covered by tests
)
$step_sym = Reactant.TracedUtils.promote_to(
Reactant.TracedRNumber{Reactant.unwrapped_eltype(typeof($step_sym))},
$step_sym,
)
end

local $counter = zero($start_sym)

$(trace_while(
Expr(
Expand Down Expand Up @@ -471,7 +487,7 @@
$(true_branch_fn_name),
$(false_branch_fn_name),
($(all_input_vars...),);
track_numbers=$(track_numbers),
track_numbers=($(track_numbers)),
)
end

Expand Down
23 changes: 22 additions & 1 deletion test/control_flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ function condition_with_structure(x)
@trace if sum(y) > 0
z = (; a=y, b=(y .- 1, y))
else
z = (; a=-y, b=(y, y .+ 1))
z = (; a=(-y), b=(y, y .+ 1))
end
return z
end
Expand Down Expand Up @@ -676,6 +676,27 @@ function while_convergence(x, y)
return diff
end

function for_no_track_numbers(x, n)
@trace track_numbers = false for i in n:16
x = x .+ 1
end
return x
end

@testset "for: track_numbers=false" begin
x = [1, 2, 3]
x_ra = Reactant.to_rarray(x)

n = 12
n_ra = Reactant.ConcreteRNumber(n)

# set optimize to only do enzyme-batch to prevent crash in opt
for_no_track_numbers_ra = @compile optimize="enzyme-batch" for_no_track_numbers(
x_ra, n_ra
)
for_no_track_numbers_ra(x_ra, n_ra) == for_no_track_numbers(x, n)
end

@testset "while: convergence" begin
x = [1.0, 10.0, 20.0]
y = [0.0, -2.0, -3.0]
Expand Down
Loading