20 #ifndef GAIA_DESCRIPTOR_H 21 #define GAIA_DESCRIPTOR_H 23 #include <QTextStream> 46 for (
int i=0; i<size; i++) (*
this)[i] = arr[i];
49 for (uint i=0; i<v.size(); i++) (*
this)[i] = v[i];
56 throw GaiaException(
"Cannot call SingleValueMorphable::SVM(int) because it is ambiguous.");
67 this->front() = value;
71 const T& toSingleValue()
const {
72 if (this->size() != 1) {
73 throw GaiaException(
"Could not convert descriptor to single value (size=", this->size(),
")");
88 if (this->size() != rhs.size()) {
89 throw GaiaException(
"left-operand and right-operand do not have same size");
94 #define transferAssignmentOperator(OP) \ 95 SingleValueMorphable& operator OP(const SingleValueMorphable& rhs) { \ 97 for (int i=0; i<this->size(); i++) { \ 98 this->operator[](i) OP rhs.at(i); \ 103 transferAssignmentOperator(+=);
104 transferAssignmentOperator(-=);
105 transferAssignmentOperator(*=);
106 transferAssignmentOperator(/=);
108 #undef transferAssignmentOperator 110 #define transferBinaryOperator(OP) \ 111 SingleValueMorphable operator OP(const SingleValueMorphable& rhs) const { \ 112 SingleValueMorphable result(*this); \ 113 return result.operator OP##=(rhs); \ 116 transferBinaryOperator(+);
117 transferBinaryOperator(-);
118 transferBinaryOperator(*);
119 transferBinaryOperator(/);
121 #undef transferBinaryOperator 123 #define transferUnaryOperator(OP) \ 124 SingleValueMorphable operator OP() const { \ 125 SingleValueMorphable result(*this); \ 126 for (int i=0; i<this->size(); i++) { \ 127 result.operator[](i) = OP result.at(i); \ 132 transferUnaryOperator(-);
134 #undef transferUnaryOperator 136 #define transferAssignmentOperatorFromSingleValue(OP) \ 137 SingleValueMorphable& operator OP(const T& x) { \ 138 for (int i=0; i<this->size(); i++) { \ 139 this->operator[](i) OP x; \ 144 transferAssignmentOperatorFromSingleValue(+=);
145 transferAssignmentOperatorFromSingleValue(-=);
146 transferAssignmentOperatorFromSingleValue(*=);
147 transferAssignmentOperatorFromSingleValue(/=);
149 #undef transferAssignmentOperatorFromSingleValue 151 #define transferBinaryOperatorFromSingleValue(OP) \ 152 SingleValueMorphable operator OP(const T& x) const { \ 153 SingleValueMorphable result(*this); \ 154 return result.operator OP##=(x); \ 157 transferBinaryOperatorFromSingleValue(+);
158 transferBinaryOperatorFromSingleValue(-);
159 transferBinaryOperatorFromSingleValue(*);
160 transferBinaryOperatorFromSingleValue(/);
162 #undef transferBinaryOperatorFromSingleValue 165 #define transferComparison(OP) \ 166 bool operator OP(const T& x) const { \ 167 for (int i=0; i<this->size(); i++) { \ 168 if (!(this->at(i) OP x)) return false; \ 173 transferComparison(<);
174 transferComparison(<=);
175 transferComparison(>);
176 transferComparison(>=);
178 #undef transferComparison 180 bool operator==(
const Array<T>& x)
const {
184 bool operator==(
const T& x)
const {
185 return toSingleValue() == x;
190 for (
int i=0; i<this->size(); i++) {
191 this->operator[](i) = std::min(this->at(i), rhs.at(i));
198 for (
int i=0; i<this->size(); i++) {
199 this->operator[](i) = std::max(this->at(i), rhs.at(i));
205 for (
int i=0; i<this->size(); i++) {
206 this->operator[](i) = std::min(this->at(i), minv);
212 for (
int i=0; i<this->size(); i++) {
213 this->operator[](i) = std::max(this->at(i), maxv);
220 for (
int i=0; i<this->size(); i++) {
221 if (gaia2::isnan(this->at(i)))
return true;
227 for (
int i=0; i<this->size(); i++) {
228 if (gaia2::isinf(this->at(i)))
return true;
234 for (
int i=0; i<this->size(); i++) {
235 this->operator[](i) = (T)1.0 / this->at(i);
241 for (
int i=0; i<this->size(); i++) {
242 this->operator[](i) = -this->at(i);
248 for (
int i=0; i<this->size(); i++) {
249 this->operator[](i) = std::sqrt(this->at(i));
255 for (
int i=0; i<this->size(); i++) {
256 this->operator[](i) = std::abs(this->at(i));
264 for (
int i=0; i<this->size(); i++) {
265 result += (*this)[i] * (*this)[i];
267 return std::sqrt(result);
270 QString toString()
const {
272 QTextStream s(&result);
274 if (this->size() == 1) s << this->at(0);
275 else if (this->size() == 0) s <<
"[]";
277 s <<
"[ " << this->at(0);
278 for (
int i=1; i<this->size(); i++) {
279 s <<
", " << this->at(i);
289 template <
typename T>
291 return (y - x).opposite();
294 template <
typename T>
296 return (y / x).inverse();
299 template <
typename T>
304 template <
typename T>
309 template <
typename T>
310 Stringifier& operator<<(Stringifier& out, const SingleValueMorphable<T>& array) {
311 return out << array.toString();
320 inline RealDescriptor sqrt(
const RealDescriptor& x) {
321 return RealDescriptor(x).sqrt();
327 #endif // GAIA_DESCRIPTOR_H Definition: descriptor.h:39
Definition: debugging.h:82
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
Exception class that can take up to 3 arguments of any type, which will be serialized into a QString ...
Definition: gaiaexception.h:46