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

Skip to content

Simplify out-of-the-box usage #1

@rahulgovind

Description

@rahulgovind

While writing compyle code, I noticed that there were a few redundancies in the syntax which made it 1) more verbose than needed, and 2) easier to make mistakes. Given below are some changes which I believe could help reduce such redundancies.

  • Set a global default backend: I guess cython would be a good default. I imagine most people will only use one backend at a time. Users can override the global default and users who use multiple backends can pass the backend argument explicitly or use the with_config syntax.

  • Remove need for annotate by default: It looks likeElementwise could wrap the function itself

  • Different backend for openmp: Replace parallel cython backend (backend='cython' and use_openmp=True) with possibly an 'openmp' backend (backend='openmp'). This is based on the observations that the use_openmp flag is useless by itself and that most of the algorithms compyle uses are different for cython and for openmp.

  • Wrapper package over numpy: This is one point I am not too sure of but it's inspired by pyopencl's array package. This makes it possible to have an interface to create arrays directly on the device if the backend is opencl or cuda. More importantly, it helps clearly differentiate between a numpy array and a "wrapped" compyle array.

If the changes above are incorporated, the simple example given for compyle would look something like this

from compyle.api import Elementwise
import compyle.array as ary

def axpb(i, x, y, a, b):
    y[i] = a*sin(x[i]) + b

x = ary.linspace(0, 1, 10000)
y = ary.zeros_like(x)
a, b = 2.0, 3.0

e = Elementwise(axpb)
e(x, y, a, b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions