-
Notifications
You must be signed in to change notification settings - Fork 7
Is it possible to support complex dtypes on Windows? #64
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
Comments
SuiteSparse:GraphBLAS should work with complex data types on Windows. Is this the python-to-C connection that doesn't work? |
Correct, we currently strip out all complex stuff for Windows. I wish we could get this working, since complex works with SuiteSparse:GraphBLAS on all OSes. I don't think we need anything from you; we'll need to figure it out, or live with this shortcoming. Similarly, I wonder whether wrapping SuiteSparse:GraphBLAS with Cython would work with complex dtypes... |
It might be possible to change how I handle my 2 complex types. I could use my own struct, as in typedef struct { double real ; double imag ; } GxB_FC64_t ; I already do many of the complex operators myself (see for example https://github.com/DrTimothyAldenDavis/GraphBLAS/blob/0b79097dfba798c158af244eb7323a55adf9cf30/Source/GB_math.h#L25 and following). |
For example, I do my own complex division because the compiler-provided versions are mixed in quality. I want to match how MATLAB does it, and they are more careful about Inf and NaN behavior. So I use this: and revised in my master branch as: If I had an #ifdef'd option to use my own complex type definition, then the GxB_CMPLX(r,i) macro would be
because this works:
If this was an #ifdef'd option, then GxB_FC32_t and GxB_FC64_t would both be typedef'd structs. Can you pass in scalars and arrays of that type? |
Downside to this: I would need to write my own complex trig and hyperbolic functions: cacos, cacosf, casin, casinf, catan, catanf, ..., cacosh, ... cpow, cexp, clog, and so many more. That would be very hard to do. I would need to find a set of definitions of these functions that I could use and incorporate into GraphBLAS. |
What if instead you pretend on your side that GxB_FC64_t has this typedef:
and then whereever you need to pass in a C scalar of that type, pass in that struct. Or a C array of that type -- just pass in a pointer to an array of those types. |
Yeah, we should be able to do that for Windows easily enough. If we tried this, do you think it should work with the latest SuiteSparse:GraphBLAS, or would you need to do something? |
I would need to make a 3-line change to GraphBLAS.h.in, and the change would have no effect on anything inside SS:GrB, nor any effect on any other users of GraphBLAS. Here's what I would do: The 3 lines would be:
... here I place lines 137 to 203 of GraphBLAS.h
Then in your C wrapper, you do this:
Then your notion of the two complex types would differ from mine, but they would be compatible at the bit level. Your C wrapper would think they are structs of 2 floats or 2 doubles. All of the GraphBLAS prototypes that you see on your side would use that definition. All of they prototypes GraphBLAS would see internally would be the built-in complex type in Windows, since you would still compile SS:GrB the same, without this preface of This would be a minor change to GraphBLAS so I could do it as a v7.5.0 version, released any time you like. I'd bump the minor version from v7.4.x to v7.5.0 because it's a new user-visible feature. It would have no effect at all on any other GraphBLAS users, except to add the Would that work on your side? |
In case this is helpful: here is how pybind11 does individual complex values: https://github.com/pybind/pybind11/blob/master/include/pybind11/complex.h I can confirm that pybind11 works for me with complex numpy arrays being read and written by a C++ extension, including on Windows. |
Oh, I think I see what's causing the problem. The MSVC command that compiles the Python extensions does not specify a C standard. The MSVC default is something ancient, which does not have complex value support. I'll submit a PR shortly that will include a Tim, GraphBLAS/CMakeLists.txt does set the C standard, but in a confusing way. The line that does so is this one: set_property ( TARGET graphblas PROPERTY C_STANDARD 11 ) (line 293). The confusing bits:
Also FYI, the preferred way to check for Clang is: if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") Notice the MATCHES, not STREQUAL. That way you handle both regular Clang and AppleClang, the default (and often only) compiler on macOS. |
The I'll let someone familiar with the complex value issue see if that fixes it or not. |
Thanks for the comments. I'll work on fixing those issues in the GraphBLAS/CMakeLists.txt file. It was the first cmake I wrote and you can see it's a bit crufty in a few places -- in particular, the large if-else block for handing different compilers. Some of that can be cleaned up. |
This took far longer than I hoped, but I have some progress. The However, using
I hacked an ugly version of approach 2 ( alugowski@dd70141 ) and:
Then I noticed those tests have nearly zero coverage so barely confirm anything, so I re-enabled test_io.py which at least touches complex values and got this:
That looks like a different issue, though, so maybe this is a success? |
The cffi docs say code from Ugly, but it'll work. |
Or just generate those files at setup time instead of checking them in. That would be nicer; those generated .c files have 81k lines. |
Interesting. This does sound like progress. So on Windows we would emit I feel like I've seen that We can test things more thoroughly in |
Oh, hey, this test ran and passed! This test is called
Okay, I'm more confident now that the exception you're seeing on Windows is expected and is why we skip those tests. This is a limitation of Windows we can live with. |
Sounds like this approach is acceptable in principle, so I'll clean it up and make a PR. |
Is there any workaround we could do to make this work? Can we write any custom C code to serve as a bridge between Python and C GraphBLAS?
If anybody needs complex dtypes on Windows or has any information for how we might get it to work, please reply here!
The text was updated successfully, but these errors were encountered: