Name: Anonymous 2014-07-22 13:29
Can be yours or not, I just want to see something good.
use prelude compiler reader macro
GRootFolder = Void
GSrcFolders = Void
GDstFolder = Void
GHeaderTimestamp = Void
GMacros = Void
read_normalized Text =
| Expr = read Text
| case Expr [`|` @As] Expr
X [`|` X]
skip_macros Xs = Xs.skip{X => X.1.is_macro}
// FIXME: do caching
get_lib_exports LibName =
| for Folder GSrcFolders
| LibFile = "[Folder][LibName].s"
| when file_exists LibFile
| Text = load_text LibFile
| Expr = read_normalized Text
| leave: case Expr.last [export @Xs] | skip_macros Xs
Else | Void
| bad "no [LibName].s"
c_runtime_compiler Dst Src =
| RtFolder = "[GRootFolder]runtime"
| unix "gcc -O1 -Wno-return-type -Wno-pointer-sign -I '[RtFolder]' -g -o '[Dst]' '[Src]'"
c_compiler Dst Src =
| RtFolder = "[GRootFolder]runtime"
| unix "gcc -O1 -Wno-return-type -Wno-pointer-sign -I '[RtFolder]' -g -fpic -shared -o '[Dst]' '[Src]'"
file_older Src Dst =
| DstDate = if file_exists Dst then file_time Dst else 0
| Src^file_time << DstDate and GHeaderTimestamp << DstDate
compile_runtime Src Dst =
| when file_older Src Dst: leave Void
| say "compiling runtime..."
| Result = c_runtime_compiler Dst Src
| when Result <> "": bad Result
add_imports Expr Deps =
| unless Deps.size: leave Expr
| [[_fn (map D Deps D.1) Expr]
@(map D Deps [_import [_quote D.0] [_quote D.1]])]
compile_expr Name Dst Expr =
| Uses = [core]
| Expr <= case Expr
[`|` [use @Us] @Xs]
| Uses <= [@Uses @Us]
| [`|` @Xs]
Else | Expr
| Deps = Uses.tail
| for D Deps: unless compile_module D: bad "cant compile [D].s"
| say "compiling [Name]..."
| Imports = (map U Uses: map E U^get_lib_exports: [U E]).join
| Imports = Imports.keep{X => X.1.is_text} // skip macros
| ExprWithDeps = add_imports Expr Imports
| ExpandedExpr = macroexpand ExprWithDeps GMacros
| CFile = "[Dst].c"
| ssa_produce_file CFile ExpandedExpr
| Result = c_compiler Dst CFile
| unless file_exists Dst: bad "[CFile]: [Result]"
| Deps
load_symta_file Filename =
| Text = load_text Filename
| read_normalized Text
compile_module Name =
| for Folder GSrcFolders
| SrcFile = "[Folder][Name].s"
| when file_exists SrcFile
| DstFile = "[GDstFolder][Name]"
| DepFile = "[DstFile].dep"
| when file_exists DepFile
| Deps = DepFile^load_symta_file.1
| CompiledDeps = map D Deps: compile_module D
| when file_older SrcFile DstFile and CompiledDeps.all{X => have X and file_older X DstFile}:
| leave DstFile
| Expr = load_symta_file SrcFile
| Deps = compile_expr Name DstFile Expr
| DepsText = Deps.infix{' '}.unchars
| save_text DepFile DepsText
| leave DstFile
| Void
build BuildFolder =
| let GMacros 'macro'^load_library.keep{X => X.1.is_macro}.as_table
GRootFolder '/Users/nikita/Documents/git/symta/'
GSrcFolders ["[BuildFolder]src/" "[GRootFolder]src/"]
GDstFolder "[BuildFolder]lib/"
GHeaderTimestamp (file_time "[GRootFolder]/runtime/runtime.c")
| RuntimeSrc = "[GRootFolder]/runtime/runtime.c"
| RuntimePath = "[BuildFolder]run"
| compile_runtime RuntimeSrc RuntimePath
| DstFile = compile_module main
| when no DstFile: bad "cant compile main.s"
| unix "[RuntimePath] '[GDstFolder]'"
export build
// /Users/nikita/Documents/git/symta/build/test/src/main.s
use build
// compile self second time
build "/Users/nikita/Documents/git/symta/build/test2/"
(
s.waitForBoot{
// stack of detuned sins
SynthDef(\bd, {
arg out = 0, amp= 1, pan = 0, attack = 0, rel= 0.1,
freq = 160, click = 0, depth = 3, detune = 10;
var env, layers, sig;
env = EnvGen.ar(Env.perc(0, rel, amp, -10), doneAction:2);
layers = [];
depth.do {|i|
layers = layers ++ SinOsc.ar(i * detune + freq, click, env);
};
Out.ar(out, Pan2.ar(Mix(layers), 0));
}).add;
// 3 detuned swooping sins
SynthDef(\bd2, {|amp= 1, rel= 0.1, freq = 160, click = 0|
var e= EnvGen.ar(Env.perc(0, rel, amp, -10), doneAction:2);
var layers = [
SinOsc.ar(Line.kr(freq - 10 * 2, freq - 10, rel), click, e*0.4),
SinOsc.ar(Line.kr(freq * 2, freq, rel), click, e*0.4),
SinOsc.ar(Line.kr(freq + 10 * 2, freq + 10, rel), click, e*0.4),
];
var z= Mix(layers);
Out.ar(0, Pan2.ar(z, 0));
}).add;
SynthDef(\bz, {|amp= 1, rel= 0.25, freq= 400|
var e= EnvGen.ar(Env.perc(0.01, rel, amp), doneAction:2);
var z= BPF.ar(Blip.ar(e+1*(freq*0.1), 3), freq*2, 0.1, amp*10*e);
Out.ar(0, Pan2.ar(z, 0));
}).add;
// 5k bpf whitenoise
SynthDef(\hh, {|amp= 1, rel= 0.05|
var e= EnvGen.ar(Env.perc(0, rel, amp, -10), doneAction:2);
var z= WhiteNoise.ar(e);
z= BPF.ar(z, 5000, 0.4);
Out.ar(0, Pan2.ar(z, 0, 1.5));
}).add;
SynthDef(\clap, {|out=0, amp=1, rel=0.2|
var e= EnvGen.ar(Env.perc(0.01, rel, amp), doneAction:2);
var sig=BPF.ar(PinkNoise.ar(e), Line.kr(300, 30, rel), 4);
Out.ar(out, Pan2.ar(sig, 0));
}).add;
};
)
(
t = TempoClock.default;
t.tempo = 135 / 60;
)
(
~bd.stop;
~bd = Pbind(
\instrument, \bd,
// \dur, Pseq(#[1, 1, 1, 1], inf),
// \dur, Pseq(#[1, 1, 1, 0.75, 0.25], inf),
// \click, Pseq(#[0, 0, 0.1, 0.1, 0.2], inf),
\dur, Pseq(#[1, 1, 0.75, 0.25, 0.5, 0.5], inf),
\amp, 0.6,
// \dur, Pseq(#[1, 1, 1, 0.5, 0.5], inf),
// \dur, Pseq(#[1, 1, 0.5, 0.5, 0.5, 0.5], inf),
).play(t, quant: 4);
)
(
~hh.stop;
~hh = Pbind(
\instrument, \hh,
\amp, Pseq(0.15 * [0, 1], inf).value,
\dur, 0.5,
).play(t, quant: 4);
)
(
~clap.stop;
~clap = Pbind(
\instrument, \clap,
\dur, 2,
\amp, 1,
\rel, Pseq([0.1, 0.1, 0.07, 0.15], inf),
).play(t, quant: [4, 1]);
)
(
~bd2.stop;
~bd2 = Pbind(
\instrument, \bd2,
\amp, 0.6,
).play(t, quant: [4, 0.48]);
)
(
~bz.stop;
~bz = Pbind(
\instrument, \bz,
\amp, Pseq([0, 0, 1, 0, 1], inf),
\dur, 0.5,
).play(t, quant: 4);
)
Prominent organizations and products that use PostgreSQL as the primary database include:
International Space Station
I'm not on any medicationJust whom are you kidding, American? You all are constantly on medication because the pharmaceutical industry controls your mind and turns you into pill-gulping drug addicts for life.
%%data = [1,0,0,1; 1,0,1,0]
%%data = rand(8,4)
n = size(data, 1);
m = size(data, 2);
neurons = 50;
decay = 0.95;
lr = 0.2;
weights = [];
weights(1:m, 1:neurons) = 0;
weights = randn(size(weights)) ./ 100.0;
delta = zeros(size(weights));
pdata = [];
batchsize = 2000;
blocki = [1:batchsize];
for(iter=1:2000)
blocki = mod(blocki .+ batchsize, n) .+ 1;
shortdata = data(blocki, :);
insig1b = shortdata * weights;
sig1b = sigmoid(insig1b);
pos = shortdata' * sig1b;
insig2a = sig1b * weights';
sig2a = sigmoid(insig2a);
insig2b = sig2a * weights;
sig2b = sigmoid(insig2b);
%% neg = data' * sig2b; %%??
neg = sig2a' * sig2b;
delta = delta .* decay .+ ((pos .- neg) ./ n) .* lr;
weights = weights .+ delta;
pdata(iter) = sum(abs(shortdata(:) .- sig2a(:)) ./ (batchsize * m));
fprintf("%citer %i, err %i / 100 ", 13, iter, pdata(iter) * 100);
endfor;
hold on;
plot(pdata, '-b')
#include <stdio.h>
int main(void)
{
int i = 0;
do if(++i-2>2<<2) break;
while (printf("%d\n",i));
}