My tools of the trade for python programming.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.7 KiB

from numpy import array, concatenate
from wpylib.db.indexing_float import generate_float_indices
indices1 = array([ 0.80038202, 0.28583295, 0.13505145, 0.79425102, 0.52347217, 0.47955401, 0.07961833, 0.1024241 , 0.26336713, 0.15990201, 0.81311686, 0.98632763, 0.08275991,
0.56862337, 0.5679713 , 0.04377884, 0.93023717, 0.60270102, 0.24538933, 0.63922544])
indices2 = array([ 0.69053462, 0.09864655, 0.86209023, 0.26140917, 0.8086512 , 0.13796145, 0.1770305 , 0.05061917, 0.81191537, 0.72801096, 0.01129504, 0.13962617, 0.56217892,
0.94299591, 0.99302594, 0.01167897, 0.54827444, 0.20160252, 0.86603525, 0.20260494])
def Test_1():
indices_raw = concatenate((indices1, indices2))
keys1 = numpy.sort(indices_raw)
keys1_test10 = keys1[-10:]
ans = generate_float_indices(keys1_test10, 1e-2, debug=101)
"""ans must be:
{
'vals': array([ 0.80038202, 0.81122781, 0.86406274, 0.93023717, 0.94299591, 0.98967679]),
'index_mapping': \
{0.80038201815850551: 0,
0.80865119885060532: 1,
0.81191536625506044: 1,
0.8131168633197402: 1,
0.8620902343091833: 2,
0.86603524560901635: 2,
0.93023716796725509: 3,
0.94299590915079168: 4,
0.98632763033630222: 5,
0.99302594015368861: 5}
}
"""
return ans
def Test_1b():
indices_raw = concatenate((indices1, indices2))
keys1 = numpy.sort(indices_raw)
keys1_test10 = concatenate((keys1[-10:], [1.03]))
ans = generate_float_indices(keys1_test10, 1e-2, debug=101)
"""ans must be:
{
'vals': array([ 0.80038202, 0.81122781, 0.86406274, 0.93023717, 0.94299591, 0.98967679, 1.03 ]),
'index_mapping': \
{0.80038202000000003: 0,
0.80865120000000001: 1,
0.81191537000000003: 1,
0.81311686000000005: 1,
0.86209022999999996: 2,
0.86603525000000003: 2,
0.93023716999999995: 3,
0.94299591000000005: 4,
0.98632763000000001: 5,
0.99302594: 5,
1.03: 6}
}
"""
return ans
# TODO: Test the following; they may trip the code:
indices3 = array([ 0.0, 0.80038202, 0.28583295, 0.13505145, 0.79425102, 0.52347217, 0.47955401, 0.07961833, 0.1024241 , 0.26336713, 0.15990201, 0.81311686, 0.98632763, 0.08275991,
0.56862337, 0.5679713 , 0.0, 0.04377884, 0.93023717, 0.60270102, 0.24538933, 0.63922544])
indices4 = array([ 0.0, 0.80038202, 0.28583295, 0.13505145, 0.79425102, 0.52347217, 0.47955401, 0.07961833, 0.1024241 , 0.26336713, 0.15990201, 0.81311686, 0.98632763, 0.08275991,
0.56862337, 0.5679713 , 1e-16, 0.04377884, 0.93023717, 0.60270102, 0.24538933, 0.63922544])