Skip to content

win: add Complex type for MSVC compatibility#92

Merged
andresy merged 3 commits into
ml-explore:mainfrom
dhiltgen:win
Feb 2, 2026
Merged

win: add Complex type for MSVC compatibility#92
andresy merged 3 commits into
ml-explore:mainfrom
dhiltgen:win

Conversation

@dhiltgen
Copy link
Copy Markdown
Contributor

Related to ml-explore/mlx#3024

Comment thread mlx/c/array.h Outdated
typedef struct {
float real;
float imag;
} mlx_complex64_t;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not using _Fcomplex (which is the MSVC counterpart of float _Complex if I am not mistaking)?

Comment thread mlx/c/array.cpp Outdated
const mlx_array arr) {
try {
*res = mlx_array_get_(arr).item<float _Complex>();
auto val = mlx_array_get_(arr).item<std::complex<float>>();
Copy link
Copy Markdown
Member

@andresy andresy Jan 30, 2026

Choose a reason for hiding this comment

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

would need to use mlx_complex64_t here instead of the two next lines which may break depending on the complex implementation

@zcbenz
Copy link
Copy Markdown

zcbenz commented Jan 30, 2026

mlx-c is written in C++ so the _Fcomplex type is not available in complex.h, which in MSVC seems to be redirected to C++ ccomplex.

A possible workaround is to copy the definition of MSVC _Fcomplex in our header:
https://github.com/hughbe/windows-sdk-headers/blob/89f151d343587fcd5b854a4851fcb8f7187f3ac4/Include/10.0.10586.0/ucrt/complex.h#L22-L42

Edit: Adding a _CRT_USE_C_COMPLEX_H macro before including complex.h seems to work, refs microsoft/STL#3280.

@dhiltgen
Copy link
Copy Markdown
Contributor Author

Sorry for the delay. The changes look good to me. Thanks!

@andresy andresy merged commit 8a943c6 into ml-explore:main Feb 2, 2026
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