Commit e3333185 authored by Kirill Terekhov's avatar Kirill Terekhov

Synchronzie

Added class used to store lambda-like expressions within automatic
differentiation.

Added assertions into workaround introduced in f8b3aca2 to check type
sizes during compile time.
parent 9cadb5b8
......@@ -27,7 +27,7 @@ const real reg_abs = 1.0e-12; //regularize abs(x) as sqrt(x*x+reg_abs)
const real reg_div = 1.0e-15; //regularize (|x|+reg_div)/(|x|+|y|+2*reg_div) to reduce to 1/2 when |x| ~= |y| ~= 0
#define OPTIMIZATION
//#define OPTIMIZATION
int main(int argc,char ** argv)
{
......@@ -388,7 +388,6 @@ int main(int argc,char ** argv)
do
{
R.Clear(); //clean up the residual
//First we need to evaluate the gradient at each cell for scaling matrix D
#if defined(USE_OMP)
#pragma omp parallel for
#endif
......@@ -443,7 +442,7 @@ int main(int argc,char ** argv)
if( R.Norm() < 1.0e-4 ) break;
Solver S(Solver::INNER_ILU2);
Solver S(Solver::INNER_MPTILUC);
S.SetMatrix(R.GetJacobian());
S.SetParameterReal("relative_tolerance", 1.0e-14);
S.SetParameterReal("absolute_tolerance", 1.0e-12);
......
......@@ -23,6 +23,11 @@
// 5. Consider optimization by checking zero variation multipliers, check that assembly do not degrade.
// 6. Document everything
//This should stop Visual Studio from complaining of very long auto-generated class types
#ifdef _MSC_VER
#pragma warning(disable : 4503)
#endif
#if defined(USE_AUTODIFF)
......@@ -186,17 +191,7 @@ namespace INMOST
INMOST_DATA_REAL_TYPE operator()(const Storage & e) const {return var.Value(e);}
};
class store_variable
{
abstract_dynamic_variable * var;
public:
store_variable(const abstract_dynamic_variable & var) : var(var.Copy()) {}
~store_variable() {delete var;}
template<typename T>
get_variable<T> get_variable() {return get_variable<T>(*var);}
abstract_dynamic_variable & retrive() {return *var;}
const abstract_dynamic_variable & retrive() const {return *var;}
};
......@@ -228,6 +223,28 @@ namespace INMOST
operator const Derived & () const {return *static_cast<const Derived *>(this);}
virtual abstract_dynamic_variable * Copy() const { return static_cast<const Derived *>(this)->Copy(); }
};
class stored_variable_expression : public shell_dynamic_variable<multivar_expression,stored_variable_expression>
{
abstract_dynamic_variable * var;
public:
stored_variable_expression() : var(NULL) {}
stored_variable_expression(const abstract_dynamic_variable & pvar) : var(pvar.Copy()) {}
stored_variable_expression(const stored_variable_expression & other) : var(other.var->Copy()) {}
~stored_variable_expression() {delete var; var = NULL;}
stored_variable_expression operator =(stored_variable_expression const & other) {var = other.var->Copy(); return *this;}
stored_variable_expression operator =(const abstract_dynamic_variable & pvar) {var = pvar.Copy(); return *this;}
INMOST_DATA_REAL_TYPE Value(const Storage & e) const {return var->Value(e);}
multivar_expression Variable(const Storage & e) const {return var->Variable(e);}
multivar_expression operator [](const Storage & e) const {return var->Variable(e);}
void GetVariation(const Storage & e, Sparse::Row & r) const { (*this)[e].GetJacobian(1.0,r); }
void GetVariation(const Storage & e, Sparse::RowMerger & r) const { (*this)[e].GetJacobian(1.0,r); }
template<typename T>
get_variable<T> get_variable() {return get_variable<T>(*var);}
abstract_dynamic_variable & retrive_expression() {return *var;}
const abstract_dynamic_variable & retrive_expression() const {return *var;}
};
class dynamic_variable : public shell_dynamic_variable<var_expression,dynamic_variable >
......@@ -378,7 +395,7 @@ namespace INMOST
const keyval_table & Table;
public:
table_variable(const shell_dynamic_variable<typename A::Var,A> & parg, const keyval_table & ptable) : Arg(parg), Table(ptable) {}
table_variable(const table_variable & other) : Arg(other.Arg), Table(other.table) {}
table_variable(const table_variable & other) : Arg(other.Arg), Table(other.Table) {}
table_variable & operator = (table_variable const & other) {Arg = other.Arg; Table = other.Table; return * this;}
multivar_expression Variable(const Storage & e) const
{
......@@ -534,7 +551,7 @@ template<class A> __INLINE INMOST::unary_const_c
template<class B> __INLINE INMOST::unary_const_custom_variable<INMOST::const_subtraction_expression<typename B::Var>,B> operator-(INMOST_DATA_REAL_TYPE Left, INMOST::shell_dynamic_variable<typename B::Var,B> const & Right) { return INMOST::unary_const_custom_variable<INMOST::const_subtraction_expression<typename B::Var>,B>(Right, Left); }
template<class A> __INLINE INMOST::unary_const_custom_variable<INMOST::const_addition_expression<typename A::Var>,A> operator-(INMOST::shell_dynamic_variable<typename A::Var,A> const & Left, INMOST_DATA_REAL_TYPE Right) { return INMOST::unary_const_custom_variable<INMOST::const_addition_expression<typename A::Var>,A>(Left, -Right); }
template<class A> __INLINE INMOST::stencil_variable<A> stencil(INMOST::Automatizator & aut, INMOST_DATA_ENUM_TYPE stncl, INMOST::shell_dynamic_variable<typename A::Var,A> const & Arg, void * user_data = NULL) { return INMOST::stencil_variable<A>(aut,stncl,Arg,user_data); }
template<class A> __INLINE INMOST::table_variable<A> get_table(INMOST::shell_dynamic_variable<typename A::Var,A> const & Arg, const INMOST::keyval_table & Table) {return INMOST::table_variable<A>(Table,Arg);}
template<class A> __INLINE INMOST::table_variable<A> get_table(INMOST::shell_dynamic_variable<typename A::Var,A> const & Arg, const INMOST::keyval_table & Table) {return INMOST::table_variable<A>(Arg,Table);}
......
......@@ -29,16 +29,28 @@
#include <istream>
#include <vector>
#include <stdint.h>
#if _MSC_VER == 1800
#define ct_assert(e) extern char (*ct_assert(void)) [sizeof(char[1 - 2*!(e)])]
/////////////////////////////////////////
// The code below is a workaround for
// Visual Studio 2013. In some cases
// it may not define uint32_t and uint64_t
// types in stdint.h header.
#if _MSC_VER == 1800 //Visual Studio 2013
#if !defined(UINT64_MAX)
#define UINT64_MAX 0xffffffffffffffffU
ct_assert(sizeof(unsigned long long) == 8); //this will fail during compilation if the type is not 64-bit
typedef unsigned long long uint64_t;
#endif // UINT64_MAX
#if !defined(UINT32_MAX)
#define UINT32_MAX 0xffffffff
ct_assert(sizeof(unsigned int) == 4); //this will fail during compilation if the type is not 32-bit
typedef unsigned int uint32_t;
#endif // UINT32_MAX
#endif
#endif //_MSC_VER == 1800
//////////////////////////////////////////
namespace INMOST
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment