Skip to content

Instantly share code, notes, and snippets.

ezyang-mbp:labs ezyang$ cat a.kk
fun f(x: list<int>) : int {
match(x) {
Nil() -> 0
Cons(_, _) -> 1
}
}
fun reuse( g : list<int> -> int, x : list<int>) : (int, int) {
(f(x), g(x))
ezyang-mbp:labs ezyang$ cat a.kk
fun f(x: list<int>) : int {
length(x)
}
fun reuse( g : list<int> -> int, x : list<int>) : (int, int) {
(f(x), g(x))
}
ezyang-mbp:labs ezyang$ koka -O2 -l -c --showcore a.kk
compile: a.kk
from dataclasses import dataclass
from typing import List, Tuple, Union, Dict, Iterator, Optional
import sys
import itertools
Id = int
class UnionFind:
parents: List[Id]
% Solution to https://teammatehunt.com/puzzles/icebreaker
#script (python)
def main(ctl):
ctl.ground([("base", [])])
seen = set()
with ctl.solve(yield_=True) as h:
for m in h:
terms = m.symbols(shown=True)
terms.sort()
person(alice; bob; carol; david).
number(alice, 2).
number(bob, 3).
number(carol, 5).
number(david, 7).
distinct(A, B, C, D)
:- number(A, NA), number(B, NB), number(C, NC), number(D, ND),
NA * NB * NC * ND = 210.
% solution for https://puzzlehunt.club.cc.cmu.edu/puzzle/15011/
#script (python)
from clingo import Function
from collections import defaultdict
import operator
from colored import bg, attr
MAP = """
..B#.~....
% solution for https://puzzlehunt.club.cc.cmu.edu/puzzle/15026/
% define a 6x6 grid, and compass directions on this grid
row(1..6).
col(1..6).
dir(n;e;s;w).
delta(n, -1, 0).
from dataclasses import dataclass
from typing import Generator, TypeVar, Any, Callable, Optional, cast, NamedTuple, Dict, Type, Tuple, Generic
R = TypeVar("R")
Eff = Generator[Tuple[Any, ...], Any, R]
def handle_op(
g: Eff[R],
op: Tuple[Any, ...],
# Translation of JIT type to a C++ argument type.
# TODO: remove use_c10_dispatcher_full kwarg from this function; type
# translation ideally doesn't depend on this
def argument_type(t: Type, *, mutable: bool, use_c10_dispatcher_full: bool) -> str:
# If it's a value type, do the value type translation
r = cpp_value_type(t)
if r is not None:
return r
if isinstance(t, BaseType):
diff --git a/build/aten/src/ATen_new/Functions.cpp b/build/aten/src/ATen/Functions.cpp
index 240605711c..2d3aacf897 100644
--- a/build/aten/src/ATen_new/Functions.cpp
+++ b/build/aten/src/ATen/Functions.cpp
@@ -188,7 +188,7 @@ Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_see
static auto op = c10::Dispatcher::singleton()
.findSchemaOrThrow("aten::_cudnn_init_dropout_state", "")
.typed<Tensor (double, bool, int64_t, c10::optional<ScalarType>, c10::optional<Layout>, c10::optional<Device>, c10::optional<bool>)>();
- return op.call(dropout, train, dropout_seed, dtype, layout, device, pin_memory);
+ return op.call(dropout, train, dropout_seed, optTypeMetaToScalarType(options.dtype_opt()), options.layout_opt(), options.device_opt(), options.pinned_memory_opt());