• Using block operations

    • rvalue, i.e. it was only read from
    • lvalues, i.e. you can assign to a block
  • Columns and rows
  • Corner-related operations
  • Block operations for vectors

  • Using block operations
Block operation Version constructing a 
dynamic-size block expression 
Version constructing a 
fixed-size block expression 
Block of size (p,q), starting at (i,j)
matrix.block(i,j,p,q);
matrix.block<p,q>(i,j);
 
    • rvalue, i.e. it was only read from
int main()
{
m << 1, 2, 3, 4,
5, 6, 7, 8,
9,10,11,12,
13,14,15,16;
cout << "Block in the middle" << endl;
cout << m.block<2,2>(1,1) << endl << endl;
for (int i = 1; i <= 3; ++i)
{
cout << "Block of size " << i << "x" << i << endl;
cout << m.block(0,0,i,i) << endl << endl;
}
}
 
 
Block in the middle
 6  7
10 11

Block of size 1x1
1

Block of size 2x2
1 2
5 6

Block of size 3x3
 1  2  3
 5  6  7
 9 10 11

    • lvalues, i.e. you can assign to a block
int main()
{
Array22f m;
m << 1,2,3,4;
Array44f a = Array44f::Constant(0.6);
cout << "Here is the array a:" << endl << a << endl << endl;
a.block<2,2>(1,1) = m;
cout << "Here is now a with m copied into its central 2x2 block:" << endl << a << endl << endl;
a.block(0,0,2,3) = a.block(2,1,2,3);
cout << "Here is now a with bottom-right 2x3 block copied into top-left 2x2 block:" << endl << a << endl << endl;
     }
Here is the array a:
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6

Here is now a with m copied into its central 2x2 block:
0.6 0.6 0.6 0.6
0.6   1   2 0.6
0.6   3   4 0.6
0.6 0.6 0.6 0.6

Here is now a with bottom-right 2x3 block copied into top-left 2x2 block:
  3   4 0.6 0.6
0.6 0.6 0.6 0.6
0.6   3   4 0.6
0.6 0.6 0.6 0.6

 
  • Columns and rows
Block operation  Method 
ith row *
matrix.row(i);
jth column *
matrix.col(j);
int main()
{
m << 1,2,3,
4,5,6,
7,8,9;
cout << "Here is the matrix m:" << endl << m << endl;
cout << "2nd Row: " << m.row(1) << endl;
m.col(2) += 3 * m.col(0);
cout << "After adding 3 times the first column into the third column, the matrix m is:\n";
cout << m << endl;
}

1 2 3
4 5 6
7 8 9
2nd Row: 4 5 6
After adding 3 times the first column into the third column, the matrix m is:
 1  2  6
 4  5 18
 7  8 30
 
  • Corner-related operations
Block operation Version constructing a 
dynamic-size block expression 
Version constructing a 
fixed-size block expression 
Top-left p by q block *
matrix.topLeftCorner(p,q);
matrix.topLeftCorner<p,q>();
Bottom-left p by q block *
matrix.bottomLeftCorner(p,q);
matrix.bottomLeftCorner<p,q>();
Top-right p by q block *
matrix.topRightCorner(p,q);
matrix.topRightCorner<p,q>();
Bottom-right p by q block *
matrix.bottomRightCorner(p,q);
matrix.bottomRightCorner<p,q>();
Block containing the first q rows *
matrix.topRows(q);
matrix.topRows<q>();
Block containing the last q rows *
matrix.bottomRows(q);
matrix.bottomRows<q>();
Block containing the first p columns *
matrix.leftCols(p);
matrix.leftCols<p>();
Block containing the last q columns *
matrix.rightCols(q);
matrix.rightCols<q>();
int main()
{
m << 1, 2, 3, 4,
5, 6, 7, 8,
9, 10,11,12,
13,14,15,16;
cout << "m.leftCols(2) =" << endl << m.leftCols(2) << endl << endl;
cout << "m.bottomRows<2>() =" << endl << m.bottomRows<2>() << endl << endl;
m.topLeftCorner(1,3) = m.bottomRightCorner(3,1).transpose();
cout << "After assignment, m = " << endl << m << endl;
}

m.leftCols(2) =
 1  2
 5  6
 9 10
13 14

m.bottomRows<2>() =
 9 10 11 12
13 14 15 16

