Skip to content

Commit c8d9b63

Browse files
[core][NDArray] Temporarily suspending Type Coercions (#242)
This PR comments out all the Type Coercions for the data types that currently implemented. This is done for the following two reasons, - The current Mojo compiler isn't able to parse and calculate the resulting data type at compile time correctly yet. - The resulting generic data type is very confusing to work with for end users currently and requires weird code shenanigans to work around it. Therefore these will be temporarily commented out. We will get back to improving it and adding it back in later version of NuMojo once Mojo type system is mature enough for us to implement these data type conversions at compile time.
1 parent c289756 commit c8d9b63

File tree

7 files changed

+1647
-1369
lines changed

7 files changed

+1647
-1369
lines changed

numojo/core/complex/complex_ndarray.mojo

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ from sys import simdwidthof
4646
from utils import Variant
4747

4848
from numojo.core.complex.complex_simd import ComplexSIMD
49-
from numojo.core.datatypes import TypeCoercion, _concise_dtype_str
49+
from numojo.core.datatypes import _concise_dtype_str
5050
from numojo.core.flags import Flags
5151
from numojo.core.item import Item
5252
from numojo.core.ndshape import NDArrayShape
@@ -113,12 +113,26 @@ struct ComplexNDArray[dtype: DType = DType.float64](
113113
var flags: Flags
114114
"Information about the memory layout of the array."
115115

116-
"""LIFETIME METHODS"""
116+
# ===-------------------------------------------------------------------===#
117+
# Life cycle methods
118+
# ===-------------------------------------------------------------------===#
117119

118120
@always_inline("nodebug")
119121
fn __init__(
120122
out self, owned re: NDArray[Self.dtype], owned im: NDArray[Self.dtype]
121-
):
123+
) raises:
124+
"""
125+
Initialize a ComplexNDArray with given real and imaginary parts.
126+
127+
Args:
128+
re: Real part of the complex array.
129+
im: Imaginary part of the complex array.
130+
"""
131+
if re.shape != im.shape:
132+
raise Error(
133+
"Error in `numojo.ComplexNDArray.__init__()`: "
134+
"Real and imaginary parts must have the same shape."
135+
)
122136
self._re = re
123137
self._im = im
124138
self.ndim = re.ndim
@@ -245,7 +259,7 @@ struct ComplexNDArray[dtype: DType = DType.float64](
245259
self._im = NDArray[Self.dtype](shape, strides, ndim, size, flags)
246260

247261
fn __init__(
248-
mut self,
262+
out self,
249263
shape: NDArrayShape,
250264
ref buffer_re: UnsafePointer[Scalar[Self.dtype]],
251265
ref buffer_im: UnsafePointer[Scalar[Self.dtype]],
@@ -320,9 +334,9 @@ struct ComplexNDArray[dtype: DType = DType.float64](
320334
# Getter dunders and other getter methods
321335
#
322336
# 1. Basic Indexing Operations
323-
# fn _getitem(self, *indices: Int) -> Scalar[dtype] # Direct unsafe getter
324-
# fn __getitem__(self) raises -> SIMD[dtype, 1] # Get 0d array value
325-
# fn __getitem__(self, index: Item) raises -> SIMD[dtype, 1] # Get by coordinate list
337+
# fn _getitem(self, *indices: Int) -> ComplexSIMD[Self.dtype] # Direct unsafe getter
338+
# fn __getitem__(self) raises -> ComplexSIMD[Self.dtype] # Get 0d array value
339+
# fn __getitem__(self, index: Item) raises -> ComplexSIMD[Self.dtype] # Get by coordinate list
326340
#
327341
# 2. Single Index Slicing
328342
# fn __getitem__(self, idx: Int) raises -> Self # Get by single index
@@ -339,11 +353,11 @@ struct ComplexNDArray[dtype: DType = DType.float64](
339353
# fn __getitem__(self, mask: List[Bool]) raises -> Self # Get by boolean list
340354
#
341355
# 5. Low-level Access
342-
# fn item(self, owned index: Int) raises -> Scalar[dtype] # Get item by linear index
343-
# fn item(self, *index: Int) raises -> Scalar[dtype] # Get item by coordinates
344-
# fn load(self, owned index: Int) raises -> Scalar[dtype] # Load with bounds check
345-
# fn load[width: Int](self, index: Int) raises -> SIMD[dtype, width] # Load SIMD value
346-
# fn load[width: Int](self, *indices: Int) raises -> SIMD[dtype, width] # Load SIMD at coordinates
356+
# fn item(self, owned index: Int) raises -> ComplexSIMD[Self.dtype] # Get item by linear index
357+
# fn item(self, *index: Int) raises -> ComplexSIMD[Self.dtype] # Get item by coordinates
358+
# fn load(self, owned index: Int) raises -> ComplexSIMD[Self.dtype] # Load with bounds check
359+
# fn load[width: Int](self, index: Int) raises -> ComplexSIMD[Self.dtype, width] # Load SIMD value
360+
# fn load[width: Int](self, *indices: Int) raises -> ComplexSIMD[Self.dtype, width] # Load SIMD at coordinates
347361
# ===-------------------------------------------------------------------===#
348362

349363
fn _getitem(self, *indices: Int) -> ComplexSIMD[Self.dtype]:

0 commit comments

Comments
 (0)