/usr/include/TiledArray/expressions/mult_expr.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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | /*
* 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_expr.h
* Mar 31, 2014
*
*/
#ifndef TILEDARRAY_EXPRESSIONS_MULT_EXPR_H__INCLUDED
#define TILEDARRAY_EXPRESSIONS_MULT_EXPR_H__INCLUDED
#include <TiledArray/expressions/binary_expr.h>
#include <TiledArray/expressions/mult_engine.h>
namespace TiledArray {
namespace expressions {
template <typename Left, typename Right>
using ConjMultExpr =
ScalMultExpr<Left, Right, TiledArray::detail::ComplexConjugate<void> >;
template <typename Left, typename Right, typename Scalar>
using ScalConjMultExpr =
ScalMultExpr<Left, Right, TiledArray::detail::ComplexConjugate<Scalar> >;
using TiledArray::detail::conj_op;
using TiledArray::detail::mult_t;
using TiledArray::detail::numeric_t;
using TiledArray::detail::scalar_t;
template <typename Left, typename Right>
struct ExprTrait<MultExpr<Left, Right> > {
typedef Left left_type; ///< The left-hand expression type
typedef Right right_type; ///< The right-hand expression type
typedef MultEngine<typename ExprTrait<Left>::engine_type,
typename ExprTrait<Right>::engine_type>
engine_type; ///< Expression engine type
typedef numeric_t<typename EngineTrait<engine_type>::eval_type>
numeric_type; ///< Multiplication result numeric type
typedef scalar_t<typename EngineTrait<engine_type>::eval_type>
scalar_type; ///< Multiplication result scalar type
};
template <typename Left, typename Right, typename Scalar>
struct ExprTrait<ScalMultExpr<Left, Right, Scalar> > {
typedef Left left_type; ///< The left-hand expression type
typedef Right right_type; ///< The right-hand expression type
typedef ScalMultEngine<typename ExprTrait<Left>::engine_type,
typename ExprTrait<Right>::engine_type, Scalar> engine_type; ///< Expression engine type
typedef numeric_t<typename EngineTrait<engine_type>::eval_type>
numeric_type; ///< Multiplication result numeric type
typedef Scalar scalar_type; ///< Tile scalar type
};
/// Multiplication expression
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
template <typename Left, typename Right>
class MultExpr : public BinaryExpr<MultExpr<Left, Right> > {
public:
typedef MultExpr<Left, Right> MultExpr_; ///< This class type
typedef BinaryExpr<MultExpr_> BinaryExpr_; ///< Binary expression base type
typedef typename ExprTrait<MultExpr_>::left_type left_type; ///< The left-hand expression type
typedef typename ExprTrait<MultExpr_>::right_type right_type; ///< The right-hand expression type
typedef typename ExprTrait<MultExpr_>::engine_type engine_type; ///< Expression engine type
// Compiler generated functions
MultExpr(const MultExpr_&) = default;
MultExpr(MultExpr_&&) = default;
~MultExpr() = default;
MultExpr_& operator=(const MultExpr_&) = delete;
MultExpr_& operator=(MultExpr_&&) = delete;
/// Expression constructor
/// \param left The left-hand expression
/// \param right The right-hand expression
MultExpr(const left_type& left, const right_type& right) :
BinaryExpr_(left, right)
{ }
/// Dot product
/// \tparam Numeric A numeric type
/// \return The dot product of this expression.
template <typename Numeric,
typename std::enable_if<
TiledArray::detail::is_numeric<Numeric>::value
>::type* = nullptr>
operator Numeric() const {
auto result = BinaryExpr_::left().dot(BinaryExpr_::right());
return result.get();
}
/// Dot product
/// \tparam Numeric A numeric type
/// \return The dot product of this expression.
template <typename Numeric,
typename std::enable_if<
TiledArray::detail::is_numeric<Numeric>::value
>::type* = nullptr>
operator Future<Numeric>() const {
return BinaryExpr_::left().dot(BinaryExpr_::right());
}
}; // class MultExpr
/// Multiplication expression
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
template <typename Left, typename Right, typename Scalar>
class ScalMultExpr : public BinaryExpr<ScalMultExpr<Left, Right, Scalar> > {
public:
typedef ScalMultExpr<Left, Right, Scalar> ScalMultExpr_; ///< This class type
typedef BinaryExpr<ScalMultExpr_> BinaryExpr_; ///< Binary expression base type
typedef typename ExprTrait<ScalMultExpr_>::left_type left_type; ///< The left-hand expression type
typedef typename ExprTrait<ScalMultExpr_>::right_type right_type; ///< The right-hand expression type
typedef typename ExprTrait<ScalMultExpr_>::engine_type engine_type; ///< Expression engine type
typedef typename ExprTrait<ScalMultExpr_>::scalar_type scalar_type; ///< Tile scalar type
private:
scalar_type factor_; ///< The scaling factor
public:
// Compiler generated functions
ScalMultExpr(const ScalMultExpr_&) = default;
ScalMultExpr(ScalMultExpr_&&) = default;
~ScalMultExpr() = default;
ScalMultExpr_& operator=(const ScalMultExpr_&) = delete;
ScalMultExpr_& operator=(ScalMultExpr_&&) = delete;
/// Expression constructor
/// \param arg The argument expression
/// \param factor The scaling factor
ScalMultExpr(const left_type& left, const right_type& right,
const scalar_type factor) :
BinaryExpr_(left, right), factor_(factor)
{ }
/// Scaling factor accessor
/// \return The scaling factor
scalar_type factor() const { return factor_; }
}; // class ScalMultExpr
/// Multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param left The left-hand expression object
/// \param right The right-hand expression object
/// \return An multiplication expression object
template <typename Left, typename Right>
inline MultExpr<Left, Right>
operator*(const Expr<Left>& left, const Expr<Right>& right) {
static_assert(TiledArray::expressions::is_aliased<Left>::value,
"no_alias() expressions are not allowed on the right-hand side of the "
"assignment operator.");
static_assert(TiledArray::expressions::is_aliased<Right>::value,
"no_alias() expressions are not allowed on the right-hand side of the "
"assignment operator.");
return MultExpr<Left, Right>(left.derived(), right.derived());
}
/// Scaled-multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param expr The multiplication expression object
/// \param factor The scaling factor
/// \return A scaled-multiplication expression object
template <typename Left, typename Right, typename Scalar,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar>::value
>::type* = nullptr>
inline ScalMultExpr<Left, Right, Scalar>
operator*(const MultExpr<Left, Right>& expr, const Scalar& factor) {
return ScalMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
factor);
}
/// Scaled-multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param factor The scaling factor
/// \param expr The multiplication expression object
/// \return A scaled-multiplication expression object
template <typename Left, typename Right, typename Scalar,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar>::value
>::type* = nullptr>
inline ScalMultExpr<Left, Right, Scalar>
operator*(const Scalar& factor, const MultExpr<Left, Right>& expr) {
return ScalMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
factor);
}
/// Scaled-multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar1 A scalar type
/// \tparam Scalar2 A scalar type
/// \param expr The multiplication expression object
/// \param factor The scaling factor
/// \return A scaled-multiplication expression object
template <typename Left, typename Right, typename Scalar1, typename Scalar2,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar2>::value
>::type* = nullptr>
inline ScalMultExpr<Left, Right, mult_t<Scalar1, Scalar2> >
operator*(const ScalMultExpr<Left, Right, Scalar1>& expr,
const Scalar2& factor)
{
return ScalMultExpr<Left, Right, mult_t<Scalar1, Scalar2> >(expr.left(),
expr.right(), expr.factor() * factor);
}
/// Scaled-multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar1 A scalar type
/// \tparam Scalar2 A scalar type
/// \param factor The scaling factor
/// \param expr The multiplication expression object
/// \return A scaled-multiplication expression object
template <typename Left, typename Right, typename Scalar1, typename Scalar2,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar1>::value
>::type* = nullptr>
inline ScalMultExpr<Left, Right, mult_t<Scalar2, Scalar1> >
operator*(const Scalar1& factor,
const ScalMultExpr<Left, Right, Scalar2>& expr)
{
return ScalMultExpr<Left, Right, mult_t<Scalar2, Scalar1> >(expr.left(),
expr.right(), expr.factor() * factor);
}
/// Negated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param expr The multiplication expression object
/// \return A scaled-multiplication expression object
template <typename Left, typename Right>
inline ScalMultExpr<Left, Right, typename ExprTrait<MultExpr<Left, Right> >::numeric_type>
operator-(const MultExpr<Left, Right>& expr) {
return ScalMultExpr<Left, Right, typename ExprTrait<MultExpr<Left,
Right> >::numeric_type>(expr.left(), expr.right(), -1);
}
/// Negated scaled-multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param expr The multiplication expression object
/// \return A scaled-multiplication expression object
template <typename Left, typename Right, typename Scalar>
inline ScalMultExpr<Left, Right, Scalar>
operator-(const ScalMultExpr<Left, Right, Scalar>& expr) {
return ScalMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
-expr.factor());
}
/// Conjugated multiplication expression factory
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param expr The multiplication expression object
/// \return A conjugated multiplication expression object
template <typename Left, typename Right>
inline ConjMultExpr<Left, Right> conj(const MultExpr<Left, Right>& expr) {
return ConjMultExpr<Left, Right>(expr.left(), expr.right(), conj_op());
}
/// Conjugated-conjugate multiplication expression factory
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param expr The multiplication expression object
/// \return A multiplication expression object
template <typename Left, typename Right>
inline MultExpr<Left, Right> conj(const ConjMultExpr<Left, Right>& expr) {
return MultExpr<Left, Right>(expr.left(), expr.right());
}
/// Conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param expr The multiplication expression object
/// \return A scaled-conjugated multiplication expression object
template <typename Left, typename Right, typename Scalar>
inline ScalConjMultExpr<Left, Right, Scalar>
conj(const ScalMultExpr<Left, Right, Scalar>& expr) {
return ScalConjMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
conj_op(TiledArray::detail::conj(expr.factor())));
}
/// Conjugated-conjugate multiplication expression factory
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param expr The scaled conjugate tensor expression object
/// \return A scaled multiplication expression object
template <typename Left, typename Right, typename Scalar>
inline ScalMultExpr<Left, Right, Scalar>
conj(const ScalConjMultExpr<Left, Right, Scalar>& expr) {
return ScalMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
TiledArray::detail::conj(expr.factor().factor()));
}
/// Scaled-conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param expr The tensor expression object
/// \param factor The scaling factor
/// \return A scaled-conjugated multiplication expression object
template <typename Left, typename Right, typename Scalar,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar>::value
>::type* = nullptr>
inline ScalConjMultExpr<Left, Right, Scalar>
operator*(const ConjMultExpr<Left, Right>& expr, const Scalar& factor) {
return ScalConjMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
conj_op(factor));
}
/// Scaled-conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param factor The scaling factor
/// \param expr The multiplication expression object
/// \return A scaled-conjugated multiplication expression object
template <typename Left, typename Right, typename Scalar,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar>::value
>::type* = nullptr>
inline ScalConjMultExpr<Left, Right, Scalar>
operator*(const Scalar& factor, const ConjMultExpr<Left, Right>& expr) {
return ScalConjMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
conj_op(factor));
}
/// Scaled-conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar1 The expression scaling factor type
/// \tparam Scalar2 The scaling factor type
/// \param expr The scaled-tensor expression object
/// \param factor The scaling factor
/// \return A scaled-conjugated multiplication expression object
template <typename Left, typename Right, typename Scalar1, typename Scalar2,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar2>::value
>::type* = nullptr>
inline ScalConjMultExpr<Left, Right, mult_t<Scalar1, Scalar2> >
operator*(const ScalConjMultExpr<Left, Right, Scalar1>& expr, const Scalar2& factor) {
return ScalConjMultExpr<Left, Right, mult_t<Scalar1, Scalar2> >(expr.left(),
expr.right(), conj_op(expr.factor().factor() * factor));
}
/// Scaled-conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar1 The scaling factor type
/// \tparam Scalar2 The expression scaling factor type
/// \param factor The scaling factor
/// \param expr The scaled-conjugated multiplication expression object
/// \return A scaled-conjugated multiplication expression object
template <typename Left, typename Right, typename Scalar1, typename Scalar2,
typename std::enable_if<
TiledArray::detail::is_numeric<Scalar1>::value
>::type* = nullptr>
inline ScalConjMultExpr<Left, Right, mult_t<Scalar2, Scalar1> >
operator*(const Scalar1& factor, const ScalConjMultExpr<Left, Right, Scalar2>& expr) {
return ScalConjMultExpr<Left, Right, mult_t<Scalar2, Scalar1> >(
expr.left(), expr.right(), conj_op(expr.factor().factor() * factor));
}
/// Negated-conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param expr The tensor expression object
/// \return A scaled-multiplication expression object
template <typename Left, typename Right>
inline ScalConjMultExpr<Left, Right,
typename ExprTrait<ConjMultExpr<Left, Right> >::numeric_type>
operator-(const ConjMultExpr<Left, Right>& expr) {
typedef typename ExprTrait<ConjMultExpr<Left, Right> >::numeric_type
scalar_type;
return ScalConjMultExpr<Left, Right, scalar_type>(expr.left(),
expr.right(), conj_op<scalar_type>(-1));
}
/// Negated-conjugated multiplication expression factor
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \tparam Scalar A scalar type
/// \param expr The scaled-conjugated-tensor expression object
/// \return A scaled-conjugated multiplication expression object
template <typename Left, typename Right, typename Scalar>
inline ScalConjMultExpr<Left, Right, Scalar>
operator-(const ScalConjMultExpr<Left, Right, Scalar>& expr) {
return ScalConjMultExpr<Left, Right, Scalar>(expr.left(), expr.right(),
conj_op(-expr.factor().factor()));
}
/// Dot product add-to operator
/// \tparam Numeric The numeric result type
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param result The result that the dot product will be added to.
/// \param expr The multiply expression object
/// \return A reference to result
template <typename Numeric, typename Left, typename Right,
typename std::enable_if<
TiledArray::detail::is_numeric<Numeric>::value
>::type* = nullptr>
inline Numeric&
operator +=(Numeric& result, const MultExpr<Left, Right>& expr) {
result += expr.left().dot(expr.right()).get();
return result;
}
/// Dot product subtract-to operator
/// \tparam Numeric The numeric result type
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param result The result that the dot product will be subtracted from.
/// \param expr The multiply expression object
/// \return A reference to result
template <typename Numeric, typename Left, typename Right,
typename std::enable_if<
TiledArray::detail::is_numeric<Numeric>::value
>::type* = nullptr>
inline Numeric&
operator -=(Numeric& result, const MultExpr<Left, Right>& expr) {
result -= expr.left().dot(expr.right()).get();
return result;
}
/// Dot product multiply-to operator
/// \tparam Numeric The numeric result type
/// \tparam Left The left-hand expression type
/// \tparam Right The right-hand expression type
/// \param result The result that the dot product will be multiplied by.
/// \param expr The multiply expression object
/// \return A reference to result
template <typename Numeric, typename Left, typename Right,
typename std::enable_if<
TiledArray::detail::is_numeric<Numeric>::value
>::type* = nullptr>
inline Numeric&
operator *=(Numeric& result, const MultExpr<Left, Right>& expr) {
result *= expr.left().dot(expr.right()).get();
return result;
}
} // namespace expressions
} // namespace TiledArray
#endif // TILEDARRAY_EXPRESSIONS_MULT_EXPR_H__INCLUDED
|