Skip to content

Instantly share code, notes, and snippets.

GET "LIBHDR"
LET START() BE
$(
WRITES("Hello, world!*N")
$)
import scala.actors.Actor
object Calculator extends Actor {
var v: Int = 0
this.start()
override def act(): Unit = {
loop {
react {
case Inc(i) => v += i
import Calculator.{Get, Dec, Inc}
import scala.actors.Actor
object Client extends Actor {
override def act(): Unit = {
Calculator ! Inc(4)
Calculator ! Inc(2)
Calculator ! Dec(1)
Calculator ! Get()
def !!!(msg: String, e: Throwable) = throw new Exception(msg, e)
implicit class ExceptionEnricher[A](thingToDo: => A) {
def !!!!(msg: String): A = {
try {
thingToDo
} catch {
case e: Throwable =>
!!!(msg, e)
trait |[+A, +B] extends Dynamic {
type Union[T] = T =|= (A | B)
}
let rk4 h f (x, y) =
let k1 = h * f(x, y)
let k2 = h * f(x + 0.5*h, y + 0.5*k1)
let k3 = h * f(x + 0.5*h, y + 0.5*k2)
let k4 = h * f(x + h, y + k3)
x + h, y + k1 / 6.0 + k2 / 3.0 + k3 / 3.0 + k4 / 6.0
// A single step
rk4 1.0 (fun (x, y) -> y) (0.0, 1.0)
let solve n r f =
let dx = 1.0 / float(n-1)
let dt = r * dx * dx
let g u0 u1 u2 = r*u0 + (1.0 - 2.0 * r)*u1 + r*u2
( 0.0,
[|for i in 0..n-1 ->
f(float i / float(n-1))|] )
|> Seq.unfold (fun (t, us) ->
Some( (t, us),
(t + dt,
class Cached[-I, +O](f: I => O) extends (I => O) {
private[this] val cache = scala.collection.concurrent.TrieMap.empty[I, O]
def apply(x: I): O = {
if (cache.contains(x)) {
cache(x)
} else {
val y = f(x)
cache += (x -> y)
y
[<ReflectedDefinition>]
let MatrixTrans(a: float32[], wi: WorkItemInfo) =
let aT = Array.zeroCreate<float32> a.Length
let aLocal = local(Array.zeroCreate<float32> (BLOCK_SIZE * BLOCK_SIZE))
for i = 0 to MULT do
for j = 0 to MULT do
let baseIdxA = (wi.GroupID(0) * NR_GROUPS + i) * BLOCK_SIZE + (wi.GroupID(1) + j * NR_GROUPS) * A_BLOCK_STRIDE
let globalIdxA = baseIdxA + wi.LocalID(0) + aWidth * wi.LocalID(1)
wi.Barrier(CLK_LOCAL_MEM_FENCE)
@explicite
explicite / ds12b20.go
Last active August 29, 2015 14:27
ds12b20
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"strconv"
"time"
)