From 8967613b2242b7ef6b1e4ac382d7fcc47ce2048b Mon Sep 17 00:00:00 2001 From: darth-photon Date: Mon, 5 Aug 2024 15:41:02 +0900 Subject: [PATCH 01/32] implemented diagflat for k < 0 --- numojo/core/array_creation_routines.mojo | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/numojo/core/array_creation_routines.mojo b/numojo/core/array_creation_routines.mojo index 10e33a8..17d589b 100644 --- a/numojo/core/array_creation_routines.mojo +++ b/numojo/core/array_creation_routines.mojo @@ -559,15 +559,17 @@ fn diagflat[dtype: DType](inout v: NDArray[dtype], k: Int = 0) raises -> NDArray var n: Int= v.ndshape.ndsize + abs(k) var result: NDArray[dtype]= NDArray[dtype](n, n, random=False) - for i in range(n): - print(n*i + i + k) - result.store(n*i + i + k, v.data[i]) + if k > 0: + for i in range(n): + result.store(n*i + i + k, v.data[i]) + else: + for i in range(n): + result.store(result.ndshape.ndsize - 1 - (n*i + i + abs(k)), v.data[v.ndshape.ndsize - 1 - i]) return result fn tri(): - pass - + fn tril(): pass From b523040defe9526b324dd00f8fea18dbb1eef350 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Mon, 5 Aug 2024 15:53:39 +0900 Subject: [PATCH 02/32] added tri() method --- numojo/core/array_creation_routines.mojo | 25 +++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/numojo/core/array_creation_routines.mojo b/numojo/core/array_creation_routines.mojo index 17d589b..b544797 100644 --- a/numojo/core/array_creation_routines.mojo +++ b/numojo/core/array_creation_routines.mojo @@ -568,11 +568,30 @@ fn diagflat[dtype: DType](inout v: NDArray[dtype], k: Int = 0) raises -> NDArray return result -fn tri(): - +fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: + """ + Generate a 2-D NDArray with ones on and below the k-th diagonal. + + Parameters: + dtype: Datatype of the NDArray elements. + + Args: + N: Number of rows in the matrix. + M: Number of columns in the matrix. + k: Diagonal offset. + + Returns: + A 2-D NDArray with ones on and below the k-th diagonal. + """ + var result: NDArray[dtype] = NDArray[dtype](N, M, random=False) + for i in range(N): + for j in range(M): + if i >= j - k: + result.store(i, j, val=Scalar[dtype](1)) + return result fn tril(): - pass + fn triu(): From 36a74a0637af1d22658da38b9637fa5ef8cd0c47 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 9 Aug 2024 21:19:44 +0800 Subject: [PATCH 03/32] added tril function --- numojo/core/array_creation_routines.mojo | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/numojo/core/array_creation_routines.mojo b/numojo/core/array_creation_routines.mojo index b544797..788e9f2 100644 --- a/numojo/core/array_creation_routines.mojo +++ b/numojo/core/array_creation_routines.mojo @@ -18,7 +18,7 @@ from algorithm import parallelize from builtin.math import pow from .ndarray import NDArray, NDArrayShape -from .utility_funcs import is_inttype, is_floattype +from .ndarray_utils import _get_index # ===------------------------------------------------------------------------===# @@ -590,8 +590,28 @@ fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: result.store(i, j, val=Scalar[dtype](1)) return result -fn tril(): +fn tril[dtype: DType](inout m: NDArray[dtype], k: Int = 0) raises: + """ + Zero out elements above the k-th diagonal. + Parameters: + dtype: Datatype of the NDArray elements. + + Args: + m: NDArray to be zeroed out. + k: Diagonal offset. + """ + var index: List[Int] = List[Int]() + for _ in range(m.ndshape.ndlen): + index.append(0) + + for i in range(m.ndshape[-1]): + for j in range(m.ndshape[-2]): + var idx: Int = _get_index(index, m.ndshape) + if i >= j - k: + m.data[idx] = Scalar[dtype](0) + index[-2] += 1 + index[-1] += 1 fn triu(): From dfbb580e4201488a1cd52b8ccc3251763b30dc35 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 9 Aug 2024 21:20:03 +0800 Subject: [PATCH 04/32] added descriptions --- numojo/core/ndarray.mojo | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 950ebbe..69ac8cd 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -1209,6 +1209,9 @@ struct NDArray[dtype: DType = DType.float64]( return narr fn _adjust_slice_(self, inout span: Slice, dim: Int): + """ + Adjusts the slice values to lie within 0 and dim. + """ if span.start < 0: span.start = dim + span.start if not span._has_end(): From 4a5e59d6e11168897e3f3952c44aa0fc66228adb Mon Sep 17 00:00:00 2001 From: darth-photon Date: Mon, 12 Aug 2024 08:34:38 +0530 Subject: [PATCH 05/32] fixed typos in ndarray --- new_tests/test_array_creation.mojo | 10 +++++-- numojo/core/ndarray.mojo | 44 +++++++++++++++--------------- numojo/math/arithmetic.mojo | 2 ++ test.mojo | 14 ++++++++-- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/new_tests/test_array_creation.mojo b/new_tests/test_array_creation.mojo index 56022e5..5ec8458 100644 --- a/new_tests/test_array_creation.mojo +++ b/new_tests/test_array_creation.mojo @@ -39,6 +39,13 @@ def test_identity(): def test_eye(): var np = Python.import_module("numpy") check(nm.eye[nm.i64](100,100),np.eye(100,100,dtype=np.int64),"Eye is broken") + +def test_diagflat(): + var np = Python.import_module("numpy") + var temp = nm.arange[nm.i64](1, 10, 10) + temp.reshape(3,3) + check(nm.diagflat[nm.i64](nm),np.diagflat(np.arange(1,10,10).reshape(3,3),"Diagflat is broken") + def main(): var np = Python.import_module("numpy") var arr = nm.arange[nm.f64](0,100) @@ -51,8 +58,7 @@ def main(): # check_is_close(nm.geomspace[nm.i64](1,100,5),np.geomspace(1,100,5,dtype=np.float64),"Logspace is broken") # print((arr@arr).to_numpy()-np.matmul(np_arr,np_arr)) print(nm.matmul_naive[nm.f64](arr,arr).to_numpy())#-np.matmul(np_arr,np_arr)) - print(np.matmul(np_arr,np_arr)) - # # Basic ND arrays + print(np.matmul(np_arr,np_arr)) # # Basic ND arrays # print(nm.sin[nm.f64](nm.arange[nm.f64](0,15))) # print( np.sin(np.arange(0,15, dtype=np.float64))) # check(nm.zeros[nm.f64](10,10,10,10),np.zeros((10,10,10,10),dtype=np.float64),"Zeros is broken") diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 69ac8cd..bc1a1a4 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2733,7 +2733,7 @@ struct NDArray[dtype: DType = DType.float64]( slices.append(Slice(0, shape[i])) else: slices.append(Slice(0, 0)) - print(result_shape.__str__()) + var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(result_shape)) slices[axis] = Slice(0, 1) result = self[slices] @@ -2824,14 +2824,14 @@ struct NDArray[dtype: DType = DType.float64]( return prod(self, axis) - # fn ravel(self): - # pass - - # fn resize(self): - # pass + fn round(self) raises -> Self: + """ + Rounds the elements of the array to a whole number. - # fn round(self): - # pass + Returns: + An NDArray. + """ + return tround[dtype](self) # for python compat this should be inplace fn sort(self) raises -> Self: @@ -2850,23 +2850,23 @@ struct NDArray[dtype: DType = DType.float64]( """ return sum(self, axis) - # fn stdev(self): - # pass - - # fn tolist(self): - # pass + fn tolist(self) -> List[Scalar[dtype]]: + """ + Convert NDArray to a 1-D List. - # fn tostring(self): - # pass + Returns: + A 1-D List. + """ + var result: List[Scalar[dtype]] = List[Scalar[dtype]]() + for i in range(self.ndshape.ndsize): + result.append(self.data[i]) + return result + + # fn toint(self): + # pass # fn trace(self): - # pass - - # fn transpose(self): - # pass - - # fn variance(self): - # pass + # pass # Technically it only changes the ArrayDescriptor and not the fundamental data fn reshape(inout self, *shape: Int, order: String = "C") raises: diff --git a/numojo/math/arithmetic.mojo b/numojo/math/arithmetic.mojo index e197264..d3262b9 100644 --- a/numojo/math/arithmetic.mojo +++ b/numojo/math/arithmetic.mojo @@ -1173,3 +1173,5 @@ fn invert[ return backend().math_func_1_array_in_one_array_out[dtype, SIMD.__invert__]( array ) + + diff --git a/test.mojo b/test.mojo index 66c5ebe..d882dc3 100644 --- a/test.mojo +++ b/test.mojo @@ -18,10 +18,18 @@ from numojo import * # print(res) fn main() raises: - var A = arange[i16](1, 7, 1) + var A = arange[i16](1, 10, 1) print(A) - var temp = flip(A) - print(temp) + # var B = tri[i16](3, 5, -1) + # print(B) + # var temp = flip(A) + # print(temp) + A.reshape(3, 3, order="F") + print(A) + tril[i16](A, k=1) + print(A) + # var temp1 = diagflat(A, k=-2) + # print(temp1) # A.reshape(2, 3, order="F") # nm.ravel(A) # print(A) From da8c42e95b3acc5588e0ce8394c8ebddcc6effc5 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Mon, 12 Aug 2024 08:35:49 +0530 Subject: [PATCH 06/32] gitignore doesn't work! --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2cda8ea..4a3ffd3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ mojo numojo.mojopkg .gitignore bench.mojo -test_ndarray.ipynb \ No newline at end of file +test_ndarray.ipynb +test.mojo +test_array_creation.mojo +.gitignore From 2145aef29ec041eaa86ce179453552543a8e47f3 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 03:40:08 +0530 Subject: [PATCH 07/32] changed quick sort to be an inplace method --- numojo/core/ndarray.mojo | 4 ++-- numojo/core/sort.mojo | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index bc1a1a4..7bbef9c 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2834,11 +2834,11 @@ struct NDArray[dtype: DType = DType.float64]( return tround[dtype](self) # for python compat this should be inplace - fn sort(self) raises -> Self: + fn sort(inout self) raises: """ Sort the array using quickstort. """ - return sort.quick_sort(self) + sort.quick_sort[dtype](self) fn sum(self: Self, axis: Int) raises -> Self: """ diff --git a/numojo/core/sort.mojo b/numojo/core/sort.mojo index b821b16..0efdbd5 100644 --- a/numojo/core/sort.mojo +++ b/numojo/core/sort.mojo @@ -124,7 +124,7 @@ fn quick_sort_inplace[ fn quick_sort[ dtype: DType -](ndarray: NDArray[dtype],) raises -> NDArray[dtype]: +](inout ndarray: NDArray[dtype]) raises: """ Quick sort the NDArray. Adopt in-place partition. @@ -146,16 +146,11 @@ fn quick_sort[ Args: ndarray: An NDArray. - Returns: - The sorted NDArray. """ - var result: NDArray[dtype] = ndarray var length = ndarray.size() - quick_sort_inplace(result, 0, length - 1) - - return result + quick_sort_inplace(ndarray, 0, length - 1) # ===------------------------------------------------------------------------===# From d062460cfb80f0876bc489d4e7aff5cae9217961 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 03:43:53 +0530 Subject: [PATCH 08/32] fixed inplace sorting --- new_tests/utils_for_test.mojo | 3 +-- numojo/core/ndarray.mojo | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/new_tests/utils_for_test.mojo b/new_tests/utils_for_test.mojo index afb447b..ef5dd70 100644 --- a/new_tests/utils_for_test.mojo +++ b/new_tests/utils_for_test.mojo @@ -2,11 +2,10 @@ from python import Python, PythonObject from testing.testing import assert_true import numojo as nm - fn check(array:nm.NDArray,np_sol:PythonObject,st:String)raises: var np = Python.import_module("numpy") assert_true(np.all(np.equal(array.to_numpy(),np_sol)),st) fn check_is_close(array:nm.NDArray,np_sol:PythonObject,st:String)raises: var np = Python.import_module("numpy") - assert_true(np.all(np.isclose(array.to_numpy(),np_sol)),st) \ No newline at end of file + assert_true(np.all(np.isclose(array.to_numpy(),np_sol)),st) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 7bbef9c..dcda0aa 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2833,10 +2833,9 @@ struct NDArray[dtype: DType = DType.float64]( """ return tround[dtype](self) - # for python compat this should be inplace fn sort(inout self) raises: """ - Sort the array using quickstort. + Sort the array inplace using quickstort. """ sort.quick_sort[dtype](self) @@ -2862,9 +2861,6 @@ struct NDArray[dtype: DType = DType.float64]( result.append(self.data[i]) return result - # fn toint(self): - # pass - # fn trace(self): # pass From 5b869b8b5516ec4bb912eefdf2ac261da6ab6196 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 03:58:50 +0530 Subject: [PATCH 09/32] changed internal sort method to sorted (inplace) --- numojo/core/ndarray.mojo | 36 +++++++++++++----------------------- numojo/core/sort.mojo | 6 ++++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 5e40784..967214a 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -9,14 +9,10 @@ Implements N-Dimensional Array """ # TODO -1) Add NDArray, NDArrayShape constructor overload for List, VariadicList types etc to cover more cases -3) Generalize mdot, rdot to take any IxJx...xKxL and LxMx...xNxP matrix and matmul it into IxJx..xKxMx...xNxP array. -4) Vectorize row(), col() to retrieve rows and columns for 2D arrays -5) Add __getitem__() overload for (Slice, Int) -7) Add vectorization for _get_index -8) Write more explanatory Error("") statements -9) Vectorize the for loops inside getitem or move these checks to compile time to try and remove the overhead from constantly checking -10) Add List[Int] and Variadic[Int] Shape args for __init__ to make it more flexible +1) Generalize mdot, rdot to take any IxJx...xKxL and LxMx...xNxP matrix and matmul it into IxJx..xKxMx...xNxP array. +2) Add vectorization for _get_index +3) Write more explanatory Error("") statements +4) Create NDArrayView and remove coefficients. """ from builtin.type_aliases import AnyLifetime @@ -639,7 +635,7 @@ struct NDArray[dtype: DType = DType.float64]( var stride: NDArrayStride """Contains offset, strides.""" var coefficient: NDArrayStride - """Contains offset, coefficient.""" + """Contains offset, coefficients for slicing.""" var datatype: DType """The datatype of memory.""" var order: String @@ -670,10 +666,8 @@ struct NDArray[dtype: DType = DType.float64]( Returns an zero array with shape 3 x 2 x 4. """ self.ndim = shape.__len__() - # I cannot name self.ndshape as self.shape as lsp gives unrecognized variable error self.ndshape = NDArrayShape(shape) self.stride = NDArrayStride(shape, offset=0, order=order) - # I gotta make coefficients empty, but let's just keep it like for now self.coefficient = NDArrayStride(shape, offset=0, order=order) self.datatype = dtype self.order = order @@ -2088,7 +2082,6 @@ struct NDArray[dtype: DType = DType.float64]( raise Error("Both arrays must have same number of elements") var result = Self(self.ndshape) - alias nelts = simdwidthof[dtype]() @parameter fn vectorized_pow[simd_width: Int](index: Int) -> None: @@ -2098,7 +2091,7 @@ struct NDArray[dtype: DType = DType.float64]( ** p.load[width=simd_width](index), ) - vectorize[vectorized_pow, nelts](self.ndshape.ndsize) + vectorize[vectorized_pow, self.simd_width](self.ndshape.ndsize) return result fn __ipow__(inout self, p: Int): @@ -2543,7 +2536,6 @@ struct NDArray[dtype: DType = DType.float64]( if not (self.dtype.is_bool() or self.dtype.is_integral()): raise Error("Array elements must be Boolean or Integer.") # We might need to figure out how we want to handle truthyness before can do this - alias nelts: Int = simdwidthof[dtype]() var result: Bool = True @parameter @@ -2552,7 +2544,7 @@ struct NDArray[dtype: DType = DType.float64]( (self.data + idx).simd_strided_load[width=simd_width](1) ) - vectorize[vectorized_all, nelts](self.ndshape.ndsize) + vectorize[vectorized_all, self.simd_width](self.ndshape.ndsize) return result fn any(self) raises -> Bool: @@ -2562,7 +2554,6 @@ struct NDArray[dtype: DType = DType.float64]( # make this a compile time check if not (self.dtype.is_bool() or self.dtype.is_integral()): raise Error("Array elements must be Boolean or Integer.") - alias nelts: Int = simdwidthof[dtype]() var result: Bool = False @parameter @@ -2571,7 +2562,7 @@ struct NDArray[dtype: DType = DType.float64]( (self.data + idx).simd_strided_load[width=simd_width](1) ) - vectorize[vectorized_any, nelts](self.ndshape.ndsize) + vectorize[vectorized_any, self.simd_width](self.ndshape.ndsize) return result fn argmax(self) -> Int: @@ -2617,7 +2608,6 @@ struct NDArray[dtype: DType = DType.float64]( Convert type of array. """ # I wonder if we can do this operation inplace instead of allocating memory. - alias nelts = simdwidthof[dtype]() var narr: NDArray[type] = NDArray[type]( self.ndshape, random=False, order=self.order ) @@ -2632,7 +2622,7 @@ struct NDArray[dtype: DType = DType.float64]( self.load[width](idx).cast[type](), 1 ) - vectorize[vectorized_astype, nelts](self.ndshape.ndsize) + vectorize[vectorized_astype, self.simd_width](self.ndshape.ndsize) else: @parameter @@ -2647,7 +2637,7 @@ struct NDArray[dtype: DType = DType.float64]( .cast[type](), ) - vectorize[vectorized_astypenb_from_b, nelts]( + vectorize[vectorized_astypenb_from_b, self.simd_width]( self.ndshape.ndsize ) else: @@ -2656,7 +2646,7 @@ struct NDArray[dtype: DType = DType.float64]( fn vectorized_astypenb[width: Int](idx: Int) -> None: narr.store[width](idx, self.load[width](idx).cast[type]()) - vectorize[vectorized_astypenb, nelts](self.ndshape.ndsize) + vectorize[vectorized_astypenb, self.simd_width](self.ndshape.ndsize) return narr @@ -2939,11 +2929,11 @@ struct NDArray[dtype: DType = DType.float64]( """ return tround[dtype](self) - fn sort(inout self) raises: + fn sorted(inout self) raises: """ Sort the array inplace using quickstort. """ - sort.quick_sort[dtype](self) + sort.quick_sort_inplace[dtype](self, 0, self.size() - 1) fn sum(self: Self, axis: Int) raises -> Self: """ diff --git a/numojo/core/sort.mojo b/numojo/core/sort.mojo index 0fdb4dd..0b24b93 100644 --- a/numojo/core/sort.mojo +++ b/numojo/core/sort.mojo @@ -124,7 +124,7 @@ fn quick_sort_inplace[ fn quick_sort[ dtype: DType -](inout ndarray: NDArray[dtype]) raises: +](ndarray: NDArray[dtype]) raises -> NDArray[dtype]: """ Quick sort the NDArray. Adopt in-place partition. @@ -148,9 +148,11 @@ fn quick_sort[ """ + var result: NDArray[dtype] = ndarray var length = ndarray.size() + quick_sort_inplace(result, 0, length - 1) - quick_sort_inplace(ndarray, 0, length - 1) + return result # ===------------------------------------------------------------------------===# From 5aebfe954db8e11977bf769feef79a65484d041e Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 07:52:54 +0530 Subject: [PATCH 10/32] added dot function base case --- numojo/math/linalg/linalg.mojo | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/numojo/math/linalg/linalg.mojo b/numojo/math/linalg/linalg.mojo index 8df5fb8..cb0d9de 100644 --- a/numojo/math/linalg/linalg.mojo +++ b/numojo/math/linalg/linalg.mojo @@ -36,7 +36,7 @@ fn cross[ The cross product of two arrays. """ - if array1.ndshape.ndlen == array2.ndshape.ndlen == 3: + if (array1.ndshape.ndsize == array2.ndshape.ndsize == 3) and (array1.ndshape.ndlen == array2.ndshape.ndlen == 1): var array3: NDArray[dtype] = NDArray[dtype](NDArrayShape(3)) array3.store( 0, @@ -67,3 +67,42 @@ fn cross[ + " and " + array2.shape().__str__() ) + +# TODO: implement other cases for dot function +fn dot[ + dtype: DType = DType.float64 +](array1: NDArray[dtype], array2: NDArray[ dtype]) raises -> NDArray[ + dtype +]: + """ + Compute the dot product of two arrays. + + Parameters + dtype: The element type. + + Args: + array1: A array. + array2: A array. + + Constraints: + `array1` and `array2` must be 1 dimensional. + + Returns: + The dot product of two arrays. + """ + + alias opt_nelts = simdwidthof[dtype]() + if array1.ndshape.ndlen == array2.ndshape.ndlen == 1: + var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(3)) + @parameter + fn vectorized_dot[simd_width: Int](idx: Int) -> None: + result.store[width=simd_width](idx, array1.load[width=simd_width](idx) * array2.load[width=simd_width](idx)) + vectorize[vectorized_dot, opt_nelts](array1.ndshape.ndsize) + return result + else: + raise Error( + "Cross product is not supported for arrays of shape " + + array1.shape().__str__() + + " and " + + array2.shape().__str__() + ) From 0523f4a6256249785b7c73a01ce0bec942ef371a Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 07:53:14 +0530 Subject: [PATCH 11/32] added inplace flatten --- numojo/core/ndarray.mojo | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 967214a..c7965af 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2693,33 +2693,12 @@ struct NDArray[dtype: DType = DType.float64]( vectorize[vectorized_fill, simd_width](self.ndshape.ndsize) return self - fn flatten(inout self, inplace: Bool = False) raises -> Optional[Self]: + fn flatten(inout self) raises: """ Convert shape of array to one dimensional. """ - # inplace has some problems right now - # if inplace: - # self.ndshape = NDArrayShape(self.ndshape.ndsize, size=self.ndshape.ndsize) - # self.stride = NDArrayStride(shape = self.ndshape, offset=0) - # return self - - var res: NDArray[dtype] = NDArray[dtype]( - self.ndshape.ndsize, random=False - ) - alias simd_width: Int = simdwidthof[dtype]() - - @parameter - fn vectorized_flatten[simd_width: Int](index: Int) -> None: - res.data.store[width=simd_width]( - index, self.data.load[width=simd_width](index) - ) - - vectorize[vectorized_flatten, simd_width](self.ndshape.ndsize) - if inplace: - self = res - return None - else: - return res + self.ndshape = NDArrayShape(self.ndshape.ndsize, size=self.ndshape.ndsize) + self.stride = NDArrayStride(shape = self.ndshape, offset=0) fn item(self, *index: Int) raises -> SIMD[dtype, 1]: """ @@ -2922,7 +2901,7 @@ struct NDArray[dtype: DType = DType.float64]( fn round(self) raises -> Self: """ - Rounds the elements of the array to a whole number. + Rounds the elements of the array to a whole number. Returns: An NDArray. From 4c1945fabe2386cf5dde0bad61aae1e9aa577939 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 08:01:09 +0530 Subject: [PATCH 12/32] added inplace flatten and new alloc flatten methods --- numojo/core/array_manipulation_routines.mojo | 28 ++++++++++++++++++++ numojo/core/ndarray.mojo | 1 + 2 files changed, 29 insertions(+) diff --git a/numojo/core/array_manipulation_routines.mojo b/numojo/core/array_manipulation_routines.mojo index 90be19d..f996ae7 100644 --- a/numojo/core/array_manipulation_routines.mojo +++ b/numojo/core/array_manipulation_routines.mojo @@ -175,3 +175,31 @@ fn flip[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: for i in range(array.ndshape.ndsize): result.data.store(i, array.data[array.ndshape.ndsize - i - 1]) return result + +fn flatten[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: + """ + Flattens the NDArray. + + Parameters: + dtype: Dataype of the NDArray elements. + + Args: + array: A NDArray. + + Returns: + The 1 dimensional flattened NDArray. + """ + + var res: NDArray[dtype] = NDArray[dtype]( + array.ndshape.ndsize, random=False + ) + alias simd_width: Int = simdwidthof[dtype]() + + @parameter + fn vectorized_flatten[simd_width: Int](index: Int) -> None: + res.data.store[width=simd_width]( + index, array.data.load[width=simd_width](index) + ) + + vectorize[vectorized_flatten, simd_width](array.ndshape.ndsize) + return res \ No newline at end of file diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index c7965af..b14cfba 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2699,6 +2699,7 @@ struct NDArray[dtype: DType = DType.float64]( """ self.ndshape = NDArrayShape(self.ndshape.ndsize, size=self.ndshape.ndsize) self.stride = NDArrayStride(shape = self.ndshape, offset=0) + self.ndim = 1 fn item(self, *index: Int) raises -> SIMD[dtype, 1]: """ From 8b22ed940b48832e3d868c0b2a755708d41b2bd5 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 08:09:21 +0530 Subject: [PATCH 13/32] fixed typos and formatted --- CONTRIBUTING.md | 2 +- numojo/core/array_creation_routines.mojo | 46 +++--- numojo/core/array_manipulation_routines.mojo | 48 +++--- numojo/core/constants.mojo | 1 - numojo/core/ndarray.mojo | 42 +++--- numojo/core/random.mojo | 2 +- numojo/core/sort.mojo | 9 +- numojo/core/utility_funcs.mojo | 1 - numojo/math/arithmetic.mojo | 10 +- numojo/math/calculus/differentiation.mojo | 13 +- numojo/math/calculus/integral.mojo | 6 +- numojo/math/linalg/linalg.mojo | 25 +-- numojo/math/linalg/matmul.mojo | 4 +- numojo/math/math_funcs.mojo | 2 +- numojo/math/statistics/cumulative_reduce.mojo | 142 +++++++++--------- numojo/math/statistics/stats.mojo | 4 +- 16 files changed, 170 insertions(+), 187 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e80d7a7..ab2f63f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ Please follow the Mojo standard library style guide for all contributions. Consi - Write concise, well-documented code. - Adhere to formatting conventions for indentation, spacing, and line breaks. -Additionally refer to `style guide.md` for docstring and nameing conventions. +Additionally refer to `style guide.md` for docstring and naming conventions. ## Pull Requests diff --git a/numojo/core/array_creation_routines.mojo b/numojo/core/array_creation_routines.mojo index 2bb0fc6..db33e61 100644 --- a/numojo/core/array_creation_routines.mojo +++ b/numojo/core/array_creation_routines.mojo @@ -25,7 +25,7 @@ from .ndarray_utils import _get_index # Arranged Value NDArray generation # ===------------------------------------------------------------------------===# fn arange[ - dtype:DType = DType.float64 + dtype: DType = DType.float64 ]( start: Scalar[dtype], stop: Scalar[dtype], @@ -54,17 +54,11 @@ fn arange[ # raise Error( # "Both input and output datatypes cannot be integers. If the input is a float, the output must also be a float." # ) - - var num: Int = ((stop - start) / step).__int__() - var result: NDArray[dtype] = NDArray[dtype]( - NDArrayShape(num, size=num) - ) + var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(num, size=num)) for idx in range(num): - result.data[idx] = ( - start + step * idx - ) + result.data[idx] = start + step * idx return result @@ -112,13 +106,9 @@ fn linspace[ # ) constrained[not dtype.is_integral()]() if parallel: - return _linspace_parallel[dtype]( - start, stop, num, endpoint - ) + return _linspace_parallel[dtype](start, stop, num, endpoint) else: - return _linspace_serial[dtype]( - start, stop, num, endpoint - ) + return _linspace_serial[dtype](start, stop, num, endpoint) fn _linspace_serial[ @@ -386,18 +376,14 @@ fn geomspace[ if endpoint: var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(num)) - var r: Scalar[dtype] = ( - stop / start - ) ** (1 / (num - 1)) + var r: Scalar[dtype] = (stop / start) ** (1 / (num - 1)) for i in range(num): result.data[i] = a * r**i return result else: var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(num)) - var r: Scalar[dtype] = ( - stop / start - ) ** (1 / (num)) + var r: Scalar[dtype] = (stop / start) ** (1 / (num)) for i in range(num): result.data[i] = a * r**i return result @@ -541,7 +527,9 @@ fn full[ return NDArray[dtype](shape, fill=tens_value) -fn diagflat[dtype: DType](inout v: NDArray[dtype], k: Int = 0) raises -> NDArray[dtype]: +fn diagflat[ + dtype: DType +](inout v: NDArray[dtype], k: Int = 0) raises -> NDArray[dtype]: """ Generate a 2-D NDArray with the flattened input as the diagonal. @@ -556,15 +544,18 @@ fn diagflat[dtype: DType](inout v: NDArray[dtype], k: Int = 0) raises -> NDArray A 2-D NDArray with the flattened input as the diagonal. """ v.reshape(v.ndshape.ndsize, 1) - var n: Int= v.ndshape.ndsize + abs(k) - var result: NDArray[dtype]= NDArray[dtype](n, n, random=False) + var n: Int = v.ndshape.ndsize + abs(k) + var result: NDArray[dtype] = NDArray[dtype](n, n, random=False) if k > 0: for i in range(n): - result.store(n*i + i + k, v.data[i]) + result.store(n * i + i + k, v.data[i]) else: for i in range(n): - result.store(result.ndshape.ndsize - 1 - (n*i + i + abs(k)), v.data[v.ndshape.ndsize - 1 - i]) + result.store( + result.ndshape.ndsize - 1 - (n * i + i + abs(k)), + v.data[v.ndshape.ndsize - 1 - i], + ) return result @@ -590,6 +581,7 @@ fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: result.store(i, j, val=Scalar[dtype](1)) return result + fn tril[dtype: DType](inout m: NDArray[dtype], k: Int = 0) raises: """ Zero out elements above the k-th diagonal. @@ -604,7 +596,7 @@ fn tril[dtype: DType](inout m: NDArray[dtype], k: Int = 0) raises: var index: List[Int] = List[Int]() for _ in range(m.ndshape.ndlen): index.append(0) - + for i in range(m.ndshape[-1]): for j in range(m.ndshape[-2]): var idx: Int = _get_index(index, m.ndshape) diff --git a/numojo/core/array_manipulation_routines.mojo b/numojo/core/array_manipulation_routines.mojo index f996ae7..f498e5c 100644 --- a/numojo/core/array_manipulation_routines.mojo +++ b/numojo/core/array_manipulation_routines.mojo @@ -7,7 +7,6 @@ Array manipulation routines. # ===----------------------------------------------------------------------=== # - fn copyto(): pass @@ -176,30 +175,29 @@ fn flip[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: result.data.store(i, array.data[array.ndshape.ndsize - i - 1]) return result + fn flatten[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: - """ - Flattens the NDArray. - - Parameters: - dtype: Dataype of the NDArray elements. - - Args: - array: A NDArray. - - Returns: - The 1 dimensional flattened NDArray. - """ - - var res: NDArray[dtype] = NDArray[dtype]( - array.ndshape.ndsize, random=False - ) - alias simd_width: Int = simdwidthof[dtype]() + """ + Flattens the NDArray. + + Parameters: + dtype: Dataype of the NDArray elements. + + Args: + array: A NDArray. - @parameter - fn vectorized_flatten[simd_width: Int](index: Int) -> None: - res.data.store[width=simd_width]( - index, array.data.load[width=simd_width](index) - ) + Returns: + The 1 dimensional flattened NDArray. + """ + + var res: NDArray[dtype] = NDArray[dtype](array.ndshape.ndsize, random=False) + alias simd_width: Int = simdwidthof[dtype]() + + @parameter + fn vectorized_flatten[simd_width: Int](index: Int) -> None: + res.data.store[width=simd_width]( + index, array.data.load[width=simd_width](index) + ) - vectorize[vectorized_flatten, simd_width](array.ndshape.ndsize) - return res \ No newline at end of file + vectorize[vectorized_flatten, simd_width](array.ndshape.ndsize) + return res diff --git a/numojo/core/constants.mojo b/numojo/core/constants.mojo index 1bd54f2..4664b09 100644 --- a/numojo/core/constants.mojo +++ b/numojo/core/constants.mojo @@ -7,7 +7,6 @@ Constants # ===----------------------------------------------------------------------=== # - @value struct Constants(AnyType): """Define constants. diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index b14cfba..76d5acf 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -942,7 +942,7 @@ struct NDArray[dtype: DType = DType.float64]( ``` A is an array with shape 2 x 2 and randomly values between 0 and 10. The output goes as follows. - + ```console [[ 6.046875 6.98046875 ] [ 6.6484375 1.736328125 ]] @@ -959,16 +959,17 @@ struct NDArray[dtype: DType = DType.float64]( if dtype.is_floating_point(): for i in range(self.ndshape.ndsize): self.data.store( - i, - random_float64(min.cast[DType.float64](), max.cast[DType.float64]()).cast[dtype]() + i, + random_float64( + min.cast[DType.float64](), max.cast[DType.float64]() + ).cast[dtype](), ) elif dtype.is_integral(): for i in range(self.ndshape.ndsize): self.data.store( - i, - random_si64(int(min), int(max)).cast[dtype]() + i, random_si64(int(min), int(max)).cast[dtype]() ) - + @always_inline("nodebug") fn __init__( inout self, @@ -995,7 +996,7 @@ struct NDArray[dtype: DType = DType.float64]( ``` A is an array with shape 2 x 2 and randomly values between 0 and 10. The output goes as follows. - + ```console [[ 6.046875 6.98046875 ] [ 6.6484375 1.736328125 ]] @@ -1012,14 +1013,15 @@ struct NDArray[dtype: DType = DType.float64]( if dtype.is_floating_point(): for i in range(self.ndshape.ndsize): self.data.store( - i, - random_float64(min.cast[DType.float64](), max.cast[DType.float64]()).cast[dtype]() + i, + random_float64( + min.cast[DType.float64](), max.cast[DType.float64]() + ).cast[dtype](), ) elif dtype.is_integral(): for i in range(self.ndshape.ndsize): self.data.store( - i, - random_si64(int(min), int(max)).cast[dtype]() + i, random_si64(int(min), int(max)).cast[dtype]() ) fn __init__( @@ -2646,7 +2648,9 @@ struct NDArray[dtype: DType = DType.float64]( fn vectorized_astypenb[width: Int](idx: Int) -> None: narr.store[width](idx, self.load[width](idx).cast[type]()) - vectorize[vectorized_astypenb, self.simd_width](self.ndshape.ndsize) + vectorize[vectorized_astypenb, self.simd_width]( + self.ndshape.ndsize + ) return narr @@ -2697,8 +2701,10 @@ struct NDArray[dtype: DType = DType.float64]( """ Convert shape of array to one dimensional. """ - self.ndshape = NDArrayShape(self.ndshape.ndsize, size=self.ndshape.ndsize) - self.stride = NDArrayStride(shape = self.ndshape, offset=0) + self.ndshape = NDArrayShape( + self.ndshape.ndsize, size=self.ndshape.ndsize + ) + self.stride = NDArrayStride(shape=self.ndshape, offset=0) self.ndim = 1 fn item(self, *index: Int) raises -> SIMD[dtype, 1]: @@ -2905,11 +2911,11 @@ struct NDArray[dtype: DType = DType.float64]( Rounds the elements of the array to a whole number. Returns: - An NDArray. + An NDArray. """ return tround[dtype](self) - fn sorted(inout self) raises: + fn sort(inout self) raises: """ Sort the array inplace using quickstort. """ @@ -2936,9 +2942,9 @@ struct NDArray[dtype: DType = DType.float64]( for i in range(self.ndshape.ndsize): result.append(self.data[i]) return result - + # fn trace(self): - # pass + # pass # Technically it only changes the ArrayDescriptor and not the fundamental data fn reshape(inout self, *shape: Int, order: String = "C") raises: diff --git a/numojo/core/random.mojo b/numojo/core/random.mojo index 14b579a..a10b1fd 100644 --- a/numojo/core/random.mojo +++ b/numojo/core/random.mojo @@ -2,7 +2,7 @@ Random values array generation. """ # ===----------------------------------------------------------------------=== # -# Implements RANDOM +# Implements RANDOM # Last updated: 2024-06-18 # ===----------------------------------------------------------------------=== # diff --git a/numojo/core/sort.mojo b/numojo/core/sort.mojo index 0b24b93..122c737 100644 --- a/numojo/core/sort.mojo +++ b/numojo/core/sort.mojo @@ -122,9 +122,7 @@ fn quick_sort_inplace[ quick_sort_inplace(ndarray, pivot_new_index + 1, right) -fn quick_sort[ - dtype: DType -](ndarray: NDArray[dtype]) raises -> NDArray[dtype]: +fn quick_sort[dtype: DType](ndarray: NDArray[dtype]) raises -> NDArray[dtype]: """ Quick sort the NDArray. Adopt in-place partition. @@ -161,8 +159,8 @@ fn quick_sort[ fn binary_sort[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> NDArray[dtype]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> NDArray[dtype]: """ Binary sorting of NDArray. @@ -182,6 +180,7 @@ fn binary_sort[ Returns: The sorted NDArray of type `dtype`. """ + @parameter if dtype != array.dtype: alias dtype = array.dtype diff --git a/numojo/core/utility_funcs.mojo b/numojo/core/utility_funcs.mojo index 89dfb62..49ff53d 100644 --- a/numojo/core/utility_funcs.mojo +++ b/numojo/core/utility_funcs.mojo @@ -7,7 +7,6 @@ Type related utility functions. # ===----------------------------------------------------------------------=== # - fn is_inttype[dtype: DType]() -> Bool: """ Check if the given dtype is an integer type at compile time. diff --git a/numojo/math/arithmetic.mojo b/numojo/math/arithmetic.mojo index 2e270de..cefc9d3 100644 --- a/numojo/math/arithmetic.mojo +++ b/numojo/math/arithmetic.mojo @@ -198,8 +198,8 @@ fn sub[ fn diff[ - dtype: DType = DType.float64 -](array: NDArray[ dtype], n: Int) raises -> NDArray[dtype]: + dtype: DType = DType.float64 +](array: NDArray[dtype], n: Int) raises -> NDArray[dtype]: """ Compute the n-th order difference of the input array. @@ -225,9 +225,7 @@ fn diff[ NDArrayShape(array.num_elements() - (num + 1)) ) for i in range(array1.num_elements() - 1): - result.store( - i, (array1.load[1](i + 1) - array1.load[1](i)) - ) + result.store(i, (array1.load[1](i + 1) - array1.load[1](i))) array1 = result return array1 @@ -1172,5 +1170,3 @@ fn invert[ return backend().math_func_1_array_in_one_array_out[dtype, SIMD.__invert__]( array ) - - diff --git a/numojo/math/calculus/differentiation.mojo b/numojo/math/calculus/differentiation.mojo index 19a5ada..df96ff2 100644 --- a/numojo/math/calculus/differentiation.mojo +++ b/numojo/math/calculus/differentiation.mojo @@ -34,7 +34,7 @@ fn gradient[ Returns: The integral of y over x using the trapezoidal rule. """ - + var result: NDArray[dtype] = NDArray[dtype](x.shape(), random=False) var space: NDArray[dtype] = core.arange[dtype]( 1, x.num_elements() + 1, step=spacing @@ -43,8 +43,7 @@ fn gradient[ var hd: Scalar[dtype] = space.get_scalar(0) result.store( 0, - (x.get_scalar(1) - x.get_scalar(0)) - / (hu - hd), + (x.get_scalar(1) - x.get_scalar(0)) / (hu - hd), ) hu = space.get_scalar(x.num_elements() - 1) @@ -59,12 +58,8 @@ fn gradient[ ) for i in range(1, x.num_elements() - 1): - var hu: Scalar[dtype] = space.get_scalar(i + 1) - space.get_scalar( - i - ) - var hd: Scalar[dtype] = space.get_scalar(i) - space.get_scalar( - i - 1 - ) + var hu: Scalar[dtype] = space.get_scalar(i + 1) - space.get_scalar(i) + var hd: Scalar[dtype] = space.get_scalar(i) - space.get_scalar(i - 1) var fi: Scalar[dtype] = ( hd**2 * x.get_scalar(i + 1) + (hu**2 - hd**2) * x.get_scalar(i) diff --git a/numojo/math/calculus/integral.mojo b/numojo/math/calculus/integral.mojo index 02fcab3..ebd521f 100644 --- a/numojo/math/calculus/integral.mojo +++ b/numojo/math/calculus/integral.mojo @@ -13,8 +13,8 @@ from algorithm import Static2DTileUnitFunc as Tile2DFunc # naive loop implementation, optimize later fn trapz[ - dtype: DType = DType.float64 -](y: NDArray[ dtype], x: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](y: NDArray[dtype], x: NDArray[dtype]) raises -> SIMD[dtype, 1]: """ Compute the integral of y over x using the trapezoidal rule. @@ -36,7 +36,7 @@ fn trapz[ raise Error("x and y must have the same shape") # move this check to compile time using constrained? - if is_inttype[ dtype]() and not is_floattype[dtype](): + if is_inttype[dtype]() and not is_floattype[dtype](): raise Error( "output dtype `Fdtype` must be a floating-point type if input dtype" " `Idtype` is not a floating-point type" diff --git a/numojo/math/linalg/linalg.mojo b/numojo/math/linalg/linalg.mojo index cb0d9de..066b017 100644 --- a/numojo/math/linalg/linalg.mojo +++ b/numojo/math/linalg/linalg.mojo @@ -15,10 +15,8 @@ from algorithm import Static2DTileUnitFunc as Tile2DFunc fn cross[ - dtype: DType = DType.float64 -](array1: NDArray[ dtype], array2: NDArray[ dtype]) raises -> NDArray[ - dtype -]: + dtype: DType = DType.float64 +](array1: NDArray[dtype], array2: NDArray[dtype]) raises -> NDArray[dtype]: """ Compute the cross product of two arrays. @@ -36,7 +34,9 @@ fn cross[ The cross product of two arrays. """ - if (array1.ndshape.ndsize == array2.ndshape.ndsize == 3) and (array1.ndshape.ndlen == array2.ndshape.ndlen == 1): + if (array1.ndshape.ndsize == array2.ndshape.ndsize == 3) and ( + array1.ndshape.ndlen == array2.ndshape.ndlen == 1 + ): var array3: NDArray[dtype] = NDArray[dtype](NDArrayShape(3)) array3.store( 0, @@ -68,12 +68,11 @@ fn cross[ + array2.shape().__str__() ) + # TODO: implement other cases for dot function fn dot[ - dtype: DType = DType.float64 -](array1: NDArray[dtype], array2: NDArray[ dtype]) raises -> NDArray[ - dtype -]: + dtype: DType = DType.float64 +](array1: NDArray[dtype], array2: NDArray[dtype]) raises -> NDArray[dtype]: """ Compute the dot product of two arrays. @@ -94,9 +93,15 @@ fn dot[ alias opt_nelts = simdwidthof[dtype]() if array1.ndshape.ndlen == array2.ndshape.ndlen == 1: var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(3)) + @parameter fn vectorized_dot[simd_width: Int](idx: Int) -> None: - result.store[width=simd_width](idx, array1.load[width=simd_width](idx) * array2.load[width=simd_width](idx)) + result.store[width=simd_width]( + idx, + array1.load[width=simd_width](idx) + * array2.load[width=simd_width](idx), + ) + vectorize[vectorized_dot, opt_nelts](array1.ndshape.ndsize) return result else: diff --git a/numojo/math/linalg/matmul.mojo b/numojo/math/linalg/matmul.mojo index 5c4df88..e989e18 100644 --- a/numojo/math/linalg/matmul.mojo +++ b/numojo/math/linalg/matmul.mojo @@ -67,9 +67,9 @@ fn matmul_parallelized[ dtype: DType ](A: NDArray[dtype], B: NDArray[dtype]) raises -> NDArray[dtype]: """ - + Matrix multiplication Vectorized and parallelized. - + Conduct `matmul` using `vectorize` and `parallelize`. Reference: https://docs.modular.com/mojo/notebooks/Matmul diff --git a/numojo/math/math_funcs.mojo b/numojo/math/math_funcs.mojo index 2bc0a52..0389304 100644 --- a/numojo/math/math_funcs.mojo +++ b/numojo/math/math_funcs.mojo @@ -351,7 +351,7 @@ fn bool_simd_store[ Parameters: width: Number of items to be retrieved. - + Args: ptr: Pointer to be retreived from. start: Start position in pointer. diff --git a/numojo/math/statistics/cumulative_reduce.mojo b/numojo/math/statistics/cumulative_reduce.mojo index 720ce15..b92210f 100644 --- a/numojo/math/statistics/cumulative_reduce.mojo +++ b/numojo/math/statistics/cumulative_reduce.mojo @@ -27,8 +27,8 @@ TODO: fn cumsum[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) -> SIMD[dtype, 1]: """Sum of all items of an array. Parameters: @@ -41,20 +41,20 @@ fn cumsum[ The sum of all items in the array as a SIMD Value of `dtype`. """ var result = Scalar[dtype]() - alias opt_nelts: Int = simdwidthof[ dtype]() + alias opt_nelts: Int = simdwidthof[dtype]() @parameter fn vectorize_sum[simd_width: Int](idx: Int) -> None: var simd_data = array.load[width=simd_width](idx) - result += (simd_data.reduce_add()) + result += simd_data.reduce_add() vectorize[vectorize_sum, opt_nelts](array.num_elements()) return result fn cumprod[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) -> SIMD[dtype, 1]: """Product of all items in an array. Parameters: @@ -68,12 +68,12 @@ fn cumprod[ """ var result: SIMD[dtype, 1] = SIMD[dtype, 1](1.0) - alias opt_nelts = simdwidthof[ dtype]() + alias opt_nelts = simdwidthof[dtype]() @parameter fn vectorize_sum[simd_width: Int](idx: Int) -> None: var simd_data = array.load[width=simd_width](idx) - result *= (simd_data.reduce_mul()) + result *= simd_data.reduce_mul() vectorize[vectorize_sum, opt_nelts](array.num_elements()) return result @@ -86,8 +86,8 @@ fn cumprod[ fn cummean[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """Arithmatic mean of all items of an array. Parameters: @@ -100,17 +100,17 @@ fn cummean[ The mean of all of the member values of array as a SIMD Value of `dtype`. """ # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[ dtype]() and is_inttype[dtype](): + if is_inttype[dtype]() and is_inttype[dtype](): raise Error( "Input and output cannot be `Int` datatype as it may lead to" " precision errors" ) - return cumsum[ dtype](array) / (array.num_elements()) + return cumsum[dtype](array) / (array.num_elements()) fn mode[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """Mode of all items of an array. Parameters: @@ -122,9 +122,7 @@ fn mode[ Returns: The mode of all of the member values of array as a SIMD Value of `dtype`. """ - var sorted_array: NDArray[dtype] = binary_sort[ dtype]( - array - ) + var sorted_array: NDArray[dtype] = binary_sort[dtype](array) var max_count = 0 var mode_value = sorted_array.item(0) var current_count = 1 @@ -146,8 +144,8 @@ fn mode[ # * IMPLEMENT median high and low fn median[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """Median value of all items of an array. Parameters: @@ -159,7 +157,7 @@ fn median[ Returns: The median of all of the member values of array as a SIMD Value of `dtype`. """ - var sorted_array = binary_sort[ dtype](array) + var sorted_array = binary_sort[dtype](array) var n = array.num_elements() if n % 2 == 1: return sorted_array.item(n // 2) @@ -169,8 +167,8 @@ fn median[ # for max and min, I can later change to the latest reduce.max, reduce.min() fn maxT[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """ Maximum value of a array. @@ -183,8 +181,8 @@ fn maxT[ The maximum of all of the member values of array as a SIMD Value of `dtype`. """ # TODO: Test this - alias opt_nelts = simdwidthof[ dtype]() - var max_value = NDArray[ dtype](NDArrayShape(opt_nelts)) + alias opt_nelts = simdwidthof[dtype]() + var max_value = NDArray[dtype](NDArrayShape(opt_nelts)) for i in range(opt_nelts): max_value[i] = array[0] # var max_value: SIMD[ dtype, opt_nelts] = SIMD[ dtype, opt_nelts](array[0]) @@ -201,7 +199,7 @@ fn maxT[ vectorize[vectorized_max, opt_nelts](array.num_elements()) - var result: Scalar[ dtype] = Scalar[dtype](max_value.get_scalar(0)) + var result: Scalar[dtype] = Scalar[dtype](max_value.get_scalar(0)) for i in range(max_value.__len__()): if max_value.get_scalar(i) > result: result = max_value.get_scalar(i) @@ -209,8 +207,8 @@ fn maxT[ fn minT[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """ Minimum value of a array. @@ -223,8 +221,8 @@ fn minT[ Returns: The minimum of all of the member values of array as a SIMD Value of `dtype`. """ - alias opt_nelts = simdwidthof[ dtype]() - var min_value = NDArray[ dtype](NDArrayShape(opt_nelts)) + alias opt_nelts = simdwidthof[dtype]() + var min_value = NDArray[dtype](NDArrayShape(opt_nelts)) for i in range(opt_nelts): min_value[i] = array[0] @@ -240,7 +238,7 @@ fn minT[ vectorize[vectorized_min, opt_nelts](array.num_elements()) - var result: Scalar[ dtype] = Scalar[dtype](min_value.get_scalar(0)) + var result: Scalar[dtype] = Scalar[dtype](min_value.get_scalar(0)) for i in range(min_value.__len__()): if min_value.get_scalar(i) < result: result = min_value.get_scalar(i) @@ -249,10 +247,10 @@ fn minT[ fn cumpvariance[ - dtype: DType = DType.float64 -]( - array: NDArray[ dtype], mu: Optional[Scalar[ dtype]] = None -) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype], mu: Optional[Scalar[dtype]] = None) raises -> SIMD[ + dtype, 1 +]: """ Population variance of a array. @@ -266,7 +264,7 @@ fn cumpvariance[ The variance of all of the member values of array as a SIMD Value of `dtype`. """ # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[ dtype]() and is_inttype[dtype](): + if is_inttype[dtype]() and is_inttype[dtype](): raise Error( "Input and output cannot be `Int` datatype as it may lead to" " precision errors" @@ -274,7 +272,7 @@ fn cumpvariance[ var mean_value: Scalar[dtype] if not mu: - mean_value = cummean[ dtype](array) + mean_value = cummean[dtype](array) else: mean_value = mu.value()[] @@ -287,10 +285,10 @@ fn cumpvariance[ fn cumvariance[ - dtype: DType = DType.float64 -]( - array: NDArray[ dtype], mu: Optional[Scalar[ dtype]] = None -) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype], mu: Optional[Scalar[dtype]] = None) raises -> SIMD[ + dtype, 1 +]: """ Variance of a array. @@ -305,7 +303,7 @@ fn cumvariance[ The variance of all of the member values of array as a SIMD Value of `dtype`. """ # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[ dtype]() and is_inttype[dtype](): + if is_inttype[dtype]() and is_inttype[dtype](): raise Error( "Input and output cannot be `Int` datatype as it may lead to" " precision errors" @@ -313,7 +311,7 @@ fn cumvariance[ var mean_value: Scalar[dtype] if not mu: - mean_value = cummean[ dtype](array) + mean_value = cummean[dtype](array) else: mean_value = mu.value()[] @@ -325,10 +323,10 @@ fn cumvariance[ fn cumpstdev[ - dtype: DType = DType.float64 -]( - array: NDArray[ dtype], mu: Optional[Scalar[ dtype]] = None -) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype], mu: Optional[Scalar[dtype]] = None) raises -> SIMD[ + dtype, 1 +]: """ Population standard deviation of a array. @@ -343,19 +341,19 @@ fn cumpstdev[ The standard deviation of all of the member values of array as a SIMD Value of `dtype`. """ # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[ dtype]() and is_inttype[dtype](): + if is_inttype[dtype]() and is_inttype[dtype](): raise Error( "Input and output cannot be `Int` datatype as it may lead to" " precision errors" ) - return math.sqrt(cumpvariance[ dtype](array, mu)) + return math.sqrt(cumpvariance[dtype](array, mu)) fn cumstdev[ - dtype: DType = DType.float64 -]( - array: NDArray[ dtype], mu: Optional[Scalar[ dtype]] = None -) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype], mu: Optional[Scalar[dtype]] = None) raises -> SIMD[ + dtype, 1 +]: """ Standard deviation of a array. @@ -369,18 +367,18 @@ fn cumstdev[ The standard deviation of all of the member values of array as a SIMD Value of `dtype`. """ # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[ dtype]() and is_inttype[dtype](): + if is_inttype[dtype]() and is_inttype[dtype](): raise Error( "Input and output cannot be `Int` datatype as it may lead to" " precision errors" ) - return math.sqrt(cumvariance[ dtype](array, mu)) + return math.sqrt(cumvariance[dtype](array, mu)) # this roughly seems to be just an alias for min in numpy fn amin[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """ Minimum value of an array. @@ -392,13 +390,13 @@ fn amin[ Returns: The minimum of all of the member values of array as a SIMD Value of `dtype`. """ - return minT[ dtype](array) + return minT[dtype](array) # this roughly seems to be just an alias for max in numpy fn amax[ - dtype: DType = DType.float64 -](array: NDArray[ dtype]) raises -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](array: NDArray[dtype]) raises -> SIMD[dtype, 1]: """ Maximum value of a array. @@ -410,12 +408,12 @@ fn amax[ Returns: The maximum of all of the member values of array as a SIMD Value of `dtype`. """ - return maxT[ dtype](array) + return maxT[dtype](array) fn mimimum[ - dtype: DType = DType.float64 -](s1: SIMD[ dtype, 1], s2: SIMD[ dtype, 1]) -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](s1: SIMD[dtype, 1], s2: SIMD[dtype, 1]) -> SIMD[dtype, 1]: """ Minimum value of two SIMD values. @@ -432,8 +430,8 @@ fn mimimum[ fn maximum[ - dtype: DType = DType.float64 -](s1: SIMD[ dtype, 1], s2: SIMD[ dtype, 1]) -> SIMD[dtype, 1]: + dtype: DType = DType.float64 +](s1: SIMD[dtype, 1], s2: SIMD[dtype, 1]) -> SIMD[dtype, 1]: """ Maximum value of two SIMD values. @@ -450,10 +448,8 @@ fn maximum[ fn minimum[ - dtype: DType = DType.float64 -](array1: NDArray[ dtype], array2: NDArray[ dtype]) raises -> NDArray[ - dtype -]: + dtype: DType = DType.float64 +](array1: NDArray[dtype], array2: NDArray[dtype]) raises -> NDArray[dtype]: """ Element wise minimum of two arrays. @@ -468,7 +464,7 @@ fn minimum[ """ var result: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias nelts = simdwidthof[ dtype]() + alias nelts = simdwidthof[dtype]() if array1.shape() != array2.shape(): raise Error("array shapes are not the same") @@ -487,10 +483,8 @@ fn minimum[ fn maximum[ - dtype: DType = DType.float64 -](array1: NDArray[ dtype], array2: NDArray[ dtype]) raises -> NDArray[ - dtype -]: + dtype: DType = DType.float64 +](array1: NDArray[dtype], array2: NDArray[dtype]) raises -> NDArray[dtype]: """ Element wise maximum of two arrays. @@ -505,7 +499,7 @@ fn maximum[ """ var result: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias nelts = simdwidthof[ dtype]() + alias nelts = simdwidthof[dtype]() if array1.shape() != array2.shape(): raise Error("array shapes are not the same") diff --git a/numojo/math/statistics/stats.mojo b/numojo/math/statistics/stats.mojo index a4c5b41..99eb0d3 100644 --- a/numojo/math/statistics/stats.mojo +++ b/numojo/math/statistics/stats.mojo @@ -193,7 +193,7 @@ fn max[ Args: array: NDArray. axis: The axis along which the sum is performed. - + Returns: An NDArray. """ @@ -239,7 +239,7 @@ fn min[ Args: array: NDArray. axis: The axis along which the sum is performed. - + Returns: An NDArray. """ From b054d7bdf82800e3f2d2d0e9dd513eb993f88e13 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 11:55:30 +0530 Subject: [PATCH 14/32] added trace for 2D arrays --- numojo/core/array_manipulation_routines.mojo | 32 ++++++++++++++++++++ numojo/core/ndarray.mojo | 20 ++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/numojo/core/array_manipulation_routines.mojo b/numojo/core/array_manipulation_routines.mojo index f498e5c..34e2940 100644 --- a/numojo/core/array_manipulation_routines.mojo +++ b/numojo/core/array_manipulation_routines.mojo @@ -201,3 +201,35 @@ fn flatten[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: vectorize[vectorized_flatten, simd_width](array.ndshape.ndsize) return res + +# TODO: implement for arbitrary axis +fn trace[dtype: DType](array: NDArray[dtype], offset: Int = 0, axis1: Int = 0 , axis2: Int = 1) raises -> NDArray[dtype]: + """ + Computes the trace of a ndarray. + + Parameters: + dtype: data type of the array. + + Args: + offset: offset of the diagonal from the main diagonal. (default: 0) + axis1: first axis. (default: 0) + axis2: second axis. (default: 1) + + Returns: + the trace of the ndarray. + """ + if array.ndim != 2: + raise Error("Trace is currently only supported for 2D arrays") + if axis1 > array.ndim - 1 or axis2 > array.ndim - 1: + raise Error("axis cannot be greater than the rank of the array") + var result: NDArray[dtype] = NDArray[dtype](1, random=False) + var rows = array.ndshape[0] + var cols = array.ndshape[1] + var diag_length = min(rows, cols - offset) if offset >= 0 else min(rows + offset, cols) + + for i in range(diag_length): + var row = i if offset >= 0 else i - offset + var col = i + offset if offset >= 0 else i + result.data.store(0, result.data.load(0) + array.data[row * cols + col]) + + return result \ No newline at end of file diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 76d5acf..805023d 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2943,8 +2943,24 @@ struct NDArray[dtype: DType = DType.float64]( result.append(self.data[i]) return result - # fn trace(self): - # pass + # TODO: add axis parameter + fn trace[dtype: dtype](self, offset: int = 0, axis1: int = 0 , axis2: int = 1) -> NDArray[dtype]: + """ + computes the trace of a ndarray. + + parameters: + dtype: data type of the array. + + args: + offset: offset of the diagonal from the main diagonal. (default: 0) + axis1: first axis. (default: 0) + axis2: second axis. (default: 1) + + returns: + the trace of the ndarray. + """ + return trace[dtype](self, offset, axis1, axis2) + # Technically it only changes the ArrayDescriptor and not the fundamental data fn reshape(inout self, *shape: Int, order: String = "C") raises: From b1fe89a027237bc096beba8fc11510a9c2cccc19 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 11:55:43 +0530 Subject: [PATCH 15/32] removed tril triu temporarily --- numojo/core/array_creation_routines.mojo | 50 ++++++++++++------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/numojo/core/array_creation_routines.mojo b/numojo/core/array_creation_routines.mojo index db33e61..dd46ec4 100644 --- a/numojo/core/array_creation_routines.mojo +++ b/numojo/core/array_creation_routines.mojo @@ -582,29 +582,27 @@ fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: return result -fn tril[dtype: DType](inout m: NDArray[dtype], k: Int = 0) raises: - """ - Zero out elements above the k-th diagonal. - - Parameters: - dtype: Datatype of the NDArray elements. - - Args: - m: NDArray to be zeroed out. - k: Diagonal offset. - """ - var index: List[Int] = List[Int]() - for _ in range(m.ndshape.ndlen): - index.append(0) - - for i in range(m.ndshape[-1]): - for j in range(m.ndshape[-2]): - var idx: Int = _get_index(index, m.ndshape) - if i >= j - k: - m.data[idx] = Scalar[dtype](0) - index[-2] += 1 - index[-1] += 1 - - -fn triu(): - pass +# fn tril[dtype: DType](inout m: NDArray[dtype], k: Int = 0) raises: + # """ + # Zero out elements above the k-th diagonal. + + # Parameters: + # dtype: Datatype of the NDArray elements. + + # Args: + # m: NDArray to be zeroed out. + # k: Diagonal offset. + # """ + # var index: List[Int] = List[Int]() + # for _ in range(m.ndshape.ndlen): + # index.append(0) + + # for i in range(m.ndshape[-1]): + # for j in range(m.ndshape[-2]): + # var idx: Int = _get_index(index, m.ndshape) + # if i >= j - k: + # m.data[idx] = Scalar[dtype](0) + # index[-2] += 1 + +# fn triu(): + # pass From b9bfc18d7db0695247fec3a9485850acbaa87aaf Mon Sep 17 00:00:00 2001 From: darth-photon Date: Fri, 16 Aug 2024 12:01:52 +0530 Subject: [PATCH 16/32] fixed docstrings for trace --- numojo/core/array_manipulation_routines.mojo | 11 ++++++----- numojo/core/ndarray.mojo | 19 ++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/numojo/core/array_manipulation_routines.mojo b/numojo/core/array_manipulation_routines.mojo index 34e2940..710923c 100644 --- a/numojo/core/array_manipulation_routines.mojo +++ b/numojo/core/array_manipulation_routines.mojo @@ -208,15 +208,16 @@ fn trace[dtype: DType](array: NDArray[dtype], offset: Int = 0, axis1: Int = 0 , Computes the trace of a ndarray. Parameters: - dtype: data type of the array. + dtype: Data type of the array. Args: - offset: offset of the diagonal from the main diagonal. (default: 0) - axis1: first axis. (default: 0) - axis2: second axis. (default: 1) + array: A NDArray. + offset: Offset of the diagonal from the main diagonal. + axis1: First axis. + axis2: Second axis. Returns: - the trace of the ndarray. + The trace of the NDArray. """ if array.ndim != 2: raise Error("Trace is currently only supported for 2D arrays") diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 805023d..c517c63 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2944,20 +2944,17 @@ struct NDArray[dtype: DType = DType.float64]( return result # TODO: add axis parameter - fn trace[dtype: dtype](self, offset: int = 0, axis1: int = 0 , axis2: int = 1) -> NDArray[dtype]: + fn trace(self, offset: Int = 0, axis1: Int = 0 , axis2: Int = 1) raises -> NDArray[dtype]: """ - computes the trace of a ndarray. + Computes the trace of a ndarray. - parameters: - dtype: data type of the array. - - args: - offset: offset of the diagonal from the main diagonal. (default: 0) - axis1: first axis. (default: 0) - axis2: second axis. (default: 1) + Args: + offset: Offset of the diagonal from the main diagonal. + axis1: First axis. + axis2: Second axis. - returns: - the trace of the ndarray. + Returns: + The trace of the ndarray. """ return trace[dtype](self, offset, axis1, axis2) From a757869f705203ae5e4bdb83f2500f10c6c06a85 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Sat, 17 Aug 2024 12:37:59 +0530 Subject: [PATCH 17/32] test --- test.mojo | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test.mojo b/test.mojo index d882dc3..24d1882 100644 --- a/test.mojo +++ b/test.mojo @@ -18,16 +18,25 @@ from numojo import * # print(res) fn main() raises: - var A = arange[i16](1, 10, 1) + # var A = arange[i16](1, 10, 1) + # print(A) + # A.reshape(3, 3) + # print(A) + var A = NDArray[i8](3, 4, random=True) print(A) + print(trace(A, offset = 1, axis1=0, axis2=1)) + # var A = NDArray[i16](5, random=True) + # print(A) + # A.sort() + # print(A) # var B = tri[i16](3, 5, -1) # print(B) # var temp = flip(A) # print(temp) - A.reshape(3, 3, order="F") - print(A) - tril[i16](A, k=1) - print(A) + # A.flatten() + # print(A) + # tril[i16](A, k=1) + # print(A) # var temp1 = diagflat(A, k=-2) # print(temp1) # A.reshape(2, 3, order="F") From 1157c0c69f4faa49872de5ccf2d84a8d1a40f91a Mon Sep 17 00:00:00 2001 From: darth-photon Date: Thu, 22 Aug 2024 11:19:02 +0530 Subject: [PATCH 18/32] added constructor method to initialize from numpy arrays --- numojo/core/ndarray.mojo | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index c517c63..63d61a1 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -21,6 +21,7 @@ from builtin.math import pow from builtin.bool import all as allb from builtin.bool import any as anyb from algorithm import parallelize, vectorize +from python import Python import . _array_funcs as _af from ..math.statistics.stats import mean, prod, sum @@ -1139,6 +1140,36 @@ struct NDArray[dtype: DType = DType.float64]( self.data = DTypePointer[dtype].alloc(size) memset_zero(self.data, size) + # creating NDArray from numpy array + fn __init__(inout self, *shape: Int, data: PythonObject, order: String = "C") raises: + self.ndim = shape.__len__() + self.ndshape = NDArrayShape(shape) + self.stride = NDArrayStride(shape, offset=0, order=order) + self.coefficient = NDArrayStride(shape, offset=0, order=order) + self.data = DTypePointer[dtype].alloc(self.ndshape.ndsize) + memset_zero(self.data, self.ndshape.ndsize) + self.datatype = dtype + self.order = order + for i in range(self.ndshape.ndsize): + self.data[i] = data.item(PythonObject(i)).to_float64() + # if self.datatype != DType.float64: + # raise Error("Only float64 is supported for now") + + # var array: PythonObject + # try: + # var np = Python.import_module("numpy") + # array = np.float32(data.copy()) + # except e: + # array = data.copy() + # print("Error in to_tensor", e) + + # var pointer = int(array.__array_interface__["data"][0].to_float64()) + # var pointer_d = DTypePointer[self.dtype](address=pointer) + # memcpy(self.data, pointer_d, self.ndshape.ndsize) + + # _ = array # to avoid unused variable warning + # _ = data + # for creating views fn __init__( inout self, From 6d20792cdd92f5ab7e9c30e0003a94e92945a5d2 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Thu, 22 Aug 2024 12:59:10 +0530 Subject: [PATCH 19/32] added transpose T() internal method for 2d arrays --- numojo/core/ndarray.mojo | 53 ++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 63d61a1..1b17a47 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -1141,7 +1141,10 @@ struct NDArray[dtype: DType = DType.float64]( memset_zero(self.data, size) # creating NDArray from numpy array + # TODO: Make it work for all data types apart from float64 fn __init__(inout self, *shape: Int, data: PythonObject, order: String = "C") raises: + if dtype != DType.float64: + raise Error("Only float64 is supported for now") self.ndim = shape.__len__() self.ndshape = NDArrayShape(shape) self.stride = NDArrayStride(shape, offset=0, order=order) @@ -1152,8 +1155,6 @@ struct NDArray[dtype: DType = DType.float64]( self.order = order for i in range(self.ndshape.ndsize): self.data[i] = data.item(PythonObject(i)).to_float64() - # if self.datatype != DType.float64: - # raise Error("Only float64 is supported for now") # var array: PythonObject # try: @@ -1226,7 +1227,7 @@ struct NDArray[dtype: DType = DType.float64]( self.data.free() # ===-------------------------------------------------------------------===# - # Set and get dunders + # Setter dunders # ===-------------------------------------------------------------------===# @always_inline("nodebug") @@ -1288,6 +1289,22 @@ struct NDArray[dtype: DType = DType.float64]( var idx: Int = _get_index(index, self.coefficient) self.data.store[width=1](idx, val) + # compiler doesn't accept this + # fn __setitem__(inout self, mask: NDArray[DType.bool], value: Scalar[dtype]) raises: + # """ + # Set the value of the array at the indices where the mask is true. + # """ + # if mask.ndshape != self.ndshape: # this behavious could be removed potentially + # raise Error("Mask and array must have the same shape") + + # for i in range(mask.ndshape.ndsize): + # if mask.data.load[width=1](i): + # print(value) + # self.data.store[width=1](i, value) + + # ===-------------------------------------------------------------------===# + # Getter dunders + # ===-------------------------------------------------------------------===# fn get_scalar(self, index: Int) raises -> SIMD[dtype, 1]: """ Linearly retreive a value from the underlying Pointer. @@ -1851,19 +1868,6 @@ struct NDArray[dtype: DType = DType.float64]( " for DType.bool" ) - # compiler doesn't accept this - # fn __setitem__(inout self, mask: NDArray[DType.bool], value: Scalar[dtype]) raises: - # """ - # Set the value of the array at the indices where the mask is true. - # """ - # if mask.ndshape != self.ndshape: # this behavious could be removed potentially - # raise Error("Mask and array must have the same shape") - - # for i in range(mask.ndshape.ndsize): - # if mask.data.load[width=1](i): - # print(value) - # self.data.store[width=1](i, value) - fn __int__(self) raises -> Int: """Get Int representation of the array. @@ -2559,6 +2563,23 @@ struct NDArray[dtype: DType = DType.float64]( # ===-------------------------------------------------------------------===# # Operations along an axis # ===-------------------------------------------------------------------===# + # TODO: implement for arbitrary axis1, and axis2 + fn T(inout self) raises: + """ + Transpose the array. + """ + if self.ndim !=2: + raise Error("Only 2-D arrays can be transposed currently.") + var rows = self.ndshape[0] + var cols = self.ndshape[1] + + var transposed = NDArray[dtype](cols, rows) + for i in range(rows): + for j in range(cols): + var xedni: List[Int] = List[Int](j, 1) + transposed[xedni] = self[i, j] + + self.data = transposed.data fn all(self) raises -> Bool: """ From 54f080c8d5800ce2b09246f6fef8104cb5bd730b Mon Sep 17 00:00:00 2001 From: darth-photon Date: Thu, 22 Aug 2024 13:12:30 +0530 Subject: [PATCH 20/32] removed shape requirement for constructor with numpy input --- numojo/core/ndarray.mojo | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 1b17a47..62fdd94 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -165,7 +165,7 @@ struct NDArrayShape[dtype: DType = DType.int32](Stringable): ) self.ndlen = len(shape) self.ndshape = DTypePointer[dtype].alloc(len(shape)) - memset_zero(self.ndshape, len(shape)) + memset_zero(self.ndshape, len(shape)) var count: Int = 1 for i in range(len(shape)): self.ndshape[i] = shape[i] @@ -1142,9 +1142,15 @@ struct NDArray[dtype: DType = DType.float64]( # creating NDArray from numpy array # TODO: Make it work for all data types apart from float64 - fn __init__(inout self, *shape: Int, data: PythonObject, order: String = "C") raises: + fn __init__(inout self, data: PythonObject, order: String = "C") raises: if dtype != DType.float64: raise Error("Only float64 is supported for now") + var len = int(len(data.shape)) + var shape: List[Int] = List[Int]() + for i in range(len): + if int(data.shape[i]) == 1: + continue + shape.append(int(data.shape[i])) self.ndim = shape.__len__() self.ndshape = NDArrayShape(shape) self.stride = NDArrayStride(shape, offset=0, order=order) From f9590527fa745c9c56fa66dc03651b5d86128feb Mon Sep 17 00:00:00 2001 From: darth-photon Date: Thu, 22 Aug 2024 14:23:23 +0530 Subject: [PATCH 21/32] fixed typo in dot function --- numojo/math/linalg/linalg.mojo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numojo/math/linalg/linalg.mojo b/numojo/math/linalg/linalg.mojo index 066b017..a309623 100644 --- a/numojo/math/linalg/linalg.mojo +++ b/numojo/math/linalg/linalg.mojo @@ -92,7 +92,7 @@ fn dot[ alias opt_nelts = simdwidthof[dtype]() if array1.ndshape.ndlen == array2.ndshape.ndlen == 1: - var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(3)) + var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(array1.ndshape.ndsize)) @parameter fn vectorized_dot[simd_width: Int](idx: Int) -> None: @@ -103,7 +103,7 @@ fn dot[ ) vectorize[vectorized_dot, opt_nelts](array1.ndshape.ndsize) - return result + return result^ else: raise Error( "Cross product is not supported for arrays of shape " From deb7b174d298788e9167a22939481ea586e1a4a4 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Thu, 22 Aug 2024 14:23:41 +0530 Subject: [PATCH 22/32] fixed tranpose arr.T() method --- numojo/core/ndarray.mojo | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 62fdd94..b7fb4cb 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2579,13 +2579,12 @@ struct NDArray[dtype: DType = DType.float64]( var rows = self.ndshape[0] var cols = self.ndshape[1] - var transposed = NDArray[dtype](cols, rows) + var transposed = NDArray[dtype](cols, rows, random=False) for i in range(rows): for j in range(cols): - var xedni: List[Int] = List[Int](j, 1) - transposed[xedni] = self[i, j] - - self.data = transposed.data + # the setitem is not working due to the symmetry issue of getter and setter + transposed.__setitem__(VariadicList[Int](j,i), val=self.item(i, j)) + self = transposed fn all(self) raises -> Bool: """ From 10e05bf0a23971b55d460de7f8f6fe72d3351a99 Mon Sep 17 00:00:00 2001 From: darth-photon Date: Thu, 22 Aug 2024 23:32:25 +0530 Subject: [PATCH 23/32] updated test.mojo --- test.mojo | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test.mojo b/test.mojo index 24d1882..9f6ccee 100644 --- a/test.mojo +++ b/test.mojo @@ -22,9 +22,16 @@ fn main() raises: # print(A) # A.reshape(3, 3) # print(A) - var A = NDArray[i8](3, 4, random=True) + var np = Python.import_module("numpy") + var A = np.arange(1, 10, 1).reshape(3, 3) print(A) - print(trace(A, offset = 1, axis1=0, axis2=1)) + var temp = NDArray[f64](data=A) + print(temp) + temp.T() + print(temp) + # var A = NDArray[i8](3, 4, random=True) + # print(A) + # print(trace(A, offset = 1, axis1=0, axis2=1)) # var A = NDArray[i16](5, random=True) # print(A) # A.sort() From 249db05d33620b7bcc752fffa6d2b3c853933474 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Sun, 8 Sep 2024 16:32:09 +0900 Subject: [PATCH 24/32] fixed spacing between fn, all simdwidthof[] parameters are renamed to `width` and function parameters to `simd_width` --- numojo/core/_array_funcs.mojo | 39 +- numojo/core/array_creation_routines.mojo | 111 ++--- numojo/core/array_manipulation_routines.mojo | 25 +- numojo/core/constants.mojo | 1 + numojo/core/ndarray.mojo | 73 ++-- numojo/core/random.mojo | 22 +- numojo/core/sort.mojo | 6 +- numojo/core/utility_funcs.mojo | 30 ++ numojo/math/arithmetic.mojo | 8 +- numojo/math/calculus/differentiation.mojo | 5 +- numojo/math/calculus/integral.mojo | 22 +- numojo/math/check.mojo | 1 + numojo/math/comparison.mojo | 1 + numojo/math/linalg/linalg.mojo | 13 +- numojo/math/linalg/matmul.mojo | 30 +- numojo/math/math_funcs.mojo | 384 +++++++++--------- numojo/math/statistics/cumulative_reduce.mojo | 67 +-- numojo/math/trig.mojo | 4 +- tests/test_array_creation.mojo | 46 +-- 19 files changed, 414 insertions(+), 474 deletions(-) diff --git a/numojo/core/_array_funcs.mojo b/numojo/core/_array_funcs.mojo index 5c1b7c7..ff419a4 100644 --- a/numojo/core/_array_funcs.mojo +++ b/numojo/core/_array_funcs.mojo @@ -27,16 +27,16 @@ fn math_func_1_array_in_one_array_out[ A new NDArray that is the result of applying the function to the NDArray. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter - fn closure[simdwidth: Int](i: Int): - var simd_data = array.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data) + fn closure[simd_width: Int](i: Int): + var simd_data = array.load[width=simd_width](i) + result_array.store[width=simd_width]( + i, func[dtype, simd_width](simd_data) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array @@ -69,17 +69,18 @@ fn math_func_2_array_in_one_array_out[ raise Error("Shape Mismatch error shapes must match for this function") var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter - fn closure[simdwidth: Int](i: Int): - var simd_data1 = array1.load[width=opt_nelts](i) - var simd_data2 = array2.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data1, simd_data2) + fn closure[simd_width: Int](i: Int): + var simd_data1 = array1.load[width=simd_width](i) + var simd_data2 = array2.load[width=simd_width](i) + result_array.store[width=simd_width]( + i, func[dtype, simd_width](simd_data1, simd_data2) ) - vectorize[closure, opt_nelts](result_array.num_elements()) + vectorize[closure, width](result_array.num_elements()) + return result_array @@ -105,14 +106,14 @@ fn math_func_one_array_one_SIMD_in_one_array_out[ """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter - fn closure[simdwidth: Int](i: Int): - var simd_data1 = array.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data1, scalar) + fn closure[simd_width: Int](i: Int): + var simd_data1 = array.load[width=simd_width](i) + result_array.store[width=simd_width]( + i, func[dtype, simd_width](simd_data1, scalar) ) - vectorize[closure, opt_nelts](result_array.num_elements()) + vectorize[closure, width](result_array.num_elements()) return result_array diff --git a/numojo/core/array_creation_routines.mojo b/numojo/core/array_creation_routines.mojo index 7176c57..f1032bd 100644 --- a/numojo/core/array_creation_routines.mojo +++ b/numojo/core/array_creation_routines.mojo @@ -3,15 +3,13 @@ Array creation routine. """ # ===----------------------------------------------------------------------=== # # ARRAY CREATION ROUTINES -# Last updated: 2024-06-16 +# Last updated: 2024-09-08 # ===----------------------------------------------------------------------=== # """ # TODO (In order of priority) -1) Add function overload for List, VariadicList types -2) Implement axis argument for the NDArray creation functions -3) Implement Row/Column Major option +1) Implement axis argument for the NDArray creation functions """ from algorithm import parallelize @@ -48,13 +46,6 @@ fn arange[ Returns: A NDArray of datatype `dtype` with elements ranging from `start` to `stop` incremented with `step`. """ - # if (is_floattype[dtype]() and is_inttype[dtype]()) or ( - # is_inttype[dtype]() and is_inttype[dtype]() - # ): - # raise Error( - # "Both input and output datatypes cannot be integers. If the input is a float, the output must also be a float." - # ) - var num: Int = ((stop - start) / step).__int__() var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(num, size=num)) for idx in range(num): @@ -66,11 +57,8 @@ fn arange[ # ===------------------------------------------------------------------------===# # Linear Spacing NDArray Generation # ===------------------------------------------------------------------------===# - - -# I think defaulting parallelization to False is better fn linspace[ - dtype: DType + dtype: DType = DType.float64 ]( start: Scalar[dtype], stop: Scalar[dtype], @@ -98,12 +86,6 @@ fn linspace[ A NDArray of datatype `dtype` with elements ranging from `start` to `stop` with num elements. """ - # if (is_inttype[dtype]() and is_inttype[dtype]()) or ( - # is_floattype[dtype]() and is_inttype[dtype]() - # ): - # raise Error( - # "Both input and output datatypes cannot be integers. If the input is a float, the output must also be a float." - # ) constrained[not dtype.is_integral()]() if parallel: return _linspace_parallel[dtype](start, stop, num, endpoint) @@ -112,7 +94,7 @@ fn linspace[ fn _linspace_serial[ - dtype: DType + dtype: DType = DType.float64 ]( start: SIMD[dtype, 1], stop: SIMD[dtype, 1], @@ -150,7 +132,7 @@ fn _linspace_serial[ fn _linspace_parallel[ - dtype: DType + dtype: DType = DType.float64 ]( start: SIMD[dtype, 1], stop: SIMD[dtype, 1], num: Int, endpoint: Bool = True ) raises -> NDArray[dtype]: @@ -197,7 +179,7 @@ fn _linspace_parallel[ # Logarithmic Spacing NDArray Generation # ===------------------------------------------------------------------------===# fn logspace[ - dtype: DType + dtype: DType = DType.float64 ]( start: Scalar[dtype], stop: Scalar[dtype], @@ -227,12 +209,6 @@ fn logspace[ - A NDArray of `dtype` with `num` logarithmic spaced elements between `start` and `stop`. """ constrained[not dtype.is_integral()]() - # if (is_inttype[dtype]() and is_inttype[dtype]()) or ( - # is_floattype[dtype]() and is_inttype[dtype]() - # ): - # raise Error( - # "Both input and output datatypes cannot be integers. If the input is a float, the output must also be a float." - # ) if parallel: return _logspace_parallel[dtype]( start, @@ -252,7 +228,7 @@ fn logspace[ fn _logspace_serial[ - dtype: DType + dtype: DType = DType.float64 ]( start: Scalar[dtype], stop: Scalar[dtype], @@ -290,7 +266,7 @@ fn _logspace_serial[ fn _logspace_parallel[ - dtype: DType + dtype: DType = DType.float64 ]( start: Scalar[dtype], stop: Scalar[dtype], @@ -339,7 +315,7 @@ fn _logspace_parallel[ # ! Outputs wrong values for Integer type, works fine for float type. fn geomspace[ - dtype: DType + dtype: DType = DType.float64 ]( start: Scalar[dtype], stop: Scalar[dtype], @@ -365,13 +341,6 @@ fn geomspace[ A NDArray of `dtype` with `num` geometrically spaced elements between `start` and `stop`. """ constrained[not dtype.is_integral()]() - # if (is_inttype[dtype]() and is_inttype[dtype]()) or ( - # is_floattype[dtype]() and is_inttype[dtype]() - # ): - # raise Error( - # "Both input and output datatypes cannot be integers. If the input is a float, the output must also be a float." - # ) - var a: Scalar[dtype] = start if endpoint: @@ -392,9 +361,7 @@ fn geomspace[ # ===------------------------------------------------------------------------===# # Commonly used NDArray Generation routines # ===------------------------------------------------------------------------===# - - -fn empty[dtype: DType](*shape: Int) raises -> NDArray[dtype]: +fn empty[dtype: DType = DType.float64](*shape: Int) raises -> NDArray[dtype]: """ Generate a NDArray of given shape with arbitrary values. @@ -410,7 +377,7 @@ fn empty[dtype: DType](*shape: Int) raises -> NDArray[dtype]: return NDArray[dtype](shape=shape) -fn zeros[dtype: DType](*shape: Int) raises -> NDArray[dtype]: +fn zeros[dtype: DType = DType.float64](*shape: Int) raises -> NDArray[dtype]: """ Generate a NDArray of zeros with given shape. @@ -426,7 +393,7 @@ fn zeros[dtype: DType](*shape: Int) raises -> NDArray[dtype]: return NDArray[dtype](shape, fill=SIMD[dtype, 1](0)) -fn eye[dtype: DType](N: Int, M: Int) raises -> NDArray[dtype]: +fn eye[dtype: DType = DType.float64](N: Int, M: Int) raises -> NDArray[dtype]: """ Return a 2-D NDArray with ones on the diagonal and zeros elsewhere. @@ -447,7 +414,7 @@ fn eye[dtype: DType](N: Int, M: Int) raises -> NDArray[dtype]: return result -fn identity[dtype: DType](N: Int) raises -> NDArray[dtype]: +fn identity[dtype: DType = DType.float64](N: Int) raises -> NDArray[dtype]: """ Generate an identity matrix of size N x N. @@ -467,7 +434,7 @@ fn identity[dtype: DType](N: Int) raises -> NDArray[dtype]: return result -fn ones[dtype: DType](*shape: Int) raises -> NDArray[dtype]: +fn ones[dtype: DType = DType.float64](*shape: Int) raises -> NDArray[dtype]: """ Generate a NDArray of ones with given shape filled with ones. @@ -488,7 +455,7 @@ fn ones[dtype: DType](*shape: Int) raises -> NDArray[dtype]: fn full[ - dtype: DType + dtype: DType = DType.float64 ](*shape: Int, fill_value: Scalar[dtype]) raises -> NDArray[dtype]: """ Generate a NDArray of `fill_value` with given shape. @@ -507,7 +474,7 @@ fn full[ fn full[ - dtype: DType + dtype: DType = DType.float64 ](shape: VariadicList[Int], fill_value: Scalar[dtype]) raises -> NDArray[dtype]: """ Generate a NDArray of `fill_value` with given shape. @@ -527,7 +494,7 @@ fn full[ fn diagflat[ - dtype: DType + dtype: DType = DType.float64 ](inout v: NDArray[dtype], k: Int = 0) raises -> NDArray[dtype]: """ Generate a 2-D NDArray with the flattened input as the diagonal. @@ -561,7 +528,9 @@ fn diagflat[ return result -fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: +fn tri[ + dtype: DType = DType.float64 +](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: """ Generate a 2-D NDArray with ones on and below the k-th diagonal. @@ -576,7 +545,7 @@ fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: Returns: A 2-D NDArray with ones on and below the k-th diagonal. """ - var result: NDArray[dtype] = NDArray[dtype](N, M, random=False) + var result: NDArray[dtype] = NDArray[dtype](N, M, fill=SIMD[dtype, 1](0)) for i in range(N): for j in range(M): if i >= j - k: @@ -584,27 +553,27 @@ fn tri[dtype: DType](N: Int, M: Int, k: Int = 0) raises -> NDArray[dtype]: return result -# fn tril[dtype: DType](inout m: NDArray[dtype], k: Int = 0) raises: - # """ - # Zero out elements above the k-th diagonal. +# fn tril[dtype: DType = DType.float64](inout m: NDArray[dtype], k: Int = 0) raises: +# """ +# Zero out elements above the k-th diagonal. - # Parameters: - # dtype: Datatype of the NDArray elements. +# Parameters: +# dtype: Datatype of the NDArray elements. - # Args: - # m: NDArray to be zeroed out. - # k: Diagonal offset. - # """ - # var index: List[Int] = List[Int]() - # for _ in range(m.ndshape.ndlen): - # index.append(0) +# Args: +# m: NDArray to be zeroed out. +# k: Diagonal offset. +# """ +# var index: List[Int] = List[Int]() +# for _ in range(m.ndshape.ndlen): +# index.append(0) - # for i in range(m.ndshape[-1]): - # for j in range(m.ndshape[-2]): - # var idx: Int = _get_index(index, m.ndshape) - # if i >= j - k: - # m.data[idx] = Scalar[dtype](0) - # index[-2] += 1 +# for i in range(m.ndshape[-1]): +# for j in range(m.ndshape[-2]): +# var idx: Int = _get_index(index, m.ndshape) +# if i >= j - k: +# m.data[idx] = Scalar[dtype](0) +# index[-2] += 1 # fn triu(): - # pass +# pass diff --git a/numojo/core/array_manipulation_routines.mojo b/numojo/core/array_manipulation_routines.mojo index 710923c..bf0f758 100644 --- a/numojo/core/array_manipulation_routines.mojo +++ b/numojo/core/array_manipulation_routines.mojo @@ -190,8 +190,8 @@ fn flatten[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: The 1 dimensional flattened NDArray. """ - var res: NDArray[dtype] = NDArray[dtype](array.ndshape.ndsize, random=False) - alias simd_width: Int = simdwidthof[dtype]() + var res: NDArray[dtype] = NDArray[dtype](array.ndshape.ndsize) + alias width: Int = simdwidthof[dtype]() @parameter fn vectorized_flatten[simd_width: Int](index: Int) -> None: @@ -199,11 +199,16 @@ fn flatten[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]: index, array.data.load[width=simd_width](index) ) - vectorize[vectorized_flatten, simd_width](array.ndshape.ndsize) + vectorize[vectorized_flatten, width](array.ndshape.ndsize) return res + # TODO: implement for arbitrary axis -fn trace[dtype: DType](array: NDArray[dtype], offset: Int = 0, axis1: Int = 0 , axis2: Int = 1) raises -> NDArray[dtype]: +fn trace[ + dtype: DType +]( + array: NDArray[dtype], offset: Int = 0, axis1: Int = 0, axis2: Int = 1 +) raises -> NDArray[dtype]: """ Computes the trace of a ndarray. @@ -217,20 +222,22 @@ fn trace[dtype: DType](array: NDArray[dtype], offset: Int = 0, axis1: Int = 0 , axis2: Second axis. Returns: - The trace of the NDArray. + The trace of the NDArray. """ if array.ndim != 2: raise Error("Trace is currently only supported for 2D arrays") if axis1 > array.ndim - 1 or axis2 > array.ndim - 1: raise Error("axis cannot be greater than the rank of the array") - var result: NDArray[dtype] = NDArray[dtype](1, random=False) + var result: NDArray[dtype] = NDArray[dtype](1) var rows = array.ndshape[0] var cols = array.ndshape[1] - var diag_length = min(rows, cols - offset) if offset >= 0 else min(rows + offset, cols) - + var diag_length = min(rows, cols - offset) if offset >= 0 else min( + rows + offset, cols + ) + for i in range(diag_length): var row = i if offset >= 0 else i - offset var col = i + offset if offset >= 0 else i result.data.store(0, result.data.load(0) + array.data[row * cols + col]) - return result \ No newline at end of file + return result diff --git a/numojo/core/constants.mojo b/numojo/core/constants.mojo index 4664b09..c2b9bd4 100644 --- a/numojo/core/constants.mojo +++ b/numojo/core/constants.mojo @@ -28,6 +28,7 @@ struct Constants(AnyType): alias c = 299_792_458 alias pi = 3.1415926535897932384626433832795028841971693937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555954930381966446229489 alias e = 2.71828182845904523536028747135266249775724609375 + alias hbar = 1.0545718176461563912626e-34 fn __init__(inout self): """ diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 53d01f4..0517343 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -166,7 +166,7 @@ struct NDArrayShape[dtype: DType = DType.int32](Stringable): ) self.ndlen = len(shape) self.ndshape = DTypePointer[dtype].alloc(len(shape)) - memset_zero(self.ndshape, len(shape)) + memset_zero(self.ndshape, len(shape)) var count: Int = 1 for i in range(len(shape)): self.ndshape[i] = shape[i] @@ -643,7 +643,7 @@ struct NDArray[dtype: DType = DType.float64]( var order: String "Memory layout of array C (C order row major) or F (Fortran order col major)." - alias simd_width: Int = simdwidthof[dtype]() # + alias width: Int = simdwidthof[dtype]() # """Vector size of the data type.""" # ===-------------------------------------------------------------------===# @@ -2017,14 +2017,13 @@ struct NDArray[dtype: DType = DType.float64]( ** p.load[width=simd_width](index), ) - vectorize[vectorized_pow, self.simd_width](self.ndshape.ndsize) + vectorize[vectorized_pow, self.width](self.ndshape.ndsize) return result fn __ipow__(inout self, p: Int): self = self.__pow__(p) fn _elementwise_pow(self, p: Int) -> Self: - alias simd_width: Int = simdwidthof[dtype]() var new_vec = self @parameter @@ -2033,7 +2032,7 @@ struct NDArray[dtype: DType = DType.float64]( index, pow(self.data.load[width=simd_width](index), p) ) - vectorize[array_scalar_vectorize, simd_width](self.ndshape.ndsize) + vectorize[array_scalar_vectorize, self.width](self.ndshape.ndsize) return new_vec fn __truediv__(self, other: SIMD[dtype, 1]) raises -> Self: @@ -2458,16 +2457,18 @@ struct NDArray[dtype: DType = DType.float64]( """ Transpose the array. """ - if self.ndim !=2: + if self.ndim != 2: raise Error("Only 2-D arrays can be transposed currently.") var rows = self.ndshape[0] var cols = self.ndshape[1] - - var transposed = NDArray[dtype](cols, rows, random=False) + + var transposed = NDArray[dtype](cols, rows) for i in range(rows): for j in range(cols): # the setitem is not working due to the symmetry issue of getter and setter - transposed.__setitem__(VariadicList[Int](j,i), val=self.item(i, j)) + transposed.__setitem__( + VariadicList[Int](j, i), val=self.item(i, j) + ) self = transposed fn all(self) raises -> Bool: @@ -2487,7 +2488,7 @@ struct NDArray[dtype: DType = DType.float64]( (self.data + idx).simd_strided_load[width=simd_width](1) ) - vectorize[vectorized_all, self.simd_width](self.ndshape.ndsize) + vectorize[vectorized_all, self.width](self.ndshape.ndsize) return result fn any(self) raises -> Bool: @@ -2505,7 +2506,7 @@ struct NDArray[dtype: DType = DType.float64]( (self.data + idx).simd_strided_load[width=simd_width](1) ) - vectorize[vectorized_any, self.simd_width](self.ndshape.ndsize) + vectorize[vectorized_any, self.width](self.ndshape.ndsize) return result fn argmax(self) -> Int: @@ -2564,7 +2565,7 @@ struct NDArray[dtype: DType = DType.float64]( self.load[width](idx).cast[type](), 1 ) - vectorize[vectorized_astype, self.simd_width](self.ndshape.ndsize) + vectorize[vectorized_astype, self.width](self.ndshape.ndsize) else: @parameter @@ -2579,7 +2580,7 @@ struct NDArray[dtype: DType = DType.float64]( .cast[type](), ) - vectorize[vectorized_astypenb_from_b, self.simd_width]( + vectorize[vectorized_astypenb_from_b, self.width]( self.ndshape.ndsize ) else: @@ -2588,9 +2589,7 @@ struct NDArray[dtype: DType = DType.float64]( fn vectorized_astypenb[width: Int](idx: Int) -> None: narr.store[width](idx, self.load[width](idx).cast[type]()) - vectorize[vectorized_astypenb, self.simd_width]( - self.ndshape.ndsize - ) + vectorize[vectorized_astypenb, self.width](self.ndshape.ndsize) return narr @@ -2628,40 +2627,35 @@ struct NDArray[dtype: DType = DType.float64]( """ Fill all items of array with value. """ - alias simd_width: Int = simdwidthof[dtype]() @parameter fn vectorized_fill[simd_width: Int](index: Int) -> None: self.data.store[width=simd_width](index, val) - vectorize[vectorized_fill, simd_width](self.ndshape.ndsize) + vectorize[vectorized_fill, self.width](self.ndshape.ndsize) + return self fn flatten(inout self) raises: """ Convert shape of array to one dimensional. """ - # inplace has some problems right now - # if inplace: - # self.ndshape = NDArrayShape(self.ndshape.ndsize, size=self.ndshape.ndsize) - # self.stride = NDArrayStride(shape = self.ndshape, offset=0) - # return self + self.ndshape = NDArrayShape( + self.ndshape.ndsize, size=self.ndshape.ndsize + ) + self.stride = NDArrayStride(shape=self.ndshape, offset=0) - var res: NDArray[dtype] = NDArray[dtype](self.ndshape.ndsize) - alias simd_width: Int = simdwidthof[dtype]() + # var res: NDArray[dtype] = NDArray[dtype](self.ndshape.ndsize) + # alias width: Int = simdwidthof[dtype]() - @parameter - fn vectorized_flatten[simd_width: Int](index: Int) -> None: - res.data.store[width=simd_width]( - index, self.data.load[width=simd_width](index) - ) + # @parameter + # fn vectorized_flatten[simd_width: Int](index: Int) -> None: + # res.data.store[width=simd_width]( + # index, self.data.load[width=simd_width](index) + # ) - vectorize[vectorized_flatten, simd_width](self.ndshape.ndsize) - if inplace: - self = res - return None - else: - return res + # vectorize[vectorized_flatten, simd_width](self.ndshape.ndsize) + # self = res^ fn item(self, *index: Int) raises -> SIMD[dtype, 1]: """ @@ -2900,7 +2894,9 @@ struct NDArray[dtype: DType = DType.float64]( return result # TODO: add axis parameter - fn trace(self, offset: Int = 0, axis1: Int = 0 , axis2: Int = 1) raises -> NDArray[dtype]: + fn trace( + self, offset: Int = 0, axis1: Int = 0, axis2: Int = 1 + ) raises -> NDArray[dtype]: """ Computes the trace of a ndarray. @@ -2910,11 +2906,10 @@ struct NDArray[dtype: DType = DType.float64]( axis2: Second axis. Returns: - The trace of the ndarray. + The trace of the ndarray. """ return trace[dtype](self, offset, axis1, axis2) - # Technically it only changes the ArrayDescriptor and not the fundamental data fn reshape(inout self, *shape: Int, order: String = "C") raises: """ diff --git a/numojo/core/random.mojo b/numojo/core/random.mojo index 0fd755b..ac7a4f6 100644 --- a/numojo/core/random.mojo +++ b/numojo/core/random.mojo @@ -3,14 +3,16 @@ Random values array generation. """ # ===----------------------------------------------------------------------=== # # Implements RANDOM -# Last updated: 2024-06-18 +# Last updated: 2024-09-06 # ===----------------------------------------------------------------------=== # import math as mt from random import random -from .ndarray import NDArray from builtin.tuple import Tuple +from .ndarray import NDArray +from .utility_funcs import is_inttype, is_floattype + fn rand[dtype: DType = DType.float64](*shape: Int) raises -> NDArray[dtype]: """ @@ -121,19 +123,19 @@ fn rand[ """ var result: NDArray[dtype] = NDArray[dtype](shape) random.seed() - # if dtype.is_integral(): + # if is_inttype(dtype): + # for i in range(result.ndshape.ndsize): + # var temp: Scalar[dtype] = random.random_float64( + # min.cast[f64](), max.cast[f64]() + # ).cast[dtype]() + # result.data[i] = temp + # elif is_floattype(dtype): # random.randint[dtype]( # ptr=result.data, # size=result.ndshape.ndsize, # low=int(min), # high=int(max), # ) - # elif dtype.is_floating_point(): - # for i in range(result.ndshape.ndsize): - # var temp: Scalar[dtype] = random.random_float64( - # min.cast[f64](), max.cast[f64]() - # ).cast[dtype]() - # result.data[i] = temp # else: # raise Error( # "Invalid type provided. dtype must be either an integral or" @@ -144,7 +146,7 @@ fn rand[ min.cast[f64](), max.cast[f64]() ).cast[dtype]() result.data[i] = temp - return result + return result^ fn randn[ diff --git a/numojo/core/sort.mojo b/numojo/core/sort.mojo index 122c737..bbbac74 100644 --- a/numojo/core/sort.mojo +++ b/numojo/core/sort.mojo @@ -9,13 +9,13 @@ Implements sort functions import math from algorithm import vectorize + from ..core.ndarray import NDArray, NDArrayShape """ -TODO: +TODO: 1) Add more sorting algorithms. -2) Add argument "inplace" for some functions. -3) Add axis. +2) Add axis. """ # ===------------------------------------------------------------------------===# diff --git a/numojo/core/utility_funcs.mojo b/numojo/core/utility_funcs.mojo index 49ff53d..f45f9c0 100644 --- a/numojo/core/utility_funcs.mojo +++ b/numojo/core/utility_funcs.mojo @@ -83,3 +83,33 @@ fn is_floattype(dtype: DType) -> Bool: ): return True return False + + +fn is_booltype[dtype: DType]() -> Bool: + """ + Check if the given dtype is a boolean type at compile time. + + Parameters: + dtype: DType. + + Returns: + Bool: True if the given dtype is a boolean type, False otherwise. + """ + if dtype == DType.bool: + return True + return False + + +fn is_booltype(dtype: DType) -> Bool: + """ + Check if the given dtype is a boolean type at run time. + + Args: + dtype: DType. + + Returns: + Bool: True if the given dtype is a boolean type, False otherwise. + """ + if dtype == DType.bool: + return True + return False diff --git a/numojo/math/arithmetic.mojo b/numojo/math/arithmetic.mojo index cefc9d3..e5154ac 100644 --- a/numojo/math/arithmetic.mojo +++ b/numojo/math/arithmetic.mojo @@ -8,11 +8,13 @@ Implements array arithmetic import math -import . math_funcs as _mf -from ..core.ndarray import NDArray, NDArrayShape from algorithm import parallelize from algorithm import Static2DTileUnitFunc as Tile2DFunc +import . math_funcs as _mf +from ..core.ndarray import NDArray, NDArrayShape +from ..core.utility_funcs import is_inttype, is_floattype, is_booltype + # ===------------------------------------------------------------------------===# # Addition/Subtraction @@ -1163,7 +1165,7 @@ fn invert[ A NDArray equal to the bitwise inversion of array. """ constrained[ - dtype.is_integral() or dtype.is_integral(), + is_inttype[dtype]() or is_booltype[dtype](), "Only Bools and integral types can be invertedd.", ]() diff --git a/numojo/math/calculus/differentiation.mojo b/numojo/math/calculus/differentiation.mojo index 965c677..08fc22f 100644 --- a/numojo/math/calculus/differentiation.mojo +++ b/numojo/math/calculus/differentiation.mojo @@ -4,6 +4,7 @@ # ===----------------------------------------------------------------------=== # import math + import .. math_funcs as _mf import ... core as core from ...core.ndarray import NDArray, NDArrayShape @@ -16,7 +17,7 @@ from ...core.utility_funcs import is_inttype, is_floattype fn gradient[ - dtype: DType + dtype: DType = DType.float64 ](x: NDArray[dtype], spacing: Scalar[dtype]) raises -> NDArray[dtype]: """ Compute the gradient of y over x using the trapezoidal rule. @@ -67,4 +68,4 @@ fn gradient[ ) / (hu * hd * (hu + hd)) result.store(i, fi) - return result + return result^ diff --git a/numojo/math/calculus/integral.mojo b/numojo/math/calculus/integral.mojo index ebd521f..0e167a7 100644 --- a/numojo/math/calculus/integral.mojo +++ b/numojo/math/calculus/integral.mojo @@ -4,17 +4,18 @@ # ===----------------------------------------------------------------------=== # import math +from algorithm import parallelize +from algorithm import Static2DTileUnitFunc as Tile2DFunc + import .. math_funcs as _mf from ...core.ndarray import NDArray, NDArrayShape from ...core.utility_funcs import is_inttype, is_floattype -from algorithm import parallelize -from algorithm import Static2DTileUnitFunc as Tile2DFunc # naive loop implementation, optimize later fn trapz[ dtype: DType = DType.float64 -](y: NDArray[dtype], x: NDArray[dtype]) raises -> SIMD[dtype, 1]: +](y: NDArray[dtype], x: NDArray[dtype]) raises -> Scalar[dtype]: """ Compute the integral of y over x using the trapezoidal rule. @@ -32,15 +33,16 @@ fn trapz[ Returns: The integral of y over x using the trapezoidal rule. """ - if x.shape() != y.shape(): - raise Error("x and y must have the same shape") - - # move this check to compile time using constrained? - if is_inttype[dtype]() and not is_floattype[dtype](): - raise Error( + constrained[ + is_inttype[dtype]() and not is_floattype[dtype](), + ( "output dtype `Fdtype` must be a floating-point type if input dtype" " `Idtype` is not a floating-point type" - ) + ), + ]() + + if x.shape() != y.shape(): + raise Error("x and y must have the same shape") var integral: SIMD[dtype] = 0.0 for i in range(x.num_elements() - 1): diff --git a/numojo/math/check.mojo b/numojo/math/check.mojo index 0a1f7bd..6763a3a 100644 --- a/numojo/math/check.mojo +++ b/numojo/math/check.mojo @@ -8,6 +8,7 @@ Implements Checking routines: currently not SIMD due to bool bit packing issue import math + import . math_funcs as _mf from ..core.ndarray import NDArray diff --git a/numojo/math/comparison.mojo b/numojo/math/comparison.mojo index 74154a9..cdb1b9b 100644 --- a/numojo/math/comparison.mojo +++ b/numojo/math/comparison.mojo @@ -8,6 +8,7 @@ Implements comparison math currently not using backend due to bool bitpacking is import math + import . math_funcs as _mf from ..core.ndarray import NDArray diff --git a/numojo/math/linalg/linalg.mojo b/numojo/math/linalg/linalg.mojo index a309623..ff9c59c 100644 --- a/numojo/math/linalg/linalg.mojo +++ b/numojo/math/linalg/linalg.mojo @@ -8,11 +8,12 @@ Linear Algebra misc. functions import math -import .. math_funcs as _mf -from ...core.ndarray import NDArray, NDArrayShape from algorithm import parallelize from algorithm import Static2DTileUnitFunc as Tile2DFunc +import .. math_funcs as _mf +from ...core.ndarray import NDArray, NDArrayShape + fn cross[ dtype: DType = DType.float64 @@ -90,9 +91,11 @@ fn dot[ The dot product of two arrays. """ - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() if array1.ndshape.ndlen == array2.ndshape.ndlen == 1: - var result: NDArray[dtype] = NDArray[dtype](NDArrayShape(array1.ndshape.ndsize)) + var result: NDArray[dtype] = NDArray[dtype]( + NDArrayShape(array1.ndshape.ndsize) + ) @parameter fn vectorized_dot[simd_width: Int](idx: Int) -> None: @@ -102,7 +105,7 @@ fn dot[ * array2.load[width=simd_width](idx), ) - vectorize[vectorized_dot, opt_nelts](array1.ndshape.ndsize) + vectorize[vectorized_dot, width](array1.ndshape.ndsize) return result^ else: raise Error( diff --git a/numojo/math/linalg/matmul.mojo b/numojo/math/linalg/matmul.mojo index e989e18..ead6f07 100644 --- a/numojo/math/linalg/matmul.mojo +++ b/numojo/math/linalg/matmul.mojo @@ -8,11 +8,12 @@ Matrix multiplication functions for NDArrays import math -import .. math_funcs as _mf -from ...core.ndarray import NDArray, NDArrayShape from algorithm import parallelize, vectorize from algorithm import Static2DTileUnitFunc as Tile2DFunc +import .. math_funcs as _mf +from ...core.ndarray import NDArray, NDArrayShape + # Perform 2D tiling on the iteration space defined by end_x and end_y. fn tile[tiled_fn: Tile2DFunc, tile_x: Int, tile_y: Int](end_x: Int, end_y: Int): @@ -29,7 +30,7 @@ fn matmul_tiled_unrolled_parallelized[ """ Matrix multiplication vectorized, tiled, unrolled, and parallelized. """ - alias nelts = max(simdwidthof[dtype](), 16) + alias width = max(simdwidthof[dtype](), 16) var C: NDArray[dtype] = NDArray[dtype]( A.ndshape.load_int(0), B.ndshape.load_int(1) ) @@ -44,20 +45,21 @@ fn matmul_tiled_unrolled_parallelized[ for k in range(y, y + tile_y): @parameter - fn dot[nelts: Int](n: Int): + fn dot[simd_width: Int](n: Int): C.store( m * t2 + (n + x), - val=C.load[nelts](m * t2 + (n + x)) - + A.load(m * t1 + k) * B.load[nelts](k * t2 + (n + x)), + val=C.load[simd_width](m * t2 + (n + x)) + + A.load(m * t1 + k) + * B.load[simd_width](k * t2 + (n + x)), ) - alias unroll_factor = tile_x // nelts + alias unroll_factor = tile_x // width vectorize[ - dot, nelts, size=tile_x, unroll_factor=unroll_factor + dot, width, size=tile_x, unroll_factor=unroll_factor ]() alias tile_size = 4 - tile[calc_tile, nelts * tile_size, tile_size](t1, t2) + tile[calc_tile, width * tile_size, tile_size](t1, t2) parallelize[calculate_A_rows](t0, t0) return C @@ -81,7 +83,7 @@ fn matmul_parallelized[ matrices. """ - alias nelts = max(simdwidthof[dtype](), 16) + alias width = max(simdwidthof[dtype](), 16) var C: NDArray[dtype] = NDArray[dtype]( A.ndshape.load_int(0), B.ndshape.load_int(1) @@ -95,14 +97,14 @@ fn matmul_parallelized[ for k in range(t1): @parameter - fn dot[nelts: Int](n: Int): + fn dot[simd_width: Int](n: Int): C.store( m * t2 + n, - val=C.load[nelts](m * t2 + n) - + A.load(m * t1 + k) * B.load[nelts](k * t2 + n), + val=C.load[simd_width](m * t2 + n) + + A.load(m * t1 + k) * B.load[simd_width](k * t2 + n), ) - vectorize[dot, nelts](t2) + vectorize[dot, width](t2) parallelize[calculate_A_rows](t0, t0) return C diff --git a/numojo/math/math_funcs.mojo b/numojo/math/math_funcs.mojo index 0389304..7747a8e 100644 --- a/numojo/math/math_funcs.mojo +++ b/numojo/math/math_funcs.mojo @@ -63,7 +63,7 @@ struct Vectorized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # var op_count:Int =0 @parameter @@ -76,7 +76,7 @@ struct Vectorized(Backend): ) # op_count+=1 - vectorize[closure, opt_nelts](array1.num_elements()) + vectorize[closure, width](array1.num_elements()) # print(op_count) return result_array @@ -111,7 +111,7 @@ struct Vectorized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -122,7 +122,7 @@ struct Vectorized(Backend): i, SIMD.fma(simd_data1, simd_data2, simd) ) - vectorize[closure, opt_nelts](array1.num_elements()) + vectorize[closure, width](array1.num_elements()) return result_array fn math_func_1_array_in_one_array_out[ @@ -145,7 +145,7 @@ struct Vectorized(Backend): A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -154,7 +154,7 @@ struct Vectorized(Backend): i, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array @@ -190,7 +190,7 @@ struct Vectorized(Backend): ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -200,7 +200,7 @@ struct Vectorized(Backend): i, func[dtype, simdwidth](simd_data1, simd_data2) ) - vectorize[closure, opt_nelts](result_array.num_elements()) + vectorize[closure, width](result_array.num_elements()) return result_array fn math_func_1_array_1_scalar_in_one_array_out[ @@ -227,7 +227,7 @@ struct Vectorized(Backend): """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -237,7 +237,7 @@ struct Vectorized(Backend): i, func[dtype, simdwidth](simd_data1, simd_data2) ) - vectorize[closure, opt_nelts](result_array.num_elements()) + vectorize[closure, width](result_array.num_elements()) return result_array fn math_func_compare_2_arrays[ @@ -255,7 +255,7 @@ struct Vectorized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -270,7 +270,7 @@ struct Vectorized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](array1.num_elements()) + vectorize[closure, width](array1.num_elements()) return result_array # TODO: add this function for other backends @@ -285,7 +285,7 @@ struct Vectorized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -297,7 +297,7 @@ struct Vectorized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](array1.num_elements()) + vectorize[closure, width](array1.num_elements()) return result_array fn math_func_is[ @@ -309,7 +309,7 @@ struct Vectorized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -318,7 +318,7 @@ struct Vectorized(Backend): i, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array fn math_func_simd_int[ @@ -328,7 +328,7 @@ struct Vectorized(Backend): ], ](self: Self, array: NDArray[dtype], intval: Int) raises -> NDArray[dtype]: var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -338,7 +338,7 @@ struct Vectorized(Backend): i, func[dtype, simdwidth](simd_data, intval) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array @@ -407,7 +407,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -418,7 +418,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, SIMD.fma(simd_data1, simd_data2, simd_data3) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array1.num_elements() ) return result_array @@ -453,7 +453,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -464,7 +464,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, SIMD.fma(simd_data1, simd_data2, simd) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array1.num_elements() ) return result_array @@ -489,7 +489,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -498,7 +498,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array.num_elements() ) @@ -535,7 +535,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -545,7 +545,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, func[dtype, simdwidth](simd_data1, simd_data2) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array1.num_elements() ) return result_array @@ -574,7 +574,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -584,7 +584,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, func[dtype, simdwidth](simd_data1, simd_data2) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array.num_elements() ) return result_array @@ -604,7 +604,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -619,7 +619,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array1.num_elements() ) return result_array @@ -635,7 +635,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -647,7 +647,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array1.num_elements() ) return result_array @@ -661,7 +661,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -670,7 +670,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array.num_elements() ) return result_array @@ -682,7 +682,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): ], ](self: Self, array: NDArray[dtype], intval: Int) raises -> NDArray[dtype]: var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -692,7 +692,7 @@ struct VectorizedUnroll[unroll_factor: Int = 1](Backend): i, func[dtype, simdwidth](simd_data, intval) ) - vectorize[closure, opt_nelts, unroll_factor=unroll_factor]( + vectorize[closure, width, unroll_factor=unroll_factor]( array.num_elements() ) return result_array @@ -743,7 +743,7 @@ struct Parallelized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores @@ -765,7 +765,7 @@ struct Parallelized(Backend): SIMD.fma(simd_data1, simd_data2, simd_data3), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() # @parameter @@ -776,7 +776,7 @@ struct Parallelized(Backend): # result_array.store[width=simdwidth]( # i+remainder_offset, SIMD.fma(simd_data1,simd_data2,simd_data3) # ) - # vectorize[remainder_closure, opt_nelts](comps_remainder) + # vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_fma[ @@ -809,7 +809,7 @@ struct Parallelized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores @@ -829,7 +829,7 @@ struct Parallelized(Backend): SIMD.fma(simd_data1, simd_data2, simd), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() # @parameter @@ -839,7 +839,7 @@ struct Parallelized(Backend): # result_array.store[width=simdwidth]( # i+remainder_offset, SIMD.fma(simd_data1,simd_data2,simd) # ) - # vectorize[remainder_closure, opt_nelts](comps_remainder) + # vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_1_array_in_one_array_out[ @@ -862,7 +862,7 @@ struct Parallelized(Backend): A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores @@ -877,7 +877,7 @@ struct Parallelized(Backend): i + comps_per_core * j, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() # @parameter @@ -886,7 +886,7 @@ struct Parallelized(Backend): # result_array.store[width=simdwidth]( # i+remainder_offset, func[dtype, simdwidth](simd_data) # ) - # vectorize[remainder_closure, opt_nelts](comps_remainder) + # vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_2_array_in_one_array_out[ @@ -920,7 +920,7 @@ struct Parallelized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores @@ -939,7 +939,7 @@ struct Parallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() # @parameter @@ -949,7 +949,7 @@ struct Parallelized(Backend): # result_array.store[width=simdwidth]( # i+remainder_offset, func[dtype, simdwidth](simd_data1, simd_data2) # ) - # vectorize[remainder_closure, opt_nelts](comps_remainder) + # vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_1_array_1_scalar_in_one_array_out[ @@ -976,7 +976,7 @@ struct Parallelized(Backend): """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores @@ -993,7 +993,7 @@ struct Parallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() return result_array @@ -1013,7 +1013,7 @@ struct Parallelized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores @@ -1037,7 +1037,7 @@ struct Parallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() # @parameter @@ -1047,7 +1047,7 @@ struct Parallelized(Backend): # result_array.store[width=simdwidth]( # i+remainder_offset, func[dtype, simdwidth](simd_data1, simd_data2) # ) - # vectorize[remainder_closure, opt_nelts](comps_remainder) + # vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_compare_array_and_scalar[ @@ -1061,7 +1061,7 @@ struct Parallelized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores @@ -1083,7 +1083,7 @@ struct Parallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() return result_array @@ -1097,7 +1097,7 @@ struct Parallelized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array.shape() ) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores @@ -1112,7 +1112,7 @@ struct Parallelized(Backend): i + comps_per_core * j, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() # @parameter @@ -1121,7 +1121,7 @@ struct Parallelized(Backend): # result_array.store[width=simdwidth]( # i+remainder_offset, func[dtype, simdwidth](simd_data) # ) - # vectorize[remainder_closure, opt_nelts](comps_remainder) + # vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_simd_int[ @@ -1131,7 +1131,7 @@ struct Parallelized(Backend): ], ](self: Self, array: NDArray[dtype], intval: Int) raises -> NDArray[dtype]: var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -1141,7 +1141,7 @@ struct Parallelized(Backend): i, func[dtype, simdwidth](simd_data, intval) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array @@ -1190,7 +1190,7 @@ struct VectorizedParallelized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1214,7 +1214,7 @@ struct VectorizedParallelized(Backend): SIMD.fma(simd_data1, simd_data2, simd_data3), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1228,7 +1228,7 @@ struct VectorizedParallelized(Backend): SIMD.fma(simd_data1, simd_data2, simd_data3), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_fma[ @@ -1261,7 +1261,7 @@ struct VectorizedParallelized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = 1 + alias width = 1 var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1283,7 +1283,7 @@ struct VectorizedParallelized(Backend): SIMD.fma(simd_data1, simd_data2, simd), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1295,7 +1295,7 @@ struct VectorizedParallelized(Backend): i + remainder_offset, SIMD.fma(simd_data1, simd_data2, simd) ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_1_array_in_one_array_out[ @@ -1318,7 +1318,7 @@ struct VectorizedParallelized(Backend): A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores var comps_remainder: Int = array.num_elements() % num_cores @@ -1335,7 +1335,7 @@ struct VectorizedParallelized(Backend): i + comps_per_core * j, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1346,7 +1346,7 @@ struct VectorizedParallelized(Backend): i + remainder_offset, func[dtype, simdwidth](simd_data) ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_2_array_in_one_array_out[ @@ -1380,7 +1380,7 @@ struct VectorizedParallelized(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1401,7 +1401,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1414,7 +1414,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_1_array_1_scalar_in_one_array_out[ @@ -1441,7 +1441,7 @@ struct VectorizedParallelized(Backend): """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores var comps_remainder: Int = array.num_elements() % num_cores @@ -1460,7 +1460,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1473,7 +1473,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_compare_2_arrays[ @@ -1491,7 +1491,7 @@ struct VectorizedParallelized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1517,7 +1517,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1535,7 +1535,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_compare_array_and_scalar[ @@ -1549,7 +1549,7 @@ struct VectorizedParallelized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1569,7 +1569,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1583,7 +1583,7 @@ struct VectorizedParallelized(Backend): func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_is[ @@ -1595,7 +1595,7 @@ struct VectorizedParallelized(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores var comps_remainder: Int = array.num_elements() % num_cores @@ -1612,7 +1612,7 @@ struct VectorizedParallelized(Backend): i + comps_per_core * j, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure]() @@ -1623,7 +1623,7 @@ struct VectorizedParallelized(Backend): i + remainder_offset, func[dtype, simdwidth](simd_data) ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_simd_int[ @@ -1633,7 +1633,7 @@ struct VectorizedParallelized(Backend): ], ](self: Self, array: NDArray[dtype], intval: Int) raises -> NDArray[dtype]: var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -1643,7 +1643,7 @@ struct VectorizedParallelized(Backend): i, func[dtype, simdwidth](simd_data, intval) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array @@ -1694,9 +1694,9 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # #var num_cores: Int = num_physical_cores() - # var simd_ops_per_core: Int = opt_nelts * (array1.num_elements() // opt_nelts) // num_cores + # var simd_ops_per_core: Int = width * (array1.num_elements() // width) // num_cores var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores var remainder_offset: Int = num_cores * comps_per_core @@ -1721,7 +1721,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( ) # op_count+=1 - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -1737,7 +1737,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( # op_count+=1 # print(op_count) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_fma[ @@ -1770,7 +1770,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = 1 + alias width = 1 # var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1792,7 +1792,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( SIMD.fma(simd_data1, simd_data2, simd), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -1804,7 +1804,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( i + remainder_offset, SIMD.fma(simd_data1, simd_data2, simd) ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_1_array_in_one_array_out[ @@ -1827,7 +1827,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores var comps_remainder: Int = array.num_elements() % num_cores @@ -1844,7 +1844,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( i + comps_per_core * j, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -1855,7 +1855,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( i + remainder_offset, func[dtype, simdwidth](simd_data) ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_2_array_in_one_array_out[ @@ -1889,7 +1889,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -1910,7 +1910,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -1923,7 +1923,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_1_array_1_scalar_in_one_array_out[ @@ -1949,7 +1949,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() var comps_per_core: Int = array.num_elements() // num_cores var comps_remainder: Int = array.num_elements() % num_cores var remainder_offset: Int = num_cores * comps_per_core @@ -1967,7 +1967,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -1980,7 +1980,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_compare_2_arrays[ @@ -1998,7 +1998,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -2024,7 +2024,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -2042,7 +2042,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_compare_array_and_scalar[ @@ -2056,7 +2056,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # var num_cores: Int = num_physical_cores() var comps_per_core: Int = array1.num_elements() // num_cores var comps_remainder: Int = array1.num_elements() % num_cores @@ -2076,7 +2076,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -2090,7 +2090,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( func[dtype, simdwidth](simd_data1, simd_data2), ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_is[ @@ -2102,7 +2102,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array.shape() ) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() # var num_cores: Int = num_physical_cores() var comps_per_core: Int = array.num_elements() // num_cores var comps_remainder: Int = array.num_elements() % num_cores @@ -2119,7 +2119,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( i + comps_per_core * j, func[dtype, simdwidth](simd_data) ) - vectorize[closure, opt_nelts](comps_per_core) + vectorize[closure, width](comps_per_core) parallelize[par_closure](num_cores, num_cores) @@ -2130,7 +2130,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( i + remainder_offset, func[dtype, simdwidth](simd_data) ) - vectorize[remainder_closure, opt_nelts](comps_remainder) + vectorize[remainder_closure, width](comps_remainder) return result_array fn math_func_simd_int[ @@ -2140,7 +2140,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( ], ](self: Self, array: NDArray[dtype], intval: Int) raises -> NDArray[dtype]: var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn closure[simdwidth: Int](i: Int): @@ -2150,7 +2150,7 @@ struct VectorizedParallelizedNWorkers[num_cores: Int = num_physical_cores()]( i, func[dtype, simdwidth](simd_data, intval) ) - vectorize[closure, opt_nelts](array.num_elements()) + vectorize[closure, width](array.num_elements()) return result_array @@ -2198,7 +2198,7 @@ struct Naive(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() for i in range(array1.num_elements()): var simd_data1 = array1.load[width=1](i) @@ -2239,7 +2239,7 @@ struct Naive(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() for i in range(array1.num_elements()): var simd_data1 = array1.load[width=1](i) @@ -2473,20 +2473,18 @@ struct VectorizedVerbose(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array1.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array1.load[width=opt_nelts](i) - var simd_data2 = array2.load[width=opt_nelts](i) - var simd_data3 = array3.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( + alias width = simdwidthof[dtype]() + for i in range(0, width * (array1.num_elements() // width), width): + var simd_data1 = array1.load[width=width](i) + var simd_data2 = array2.load[width=width](i) + var simd_data3 = array3.load[width=width](i) + result_array.store[width=width]( i, SIMD.fma(simd_data1, simd_data2, simd_data3) ) - if array1.num_elements() % opt_nelts != 0: + if array1.num_elements() % width != 0: for i in range( - opt_nelts * (array1.num_elements() // opt_nelts), + width * (array1.num_elements() // width), array1.num_elements(), ): var simd_data1 = array1.load[width=1](i) @@ -2527,20 +2525,18 @@ struct VectorizedVerbose(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array1.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array1.load[width=opt_nelts](i) - var simd_data2 = array2.load[width=opt_nelts](i) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array1.num_elements() // width), width): + var simd_data1 = array1.load[width=width](i) + var simd_data2 = array2.load[width=width](i) - result_array.store[width=opt_nelts]( + result_array.store[width=width]( i, SIMD.fma(simd_data1, simd_data2, simd) ) - if array1.num_elements() % opt_nelts != 0: + if array1.num_elements() % width != 0: for i in range( - opt_nelts * (array1.num_elements() // opt_nelts), + width * (array1.num_elements() // width), array1.num_elements(), ): var simd_data1 = array1.load[width=1](i) @@ -2571,18 +2567,14 @@ struct VectorizedVerbose(Backend): A new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array.num_elements() // opt_nelts), opt_nelts - ): - var simd_data = array.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data) - ) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array.num_elements() // width), width): + var simd_data = array.load[width=width](i) + result_array.store[width=width](i, func[dtype, width](simd_data)) - if array.num_elements() % opt_nelts != 0: + if array.num_elements() % width != 0: for i in range( - opt_nelts * (array.num_elements() // opt_nelts), + width * (array.num_elements() // width), array.num_elements(), ): var simd_data = func[dtype, 1](array.load[width=1](i)) @@ -2620,19 +2612,17 @@ struct VectorizedVerbose(Backend): "Shape Mismatch error shapes must match for this function" ) var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array1.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array1.load[width=opt_nelts](i) - var simd_data2 = array2.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data1, simd_data2) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array1.num_elements() // width), width): + var simd_data1 = array1.load[width=width](i) + var simd_data2 = array2.load[width=width](i) + result_array.store[width=width]( + i, func[dtype, width](simd_data1, simd_data2) ) - if array1.num_elements() % opt_nelts != 0: + if array1.num_elements() % width != 0: for i in range( - opt_nelts * (array1.num_elements() // opt_nelts), + width * (array1.num_elements() // width), array1.num_elements(), ): var simd_data1 = array1.load[width=1](i) @@ -2665,19 +2655,17 @@ struct VectorizedVerbose(Backend): A a new NDArray that is NDArray with the function func applied. """ var result_array: NDArray[dtype] = NDArray[dtype](array.shape()) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array.load[width=opt_nelts](i) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array.num_elements() // width), width): + var simd_data1 = array.load[width=width](i) var simd_data2 = scalar - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data1, simd_data2) + result_array.store[width=width]( + i, func[dtype, width](simd_data1, simd_data2) ) - if array.num_elements() % opt_nelts != 0: + if array.num_elements() % width != 0: for i in range( - opt_nelts * (array.num_elements() // opt_nelts), + width * (array.num_elements() // width), array.num_elements(), ): var simd_data1 = array.load[width=1](i) @@ -2702,23 +2690,21 @@ struct VectorizedVerbose(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array1.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array1.load[width=opt_nelts](i) - var simd_data2 = array2.load[width=opt_nelts](i) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array1.num_elements() // width), width): + var simd_data1 = array1.load[width=width](i) + var simd_data2 = array2.load[width=width](i) # result_array.store[width=simdwidth]( - # i, func[dtype, opt_nelts](simd_data1, simd_data2) + # i, func[dtype, width](simd_data1, simd_data2) # ) - bool_simd_store[opt_nelts]( + bool_simd_store[width]( result_array.unsafe_ptr(), i, - func[dtype, opt_nelts](simd_data1, simd_data2), + func[dtype, width](simd_data1, simd_data2), ) - if array1.num_elements() % opt_nelts != 0: + if array1.num_elements() % width != 0: for i in range( - opt_nelts * (array1.num_elements() // opt_nelts), + width * (array1.num_elements() // width), array1.num_elements(), ): var simd_data1 = array1.load[width=1](i) @@ -2744,20 +2730,18 @@ struct VectorizedVerbose(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array1.shape() ) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array1.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array1.load[width=opt_nelts](i) - var simd_data2 = SIMD[dtype, opt_nelts].splat(scalar) - bool_simd_store[opt_nelts]( + alias width = simdwidthof[dtype]() + for i in range(0, width * (array1.num_elements() // width), width): + var simd_data1 = array1.load[width=width](i) + var simd_data2 = SIMD[dtype, width].splat(scalar) + bool_simd_store[width]( result_array.unsafe_ptr(), i, - func[dtype, opt_nelts](simd_data1, simd_data2), + func[dtype, width](simd_data1, simd_data2), ) - if array1.num_elements() % opt_nelts != 0: + if array1.num_elements() % width != 0: for i in range( - opt_nelts * (array1.num_elements() // opt_nelts), + width * (array1.num_elements() // width), array1.num_elements(), ): var simd_data1 = array1.load[width=1](i) @@ -2778,18 +2762,14 @@ struct VectorizedVerbose(Backend): var result_array: NDArray[DType.bool] = NDArray[DType.bool]( array.shape() ) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array.num_elements() // opt_nelts), opt_nelts - ): - var simd_data = array.load[width=opt_nelts](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data) - ) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array.num_elements() // width), width): + var simd_data = array.load[width=width](i) + result_array.store[width=width](i, func[dtype, width](simd_data)) - if array.num_elements() % opt_nelts != 0: + if array.num_elements() % width != 0: for i in range( - opt_nelts * (array.num_elements() // opt_nelts), + width * (array.num_elements() // width), array.num_elements(), ): var simd_data = func[dtype, 1](array.load[width=1](i)) @@ -2803,19 +2783,17 @@ struct VectorizedVerbose(Backend): ], ](self: Self, array1: NDArray[dtype], intval: Int) raises -> NDArray[dtype]: var result_array: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias opt_nelts = simdwidthof[dtype]() - for i in range( - 0, opt_nelts * (array1.num_elements() // opt_nelts), opt_nelts - ): - var simd_data1 = array1.load[width=opt_nelts](i) + alias width = simdwidthof[dtype]() + for i in range(0, width * (array1.num_elements() // width), width): + var simd_data1 = array1.load[width=width](i) - result_array.store[width=opt_nelts]( - i, func[dtype, opt_nelts](simd_data1, intval) + result_array.store[width=width]( + i, func[dtype, width](simd_data1, intval) ) - if array1.num_elements() % opt_nelts != 0: + if array1.num_elements() % width != 0: for i in range( - opt_nelts * (array1.num_elements() // opt_nelts), + width * (array1.num_elements() // width), array1.num_elements(), ): var simd_data1 = array1.load[width=1](i) diff --git a/numojo/math/statistics/cumulative_reduce.mojo b/numojo/math/statistics/cumulative_reduce.mojo index 98e8604..56e4632 100644 --- a/numojo/math/statistics/cumulative_reduce.mojo +++ b/numojo/math/statistics/cumulative_reduce.mojo @@ -9,6 +9,7 @@ Cumulative reduction statistics functions for NDArrays import math from algorithm import vectorize + from ...core.ndarray import NDArray, NDArrayShape from ...core.utility_funcs import is_inttype, is_floattype from ...core.sort import binary_sort @@ -41,14 +42,14 @@ fn cumsum[ The sum of all items in the array as a SIMD Value of `dtype`. """ var result = Scalar[dtype]() - alias opt_nelts: Int = simdwidthof[dtype]() + alias width: Int = simdwidthof[dtype]() @parameter fn vectorize_sum[simd_width: Int](idx: Int) -> None: var simd_data = array.load[width=simd_width](idx) result += simd_data.reduce_add() - vectorize[vectorize_sum, opt_nelts](array.num_elements()) + vectorize[vectorize_sum, width](array.num_elements()) return result @@ -68,14 +69,14 @@ fn cumprod[ """ var result: SIMD[dtype, 1] = SIMD[dtype, 1](1.0) - alias opt_nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() @parameter fn vectorize_sum[simd_width: Int](idx: Int) -> None: var simd_data = array.load[width=simd_width](idx) result *= simd_data.reduce_mul() - vectorize[vectorize_sum, opt_nelts](array.num_elements()) + vectorize[vectorize_sum, width](array.num_elements()) return result @@ -99,12 +100,6 @@ fn cummean[ Returns: The mean of all of the member values of array as a SIMD Value of `dtype`. """ - # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[dtype]() and is_inttype[dtype](): - raise Error( - "Input and output cannot be `Int` datatype as it may lead to" - " precision errors" - ) return cumsum[dtype](array) / (array.num_elements()) @@ -181,11 +176,11 @@ fn maxT[ The maximum of all of the member values of array as a SIMD Value of `dtype`. """ # TODO: Test this - alias opt_nelts = simdwidthof[dtype]() - var max_value = NDArray[dtype](NDArrayShape(opt_nelts)) - for i in range(opt_nelts): + alias width = simdwidthof[dtype]() + var max_value = NDArray[dtype](NDArrayShape(width)) + for i in range(width): max_value[i] = array[0] - # var max_value: SIMD[ dtype, opt_nelts] = SIMD[ dtype, opt_nelts](array[0]) + # var max_value: SIMD[ dtype, width] = SIMD[ dtype, width](array[0]) @parameter fn vectorized_max[simd_width: Int](idx: Int) -> None: @@ -197,7 +192,7 @@ fn maxT[ ), ) - vectorize[vectorized_max, opt_nelts](array.num_elements()) + vectorize[vectorized_max, width](array.num_elements()) var result: Scalar[dtype] = Scalar[dtype](max_value.get_scalar(0)) for i in range(max_value.__len__()): @@ -221,9 +216,9 @@ fn minT[ Returns: The minimum of all of the member values of array as a SIMD Value of `dtype`. """ - alias opt_nelts = simdwidthof[dtype]() - var min_value = NDArray[dtype](NDArrayShape(opt_nelts)) - for i in range(opt_nelts): + alias width = simdwidthof[dtype]() + var min_value = NDArray[dtype](NDArrayShape(width)) + for i in range(width): min_value[i] = array[0] @parameter @@ -236,7 +231,7 @@ fn minT[ ), ) - vectorize[vectorized_min, opt_nelts](array.num_elements()) + vectorize[vectorized_min, width](array.num_elements()) var result: Scalar[dtype] = Scalar[dtype](min_value.get_scalar(0)) for i in range(min_value.__len__()): @@ -263,14 +258,6 @@ fn cumpvariance[ Returns: The variance of all of the member values of array as a SIMD Value of `dtype`. """ - # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - # * REMOVE THIS CONSTRAINT? - if is_inttype[dtype]() and is_inttype[dtype](): - raise Error( - "Input and output cannot be `Int` datatype as it may lead to" - " precision errors" - ) - var mean_value: Scalar[dtype] if not mu: mean_value = cummean[dtype](array) @@ -303,12 +290,6 @@ fn cumvariance[ Returns: The variance of all of the member values of array as a SIMD Value of `dtype`. """ - # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[dtype]() and is_inttype[dtype](): - raise Error( - "Input and output cannot be `Int` datatype as it may lead to" - " precision errors" - ) var mean_value: Scalar[dtype] if not mu: @@ -341,12 +322,6 @@ fn cumpstdev[ Returns: The standard deviation of all of the member values of array as a SIMD Value of `dtype`. """ - # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[dtype]() and is_inttype[dtype](): - raise Error( - "Input and output cannot be `Int` datatype as it may lead to" - " precision errors" - ) return math.sqrt(cumpvariance[dtype](array, mu)) @@ -367,12 +342,6 @@ fn cumstdev[ Returns: The standard deviation of all of the member values of array as a SIMD Value of `dtype`. """ - # constrained[is_inttype[ dtype]() and is_inttype[dtype](), "Input and output both cannot be `Integer` datatype as it may lead to precision errors"]() - if is_inttype[dtype]() and is_inttype[dtype](): - raise Error( - "Input and output cannot be `Int` datatype as it may lead to" - " precision errors" - ) return math.sqrt(cumvariance[dtype](array, mu)) @@ -465,7 +434,7 @@ fn minimum[ """ var result: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() if array1.shape() != array2.shape(): raise Error("array shapes are not the same") @@ -479,7 +448,7 @@ fn minimum[ ), ) - vectorize[vectorized_min, nelts](array1.num_elements()) + vectorize[vectorized_min, width](array1.num_elements()) return result @@ -500,7 +469,7 @@ fn maximum[ """ var result: NDArray[dtype] = NDArray[dtype](array1.shape()) - alias nelts = simdwidthof[dtype]() + alias width = simdwidthof[dtype]() if array1.shape() != array2.shape(): raise Error("array shapes are not the same") @@ -514,7 +483,7 @@ fn maximum[ ), ) - vectorize[vectorized_max, nelts](array1.num_elements()) + vectorize[vectorized_max, width](array1.num_elements()) return result diff --git a/numojo/math/trig.mojo b/numojo/math/trig.mojo index c731ab9..9b76f14 100644 --- a/numojo/math/trig.mojo +++ b/numojo/math/trig.mojo @@ -8,9 +8,9 @@ Implements Trigonometry functions for arrays. import math -import . math_funcs as _mf -from .arithmetic import sqrt, fma +from .arithmetic import sqrt, fma +import . math_funcs as _mf from ..core.ndarray import NDArray # TODO: add dtype in backends and pass it here. diff --git a/tests/test_array_creation.mojo b/tests/test_array_creation.mojo index 79c225a..984b7bd 100644 --- a/tests/test_array_creation.mojo +++ b/tests/test_array_creation.mojo @@ -113,39 +113,15 @@ def test_identity(): def test_eye(): var np = Python.import_module("numpy") - check(nm.eye[nm.i64](100,100),np.eye(100,100,dtype=np.int64),"Eye is broken") + check( + nm.eye[nm.i64](100, 100), + np.eye(100, 100, dtype=np.int64), + "Eye is broken", + ) -def test_diagflat(): - var np = Python.import_module("numpy") - var temp = nm.arange[nm.i64](1, 10, 10) - temp.reshape(3,3) - check(nm.diagflat[nm.i64](nm),np.diagflat(np.arange(1,10,10).reshape(3,3),"Diagflat is broken") - -def main(): - # var np = Python.import_module("numpy") - # var arr = nm.arange[nm.f64](0, 100) - # arr.reshape(10, 10) - # var np_arr = np.arange(0, 100).reshape(10, 10) - var np = Python.import_module("numpy") - var fill_val: Scalar[nm.i32] = 5 - print(nm.NDArray(5, 5, 5, fill=fill_val).shape()) - print(np.zeros([5, 5, 5], dtype=np.float64).fill(5)) - # Arange like flat arrays - # check(nm.arange[nm.i64](0,100),np.arange(0,100,dtype=np.int64),"Arange is broken") - # check(nm.linspace[nm.i64](0,100),np.linspace(0,100,dtype=np.float64),"Linspace is broken") - # check_is_close(nm.logspace[nm.i64](0,100,5),np.logspace(0,100,5,dtype=np.float64),"Logspace is broken") - # check_is_close(nm.geomspace[nm.i64](1,100,5),np.geomspace(1,100,5,dtype=np.float64),"Logspace is broken") - # print((arr@arr).to_numpy()-np.matmul(np_arr,np_arr)) - print(nm.matmul_naive[nm.f64](arr,arr).to_numpy())#-np.matmul(np_arr,np_arr)) - print(np.matmul(np_arr,np_arr)) # # Basic ND arrays - # print(nm.sin[nm.f64](nm.arange[nm.f64](0,15))) - # print( np.sin(np.arange(0,15, dtype=np.float64))) - # check(nm.zeros[nm.f64](10,10,10,10),np.zeros((10,10,10,10),dtype=np.float64),"Zeros is broken") - # check(nm.ones[nm.f64](10,10,10,10),np.ones((10,10,10,10),dtype=np.float64),"Ones is broken") - # check(nm.full[nm.f64](10,10,10,10,fill_value=10),np.full((10,10,10,10),10,dtype=np.float64),"Full is broken") - - # # 2d Linalg related arrays - - # check(nm.identity[nm.i64](100),np.identity(100,dtype=np.int64),"Identity is broken") - # check(nm.eye[nm.i64](100,100),np.eye(100,100,dtype=np.int64),"Eye is broken") - # check(nm.eye[nm.i64](100,100),np.eye(100,100,dtype=np.int64),"Eye is broken") + +# def test_diagflat(): +# var np = Python.import_module("numpy") +# var temp = nm.arange[nm.i64](1, 10, 10) +# temp.reshape(3,3) +# check(nm.diagflat[nm.i64](nm), np.diagflat(np.arange(1,10,10).reshape(3,3), "Diagflat is broken") From 96d0ecc86638fa1469686af92614bb629d20c5a8 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Sun, 8 Sep 2024 16:53:00 +0900 Subject: [PATCH 25/32] fixed unit test errors --- numojo/core/ndarray.mojo | 2 +- test.mojo | 41 +++++++++++++++++++++------------------ tests/test_math.mojo | 2 +- tests/test_sort.mojo | 6 +++--- tests/utils_for_test.mojo | 4 ++-- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 0517343..97e07f0 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -12,7 +12,7 @@ Implements N-Dimensional Array 1) Generalize mdot, rdot to take any IxJx...xKxL and LxMx...xNxP matrix and matmul it into IxJx..xKxMx...xNxP array. 2) Add vectorization for _get_index 3) Write more explanatory Error("") statements -4) Create NDArrayView and remove coefficients. +4) Create NDArrayView and remove coefficients. """ from builtin.type_aliases import AnyLifetime diff --git a/test.mojo b/test.mojo index 428ef0e..4c8cc7b 100644 --- a/test.mojo +++ b/test.mojo @@ -78,6 +78,9 @@ fn test_constructors1() raises: print("offset: ", arr6.stride.ndoffset) print("dtype: ", arr6.dtype) + var arr7 = nm.NDArray[nm.f32](String("[[1.0,0,1], [0,2,1], [1,1,1]]")) + print(arr7) + fn test_constructors2() raises: var fill_value: SIMD[i32, 1] = 10 @@ -86,34 +89,34 @@ fn test_constructors2() raises: fn test_random() raises: - var arr_variadic = nm.core.random.rand( - shape=List[Int](10, 10, 10), min=1.0, max=2.0 - ) - print(arr_variadic) - var random_array_var = nm.core.random.randn[i16](3, 2, mean=0, variance=5) - print(random_array_var) - var random_array_list = nm.core.random.randn[i16]( - List[Int](3, 2), mean=0, variance=1 - ) - print(random_array_list) - - var random_array_var1 = nm.core.random.rand[i16](3, 2, min=0, max=100) - print(random_array_var1) - var random_array_list1 = nm.core.random.rand[i16]( + # var arr_variadic = nm.core.random.rand( + # shape=List[Int](10, 10, 10), min=1.0, max=2.0 + # ) + # print(arr_variadic) + # var random_array_var = nm.core.random.randn[i16](3, 2, mean=0, variance=5) + # print(random_array_var) + # var random_array_list = nm.core.random.randn[i16]( + # List[Int](3, 2), mean=0, variance=1 + # ) + # print(random_array_list) + + # var random_array_var1 = nm.core.random.rand[i16](3, 2, min=0, max=100) + # print(random_array_var1) + var random_array_list1 = nm.core.random.rand[i32]( List[Int](3, 2), min=0, max=100 ) print(random_array_list1) - fn test_arr_manipulation() raises: - var A = arange[i16](1, 7, 1) + var np = Python.import_module("numpy") + var A = np.arange(12) print(A) var temp = NDArray[f64](data=A) print(temp) temp.T() print(temp) A.reshape(2, 3, order="F") - nm.ravel(A) + # nm.ravel(A) print(A) var B = arange[i16](0, 12, 1) B.reshape(3, 2, 2, order="F") @@ -250,10 +253,10 @@ fn test_slicing() raises: fn main() raises: # test_constructors1() # test_constructors2() - # test_random() + test_random() # test_arr_manipulation() # test_bool_masks1() - test_bool_masks2() + # test_bool_masks2() # test_creation_routines() # test_slicing() diff --git a/tests/test_math.mojo b/tests/test_math.mojo index 2f35c6c..f52ea4c 100644 --- a/tests/test_math.mojo +++ b/tests/test_math.mojo @@ -74,7 +74,7 @@ def test_matmul(): def test_inverse(): var np = Python.import_module("numpy") - var arr = nm.NDArray("[[1,0,1], [0,2,1], [1,1,1]]") + var arr = nm.NDArray[nm.f32](String("[[1,0,1], [0,2,1], [1,1,1]]")) var np_arr = arr.to_numpy() check_is_close( nm.math.linalg.inverse(arr), np.linalg.inv(np_arr), "Inverse is broken" diff --git a/tests/test_sort.mojo b/tests/test_sort.mojo index e46a31f..c8bab18 100644 --- a/tests/test_sort.mojo +++ b/tests/test_sort.mojo @@ -5,11 +5,11 @@ from utils_for_test import check, check_is_close def test_sort_1d(): - arr = nm.core.random.rand(25) + var arr = nm.core.random.rand[nm.i16](25) var np = Python.import_module("numpy") - arr_sorted = arr.sort() + arr.sort() np_arr_sorted = np.sort(arr.to_numpy()) - return check(arr_sorted, np_arr_sorted, "quick sort is broken") + return check[nm.i16](arr, np_arr_sorted, "quick sort is broken") # ND sorting currently works differently than numpy which has an on axis diff --git a/tests/utils_for_test.mojo b/tests/utils_for_test.mojo index 94b3ef7..9a65910 100644 --- a/tests/utils_for_test.mojo +++ b/tests/utils_for_test.mojo @@ -3,11 +3,11 @@ from testing.testing import assert_true import numojo as nm -fn check(array: nm.NDArray, np_sol: PythonObject, st: String) raises: +fn check[dtype: DType](array: nm.NDArray[dtype], np_sol: PythonObject, st: String) raises: var np = Python.import_module("numpy") assert_true(np.all(np.equal(array.to_numpy(), np_sol)), st) -fn check_is_close(array: nm.NDArray, np_sol: PythonObject, st: String) raises: +fn check_is_close[dtype: DType](array: nm.NDArray[dtype], np_sol: PythonObject, st: String) raises: var np = Python.import_module("numpy") assert_true(np.all(np.isclose(array.to_numpy(), np_sol)), st) From 1c52fc5e087dc6327e385eb9db0a7102e6aea9e1 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Mon, 9 Sep 2024 01:17:13 +0900 Subject: [PATCH 26/32] fixed random module compile time randint error --- numojo/core/random.mojo | 115 ++++++++++++++++++++------------- numojo/core/utility_funcs.mojo | 9 +++ tests/utils_for_test.mojo | 8 ++- 3 files changed, 84 insertions(+), 48 deletions(-) diff --git a/numojo/core/random.mojo b/numojo/core/random.mojo index ac7a4f6..1fd88eb 100644 --- a/numojo/core/random.mojo +++ b/numojo/core/random.mojo @@ -40,6 +40,51 @@ fn rand[dtype: DType = DType.float64](*shape: Int) raises -> NDArray[dtype]: return result^ +@parameter +fn int_rand_func[ + dtype: DType +](inout result: NDArray[dtype], min: Scalar[dtype], max: Scalar[dtype]): + """ + Generate random integers between `min` and `max` and store them in the given NDArray. + + Parameters: + dtype: The data type of the random integers. + + Args: + result: The NDArray to store the random integers. + min: The minimum value of the random integers. + max: The maximum value of the random integers. + """ + random.randint[dtype]( + ptr=result.data, + size=result.ndshape.ndsize, + low=int(min), + high=int(max), + ) + + +@parameter +fn float_rand_func[ + dtype: DType +](inout result: NDArray[dtype], min: Scalar[dtype], max: Scalar[dtype]): + """ + Generate random floating-point numbers between `min` and `max` and store them in the given NDArray. + + Parameters: + dtype: The data type of the random floating-point numbers. + + Args: + result: The NDArray to store the random floating-point numbers. + min: The minimum value of the random floating-point numbers. + max: The maximum value of the random floating-point numbers. + """ + for i in range(result.ndshape.ndsize): + var temp: Scalar[dtype] = random.random_float64( + min.cast[f64](), max.cast[f64]() + ).cast[dtype]() + result.data[i] = temp + + fn rand[ dtype: DType = DType.float64 ](*shape: Int, min: Scalar[dtype], max: Scalar[dtype]) raises -> NDArray[dtype]: @@ -67,29 +112,18 @@ fn rand[ """ var result: NDArray[dtype] = NDArray[dtype](shape) random.seed() - # if dtype.is_integral(): - # random.randint[dtype]( - # ptr=result.data, - # size=result.ndshape.ndsize, - # low=int(min), - # high=int(max), - # ) - # elif dtype.is_floating_point(): - # for i in range(result.ndshape.ndsize): - # var temp: Scalar[dtype] = random.random_float64( - # min.cast[f64](), max.cast[f64]() - # ).cast[dtype]() - # result.__setitem__(i, temp) - # else: - # raise Error( - # "Invalid type provided. dtype must be either an integral or" - # " floating-point type." - # ) - for i in range(result.ndshape.ndsize): - var temp: Scalar[dtype] = random.random_float64( - min.cast[f64](), max.cast[f64]() - ).cast[dtype]() - result.data[i] = temp + + @parameter + if is_floattype[dtype](): + float_rand_func[dtype](result, min, max) + elif is_inttype[dtype](): + int_rand_func[dtype](result, min, max) + else: + raise Error( + "Invalid type provided. dtype must be either an integral or" + " floating-point type." + ) + return result^ @@ -123,29 +157,18 @@ fn rand[ """ var result: NDArray[dtype] = NDArray[dtype](shape) random.seed() - # if is_inttype(dtype): - # for i in range(result.ndshape.ndsize): - # var temp: Scalar[dtype] = random.random_float64( - # min.cast[f64](), max.cast[f64]() - # ).cast[dtype]() - # result.data[i] = temp - # elif is_floattype(dtype): - # random.randint[dtype]( - # ptr=result.data, - # size=result.ndshape.ndsize, - # low=int(min), - # high=int(max), - # ) - # else: - # raise Error( - # "Invalid type provided. dtype must be either an integral or" - # " floating-point type." - # ) - for i in range(result.ndshape.ndsize): - var temp: Scalar[dtype] = random.random_float64( - min.cast[f64](), max.cast[f64]() - ).cast[dtype]() - result.data[i] = temp + + @parameter + if is_floattype[dtype](): + float_rand_func[dtype](result, min, max) + elif is_inttype[dtype](): + int_rand_func[dtype](result, min, max) + else: + raise Error( + "Invalid type provided. dtype must be either an integral or" + " floating-point type." + ) + return result^ diff --git a/numojo/core/utility_funcs.mojo b/numojo/core/utility_funcs.mojo index f45f9c0..f83139e 100644 --- a/numojo/core/utility_funcs.mojo +++ b/numojo/core/utility_funcs.mojo @@ -7,6 +7,7 @@ Type related utility functions. # ===----------------------------------------------------------------------=== # +@parameter fn is_inttype[dtype: DType]() -> Bool: """ Check if the given dtype is an integer type at compile time. @@ -17,6 +18,8 @@ fn is_inttype[dtype: DType]() -> Bool: Returns: Bool: True if the given dtype is an integer type, False otherwise. """ + + @parameter if ( dtype == DType.int8 or dtype == DType.int16 @@ -47,6 +50,7 @@ fn is_inttype(dtype: DType) -> Bool: return False +@parameter fn is_floattype[dtype: DType]() -> Bool: """ Check if the given dtype is a floating point type at compile time. @@ -57,6 +61,8 @@ fn is_floattype[dtype: DType]() -> Bool: Returns: Bool: True if the given dtype is a floating point type, False otherwise. """ + + @parameter if ( dtype == DType.float16 or dtype == DType.float32 @@ -85,6 +91,7 @@ fn is_floattype(dtype: DType) -> Bool: return False +@parameter fn is_booltype[dtype: DType]() -> Bool: """ Check if the given dtype is a boolean type at compile time. @@ -95,6 +102,8 @@ fn is_booltype[dtype: DType]() -> Bool: Returns: Bool: True if the given dtype is a boolean type, False otherwise. """ + + @parameter if dtype == DType.bool: return True return False diff --git a/tests/utils_for_test.mojo b/tests/utils_for_test.mojo index 9a65910..0fb2e5f 100644 --- a/tests/utils_for_test.mojo +++ b/tests/utils_for_test.mojo @@ -3,11 +3,15 @@ from testing.testing import assert_true import numojo as nm -fn check[dtype: DType](array: nm.NDArray[dtype], np_sol: PythonObject, st: String) raises: +fn check[ + dtype: DType +](array: nm.NDArray[dtype], np_sol: PythonObject, st: String) raises: var np = Python.import_module("numpy") assert_true(np.all(np.equal(array.to_numpy(), np_sol)), st) -fn check_is_close[dtype: DType](array: nm.NDArray[dtype], np_sol: PythonObject, st: String) raises: +fn check_is_close[ + dtype: DType +](array: nm.NDArray[dtype], np_sol: PythonObject, st: String) raises: var np = Python.import_module("numpy") assert_true(np.all(np.isclose(array.to_numpy(), np_sol)), st) From f5f3c09b0bf0a392dc8a908e9f6320d8e56d3de4 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Mon, 9 Sep 2024 12:25:40 +0900 Subject: [PATCH 27/32] fixed docstring error in solve.mojo --- numojo/math/linalg/solve.mojo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numojo/math/linalg/solve.mojo b/numojo/math/linalg/solve.mojo index 541b3c4..85e060c 100644 --- a/numojo/math/linalg/solve.mojo +++ b/numojo/math/linalg/solve.mojo @@ -24,7 +24,7 @@ fn lu_decomposition[ A tuple of the upper and lower triangular matrices. Example: - ```mojo + ``` import numojo as nm fn main() raises: var arr = nm.NDArray[nm.f64]("[[1,2,3], [4,5,6], [7,8,9]]") @@ -188,7 +188,7 @@ fn inverse[ An example goes as follows: - ```mojo + ``` import numojo as nm fn main() raises: var A = nm.NDArray("[[1,0,1], [0,2,1], [1,1,1]]") From 205ac110bc607bb49065c4f0119d778673684061 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Tue, 10 Sep 2024 01:04:28 +0900 Subject: [PATCH 28/32] added magic support with predefined tasks --- magic.lock | 1583 ++++++++++++++++++++++++++++++++++++++++++++++ mojoproject.toml | 24 + 2 files changed, 1607 insertions(+) create mode 100644 magic.lock create mode 100644 mojoproject.toml diff --git a/magic.lock b/magic.lock new file mode 100644 index 0000000..5050f2a --- /dev/null +++ b/magic.lock @@ -0,0 +1,1583 @@ +version: 5 +environments: + default: + channels: + - url: https://conda.anaconda.org/conda-forge/ + - url: https://conda.modular.com/max/ + packages: + linux-64: + - conda: https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-h4bc722e_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2024.8.30-hbcca054_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.4.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/importlib_metadata-8.4.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_client-8.6.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/jupyter_core-5.7.2-py311h38be061_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.1-h166bdaf_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/krb5-1.21.3-h659f571_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.40-hf3520f5_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libblas-3.9.0-23_linux64_openblas.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.9.0-23_linux64_openblas.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20191231-he28a2e2_2.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.6.3-h5888daf_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libffi-3.4.2-h7f98852_5.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-14.1.0-h77fa898_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-14.1.0-h69a702a_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-14.1.0-h69a702a_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-ng-14.1.0-h69a702a_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-14.1.0-hc5f4f2c_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgomp-14.1.0-h77fa898_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.9.0-23_linux64_openblas.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libnsl-2.0.1-hd590300_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.27-pthreads_hac2b453_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libsodium-1.0.20-h4ab18f5_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.46.1-hadc24fc_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-14.1.0-hc0a3c3a_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-14.1.0-h4852527_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.38.1-h0b41bf4_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.1-h4ab18f5_1.conda + - conda: https://conda.modular.com/max/noarch/max-24.4.0-pyh4616a5c_1.conda + - conda: https://conda.modular.com/max/linux-64/max-core-24.4.0-hb0f4dca_1.conda + - conda: https://conda.modular.com/max/linux-64/max-python-24.4.0-py311h0c25911_1.conda + - conda: https://conda.modular.com/max/noarch/mblack-0.2.dev0-pyh5ed91e1_0.conda + - conda: https://conda.modular.com/max/noarch/mojo-jupyter-24.4.0-pyh5ed91e1_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.5-he02047a_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/numpy-2.1.1-py311h71ddf71_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/openssl-3.3.2-hb9d3cd8_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.11.9-hb806964_0_cpython.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.11-5_cp311.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pyzmq-26.2.0-py311h7deb3e3_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8228510_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/tornado-6.4.1-py311h9ecbd09_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024a-h8827d51_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xz-5.2.6-h166bdaf_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/linux-64/zeromq-4.3.5-ha4adb4c_5.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.20.1-pyhd8ed1ab_0.conda + osx-arm64: + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-h99b78c6_7.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2024.8.30-hf0a4a13_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.4.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/importlib_metadata-8.4.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_client-8.6.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/jupyter_core-5.7.2-py311h267d04e_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/krb5-1.21.3-h237132a_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libblas-3.9.0-23_osxarm64_openblas.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcblas-3.9.0-23_osxarm64_openblas.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-18.1.8-h3ed4263_7.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libedit-3.1.20191231-hc8eb9b7_2.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.6.3-hf9b8971_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libffi-3.4.2-h3422bc3_5.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libgfortran-5.0.0-13_2_0_hd922786_3.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libgfortran5-13.2.0-hf226fd6_3.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/liblapack-3.9.0-23_osxarm64_openblas.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libopenblas-0.3.27-openmp_h517c56d_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libsodium-1.0.20-h99b78c6_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libsqlite-3.46.1-hc14010f_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libzlib-1.3.1-hfb2fe0b_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/llvm-openmp-18.1.8-hde57baf_1.conda + - conda: https://conda.modular.com/max/noarch/max-24.4.0-pyh4616a5c_1.conda + - conda: https://conda.modular.com/max/osx-arm64/max-core-24.4.0-h60d57d3_1.conda + - conda: https://conda.modular.com/max/osx-arm64/max-python-24.4.0-py311h13a3eaa_1.conda + - conda: https://conda.modular.com/max/noarch/mblack-0.2.dev0-pyh5ed91e1_0.conda + - conda: https://conda.modular.com/max/noarch/mojo-jupyter-24.4.0-pyh5ed91e1_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.5-h7bae524_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/numpy-2.1.1-py311h6de8079_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/openssl-3.3.2-h8359307_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.11.9-h932a869_0_cpython.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.11-5_cp311.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pyzmq-26.2.0-py311h137d824_2.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/tornado-6.4.1-py311h460d6c5_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024a-h8827d51_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/xz-5.2.6-h57fd34a_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/zeromq-4.3.5-h64debc3_5.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.20.1-pyhd8ed1ab_0.conda +packages: +- kind: conda + name: _libgcc_mutex + version: '0.1' + build: conda_forge + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2 + sha256: fe51de6107f9edc7aa4f786a70f4a883943bc9d39b3bb7307c04c41410990726 + md5: d7c89558ba9fa0495403155b64376d81 + license: None + size: 2562 + timestamp: 1578324546067 +- kind: conda + name: _openmp_mutex + version: '4.5' + build: 2_gnu + build_number: 16 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2 + sha256: fbe2c5e56a653bebb982eda4876a9178aedfc2b545f25d0ce9c4c0b508253d22 + md5: 73aaf86a425cc6e73fcf236a5a46396d + depends: + - _libgcc_mutex 0.1 conda_forge + - libgomp >=7.5.0 + constrains: + - openmp_impl 9999 + license: BSD-3-Clause + license_family: BSD + size: 23621 + timestamp: 1650670423406 +- kind: conda + name: bzip2 + version: 1.0.8 + build: h4bc722e_7 + build_number: 7 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-h4bc722e_7.conda + sha256: 5ced96500d945fb286c9c838e54fa759aa04a7129c59800f0846b4335cee770d + md5: 62ee74e96c5ebb0af99386de58cf9553 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc-ng >=12 + license: bzip2-1.0.6 + license_family: BSD + size: 252783 + timestamp: 1720974456583 +- kind: conda + name: bzip2 + version: 1.0.8 + build: h99b78c6_7 + build_number: 7 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-h99b78c6_7.conda + sha256: adfa71f158cbd872a36394c56c3568e6034aa55c623634b37a4836bd036e6b91 + md5: fc6948412dbbbe9a4c9ddbbcfe0a79ab + depends: + - __osx >=11.0 + license: bzip2-1.0.6 + license_family: BSD + size: 122909 + timestamp: 1720974522888 +- kind: conda + name: ca-certificates + version: 2024.8.30 + build: hbcca054_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2024.8.30-hbcca054_0.conda + sha256: afee721baa6d988e27fef1832f68d6f32ac8cc99cdf6015732224c2841a09cea + md5: c27d1c142233b5bc9ca570c6e2e0c244 + license: ISC + size: 159003 + timestamp: 1725018903918 +- kind: conda + name: ca-certificates + version: 2024.8.30 + build: hf0a4a13_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2024.8.30-hf0a4a13_0.conda + sha256: 2db1733f4b644575dbbdd7994a8f338e6ef937f5ebdb74acd557e9dda0211709 + md5: 40dec13fd8348dbe303e57be74bd3d35 + license: ISC + size: 158482 + timestamp: 1725019034582 +- kind: conda + name: click + version: 8.1.7 + build: unix_pyh707e725_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda + sha256: f0016cbab6ac4138a429e28dbcb904a90305b34b3fe41a9b89d697c90401caec + md5: f3ad426304898027fc619827ff428eca + depends: + - __unix + - python >=3.8 + license: BSD-3-Clause + license_family: BSD + size: 84437 + timestamp: 1692311973840 +- kind: conda + name: importlib-metadata + version: 8.4.0 + build: pyha770c72_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.4.0-pyha770c72_0.conda + sha256: 02c95f6f62675012e0b2ab945eba6fc14fa6a693c17bced3554db7b62d586f0c + md5: 6e3dbc422d3749ad72659243d6ac8b2b + depends: + - python >=3.8 + - zipp >=0.5 + license: Apache-2.0 + license_family: APACHE + size: 28338 + timestamp: 1724187329246 +- kind: conda + name: importlib_metadata + version: 8.4.0 + build: hd8ed1ab_0 + subdir: noarch + noarch: generic + url: https://conda.anaconda.org/conda-forge/noarch/importlib_metadata-8.4.0-hd8ed1ab_0.conda + sha256: c9c782fdf59fb169220b69ea0bbefc3fdc7f58c9fdbdf2d6ff734aa033647b59 + md5: 01b7411c765c3d863dcc920207f258bd + depends: + - importlib-metadata >=8.4.0,<8.4.1.0a0 + license: Apache-2.0 + license_family: APACHE + size: 9292 + timestamp: 1724187331653 +- kind: conda + name: jupyter_client + version: 8.6.2 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/jupyter_client-8.6.2-pyhd8ed1ab_0.conda + sha256: 634f065cdd1d0aacd4bb6848ebf240dcebc8578135d65f4ad4aa42b2276c4e0c + md5: 3cdbb2fa84490e5fd44c9f9806c0d292 + depends: + - importlib_metadata >=4.8.3 + - jupyter_core >=4.12,!=5.0.* + - python >=3.8 + - python-dateutil >=2.8.2 + - pyzmq >=23.0 + - tornado >=6.2 + - traitlets >=5.3 + license: BSD-3-Clause + license_family: BSD + size: 106248 + timestamp: 1716472312833 +- kind: conda + name: jupyter_core + version: 5.7.2 + build: py311h267d04e_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/jupyter_core-5.7.2-py311h267d04e_0.conda + sha256: 0606c9f5a0a9de1e3d8348df4639b7f9dc493a7cf641fd4e9c956af5a33d2b7a + md5: f9e296ff8724469af7117f453824a6de + depends: + - platformdirs >=2.5 + - python >=3.11,<3.12.0a0 + - python >=3.11,<3.12.0a0 *_cpython + - python_abi 3.11.* *_cp311 + - traitlets >=5.3 + license: BSD-3-Clause + license_family: BSD + size: 96069 + timestamp: 1710257757802 +- kind: conda + name: jupyter_core + version: 5.7.2 + build: py311h38be061_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/jupyter_core-5.7.2-py311h38be061_0.conda + sha256: 49834d76e70d6461e19c265296b0f492578f63360d0e4799b06bbe2c0d018a7a + md5: f85e78497dfed6f6a4b865191f42de2e + depends: + - platformdirs >=2.5 + - python >=3.11,<3.12.0a0 + - python_abi 3.11.* *_cp311 + - traitlets >=5.3 + license: BSD-3-Clause + license_family: BSD + size: 95226 + timestamp: 1710257482063 +- kind: conda + name: keyutils + version: 1.6.1 + build: h166bdaf_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.1-h166bdaf_0.tar.bz2 + sha256: 150c05a6e538610ca7c43beb3a40d65c90537497a4f6a5f4d15ec0451b6f5ebb + md5: 30186d27e2c9fa62b45fb1476b7200e3 + depends: + - libgcc-ng >=10.3.0 + license: LGPL-2.1-or-later + size: 117831 + timestamp: 1646151697040 +- kind: conda + name: krb5 + version: 1.21.3 + build: h237132a_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/krb5-1.21.3-h237132a_0.conda + sha256: 4442f957c3c77d69d9da3521268cad5d54c9033f1a73f99cde0a3658937b159b + md5: c6dc8a0fdec13a0565936655c33069a1 + depends: + - __osx >=11.0 + - libcxx >=16 + - libedit >=3.1.20191231,<3.2.0a0 + - libedit >=3.1.20191231,<4.0a0 + - openssl >=3.3.1,<4.0a0 + license: MIT + license_family: MIT + size: 1155530 + timestamp: 1719463474401 +- kind: conda + name: krb5 + version: 1.21.3 + build: h659f571_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/krb5-1.21.3-h659f571_0.conda + sha256: 99df692f7a8a5c27cd14b5fb1374ee55e756631b9c3d659ed3ee60830249b238 + md5: 3f43953b7d3fb3aaa1d0d0723d91e368 + depends: + - keyutils >=1.6.1,<2.0a0 + - libedit >=3.1.20191231,<3.2.0a0 + - libedit >=3.1.20191231,<4.0a0 + - libgcc-ng >=12 + - libstdcxx-ng >=12 + - openssl >=3.3.1,<4.0a0 + license: MIT + license_family: MIT + size: 1370023 + timestamp: 1719463201255 +- kind: conda + name: ld_impl_linux-64 + version: '2.40' + build: hf3520f5_7 + build_number: 7 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.40-hf3520f5_7.conda + sha256: 764b6950aceaaad0c67ef925417594dd14cd2e22fff864aeef455ac259263d15 + md5: b80f2f396ca2c28b8c14c437a4ed1e74 + constrains: + - binutils_impl_linux-64 2.40 + license: GPL-3.0-only + license_family: GPL + size: 707602 + timestamp: 1718625640445 +- kind: conda + name: libblas + version: 3.9.0 + build: 23_linux64_openblas + build_number: 23 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libblas-3.9.0-23_linux64_openblas.conda + sha256: edb1cee5da3ac4936940052dcab6969673ba3874564f90f5110f8c11eed789c2 + md5: 96c8450a40aa2b9733073a9460de972c + depends: + - libopenblas >=0.3.27,<0.3.28.0a0 + - libopenblas >=0.3.27,<1.0a0 + constrains: + - liblapacke 3.9.0 23_linux64_openblas + - libcblas 3.9.0 23_linux64_openblas + - liblapack 3.9.0 23_linux64_openblas + - blas * openblas + license: BSD-3-Clause + license_family: BSD + size: 14880 + timestamp: 1721688759937 +- kind: conda + name: libblas + version: 3.9.0 + build: 23_osxarm64_openblas + build_number: 23 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libblas-3.9.0-23_osxarm64_openblas.conda + sha256: 1c30da861e306a25fac8cd30ce0c1b31c9238d04e7768c381cf4d431b4361e6c + md5: acae9191e8772f5aff48ab5232d4d2a3 + depends: + - libopenblas >=0.3.27,<0.3.28.0a0 + - libopenblas >=0.3.27,<1.0a0 + constrains: + - liblapack 3.9.0 23_osxarm64_openblas + - blas * openblas + - liblapacke 3.9.0 23_osxarm64_openblas + - libcblas 3.9.0 23_osxarm64_openblas + license: BSD-3-Clause + license_family: BSD + size: 15103 + timestamp: 1721688997980 +- kind: conda + name: libcblas + version: 3.9.0 + build: 23_linux64_openblas + build_number: 23 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.9.0-23_linux64_openblas.conda + sha256: 3e7a3236e7e03e308e1667d91d0aa70edd0cba96b4b5563ef4adde088e0881a5 + md5: eede29b40efa878cbe5bdcb767e97310 + depends: + - libblas 3.9.0 23_linux64_openblas + constrains: + - liblapacke 3.9.0 23_linux64_openblas + - liblapack 3.9.0 23_linux64_openblas + - blas * openblas + license: BSD-3-Clause + license_family: BSD + size: 14798 + timestamp: 1721688767584 +- kind: conda + name: libcblas + version: 3.9.0 + build: 23_osxarm64_openblas + build_number: 23 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libcblas-3.9.0-23_osxarm64_openblas.conda + sha256: c39d944909d0608bd0333398be5e0051045c9451bfd6cc6320732d33375569c8 + md5: bad6ee9b7d5584efc2bc5266137b5f0d + depends: + - libblas 3.9.0 23_osxarm64_openblas + constrains: + - liblapack 3.9.0 23_osxarm64_openblas + - liblapacke 3.9.0 23_osxarm64_openblas + - blas * openblas + license: BSD-3-Clause + license_family: BSD + size: 14991 + timestamp: 1721689017803 +- kind: conda + name: libcxx + version: 18.1.8 + build: h3ed4263_7 + build_number: 7 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-18.1.8-h3ed4263_7.conda + sha256: 15b4abaa249f0965ce42aeb4a1a2b1b5df9a1f402e7c5bd8156272fd6cad2878 + md5: e0e7d9a2ec0f9509ffdfd5f48da522fb + depends: + - __osx >=11.0 + license: Apache-2.0 WITH LLVM-exception + license_family: Apache + size: 436921 + timestamp: 1725403628507 +- kind: conda + name: libedit + version: 3.1.20191231 + build: hc8eb9b7_2 + build_number: 2 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libedit-3.1.20191231-hc8eb9b7_2.tar.bz2 + sha256: 3912636197933ecfe4692634119e8644904b41a58f30cad9d1fc02f6ba4d9fca + md5: 30e4362988a2623e9eb34337b83e01f9 + depends: + - ncurses >=6.2,<7.0.0a0 + license: BSD-2-Clause + license_family: BSD + size: 96607 + timestamp: 1597616630749 +- kind: conda + name: libedit + version: 3.1.20191231 + build: he28a2e2_2 + build_number: 2 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20191231-he28a2e2_2.tar.bz2 + sha256: a57d37c236d8f7c886e01656f4949d9dcca131d2a0728609c6f7fa338b65f1cf + md5: 4d331e44109e3f0e19b4cb8f9b82f3e1 + depends: + - libgcc-ng >=7.5.0 + - ncurses >=6.2,<7.0.0a0 + license: BSD-2-Clause + license_family: BSD + size: 123878 + timestamp: 1597616541093 +- kind: conda + name: libexpat + version: 2.6.3 + build: h5888daf_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.6.3-h5888daf_0.conda + sha256: 4bb47bb2cd09898737a5211e2992d63c555d63715a07ba56eae0aff31fb89c22 + md5: 59f4c43bb1b5ef1c71946ff2cbf59524 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=13 + constrains: + - expat 2.6.3.* + license: MIT + license_family: MIT + size: 73616 + timestamp: 1725568742634 +- kind: conda + name: libexpat + version: 2.6.3 + build: hf9b8971_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.6.3-hf9b8971_0.conda + sha256: 5cbe5a199fba14ade55457a468ce663aac0b54832c39aa54470b3889b4c75c4a + md5: 5f22f07c2ab2dea8c66fe9585a062c96 + depends: + - __osx >=11.0 + constrains: + - expat 2.6.3.* + license: MIT + license_family: MIT + size: 63895 + timestamp: 1725568783033 +- kind: conda + name: libffi + version: 3.4.2 + build: h3422bc3_5 + build_number: 5 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libffi-3.4.2-h3422bc3_5.tar.bz2 + sha256: 41b3d13efb775e340e4dba549ab5c029611ea6918703096b2eaa9c015c0750ca + md5: 086914b672be056eb70fd4285b6783b6 + license: MIT + license_family: MIT + size: 39020 + timestamp: 1636488587153 +- kind: conda + name: libffi + version: 3.4.2 + build: h7f98852_5 + build_number: 5 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libffi-3.4.2-h7f98852_5.tar.bz2 + sha256: ab6e9856c21709b7b517e940ae7028ae0737546122f83c2aa5d692860c3b149e + md5: d645c6d2ac96843a2bfaccd2d62b3ac3 + depends: + - libgcc-ng >=9.4.0 + license: MIT + license_family: MIT + size: 58292 + timestamp: 1636488182923 +- kind: conda + name: libgcc + version: 14.1.0 + build: h77fa898_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libgcc-14.1.0-h77fa898_1.conda + sha256: 10fa74b69266a2be7b96db881e18fa62cfa03082b65231e8d652e897c4b335a3 + md5: 002ef4463dd1e2b44a94a4ace468f5d2 + depends: + - _libgcc_mutex 0.1 conda_forge + - _openmp_mutex >=4.5 + constrains: + - libgomp 14.1.0 h77fa898_1 + - libgcc-ng ==14.1.0=*_1 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 846380 + timestamp: 1724801836552 +- kind: conda + name: libgcc-ng + version: 14.1.0 + build: h69a702a_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-14.1.0-h69a702a_1.conda + sha256: b91f7021e14c3d5c840fbf0dc75370d6e1f7c7ff4482220940eaafb9c64613b7 + md5: 1efc0ad219877a73ef977af7dbb51f17 + depends: + - libgcc 14.1.0 h77fa898_1 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 52170 + timestamp: 1724801842101 +- kind: conda + name: libgfortran + version: 5.0.0 + build: 13_2_0_hd922786_3 + build_number: 3 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libgfortran-5.0.0-13_2_0_hd922786_3.conda + sha256: 44e541b4821c96b28b27fef5630883a60ce4fee91fd9c79f25a199f8f73f337b + md5: 4a55d9e169114b2b90d3ec4604cd7bbf + depends: + - libgfortran5 13.2.0 hf226fd6_3 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 110233 + timestamp: 1707330749033 +- kind: conda + name: libgfortran + version: 14.1.0 + build: h69a702a_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-14.1.0-h69a702a_1.conda + sha256: ed77f04f873e43a26e24d443dd090631eedc7d0ace3141baaefd96a123e47535 + md5: 591e631bc1ae62c64f2ab4f66178c097 + depends: + - libgfortran5 14.1.0 hc5f4f2c_1 + constrains: + - libgfortran-ng ==14.1.0=*_1 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 52142 + timestamp: 1724801872472 +- kind: conda + name: libgfortran-ng + version: 14.1.0 + build: h69a702a_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-ng-14.1.0-h69a702a_1.conda + sha256: a2dc35cb7f87bb5beebf102d4085574c6a740e1df58e743185d4434cc5e4e0ae + md5: 16cec94c5992d7f42ae3f9fa8b25df8d + depends: + - libgfortran 14.1.0 h69a702a_1 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 52212 + timestamp: 1724802086021 +- kind: conda + name: libgfortran5 + version: 13.2.0 + build: hf226fd6_3 + build_number: 3 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libgfortran5-13.2.0-hf226fd6_3.conda + sha256: bafc679eedb468a86aa4636061c55966186399ee0a04b605920d208d97ac579a + md5: 66ac81d54e95c534ae488726c1f698ea + depends: + - llvm-openmp >=8.0.0 + constrains: + - libgfortran 5.0.0 13_2_0_*_3 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 997381 + timestamp: 1707330687590 +- kind: conda + name: libgfortran5 + version: 14.1.0 + build: hc5f4f2c_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-14.1.0-hc5f4f2c_1.conda + sha256: c40d7db760296bf9c776de12597d2f379f30e890b9ae70c1de962ff2aa1999f6 + md5: 10a0cef64b784d6ab6da50ebca4e984d + depends: + - libgcc >=14.1.0 + constrains: + - libgfortran 14.1.0 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 1459939 + timestamp: 1724801851300 +- kind: conda + name: libgomp + version: 14.1.0 + build: h77fa898_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libgomp-14.1.0-h77fa898_1.conda + sha256: c96724c8ae4ee61af7674c5d9e5a3fbcf6cd887a40ad5a52c99aa36f1d4f9680 + md5: 23c255b008c4f2ae008f81edcabaca89 + depends: + - _libgcc_mutex 0.1 conda_forge + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 460218 + timestamp: 1724801743478 +- kind: conda + name: liblapack + version: 3.9.0 + build: 23_linux64_openblas + build_number: 23 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.9.0-23_linux64_openblas.conda + sha256: 25c7aef86c8a1d9db0e8ee61aa7462ba3b46b482027a65d66eb83e3e6f949043 + md5: 2af0879961951987e464722fd00ec1e0 + depends: + - libblas 3.9.0 23_linux64_openblas + constrains: + - liblapacke 3.9.0 23_linux64_openblas + - libcblas 3.9.0 23_linux64_openblas + - blas * openblas + license: BSD-3-Clause + license_family: BSD + size: 14823 + timestamp: 1721688775172 +- kind: conda + name: liblapack + version: 3.9.0 + build: 23_osxarm64_openblas + build_number: 23 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/liblapack-3.9.0-23_osxarm64_openblas.conda + sha256: 13799a137ffc80786725e7e2820d37d4c0d59dbb76013a14c21771415b0a4263 + md5: 754ef44f72ab80fd14eaa789ac393a27 + depends: + - libblas 3.9.0 23_osxarm64_openblas + constrains: + - blas * openblas + - liblapacke 3.9.0 23_osxarm64_openblas + - libcblas 3.9.0 23_osxarm64_openblas + license: BSD-3-Clause + license_family: BSD + size: 14999 + timestamp: 1721689026268 +- kind: conda + name: libnsl + version: 2.0.1 + build: hd590300_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libnsl-2.0.1-hd590300_0.conda + sha256: 26d77a3bb4dceeedc2a41bd688564fe71bf2d149fdcf117049970bc02ff1add6 + md5: 30fd6e37fe21f86f4bd26d6ee73eeec7 + depends: + - libgcc-ng >=12 + license: LGPL-2.1-only + license_family: GPL + size: 33408 + timestamp: 1697359010159 +- kind: conda + name: libopenblas + version: 0.3.27 + build: openmp_h517c56d_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libopenblas-0.3.27-openmp_h517c56d_1.conda + sha256: 46cfcc592b5255262f567cd098be3c61da6bca6c24d640e878dc8342b0f6d069 + md5: 71b8a34d70aa567a990162f327e81505 + depends: + - __osx >=11.0 + - libgfortran 5.* + - libgfortran5 >=12.3.0 + - llvm-openmp >=16.0.6 + constrains: + - openblas >=0.3.27,<0.3.28.0a0 + license: BSD-3-Clause + license_family: BSD + size: 2925328 + timestamp: 1720425811743 +- kind: conda + name: libopenblas + version: 0.3.27 + build: pthreads_hac2b453_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.27-pthreads_hac2b453_1.conda + sha256: 714cb82d7c4620ea2635a92d3df263ab841676c9b183d0c01992767bb2451c39 + md5: ae05ece66d3924ac3d48b4aa3fa96cec + depends: + - libgcc-ng >=12 + - libgfortran-ng + - libgfortran5 >=12.3.0 + constrains: + - openblas >=0.3.27,<0.3.28.0a0 + license: BSD-3-Clause + license_family: BSD + size: 5563053 + timestamp: 1720426334043 +- kind: conda + name: libsodium + version: 1.0.20 + build: h4ab18f5_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libsodium-1.0.20-h4ab18f5_0.conda + sha256: 0105bd108f19ea8e6a78d2d994a6d4a8db16d19a41212070d2d1d48a63c34161 + md5: a587892d3c13b6621a6091be690dbca2 + depends: + - libgcc-ng >=12 + license: ISC + size: 205978 + timestamp: 1716828628198 +- kind: conda + name: libsodium + version: 1.0.20 + build: h99b78c6_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libsodium-1.0.20-h99b78c6_0.conda + sha256: fade8223e1e1004367d7101dd17261003b60aa576df6d7802191f8972f7470b1 + md5: a7ce36e284c5faaf93c220dfc39e3abd + depends: + - __osx >=11.0 + license: ISC + size: 164972 + timestamp: 1716828607917 +- kind: conda + name: libsqlite + version: 3.46.1 + build: hadc24fc_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.46.1-hadc24fc_0.conda + sha256: 9851c049abafed3ee329d6c7c2033407e2fc269d33a75c071110ab52300002b0 + md5: 36f79405ab16bf271edb55b213836dac + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=13 + - libzlib >=1.3.1,<2.0a0 + license: Unlicense + size: 865214 + timestamp: 1725353659783 +- kind: conda + name: libsqlite + version: 3.46.1 + build: hc14010f_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libsqlite-3.46.1-hc14010f_0.conda + sha256: 3725f962f490c5d44dae326d5f5b2e3c97f71a6322d914ccc85b5ddc2e50d120 + md5: 58050ec1724e58668d0126a1615553fa + depends: + - __osx >=11.0 + - libzlib >=1.3.1,<2.0a0 + license: Unlicense + size: 829500 + timestamp: 1725353720793 +- kind: conda + name: libstdcxx + version: 14.1.0 + build: hc0a3c3a_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-14.1.0-hc0a3c3a_1.conda + sha256: 44decb3d23abacf1c6dd59f3c152a7101b7ca565b4ef8872804ceaedcc53a9cd + md5: 9dbb9699ea467983ba8a4ba89b08b066 + depends: + - libgcc 14.1.0 h77fa898_1 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 3892781 + timestamp: 1724801863728 +- kind: conda + name: libstdcxx-ng + version: 14.1.0 + build: h4852527_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-14.1.0-h4852527_1.conda + sha256: a2dc44f97290740cc187bfe94ce543e6eb3c2ea8964d99f189a1d8c97b419b8c + md5: bd2598399a70bb86d8218e95548d735e + depends: + - libstdcxx 14.1.0 hc0a3c3a_1 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + size: 52219 + timestamp: 1724801897766 +- kind: conda + name: libuuid + version: 2.38.1 + build: h0b41bf4_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.38.1-h0b41bf4_0.conda + sha256: 787eb542f055a2b3de553614b25f09eefb0a0931b0c87dbcce6efdfd92f04f18 + md5: 40b61aab5c7ba9ff276c41cfffe6b80b + depends: + - libgcc-ng >=12 + license: BSD-3-Clause + license_family: BSD + size: 33601 + timestamp: 1680112270483 +- kind: conda + name: libxcrypt + version: 4.4.36 + build: hd590300_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda + sha256: 6ae68e0b86423ef188196fff6207ed0c8195dd84273cb5623b85aa08033a410c + md5: 5aa797f8787fe7a17d1b0821485b5adc + depends: + - libgcc-ng >=12 + license: LGPL-2.1-or-later + size: 100393 + timestamp: 1702724383534 +- kind: conda + name: libzlib + version: 1.3.1 + build: h4ab18f5_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.1-h4ab18f5_1.conda + sha256: adf6096f98b537a11ae3729eaa642b0811478f0ea0402ca67b5108fe2cb0010d + md5: 57d7dc60e9325e3de37ff8dffd18e814 + depends: + - libgcc-ng >=12 + constrains: + - zlib 1.3.1 *_1 + license: Zlib + license_family: Other + size: 61574 + timestamp: 1716874187109 +- kind: conda + name: libzlib + version: 1.3.1 + build: hfb2fe0b_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/libzlib-1.3.1-hfb2fe0b_1.conda + sha256: c34365dd37b0eab27b9693af32a1f7f284955517c2cc91f1b88a7ef4738ff03e + md5: 636077128927cf79fd933276dc3aed47 + depends: + - __osx >=11.0 + constrains: + - zlib 1.3.1 *_1 + license: Zlib + license_family: Other + size: 46921 + timestamp: 1716874262512 +- kind: conda + name: llvm-openmp + version: 18.1.8 + build: hde57baf_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/llvm-openmp-18.1.8-hde57baf_1.conda + sha256: 7a76e2932ac77e6314bfa1c4ff83f617c8260313bfed1b8401b508ed3e9d70ba + md5: fe89757e3cd14bb1c6ebd68dac591363 + depends: + - __osx >=11.0 + constrains: + - openmp 18.1.8|18.1.8.* + license: Apache-2.0 WITH LLVM-exception + license_family: APACHE + size: 276263 + timestamp: 1723605341828 +- kind: conda + name: max + version: 24.4.0 + build: pyh4616a5c_1 + build_number: 1 + subdir: noarch + noarch: python + url: https://conda.modular.com/max/noarch/max-24.4.0-pyh4616a5c_1.conda + sha256: 63a138f9cbc565f5c956694f0a33abc8e29ae73bc79877f6595652699d3e02f4 + md5: 8eec10780fa4394aeeb2cb0fff090fec + depends: + - max-core >=24.4.0,<24.4.1.0a0 + - max-python >=24.4.0,<24.4.1.0a0 + - mojo-jupyter >=24.4.0,<24.4.1.0a0 + - mblack >=0.2.0dev,<0.2.1dev.0a0 + size: 9537 + timestamp: 1725428495095 +- kind: conda + name: max-core + version: 24.4.0 + build: h60d57d3_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.modular.com/max/osx-arm64/max-core-24.4.0-h60d57d3_1.conda + sha256: d2be41709b408daa69b9494eaf937d69a2ec1c0a6fe9f432ba3b9af99d353f9d + md5: f96261e62768c42a05fdadb9f8ad7e37 + depends: + - mblack >=0.2.0dev,<0.2.1dev.0a0 + arch: arm64 + platform: osx + size: 222155590 + timestamp: 1725398763224 +- kind: conda + name: max-core + version: 24.4.0 + build: hb0f4dca_1 + build_number: 1 + subdir: linux-64 + url: https://conda.modular.com/max/linux-64/max-core-24.4.0-hb0f4dca_1.conda + sha256: 3a738abc9aa82ea5b38da1dcfd0d876a6a96ef33a3665c8239bffe832bcc4059 + md5: 08e880ecc46aa9e289275d8c25352ba1 + depends: + - mblack >=0.2.0dev,<0.2.1dev.0a0 + arch: x86_64 + platform: linux + size: 331860674 + timestamp: 1725398757293 +- kind: conda + name: max-python + version: 24.4.0 + build: py311h0c25911_1 + build_number: 1 + subdir: linux-64 + url: https://conda.modular.com/max/linux-64/max-python-24.4.0-py311h0c25911_1.conda + sha256: 6bccd3c85f4ddc69487c7418286a8fb8d4c8df9409d6aa304caa464f4201afb0 + md5: 9b7d70399fcbc66d083854f15ec205e8 + depends: + - max-core ==24.4.0 hb0f4dca_1 + - python 3.11.* + - numpy >=1.26.0 + - python_abi 3.11.* *_cp311 + arch: x86_64 + platform: linux + size: 283531260 + timestamp: 1725398757298 +- kind: conda + name: max-python + version: 24.4.0 + build: py311h13a3eaa_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.modular.com/max/osx-arm64/max-python-24.4.0-py311h13a3eaa_1.conda + sha256: 1ae0cca9601963cdaf3962999bb7a3fc5941285cb324f8f1858ee7dd065ee5f9 + md5: ab9ca8abade16011405cced3351d3e76 + depends: + - max-core ==24.4.0 h60d57d3_1 + - python 3.11.* + - numpy >=1.26.0 + - python_abi 3.11.* *_cp311 + arch: arm64 + platform: osx + size: 110982929 + timestamp: 1725398763227 +- kind: conda + name: mblack + version: 0.2.dev0 + build: pyh5ed91e1_0 + subdir: noarch + noarch: python + url: https://conda.modular.com/max/noarch/mblack-0.2.dev0-pyh5ed91e1_0.conda + sha256: 69365a192d739981eb9320375474bf70c561d63da44816a33058f7f601298277 + md5: 941acc7303a283900c6faf043e1b1ea5 + depends: + - python >=3.9,<3.12 + - click >=8.0.0 + - mypy_extensions >=0.4.3 + - packaging >=22.0 + - pathspec >=0.9.0 + - platformdirs >=2 + - python + license: MIT + size: 130513 + timestamp: 1725428495097 +- kind: conda + name: mojo-jupyter + version: 24.4.0 + build: pyh5ed91e1_1 + build_number: 1 + subdir: noarch + noarch: python + url: https://conda.modular.com/max/noarch/mojo-jupyter-24.4.0-pyh5ed91e1_1.conda + sha256: 887bc0e36878e8226c99e87b64140fb6434b0a2d08e99265916943c0efc884dc + md5: f10c488ba172cffbec23c9798a1ea014 + depends: + - max-core >=24.4.0,<24.4.1.0a0 + - python >=3.9,<3.12 + - jupyter_client >=8.6.0,<8.7 + - python + size: 21439 + timestamp: 1725428495098 +- kind: conda + name: mypy_extensions + version: 1.0.0 + build: pyha770c72_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda + sha256: f240217476e148e825420c6bc3a0c0efb08c0718b7042fae960400c02af858a3 + md5: 4eccaeba205f0aed9ac3a9ea58568ca3 + depends: + - python >=3.5 + license: MIT + license_family: MIT + size: 10492 + timestamp: 1675543414256 +- kind: conda + name: ncurses + version: '6.5' + build: h7bae524_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.5-h7bae524_1.conda + sha256: 27d0b9ff78ad46e1f3a6c96c479ab44beda5f96def88e2fe626e0a49429d8afc + md5: cb2b0ea909b97b3d70cd3921d1445e1a + depends: + - __osx >=11.0 + license: X11 AND BSD-3-Clause + size: 802321 + timestamp: 1724658775723 +- kind: conda + name: ncurses + version: '6.5' + build: he02047a_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.5-he02047a_1.conda + sha256: 6a1d5d8634c1a07913f1c525db6455918cbc589d745fac46d9d6e30340c8731a + md5: 70caf8bb6cf39a0b6b7efc885f51c0fe + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc-ng >=12 + license: X11 AND BSD-3-Clause + size: 889086 + timestamp: 1724658547447 +- kind: conda + name: numpy + version: 2.1.1 + build: py311h6de8079_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/numpy-2.1.1-py311h6de8079_0.conda + sha256: 4f98d4a19f1917ffa58fed03c0e5aa7a6c8feab0444859c8c3d45585206b0cfc + md5: e424bdd9b324c68fbff3a3b4118f437a + depends: + - __osx >=11.0 + - libblas >=3.9.0,<4.0a0 + - libcblas >=3.9.0,<4.0a0 + - libcxx >=17 + - liblapack >=3.9.0,<4.0a0 + - python >=3.11,<3.12.0a0 + - python >=3.11,<3.12.0a0 *_cpython + - python_abi 3.11.* *_cp311 + constrains: + - numpy-base <0a0 + license: BSD-3-Clause + license_family: BSD + size: 7073664 + timestamp: 1725412362503 +- kind: conda + name: numpy + version: 2.1.1 + build: py311h71ddf71_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/numpy-2.1.1-py311h71ddf71_0.conda + sha256: 46787dedac5fabee2d79d6682af0de9a2d388e765850773cd8bb397a4ad06be8 + md5: da5f27f7c621bd5ed30a4b8b2e022dab + depends: + - __glibc >=2.17,<3.0.a0 + - libblas >=3.9.0,<4.0a0 + - libcblas >=3.9.0,<4.0a0 + - libgcc >=13 + - liblapack >=3.9.0,<4.0a0 + - libstdcxx >=13 + - python >=3.11,<3.12.0a0 + - python_abi 3.11.* *_cp311 + constrains: + - numpy-base <0a0 + license: BSD-3-Clause + license_family: BSD + size: 9093402 + timestamp: 1725412393388 +- kind: conda + name: openssl + version: 3.3.2 + build: h8359307_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/openssl-3.3.2-h8359307_0.conda + sha256: 940fa01c4dc6152158fe8943e05e55a1544cab639df0994e3b35937839e4f4d1 + md5: 1773ebccdc13ec603356e8ff1db9e958 + depends: + - __osx >=11.0 + - ca-certificates + license: Apache-2.0 + license_family: Apache + size: 2882450 + timestamp: 1725410638874 +- kind: conda + name: openssl + version: 3.3.2 + build: hb9d3cd8_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/openssl-3.3.2-hb9d3cd8_0.conda + sha256: cee91036686419f6dd6086902acf7142b4916e1c4ba042e9ca23e151da012b6d + md5: 4d638782050ab6faa27275bed57e9b4e + depends: + - __glibc >=2.17,<3.0.a0 + - ca-certificates + - libgcc >=13 + license: Apache-2.0 + license_family: Apache + size: 2891789 + timestamp: 1725410790053 +- kind: conda + name: packaging + version: '24.1' + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/packaging-24.1-pyhd8ed1ab_0.conda + sha256: 36aca948219e2c9fdd6d80728bcc657519e02f06c2703d8db3446aec67f51d81 + md5: cbe1bb1f21567018ce595d9c2be0f0db + depends: + - python >=3.8 + license: Apache-2.0 + license_family: APACHE + size: 50290 + timestamp: 1718189540074 +- kind: conda + name: pathspec + version: 0.12.1 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda + sha256: 4e534e66bfe8b1e035d2169d0e5b185450546b17e36764272863e22e0370be4d + md5: 17064acba08d3686f1135b5ec1b32b12 + depends: + - python >=3.7 + license: MPL-2.0 + license_family: MOZILLA + size: 41173 + timestamp: 1702250135032 +- kind: conda + name: platformdirs + version: 4.3.2 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.2-pyhd8ed1ab_0.conda + sha256: 3aef5bb863a2db94e47272fd5ec5a5e4b240eafba79ebb9df7a162797cf035a3 + md5: e1a2dfcd5695f0744f1bcd3bbfe02523 + depends: + - python >=3.8 + license: MIT + size: 20623 + timestamp: 1725821846879 +- kind: conda + name: python + version: 3.11.9 + build: h932a869_0_cpython + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.11.9-h932a869_0_cpython.conda + sha256: a436ceabde1f056a0ac3e347dadc780ee2a135a421ddb6e9a469370769829e3c + md5: 293e0713ae804b5527a673e7605c04fc + depends: + - __osx >=11.0 + - bzip2 >=1.0.8,<2.0a0 + - libexpat >=2.6.2,<3.0a0 + - libffi >=3.4,<4.0a0 + - libsqlite >=3.45.3,<4.0a0 + - libzlib >=1.2.13,<2.0.0a0 + - ncurses >=6.4.20240210,<7.0a0 + - openssl >=3.2.1,<4.0a0 + - readline >=8.2,<9.0a0 + - tk >=8.6.13,<8.7.0a0 + - tzdata + - xz >=5.2.6,<6.0a0 + constrains: + - python_abi 3.11.* *_cp311 + license: Python-2.0 + size: 14644189 + timestamp: 1713552154779 +- kind: conda + name: python + version: 3.11.9 + build: hb806964_0_cpython + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/python-3.11.9-hb806964_0_cpython.conda + sha256: 177f33a1fb8d3476b38f73c37b42f01c0b014fa0e039a701fd9f83d83aae6d40 + md5: ac68acfa8b558ed406c75e98d3428d7b + depends: + - bzip2 >=1.0.8,<2.0a0 + - ld_impl_linux-64 >=2.36.1 + - libexpat >=2.6.2,<3.0a0 + - libffi >=3.4,<4.0a0 + - libgcc-ng >=12 + - libnsl >=2.0.1,<2.1.0a0 + - libsqlite >=3.45.3,<4.0a0 + - libuuid >=2.38.1,<3.0a0 + - libxcrypt >=4.4.36 + - libzlib >=1.2.13,<2.0.0a0 + - ncurses >=6.4.20240210,<7.0a0 + - openssl >=3.2.1,<4.0a0 + - readline >=8.2,<9.0a0 + - tk >=8.6.13,<8.7.0a0 + - tzdata + - xz >=5.2.6,<6.0a0 + constrains: + - python_abi 3.11.* *_cp311 + license: Python-2.0 + size: 30884494 + timestamp: 1713553104915 +- kind: conda + name: python-dateutil + version: 2.9.0 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0-pyhd8ed1ab_0.conda + sha256: f3ceef02ac164a8d3a080d0d32f8e2ebe10dd29e3a685d240e38b3599e146320 + md5: 2cf4264fffb9e6eff6031c5b6884d61c + depends: + - python >=3.7 + - six >=1.5 + license: Apache-2.0 + license_family: APACHE + size: 222742 + timestamp: 1709299922152 +- kind: conda + name: python_abi + version: '3.11' + build: 5_cp311 + build_number: 5 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.11-5_cp311.conda + sha256: 2660b8059b3ee854bc5d3c6b1fce946e5bd2fe8fbca7827de2c5885ead6209de + md5: 139a8d40c8a2f430df31048949e450de + constrains: + - python 3.11.* *_cpython + license: BSD-3-Clause + license_family: BSD + size: 6211 + timestamp: 1723823324668 +- kind: conda + name: python_abi + version: '3.11' + build: 5_cp311 + build_number: 5 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.11-5_cp311.conda + sha256: adc05729b7e0aca7b436e60a86f10822a92185dfcb48d66d6444e3629d3a1f6a + md5: 3b855e3734344134cb56c410f729c340 + constrains: + - python 3.11.* *_cpython + license: BSD-3-Clause + license_family: BSD + size: 6308 + timestamp: 1723823096865 +- kind: conda + name: pyzmq + version: 26.2.0 + build: py311h137d824_2 + build_number: 2 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/pyzmq-26.2.0-py311h137d824_2.conda + sha256: 4120b8d7d2af1032d6fbaa7755bd1c61bac698a3230007bf1d081c9d855bdbce + md5: 02cc2681fe81c2e7a7f37d8953fed1ef + depends: + - __osx >=11.0 + - libcxx >=17 + - libsodium >=1.0.20,<1.0.21.0a0 + - python >=3.11,<3.12.0a0 + - python >=3.11,<3.12.0a0 *_cpython + - python_abi 3.11.* *_cp311 + - zeromq >=4.3.5,<4.4.0a0 + license: BSD-3-Clause + license_family: BSD + size: 365169 + timestamp: 1725449249789 +- kind: conda + name: pyzmq + version: 26.2.0 + build: py311h7deb3e3_2 + build_number: 2 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/pyzmq-26.2.0-py311h7deb3e3_2.conda + sha256: fecb5b336ef6abb67e4a06f81b329fff85d8f05c27d819de97033d64b549ecb1 + md5: 5d3fc8b5c5765e1f207c53554a713907 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=13 + - libsodium >=1.0.20,<1.0.21.0a0 + - libstdcxx >=13 + - python >=3.11,<3.12.0a0 + - python_abi 3.11.* *_cp311 + - zeromq >=4.3.5,<4.4.0a0 + license: BSD-3-Clause + license_family: BSD + size: 387556 + timestamp: 1725449077083 +- kind: conda + name: readline + version: '8.2' + build: h8228510_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8228510_1.conda + sha256: 5435cf39d039387fbdc977b0a762357ea909a7694d9528ab40f005e9208744d7 + md5: 47d31b792659ce70f470b5c82fdfb7a4 + depends: + - libgcc-ng >=12 + - ncurses >=6.3,<7.0a0 + license: GPL-3.0-only + license_family: GPL + size: 281456 + timestamp: 1679532220005 +- kind: conda + name: readline + version: '8.2' + build: h92ec313_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda + sha256: a1dfa679ac3f6007362386576a704ad2d0d7a02e98f5d0b115f207a2da63e884 + md5: 8cbb776a2f641b943d413b3e19df71f4 + depends: + - ncurses >=6.3,<7.0a0 + license: GPL-3.0-only + license_family: GPL + size: 250351 + timestamp: 1679532511311 +- kind: conda + name: six + version: 1.16.0 + build: pyh6c4a22f_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2 + sha256: a85c38227b446f42c5b90d9b642f2c0567880c15d72492d8da074a59c8f91dd6 + md5: e5f25f8dbc060e9a8d912e432202afc2 + depends: + - python + license: MIT + license_family: MIT + size: 14259 + timestamp: 1620240338595 +- kind: conda + name: tk + version: 8.6.13 + build: h5083fa2_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda + sha256: 72457ad031b4c048e5891f3f6cb27a53cb479db68a52d965f796910e71a403a8 + md5: b50a57ba89c32b62428b71a875291c9b + depends: + - libzlib >=1.2.13,<2.0.0a0 + license: TCL + license_family: BSD + size: 3145523 + timestamp: 1699202432999 +- kind: conda + name: tk + version: 8.6.13 + build: noxft_h4845f30_101 + build_number: 101 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda + sha256: e0569c9caa68bf476bead1bed3d79650bb080b532c64a4af7d8ca286c08dea4e + md5: d453b98d9c83e71da0741bb0ff4d76bc + depends: + - libgcc-ng >=12 + - libzlib >=1.2.13,<2.0.0a0 + license: TCL + license_family: BSD + size: 3318875 + timestamp: 1699202167581 +- kind: conda + name: tornado + version: 6.4.1 + build: py311h460d6c5_1 + build_number: 1 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/tornado-6.4.1-py311h460d6c5_1.conda + sha256: bba4940ef7522c3b4ae6eacd296e5e110de3659f7e4c3654d4fc2bb213c2091c + md5: 8ba6d177509dc4fac7af09749556eed0 + depends: + - __osx >=11.0 + - python >=3.11,<3.12.0a0 + - python >=3.11,<3.12.0a0 *_cpython + - python_abi 3.11.* *_cp311 + license: Apache-2.0 + license_family: Apache + size: 859139 + timestamp: 1724956356600 +- kind: conda + name: tornado + version: 6.4.1 + build: py311h9ecbd09_1 + build_number: 1 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/tornado-6.4.1-py311h9ecbd09_1.conda + sha256: 21390d0c5708581959ebd89702433c1d06a56ddd834797a194b217f98e38df53 + md5: 616fed0b6f5c925250be779b05d1d7f7 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=13 + - python >=3.11,<3.12.0a0 + - python_abi 3.11.* *_cp311 + license: Apache-2.0 + license_family: Apache + size: 856725 + timestamp: 1724956239832 +- kind: conda + name: traitlets + version: 5.14.3 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda + sha256: 8a64fa0f19022828513667c2c7176cfd125001f3f4b9bc00d33732e627dd2592 + md5: 3df84416a021220d8b5700c613af2dc5 + depends: + - python >=3.8 + license: BSD-3-Clause + license_family: BSD + size: 110187 + timestamp: 1713535244513 +- kind: conda + name: tzdata + version: 2024a + build: h8827d51_1 + build_number: 1 + subdir: noarch + noarch: generic + url: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024a-h8827d51_1.conda + sha256: 7d21c95f61319dba9209ca17d1935e6128af4235a67ee4e57a00908a1450081e + md5: 8bfdead4e0fff0383ae4c9c50d0531bd + license: LicenseRef-Public-Domain + size: 124164 + timestamp: 1724736371498 +- kind: conda + name: xz + version: 5.2.6 + build: h166bdaf_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/xz-5.2.6-h166bdaf_0.tar.bz2 + sha256: 03a6d28ded42af8a347345f82f3eebdd6807a08526d47899a42d62d319609162 + md5: 2161070d867d1b1204ea749c8eec4ef0 + depends: + - libgcc-ng >=12 + license: LGPL-2.1 and GPL-2.0 + size: 418368 + timestamp: 1660346797927 +- kind: conda + name: xz + version: 5.2.6 + build: h57fd34a_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/xz-5.2.6-h57fd34a_0.tar.bz2 + sha256: 59d78af0c3e071021cfe82dc40134c19dab8cdf804324b62940f5c8cd71803ec + md5: 39c6b54e94014701dd157f4f576ed211 + license: LGPL-2.1 and GPL-2.0 + size: 235693 + timestamp: 1660346961024 +- kind: conda + name: zeromq + version: 4.3.5 + build: h64debc3_5 + build_number: 5 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/zeromq-4.3.5-h64debc3_5.conda + sha256: b4ba544a04129472651a5df3b8906ed68e7f43bf23e724fd0e368218083c920c + md5: c29dbe9343a0b55b027fa645644c59d9 + depends: + - __osx >=11.0 + - krb5 >=1.21.3,<1.22.0a0 + - libcxx >=17 + - libsodium >=1.0.20,<1.0.21.0a0 + license: MPL-2.0 + license_family: MOZILLA + size: 296355 + timestamp: 1725430145243 +- kind: conda + name: zeromq + version: 4.3.5 + build: ha4adb4c_5 + build_number: 5 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/zeromq-4.3.5-ha4adb4c_5.conda + sha256: dd48adc07fcd029c86fbf82e68d0e4818c7744b768e08139379920b56b582814 + md5: e8372041ebb377237db9d0d24c7b5962 + depends: + - __glibc >=2.17,<3.0.a0 + - krb5 >=1.21.3,<1.22.0a0 + - libgcc >=13 + - libsodium >=1.0.20,<1.0.21.0a0 + - libstdcxx >=13 + license: MPL-2.0 + license_family: MOZILLA + size: 353159 + timestamp: 1725429777124 +- kind: conda + name: zipp + version: 3.20.1 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/zipp-3.20.1-pyhd8ed1ab_0.conda + sha256: 30762bd25b6fc8714d5520a223ccf20ad4a6792dc439c54b59bf44b60bf51e72 + md5: 74a4befb4b38897e19a107693e49da20 + depends: + - python >=3.8 + license: MIT + license_family: MIT + size: 21110 + timestamp: 1724731063145 diff --git a/mojoproject.toml b/mojoproject.toml new file mode 100644 index 0000000..9ba8bcc --- /dev/null +++ b/mojoproject.toml @@ -0,0 +1,24 @@ +[project] +name = "NuMojo" +version = "0.2.0" +description = "NuMojo is a library for numerical computing written in Mojo 🔥" +authors = [ + "Shivasankar ", + "MadAlex1997 <>", + "Yuhao Zhu <>", + "mmenendezg <>", + "sandstromviktor <>", +] +channels = ["conda-forge", "https://conda.modular.com/max"] +platforms = ["osx-arm64", "linux-64"] +license = "Apache-2.0" + +[tasks] +# test whether tests pass and the package can be built +test = " magic run mojo test tests -I ./ && magic run mojo package numojo" +package = "magic run mojo package numojo" +# runs all final checks before a commit +final = "magic run mojo test tests -I ./ && magic run mojo format ./ && magic run mojo package numojo" + +[dependencies] +max = ">=24.4.0,<25" From 66f53be14676f96fd0646b551b1d7c27d20289ea Mon Sep 17 00:00:00 2001 From: shivasankar Date: Tue, 10 Sep 2024 01:07:23 +0900 Subject: [PATCH 29/32] added more tasks to .toml --- .gitignore | 11 ++++++++-- mojoproject.toml | 4 +++- test.mojo | 55 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 0c3e5d4..3b12b24 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,14 @@ *.py mojo numojo.mojopkg -.gitignore bench.mojo test_ndarray.ipynb -/venv \ No newline at end of file +/venv# pixi environments +.pixi +*.egg-info + +# magic environments +.magic + +.gitattributes +.gitignore diff --git a/mojoproject.toml b/mojoproject.toml index 9ba8bcc..e7bc3ba 100644 --- a/mojoproject.toml +++ b/mojoproject.toml @@ -16,9 +16,11 @@ license = "Apache-2.0" [tasks] # test whether tests pass and the package can be built test = " magic run mojo test tests -I ./ && magic run mojo package numojo" -package = "magic run mojo package numojo" # runs all final checks before a commit final = "magic run mojo test tests -I ./ && magic run mojo format ./ && magic run mojo package numojo" +# defaults tasks +package = "magic run mojo package numojo" +format = "magic run mojo format ./" [dependencies] max = ">=24.4.0,<25" diff --git a/test.mojo b/test.mojo index 4c8cc7b..8216906 100644 --- a/test.mojo +++ b/test.mojo @@ -4,6 +4,7 @@ from benchmark.compiler import keep from python import Python # from random import seed +from random.random import randint, random_float64 import numojo as nm from numojo import * @@ -89,24 +90,25 @@ fn test_constructors2() raises: fn test_random() raises: - # var arr_variadic = nm.core.random.rand( - # shape=List[Int](10, 10, 10), min=1.0, max=2.0 - # ) - # print(arr_variadic) - # var random_array_var = nm.core.random.randn[i16](3, 2, mean=0, variance=5) - # print(random_array_var) - # var random_array_list = nm.core.random.randn[i16]( - # List[Int](3, 2), mean=0, variance=1 - # ) - # print(random_array_list) - - # var random_array_var1 = nm.core.random.rand[i16](3, 2, min=0, max=100) - # print(random_array_var1) + var arr_variadic = nm.core.random.rand( + shape=List[Int](10, 10, 10), min=1.0, max=2.0 + ) + print(arr_variadic) + var random_array_var = nm.core.random.randn[i16](3, 2, mean=0, variance=5) + print(random_array_var) + var random_array_list = nm.core.random.randn[i16]( + List[Int](3, 2), mean=0, variance=1 + ) + print(random_array_list) + + var random_array_var1 = nm.core.random.rand[f16](3, 2, min=0, max=100) + print(random_array_var1) var random_array_list1 = nm.core.random.rand[i32]( List[Int](3, 2), min=0, max=100 ) print(random_array_list1) + fn test_arr_manipulation() raises: var np = Python.import_module("numpy") var A = np.arange(12) @@ -250,6 +252,33 @@ fn test_slicing() raises: print(slicedy) +fn test_rand_funcs[ + dtype: DType = DType.float64 +](shape: List[Int], min: Scalar[dtype], max: Scalar[dtype]) raises -> NDArray[ + dtype +]: + var result: NDArray[dtype] = NDArray[dtype](shape) + if dtype.is_integral(): + random.randint[dtype]( + ptr=result.data, + size=result.ndshape.ndsize, + low=int(min), + high=int(max), + ) + elif dtype.is_floating_point(): + for i in range(result.ndshape.ndsize): + var temp: Scalar[dtype] = random.random_float64( + min.cast[f64](), max.cast[f64]() + ).cast[dtype]() + result.__setitem__(i, temp) + else: + raise Error( + "Invalid type provided. dtype must be either an integral or" + " floating-point type." + ) + return result + + fn main() raises: # test_constructors1() # test_constructors2() From 9f183f97639b903abd7c0deeae7f4be22f781865 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Tue, 10 Sep 2024 01:22:46 +0900 Subject: [PATCH 30/32] fixed docstring error in ndarray --- numojo/core/ndarray.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 97e07f0..58d5a47 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -923,7 +923,7 @@ struct NDArray[dtype: DType = DType.float64]( before it is passed into the function. Example: - ```mojo + ``` import numojo as nm fn main() raises: From 061ce03fc42b767b535e90fd9f3f645ba977b46b Mon Sep 17 00:00:00 2001 From: shivasankar Date: Tue, 10 Sep 2024 02:00:22 +0900 Subject: [PATCH 31/32] fixed linting error, added readme to .toml --- mojoproject.toml | 1 + numojo/core/ndarray.mojo | 10 ++++++---- tests/test_math.mojo | 7 +++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mojoproject.toml b/mojoproject.toml index e7bc3ba..96b767b 100644 --- a/mojoproject.toml +++ b/mojoproject.toml @@ -12,6 +12,7 @@ authors = [ channels = ["conda-forge", "https://conda.modular.com/max"] platforms = ["osx-arm64", "linux-64"] license = "Apache-2.0" +readme = "README.md" [tasks] # test whether tests pass and the package can be built diff --git a/numojo/core/ndarray.mojo b/numojo/core/ndarray.mojo index 0fe6602..50876b4 100644 --- a/numojo/core/ndarray.mojo +++ b/numojo/core/ndarray.mojo @@ -2746,8 +2746,9 @@ struct NDArray[dtype: DType = DType.float64]( raise Error("Error: Elements of `index` exceed the array shape") return self.data.load[width=1](_get_index(index, self.stride)) - - fn itemset(inout self, index: Variant[Int, List[Int]], item: Scalar[dtype]) raises: + fn itemset( + inout self, index: Variant[Int, List[Int]], item: Scalar[dtype] + ) raises: """Set the scalar at the coordinates. Args: @@ -2820,10 +2821,11 @@ struct NDArray[dtype: DType = DType.float64]( raise Error("Error: Length of Indices do not match the shape") for i in range(indices.__len__()): if indices[i] >= self.ndshape[i]: - raise Error("Error: Elements of `index` exceed the array shape") + raise Error( + "Error: Elements of `index` exceed the array shape" + ) self.data.store[width=1](_get_index(indices, self.stride), item) - fn max(self, axis: Int = 0) raises -> Self: """ Max on axis. diff --git a/tests/test_math.mojo b/tests/test_math.mojo index a750a2e..9b89421 100644 --- a/tests/test_math.mojo +++ b/tests/test_math.mojo @@ -89,12 +89,11 @@ def test_inverse_2(): nm.math.linalg.inverse(arr), np.linalg.inv(np_arr), "Inverse is broken" ) + def test_setitem(): var np = Python.import_module("numpy") var arr = nm.NDArray(4, 4) var np_arr = arr.to_numpy() - arr.itemset(List(2,2), 1000) + arr.itemset(List(2, 2), 1000) np_arr[(2, 2)] = 1000 - check_is_close( - arr, np_arr, "Itemset is broken" - ) \ No newline at end of file + check_is_close(arr, np_arr, "Itemset is broken") From 4d4583ecf7f603aa474d80ae9e007507c772ccb4 Mon Sep 17 00:00:00 2001 From: shivasankar Date: Tue, 10 Sep 2024 02:20:29 +0900 Subject: [PATCH 32/32] added instructions for final check in contributing --- CONTRIBUTING.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ab2f63f..5e16c5d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,16 +50,20 @@ Following this structure ensures that similar functionalities are grouped togeth ``` 4. **Make Your Changes**: Implement your changes in your branch. -5. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message. +5. **Run Tests**: NuMojo now uses the `Magic` package manager by Modular. To ensure that all unit tests pass, the NuMojo module packages correctly, and the .mojo files are properly formatted, run the following command: + ```sh + magic run final + ``` +6. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message. ```sh git commit -m "Add feature XYZ" ``` -6. **Push Your Changes**: Push your branch to your fork on GitHub. +7. **Push Your Changes**: Push your branch to your fork on GitHub. ```sh git push origin feature-name ``` -7. **Submit a Pull Request**: Open a pull request to the `main` branch of the original repository. +8. **Submit a Pull Request**: Open a pull request to the `main` branch of the original repository.