/
scalar_array.hpp
155 lines (107 loc) · 3.32 KB
/
scalar_array.hpp
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
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef VPYTHON_PYTHON_SCALAR_ARRAY_HPP
#define VPYTHON_PYTHON_SCALAR_ARRAY_HPP
// This alternative to numpy is not currently being used
// but is retained in CVS for possible future use.
// In particular, information about array objects such
// as curve cannot currently be cached because we don't
// know when a numpy pos array has been changed.
// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.
#include "util/vector.hpp"
#include <deque>
#include <boost/python/numeric.hpp>
namespace cvisual { namespace python {
class vector_array;
class scalar_array
{
private:
std::deque<double> data;
friend class vector_array;
public:
typedef std::deque<double>::iterator iterator;
typedef std::deque<double>::const_iterator const_iterator;
inline scalar_array( int size = 0, double fill = 0)
: data( size, fill) {}
// Construct from a continuous 1-D sequence (tuple or list)
explicit scalar_array( const boost::python::list& sequence);
explicit scalar_array( const boost::python::numeric::array& sequence);
inline scalar_array( const scalar_array& other)
: data( other.data) {}
boost::python::handle<PyObject>
as_array() const;
inline iterator
begin() { return data.begin(); }
inline const_iterator
begin() const { return data.begin(); }
inline iterator
end() { return data.end(); }
inline const_iterator
end() const { return data.end(); }
// Append a single element to the array.
void append( double s);
// Prepend a single element the the array.
void prepend( double s);
// Remove a single element from the beginning of the array
void head_clip();
// Remove i elemnts from the beginning of the array.
void head_crop( int i);
// Remove a single element from the end of the array.
void tail_clip();
// Remove i elements from the end of the array.
void tail_crop( int i);
scalar_array
operator*( double s) const;
scalar_array
operator*( const scalar_array& s) const;
vector_array
operator*( const vector_array& v) const;
vector_array
operator*( const vector& v) const;
const scalar_array&
operator*=( double s);
const scalar_array&
operator*=( const scalar_array& s);
scalar_array
operator/( double s) const;
scalar_array
operator/( const scalar_array& s) const;
const scalar_array&
operator/=( double s);
const scalar_array&
operator/=( const scalar_array& s);
scalar_array
operator+( const scalar_array& s) const;
scalar_array
operator+( double s) const;
const scalar_array&
operator+=( double s);
const scalar_array&
operator+=( const scalar_array& s);
scalar_array
operator-( const scalar_array& s) const;
scalar_array
operator-( double s) const;
const scalar_array&
operator-=( double s);
const scalar_array&
operator-=( const scalar_array& s);
scalar_array
operator-() const;
inline double&
operator[]( int i) { return data[i]; }
inline const double&
operator[]( int i) const { return data[i]; }
// Returns the number of elemnts in the array.
inline int
size() const { return data.size(); }
double
py_getitem( int index);
void
py_setitem( int index, double value);
double
sum() const;
};
void wrap_scalar_array();
} } // !namepace cvisual::python
#endif // !VPYTHON_PYTHON_SCALAR_ARRAY_HPP