title | author | date | patat | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Futhark Presentation for the /r/ProgrammingLanguages meetup |
Troels Henriksen |
November 22nd, 2020 |
|
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
#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; | |
} |
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
(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)) |
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
let isnan32 (x: f32) = | |
let x = f32.to_bits x | |
let exponent = (x >> 23) & 0b11111111 | |
let significand = x & 0b11111111111111111111111 | |
in exponent == 0b11111111 && significand != 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
-- 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 |
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 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) |
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
fun nub [] = [] | |
| nub [x] = [x] | |
| nub (x::y::xs) = if x = y | |
then nub (x::xs) | |
else x :: nub (y::xs) |
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
#!/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): |
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
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 |
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
#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> |
NewerOlder