예제 #1
0
/**
Allocate matrix on integers with dimension [nrl to nrh] x [ncl to nch].
\param nrl lower row matrix index
\param nrh upper row matrix index
\param ncl lower column matrix index
\param nch upper column matrix index
*/
void imatrix::allocate(
  const ad_integer& nrl, const ad_integer& nrh,
  const index_type& ncl, const index_type& nch)
{
  if (nrl > nrh)
  {
    allocate();
  }
  else
  {
    index_min = nrl;
    index_max = nrh;
    if ((ncl.isinteger() && (nrl != ncl.indexmin() || nrh != ncl.indexmax()))
       || (nch.isinteger() && (nrl != nch.indexmin() || nrh != nch.indexmax())))
    {
      cerr << "Incompatible imatrix bounds in " << __FILE__ << ':' << __LINE__ << ".\n";
      if(nrh==0) 
      {
        // Some models use 0 for columns to "turn off" a parameter, so we
        // don't want to exit in this case, just throw error.
        cerr << "0 columns - was this intentional?\n" ;
      }
      else
      {
        ad_exit(1);
      }
    }
    unsigned int ss = static_cast<unsigned int>(nrh - nrl + 1);
    if ((m = new ivector[ss]) == 0)
    {
      cerr << " Error: imatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    if ((shape = new mat_shapex(m)) == 0)
    {
      cerr << " Error: imatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    m -= int(nrl);
    for (int i = nrl; i <= nrh; ++i)
    {
      m[i].allocate(ncl(i), nch(i));
    }
  }
}
예제 #2
0
/**
Allocate array of matrices with dimensions
[sl to sh] x [nrl to nrh] x [ncl to nch].
\param sl lower vector index
\param sh upper vector index
\param nrl lower matrix row index
\param nrl upper matrix row index
\param ncl lower matrix column index
\param ncl upper matrix column index
*/
void i3_array::allocate(
  int sl, int sh,
  const index_type& nrl, const index_type& nrh,
  const index_type& ncl, const index_type& nch)
{
  if (sl > sh)
  {
    allocate();
  }
  else
  {  
    if ((nrl.isinteger() && (sl !=nrl.indexmin() || sh !=nrl.indexmax()))
       || (nch.isinteger() && (sl !=nch.indexmin() || sh !=nch.indexmax()))
       || (ncl.isinteger() && (sl !=ncl.indexmin() || sh !=ncl.indexmax()))
       || (nrh.isinteger() && (sl !=nrh.indexmin() || sh !=nrh.indexmax())))
    {
      cerr << "Incompatible i3_array bounds in " << __FILE__ << ':' << __LINE__ << ".\n";
      ad_exit(1);
    }
    if ((shape = new three_array_shape(sl,sh)) == 0)
    {
      cerr << " Error: d3_array unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    if ((t = new imatrix[slicesize()]) == 0)
    {
      cerr << " Error: d3_array unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    t -= slicemin();
    for (int i = sl; i <= sh; ++i)
    {
      t[i].allocate(nrl(i), nrh(i), ncl(i), nch(i));
    }
  }
}
예제 #3
0
/**
Allocate matrix with dimensions [nrl to nrh] x [ncl to nch]
\param nrl lower matrix row index
\param nrl upper matrix row index
\param ncl lower matrix column index
\param ncl upper matrix column index
*/
void dmatrix::allocate(
  const ad_integer& nrl, const ad_integer& nrh,
  const index_type& ncl, const index_type& nch)
{
  if (nrh < nrl)
  {
    allocate();
  }
  else
  {
    if ((ncl.isinteger() && (nrl != ncl.indexmin() || nrh != ncl.indexmax()))
       || (nch.isinteger() && (nrl != nch.indexmin() || nrh != nch.indexmax())))
    {
      cerr << "Incompatible dmatrix bounds in " << __FILE__ << ':' << __LINE__ << ".\n";
      ad_exit(1);
    }
    index_min = int(nrl);
    index_max = int(nrh);
    if ((m = new dvector[rowsize()]) == 0)
    {
      cerr << " Error: dmatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    if ((shape = new mat_shapex(m)) == 0)
    {
      cerr << " Error: dmatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    m -= int(nrl);
    for (int i = nrl; i <= nrh; ++i)
    {
      m[i].allocate(ncl[i], nch[i]);
    }
  }
}