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

Mark Florisson Robert Bradshaw
Mark Florisson

Element-wise array expressions for Cython

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

refactor indexnode2 #137

Robert Bradshaw 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"
Robert Bradshaw Owner

Meaning of this value?

Mark Florisson 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
Robert Bradshaw 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:
Robert Bradshaw Owner

Would these be better expressed as a dictionary?

Mark Florisson Collaborator

Yes I think that would be nicer.

Mark Florisson 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?).

Robert Bradshaw Owner

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

Mark Florisson 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
Robert Bradshaw 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"
Robert Bradshaw Owner

unused code

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

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. Mark Florisson
  2. Mark Florisson
  3. Mark Florisson
  4. Mark Florisson
  5. Mark Florisson
  6. Mark Florisson
  7. Mark Florisson

    Fix python 3 import

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

    Support overlapping memory and broadcasting assignment

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

    Implement a code cache

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

    Auto-tune OpenMP size

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