Thanks to visit codestin.com
Credit goes to github.com

Skip to content

arrayfire/arrayfire-py

Repository files navigation

arrayfire-py

ArrayFire is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL, oneAPI and CPU devices.

This project is meant is meant to provide an easy to use Python interface for the ArrayFire C library, i.e, it provides array functionality, math operations, printing, etc. This is the front-end python library for using ArrayFire. It is currently supported on Python 3.10+.

Here is an example of the library at work:

import arrayfire as af

# Set any backend and device (optional: 'cuda', 'opencl', 'oneapi', 'cpu')
af.setBackend(af.BackendType.cuda)
af.setDevice(0)

# Monte Carlo estimation of pi
def calc_pi_device(samples):
    # Simple, array based API
    # Generate uniformly distributed random numers
    x = af.randu(samples)
    y = af.randu(samples)
    # Supports Just In Time Compilation
    # The following line generates a single kernel
    within_unit_circle = (x * x + y * y) < 1
    # Intuitive function names
    return 4 * af.count(within_unit_circle) / samples

Find out more in our examples directory or just read the documentation.

Prequisites and Installing

This project provides the python interface to ArrayFire, however it requires access to the ArrayFire binaries as a prequisite. The dependency chain can be separated into 3 different parts as follows:

arrayfire-py -> arrayfire-binary-python-wrapper -> ArrayFire C Libraries

To run arrayfire with python each of these parts is needed:

  • arrayfire-py is the intended User Interface that provides a numpy-like layer to execute math and array operations with ArrayFire.
  • arrayfire-binary-python-wrapper is a thin wrapper that provides Python direct access to the ArrayFire functions in the C library. This package must have access to ArrayFire binaries, either through a system-wide install, or through a pre-bundled wheel that includes binaries.
  • ArrayFire C Libraries are the binaries obtained from compiling the ArrayFire C/C++ Project or more simply by downloading installers in the ArrayFire download page. Binaries can also be obtained as part of a pre-packaged arrayfire-binary-python-wrapper wheel.

Install the python wrapper with existing ArrayFire install:

# install required binary wrapper, assumes ArrayFire binaries will be installed on the system
pip install arrayfire-binary-python-wrapper
pip install arrayfire-py # install arrayfire python interface library

Install wrapper with a pre-built wheel:

# will grab a binary wrapper with included pre-built binaries
pip install arrayfire-binary-python-wrapper -f https://repo.arrayfire.com/python/wheels/3.10.0/ 
pip install arrayfire-py

Running Tests

Tests are located in folder tests.

To run the tests, use:

python -m pytest tests/

Building

python -m pip install -r dev-requirements.txt
python -m build --wheel

Note: Building this project does not require the arrayfire-binary-python-wrapper package; however, the binary wrapper is needed to run any projects with it

Experimental Array API support

This wrapper is exploring an experimental implementation of the DataAPIs array API standard in this directory with the goal of allowing ArrayFire to seamlessly interoperate with the broader Python landscape. Some portions of the standard are still unimplemented however some simpler examples are working.

Contributing

If you are interested in using ArrayFire through python, we would appreciate any feedback and contributions.

The community of ArrayFire developers invites you to build with us if you are interested and able to write top-performing tensor functions. Together we can fulfill The ArrayFire Mission for fast scientific computing for all.

Contributions of any kind are welcome! Please refer to the wiki and our Code of Conduct to learn more about how you can get involved with the ArrayFire Community through Sponsorship, Developer Commits, or Governance.

Citations and Acknowledgements

If you redistribute ArrayFire, please follow the terms established in the license.

ArrayFire development is funded by AccelerEyes LLC and several third parties, please see the list of acknowledgements for an expression of our gratitude.

Support and Contact Info

Trademark Policy

The literal mark "ArrayFire" and ArrayFire logos are trademarks of AccelerEyes LLC (dba ArrayFire). If you wish to use either of these marks in your own project, please consult ArrayFire's Trademark Policy

About

Arrayfire python wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5