Commit 51325319 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev
Browse files

fixed packing to 4x faster

parent fc63a9dd
Loading
Loading
Loading
Loading
+27 −8
Original line number Original line Diff line number Diff line
@@ -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):
# 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):