Skip to content

Instantly share code, notes, and snippets.

@simonster
simonster / attention_distance.py
Last active March 19, 2024 06:09
Mean attention distance
# Copyright 2022 Google LLC.
# SPDX-License-Identifier: Apache-2.0
# Author: Maithra Raghu <maithra@google.com>
def compute_distance_matrix(patch_size, num_patches, length):
"""Helper function to compute distance matrix."""
distance_matrix = np.zeros((num_patches, num_patches))

To the members of the MIT community:

We are writing to inform you of plans to upgrade the MIT campus network, and in particular to upgrade MIT to the next generation of Internet addressing. (Please note that no action is required on your part.)

Machines on the Internet are identified by addresses. The current addressing scheme, called IPv4, was specified around 1980, and allowed for about 4 billion addresses. That seemed enough at the time, which was before local area networks, personal computers and the like, but the Internet research community recognized around 1990 that this supply of addresses was inadequate, and put in place a plan to replace the IPv4 addresses with a new address format, called IPv6. IPv6 uses a 128-bit address scheme and is capable of 340 undecillion addresses (340 times 10^36, or 340 trillion trillion trillion possible IP addresses). This stock of addresses allows great flexibility in how addresses are assigned to hosts, for example allowing every host to use a range of addresses to

.-"-._( ) )
/ , , 66\
`======\ )_\\=\_o)=
`~~"~ `"
using Compat
# Original C version at https://naml.us/post/inverse-of-a-hash-function/
function inverse_hash(key::UInt64)
local tmp::UInt64
# Invert key = key + (key << 31)
tmp = key-(key<<31)
key = key-(tmp<<31)
flatten_dot(s::Symbol) = (s,)
flatten_dot(ex::Expr) = tuple(flatten_dot(ex.args[1])..., ex.args[2].args[1])
macro reexport(syms...)
if length(syms) == 1 && isa(syms[1], Expr) && syms[1].head != :.
syms[1].head == :tuple || error("@reexport: invalid syntax")
syms = syms[1].args
end
modules = (Symbol...)[begin
if isa(arg, Symbol) || (isa(arg, Expr) && arg.head == :.)
@simonster
simonster / gist:7792245
Created December 4, 2013 17:53
gtindex w/sizes as arguments
julia> function gtindex{T}(parent::Array{T,2}, sz1::Int, sz2::Int, first_index::Int, strd1::Int, strd2::Int, ind::Int)
ind -= 1
i2 = div(ind,sz1)
i1 = ind-i2*sz1
@inbounds ret = parent[first_index + i1*strd1 + i2*strd2]
ret
end;
julia> code_native(gtindex, (Array{Int, 2}, Int, Int, Int, Int, Int, Int))
.text
13 -0.2214 -0.0097 0.0554 -0.0184 0.0453 0.9501 66.73 46.66 0.951
14 -0.1920 -0.0266 0.0510 -0.0213 0.0456 0.6865 56.65 44.9 0.688
15 -0.2029 -0.0415 0.0558 -0.0250 0.0403 0.6010 53.6 43.76 0.603
16 -0.2030 -0.0196 0.0498 -0.0262 0.0417 0.6029 52.8 42.64 0.605
17 -0.2046 -0.0319 0.0479 -0.0251 0.0396 0.5895 51.7 41.8 0.591
@simonster
simonster / gist:6191203
Created August 9, 2013 04:30
IJulia error
2013-08-09 00:29:39.856 [NotebookApp] Using existing profile dir: u'/Users/simon/.ipython/profile_julia'
2013-08-09 00:29:39.883 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2013-08-09 00:29:39.898 [NotebookApp] Serving notebooks from local directory: /Users/simon
2013-08-09 00:29:39.899 [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
2013-08-09 00:29:39.899 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
2013-08-09 00:29:51.461 [NotebookApp] Connecting to: tcp://127.0.0.1:62750
2013-08-09 00:29:51.462 [NotebookApp] Kernel started: 94e986c1-1aec-41f1-8251-bbada5073d53
2013-08-09 00:29:51.811 [NotebookApp] Connecting to: tcp://127.0.0.1:62747
2013-08-09 00:29:51.818 [NotebookApp] Connecting to: tcp://127.0.0.1:62749
2013-08-09 00:29:51.819 [NotebookApp] Connecting to: tcp://127.0.0.1:62748
@simonster
simonster / gist:6157543
Created August 5, 2013 17:01
Loop vectorizer benchmarks
Commit 5d05a4876df53257c7fde518ab3598cf9adeb6f9
➜ perf>make
fib 0.103 0.105 0.104 0.001
parse_int 0.332 0.344 0.338 0.005
mandel 0.332 0.338 0.334 0.003
quicksort 0.495 0.512 0.503 0.007
pi_sum 48.416 56.452 51.751 3.129
rand_mat_stat 48.037 70.606 59.050 9.001
rand_mat_mul 79.485 129.067 98.886 20.258
printfd 47.455 73.397 54.434 10.801
define void @julia_f(%jl_value_t*, i64) #2 {
top:
%2 = icmp slt i64 %1, 1, !dbg !3364
br i1 %2, label %L2, label %if.lr.ph, !dbg !3364
if.lr.ph: ; preds = %top
%3 = getelementptr inbounds %jl_value_t* %0, i64 1, i32 0, !dbg !3369
%4 = load %jl_value_t** %3, align 8, !dbg !3369
br label %if, !dbg !3364