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)
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 {
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)
The top five results are
golden retriever
0.7964490652084351
Labrador retriever
0.0944252461194992
kuvasz
0.03383997827768326
clumber
0.005355054046958685
Great Pyrenees
# This file is useful for reading the contents of the ops generated by ruby.
# You can read any graph defination in pb/pbtxt format generated by ruby
# or by python and then convert it back and forth from human readable to binary format.
import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.platform import gfile
def pbtxt_to_graphdef(filename):
with open(filename, 'r') as f:
3
input1 Placeholder*
dtype0 *
shape:
3
input2 Placeholder*
dtype0 *
shape:
&