Skip to content

Instantly share code, notes, and snippets.

@nebuta
nebuta / halide-examples.cpp
Last active December 20, 2015 15:18
Halide simple examples of pointwise opreation, image IO, and stencil operation.
#include <Halide.h>
#include <cstdio>
using namespace Halide;
#include "image_io.h"
#include <sys/time.h>
double currentTime() {
timeval t;
gettimeofday(&t, NULL);
@nebuta
nebuta / halide-schedule.cpp
Created August 4, 2013 04:33
Halide simple example
// Modified from tutorials/lesson_02.cpp and test/vectorize.cpp
// On linux, you can compile and run it like so:
// g++ -I ../include -L ../bin -lHalide -lpthread -ldl -lpng blur.cpp
// LD_LIBRARY_PATH=../bin ./lesson_02
// On os x:
// g++ -I ../include -L ../bin -lHalide `libpng-config --cflags --ldflags` blur.cpp
// DYLD_LIBRARY_PATH=../bin ./lesson_02
@nebuta
nebuta / reify2-rws.hs
Last active December 20, 2015 12:09
Reification of AST using a RSW monad.
{-# LANGUAGE OverloadedStrings,GADTs,FlexibleInstances #-}
import Data.List (intercalate,foldl1)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Map (Map)
import qualified Data.Map as M
import Control.Monad.RWS
import Control.Monad.State.Class
@nebuta
nebuta / reify.hs
Created August 1, 2013 04:40
Example of Reification of AST.
{-# LANGUAGE OverloadedStrings,GADTs,FlexibleInstances #-}
import Data.List (intercalate)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
type Ident = Text
-- 2D matrix
@nebuta
nebuta / ast-gadt.hs
Created July 27, 2013 21:24
Typed AST with GADT in Haskell
{-# LANGUAGE GADTs #-} -- You need GADTs pragma.
data Exp r where
Const :: (Show r) => r -> Exp r
Add :: (Num r) => Exp r -> Exp r -> Exp r
Subtract :: (Num r) => Exp r -> Exp r -> Exp r
Eq :: (Eq r) => Exp r -> Exp r -> Exp Bool
And :: Exp Bool -> Exp Bool -> Exp Bool
Or :: Exp Bool -> Exp Bool -> Exp Bool
@nebuta
nebuta / ast-no-gadt.hs
Created July 27, 2013 21:17
Haskell AST basic example
data Exp r = Const r | Add (Exp r) (Exp r) | Subtract (Exp r) (Exp r)
eval :: (Num r) => Exp r -> r
eval (Const v) = v
eval (Add e1 e2) = (eval e1) + (eval e2)
eval (Subtract e1 e2) = (eval e1) - (eval e2)
reify :: (Show r) => Exp r -> String
reify (Const v) = show v
reify (Add e1 e2) = concat ["(",reify e1,"+",reify e2,")"]
@nebuta
nebuta / gadt-dsl.hs
Last active December 20, 2015 04:09
Prototype of typed EDSL in Haskell for Matlab code generation.
{-# LANGUAGE NoImplicitPrelude,OverloadedStrings,GADTs,MultiParamTypeClasses,FlexibleInstances #-}
-- GADTを使った型付きDSLのごく簡単なプロトタイプ。
-- 出力のロジックに、この記事のアイデア・実装を一部利用: http://d.hatena.ne.jp/keigoi/20111206/haskell_tagless_dsl
import BasicPrelude as B
import Prelude (Show(..))
import Control.Monad.Writer
import Control.Monad.State
@nebuta
nebuta / find.hs
Last active December 19, 2015 05:58
Haskell equivalent of Ruby's Find.find()
import System.Directory
import Control.Monad
import Data.Maybe
import Data.List
filesep :: String
filesep = "/"
findUnder :: FilePath -> (FilePath -> IO (a,Bool)) -> IO [a]
findUnder dir func = do
@nebuta
nebuta / yesod-log.txt
Created May 29, 2013 10:38
Yesod 1.2 cabal install log
nebutas-MacBook-Air:~ nebuta$ time sudo cabal install yesod-platform yesod-bin
Resolving dependencies...
Configuring SHA-1.6.1...
Building SHA-1.6.1...
Preprocessing library SHA-1.6.1...
[1 of 1] Compiling Data.Digest.Pure.SHA ( Data/Digest/Pure/SHA.hs, dist/build/Data/Digest/Pure/SHA.o )
[1 of 1] Compiling Data.Digest.Pure.SHA ( Data/Digest/Pure/SHA.hs, dist/build/Data/Digest/Pure/SHA.p_o )
In-place registering SHA-1.6.1...
Running Haddock for SHA-1.6.1...
Preprocessing library SHA-1.6.1...
@nebuta
nebuta / tweet.json
Created May 19, 2013 08:04
Jubatus Twitter classification test
{
"method": "AROW",
"converter": {
"num_filter_types": {},
"num_filter_rules": [],
"string_filter_types": {},
"string_filter_rules": [],
"num_types": {},
"num_rules": [],