Skip to content

Conversation

@shivasankarka
Copy link
Owner

No description provided.

shivasankarka and others added 30 commits October 22, 2025 12:52
…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.
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]>
shivasankarka and others added 28 commits November 23, 2025 18:23
…-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
…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]>
@shivasankarka shivasankarka changed the base branch from main to prev0.8 December 12, 2025 06:39
@shivasankarka shivasankarka merged commit 9cc177b into prev0.8 Dec 12, 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.

2 participants