Skip to content

Instantly share code, notes, and snippets.

View athas's full-sized avatar
🐈
how did this get here i am not good with compute

Troels Henriksen athas

🐈
how did this get here i am not good with compute
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
double seconds() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec + ts.tv_nsec/1000000000.0;
}
@athas
athas / thegoodstuff.el
Created April 2, 2022 10:07
Setting up Futhark with lsp-mode
(add-to-list 'lsp-language-id-configuration '(futhark-mode . "futhark"))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection '("futhark" "lsp"))
:activation-fn (lsp-activate-on "futhark")
:server-id 'futhark))
let isnan32 (x: f32) =
let x = f32.to_bits x
let exponent = (x >> 23) & 0b11111111
let significand = x & 0b11111111111111111111111
in exponent == 0b11111111 && significand != 0
title author date patat
Futhark Presentation for the /r/ProgrammingLanguages meetup
Troels Henriksen
November 22nd, 2020
theme
codeBlock header emph
bold
bold
-- Summarises an n-element input in k bins, with each of the k bins
-- containing the maximum of the input in that span.
let main [n] (k: i64) (samples: [n]i32) =
let bin_size = f32.i64 n / f32.i64 k
let index i = i64.f32 (f32.i64 i / bin_size)
in reduce_by_index (replicate k 0) i32.max i32.highest
(map index (iota n)) samples
import futhark_data
import numpy as np
import sys
buf = sys.stdin.buffer.read()
arr = np.frombuffer(buf, dtype=np.uint8)
futhark_data.dump(arr, sys.stdout.buffer, binary=True)
@athas
athas / nub.sml
Created September 22, 2020 08:53
fun nub [] = []
| nub [x] = [x]
| nub (x::y::xs) = if x = y
then nub (x::xs)
else x :: nub (y::xs)
@athas
athas / txtcanvas.py
Last active September 20, 2020 13:26
#!/usr/bin/env python3
import futhark_data
import sys
arr = next(futhark_data.loadb(sys.stdin.buffer.read()))
h, w = arr.shape
for i in range(h):
for j in range(w):
type cell = i32
type dir = #north | #south | #east | #west
let dir_to_bit (d: dir) : i32 =
match d
case #north -> 1
case #south -> 2
case #east -> 4
case #west -> 8
#include <sys/socket.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#include <math.h>
#include <unistd.h>