示例#1
0
文件: dmat.cpp 项目: jimianelli/admb
/**
 * Description not yet available.
 * \param
 */
 void dmatrix::allocate(int nrl,int nrh,const ivector& ncl,const ivector& nch)
 {
   if (nrh<nrl)
   {
     allocate();
     return;
   }

   if (nrl !=ncl.indexmin() || nrh !=ncl.indexmax() ||
     nrl !=nch.indexmin() || nrh !=nch.indexmax())
   {
     cerr << "Incompatible array bounds in "
     "dmatrix(int nrl,int nrh,const ivector& ncl,const ivector& nch)\n";
     ad_exit(1);
   }
   index_min=nrl;
   index_max=nrh;
   if ( (m = new dvector [rowsize()]) == 0)
   {
     cerr << " Error allocating memory in dmatrix contructor\n";
     ad_exit(21);
   }
   if ( (shape = new mat_shapex(m))== 0)
   {
     cerr << " Error allocating memory in dmatrix contructor\n";
     ad_exit(21);
   }

   m -= rowmin();
   for (int i=rowmin(); i<=rowmax(); i++)
   {
     m[i].allocate(ncl(i),nch(i));
   }
 }
示例#2
0
/**
Allocate variable vector of matrices with dimensions
[sl to sh] x ([nrl to nrh] x [ncl to nch])
where nrl and nrh are vectors of indexes.
\param sl lower index of vector
\param sh upper index of vector
\param nrl vector of lower row indexes for matrix
\param nrh vector of upper row indexes for matrix
\param ncl upper column index for matrix
\param nch upper column index for matrix
*/
void dvar3_array::allocate(int sl, int sh, const ivector& nrl,
  const ivector& nrh, int ncl, int nch)
{
  if (sl != nrl.indexmin() || sh != nrl.indexmax()
      || sl != nrh.indexmin() || sh != nrh.indexmax())
  {
    cerr << "Incompatible array bounds in "
     "dmatrix(int nrl,int nrh, const ivector& ncl, const ivector& nch)" << endl;
    ad_exit(1);
  }
  if ( (shape=new three_array_shape(sl,sh)) == 0)
  {
    cerr << "Error allocating memory in dvar3_array contructor" << endl;
  }
  if ((t = new dvar_matrix[slicesize()]) == 0)
  {
    cerr << " Error allocating memory in dvar3_array contructor" << endl;
    ad_exit(21);
  }
  t -= slicemin();
  for (int i = sl; i <= sh; ++i)
  {
    t[i].allocate(nrl(i), nrh(i), ncl, nch);
  }
}
示例#3
0
/**
 * Description not yet available.
 * \param
 */
 void lmatrix::allocate(int nrl, int nrh, int ncl, const ivector& nch)
 {
   if (nrl !=nch.indexmin() || nrh !=nch.indexmax())
   {
     cerr << "Incompatible array bounds in "
     "lmatrix::allocate(int nrl,int nrh,int ncl, const ivector& nch)\n";
     ad_exit(1);
   }
   if ( (shape = new mat_shape(nrl,nrh,ncl,nch(nch.indexmin())))== 0)
   {
     cerr << " Error allocating memory in lmatrix contructor\n";
     ad_exit(21);
   }
   size_t rs=rowsize();
   if ( (m = new lvector [rs]) == 0)
   {
     cerr << " Error allocating memory in lmatrix contructor\n";
     ad_exit(21);
   }
   m -= rowmin();
   for (int i=rowmin(); i<=rowmax(); i++)
   {
     m[i].allocate(ncl,nch(i));
   }
 }