After assignment, m = 
 8 12 16  4
 5  6  7  820:37:13
 9 10 11 12
13 14 15 16

 
  • Block operations for vectors
Block operation  Version constructing a 
dynamic-size block expression 
Version constructing a 
fixed-size block expression 
Block containing the first n elements *
vector.head(n);
vector.head<n>();
Block containing the last n elements *
vector.tail(n);
vector.tail<n>();
Block containing n elements, starting at position i *
vector.segment(i,n);
vector.segment<n>(i);
int main()
{
Eigen::ArrayXf v(6);
v << 1, 2, 3, 4, 5, 6;
cout << "v.head(3) =" << endl << v.head(3) << endl << endl;
cout << "v.tail<3>() = " << endl << v.tail<3>() << endl << endl;
v.segment(1,4) *= 2;
cout << "after 'v.segment(1,4) *= 2', v =" << endl << v << endl;
     }
v.head(3) =
1
2
3

v.tail<3>() = 
4
5
6

after 'v.segment(1,4) *= 2', v =
 1
 4
 6
 8
10
 6

 
 
 
 
 
 
 
 
 
 

C++_Eigen函数库用法笔记——Block Operations的更多相关文章

  1. C++_Eigen函数库用法笔记——The Array class and Coefficient-wise operations

    The advantages of Array Addition and subtraction Array multiplication abs() & sqrt() Converting ...

  2. C++_Eigen函数库用法笔记——Advanced Initialization

    The comma initializer a simple example  join and block initialize  join two row vectors together ini ...

  3. C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic

    Addition and subtraction Scalar multiplication and division Transposition Matrix-matrix and matrix-v ...

  4. PHP中正则替换函数preg_replace用法笔记

    今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. 转: ES6异步编程: co函数库的含义与用法

    转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Ge ...

  7. makefile笔记10 - makefile 函数库文件

    函数库文件也就是对 Object 文件(程序编译的中间文件)的打包文件.在 Unix 下,一般是由命令"ar"来完成打包工作. 一.函数库文件的成员 一个函数库文件由多个文件组成. ...

  8. OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法

    函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...

  9. python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法

    python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...

随机推荐

  1. 去他的效应(what-the-hell effect)与自我放纵

    去他的 效应(what-the-hell effect)与自我放纵 为什么写这篇文章: 对于我来说,但我感到疲惫——"无意拿起"手机,对自己说"随便看看"——但 ...

  2. android背景选择器selector用法汇总

    一.创建xml文件,位置:drawable/xxx.xml,同目录下记得要放相关图片 <?xml version="1.0" encoding="utf-8&quo ...

  3. LINUX第五次实验报告

    北京电子科技学院(BESTI) 实     验    报     告 课程:信息安全系统设计基础                     班级: 201353 姓名:刘世鹏 郝爽 学号:2013530 ...

  4. GDB深入研究

    GDB深入研究 一.GDB代码调试 (一)GDB调试实例 在终端中编译一个示例C语言小程序,保存到文件 gdb-sample.c 中,用GCC编译之 #include <stdio.h> ...

  5. css平时写的时候注意的

    1.如果用absolute的时候一定要注意,bottom如果为)的话,一定要注意上一级的relative是否有height. 2.chrome浏览器,我们需要注意的是width包含了padding,但 ...

  6. Javascript基础系列之(三)数据类型 (数值 Number)

    javascript中想限定一个数的数值,无需限定它是整数还是浮点数型 var num1 = 80 ; var num2 = 55.51; var num3 = -34; var num4 = 9e5 ...

  7. 每天一个linux命令(23): chown命令

    chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...

  8. .net架构设计读书笔记--第二章 第7节 神化般的业务层

    一.编排业务逻辑的模式1. 事务脚本模式TS(The Transaction Script pattern ) TS模式概述     TS 鼓励你跳过任何的面向对象的设计,你直接到所需的用户操作的业务 ...

  9. POJ 2153 stl

    #include<iostream> #include<map> #include<string> using namespace std; int main() ...

  10. 将定时任务cron 解析成中文

    在使用定时器 quartz 时,其中的cron 表达式,老板表示作为开发的你能看懂外,其他的非开发同事可能看不懂,要用一个他们能看懂的方式表达出来. 还好我们的项目要求的表达式不是特别的麻烦,所以就写 ...