Commit Graph

1472 Commits

Author SHA1 Message Date
14e14cb6eb [core] codegen: Reimplement np_dot() for scalars and 1D
Based on 693b7f37: core/ndstrides: implement np_dot() for scalars and 1D
2024-12-24 15:40:33 +08:00
a525592941 [core] codegen/ndarray: Reimplement matmul
Based on 73c2203b: core/ndstrides: implement general matmul
2024-12-24 15:39:40 +08:00
7da45a4fbd [core] codegen: Reimplement ndarray cmpop
Based on 56cccce1: core/ndstrides: implement cmpop
2024-12-24 15:39:34 +08:00
f43523ec72 [core] codegen: Reimplement ndarray unary op
Based on bb992704: core/ndstrides: implement unary op
2024-12-24 15:38:40 +08:00
303b20db15 [core] codegen: Reimplement ndarray binop
Based on 9e40c834: core/ndstrides: implement binop
2024-12-24 15:38:24 +08:00
90c19bed16 [core] codegen: Reimplement builtin funcs to support strided ndarrays
Based on 7f3c4530: core/ndstrides: update builtin_fns to use ndarray
with strides
2024-12-24 15:38:22 +08:00
61ba5fa2e5 [core] codegen/ndarray: Add NDArrayOut, broadcast_map, map
Based on fbfc0b29: core/ndstrides: add NDArrayOut, broadcast_map and map
2024-12-24 15:34:45 +08:00
5c8a1d5f2f [core] codegen/ndarray: Implement subscript assignment
Based on 5bed394e: core/ndstrides: implement subscript assignment

Overlapping is not handled. Currently it has undefined behavior.
2024-12-24 15:34:02 +08:00
8d8f9e9b2a [core] codegen/values/ndarray: Add more ScalarOrNDArray utils
Based on f731e604: core/ndstrides: add more ScalarOrNDArray and
NDArrayObject utils
2024-12-24 15:33:41 +08:00
d1bf5085a6 [core] codegen/ndarray: Implement np_transpose without axes argument
Based on 052b67c8: core/ndstrides: implement np_transpose() (no axes
argument)

The IRRT implementation knows how to handle axes. But the argument is
not in NAC3 yet.
2024-12-24 15:32:58 +08:00
32e1d55de9 [core] codegen/ndarray: Reimplement broadcasting
Based on 9359ed96: core/ndstrides: implement broadcasting &
np_broadcast_to()
2024-12-24 15:32:32 +08:00
936749ae5f [core] codegen/ndarray: Implement np_reshape
Based on 926e7e93: core/ndstrides: implement np_reshape()
2024-12-24 15:21:25 +08:00
297078ed61 [core] toplevel: Add view functions category
Based on 9e0f636d: core: categorize np_{transpose,reshape} as 'view
functions'
2024-12-24 15:21:04 +08:00
c7192f861b [core] toplevel: Implement np_size
Based on 2c1030d1: core/ndstrides: implement np_size()
2024-12-24 15:21:00 +08:00
694265ed6d [core] codegen/ndarray: Implement np_{shape,strides}
Based on 40c24486: core/ndstrides: implement np_shape() and np_strides()

These functions are not important, but they are handy for debugging.

`np.strides()` is not an actual NumPy function, but `ndarray.strides` is
used.
2024-12-24 15:20:30 +08:00
34c64a2ef5 [core] codegen/ndarray: Reimplement np_{copy,fill}
Based on 18db85fa: core/ndstrides: implement ndarray.fill() and .copy()
2024-12-24 15:19:34 +08:00
6bd81ce1ac [core] codegen/ndarray: Reimplement np_{eye,identity}
Based on fa047d50: core/ndstrides: implement np_identity() and np_eye()
2024-12-24 15:19:17 +08:00
1eb462a5c2 [core] codegen/ndarray: Reimplement np_array()
Based on 8f0084ac: core/ndstrides: implement np_array()

It also checks for inconsistent dimensions if the input is a list.
e.g., rejecting `[[1.0, 2.0], [3.0]]`.

