We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sections AAA and BBB perform the same logic. AAA is much more concise but crashes when compiling.
import math import numpy input_order = [ 'nym', 'nf', 'ebci', 'ebui', 'bbi', 'eaci', 'eaui', 'bai', 'egc', 'egu', 'bg', 'edc', 'edu', 'bi', 'edgc', 'edgu', 'erc', 'eru', 'br', 'chu', 'af', 'lp', 'ly', 'acti', 's' ] input_indices = dict([(k,i) for i,k in enumerate(input_order)]) def get_index (acti, acc, cnum): for item in acti: if item[0] == acc and item[1] == cnum: return item[2] return None #pythran export n_steps n_steps = 9 #pythran export n_state_vars n_state_vars = 12 cache_indices = { 'ec' : 0, 'eu' : 1, 'b' : 2, 'cgc' : 3, 'cgu' : 4, 'cgb' : 5, 'c' : 6, 'poc' : 7, 'ed' : 8, 'ta' : 9, 'rdwa' : 10, 'max_rdwa' : 11, } #pythran export set_cache ( # float64 [], int, int, float64 [][][][][][] order(C), # ( # int, int, # float64 [], float64 [], float64 [], float64 [], float64 [], float64 [], float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [][] order(C), float64 [], float64 [], float64 [], float64 [], # (str, int, int) list, # # float64 # ) #) def set_cache (x, cnum, cache_index, cache, inputs): nym = inputs[input_indices['nym']] nf = inputs[input_indices['nf']] acti = inputs[input_indices['acti']] s = inputs[input_indices['s']] index = get_index (acti, 'a', cnum) #if index is None: #return ebci = inputs[input_indices['ebci']][cnum] ebui = inputs[input_indices['ebui']][cnum] bbi = inputs[input_indices['bbi']][cnum] eaci = inputs[input_indices['eaci']][cnum] eaui = inputs[input_indices['eaui']][cnum] bai = inputs[input_indices['bai']][cnum] egc = inputs[input_indices['egc']][cnum] / 100. egu = inputs[input_indices['egu']][cnum] / 100. bg = inputs[input_indices['bg']][cnum] / 100. edc = inputs[input_indices['edc']][cnum] / 100. edu = inputs[input_indices['edu']][cnum] / 100. bi = inputs[input_indices['bi']][cnum] / 100. edgc = inputs[input_indices['edgc']][cnum] / 100. edgu = inputs[input_indices['edgu']][cnum] / 100. erc = inputs[input_indices['erc']][cnum] / 100. eru = inputs[input_indices['eru']][cnum] / 100. br = inputs[input_indices['br']][cnum] / 100. chu = inputs[input_indices['chu']][cnum] / 100. af = inputs[input_indices['af']][cnum] / 100. lp = inputs[input_indices['lp']][cnum] ly = inputs[input_indices['ly']][cnum] tbi = ebci + ebui + bbi if tbi != 0: ecf = ebci / tbi euf = ebui / tbi bf = bbi / tbi else: # AAA iec = egc != 0 or edc != 0 or edgc != 0 ieu = egu != 0 or edu != 0 or edgu != 0 ib = bg != 0 or bi != 0 # /AAA # BBB #iec = False #ieu = False #ib = False #if egc != 0 or edc != 0 or edgc != 0: #iec = True #if egu != 0 or edu != 0 or edgu != 0: #ieu = True #if bg != 0 or bi != 0: #ib = True # /BBB ni = [iec, ieu, ib].count(True) if ni == 0: ecf = 1 euf = 0 bf = 0 else: ecf = 1 / ni euf = 1 / ni bf = 1 / ni # --------------------------------------- def f1 (ats, which, c, ta, ebc, ebu, b, cgc, cgu, cgb): if which == 'c': ba = ebc cg = cgc elif which == 'u': ba = ebu cg = cgu elif which == 'b': ba = b cg = cgb else: raise Exception('which = %s' % (str(which))) fs = ats / ba tag = min(cg * fs, 10 * s) * 0.2 + max(cg * fs - 10 * s, 0) * 0.35 c_delta = ats c += ats ta += tag if which == 'c': ebc -= ats cgc *= (1 - fs) elif which == 'u': ebu -= ats cgu *= (1 - fs) elif which == 'b': b -= ats cgb *= (1 - fs) else: raise Exception('which = %s' % (str(which))) return c_delta, c, ta, ebc, ebu, b, cgc, cgu, cgb # --------------------------------------- if cache_index >= 2: ny_min = cache_index else: ny_min = 0 if ny_min != 0: for ny in range(0, ny_min): cache[cache_index,ny,cnum,:,:,:] = cache[0,ny,cnum,:,:,:] for ny in range(ny_min, nym + 1): if ny != 0: y = ny - 1 else: y = 0 if ny == 0: ebc = ebci ebu = ebui b = bbi cgc = ebc - eaci cgu = ebu - eaui cgb = b - bai else: ebc = cache[cache_index][ny - 1][cnum][0][n_steps - 1][cache_indices['ec']] ebu = cache[cache_index][ny - 1][cnum][0][n_steps - 1][cache_indices['eu']] b = cache[cache_index][ny - 1][cnum][0][n_steps - 1][cache_indices['b']] cgc = cache[cache_index][ny - 1][cnum][0][n_steps - 1][cache_indices['cgc']] cgu = cache[cache_index][ny - 1][cnum][0][n_steps - 1][cache_indices['cgu']] cgb = cache[cache_index][ny - 1][cnum][0][n_steps - 1][cache_indices['cgb']] # ---------------- for j in range(2): c = 0. poc = 0. ed = 0. ta = 0. if j == 0: max_rdwa = 0. if ny == 0 or j == 1: rdwa = 0. else: rdwa = x[index + y * nf] if j == 1: li = True else: li = False if j == 0: tbjls = ebc + ebu + b # ------------------- step = 0 # 8. step += 1 if j == 0 and rdwa < 0.001 * s: c += abs(rdwa) rdwa = 0. ebc += c * ecf ebu += c * euf b += c * bf c = 0. else: if j == 0: n = 3 o = [ebci, ebui, bbi] cu = [ebc, ebu, b] ai = [i for i,val in enumerate(cu) if val != 0] total_o = sum([o[i] if i in ai else 0. for i in range(n)]) fo = [o[i] / total_o if i in ai else 0. for i in range(n)] t = [] for i in range(n): if i not in ai: t.append([]) else: t.append( [cu[i] * fo[j] / fo[i] for j in range(n)] ) fi = [] for i in range(n): if len(t[i]) != 0 and all([ t[i][j] <= cu[j] + 0.001 * s for j in range(n) ]): fi.append(i) ri = [i for i in range(n) if i not in fi] mr = [cu[i] - t[fi[0]][i] if i in ri else 0 for i in range(n)] smr = sum(mr) if rdwa < smr: ar = [mr[i] * rdwa / smr for i in range(n)] else: ar = [mr[i] + (rdwa - smr) * fo[i] for i in range(n)] else: ar = [ebc, ebu, b] #delta, c_, ta_, ebc_, ebu_, b_, cgc_, cgu_, cgb_ = f1 (ar[0], 'c', c, ta, ebc, ebu, b, cgc, cgu, cgb) #c = c_ + 0.; ta = ta_ + 0.; ebc = ebc_ + 0.; ebu = ebu_ + 0.; b = b_ + 0.; cgc = cgc_ + 0.; cgu = cgu_ + 0.; cgb = cgb_ + 0. #c -= delta #poc += delta #rdwa -= delta #max_rdwa += delta cache[cache_index][ny][cnum][j][step - 1][:] = [ebc, ebu, b, cgc, cgu, cgb, c, poc, ed, ta, rdwa, max_rdwa]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Sections AAA and BBB perform the same logic.
AAA is much more concise but crashes when compiling.
The text was updated successfully, but these errors were encountered: