wo80 / CSparse.NET

A concise library for solving sparse linear systems with direct methods.
GNU Lesser General Public License v2.1
58 stars 25 forks source link

Can I slice a CSC sparse matrix? #36

Closed AlbertLiDesign closed 2 years ago

AlbertLiDesign commented 2 years ago

Hello,

I'm writing a Finite element framework. And I need to remove several rows and columns from a CSC sparse matrix A. In Matlab, I can use slicing operations like A([2, 3, 4], [6, 7, 8]) to select several rows and columns for computing. How can I implement this using CSparse?

Or can I access a value from the CSC sparse matrix by inputting (i, j)?

Cheers

epsi1on commented 2 years ago

Hi, Not sure if directly possible to slice a sparse matrix, but an option would be to use permutation matrix to slice it. Check this stackoverflow.com question which is probably near to what you need: StackOverflow.com: Solving a linear system of equations

AlbertLiDesign commented 2 years ago

Hi, Not sure if directly possible to slice a sparse matrix, but an option would be to use permutation matrix to slice it. Check this stackoverflow.com question which is probably near to what you need: StackOverflow.com: Solving a linear system of equations

Hi,

This is a good idea. I expect CSparse to implement this feature.

Have a nice day!

wo80 commented 2 years ago

I've added a simple row/column extraction method to the csparse-extensions project: CompressedColumnStorageExtensions.cs#L74-L82

See the tests for usage: CompressedColumnStorageTests.cs#L54-L74

AlbertLiDesign commented 2 years ago

I've added a simple row/column extraction method to the csparse-extensions project: CompressedColumnStorageExtensions.cs#L74-L82

See the tests for usage: CompressedColumnStorageTests.cs#L54-L74

Thank you for your amazing work!