From 40d5d7a4f83d4d7297c1065f2870929c69074b36 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 29 Jul 2013 12:58:14 -0400 Subject: [PATCH] Make offset/subscript code gen work in the presence of complex numbers (see added comments) --- loopy/codegen/expression.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/loopy/codegen/expression.py b/loopy/codegen/expression.py index 0ef370ba2..a672c55c2 100644 --- a/loopy/codegen/expression.py +++ b/loopy/codegen/expression.py @@ -695,7 +695,13 @@ class LoopyCCodeMapper(RecursiveMapper): self.join_rec(" + ", expr.children, PREC_SUM, type_context), enclosing_prec, PREC_SUM) - if not self.allow_complex: + # I've added 'type_context == "i"' because of the following + # idiotic corner case: Code generation for subscripts comes + # through here, and it may involve variables that we know + # nothing about (offsets and such). If we fall into the allow_complex + # branch, we'll try to do type inference on these variables, + # and stuff breaks. This band-aid works around that. -AK + if not self.allow_complex or type_context == "i": return base_impl(expr, enclosing_prec, type_context) tgt_dtype = self.infer_type(expr) @@ -730,7 +736,13 @@ class LoopyCCodeMapper(RecursiveMapper): self.join_rec(" * ", expr.children, PREC_PRODUCT, type_context), enclosing_prec, PREC_PRODUCT) - if not self.allow_complex: + # I've added 'type_context == "i"' because of the following + # idiotic corner case: Code generation for subscripts comes + # through here, and it may involve variables that we know + # nothing about (offsets and such). If we fall into the allow_complex + # branch, we'll try to do type inference on these variables, + # and stuff breaks. This band-aid works around that. -AK + if not self.allow_complex or type_context == "i": return base_impl(expr, enclosing_prec, type_context) tgt_dtype = self.infer_type(expr) -- GitLab