113 RankCombinationViewType rank_combination_types)
115 tensor_view_iterator_(tensor_view),
116 view1_iterator_(view1),
117 view2_iterator_(view2),
118 rank_combination_types_(rank_combination_types)
136 unsigned max_component_rank = (view1.rank() > view2.rank()) ? view1.rank() : view2.rank();
137 unsigned max_rank = (tensor_view.rank() > max_component_rank) ? tensor_view.rank() : max_component_rank;
141 unsigned expected_rank = 0;
142 bool contracting =
false;
143 for (
unsigned d=0; d<rank_combination_types.extent(0); d++)
145 if (rank_combination_types[d] == TENSOR_CONTRACTION)
156 if (rank_combination_types[d] == TENSOR_PRODUCT)
158 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(tensor_view.extent_int(d) != view1.extent_int(d) * view2.extent_int(d), std::invalid_argument,
"For TENSOR_PRODUCT rank combination, the tensor View must have length in that dimension equal to the product of the two component views in that dimension");
162 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(view1.extent_int(d) != view2.extent_int(d), std::invalid_argument,
"For DIMENSION_MATCH rank combination, all three views must have length equal to each other in that rank");
163 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(tensor_view.extent_int(d) != view1.extent_int(d), std::invalid_argument,
"For DIMENSION_MATCH rank combination, all three views must have length equal to each other in that rank");
180 int view2_next_increment_rank = view2_iterator_.nextIncrementRank();
181 int view1_next_increment_rank = view1_iterator_.nextIncrementRank();
182 if (view2_next_increment_rank > view1_next_increment_rank)
return view2_next_increment_rank;
183 else return view1_next_increment_rank;
201 int view2_next_increment_rank = view2_iterator_.nextIncrementRank();
202 int view1_next_increment_rank = view1_iterator_.nextIncrementRank();
203 if (view2_next_increment_rank > view1_next_increment_rank)
206 device_assert(rank_combination_types_[view2_next_increment_rank]==TENSOR_PRODUCT);
207 view1_iterator_.reset(view2_next_increment_rank);
208 view2_iterator_.increment();
209 tensor_view_iterator_.increment();
210 return view2_next_increment_rank;
214 int view1_rank_change = view1_iterator_.increment();
215 if (view1_rank_change >= 0)
217 switch (rank_combination_types_[view1_rank_change])
219 case DIMENSION_MATCH:
220 view2_iterator_.increment();
221 tensor_view_iterator_.increment();
225 tensor_view_iterator_.increment();
227 case TENSOR_CONTRACTION:
229 view2_iterator_.increment();
232 return view1_rank_change;
250 void setLocation(Kokkos::Array<int,7> location1, Kokkos::Array<int,7> location2)
252 view1_iterator_.setLocation(location1);
253 view2_iterator_.setLocation(location2);
254 Kokkos::Array<int,7> tensor_location = location1;
255 for (
unsigned d=0; d<rank_combination_types_.extent(0); d++)
257 switch (rank_combination_types_[d])
261 tensor_location[d] = location2[d] * view1_iterator_.getExtent(d) + location1[d];
263 case DIMENSION_MATCH:
266 case TENSOR_CONTRACTION:
267 tensor_location[d] = 0;
271#ifdef HAVE_INTREPID2_DEBUG
273 for (
unsigned d=0; d<rank_combination_types_.extent(0); d++)
275 switch (rank_combination_types_[d])
280 case DIMENSION_MATCH:
281 case TENSOR_CONTRACTION:
288 device_assert(tensor_location[d] < tensor_view_iterator_.getExtent(d));
291 tensor_view_iterator_.setLocation(tensor_location);