/usr/include/TiledArray/tile_op/add.h is in libtiledarray-dev 0.6.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | /*
* This file is a part of TiledArray.
* Copyright (C) 2013 Virginia Tech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Justus Calvin
* Department of Chemistry, Virginia Tech
*
* add.h
* May 7, 2013
*
*/
#ifndef TILEDARRAY_TILE_OP_ADD_H__INCLUDED
#define TILEDARRAY_TILE_OP_ADD_H__INCLUDED
#include <TiledArray/tile_op/tile_interface.h>
#include <TiledArray/zero_tensor.h>
namespace TiledArray {
/// Tile addition operation
/// This addition operation will add the content two tiles, and accepts an
/// optional permute argument.
/// \tparam Left The left-hand argument type
/// \tparam Right The right-hand argument type
/// \tparam LeftConsumable A flag that is \c true when the left-hand
/// argument is consumable.
/// \tparam RightConsumable A flag that is \c true when the right-hand
/// argument is consumable.
template <typename Left, typename Right, bool LeftConsumable,
bool RightConsumable>
class Add {
public:
typedef Add<Left, Right, LeftConsumable, RightConsumable> Add_;
typedef Left left_type; ///< Left-hand argument base type
typedef Right right_type; ///< Right-hand argument base type
// typedef Left result_type;
typedef decltype(add(std::declval<left_type>(), std::declval<right_type>()))
result_type;
static constexpr bool left_is_consumable =
LeftConsumable && std::is_same<result_type, left_type>::value;
static constexpr bool right_is_consumable =
RightConsumable && std::is_same<result_type, right_type>::value;
private:
// Permuting tile evaluation function
// These operations cannot consume the argument tile since this operation
// requires temporary storage space.
static result_type eval(const left_type& first, const right_type& second,
const Permutation& perm)
{
using TiledArray::add;
return add(first, second, perm);
}
static result_type eval(ZeroTensor, const right_type& second,
const Permutation& perm)
{
using TiledArray::permute;
return permute(second, perm);
}
static result_type eval(const left_type& first, ZeroTensor,
const Permutation& perm)
{
using TiledArray::permute;
return permute(first, perm);
}
// Non-permuting tile evaluation functions
// The compiler will select the correct functions based on the consumability
// of the arguments.
template <bool LC, bool RC,
typename std::enable_if<!(LC || RC)>::type* = nullptr>
static result_type eval(const left_type& first, const right_type& second) {
using TiledArray::add;
return add(first, second);
}
template <bool LC, bool RC,
typename std::enable_if<LC>::type* = nullptr>
static result_type eval(left_type& first, const right_type& second) {
using TiledArray::add_to;
return add_to(first, second);
}
template <bool LC, bool RC,
typename std::enable_if<!LC && RC>::type* = nullptr>
static result_type eval(const left_type& first, right_type& second) {
using TiledArray::add_to;
return add_to(second, first);
}
template <bool LC, bool RC,
typename std::enable_if<!RC>::type* = nullptr>
static result_type eval(const ZeroTensor&, const right_type& second) {
using TiledArray::clone;
return clone(second);
}
template <bool LC, bool RC,
typename std::enable_if<RC>::type* = nullptr>
static result_type eval(const ZeroTensor&, right_type& second) {
return second;
}
template <bool LC, bool RC,
typename std::enable_if<!LC>::type* = nullptr>
static result_type eval(const left_type& first, const ZeroTensor&) {
using TiledArray::clone;
return clone(first);
}
template <bool LC, bool RC,
typename std::enable_if<LC>::type* = nullptr>
static result_type eval(left_type& first, const ZeroTensor&) {
return first;
}
public:
/// Add-and-permute operator
/// Compute the sum of two tiles and permute the result. One of the argument
/// tiles may be replaced with `ZeroTensor` argument, in which case the
/// argument's element values are assumed to be `0`.
/// \tparam L The left-hand tile argument type
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \param perm The permutation applied to the result tile
/// \return The permuted and scaled sum of `left` and `right`.
template <typename L, typename R>
result_type operator()(L&& left, R&& right, const Permutation& perm) const {
return eval(std::forward<L>(left), std::forward<R>(right), perm);
}
/// Add operator
/// Compute the sum of two tiles. One of the argument tiles may be replaced
/// with `ZeroTensor` argument, in which case the argument's element values
/// are assumed to be `0`.
/// \tparam L The left-hand tile argument type
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The scaled sum of `left` and `right`.
template <typename L, typename R>
result_type operator()(L&& left, R&& right) const {
return Add_::template eval<left_is_consumable, right_is_consumable>(
std::forward<L>(left), std::forward<R>(right));
}
/// Add right to left
/// Add the right tile to the left. The right tile may be replaced with
/// `ZeroTensor` argument, in which case the argument's element values are
/// assumed to be `0`.
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The sum of `left` and `right`.
template <typename R>
result_type consume_left(left_type& left, R&& right) const {
return Add_::template eval<is_consumable_tile<left_type>::value,
false>(left, std::forward<R>(right));
}
/// Add left to right
/// Add the left tile to the right. The left tile may be replaced with
/// `ZeroTensor` argument, in which case the argument's element values are
/// assumed to be `0`.
/// \tparam L The left-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The sum of `left` and `right`.
template <typename L>
result_type consume_right(L&& left, right_type& right) const {
return Add_::template eval<false,
is_consumable_tile<right_type>::value>(std::forward<L>(left), right);
}
}; // class Add
/// Tile scale-addition operation
/// This addition operation will add the content two tiles and apply a
/// permutation to the result tensor. If no permutation is given or the
/// permutation is null, then the result is not permuted.
/// \tparam Left The left-hand argument type
/// \tparam Right The right-hand argument type
/// \tparam Scalar The scaling factor type
/// \tparam LeftConsumable A flag that is \c true when the left-hand
/// argument is consumable.
/// \tparam RightConsumable A flag that is \c true when the right-hand
/// argument is consumable.
template <typename Left, typename Right, typename Scalar, bool LeftConsumable,
bool RightConsumable>
class ScalAdd {
public:
typedef ScalAdd<Left, Right, Scalar, LeftConsumable, RightConsumable> ScalAdd_;
typedef Left left_type; ///< Left-hand argument base type
typedef Right right_type; ///< Right-hand argument base type
typedef Scalar scalar_type; ///< Scaling factor type
// typedef Left result_type;
typedef decltype(add(std::declval<left_type>(), std::declval<right_type>(),
std::declval<scalar_type>())) result_type;
static constexpr bool left_is_consumable =
LeftConsumable && std::is_same<result_type, left_type>::value;
static constexpr bool right_is_consumable =
RightConsumable && std::is_same<result_type, right_type>::value;
private:
scalar_type factor_;
// Permuting tile evaluation function
// These operations cannot consume the argument tile since this operation
// requires temporary storage space.
result_type eval(const left_type& first, const right_type& second,
const Permutation& perm) const
{
using TiledArray::add;
return add(first, second, factor_, perm);
}
result_type eval(ZeroTensor, const right_type& second,
const Permutation& perm) const
{
using TiledArray::scale;
return scale(second, factor_, perm);
}
result_type eval(const left_type& first, ZeroTensor,
const Permutation& perm) const
{
using TiledArray::scale;
return scale(first, factor_, perm);
}
// Non-permuting tile evaluation functions
// The compiler will select the correct functions based on the consumability
// of the arguments.
template <bool LC, bool RC,
typename std::enable_if<!(LC || RC)>::type* = nullptr>
result_type eval(const left_type& first, const right_type& second) const {
using TiledArray::add;
return add(first, second, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<LC>::type* = nullptr>
result_type eval(left_type& first, const right_type& second) const {
using TiledArray::add_to;
return add_to(first, second, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<!LC && RC>::type* = nullptr>
result_type eval(const left_type& first, right_type& second) const {
using TiledArray::add_to;
return add_to(second, first, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<!RC>::type* = nullptr>
result_type eval(const ZeroTensor&, const right_type& second) const {
using TiledArray::scale;
return scale(second, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<RC>::type* = nullptr>
result_type eval(const ZeroTensor&, right_type& second) const {
using TiledArray::scale_to;
return scale_to(second, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<!LC>::type* = nullptr>
result_type eval(const left_type& first, const ZeroTensor&) const {
using TiledArray::scale;
return scale(first, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<LC>::type* = nullptr>
result_type eval(left_type& first, const ZeroTensor&) const {
using TiledArray::scale_to;
return scale_to(first, factor_);
}
public:
// Compiler generated functions
ScalAdd(const ScalAdd_&) = default;
ScalAdd(ScalAdd_&&) = default;
~ScalAdd() = default;
ScalAdd_& operator=(const ScalAdd_&) = default;
ScalAdd_& operator=(ScalAdd_&&) = default;
/// Constructor
/// \param factor The scaling factor applied to result tiles
explicit ScalAdd(const Scalar factor) : factor_(factor) { }
/// Scale-add-and-permute operator
/// Compute the scaled sum of two tiles and permute the result. One of the
/// argument tiles may be replaced with `ZeroTensor` argument, in which
/// case the argument's element values are assumed to be `0`.
/// \tparam L The left-hand tile argument type
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \param perm The permutation applied to the result tile
/// \return The permuted and scaled sum of `left` and `right`.
template <typename L, typename R>
result_type operator()(L&& left, R&& right, const Permutation& perm) const {
return eval(std::forward<L>(left), std::forward<R>(right), perm);
}
/// Scale-and-add operator
/// Compute the scaled sum of two tiles. One of the argument tiles may be
/// replaced with `ZeroTensor` argument, in which case the argument's
/// element values are assumed to be `0`.
/// \tparam L The left-hand tile argument type
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The scaled sum of `left` and `right`.
template <typename L, typename R>
result_type operator()(L&& left, R&& right) const {
return ScalAdd_::template eval<left_is_consumable,
right_is_consumable>(std::forward<L>(left), std::forward<R>(right));
}
/// Add right to left and scale the result
/// Add the right tile to the left. The right tile may be replaced with
/// `ZeroTensor` argument, in which case the argument's element values are
/// assumed to be `0`.
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The sum of `left` and `right`.
template <typename R>
result_type consume_left(left_type& left, R&& right) const {
return ScalAdd_::template eval<is_consumable_tile<left_type>::value,
false>(left, std::forward<R>(right));
}
/// Add left to right and scale the result
/// Add the left tile to the right, and scale the resulting left tile. The
/// left tile may be replaced with `ZeroTensor` argument, in which case the
/// argument's element values are assumed to be `0`.
/// \tparam L The left-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The sum of `left` and `right`.
template <typename L>
result_type consume_right(L&& left, right_type& right) const {
return ScalAdd_::template eval<false,
is_consumable_tile<right_type>::value>(std::forward<L>(left), right);
}
}; // class ScalAdd
} // namespace TiledArray
#endif // TILEDARRAY_TILE_OP_ADD_H__INCLUDED
|