-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Pressio/13-elementiwe_reicprocal-also-add…
…-for-teptra-and-tpetra-block #13: Add elementwise_reciprocal for tpetra and tpetra block
- Loading branch information
Showing
9 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.. include:: ../../mydefs.rst | ||
|
||
``elementwise_reciprocal`` | ||
========================== | ||
|
||
Header: ``<pressio/ops.hpp>`` | ||
|
||
API | ||
--- | ||
|
||
.. code-block:: cpp | ||
namespace pressio { namespace ops{ | ||
template <class T1, class T2> | ||
void elementwise_reciprocal(const T1 & z, T2 & y); | ||
}} // end namespace pressio::ops | ||
Description | ||
----------- | ||
|
||
* Computes the elementwise reciprocal of ``z`` and stores it in ``y`` (``y = 1/z``) | ||
|
||
* ``T1`` and ``T2`` must be one-dimensional containers with compatible scalar types. They may be: | ||
|
||
* Eigen vectors or Pressio rank-1 expressions built from Eigen containers | ||
|
||
* Kokkos rank-1 views or Pressio rank-1 expressions built from Kokkos containers | ||
|
||
* Tpetra vectors or column expressions | ||
|
||
* Tpetra block vectors or column expressions | ||
|
||
Notes | ||
----- | ||
|
||
* See the :doc:`ops homepage <../ops>` for a table of booleans to use when checking that ``T1`` and ``T2`` have the correct types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// ops_elementwise_reciprocal.hpp | ||
// Pressio | ||
// Copyright 2019 | ||
// National Technology & Engineering Solutions of Sandia, LLC (NTESS) | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, the | ||
// U.S. Government retains certain rights in this software. | ||
// | ||
// Pressio is licensed under BSD-3-Clause terms of use: | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its | ||
// contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
// Questions? Contact Francesco Rizzi ([email protected]) | ||
// | ||
// ************************************************************************ | ||
//@HEADER | ||
*/ | ||
|
||
#ifndef PRESSIOOPS_OPS_TPETRA_OPS_ELEMENTWISE_RECIPROCAL_HPP_ | ||
#define PRESSIOOPS_OPS_TPETRA_OPS_ELEMENTWISE_RECIPROCAL_HPP_ | ||
|
||
namespace pressio{ namespace ops{ | ||
|
||
//---------------------------------------------------------------------- | ||
// computing elementwise: y = 1/z | ||
//---------------------------------------------------------------------- | ||
template <typename T1, typename T2> | ||
std::enable_if_t< | ||
// TPL/container specific | ||
( ::pressio::is_vector_tpetra<T1>::value | ||
|| ::pressio::is_expression_column_acting_on_tpetra<T1>::value) | ||
&& ( ::pressio::is_vector_tpetra<T2>::value | ||
|| ::pressio::is_expression_column_acting_on_tpetra<T2>::value) | ||
// scalar compatibility | ||
&& ::pressio::all_have_traits_and_same_scalar<T1, T2>::value | ||
&& (std::is_floating_point<typename ::pressio::Traits<T1>::scalar_type>::value | ||
|| std::is_integral<typename ::pressio::Traits<T1>::scalar_type>::value) | ||
> | ||
elementwise_reciprocal(const T1 & zin, T2 & yin) | ||
{ | ||
auto z = impl::get_native(zin); | ||
auto y = impl::get_native(yin); | ||
assert(::pressio::ops::extent(z, 0)==::pressio::ops::extent(y, 0)); | ||
y.reciprocal(z); | ||
} | ||
|
||
}}//end namespace pressio::ops | ||
#endif // PRESSIOOPS_OPS_TPETRA_OPS_ELEMENTWISE_RECIPROCAL_HPP_ |
77 changes: 77 additions & 0 deletions
77
include/pressio/ops/tpetra_block/ops_elementwise_reciprocal.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// ops_elementwise_reciprocal.hpp | ||
// Pressio | ||
// Copyright 2019 | ||
// National Technology & Engineering Solutions of Sandia, LLC (NTESS) | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, the | ||
// U.S. Government retains certain rights in this software. | ||
// | ||
// Pressio is licensed under BSD-3-Clause terms of use: | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its | ||
// contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
// Questions? Contact Francesco Rizzi ([email protected]) | ||
// | ||
// ************************************************************************ | ||
//@HEADER | ||
*/ | ||
|
||
#ifndef PRESSIOOPS_OPS_TPETRA_BLOCK_OPS_ELEMENTWISE_RECIPROCAL_HPP_ | ||
#define PRESSIOOPS_OPS_TPETRA_BLOCK_OPS_ELEMENTWISE_RECIPROCAL_HPP_ | ||
|
||
namespace pressio{ namespace ops{ | ||
|
||
//---------------------------------------------------------------------- | ||
// computing elementwise: y = 1/z | ||
//---------------------------------------------------------------------- | ||
template <typename T1, typename T2> | ||
std::enable_if_t< | ||
( ::pressio::is_vector_tpetra_block<T1>::value | ||
|| ::pressio::is_expression_column_acting_on_tpetra_block<T1>::value) | ||
&& ( ::pressio::is_vector_tpetra_block<T2>::value | ||
|| ::pressio::is_expression_column_acting_on_tpetra_block<T2>::value) | ||
// scalar compatibility | ||
&& ::pressio::all_have_traits_and_same_scalar<T1, T2>::value | ||
&& (std::is_floating_point<typename ::pressio::Traits<T1>::scalar_type>::value | ||
|| std::is_integral<typename ::pressio::Traits<T1>::scalar_type>::value) | ||
> | ||
elementwise_reciprocal(const T1 & z, T2 & y) | ||
{ | ||
assert(extent(z,0)==extent(y,0)); | ||
auto z_tp = impl::get_underlying_tpetra_object(z); | ||
auto y_tp = impl::get_underlying_tpetra_object(y); | ||
y_tp.reciprocal(z_tp); | ||
} | ||
|
||
}}//end namespace pressio::ops | ||
#endif // PRESSIOOPS_OPS_TPETRA_BLOCK_OPS_ELEMENTWISE_RECIPROCAL_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters