Implement ndarray binary, unary and compare operators #390

Merged
sb10q merged 1 commits from enhance/issue-149-ndarray/operators into master 2024-08-17 17:37:21 +08:00
Collaborator

Omissions (will be implemented in a separate PR):

  • Matrix multiplication
  • Chained comparison (e.g. 1 < 2 < np_identity(2))
Omissions (will be implemented in a separate PR): - Matrix multiplication - Chained comparison (e.g. `1 < 2 < np_identity(2)`)
derppening force-pushed enhance/issue-149-ndarray/operators from 29ae48faad to e69fab866c 2024-04-01 17:35:07 +08:00 Compare
derppening force-pushed enhance/issue-149-ndarray/operators from e69fab866c to 847d19077e 2024-04-02 16:56:58 +08:00 Compare
derppening changed title from WIP: Implement ndarray binary, unary and compare operators to Implement ndarray binary, unary and compare operators 2024-04-02 16:57:12 +08:00
derppening requested review from sb10q 2024-04-02 16:57:16 +08:00
sb10q reviewed 2024-04-02 16:59:04 +08:00
@ -524,6 +545,20 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
methods: vec![
("copy".into(), ndarray_copy_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 1)),
("fill".into(), ndarray_fill_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 2)),
("__add__".into(), ndarray_add_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 3)),
Owner

All this manual and error-prone definitionid allocation will have to be cleaned up at some point.

All this manual and error-prone definitionid allocation will have to be cleaned up at some point.
sb10q reviewed 2024-04-02 17:00:32 +08:00
@ -233,0 +246,4 @@
}
}
impl TryFrom<SymbolValue> for i128 {
Owner

Why do we need i128 anywhere?

Why do we need i128 anywhere?
Author
Collaborator

Copied with the conversation in Mattermost:

it's for implicit promotion for const generics. currently, the ndims typevar for ndarray is implemented either as a u32 or u64 depending on the size of size_t of the target platform, so i thought it would make more sense that ndarray[float, 1] could be implicitly promoted into ndarray[float, uint64(1)] while also preserving compile-time checks (as it is a compile-time constant)

then, in the unifier implementation, i just need to cast the expected and actual const generic type into a common numeric type (in this case, i128), to check whether they are compatible

[we don't use u64 as the common type because] const generics can also be signed numbers, and u64 cannot represent signed numbers

i128 is used in the implementation of the unifier, so the common integral type needs to take into consideration future code that may use signed const generics as well

Copied with the conversation in Mattermost: > it's for implicit promotion for const generics. currently, the `ndims` typevar for `ndarray` is implemented either as a `u32` or `u64` depending on the size of `size_t` of the target platform, so i thought it would make more sense that `ndarray[float, 1]` could be implicitly promoted into `ndarray[float, uint64(1)]` while also preserving compile-time checks (as it is a compile-time constant) > > then, in the unifier implementation, i just need to cast the expected and actual const generic type into a common numeric type (in this case, `i128`), to check whether they are compatible > > [we don't use `u64` as the common type because] const generics can also be signed numbers, and `u64` cannot represent signed numbers > > `i128` is used in the implementation of the unifier, so the common integral type needs to take into consideration future code that may use signed const generics as well
derppening force-pushed enhance/issue-149-ndarray/operators from 847d19077e to a920fe0501 2024-04-03 00:13:41 +08:00 Compare
sb10q merged commit a920fe0501 into master 2024-04-03 12:19:22 +08:00
sb10q deleted branch enhance/issue-149-ndarray/operators 2024-04-03 12:19:50 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#390
No description provided.