Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-22 07:46:52

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <array>
0012 #include <cstddef>
0013 #include <span>
0014 
0015 #include <Eigen/Core>
0016 
0017 namespace Acts::detail {
0018 
0019 template <typename T, std::size_t N>
0020 std::array<T, N> stdArrayCopy(const std::span<const T, N> arr) {
0021   std::array<T, N> result{};
0022   for (std::size_t i = 0; i < N; ++i) {
0023     result[i] = arr[i];
0024   }
0025   return result;
0026 }
0027 
0028 template <typename T, int N>
0029 std::array<T, N> stdArrayCopy(const Eigen::Vector<T, N>& arr)
0030   requires(N > 0)
0031 {
0032   std::array<T, N> result{};
0033   for (std::size_t i = 0; i < N; ++i) {
0034     result[i] = arr[i];
0035   }
0036   return result;
0037 }
0038 
0039 template <typename T, std::size_t N>
0040 Eigen::Vector<T, N> stdArrayToEigen(const std::array<T, N>& arr) {
0041   Eigen::Vector<T, N> result;
0042   for (std::size_t i = 0; i < N; ++i) {
0043     result[i] = arr[i];
0044   }
0045   return result;
0046 }
0047 
0048 template <typename T, std::size_t N>
0049 std::array<T, N> stdArrayAddScaled(const std::array<T, N>& a,
0050                                    const std::array<T, N>& b, const T scale) {
0051   std::array<T, N> result{};
0052   for (std::size_t i = 0; i < N; ++i) {
0053     result[i] = a[i] + b[i] * scale;
0054   }
0055   return result;
0056 }
0057 
0058 template <typename T, std::size_t N>
0059 T stdArrayDot(const std::array<T, N>& a, const std::array<T, N>& b) {
0060   T result = 0;
0061   for (std::size_t i = 0; i < N; ++i) {
0062     result += a[i] * b[i];
0063   }
0064   return result;
0065 }
0066 
0067 template <typename T>
0068 std::array<T, 3> stdArrayCross(const std::array<T, 3>& a,
0069                                const std::array<T, 3>& b) {
0070   std::array<T, 3> result{};
0071   result[0] = a[1] * b[2] - a[2] * b[1];
0072   result[1] = a[2] * b[0] - a[0] * b[2];
0073   result[2] = a[0] * b[1] - a[1] * b[0];
0074   return result;
0075 }
0076 
0077 }  // namespace Acts::detail