# Path: src/e2eflow/ops.py
# OP_NAMES = ['backward_warp', 'downsample', 'correlation', 'forward_warp']
# def compile(op=None):
# def correlation(first, second, **kwargs):
# def _BackwardWarpGrad(op, grad):
# def _ForwardWarpGrad(op, grad):
# def _CorrelationGrad(op, in_grad, in_grad1, in_grad2):


import tensorflow as tf
from ..ops import downsample as downsample_ops


def summarized_placeholder(name, prefix=None, key=tf.GraphKeys.SUMMARIES):
    prefix = '' if not prefix else prefix + '/'
    p = tf.placeholder(tf.float32, name=name)
    tf.summary.scalar(prefix + name, p, collections=[key])
    return p


def resize_area(tensor, like):
    _, h, w, _ = tf.unstack(tf.shape(like))
    return tf.stop_gradient(tf.image.resize_area(tensor, [h, w]))


def resize_bilinear(tensor, like):
    _, h, w, _ = tf.unstack(tf.shape(like))
    return tf.stop_gradient(tf.image.resize_bilinear(tensor, [h, w]))

def downsample(tensor, num):
    _,height, width,_ = tensor.shape.as_list()
    if height%2==0 and width%2==0:

# Path: src/e2eflow/ops.py
# OP_NAMES = ['backward_warp', 'downsample', 'correlation', 'forward_warp']
# def compile(op=None):
# def correlation(first, second, **kwargs):
# def _BackwardWarpGrad(op, grad):
# def _ForwardWarpGrad(op, grad):
# def _CorrelationGrad(op, in_grad, in_grad1, in_grad2):


# Path: src/e2eflow/core/util.py
import tensorflow as tf
from ..ops import downsample as downsample_ops



def summarized_placeholder(name, prefix=None, key=tf.GraphKeys.SUMMARIES):
    prefix = '' if not prefix else prefix + '/'
    p = tf.placeholder(tf.float32, name=name)
    tf.summary.scalar(prefix + name, p, collections=[key])
    return p


def resize_area(tensor, like):
    _, h, w, _ = tf.unstack(tf.shape(like))
    return tf.stop_gradient(tf.image.resize_area(tensor, [h, w]))


def resize_bilinear(tensor, like):
    _, h, w, _ = tf.unstack(tf.shape(like))
    return tf.stop_gradient(tf.image.resize_bilinear(tensor, [h, w]))

def downsample(tensor, num):
    _,height, width,_ = tensor.shape.as_list()
    if height%2==0 and width%2==0:

        return downsample_ops(tensor, num)