File: util.h

package info (click to toggle)
libthrust 1.17.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,900 kB
  • sloc: ansic: 29,519; cpp: 23,989; python: 1,421; sh: 811; perl: 460; makefile: 112
file content (67 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download | duplicates (5)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include <iostream>
#include <string>
#include <typeinfo>
#include <unittest/system.h>

#include <thrust/extrema.h>
#include <thrust/limits.h>
#include <thrust/detail/type_traits.h>

namespace unittest
{

template<typename T>
  std::string type_name(void)
{
  return demangle(typeid(T).name());
} // end type_name()

// Use this with counting_iterator to avoid generating a range larger than we
// can represent.
template <typename T>
typename THRUST_NS_QUALIFIER::detail::disable_if<
  THRUST_NS_QUALIFIER::detail::is_floating_point<T>::value
, T
>::type truncate_to_max_representable(std::size_t n)
{
  return static_cast<T>(THRUST_NS_QUALIFIER::min<std::size_t>(
    n,
    static_cast<std::size_t>(THRUST_NS_QUALIFIER::numeric_limits<T>::max())));
}

// TODO: This probably won't work for `half`.
template <typename T>
typename THRUST_NS_QUALIFIER::detail::enable_if<
  THRUST_NS_QUALIFIER::detail::is_floating_point<T>::value
, T
>::type truncate_to_max_representable(std::size_t n)
{
  return THRUST_NS_QUALIFIER::min<T>(
    static_cast<T>(n),
    THRUST_NS_QUALIFIER::numeric_limits<T>::max());
}

} // end unittest

template <typename Iterator>
void PRINT(Iterator first, Iterator last)
{
  size_t n = 0;
  for (Iterator i = first; i != last; i++, n++)
    std::cout << ">>> [" << n << "] = " << *i << std::endl;
}

template <typename Container>
void PRINT(const Container& c)
{
  PRINT(c.begin(), c.end());
}

template <size_t N>
void PRINT(const char (&c)[N])
{
  std::cout << std::string(c, c + N) << std::endl;
}