Added boolean mask __getitem__ methods so that it supports the following
var arr = NDArray[i16](3, 3, random=True)
var masked_arr = arr[ arr % 2 == 0 ]
var masked_arr = arr[ arr * 2 == 4]
Added comparison methods __lt__, __le__, __gt__, __ge__, __ne__ with overload for supporting both SIMD[dtype, 1] and NDArray[dtype]. This allows for the following boolean masks,
var arr = NDArray[i16](3, 3, random=True)
var masked_simd = arr[ arr > Scalar[i16](10)]
seed(42)
var arr1 = NDArray[i16](3, 3, random=True)
var masked_ndarray = arr[arr <= arr1]
Added __setitem__ to support the following,
var arr = NDArray[i16](3, 3, random=True)
seed(42)
var arr1 = NDArray[i16](3, 3, random=True)
var arr[arr > 20] = arr1 # replaces elements of arr with elements of arr1 at positions where element of arr is greater than 10
Docstrings
Updated functions with docstrings following style guide all .mojo files except ndarray.mojo (Ongoing) and some functions in sort.mojo (fixing issues with __setitem__)
Quirks
In the booleans masks, you have to explicitly cast the scalar (to be compared with) to the correct dtype, if dtype is any integer data type (float values don't require such casting) in the following way,
var A = NDArray[i16](3, 3, random=True)
var gt = A > Scalar[i16](20)
After some extensive traceback, I found that using NDArray with i8 datatype causes segfault at random even though it shows the correct final result. For example,
var A = NDArray[i8](3, 3, random=True)
var masked = A[ A%2 == 0] # will randomly cause segfault
NDArray
__getitem__
methods so that it supports the following__lt__
,__le__
,__gt__
,__ge__
,__ne__
with overload for supporting both SIMD[dtype, 1] and NDArray[dtype]. This allows for the following boolean masks,__setitem__
to support the following,Docstrings
Updated functions with docstrings following style guide all .mojo files except
ndarray.mojo
(Ongoing) and some functions insort.mojo
(fixing issues with__setitem__
)Quirks
dtype
, ifdtype
is any integer data type (float values don't require such casting) in the following way,i8
datatype causes segfault at random even though it shows the correct final result. For example,