plonky2 icon indicating copy to clipboard operation
plonky2 copied to clipboard

Matrix type

Open nbgl opened this issue 3 years ago • 2 comments

A proposal for a simple matrix type that supports the following operations:

  • Construction in a few ways
    • From iterator of iterators
    • From flat vector
    • Using closure that initializes a matrix of MaybeUninit
  • Indexing by row (each row is a slice)
  • Mutable and non-mutable iteration (the iterators yield slices, one per row)
  • Transposition
  • Cloning

nbgl avatar Jan 27 '22 01:01 nbgl

A Box will also store the length of the buffer, which is redundant information since the matrix already stores a height and a width (although you're right that it's less redundant than a Vec).

This code does already use Box for allocation and deallocation, it just stores it in a decomposed format. Like, to allocate a Matrix, we get a Box (somehow) and then extract the pointer to the first element, which we then store. In drop, we construct a Box from the pointer and the buffer size (computed from height and width), which takes care of deallocation.

I'm happy to just store a Box if that's your strong preference, but it would mean redundant information, and all the possible inconsistencies/bugs that come with it.

nbgl avatar Apr 01 '22 16:04 nbgl

This is really cool, I expect it to be a big improvement over Vec<Vec<_>>. Contiguous memory FTW! 🚀

recmo avatar Apr 08 '22 21:04 recmo

Hello!

This PR has been open for a long time, please review and update as following:

  1. If this PR is no l longer relevant, close it.
  2. If this PR is relevant but not read, mark it as Draft and make a comment of what else needs to be done.
  3. Fix any issues and get it merged / reviewed by 10/27/2023.

If there's no update by 10/27/2023 this PR will be closed.

pgebheim avatar Oct 23 '23 17:10 pgebheim

Let's close this since it's a central aspect of Plonky3, and doesn't seem worthwhile to rework a bunch of Plonky2 code also to work with matrices.

dlubarov avatar Oct 23 '23 18:10 dlubarov