Skip to content

Commit

Permalink
pseudo F for interp xlnsb; testnpbufunc
Browse files Browse the repository at this point in the history
  • Loading branch information
markgarnold committed Nov 22, 2024
1 parent 6e576a4 commit e46cb5b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/xlnsconf/interp_cotran_ufunc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import xlns as xl
import numpy as np
import math

def sbdb_ufunc_interpsb(z,s,B=None,F=None):
if B == None:
B = xl.xlnsB
if F == None:
F = xl.xlnsF
F = -math.floor(math.log(math.log(B,2),2))
N = (F-5)//2
J = F - N
#print("N="+str(N))
Expand All @@ -32,7 +33,7 @@ def sbdb_ufunc_cotrdb(z,s,B=None,F=None):
if B == None:
B = xl.xlnsB
if F == None:
F = xl.xlnsF
F = -math.floor(math.log(math.log(B,2),2))
N = (F-5)//2
J = F - N
zhmask = -(1<<J)
Expand Down Expand Up @@ -78,7 +79,9 @@ def sbdb_ufunc_interpsbcotrdb(z,s,B=None,F=None):
if B == None:
B = xl.xlnsB
if F == None:
F = xl.xlnsF
#F = xl.xlnsF
F = -math.floor(math.log(math.log(B,2),2))

N = (F-5)//2
J = F - N
zhmask = -(1<<J)
Expand Down
39 changes: 39 additions & 0 deletions test/testnpbufunc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'''
exhaustive test of user-configuration ufunc against 64-bit FP
uses xlnsnpb to trigger F-bit sbdb_ufunc calls to ufunc passed to it
'''

import math
import xlns as xl
import numpy as np
import xlnsconf.interp_cotran_ufunc


def testufunc(f, ufunc):
xl.sbdb_ufunc = ufunc
xl.xlns1stCons = True # avoid warnings for each change to F which can be ignored
xl.xlnssetF(f)
x = xl.xlnsnpb(np.multiply.accumulate(np.array((f*2**f)*[xl.xlns(2**2**-f)])),2**2**-f)
xf = np.multiply.accumulate(np.array(((f*2**f)*[2**2**-f])))
relerr_sb = (((xf+1)-xl.float64(x+1))/(xf+1))
relerr_db = (((xf-1)-xl.float64(x-1))/(xf-1))
#for i in range(0,len(relerr_db)):
# if relerr_db[i]>.1:
# print(str(i)+" "+str(relerr_db[i]))
xl.sbdb_ufunc = xl.sbdb_ufunc_ideal
return (relerr_sb.min(), relerr_sb.max(), relerr_db.min(), relerr_db.max())

def testinterpcotran():
for f in [8,9,11]:
#for f in [8,9,11,13,15]:
#for f in [19]:
print("f="+str(f))
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_interpsb)
print(str(res)+" interp sb only")
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_cotrdb)
print(str(res)+" cotran db only")
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_interpsbcotrdb)
print(str(res)+" interp sb+cotran db")

testinterpcotran()
6 changes: 3 additions & 3 deletions test/testnpufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import math
import xlns as xl
import numpy as np
#import xlnsconf.interp_cotran_ufunc
import interp_cotran_ufunc
import xlnsconf.interp_cotran_ufunc


def testufunc(f, ufunc):
Expand All @@ -26,8 +25,9 @@ def testufunc(f, ufunc):
return (relerr_sb.min(), relerr_sb.max(), relerr_db.min(), relerr_db.max())

def testinterpcotran():
for f in [8,9,11]:
#for f in [8,9,11,13,15]:
for f in [19]:
#for f in [19]:
print("f="+str(f))
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_interpsb)
print(str(res)+" interp sb only")
Expand Down
19 changes: 19 additions & 0 deletions test/testvufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ def testufunc(f,ufunc):
xf=np.multiply.accumulate(np.array(((f*2**f)*[2**2**-f])))
relerr_sb = (((xf+1)-xl.float64(x+1))/(xf+1))
relerr_db = (((xf-1)-xl.float64(x-1))/(xf-1))
for i in range(0,len(relerr_db)):
if relerr_db[i]>.1:
print(str(i)+" "+str(relerr_db[i]))
xl.sbdb_ufunc = xl.sbdb_ufunc_ideal
return (relerr_sb.min(), relerr_sb.max(), relerr_db.min(), relerr_db.max())

#f=8
#res = testufunc(f,xlnsconf.interp_cotran_ufunc.sbdb_ufunc_interpsb)
#res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_interpsb)
#print(res)
#-0.004508454874271358 0.003607134478010154
#print(math.log(abs(res[0]),2))
Expand All @@ -29,4 +33,19 @@ def testufunc(f,ufunc):
#print(math.log(abs(res[3]),2))
#-7.793151203102941
#-8.114931075248318
#res = testufunc(f,xlnsconf.interp_cotran_ufunc.sbdb_ufunc_cotrdb)
#res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_cotrdb)
#print(res)

def testinterpcotran():
for f in [8,9,11]:
#for f in [8,9,11,13,15]:
print("f="+str(f))
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_interpsb)
print(str(res)+" interp sb only")
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_cotrdb)
print(str(res)+" cotran db only")
res = testufunc(f,interp_cotran_ufunc.sbdb_ufunc_interpsbcotrdb)
print(str(res)+" interp sb+cotran db")

testinterpcotran()

0 comments on commit e46cb5b

Please sign in to comment.