shunwang / numexpr

Automatically exported from code.google.com/p/numexpr
MIT License
0 stars 0 forks source link

Can evalute expersions with record arrays #83

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a record array
img = numpy.zeros([10], dtype=[('r',float),('g',float),('b',float)])
img['r'] = numpy.arange(10)
2. call numexpr
numexpr.evaluate("img['r'] * 2")
3.

What is the expected output? What do you see instead?
expect the expression to be evaluate on the 'r' column of img.
instead i get
>>> numexpr.evaluate("img['r'] * 2")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/numexpr/necompiler.py", line 687, in evaluate
    _names_cache[expr_key] = getExprNames(ex, context)
  File "/usr/lib/python2.7/site-packages/numexpr/necompiler.py", line 608, in getExprNames
    ex = stringToExpression(text, {}, context)
  File "/usr/lib/python2.7/site-packages/numexpr/necompiler.py", line 231, in stringToExpression
    ex = eval(c, names)
  File "<expr>", line 1, in <module>
TypeError: 'VariableNode' object has no attribute '__getitem__'

What version of the product are you using? On what operating system?
Numexpr version:   2.0.1
NumPy version:     1.6.1
Python version:    2.7.3 (default, Apr 30 2012, 21:18:10) 
[GCC 4.7.0 20120416 (Red Hat 4.7.0-2)]
Platform:          linux2-i686
AMD/Intel CPU?     True
VML available?     False
Detected cores:    2

Please provide any additional information below.

i can sort of work around this using the local_dict, but it is a bit messy.
numexpr.evaluate("r * 2", local_dict={'r':img['r']})
array([  0.,   2.,   4.,   6.,   8.,  10.,  12.,  14.,  16.,  18.])

Original issue reported on code.google.com by samtyg...@gmail.com on 31 May 2012 at 11:51

GoogleCodeExporter commented 9 years ago
This is affecting me too. Doesn't local_dict={'r':img['r']} allocate additional 
memory? As much of the numexpr functionality is centered around numpy arrays, I 
feel that record access notation is important.

Original comment by wbuck...@beatsmusic.com on 15 Aug 2013 at 8:51