Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc. about linear from/to Cartesian indices #49343

Merged
merged 1 commit into from
Apr 13, 2023
Merged

Fix doc. about linear from/to Cartesian indices #49343

merged 1 commit into from
Apr 13, 2023

Conversation

emmt
Copy link
Contributor

@emmt emmt commented Apr 13, 2023

Since Julia (ordinary) arrays have 1-based indices and are in column-major order, the linear index k and the Cartesian index (i,j) of an element in a m×n Julia array are related by: k = i + m*(j - 1). The examples of conversion between linear and Cartesian indices in the doc. use incorrect formulae although the results were correct in the specific element at (1,3). This can be easily checked for other indices than (1,3) with a simple 2×3 array (as in the examples) built by A = reshape(collect(1:6),2,3).

Since Julia (ordinary) arrays have 1-based indices and are in column-major order, the linear index `k` and the Cartesian index `(i,j)` of an element in a `m×n` Julia array are related by: `k = i + m*(j - 1)`. The examples of conversion between linear and Cartesian indices in the doc. use incorrect formulae although the results were correct in the specific element at `(1,3)`. This can be easily checked for other indices than `(1,3)` with a simple `2×3` array (as in the examples) built by `A = reshape(collect(1:6),2,3)`.
@timholy timholy merged commit b987396 into JuliaLang:master Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants