Skip to content

Instantly share code, notes, and snippets.

View arafatkatze's full-sized avatar
💭
Lover of life and all things beautiful

Ara arafatkatze

💭
Lover of life and all things beautiful
View GitHub Profile
@arafatkatze
arafatkatze / test_berkowitz.py
Created March 5, 2016 13:35
Testing Sympy Berkowitz Algorithm
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
@arafatkatze
arafatkatze / berkowitz_test.rb
Last active March 5, 2016 13:45
A speed test for berkowitz algorithm
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
/////////////////////////////////////////////////////////////////////
// = 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
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)
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
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]]
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)
node {
name: "Placeholder"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
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)]))))
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)