def warp_coords(coord_map, shape, dtype=np.float64):
 shape = safe_as_int(shape)
 (rows, cols) = (shape[0], shape[1])
 coords_shape = [len(shape), rows, cols]
 if (len(shape) == 3):
  coords_shape.append(shape[2])
 coords = np.empty(coords_shape, dtype=dtype)
 tf_coords = np.indices((cols, rows), dtype=dtype).reshape(2, (-1)).T
 tf_coords = coord_map(tf_coords)
 tf_coords = tf_coords.T.reshape(((-1), cols, rows)).swapaxes(1, 2)
 _stackcopy(coords[1, ...], tf_coords[0, ...])
 _stackcopy(coords[0, ...], tf_coords[1, ...])
 if (len(shape) == 3):
  coords[2, ...] = range(shape[2])
 return coords

def warp_coords ( coord_map , shape , dtype = np . float64 ) : shape = safe_as_int ( shape ) ( rows , cols ) = ( shape [ 0 ] , shape [ 1 ] ) coords_shape = [ len ( shape ) , rows , cols ] if ( len ( shape ) == 3 ) : coords_shape . append ( shape [ 2 ] ) coords = np . empty ( coords_shape , dtype = dtype ) tf_coords = np . indices ( ( cols , rows ) , dtype = dtype ) . reshape ( 2 , ( - 1 ) ) . T tf_coords = coord_map ( tf_coords ) tf_coords = tf_coords . T . reshape ( ( ( - 1 ) , cols , rows ) ) . swapaxes ( 1 , 2 ) _stackcopy ( coords [ 1 , ... ] , tf_coords [ 0 , ... ] ) _stackcopy ( coords [ 0 , ... ] , tf_coords [ 1 , ... ] ) if ( len ( shape ) == 3 ) : coords [ 2 , ... ] = range ( shape [ 2 ] ) return coords
build the source coordinates for the output of a 2-d image warp .