Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds an implementation using Python interfaces and python functions, instead of using MatchPy.
The array algorithms are type dispatching functions with a default implementation that works with generic arrays.
The idea was that since we are writing in Python, let's not reinvent what it means to be a function and instead just write our functions imperatively in Python. So instead of writing things like
If(LessThan(x, Int(2)), ...)
we writeif x < 2: ...
. We restrict ourselves to a subset of Python types,Array
s,Naturals
' (see./uarray/native/typing.py
for their definitions), and operations on integers. Then, given those types we build up MoA and NumPy semantics with functions on those types.This approach is a lot easier to write and follow than the other of writing symbolic expressions, because we don't have to invent a new language/world to live in, we just use the Python one.
"But how would we use this code to compile array algorithms to xxx (C, LLVM, Tensorflow)?" is the obvious question though. The reason I stayed away from doing things this way, was that then you have these opaque Python functions with control flow in them, and if you want to compile that to another backend then you have to somehow interpret those. Whereas, if you build everything up in MatchPy, you limit what is possible from the get-go, you don't get the freedom of the Python language. So yes, for this approach to be performant in any way, we would have to use/build something that could take these Python functions and re-interpret them as array expressions. Something a little like Numba, but also very different in scope.
From a high level, to compile/optimize these types of expressions would require at least three things:
if
statement and know it's condition, then we can replace it)if
) need to be compiled to the target language, like LLVM.Pros of this approach:
Cons of this approach:
My current recommendation: