示例#1
0
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

from   hep import test
import hep.expr
import hep.table

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

# Open the table.
table = hep.table.open("table3.table")

selection = hep.expr.parse("index % 4 == 3")
for row in table.select(selection):
    test.compare(row["_index"] % 4, 3)
示例#2
0
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

import hep.table
from   hep.test import compare

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

schema = hep.table.Schema()
table = hep.table.create("index1.table", schema)
for i in range(10):
    table.append()
del table

table = hep.table.open("index1.table")
index_expr = table.compile("_index")

for i in range(9, -1, -1):
    row = table[i]
    compare(row["_index"], i)
    compare(index_expr.evaluate(row), i)
    
for row in table.select("_index % 3 == 1"):
    compare(row["_index"] % 3, 1)
示例#3
0
#-----------------------------------------------------------------------

# Create a new table.
schema = hep.table.Schema()
schema.addColumn("c", "complex128")
table = hep.table.create("complex1.table", schema)

# Fill in some rows.
values1 = []
values2 = []
for i in xrange(0, 1000):
    value = random() + random() * 1j
    table.append(c=value)
    if abs(value) > 1:
        values1.append(value)
    if value.real > 0.5 and value.imag < -0.5:
        values2.append(value)

# Write and close the table.
del schema, table

# Reopen the table.
table = hep.table.open("complex1.table")

# Check rows.
for row, value in zip(table.select("abs(c) > 1"), values1):
    compare(row["c"], value)
for row, value in zip(table.select("c.real > 0.5 and c.imag < -0.5"), values2):
    compare(row["c"], value)