1 #ifndef INMOST_AUTODIFF_ETEXPR_H_INCLUDED
2 #define INMOST_AUTODIFF_ETEXPR_H_INCLUDED
3 #include "inmost_common.h"
4 #include "inmost_sparse.h"
25 #pragma warning(disable : 4503)
28 #define CNT_USE_MERGER 0
31 #if defined(USE_AUTODIFF)
42 virtual INMOST_DATA_REAL_TYPE GetValue()
const = 0;
43 virtual void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const = 0;
44 virtual void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const = 0;
46 virtual INMOST_DATA_ENUM_TYPE GetCount()
const = 0;
50 template<
class Derived>
55 __INLINE
virtual INMOST_DATA_REAL_TYPE GetValue()
const {
return static_cast<const Derived *
>(
this)->GetValue(); }
56 __INLINE
virtual void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const {
if( mult )
return static_cast<const Derived *
>(
this)->GetJacobian(mult,r); }
57 __INLINE
virtual void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const {
if( mult )
return static_cast<const Derived *
>(
this)->GetJacobian(mult,r); }
58 __INLINE
virtual void GetHessian(INMOST_DATA_REAL_TYPE multJ,
Sparse::Row & J, INMOST_DATA_REAL_TYPE multH,
Sparse::HessianRow & H)
const {
return static_cast<const Derived *
>(
this)->GetHessian(multJ,J,multH,H); }
59 __INLINE
virtual INMOST_DATA_ENUM_TYPE GetCount()
const {
return static_cast<const Derived*
>(
this)->GetCount(); }
60 operator Derived & () {
return *
static_cast<Derived *
>(
this);}
61 operator const Derived & ()
const {
return *
static_cast<const Derived *
>(
this);}
68 INMOST_DATA_REAL_TYPE value;
72 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
73 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const {(void)mult; (void)r;}
74 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const {(void)mult; (void)r;}
75 __INLINE
void GetHessian(INMOST_DATA_REAL_TYPE multJ,
Sparse::Row & J, INMOST_DATA_REAL_TYPE multH,
Sparse::HessianRow & H)
const {(void)multJ; (void)J; (void)multH; (void)H;}
76 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return 0; }
87 INMOST_DATA_REAL_TYPE value;
88 INMOST_DATA_ENUM_TYPE index;
92 var_expression(INMOST_DATA_REAL_TYPE pvalue, INMOST_DATA_ENUM_TYPE pindex) : value(pvalue), index(pindex) {}
93 var_expression(INMOST_DATA_REAL_TYPE pvalue) : value(pvalue), index(ENUMUNDEF) {}
94 __INLINE
void SetValue(INMOST_DATA_REAL_TYPE val) { value = val; }
95 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
96 __INLINE INMOST_DATA_ENUM_TYPE GetIndex()
const {
return index; }
97 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const {
if( mult && index != ENUMUNDEF ) r[index] += mult;}
98 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const {
if( mult && index != ENUMUNDEF ) r[index] += mult;}
99 __INLINE
void GetHessian(INMOST_DATA_REAL_TYPE multJ,
Sparse::Row & J, INMOST_DATA_REAL_TYPE multH,
Sparse::HessianRow & H)
const {
if( index != ENUMUNDEF ) J.
Push(index,multJ); (void)multH; (void)H;}
100 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return index == ENUMUNDEF ? 0 : 1; }
101 __INLINE INMOST_DATA_REAL_TYPE GetDerivative(INMOST_DATA_ENUM_TYPE i)
const {
return index == i? 1.0 : 0.0;}
114 bool check_nans()
const
116 return value != value;
118 bool check_infs()
const
120 return __isinf__(value);
124 #if defined(PACK_ARRAY)
125 #pragma pack(push,r1,4)
132 INMOST_DATA_REAL_TYPE value;
139 : value(pvalue), entries(pentries) {}
140 multivar_expression(INMOST_DATA_REAL_TYPE pvalue, INMOST_DATA_ENUM_TYPE pindex, INMOST_DATA_REAL_TYPE pdmult = 1.0)
143 entries.
Push(pindex,pdmult);
147 value = expr.GetValue();
148 INMOST_DATA_ENUM_TYPE cnt = expr.GetCount();
152 expr.GetJacobian(1.0, *merger);
153 merger->RetrieveRow(entries);
158 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
159 __INLINE
void SetValue(INMOST_DATA_REAL_TYPE val) { value = val; }
160 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
164 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
166 INMOST_DATA_ENUM_TYPE cnt = entries.
Size() + r.
Size();
167 if (cnt >= CNT_USE_MERGER)
170 merger->AddRow(mult, entries);
171 merger->AddRow(1.0, r);
172 merger->RetrieveRow(r);
176 r[it->first] += it->second * mult;
186 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return entries.
Size(); }
196 entries = other.entries;
215 __INLINE
const Sparse::Row & GetRow()
const {
return entries;}
216 __INLINE INMOST_DATA_REAL_TYPE GetDerivative(INMOST_DATA_ENUM_TYPE index)
const {
return GetRow().
get_safe(index);}
217 __INLINE
bool operator < (INMOST_DATA_REAL_TYPE right)
const {
return value < right;}
218 __INLINE
bool operator > (INMOST_DATA_REAL_TYPE right)
const {
return value > right;}
219 __INLINE
bool operator <=(INMOST_DATA_REAL_TYPE right)
const {
return value <= right;}
220 __INLINE
bool operator >=(INMOST_DATA_REAL_TYPE right)
const {
return value >= right;}
221 __INLINE
bool operator ==(INMOST_DATA_REAL_TYPE right)
const {
return value == right;}
222 __INLINE
bool operator !=(INMOST_DATA_REAL_TYPE right)
const {
return value != right;}
223 __INLINE
bool operator < (
basic_expression const & expr)
const {
return value < expr.GetValue();}
224 __INLINE
bool operator > (
basic_expression const & expr)
const {
return value > expr.GetValue();}
225 __INLINE
bool operator <=(
basic_expression const & expr)
const {
return value <= expr.GetValue();}
226 __INLINE
bool operator >=(
basic_expression const & expr)
const {
return value >= expr.GetValue();}
227 __INLINE
bool operator ==(
basic_expression const & expr)
const {
return value == expr.GetValue();}
228 __INLINE
bool operator !=(
basic_expression const & expr)
const {
return value != expr.GetValue();}
229 __INLINE
bool operator < (
multivar_expression const & expr)
const {
return value < expr.GetValue();}
230 __INLINE
bool operator > (
multivar_expression const & expr)
const {
return value > expr.GetValue();}
231 __INLINE
bool operator <=(
multivar_expression const & expr)
const {
return value <= expr.GetValue();}
232 __INLINE
bool operator >=(
multivar_expression const & expr)
const {
return value >= expr.GetValue();}
233 __INLINE
bool operator ==(
multivar_expression const & expr)
const {
return value == expr.GetValue();}
234 __INLINE
bool operator !=(
multivar_expression const & expr)
const {
return value != expr.GetValue();}
237 value += expr.GetValue();
238 INMOST_DATA_ENUM_TYPE cnt = entries.
Size() + expr.GetCount();
242 merger->PushRow(1.0, entries);
243 expr.GetJacobian(1.0, *merger);
244 merger->RetrieveRow(entries);
252 value -= expr.GetValue();
253 INMOST_DATA_ENUM_TYPE cnt = entries.
Size() + expr.GetCount();
257 merger->PushRow(1.0, entries);
258 expr.GetJacobian(-1.0, *merger);
259 merger->RetrieveRow(entries);
267 INMOST_DATA_REAL_TYPE lval = value, rval = expr.GetValue();
268 INMOST_DATA_ENUM_TYPE cnt = entries.
Size() + expr.GetCount();
272 merger->PushRow(rval, entries);
273 expr.GetJacobian(lval, *merger);
274 merger->RetrieveRow(entries);
288 INMOST_DATA_REAL_TYPE rval = expr.GetValue();
289 INMOST_DATA_REAL_TYPE reciprocial_rval = 1.0/rval;
290 value *= reciprocial_rval;
291 INMOST_DATA_ENUM_TYPE cnt = entries.
Size() + expr.GetCount();
295 merger->PushRow(reciprocial_rval, entries);
296 expr.GetJacobian(-value * reciprocial_rval, *merger);
297 merger->RetrieveRow(entries);
330 bool check_nans()
const
332 if( value != value )
return true;
334 if( it->second != it->second )
return true;
337 bool check_infs()
const
339 if( __isinf__(value) )
return true;
341 if( __isinf__(it->second) )
return true;
351 INMOST_DATA_ENUM_TYPE k = 0;
355 for(INMOST_DATA_ENUM_TYPE r = 0; r < entries.
Size(); ++r)
366 return 1 + entries.
Size();
376 entries.
Resize(v[k].first);
378 for(
int r = 0; r < (int)entries.
Size(); ++r)
389 return 1 + v[0].
first;
391 void Print(
double eps = -1, std::ostream & sout = std::cout)
const
393 sout << value <<
" ";
394 entries.
Print(eps, sout);
396 void swap(multivar_expression & b)
398 std::swap(value,b.value);
399 entries.
Swap(b.entries);
401 friend class multivar_expression_reference;
409 INMOST_DATA_REAL_TYPE value;
415 std::swap(value,b.value);
416 entries.
Swap(b.entries);
417 hessian_entries.Swap(b.hessian_entries);
429 : value(pvalue), entries(pentries) {}
432 : value(pvalue), entries(pentries), hessian_entries(phentries) {}
437 entries.
Push(pindex,pdmult);
442 value = expr.GetValue();
443 expr.GetHessian(1.0,entries,1.0,hessian_entries);
445 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
446 __INLINE
void SetValue(INMOST_DATA_REAL_TYPE val) { value = val; }
447 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult, Sparse::RowMerger & r)
const
449 r.AddRow(mult,entries);
453 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult, Sparse::Row & r)
const
455 INMOST_DATA_ENUM_TYPE cnt = entries.
Size() + r.Size();
456 if (cnt >= CNT_USE_MERGER)
459 merger->AddRow(mult, entries);
460 merger->AddRow(1.0, r);
461 merger->RetrieveRow(r);
465 r[it->first] += it->second * mult;
467 __INLINE
void GetHessian(INMOST_DATA_REAL_TYPE multJ, Sparse::Row & J, INMOST_DATA_REAL_TYPE multH, Sparse::HessianRow & H)
const
470 if( !J.isSorted() ) std::sort(J.Begin(),J.End());
473 for(Sparse::HessianRow::iterator it = H.Begin(); it != H.End(); ++it) it->second *= multH;
475 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return entries.
Size(); }
476 __INLINE multivar_expression GetVariable(INMOST_DATA_ENUM_TYPE index)
478 multivar_expression ret(0);
479 for(
int k = 0; k < (int)entries.
Size(); ++k)
484 Sparse::Row & r = ret.GetRow();
485 for(
int q = 0; q < (int)hessian_entries.
Size(); ++q)
488 if( i.first == index )
489 r.Push(i.second,hessian_entries.GetValue(q)*(i.first == i.second ? 1.0 : 0.5));
490 else if( i.second == index )
491 r.Push(i.first,hessian_entries.GetValue(q)*(i.first == i.second ? 1.0 : 0.5));
502 hessian_entries.
Clear();
529 entries = other.entries;
530 hessian_entries = other.hessian_entries;
533 __INLINE Sparse::Row & GetRow() {
return entries;}
534 __INLINE Sparse::HessianRow & GetHessianRow() {
return hessian_entries;}
535 __INLINE
const Sparse::Row & GetRow()
const {
return entries;}
536 __INLINE INMOST_DATA_REAL_TYPE GetDerivative(INMOST_DATA_ENUM_TYPE index)
const {
return GetRow().
get_safe(index);}
537 __INLINE
const Sparse::HessianRow & GetHessianRow()
const {
return hessian_entries;}
540 value += expr.GetValue();
541 Sparse::Row tmpr, tmp;
542 Sparse::HessianRow htmpr, htmp;
543 expr.GetHessian(1.0,tmpr,1.0,htmpr);
547 hessian_entries.Swap(htmp);
552 value -= expr.GetValue();
553 Sparse::Row tmpr, tmp;
554 Sparse::HessianRow htmpr, htmp;
555 expr.GetHessian(1.0,tmpr,1.0,htmpr);
559 hessian_entries.Swap(htmp);
564 throw NotImplemented;
565 INMOST_DATA_REAL_TYPE lval = value, rval = expr.GetValue();
566 Sparse::Row tmp, tmpr;
567 Sparse::HessianRow htmp, htmpr;
568 expr.GetHessian(1.0,tmpr,1.0,htmpr);
572 hessian_entries.Swap(htmp);
577 throw NotImplemented;
578 INMOST_DATA_REAL_TYPE rval = expr.GetValue();
579 INMOST_DATA_REAL_TYPE reciprocial_rval = 1.0/rval;
580 value *= reciprocial_rval;
581 Sparse::Row tmp, tmpr;
582 Sparse::HessianRow htmp, htmpr;
583 expr.GetHessian(-value*reciprocial_rval,tmpr,1.0,htmpr);
587 hessian_entries.Swap(htmp);
604 for(Sparse::HessianRow::iterator it = hessian_entries.Begin(); it != hessian_entries.End(); ++it) it->second *= right;
611 for(Sparse::HessianRow::iterator it = hessian_entries.Begin(); it != hessian_entries.End(); ++it) it->second /= right;
614 bool check_nans()
const
616 if( value != value )
return true;
618 if( it->second != it->second )
return true;
619 for(Sparse::HessianRow::const_iterator it = hessian_entries.Begin(); it != hessian_entries.End(); ++it)
620 if( it->second != it->second )
return true;
623 bool check_infs()
const
625 if( __isinf__(value))
return true;
627 if( __isinf__(it->second) )
return true;
628 for(Sparse::HessianRow::const_iterator it = hessian_entries.Begin(); it != hessian_entries.End(); ++it)
629 if( __isinf__(it->second) )
return true;
632 friend class hessian_multivar_expression_reference;
634 #if defined(PACK_ARRAY)
638 static INMOST_DATA_REAL_TYPE stub_multivar_expression_reference_value;
643 INMOST_DATA_REAL_TYPE & value;
650 : value(_value), entries(_entries) {}
653 : value(other.value), entries(other.entries) {}
656 : value(other.value), entries(&other.entries) {}
658 __INLINE INMOST_DATA_REAL_TYPE
GetValue()
const {
return value; }
660 __INLINE
void SetValue(INMOST_DATA_REAL_TYPE val) { value = val; }
676 INMOST_DATA_ENUM_TYPE cnt = entries->
Size() + r.
Size();
677 if (cnt >= CNT_USE_MERGER)
680 merger->AddRow(mult, *entries);
681 merger->AddRow(1.0, r);
682 merger->RetrieveRow(r);
686 r[it->first] += it->second * mult;
700 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return entries->
Size(); }
710 value = expr.GetValue();
713 INMOST_DATA_ENUM_TYPE cnt = expr.GetCount();
717 expr.GetJacobian(1.0, *merger);
718 merger->RetrieveRow(*entries);
732 value = other.GetValue();
733 *entries = other.GetRow();
744 __INLINE Sparse::Row & GetRow() {
return *entries;}
745 __INLINE
const Sparse::Row & GetRow()
const {
return *entries;}
746 __INLINE INMOST_DATA_REAL_TYPE GetDerivative(INMOST_DATA_ENUM_TYPE index)
const {
return GetRow().
get_safe(index);}
749 value += expr.GetValue();
752 INMOST_DATA_ENUM_TYPE cnt = entries->
Size() + expr.GetCount();
756 merger->PushRow(1.0, *entries);
757 expr.GetJacobian(1.0, *merger);
758 merger->RetrieveRow(*entries);
767 value -= expr.GetValue();
770 INMOST_DATA_ENUM_TYPE cnt = entries->
Size() + expr.GetCount();
774 merger->PushRow(1.0, *entries);
775 expr.GetJacobian(-1.0, *merger);
776 merger->RetrieveRow(*entries);
785 INMOST_DATA_REAL_TYPE lval = value, rval = expr.GetValue();
788 INMOST_DATA_ENUM_TYPE cnt = entries->
Size() + expr.GetCount();
792 merger->PushRow(rval, *entries);
793 expr.GetJacobian(lval, *merger);
794 merger->RetrieveRow(*entries);
809 INMOST_DATA_REAL_TYPE rval = expr.GetValue();
810 INMOST_DATA_REAL_TYPE reciprocial_rval = 1.0/rval;
811 value *= reciprocial_rval;
814 INMOST_DATA_ENUM_TYPE cnt = entries->
Size() + expr.GetCount();
818 merger->PushRow(reciprocial_rval, *entries);
819 expr.GetJacobian(-value * reciprocial_rval, *merger);
820 merger->RetrieveRow(*entries);
854 bool check_nans()
const
856 if( value != value )
return true;
858 if( it->second != it->second )
return true;
861 bool check_infs()
const
863 if( __isinf__(value) )
return true;
865 if( __isinf__(it->second) )
return true;
872 INMOST_DATA_REAL_TYPE& value;
881 : value(other.value) {}
939 bool check_nans()
const
941 if (value != value)
return true;
944 bool check_infs()
const
946 if (__isinf__(value))
return true;
949 operator INMOST_DATA_REAL_TYPE()
const {
return value; }
950 operator INMOST_DATA_REAL_TYPE& () {
return value; }
957 INMOST_DATA_REAL_TYPE & value;
963 : value(_value), entries(_entries), hentries(_hentries) {}
966 : value(other.value), entries(other.entries), hentries(other.hentries) {}
969 : value(other.value), entries(&other.entries), hentries(&other.hessian_entries) {}
971 __INLINE INMOST_DATA_REAL_TYPE
GetValue()
const {
return value; }
973 __INLINE
void SetValue(INMOST_DATA_REAL_TYPE val) { value = val; }
984 INMOST_DATA_ENUM_TYPE cnt = entries->
Size() + r.
Size();
985 if (cnt >= CNT_USE_MERGER)
988 merger->AddRow(mult, *entries);
989 merger->AddRow(1.0, r);
990 merger->RetrieveRow(r);
994 r[it->first] += it->second * mult;
1002 for(Sparse::HessianRow::iterator it = H.Begin(); it != H.End(); ++it) it->second *= multH;
1004 __INLINE INMOST_DATA_REAL_TYPE GetDerivative(INMOST_DATA_ENUM_TYPE index)
const {
return GetRow().
get_safe(index);}
1005 __INLINE multivar_expression GetVariable(INMOST_DATA_ENUM_TYPE index)
1007 multivar_expression ret(0);
1008 for(
int k = 0; k < (int)entries->
Size(); ++k)
1010 if( entries->
GetIndex(k) == index )
1012 ret.SetValue(entries->
GetValue(k));
1013 Sparse::Row & r = ret.GetRow();
1014 for(
int q = 0; q < (int)hentries->
Size(); ++q)
1017 if( i.first == index )
1018 r.Push(i.second,hentries->GetValue(q)*(i.first == i.second ? 1.0 : 0.5));
1019 else if( i.second == index )
1020 r.Push(i.first,hentries->GetValue(q)*(i.first == i.second ? 1.0 : 0.5));
1036 value = expr.GetValue();
1038 Sparse::HessianRow htmp;
1039 expr.GetHessian(1.0,tmp,1.0,htmp);
1041 hentries->Swap(htmp);
1046 value = other.GetValue();
1047 *entries = other.GetRow();
1053 value = other.GetValue();
1054 *entries = other.GetRow();
1060 value = other.GetValue();
1061 *entries = other.GetRow();
1062 *hentries = other.GetHessianRow();
1067 value = other.GetValue();
1068 *entries = other.GetRow();
1069 *hentries = other.GetHessianRow();
1072 __INLINE Sparse::Row & GetRow() {
return *entries;}
1073 __INLINE Sparse::HessianRow & GetHessianRow() {
return *hentries;}
1074 __INLINE
const Sparse::Row & GetRow()
const {
return *entries;}
1075 __INLINE
const Sparse::HessianRow & GetHessianRow()
const {
return *hentries;}
1078 value += expr.GetValue();
1079 Sparse::Row tmpr, tmp;
1080 Sparse::HessianRow htmpr, htmp;
1081 expr.GetHessian(1.0,tmpr,1.0,htmpr);
1085 hentries->Swap(htmp);
1090 value -= expr.GetValue();
1091 Sparse::Row tmpr, tmp;
1092 Sparse::HessianRow htmpr, htmp;
1093 expr.GetHessian(1.0,tmpr,1.0,htmpr);
1097 hentries->Swap(htmp);
1102 throw NotImplemented;
1103 INMOST_DATA_REAL_TYPE lval = value, rval = expr.GetValue();
1104 Sparse::Row tmp, tmpr;
1105 Sparse::HessianRow htmp, htmpr;
1106 expr.GetHessian(1.0,tmpr,1.0,htmpr);
1110 hentries->Swap(htmp);
1116 throw NotImplemented;
1117 INMOST_DATA_REAL_TYPE rval = expr.GetValue();
1118 INMOST_DATA_REAL_TYPE reciprocial_rval = 1.0/rval;
1119 value *= reciprocial_rval;
1120 Sparse::Row tmp, tmpr;
1121 Sparse::HessianRow htmp, htmpr;
1122 expr.GetHessian(-value*reciprocial_rval,tmpr,1.0,htmpr);
1126 hentries->Swap(htmp);
1143 for(Sparse::HessianRow::iterator it = hentries->Begin(); it != hentries->End(); ++it)
1144 it->second *= right;
1151 for(Sparse::HessianRow::iterator it = hentries->Begin(); it != hentries->End(); ++it) it->second /= right;
1154 bool check_nans()
const
1156 if( value != value )
return true;
1158 if( it->second != it->second )
return true;
1159 for(Sparse::HessianRow::iterator it = hentries->Begin(); it != hentries->End(); ++it)
1160 if( it->second != it->second )
return true;
1163 bool check_infs()
const
1165 if( __isinf__(value) )
return true;
1167 if( __isinf__(it->second) )
return true;
1168 for(Sparse::HessianRow::iterator it = hentries->Begin(); it != hentries->End(); ++it)
1169 if( __isinf__(it->second) )
return true;
1179 INMOST_DATA_REAL_TYPE value, dmult;
1183 value = arg.GetValue()*dmult;
1187 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1188 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1190 arg.GetJacobian(mult*dmult,r);
1192 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1194 arg.GetJacobian(mult*dmult,r);
1198 arg.GetHessian(multJ*dmult,J,multH*dmult,H);
1200 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1207 INMOST_DATA_REAL_TYPE value, dmult;
1211 value = arg.GetValue();
1215 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1216 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1218 arg.GetJacobian(mult*dmult,r);
1220 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1222 arg.GetJacobian(mult*dmult,r);
1226 arg.GetHessian(multJ*dmult,J,multH*dmult,H);
1228 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1236 INMOST_DATA_REAL_TYPE value, dmult;
1241 value = arg.GetValue()*dmult;
1245 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1246 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1248 arg.GetJacobian(mult*dmult,r);
1250 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1252 arg.GetJacobian(mult*dmult,r);
1256 arg.GetHessian(multJ*dmult,J,multH*dmult,H);
1258 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1265 INMOST_DATA_REAL_TYPE value;
1269 value = arg.GetValue()+padd;
1273 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1274 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1276 arg.GetJacobian(mult,r);
1278 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1280 arg.GetJacobian(mult,r);
1284 arg.GetHessian(multJ,J,multH,H);
1286 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1293 INMOST_DATA_REAL_TYPE value;
1297 value = pleft-arg.GetValue();
1301 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1302 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1304 arg.GetJacobian(-mult,r);
1306 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1308 arg.GetJacobian(-mult,r);
1312 arg.GetHessian(-multJ,J,-multH,H);
1314 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1323 INMOST_DATA_REAL_TYPE value, reciprocial_val;
1327 reciprocial_val = 1.0/arg.GetValue();
1328 value = coef*reciprocial_val;
1331 : arg(other.arg), value(other.value), reciprocial_val(other.reciprocial_val) {}
1333 : arg(parg), value(other.value), reciprocial_val(other.reciprocial_val) {}
1334 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1335 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1337 arg.GetJacobian(-mult*value*reciprocial_val,r);
1339 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1341 arg.GetJacobian(-mult*value*reciprocial_val,r);
1346 double coefJ = -multJ*value*reciprocial_val;
1347 double signJ = coefJ < 0 ? -1 : 1;
1348 arg.GetHessian(signJ,J,-2*multH*value*reciprocial_val,ArgH);
1349 Sparse::HessianRow::MergeJacobianHessian(2*value*reciprocial_val*reciprocial_val*signJ,J,J,1.0,ArgH,H);
1350 for(INMOST_DATA_ENUM_TYPE k = 0; k < J.
Size(); ++k) J.
GetValue(k) *= coefJ*signJ;
1352 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1359 INMOST_DATA_REAL_TYPE value;
1364 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value;}
1365 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1367 arg.GetJacobian(-mult,r);
1369 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1371 arg.GetJacobian(-mult,r);
1375 arg.GetHessian(-multJ,J,-multH,H);
1377 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1384 INMOST_DATA_REAL_TYPE value;
1389 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value;}
1390 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1392 arg.GetJacobian(mult,r);
1394 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1396 arg.GetJacobian(mult,r);
1400 arg.GetHessian(multJ,J,multH,H);
1402 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1409 INMOST_DATA_REAL_TYPE value, dmult;
1413 value = arg.GetValue();
1414 dmult = value < 0.0 ? -1.0 : 1.0;
1415 value = ::fabs(value);
1419 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value;}
1420 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1422 arg.GetJacobian( (value == 0 ? (mult < 0.0 ? -1 : 1) : 1) * mult * dmult, r);
1424 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1426 arg.GetJacobian( (value == 0 ? (mult < 0.0 ? -1 : 1) : 1) * mult * dmult, r);
1430 double a = (value == 0 ? (multJ < 0.0 ? -1 : 1) : 1);
1431 double b = (value == 0 ? (multH < 0.0 ? -1 : 1) : 1);
1432 arg.GetHessian( a * multJ * dmult,J, b*multH * dmult,H);
1434 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1442 INMOST_DATA_REAL_TYPE value;
1446 value = arg.GetValue();
1447 value = ::exp(value);
1451 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1452 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1454 arg.GetJacobian( mult * value, r);
1456 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1458 arg.GetJacobian( mult * value, r);
1463 double coefJ = multJ*value;
1464 double signJ = coefJ < 0.0 ? -1 : 1;
1465 arg.GetHessian(signJ, J, multH*value, ArgH);
1466 Sparse::HessianRow::MergeJacobianHessian(coefJ*signJ,J,J,1.0,ArgH,H);
1467 for(INMOST_DATA_ENUM_TYPE k = 0; k < J.
Size(); ++k) J.
GetValue(k) *= coefJ*signJ;
1469 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1476 INMOST_DATA_REAL_TYPE value, dmult;
1480 value = arg.GetValue();
1482 value = ::log(value);
1486 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1487 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1489 arg.GetJacobian(mult*dmult,r);
1491 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1493 arg.GetJacobian(mult*dmult,r);
1498 double coefJ = multJ*dmult;
1499 double signJ = coefJ < 0.0 ? -1 : 1;
1500 arg.GetHessian(signJ, J, 2*multH*dmult, ArgH);
1501 Sparse::HessianRow::MergeJacobianHessian(-coefJ*signJ*dmult,J,J,1.0,ArgH,H);
1502 for(INMOST_DATA_ENUM_TYPE k = 0; k < J.
Size(); ++k) J.
GetValue(k) *= coefJ*signJ;
1504 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1512 INMOST_DATA_REAL_TYPE value, dmult;
1516 value = arg.GetValue();
1517 dmult = ::cos(value);
1518 value = ::sin(value);
1522 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1523 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1525 arg.GetJacobian(mult*dmult,r);
1527 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1529 arg.GetJacobian(mult*dmult,r);
1534 arg.GetHessian(1,J,1,htmp);
1536 assert(htmp.isSorted());
1537 Sparse::HessianRow::MergeJacobianHessian(-value*multH,J,J,dmult*multH,htmp,H);
1539 assert(H.isSorted());
1541 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1548 INMOST_DATA_REAL_TYPE value, dmult;
1552 value = arg.GetValue();
1553 dmult = -(::sin(value));
1554 value = ::cos(value);
1558 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1559 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1561 arg.GetJacobian(mult*dmult,r);
1563 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1565 arg.GetJacobian(mult*dmult,r);
1571 arg.GetHessian(1,J,1,htmp);
1572 Sparse::HessianRow::MergeJacobianHessian(-value*multH,J,J,dmult*multH,htmp,H);
1575 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1582 INMOST_DATA_REAL_TYPE value;
1586 value = ::sqrt(arg.GetValue());
1590 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1591 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1593 if( value ) arg.GetJacobian(0.5*mult/value,r);
1595 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1597 if( value ) arg.GetJacobian(0.5*mult/value,r);
1606 arg.GetHessian(1,J,1,htmp);
1607 Sparse::HessianRow::MergeJacobianHessian(-0.25/::pow(value,3.0)*multH,J,J,0.5/value*multH,htmp,H);
1612 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1620 INMOST_DATA_REAL_TYPE value, dmult;
1624 INMOST_DATA_REAL_TYPE lval = arg.GetValue();
1625 value = ::sqrt(lval*lval+tol*tol);
1626 dmult = value ? lval/value : 0.0;
1630 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1631 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1633 arg.GetJacobian(mult*dmult,r);
1635 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1637 arg.GetJacobian(mult*dmult,r);
1641 (void)multJ,(
void)J,(void)multH,(
void)H;
1642 throw NotImplemented;
1644 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1651 INMOST_DATA_REAL_TYPE value, dmult;
1655 INMOST_DATA_REAL_TYPE lval = arg.GetValue(), lval2 = lval*lval;
1656 INMOST_DATA_REAL_TYPE div = lval2+tol*tol;
1657 INMOST_DATA_REAL_TYPE sdiv = ::sqrt(div);
1658 value = sdiv ? lval/sdiv : 0.0;
1659 dmult = sdiv ? (1.0 - (div ? lval2/div : 0.0))/sdiv : 0.0;
1663 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; };
1664 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1666 arg.GetJacobian(mult*dmult,r);
1668 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1670 arg.GetJacobian(mult*dmult,r);
1674 (void)multJ,(
void)J,(void)multH,(
void)H;
1675 throw NotImplemented;
1677 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
1680 template<
class A,
class B>
1685 INMOST_DATA_REAL_TYPE value, ldmult, rdmult;
1689 INMOST_DATA_REAL_TYPE lval = left.GetValue(), rval = right.GetValue();
1690 INMOST_DATA_REAL_TYPE diff = lval-rval, root = ::sqrt(diff*diff+tol*tol);
1691 value = 0.5*(lval+rval + root);
1694 ldmult = 0.5 * (1 + diff / root);
1695 rdmult = 0.5 * (1 - diff / root);
1697 else ldmult = rdmult = 0.5;
1700 : left(other.left), right(other.right), value(other.value), ldmult(other.ldmult), rdmult(other.rdmult) {}
1702 : left(pleft), right(pright), value(other.value), ldmult(other.ldmult), rdmult(other.rdmult) {}
1704 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1705 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1707 left.GetJacobian(mult*ldmult,r);
1708 right.GetJacobian(mult*rdmult,r);
1710 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1712 left.GetJacobian(mult*ldmult,r);
1713 right.GetJacobian(mult*rdmult,r);
1717 (void)multJ,(
void)J,(void)multH,(
void)H;
1718 throw NotImplemented;
1720 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
1727 INMOST_DATA_REAL_TYPE right;
1728 INMOST_DATA_REAL_TYPE value, ldmult;
1732 INMOST_DATA_REAL_TYPE lval = left.GetValue(), rval = right;
1733 INMOST_DATA_REAL_TYPE diff = lval - rval, root = ::sqrt(diff * diff + tol * tol);
1734 value = 0.5 * (lval + rval + root);
1735 ldmult = 0.5 * (1 + (root ? diff / root : 0.0));
1738 : left(other.left), right(other.right), value(other.value), ldmult(other.ldmult) {}
1740 : left(pleft), right(pright), value(other.value), ldmult(other.ldmult) {}
1741 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1742 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger& r)
const {left.GetJacobian(mult * ldmult, r);}
1743 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row& r)
const {left.GetJacobian(mult * ldmult, r);}
1746 (void)multJ, (
void)J, (void)multH, (
void)H;
1747 throw NotImplemented;
1749 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount(); }
1752 template<
class A,
class B>
1757 INMOST_DATA_REAL_TYPE value, ldmult, rdmult;
1761 INMOST_DATA_REAL_TYPE lval = left.GetValue(), rval = right.GetValue();
1762 INMOST_DATA_REAL_TYPE diff = lval-rval, root = ::sqrt(diff*diff+tol*tol);
1763 value = 0.5*(lval+rval - root);
1766 ldmult = 0.5 * (1 - diff / root);
1767 rdmult = 0.5 * (1 + diff / root);
1769 else ldmult = rdmult = 0.5;
1772 : left(other.left), right(other.right), value(other.value), ldmult(other.ldmult), rdmult(other.rdmult) {}
1774 : left(pleft), right(pright), value(other.value), ldmult(other.ldmult), rdmult(other.rdmult) {}
1775 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1776 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1778 left.GetJacobian(mult*ldmult,r);
1779 right.GetJacobian(mult*rdmult,r);
1781 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1783 left.GetJacobian(mult*ldmult,r);
1784 right.GetJacobian(mult*rdmult,r);
1788 (void)multJ,(
void)J,(void)multH,(
void)H;
1789 throw NotImplemented;
1791 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
1799 INMOST_DATA_REAL_TYPE right;
1800 INMOST_DATA_REAL_TYPE value, ldmult;
1804 INMOST_DATA_REAL_TYPE lval = left.GetValue(), rval = right;
1805 INMOST_DATA_REAL_TYPE diff = lval - rval, root = ::sqrt(diff * diff + tol * tol);
1806 value = 0.5 * (lval + rval - root);
1807 ldmult = 0.5 * (1 - (root ? diff / root : 0.0));
1810 : left(other.left), right(other.right), value(other.value), ldmult(other.ldmult) {}
1812 : left(pleft), right(pright), value(other.value), ldmult(other.ldmult) {}
1813 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1814 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger& r)
const {left.GetJacobian(mult * ldmult, r);}
1815 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row& r)
const { left.GetJacobian(mult * ldmult, r); }
1818 (void)multJ, (
void)J, (void)multH, (
void)H;
1819 throw NotImplemented;
1821 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount(); }
1824 template<
class A,
class B>
1829 INMOST_DATA_REAL_TYPE value;
1833 value = left.GetValue()*right.GetValue();
1836 : left(other.left), right(other.right), value(other.value) {}
1838 : left(pleft), right(pright), value(other.value) {}
1839 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1840 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1842 left.GetJacobian(mult*right.GetValue(),r);
1843 right.GetJacobian(mult*left.GetValue(),r);
1845 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1847 left.GetJacobian(mult*right.GetValue(),r);
1848 right.GetJacobian(mult*left.GetValue(),r);
1855 left.GetHessian(1,JL,1,HL);
1857 assert(HL.isSorted());
1858 right.GetHessian(1,JR,1,HR);
1860 assert(HR.isSorted());
1869 Sparse::HessianRow::MergeJacobianHessian(2.0*multH,JL,JR,right.
GetValue()*multH,HL,left.GetValue()*multH,HR,H);
1870 assert(H.isSorted());
1872 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
1875 template<
class A,
class B>
1880 INMOST_DATA_REAL_TYPE value, reciprocal_rval;
1884 INMOST_DATA_REAL_TYPE lval = left.GetValue();
1885 INMOST_DATA_REAL_TYPE rval = right.GetValue();
1888 reciprocal_rval = 1.0 / rval;
1889 value = lval * reciprocal_rval;
1893 reciprocal_rval = 0;
1899 left(pleft), right(pright), value(other.value), reciprocal_rval(other.reciprocal_rval) {}
1901 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1902 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1904 left.GetJacobian(mult * reciprocal_rval,r);
1905 right.GetJacobian(- mult * value * reciprocal_rval,r);
1907 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1909 left.GetJacobian(mult * reciprocal_rval,r);
1910 right.GetJacobian(- mult * value * reciprocal_rval,r);
1914 throw NotImplemented;
1917 left.GetHessian(multJ,JL,multH,HL);
1918 right.GetHessian(multJ,JR,multH,HR);
1926 Sparse::HessianRow::MergeJacobianHessian(2.0,JL,JR,reciprocal_rval,HL,2*left.GetValue()*multH,HR,H);
1928 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return reciprocal_rval ? left.GetCount() + right.GetCount() : 0; }
1931 template<
class A,
class B>
1936 INMOST_DATA_REAL_TYPE value;
1940 value = left.GetValue() + right.GetValue();
1943 : left(other.left), right(other.right), value(other.value) {}
1945 : left(pleft), right(pright), value(other.value) {}
1946 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1947 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1949 left.GetJacobian(mult,r);
1950 right.GetJacobian(mult,r);
1952 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1954 left.GetJacobian(mult,r);
1955 right.GetJacobian(mult,r);
1961 left.GetHessian(1,JL,1,HL);
1963 assert(HL.isSorted());
1964 right.GetHessian(1,JR,1,HR);
1966 assert(HR.isSorted());
1970 assert(H.isSorted());
1972 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
1975 template<
class A,
class B>
1980 INMOST_DATA_REAL_TYPE value;
1984 value = left.GetValue() - right.GetValue();
1987 : left(other.left), right(other.right),value(other.value) {}
1989 : left(pleft), right(pright),value(other.value) {}
1990 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
1991 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
1993 left.GetJacobian(mult,r);
1994 right.GetJacobian(-mult,r);
1996 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
1998 left.GetJacobian(mult,r);
1999 right.GetJacobian(-mult,r);
2006 left.GetHessian(1,JL,1,HL);
2007 right.GetHessian(1,JR,1,HR);
2011 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
2014 template<
class A,
class B>
2019 INMOST_DATA_REAL_TYPE value, ldmult, rdmult;
2023 INMOST_DATA_REAL_TYPE lval = left.GetValue();
2024 INMOST_DATA_REAL_TYPE rval = right.GetValue();
2025 value = ::pow(lval,rval);
2028 ldmult = value * rval / lval;
2029 rdmult = value * ::log(lval);
2038 :left(other.left), right(other.right), value(other.value),
2039 ldmult(other.ldmult), rdmult(other.rdmult) {}
2041 :left(pleft), right(pright), value(other.value),
2042 ldmult(other.ldmult), rdmult(other.rdmult) {}
2043 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
2044 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2046 left.GetJacobian(mult*ldmult,r);
2047 right.GetJacobian(mult*rdmult,r);
2049 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2051 left.GetJacobian(mult*ldmult,r);
2052 right.GetJacobian(mult*rdmult,r);
2056 throw NotImplemented;
2058 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
2062 template<
class A,
class B>
2067 INMOST_DATA_REAL_TYPE value, ldmult, rdmult;
2071 INMOST_DATA_REAL_TYPE lval = left.GetValue();
2072 INMOST_DATA_REAL_TYPE rval = right.GetValue();
2073 value = ::atan2(lval,rval);
2074 ldmult = rval/(rval*rval+lval*lval);
2075 rdmult = -lval/(rval*rval+lval*lval);
2078 :left(other.left), right(other.right), value(other.value),
2079 ldmult(other.ldmult), rdmult(other.rdmult) {}
2081 :left(pleft), right(pright), value(other.value),
2082 ldmult(other.ldmult), rdmult(other.rdmult) {}
2083 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
2084 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2086 left.GetJacobian(mult*ldmult,r);
2087 right.GetJacobian(mult*rdmult,r);
2089 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2091 left.GetJacobian(mult*ldmult,r);
2092 right.GetJacobian(mult*rdmult,r);
2096 throw NotImplemented;
2098 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount() + right.GetCount(); }
2105 INMOST_DATA_REAL_TYPE value, ldmult, ldmult2;
2109 INMOST_DATA_REAL_TYPE lval = left.GetValue();
2110 value = ::pow(lval,pright);
2113 ldmult = value * pright / lval;
2114 ldmult2 = ldmult * (pright-1) / lval;
2117 ldmult = ldmult2 = 0;
2120 :left(other.left), value(other.value), ldmult(other.ldmult) {}
2122 :left(pleft), value(other.value), ldmult(other.ldmult) {}
2123 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
2124 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2126 left.GetJacobian(mult*ldmult,r);
2128 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2130 left.GetJacobian(mult*ldmult,r);
2138 left.GetHessian(1,JL,1,HL);
2139 Sparse::HessianRow::MergeJacobianHessian(multH*ldmult2,JL,JL,multH*ldmult,HL,H);
2143 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return left.GetCount(); }
2150 INMOST_DATA_REAL_TYPE value, rdmult;
2154 INMOST_DATA_REAL_TYPE rval = right.GetValue();
2155 value = ::pow(pleft,rval);
2157 rdmult = value * ::log(pleft);
2162 :right(other.right), value(other.value), rdmult(other.rdmult) {}
2164 :right(pright), value(other.value), rdmult(other.rdmult) {}
2165 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
2166 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2168 right.GetJacobian(mult*rdmult,r);
2170 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2172 right.GetJacobian(mult*rdmult,r);
2176 throw NotImplemented;
2178 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return right.GetCount(); }
2181 template<
class A,
class B,
class C>
2187 INMOST_DATA_REAL_TYPE value, cond_value;
2191 cond_value = cond.GetValue();
2192 value = cond_value >= 0.0 ? left.GetValue() : right.GetValue();
2195 :cond(other.cond), left(other.left), right(other.right),
2196 value(other.value), cond_value(other.cond_value) {}
2198 :cond(pcond), left(pleft), right(pright),
2199 value(other.value), cond_value(other.cond_value) {}
2200 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
2201 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2203 if( cond_value >= 0.0 )
2204 left.GetJacobian(mult,r);
2206 right.GetJacobian(mult,r);
2208 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2210 if( cond_value >= 0.0 )
2211 left.GetJacobian(mult,r);
2213 right.GetJacobian(mult,r);
2217 if( cond_value >= 0.0 )
2218 left.GetHessian(multJ,J,multH,H);
2220 right.GetHessian(multJ,J,multH,H);
2222 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return cond_value >= 0.0 ? left.GetCount() : right.GetCount(); }
2225 template<
class A,
class B>
2231 INMOST_DATA_REAL_TYPE value;
2239 value = cond ? left.GetValue() : right.GetValue();
2242 :cond(other.cond), left(other.left), right(other.right),
2243 value(other.value) {}
2245 :cond(pcond), left(pleft), right(pright),
2246 value(other.value) {}
2247 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value; }
2248 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2251 left.GetJacobian(mult,r);
2253 right.GetJacobian(mult,r);
2255 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2258 left.GetJacobian(mult,r);
2260 right.GetJacobian(mult,r);
2265 left.GetHessian(multJ,J,multH,H);
2267 right.GetHessian(multJ,J,multH,H);
2269 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return cond ? left.GetCount() : right.GetCount(); }
2270 void SetCondition(
bool _cond)
2273 value = cond ? left.GetValue() : right.GetValue();
2282 INMOST_DATA_REAL_TYPE value, dmult, ddmult;
2285 : arg(_arg), value(1), dmult(0) {}
2288 INMOST_DATA_REAL_TYPE pddmult = 0)
2289 : arg(_arg), value(pvalue), dmult(pdmult), ddmult(pddmult) {}
2292 : arg(other.arg), value(other.value), dmult(other.dmult), ddmult(other.ddmult) {}
2294 : arg(parg), value(other.value), dmult(other.dmult), ddmult(other.ddmult) {}
2304 __INLINE INMOST_DATA_REAL_TYPE GetValue()
const {
return value;}
2305 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::RowMerger & r)
const
2307 arg.GetJacobian(mult*dmult,r);
2309 __INLINE
void GetJacobian(INMOST_DATA_REAL_TYPE mult,
Sparse::Row & r)
const
2311 arg.GetJacobian(mult*dmult,r);
2315 arg.GetHessian(multJ*dmult,J,multH*ddmult,H);
2317 __INLINE INMOST_DATA_ENUM_TYPE GetCount()
const {
return arg.GetCount(); }
2318 void SetFunctionValue(INMOST_DATA_REAL_TYPE val) {value = val;}
2319 void SetFunctionDerivative(INMOST_DATA_REAL_TYPE val) {dmult = val;}
2326 INMOST_DATA_REAL_TYPE * vals;
2327 INMOST_DATA_REAL_TYPE * args;
2328 INMOST_DATA_ENUM_TYPE size;
2329 INMOST_DATA_ENUM_TYPE binary_search(INMOST_DATA_REAL_TYPE arg)
const
2331 int l = 0, r =
static_cast<int>(size)-1, mid = 0;
2335 if (args[mid] > arg) r = mid - 1;
2336 else if (args[mid] < arg) l = mid + 1;
2340 if (mid >
static_cast<int>(size - 2)) mid =
static_cast<int>(size - 2);
2341 return static_cast<INMOST_DATA_ENUM_TYPE
>(mid);
2344 INMOST_DATA_REAL_TYPE GetValue(INMOST_DATA_REAL_TYPE arg)
const
2346 if (arg < args[0])
return vals[0];
2347 INMOST_DATA_ENUM_TYPE i = binary_search(arg);
2348 return vals[i] + (vals[i + 1] - vals[i]) * (arg - args[i]) / (args[i + 1] - args[i]);
2350 INMOST_DATA_REAL_TYPE GetDerivative(INMOST_DATA_REAL_TYPE arg)
const
2352 if (arg < args[0])
return 0.0;
2353 INMOST_DATA_ENUM_TYPE i = binary_search(arg);
2354 return (vals[i + 1] - vals[i]) / (args[i + 1] - args[i]);
2356 std::pair<INMOST_DATA_REAL_TYPE, INMOST_DATA_REAL_TYPE> GetBoth(INMOST_DATA_REAL_TYPE arg)
const
2358 if (arg < args[0])
return std::make_pair(vals[0], 0.0);
2359 INMOST_DATA_ENUM_TYPE i = binary_search(arg);
2360 INMOST_DATA_REAL_TYPE der = (vals[i + 1] - vals[i]) / (args[i + 1] - args[i]);
2361 return std::make_pair(vals[i] + der * (arg - args[i]), der);
2363 keyval_table() :name(
""), vals(NULL), args(NULL), size(0) {}
2364 keyval_table(std::string _name,
const INMOST_DATA_REAL_TYPE * _args,
const INMOST_DATA_REAL_TYPE * _vals, INMOST_DATA_ENUM_TYPE _size)
2368 vals =
new INMOST_DATA_REAL_TYPE[size];
2369 memcpy(vals,_vals,
sizeof(INMOST_DATA_REAL_TYPE)*size);
2371 args =
new INMOST_DATA_REAL_TYPE[size];
2372 memcpy(args,_args,
sizeof(INMOST_DATA_REAL_TYPE)*size);
2379 vals =
new INMOST_DATA_REAL_TYPE[size];
2380 memcpy(vals,other.vals,
sizeof(INMOST_DATA_REAL_TYPE)*size);
2382 args =
new INMOST_DATA_REAL_TYPE[size];
2383 memcpy(args,other.args,
sizeof(INMOST_DATA_REAL_TYPE)*size);
2391 vals =
new INMOST_DATA_REAL_TYPE[size];
2392 memcpy(vals,other.vals,
sizeof(INMOST_DATA_REAL_TYPE)*size);
2394 args =
new INMOST_DATA_REAL_TYPE[size];
2395 memcpy(args,other.args,
sizeof(INMOST_DATA_REAL_TYPE)*size);
2406 if( args ) {
delete [] args; args = NULL;}
2407 if( vals ) {
delete [] vals; vals = NULL;}
2414 const INMOST_DATA_REAL_TYPE * GetTableArguments()
const {
return args;}
2415 const INMOST_DATA_REAL_TYPE * GetTableValues()
const {
return vals;}
2416 INMOST_DATA_REAL_TYPE * GetTableArguments() {
return args;}
2417 INMOST_DATA_REAL_TYPE * GetTableValues() {
return vals;}
2418 INMOST_DATA_ENUM_TYPE GetSize()
const {
return size;}
2427 __INLINE
bool check_nans(INMOST_DATA_REAL_TYPE val) {
return val != val;}
2431 __INLINE
bool check_infs(INMOST_DATA_REAL_TYPE val) {
return __isinf__(val);}
2435 __INLINE
bool check_nans_infs(INMOST_DATA_REAL_TYPE val) {
return check_nans(val) || check_infs(val);}
2436 __INLINE
bool check_nans_infs(
INMOST::var_expression const & e) {
return e.check_nans() || e.check_infs();}
2439 __INLINE INMOST_DATA_ENUM_TYPE GetCount(INMOST_DATA_REAL_TYPE val) { (void)val;
return 0; }
2440 __INLINE INMOST_DATA_ENUM_TYPE GetCount(INMOST_DATA_CPLX_TYPE val) { (void)val;
return 0; }
2443 template<
class A,
class B,
class C> __INLINE
INMOST::condition_expression<A,B,C> condition(
INMOST::shell_expression<A> const & control,
INMOST::shell_expression<B> const & if_ge_zero,
INMOST::shell_expression<C> const & if_lt_zero) {
return INMOST::condition_expression<A,B,C>(control,if_ge_zero,if_lt_zero); }
2444 __INLINE INMOST_DATA_REAL_TYPE condition(INMOST_DATA_REAL_TYPE control, INMOST_DATA_REAL_TYPE if_ge_zero, INMOST_DATA_REAL_TYPE if_lt_zero) {
return control >= 0.0 ? if_ge_zero : if_lt_zero;}
2454 __INLINE INMOST_DATA_REAL_TYPE variation(INMOST_DATA_REAL_TYPE Arg, INMOST_DATA_REAL_TYPE) {
return Arg;}
2456 __INLINE INMOST_DATA_REAL_TYPE get_value(INMOST_DATA_REAL_TYPE Arg) {
return Arg;}
2457 __INLINE INMOST_DATA_CPLX_TYPE get_value(INMOST_DATA_CPLX_TYPE Arg) {
return Arg; }
2458 __INLINE INMOST_DATA_CPLX_TYPE get_value(std::complex<INMOST::var_expression>
const& Arg) {
return INMOST_DATA_CPLX_TYPE(Arg.real().GetValue(), Arg.imag().GetValue()); }
2459 __INLINE INMOST_DATA_CPLX_TYPE get_value(std::complex<INMOST::multivar_expression>
const& Arg) {
return INMOST_DATA_CPLX_TYPE(Arg.real().GetValue(), Arg.imag().GetValue()); }
2460 __INLINE INMOST_DATA_CPLX_TYPE get_value(std::complex<INMOST::hessian_multivar_expression>
const& Arg) {
return INMOST_DATA_CPLX_TYPE(Arg.real().GetValue(), Arg.imag().GetValue()); }
2469 __INLINE
void set_value(INMOST_DATA_REAL_TYPE & Arg, INMOST_DATA_REAL_TYPE Val) {Arg = Val;}
2470 __INLINE
void set_value(INMOST_DATA_REAL_TYPE & Arg,
const INMOST::var_expression & Val) {Arg = Val.GetValue();}
2479 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg, INMOST_DATA_INTEGER_TYPE Val) {Arg = Val;}
2480 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg, INMOST_DATA_REAL_TYPE Val) {Arg = (INMOST_DATA_INTEGER_TYPE)Val;}
2481 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg,
const INMOST::var_expression & Val) {Arg = (INMOST_DATA_INTEGER_TYPE)Val.GetValue();}
2482 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg,
const INMOST::multivar_expression & Val) {Arg = (INMOST_DATA_INTEGER_TYPE)Val.GetValue();}
2486 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg, INMOST_DATA_INTEGER_TYPE Val) {Arg = (INMOST_DATA_REAL_TYPE)Val;}
2487 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg, INMOST_DATA_REAL_TYPE Val) {Arg = Val;}
2488 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg,
const INMOST::var_expression & Val) {Arg = Val.GetValue();}
2494 __INLINE
void assign(INMOST_DATA_CPLX_TYPE& Arg,
const INMOST_DATA_CPLX_TYPE& Val) { Arg = Val; }
2495 __INLINE
void assign(INMOST_DATA_CPLX_TYPE& Arg, INMOST_DATA_INTEGER_TYPE Val) { Arg = (INMOST_DATA_REAL_TYPE)Val; }
2496 __INLINE
void assign(INMOST_DATA_CPLX_TYPE& Arg, INMOST_DATA_REAL_TYPE Val) { Arg = Val; }
2497 __INLINE
void assign(INMOST_DATA_CPLX_TYPE& Arg,
const INMOST::var_expression& Val) { Arg = Val.GetValue(); }
2503 __INLINE
void assign(
INMOST::var_expression & Arg, INMOST_DATA_INTEGER_TYPE Val) {Arg = (INMOST_DATA_REAL_TYPE)Val; }
2533 template<
class A> __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg,
const INMOST::shell_expression<A> & Val) {Arg = (INMOST_DATA_REAL_TYPE)Val.GetValue();}
2534 template<
class A> __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg,
const INMOST::shell_expression<A> & Val) {Arg = Val.GetValue();}
2541 #if defined(USE_FP64)
2542 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg,
float Val) {Arg = (INMOST_DATA_INTEGER_TYPE)Val; }
2543 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg,
float Val) {Arg = (INMOST_DATA_REAL_TYPE)Val; }
2544 __INLINE
void assign(
float& Arg,
float Val) {Arg = (float)Val; }
2551 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg,
double Val) {Arg = (INMOST_DATA_INTEGER_TYPE)Val; }
2552 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg,
double Val) {Arg = (INMOST_DATA_REAL_TYPE)Val; }
2553 __INLINE
void assign(
double& Arg,
double Val) {Arg = (INMOST_DATA_REAL_TYPE)Val; }
2560 __INLINE INMOST_DATA_REAL_TYPE soft_fabs(INMOST_DATA_REAL_TYPE Arg, INMOST_DATA_REAL_TYPE tol = 0) {return ::sqrt(Arg*Arg+tol*tol);}
2562 __INLINE INMOST_DATA_REAL_TYPE soft_sign(INMOST_DATA_REAL_TYPE Arg, INMOST_DATA_REAL_TYPE tol = 0) {
return Arg/::sqrt(Arg*Arg+tol*tol);}
2572 __INLINE INMOST_DATA_REAL_TYPE soft_max(INMOST_DATA_REAL_TYPE Left, INMOST_DATA_REAL_TYPE Right, INMOST_DATA_REAL_TYPE tol = 0.0) {
return 0.5*(Left+Right+::sqrt((Left-Right)*(Left-Right)+tol*tol));}
2576 __INLINE INMOST_DATA_REAL_TYPE soft_min(INMOST_DATA_REAL_TYPE Left, INMOST_DATA_REAL_TYPE Right, INMOST_DATA_REAL_TYPE tol = 0.0) {
return 0.5*(Left+Right-::sqrt((Left-Right)*(Left-Right)+tol*tol));}
2593 template<
class A> __INLINE
bool operator == (
INMOST::shell_expression<A> const & Left, INMOST_DATA_REAL_TYPE Right) {
return Left.GetValue() == Right;}
2594 template<
class A> __INLINE
bool operator != (
INMOST::shell_expression<A> const & Left, INMOST_DATA_REAL_TYPE Right) {
return Left.GetValue() != Right;}
2595 template<
class A> __INLINE
bool operator < (
INMOST::shell_expression<A> const & Left, INMOST_DATA_REAL_TYPE Right) {
return Left.GetValue() < Right;}
2596 template<
class A> __INLINE
bool operator > (
INMOST::shell_expression<A> const & Left, INMOST_DATA_REAL_TYPE Right) {
return Left.GetValue() > Right;}
2597 template<
class A> __INLINE
bool operator <= (
INMOST::shell_expression<A> const & Left, INMOST_DATA_REAL_TYPE Right) {
return Left.GetValue() <= Right;}
2598 template<
class A> __INLINE
bool operator >= (
INMOST::shell_expression<A> const & Left, INMOST_DATA_REAL_TYPE Right) {
return Left.GetValue() >= Right;}
2599 template<
class B> __INLINE
bool operator == (INMOST_DATA_REAL_TYPE Left,
INMOST::shell_expression<B> const & Right) {
return Left == Right.GetValue();}
2600 template<
class B> __INLINE
bool operator != (INMOST_DATA_REAL_TYPE Left,
INMOST::shell_expression<B> const & Right) {
return Left != Right.GetValue();}
2601 template<
class B> __INLINE
bool operator < (INMOST_DATA_REAL_TYPE Left,
INMOST::shell_expression<B> const & Right) {
return Left < Right.GetValue();}
2602 template<
class B> __INLINE
bool operator > (INMOST_DATA_REAL_TYPE Left,
INMOST::shell_expression<B> const & Right) {
return Left > Right.GetValue();}
2603 template<
class B> __INLINE
bool operator <= (INMOST_DATA_REAL_TYPE Left,
INMOST::shell_expression<B> const & Right) {
return Left <= Right.GetValue();}
2604 template<
class B> __INLINE
bool operator >= (INMOST_DATA_REAL_TYPE Left,
INMOST::shell_expression<B> const & Right) {
return Left >= Right.GetValue();}
2607 std::pair<INMOST_DATA_REAL_TYPE, INMOST_DATA_REAL_TYPE> both = Table.GetBoth(Arg.GetValue());
2610 __INLINE INMOST_DATA_REAL_TYPE get_table(INMOST_DATA_REAL_TYPE Arg,
const INMOST::keyval_table & Table) {
return Table.GetValue(Arg);}
2612 __INLINE INMOST_DATA_ENUM_TYPE GetCount(INMOST_DATA_REAL_TYPE val) { (void)val;
return 0; }
2613 __INLINE INMOST_DATA_ENUM_TYPE GetCount(INMOST_DATA_CPLX_TYPE val) { (void)val;
return 0; }
2614 __INLINE
bool check_nans(INMOST_DATA_REAL_TYPE val) {
return val != val;}
2615 __INLINE
bool check_infs(INMOST_DATA_REAL_TYPE val) {
return __isinf__(val);}
2616 __INLINE
bool check_nans_infs(INMOST_DATA_REAL_TYPE val) {
return check_nans(val) || check_infs(val);}
2617 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg, INMOST_DATA_INTEGER_TYPE Val) {Arg = Val;}
2618 __INLINE
void assign(INMOST_DATA_INTEGER_TYPE & Arg, INMOST_DATA_REAL_TYPE Val) {Arg =
static_cast<INMOST_DATA_INTEGER_TYPE
>(Val);}
2619 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg, INMOST_DATA_INTEGER_TYPE Val) {Arg =
static_cast<INMOST_DATA_REAL_TYPE
>(Val);}
2620 __INLINE
void assign(INMOST_DATA_REAL_TYPE & Arg, INMOST_DATA_REAL_TYPE Val) {Arg = Val;}
2621 __INLINE
void assign(INMOST_DATA_CPLX_TYPE& Arg, INMOST_DATA_REAL_TYPE Val) { Arg = Val; }
2622 __INLINE
void assign(INMOST_DATA_CPLX_TYPE& Arg, INMOST_DATA_CPLX_TYPE Val) { Arg = Val; }
2623 __INLINE
void set_value(INMOST_DATA_REAL_TYPE & Arg, INMOST_DATA_REAL_TYPE Val) {Arg = Val;}
2624 __INLINE INMOST_DATA_REAL_TYPE get_value(INMOST_DATA_REAL_TYPE Arg) {
return Arg;}
2625 __INLINE INMOST_DATA_CPLX_TYPE get_value(INMOST_DATA_CPLX_TYPE Arg) {
return Arg; }
2626 __INLINE INMOST_DATA_REAL_TYPE variation(INMOST_DATA_REAL_TYPE Arg, INMOST_DATA_REAL_TYPE) {
return Arg;}
2627 __INLINE INMOST_DATA_REAL_TYPE soft_fabs(INMOST_DATA_REAL_TYPE Arg, INMOST_DATA_REAL_TYPE tol = 0) {return ::sqrt(Arg*Arg+tol*tol);}
2628 __INLINE INMOST_DATA_REAL_TYPE soft_sign(INMOST_DATA_REAL_TYPE Arg, INMOST_DATA_REAL_TYPE tol = 0) {
return Arg/::sqrt(Arg*Arg+tol*tol);}
2629 __INLINE INMOST_DATA_REAL_TYPE soft_max(INMOST_DATA_REAL_TYPE Left, INMOST_DATA_REAL_TYPE Right, INMOST_DATA_REAL_TYPE tol) {
return 0.5*(Left+Right+::sqrt((Left-Right)*(Left-Right)+tol*tol));}
2630 __INLINE INMOST_DATA_REAL_TYPE soft_min(INMOST_DATA_REAL_TYPE Left, INMOST_DATA_REAL_TYPE Right, INMOST_DATA_REAL_TYPE tol) {
return 0.5*(Left+Right-::sqrt((Left-Right)*(Left-Right)+tol*tol));}
Class to store the compressed symmetric matrix of a hessian row.
void Clear()
Clear all data of the current row.
static void MergeSortedRows(INMOST_DATA_REAL_TYPE alpha, const HessianRow &left, INMOST_DATA_REAL_TYPE beta, const HessianRow &right, HessianRow &output)
output = alpha * left + beta *right
INMOST_DATA_ENUM_TYPE Size() const
The size of the sparse row, i.e. the total number of nonzero elements.
struct INMOST::Sparse::HessianRow::hessian_index_s index
Entry of the sparse matrix row.
This class may be used to sum multiple sparse rows.
void AddRow(INMOST_DATA_REAL_TYPE coef, const Row &r)
Add a row with a coefficient into non-empty linked list.
Class to store the sparse matrix row.
void Swap(Row &other)
Exchange all the data with another row.
INMOST_DATA_REAL_TYPE get_safe(INMOST_DATA_ENUM_TYPE i) const
Finds and returns value with specified index.
void Clear()
Clear all data of the current row.
INMOST_DATA_REAL_TYPE & GetValue(INMOST_DATA_ENUM_TYPE k)
Retrieve a value corresponding to certain position in the array of pairs of index and value.
void Print(double eps=-1, std::ostream &sout=std::cout) const
Output all entries of the row.
Entries::iterator iterator
Iterator over pairs of index and value.
bool isSorted() const
Check whether the row is sorted.
void Resize(INMOST_DATA_ENUM_TYPE size)
Resize row to specified size.
static void MergeSortedRows(INMOST_DATA_REAL_TYPE alpha, const Row &left, INMOST_DATA_REAL_TYPE beta, const Row &right, Row &output)
Add up two rows.
iterator End()
An iterator pointing behind the last position in the array of pairs of index and value.
INMOST_DATA_ENUM_TYPE Size() const
The size of the sparse row, i.e. the total number of nonzero elements.
Entries::const_iterator const_iterator
Iterator over constant pairs of index and value.
iterator Begin()
Retrive interval of nonzeroes.
INMOST_DATA_ENUM_TYPE & GetIndex(INMOST_DATA_ENUM_TYPE k)
Retrieve an index corresponding to certain position in the array of pairs of index and value.
void Push(INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_REAL_TYPE val)
Push specified element into sparse row.
__INLINE INMOST_DATA_REAL_TYPE GetValue() const
Retrieve value.
hessian_multivar_expression_reference(hessian_multivar_expression &other)
Copy constructor from hessian_multivar_expression, sets links to the same reference of value and entr...
__INLINE void GetJacobian(INMOST_DATA_REAL_TYPE mult, Sparse::RowMerger &r) const
Retrieve derivatives with multiplier into Sparse::RowMerger structure.
hessian_multivar_expression_reference(INMOST_DATA_REAL_TYPE &_value, Sparse::Row *_entries, Sparse::HessianRow *_hentries)
Constructor, set links to the provided value and entries.
__INLINE void GetJacobian(INMOST_DATA_REAL_TYPE mult, Sparse::Row &r) const
Retrieve derivatives with multiplier into Sparse::Row structure.
hessian_multivar_expression_reference(const hessian_multivar_expression_reference &other)
Copy constructor, sets links to the same reference of value and entries.
__INLINE void SetValue(INMOST_DATA_REAL_TYPE val)
Set value without changing derivatives.
A class that represents a variable with multiple first order and second order variations.
hessian_multivar_expression(INMOST_DATA_REAL_TYPE pvalue)
Sets value and no first or second order variations.
hessian_multivar_expression(INMOST_DATA_REAL_TYPE pvalue, Sparse::Row &pentries, Sparse::HessianRow &phentries)
Sets value and all first and second order variations.
hessian_multivar_expression(INMOST_DATA_REAL_TYPE pvalue, INMOST_DATA_ENUM_TYPE pindex, INMOST_DATA_REAL_TYPE pdmult=1.0)
Sets value and it's variation index.
hessian_multivar_expression(const basic_expression &expr)
Evaluates argument expression to get the value and all variations of variable.
hessian_multivar_expression()
Sets zero value and no first or second order variations.
hessian_multivar_expression(INMOST_DATA_REAL_TYPE pvalue, Sparse::Row &pentries)
Copy value and all first variations from variable, no second order variations.
hessian_multivar_expression(const hessian_multivar_expression &other)
Copy value and all first and second order variations from hessian_variable.
__INLINE void GetJacobian(INMOST_DATA_REAL_TYPE mult, Sparse::RowMerger &r) const
Retrieve derivatives with multiplier into Sparse::RowMerger structure.
multivar_expression_reference(INMOST_DATA_REAL_TYPE &_value, Sparse::Row *_entries)
Constructor, set links to the provided value and entries.
multivar_expression_reference()
Default constructor.
__INLINE void GetJacobian(INMOST_DATA_REAL_TYPE mult, Sparse::Row &r) const
Retrieve derivatives with multiplier into Sparse::Row structure.
__INLINE INMOST_DATA_REAL_TYPE GetValue() const
Retrieve value.
multivar_expression_reference(multivar_expression &other)
Copy constructor from multivar_expression, sets links to the same reference of value and entries.
__INLINE void SetValue(INMOST_DATA_REAL_TYPE val)
Set value without changing derivatives.
multivar_expression_reference(const multivar_expression_reference &other)
Copy constructor, sets links to the same reference of value and entries.
A class that represents a variable with multiple first order variations.
static INMOST_DATA_ENUM_TYPE RetrieveSize(const Sparse::Row::entry *v)
Number of entries used.
INMOST_DATA_ENUM_TYPE Retrieve(const Sparse::Row::entry *v)
Retrieve variable from array of entries.
INMOST_DATA_ENUM_TYPE Record(Sparse::Row::entry *v) const
Write variable into array of entries.
INMOST_DATA_ENUM_TYPE RecordSize() const
Number of entries required to record the variable.
(c/x)' = -c dx / (x*x) (c/x)'' = 2 c dx dx / (x*x*x)
value_reference(const value_reference &other)
Copy constructor, sets links to the same reference of value and entries.
value_reference(INMOST_DATA_REAL_TYPE &_value)
Constructor, set links to the provided value and entries.
value_reference()
Default constructor.
Entry of the sparse matrix row.
INMOST_DATA_REAL_TYPE second
the real value of the row element.
INMOST_DATA_ENUM_TYPE first
the column number of the row element.