Commit 51325319 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

fixed packing to 4x faster

parent fc63a9dd
...@@ -42,18 +42,25 @@ def pack_layer(layer,lut_row): ...@@ -42,18 +42,25 @@ def pack_layer(layer,lut_row):
t = layer.flatten() t = layer.flatten()
out = np.array([]) #out = np.array([])
out = np.empty(len(lut_row))
# iterate through rows # iterate through rows
for i in range(len(lut_row)): for i in range(len(lut_row)):
val = 0 val = 0
# process row value # process row value
for j in lut_row[i]: for j in lut_row[i]:
if np.isnan(t[j[0]]): ## big slowdown
val = np.nan #if np.isnan(t[j[0]]):
break # val = np.nan
val += t[j[0]]*j[1] # break
out = np.append(out,val) #val += t[j[0]]*j[1]
val += t[j[0]]
#out = np.append(out,val)
#out[i] = val
out[i] = val
return out return out
...@@ -61,13 +68,25 @@ def pack_layer(layer,lut_row): ...@@ -61,13 +68,25 @@ def pack_layer(layer,lut_row):
# tile and lut already ordered and indices match # tile and lut already ordered and indices match
def pack_tile(tile,lut): def pack_tile(tile,lut):
out = np.array([]) #out = np.array([])
#s = 0
#for i in range(len(lut)):
# s += len(lut[i])
#out = np.empty(s)
out = np.empty(100)
ptr = 0
for i in range(len(lut)): for i in range(len(lut)):
layer = pack_layer(tile[:,:,i],lut[i]) layer = pack_layer(tile[:,:,i],lut[i])
out = np.append(out,layer) #out = np.append(out,layer)
out[ptr:ptr+len(lut[i])] = layer
#out[ptr:ptr+len(lut[i])] = np.empty(25)
ptr += len(lut[i])
return out return out
# tiles are already packed # tiles are already packed
def get_tile_with_neighbors(tiles,i,j,radius): def get_tile_with_neighbors(tiles,i,j,radius):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment