daphne-project/daphne

Slicing column segments out of CSRMatrix

Open

#219 opened on Mar 11, 2022

 (1 comment) (0 reactions) (0 assignees)C++ (84 forks)auto 404
good first issue

Repository metrics

Stars
 (80 stars)
PR merge metrics
 (PR metrics pending)

Description

In GitLab by @pdamme on Mar 11, 2022, 13:11

DAPHNE data types need to support extracting rectangular fragments out of them. This is required at several points, e.g.

  • in the vectorized engine, where we split the input into segments for multi-threaded and cache-conscious processing
  • for so-called right indexing in DaphneDSL, where a user might want to extract a certain part out of a data object (for instance, x[100:200, 3:5]; extracts rows 100 to 199 of columns 3 to 4 from x)

For that reason, Structure, the superclass of all DAPHNE data types, defines the following slicing methods:

  • sliceRow(rl, ru) -> extracts a row segment (all columns, but only a segment of the rows)
  • sliceCol(cl, cu) -> extracts a column segment (all rows, but only a segment of the columns)
  • slice(rl, ru, cl, cu) -> extracts the intersection of a row and a column segment

We already have implementations for DenseMatrix and Frame, but CSRMatrix supports only sliceRow so far.

The Task:

  1. Implement CSRMatrix::sliceCol().
  2. Optionally implement CSRMatrix::slice().

Hints:

  • In contrast to the existing slice/sliceRow/sliceCol implementations, sliceCol on CSRMatrix is no zero-copy operation, in the general case. Thus, you need to create a fresh CSRMatrix.
  • A possible approach could be as follows: For each row: find the range of colIdx-value pairs which are within the bounds of the column segment to extract (note that column indexes are sorted within each row), and copy those over to the output CSRMatrix.
  • Optionally, you may also implement the general slice on CSRMatrix, that should be straightforward once you've implemented sliceCol.

Contributor guide