dimforge / dimforge/nalgebra

Flattening/unflattening vectors/matrices

Open
#596 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

I find myself repeatedly needing to convert between e.g. `Vec>` and `DVector`, where the latter is basically a concatenated form of the former.

When working with e.g. Finite Element code that deal with vector-valued functions, such as displacement-based FEM formulations, these kind of operations are quite common. Typically, one might have mesh vertices represented in terms of e.g. `Vec>`, but the linear solver works with a single, long vector.

@sebcrozet kindly pointed out to me on Discord that one solution is something along the lines of

```rust
vectors.iter().flat_map(|v| v).cloned().collect::>()
```

However, we might discuss if this use case is frequent enough to warrant built-in functionality. And I suppose in that case it should be more general than just flattening a list of vectors into a single vector; we probably want to have a consistent way of handling matrices as well. As an example, consider `Vec>`, and turning this into either a single long vector or a `3x(3N)` matrix or a `(3N)x3` matrix. This ambiguity suggests that we would need e.g. multiple functions for flattening, depending on the axis the user wants to flatten along.

At the moment, I don't have a concrete proposal for how best to solve this in a suitably practical, yet generally applicable way, but I wanted to at least explain my specific use case. I would be happy to contribute such a feature, however I would also be happy to get some feedback first, if anyone has some input.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.