Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81579220
loop_utils.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 6, 20:50
Size
2 KB
Mime Type
text/x-c++
Expires
Sun, Sep 8, 20:50 (2 d)
Engine
blob
Format
Raw Data
Handle
20598383
Attached To
rTAMAAS tamaas
loop_utils.hh
View Options
/**
* @file
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef __LOOP_UTILS_HH__
#define __LOOP_UTILS_HH__
/* -------------------------------------------------------------------------- */
#include "tamaas.hh"
#include "loop.hh"
#include <type_traits>
#include <limits>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
namespace
detail
{
template
<
bool
only_points
=
false
,
typename
...
Grids
>
UInt
loopSize
(
Grids
&&
...
grids
)
{
return
(
only_points
)
?
std
::
get
<
0
>
(
std
::
forward_as_tuple
(
grids
...)).
getNbPoints
()
:
std
::
get
<
0
>
(
std
::
forward_as_tuple
(
grids
...)).
dataSize
();
}
template
<
operation
op
>
struct
reduction_helper
;
template
<>
struct
reduction_helper
<
operation
::
plus
>
{
template
<
typename
T
>
static
constexpr
T
init
()
{
return
T
(
0
);
}
template
<
typename
T
>
static
void
reduce
(
T
&
res
,
T
val
)
{
res
+=
val
;
}
};
template
<>
struct
reduction_helper
<
operation
::
times
>
{
template
<
typename
T
>
static
constexpr
T
init
()
{
return
T
(
1
);
}
template
<
typename
T
>
static
void
reduce
(
T
&
res
,
T
val
)
{
res
*=
val
;
}
};
template
<>
struct
reduction_helper
<
operation
::
min
>
{
template
<
typename
T
>
static
constexpr
T
init
()
{
return
std
::
numeric_limits
<
T
>::
max
();
}
template
<
typename
T
>
static
void
reduce
(
T
&
res
,
T
val
)
{
res
=
std
::
min
(
res
,
val
);
}
};
template
<>
struct
reduction_helper
<
operation
::
max
>
{
template
<
typename
T
>
static
constexpr
T
init
()
{
return
std
::
numeric_limits
<
T
>::
lowest
();
}
template
<
typename
T
>
static
void
reduce
(
T
&
res
,
T
val
)
{
res
=
std
::
max
(
res
,
val
);
}
};
}
__END_TAMAAS__
#endif
// __LOOP_UTILS_HH
Event Timeline
Log In to Comment