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"
65 template <
class T,
class C>
67 rowCount(
const MultiArrayView<2, T, C> &x);
69 template <
class T,
class C>
73 template <
class T,
class C>
74 inline MultiArrayView <2, T, C>
77 template <
class T,
class C>
78 inline MultiArrayView <2, T, C>
81 template <
class T,
class ALLOC = std::allocator<T> >
82 class TemporaryMatrix;
84 template <
class T,
class C1,
class C2>
85 void transpose(
const MultiArrayView<2, T, C1> &v, MultiArrayView<2, T, C2> &r);
87 template <
class T,
class C>
90 enum RawArrayMemoryLayout { RowMajor, ColumnMajor };
120 template <
class T,
class ALLOC = std::allocator<T> >
128 typedef TemporaryMatrix<T, ALLOC> temp_type;
137 typedef ALLOC allocator_type;
155 explicit Matrix(
const difference_type &aShape,
156 ALLOC
const & alloc = allocator_type())
165 Matrix(difference_type_1 rows, difference_type_1 columns,
166 ALLOC
const & alloc = allocator_type())
167 :
BaseType(difference_type(rows, columns), alloc)
176 allocator_type
const & alloc = allocator_type())
185 Matrix(difference_type_1 rows, difference_type_1 columns, const_reference init,
186 allocator_type
const & alloc = allocator_type())
187 :
BaseType(difference_type(rows, columns), init, alloc)
197 Matrix(
const difference_type &
shape, const_pointer init, RawArrayMemoryLayout layout = RowMajor,
198 allocator_type
const & alloc = allocator_type())
201 if(layout == RowMajor)
203 difference_type trans(shape[1], shape[0]);
219 Matrix(difference_type_1 rows, difference_type_1 columns, const_pointer init, RawArrayMemoryLayout layout = RowMajor,
220 allocator_type
const & alloc = allocator_type())
221 :
BaseType(difference_type(rows, columns), alloc)
223 if(layout == RowMajor)
225 difference_type trans(columns, rows);
251 Matrix(
const TemporaryMatrix<T, ALLOC> &rhs)
254 this->
swap(
const_cast<TemporaryMatrix<T, ALLOC> &
>(rhs));
260 template<
class U,
class C>
284 if(this->
shape() == rhs.shape())
287 this->
swap(
const_cast<TemporaryMatrix<T, ALLOC> &
>(rhs));
297 template <
class U,
class C>
323 void reshape(difference_type_1 rows, difference_type_1 columns)
330 void reshape(difference_type_1 rows, difference_type_1 columns, const_reference init)
337 void reshape(difference_type
const & newShape)
344 void reshape(difference_type
const & newShape, const_reference init)
393 TemporaryMatrix<T>
sum()
const
395 TemporaryMatrix<T> result(1, 1);
397 destMultiArrayRange(result),
404 TemporaryMatrix<T>
sum(difference_type_1 d)
const
407 TemporaryMatrix<T> result(shape);
409 destMultiArrayRange(result),
416 TemporaryMatrix<T>
mean()
const
418 TemporaryMatrix<T> result(1, 1);
420 destMultiArrayRange(result),
427 TemporaryMatrix<T>
mean(difference_type_1 d)
const
430 TemporaryMatrix<T> result(shape);
432 destMultiArrayRange(result),
445 value_type &
operator()(difference_type_1 row, difference_type_1 column);
451 value_type
operator()(difference_type_1 row, difference_type_1 column)
const;
455 typename NormTraits<Matrix>::SquaredNormType
squaredNorm()
const;
459 typename NormTraits<Matrix>::NormType
norm()
const;
474 template <
class U,
class C>
483 template <
class U,
class C>
492 template <
class U,
class C>
501 template <
class U,
class C>
545 template <
class T,
class ALLOC>
546 class TemporaryMatrix
547 :
public Matrix<T, ALLOC>
549 typedef Matrix<T, ALLOC> BaseType;
551 typedef Matrix<T, ALLOC> matrix_type;
552 typedef TemporaryMatrix<T, ALLOC> temp_type;
554 typedef typename BaseType::value_type value_type;
555 typedef typename BaseType::pointer pointer;
556 typedef typename BaseType::const_pointer const_pointer;
557 typedef typename BaseType::reference reference;
558 typedef typename BaseType::const_reference const_reference;
559 typedef typename BaseType::difference_type difference_type;
560 typedef typename BaseType::difference_type_1 difference_type_1;
561 typedef ALLOC allocator_type;
563 TemporaryMatrix(difference_type
const & shape)
564 : BaseType(shape, ALLOC())
567 TemporaryMatrix(difference_type
const & shape, const_reference init)
568 : BaseType(shape, init, ALLOC())
571 TemporaryMatrix(difference_type_1 rows, difference_type_1 columns)
572 : BaseType(rows, columns, ALLOC())
575 TemporaryMatrix(difference_type_1 rows, difference_type_1 columns, const_reference init)
576 : BaseType(rows, columns, init, ALLOC())
579 template<
class U,
class C>
580 TemporaryMatrix(
const MultiArrayView<2, U, C> &rhs)
584 TemporaryMatrix(
const TemporaryMatrix &rhs)
587 this->
swap(const_cast<TemporaryMatrix &>(rhs));
591 TemporaryMatrix & init(
const U & init)
597 template <
class U,
class C>
598 TemporaryMatrix &
operator+=(MultiArrayView<2, U, C>
const & other)
604 template <
class U,
class C>
605 TemporaryMatrix &
operator-=(MultiArrayView<2, U, C>
const & other)
611 template <
class U,
class C>
612 TemporaryMatrix &
operator*=(MultiArrayView<2, U, C>
const & other)
618 template <
class U,
class C>
619 TemporaryMatrix &
operator/=(MultiArrayView<2, U, C>
const & other)
650 TemporaryMatrix &
operator=(
const TemporaryMatrix &rhs);
667 template <
class T,
class C>
680 template <
class T,
class C>
693 template <
class T,
class C>
709 template <
class T,
class C>
714 return m.
subarray(first, Shape(first[0]+1, end));
723 template <
class T,
class C>
738 template <
class T,
class C>
743 return m.
subarray(first, Shape(end, first[1]+1));
757 template <
class T,
class C>
763 return m.
subarray(Shape(first, 0), Shape(end, 1));
764 vigra_precondition(
rowCount(m) == 1,
765 "linalg::subVector(): Input must be a vector (1xN or Nx1).");
766 return m.
subarray(Shape(0, first), Shape(1, end));
775 template <
class T,
class C>
785 if(m(j, i) != m(i, j))
797 template <
class T,
class C>
798 typename NumericTraits<T>::Promote
801 typedef typename NumericTraits<T>::Promote SumType;
804 vigra_precondition(size ==
columnCount(m),
"linalg::trace(): Matrix must be square.");
806 SumType
sum = NumericTraits<SumType>::zero();
812 #ifdef DOXYGEN // documentation only -- function is already defined in vigra/multi_array.hxx
820 template <
class T,
class ALLOC>
821 typename Matrix<T, ALLLOC>::SquaredNormType
830 template <
class T,
class ALLOC>
831 typename Matrix<T, ALLLOC>::NormType
832 norm(
const Matrix<T, ALLLOC> &a);
842 template <
class T,
class C>
847 "identityMatrix(): Matrix must be square.");
850 r(j, i) = NumericTraits<T>::zero();
851 r(i, i) = NumericTraits<T>::one();
869 TemporaryMatrix<T> ret(size, size, NumericTraits<T>::zero());
871 ret(i, i) = NumericTraits<T>::one();
889 return TemporaryMatrix<T>(rows, cols, NumericTraits<T>::one());
894 template <
class T,
class C1,
class C2>
899 "diagonalMatrix(): result must be a square matrix.");
912 template <
class T,
class C1,
class C2>
916 "diagonalMatrix(): input must be a vector.");
917 r.
init(NumericTraits<T>::zero());
940 template <
class T,
class C>
944 "diagonalMatrix(): input must be a vector.");
946 TemporaryMatrix<T> ret(size, size, NumericTraits<T>::zero());
962 template <
class T,
class C1,
class C2>
968 "transpose(): arrays must have transposed shapes.");
991 template <
class T,
class C>
1006 template <
class T,
class C1,
class C2>
1007 inline TemporaryMatrix<T>
1010 typedef typename TemporaryMatrix<T>::difference_type Shape;
1014 "joinVertically(): shape mismatch.");
1018 TemporaryMatrix<T> t(ma + mb, n, T());
1019 t.subarray(Shape(0,0), Shape(ma, n)) = a;
1020 t.subarray(Shape(ma,0), Shape(ma+mb, n)) = b;
1032 template <
class T,
class C1,
class C2>
1033 inline TemporaryMatrix<T>
1036 typedef typename TemporaryMatrix<T>::difference_type Shape;
1039 vigra_precondition(m ==
rowCount(b),
1040 "joinHorizontally(): shape mismatch.");
1044 TemporaryMatrix<T> t(m, na + nb, T());
1045 t.subarray(Shape(0,0), Shape(m, na)) = a;
1046 t.subarray(Shape(0, na), Shape(m, na + nb)) = b;
1060 template <
class T,
class C1,
class C2>
1062 unsigned int verticalCount,
unsigned int horizontalCount)
1068 "repeatMatrix(): Shape mismatch.");
1070 for(
MultiArrayIndex l=0; l<static_cast<MultiArrayIndex>(horizontalCount); ++l)
1072 for(
MultiArrayIndex k=0; k<static_cast<MultiArrayIndex>(verticalCount); ++k)
1074 r.
subarray(Shape(k*m, l*n), Shape((k+1)*m, (l+1)*n)) = v;
1090 template <
class T,
class C>
1095 TemporaryMatrix<T> ret(verticalCount*m, horizontalCount*n);
1107 template <
class T,
class C1,
class C2,
class C3>
1115 "add(): Matrix shapes must agree.");
1119 r(j, i) = a(j, i) + b(j, i);
1132 template <
class T,
class C1,
class C2>
1133 inline TemporaryMatrix<T>
1136 return TemporaryMatrix<T>(a) += b;
1139 template <
class T,
class C>
1140 inline TemporaryMatrix<T>
1143 return const_cast<TemporaryMatrix<T> &
>(a) += b;
1146 template <
class T,
class C>
1147 inline TemporaryMatrix<T>
1148 operator+(
const MultiArrayView<2, T, C> &a,
const TemporaryMatrix<T> &b)
1150 return const_cast<TemporaryMatrix<T> &
>(b) += a;
1154 inline TemporaryMatrix<T>
1155 operator+(
const TemporaryMatrix<T> &a,
const TemporaryMatrix<T> &b)
1157 return const_cast<TemporaryMatrix<T> &
>(a) += b;
1167 template <
class T,
class C>
1168 inline TemporaryMatrix<T>
1171 return TemporaryMatrix<T>(a) += b;
1175 inline TemporaryMatrix<T>
1176 operator+(
const TemporaryMatrix<T> &a, T b)
1178 return const_cast<TemporaryMatrix<T> &
>(a) += b;
1188 template <
class T,
class C>
1189 inline TemporaryMatrix<T>
1192 return TemporaryMatrix<T>(b) += a;
1196 inline TemporaryMatrix<T>
1197 operator+(T a,
const TemporaryMatrix<T> &b)
1199 return const_cast<TemporaryMatrix<T> &
>(b) += a;
1209 template <
class T,
class C1,
class C2,
class C3>
1217 "subtract(): Matrix shapes must agree.");
1221 r(j, i) = a(j, i) - b(j, i);
1234 template <
class T,
class C1,
class C2>
1235 inline TemporaryMatrix<T>
1238 return TemporaryMatrix<T>(a) -= b;
1241 template <
class T,
class C>
1242 inline TemporaryMatrix<T>
1245 return const_cast<TemporaryMatrix<T> &
>(a) -= b;
1248 template <
class T,
class C>
1250 operator-(
const MultiArrayView<2, T, C> &a,
const TemporaryMatrix<T> &b)
1254 vigra_precondition(rows == b.rowCount() && cols == b.columnCount(),
1255 "Matrix::operator-(): Shape mismatch.");
1259 const_cast<TemporaryMatrix<T> &
>(b)(j, i) = a(j, i) - b(j, i);
1264 inline TemporaryMatrix<T>
1265 operator-(
const TemporaryMatrix<T> &a,
const TemporaryMatrix<T> &b)
1267 return const_cast<TemporaryMatrix<T> &
>(a) -= b;
1277 template <
class T,
class C>
1278 inline TemporaryMatrix<T>
1281 return TemporaryMatrix<T>(a) *= -NumericTraits<T>::one();
1285 inline TemporaryMatrix<T>
1288 return const_cast<TemporaryMatrix<T> &
>(a) *= -NumericTraits<T>::one();
1298 template <
class T,
class C>
1299 inline TemporaryMatrix<T>
1302 return TemporaryMatrix<T>(a) -= b;
1306 inline TemporaryMatrix<T>
1307 operator-(
const TemporaryMatrix<T> &a, T b)
1309 return const_cast<TemporaryMatrix<T> &
>(a) -= b;
1319 template <
class T,
class C>
1320 inline TemporaryMatrix<T>
1323 return TemporaryMatrix<T>(b.
shape(), a) -= b;
1338 template <
class T,
class C1,
class C2>
1339 typename NormTraits<T>::SquaredNormType
1342 typename NormTraits<T>::SquaredNormType ret =
1343 NumericTraits<typename NormTraits<T>::SquaredNormType>::zero();
1346 std::ptrdiff_t size = y.
shape(0);
1348 for(std::ptrdiff_t i = 0; i < size; ++i)
1349 ret += x(0, i) * y(i, 0);
1350 else if(x.
shape(1) == 1u && x.
shape(0) == size)
1351 for(std::ptrdiff_t i = 0; i < size; ++i)
1352 ret += x(i, 0) * y(i, 0);
1354 vigra_precondition(
false,
"dot(): wrong matrix shapes.");
1356 else if(y.
shape(0) == 1)
1358 std::ptrdiff_t size = y.
shape(1);
1360 for(std::ptrdiff_t i = 0; i < size; ++i)
1361 ret += x(0, i) * y(0, i);
1362 else if(x.
shape(1) == 1u && x.
shape(0) == size)
1363 for(std::ptrdiff_t i = 0; i < size; ++i)
1364 ret += x(i, 0) * y(0, i);
1366 vigra_precondition(
false,
"dot(): wrong matrix shapes.");
1369 vigra_precondition(
false,
"dot(): wrong matrix shapes.");
1380 template <
class T,
class C1,
class C2>
1381 typename NormTraits<T>::SquaredNormType
1386 "dot(): shape mismatch.");
1387 typename NormTraits<T>::SquaredNormType ret =
1388 NumericTraits<typename NormTraits<T>::SquaredNormType>::zero();
1401 template <
class T,
class C1,
class C2,
class C3>
1406 "cross(): vectors must have length 3.");
1407 r(0) = x(1)*y(2) - x(2)*y(1);
1408 r(1) = x(2)*y(0) - x(0)*y(2);
1409 r(2) = x(0)*y(1) - x(1)*y(0);
1420 template <
class T,
class C1,
class C2,
class C3>
1425 "cross(): vectors must have length 3.");
1426 r(0,0) = x(1,0)*y(2,0) - x(2,0)*y(1,0);
1427 r(1,0) = x(2,0)*y(0,0) - x(0,0)*y(2,0);
1428 r(2,0) = x(0,0)*y(1,0) - x(1,0)*y(0,0);
1439 template <
class T,
class C1,
class C2>
1443 TemporaryMatrix<T> ret(3, 1);
1456 template <
class T,
class C1,
class C2,
class C3>
1464 "outer(): shape mismatch.");
1467 r(j, i) = x(j, 0) * y(0, i);
1479 template <
class T,
class C1,
class C2>
1486 "outer(): shape mismatch.");
1487 TemporaryMatrix<T> ret(rows, cols);
1499 template <
class T,
class C>
1505 vigra_precondition(rows == 1 || cols == 1,
1506 "outer(): matrix does not represent a vector.");
1508 TemporaryMatrix<T> ret(size, size);
1514 ret(j, i) = x(0, j) * x(0, i);
1520 ret(j, i) = x(j, 0) * x(i, 0);
1532 template <
class T,
int N>
1536 TemporaryMatrix<T> ret(N, N);
1540 ret(j, i) = x[j] * x[i];
1550 PointWise(T
const & it)
1556 PointWise<T> pointWise(T
const & t)
1558 return PointWise<T>(t);
1569 template <
class T,
class C1,
class C2>
1575 "smul(): Matrix sizes must agree.");
1579 r(j, i) = a(j, i) * b;
1589 template <
class T,
class C2,
class C3>
1602 template <
class T,
class C1,
class C2,
class C3>
1610 "mmul(): Matrix shapes must agree.");
1616 r(j, i) = a(j, 0) * b(0, i);
1619 r(j, i) += a(j, k) * b(k, i);
1631 template <
class T,
class C1,
class C2>
1632 inline TemporaryMatrix<T>
1647 template <
class T,
class C1,
class C2,
class C3>
1655 "pmul(): Matrix shapes must agree.");
1659 r(j, i) = a(j, i) * b(j, i);
1672 template <
class T,
class C1,
class C2>
1673 inline TemporaryMatrix<T>
1676 TemporaryMatrix<T> ret(a.
shape());
1699 template <
class T,
class C,
class U>
1700 inline TemporaryMatrix<T>
1703 return pmul(a, b.t);
1713 template <
class T,
class C>
1714 inline TemporaryMatrix<T>
1717 return TemporaryMatrix<T>(a) *= b;
1721 inline TemporaryMatrix<T>
1722 operator*(
const TemporaryMatrix<T> &a, T b)
1724 return const_cast<TemporaryMatrix<T> &
>(a) *= b;
1734 template <
class T,
class C>
1735 inline TemporaryMatrix<T>
1738 return TemporaryMatrix<T>(b) *= a;
1742 inline TemporaryMatrix<T>
1743 operator*(T a,
const TemporaryMatrix<T> &b)
1745 return const_cast<TemporaryMatrix<T> &
>(b) *= a;
1756 template <
class T,
class A,
int N,
class DATA,
class DERIVED>
1761 "operator*(Matrix, TinyVector): Shape mismatch.");
1777 template <
class T,
int N,
class DATA,
class DERIVED,
class A>
1782 "operator*(TinyVector, Matrix): Shape mismatch.");
1798 template <
class T,
class C1,
class C2>
1799 inline TemporaryMatrix<T>
1814 template <
class T,
class C1,
class C2>
1820 "sdiv(): Matrix sizes must agree.");
1824 r(j, i) = a(j, i) / b;
1834 template <
class T,
class C1,
class C2,
class C3>
1842 "pdiv(): Matrix shapes must agree.");
1846 r(j, i) = a(j, i) / b(j, i);
1859 template <
class T,
class C1,
class C2>
1860 inline TemporaryMatrix<T>
1863 TemporaryMatrix<T> ret(a.
shape());
1886 template <
class T,
class C,
class U>
1887 inline TemporaryMatrix<T>
1890 return pdiv(a, b.t);
1900 template <
class T,
class C>
1901 inline TemporaryMatrix<T>
1904 return TemporaryMatrix<T>(a) /= b;
1908 inline TemporaryMatrix<T>
1909 operator/(
const TemporaryMatrix<T> &a, T b)
1911 return const_cast<TemporaryMatrix<T> &
>(a) /= b;
1921 template <
class T,
class C>
1922 inline TemporaryMatrix<T>
1925 return TemporaryMatrix<T>(b.
shape(), a) / pointWise(b);
1950 template <
class T,
class C>
1953 T vopt = NumericTraits<T>::max();
1955 for(
int k=0; k < a.
size(); ++k)
1983 template <
class T,
class C>
1986 T vopt = NumericTraits<T>::min();
1988 for(
int k=0; k < a.
size(); ++k)
2018 template <
class T,
class C,
class UnaryFunctor>
2021 T vopt = NumericTraits<T>::max();
2023 for(
int k=0; k < a.
size(); ++k)
2025 if(condition(a[k]) && a[k] < vopt)
2053 template <
class T,
class C,
class UnaryFunctor>
2056 T vopt = NumericTraits<T>::min();
2058 for(
int k=0; k < a.
size(); ++k)
2060 if(condition(a[k]) && vopt < a[k])
2071 template <
class T,
class C>
2074 linalg::TemporaryMatrix<T> t(v.
shape());
2084 linalg::TemporaryMatrix<T>
pow(linalg::TemporaryMatrix<T>
const & v, T exponent)
2086 linalg::TemporaryMatrix<T> & t =
const_cast<linalg::TemporaryMatrix<T> &
>(v);
2095 template <
class T,
class C>
2096 linalg::TemporaryMatrix<T>
pow(MultiArrayView<2, T, C>
const & v,
int exponent)
2098 linalg::TemporaryMatrix<T> t(v.shape());
2103 t(j, i) = vigra::pow(v(j, i), exponent);
2108 linalg::TemporaryMatrix<T>
pow(linalg::TemporaryMatrix<T>
const & v,
int exponent)
2110 linalg::TemporaryMatrix<T> & t =
const_cast<linalg::TemporaryMatrix<T> &
>(v);
2120 linalg::TemporaryMatrix<int>
pow(MultiArrayView<2, int, C>
const & v,
int exponent)
2122 linalg::TemporaryMatrix<int> t(v.shape());
2127 t(j, i) =
static_cast<int>(
vigra::pow(static_cast<double>(v(j, i)), exponent));
2132 linalg::TemporaryMatrix<int>
pow(linalg::TemporaryMatrix<int>
const & v,
int exponent)
2134 linalg::TemporaryMatrix<int> & t =
const_cast<linalg::TemporaryMatrix<int> &
>(v);
2139 t(j, i) =
static_cast<int>(
vigra::pow(static_cast<double>(t(j, i)), exponent));
2144 template <
class T,
class C>
2145 linalg::TemporaryMatrix<T>
sqrt(MultiArrayView<2, T, C>
const & v);
2147 template <
class T,
class C>
2148 linalg::TemporaryMatrix<T>
exp(MultiArrayView<2, T, C>
const & v);
2150 template <
class T,
class C>
2151 linalg::TemporaryMatrix<T>
log(MultiArrayView<2, T, C>
const & v);
2153 template <
class T,
class C>
2154 linalg::TemporaryMatrix<T>
log10(MultiArrayView<2, T, C>
const & v);
2156 template <
class T,
class C>
2157 linalg::TemporaryMatrix<T>
sin(MultiArrayView<2, T, C>
const & v);
2159 template <
class T,
class C>
2160 linalg::TemporaryMatrix<T>
asin(MultiArrayView<2, T, C>
const & v);
2162 template <
class T,
class C>
2163 linalg::TemporaryMatrix<T>
cos(MultiArrayView<2, T, C>
const & v);
2165 template <
class T,
class C>
2166 linalg::TemporaryMatrix<T>
acos(MultiArrayView<2, T, C>
const & v);
2168 template <
class T,
class C>
2169 linalg::TemporaryMatrix<T>
tan(MultiArrayView<2, T, C>
const & v);
2171 template <
class T,
class C>
2172 linalg::TemporaryMatrix<T>
atan(MultiArrayView<2, T, C>
const & v);
2174 template <
class T,
class C>
2175 linalg::TemporaryMatrix<T>
round(MultiArrayView<2, T, C>
const & v);
2177 template <
class T,
class C>
2178 linalg::TemporaryMatrix<T>
floor(MultiArrayView<2, T, C>
const & v);
2180 template <
class T,
class C>
2181 linalg::TemporaryMatrix<T>
ceil(MultiArrayView<2, T, C>
const & v);
2183 template <
class T,
class C>
2184 linalg::TemporaryMatrix<T>
abs(MultiArrayView<2, T, C>
const & v);
2186 template <
class T,
class C>
2187 linalg::TemporaryMatrix<T>
sq(MultiArrayView<2, T, C>
const & v);
2189 template <
class T,
class C>
2190 linalg::TemporaryMatrix<T>
sign(MultiArrayView<2, T, C>
const & v);
2192 #define VIGRA_MATRIX_UNARY_FUNCTION(FUNCTION, NAMESPACE) \
2193 using NAMESPACE::FUNCTION; \
2194 template <class T, class C> \
2195 linalg::TemporaryMatrix<T> FUNCTION(MultiArrayView<2, T, C> const & v) \
2197 linalg::TemporaryMatrix<T> t(v.shape()); \
2198 MultiArrayIndex m = rowCount(v), n = columnCount(v); \
2200 for(MultiArrayIndex i = 0; i < n; ++i) \
2201 for(MultiArrayIndex j = 0; j < m; ++j) \
2202 t(j, i) = NAMESPACE::FUNCTION(v(j, i)); \
2206 template <class T> \
2207 linalg::TemporaryMatrix<T> FUNCTION(linalg::Matrix<T> const & v) \
2209 linalg::TemporaryMatrix<T> t(v.shape()); \
2210 MultiArrayIndex m = rowCount(v), n = columnCount(v); \
2212 for(MultiArrayIndex i = 0; i < n; ++i) \
2213 for(MultiArrayIndex j = 0; j < m; ++j) \
2214 t(j, i) = NAMESPACE::FUNCTION(v(j, i)); \
2218 template <class T> \
2219 linalg::TemporaryMatrix<T> FUNCTION(linalg::TemporaryMatrix<T> const & v) \
2221 linalg::TemporaryMatrix<T> & t = const_cast<linalg::TemporaryMatrix<T> &>(v); \
2222 MultiArrayIndex m = rowCount(t), n = columnCount(t); \
2224 for(MultiArrayIndex i = 0; i < n; ++i) \
2225 for(MultiArrayIndex j = 0; j < m; ++j) \
2226 t(j, i) = NAMESPACE::FUNCTION(t(j, i)); \
2230 using linalg::FUNCTION;\
2233 VIGRA_MATRIX_UNARY_FUNCTION(
sqrt, std)
2234 VIGRA_MATRIX_UNARY_FUNCTION(
exp, std)
2235 VIGRA_MATRIX_UNARY_FUNCTION(
log, std)
2236 VIGRA_MATRIX_UNARY_FUNCTION(
log10, std)
2237 VIGRA_MATRIX_UNARY_FUNCTION(
sin, std)
2238 VIGRA_MATRIX_UNARY_FUNCTION(
asin, std)
2239 VIGRA_MATRIX_UNARY_FUNCTION(
cos, std)
2240 VIGRA_MATRIX_UNARY_FUNCTION(
acos, std)
2241 VIGRA_MATRIX_UNARY_FUNCTION(
tan, std)
2242 VIGRA_MATRIX_UNARY_FUNCTION(
atan, std)
2243 VIGRA_MATRIX_UNARY_FUNCTION(
round, vigra)
2244 VIGRA_MATRIX_UNARY_FUNCTION(
floor, vigra)
2245 VIGRA_MATRIX_UNARY_FUNCTION(
ceil, vigra)
2246 VIGRA_MATRIX_UNARY_FUNCTION(
abs, vigra)
2247 VIGRA_MATRIX_UNARY_FUNCTION(
sq, vigra)
2248 VIGRA_MATRIX_UNARY_FUNCTION(
sign, vigra)
2250 #undef VIGRA_MATRIX_UNARY_FUNCTION
2256 using linalg::RowMajor;
2257 using linalg::ColumnMajor;
2258 using linalg::Matrix;
2262 using linalg::pointWise;
2286 template <
class T,
class ALLOC>
2287 struct NormTraits<Matrix<T, ALLOC> >
2288 :
public NormTraits<MultiArray<2, T, ALLOC> >
2290 typedef NormTraits<MultiArray<2, T, ALLOC> > BaseType;
2291 typedef Matrix<T, ALLOC> Type;
2292 typedef typename BaseType::SquaredNormType SquaredNormType;
2293 typedef typename BaseType::NormType NormType;
2296 template <
class T,
class ALLOC>
2297 struct NormTraits<linalg::TemporaryMatrix<T, ALLOC> >
2298 :
public NormTraits<Matrix<T, ALLOC> >
2300 typedef NormTraits<Matrix<T, ALLOC> > BaseType;
2301 typedef linalg::TemporaryMatrix<T, ALLOC> Type;
2302 typedef typename BaseType::SquaredNormType SquaredNormType;
2303 typedef typename BaseType::NormType NormType;
2320 template <
class T,
class C>
2322 operator<<(ostream & s, const vigra::MultiArrayView<2, T, C> &m)
2326 ios::fmtflags flags = s.setf(ios::right | ios::fixed, ios::adjustfield | ios::floatfield);
2331 s << m(j, i) <<
" ";
2349 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2351 columnStatisticsImpl(MultiArrayView<2, T1, C1>
const & A,
2352 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & sumOfSquaredDifferences)
2358 "columnStatistics(): Shape mismatch between input and output.");
2361 mean.init(NumericTraits<T2>::zero());
2362 sumOfSquaredDifferences.init(NumericTraits<T3>::zero());
2366 typedef typename NumericTraits<T2>::RealPromote TmpType;
2368 TmpType f = TmpType(1.0 / (k + 1.0)),
2369 f1 = TmpType(1.0 - f);
2371 sumOfSquaredDifferences += f1*
sq(t);
2375 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2377 columnStatistics2PassImpl(MultiArrayView<2, T1, C1>
const & A,
2378 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & sumOfSquaredDifferences)
2384 "columnStatistics(): Shape mismatch between input and output.");
2387 mean.init(NumericTraits<T2>::zero());
2392 mean /=
static_cast<double>(m);
2394 sumOfSquaredDifferences.init(NumericTraits<T3>::zero());
2397 sumOfSquaredDifferences +=
sq(
rowVector(A, k) - mean);
2462 template <
class T1,
class C1,
class T2,
class C2>
2465 MultiArrayView<2, T2, C2> & mean)
2470 "columnStatistics(): Shape mismatch between input and output.");
2472 mean.init(NumericTraits<T2>::zero());
2481 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2484 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev)
2486 detail::columnStatisticsImpl(A, mean, stdDev);
2492 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3,
class T4,
class C4>
2495 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev, MultiArrayView<2, T4, C4> &
norm)
2502 "columnStatistics(): Shape mismatch between input and output.");
2504 detail::columnStatisticsImpl(A, mean, stdDev);
2505 norm =
sqrt(stdDev + T2(m) *
sq(mean));
2506 stdDev =
sqrt(stdDev / T3(m - 1.0));
2565 template <
class T1,
class C1,
class T2,
class C2>
2568 MultiArrayView<2, T2, C2> & mean)
2571 "rowStatistics(): Shape mismatch between input and output.");
2572 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2576 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2579 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev)
2583 "rowStatistics(): Shape mismatch between input and output.");
2584 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2585 MultiArrayView<2, T3, StridedArrayTag> ts =
transpose(stdDev);
2589 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3,
class T4,
class C4>
2592 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev, MultiArrayView<2, T4, C4> & norm)
2597 "rowStatistics(): Shape mismatch between input and output.");
2598 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2599 MultiArrayView<2, T3, StridedArrayTag> ts =
transpose(stdDev);
2600 MultiArrayView<2, T4, StridedArrayTag> tn =
transpose(norm);
2606 template <
class T1,
class C1,
class U,
class T2,
class C2,
class T3,
class C3>
2607 void updateCovarianceMatrix(MultiArrayView<2, T1, C1>
const & features,
2608 U & count, MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & covariance)
2612 "updateCovarianceMatrix(): Features must be a row or column vector.");
2613 vigra_precondition(mean.shape() == features.shape(),
2614 "updateCovarianceMatrix(): Shape mismatch between feature vector and mean vector.");
2616 "updateCovarianceMatrix(): Shape mismatch between feature vector and covariance matrix.");
2619 Matrix<T2> t = features - mean;
2621 T2 f = T2(1.0) / count,
2629 covariance(k, k) += f1*
sq(t(0, k));
2632 covariance(k, l) += f1*t(0, k)*t(0, l);
2633 covariance(l, k) = covariance(k, l);
2641 covariance(k, k) += f1*
sq(t(k, 0));
2644 covariance(k, l) += f1*t(k, 0)*t(l, 0);
2645 covariance(l, k) = covariance(k, l);
2661 template <
class T1,
class C1,
class T2,
class C2>
2667 "covarianceMatrixOfColumns(): Shape mismatch between feature matrix and covariance matrix.");
2670 covariance.
init(NumericTraits<T2>::zero());
2672 detail::updateCovarianceMatrix(
rowVector(features, k), count, means, covariance);
2673 covariance /= T2(m - 1);
2684 template <
class T,
class C>
2701 template <
class T1,
class C1,
class T2,
class C2>
2707 "covarianceMatrixOfRows(): Shape mismatch between feature matrix and covariance matrix.");
2710 covariance.
init(NumericTraits<T2>::zero());
2712 detail::updateCovarianceMatrix(
columnVector(features, k), count, means, covariance);
2713 covariance /= T2(n - 1);
2724 template <
class T,
class C>
2733 enum DataPreparationGoals { ZeroMean = 1, UnitVariance = 2, UnitNorm = 4, UnitSum = 8 };
2735 inline DataPreparationGoals operator|(DataPreparationGoals l, DataPreparationGoals r)
2737 return DataPreparationGoals(
int(l) |
int(r));
2742 template <
class T,
class C1,
class C2,
class C3,
class C4>
2744 prepareDataImpl(
const MultiArrayView<2, T, C1> & A,
2745 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2746 DataPreparationGoals goals)
2750 vigra_precondition(A.shape() == res.shape() &&
2753 "prepareDataImpl(): Shape mismatch between input and output.");
2758 offset.init(NumericTraits<T>::zero());
2759 scaling.init(NumericTraits<T>::one());
2763 bool zeroMean = (goals & ZeroMean) != 0;
2764 bool unitVariance = (goals & UnitVariance) != 0;
2765 bool unitNorm = (goals & UnitNorm) != 0;
2766 bool unitSum = (goals & UnitSum) != 0;
2770 vigra_precondition(goals == UnitSum,
2771 "prepareData(): Unit sum is not compatible with any other data preparation goal.");
2775 offset.init(NumericTraits<T>::zero());
2779 if(scaling(0, k) != NumericTraits<T>::zero())
2781 scaling(0, k) = NumericTraits<T>::one() / scaling(0, k);
2786 scaling(0, k) = NumericTraits<T>::one();
2793 vigra_precondition(!(unitVariance && unitNorm),
2794 "prepareData(): Unit variance and unit norm cannot be achieved at the same time.");
2796 Matrix<T> mean(1, n), sumOfSquaredDifferences(1, n);
2797 detail::columnStatisticsImpl(A, mean, sumOfSquaredDifferences);
2801 T stdDev =
std::sqrt(sumOfSquaredDifferences(0, k) / T(m-1));
2803 stdDev = NumericTraits<T>::zero();
2804 if(zeroMean && stdDev > NumericTraits<T>::zero())
2807 offset(0, k) = mean(0, k);
2808 mean(0, k) = NumericTraits<T>::zero();
2813 offset(0, k) = NumericTraits<T>::zero();
2816 T norm = mean(0,k) == NumericTraits<T>::zero()
2817 ?
std::sqrt(sumOfSquaredDifferences(0, k))
2818 : std::
sqrt(sumOfSquaredDifferences(0, k) + T(m) *
sq(mean(0,k)));
2819 if(unitNorm && norm > NumericTraits<T>::zero())
2822 scaling(0, k) = NumericTraits<T>::one() /
norm;
2824 else if(unitVariance && stdDev > NumericTraits<T>::zero())
2827 scaling(0, k) = NumericTraits<T>::one() / stdDev;
2831 scaling(0, k) = NumericTraits<T>::one();
2913 template <
class T,
class C1,
class C2,
class C3,
class C4>
2916 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2917 DataPreparationGoals goals = ZeroMean | UnitVariance)
2919 detail::prepareDataImpl(A, res, offset, scaling, goals);
2922 template <
class T,
class C1,
class C2>
2924 prepareColumns(MultiArrayView<2, T, C1>
const & A, MultiArrayView<2, T, C2> & res,
2925 DataPreparationGoals goals = ZeroMean | UnitVariance)
2928 detail::prepareDataImpl(A, res, offset, scaling, goals);
2989 template <
class T,
class C1,
class C2,
class C3,
class C4>
2992 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2993 DataPreparationGoals goals = ZeroMean | UnitVariance)
2996 detail::prepareDataImpl(
transpose(A), tr, to, ts, goals);
2999 template <
class T,
class C1,
class C2>
3001 prepareRows(MultiArrayView<2, T, C1>
const & A, MultiArrayView<2, T, C2> & res,
3002 DataPreparationGoals goals = ZeroMean | UnitVariance)
3004 MultiArrayView<2, T, StridedArrayTag> tr =
transpose(res);
3006 detail::prepareDataImpl(
transpose(A), tr, offset, scaling, goals);
3017 using linalg::ZeroMean;
3018 using linalg::UnitVariance;
3019 using linalg::UnitNorm;
3020 using linalg::UnitSum;
3026 #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:185
Matrix & operator-=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:484
Matrix & operator+=(T other)
Definition: matrix.hxx:510
Matrix & operator-=(T other)
Definition: matrix.hxx:518
linalg::TemporaryMatrix< T > acos(MultiArrayView< 2, T, C > const &v)
difference_type_1 rowCount() const
Definition: matrix.hxx:365
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:2662
MultiArrayView< 2, T, C > columnVector(MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
Definition: matrix.hxx:725
Matrix(const difference_type &aShape, ALLOC const &alloc=allocator_type())
Definition: matrix.hxx:155
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:2448
MultiArrayShape< actual_dimension >::type difference_type
Definition: multi_array.hxx:685
Matrix(difference_type_1 rows, difference_type_1 columns, const_pointer init, RawArrayMemoryLayout layout=RowMajor, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:219
MultiArrayIndex rowCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:669
void transpose(const MultiArrayView< 2, T, C1 > &v, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:963
MultiArray & operator/=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2696
linalg::TemporaryMatrix< T > sqrt(MultiArrayView< 2, T, C > const &v)
Matrix & operator=(const Matrix &rhs)
Definition: matrix.hxx:270
void cross(const MultiArrayView< 1, T, C1 > &x, const MultiArrayView< 1, T, C2 > &y, MultiArrayView< 1, T, C3 > &r)
Definition: matrix.hxx:1402
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
difference_type_1 columnCount() const
Definition: matrix.hxx:372
int argMin(MultiArrayView< 2, T, C > const &a)
Find the index of the minimum element in a matrix.
Definition: matrix.hxx:1951
const difference_type & shape() const
Definition: multi_array.hxx:1594
difference_type m_shape
Definition: multi_array.hxx:741
Definition: matrix.hxx:121
linalg::TemporaryMatrix< T > exp(MultiArrayView< 2, T, C > const &v)
difference_type_1 elementCount() const
Definition: matrix.hxx:379
linalg::TemporaryMatrix< T > sign(MultiArrayView< 2, T, C > const &v)
Matrix & init(const U &init)
Definition: matrix.hxx:315
pointer data() const
Definition: multi_array.hxx:1844
TemporaryMatrix< T > operator+(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1134
Matrix & operator/=(T other)
Definition: matrix.hxx:534
difference_type_1 elementCount() const
Definition: multi_array.hxx:1576
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:2019
TemporaryMatrix< T > joinVertically(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1008
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:2420
void repeatMatrix(MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r, unsigned int verticalCount, unsigned int horizontalCount)
Definition: matrix.hxx:1061
TemporaryMatrix< T > ones(MultiArrayIndex rows, MultiArrayIndex cols)
Definition: matrix.hxx:887
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2807
linalg::TemporaryMatrix< T > asin(MultiArrayView< 2, T, C > const &v)
bool isSymmetric(const MultiArrayView< 2, T, C > &v)
Definition: matrix.hxx:777
Matrix & operator*=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:493
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:1888
bool isSymmetric() const
Definition: matrix.hxx:386
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:2702
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:2054
void add(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1108
MultiArray & operator+=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2649
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:1603
Matrix(difference_type_1 rows, difference_type_1 columns, ALLOC const &alloc=allocator_type())
Definition: matrix.hxx:165
Matrix & operator/=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:502
MultiArrayView< N, T, StridedArrayTag > transpose() const
Definition: multi_array.hxx:1513
view_type::difference_type difference_type
Definition: multi_array.hxx:2468
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:2665
Matrix(ALLOC const &alloc)
Definition: matrix.hxx:146
NumericTraits< T >::Promote trace(MultiArrayView< 2, T, C > const &m)
Definition: matrix.hxx:799
void prepareRows(...)
Standardize the rows of a matrix according to given DataPreparationGoals.
MultiArray & operator=(const MultiArray &rhs)
Definition: multi_array.hxx:2615
MultiArrayView< N-M, T, StridedArrayTag > bindInner(const TinyVector< Index, M > &d) const
Definition: multi_array.hxx:2153
void sdiv(const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:1815
view_type rowVector(difference_type_1 d) const
Definition: matrix.hxx:351
difference_type_1 size() const
Definition: multi_array.hxx:1587
TemporaryMatrix< T > mean() const
Definition: matrix.hxx:416
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:2456
TemporaryMatrix< T > operator-(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
Definition: matrix.hxx:1236
linalg::TemporaryMatrix< T > log10(MultiArrayView< 2, T, C > const &v)
void reshape(difference_type const &newShape, const_reference init)
Definition: matrix.hxx:344
void sub(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1210
void reshape(difference_type const &newShape)
Definition: matrix.hxx:337
linalg::TemporaryMatrix< T > pow(MultiArrayView< 2, T, C > const &v, T exponent)
Definition: matrix.hxx:2072
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:1034
MultiArray & init(const U &init)
Definition: multi_array.hxx:2797
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:261
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
void copy(const MultiArrayView &rhs)
Definition: multi_array.hxx:1162
Matrix< T, ALLLOC >::SquaredNormType squaredNorm(const Matrix< T, ALLLOC > &a)
allocator_type const & allocator() const
Definition: multi_array.hxx:2856
Matrix & operator=(const MultiArrayView< 2, U, C > &rhs)
Definition: matrix.hxx:298
MultiArrayView< 2, T, C > subVector(MultiArrayView< 2, T, C > const &m, int first, int end)
Definition: matrix.hxx:759
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:323
view_type::const_pointer const_pointer
Definition: multi_array.hxx:2452
view_type::value_type value_type
Definition: multi_array.hxx:2444
Matrix & operator=(const TemporaryMatrix< T, ALLOC > &rhs)
Definition: matrix.hxx:282
Matrix & operator*=(T other)
Definition: matrix.hxx:526
void diagonalMatrix(MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:913
int argMax(MultiArrayView< 2, T, C > const &a)
Find the index of the maximum element in a matrix.
Definition: matrix.hxx:1984
NormTraits< T >::SquaredNormType dot(const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y)
Definition: matrix.hxx:1340
void outer(const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1457
MultiArrayView< 2, vluae_type, StridedArrayTag > transpose() const
void reshape(difference_type_1 rows, difference_type_1 columns, const_reference init)
Definition: matrix.hxx:330
bool closeAtTolerance(T1 l, T2 r, typename PromoteTraits< T1, T2 >::Promote epsilon)
Tolerance based floating-point equality.
Definition: mathutil.hxx:1628
linalg::TemporaryMatrix< T > log(MultiArrayView< 2, T, C > const &v)
TemporaryMatrix< T > mean(difference_type_1 d) const
Definition: matrix.hxx:427
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:843
Matrix(const difference_type &aShape, const_reference init, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:175
TemporaryMatrix< T > sum(difference_type_1 d) const
Definition: matrix.hxx:404
MultiArrayView< 2, T, C > rowVector(MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
Definition: matrix.hxx:695
void prepareColumns(...)
Standardize the columns of a matrix according to given DataPreparationGoals.
view_type::difference_type_1 difference_type_1
Definition: multi_array.hxx:2472
MultiArrayIndex columnCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:682
void pmul(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1648
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:197
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:650
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:1570
linalg::TemporaryMatrix< T > tan(MultiArrayView< 2, T, C > const &v)
MultiArrayView & init(const U &init)
Definition: multi_array.hxx:1152
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:1474
linalg::TemporaryMatrix< T > abs(MultiArrayView< 2, T, C > const &v)
Matrix(const Matrix &rhs)
Definition: matrix.hxx:237
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)
Matrix(const TemporaryMatrix< T, ALLOC > &rhs)
Definition: matrix.hxx:251
void swap(MultiArray &other)
Matrix()
Definition: matrix.hxx:141
view_type columnVector(difference_type_1 d) const
Definition: matrix.hxx:358
NormTraits< Matrix >::NormType norm() const
TemporaryMatrix< T > sum() const
Definition: matrix.hxx:393
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:2130
void pdiv(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1835
Matrix & operator+=(MultiArrayView< 2, U, C > const &other)
Definition: matrix.hxx:475
linalg::TemporaryMatrix< T > floor(MultiArrayView< 2, T, C > const &v)
view_type::const_reference const_reference
Definition: multi_array.hxx:2460
Matrix & operator=(value_type const &v)
Definition: matrix.hxx:307
TemporaryMatrix< T > operator*(const MultiArrayView< 2, T, C > &a, PointWise< U > b)
Definition: matrix.hxx:1701
MultiArray & operator*=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2680