Skip to content

Commit 8b77ba7

Browse files
lukstaficlaude
andcommitted
Handle corner case in iterated variable processing
When processing deferred iterated variables, if the variable maps to another Var that also has no projection, the second variable would be added to iterated_vars but not processed (since we're already iterating). Fix: Reset iterated_vars before processing, then check if any new variables were added during iteration - these indicate broken projection chains and should raise an error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 965ac81 commit 8b77ba7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tensor/row.ml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,17 +3864,23 @@ let%debug4_sexp solve_proj_equations (eqs : proj_equation list)
38643864
iterated_vars := v :: !iterated_vars
38653865
| Some proj -> loop @@ Iterated proj)
38663866
in
3867+
let no_proj_assigned v =
3868+
raise
3869+
@@ Shape_error
3870+
( "Iterated variable has no projection assigned: "
3871+
^ Sexp.to_string_hum ([%sexp_of: dim_var] v),
3872+
[] )
3873+
in
38673874
List.iter eqs ~f:loop;
38683875
(* Process deferred iterated variables: they should now have projections assigned *)
3869-
List.iter !iterated_vars ~f:(fun v ->
3876+
let pending_vars = !iterated_vars in
3877+
iterated_vars := [];
3878+
List.iter pending_vars ~f:(fun v ->
38703879
match Hashtbl.find v_env v with
3871-
| None ->
3872-
raise
3873-
@@ Shape_error
3874-
( "Iterated variable has no projection assigned: "
3875-
^ Sexp.to_string_hum ([%sexp_of: dim_var] v),
3876-
[] )
3880+
| None -> no_proj_assigned v
38773881
| Some proj -> loop @@ Iterated proj);
3882+
(* Any variables added during the above iteration have no valid projection chain *)
3883+
List.iter !iterated_vars ~f:no_proj_assigned;
38783884
let projs = ref @@ Map.empty (module Proj_id) in
38793885
List.iter !p_solved ~f:(fun (p, idx) ->
38803886
let repr, _ = Utils.union_find ~equal:Proj_id.equal !proj_classes ~key:p ~rank:0 in

0 commit comments

Comments
 (0)