mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
* Merge Extract and Part to the Part expression.
Renamed "MatrixBase::extract() const" to "MatrixBase::part() const" * Renamed static functions identity, zero, ones, random with an upper case first letter: Identity, Zero, Ones and Random.
This commit is contained in:
@@ -18,7 +18,7 @@ topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols)
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Matrix4d m = Matrix4d::identity();
|
||||
Matrix4d m = Matrix4d::Identity();
|
||||
cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version
|
||||
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
|
||||
cout << "Now the matrix m is:" << endl << m << endl;
|
||||
|
||||
@@ -11,7 +11,7 @@ template<typename Scalar> struct MakeComplexOp EIGEN_EMPTY_STRUCT {
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Matrix4d m1 = Matrix4d::random(), m2 = Matrix4d::random();
|
||||
Matrix4d m1 = Matrix4d::Random(), m2 = Matrix4d::Random();
|
||||
cout << m1.binaryExpr(m2, MakeComplexOp<double>()) << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ struct CwiseClampOp {
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Matrix4d m1 = Matrix4d::random();
|
||||
Matrix4d m1 = Matrix4d::Random();
|
||||
cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ topLeft2x2Corner(const MatrixBase<Derived>& m)
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Matrix3d m = Matrix3d::identity();
|
||||
Matrix3d m = Matrix3d::Identity();
|
||||
cout << topLeft2x2Corner(4*m) << endl; // calls the const version
|
||||
topLeft2x2Corner(m) *= 2; // calls the non-const version
|
||||
cout << "Now the matrix m is:" << endl << m << endl;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
typedef Matrix<float,Dynamic,2> DataMatrix;
|
||||
// let's generate some samples on the 3D plane of equation z = 2x+3y (with some noise)
|
||||
DataMatrix samples = DataMatrix::random(12,2);
|
||||
VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::random(12)*0.1;
|
||||
DataMatrix samples = DataMatrix::Random(12,2);
|
||||
VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::Random(12)*0.1;
|
||||
// and let's solve samples * x = elevations in least square sense:
|
||||
cout << (samples.adjoint() * samples).cholesky().solve((samples.adjoint()*elevations).eval()) << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix2cf m = Matrix2cf::random();
|
||||
Matrix2cf m = Matrix2cf::Random();
|
||||
cout << "Here is the 2x2 complex matrix m:" << endl << m << endl;
|
||||
cout << "Here is the adjoint of m:" << endl << m.adjoint() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
RowVector4i v = RowVector4i::random();
|
||||
RowVector4i v = RowVector4i::Random();
|
||||
cout << "Here is the vector v:" << endl << v << endl;
|
||||
cout << "Here is v.block(1, 2):" << endl << v.block(1, 2) << endl;
|
||||
v.block(1, 2).setZero();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix4i m = Matrix4i::random();
|
||||
Matrix4i m = Matrix4i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here is m.block(1, 1, 2, 2):" << endl << m.block(1, 1, 2, 2) << endl;
|
||||
m.block(1, 1, 2, 2).setZero();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix2d md = Matrix2d::identity() * 0.45;
|
||||
Matrix2f mf = Matrix2f::identity();
|
||||
Matrix2d md = Matrix2d::Identity() * 0.45;
|
||||
Matrix2f mf = Matrix2f::Identity();
|
||||
cout << md + mf.cast<double>() << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix3d m = Matrix3d::identity();
|
||||
Matrix3d m = Matrix3d::Identity();
|
||||
m.col(1) = Vector3d(4,5,6);
|
||||
cout << m << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = Matrix3d::random();
|
||||
Matrix3d m = Matrix3d::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
Matrix3d inv;
|
||||
m.computeInverse(&inv);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix4i m = Matrix4i::random();
|
||||
Matrix4i m = Matrix4i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here is the bottom-right 2x3 corner in m:" << endl
|
||||
<< m.corner(Eigen::BottomRight, 2, 3) << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3i m = Matrix3i::random();
|
||||
Matrix3i m = Matrix3i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here are the coefficients on the main diagonal of m:" << endl
|
||||
<< m.diagonal() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
RowVector4i v = RowVector4i::random();
|
||||
RowVector4i v = RowVector4i::Random();
|
||||
cout << "Here is the vector v:" << endl << v << endl;
|
||||
cout << "Here is v.end(2):" << endl << v.end(2) << endl;
|
||||
v.end(2).setZero();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix2f M = Matrix2f::random();
|
||||
Matrix2f M = Matrix2f::Random();
|
||||
Matrix2f m;
|
||||
m = M;
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
Matrix3i m = Matrix3i::random();
|
||||
Matrix3i m = Matrix3i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here is the upper-triangular matrix extracted from m:" << endl
|
||||
<< m.extract<Eigen::Upper>() << endl;
|
||||
<< m.part<Eigen::Upper>() << endl;
|
||||
cout << "Here is the strictly-upper-triangular matrix extracted from m:" << endl
|
||||
<< m.extract<Eigen::StrictlyUpper>() << endl;
|
||||
<< m.part<Eigen::StrictlyUpper>() << endl;
|
||||
cout << "Here is the unit-lower-triangular matrix extracted from m:" << endl
|
||||
<< m.extract<Eigen::UnitLower>() << endl;
|
||||
<< m.part<Eigen::UnitLower>() << endl;
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << Matrix<double, 3, 4>::identity() << endl;
|
||||
cout << Matrix<double, 3, 4>::Identity() << endl;
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << MatrixXd::identity(4, 3) << endl;
|
||||
cout << MatrixXd::Identity(4, 3) << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix3d m = Matrix3d::random();
|
||||
Matrix3d m = Matrix3d::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Its inverse is:" << endl << m.inverse() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = 10000 * Matrix3d::identity();
|
||||
Matrix3d m = 10000 * Matrix3d::Identity();
|
||||
m(0,2) = 1;
|
||||
cout << "Here's the matrix m:" << endl << m << endl;
|
||||
cout << "m.isDiagonal() returns: " << m.isDiagonal() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = Matrix3d::identity();
|
||||
Matrix3d m = Matrix3d::Identity();
|
||||
m(0,2) = 1e-4;
|
||||
cout << "Here's the matrix m:" << endl << m << endl;
|
||||
cout << "m.isIdentity() returns: " << m.isIdentity() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = Matrix3d::ones();
|
||||
Matrix3d m = Matrix3d::Ones();
|
||||
m(0,2) += 1e-4;
|
||||
cout << "Here's the matrix m:" << endl << m << endl;
|
||||
cout << "m.isOnes() returns: " << m.isOnes() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = Matrix3d::identity();
|
||||
Matrix3d m = Matrix3d::Identity();
|
||||
m(0,2) = 1e-4;
|
||||
cout << "Here's the matrix m:" << endl << m << endl;
|
||||
cout << "m.isUnitary() returns: " << m.isUnitary() << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = Matrix3d::zero();
|
||||
Matrix3d m = Matrix3d::Zero();
|
||||
m(0,2) = 1e-4;
|
||||
cout << "Here's the matrix m:" << endl << m << endl;
|
||||
cout << "m.isZero() returns: " << m.isZero() << endl;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Matrix3d m = Matrix3d::zero();
|
||||
Matrix3d m = Matrix3d::Zero();
|
||||
m.part<Eigen::Upper>().setOnes();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
Matrix3d n = Matrix3d::ones();
|
||||
Matrix3d n = Matrix3d::Ones();
|
||||
n.part<Eigen::Lower>() *= 2;
|
||||
cout << "Here is the matrix n:" << endl << n << endl;
|
||||
cout << "And now here is m.inverse()*n, taking advantage of the fact that"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix3i m = Matrix3i::random();
|
||||
Matrix3i m = Matrix3i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here is m.minor(1,1):" << endl << m.minor(1,1) << endl;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
cout << Matrix2d::ones() << endl;
|
||||
cout << 6 * RowVector4i::ones() << endl;
|
||||
cout << Matrix2d::Ones() << endl;
|
||||
cout << 6 * RowVector4i::Ones() << endl;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
cout << 6 * RowVectorXi::ones(4) << endl;
|
||||
cout << VectorXf::ones(2) << endl;
|
||||
cout << 6 * RowVectorXi::Ones(4) << endl;
|
||||
cout << VectorXf::Ones(2) << endl;
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << MatrixXi::ones(2,3) << endl;
|
||||
cout << MatrixXi::Ones(2,3) << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix3d m = Matrix3i::zero();
|
||||
Matrix3d m = Matrix3i::Zero();
|
||||
m.part<Eigen::StrictlyUpper>().setOnes();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "And let us now compute m*m.adjoint() in a very optimized way" << endl
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << 100 * Matrix2i::random() << endl;
|
||||
cout << 100 * Matrix2i::Random() << endl;
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << VectorXi::random(2) << endl;
|
||||
cout << VectorXi::Random(2) << endl;
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << MatrixXi::random(2,3) << endl;
|
||||
cout << MatrixXi::Random(2,3) << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix3d m = Matrix3d::identity();
|
||||
Matrix3d m = Matrix3d::Identity();
|
||||
m.row(1) = Vector3d(4,5,6);
|
||||
cout << m << endl;
|
||||
|
||||
@@ -3,7 +3,7 @@ m1 << 1, 2, 3,
|
||||
4, 5, 6,
|
||||
7, 8, 9;
|
||||
cout << m1 << endl << endl;
|
||||
Matrix3i m2 = Matrix3i::identity();
|
||||
Matrix3i m2 = Matrix3i::Identity();
|
||||
m2.block(0,0, 2,2) << 10, 11, 12, 13;
|
||||
cout << m2 << endl << endl;
|
||||
Vector2i v1;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix4i m = Matrix4i::zero();
|
||||
Matrix4i m = Matrix4i::Zero();
|
||||
m.block<3,3>(1,0).setIdentity();
|
||||
cout << m << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix4i m = Matrix4i::random();
|
||||
Matrix4i m = Matrix4i::Random();
|
||||
m.row(1).setOnes();
|
||||
cout << m << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix4i m = Matrix4i::zero();
|
||||
Matrix4i m = Matrix4i::Zero();
|
||||
m.col(1).setRandom();
|
||||
cout << m << endl;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Matrix4i m = Matrix4i::random();
|
||||
Matrix4i m = Matrix4i::Random();
|
||||
m.row(1).setZero();
|
||||
cout << m << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
RowVector4i v = RowVector4i::random();
|
||||
RowVector4i v = RowVector4i::Random();
|
||||
cout << "Here is the vector v:" << endl << v << endl;
|
||||
cout << "Here is v.start(2):" << endl << v.start(2) << endl;
|
||||
v.start(2).setZero();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
RowVector4i v = RowVector4i::random();
|
||||
RowVector4i v = RowVector4i::Random();
|
||||
cout << "Here is the vector v:" << endl << v << endl;
|
||||
cout << "Here is v.end(2):" << endl << v.end<2>() << endl;
|
||||
v.end<2>().setZero();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix4i m = Matrix4i::random();
|
||||
Matrix4i m = Matrix4i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here is the bottom-right 2x3 corner in m:" << endl
|
||||
<< m.corner<2,3>(Eigen::BottomRight) << endl;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
RowVector4i v = RowVector4i::random();
|
||||
RowVector4i v = RowVector4i::Random();
|
||||
cout << "Here is the vector v:" << endl << v << endl;
|
||||
cout << "Here is v.start(2):" << endl << v.start<2>() << endl;
|
||||
v.start<2>().setZero();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Matrix2i m = Matrix2i::random();
|
||||
Matrix2i m = Matrix2i::Random();
|
||||
cout << "Here is the matrix m:" << endl << m << endl;
|
||||
cout << "Here is the transpose of m:" << endl << m.transpose() << endl;
|
||||
cout << "Here is the coefficient (1,0) in the transpose of m:" << endl
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
cout << Matrix2d::zero() << endl;
|
||||
cout << RowVector4i::zero() << endl;
|
||||
cout << Matrix2d::Zero() << endl;
|
||||
cout << RowVector4i::Zero() << endl;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
cout << RowVectorXi::zero(4) << endl;
|
||||
cout << VectorXf::zero(2) << endl;
|
||||
cout << RowVectorXi::Zero(4) << endl;
|
||||
cout << VectorXf::Zero(2) << endl;
|
||||
|
||||
@@ -1 +1 @@
|
||||
cout << MatrixXi::zero(2,3) << endl;
|
||||
cout << MatrixXi::Zero(2,3) << endl;
|
||||
|
||||
Reference in New Issue
Block a user