a176c3eb70
core/irrt: Change handle_slice_indices to instead take length of object
...
So that all other array-like datatypes (e.g. ndarray) can also take
advantage of it.
2024-06-03 16:40:05 +08:00
2cf79510c2
core/numpy: Add more helper functions
2024-06-03 16:40:05 +08:00
b6ff75dcaf
core/irrt: Add support for calculating partial size of NDArray
2024-06-03 16:40:05 +08:00
588c15f80d
core/stmt: Add gen_for_range_callback
...
For generating for loops over range objects or array slices.
2024-06-03 16:40:05 +08:00
82cc693b11
meta: Update dependencies
2024-06-03 16:40:02 +08:00
520e1adc56
core/builtins: Add np_minimum/np_maximum
2024-05-09 15:01:20 +08:00
73e81259f3
core/builtins: Add np_min/np_max
2024-05-09 15:01:20 +08:00
7627acea41
core/type_inferencer: Fix error message
2024-05-09 15:01:20 +08:00
a777099ea8
core/type_inferencer: Fix missing lowering for some builtin TVars
2024-05-09 15:01:20 +08:00
30c6cffbad
core/builtins: Refactored numpy builtins to accept scalar and ndarrays
2024-05-06 15:38:29 +08:00
51671800b6
core/builtins: Extract codegen portion into functions
...
We will need to reuse them when implementing elementwise function
application for ndarrays.
2024-05-06 13:21:54 +08:00
7195476edb
core/builtins: Add llvm_intrinsics prefix
2024-05-06 13:21:54 +08:00
eecba0b71d
core: Add GenCall::create_dummy
...
A simple abstraction for GenCalls that are already handled elsewhere.
2024-05-06 13:21:54 +08:00
7b4253ccd8
core/numpy: Add missing lifetime parameters
2024-05-06 13:21:54 +08:00
f58c3a11f8
core/builtins: Rework handling of PrimitiveStore-Unifier tuples
2024-05-06 13:21:54 +08:00
d0766a116f
core: Remove Box from GenCallCallback type alias
...
So that references to the function type can be taken.
2024-05-06 13:21:54 +08:00
64a3751fc2
core: Remove custom function type definitions for ndarray operators
2024-05-06 13:21:54 +08:00
062e318dd5
core/magic_methods: Fix clippy warnings
2024-05-06 13:21:54 +08:00
847615fc2f
core: Implement numpy.matmul for 2D-2D ndarrays
2024-04-23 10:27:37 +08:00
5dfcc63978
core/classes: Take reference of indexes
2024-04-16 17:20:24 +08:00
025b3cd02f
core/stmt: Remove gen_if_chained*
...
Turns out it is really difficult to get lifetimes and closures right, so
let's just provide the most rudimentary if-else codegen and we can nest
them if necessary.
2024-04-16 17:16:50 +08:00
e0f440040c
core/expr: Implement negative indices for ndarray
2024-04-15 12:49:42 +08:00
f0715e2b6d
core/stmt: Add gen_if* functions
...
For generating if-constructs in IR.
2024-04-15 12:20:34 +08:00
e7fca67786
core/stmt: Do not generate jumps if bb is already terminated
...
Future-proofs gen_*_callback functions in case other codegen functions
will delegate to it in the future.
2024-04-15 12:20:34 +08:00
52c731c312
core: Implement Not/UAdd/USub for booleans
...
Not sure if this is deliberate or an oversight, but we implement it
anyway for consistency with other Python implementations.
2024-04-12 18:29:58 +08:00
00d1b9be9b
core: Fix __inv__ for i8-based boolean operands
2024-04-12 15:35:54 +08:00
e614dd4257
core/type_inferencer: Fix location of unary/compare expressions
...
Codegen uses this location information to determine the CallId, and if
a function call is the operand of a unary expression or left-hand
operand of a compare expression, codegen will use the type of the
operator expression rather than the actual operand type.
2024-04-05 15:42:10 +08:00
937a8b9698
core/magic_methods: Fix type of unary ops with primitive types
2024-04-05 13:23:08 +08:00
876ad6c59c
core/type_inferencer: Include location info if inferencer fails
2024-04-05 13:22:35 +08:00
a920fe0501
core: Implement elementwise comparison operators
2024-04-03 00:07:33 +08:00
727a1886b3
core: Implement elementwise unary operators
2024-04-03 00:07:33 +08:00
6af13a8261
core: Implement elementwise binary operators
...
Including immediate variants of these operators.
2024-04-03 00:07:33 +08:00
3540d0ab29
core/magic_methods: Add typeof_*op
...
Used to determine the expected type of the binary operator with
primitive operands.
2024-04-03 00:07:33 +08:00
3a6c53d760
core/toplevel/numpy: Split ndarray type var utilities
2024-04-03 00:07:33 +08:00
87bc34f7ec
core: Implement calculations for broadcasting ndarrays
2024-04-03 00:07:31 +08:00
f50a5f0345
core/type_inferencer: Allow both int32 and isize when indexing ndarray
2024-04-02 16:49:12 +08:00
a77fd213e0
core/magic_methods: Allow unknown return types
...
These types can be later inferred by the type inferencer.
2024-04-02 16:49:12 +08:00
8f1497df83
core/helper: Add PrimitiveDefinitionIds::iter
2024-04-02 16:49:12 +08:00
5ca2dbeec8
core/typedef: Add Type::obj_id to replace get_obj_id
2024-04-02 16:49:10 +08:00
9a98cde595
core: Extract codegen portion of gen_*op_expr
...
This allows *ops to be generated internally using LLVM values as
input. Required in a future change.
2024-04-01 16:48:25 +08:00
5ba8601b39
core: Remove ArrayValue variants of functions
...
These will be lowered and optimized away later anyways, and we have
ArrayLikeAccessor now.
2024-04-01 16:48:25 +08:00
26a01b14d5
core: Use more typed slices in APIs
2024-04-01 16:48:25 +08:00
d5f4817134
core/builtins: Fix len() on ndarrays
2024-04-01 16:48:24 +08:00
789bfb5a26
core: Fix index-based operations not returning i32
2024-04-01 16:46:45 +08:00
4bb0e60981
core: Apply clippy suggestions
2024-04-01 16:46:41 +08:00
13f06f3e29
core: Refactor VarMap to IndexMap
...
This is the only Map I can find that preserves insertion order while
also deduplicating elements by key.
2024-03-22 15:51:23 +08:00
f0da9c0283
core: Add ArrayLikeValue
...
For exposing LLVM values that can be accessed like an array.
2024-03-22 15:51:06 +08:00
2c4bf3ce59
core: Allow unsized CodeGenerator to be passed to some codegen functions
...
Enables codegen_callback to call these codegen functions as well.
2024-03-22 15:07:28 +08:00
e980f19c93
core: Simplify typed value assertions
2024-03-22 15:07:28 +08:00
cfbc37c1ed
core: Add gen_for_callback_incrementing
...
Simplifies generation of monotonically increasing for loops.
2024-03-22 15:07:28 +08:00
50264e8750
core: Add missing unchecked accessors for NDArrayDimsProxy
2024-03-22 15:07:28 +08:00
1b77e62901
core: Split numpy into codegen and toplevel
2024-03-22 15:07:28 +08:00
fd44ee6887
core: Apply clippy suggestions
2024-03-22 15:07:23 +08:00
c8866b1534
core/classes: Rename get_* functions to remove prefix
...
As suggested by Rust API Guidelines.
2024-03-21 15:46:10 +08:00
84a888758a
core: Rename unsafe functions to unchecked
...
This is this intended name of the functions.
2024-03-21 15:46:10 +08:00
c3b122acfc
core: Implement ndarray.copy
2024-03-07 14:59:13 +08:00
a94927a11d
core: Update __builtin_assume expressions
...
No dimension size should be 0.
2024-03-07 14:59:13 +08:00
ebf86cd134
core: Use size_t for accessing array elements
2024-03-07 14:59:13 +08:00
cccd8f2d00
core: Fix ndarray_eye not preserving signness of offset
2024-03-07 14:59:13 +08:00
3292aed099
core: Fix ndarray subscript operator returning the wrong object
...
Should be returning the newly created object instead of the original
ndarray...
2024-03-07 14:59:13 +08:00
96b7f29679
core: Implement ndarray.fill
2024-03-07 14:59:13 +08:00
3d2abf73c8
core: Replace ndarray_init_dims IRRT impl with IR impl
...
Implementation of that function in IR allows for more flexibility in
terms of different integer type widths.
2024-03-07 14:59:13 +08:00
f682e9bf7a
core: Match IRRT compile flavor with build profile
2024-03-07 14:59:02 +08:00
b26cb2b360
core: Express member func def IDs as offsets from class def ID
2024-03-06 12:24:39 +08:00
2317516cf6
core: Use tvars from ndarray for class definition
2024-03-04 23:58:02 +08:00
77de24ef74
core: Use BTreeMap for type variable mapping
...
There have been multiple instances where I had the need to iterate over
type variables, only to discover that the traversal order is arbitrary.
This commit fixes that by adding SortedMapping, which utilizes BTreeMap
internally to guarantee a traversal order. All instances of VarMap are
now refactored to use this to ensure that type variables are iterated in
the order of its variable ID, which should be monotonically incremented
by the unifier.
2024-03-04 23:56:04 +08:00
234a6bde2a
core: Use TObj for NDArray
2024-03-01 15:41:55 +08:00
c3db6297d9
core: Add primitive definition-id list
...
So that we have a single ground truth for the definition IDs of
primitive types.
2024-03-01 11:29:10 +08:00
82fdb02d13
core: Extract LLVM intrinsic functions to their functions
2024-02-23 15:41:06 +08:00
4efdd17513
core: Add missing From implementations for LLVM wrapper classes
2024-02-23 15:41:06 +08:00
49de81ef1e
core: Apply clippy suggestions
2024-02-23 15:41:06 +08:00
8492503af2
core: Update cargo dependencies
2024-02-23 15:41:04 +08:00
cc538d221a
core: Implement codegen for indexing into ndarray
2024-02-19 17:13:09 +08:00
0d5c53e60c
core: Implement type inference for indexing into ndarray
2024-02-19 17:13:09 +08:00
976a9512c1
core: Add const variants to NDArray element getters
2024-02-19 16:56:21 +08:00
1eacaf9afa
core: Fix IRRT argument order to ndarray_flatten_index
2024-02-19 16:37:13 +08:00
8c7e44098a
core: Fix IRRT implementation of ndarray_flatten_index
2024-02-19 16:37:13 +08:00
282a3e1911
core: Fix typo in error message
2024-02-14 16:26:13 +08:00
5cecb2bb74
core: Fix Literal use in variable type annotation
2024-02-06 18:16:14 +08:00
1963c30744
core: Use Display output for locations
2024-02-06 18:11:51 +08:00
27011f385b
core: Add location to non-primitive value return error
2024-02-02 12:49:21 +08:00
d6302b6ec8
core: Allow tuple of primitives to be returned
2024-02-02 12:48:52 +08:00
b3736c3e99
core: Disallow returning of non-primitive values
...
Non-primitive values are represented by an `alloca`-ed value in the
function body, and when the pointer is returned from the function, the
`alloca`-ed object is deallocated on the stack.
Related to #54 .
2024-01-29 12:49:24 +08:00
8470915809
core: Add NDArrayValue and helper functions
2024-01-25 15:51:39 +08:00
148900302e
core: Add RangeValue and helper functions
2024-01-25 15:51:39 +08:00
5ee08b585f
core: Add ListValue and helper functions
2024-01-25 15:51:39 +08:00
f1581299fc
core: Minor changes to IRRT
...
Add missing documentation, remove redundant lifetime variables, and fix
typos.
2024-01-25 15:50:53 +08:00
e3e2c36ef4
core: Mark TNDArray and TLiteral as unimplemented in tests
2024-01-17 09:58:14 +08:00
4f9a0110c4
meta: Update insta snapshots
2024-01-17 09:49:50 +08:00
12c0eed0a3
core: Fix compilation of tests
2024-01-17 09:49:49 +08:00
140f8f8a08
core: Implement most ndarray-creation functions
2023-12-22 16:29:55 +08:00
27fcf8926e
core: Implement ndarray constructor and numpy.empty
2023-12-22 16:29:54 +08:00
afa7d9b100
core: Implement helper for creation of generic ndarray
2023-12-21 15:39:49 +08:00
c395472094
core: Initial infrastructure for ndarray
2023-12-21 15:39:46 +08:00
03870f222d
core: Extract special method handling in type inferencer
...
To prepare for more special handling with methods.
2023-12-21 15:38:26 +08:00
e435b25756
core: Allow implicit promotions of integral literals
...
It should not matter, since it is the value of the literal that matters
with respect to the const generic variable.
2023-12-21 15:21:08 +08:00
bd792904f9
core: Add size_t to primitive store
...
Used for ndims in ndarray.
2023-12-21 15:20:31 +08:00
1c3a823670
core: Do not discard value names for IRRT
2023-12-20 15:16:02 +08:00
9d64e606f4
core: Reject multiple literal bounds
...
This is currently broken due to how we handle function calls in the
unifier.
2023-12-18 10:04:25 +08:00
6dccb343bb
Revert "core: Do not keep unification result for function arguments"
...
This reverts commit f09f3c27a5
.
2023-12-18 10:01:23 +08:00
8886964776
core: Remove redundant argument in type annotation parsing
2023-12-16 18:40:48 +08:00
f09f3c27a5
core: Do not keep unification result for function arguments
...
For some reason, when unifying a function call parameter with an
argument, subsequent calls to the same function will only accept the
type of the substituted argument.
This affect snippets like:
```
def make1() -> C[Literal[1]]:
return ...
def make2() -> C[Literal[2]]:
return ...
def consume(instance: C[Literal[1, 2]]):
pass
consume(make1())
consume(make2())
```
The last statement will result in a compiler error, as the parameter of
consume is replaced with C[Literal[1]].
We fix this by getting a snapshot before performing unification, and
restoring the snapshot after unification succeeds.
2023-12-16 18:40:48 +08:00
0bbc9ce6f5
core: Deduplicate values in Literal
...
Matches the behavior with `typing.Literal`.
2023-12-16 18:40:48 +08:00
457d3b6cd7
core: Refactor generic constants to Literal
...
Better matches the syntax of `typing.Literal`.
2023-12-16 18:40:48 +08:00
5f692debd8
core: Add PrimitiveStore into Unifier
...
This will be used during unification between a const generic variable
and a `Literal`.
2023-12-16 18:40:48 +08:00
b47ac1b89b
core: Minor formatting cleanup
2023-12-15 17:46:44 +08:00
a19f1065e3
meta: Refactor to use more let-else bindings
2023-12-12 16:31:14 +08:00
32746c37be
core: Refactor to return errors by HashSet
2023-12-12 15:41:59 +08:00
16655959f2
meta: Update cargo dependencies
2023-12-12 15:41:59 +08:00
d4c109b6ef
core: Add missing generic constant concrete type
2023-12-12 11:28:01 +08:00
5ffd06dd61
core: Remove debugging statement
2023-12-12 11:23:51 +08:00
bd3d67f3d6
artiq: Apply clippy pedantic changes
2023-12-11 15:16:23 +08:00
02933753ca
core: Apply clippy pedantic changes
2023-12-11 15:16:23 +08:00
a1f244834f
meta: Bringup some documentation
2023-12-11 15:16:23 +08:00
d304afd333
meta: Apply clippy suggested changes
2023-12-11 15:16:23 +08:00
ef04696b02
meta: Lift return out of conditional statement
2023-12-11 15:16:23 +08:00
4dc5dbb856
meta: Replace equality assertion with assert_eq
...
Emits a more useful assertion message.
2023-12-11 15:16:23 +08:00
fd9f66b8d9
meta: Remove redundant casts and brackets
2023-12-11 15:16:23 +08:00
5182453bd9
meta: Remove redundant path prefixes
2023-12-11 15:16:23 +08:00
031e660f18
core: Initial implementation for const generics
2023-12-08 18:02:11 +08:00
b6dfcfcc38
core: Move some SymbolValue functions to symbol_resolver.rs
2023-12-08 18:00:51 +08:00
c93ad152d7
core: Codegen for ellipsis expression as NotImplemented
...
A lot of refactoring was performed, specifically with relaxing
expression codegen to return Option in case where ellipsis are used
within a subexpression.
2023-12-08 18:00:51 +08:00
68b97347b1
core: Infer builtins name list using builtin declaration list
2023-12-08 17:29:34 +08:00
875d534de4
ast: Use {filename}:{row}:{col}
for location output
2023-12-08 15:48:54 +08:00
cee62aa6c5
pin down LLVM used for IRRT
2023-11-25 20:15:29 +08:00
5c5620692f
core: Add np_{round,floor,ceil}
...
These functions are NumPy variants of round/floor/ceil, which returns
floats instead of ints.
2023-11-23 13:45:07 +08:00
0af1e37e99
core: Prefix all NumPy/SciPy functions with np_/sp_spec
2023-11-23 13:35:23 +08:00
10538b5296
core: Update insta snapshots
2023-11-09 13:00:27 +08:00
d322c91697
core: Change bitshift operators to accept int32/uint32 for RHS operand
2023-11-09 12:16:20 +08:00
3231eb0d78
core: Add compile-time error and runtime assertion for negative shifts
2023-11-09 12:16:20 +08:00
08a5050f9a
core: Implement non-trivial builtin functions using IRRT
2023-11-06 12:57:23 +08:00
0a84f7ac31
Add CodeGenerator::gen_block and refactor to use it
2023-11-04 13:42:44 +08:00
fd787ca3f5
core: Remove trunc
...
The behavior of trunc is already implemented by casts and is therefore
redundant.
2023-11-04 13:35:53 +08:00
4dbe07a0c0
core: Revert breaking changes to round-family functions
...
These functions should return ints as the math.* functions do instead of
following the convention of numpy.* functions.
2023-11-04 13:35:53 +08:00
2e055e8ab1
core: Replace rint implementation with LLVM intrinsic
2023-11-04 13:35:53 +08:00
c6b9aefe00
core: Fix int32-to-uint64 conversion
...
This conversion should be sign-extended.
2023-11-03 16:24:26 +08:00
8ad09748d0
core: Fix conversion from float to unsigned types
...
These conversions also need to wraparound.
2023-11-03 16:24:26 +08:00
7a5a2db842
core: Fix handling of float-to-int32 casts
...
Out-of-bound conversions should be wrapped around.
2023-11-03 16:24:26 +08:00
92d6f0a5d3
core: Implement bitwise not for unsigned ints and fix implementation
2023-11-03 16:24:26 +08:00
ff1fed112c
core: Rework gamma/gammaln to match SciPy behavior
...
Matches behavior for infinities and NaNs.
2023-11-01 18:03:29 +08:00
36a6a7b8cd
core: Replace TopLevelDef comments with documentation
2023-11-01 18:03:29 +08:00
2b635a0b97
core: Implement numpy and scipy functions
2023-11-01 18:03:29 +08:00
60ad100fbb
core: Implement and expose {isinf,isnan}
2023-11-01 18:03:29 +08:00
7cf7634985
core: Add create_fn_by_* functions
...
Used for abstracting the creation of function from different sources.
2023-11-01 18:03:29 +08:00
068f0d9faf
core: Do not cast floor/ceil result to int
...
NumPy explicitly states that the return type of the floor/ceil is float.
2023-11-01 18:03:29 +08:00
95810d4229
core: Remove {ceil64,floor64,round,round64}
...
These are not present in NumPy or Artiq.
2023-11-01 18:03:29 +08:00
e95586f61e
core: Fix IR generation of for
loop containing break/continue
...
Fix cases where the body BB would have two terminators because of a
preceding continue/break statement already emitting a terminator.
2023-11-01 13:21:27 +08:00
e1487ed335
cargo: Update dependencies
2023-10-20 18:11:45 +08:00
73500c9081
core: Remove lazy_static from dependencies
2023-10-16 15:55:10 +08:00
50230e61f3
core: Simplify loop condition check for list comprehension
2023-10-06 12:24:03 +08:00