From a99517318120c1d68d6e7703f58f44037bc67a5a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Tue, 15 Mar 2016 13:38:55 -0500 Subject: [PATCH] For 1D arrays, allow undetermined shape in shape determination --- examples/python/sparse.py | 6 +----- loopy/kernel/creation.py | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/python/sparse.py b/examples/python/sparse.py index 14d157b6a..5fba194ef 100644 --- a/examples/python/sparse.py +++ b/examples/python/sparse.py @@ -10,9 +10,5 @@ k = lp.make_kernel([ rowsum = 0 {id=zerosum} rowsum = rowsum + x[-1 + colindices[-1 + rowstart + j]]*values[-1 + rowstart + j] {dep=zerosum} y[i] = rowsum - """, - [ - lp.GlobalArg("colindices,values,x", shape=None), - "..." - ]) + """) print(k) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index 6a5d523e6..830fe0efa 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -914,13 +914,27 @@ def guess_arg_shape_if_requested(kernel, default_order): if armap.access_range is None: if armap.bad_subscripts: - raise RuntimeError("cannot determine access range for '%s': " - "undetermined index in subscript(s) '%s'" - % (arg.name, ", ".join( - str(i) for i in armap.bad_subscripts))) + n_axes_in_subscripts = set( + len(sub.index_tuple) for sub in armap.bad_subscripts) - # no subscripts found, let's call it a scalar - shape = () + if len(n_axes_in_subscripts) != 1: + raise RuntimeError("subscripts of '%s' with differing " + "numbers of axes were found" % arg.name) + + n_axes, = n_axes_in_subscripts + + if n_axes == 1: + # Leave shape undetermined--we can live with that for 1D. + shape = (None,) + else: + raise RuntimeError("cannot determine access range for '%s': " + "undetermined index in subscript(s) '%s'" + % (arg.name, ", ".join( + str(i) for i in armap.bad_subscripts))) + + else: + # no subscripts found, let's call it a scalar + shape = () else: from loopy.isl_helpers import static_max_of_pw_aff from loopy.symbolic import pw_aff_to_expr -- GitLab