Skip to content

Memory layout of arrays #198

@wkearn

Description

@wkearn

numpy arrays can have either row- or column-major layouts. We currently handle these layouts inconsistently, and this is an ongoing source of confusion.

Here is how things should behave:

  • libtopotoolbox functions should be agnostic to the memory layout of their arguments.
  • libtopotoolbox functions should iterate in "column-major" order. Really this means iterating over the fastest-changing dimension first, and otherwise the dimensions shouldn't matter too much. You do have to swap the order of the dimensions if you pass a row-major array.
  • dem.shape should return (rows, columns) for every array, regardless of its memory order, just as numpy arrays.
  • dem.dims should return (rows, columns) for column-major ('F') arrays and (columns, rows) for row-major ('C') arrays.
  • pytopotoolbox should pass dem.dims rather than dem.shape to libtopotoolbox.
  • StreamObject and FlowObject refer to their nodes with 0-based linear indices in column-major order.

The one major exception here is for graphflood, because I don't think we were very careful about matching it to the other libtopotoolbox functions. Correct me if I am wrong, @bgailleton, but I think it works kind of the same way as the other libtopotoolbox functions, but the dim arguments are reversed relative to the libtopotoolbox -- (rows, columns) for row-major and (columns, rows) for column-major.

I am noticing that the addition of the dims argument did not propagate to every libtopotoolbox function in pytopotoolbox.

I have added subissues for tasks that we need to fix these problems.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions