Skip to content

Instantly share code, notes, and snippets.

function partest(model, corpus)
for i=1:numel(corpus)
sentence = corpus{i};
parser = initparser(model, sentence);
while 1
valid = validmoves(parser);
if ~any(valid) break; end
x = getfeatures(parser, sentence, model);
scores = predict(model, x);
scores(~valid) = -inf;
function foo = bar(x)
foo=x*x;
end
function foo = bar(baz)
foo = baz * baz;
end
% Here is our weight matrix:
>> w=randn(20000,1000);
% Here is our instance:
>> x=randn(1000,1);
% Try multiplying them on cpu:
>> tic; for i=1:10000 y=w*x; end; toc;
Elapsed time is 59.851655 seconds.
% Try multiplying them on gpu:
>> gw = gpuArray(w);
function partest2(model, corpus, batchsize)
batches = ceil(numel(corpus)/batchsize);
for batch=1:batches
% Initialize a batch of sentences and parsers:
bstart = (batch-1)*batchsize+1;
bend = min(batch*batchsize, numel(corpus));
sentences = corpus(bstart:bend);
nsentences = numel(sentences);
parsers = cell(1, nsentences);
for i=1:nsentences
function forw(l::Layer, x, apply_fx=true)
initforw(l, x)
isdefined(l,:fx) && apply_fx && l.fx(l,x)
@into! l.y = l.w * x
isdefined(l,:b) && (@in1! l.y .+ l.b)
isdefined(l,:f) && l.f(l,l.y)
l.x = x
return l.y
end
(gdb) bt
#0 0x00007ffff6dd134c in jl_gc_alloc_1w () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#1 0x00007ffdec4a9e4a in ?? ()
#2 0x0000000100000001 in ?? ()
#3 0x00007ffdefeb9b60 in ?? ()
#4 0x00007ffdeffe0cf0 in ?? ()
#5 0x00007ffdeffe0c00 in ?? ()
#6 0x01007ffdf08b67c0 in ?? ()
#7 0x00007ffdf01528f0 in ?? ()
#8 0x0000000000000060 in ?? ()
#0 0x00007ffff6cf9995 in inst_datatype () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#1 0x00007ffff6cfa207 in jl_inst_concrete_tupletype_v ()
from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#2 0x00007ffff6d116a2 in jl_f_tuple () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#3 0x00007fffee048b1d in zeros () at array.jl:211
#4 0x00007ffdec4a74d9 in ?? ()
#5 0x00007ffdec534010 in ?? ()
#6 0x00007ffdf02229f0 in ?? ()
#7 0x00007fffffffd0f0 in ?? ()
#8 0x00007ffff6d01afb in cache_match () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#0 0x00007ffff6cf90cc in lookup_type_idx () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#1 0x00007ffff6cf9221 in lookup_type () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#2 0x00007ffff6cf99dd in inst_datatype () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#3 0x00007ffff6cfa207 in jl_inst_concrete_tupletype_v ()
from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#4 0x00007ffff6d116a2 in jl_f_tuple () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#5 0x00007fffee0360f4 in call () at bitarray.jl:12
#6 0x00007ffdec4b16c3 in ?? ()
#7 0x000000000000000a in ?? ()
#8 0x00007fffffffd030 in ?? ()
#0 0x00007ffff6cf8da2 in typekey_compare () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#1 0x00007ffff6cf90e6 in lookup_type_idx () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#2 0x00007ffff6cf9221 in lookup_type () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#3 0x00007ffff6cf99dd in inst_datatype () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#4 0x00007ffff6cfa207 in jl_inst_concrete_tupletype_v ()
from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#5 0x00007ffff6d116a2 in jl_f_tuple () from /auto/nlg-05/dy_052/julia/v0.4.0-rc3/bin/../lib/julia/libjulia-debug.so
#6 0x00007ffdec4a584f in ?? ()
#7 0x00007fffffffd240 in ?? ()
#8 0x0000000000000002 in ?? ()