xtensor
Toggle main menu visibility
Loading...
Searching...
No Matches
xinfo.hpp
1
/***************************************************************************
2
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
3
* Copyright (c) QuantStack *
4
* *
5
* Distributed under the terms of the BSD 3-Clause License. *
6
* *
7
* The full license is in the file LICENSE, distributed with this software. *
8
****************************************************************************/
9
10
#ifndef XTENSOR_INFO_HPP
11
#define XTENSOR_INFO_HPP
12
13
#include <string>
14
15
#include "../core/xlayout.hpp"
16
17
namespace
xt
18
{
19
// see http://stackoverflow.com/a/20170989
20
struct
static_string
21
{
22
template
<std::
size_t
N>
23
explicit
constexpr
static_string(
const
char
(&a)[N]) noexcept
24
: data(a)
25
, size(N - 1)
26
{
27
}
28
29
constexpr
static_string(
const
char
* a,
const
std::size_t sz) noexcept
30
: data(a)
31
, size(sz)
32
{
33
}
34
35
const
char
*
const
data;
36
const
std::size_t size;
37
};
38
39
template
<
class
T>
40
constexpr
static_string
type_name()
41
{
42
#ifdef __clang__
43
static_string
p(__PRETTY_FUNCTION__);
44
return
static_string
(p.data + 39, p.size - 39 - 1);
45
#elif defined(__GNUC__)
46
static_string
p(__PRETTY_FUNCTION__);
47
return
static_string
(p.data + 54, p.size - 54 - 1);
48
#elif defined(_MSC_VER)
49
static
const
static_string
p(__FUNCSIG__);
50
return
static_string
(p.data + 47, p.size - 47 - 7);
51
#endif
52
}
53
54
template
<
class
T>
55
std::string type_to_string()
56
{
57
static_string static_name = type_name<T>();
58
return
std::string(static_name.data, static_name.size);
59
}
60
61
template
<
class
T>
62
std::string info(
const
T& t)
63
{
64
std::string s;
65
s +=
"\nValue type: "
+ type_to_string<typename T::value_type>();
66
s +=
"\nLayout: "
;
67
if
(t.layout() ==
layout_type::row_major
)
68
{
69
s +=
"row_major"
;
70
}
71
else
if
(t.layout() ==
layout_type::column_major
)
72
{
73
s +=
"column_major"
;
74
}
75
else
if
(t.layout() ==
layout_type::dynamic
)
76
{
77
s +=
"dynamic"
;
78
}
79
else
80
{
81
s +=
"any"
;
82
}
83
s +=
"\nShape: ("
;
84
bool
first =
true
;
85
for
(
const
auto
& el : t.shape())
86
{
87
if
(!first)
88
{
89
s +=
", "
;
90
}
91
first =
false
;
92
s += std::to_string(el);
93
}
94
s +=
")\nStrides: ("
;
95
first =
true
;
96
for
(
const
auto
& el : t.strides())
97
{
98
if
(!first)
99
{
100
s +=
", "
;
101
}
102
first =
false
;
103
s += std::to_string(el);
104
}
105
s +=
")\nSize: "
+ std::to_string(t.size()) +
"\n"
;
106
return
s;
107
}
108
}
109
110
#endif
xt
standard mathematical functions for xexpressions
Definition
xchunked_array.hpp:20
xt::layout_type::row_major
@ row_major
Definition
xlayout.hpp:30
xt::layout_type::column_major
@ column_major
Definition
xlayout.hpp:32
xt::layout_type::dynamic
@ dynamic
Definition
xlayout.hpp:26
xt::static_string
Definition
xinfo.hpp:21
include
xtensor
io
xinfo.hpp
Generated by
1.17.0