Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
8b0a9960
There was an error fetching the commit references. Please try again later.
Commit
8b0a9960
authored
7 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Replaced larger_type with std::common_type in Math.h
parent
9d7576a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/TNL/Math.h
+7
-27
7 additions, 27 deletions
src/TNL/Math.h
with
7 additions
and
27 deletions
src/TNL/Math.h
+
7
−
27
View file @
8b0a9960
...
...
@@ -18,32 +18,12 @@
namespace
TNL
{
template
<
typename
T1
,
typename
T2
>
using
enable_if_same_base
=
std
::
enable_if
<
std
::
is_same
<
typename
std
::
decay
<
T1
>::
type
,
T2
>::
value
,
T2
>
;
template
<
typename
T1
,
typename
T2
>
using
both_integral_or_floating
=
typename
std
::
conditional
<
(
std
::
is_integral
<
T1
>::
value
&&
std
::
is_integral
<
T2
>::
value
)
||
(
std
::
is_floating_point
<
T1
>::
value
&&
std
::
is_floating_point
<
T2
>::
value
),
std
::
true_type
,
std
::
false_type
>::
type
;
// 1. If both types are integral or floating-point, the larger type is selected.
// 2. If one type is integral and the other floating-point, the floating-point type is selected.
// Casting both arguments to the same type is necessary because std::min and std::max
// are implemented as a single-type template.
template
<
typename
T1
,
typename
T2
>
using
larger_type
=
typename
std
::
conditional
<
(
both_integral_or_floating
<
T1
,
T2
>::
value
&&
sizeof
(
T1
)
>=
sizeof
(
T2
)
)
||
std
::
is_floating_point
<
T1
>::
value
,
T1
,
T2
>::
type
;
/***
* This function returns minimum of two numbers.
* GPU device code uses the functions defined in the CUDA's math_functions.h,
* MIC uses trivial override and host uses the STL functions.
*/
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
inline
ResultType
min
(
const
T1
&
a
,
const
T2
&
b
)
{
...
...
@@ -62,7 +42,7 @@ ResultType min( const T1& a, const T2& b )
* GPU device code uses the functions defined in the CUDA's math_functions.h,
* MIC uses trivial override and host uses the STL functions.
*/
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
ResultType
max
(
const
T1
&
a
,
const
T2
&
b
)
{
...
...
@@ -94,7 +74,7 @@ T abs( const T& n )
/***
* This function returns argument of minimum of two numbers.
*/
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
inline
ResultType
argMin
(
const
T1
&
a
,
const
T2
&
b
)
{
...
...
@@ -104,7 +84,7 @@ ResultType argMin( const T1& a, const T2& b )
/***
* This function returns argument of maximum of two numbers.
*/
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
ResultType
argMax
(
const
T1
&
a
,
const
T2
&
b
)
{
...
...
@@ -114,7 +94,7 @@ ResultType argMax( const T1& a, const T2& b )
/***
* This function returns argument of minimum of absolute values of two numbers.
*/
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
inline
ResultType
argAbsMin
(
const
T1
&
a
,
const
T2
&
b
)
{
...
...
@@ -124,14 +104,14 @@ ResultType argAbsMin( const T1& a, const T2& b )
/***
* This function returns argument of maximum of absolute values of two numbers.
*/
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
ResultType
argAbsMax
(
const
T1
&
a
,
const
T2
&
b
)
{
return
(
TNL
::
abs
(
a
)
>
TNL
::
abs
(
b
)
)
?
a
:
b
;
}
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
larger
_type
<
T1
,
T2
>
>
template
<
typename
T1
,
typename
T2
,
typename
ResultType
=
typename
std
::
common
_type
<
T1
,
T2
>
::
type
>
__cuda_callable__
inline
ResultType
pow
(
const
T1
&
base
,
const
T2
&
exp
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment