Skip to content

Instantly share code, notes, and snippets.

@tomkooij
Last active March 30, 2016 13:49
Show Gist options
  • Save tomkooij/461de490f60e290d201d9c8eefc6c90f to your computer and use it in GitHub Desktop.
Save tomkooij/461de490f60e290d201d9c8eefc6c90f to your computer and use it in GitHub Desktop.
"""
Simulate a read_where() query on a pytables table
Issue: Using MKL 11.3 the numexpr NumExpr query is wrong
works with without MKL.
works with and without MKL using a single column.
It seems the VML log10 function is not correctly called.
The table has different memory mapping as a single column.
It seems the VML call does not account for this correctly.
"""
import numpy
import numexpr
from numexpr.necompiler import NumExpr, stringToExpression
INPUT = [1.e12, 1.e13, 1.e14, 1.e15, 1.e16]
RESULT = 3
def make_NumExpr():
""" Make a NumExpr object exactly as pytables """
mysig = [('f1', float)]
typemap = {'f1': float}
strexpr = stringToExpression('log10(f1) >= 14.', typemap, {})
print "DEBUG: strexpr ", strexpr
return NumExpr(strexpr, mysig)
def make_recarray(val):
""" make a pytables table-like numpy.rec.array """
l = len(val)
data = numpy.rec.array(None, formats=('f4,f4,f4'), shape=(l,))
data['f0']= l*[1.]
data['f1']= val
data['f2']= l*[1.e14]
return data
if __name__ == '__main__':
print "numexpr version: ", numexpr.__version__
print "VML: ", numexpr.get_vml_version()
expr = make_NumExpr()
table = make_recarray(INPUT)
dt = [('f1', numpy.float32)]
single_column = numpy.array(table['f1'], dtype=dt)
recarrs = [single_column, table]
for recarr in recarrs:
# simulate pytables get_nested_field()
field = recarr['f1']
# this is the call pytables makes in tables.conditions.call_on_recarray()
result = expr(*[field])
print "DEBUG: strides of this recarray: ", field.strides
if sum(result) == RESULT:
print "Succes!: ", result
else:
print "FAIL!: ", result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment