Commit Graph

122 Commits

Author SHA1 Message Date
mwojcik 0ba0330b53 compiler: support free subkernel message passing 2024-01-31 11:46:07 +08:00
mwojcik 0a750c77e8 compiler: support subkernels 2023-10-08 17:11:51 +08:00
Jonathan Coates 5c85cef0c2
Allow indexing tuples in kernel code
This only allows for indexing with a constant value (e.g. x[0]).

While slices would be possible to implement, it's not clear how to
preserve type inference here. The current typing rule is:

  Γ ⊢ x : τ  Γ ⊢ a : Int  Γ ⊢ b : Int
  ------------------------------------
             Γ ⊢ x[a:b] : τ

However, tuples would require a different typing rule, and so we'd need
to defer type inference if τ is a tyvar. I'm not confident that this
won't change behaviour, so we leave as-is for now.

Signed-off-by: Jonathan Coates <jonathan.coates@oxionics.com>
2023-09-12 14:43:38 +01:00
pca006132 822e8565f7 compiler: supports kernel decorators with path 2021-07-02 17:01:31 +08:00
David Nadlinger b8cd163978 compiler: Fix type inference for "ternary" if expressions
Previously, any type would be accepted for the test expression,
leading to internal errors in the code generator if the passed
value wasn't in fact a bool.
2021-03-20 00:27:25 +00:00
David Nadlinger 5ba22c11c3 compiler: Change type inference rules for empty array() calls
array([...]), the constructor for NumPy arrays, currently has the
status of some weird kind of macro in ARTIQ Python, as it needs
to determine the number of dimensions in the resulting array
type, which is a fixed type parameter on which inference cannot
be performed.

This leads to an ambiguity for empty lists, which could contain
elements of arbitrary type, including other lists (which would
add to the number of dimensions).

Previously, I had chosen to make array([]) to be of completely
indeterminate type for this reason. However, this is different
to how the call behaves in host NumPy, where this is a well-formed
call creating an empty 1D array (or 2D for array([[], []]), etc.).

This commit adds special matching for (recursive lists of) empty
ListT AST nodes to treat them as scalar dimensions, with the
element type still unknown.

