问题标签 [column-major-order]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
609 浏览

c - 列主要顺序与行主要顺序的表示

考虑一个包含值的二维数组“数组”:{1,2,3,4,5,6,7,8,9}。我对这两个订单的理解的主要问题是,如果将 Row Major Order 表示为 Array[i,j] (而 i 是行,j 是列),

因此,如果您被问到诸如“在 Array[2][2] 中查找元素 Array[1,2] 的地址”之类的问题,您就会知道行数在列数之前,并且很容易将它们放入公式中:

这是否意味着列顺序可以表示为 Array[j,i] 这意味着列号出现在行号之前。因此无法知道 Array[j][i](例如 Array[3][4])的 i,j,Row_lowerbound 和 Col_lowerbound 值应放在公式中的什么位置。

例如,如果问题显示为:“在数组 Array[3][4] 中查找 Array[1][2] 的地址”您如何知道 3 是列数还是 4?你怎么知道'i'是3还是4?

0 投票
1 回答
145 浏览

matrix - fortran Do 循环索引问题以优化代码

首先我的英语不好。抱歉。

我所知道的。Fortran 地址是主要列。我的旧 Fortran 代码长时间没有优化。我尝试更改我的 Fortran90 代码索引以获得更好的速度。

代码几乎是 3 维矩阵。(i, j, k) 并且几乎 Do-loop 是关于 i 和 j 的。i 和 j 的大小约为 2000~3000 而 k 只是 2,这意味着 x,y

我旧代码的索引顺序是 (i, k, j)

例如

我的代码中有很多这样的东西。

所以我改变了索引顺序。例如 (i, j, k), (k, i, j), (i, k, j) 我认为 (k, i, j) 是 fortran (column major) 中的最佳选择。

但结果不是。

所有 3 个案例 [ (i, j, k), (k, i, j), (i, k, j) ] 都花费了几乎时间。(1961 年代、1955 年代、1692 年代)。

我的程序代码这么长,Iteration足以比较(32000)

下面是我的编译选项。

我不明白上面的结果。请帮我。

感谢阅读。

另外,以下是我的程序之一。矩阵 L_X(i, :, j) 是我的目标, : 是 1 和 2

0 投票
2 回答
169 浏览

python - 什么导致numpy中C与F有序数组沿轴的数组总和不同

我很好奇是否有人能解释究竟是什么导致了numpy. 请看下面的代码:

印刷:

0 投票
1 回答
264 浏览

python - How to keep major-order when copying or groupby-ing a pandas DataFrame?

How can I use or manipulate (monkey-patch) pandas in order, to keep always the same major-order on the resulting object for copy and groupby aggregations?

I use pandas.DataFrame as datastructure within a business application (risk model) and need fast aggregation of multidimensional data. Aggregation with pandas depends crucially on the major-ordering scheme in use on the underlying numpy array.

Unfortunatly, pandas (version 0.23.4) changes the major-order of the underlying numpy array when I create a copy or when I perform an aggregation with groupby and sum.

The impact is:

case 1: 17.2 seconds

case 2: 5 min 46 s seconds

on a DataFrame and its copy with 45023 rows and 100000 columns. Aggregation was performed on the index. The index is a pd.MultiIndex with 15 levels. Aggregation keeps three levels and leads to about 239 groups.

I work typically on DataFrames with 45000 rows and 100000 columns. On the row I have a pandas.MultiIndex with about 15 levels. To compute statistics on various hierarchy nodes I need to aggregate (sum) on the index dimension.

Aggregation is fast, if the underlying numpy array is c_contiguous, hence held in column-major-order (C order). It is very slow if it is f_contiguous, hence in row-major-order (F order).

Unfortunatly, pandas changes the the major-order from C to F when

  • creating a copy of a DataFrame and even when,

  • performing an aggregation via a grouby and and taking the sum on the grouper. Hence the resulting DataFrame has a differnt major-order (!)

Sure, I could stick to another 'datamodel', just by keeping the MultiIndex on the columns. Then the current pandas version would always work to my favor. But this is a no go. I think, that one can expect, that for the two operations under consideration (groupby-sum and copy) the major-order should not be changed.

The major order of the data should be preserved. If pandas likes to switch to an implicit preference, then it should allow to overwrite this. Numpy allows to input the order when creating a copy.

A patched version of pandas should result in

for the example code snipped above.

0 投票
1 回答
28 浏览

python - Numpy.array 从图像创建列主矩阵

我正在尝试在 python 中打开一个具有 960(宽度)x 640(高度)像素的图像作为矩阵。

出于某种原因,在运行以下行之后:

originalImageMatrix是大小(640, 960, 3),我必须通过在行坐标之前提供列坐标来访问它的元素

如果我尝试执行以下操作:originalImageMatrix[959][1][1]我收到以下错误:

你知道我错过了什么吗?

0 投票
1 回答
88 浏览

performance - 如何确定内存组织是否遵循行主要顺序或列主要顺序?

如何确定内存组织是否遵循行优先顺序或列优先顺序?我学习了这个新概念并且知道如果我们知道什么内存组织遵循行优先顺序或列优先顺序,我们可以使我们的数组以这样一种方式运行,即通过减少代码的数量来提高性能页面错误。但我无法找到“如何确定内存组织是否遵循行优先顺序或列优先顺序?”。

0 投票
0 回答
71 浏览

fortran - 有没有一种简单的方法来重构或编译用于行主要存储的 Fortran 代码?

我有一些非常古老的遗留 Fortran 代码,我正在尝试加速它们。一个主要的性能问题是,它使用了非常多、非常大的 3-D 数组,存储为 (Y,Z,X) 并且各个 (Z,X) 层必须通过网络进行通信。

这需要我在发送之前遍历数组并缓冲它们,因为 Fortran 使用列主要格式。有没有一种简单的方法,比如编译器标志或重构工具,让我的 (Z,X) 层位于连续内存中或将 Fortran 交换为行优先数组顺序?