Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


array expressions #144

wants to merge 56 commits into from

2 participants


Element-wise array expressions for Cython

markflorisson88 added some commits
@markflorisson88 markflorisson88 Split buffer and memoryview operations from IndexNode fbae57b
@markflorisson88 markflorisson88 Split analyse_types of IndexNode some more 26d7c28
@markflorisson88 markflorisson88 Fix copy/copy_fortran return type & tests 1df5077
@markflorisson88 markflorisson88 Refactor memoryview dtype validation 98d0d60
@markflorisson88 markflorisson88 Fix transpose memoryview type 36f037b
@markflorisson88 markflorisson88 Refactor slice assignment and copying 922af21
@markflorisson88 markflorisson88 Fix python 3 import 9536b62
@markflorisson88 markflorisson88 Start on elementwise expressions 6244394
@markflorisson88 markflorisson88 Allow strided memoryviews to be copied to contiguous memoryviews 148c290
@markflorisson88 markflorisson88 Specialize for contiguous operands 9b0fc9e
@markflorisson88 markflorisson88 Add minivect as submodule 1217a97
@markflorisson88 markflorisson88 Choose typedefed type in widest_numeric_type & support tyepdef Cython…
… types in vector expressions
@markflorisson88 markflorisson88 Allow arbitrary Cython types compatible with C expressions as vector …
…expression dtypes
@markflorisson88 markflorisson88 Support complex numbers in vector expressions 1e53ae2
@markflorisson88 markflorisson88 Support objects in vector expressions 451c802
@markflorisson88 markflorisson88 Use array funcarg method f4496bc
@markflorisson88 markflorisson88 Select specialization at runtime & support broadcasting b8ab0f3
@markflorisson88 markflorisson88 Support overlapping memory and broadcasting assignment
    (Avoid recomputation along broadcasting axes)
    (Need some tests)
@markflorisson88 markflorisson88 DECREF lhs in slice assignment w/ dtype object c4e72cf
@markflorisson88 markflorisson88 Don't choose contig specialization for broadcasting operations known …
…at compile time
@markflorisson88 markflorisson88 Remove broadcasting leading dimensions from RHS 48672b0
@markflorisson88 markflorisson88 Split vector expression tests & add runtime broadcasting test bc22f9f
@markflorisson88 markflorisson88 Select specialization at runtime 32e6671
@markflorisson88 markflorisson88 Support tiling specializations aae2d35
@markflorisson88 markflorisson88 Let the LHS participate in determining array layout order b13c9e2
@markflorisson88 markflorisson88 Implement a code cache 46fe298
@markflorisson88 markflorisson88 Support scalar arguments a02e733
@markflorisson88 markflorisson88 Support unary operations d640297
@markflorisson88 markflorisson88 Support non-slice array expression assignment 62f8783
@markflorisson88 markflorisson88 Support non-assignment array expressions ce10532
@markflorisson88 markflorisson88 Fix broadcasting & add omitted tests 0653f04
@markflorisson88 markflorisson88 Support restrict and const qualifiers for array expression arguments 6a6e9a7
@markflorisson88 markflorisson88 Support inner-contiguous specialization selection 94ddebd
@markflorisson88 markflorisson88 Map more types to minivect, change qualify to use immutable types e19b8a7
@markflorisson88 markflorisson88 Support OpenMP in array expressions d22b3c4
@markflorisson88 markflorisson88 Filter duplicate expression arguments ef46dfd
@markflorisson88 markflorisson88 Add auto-tuner for square tiling blocksize (+caching) 2182b34
@markflorisson88 markflorisson88 Name mangle all variable and function names in the tiling utility code 842952f
@markflorisson88 markflorisson88 Make tiling blocksize type signed (avoid compiler warnings about sign…
…ed/unsigned comparison)
@markflorisson88 markflorisson88 Divide tiling blocksize by itemsize 5c8409c
@markflorisson88 markflorisson88 Auto-tune OpenMP size e413b45
@markflorisson88 markflorisson88 Test various binary operators dd455de
@markflorisson88 markflorisson88 Support (partial) elementwise function calls b42b157
@markflorisson88 markflorisson88 Avoid tiled specializations if all operands are C or F contig d41d090
@markflorisson88 markflorisson88 Support vectorized specializations ebc8850
@markflorisson88 markflorisson88 Add support for graphviz AST visualisation c596986
@markflorisson88 markflorisson88 Use more sensible output filenames for graphviz .dot files 7c5f2f2
@markflorisson88 markflorisson88 Only print debug code for expression 1ef2ebd
@markflorisson88 markflorisson88 Add variable resolving mixin class adbb911
@markflorisson88 markflorisson88 Fix code caching for array expressions 53b77f7
@markflorisson88 markflorisson88 Omit type information for graphviz 1719bdb
@markflorisson88 markflorisson88 Resolve non-external typedefs for array expressions d146ac7
@markflorisson88 markflorisson88 Add some more documentation 4ae867f
@markflorisson88 markflorisson88 Create minivect function type for function calls bdaeea5
@scoder scoder referenced this pull request

refactor indexnode2 #137

