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--present, The Simons Foundation
2// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3// SPDX-License-Identifier: Apache-2.0
4// See LICENSE in the root of this distribution for details.
5
10
11#pragma once
12
13#include "../declarations.hpp"
14#include "../macros.hpp"
15#include "../traits.hpp"
16
17namespace nda::linalg {
18
28 template <typename V>
29 auto cross_product(V const &x, V const &y) {
30 EXPECTS_WITH_MESSAGE(x.shape()[0] == 3, "nda::linalg::cross_product: Only defined for 3-dimensional vectors");
31 EXPECTS_WITH_MESSAGE(y.shape()[0] == 3, "nda::linalg::cross_product: Only defined for 3-dimensional vectors");
32 array<get_value_t<V>, 1> r(3);
33 r(0) = x(1) * y(2) - y(1) * x(2);
34 r(1) = -x(0) * y(2) + y(0) * x(2);
35 r(2) = x(0) * y(1) - y(0) * x(1);
36 return r;
37 }
38
39} // namespace nda::linalg
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
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.