-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
ccall does not support C99 complex numbers #85
Comments
This is a difficult one. The problem is that when structs or C99 complex numbers are involved, the calling convention changes and no longer depends only on the size of the value in question. On x86-64, I think this would be fixed by using a proper struct. On 32-bit I don't believe there is a standard ABI for these types. LLVM does not directly support the C99 complex types, so we could try to borrow from clang. Then we would need to make Complex64 and Complex128 special so the code generator knows they correspond to _Complex. Not a fun situation. In other words, a "full" C99 interface needs to include complex as an explicit feature; the type can't be implemented in pure julia. However, so far we haven't specified which C standard our C FFI supports :) |
Ugh. That's a shame. Oh, well. |
Is it safe to mark this one as "wontfix"? We just avoid calling BLAS routines for complex dot(). |
Given that this datatype is part of the C99 standard, I think this would actually be a reasonable solution. |
We can add types CComplexFloat and CComplexDouble to be used in ccall, which can then be converted to our types. Or we could make Complex128 and Complex64 built-in, but I'm not sure of all the implications of tying our complex numbers to the C99 type. |
I think that what Jeff was talking about was making |
Oh, I misread that post as from Viral. Obviously, I'm not going to argue with Jeff about what he meant. Regardless of whether it's what you meant, can't we do that? |
If |
I don't think it's all that strange. We sort of do the same thing in essence by dispatching the methods for |
Usually, very few library functions return one complex value as in dot(). I think it is safe to not put effort into this one. Its just that it took me a while before I realized what was going on. Perhaps ccall should just throw a warning when it sees things that are unlikely to work? -viral On Jun 28, 2011, at 2:05 AM, StefanKarpinski wrote:
|
openlibm has a bunch of functions that return complex numbers, which we may want to use. For example, csinh. How do we call these? It would be nice if Complex128 mapped to C's double complex. |
Yes, it would be nice. But we have our own implementation of complex sin in terms of real functions. If their complex sin performs some tricks we need, we should try to port them to the julia code. |
Apart from this, I cannot think of any other use for this feature. Can we close this? -viral On 09-Jan-2012, at 2:27 AM, [email protected] wrote:
|
I guess this can be considered a duplicate of handling C structs in general. The only extra feature is handling c99 complex on IA32, where there is no standard ABI for it, and we would have to do something special. That is a fairly marginal feature however. Up to you. |
I am closing this one and marking it wontfix. |
Do we want to be able to call |
I think those are fairly important. It seems very premature to close this as "won't fix". |
BLAS 1 is not such a big deal. But yes, would call them if it worked. -viral On 18-Aug-2012, at 1:10 AM, Jeff Bezanson [email protected] wrote:
|
The discussion seems to suggest that it is not clear what should be done. Please reopen if we can implement. -viral On 18-Aug-2012, at 1:18 AM, Stefan Karpinski [email protected] wrote:
|
I think we can definitely have it on x86_64, then from there see what happens on IA32. |
Please ignore my reference. |
I just ran into this issue when trying to write a Julia interface for some C99 special-function evaluation code (http://ab-initio.mit.edu/Faddeeva) that is too complicated to contemplate rewriting in Julia. At the very least, the ccall interface should exit with an error if the return type is Complex, rather than silently producing erroneous results. (Note that this contradicts the documentation of ccall, which says that "any bits type" is supported. The documentation should be fixed too if Complex is not supported.) Furthermore, it does not seem to be just return types that cause a problem -- even complex arguments seem to be problematic when passed by value. For example, the following code gives rather unexpected (nondeterministic!) results on x86_64 (Debian GNU/Linux, gcc 4.4.5):
compile with: gcc -std=c99 -fPIC -shared -Wl,-soname,libfoo.so.0 -o libfoo.so foo.c In Julia:
|
Yes, you're right that this should be fixed in the docs and, ideally, supported. |
Noting that this is now supported via |
This is pretty exciting – we've wanted to do this for a very long time. Our mandelbrot benchmark might get substantially faster. |
Please leave this issue open until |
@stevengj The conversion between Complex128 and ComplexPair should be relatively automatic in most use cases. Currently, Complex128 is needed for making arrays, where as ComplexPair is needed for ccalls. Eventually, however, Complex128 will be turned into an alias for ComplexPair (when it is possible to declare that instances of ComplexPair are immutable, and thus can be copied) |
I see; the main thing until then is to update the documention, but we have issue #2145 for that. |
Add AssertionError as typealias of ExceptionError
I fixed complex dot(), but it still does not work correctly. I can't figure out what might be wrong. The only thing I can think of is that the C interface probably does not know how to return complex numbers.
The text was updated successfully, but these errors were encountered: