TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
cross_product.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2024 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "../declarations.hpp"
25#include "../macros.hpp"
26#include "../traits.hpp"
27
28namespace nda::linalg {
29
39 template <typename V>
40 auto cross_product(V const &x, V const &y) {
41 EXPECTS_WITH_MESSAGE(x.shape()[0] == 3, "nda::linalg::cross_product: Only defined for 3-dimensional vectors");
42 EXPECTS_WITH_MESSAGE(y.shape()[0] == 3, "nda::linalg::cross_product: Only defined for 3-dimensional vectors");
43 array<get_value_t<V>, 1> r(3);
44 r(0) = x(1) * y(2) - y(1) * x(2);
45 r(1) = -x(0) * y(2) + y(0) * x(2);
46 r(2) = x(0) * y(1) - y(0) * x(1);
47 return r;
48 }
49
50} // namespace nda::linalg
A generic multi-dimensional array.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
auto cross_product(V const &x, V const &y)
Compute the cross product of two 3-dimensional vectors.
Macros used in the nda library.
Provides type traits for the nda library.