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;
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)
344 void reshape(difference_type
const & shape, 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.");
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);
1531 PointWise(T
const & it)
1537 PointWise<T> pointWise(T
const & t)
1539 return PointWise<T>(t);
1550 template <
class T,
class C1,
class C2>
1556 "smul(): Matrix sizes must agree.");
1560 r(j, i) = a(j, i) * b;
1570 template <
class T,
class C2,
class C3>
1583 template <
class T,
class C1,
class C2,
class C3>
1591 "mmul(): Matrix shapes must agree.");
1597 r(j, i) = a(j, 0) * b(0, i);
1600 r(j, i) += a(j, k) * b(k, i);
1612 template <
class T,
class C1,
class C2>
1613 inline TemporaryMatrix<T>
1628 template <
class T,
class C1,
class C2,
class C3>
1636 "pmul(): Matrix shapes must agree.");
1640 r(j, i) = a(j, i) * b(j, i);
1653 template <
class T,
class C1,
class C2>
1654 inline TemporaryMatrix<T>
1657 TemporaryMatrix<T> ret(a.
shape());
1680 template <
class T,
class C,
class U>
1681 inline TemporaryMatrix<T>
1684 return pmul(a, b.t);
1694 template <
class T,
class C>
1695 inline TemporaryMatrix<T>
1698 return TemporaryMatrix<T>(a) *= b;
1702 inline TemporaryMatrix<T>
1703 operator*(
const TemporaryMatrix<T> &a, T b)
1705 return const_cast<TemporaryMatrix<T> &
>(a) *= b;
1715 template <
class T,
class C>
1716 inline TemporaryMatrix<T>
1719 return TemporaryMatrix<T>(b) *= a;
1723 inline TemporaryMatrix<T>
1724 operator*(T a,
const TemporaryMatrix<T> &b)
1726 return const_cast<TemporaryMatrix<T> &
>(b) *= a;
1737 template <
class T,
class A,
int N,
class DATA,
class DERIVED>
1742 "operator*(Matrix, TinyVector): Shape mismatch.");
1758 template <
class T,
int N,
class DATA,
class DERIVED,
class A>
1763 "operator*(TinyVector, Matrix): Shape mismatch.");
1779 template <
class T,
class C1,
class C2>
1780 inline TemporaryMatrix<T>
1795 template <
class T,
class C1,
class C2>
1801 "sdiv(): Matrix sizes must agree.");
1805 r(j, i) = a(j, i) / b;
1815 template <
class T,
class C1,
class C2,
class C3>
1823 "pdiv(): Matrix shapes must agree.");
1827 r(j, i) = a(j, i) / b(j, i);
1840 template <
class T,
class C1,
class C2>
1841 inline TemporaryMatrix<T>
1844 TemporaryMatrix<T> ret(a.
shape());
1867 template <
class T,
class C,
class U>
1868 inline TemporaryMatrix<T>
1871 return pdiv(a, b.t);
1881 template <
class T,
class C>
1882 inline TemporaryMatrix<T>
1885 return TemporaryMatrix<T>(a) /= b;
1889 inline TemporaryMatrix<T>
1890 operator/(
const TemporaryMatrix<T> &a, T b)
1892 return const_cast<TemporaryMatrix<T> &
>(a) /= b;
1902 template <
class T,
class C>
1903 inline TemporaryMatrix<T>
1906 return TemporaryMatrix<T>(b.
shape(), a) / pointWise(b);
1931 template <
class T,
class C>
1934 T vopt = NumericTraits<T>::max();
1936 for(
int k=0; k < a.
size(); ++k)
1964 template <
class T,
class C>
1967 T vopt = NumericTraits<T>::min();
1969 for(
int k=0; k < a.
size(); ++k)
1999 template <
class T,
class C,
class UnaryFunctor>
2002 T vopt = NumericTraits<T>::max();
2004 for(
int k=0; k < a.
size(); ++k)
2006 if(condition(a[k]) && a[k] < vopt)
2034 template <
class T,
class C,
class UnaryFunctor>
2037 T vopt = NumericTraits<T>::min();
2039 for(
int k=0; k < a.
size(); ++k)
2041 if(condition(a[k]) && vopt < a[k])
2052 template <
class T,
class C>
2055 linalg::TemporaryMatrix<T> t(v.
shape());
2065 linalg::TemporaryMatrix<T>
pow(linalg::TemporaryMatrix<T>
const & v, T exponent)
2067 linalg::TemporaryMatrix<T> & t =
const_cast<linalg::TemporaryMatrix<T> &
>(v);
2076 template <
class T,
class C>
2077 linalg::TemporaryMatrix<T>
pow(MultiArrayView<2, T, C>
const & v,
int exponent)
2079 linalg::TemporaryMatrix<T> t(v.shape());
2084 t(j, i) = vigra::pow(v(j, i), exponent);
2089 linalg::TemporaryMatrix<T>
pow(linalg::TemporaryMatrix<T>
const & v,
int exponent)
2091 linalg::TemporaryMatrix<T> & t =
const_cast<linalg::TemporaryMatrix<T> &
>(v);
2101 linalg::TemporaryMatrix<int>
pow(MultiArrayView<2, int, C>
const & v,
int exponent)
2103 linalg::TemporaryMatrix<int> t(v.shape());
2108 t(j, i) = (int)vigra::pow((
double)v(j, i), exponent);
2113 linalg::TemporaryMatrix<int>
pow(linalg::TemporaryMatrix<int>
const & v,
int exponent)
2115 linalg::TemporaryMatrix<int> & t =
const_cast<linalg::TemporaryMatrix<int> &
>(v);
2120 t(j, i) = (int)vigra::pow((
double)t(j, i), exponent);
2125 template <
class T,
class C>
2126 linalg::TemporaryMatrix<T>
sqrt(MultiArrayView<2, T, C>
const & v);
2128 template <
class T,
class C>
2129 linalg::TemporaryMatrix<T>
exp(MultiArrayView<2, T, C>
const & v);
2131 template <
class T,
class C>
2132 linalg::TemporaryMatrix<T>
log(MultiArrayView<2, T, C>
const & v);
2134 template <
class T,
class C>
2135 linalg::TemporaryMatrix<T>
log10(MultiArrayView<2, T, C>
const & v);
2137 template <
class T,
class C>
2138 linalg::TemporaryMatrix<T>
sin(MultiArrayView<2, T, C>
const & v);
2140 template <
class T,
class C>
2141 linalg::TemporaryMatrix<T>
asin(MultiArrayView<2, T, C>
const & v);
2143 template <
class T,
class C>
2144 linalg::TemporaryMatrix<T>
cos(MultiArrayView<2, T, C>
const & v);
2146 template <
class T,
class C>
2147 linalg::TemporaryMatrix<T>
acos(MultiArrayView<2, T, C>
const & v);
2149 template <
class T,
class C>
2150 linalg::TemporaryMatrix<T>
tan(MultiArrayView<2, T, C>
const & v);
2152 template <
class T,
class C>
2153 linalg::TemporaryMatrix<T>
atan(MultiArrayView<2, T, C>
const & v);
2155 template <
class T,
class C>
2156 linalg::TemporaryMatrix<T>
round(MultiArrayView<2, T, C>
const & v);
2158 template <
class T,
class C>
2159 linalg::TemporaryMatrix<T>
floor(MultiArrayView<2, T, C>
const & v);
2161 template <
class T,
class C>
2162 linalg::TemporaryMatrix<T>
ceil(MultiArrayView<2, T, C>
const & v);
2164 template <
class T,
class C>
2165 linalg::TemporaryMatrix<T>
abs(MultiArrayView<2, T, C>
const & v);
2167 template <
class T,
class C>
2168 linalg::TemporaryMatrix<T>
sq(MultiArrayView<2, T, C>
const & v);
2170 template <
class T,
class C>
2171 linalg::TemporaryMatrix<T>
sign(MultiArrayView<2, T, C>
const & v);
2173 #define VIGRA_MATRIX_UNARY_FUNCTION(FUNCTION, NAMESPACE) \
2174 using NAMESPACE::FUNCTION; \
2175 template <class T, class C> \
2176 linalg::TemporaryMatrix<T> FUNCTION(MultiArrayView<2, T, C> const & v) \
2178 linalg::TemporaryMatrix<T> t(v.shape()); \
2179 MultiArrayIndex m = rowCount(v), n = columnCount(v); \
2181 for(MultiArrayIndex i = 0; i < n; ++i) \
2182 for(MultiArrayIndex j = 0; j < m; ++j) \
2183 t(j, i) = NAMESPACE::FUNCTION(v(j, i)); \
2187 template <class T> \
2188 linalg::TemporaryMatrix<T> FUNCTION(linalg::Matrix<T> const & v) \
2190 linalg::TemporaryMatrix<T> t(v.shape()); \
2191 MultiArrayIndex m = rowCount(v), n = columnCount(v); \
2193 for(MultiArrayIndex i = 0; i < n; ++i) \
2194 for(MultiArrayIndex j = 0; j < m; ++j) \
2195 t(j, i) = NAMESPACE::FUNCTION(v(j, i)); \
2199 template <class T> \
2200 linalg::TemporaryMatrix<T> FUNCTION(linalg::TemporaryMatrix<T> const & v) \
2202 linalg::TemporaryMatrix<T> & t = const_cast<linalg::TemporaryMatrix<T> &>(v); \
2203 MultiArrayIndex m = rowCount(t), n = columnCount(t); \
2205 for(MultiArrayIndex i = 0; i < n; ++i) \
2206 for(MultiArrayIndex j = 0; j < m; ++j) \
2207 t(j, i) = NAMESPACE::FUNCTION(t(j, i)); \
2211 using linalg::FUNCTION;\
2214 VIGRA_MATRIX_UNARY_FUNCTION(
sqrt, std)
2215 VIGRA_MATRIX_UNARY_FUNCTION(
exp, std)
2216 VIGRA_MATRIX_UNARY_FUNCTION(
log, std)
2217 VIGRA_MATRIX_UNARY_FUNCTION(
log10, std)
2218 VIGRA_MATRIX_UNARY_FUNCTION(
sin, std)
2219 VIGRA_MATRIX_UNARY_FUNCTION(
asin, std)
2220 VIGRA_MATRIX_UNARY_FUNCTION(
cos, std)
2221 VIGRA_MATRIX_UNARY_FUNCTION(
acos, std)
2222 VIGRA_MATRIX_UNARY_FUNCTION(
tan, std)
2223 VIGRA_MATRIX_UNARY_FUNCTION(
atan, std)
2224 VIGRA_MATRIX_UNARY_FUNCTION(
round, vigra)
2225 VIGRA_MATRIX_UNARY_FUNCTION(
floor, vigra)
2226 VIGRA_MATRIX_UNARY_FUNCTION(
ceil, vigra)
2227 VIGRA_MATRIX_UNARY_FUNCTION(
abs, vigra)
2228 VIGRA_MATRIX_UNARY_FUNCTION(
sq, vigra)
2229 VIGRA_MATRIX_UNARY_FUNCTION(
sign, vigra)
2231 #undef VIGRA_MATRIX_UNARY_FUNCTION
2237 using linalg::RowMajor;
2238 using linalg::ColumnMajor;
2239 using linalg::Matrix;
2243 using linalg::pointWise;
2267 template <
class T,
class ALLOC>
2268 struct NormTraits<Matrix<T, ALLOC> >
2269 :
public NormTraits<MultiArray<2, T, ALLOC> >
2271 typedef NormTraits<MultiArray<2, T, ALLOC> > BaseType;
2272 typedef Matrix<T, ALLOC> Type;
2273 typedef typename BaseType::SquaredNormType SquaredNormType;
2274 typedef typename BaseType::NormType NormType;
2277 template <
class T,
class ALLOC>
2278 struct NormTraits<linalg::TemporaryMatrix<T, ALLOC> >
2279 :
public NormTraits<Matrix<T, ALLOC> >
2281 typedef NormTraits<Matrix<T, ALLOC> > BaseType;
2282 typedef linalg::TemporaryMatrix<T, ALLOC> Type;
2283 typedef typename BaseType::SquaredNormType SquaredNormType;
2284 typedef typename BaseType::NormType NormType;
2301 template <
class T,
class C>
2303 operator<<(ostream & s, const vigra::MultiArrayView<2, T, C> &m)
2307 ios::fmtflags flags = s.setf(ios::right | ios::fixed, ios::adjustfield | ios::floatfield);
2312 s << m(j, i) <<
" ";
2330 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2332 columnStatisticsImpl(MultiArrayView<2, T1, C1>
const & A,
2333 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & sumOfSquaredDifferences)
2339 "columnStatistics(): Shape mismatch between input and output.");
2342 mean.init(NumericTraits<T2>::zero());
2343 sumOfSquaredDifferences.init(NumericTraits<T3>::zero());
2347 typedef typename NumericTraits<T2>::RealPromote TmpType;
2349 TmpType f = TmpType(1.0 / (k + 1.0)),
2350 f1 = TmpType(1.0 - f);
2352 sumOfSquaredDifferences += f1*
sq(t);
2356 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2358 columnStatistics2PassImpl(MultiArrayView<2, T1, C1>
const & A,
2359 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & sumOfSquaredDifferences)
2365 "columnStatistics(): Shape mismatch between input and output.");
2368 mean.init(NumericTraits<T2>::zero());
2375 sumOfSquaredDifferences.init(NumericTraits<T3>::zero());
2378 sumOfSquaredDifferences +=
sq(
rowVector(A, k) - mean);
2443 template <
class T1,
class C1,
class T2,
class C2>
2446 MultiArrayView<2, T2, C2> & mean)
2451 "columnStatistics(): Shape mismatch between input and output.");
2453 mean.init(NumericTraits<T2>::zero());
2462 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2465 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev)
2467 detail::columnStatisticsImpl(A, mean, stdDev);
2473 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3,
class T4,
class C4>
2476 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev, MultiArrayView<2, T4, C4> &
norm)
2483 "columnStatistics(): Shape mismatch between input and output.");
2485 detail::columnStatisticsImpl(A, mean, stdDev);
2486 norm =
sqrt(stdDev + T2(m) *
sq(mean));
2487 stdDev =
sqrt(stdDev / T3(m - 1.0));
2544 doxygen_overloaded_function(template <...>
void rowStatistics)
2546 template <
class T1,
class C1,
class T2,
class C2>
2549 MultiArrayView<2, T2, C2> & mean)
2552 "rowStatistics(): Shape mismatch between input and output.");
2553 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2557 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3>
2560 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev)
2564 "rowStatistics(): Shape mismatch between input and output.");
2565 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2566 MultiArrayView<2, T3, StridedArrayTag> ts =
transpose(stdDev);
2570 template <
class T1,
class C1,
class T2,
class C2,
class T3,
class C3,
class T4,
class C4>
2573 MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & stdDev, MultiArrayView<2, T4, C4> & norm)
2578 "rowStatistics(): Shape mismatch between input and output.");
2579 MultiArrayView<2, T2, StridedArrayTag> tm =
transpose(mean);
2580 MultiArrayView<2, T3, StridedArrayTag> ts =
transpose(stdDev);
2581 MultiArrayView<2, T4, StridedArrayTag> tn =
transpose(norm);
2587 template <
class T1,
class C1,
class U,
class T2,
class C2,
class T3,
class C3>
2588 void updateCovarianceMatrix(MultiArrayView<2, T1, C1>
const & features,
2589 U & count, MultiArrayView<2, T2, C2> & mean, MultiArrayView<2, T3, C3> & covariance)
2593 "updateCovarianceMatrix(): Features must be a row or column vector.");
2594 vigra_precondition(mean.shape() == features.shape(),
2595 "updateCovarianceMatrix(): Shape mismatch between feature vector and mean vector.");
2597 "updateCovarianceMatrix(): Shape mismatch between feature vector and covariance matrix.");
2600 Matrix<T2> t = features - mean;
2602 double f = 1.0 / count,
2610 covariance(k, k) += f1*
sq(t(0, k));
2613 covariance(k, l) += f1*t(0, k)*t(0, l);
2614 covariance(l, k) = covariance(k, l);
2622 covariance(k, k) += f1*
sq(t(k, 0));
2625 covariance(k, l) += f1*t(k, 0)*t(l, 0);
2626 covariance(l, k) = covariance(k, l);
2642 template <
class T1,
class C1,
class T2,
class C2>
2648 "covarianceMatrixOfColumns(): Shape mismatch between feature matrix and covariance matrix.");
2651 covariance.
init(NumericTraits<T2>::zero());
2653 detail::updateCovarianceMatrix(
rowVector(features, k), count, means, covariance);
2654 covariance /= T2(m - 1);
2665 template <
class T,
class C>
2682 template <
class T1,
class C1,
class T2,
class C2>
2688 "covarianceMatrixOfRows(): Shape mismatch between feature matrix and covariance matrix.");
2691 covariance.
init(NumericTraits<T2>::zero());
2693 detail::updateCovarianceMatrix(
columnVector(features, k), count, means, covariance);
2694 covariance /= T2(m - 1);
2705 template <
class T,
class C>
2714 enum DataPreparationGoals { ZeroMean = 1, UnitVariance = 2, UnitNorm = 4, UnitSum = 8 };
2716 inline DataPreparationGoals operator|(DataPreparationGoals l, DataPreparationGoals r)
2718 return DataPreparationGoals(
int(l) |
int(r));
2723 template <
class T,
class C1,
class C2,
class C3,
class C4>
2725 prepareDataImpl(
const MultiArrayView<2, T, C1> & A,
2726 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2727 DataPreparationGoals goals)
2731 vigra_precondition(A.shape() == res.shape() &&
2734 "prepareDataImpl(): Shape mismatch between input and output.");
2739 offset.init(NumericTraits<T>::zero());
2740 scaling.init(NumericTraits<T>::one());
2744 bool zeroMean = (goals & ZeroMean) != 0;
2745 bool unitVariance = (goals & UnitVariance) != 0;
2746 bool unitNorm = (goals & UnitNorm) != 0;
2747 bool unitSum = (goals & UnitSum) != 0;
2751 vigra_precondition(goals == UnitSum,
2752 "prepareData(): Unit sum is not compatible with any other data preparation goal.");
2756 offset.init(NumericTraits<T>::zero());
2760 if(scaling(0, k) != NumericTraits<T>::zero())
2762 scaling(0, k) = NumericTraits<T>::one() / scaling(0, k);
2767 scaling(0, k) = NumericTraits<T>::one();
2774 vigra_precondition(!(unitVariance && unitNorm),
2775 "prepareData(): Unit variance and unit norm cannot be achieved at the same time.");
2777 Matrix<T> mean(1, n), sumOfSquaredDifferences(1, n);
2778 detail::columnStatisticsImpl(A, mean, sumOfSquaredDifferences);
2782 T stdDev =
std::sqrt(sumOfSquaredDifferences(0, k) / T(m-1));
2784 stdDev = NumericTraits<T>::zero();
2785 if(zeroMean && stdDev > NumericTraits<T>::zero())
2788 offset(0, k) = mean(0, k);
2789 mean(0, k) = NumericTraits<T>::zero();
2794 offset(0, k) = NumericTraits<T>::zero();
2797 T norm = mean(0,k) == NumericTraits<T>::zero()
2798 ?
std::sqrt(sumOfSquaredDifferences(0, k))
2799 : std::
sqrt(sumOfSquaredDifferences(0, k) + T(m) *
sq(mean(0,k)));
2800 if(unitNorm && norm > NumericTraits<T>::zero())
2803 scaling(0, k) = NumericTraits<T>::one() /
norm;
2805 else if(unitVariance && stdDev > NumericTraits<T>::zero())
2808 scaling(0, k) = NumericTraits<T>::one() / stdDev;
2812 scaling(0, k) = NumericTraits<T>::one();
2894 template <
class T,
class C1,
class C2,
class C3,
class C4>
2897 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2898 DataPreparationGoals goals = ZeroMean | UnitVariance)
2900 detail::prepareDataImpl(A, res, offset, scaling, goals);
2903 template <
class T,
class C1,
class C2>
2905 prepareColumns(MultiArrayView<2, T, C1>
const & A, MultiArrayView<2, T, C2> & res,
2906 DataPreparationGoals goals = ZeroMean | UnitVariance)
2909 detail::prepareDataImpl(A, res, offset, scaling, goals);
2968 doxygen_overloaded_function(template <...>
void prepareRows)
2970 template <
class T,
class C1,
class C2,
class C3,
class C4>
2973 MultiArrayView<2, T, C2> & res, MultiArrayView<2, T, C3> & offset, MultiArrayView<2, T, C4> & scaling,
2974 DataPreparationGoals goals = ZeroMean | UnitVariance)
2977 detail::prepareDataImpl(
transpose(A), tr, to, ts, goals);
2980 template <
class T,
class C1,
class C2>
2982 prepareRows(MultiArrayView<2, T, C1>
const & A, MultiArrayView<2, T, C2> & res,
2983 DataPreparationGoals goals = ZeroMean | UnitVariance)
2985 MultiArrayView<2, T, StridedArrayTag> tr =
transpose(res);
2987 detail::prepareDataImpl(
transpose(A), tr, offset, scaling, goals);
2998 using linalg::ZeroMean;
2999 using linalg::UnitVariance;
3000 using linalg::UnitNorm;
3001 using linalg::UnitSum;
3007 #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)
Definition: matrix.hxx:2643
MultiArrayView< 2, T, C > columnVector(MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
Definition: matrix.hxx:725
Iterator argMinIf(Iterator first, Iterator last, UnaryFunctor condition)
Definition: algorithm.hxx:129
linalg::TemporaryMatrix< T > ceil(MultiArrayView< 2, T, C > const &v)
view_type::pointer pointer
Definition: multi_array.hxx:2417
MultiArrayShape< actual_dimension >::type difference_type
Definition: multi_array.hxx:801
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:2645
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)
Definition: matrix.hxx:1932
const difference_type & shape() const
Definition: multi_array.hxx:1602
difference_type m_shape
Definition: multi_array.hxx:843
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:1829
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:1584
linalg::TemporaryMatrix< T > round(MultiArrayView< 2, T, C > const &v)
int argMinIf(MultiArrayView< 2, T, C > const &a, UnaryFunctor condition)
Definition: matrix.hxx:2000
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:595
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:2756
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:1052
TemporaryMatrix< T > operator/(const MultiArrayView< 2, T, C > &a, PointWise< U > b)
Definition: matrix.hxx:1869
bool isSymmetric() const
Definition: matrix.hxx:386
void covarianceMatrixOfRows(MultiArrayView< 2, T1, C1 > const &features, MultiArrayView< 2, T2, C2 > &covariance)
Definition: matrix.hxx:2683
int argMaxIf(MultiArrayView< 2, T, C > const &a, UnaryFunctor condition)
Definition: matrix.hxx:2035
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:2598
std::ptrdiff_t MultiArrayIndex
Definition: multi_iterator.hxx:348
Find the sum of the pixel values in an image or ROI.
Definition: inspectimage.hxx:947
void mmul(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1584
MultiArrayView subarray(const difference_type &p, const difference_type &q) const
Definition: multi_array.hxx:1490
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:1528
view_type::difference_type difference_type
Definition: multi_array.hxx:2437
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:2614
Matrix(ALLOC const &alloc)
Definition: matrix.hxx:146
NumericTraits< T >::Promote trace(MultiArrayView< 2, T, C > const &m)
Definition: matrix.hxx:799
MultiArray & operator=(const MultiArray &rhs)
Definition: multi_array.hxx:2564
MultiArrayView< N-M, T, StridedArrayTag > bindInner(const TinyVector< Index, M > &d) const
Definition: multi_array.hxx:2124
void sdiv(const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:1796
view_type rowVector(difference_type_1 d) const
Definition: matrix.hxx:351
difference_type_1 size() const
Definition: multi_array.hxx:1595
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
view_type::reference reference
Definition: multi_array.hxx:2425
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 sub(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1210
linalg::TemporaryMatrix< T > pow(MultiArrayView< 2, T, C > const &v, T exponent)
Definition: matrix.hxx:2053
NumericTraits< V >::Promote sum(TinyVectorBase< V, SIZE, D1, D2 > const &l)
sum of the vector's elements
Definition: tinyvector.hxx:1683
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:2746
TinyVector< V, SIZE > pow(TinyVectorBase< V, SIZE, D1, D2 > const &v, E exponent)
Definition: tinyvector.hxx:1646
Iterator argMax(Iterator first, Iterator last)
Definition: algorithm.hxx:96
linalg::TemporaryMatrix< T > sq(MultiArrayView< 2, T, C > const &v)
Matrix(const difference_type &shape, const_reference init, allocator_type const &alloc=allocator_type())
Definition: matrix.hxx:175
Matrix< T, ALLLOC >::NormType norm(const Matrix< T, ALLLOC > &a)
Matrix(const MultiArrayView< 2, U, C > &rhs)
Definition: matrix.hxx:261
void copy(const MultiArrayView &rhs)
Definition: multi_array.hxx:1224
Matrix< T, ALLLOC >::SquaredNormType squaredNorm(const Matrix< T, ALLLOC > &a)
allocator_type const & allocator() const
Definition: multi_array.hxx:2805
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:524
void reshape(difference_type_1 rows, difference_type_1 columns)
Definition: matrix.hxx:323
view_type::const_pointer const_pointer
Definition: multi_array.hxx:2421
view_type::value_type value_type
Definition: multi_array.hxx:2413
Matrix & operator=(const TemporaryMatrix< T, ALLOC > &rhs)
Definition: matrix.hxx:282
Matrix & operator*=(T other)
Definition: matrix.hxx:526
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:939
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)
Definition: matrix.hxx:1965
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)
Definition: mathutil.hxx:1551
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)
Definition: algorithm.hxx:165
void identityMatrix(MultiArrayView< 2, T, C > &r)
Definition: matrix.hxx:843
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
view_type::difference_type_1 difference_type_1
Definition: multi_array.hxx:2441
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:1629
Base class for fixed size vectors.
Definition: tinyvector.hxx:75
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:593
void transformMultiArray(...)
Transform a multi-dimensional array with a unary function or functor.
linalg::TemporaryMatrix< T > atan(MultiArrayView< 2, T, C > const &v)
void reshape(difference_type const &shape, const_reference init)
Definition: matrix.hxx:344
void smul(const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
Definition: matrix.hxx:1551
linalg::TemporaryMatrix< T > tan(MultiArrayView< 2, T, C > const &v)
MultiArrayView & init(const U &init)
Definition: multi_array.hxx:1214
Iterator argMin(Iterator first, Iterator last)
Definition: algorithm.hxx:68
void reshape(difference_type const &shape)
Definition: matrix.hxx:337
FFTWComplex< R > & operator/=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
divide-assignment
Definition: fftw3.hxx:884
Matrix(const difference_type &shape, ALLOC const &alloc=allocator_type())
Definition: matrix.hxx:155
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:2101
void pdiv(const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
Definition: matrix.hxx:1816
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:2429
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:1682
MultiArray & operator*=(const MultiArrayView< N, U, StrideTag > &rhs)
Definition: multi_array.hxx:2629