Anonymous user
Deconvolution/2D+: Difference between revisions
m
→{{header|D}}: minor change again
m (→{{header|D}}: minor change) |
m (→{{header|D}}: minor change again) |
||
Line 84:
<lang d>import std.stdio, std.conv ;
import std.array, std.algorithm, std.numeric, std.range ;
size_t[] seq2idx(size_t seq, const size_t[] subSize) {▼
size_t acc = seq, tmp ;▼
size_t[] idx ;▼
foreach(e ; subSize) {▼
idx ~= tmp = acc / e ;▼
acc = acc - tmp*e ; // same as % (mod) e ;▼
}▼
return idx ;▼
foreach(i;0..dm.length)▼
res ~= reduce!"a*b"(1,dm[i+1..$]) ;▼
class M(T) {
Line 120 ⟶ 103:
assert(e > 0, "no zero dimension") ;
dim = dimension.dup ;
subsize =
auto dlength = dim[0] * subsize[0] ;
if(d.length != dlength)
Line 131 ⟶ 116:
d[0..minLen] = t[0..minLen] ;
return this ;
▲ }
▲ size_t acc = seq, tmp ;
▲ size_t[] idx ;
▲ idx ~= tmp = acc / e ;
▲ acc = acc - tmp*e ; // same as % (mod) e ;
}▼
▲ return idx ;
}
Line 157 ⟶ 152:
return dim == rhs.dim && d == rhs.d ;
}
int opApply(int delegate(ref size_t[]) dg) {
size_t[] yieldIdx ;
foreach(i;0..d.length) {
yieldIdx = seq2idx(i
if(dg(yieldIdx))
break ;
Line 182 ⟶ 177:
auto bound = m.size ;
foreach(i;0..d.length) {
auto thisIdx = seq2idx(i
foreach(j;0..rhs.d.length) {
dm[] = thisIdx[] + rhs.seq2idx(j
auto midx1d = dotProduct(dm, m.subsize) ;
if( midx1d < bound)
Line 203 ⟶ 198:
foreach(i;0..m.size) {
auto idx = m.seq2idx(i
m.d[i] = this[idx] ;
foreach(j;0..i) {
auto jdx = m.seq2idx(j
dm[] = idx[] - jdx[];
if(rhs.checkBound(dm))
|