This file contains 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 png | |
' ## Colormaps | |
Here we model colormaps as sequences of RGB colors which are then | |
piecewise linearly interpolated in the interval [0,1] upon evaluation. | |
RGB = (Fin 3)=>Float | |
cmap_viridis = [[253.0, 231.0, 37.0] | |
,[ 94.0, 201.0, 98.0] |
This file contains 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
using Images | |
# CC0 license: https://commons.wikimedia.org/wiki/File:Wikicommons_kamera_rollei35_rrt877.jpg | |
file = download("https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Wikicommons_kamera_rollei35_rrt877.jpg/640px-Wikicommons_kamera_rollei35_rrt877.jpg") | |
img = load(file) | |
open("camera.ppm", "w+") do io | |
println(io, "P6") | |
println(io, size(img, 2), " ", size(img, 1)) | |
println(io, 255) | |
for row in eachrow(img) |
This file contains 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 plot | |
import png | |
key = new_key 1234 | |
Height = Fin 100 | |
Width = Fin 300 | |
img_ = for i:Height. for j:Width. n_to_f ((ordinal i) + (ordinal j)) | |
img = img_ / (n_to_f (size Height + size Width)) | |
:html matshow img | |
:t img |
This file contains 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
# rrule from frule (transposition) | |
using Zygote | |
using ChainRulesCore | |
using LinearAlgebra | |
function f(x) | |
a = sin.(x) | |
b = sum(a) | |
c = b * a | |
return c |
This file contains 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 torch | |
import jax | |
import jax.dlpack | |
import torch.utils.dlpack | |
from jax.config import config | |
config.update("jax_enable_x64", True) | |
def jax2torch(x): | |
return torch.utils.dlpack.from_dlpack(jax.dlpack.to_dlpack(x)) |
This file contains 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
using NLsolve | |
using Zygote | |
using ChainRulesCore | |
using IterativeSolvers | |
using LinearMaps | |
using SparseArrays | |
using LinearAlgebra | |
using BenchmarkTools | |
using Random | |
Random.seed!(1234) |
This file contains 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 plot | |
-- Conjugate gradients solver | |
def solve (mat:m=>m=>Float) (b:m=>Float) : m=>Float = | |
x0 = for i:m. 0.0 | |
ax = mat **. x0 | |
r0 = b - ax | |
(xOut, _, _) = fold (x0, r0, r0) $ | |
\s:m (x, r, p). | |
ap = mat **. p |
This file contains 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 jax | |
from jax import core | |
from graphviz import Digraph | |
import itertools | |
styles = { | |
'const': dict(style='filled', color='goldenrod1'), | |
'invar': dict(color='mediumspringgreen', style='filled'), | |
'outvar': dict(style='filled,dashed', fillcolor='indianred1', color='black'), |
This file contains 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
#!/bin/bash | |
# 1. Install CUDA | |
echo "Installing CUDA..." | |
# Only install if CUDA is not already installed. | |
if ! sudo dpkg-query -W cuda; then | |
# The 18.04 installer | |
sudo curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb | |
sudo dpkg -i ./cuda-repo-ubuntu1804_10.0.130-1_amd64.deb | |
sudo apt-get update | |
sudo apt-get install cuda -y |