示例#4
0
/**
Allocate variable vector of matrices with dimensions
[sl to sh] x ([nrl to nrh] x [ncl to nch])
where nch is a vector of indexes.
\param sl lower index of vector
\param sh upper index of vector
\param nrl lower row index for matrix
\param nrh upper row index for matrix
\param ncl vector of lower column indexes for matrix
\param nch vector of upper column indexes for matrix
*/
void dvar3_array::allocate(int sl, int sh, int nrl, int nrh,
  const ivector& ncl, const ivector& nch)
{
  if (sh<sl)
  {
    allocate();
    return;
  }
#ifdef DIAG
  myheapcheck("Entering dvar3_array matrix(sl,sh,nrl,nrh,ncl,nch)" );
#endif
  if (sl !=ncl.indexmin() || sh !=ncl.indexmax()
      || sl !=nch.indexmin() || sh !=nch.indexmax())
  {
    cerr << "Incompatible array bounds in "
     "dmatrix(int nrl,int nrh, const ivector& ncl, const ivector& nch)" << endl;
    ad_exit(1);
  }
  if ((shape = new three_array_shape(sl, sh)) == 0)
  {
    cerr << " Error allocating memory in dvar3_array contructor" << endl;
  }
  if ( (t = new dvar_matrix[slicesize()]) == 0)
  {
    cerr << " Error allocating memory in dvar3_array contructor" << endl;
    ad_exit(21);
  }
  t -= slicemin();
  for (int i = sl; i <= sh; ++i)
  {
    t[i].allocate(nrl, nrh, ncl(i), nch(i));
  }
}
示例#5
0
/**
 * Description not yet available.
 * \param
 */
dmatrix dmatrix::operator()(const ivector& t)
{
  dmatrix tmp(t.indexmin(), t.indexmax(), t.indexmin(), t.indexmax());

  for (int i=t.indexmin(); i <= t.indexmax(); i++)
  {
    tmp(i) = (*this)(t(i))(t);
  }
  return(tmp);
}
示例#6
0
文件: dvect8.cpp 项目: pwoo/admb
/**
 * Description not yet available.
 * \param
 */
dvector dvector::operator ()(const ivector& u)
 {
   dvector tmp(u.indexmin(),u.indexmax());

   for ( int i=u.indexmin(); i<=u.indexmax(); i++)
   {
     tmp(i)=(*this)(u(i));
   }
   return tmp;
 }
示例#7
0
ivector match(const ivector& x, const ivector& table)
  {
    int i,j;
    ivector pos(x.indexmin(),x.indexmax());
    for(i=x.indexmin();i<=x.indexmax();i++)
    {
        for(j=table.indexmin();j<=table.indexmax();j++)
        {
            if(x(i) == table(j) )
            {
                pos(i) = j;
                break;
            }
        }
    }
    return(pos);
  }
示例#8
0
文件: dvect8.cpp 项目: pwoo/admb
/**
 * Description not yet available.
 * \param
 */
dvector::dvector(const ivector& u)
 {
   allocate(u.indexmin(),u.indexmax());
   for ( int i=indexmin(); i<=indexmax(); i++)
   {
     elem(i)=u.elem(i);
   }
 }
示例#9
0
/**
Returns the sum of the squares of all elements in ivec.

\param ivec ivector
*/
int norm2(const ivector& ivec)
{
  int sum = 0;
  for (int i = ivec.indexmin(); i <= ivec.indexmax(); ++i)
  {
    sum += ivec(i) * ivec(i);
  }
  return sum;
}
示例#10
0
/**
Return dvector results of squaring elements in a values;
constant vector object.

\ingroup misc
\param values of constant object to be squared.
\return vector of the same length as #values containing \f$values_i^2\f$
*/
ivector square(const ivector& values)
{
  ivector results;
  results.allocate(values);
  for (int i = values.indexmin(); i <= values.indexmax(); ++i)
  {
    results(i) = values(i) * values(i);
  }
  return results;
}
示例#11
0
 void pvm_int::assign(const ivector& u)
 {
   if(ad_comm::pvm_manager)
   {
     int nsp=ad_comm::pvm_manager->num_slave_processes;
     if (u.indexmin() !=0 || u.indexmax() != nsp)
     {
       cerr << "Error in pvm_int::assign  validindex bounds must be 0 "
            << ad_comm::pvm_manager->num_slave_processes << endl;
       ad_exit(1);
     }
     if (allocated(v))
       v.deallocate();
     v.allocate(0,nsp);
     v=u;
     d=u(0);
   }
 }
示例#12
0
文件: dmat.cpp 项目: jimianelli/admb
/**
 * Description not yet available.
 * \param
 */
int ivector_check(const ivector& v, int l, int u)
  {
    if (v.indexmin()!=l||v.indexmax()!=u) return 1;
    return 0;
  }
示例#13
0
/**
 * Description not yet available.
 * \param
 */
ivector_position::ivector_position(const ivector& iv)
{
  min=iv.indexmin();
  max=iv.indexmax();
  v=iv.get_v();
}
示例#14
0
/**
 * Description not yet available.
 * \param
 */
void ivector::allocate(const ivector& dv)
{
  allocate(dv.indexmin(),dv.indexmax());
}