<div>should move </div><span style> dvar_vector y(1,n+m-1);</span><div><br></div><div>after following lines<br style><span style> m=size_count(x);</span><br style><span style> n=size_count(h);</span></div><div><br></div>
<div><br></div><div>weihai<br style><br><div class="gmail_quote">On Fri, May 25, 2012 at 4:41 AM, Øigård Tor Arne <span dir="ltr"><<a href="mailto:tor.arne.oeigaard@imr.no" target="_blank">tor.arne.oeigaard@imr.no</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I tried to implement a convolution in the GLOBAL_SECTION so that I can call a function conv(x,h) in the PROCEDURE_SECTION. The program compiles, but does not run, get the error message "size of file cmpdiff.tmp = 0" in the log.<br>
<br>
I read in two vectors x and h in the DATA_SECTION and want to create a vector y = conv(x,h) in the PROCEDURE_SECTION. The variable y has been declared as a vector in the PARAMETER_SECTION. In the GLOBAL_SECTION i added:<br>
<br>
#include <admodel.h><br>
<br>
dvar_vector conv1(const dvar_vector& x, const dvar_vector& h)<br>
{<br>
<br>
int k,j,m,n;<br>
dvector lowerlimit(1,2);<br>
dvector upperlimit(1,2);<br>
dvar_vector y(1,n+m-1);<br>
<br>
m=size_count(x);<br>
n=size_count(h);<br>
<br>
for(k=1;k<=(int) (m+n-1);k++)<br>
{<br>
y(k) = 0;<br>
lowerlimit(1) = 1;<br>
lowerlimit(2) = k+1-n;<br>
upperlimit(1) = k;<br>
upperlimit(2) = m;<br>
<br>
for(j=max(lowerlimit);j<=(int) min(upperlimit);j++)<br>
{<br>
y(k) = y(k) + x(j)*h(k-j+1);<br>
}<br>
}<br>
<br>
return y;<br>
<br>
}<br>
<br>
So the local variable y in the function is declared as a dvar_vector, and the function is declared as a dvar_vector. I wonder if the problem has something to do with that.<br>
<br>
I tried to make another conv-function (below) which only returns one element of the output vector y, i.e., y_i, instead of the whole vector y, and then run a loop in the PROCEDURE_SECTION (the first loop in the conv1-function was moved to the PROCEDURE_SECTION). In this scenario the function conv2 is declared as a dvariable, and the local variable y (scalar) is declared as a dvariable. In this case it worked like a charm. Hence, it looks like I do something wrong when declaring the variables for the conv1-function. I also tried to replace the dvar_vector declaration for the conv1 and the local y vector with a dvector, but that did not help much.<br>
<br>
<br>
dvariable conv2(const dvar_vector& x, const dvar_vector& h, const double& k)<br>
{<br>
<br>
int j,m,n;<br>
dvector lowerlimit(1,2);<br>
dvector upperlimit(1,2);<br>
dvariable y;<br>
<br>
m=size_count(x);<br>
n=size_count(h);<br>
<br>
y = 0;<br>
lowerlimit(1) = 1;<br>
lowerlimit(2) = k+1-n;<br>
upperlimit(1) = k;<br>
upperlimit(2) = m;<br>
<br>
<br>
for(j=max(lowerlimit);j<=(int) min(upperlimit);j++)<br>
{<br>
y = y + x(j)*h(k-j+1);<br>
}<br>
<br>
return y;<br>
<br>
}<br>
<br>
Any good advice is very much appreciated.<br>
<br>
Kind regards,<br>
Tor Arne<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@admb-project.org">Users@admb-project.org</a><br>
<a href="http://lists.admb-project.org/mailman/listinfo/users" target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
</blockquote></div><br></div>