ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
array_vector.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "algebra/impl/array_operators.hpp"
13#include "detray/algebra/common/math.hpp"
14#include "detray/algebra/concepts.hpp"
15#include "detray/algebra/generic/generic.hpp"
16#include "detray/definitions/detail/qualifiers.hpp"
17
18namespace detray::algebra::array {
19
23template <concepts::index index_t, template <typename, index_t> class array_t,
24 concepts::scalar scalar_t, index_t N>
25 requires(N >= 2)
26DETRAY_HOST_DEVICE constexpr scalar_t phi(const array_t<scalar_t, N> &v) {
27 return algebra::generic::math::phi(v);
28}
29
33template <concepts::index index_t, template <typename, index_t> class array_t,
34 concepts::scalar scalar_t, index_t N>
35 requires(N >= 2)
36DETRAY_HOST_DEVICE constexpr scalar_t perp(const array_t<scalar_t, N> &v) {
37 return algebra::generic::math::perp(v);
38}
39
43template <concepts::index index_t, template <typename, index_t> class array_t,
44 concepts::scalar scalar_t, index_t N>
45 requires(N >= 2)
46DETRAY_HOST_DEVICE constexpr scalar_t theta(const array_t<scalar_t, N> &v) {
47 return algebra::generic::math::theta(v);
48}
49
62template <concepts::index index_t, template <typename, index_t> class array_t,
63 concepts::scalar scalar_t, index_t N>
64 requires(N >= 3)
65DETRAY_HOST_DEVICE constexpr array_t<scalar_t, N> cross(
66 const array_t<scalar_t, N> &a, const array_t<scalar_t, N> &b) {
67 return algebra::generic::math::cross(a, b);
68}
69
70template <concepts::index index_t, template <typename, index_t> class array_t,
71 concepts::scalar scalar_t, index_t N>
72 requires(N >= 3)
73DETRAY_HOST_DEVICE constexpr array_t<scalar_t, N> cross(
74 const array_t<scalar_t, N> &a, const array_t<array_t<scalar_t, N>, 1> &b) {
75 return algebra::generic::math::cross(a, b);
76}
77
78template <concepts::index index_t, template <typename, index_t> class array_t,
79 concepts::scalar scalar_t, index_t N>
80 requires(N >= 3)
81DETRAY_HOST_DEVICE constexpr array_t<scalar_t, N> cross(
82 const array_t<array_t<scalar_t, N>, 1> &a, const array_t<scalar_t, N> &b) {
83 return algebra::generic::math::cross(a, b);
84}
85
86template <concepts::index index_t, template <typename, index_t> class array_t,
87 concepts::scalar scalar_t, index_t N>
88 requires(N >= 3)
89DETRAY_HOST_DEVICE constexpr array_t<scalar_t, N> cross(
90 const array_t<array_t<scalar_t, N>, 1> &a,
91 const array_t<array_t<scalar_t, N>, 1> &b) {
92 return algebra::generic::math::cross(a, b);
93}
95
103template <concepts::index index_t, template <typename, index_t> class array_t,
104 concepts::scalar scalar_t, index_t N>
105DETRAY_HOST_DEVICE constexpr scalar_t dot(const array_t<scalar_t, N> &a,
106 const array_t<scalar_t, N> &b) {
107 array_t<scalar_t, N> tmp{};
108 for (index_t i = 0; i < N; i++) {
109 tmp[i] = a[i] * b[i];
110 }
111 scalar_t ret{0.f};
112 for (index_t i = 0; i < N; i++) {
113 ret += tmp[i];
114 }
115 return ret;
116}
117
118template <concepts::index index_t, template <typename, index_t> class array_t,
119 concepts::scalar scalar_t, index_t N>
120DETRAY_HOST_DEVICE constexpr scalar_t dot(
121 const array_t<scalar_t, N> &a, const array_t<array_t<scalar_t, N>, 1> &b) {
122 array_t<scalar_t, N> tmp{};
123 for (index_t i = 0; i < N; i++) {
124 tmp[i] = a[i] * b[0][i];
125 }
126 scalar_t ret{0.f};
127 for (index_t i = 0; i < N; i++) {
128 ret += tmp[i];
129 }
130 return ret;
131}
132
133template <concepts::index index_t, template <typename, index_t> class array_t,
134 concepts::scalar scalar_t, index_t N>
135DETRAY_HOST_DEVICE constexpr scalar_t dot(
136 const array_t<array_t<scalar_t, N>, 1> &a, const array_t<scalar_t, N> &b) {
137 array_t<scalar_t, N> tmp{};
138 for (index_t i = 0; i < N; i++) {
139 tmp[i] = a[0][i] * b[i];
140 }
141 scalar_t ret{0.f};
142 for (index_t i = 0; i < N; i++) {
143 ret += tmp[i];
144 }
145 return ret;
146}
147
148template <concepts::index index_t, template <typename, index_t> class array_t,
149 concepts::scalar scalar_t, index_t N>
150DETRAY_HOST_DEVICE constexpr scalar_t dot(
151 const array_t<array_t<scalar_t, N>, 1> &a,
152 const array_t<array_t<scalar_t, N>, 1> &b) {
153 array_t<scalar_t, N> tmp{};
154 for (index_t i = 0; i < N; i++) {
155 tmp[i] = a[0][i] * b[0][i];
156 }
157 scalar_t ret{0.f};
158 for (index_t i = 0; i < N; i++) {
159 ret += tmp[i];
160 }
161 return ret;
162}
164
168template <concepts::index index_t, template <typename, index_t> class array_t,
169 concepts::scalar scalar_t, index_t N>
170 requires(N >= 2)
171DETRAY_HOST_DEVICE constexpr scalar_t norm(const array_t<scalar_t, N> &v) {
172 return algebra::math::sqrt(dot(v, v));
173}
174
179template <concepts::index index_t, template <typename, index_t> class array_t,
180 concepts::scalar scalar_t, index_t N>
181 requires(N >= 3)
182DETRAY_HOST_DEVICE constexpr scalar_t eta(
183 const array_t<scalar_t, N> &v) noexcept {
184 return algebra::math::atanh(v[2] / norm(v));
185}
186
190template <concepts::index index_t, template <typename, index_t> class array_t,
191 concepts::scalar scalar_t, index_t N>
192DETRAY_HOST_DEVICE constexpr array_t<scalar_t, N> normalize(
193 const array_t<scalar_t, N> &v) {
194 return (static_cast<scalar_t>(1.) / norm(v)) * v;
195}
196
197} // namespace detray::algebra::array
constexpr decltype(auto) sqrt(T &&vec)
Definition vc_soa_math.hpp:78