Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:55

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 // Project include(s)
0012 #include "detray/algebra/concepts.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 
0015 // System include(s)
0016 #include <concepts>
0017 
0018 namespace detray::algebra {
0019 
0020 /// Cast a salar (might be simd) @param s to the precision given by
0021 /// @tparam value_t
0022 template <concepts::value value_t, concepts::scalar scalar_t>
0023   requires std::convertible_to<scalar_t, value_t>
0024 DETRAY_HOST_DEVICE constexpr auto cast_to(const scalar_t& s) {
0025   return static_cast<value_t>(s);
0026 }
0027 
0028 /// Cast a generic vector or point @param v to the precision given by
0029 /// @tparam value_t
0030 template <concepts::value value_t, typename vector_t>
0031   requires(concepts::vector<vector_t> || concepts::point<vector_t>)
0032 DETRAY_HOST_DEVICE constexpr auto cast_to(const vector_t& v) {
0033   using index_t = detray::traits::index_t<vector_t>;
0034 
0035   constexpr index_t size{detray::traits::size<vector_t>};
0036 
0037   using new_vector_t = detray::traits::get_vector_t<vector_t, size, value_t>;
0038   new_vector_t ret;
0039 
0040   static_assert(std::same_as<value_t, detray::traits::value_t<new_vector_t>>);
0041 
0042   for (index_t i = 0; i < size; ++i) {
0043     ret[i] = ::detray::algebra::cast_to<value_t>(v[i]);
0044   }
0045 
0046   return ret;
0047 }
0048 
0049 /// Cast a column matrix @param v to the precision given by @tparam value_t
0050 template <concepts::value value_t, concepts::column_matrix vector_t>
0051 DETRAY_HOST_DEVICE constexpr auto cast_to(const vector_t& v) {
0052   using index_t = detray::traits::index_t<vector_t>;
0053   using element_getter_t = detray::traits::element_getter_t<vector_t>;
0054 
0055   constexpr index_t rows{detray::traits::rows<vector_t>};
0056 
0057   using new_vector_t = detray::traits::get_matrix_t<vector_t, rows, 1, value_t>;
0058   new_vector_t ret;
0059 
0060   static_assert(std::same_as<value_t, detray::traits::value_t<new_vector_t>>);
0061 
0062   for (index_t i = 0; i < rows; ++i) {
0063     element_getter_t{}(ret, i, 0) =
0064         ::detray::algebra::cast_to<value_t>(element_getter_t{}(v, i, 0));
0065   }
0066 
0067   return ret;
0068 }
0069 
0070 /// Cast a generic matrix @param v to the precision given by @tparam value_t
0071 template <concepts::value value_t, concepts::matrix matrix_t>
0072 DETRAY_HOST_DEVICE constexpr auto cast_to(const matrix_t& m) {
0073   using index_t = detray::traits::index_t<matrix_t>;
0074   using element_getter_t = detray::traits::element_getter_t<matrix_t>;
0075 
0076   constexpr index_t rows{detray::traits::rows<matrix_t>};
0077   constexpr index_t columns{detray::traits::columns<matrix_t>};
0078 
0079   using new_matrix_t =
0080       detray::traits::get_matrix_t<matrix_t, rows, columns, value_t>;
0081   new_matrix_t ret;
0082 
0083   static_assert(std::same_as<value_t, detray::traits::value_t<new_matrix_t>>);
0084 
0085   for (index_t j = 0; j < columns; ++j) {
0086     for (index_t i = 0; i < rows; ++i) {
0087       element_getter_t{}(ret, i, j) =
0088           ::detray::algebra::cast_to<value_t>(element_getter_t{}(m, i, j));
0089     }
0090   }
0091 
0092   return ret;
0093 }
0094 
0095 /// Cast a 3D transform @param trf to the precision given by @tparam scalar_t
0096 template <concepts::scalar scalar_t, concepts::transform3D transform_t>
0097   requires(!concepts::simd_scalar<scalar_t> &&
0098            !concepts::simd_scalar<typename transform_t::scalar_type>)
0099 DETRAY_HOST_DEVICE constexpr auto cast_to(const transform_t& trf) {
0100   using new_trf3_t = typename transform_t::template other_type<scalar_t>;
0101 
0102   return new_trf3_t{::detray::algebra::cast_to<scalar_t>(trf.matrix()),
0103                     ::detray::algebra::cast_to<scalar_t>(trf.matrix_inverse())};
0104 }
0105 
0106 }  // namespace detray::algebra