Type patterns does incorrect dimension computation
sac2c 1.3.3-MijasCosta-1143-g21fdd4
build-type: DEBUG
built-by: "thomas" at 2024-01-30T10:37:51
Following program throws runtime error *** Type pattern error in application of MultiConv: feature \
b:bshp' in return value does not match feature `b' in in`
use StdIO: all;
use Array: all;
noinline
float[m:mshp,n:oshp,b:bshp] MultiConv(float[n:ishp,b:bshp] in,
float[m:mshp,n:wshp] weights,
float[m:mshp] bias)
| all(oshp == ishp - wshp + 1)
{
printf("m = %d, n = %d, b = %d\n", m, n, b);
x = {iv -> Convolve(in, weights[iv]) + bias[iv] | iv < mshp};
print(shape(x));
return x;
}
noinline
float[n:oshp,b:bshp] Convolve(float[n:ishp,b:bshp] in, float[n:wshp] weights)
{
oshp = ishp - wshp + 1;
// return {iv -> rsum(n, {jv -> weights[jv] * in[iv + jv]}) | iv < oshp};
return {iv -> sum({jv -> weights[jv] * in[iv + jv]}) | iv < oshp};
}
int main()
{
in = genarray([28, 28], 0f);
weights = genarray([6, 5, 5], 0f);
bias = genarray([6], 0f);
print(MultiConv(in, weights, bias));
return 0;
}
Generated guard shows
_rtpf_0_pred = ( _eq_SxS_( b, _sub_SxS_( _dim_A_( _rtpf_1_ret), _sub_SxS_( m, n))) ? _rtpf_0_pred : _guard_error_( _|_ /* Type pattern error in application of MultiConv: feature `b:bshp' in return value does not match feature `b' in in */) );
or in other words checks that b == dim(out) - (m - n)
while it should be b == dim(out) - (m + n)
.