예제 #1
0
파일: plot_op.py 프로젝트: 21hub/tdb
def plot_op(fn, inputs=[], outputs=[]):
	"""
	User-exposed api method for constructing a python_node

	Args:
	fn: python function that computes some np.ndarrays given np.ndarrays as inputs. it can have arbitrary side effects.
	inputs: array of tf.Tensors (optional). These are where fn derives its values from
	outputs: tf.Placeholder nodes (optional). These are constructed by the user (which allows the user to
		plug them into other ht.Ops or tf.Ops). The outputs of fn are mapped to each of the output placeholders.

	raises an Error if fn cannot map
	"""
	global COUNT, ht
	# check outputs
	if not isinstance(outputs,list):
		outputs=[outputs]

	for tensor in outputs:
		if tensor.op.type is not 'Placeholder':
			raise Error('Output nodes must be Placeholders')

	op=PlotOp(fn, COUNT, inputs, outputs)

	op_store.add_op(op)
	COUNT+=1 

	# if node has output, return value for python_op is the first output (placeholder) tensor
	# otherwise, return the op
	if outputs:
		return outputs[0]
	else:
		return op
예제 #2
0
def python_op(fn, inputs=None, outputs=None):
    """
	User-exposed api method for constructing a python_node

	Args:
	fn: python function that computes some np.ndarrays given np.ndarrays as inputs. it can have arbitrary side effects.
	inputs: array of tf.Tensors (optional). These are where fn derives its values from
	outputs: tf.Placeholder nodes (optional). These are constructed by the user (which allows the user to
		plug them into other ht.Ops or tf.Ops). The outputs of fn are mapped to each of the output placeholders.

	raises an Error if fn cannot map
	"""

    # construct a PythonOp and return its TensorNode outputs, if it has one
    global COUNT
    # check outputs
    if not isinstance(outputs, list):
        outputs = [outputs]
    for tensor in outputs:
        if tensor.op.type != 'Placeholder':
            raise TypeError('Output nodes must be Placeholders')
    op = PythonOp('Python', fn, COUNT, inputs, outputs)
    op_store.add_op(op)
    COUNT += 1
    if outputs:
        return outputs[0]
    else:
        return op
예제 #3
0
파일: plot_op.py 프로젝트: zhoutengteng/tdb
def plot_op(fn, inputs=[], outputs=[]):
    """
	User-exposed api method for constructing a python_node

	Args:
	fn: python function that computes some np.ndarrays given np.ndarrays as inputs. it can have arbitrary side effects.
	inputs: array of tf.Tensors (optional). These are where fn derives its values from
	outputs: tf.Placeholder nodes (optional). These are constructed by the user (which allows the user to
		plug them into other ht.Ops or tf.Ops). The outputs of fn are mapped to each of the output placeholders.

	raises an Error if fn cannot map
	"""
    global COUNT, ht
    # check outputs
    if not isinstance(outputs, list):
        outputs = [outputs]

    for tensor in outputs:
        if tensor.op.type is not 'Placeholder':
            raise Error('Output nodes must be Placeholders')

    op = PlotOp(fn, COUNT, inputs, outputs)

    op_store.add_op(op)
    COUNT += 1

    # if node has output, return value for python_op is the first output (placeholder) tensor
    # otherwise, return the op
    if outputs:
        return outputs[0]
    else:
        return op
예제 #4
0
파일: python_op.py 프로젝트: 21hub/tdb
def python_op(fn, inputs=None, outputs=None):
	"""
	User-exposed api method for constructing a python_node

	Args:
	fn: python function that computes some np.ndarrays given np.ndarrays as inputs. it can have arbitrary side effects.
	inputs: array of tf.Tensors (optional). These are where fn derives its values from
	outputs: tf.Placeholder nodes (optional). These are constructed by the user (which allows the user to
		plug them into other ht.Ops or tf.Ops). The outputs of fn are mapped to each of the output placeholders.

	raises an Error if fn cannot map
	"""

	# construct a PythonOp and return its TensorNode outputs, if it has one
	global COUNT
	# check outputs
	if not isinstance(outputs,list):
		outputs=[outputs]
	for tensor in outputs:
		if tensor.op.type != 'Placeholder':
			raise TypeError('Output nodes must be Placeholders')
	op=PythonOp('Python', fn, COUNT, inputs, outputs)
	op_store.add_op(op)
	COUNT+=1 
	if outputs:
		return outputs[0]
	else:
		return op