Version:
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
This was made with commands:
./configure --ninja --node-builtin-modules-path `pwd`| import numpy as np | |
| import tf_api as tf | |
| # Create model | |
| model = lambda x: 1.23 * x + 10 | |
| # Create small dataset of 5 entries | |
| train_X = np.linspace(0, 5, 5).reshape((-1, 1)) | |
| train_Y = np.array([model(x) for x in train_X]).reshape((-1, 1)) |
| class multiply(BinaryOperation): | |
| """ | |
| Computes a * b, element-wise | |
| """ | |
| def forward(self, a, b): | |
| return a * b | |
| def backward(self, upstream_grad): | |
| raise NotImplementedError |
| class BinaryOperation(Operation): | |
| def __init__(self, a, b): | |
| super().__init__([a, b]) |
| import tf_api as tf | |
| # create default graph | |
| tf.Graph().as_default() | |
| # construct computational graph by creating some nodes | |
| a = tf.Constant(15) | |
| b = tf.Constant(5) | |
| prod = tf.multiply(a, b) | |
| sum = tf.add(a, b) |
| class Session(): | |
| def run(self, operation, feed_dict={}): | |
| nodes_sorted = topology_sort(operation) | |
| for node in nodes_sorted: | |
| if type(node) == Placeholder: | |
| node.output = feed_dict[node] | |
| elif type(node) == Variable or type(node) == Constant: | |
| node.output = node.value | |
| else: |
| def topology_sort(operation): | |
| ordering = [] | |
| visited_nodes = set() | |
| def recursive_helper(node): | |
| if isinstance(node, Operation): | |
| for input_node in node.input_nodes: | |
| if input_node not in visited_nodes: | |
| recursive_helper(input_node) |
| class Variable(): | |
| def __init__(self, initial_value=None): | |
| self.value = initial_value | |
| _default_graph.variables.append(self) |
| class Placeholder(): | |
| def __init__(self): | |
| self.value = None | |
| _default_graph.placeholders.append(self) |