本文整理汇总了C++中Matrix::Columns方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::Columns方法的具体用法?C++ Matrix::Columns怎么用?C++ Matrix::Columns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::Columns方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extend_orthonormal
// Matrix A's first n columns are orthonormal
// so A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix.
// Fill out the remaining columns of A to make them orthonormal
// so A.t() * A is the identity matrix
void extend_orthonormal(Matrix& A, int n)
{
REPORT
Tracer et("extend_orthonormal");
int nr = A.nrows(); int nc = A.ncols();
if (nc > nr) Throw(IncompatibleDimensionsException(A));
if (n > nc) Throw(IncompatibleDimensionsException(A));
ColumnVector SSR;
{ Matrix A1 = A.Columns(1,n); SSR = A1.sum_square_rows(); }
for (int i = n; i < nc; ++i)
{
// pick row with smallest SSQ
int k; SSR.minimum1(k);
// orthogonalise column with 1 at element k, 0 elsewhere
// next line is rather inefficient
ColumnVector X = - A.Columns(1, i) * A.SubMatrix(k, k, 1, i).t();
X(k) += 1.0;
// normalise
X /= sqrt(X.SumSquare());
// update row sums of squares
for (k = 1; k <= nr; ++k) SSR(k) += square(X(k));
// load new column into matrix
A.Column(i+1) = X;
}
}
示例2: VectorizeScan
void VectorizeScan(std::vector<Index>& scan,
const Matrix<Real> &M)
{
Index index(0,0);
scan.reserve(M.Rows() * M.Columns());
for (unsigned i=0; i<scan.capacity(); ++i) {
scan.push_back(index);
}
for (int i=0; i<M.Rows(); ++i) {
for (int j=0; j<M.Columns(); ++j) {
scan[M(i,j)].first = i;
scan[M(i,j)].second = j;
}
}
}
示例3: InPlaceGaussJordan
void PCL_FUNC InPlaceGaussJordan( Matrix& A, Matrix& B )
{
A.SetUnique();
B.SetUnique();
if ( (*API->Numerical->GaussJordanInPlaceD)( A.DataPtr(), B.DataPtr(), A.Rows(), B.Columns() ) == api_false )
throw APIFunctionError( "GaussJordanInPlaceD" );
}
示例4: WriteMatrixToFile
bool WriteMatrixToFile(const Matrix<Real> &M, const std::string& filename) {
std::ofstream file(filename.c_str());
if (!file.is_open()) {
std::cout << "File not found: " << filename << std::endl;
return false;
}
file << M.Rows() << "\n";
file << M.Columns() << "\n";
for (int r=0; r<M.Rows(); ++r) {
for (int c=0; c<M.Columns(); ++c) {
file << M(r,c) << " ";
}
file << "\n";
}
return true;
}
示例5: InPlaceSVDImplementation
void PCL_FUNC InPlaceSVDImplementation( Matrix& A, Vector& W, Matrix& V )
{
A.SetUnique();
int m = A.Rows();
int n = A.Columns();
W = Vector( n );
V = Matrix( n, n );
if ( (*API->Numerical->SVDInPlaceD)( A.DataPtr(), W.DataPtr(), V.DataPtr(), m, n ) == api_false )
throw APIFunctionError( "SVDInPlaceD" );
}
示例6: Equal
bool Matrix::Equal( Matrix& a, Matrix& b )
{
if( a.Type() != b.Type() )
return false;
if( a.Rows() != b.Rows() ||
a.Columns() != b.Columns() )
return false;
for( UINT r=0; r < a.Rows(); r++ )
{
for( UINT c=0; c < a.Columns(); c++ )
{
DataType* pA = a.Get(r, c);
DataType* pB = b.Get(r, c);
if( !DataType::Equal( pA, pB ) )
return false;
}
}
return true;
}
示例7: CircularShift
void CircularShift(const Matrix& X1, int first, int last)
{
Matrix X; UpperTriangularMatrix U1, U2;
int n = X1.Ncols();
// Try right circular shift of columns
X = X1; QRZ(X, U1);
RightCircularUpdateCholesky(U1, first, last);
X = X1.Columns(1,first-1) | X1.Column(last)
| X1.Columns(first,last-1) | X1.Columns(last+1,n);
QRZ(X, U2);
X = U1 - U2; Clean(X, 0.000000001); Print(X);
// Try left circular shift of columns
X = X1; QRZ(X, U1);
LeftCircularUpdateCholesky(U1, first, last);
X = X1.Columns(1,first-1) | X1.Columns(first+1,last)
| X1.Column(first) | X1.Columns(last+1,n);
QRZ(X, U2);
X = U1 - U2; Clean(X, 0.000000001); Print(X);
}
示例8: input
SCENARIO("Matrix init", "[init]")
{
GIVEN("The number of rows and columns")
{
auto rows = 3;
auto columns = 4;
WHEN("Create instansce of Matrix")
{
Matrix<int> A(rows, columns);
Matrix<int> B;
THEN("The number of rows and columns must be preserved")
{
REQUIRE(A.Rows() == rows);
REQUIRE(A.Columns() == columns);
REQUIRE(B.Rows() == 0);
REQUIRE(B.Columns() == 0);
}
}
}
}
SCENARIO("Matrix operator >>", "[Fill]")
{
std::ifstream input("A.txt");
Matrix<int> A(2, 2);
std::cout << endl;
REQUIRE( input >> A );
REQUIRE( A[0][0] == 2 );
REQUIRE( A[0][1] == 1 );
REQUIRE( A[1][0] == 1 );
REQUIRE( A[1][1] == 2 );