@robertwb robertwb commented on the diff
((24 lines not shown))
+# Print generated minivect code
+_debug = False
+# Generate debug calls from specialized functions
+_context_debug = False
+### Graphviz related things. .dot files are only written when write_graphviz
+### is true.
+graphviz_out_filename_unspecialized = os.path.expanduser("~/")
+graphviz_out_filename = os.path.expanduser("~/")
+write_graphviz = False
+# Macro that should be defined to enable explicit vectorization
+cython_vector_size = "CYTHON_VECTOR_SIZE"
@robertwb Owner

Meaning of this value?

@markflorisson88 Collaborator

Compiling with -DCYTHON_VECTOR_SIZE=X enables vectorization, with 4 meaning SSE2 (4 floats), and 8 meaning AVX (8 floats).

The new branch is called _array_expressions_rebased, but the py3k build segfaults with a refcount error. I still need to investigate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@robertwb robertwb commented on the diff
((43 lines not shown))
+ Map Cython types to minitypes.
+ """
+ def map_type(self, type, wrap=False):
+ if type.is_typedef:
+ if type.typedef_is_external:
+ return minitypes.TypeWrapper(type, self.context)
+ else:
+ type = type.resolve()
+ if type.is_memoryviewslice:
+ dtype = self.map_type(type.dtype, wrap=wrap)
+ return minitypes.ArrayType(dtype, len(type.axes),
+ is_c_contig=type.is_c_contig,
+ is_f_contig=type.is_f_contig)
+ elif type.is_float:
@robertwb Owner

Would these be better expressed as a dictionary?

@markflorisson88 Collaborator

Yes I think that would be nicer.

@markflorisson88 Collaborator

Oh I remember why I didn't do that now. It's because you can create new types, and for instance c_sint_type and c_int_type are the same, but don't compare equal (I'm not sure why?).

@robertwb Owner

Like typedefs I guess. Does this then assume you know the exact size at compile time? Hmm...

@markflorisson88 Collaborator

No, it needs that only for the LLVM backend (which isn't used by Cython). It uses the external typedef name if the typedef is external, otherwise it uses the actual types to allow code reuse of expressions of equivalent types. I got everything working, except for one pyximport test, but I think that might be my test setup. I'll try a new PR next weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@robertwb robertwb commented on the diff
((959 lines not shown))
+ code.putln("else {")
+ code.putln("/* Strided specializations */")
+ self.put_ordered_specializations(code, specializers.StridedSpecializer,
+ specializers.StridedFortranSpecializer)
+ if if_clause != "if":
+ code.putln("}")
+ def generate_result_code(self, code):
+ "Generate a branch and call to each specialization"
+ contig, mixed_contig, c_contig, f_contig = all_c_or_f_contig(self.operands)
+ self.context.original_cython_code = code
+ if_clause = "if"
@robertwb Owner

unused code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

In my (albeit somewhat cursory) perusal of the code, I think it looks good. Is there any way to test that your code is being used (i.e. unnecessary intermediates are not being created) as well as getting the correct output? (Perhaps an object type that prints out arithmetic operations could verify the expected sequence of operations, though this might be too much subject to change). Also, it'd be good to have a link somewhere to your thesis or other high-level overview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 23, 2012
  1. @markflorisson88
  2. @markflorisson88
  3. @markflorisson88
  4. @markflorisson88
  5. @markflorisson88
  6. @markflorisson88
  7. @markflorisson88

    Fix python 3 import

    markflorisson88 authored
  8. @markflorisson88
  9. @markflorisson88
  10. @markflorisson88
  11. @markflorisson88
  12. @markflorisson88
  13. @markflorisson88
  14. @markflorisson88
  15. @markflorisson88
  16. @markflorisson88
  17. @markflorisson88
  18. @markflorisson88

    Support overlapping memory and broadcasting assignment

    markflorisson88 authored
        (Avoid recomputation along broadcasting axes)
        (Need some tests)
  19. @markflorisson88
  20. @markflorisson88
  21. @markflorisson88
  22. @markflorisson88
  23. @markflorisson88
  24. @markflorisson88
  25. @markflorisson88
  26. @markflorisson88

    Implement a code cache

    markflorisson88 authored
  27. @markflorisson88
  28. @markflorisson88
  29. @markflorisson88
  30. @markflorisson88
  31. @markflorisson88
  32. @markflorisson88
  33. @markflorisson88
  34. @markflorisson88
  35. @markflorisson88
  36. @markflorisson88
  37. @markflorisson88
  38. @markflorisson88
  39. @markflorisson88
  40. @markflorisson88
  41. @markflorisson88

    Auto-tune OpenMP size

    markflorisson88 authored
  42. @markflorisson88
  43. @markflorisson88
  44. @markflorisson88
  45. @markflorisson88
  46. @markflorisson88
  47. @markflorisson88
Commits on Aug 1, 2012
  1. @markflorisson88
Commits on Aug 5, 2012
  1. @markflorisson88
Commits on Aug 11, 2012
  1. @markflorisson88
Commits on Aug 13, 2012
  1. @markflorisson88
Commits on Aug 21, 2012
  1. @markflorisson88
Commits on Aug 23, 2012
  1. @markflorisson88
Commits on Sep 16, 2012
  1. @markflorisson88
Commits on Oct 14, 2012
  1. @markflorisson88
  2. @markflorisson88
Something went wrong with that request. Please try again.