forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxinfo.hpp
More file actions
142 lines (131 loc) · 3.82 KB
/
Copy pathxinfo.hpp
File metadata and controls
142 lines (131 loc) · 3.82 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* Copyright (c) QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XTENSOR_INFO_HPP
#define XTENSOR_INFO_HPP
#include <string>
#include "xlayout.hpp"
#ifndef _MSC_VER
#if __cplusplus < 201103
#define CONSTEXPR11_TN
#define CONSTEXPR14_TN
#define NOEXCEPT_TN
#elif __cplusplus < 201402
#define CONSTEXPR11_TN constexpr
#define CONSTEXPR14_TN
#define NOEXCEPT_TN noexcept
#else
#define CONSTEXPR11_TN constexpr
#define CONSTEXPR14_TN constexpr
#define NOEXCEPT_TN noexcept
#endif
#else // _MSC_VER
#if _MSC_VER < 1900
#define CONSTEXPR11_TN
#define CONSTEXPR14_TN
#define NOEXCEPT_TN
#elif _MSC_VER < 2000
#define CONSTEXPR11_TN constexpr
#define CONSTEXPR14_TN
#define NOEXCEPT_TN noexcept
#else
#define CONSTEXPR11_TN constexpr
#define CONSTEXPR14_TN constexpr
#define NOEXCEPT_TN noexcept
#endif
#endif
namespace xt
{
// see http://stackoverflow.com/a/20170989
struct static_string
{
template <std::size_t N>
explicit CONSTEXPR11_TN static_string(const char (&a)[N]) NOEXCEPT_TN : data(a),
size(N - 1)
{
}
CONSTEXPR11_TN static_string(const char* a, const std::size_t sz) NOEXCEPT_TN : data(a),
size(sz)
{
}
const char* const data;
const std::size_t size;
};
template <class T>
CONSTEXPR14_TN static_string type_name()
{
#ifdef __clang__
static_string p(__PRETTY_FUNCTION__);
return static_string(p.data + 39, p.size - 39 - 1);
#elif defined(__GNUC__)
static_string p(__PRETTY_FUNCTION__);
#if __cplusplus < 201402
return static_string(p.data + 36, p.size - 36 - 1);
#else
return static_string(p.data + 54, p.size - 54 - 1);
#endif
#elif defined(_MSC_VER)
static const static_string p(__FUNCSIG__);
return static_string(p.data + 47, p.size - 47 - 7);
#endif
}
template <class T>
std::string type_to_string()
{
static_string static_name = type_name<T>();
return std::string(static_name.data, static_name.size);
}
template <class T>
std::string info(const T& t)
{
std::string s;
s += "\nValue type: " + type_to_string<typename T::value_type>();
s += "\nLayout: ";
if (t.layout() == layout_type::row_major)
{
s += "row_major";
}
else if (t.layout() == layout_type::column_major)
{
s += "column_major";
}
else if (t.layout() == layout_type::dynamic)
{
s += "dynamic";
}
else
{
s += "any";
}
s += "\nShape: (";
bool first = true;
for (const auto& el : t.shape())
{
if (!first)
{
s += ", ";
}
first = false;
s += std::to_string(el);
}
s += ")\nStrides: (";
first = true;
for (const auto& el : t.strides())
{
if (!first)
{
s += ", ";
}
first = false;
s += std::to_string(el);
}
s += ")\nSize: " + std::to_string(t.size()) + "\n";
return s;
}
}
#endif