Exemplo n.º 1
0
/** Compute the dot product of two variable type vectors. The minimum and maxium
  legal subscripts of the arguments must agree; otherwize an error message
   is printed and execution terminates.
  \ingroup matop
  \param v1 A dvar_vector, \f$a\f$.
  \param v2 A dvar_vector, \f$b\f$.
  \return A dvariable, \f$z = a\cdot b = \sum_i a_i\cdot b_i\f$  containing
  the value of the dot product of the two arguments.
*/
dvariable operator*(const dvar_vector& v1, const dvar_vector& v2)
{
    RETURN_ARRAYS_INCREMENT();
    if (v1.indexmin()!=v2.indexmin()||v1.indexmax()!=v2.indexmax())
    {
        cerr << "Incompatible bounds in "
             "prevariable operator * (const dvar_vector& v1, const dvar_vector& v2)"
             << endl;
        ad_exit(1);
    }
    double tmp=0;

#ifndef USE_ASSEMBLER
    int mmin=v1.indexmin();
    int mmax=v1.indexmax();
#ifdef OPT_LIB
    double * pt1=&v1.elem_value(mmin);
    double * pt1m=&v1.elem_value(mmax);
    double * pt2=&v2.elem_value(mmin);
    do
    {
        tmp+= *pt1++ * *pt2++;
    }
    while (pt1<=pt1m);
#else
    for (int i=mmin; i<=mmax; i++)
    {
        tmp+=v1.elem_value(i)*v2.elem_value(i);
    }
#endif
#else
    int mmin=v1.indexmin();
    int n=v1.indexmax()-mmin+1;
    dp_dotproduct(&tmp,&(v1.elem_value(mmin)),&(v2.elem_value(mmin)),n);
#endif

    dvariable vtmp=nograd_assign(tmp);

    // The derivative list considerations
    save_identifier_string("bbbb");
    v1.save_dvar_vector_value();
    v1.save_dvar_vector_position();
    v2.save_dvar_vector_value();
    v2.save_dvar_vector_position();
    vtmp.save_prevariable_position();
    save_identifier_string("aaaa");
    gradient_structure::GRAD_STACK1->
    set_gradient_stack(dvdv_dot);
    RETURN_ARRAYS_DECREMENT();
    return vtmp;
}
Exemplo n.º 2
0
/**
 * Description not yet available.
 * \param
 */
dvar_vector operator-(const dvar_vector& t1, const double x)
  {
    RETURN_ARRAYS_INCREMENT();
    dvar_vector tmp(t1.indexmin(),t1.indexmax());
    save_identifier_string("ucbb");
    for (int i=t1.indexmin(); i<=t1.indexmax(); i++)
    {
      tmp.elem_value(i)=t1.elem_value(i)-x;
    }
    tmp.save_dvar_vector_position();
    t1.save_dvar_vector_position();
    save_identifier_string("dduu");
    RETURN_ARRAYS_DECREMENT();
    gradient_structure::GRAD_STACK1->set_gradient_stack(DF_dv_cdble_diff);
    return(tmp);
  }
Exemplo n.º 3
0
/**
 * Description not yet available.
 * \param
 */
dvar_vector operator+(const prevariable& x, const dvar_vector& t1)
  {
    RETURN_ARRAYS_INCREMENT();
    dvar_vector tmp(t1.indexmin(),t1.indexmax());
    save_identifier_string("wcbf");
    x.save_prevariable_position();
    for (int i=t1.indexmin(); i<=t1.indexmax(); i++)
    {
      tmp.elem_value(i)=t1.elem_value(i)+value(x);
    }
    tmp.save_dvar_vector_position();
    t1.save_dvar_vector_position();
    save_identifier_string("dduu");
    RETURN_ARRAYS_DECREMENT();
    gradient_structure::GRAD_STACK1->set_gradient_stack(DF_dble_dv_add);
    return(tmp);
  }