Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Ichoran's full-sized avatar
💭
Ichoran is diffracting imperceptibly (more, with JPEG artifacts)

Ichoran

💭
Ichoran is diffracting imperceptibly (more, with JPEG artifacts)
View GitHub Profile
@Ichoran
Ichoran / Simple.scala plus bytecode
Created February 18, 2023 00:48
Early return converted to break
class Simple {
import scala.util.boundary
import kse.flow.{given, _}
def exists[T](xs: Iterable[T], fn: T => Boolean) =
boundary:
iFor(xs.iterator): (x, _) =>
if fn(x) then boundary.break(true)
false
}
@Ichoran
Ichoran / Bench.scala
Created June 12, 2018 22:06
Thyme benchmark of tap and pipe vs manual inlining
package bench
import scala.language.implicitConversions
import ichi.bench._
object Implicits {
final class ChainingOps[A](private val self: A) extends AnyVal {
@inline def tap[U](f: A => U): A = { f(self); self }
@inline def pipe[B](f: A => B): B = f(self)
@Ichoran
Ichoran / Weighted_Sampling_No_Replace.scala
Created June 10, 2018 00:46
Sketch of a reasonably efficient algorithm for weighted sampling without replacement
def cuml(wt: Array[Double]) = {
val l = wt.length
val base = if ((l & (l-1)) == 0) l else java.lang.Integer.highestOneBit(l)*2
val tree = new Array[Double](base*2)
System.arraycopy(wt, 0, tree, 0, wt.length)
var in = 0
var out = base
var n = base
while (in + 1 < out) {
while (in + 1 < n) {
@Ichoran
Ichoran / Test_Imm_List_Str.scala
Created October 20, 2017 03:48
Example of what generated code looks like with collection-laws rewrite
// Autogenerated test for collection List with element type String
package laws
class Test_Imm_List_Str(numb: Numbers, oper: Ops[String, Option[String]], inst: Instance[String, scala.collection.immutable.List[String]], lln: Int)
extends StrTest[scala.collection.immutable.List[String], Test_Imm_List_Str](numb, oper, inst, lln) {
import Test.ComparesTo
import Test.Logic
def renumber(numb: Numbers) = new Test_Imm_List_Str(numb, ops, instance, lawLine)
def reinstance(inst: Instance[String, scala.collection.immutable.List[String]]) = new Test_Imm_List_Str(num, ops, inst, lawLine)
@Ichoran
Ichoran / openworm_wcon_iwm_2017.md
Created March 16, 2017 16:40
Abstract of IWM 2017 for OpenWorm WCON project

A Common Format for Worm Tracking Data

Michael Currie (1a), Rex A. Kerr (2), Chee Wai Lee (1b), Jim Hokanson(1c), and Andrew E.X. Brown (3).

  1. OpenWorm (a. Somewhere; b. Somewhere Else; c. Somewhere Yet Again)
  2. Calico Life Sciences
  3. Imperial College London

Many labs, including ours, have built a wide variety of worm trackers.

@Ichoran
Ichoran / Ranged.scala
Created January 25, 2017 04:42
Quick and dirty benchmark of different approaches to Range specialization
package test
class Super[+A] {
def foreach[U](f: A => U): Unit = ???
}
final class Ranged(i0: Int, iN: Int) extends Super[Int] {
override def foreach[@specialized(Unit) U](f: Int => U) {
var i = i0
while (i < iN) {
@Ichoran
Ichoran / GroupByBench.scala
Created November 14, 2016 19:07
Benchmarks for groupBy / map getOrElseUpdate slowdown
import ichi.bench._
object GroupByBench {
class Sum(var value: Int = 0) {
def ++(): this.type = { value += 1; this }
}
val a1k = Array.tabulate(1024)(i => ((i*7) % 13).toString)
val l1k = a1k.toList
val v1k = a1k.toVector