However, currently only `np_array(<input>, copy=False)` and `np_array
(<input>, copy=True)` are supported. In NumPy, copy could be false,
true, or None. Right now, NAC3's `np_array(<input>, copy=False)` behaves
like NumPy's `np.array(<input>, copy=None)`.
2024-12-24 15:19:00 +08:00
9a9eeba28d [core] codegen: Refactor len()
Based on 54a842a9: core/ndstrides: implement len(ndarray) & refactor
len()
2024-12-24 15:18:43 +08:00
ef01578467 [core] codegen/ndarray: Reimplement np_{zeros,ones,full,empty}
Based on 792374fa: core/ndstrides: implement np_{zeros,ones,full,empty}.
2024-12-24 15:18:37 +08:00
d2e2b97d22 [core] codegen: Implement Tuple{Type,Value} 2024-12-24 15:10:01 +08:00
7fcbbd0dda [core] codegen: Refactor ListType to use derive(StructFields) 2024-12-24 15:10:01 +08:00
53d09b86f7 [core] codegen/types: Refactor ProxyType
- Add alloca_type() function to obtain the type that should be passed
into a `build_alloca` call
- Provide default implementations for raw_alloca and array_alloca
- Add raw_alloca_var and array_alloca_var to distinguish alloca
instructions placed at the front of the function vs at the current
builder location
2024-12-24 15:10:01 +08:00
90071be0a7 [core] codegen/ndarray: Use IRRT for size() and indexing operations
Also refactor some usages of call_ndarray_calc_size with ndarray.size().
2024-12-24 15:10:01 +08:00
155002629b [core] codegen: Update raw_alloca to return PointerValue
Better match the expected behavior of alloca.
2024-12-24 15:10:01 +08:00
1b1cb775af [core] Minor improvements to IRRT and add missing documentation 2024-12-24 15:09:59 +08:00
a2efccee1c [core] codegen: Refactor TypedArrayLikeAdapter to use fn
Allows for greater flexibility when TypedArrayLikeAdapter is used with
custom value types.
2024-12-24 14:54:29 +08:00
35b49dc279 [core] codegen: Rename classes/functions for consistency
- ContiguousNDArrayFields -> ContiguousNDArrayStructFields
- ndarray/nditer: Add _field suffix to field accessors
2024-12-24 14:54:29 +08:00
b3d7001561 [core] irrt: Minor cleanup 2024-12-24 14:54:29 +08:00
f62babbace [core] Refactor/Remove redundant and unused constructs
- Use ProxyValue.name where necessary
- Remove NDArrayValue::ptr_to_{shape,strides}
- Remove functions made obsolete by ndstrides
- Remove use statement for ndarray::views as it only contain an impl
block.
- Remove class_names field in Resolvers of test sources
2024-12-23 22:42:11 +08:00
08b717d640 [meta] Refactor itertools::{chain,enumerate,repeat_n} with std equiv 2024-12-18 10:47:15 +08:00
1531b6cc98 cargo: update dependencies 2024-12-13 19:42:01 +08:00
9bbc40bbfa flake: update dependencies 2024-12-13 19:41:52 +08:00
790e56d106 msys2: update 2024-12-13 19:39:39 +08:00
a00eb7969e [core] codegen: Implement matrix_power
Last of the functions that need to be ported over to strided-ndarray.
2024-12-13 15:23:31 +08:00
27a6f47330 [core] codegen: Implement construction of unsized ndarrays
Partially based on f731e604: core/ndstrides: add more ScalarOrNDArray
and NDArrayObject utils.
2024-12-13 15:23:31 +08:00
061747c67b [core] codegen: Implement NDArrayValue::atleast_nd
Based on 9cfa2622: core/ndstrides: add NDArrayObject::atleast_nd.
2024-12-13 15:23:31 +08:00
dc91d9e35a [core] codegen: Implement ScalarOrNDArray and use it in indexing
Based on 8f9d2d82: core/ndstrides: implement ndarray indexing.
2024-12-13 15:23:31 +08:00
438943ac6f [core] codegen: Implement indexing for NDArray
Based on 8f9d2d82: core/ndstrides: implement ndarray indexing

The functionality for `...` and `np.newaxis` is there in IRRT, but there
is no implementation of them for @kernel Python expressions because of
#486.
2024-12-13 15:23:31 +08:00
678e56c95d [core] irrt: rename NDIndex to NDIndexInt
Unfortunately the name `NDIndex` is used in later commits. Renaming this
typedef to `NDIndexInt` to avoid amending. `NDIndexInt` will be removed
anyway when ndarray strides is completed.
2024-12-13 15:23:31 +08:00
fdfc80ca5f [core] codegen: Implement Slice{Type,Value}, RustSlice
Based on 01c96396: core/irrt: add Slice and Range and part of
8f9d2d82: core/ndstrides: implement ndarray indexing.

Needed for implementing general ndarray indexing.

Currently IRRT slice and range have nothing to do with NAC3's slice
and range. The IRRT slice and range are currently there to implement
ndarray specific features. However, in the future their definitions may
be used to replace that of NAC3's. (NAC3's range is a [i32 x 3], IRRT's
range is a proper struct. NAC3 does not have a slice struct).
2024-12-13 15:23:31 +08:00
8b3429d62a [artiq] Reimplement get_obj_value for strided ndarray
Based on 7ef93472: artiq: reimplement get_obj_value to use ndarray with
strides
2024-12-13 15:23:31 +08:00
f4c5038b95 [artiq] codegen: Reimplement polymorphic_print for strided ndarray
Based on 2a6ee503: artiq: reimplement polymorphic_print for ndarray
2024-12-13 15:23:31 +08:00
ddd16738a6 [core] codegen: implement ndarray iterator NDIter
Based on 50f960ab: core/ndstrides: implement ndarray iterator NDIter

A necessary utility to iterate through all elements in a possibly
strided ndarray.
2024-12-13 15:23:31 +08:00
44c49dc102 [artiq] codegen: Reimplement polymorphic_print for strided ndarray
Based on 2a6ee503: artiq: reimplement polymorphic_print for ndarray
2024-12-13 15:23:31 +08:00
e4bd376587 [core] codegen: Implement ContiguousNDArray
Fixes compatibility with linalg algorithms. matrix_power is missing due
to the need for indexing support.
2024-12-13 15:23:29 +08:00
44498f22f6 [core] codegen: Implement NDArray functions from a0a1f35b 2024-12-13 15:22:11 +08:00
110416d07a [core] codegen/irrt: Add IRRT functions for strided-ndarray 2024-12-13 15:22:11 +08:00
08a7d01a13 [core] Add itemsize and strides to NDArray struct
Temporarily disable linalg ndarray tests as they are not ported to work
with strided-ndarray.
2024-12-13 15:22:09 +08:00
3cd36fddc3 [core] codegen/types: Add check_struct_type_matches_fields
Shorthand for checking if a type is representable by a StructFields
instance.
2024-12-12 11:40:44 +08:00