官术网_书友最值得收藏!

Matrix storage

Now that you know that the matrix layout is going to be column matrices, the next question is how to store the actual matrix. Matrix storage is a confusing topic.

Since a matrix is stored in memory as a linear array, let's figure out what elements should be placed where. A row-major matrix is stored in memory one row at a time. A column-major matrix is stored one column at a time.

Since both row- and column-major matrices contain the same vectors, the final linear mapping ends up being the same, regardless of the major of the matrix. The following Figure 3.3 demonstrates this:

Figure 3.3: Matrix storage mapping to a linear array

Figure 3.3: Matrix storage mapping to a linear array

The matrix class you will be building is a column-major matrix with column storage; this means there will be a discrepancy between the physical memory layout of the matrix and the logical placement of its elements. It's easy to treat a matrix with a linear memory layout as a row matrix but remember that each of those rows is actually a column.

Important note

The typical mapping of a two-dimensional grid to linear storage is "row * numberOfColumns + column". This mapping won't work for storing a column-major matrix. When looking at a matrix, the element in column 2, row 3 should have a linear index of 7, but the previous mapping yields 14. Instead, to account for the column-major storage, the mapping formula is "column * numberOfRows + row".

Understanding how a matrix is stored in memory is important, it's going to affect how data is stored and how APIs can access that data. In the next section, you will start to implement a matrix structure.

主站蜘蛛池模板: 富宁县| 海安县| 哈尔滨市| 琼中| 和顺县| 东方市| 澳门| 航空| 二手房| 灵山县| 吉首市| 囊谦县| 普安县| 阿合奇县| 灵璧县| 保山市| 高唐县| 师宗县| 阿鲁科尔沁旗| 长丰县| 仙桃市| 普安县| 临夏县| 临西县| 青田县| 怀宁县| 阳春市| 彭州市| 双鸭山市| 漳浦县| 洪湖市| 涪陵区| 新丰县| 巫溪县| 明水县| 北京市| 兴海县| 巴中市| 禹州市| 冕宁县| 夹江县|