jakevdp/SciDB-py — pull request #22 by ChrisBeaumont (2014-03-27 02:27:06+00:00)
Title: AFL Bindings

This implements an AFL binding layer, as discussed in #18. It provides a functional mapping to the basic AFL operators, with docstrings parsed using https://github.com/ChrisBeaumont/scidbpy-aflgen.

Basic use:

```python
X = sdb.ones((5,5))
afl = sdb.afl

afl.sum(X) # an expression
afl.sum(X).query # query string
afl.sum(X).eval() # run result, return as SciDBArray
afl.sum(X).toarray() # convert to numpy array
```

Docstring example:
```
In [29]: afl.max?
Type: type
String Form:
File: /Users/beaumont/scidbpy/scidbpy/afl.py
Docstring:
max( srcArray [, attr {, groupbyDim}*] )

Produces a result array containing the max value among the values of an attribute. If a list of groupbyDims is provided, one max value is calculated for every distinct group.

Parameters
----------

- srcArray: a source array with srcAttrs and srcDims.
- 0 or 1 attributes from srcAttrs. If no attribute is provided, the
first attribute is used.
- an optional list of groupbyDims.

Notes
-----

- same as aggregate(srcArray, max(attr), groupbyDims).

```

Queries are nestable, evaluated lazily, and cached. Some basic argument count checking is included, but no argument type checking.

Before merging, I'd like to try refactoring some of the SciDBArray/SciDBInterface code to use this binding layer, just to make sure things are working as expected. However, I'll put that code in a new PR.

I'd love to hear what @jakevdp or @bwlewis think about some of the choices made here, including:

1) The default behavior of eval() is to allocate a new array, and wrap the expression in a store() call. The store call can be removed by calling `eval(store=False)`, but I guess the assumption here is that all AFL operators return arrays

2) Some AFL operators take quoted strings: `list('arrays')`. Others take unoquted string-like arguments like `sum(X, f0, i0)`. These two cases map to `afl.list("'arrays'")` and `afl.sum(X, 'f0', 'i0')`. Having to manually quote "arrays" is kind of annoying, but I see no way around it

3) While additional operators from other libraries can be registered, there is currently no mechanism to discover them automatically.