def solve(r, t): r= np.float96(r) t = np.float96(t) if debug: if case == 20: pdb.set_trace() tmp= 1-2*r + np.sqrt( (2*r - 1) **2 + 8 *t ) return int( tmp/4.0 )
def sciFormat(x, dec): l = sp.log10(np.float96(x)) lf = float(np.floor(l)) if l > 5: m = float(np.round(x/10**lf, dec)) return r"$" + format(m, '.'+format(int(dec))+'f') + r" \times 10^{" + \ format(int(lf),'d') + r"}$" else: return format(x)
def sciFormat(x, dec): l = sp.log10(np.float96(x)) lf = float(np.floor(l)) if l > 5: m = float(np.round(x / 10**lf, dec)) return r"$" + format(m, '.'+format(int(dec))+'f') + r" \times 10^{" + \ format(int(lf),'d') + r"}$" else: return format(x)
def eigmcPowerMethod(A, m, N, numseq): (n, nn) = A.shape if (n != nn): raise Exception("non square matrix") h = np.repeat(1.0, n) p0 = h / sum(h) P = normalize(A) sumW = np.float96(0.0) sumW_1 = np.float96(0.0) for i in range(N): k = getWeighted(range(n), p0, numseq) W = h[k] / p0[k] W_1 = W for j in range(m): k_1 = k vals = P.indices[P.indptr[k_1]:P.indptr[k_1 + 1]] weights = P.data[P.indptr[k_1]:P.indptr[k_1 + 1]] k = getWeighted(vals, weights, numseq) W_1 = W W *= A[k_1, k] / P[k_1, k] sumW += W sumW_1 += W_1 return sumW / sumW_1
'uint8': [0, 2**8 - 1], 'int16': [-2**15, 2**15 - 1], 'uint16': [0, 2**16 - 1], 'int32': [-2**31, 2**31 - 1], 'uint32': [0, 2**32 - 1], 'int64': [-2**63, 2**63 - 1], 'uint64': [0, 2**64 - 1], 'float32': [-infinityf, infinityf], 'float64': [-infinity, infinity], } if hasattr(numpy, 'float16'): infinitymap['float16'] = [-numpy.float16(numpy.inf), numpy.float16(numpy.inf)] if hasattr(numpy, 'float96'): infinitymap['float96'] = [-numpy.float96(numpy.inf), numpy.float96(numpy.inf)] if hasattr(numpy, 'float128'): infinitymap['float128'] = [-numpy.float128(numpy.inf), numpy.float128(numpy.inf)] # deprecated API infinityMap = infinitymap infinityF = infinityf # Utility functions def inftype(dtype, itemsize, sign=+1): """Return a superior limit for maximum representable data type."""
'int32': [-2**31, 2**31 - 1], 'uint32': [0, 2**32 - 1], 'int64': [-2**63, 2**63 - 1], 'uint64': [0, 2**64 - 1], 'float32': [-infinityf, infinityf], 'float64': [-infinity, infinity], } if hasattr(numpy, 'float16'): infinitymap['float16'] = [ -numpy.float16(numpy.inf), numpy.float16(numpy.inf) ] if hasattr(numpy, 'float96'): infinitymap['float96'] = [ -numpy.float96(numpy.inf), numpy.float96(numpy.inf) ] if hasattr(numpy, 'float128'): infinitymap['float128'] = [ -numpy.float128(numpy.inf), numpy.float128(numpy.inf) ] # deprecated API infinityMap = infinitymap infinityF = infinityf # Utility functions
import numpy as np reveal_type(np.uint128()) reveal_type(np.uint256()) reveal_type(np.int128()) reveal_type(np.int256()) reveal_type(np.float80()) reveal_type(np.float96()) reveal_type(np.float128()) reveal_type(np.float256()) reveal_type(np.complex160()) reveal_type(np.complex192()) reveal_type(np.complex256()) reveal_type(np.complex512())
'int8': [-2**7, 2**7 - 1], 'uint8': [0, 2**8 - 1], 'int16': [-2**15, 2**15 - 1], 'uint16': [0, 2**16 - 1], 'int32': [-2**31, 2**31 - 1], 'uint32': [0, 2**32 - 1], 'int64': [-2**63, 2**63 - 1], 'uint64': [0, 2**64 - 1], 'float32': [-infinityf, infinityf], 'float64': [-infinity, infinity], } if hasattr(np, 'float16'): infinitymap['float16'] = [-np.float16(np.inf), np.float16(np.inf)] if hasattr(np, 'float96'): infinitymap['float96'] = [-np.float96(np.inf), np.float96(np.inf)] if hasattr(np, 'float128'): infinitymap['float128'] = [-np.float128(np.inf), np.float128(np.inf)] # deprecated API infinityMap = infinitymap infinityF = infinityf # Utility functions def inftype(dtype, itemsize, sign=+1): """Return a superior limit for maximum representable data type.""" assert sign in [-1, +1]
"int8": [-2 ** 7, 2 ** 7 - 1], "uint8": [0, 2 ** 8 - 1], "int16": [-2 ** 15, 2 ** 15 - 1], "uint16": [0, 2 ** 16 - 1], "int32": [-2 ** 31, 2 ** 31 - 1], "uint32": [0, 2 ** 32 - 1], "int64": [-2 ** 63, 2 ** 63 - 1], "uint64": [0, 2 ** 64 - 1], "float32": [-infinityf, infinityf], "float64": [-infinity, infinity], } if hasattr(numpy, "float16"): infinitymap["float16"] = [-numpy.float16(numpy.inf), numpy.float16(numpy.inf)] if hasattr(numpy, "float96"): infinitymap["float96"] = [-numpy.float96(numpy.inf), numpy.float96(numpy.inf)] if hasattr(numpy, "float128"): infinitymap["float128"] = [-numpy.float128(numpy.inf), numpy.float128(numpy.inf)] # deprecated API infinityMap = infinitymap infinityF = infinityf # Utility functions def inftype(dtype, itemsize, sign=+1): """Return a superior limit for maximum representable data type.""" assert sign in [-1, +1]
#-- Define all Nup values possible all_Nup = range(Ntot,-1,-1) #-- Table header lines = [] headings = [r"N_{\uparrow}", r"U/\mu B", r"M/N\mu", r"\Omega", r"S/k", r"kT/\mu B", r"C/Nk"] nel = len(headings) header = r"$" + r"$ & $".join(headings) + r"$ \\ \midrule \addlinespace[5pt]" lines.append(r"\begin{tabular}{rrrcrrc}") lines.append(header) tableRows = [] for Nup in all_Nup: Ndown = np.float96(Ntot - Nup) U_by_mu_B = np.float96(Ntot - 2*Nup) M_by_N_mu = np.float96(Nup-Ndown)/np.float96(Ntot) Omega = sp.comb(Ntot, Nup, exact=True) S_by_k = np.log(np.float96(Omega)) tableRows.append( [Nup, U_by_mu_B, M_by_N_mu, Omega, S_by_k] ) rowNum = 0 for row in tableRows: if rowNum == 0 or rowNum == Ntot: kT_by_mu_B = 0 else: kT_by_mu_B = (tableRows[rowNum+1][1]-tableRows[rowNum-1][1]) / \ (tableRows[rowNum+1][4]-tableRows[rowNum-1][4]) tableRows[rowNum].append( kT_by_mu_B ) rowNum += 1
all_Nup = range(Ntot, -1, -1) #-- Table header lines = [] headings = [ r"N_{\uparrow}", r"U/\mu B", r"M/N\mu", r"\Omega", r"S/k", r"kT/\mu B", r"C/Nk" ] nel = len(headings) header = r"$" + r"$ & $".join(headings) + r"$ \\ \midrule \addlinespace[5pt]" lines.append(r"\begin{tabular}{rrrcrrc}") lines.append(header) tableRows = [] for Nup in all_Nup: Ndown = np.float96(Ntot - Nup) U_by_mu_B = np.float96(Ntot - 2 * Nup) M_by_N_mu = np.float96(Nup - Ndown) / np.float96(Ntot) Omega = sp.comb(Ntot, Nup, exact=True) S_by_k = np.log(np.float96(Omega)) tableRows.append([Nup, U_by_mu_B, M_by_N_mu, Omega, S_by_k]) rowNum = 0 for row in tableRows: if rowNum == 0 or rowNum == Ntot: kT_by_mu_B = 0 else: kT_by_mu_B = (tableRows[rowNum+1][1]-tableRows[rowNum-1][1]) / \ (tableRows[rowNum+1][4]-tableRows[rowNum-1][4]) tableRows[rowNum].append(kT_by_mu_B) rowNum += 1
#m=1E-3 #for i in range(1001): #x=0.001*i #for e in (math.exp,np.exp): #n,d,v=v(x, m, e) #print(e, x, n, d, v) ###!OUTPUT: ###File "ej5.51.py", line 7, in v ###den=1-exp(1./mu) ###OverflowError: math range error x = np.linspace(0, 1, 10001) n, d, y1 = v(x, mu=1, exp=np.exp) n, d, y2 = v(x, mu=0.1, exp=np.exp) n, d, y3 = v(x, mu=0.01, exp=np.exp) plt.plot(x, y1, "k-", label="mu=1") plt.plot(x, y2, "r-", label="mu=0.1") plt.plot(x, y3, "b-", label="mu=0.01") #can't plot 0.001 plt.title("v(x) for various mu") plt.legend() plt.savefig("ej5.51vx.png") plt.show() m = 1E-3 m = np.float96( m) #AttributeError: module 'numpy' has no attribute 'float96' :( x2 = np.float96(x) #Can't make it work so I move on. n, d, y = v(x, mu=m, exp=np.exp)
'uint8': [0, 2**8 - 1], 'int16': [-2**15, 2**15 - 1], 'uint16': [0, 2**16 - 1], 'int32': [-2**31, 2**31 - 1], 'uint32': [0, 2**32 - 1], 'int64': [-2**63, 2**63 - 1], 'uint64': [0, 2**64 - 1], 'float32': [-infinityf, infinityf], 'float64': [-infinity, infinity], } if hasattr(numpy, 'float16'): infinitymap['float16'] = [-numpy.float16(numpy.inf), numpy.float16(numpy.inf)] if hasattr(numpy, 'float96'): infinitymap['float96'] = [-numpy.float96(numpy.inf), numpy.float96(numpy.inf)] if hasattr(numpy, 'float128'): infinitymap['float128'] = [-numpy.float128(numpy.inf), numpy.float128(numpy.inf)] # deprecated API infinityMap = infinitymap infinityF = infinityf # Utility functions def inftype(dtype, itemsize, sign=+1): """Return a superior limit for maximum representable data type"""