Skip to content

Conversation

@shivasankarka
Copy link
Collaborator

@shivasankarka shivasankarka commented Apr 15, 2025

Summary

Previously, the distinction between NDArray and ComplexNDArray was partially encoded through the use of DType and CDType. This PR simplifies the type system by removing the custom CDType datatype and replacing it with the standard DType. The use of CDType introduced issues with Mojo's compile-time type conversions, resulting in suboptimal user ergonomics and problems when converting between datatypes. To address this, we are standardizing on DType moving forward.


New Syntax Proposal

To clearly differentiate between functions that create or manipulate standard and complex arrays, we introduce a simple naming convention: append a C suffix to functions returning complex arrays since Mojo does not support function overloading based on return type. The following is one such example,

fn ones[dtype: DType = DType.float64](shape: NDArrayShape) raises -> NDArray[dtype]
    pass

fn onesC[dtype: DType = DType.float64](shape: NDArrayShape) raises -> ComplexNDArray[dtype]
    pass

This approach keeps the API intuitive, avoids return-type ambiguity, and aligns better with Mojo's type system and simplifies a lot of type conversions.

@shivasankarka shivasankarka requested a review from Copilot April 15, 2025 09:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 14 changed files in this pull request and generated no comments.

Files not reviewed (10)
  • numojo/init.mojo: Language not supported
  • numojo/core/init.mojo: Language not supported
  • numojo/core/complex/init.mojo: Language not supported
  • numojo/core/complex/complex_simd.mojo: Language not supported
  • numojo/core/datatypes.mojo: Language not supported
  • numojo/core/matrix.mojo: Language not supported
  • numojo/prelude.mojo: Language not supported
  • numojo/routines/io/formatting.mojo: Language not supported
  • tests/core/test_complexArray.mojo: Language not supported
  • tests/core/test_complexSIMD.mojo: Language not supported

@forfudan
Copy link
Collaborator

@shivasankarka It is absolutely a good move. ComplexDType is not very necessary since the real and imaginary parts can be decomposed into two DTypes, and the operations on complex arrays can be decomposed into operations on normal arrays.

Another nice thing is that we do not need to worry about the license anymore. Maybe we can remove the following paragraph from the readme file.

This project includes code from Mojo Standard Library, licensed under the Apache License v2.0 with LLVM Exceptions (see the LLVM License). MAX and Mojo usage and distribution are licensed under the MAX & Mojo Community License.

@MadAlex1997 MadAlex1997 merged commit 030f370 into Mojo-Numerics-and-Algorithms-group:pre-0.7 Apr 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants