From d15404bbcc2db81840240b5279bc67564228c1a8 Mon Sep 17 00:00:00 2001
From: arghdos <arghdos@gmail.com>
Date: Fri, 5 May 2017 15:31:43 -0400
Subject: [PATCH] ditch _as_strided, as it's causing segfaults in my more
 complicated kernels

---
 loopy/target/c/c_execution.py | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/loopy/target/c/c_execution.py b/loopy/target/c/c_execution.py
index 6e59125a1..0d0e3113a 100644
--- a/loopy/target/c/c_execution.py
+++ b/loopy/target/c/c_execution.py
@@ -97,23 +97,31 @@ class CExecutionWrapperGenerator(ExecutionWrapperGeneratorBase):
                 var("_lpy_shape_%d" % i)
                 for i in range(num_axes))
 
+        # find order of array
+        order = "'C'"
+        if num_axes > 1:
+            ldim = arg.unvec_strides[1]
+            if ldim == arg.unvec_shape[0]:
+                order = "'F'"
+            else:
+                order = "'C'"
+
         gen("%(name)s = _lpy_np.empty(%(shape)s, "
-                "%(dtype)s)"
+                "%(dtype)s, order=%(order)s)"
                 % dict(
                     name=arg.name,
                     shape=strify(sym_shape),
                     dtype=self.python_dtype_str(
-                        kernel_arg.dtype.numpy_dtype)))
+                        kernel_arg.dtype.numpy_dtype),
+                    order=order))
 
         #check strides
-        gen("%(name)s = _lpy_strided(%(name)s, %(shape)s, "
-                "%(strides)s)"
-                % dict(
-                    name=arg.name,
-                    shape=strify(sym_shape),
-                    strides=strify(sym_strides)))
-
         if not skip_arg_checks:
+            gen("assert '%(strides)s == %(name)s.strides', "
+                    "'Strides of loopy created array %(name)s, "
+                    "do not match expected.'" %
+                    dict(name=arg.name,
+                         strides=strify(sym_strides)))
             for i in range(num_axes):
                 gen("del _lpy_shape_%d" % i)
                 gen("del _lpy_strides_%d" % i)
-- 
GitLab