Skip to content

Instantly share code, notes, and snippets.

infixr 4 %%@~, <%@~, %%~, <+~, <*~, <-~, <//~, <^~, <^^~, <**~
infix 4 %%@=, <%@=, %%=, <+=, <*=, <-=, <//=, <^=, <^^=, <**=
infixr 2 <<~
infixr 9 #.
infixl 8 .#
infixr 8 ^!, ^@!
infixl 1 &, <&>, ??
infixl 8 ^., ^@.
infixr 9 <.>, <., .>
infixr 4 %@~, .~, +~, *~, -~, //~, ^~, ^^~, **~, &&~, <>~, ||~, %~
{-# LANGUAGE RankNTypes, StandaloneDeriving, TemplateHaskell, UndecidableInstances #-}
module Data.Tree.Diverse
( Node(..), _Node
, Children(..), overChildren
, Ann(..), ann, val
) where
import qualified Control.Lens as Lens
import Data.Functor.Const (Const(..))
@yairchu
yairchu / bug.c
Created August 5, 2018 15:49
IPP sqrt bug
#include <stdio.h>
#include "ipps.h"
int main()
{
float t;
(*(int*)&t) = 3116044;
printf ("%g %g\n", t, sqrtf (t));
IppStatus status = ippsSqrt_32f_I (&t, 1);
printf ("%g %d\n", t, status);
@yairchu
yairchu / ast-parsing-with-prisms.hs
Last active December 29, 2019 15:17
Parsing a simple AST with Prisms (without detailed syntax error reporting)
{-# LANGUAGE RankNTypes, TupleSections, TemplateHaskell, DeriveGeneric #-}
import Control.Applicative
import Control.Lens
import qualified Data.Char as Char
import GHC.Generics
import Test.QuickCheck
import Test.QuickCheck.Arbitrary.ADT
data Expr
@yairchu
yairchu / verboseprism.hs
Last active September 6, 2023 07:57
Prisms with error reporting
{-# LANGUAGE
RankNTypes,
TypeFamilies,
DeriveFunctor,
FlexibleContexts,
DefaultSignatures,
FlexibleInstances,
MultiParamTypeClasses
#-}
@yairchu
yairchu / test.cpp
Last active May 3, 2021 11:53
operator<< for STL types
#include <iostream>
#include <map>
#include <vector>
// Adding forward declarations would make this compile
// template <typename K, typename V>
// std::ostream& operator<< (std::ostream&, const std::map<K, V>&);
// template <typename T>
import autograd
import autograd.numpy as np
import numpy as orig_np
import xarray as xr
def patch_for_xarray_autograd_interop():
def autograd_nanmean(x, *args, dtype=None, **kwargs):
r = np.mean(x[np.isfinite(x)], *args, **kwargs)
if dtype is not None: