Public
Edited
Sep 3, 2024
Insert cell
Insert cell
function test(fn, args){
const t = Date.now()
fn(...args)
return Date.now()-t
}
Insert cell
results = {
let trials = []
for(let n=1; n<100;n++){
const A = math.random([n,n])
const x = math.random([n,1])
const At = tf.tensor(A)
const xt = tf.tensor(x)
for(let trial = 1; trial <= 50;trial++){
const timeMath = test(math.multiply, [A,x])
const timeTF = test(tf.matMul, [At,xt])
if(trial > 5)
trials.push({n, timeMath, timeTF})
}
}
return trials

}
Insert cell
n = 100
Insert cell
A = math.random([n, n])
Insert cell
B = math.random([n,1])
Insert cell
cMath = math.multiply(A,B)
Insert cell
cTF = tf.matMul(Atensor,Btensor).array()
Insert cell
Atensor = tf.tensor(A)

Insert cell
Btensor = tf.tensor(B)

Insert cell
math.smaller(math.max(math.subtract(cMath, cTF)), 1e-5) ? 'equal results' : 'unequal results'

Insert cell
math = import("https://cdn.jsdelivr.net/npm/mathjs@latest/+esm")
Insert cell
tf = require('@tensorflow/tfjs@latest')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more