This also happens to fix type inference for embedding empty 1D
NumPy arrays from host object attributes, although multi-dimensional
arrays will still require work (see GitHub #1633).

GitHub: Fixes #1626.
2021-03-14 22:48:43 +00:00
David Nadlinger c707ccf7d7 compiler: Properly implement NumPy array slicing
Strided slicing of one-dimensional arrays (i.e. with non-trivial
steps) might have previously been working, but would have had
different semantics, as all slices were copies rather than a view
into the original data.

Fixing this in the future will require adding support for an index
stride field/tuple to our array representation (and all the
associated indexing logic).

GitHub: Fixes #1627.
2021-03-14 20:02:59 +00:00
David Nadlinger 557671b7db compiler: Fix type inference in slice expressions
This was a long-standing issue affecting both lists and
the new NumPy array implementation, just caused by the
generic inference passes not being run on the slice
subexpressions (and thus e.g. ints not being monomorphized).

GitHub: Fixes #1632.
2021-03-14 18:46:28 +00:00
Sebastien Bourdeauducq 072053c3b2 compiler: remove obsolete watchdog code (#1458) 2020-12-08 13:25:08 +08:00
David Nadlinger d95e619567 compiler: Implement binary NumPy math functions (arctan2, …)
The bulk of the diff is just factoring out the implementation
for binary arithmetic implementations, to be reused for binary
function calls.
2020-11-11 01:35:28 +01:00
David Nadlinger d161fd5d84 compiler: Properly expand dimensions for array([]) with ndarray elements
This matches host NumPy behaviour (and, in either case, was
previously broken, as it still continued past the array element
type).
2020-10-20 01:40:14 +02:00
David Nadlinger 94489f9183 compiler: Fix inference order issue in multi-dim. subscript
This will be caught by the test for an imminent array quoting fix.
2020-10-20 01:40:14 +02:00
David Nadlinger daf57969b2 compiler: Do not expand strings into TInt(8)s in array() 2020-08-09 23:46:45 +01:00
David Nadlinger 778f2cf905 compiler: Fix numpy.full, implement for >1D 2020-08-09 23:46:45 +01:00
David Nadlinger 53d64d08a8 compiler: Fix multi-dim slice error message test, tweak wording 2020-08-09 23:14:56 +01:00
David Nadlinger 33d931a5b7 compiler: Implement multi-dimensional indexing of arrays
This generates rather more code than necessary, but has
the advantage of automatically handling incomplete
multi-dimensional subscripts which still leave arrays
behind.
2020-08-09 17:08:43 +01:00
David Nadlinger b00ba5ece1 compiler: Support explicit array(…, dtype=…) syntax 2020-08-09 17:08:43 +01:00
David Nadlinger 5472e830f6 compiler: Assume array()s are always rectangular 2020-08-09 03:54:42 +01:00
David Nadlinger cc00ae9580 compiler: Implement broadcasting of math functions 2020-08-09 03:54:42 +01:00
David Nadlinger be7d78253f compiler: Implement 1D-/2D- array transpose
Left generic transpose (shape order inversion) for now, as that
would be less ugly if we implement forwarding to Python function
bodies for array function implementations.

Needs a runtime test case.
2020-08-09 03:54:42 +01:00
David Nadlinger faea886c44 compiler: Implement array vs. scalar broadcasting 2020-08-09 03:54:42 +01:00
David Nadlinger 78afa2ea8e compiler: Support MatMult in inferencer
Still needs actual codegen support.
2020-08-09 03:54:42 +01:00
David Nadlinger 4426e4144f compiler: Implement unary plus/minus for arrays
Implementation is needlessly generic to anticipate
coercion/transcendental functions.
2020-08-09 03:54:41 +01:00
David Nadlinger e77c7d1c39 compiler: Add inferencer support for array operations 2020-08-09 03:54:41 +01:00
David Nadlinger cb1cadb46a compiler: Fix/test 1D array construction from generic iterables 2020-08-09 03:54:41 +01:00
David Nadlinger c95a978ab6 compiler: Iteration for 1D ndarrays 2020-08-09 03:54:41 +01:00
David Nadlinger bc17bb4d1a compiler: Parametrize TArray in number of dimensions 2020-08-09 03:54:41 +01:00
David Nadlinger 56010c49fb compiler/inferencer: Detect rectangular array()s
Still needs support through all the rest of the compiler, and
support for higher-dimensional arrays.

Alternatively, we could always assume ndarrays of ndarrays
are rectangular (i.e. ban array/list element types), and
detect mismatch at runtime. This might turn out to be
preferrable to be able to construct matrices from rows/columns.

`array()` is disallowed for no particularly good reason but
numpy API compatibility.
2020-08-09 03:54:41 +01:00
David Nadlinger cdaf554736 compiler: Implement abs() for scalars
GitHub: Fixes #1303.
2019-04-13 13:39:16 +08:00
whitequark 58967f14fd compiler: do not try to re-coerce fully coerced numerics. 2018-04-21 18:25:52 +00:00
whitequark 86ceee570f compiler: reject calls with unexpected keyword arguments.
Fixes #924.
2018-02-21 11:37:12 +00:00
whitequark 4d915ad15b compiler: do not permit str(...). (#878) 2017-12-27 03:10:50 +00:00
whitequark ad2ee714c2 compiler: do not permit iterating str values.
This currently breaks badly on UTF-8, and doesn't even return
a value of a correct type.
2017-06-09 07:29:31 +00:00
whitequark e9564b15c8 compiler: add support for bytearray type (#714). 2017-06-09 07:15:24 +00:00
whitequark 5b4fde30a8 compiler: unbreak subscripts for bytes values (#714). 2017-06-09 07:10:48 +00:00
whitequark 778e7dc2ab compiler: add support for concatenating bytes values (#714). 2017-06-09 07:10:48 +00:00
whitequark 31048f4b6a compiler: fix monomorphization of coerced integer literals.
Fixes #703.
2017-04-12 04:11:47 +00:00
whitequark 7e886ddc89 transforms.inferencer: do not unnecessarily mutate typedtree.
This caused the hash to change after every iteration of inference,
if the result of any coercion was an integer of indefinite width.
2017-03-02 16:15:37 +00:00
whitequark 68de724554 compiler: monomorphize int64(round(x)) to not lose precision.
This applies to any expression with an indeterminate integer type
cast to int64(), not just round().
2016-12-02 15:02:44 +00:00
whitequark 55ea68da7f compiler: unbreak casts to int32/int64. 2016-11-21 14:20:28 +00:00
whitequark 35f4449ef2 inferencer: significantly improve the op-assignment diagnostic.
Before this commit, it displayed incorrect output if an error
appeared on 2nd run and beyond, and displayed messages for trying
to do "num32 -= num64" that made very little sense.
2016-11-21 14:20:24 +00:00
whitequark 009d396740 Move mu_to_seconds, seconds_to_mu to Core. 2016-11-21 05:37:30 +00:00
whitequark 1a518ea7eb compiler.embedding: implement string concatenation.
Fixes #526.
2016-08-08 04:05:52 +00:00
whitequark d90fd7dc00 compiler: implement numpy.full (#424). 2016-07-07 06:33:38 +00:00
whitequark 933ea53c77 compiler: add basic numpy array support (#424). 2016-07-06 09:51:57 +00:00
whitequark 906db876a6 language: replace coredevice int with numpy.{int32,int64}.
Fixes #453.
2016-07-06 04:44:21 +00:00
whitequark fa71b40c80 compiler: print the builtin type int(width=...) as np.int... 2016-07-06 04:22:51 +00:00
whitequark 33e8e59cc7 compiler: implement min()/max() as builtins.
Fixes #239.
2016-06-22 01:09:41 +00:00
whitequark 26117e8d93 transforms.inferencer: allow variable as type of `n` in `[]*n`.
Fixes #473.
2016-06-16 13:35:00 +00:00
whitequark 355af3e569 embedding: specialize inherited functions.
Fixes #414.
2016-05-16 15:59:26 +00:00