This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy import * | |
import time | |
matrix = Matrix([ [ 1.0, 2.0, 1.0] , [-2.0, -3.0, 1.0] , [ 3.0, 5.0, 0.0] ]) | |
start = time.clock() | |
for x in range(0, 1000): | |
matrix.berkowitz() | |
print time.clock() - start | |
#2.103344 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nmatrix' | |
require 'time' | |
def timer n | |
matrix = NMatrix.new([3,3], [1.0, 2.0, 1.0, -2.0, -3.0, 1.0 ,3.0, 5.0, 0.0]) | |
now = Time.now.to_f | |
n.times do | |
matrix.charpoly | |
end | |
endd = Time.now.to_f | |
endd-now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////// | |
// = NMatrix | |
// | |
// A linear algebra library for scientific computation in Ruby. | |
// NMatrix is part of SciRuby. | |
// | |
// NMatrix was originally inspired by and derived from NArray, by | |
// Masahiro Tanaka: http://narray.rubyforge.org | |
// | |
// == Copyright Information |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
input1 = tf.placeholder(tf.int64, shape=(2, 2), name = "input1") | |
input2 = tf.placeholder(tf.int64, shape=(2, 2), name = "input2") | |
output = tf.add(input1, input2, name = "output") | |
with tf.Session() as sess: | |
tf.train.write_graph(sess.graph_def, "model/", "graph.pb", as_text=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tensorflow' | |
graph = Tensorflow::Graph.new | |
tensor_1 = Tensorflow::Tensor.new([[2, 2.3], [ 10, 6.2]]) | |
tensor_2 = Tensorflow::Tensor.new([[4, 3.2], [ 47, 1.2]]) | |
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num) | |
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num) | |
opspec = Tensorflow::OpSpec.new('Addition_of_tensors', 'Add', nil, [placeholder_1, placeholder_2]) | |
op = graph.AddOperation(opspec) | |
session_op = Tensorflow::Session_options.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tensorflow' | |
graph = Tensorflow::Graph.new | |
tensor_1 = Tensorflow::Tensor.new([[ [2.0,5.0], | |
[1.0,-20.0]], | |
[[124.0,5.0], | |
[53.0,-2.0]], | |
[[1.0,0.0], | |
[0.0,1.0]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
a = tf.Graph() | |
input1 = tf.placeholder(tf.float32, shape=(2)) | |
input2 = tf.placeholder(tf.float32, shape=(2)) | |
output = tf.mul(input1, input2) | |
with tf.Session() as sess: | |
print(sess.run([output], feed_dict={input1:[7,2], input2:[2,4]})) | |
tf.train.write_graph(sess.graph_def, 'models/', 'test_graph_multi_dim.pb', as_text=True) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
name: "Placeholder" | |
op: "Placeholder" | |
attr { | |
key: "dtype" | |
value { | |
type: DT_FLOAT | |
} | |
} | |
attr { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tensorflow' | |
graph_def = Tensorflow::GraphDef.new | |
node_a = Tensorflow::NodeDef.new(name: "Placeholder", op: "Placeholder", attr: []) | |
node_a.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "dtype" ,value: Tensorflow::AttrValue.new(type: 1))) | |
node_a.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "shape" , value: Tensorflow::AttrValue.new(shape: Tensorflow::TensorShapeProto.new(dim: [Tensorflow::TensorShapeProto::Dim.new(size: 2)])))) | |
graph_def.node.push(node_a) | |
node_b = Tensorflow::NodeDef.new(name: "Placeholder_1", op: "Placeholder", attr: []) | |
node_b.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "dtype" ,value: Tensorflow::AttrValue.new(type: 1))) | |
node_b.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "shape" , value: Tensorflow::AttrValue.new(shape: Tensorflow::TensorShapeProto.new(dim: [Tensorflow::TensorShapeProto::Dim.new(size: 2)])))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.python.platform import gfile | |
import sys | |
def converter(filename): | |
with gfile.FastGFile(filename,'rb') as f: | |
graph_def = tf.GraphDef() | |
graph_def.ParseFromString(f.read()) | |
tf.import_graph_def(graph_def, name='') | |
tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pbtxt', as_text=True) |
OlderNewer