File: numpy_dtype.h

package info (click to toggle)
fenics-dolfinx 1%3A0.9.0-11
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,376 kB
  • sloc: cpp: 33,701; python: 22,338; makefile: 230; sh: 171; xml: 55
file content (44 lines) | stat: -rw-r--r-- 1,172 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

// Copyright (C) 2024 Chris Richardson and Garth N. Wells
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier:    LGPL-3.0-or-later

#include <complex>
#include <cstdint>
#include <type_traits>

#pragma once

namespace dolfinx_wrappers
{

/// @brief Return NumPy dtype char type for a C++ type
/// @tparam T C++ type
/// @return NumPy dtype
template <typename T>
constexpr char numpy_dtype()
{
  if constexpr (std::is_same_v<T, float>)
    return 'f';
  else if constexpr (std::is_same_v<T, double>)
    return 'd';
  else if constexpr (std::is_same_v<T, std::complex<float>>)
    return 'F';
  else if constexpr (std::is_same_v<T, std::complex<double>>)
    return 'D';
  else if constexpr (std::is_same_v<T, std::int8_t>)
    return 'b';
  else if constexpr (std::is_same_v<T, std::uint8_t>)
    return 'B';
  else if constexpr (std::is_same_v<T, std::int32_t>)
    return 'i';
  else if constexpr (std::is_same_v<T, std::uint32_t>)
    return 'I';
  else if constexpr (std::is_same_v<T, std::int64_t>)
    return 'l';
  else if constexpr (std::is_same_v<T, std::uint64_t>)
    return 'L';
}
} // namespace dolfinx_wrappers