Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Konovalov alexknvl

View GitHub Profile
View backprop.cpp
#include <iostream>
#include <cmath>
#include <vector>
#include <cassert>
#include <memory>
enum NodeOp {
OP_CONST,
OP_ADD,
OP_MUL,
View sigma5.py
@numba.jit("i4(i4, i4)", nopython=True, nogil=True)
def gcd(a, b):
while True:
if a == 0: return b
if b == 0: return a
if a == b: return a
if b > a:
a, b = a, b % a
else:
a, b = a % b, b
View Free Free.scala
sealed trait Free[+F[_], A]
object Free {
def eval[F[_], A](fa: Free[F, A])(implicit F: Monad[F]): F[A] = {
type State = (Free[F, Any], List[Any => Free[F, Any]])
def go(s: State): F[Either[State, Any]] = s match {
case (current, stack) =>
current match {
case Done(a) =>
stack match {
case Nil =>
View Lazy-Step1.scala
///////////////////////////////////////////////////////////////////
// STEP 1 - Evaluation by need monad
///////////////////////////////////////////////////////////////////
import scala.annotation.unchecked.{ uncheckedVariance => uV }
final class Need[+A](private[this] var thunk: Need.Thunk[A @uV]) { A =>
import Need._
def value: A = thunk match {
case Done(x) => x
View zio-prelude.md
  1. def hash(a: A): Int makes me sad. What about hashing to 64 bits or SL2 Fp?
  2. def MapHash[A, B: Hash]: Hash[Map[A, B]] is a bit odd. Why not A: Hash?
  3. reflexiveLaw + symmetryLaw + transitivityLaw is too weak for "equality". This defines a general equivalence relationship only.
  4. val AnyEqual: Equal[Any] is worrisome, considering all the resolution bugs!
  5. val DoubleEqual: Equal[Double] should be implemented using java.lang.Double.doubleToRawLongBits.
  6. A combintation of [trait Ord[-A] extends Equal[A]](https://github.com/zio/zi
View SingletonEquality.scala
// This sums up my understanding of
// https://github.com/lampepfl/dotty/issues/9359
// and https://github.com/lampepfl/dotty/issues/8430
// == on AnyVal does not imply singleton type equality
class Test[A](val x: Int) extends AnyVal
def coerce1[A, B](a: A): B = {
val x = new Test[A](1)
val y = new Test[B](1)
View ParseInt.scala
trait CharReader {
def current(): Int
def advance(): Unit
}
object CharReader {
final val EOF: Int = -1
final val EOB: Int = -2
@silent final class FromString(val text: String, end: Int) extends CharReader {
var index = 0
View hasse.py
from itertools import *
# Compute our D(pi) function
elements = {}
for p in permutations([1,2,3,4]):
d = [i+1 for i in range(3) if p[i] > p[i + 1]]
elements[p] = frozenset(d)
# Make a graph with the given pi < tau relation.
graph = {}
View MuFixEqLazy.scala
import cats.Eval
import cats.syntax.all._
trait Eq[A] {
def eqv(x: A, y: A): Eval[Boolean]
}
trait Eq1[F[_]] {
def eqv1[A](x: F[A], y: F[A])(implicit A: Eq[A]): Eval[Boolean]
}
View MuFixEq.scala
import cats.Eq
trait Eq1[F[_]] {
def eqv1[A](x: F[A], y: F[A])(implicit A: Eq[A]): Boolean
}
final case class Fix[F[_]](unfix: F[Fix[F]])
object Fix {
implicit def eqv[F[_]: Eq1]: Eq[Fix[F]] = new Eq[Fix[F]] {
def eqv(x: Fix[F], y: Fix[F]): Boolean =
You can’t perform that action at this time.