/usr/include/TiledArray/tile_op/mult.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 | /*
* 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
*
* mult.h
* May 8, 2013
*
*/
#ifndef TILEDARRAY_TILE_OP_MULT_H__INCLUDED
#define TILEDARRAY_TILE_OP_MULT_H__INCLUDED
#include <TiledArray/error.h>
#include <TiledArray/tile_op/tile_interface.h>
#include <TiledArray/zero_tensor.h>
namespace TiledArray {
namespace detail {
template <typename> class BinaryWrapper;
} // namespace detail
/// Tile multiplication operation
/// This multiplication will multiply 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 Mult {
public:
typedef Mult<Left, Right, LeftConsumable, RightConsumable> Mult_;
typedef Left left_type; ///< Left-hand argument base type
typedef Right right_type; ///< Right-hand argument base type
// typedef Left result_type;
typedef decltype(mult(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::mult;
return mult(first, second, perm);
}
static result_type eval(ZeroTensor, const right_type& second,
const Permutation& perm)
{
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
static result_type eval(const left_type& first, ZeroTensor,
const Permutation& perm)
{
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
// 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::mult;
return mult(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::mult_to;
return mult_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::mult_to;
return mult_to(second, first);
}
template <bool LC, bool RC,
typename std::enable_if<!RC>::type* = nullptr>
static result_type eval(ZeroTensor, const right_type& second) {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
template <bool LC, bool RC,
typename std::enable_if<RC>::type* = nullptr>
static result_type eval(ZeroTensor, right_type& second) {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
template <bool LC, bool RC,
typename std::enable_if<!LC>::type* = nullptr>
static result_type eval(const left_type& first, ZeroTensor) {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
template <bool LC, bool RC,
typename std::enable_if<LC>::type* = nullptr>
static result_type eval(left_type& first, ZeroTensor) {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
public:
/// Multiply-and-permute operator
/// Compute the product of two tiles and permute the result.
/// \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 product 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);
}
/// Multiply operator
/// Compute the product of two tiles.
/// \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 product of `left` and `right`.
template <typename L, typename R>
result_type operator()(L&& left, R&& right) const {
return Mult_::template eval<left_is_consumable, right_is_consumable>(
std::forward<L>(left), std::forward<R>(right));
}
/// Multiply right to left
/// Multiply the right tile to the left.
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The product of `left` and `right`.
template <typename R>
result_type consume_left(left_type& left, R&& right) const {
return Mult_::template eval<is_consumable_tile<left_type>::value, false>(
left, std::forward<R>(right));
}
/// Multiply left to right
/// Multiply the left tile to the right.
/// \tparam L The left-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The product of `left` and `right`.
template <typename L>
result_type consume_right(L&& left, right_type& right) const {
return Mult_::template eval<false, is_consumable_tile<right_type>::value>(
std::forward<L>(left), right);
}
}; // class Mult
/// Tile scale-multiplication operation
/// This multiplication operation will multiply 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 ScalMult {
public:
typedef ScalMult<Left, Right, Scalar, LeftConsumable, RightConsumable> ScalMult_;
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(mult(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::mult;
return mult(first, second, factor_, perm);
}
result_type eval(ZeroTensor, const right_type& second,
const Permutation& perm) const
{
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
result_type eval(const left_type& first, ZeroTensor,
const Permutation& perm) const
{
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
// 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::mult;
return mult(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::mult_to;
return mult_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::mult_to;
return mult_to(second, first, factor_);
}
template <bool LC, bool RC,
typename std::enable_if<!RC>::type* = nullptr>
result_type eval(ZeroTensor, const right_type& second) const {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
template <bool LC, bool RC,
typename std::enable_if<RC>::type* = nullptr>
result_type eval(ZeroTensor, right_type& second) const {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
template <bool LC, bool RC,
typename std::enable_if<!LC>::type* = nullptr>
result_type eval(const left_type& first, ZeroTensor) const {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
template <bool LC, bool RC,
typename std::enable_if<LC>::type* = nullptr>
result_type eval(left_type& first, ZeroTensor) const {
TA_ASSERT(false); // Invalid arguments for this operation
return result_type();
}
public:
// Compiler generated functions
ScalMult(const ScalMult_&) = default;
ScalMult(ScalMult_&&) = default;
~ScalMult() = default;
ScalMult_& operator=(const ScalMult_&) = default;
ScalMult_& operator=(ScalMult_&&) = default;
/// Constructor
/// \param factor The scaling factor applied to result tiles
explicit ScalMult(const Scalar factor) : factor_(factor) { }
/// Scale-multiply-and-permute operator
/// Compute the scaled product of two tiles and permute the result.
/// \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 product 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-multiply operator
/// Compute the scaled product of two tiles.
/// \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 product of `left` and `right`.
template <typename L, typename R>
result_type operator()(L&& left, R&& right) const {
return ScalMult_::template eval<left_is_consumable,
right_is_consumable>(std::forward<L>(left), std::forward<R>(right));
}
/// Multiply right to left and scale the result
/// Multiply the right tile to the left.
/// \tparam R The right-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The product of `left` and `right`.
template <typename R>
result_type consume_left(left_type& left, R&& right) const {
return ScalMult_::template eval<is_consumable_tile<left_type>::value, false>(left,
std::forward<R>(right));
}
/// Multiply left to right and scale the result
/// Multiply the left tile to the right, and scale the resulting left tile.
/// \tparam L The left-hand tile argument type
/// \param left The left-hand tile argument
/// \param right The right-hand tile argument
/// \return The product of `left` and `right`.
template <typename L>
result_type consume_right(L&& left, right_type& right) const {
return ScalMult_::template eval<false, is_consumable_tile<right_type>::value>(std::forward<L>(left),
right);
}
}; // class ScalMult
} // namespace TiledArray
#endif // TILEDARRAY_TILE_OP_MULT_H__INCLUDED
|