Monday, February 13, 2017
Sunday, February 12, 2017
Numpy vs Tensorflow Matrix multiplication
Numpy is much much faster (Note: Used CPU version, not the GPU version)
import numpy import tensorflow as tf import time def getTestData(): A = [[1., 2., 3., 4.],[3.,4.,5.,6.],[7.,8,9.,10.],[11.,12.,13.,14.]] return 6,A def tfMatMul(): n,A = getTestData() A = tf.constant(A) sess = tf.Session() for num in range(1,n): A = tf.matmul(A,A) output = sess.run(A) A = tf.convert_to_tensor(output) sess.close() return output def numPyMatMul(): n,A = getTestData() for num in range(1,n): A = numpy.matmul(A,A) return A def timedRun(methodToRun): start = time.time() result = methodToRun() end = time.time() diff = end - start print("Time Taken :"+str(diff)) print(result) timedRun(numPyMatMul) timedRun(tfMatMul)
Saturday, February 11, 2017
conda commands
conda create --name test35 python=3.5
conda info --envs (list)
activate test35
deactivate test35
conda remove --name test35 --all
conda install -y scipy
conda install -y scipy
PyCharm with Anaconda - Using a specific environment
Search for "Project Interpreter"
Click on Settings Icon(Wheel)
Add Local
Choose python.exe in your env, path is like Anaconda3\envs\<env_name>\python.exe
Thursday, February 9, 2017
scala notes
https://www.safaribooksonline.com/library/view/scala-for-the/9780134510613/
for yield => map
for yield => map
for yield with guard clause => filter
reduceLeft
clojures - how are they implemented? In scala, they are objects which capture the method and bindings of free variables.
Expression evalutation (Recursive data structures)
abstract class Expr case class Num(value: Int) extends Expr case class Sum(left: Expr, right: Expr) extends Expr case class Product(left: Expr, right: Expr) extends Expr val e = Product(Num(3), Sum(Num(4), Num(5))) def eval(e: Expr):Int = e match { case Num(v) => v case Sum(l,r) => eval(l) + eval(r) case Product(l,r) => eval(l) * eval(r) } eval(e)
Expression evalutation (Recursive data structures) - OOP version
abstract class Expr { def eval: Int } class Num(val data: Int) extends Expr { def eval: Int = data } class Product(val left: Expr, val right: Expr) extends Expr { def eval: Int = left.eval * right.eval } class Sum(val left: Expr, val right: Expr) extends Expr { def eval: Int = left.eval + right.eval } val e = new Product(new Num(3), new Sum(new Num(4), new Num(5))) e.evalSo what to use, Polymorphism version or case classes.
Use case classes when your cases are bound. Like here. There is a finite set of expressions.
Use Polymorphism
Wednesday, February 8, 2017
scala notes
https://www.safaribooksonline.com/library/view/scala-for-the/9780134510613/
packages => nesting can be all at one place, no need to have similar source directories
packages => nesting can be all at one place, no need to have similar source directories
imports are flexible, can import specific classes, can hide a class, can alias, can import anywhere (lexical scoping)
Traits (like Java interfaces)
But much more powerful
Traits cannot have construction parameters, otherwise they are same as classes.
traits can be mixed in with objects, rather than class declaration
traits can invoke others in a priorlayer (consolelogger, timestamplogger, shortlogger)
Thursday, February 2, 2017
Changing the port for react app(create-react-app)
Built with create react app
Edit node_modules/react-scripts/scripts/start.js
Search for DEFAULT_PORT and modify as follows:
var DEFAULT_PORT = process.env.PORT || 80;
Edit node_modules/react-scripts/scripts/start.js
Search for DEFAULT_PORT and modify as follows:
var DEFAULT_PORT = process.env.PORT || 80;
Subscribe to:
Posts (Atom)