-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataArray.cpp
More file actions
147 lines (123 loc) · 3.44 KB
/
DataArray.cpp
File metadata and controls
147 lines (123 loc) · 3.44 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
143
144
145
146
147
/*
* Copyright (c) 2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
# include "DataArray.h"
# include <cassert>
using namespace std;
DataArray::~DataArray()
{
}
bool DataArray::reconfig(const std::vector<long>&, DataArray::type_t)
{
return false;
}
std::vector<long> DataArray::get_axes(void) const
{
return std::vector<long> ();
}
int DataArray::get_line_raw(const std::vector<long>&, long, type_t, void*, int&, uint8_t*)
{
return -1;
}
int DataArray::set_line_raw(const std::vector<long>&, long, type_t, const void*, const uint8_t*)
{
return -1;
}
DataArray::type_t DataArray::type_from_string(const std::string&str)
{
const static struct {
const char*name;
DataArray::type_t code;
} type[] = {
{ "int8", DT_INT8 },
{ "int16", DT_INT16 },
{ "int32", DT_INT32 },
{ "int64", DT_INT64 },
{ "uint8", DT_UINT8 },
{ "uint16", DT_UINT16 },
{ "uint32", DT_UINT32 },
{ "uint64", DT_UINT64 },
{ "float32",DT_FLOAT32 },
{ "float64",DT_FLOAT64 },
{ "double", DT_DOUBLE },
{ "complex",DT_COMPLEX },
{ 0, DT_VOID }
};
for (int idx = 0 ; type[idx].name != 0 ; idx += 1) {
if (str == type[idx].name)
return type[idx].code;
}
return DT_VOID;
}
size_t DataArray::get_pixel_count(const std::vector<long>&axes)
{
if (axes.size() == 0) return 0;
size_t count = 1;
for (size_t idx = 0 ; idx < axes.size() ; idx += 1)
count *= axes[idx];
return count;
}
std::vector<long> DataArray::zero_addr(size_t axes)
{
vector<long> addr (axes);
for (size_t idx = 0 ; idx < addr.size() ; idx += 1)
addr[idx] = 0;
return addr;
}
bool DataArray::incr(std::vector<long>&addr, const std::vector<long>&ref, size_t axis)
{
size_t cur = axis;
while (cur < addr.size()) {
addr[cur] += 1;
if (addr[cur] < ref[cur])
return true;
addr[cur] = 0;
cur += 1;
}
return false;
}
std::vector<long> DataArray::add(const std::vector<long>&a, const std::vector<long>&b)
{
vector<long>out = a;
assert(out.size() >= b.size());
for (size_t idx = 0 ; idx < b.size() ; idx += 1)
out[idx] += b[idx];
return out;
}
pixel_iterator::pixel_iterator(const std::vector<long>&ul, const std::vector<long>&lr)
: ul_(ul), lr_(lr)
{
assert(ul_.size() == lr_.size());
addr_ = ul_;
}
pixel_iterator::~pixel_iterator()
{
}
bool pixel_iterator::incr(size_t axis, long step)
{
size_t cur = axis;
while (cur < addr_.size()) {
addr_[cur] += step;
if (addr_[cur] < lr_[cur])
return true;
addr_[cur] = ul_[cur];
cur += 1;
}
addr_.clear();
return false;
}