37 #ifndef VIGRA_MATRIX_HXX
38 #define VIGRA_MATRIX_HXX
43 #include "multi_array.hxx"
44 #include "mathutil.hxx"
45 #include "numerictraits.hxx"
46 #include "multi_pointoperators.hxx"
67 template <
class T,
class C>
69 rowCount(
const MultiArrayView<2, T, C> &x);
71 template <
class T,
class C>
75 template <
class T,
class C>
76 inline MultiArrayView <2, T, C>
79 template <
class T,
class C>
80 inline MultiArrayView <2, T, C>
83 template <
class T,
class ALLOC = std::allocator<T> >
84 class TemporaryMatrix;
86 template <
class T,
class C1,
class C2>
87 void transpose(
const MultiArrayView<2, T, C1> &v, MultiArrayView<2, T, C2> &r);
89 template <
class T,
class C>
92 enum RawArrayMemoryLayout { RowMajor, ColumnMajor };
122 template <
class T,
class ALLOC = std::allocator<T> >
130 typedef TemporaryMatrix<T, ALLOC> temp_type;
139 typedef ALLOC allocator_type;
157 explicit Matrix(
const difference_type &aShape,
158 ALLOC
const & alloc = allocator_type())
167 Matrix(difference_type_1 rows, difference_type_1 columns,
168 ALLOC
const & alloc = allocator_type())
169 :
BaseType(difference_type(rows, columns), alloc)
178 allocator_type
const & alloc = allocator_type())
187 Matrix(difference_type_1 rows, difference_type_1 columns, const_reference init,
188 allocator_type
const & alloc = allocator_type())
189 :
BaseType(difference_type(rows, columns), init, alloc)
199 Matrix(
const difference_type &
shape, const_pointer init, RawArrayMemoryLayout layout = RowMajor,
200 allocator_type
const & alloc = allocator_type())
203 if(layout == RowMajor)
205 difference_type trans(shape[1], shape[0]);
221 Matrix(difference_type_1 rows, difference_type_1 columns, const_pointer init, RawArrayMemoryLayout layout = RowMajor,
222 allocator_type
const & alloc = allocator_type())
223 :
BaseType(difference_type(rows, columns), alloc)
225 if(layout == RowMajor)
227 difference_type trans(columns, rows);
253 Matrix(
const TemporaryMatrix<T, ALLOC> &rhs)
256 this->
swap(
const_cast<TemporaryMatrix<T, ALLOC> &
>(rhs));
262 template<
class U,
class C>
286 if(this->
shape() == rhs.shape())
289 this->
swap(
const_cast<TemporaryMatrix<T, ALLOC> &
>(rhs));
299 template <
class U,
class C>
325 void reshape(difference_type_1 rows, difference_type_1 columns)
332 void reshape(difference_type_1 rows, difference_type_1 columns, const_reference init)
339 void reshape(difference_type
const & newShape)
346 void reshape(difference_type
const & newShape, const_reference init)
395 TemporaryMatrix<T>
sum()
const
397 TemporaryMatrix<T> result(1, 1);
399 destMultiArrayRange(result),
406 TemporaryMatrix<T>
sum(difference_type_1 d)
const
409 TemporaryMatrix<T> result(shape);
411 destMultiArrayRange(result),
418 TemporaryMatrix<T>
mean()
const
420 TemporaryMatrix<T> result(1, 1);
422 destMultiArrayRange(result),
429 TemporaryMatrix<T>
mean(difference_type_1 d)
const
432 TemporaryMatrix<T> result(shape);
434 destMultiArrayRange(result),
447 value_type &
operator()(difference_type_1 row, difference_type_1 column);
453 value_type
operator()(difference_type_1 row, difference_type_1 column)
const;
457 typename NormTraits<Matrix>::SquaredNormType
squaredNorm()
const;
461 typename NormTraits<Matrix>::NormType
norm()
const;
476 template <
class U,
class C>
485 template <
class U,
class C>
494 template <
class U,
class C>
503 template <
class U,
class C>
547 template <
class T,
class ALLOC>
548 class TemporaryMatrix
549 :
public Matrix<T, ALLOC>
551 typedef Matrix<T, ALLOC> BaseType;
553 typedef Matrix<T, ALLOC> matrix_type;
554 typedef TemporaryMatrix<T, ALLOC> temp_type;
556 typedef typename BaseType::value_type value_type;
557 typedef typename BaseType::pointer pointer;
558 typedef typename BaseType::const_pointer const_pointer;
559 typedef typename BaseType::reference reference;
560 typedef typename BaseType::const_reference const_reference;
561 typedef typename BaseType::difference_type difference_type;
562 typedef typename BaseType::difference_type_1 difference_type_1;
563 typedef ALLOC allocator_type;
565 TemporaryMatrix(difference_type
const & shape)
566 : BaseType(shape, ALLOC())
569 TemporaryMatrix(difference_type
const & shape, const_reference init)
570 : BaseType(shape, init, ALLOC())
573 TemporaryMatrix(difference_type_1 rows, difference_type_1 columns)
574 : BaseType(rows, columns, ALLOC())
577 TemporaryMatrix(difference_type_1 rows, difference_type_1 columns, const_reference init)
578 : BaseType(rows, columns, init, ALLOC())
581 template<
class U,
class C>
582 TemporaryMatrix(
const MultiArrayView<2, U, C> &rhs)
586 TemporaryMatrix(
const TemporaryMatrix &rhs)
589 this->
swap(const_cast<TemporaryMatrix &>(rhs));
593 TemporaryMatrix & init(
const U & init)
599 template <
class U,
class C>
600 TemporaryMatrix &
operator+=(MultiArrayView<2, U, C>
const & other)
606 template <
class U,
class C>
607 TemporaryMatrix &
operator-=(MultiArrayView<2, U, C>
const & other)
613 template <
class U,
class C>
614 TemporaryMatrix &
operator*=(MultiArrayView<2, U, C>
const & other)
620 template <
class U,
class C>
621 TemporaryMatrix &
operator/=(MultiArrayView<2, U, C>
const & other)
652 TemporaryMatrix &
operator=(
const TemporaryMatrix &rhs);
669 template <
class T,
class C>
682 template <
class T,
class C>
695 template <
class T,
class C>
711 template <
class T,
class C>
716 return m.
subarray(first, Shape(first[0]+1, end));
725 template <
class T,
class C>
740 template <
class T,
class C>
745 return m.
subarray(first, Shape(end, first[1]+1));
759 template <
class T,
class C>
765 return m.
subarray(Shape(first, 0), Shape(end, 1));
766 vigra_precondition(
rowCount(m) == 1,
767 "linalg::subVector(): Input must be a vector (1xN or Nx1).");
768 return m.
subarray(Shape(0, first), Shape(1, end));
777 template <
class T,
class C>
787 if(m(j, i) != m(i, j))
799 template <
class T,
class C>
800 typename NumericTraits<T>::Promote
803 typedef typename NumericTraits<T>::Promote SumType;
806 vigra_precondition(size ==
columnCount(m),
"linalg::trace(): Matrix must be square.");
808 SumType
sum = NumericTraits<SumType>::zero();
814 #ifdef DOXYGEN // documentation only -- function is already defined in vigra/multi_array.hxx
822 template <
class T,
class ALLOC>
823 typename Matrix<T, ALLLOC>::SquaredNormType
832 template <
class T,
class ALLOC>
833 typename Matrix<T, ALLLOC>::NormType
834 norm(
const Matrix<T, ALLLOC> &a);
844 template <
class T,
class C>
849 "identityMatrix(): Matrix must be square.");
852 r(j, i) = NumericTraits<T>::zero();
853 r(i, i) = NumericTraits<T>::one();
871 TemporaryMatrix<T> ret(size, size, NumericTraits<T>::zero());
873 ret(i, i) = NumericTraits<T>::one();
891 return TemporaryMatrix<T>(rows, cols, NumericTraits<T>::one());
896 template <
class T,
class C1,
class C2>
901 "diagonalMatrix(): result must be a square matrix.");
914 template <
class T,
class C1,
class C2>
918 "diagonalMatrix(): input must be a vector.");
919 r.
init(NumericTraits<T>::zero());
942 template <
class T,
class C>
946 "diagonalMatrix(): input must be a vector.");
948 TemporaryMatrix<T> ret(size, size, NumericTraits<T>::zero());
964 template <
class T,
class C1,
class C2>
970 "transpose(): arrays must have transposed shapes.");
993 template <
class T,
class C>
1008 template <
class T,
class C1,
class C2>
1009 inline TemporaryMatrix<T>
1012 typedef typename TemporaryMatrix<T>::difference_type Shape;
1016 "joinVertically(): shape mismatch.");
1020 TemporaryMatrix<T> t(ma + mb, n, T());
1021 t.subarray(Shape(0,0), Shape(ma, n)) = a;
1022 t.subarray(Shape(ma,0), Shape(ma+mb, n)) = b;
1034 template <
class T,
class C1,
class C2>
1035 inline TemporaryMatrix<T>
1038 typedef typename TemporaryMatrix<T>::difference_type Shape;
1041 vigra_precondition(m ==
rowCount(b),
1042 "joinHorizontally(): shape mismatch.");
1046 TemporaryMatrix<T> t(m, na + nb, T());
1047 t.subarray(Shape(0,0), Shape(m, na)) = a;
1048 t.subarray(Shape(0, na), Shape(m, na + nb)) = b;
1062 template <
class T,
class C1,
class C2>
1064 unsigned int verticalCount,
unsigned int horizontalCount)
1070 "repeatMatrix(): Shape mismatch.");
1072 for(
MultiArrayIndex l=0; l<static_cast<MultiArrayIndex>(horizontalCount); ++l)
1074 for(
MultiArrayIndex k=0; k<static_cast<MultiArrayIndex>(verticalCount); ++k)
1076 r.
subarray(Shape(k*m, l*n), Shape((k+1)*m, (l+1)*n)) = v;
1092 template <
class T,
class C>
1097 TemporaryMatrix<T> ret(verticalCount*m, horizontalCount*n);
1109 template <
class T,
class C1,
class C2,
class C3>
1117 "add(): Matrix shapes must agree.");
1121 r(j, i) = a(j, i) + b(j, i);
1134 template <
class T,
class C1,
class C2>
1135 inline TemporaryMatrix<T>
1138 return TemporaryMatrix<T>(a) += b;
1141 template <
class T,
class C>
1142 inline TemporaryMatrix<T>
1145 return const_cast<TemporaryMatrix<T> &
>(a) += b;
1148 template <
class T,
class C>
1149 inline TemporaryMatrix<T>
1150 operator+(
const MultiArrayView<2, T, C> &a,
const TemporaryMatrix<T> &b)
1152 return const_cast<TemporaryMatrix<T> &
>(b) += a;
1156 inline TemporaryMatrix<T>
1157 operator+(
const TemporaryMatrix<T> &a,
const TemporaryMatrix<T> &b)
1159 return const_cast<TemporaryMatrix<T> &
>(a) += b;
1169 template <
class T,
class C>
1170 inline TemporaryMatrix<T>
1173 return TemporaryMatrix<T>(a) += b;
1177 inline TemporaryMatrix<T>
1178 operator+(
const TemporaryMatrix<T> &a, T b)
1180 return const_cast<TemporaryMatrix<T> &
>(a) += b;
1190 template <
class T,
class C>
1191 inline TemporaryMatrix<T>
1194 return TemporaryMatrix<T>(b) += a;
1198 inline TemporaryMatrix<T>
1199 operator+(T a,
const TemporaryMatrix<T> &b)
1201 return const_cast<TemporaryMatrix<T> &
>(b) += a;
1211 template <
class T,
class C1,
class C2,
class C3>
1219 "subtract(): Matrix shapes must agree.");
1223 r(j, i) = a(j, i) - b(j, i);
1236 template <
class T,
class C1,
class C2>
1237 inline TemporaryMatrix<T>
1240 return TemporaryMatrix<T>(a) -= b;
1243 template <
class T,
class C>
1244 inline TemporaryMatrix<T>
1247 return const_cast<TemporaryMatrix<T> &
>(a) -= b;
1250 template <
class T,
class C>
1252 operator-(
const MultiArrayView<2, T, C> &a,
const TemporaryMatrix<T> &b)
1256 vigra_precondition(rows == b.rowCount() && cols == b.columnCount(),
1257 "Matrix::operator-(): Shape mismatch.");
1261 const_cast<TemporaryMatrix<T> &
>(b)(j, i) = a(j, i) - b(j, i);
1266 inline TemporaryMatrix<T>
1267 operator-(
const TemporaryMatrix<T> &a,
const TemporaryMatrix<T> &b)
1269 return const_cast<TemporaryMatrix<T> &
>(a) -= b;
1279 template <
class T,
class C>
1280 inline TemporaryMatrix<T>
1283 return TemporaryMatrix<T>(a) *= -NumericTraits<T>::one();
1287 inline TemporaryMatrix<T>
1290 return const_cast<TemporaryMatrix<T> &
>(a) *= -NumericTraits<T>::one();
1300 template <
class T,
class C>
1301 inline TemporaryMatrix<T>
1304 return TemporaryMatrix<T>(a) -= b;
1308 inline TemporaryMatrix<T>
1309 operator-(
const TemporaryMatrix<T> &a, T b)
1311 return const_cast<TemporaryMatrix<T> &
>(a) -= b;
1321 template <
class T,
class C>
1322 inline TemporaryMatrix<T>
1325 return TemporaryMatrix<T>(b.
shape(), a) -= b;
1340 template <
class T,
class C1,
class C2>
1341 typename NormTraits<T>::SquaredNormType
1344 typename NormTraits<T>::SquaredNormType ret =
1345 NumericTraits<typename NormTraits<T>::SquaredNormType>::zero();
1348 std::ptrdiff_t size = y.
shape(0);
1350 for(std::ptrdiff_t i = 0; i < size; ++i)
1351 ret += x(0, i) * y(i, 0);
1352 else if(x.
shape(1) == 1u && x.
shape(0) == size)
1353 for(std::ptrdiff_t i = 0; i < size; ++i)
1354 ret += x(i, 0) * y(i, 0);
1356 vigra_precondition(
false,
"dot(): wrong matrix shapes.");
1358 else if(y.
shape(0) == 1)
1360 std::ptrdiff_t size = y.
shape(1);
1362 for(std::ptrdiff_t i = 0; i < size; ++i)
1363 ret += x(0, i) * y(0, i);
1364 else if(x.
shape(1) == 1u && x.
shape(0) == size)
1365 for(std::ptrdiff_t i = 0; i < size; ++i)
1366 ret += x(i, 0) * y(0, i);
1368 vigra_precondition(
false,
"dot(): wrong matrix shapes.");
1371 vigra_precondition(
false,
"dot(): wrong matrix shapes.");
1382 template <
class T,
class C1,
class C2>
1383 typename NormTraits<T>::SquaredNormType
1388 "dot(): shape mismatch.");
1389 typename NormTraits<T>::SquaredNormType ret =
1390 NumericTraits<typename NormTraits<T>::SquaredNormType>::zero();
1403 template <
class T,
class C1,
class C2,
class C3>
1408 "cross(): vectors must have length 3.");
1409 r(0) = x(1)*y(2) - x(2)*y(1);
1410 r(1) = x(2)*y(0) - x(0)*y(2);
1411 r(2) = x(0)*y(1) - x(1)*y(0);
1422 template <
class T,
class C1,
class C2,
class C3>
1427 "cross(): vectors must have length 3.");
1428 r(0,0) = x(1,0)*y(2,0) - x(2,0)*y(1,0);
1429 r(1,0) = x(2,0)*y(0,0) - x(0,0)*y(2,0);
1430 r(2,0) = x(0,0)*y(1,0) - x(1,0)*y(0,0);
1441 template <
class T,
class C1,
class C2>
1445 TemporaryMatrix<T> ret(3, 1);
1458 template <
class T,
class C1,
class C2,
class C3>
1466 "outer(): shape mismatch.");
1469 r(j, i) = x(j, 0) * y(0, i);
1481 template <
class T,
class C1,
class C2>
1488 "outer(): shape mismatch.");
1489 TemporaryMatrix<T> ret(rows, cols);
1501 template <
class T,
class C>
1507 vigra_precondition(rows == 1 || cols == 1,
1508 "outer(): matrix does not represent a vector.");
1510 TemporaryMatrix<T> ret(size, size);
1516 ret(j, i) = x(0, j) * x(0, i);
1522 ret(j, i) = x(j, 0) * x(i, 0);
1534 template <
class T,
int N>
1538 TemporaryMatrix<T> ret(N, N);
1542 ret(j, i) = x[j] * x[i];
1552 PointWise(T
const & it)
1558 PointWise<T> pointWise(T
const & t)
1560 return PointWise<T>(t);
1571 template <
class T,
class C1,
class C2>
1577 "smul(): Matrix sizes must agree.");
1581 r(j, i) = a(j, i) * b;
1591 template <
class T,
class C2,
class C3>
1604 template <
class T,
class C1,
class C2,
class C3>
1612 "mmul(): Matrix shapes must agree.");
1618 r(j, i) = a(j, 0) * b(0, i);
1621 r(j, i) += a(j, k) * b(k, i);
1633 template <
class T,
class C1,
class C2>
1634 inline TemporaryMatrix<T>
1649 template <
class T,
class C1,
class C2,
class C3>
1657 "pmul(): Matrix shapes must agree.");
1661 r(j, i) = a(j, i) * b(j, i);
1674 template <
class T,
class C1,
class C2>
1675 inline TemporaryMatrix<T>
1678 TemporaryMatrix<T> ret(a.
shape());
1701 template <
class T,
class C,
class U>
1702 inline TemporaryMatrix<T>
1705 return pmul(a, b.t);
1715 template <
class T,
class C>
1716 inline TemporaryMatrix<T>
1719 return TemporaryMatrix<T>(a) *= b;
1723 inline TemporaryMatrix<T>
1724 operator*(
const TemporaryMatrix<T> &a, T b)
1726 return const_cast<TemporaryMatrix<T> &
>(a) *= b;
1736 template <
class T,
class C>
1737 inline TemporaryMatrix<T>
1740 return TemporaryMatrix<T>(b) *= a;
1744 inline TemporaryMatrix<T>
1745 operator*(T a,
const TemporaryMatrix<T> &b)
1747 return const_cast<TemporaryMatrix<T> &
>(b) *= a;
1758 template <
class T,
class A,
int N,
class DATA,
class DERIVED>
1763 "operator*(Matrix, TinyVector): Shape mismatch.");
1779 template <
class T,
int N,
class DATA,
class DERIVED,
class A>
1784 "operator*(TinyVector, Matrix): Shape mismatch.");
1800 template <
class T,
class C1,
class C2>
1801 inline TemporaryMatrix<T>
1816 template <
class T,
class C1,
class C2>
1822 "sdiv(): Matrix sizes must agree.");
1826 r(j, i) = a(j, i) / b;
1836 template <
class T,
class C1,
class C2,
class C3>
1844 "pdiv(): Matrix shapes must agree.");
1848 r(j, i) = a(j, i) / b(j, i);
1861 template <
class T,
class C1,
class C2>
1862 inline TemporaryMatrix<T>
1865 TemporaryMatrix<T> ret(a.
shape());
1888 template <
class T,
class C,
class U>
1889 inline TemporaryMatrix<T>
1892 return pdiv(a, b.t);
1902 template <
class T,
class C>
1903 inline TemporaryMatrix<T>
1906 return TemporaryMatrix<T>(a) /= b;
1910 inline TemporaryMatrix<T>
1911 operator/(
const TemporaryMatrix<T> &a, T b)
1913 return const_cast<TemporaryMatrix<T> &
>(a) /= b;
1923 template <
class T,
class C>
1924 inline TemporaryMatrix<T>
1927 return TemporaryMatrix<T>(b.
shape(), a) / pointWise(b);
1952 template <
class T,
class C>
1955 T vopt = NumericTraits<T>::max();
1957 for(
int k=0; k < a.
size(); ++k)
1985 template <
class T,
class C>
1988 T vopt = NumericTraits<T>::min();
1990 for(
int k=0; k < a.
size(); ++k)
2020 template <
class T,
class C,
class UnaryFunctor>
2023 T vopt = NumericTraits<T>::max();
2025 for(
int k=0; k < a.
size(); ++k)
2027 if(condition(a[k]) && a[k] < vopt)
2055 template <
class T,
class C,
class UnaryFunctor>
2058 T vopt = NumericTraits<T>::min();
2060 for(
int k=0; k < a.
size(); ++k)
2062 if(condition(a[k]) && vopt < a[k])
2073 template <
class T,
class C>
2076 linalg::TemporaryMatrix<T> t(v.
shape());
2086 linalg::TemporaryMatrix<T>
pow(linalg::TemporaryMatrix<T>
const & v, T exponent)
2088 linalg::TemporaryMatrix<T> & t =
const_cast<linalg::TemporaryMatrix<T> &
>(v);
2097 template <
class T,
class C>
2098 linalg::TemporaryMatrix<T>
pow(MultiArrayView<2, T, C>
const & v,
int exponent)
2100 linalg::TemporaryMatrix<T> t(v.shape());
2105 t(j, i) = vigra::pow(v(j, i), exponent);
2110 linalg::TemporaryMatrix<T>
pow(linalg::TemporaryMatrix<T>
const & v,
int exponent)
2112 linalg::TemporaryMatrix<T> & t =
const_cast<linalg::TemporaryMatrix<T> &
>(v);
2122 linalg::TemporaryMatrix<int>
pow(MultiArrayView<2, int, C>
const & v,
int exponent)
2124 linalg::TemporaryMatrix<int> t(v.shape());
2129 t(j, i) =
static_cast<int>(
vigra::pow(static_cast<double>(v(j, i)), exponent));
2134 linalg::TemporaryMatrix<int>
pow(linalg::TemporaryMatrix<int>
const & v,
int exponent)
2136 linalg::TemporaryMatrix<int> & t =
const_cast<linalg::TemporaryMatrix<int> &
>(v);
2141 t(j, i) =
static_cast<int>(
vigra::pow(static_cast<double>(t(j, i)), exponent));
2146 template <
class T,
class C>
2147 linalg::TemporaryMatrix<T>
sqrt(MultiArrayView<2, T, C>
const & v);
2149 template <
class T,
class C>
2150 linalg::TemporaryMatrix<T>
exp(MultiArrayView<2, T, C>
const & v);
2152 template <
class T,
class C>
2153 linalg::TemporaryMatrix<T>
log(MultiArrayView<2, T, C>
const & v);
2155 template <
class T,
class C>
2156 linalg::TemporaryMatrix<T>
log10(MultiArrayView<2, T, C>
const & v);
2158 template <
class T,
class C>
2159 linalg::TemporaryMatrix<T>
sin(MultiArrayView<2, T, C>
const & v);
2161 template <
class T,
class C>
2162 linalg::TemporaryMatrix<T>
asin(MultiArrayView<2, T, C>
const & v);
2164 template <
class T,
class C>
2165 linalg::TemporaryMatrix<T>
cos(MultiArrayView<2, T, C>
const & v);
2167 template <
class T,
class C>
2168 linalg::TemporaryMatrix<T>
acos(MultiArrayView<2, T, C>
const & v);
2170 template <
class T,
class C>
2171 linalg::TemporaryMatrix<T>
tan(MultiArrayView<2, T, C>
const & v);
2173 template <
class T,
class C>
2174 linalg::TemporaryMatrix<T>
atan(MultiArrayView<2, T, C>
const & v);
2176 template <
class T,
class C>
2177 linalg::TemporaryMatrix<T>
round(MultiArrayView<2, T, C>
const & v);
2179 template <
class T,
class C>
2180 linalg::TemporaryMatrix<T>
floor(MultiArrayView<2, T, C>
const & v);
2182 template <
class T,
class C>
2183 linalg::TemporaryMatrix<T>
ceil(MultiArrayView<2, T, C>
const & v);
2185 template <
class T,
class C>
2186 linalg::TemporaryMatrix<T>
abs(MultiArrayView<2, T, C>
const & v);
2188 template <
class T,
class C>
2189 linalg::TemporaryMatrix<T>
sq(MultiArrayView<2, T, C>
const & v);
2191 template <
class T,
class C>
2192 linalg::TemporaryMatrix<T>
sign(MultiArrayView<2, T, C>
const & v);
2194 #define VIGRA_MATRIX_UNARY_FUNCTION(FUNCTION, NAMESPACE) \
2195 using NAMESPACE::FUNCTION; \
2196 template <class T, class C> \
2197 linalg::TemporaryMatrix<T> FUNCTION(MultiArrayView<2, T, C> const & v) \
2199 linalg::TemporaryMatrix<T> t(v.shape()); \
2200 MultiArrayIndex m = rowCount(v), n = columnCount(v); \
2202 for(MultiArrayIndex i = 0; i < n; ++i) \
2203 for(MultiArrayIndex j = 0; j < m; ++j) \
2204 t(j, i) = NAMESPACE::FUNCTION(v(j, i)); \
2208 template <class T> \
2209 linalg::TemporaryMatrix<T> FUNCTION(linalg::Matrix<T> const & v) \
2211 linalg::TemporaryMatrix<T> t(v.shape()); \
2212 MultiArrayIndex m = rowCount(v), n = columnCount(v); \
2214 for(MultiArrayIndex i = 0; i < n; ++i) \
2215 for(MultiArrayIndex j = 0; j < m; ++j) \
2216 t(j, i) = NAMESPACE::FUNCTION(v(j, i)); \
2220 template <class T> \
2221 linalg::TemporaryMatrix<T> FUNCTION(linalg::TemporaryMatrix<T> const & v) \
2223 linalg::TemporaryMatrix<T> & t = const_cast<linalg::TemporaryMatrix<T> &>(v); \
2224 MultiArrayIndex m = rowCount(t), n = columnCount(t); \
2226 for(MultiArrayIndex i = 0; i < n; ++i) \
2227 for(MultiArrayIndex j = 0; j < m; ++j) \
2228 t(j, i) = NAMESPACE::FUNCTION(t(j, i)); \
2232 using linalg::FUNCTION;\
2235 VIGRA_MATRIX_UNARY_FUNCTION(
sqrt, std)
2236 VIGRA_MATRIX_UNARY_FUNCTION(
exp, std)
2237 VIGRA_MATRIX_UNARY_FUNCTION(
log, std)
2238 VIGRA_MATRIX_UNARY_FUNCTION(
log10, std)
2239 VIGRA_MATRIX_UNARY_FUNCTION(
sin, std)
2240 VIGRA_MATRIX_UNARY_FUNCTION(
asin, std)
2241 VIGRA_MATRIX_UNARY_FUNCTION(
cos, std)
2242 VIGRA_MATRIX_UNARY_FUNCTION(
acos, std)
2243 VIGRA_MATRIX_UNARY_FUNCTION(
tan, std)
2244 VIGRA_MATRIX_UNARY_FUNCTION(
atan, std)
2245 VIGRA_MATRIX_UNARY_FUNCTION(
round, vigra)
2246 VIGRA_MATRIX_UNARY_FUNCTION(
floor, vigra)
2247 VIGRA_MATRIX_UNARY_FUNCTION(
ceil, vigra)
2248 VIGRA_MATRIX_UNARY_FUNCTION(
abs, vigra)
2249 VIGRA_MATRIX_UNARY_FUNCTION(
sq, vigra)
2250 VIGRA_MATRIX_UNARY_FUNCTION(
sign, vigra)
2252 #undef VIGRA_MATRIX_UNARY_FUNCTION
2258 using linalg::RowMajor;
2259 using linalg::ColumnMajor;
2260 using linalg::Matrix;
2264 using linalg::pointWise;
2288 template <
class T,
class ALLOC>
2289 struct NormTraits<Matrix<T, ALLOC> >
2290 :
public NormTraits<MultiArray<2, T, ALLOC> >
2292 typedef NormTraits<MultiArray<2, T, ALLOC> > BaseType;
2293 typedef Matrix<T, ALLOC> Type;
2294 typedef typename BaseType::SquaredNormType SquaredNormType;
2295 typedef typename BaseType::NormType NormType;
2298 template <
class T,
class ALLOC>
2299 struct NormTraits<linalg::TemporaryMatrix<T, ALLOC> >
2300 :
public NormTraits<Matrix<T, ALLOC> >
2302 typedef NormTraits<Matrix<T, ALLOC> > BaseType;
2303 typedef linalg::TemporaryMatrix<T, ALLOC> Type;
2304 typedef typename BaseType::SquaredNormType SquaredNormType;
2305 typedef typename BaseType::NormType NormType;
2322 template <
class T,
class C>
2324 operator<<(ostream & s, const vigra::MultiArrayView<2, T, C> &m)
2328 ios::fmtflags flags = s.setf(ios::right | ios::fixed, ios::adjustfield | ios::floatfield);
2333 s << m(j, i) <<
" ";
2351 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2353 columnStatisticsImpl(MultiArrayView<2, T1, C1>
const & A,
2354 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & sumOfSquaredDifferences)
2360 "columnStatistics(): Shape mismatch between input and output.");
2363 mean.init(NumericTraits<T2>::zero());
2364 sumOfSquaredDifferences.init(NumericTraits<T3>::zero());
2368 typedef typename NumericTraits<T2>::RealPromote TmpType;
2370 TmpType f = TmpType(1.0 / (k + 1.0)),
2371 f1 = TmpType(1.0 - f);
2373 sumOfSquaredDifferences += f1*
sq(t);
2377 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2379 columnStatistics2PassImpl(MultiArrayView<2, T1, C1>
const & A,
2380 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & sumOfSquaredDifferences)
2386 "columnStatistics(): Shape mismatch between input and output.");
2389 mean.init(NumericTraits<T2>::zero());
2394 mean /=
static_cast<double>(m);
2396 sumOfSquaredDifferences.init(NumericTraits<T3>::zero());
2399 sumOfSquaredDifferences +=
sq(
rowVector(A, k) - mean);
2464 template <
class T1,
class C1,
class T2,
class C2>
2467 MultiArrayView<2, T2, C2> & mean)
2472 "columnStatistics(): Shape mismatch between input and output.");
2474 mean.init(NumericTraits<T2>::zero());
2483 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2486 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev)
2488 detail::columnStatisticsImpl(A, mean, stdDev);
2494 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3,
class T4,
class C4>
2497 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev, MultiArrayView<2, T4, C4> &
norm)
2504 "columnStatistics(): Shape mismatch between input and output.");
2506 detail::columnStatisticsImpl(A, mean, stdDev);
2507 norm =
sqrt(stdDev + T2(m) *
sq(mean));
2508 stdDev =
sqrt(stdDev / T3(m - 1.0));
2567 template <
class T1,
class C1,
class T2,
class C2>
2570 MultiArrayView<2, T2, C2> & mean)
2573 "rowStatistics(): Shape mismatch between input and output.");
2574 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2578 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2581 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev)
2585 "rowStatistics(): Shape mismatch between input and output.");
2586 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2587 MultiArrayView<2, T3, StridedArrayTag> ts =
transpose(stdDev);
2591 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3,
class T4,
class C4>
2594 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev, MultiArrayView<2, T4, C4> & norm)
2599 "rowStatistics(): Shape mismatch between input and output.");
2600 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2601 MultiArrayView<2, T3, StridedArrayTag> ts =
transpose(stdDev);
2602 MultiArrayView<2, T4, StridedArrayTag> tn =
transpose(norm);
2608 template <
class T1,
class C1,
class U,
class T2,
class C2,
class T3,
class C3>
2609 void updateCovarianceMatrix(MultiArrayView<2, T1, C1>
const & features,
2610 U & count, MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & covariance)
2614 "updateCovarianceMatrix(): Features must be a row or column vector.");
2615 vigra_precondition(mean.shape() == features.shape(),
2616 "updateCovarianceMatrix(): Shape mismatch between feature vector and mean vector.");
2618 "updateCovarianceMatrix(): Shape mismatch between feature vector and covariance matrix.");
2621 Matrix<T2> t = features - mean;
2623 T2 f = T2(1.0) / count,
2631 covariance(k, k) += f1*
sq(t(0, k));
2634 covariance(k, l) += f1*t(0, k)*t(0, l);
2635 covariance(l, k) = covariance(k, l);
2643 covariance(k, k) += f1*
sq(t(k, 0));
2646 covariance(k, l) += f1*t(k, 0)*t(l, 0);
2647 covariance(l, k) = covariance(k, l);
2663 template <
class T1,
class C1,
class T2,
class C2>
2669 "covarianceMatrixOfColumns(): Shape mismatch between feature matrix and covariance matrix.");
2672 covariance.
init(NumericTraits<T2>::zero());
2674 detail::updateCovarianceMatrix(
rowVector(features, k), count, means, covariance);
2675 covariance /= T2(m - 1);
2686 template <
class T,
class C>
2703 template <
class T1,
class C1,
class T2,
class C2>
2709 "covarianceMatrixOfRows(): Shape mismatch between feature matrix and covariance matrix.");
2712 covariance.
init(NumericTraits<T2>::zero());
2714 detail::updateCovarianceMatrix(
columnVector(features, k), count, means, covariance);
2715 covariance /= T2(n - 1);
2726 template <
class T,
class C>
2735 enum DataPreparationGoals { ZeroMean = 1, UnitVariance = 2, UnitNorm = 4, UnitSum = 8 };
2737 inline DataPreparationGoals operator|(DataPreparationGoals l, DataPreparationGoals r)
2739 return DataPreparationGoals(
int(l) |
int(r));
2744 template <
class T,
class C1,
class C2,
class C3,
class C4>
2746 prepareDataImpl(
const MultiArrayView<2, T, C1> & A,
2747 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2748 DataPreparationGoals goals)
2752 vigra_precondition(A.shape() == res.shape() &&
2755 "prepareDataImpl(): Shape mismatch between input and output.");
2760 offset.init(NumericTraits<T>::zero());
2761 scaling.init(NumericTraits<T>::one());
2765 bool zeroMean = (goals & ZeroMean) != 0;
2766 bool unitVariance = (goals & UnitVariance) != 0;
2767 bool unitNorm = (goals & UnitNorm) != 0;
2768 bool unitSum = (goals & UnitSum) != 0;
2772 vigra_precondition(goals == UnitSum,
2773 "prepareData(): Unit sum is not compatible with any other data preparation goal.");
2777 offset.init(NumericTraits<T>::zero());
2781 if(scaling(0, k) != NumericTraits<T>::zero())
2783 scaling(0, k) = NumericTraits<T>::one() / scaling(0, k);
2788 scaling(0, k) = NumericTraits<T>::one();
2795 vigra_precondition(!(unitVariance && unitNorm),
2796 "prepareData(): Unit variance and unit norm cannot be achieved at the same time.");
2798 Matrix<T> mean(1, n), sumOfSquaredDifferences(1, n);
2799 detail::columnStatisticsImpl(A, mean, sumOfSquaredDifferences);
2803 T stdDev =
std::sqrt(sumOfSquaredDifferences(0, k) / T(m-1));
2805 stdDev = NumericTraits<T>::zero();
2806 if(zeroMean && stdDev > NumericTraits<T>::zero())
2809 offset(0, k) = mean(0, k);
2810 mean(0, k) = NumericTraits<T>::zero();
2815 offset(0, k) = NumericTraits<T>::zero();
2818 T norm = mean(0,k) == NumericTraits<T>::zero()
2819 ?
std::sqrt(sumOfSquaredDifferences(0, k))
2820 : std::
sqrt(sumOfSquaredDifferences(0, k) + T(m) *
sq(mean(0,k)));
2821 if(unitNorm && norm > NumericTraits<T>::zero())
2824 scaling(0, k) = NumericTraits<T>::one() /
norm;
2826 else if(unitVariance && stdDev > NumericTraits<T>::zero())
2829 scaling(0, k) = NumericTraits<T>::one() / stdDev;
2833 scaling(0, k) = NumericTraits<T>::one();
2915 template <
class T,
class C1,
class C2,
class C3,
class C4>
2918 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2919 DataPreparationGoals goals = ZeroMean | UnitVariance)
2921 detail::prepareDataImpl(A, res, offset, scaling, goals);
2924 template <
class T,
class C1,
class C2>
2926 prepareColumns(MultiArrayView<2, T, C1>
const & A, MultiArrayView<2, T, C2> & res,
2927 DataPreparationGoals goals = ZeroMean | UnitVariance)
2930 detail::prepareDataImpl(A, res, offset, scaling, goals);
2991 template <
class T,
class C1,
class C2,
class C3,
class C4>
2994 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2995 DataPreparationGoals goals = ZeroMean | UnitVariance)
2998 detail::prepareDataImpl(
transpose(A), tr, to, ts, goals);
3001 template <
class T,
class C1,
class C2>
3003 prepareRows(MultiArrayView<2, T, C1>
const & A, MultiArrayView<2, T, C2> & res,
3004 DataPreparationGoals goals = ZeroMean | UnitVariance)
3006 MultiArrayView<2, T, StridedArrayTag> tr =
transpose(res);
3008 detail::prepareDataImpl(
transpose(A), tr, offset, scaling, goals);
3019 using linalg::ZeroMean;
3020 using linalg::UnitVariance;
3021 using linalg::UnitNorm;
3022 using linalg::UnitSum;
3028 #endif // VIGRA_MATRIX_HXX
Matrix(difference_type_1 rows, difference_type_1 columns, const_reference init, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:187
Matrix & operator-=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:486
Matrix & operator+=(T other)
Definition: matrix.hxx:512
Matrix & operator-=(T other)
Definition: matrix.hxx:520
linalg::TemporaryMatrix< T > acos(MultiArrayView< 2, T, C > const &v)
difference_type_1 rowCount() const
Definition: matrix.hxx:367
NormTraits< Matrix >::SquaredNormType squaredNorm() const
void covarianceMatrixOfColumns(MultiArrayView< 2, T1, C1 > const &features, MultiArrayView< 2, T2, C2 > &covariance)
Compute the covariance matrix between the columns of a matrix features.
Definition: matrix.hxx:2664
MultiArrayView< 2, T, C > columnVector(MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
Definition: matrix.hxx:727
Matrix(const difference_type &aShape, ALLOC const &alloc=allocator_type())
Definition: matrix.hxx:157
Iterator argMinIf(Iterator first, Iterator last, UnaryFunctor condition)
Find the minimum element in a sequence conforming to a condition.
Definition: algorithm.hxx:129
linalg::TemporaryMatrix< T > ceil(MultiArrayView< 2, T, C > const &v)
view_type::pointer pointer
Definition: multi_array.hxx:2502
MultiArrayShape< actual_dimension >::type difference_type
Definition: multi_array.hxx:739
Matrix(difference_type_1 rows, difference_type_1 columns, const_pointer init, RawArrayMemoryLayout layout=RowMajor, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:221
MultiArrayIndex rowCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:671
void transpose(const MultiArrayView< 2, T, C1 > &v, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:965
MultiArray & operator/=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2750
linalg::TemporaryMatrix< T > sqrt(MultiArrayView< 2, T, C > const &v)
Matrix & operator=(const Matrix &rhs)
Definition: matrix.hxx:272
void cross(const MultiArrayView< 1, T, C1 > &x, const MultiArrayView< 1, T, C2 > &y, MultiArrayView< 1, T, C3 > &r)
Definition: matrix.hxx:1404
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
difference_type_1 columnCount() const
Definition: matrix.hxx:374
int argMin(MultiArrayView< 2, T, C > const &a)
Find the index of the minimum element in a matrix.
Definition: matrix.hxx:1953
const difference_type & shape() const
Definition: multi_array.hxx:1648
difference_type m_shape
Definition: multi_array.hxx:795
Definition: matrix.hxx:123
linalg::TemporaryMatrix< T > exp(MultiArrayView< 2, T, C > const &v)
difference_type_1 elementCount() const
Definition: matrix.hxx:381
linalg::TemporaryMatrix< T > sign(MultiArrayView< 2, T, C > const &v)
Matrix & init(const U &init)
Definition: matrix.hxx:317
pointer data() const
Definition: multi_array.hxx:1898
TemporaryMatrix< T > operator+(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1136
Matrix & operator/=(T other)
Definition: matrix.hxx:536
difference_type_1 elementCount() const
Definition: multi_array.hxx:1630
linalg::TemporaryMatrix< T > round(MultiArrayView< 2, T, C > const &v)
int argMinIf(MultiArrayView< 2, T, C > const &a, UnaryFunctor condition)
Find the index of the minimum element in a matrix subject to a condition.
Definition: matrix.hxx:2021
TemporaryMatrix< T > joinVertically(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1010
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:2474
void repeatMatrix(MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r, unsigned int verticalCount, unsigned int horizontalCount)
Definition: matrix.hxx:1063
TemporaryMatrix< T > ones(MultiArrayIndex rows, MultiArrayIndex cols)
Definition: matrix.hxx:889
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2861
linalg::TemporaryMatrix< T > asin(MultiArrayView< 2, T, C > const &v)
bool isSymmetric(const MultiArrayView< 2, T, C > &v)
Definition: matrix.hxx:779
Matrix & operator*=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:495
Find the average pixel value in an image or ROI.
Definition: inspectimage.hxx:1248
TemporaryMatrix< T > operator/(const MultiArrayView< 2, T, C > &a, PointWise< U > b)
Definition: matrix.hxx:1890
bool isSymmetric() const
Definition: matrix.hxx:388
void covarianceMatrixOfRows(MultiArrayView< 2, T1, C1 > const &features, MultiArrayView< 2, T2, C2 > &covariance)
Compute the covariance matrix between the rows of a matrix features.
Definition: matrix.hxx:2704
int argMaxIf(MultiArrayView< 2, T, C > const &a, UnaryFunctor condition)
Find the index of the maximum element in a matrix subject to a condition.
Definition: matrix.hxx:2056
void add(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1110
MultiArray & operator+=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2703
std::ptrdiff_t MultiArrayIndex
Definition: multi_fwd.hxx:60
Find the sum of the pixel values in an image or ROI.
Definition: inspectimage.hxx:1143
void mmul(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1605
Matrix(difference_type_1 rows, difference_type_1 columns, ALLOC const &alloc=allocator_type())
Definition: matrix.hxx:167
Matrix & operator/=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:504
MultiArrayView< N, T, StridedArrayTag > transpose() const
Definition: multi_array.hxx:1567
view_type::difference_type difference_type
Definition: multi_array.hxx:2522
FFTWComplex< R > & operator-=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
subtract-assignment
Definition: fftw3.hxx:867
MultiArray & operator-=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2719
Matrix(ALLOC const &alloc)
Definition: matrix.hxx:148
NumericTraits< T >::Promote trace(MultiArrayView< 2, T, C > const &m)
Definition: matrix.hxx:801
void prepareRows(...)
Standardize the rows of a matrix according to given DataPreparationGoals.
MultiArray & operator=(const MultiArray &rhs)
Definition: multi_array.hxx:2669
MultiArrayView< N-M, T, StridedArrayTag > bindInner(const TinyVector< Index, M > &d) const
Definition: multi_array.hxx:2207
void sdiv(const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:1817
view_type rowVector(difference_type_1 d) const
Definition: matrix.hxx:353
difference_type_1 size() const
Definition: multi_array.hxx:1641
TemporaryMatrix< T > mean() const
Definition: matrix.hxx:418
void columnStatistics(...)
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859
Definition: multi_fwd.hxx:63
view_type::reference reference
Definition: multi_array.hxx:2510
TemporaryMatrix< T > operator-(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1238
linalg::TemporaryMatrix< T > log10(MultiArrayView< 2, T, C > const &v)
void reshape(difference_type const &newShape, const_reference init)
Definition: matrix.hxx:346
void sub(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1212
void reshape(difference_type const &newShape)
Definition: matrix.hxx:339
linalg::TemporaryMatrix< T > pow(MultiArrayView< 2, T, C > const &v, T exponent)
Definition: matrix.hxx:2074
NumericTraits< V >::Promote sum(TinyVectorBase< V, SIZE, D1, D2 > const &l)
sum of the vector's elements
Definition: tinyvector.hxx:2073
TemporaryMatrix< T > joinHorizontally(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1036
MultiArray & init(const U &init)
Definition: multi_array.hxx:2851
TinyVector< V, SIZE > pow(TinyVectorBase< V, SIZE, D1, D2 > const &v, E exponent)
Definition: tinyvector.hxx:2036
Iterator argMax(Iterator first, Iterator last)
Find the maximum element in a sequence.
Definition: algorithm.hxx:96
linalg::TemporaryMatrix< T > sq(MultiArrayView< 2, T, C > const &v)
Matrix< T, ALLLOC >::NormType norm(const Matrix< T, ALLLOC > &a)
Matrix(const MultiArrayView< 2, U, C > &rhs)
Definition: matrix.hxx:263
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
void copy(const MultiArrayView &rhs)
Definition: multi_array.hxx:1216
Matrix< T, ALLLOC >::SquaredNormType squaredNorm(const Matrix< T, ALLLOC > &a)
allocator_type const & allocator() const
Definition: multi_array.hxx:2910
Matrix & operator=(const MultiArrayView< 2, U, C > &rhs)
Definition: matrix.hxx:300
MultiArrayView< 2, T, C > subVector(MultiArrayView< 2, T, C > const &m, int first, int end)
Definition: matrix.hxx:761
FFTWComplex< R > & operator*=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
multiply-assignment
Definition: fftw3.hxx:875
Wrapper for fixed size vectors.
Definition: tinyvector.hxx:621
void reshape(difference_type_1 rows, difference_type_1 columns)
Definition: matrix.hxx:325
view_type::const_pointer const_pointer
Definition: multi_array.hxx:2506
view_type::value_type value_type
Definition: multi_array.hxx:2498
Matrix & operator=(const TemporaryMatrix< T, ALLOC > &rhs)
Definition: matrix.hxx:284
Matrix & operator*=(T other)
Definition: matrix.hxx:528
void diagonalMatrix(MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:915
int argMax(MultiArrayView< 2, T, C > const &a)
Find the index of the maximum element in a matrix.
Definition: matrix.hxx:1986
NormTraits< T >::SquaredNormType dot(const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y)
Definition: matrix.hxx:1342
void outer(const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1459
MultiArrayView< 2, vluae_type, StridedArrayTag > transpose() const
void reshape(difference_type_1 rows, difference_type_1 columns, const_reference init)
Definition: matrix.hxx:332
bool closeAtTolerance(T1 l, T2 r, typename PromoteTraits< T1, T2 >::Promote epsilon)
Tolerance based floating-point equality.
Definition: mathutil.hxx:1638
linalg::TemporaryMatrix< T > log(MultiArrayView< 2, T, C > const &v)
TemporaryMatrix< T > mean(difference_type_1 d) const
Definition: matrix.hxx:429
Iterator argMaxIf(Iterator first, Iterator last, UnaryFunctor condition)
Find the maximum element in a sequence conforming to a condition.
Definition: algorithm.hxx:165
void identityMatrix(MultiArrayView< 2, T, C > &r)
Definition: matrix.hxx:845
Matrix(const difference_type &aShape, const_reference init, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:177
TemporaryMatrix< T > sum(difference_type_1 d) const
Definition: matrix.hxx:406
MultiArrayView< 2, T, C > rowVector(MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
Definition: matrix.hxx:697
void prepareColumns(...)
Standardize the columns of a matrix according to given DataPreparationGoals.
view_type::difference_type_1 difference_type_1
Definition: multi_array.hxx:2526
MultiArrayIndex columnCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:684
void pmul(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1650
Base class for fixed size vectors.
Definition: tinyvector.hxx:82
Matrix(const difference_type &shape, const_pointer init, RawArrayMemoryLayout layout=RowMajor, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:199
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:704
void transformMultiArray(...)
Transform a multi-dimensional array with a unary function or functor.
linalg::TemporaryMatrix< T > atan(MultiArrayView< 2, T, C > const &v)
void smul(const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:1572
linalg::TemporaryMatrix< T > tan(MultiArrayView< 2, T, C > const &v)
MultiArrayView & init(const U &init)
Definition: multi_array.hxx:1206
Iterator argMin(Iterator first, Iterator last)
Find the minimum element in a sequence.
Definition: algorithm.hxx:68
FFTWComplex< R > & operator/=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
divide-assignment
Definition: fftw3.hxx:884
MultiArrayView subarray(difference_type p, difference_type q) const
Definition: multi_array.hxx:1528
linalg::TemporaryMatrix< T > abs(MultiArrayView< 2, T, C > const &v)
Matrix(const Matrix &rhs)
Definition: matrix.hxx:239
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)
Matrix(const TemporaryMatrix< T, ALLOC > &rhs)
Definition: matrix.hxx:253
void swap(MultiArray &other)
Matrix()
Definition: matrix.hxx:143
view_type columnVector(difference_type_1 d) const
Definition: matrix.hxx:360
NormTraits< Matrix >::NormType norm() const
TemporaryMatrix< T > sum() const
Definition: matrix.hxx:395
value_type & operator()(difference_type_1 row, difference_type_1 column)
MultiArrayView< N-M, T, StrideTag > bindOuter(const TinyVector< Index, M > &d) const
Definition: multi_array.hxx:2184
void pdiv(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1837
Matrix & operator+=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:477
linalg::TemporaryMatrix< T > floor(MultiArrayView< 2, T, C > const &v)
view_type::const_reference const_reference
Definition: multi_array.hxx:2514
Matrix & operator=(value_type const &v)
Definition: matrix.hxx:309
TemporaryMatrix< T > operator*(const MultiArrayView< 2, T, C > &a, PointWise< U > b)
Definition: matrix.hxx:1703
MultiArray & operator*=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2734