-
Notifications
You must be signed in to change notification settings - Fork 13
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
Improve documentation on pyChapel return types #80
Comments
Only certain types are supported across the Python-Chapel divide. In the current implementation, we've had to explicitly mention certain types, so you won't see every type Chapel or Python could support. While arrays can be passed to Chapel functions, they cannot currently be returned from them (but you will see modifications made to arrays you pass in to Chapel functions) |
It is an action item to support arrays of more than just the one element type, to return them, and to support arbitrary structures defined within Chapel and Python |
In the example below, Chapel is modifying and
Is the Python view of the "voodoo" variable modified? |
Also, I'm trying to send an array into a routine defined in an sfile. I need an example of the syntax. This failed:
with error
|
re: the voodoo variable - I believe Python will see any changes made to it, and since it is an argument to the function, will be able to work with the actual used after the call has completed. But you should double check that to be certain. Hmm, I don't think we have any tests of sending an array to a function defined in an sfile. I suspect that the ?D domain is causing issues, since Chapel arguments to functions that Python calls must be fully concrete and ?D or no domain at all makes the argument generic. That really shouldn't be an internal error (and is a problem on the Chapel side). Perhaps try specifying the domain exactly for the call? |
And if you wouldn't mind, please open an issue on the Chapel repository about exporting a function with a generic array argument causing an internal error instead of a user facing one :) |
Maybe we will be able to allow the exporting of functions with generic arguments when our separate compilation story gets implemented |
Sorry, just saw this, should I still open that ticket? I'm not sure I understand it, but I'm happy to parrot your words. |
Thanks! |
Do you have a basic example of sending an integer between python and chapel? Something like import os
from pych.extern import Chapel
currentloc = os.path.dirname(os.path.realpath(__file__))
@Chapel(sfile=os.path.join(currentloc + '/response.chpl'))
def flip_bit(v=int):
return int
if __name__=="__main__":
u = 71
w = flip_bit(u)
print(w) And module Response{
export
proc flip_bit(v: int) :int {
v = -v;
return v;
}
} This example isn't working, but I can't tell from the docs how to send in Thanks! |
The interaction of these two files seems to work for me: python file and chapel file I suspect the difference has something to do with wrapping your chapel code in a module, since you would normally need a |
Note that this might interplay with issue #10 |
Changing to lower case
Removing declaration of module so
Brings me this when I do
|
Oh, right. That's because you're trying to assign to the argument, when the argument's default intent is |
Should we be having this conversation on stackoverflow? |
Hey, that's fine with me! Okay, I'll start one and post it here. Good idea! |
HIT IT! Note to future readers, solution is on SO |
From the Misc. Page we can see that primitives can be returned from a Chapel routine into Python. This isn't explicitly stated. Is there a way to return non-primitives? How would I return arrays or sparse arrays, for instance? What about JSON or blobs?
This could be useful for sending data back and forth. I'm sure there are reasonable limits I don't understand.
The text was updated successfully, but these errors were encountered: