Debian Codegraph @

src/acl/aclMath/aclVectorOfElementsDef.cxx

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include <algorithm>
24 #include "aclVectorOfElementsDef.h"
25 #include "aclVectorOfElementsOperations.h"
26 #include "aclUtilities.h"
27 #include "acl.h"
28 #include "DataTypes/aclConstant.h"
29 #include "../aslUtilities.h"
30 #include "Kernels/aclKernel.h"
31 #include "acl/DataTypes/aclArray.h"
32 #include "../aclHardware.h"
33 #include "aclTypesList.h"
34
35 using asl::errorMessage;
36
37 using namespace std;
38
39 namespace acl
40 {
41 VectorOfElementsData::VectorOfElementsData():
42 std::vector<ElementData>()
43 {
44 }
45
46
47 VectorOfElementsData::VectorOfElementsData(unsigned int n):
48 std::vector<ElementData>(n)
49 {
50 }
51
52 template <typename T> VectorOfElementsData::VectorOfElementsData(unsigned int n,
53 unsigned int s,
54 T,
55 CommandQueue queue):
56 std::vector<ElementData>(n)
57 {
58 for (unsigned int i(0); i < n; ++i)
59 (*this)[i] = ElementData(new Array<T>(s, queue));
60 }
61
62 #define BOOST_TT_rep_expression(r, data, t) \
63 template VectorOfElementsData::VectorOfElementsData(unsigned int n, unsigned int s, t, CommandQueue queue);
64 BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types)
65 #undef BOOST_TT_rep_expression
66
67 template <typename T> VectorOfElementsData::VectorOfElementsData(unsigned int n,
68 unsigned int s,
69 T):
70 VectorOfElementsData(n,s,T(0),hardware.defaultQueue)
71 {
72 }
73 #define BOOST_TT_rep_expression(r, data, t) \
74 template VectorOfElementsData::VectorOfElementsData(unsigned int n, unsigned int s, t);
75 BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types)
76 #undef BOOST_TT_rep_expression
77
78
79 void VectorOfElementsData::resizeElements(unsigned int n)
80 {
81 if ((*this)[0].get() == 0)
82 return ;
83 else
84 if ((*this)[0]->getSize() == n)
85 return ;
86
87 auto q((*this)[0]->getQueue());
88
89 for (unsigned int i(0); i < size(); ++i)
90 {
91 TypeID t((*this)[i]->getTypeID());
92 (*this)[i] = generateElementArray(t, n, q);
93 }
94 }
95
96
97 VectorOfElements VectorOfElementsData::operator=(const VectorOfElements &a) const
98 {
99 return assignmentSafe(*this, a);
100 }
101
102 VectorOfElements VectorOfElementsData::operator=(const VectorOfElementsData &a) const
103 {
104 return assignmentSafe(*this, a);
105 }
106
107
108
109 VectorOfElements::VectorOfElements():
110 std::vector<Element>()
111 {
112 }
113
114
115 VectorOfElements::VectorOfElements(unsigned int n):
116 std::vector<Element>(n, Element(new Constant<cl_int>(0)))
117 {
118 }
119
120
121 VectorOfElements::VectorOfElements(const VectorOfElementsData & a):
122 std::vector<Element>(a.size())
123 {
124 for (unsigned int i(0); i < a.size(); ++i)
125 (*this)[i] = a[i];
126 }
127
128
129 VectorOfElements VectorOfElements::operator=(const VectorOfElements &a) const
130 {
131 if (size() != a.size())
132 errorMessage("operator= - the sizes of two VectorOfElements are incompatible: "
133 + numToStr(size()) + " and " + numToStr(a.size()));
134
135 VectorOfElements ve(a.size());
136 for (unsigned int i(0); i < size(); ++i)
137 ve[i] = elementOperators::operatorAssignment((*this)[i], a[i]);
138 return ve;
139 }
140
141 /// \todo change name to: compatible()?
142 bool VectorOfElements::checkCompatibility() const
143 {
144 unsigned int s((*this)[0]->getSize());
145 CommandQueue queue((*this)[0]->getQueue());
146 bool isCompatible(true);
147 for (unsigned int i = 1; i < size(); ++i)
148 {
149 isCompatible &= compatible(s, queue, (*this)[i]);
150 s = std::max(s, (*this)[i]->getSize());
151 CommandQueue q((*this)[0]->getQueue());
152 queue = (q.get() != 0 ? q : queue);
153 }
154 return isCompatible;
155 }
156
157
158 /// \todo change name to: compatibleSizes()?
159 bool VectorOfElements::checkSizesCompatibility(unsigned int n) const
160 {
161 bool isCompatible(true);
162 for (unsigned int i = 0; i < size(); ++i)
163 {
164 isCompatible &= compatibleSizes(n, (*this)[i]);
165 }
166 return isCompatible;
167 }
168
169 unsigned int getElementsSize(const VectorOfElements & a)
170 {
171 if (a.size() > 0 && a[0].get() != 0)
172 return a[0]->getSize();
173 else
174 return 0;
175 }
176
177 acl::TypeID getElementType(const VectorOfElements & a, unsigned int i)
178 {
179 return a.at(i)->getTypeID();
180 }
181 } // namespace acl