blob: 8056366a1c97da9169d667fc2d46f30670393478 (
plain) (
blame)
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
|
/* -*- mode: c++; c-basic-offset: 4 -*- */
/* Utilities to create scalars and empty arrays that behave like the
Numpy array wrappers in numpy_cpp.h */
#ifndef _SCALAR_H_
#define _SCALAR_H_
namespace array
{
template <typename T, int ND>
class scalar
{
public:
T m_value;
scalar(const T value) : m_value(value)
{
}
T &operator()(int i, int j = 0, int k = 0)
{
return m_value;
}
const T &operator()(int i, int j = 0, int k = 0) const
{
return m_value;
}
int dim(size_t i)
{
return 1;
}
size_t size()
{
return 1;
}
};
template <typename T>
class empty
{
public:
typedef empty<T> sub_t;
empty()
{
}
T &operator()(int i, int j = 0, int k = 0)
{
throw std::runtime_error("Accessed empty array");
}
const T &operator()(int i, int j = 0, int k = 0) const
{
throw std::runtime_error("Accessed empty array");
}
sub_t operator[](int i) const
{
return empty<T>();
}
int dim(size_t i) const
{
return 0;
}
size_t size() const
{
return 0;
}
};
}
#endif
|