Skip to content
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

Expand the number of types that can cross the Python-Chapel divide #8

Open
lydia-duncan opened this issue Dec 10, 2014 · 4 comments
Open

Comments

@lydia-duncan
Copy link
Member

lydia-duncan commented Dec 10, 2014

At the moment, the types that can be passed to and returned from a Chapel function by Python code are limited to primitives (such as (Python)int->(Chapel)int and float->real(64)) and a single instantiation of the NumPy array type. To make a broader claim of usability and usefulness, this issue must be addressed.

Only NumPy arrays of reals with stride equal to their itemsize are supported, and those are not currently returnable from a Chapel function.

List of types that can theoretically be translated for arguments:
Python: Chapel

  • None: void
  • bool: bool
  • int: int
  • int: int(64)
  • float: real(64)
  • str: string (recent experimenting seems to indicate this doesn't work)
  • np.ndarray: pych_array (an extern type with fields to match the declaration of ndarray, with the storage being translated to _ddata under the covers)

List of types that can theoretically be translated for returns:
Chapel: Python

  • void: None
  • bool: bool
  • int: int
  • int(16): int
  • int(32): int
  • int(64): int
  • real: float
  • real(32): float
  • real(64): float
@lydia-duncan
Copy link
Member Author

User request for supporting sending JSON as an argument to Chapel

@buddha314
Copy link

buddha314 commented Aug 10, 2017

And that user was ME!

Additional question, since we can send in np.array types, what is the declared type within the file. E.g.

call.py

from pych.extern import Chapel
import numpy as np

currentloc = os.path.dirname(os.path.realpath(__file__))
@Chapel(sfile=os.path.join(currentloc + '/response.chpl'))
def flip_bit(v=np.array):
    return int

if __name__=="__main__":
    u = np.array([9,8,7])
    w = flip_bit(u)
    print(w)

And now I need to describe the argument of the function to accept that array type.
response.chpl

export
proc flip_bit(v: <HELP_ME_LYDIA>) {
  v[0] = -v[0];
  return v[0];
}

I tried this, but got an undefined error. I guess that's because I need to import the type, but from where?

export
proc flip_bit(v: pych_array) {
  v[0] = -v[0];
  return v[0];
}
```

Any thoughts?

@lydia-duncan
Copy link
Member Author

So pyChapel has an extern record defined to understand what the pych_array type is. The extern record declaration is in modules/templates/prefix.chpl, with the C definition in modules/include/pych.h. However, prefix.chpl also has a function pych_to_chpl1D (and one for 2D but that isn't used anywhere) which translates a pych_array into a bit of the undercover magic for arrays and is used for the argument conversion of inline functions only.

You might be able to use prefix in order to get access to the extern record declaration and insert the pych_to_chpl1D call yourself (following a template from module/templates/convert.pych.1d.chpl to get that into an actual array), but I suspect because these files are "load"ed by python, they aren't visible to ordinary chapel programs. But then again, maybe they are?

Even if that works, that seems like a work around when pyChapel should really do the conversion of pych_array argument to actual array argument itself, though.

@buddha314
Copy link

Summary, here are some issues with transferring data that I have run into.

  • You cannot push an np.array into chapel using sfiles, only if they are inline
  • These arrays must be of reals and it does not support ints
  • Chapel cannot send back arrays of any type
  • You cannot push or receive strings, either inline or with sfiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants