Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kirill Terekhov
INMOST
Commits
44579f01
Commit
44579f01
authored
Dec 15, 2016
by
Kirill Terekhov
Browse files
Add atan2 function to automatic differentiation
parent
24d1863f
Changes
1
Show whitespace changes
Inline
Side-by-side
Source/Headers/inmost_expression.h
View file @
44579f01
...
...
@@ -1463,6 +1463,42 @@ namespace INMOST
}
};
template
<
class
A
,
class
B
>
class
atan2_expression
:
public
shell_expression
<
atan2_expression
<
A
,
B
>
>
{
const
A
&
left
;
const
B
&
right
;
INMOST_DATA_REAL_TYPE
value
,
ldmult
,
rdmult
;
public:
atan2_expression
(
const
shell_expression
<
A
>
&
pleft
,
const
shell_expression
<
B
>
&
pright
)
:
left
(
pleft
),
right
(
pright
)
{
INMOST_DATA_REAL_TYPE
lval
=
left
.
GetValue
();
INMOST_DATA_REAL_TYPE
rval
=
right
.
GetValue
();
value
=
::
atan2
(
lval
,
rval
);
ldmult
=
rval
/
(
rval
*
rval
+
lval
*
lval
);
rdmult
=
-
lval
/
(
rval
*
rval
+
lval
*
lval
);
}
atan2_expression
(
const
atan2_expression
&
other
)
:
left
(
other
.
left
),
right
(
other
.
right
),
value
(
other
.
value
),
ldmult
(
other
.
ldmult
),
rdmult
(
other
.
rdmult
)
{}
__INLINE
INMOST_DATA_REAL_TYPE
GetValue
()
const
{
return
value
;
}
__INLINE
void
GetJacobian
(
INMOST_DATA_REAL_TYPE
mult
,
Sparse
::
RowMerger
&
r
)
const
{
left
.
GetJacobian
(
mult
*
ldmult
,
r
);
right
.
GetJacobian
(
mult
*
rdmult
,
r
);
}
__INLINE
void
GetJacobian
(
INMOST_DATA_REAL_TYPE
mult
,
Sparse
::
Row
&
r
)
const
{
left
.
GetJacobian
(
mult
*
ldmult
,
r
);
right
.
GetJacobian
(
mult
*
rdmult
,
r
);
}
__INLINE
void
GetHessian
(
INMOST_DATA_REAL_TYPE
multJ
,
Sparse
::
Row
&
J
,
INMOST_DATA_REAL_TYPE
multH
,
Sparse
::
HessianRow
&
H
)
const
{
throw
NotImplemented
;
}
};
template
<
class
A
>
class
pow_const_expression
:
public
shell_expression
<
pow_const_expression
<
A
>
>
{
...
...
@@ -1852,6 +1888,7 @@ template<class A, class B> __INLINE INMOST::division_expression<A,
template
<
class
A
,
class
B
>
__INLINE
INMOST
::
addition_expression
<
A
,
B
>
operator
+
(
INMOST
::
shell_expression
<
A
>
const
&
Left
,
INMOST
::
shell_expression
<
B
>
const
&
Right
)
{
return
INMOST
::
addition_expression
<
A
,
B
>
(
Left
,
Right
);
}
template
<
class
A
,
class
B
>
__INLINE
INMOST
::
subtraction_expression
<
A
,
B
>
operator
-
(
INMOST
::
shell_expression
<
A
>
const
&
Left
,
INMOST
::
shell_expression
<
B
>
const
&
Right
)
{
return
INMOST
::
subtraction_expression
<
A
,
B
>
(
Left
,
Right
);
}
template
<
class
A
,
class
B
>
__INLINE
INMOST
::
pow_expression
<
A
,
B
>
pow
(
INMOST
::
shell_expression
<
A
>
const
&
Left
,
INMOST
::
shell_expression
<
B
>
const
&
Right
)
{
return
INMOST
::
pow_expression
<
A
,
B
>
(
Left
,
Right
);
}
template
<
class
A
,
class
B
>
__INLINE
INMOST
::
atan2_expression
<
A
,
B
>
atan2
(
INMOST
::
shell_expression
<
A
>
const
&
Left
,
INMOST
::
shell_expression
<
B
>
const
&
Right
)
{
return
INMOST
::
atan2_expression
<
A
,
B
>
(
Left
,
Right
);
}
template
<
class
A
,
class
B
>
__INLINE
INMOST
::
soft_max_expression
<
A
,
B
>
soft_max
(
INMOST
::
shell_expression
<
A
>
const
&
Left
,
INMOST
::
shell_expression
<
B
>
const
&
Right
,
INMOST_DATA_REAL_TYPE
tol
)
{
return
INMOST
::
soft_max_expression
<
A
,
B
>
(
Left
,
Right
,
tol
);
}
__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
));}
template
<
class
A
,
class
B
>
__INLINE
INMOST
::
soft_min_expression
<
A
,
B
>
soft_min
(
INMOST
::
shell_expression
<
A
>
const
&
Left
,
INMOST
::
shell_expression
<
B
>
const
&
Right
,
INMOST_DATA_REAL_TYPE
tol
)
{
return
INMOST
::
soft_min_expression
<
A
,
B
>
(
Left
,
Right
,
tol
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment