14 typedef typename Real_::DoubleType Double_;
29 if (a(i,i) == 0)
return false;
34 template<
class B,
class X>
37 assert(b.rows() == r.rows());
42 for (
sdt k = n-1; k >= 0; --k)
44 for (
sdt j = 0; j < nx; ++j)
46 for (
sdt i = 0; i < k; ++i)
47 for (
sdt j = 0; j < nx; ++j)
48 x(i,j) -= x(k,j)*r(i,k);
53 template<
class B,
class X>
56 assert(b.rows() == u.rows());
58 x.
resize(vt.cols(), b.cols());
67 x.
resize(vt.cols(), u.rows());
72 template<
class B,
class X>
75 assert(b.rows() == l.rows());
80 for (
sdt k = 0; k < n; ++k)
82 for (
sdt j = 0; j < nx; ++j)
84 for (
sdt i = k+1; i < n; ++i)
85 for (
sdt j = 0; j < nx; ++j)
86 x(i,j) -= x(k,j)*l(i,k);
93 template<
typename T1,
typename T2,
typename T3>
94 static void matrAXPY(
sdt m,
sdt n,
const T1& x,
sdt dx,
const T2& a,
sdt ai,
sdt inca, T3& y,
sdt dy)
101 for( i = 0; i < m; i++, xi += dx, yi += dy )
106 for(; j <= n - 4; j += 4 )
108 R3 t0 = (R3)(y(yi+j) + s*x(xi+j));
109 R3 t1 = (R3)(y(yi+j+1) + s*x(xi+j+1));
112 t0 = (R3)(y(yi+j+2) + s*x(xi+j+2));
113 t1 = (R3)(y(yi+j+3) + s*x(xi+j+3));
119 y(yi+j) = (R3)(y(yi+j) + s*x(xi+j));
124 template<
class B,
class X>
125 static void backSubSvd(
const Vec& w,
const Matrix& u,
const Matrix& vt,
126 optional<
const MatrixBase<B>&> b, MatrixBase<X>& x, Vec_d& buffer)
128 Double threshold = 0;
130 sdt m = u.rows(), n = vt.cols();
131 sdt udelta0 = 1, udelta1 = u.cols();
132 sdt vdelta0 = vt.cols(), vdelta1 = 1;
134 sdt ldb = b ? b->cols() : 0, ldx = x.cols();
136 sdt nb = b ? b->cols() : m;
140 for( i = 0; i < nm; i++ )
145 for( i = 0; i < nm; i++, ui += udelta0, vi += vdelta0 )
156 for( j = 0; j < m; j++ )
157 s += u(ui+j*udelta1) * (*b)(j*ldb);
162 for( j = 0; j < n; j++ )
163 x(j*ldx) = (
Real)(x(j*ldx) + s*vt(vi+j*vdelta1));
169 for( j = 0; j < nb; j++ )
171 matrAXPY( m, nb, *b, ldb, u, ui, udelta1, buffer, 0 );
172 for( j = 0; j < nb; j++ )
177 for( j = 0; j < nb; j++ )
178 buffer[j] = u(ui+j*udelta1)*wi;
181 matrAXPY( n, nb, buffer, 0, vt, vi, vdelta1, x, ldx );
static bool isFullRank(const MatrixBase< T > &a)
Check if a triangular/trapezoidal matrix has full rank (ie. all vectors are linearly independent; no ...
Definition: BackSub.h:25
Algebra.
Definition: Alge.h:13
Vec< matrix::dynamic, Real > Vec
Definition: BackSub.h:21
static optnull_t optnull
Null optional, use to reset an optional to an uninitialized state or test for initialization.
Definition: Optional.h:12
ptrdiff_t sdt
Size difference type, shorthand for ptrdiff_t.
Definition: Core.h:92
static void solveFwd(const Matrix &l, const MatrixBase< B > &b, MatrixBase< X > &x)
Solve where L is a lower triangular/trapezoidal matrix. L and B row sizes must match. L must have full rank.
Definition: BackSub.h:73
void solve(const Vec &w, const Matrix &u, const Matrix &vt, MatrixBase< X > &x)
Solve given the SVD of A. .
Definition: BackSub.h:64
std::enable_if< mt::isIterator< Iter1 >::value, Range_< Iter1, Iter2 > >::type range(Iter1 &&first, Iter2 &&last)
Range from iterators [first, last)
Definition: Range.h:116
static Int abs(Int x)
Get absolute value of signed integer.
Definition: Alge.h:21
static std::common_type< Num, Num2 >::type min(Num a, Num2 b)
Get the minimum of two numbers.
Definition: Alge.h:89
void solve(const Vec &w, const Matrix &u, const Matrix &vt, const MatrixBase< B > &b, MatrixBase< X > &x)
Solve given the SVD of A. A and B row sizes must match. .
Definition: BackSub.h:54
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Numeric type information, use numeral() to get instance safely from a static context.
Definition: Numeral.h:17
MatrixS & resize(sdt rows, sdt cols)
Sets number of rows/columns and reallocates only if the size has changed (rows*cols). All previous data is lost on reallocation. Returns self.
Definition: Base.h:277
Vec< matrix::dynamic, Double > Vec_d
Definition: BackSub.h:20
Enables any type to be optional so it can exist in an uninitialized null state.
Definition: Optional.h:52
static void solve(const Matrix &r, const MatrixBase< B > &b, MatrixBase< X > &x)
Solve where R is an upper triangular/trapezoidal matrix. R and B row sizes must match. R must have full rank.
Definition: BackSub.h:35
double Real
Definition: Real.h:14
Matrix< matrix::dynamic, matrix::dynamic, Real > Matrix
Definition: BackSub.h:19
static const double epsilon
Definition: Double.h:37
Matrix base class.
Definition: Base.h:17
Global Honeycomb namespace.
Back substitute to solve a linear system.
Definition: BackSub.h:11
VecS & resize(sdt dim)
Sets number of dimensions and reallocates only if different. All previous data is lost on reallocatio...
Definition: Base.h:69