Commit Graph

1381 Commits

Author SHA1 Message Date
lyken 76531c7d1c
core: update insta after ndstrides
New type vars are introduced when programming new ndarray functions.
2024-08-30 16:22:06 +08:00
lyken e1cdc2dc78
core: remove old ndarray code and NDArray proxy
Nothing depends on the old ndarray implementation now.
2024-08-30 16:19:36 +08:00
lyken 1f0463463f
artiq: reimplement get_obj_value to use ndarray with strides 2024-08-30 16:16:25 +08:00
lyken bb512b8f57
artiq: reimplement polymorphic_print for ndarray 2024-08-30 16:13:59 +08:00
lyken 700357a8b2
artiq: reimplement reformat_rpc_arg for ndarray 2024-08-30 16:13:47 +08:00
lyken 4e9facd457
standalone/ndarray: improve {reshape,broadcast_to,transpose} tests
Print their shapes and exhaustively print all contents.
2024-08-30 15:15:21 +08:00
lyken b3a66948fa
standalone/ndarray: add and organize view function tests 2024-08-30 15:15:07 +08:00
lyken 7fb5e10ee2
core/ndstrides: update builtin_fns to use ndarray with strides 2024-08-30 15:14:29 +08:00
lyken 1de3f05734
core/ndstrides: add NDArrayObject::to_any 2024-08-30 15:10:03 +08:00
lyken 3426e0c9c2
core/ndstrides: add ContiguousNDArray
Currently this is used to interop with nalgebra.
2024-08-30 15:09:54 +08:00
lyken 4baf1c64ed
core/ndstrides: implement np_dot() for scalars and 1D 2024-08-30 15:07:44 +08:00
lyken c93f05f74b
core/ndstrides: implement general matmul 2024-08-30 15:06:28 +08:00
lyken e86718d3d9
core/ndstrides: implement cmpop 2024-08-30 14:59:34 +08:00
lyken a43ec47530
core/ndstrides: implement unary op 2024-08-30 14:57:26 +08:00
lyken bc88819eaf
core/ndstrides: implement binop 2024-08-30 14:57:11 +08:00
lyken c6d3620431
core/ndstrides: add NDArrayOut, broadcast_map and map 2024-08-30 14:57:02 +08:00
lyken cea512456a
core/ndstrides: implement subscript assignment
Overlapping is not handled. Currently it has undefined behavior.
2024-08-30 14:54:53 +08:00
lyken b22f2bc76c
core/ndstrides: add more ScalarOrNDArray and NDArrayObject utils 2024-08-30 14:52:57 +08:00
lyken b9e837109b
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-08-30 14:50:48 +08:00
lyken d32268fb5d
core/ndstrides: implement broadcasting & np_broadcast_to() 2024-08-30 14:45:43 +08:00
lyken 916a2b4993
core/ndstrides: implement np_reshape() 2024-08-30 14:41:54 +08:00
lyken c7c3cc21a8
core: categorize np_{transpose,reshape} as 'view functions' 2024-08-30 14:41:54 +08:00
lyken d2072d9248
core/ndstrides: implement np_size() 2024-08-30 14:41:00 +08:00
lyken be19165ead
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-08-30 14:41:00 +08:00
lyken ee58cf3fc3
core/ndstrides: implement ndarray.fill() and .copy() 2024-08-30 14:41:00 +08:00
lyken 8fe8ccf200
core/ndstrides: implement np_identity() and np_eye() 2024-08-30 14:41:00 +08:00
lyken d222236492
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-08-30 14:40:15 +08:00
lyken 13715dbda9
core/irrt: add List
Needed for implementing np_array()
2024-08-30 14:20:19 +08:00
lyken 7910de10a1
core/ndstrides: add NDArrayObject::atleast_nd 2024-08-30 14:18:34 +08:00
lyken 6edc3f895b
core/ndstrides: add NDArrayObject::make_copy 2024-08-30 14:18:17 +08:00
lyken a40cdde8d2
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-08-30 14:12:54 +08:00
lyken 853fa39537
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-08-30 14:00:19 +08:00
lyken b6a1880226
core/irrt: add Slice and Range
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-08-30 13:57:10 +08:00
lyken d1c75c7444
core/ndstrides: implement len(ndarray) & refactor len() 2024-08-30 13:45:25 +08:00
lyken 58c5bc56b9
core/ndstrides: implement np_{zeros,ones,full,empty} 2024-08-30 13:44:12 +08:00
lyken ddc0e44c61
core/model: add util::gen_for_model 2024-08-30 13:42:39 +08:00
lyken 549536f72c
core/object: add ListObject and TupleObject
Needed for implementing other ndarray utils.
2024-08-30 13:41:31 +08:00
lyken 40c42b571a
core/ndstrides: implement ndarray iterator NDIter
A necessary utility to iterate through all elements in a possibly strided ndarray.
2024-08-30 13:39:10 +08:00
lyken 92e7103ec7
core/ndstrides: introduce NDArray
NDArray with strides.
2024-08-30 13:24:45 +08:00
lyken 9bc5e96dba
core/irrt: fix exception.hpp C++ castings 2024-08-30 13:15:07 +08:00
lyken 78639b1030
core/toplevel/helper: add {extract,create}_ndims 2024-08-30 13:05:16 +08:00
lyken 9723c17e24
core/object: introduce object
A small abstraction to simplify implementations.
2024-08-30 13:04:54 +08:00
lyken d1c7a8ee50
StructKind::{traverse -> iter}_fields 2024-08-30 12:51:17 +08:00
lyken e0524c19eb
Newline "Otherwise, it will be caught..." 2024-08-30 12:51:17 +08:00
lyken 32822f9052
gep_index must be u32 2024-08-30 12:51:17 +08:00
lyken 6283036815
FieldTraversal::{Out -> Output} 2024-08-30 12:51:17 +08:00
lyken f167f5f215
Ptr::copy_from to use SizeT 2024-08-30 12:51:17 +08:00
lyken baf8ee2b3d
Ptr::offset_const offset i64, can be negative 2024-08-30 12:51:17 +08:00
lyken d68760447f
Int::const_int to have sign_extend 2024-08-30 12:51:17 +08:00
lyken fdd194ee2a
FnCall::{begin -> builder} 2024-08-30 12:51:17 +08:00