forked from Mojo-Numerics-and-Algorithms-group/NuMojo
-
Notifications
You must be signed in to change notification settings - Fork 0
[core] Improve Item #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
merging changes from prev0.8
to return Matrix[RefData]
…ithms-group#281) This PR implements the first two steps as discussed in Mojo-Numerics-and-Algorithms-group#279 to ensure minimal damage in code while migrating. --------- Co-authored-by: ZHU Yuhao 朱宇浩 <[email protected]>
arithmetic dunder methods for views and original instances.
enable operations with views
merging changes from upstream pre0.8 to improve getter
…up#280) This PR lays the groundwork for returning views in both the Matrix and NDArray types. It also implements full support for Matrix views. The design for returning view is described in the NuMojo enhancement proposal Mojo-Numerics-and-Algorithms-group#279 Support for NDArray views will be completed in a subsequent PR. Currently test workflow is commented out. Since Mojo has removed the `test` command, we will use the `TestSuite` to run tests hereafter. The tests will be fixed in the follow up PR. --------- Co-authored-by: ZHU Yuhao 朱宇浩 <[email protected]>
…-and-Algorithms-group#286) For more details on the new Matrix view model, refer to Mojo-Numerics-and-Algorithms-group#279 where I have explained the updated (2025/11/22) model as of Mojo 25.7 --------- Co-authored-by: ZHU Yuhao 朱宇浩 <[email protected]>
…orithms-group#287) This PR improves the docstrings in `matrix.mojo` by adding clear explanations for all variables, methods and adding examples. It also standardizes the format of the docstring. --------- Co-authored-by: ZHU Yuhao 朱宇浩 <[email protected]>
merging changes from docs branch
merge changes from upstream/pre-0.8
…lgorithms-group#290) This PR expands complex-datatype support, improves ComplexSIMD and ComplexNDArray usability, introduces new convenience APIs, and enhances documentation across the complex-number ecosystem. ## Added ### ComplexDType & DType System * Support for additional complex dtypes (`ComplexDType.int16`, `ComplexDType.int32`). ### ComplexSIMD * Added `component_bitwidth()` to distinguish SIMD bitwidth from the bitwidth of its `real` and `imag` components. * Added arithmetic operator overloads for more complete ComplexSIMD math support. * Added `elem_pow` for per-component exponentiation (distinct from `__pow__`). * Added `all_close()` for comparing real and imaginary components across two ComplexSIMD instances. * Added broadcasting support for scalar complex values, simplifying scalar construction: ```mojo var a = CScalar(1.0) # 1.0 + 1.0j var b = ComplexSIMD[f32, 2](1.0) # [1.0, 1.0] + [1.0, 1.0]j ``` * Added convenience constructors: * `ComplexSIMD[cf64].zero()` * `ComplexSIMD[cf64].one()` * `ComplexSIMD[cf64].I()` * `ComplexSIMD[cf64].from_polar(2.0, 0.5)` ### ComplexNDArray * Expanded and clarified documentation for all `ComplexNDArray` methods. ### Python-like Complex Literal * Introduce a `ImaginaryUnit` type and the alias ``1j`` to enable natural, Pythonic complex number creation in NuMojo. Previously, creating complex numbers required explicit constructor calls which were pretty long, but now users can write mathematical expressions using familiar notation. The `1j` constant automatically adapts to match operand types and SIMD widths. It also has full support for all operations between `1j` and scalars, SIMD vectors, and other complex numbers. It is by default of type ComplexDType.float64. ```mojo from numojo import `1j` # Scalar complex numbers var c1 = 3 + 4 * `1j` # ComplexScalar[cint]: (3 + 4j) var c2 = 2.0 * `1j` # ComplexScalar[cf64]: (0 + 2j) var c3 = 5 - `1j` # ComplexScalar[cint]: (5 - 1j) # SIMD complex vectors var c4 = SIMD[f32, 4](1.0) + `1j` * SIMD[f32, 4](2.0) # ComplexSIMD[cf32, 4] var c5 = SIMD[f64, 2](3.0, 4.0) + `1j` # ComplexSIMD[cf64, 2] var d = SIMD[f32, 2](1) + SIMD[f32, 2](2) * `1j` # creates [( 1 + 2 j) (1 + 2 j)] # Mathematical properties var c6 = `1j` * `1j` # -1 (Scalar[f64]) var c7 = `1j` ** 3 # (0 - 1j) (ComplexScalar[cf64]) var c8 = (1 + `1j`) / `1j` # (1 - 1j) (ComplexScalar[cf64]) ``` * Added documentation for ImaginaryUnit methods. ### NDArray Improvements * Added `normalize` for handling negative indices. * Improved constructor documentation. --- ## Changed * Enhanced documentation for `ComplexSIMD`, including clearer conceptual explanations and usage examples. * Change the behaviour of `__getitem__`, `__setitem__`, `item`, `itemset` methods of `ComplexSIMD`. The earlier method were confusing to use and were not flexible enough to access all parts of the complex SIMD vectors. The current methods allow accessing the ComplexSIMD vectors in the following manner, ```mojo var complex_simd = ComplexSIMD[cf32, 4](1.0, 2.0) # All lanes set to 1+2i # Lane-wise access var lane2 = complex_simd[2] # Get ComplexScalar at lane 2 complex_simd[1] = ComplexScalar[cf32](3.0, 4.0) # Set lane 1 to 3+4i # Component access var real_part = complex_simd.item["re"](2) # Get real part of lane 2 complex_simd.itemset["im"](1, 5.0) # Set imaginary part of lane 1 to 5.0 # Bulk access var all_reals = complex_simd.re # Get all real parts as SIMD vector var all_imags = complex_simd.im # Get all imaginary parts as SIMD vector ``` --- ## 4. Removed * N/A --- --------- Co-authored-by: ZHU Yuhao 朱宇浩 <[email protected]>
merging changes from upstream pre-0.8
change printing methods, add copy methods
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.