product.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2020 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Eduard Valeyev
19  * Department of Chemistry, Virginia Tech
20  *
21  * permopt.h
22  * Nov 2, 2020
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXPRESSIONS_PRODUCT_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_PRODUCT_H__INCLUDED
28 
30 
31 namespace TiledArray {
32 namespace expressions {
33 
35 enum class TensorProduct {
37  Hadamard,
39  Contraction,
41  General,
43  Invalid = -1
44 };
45 
51 inline TensorProduct compute_product_type(const IndexList& left_indices,
52  const IndexList& right_indices) {
54  if (left_indices && right_indices) {
55  if (left_indices.size() == right_indices.size() &&
56  left_indices.is_permutation(right_indices))
57  result = TensorProduct::Hadamard;
58  else
59  result = TensorProduct::Contraction;
60  }
61  return result;
62 }
63 
66 inline TensorProduct compute_product_type(const IndexList& left_indices,
67  const IndexList& right_indices,
68  const IndexList& target_indices) {
69  auto result = compute_product_type(left_indices, right_indices);
70  if (result == TensorProduct::Hadamard)
71  TA_ASSERT(left_indices.is_permutation(target_indices));
72  return result;
73 }
74 
75 } // namespace expressions
76 } // namespace TiledArray
77 
78 #endif // TILEDARRAY_EXPRESSIONS_PRODUCT_H__INCLUDED
bool is_permutation(const IndexList &other) const
Check that this index list is a permutation of other.
Definition: index_list.h:254
#define TA_ASSERT(EXPR,...)
Definition: error.h:39
TensorProduct compute_product_type(const IndexList &left_indices, const IndexList &right_indices)
Definition: product.h:51
TensorProduct
types of binary tensor products known to TiledArray
Definition: product.h:35
unsigned int size() const
Returns the number of elements in the index list.
Definition: index_list.h:197