operate on row-compressed format from igraph_sparsemat_t












2















Is it possible to build an igraph_sparsemat_t from an already available matrix stored in row-compressed (CSR) format and not set every value with igraph_sparsemat_entry()?



Also can I extract the CSR structure from an igraph_sparsemat_t so that I can use the CSR-matrix with other libraries?



I know that conversion from igraph_sparsemat_t to igraph is possible, but I don't know what I could do from there on.










share|improve this question

























  • I am not sure what you want to do ? Copy it, add new members or ? If not time and memory is a problem, then convert to normal matrix and use all the igraph_matrix_ functions.

    – split
    Nov 22 '18 at 1:43











  • @split That pretty much defeats the purpose of ever using any sparse matrix data structure. What OP is asking is not even to have to convert the CSC representation into a list of (i,j) -> value index/value pairs (which would be the simple way to convert this to another sparse library's format).

    – Szabolcs
    Nov 22 '18 at 9:56
















2















Is it possible to build an igraph_sparsemat_t from an already available matrix stored in row-compressed (CSR) format and not set every value with igraph_sparsemat_entry()?



Also can I extract the CSR structure from an igraph_sparsemat_t so that I can use the CSR-matrix with other libraries?



I know that conversion from igraph_sparsemat_t to igraph is possible, but I don't know what I could do from there on.










share|improve this question

























  • I am not sure what you want to do ? Copy it, add new members or ? If not time and memory is a problem, then convert to normal matrix and use all the igraph_matrix_ functions.

    – split
    Nov 22 '18 at 1:43











  • @split That pretty much defeats the purpose of ever using any sparse matrix data structure. What OP is asking is not even to have to convert the CSC representation into a list of (i,j) -> value index/value pairs (which would be the simple way to convert this to another sparse library's format).

    – Szabolcs
    Nov 22 '18 at 9:56














2












2








2








Is it possible to build an igraph_sparsemat_t from an already available matrix stored in row-compressed (CSR) format and not set every value with igraph_sparsemat_entry()?



Also can I extract the CSR structure from an igraph_sparsemat_t so that I can use the CSR-matrix with other libraries?



I know that conversion from igraph_sparsemat_t to igraph is possible, but I don't know what I could do from there on.










share|improve this question
















Is it possible to build an igraph_sparsemat_t from an already available matrix stored in row-compressed (CSR) format and not set every value with igraph_sparsemat_entry()?



Also can I extract the CSR structure from an igraph_sparsemat_t so that I can use the CSR-matrix with other libraries?



I know that conversion from igraph_sparsemat_t to igraph is possible, but I don't know what I could do from there on.







c igraph






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 5:24







ps3lister

















asked Nov 22 '18 at 1:00









ps3listerps3lister

135




135













  • I am not sure what you want to do ? Copy it, add new members or ? If not time and memory is a problem, then convert to normal matrix and use all the igraph_matrix_ functions.

    – split
    Nov 22 '18 at 1:43











  • @split That pretty much defeats the purpose of ever using any sparse matrix data structure. What OP is asking is not even to have to convert the CSC representation into a list of (i,j) -> value index/value pairs (which would be the simple way to convert this to another sparse library's format).

    – Szabolcs
    Nov 22 '18 at 9:56



















  • I am not sure what you want to do ? Copy it, add new members or ? If not time and memory is a problem, then convert to normal matrix and use all the igraph_matrix_ functions.

    – split
    Nov 22 '18 at 1:43











  • @split That pretty much defeats the purpose of ever using any sparse matrix data structure. What OP is asking is not even to have to convert the CSC representation into a list of (i,j) -> value index/value pairs (which would be the simple way to convert this to another sparse library's format).

    – Szabolcs
    Nov 22 '18 at 9:56

















I am not sure what you want to do ? Copy it, add new members or ? If not time and memory is a problem, then convert to normal matrix and use all the igraph_matrix_ functions.

– split
Nov 22 '18 at 1:43





I am not sure what you want to do ? Copy it, add new members or ? If not time and memory is a problem, then convert to normal matrix and use all the igraph_matrix_ functions.

– split
Nov 22 '18 at 1:43













@split That pretty much defeats the purpose of ever using any sparse matrix data structure. What OP is asking is not even to have to convert the CSC representation into a list of (i,j) -> value index/value pairs (which would be the simple way to convert this to another sparse library's format).

– Szabolcs
Nov 22 '18 at 9:56





@split That pretty much defeats the purpose of ever using any sparse matrix data structure. What OP is asking is not even to have to convert the CSC representation into a list of (i,j) -> value index/value pairs (which would be the simple way to convert this to another sparse library's format).

– Szabolcs
Nov 22 '18 at 9:56












1 Answer
1






active

oldest

votes


















0














The igraph documentation mentions that igraph_sparsemat_t is a thin wrapper for the CXSparse library's datatype. The documentation for that library is essentially this book:




  • Timothy A. Davis: Direct Methods for Sparse Linear Systems


But you don't really need the book to solve this. You can dig a bit in the source and find igraph_sparsemat_t just contains a cs_di_sparse, which is



typedef struct cs_di_sparse  /* matrix in compressed-column or triplet form */
{
int nzmax ; /* maximum number of entries */
int m ; /* number of rows */
int n ; /* number of columns */
int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
int *i ; /* row indices, size nzmax */
double *x ; /* numerical values, size nzmax */
int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
} cs_di ;


You can build or read this directly.



The igraph documentation mentions that this may contain either a CSC representation of a triplet matrix. Pay attention to this (see comment on the last entry).



Do look at the memory allocation/deallocation functions in cs.h (cs_di_malloc/cs_di_free/etc.) and use them instead of you standard malloc/free, to ensure that a compatible free is used on memory allocated with a certain malloc.



Note that the MATLAB interface of CSparse (take a look at the sources I linked above) also uses this approach: it manipulates the struct directly.



Finally, do pay attention that igraph interprets this matrix as CSC, not CSR. If you convert to another library's data structure, you might need to transpose. If you do that, you would need to convert to (index, value) pairs anyway.






share|improve this answer


























  • Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

    – ps3lister
    Nov 22 '18 at 10:57











  • I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

    – ps3lister
    Nov 22 '18 at 12:17











  • @ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

    – Szabolcs
    Nov 22 '18 at 12:28











  • @ps3lister Out of curiosity, what other library are you adapting this to?

    – Szabolcs
    Nov 22 '18 at 12:28











  • Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

    – ps3lister
    Nov 22 '18 at 14:17











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422514%2foperate-on-row-compressed-format-from-igraph-sparsemat-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The igraph documentation mentions that igraph_sparsemat_t is a thin wrapper for the CXSparse library's datatype. The documentation for that library is essentially this book:




  • Timothy A. Davis: Direct Methods for Sparse Linear Systems


But you don't really need the book to solve this. You can dig a bit in the source and find igraph_sparsemat_t just contains a cs_di_sparse, which is



typedef struct cs_di_sparse  /* matrix in compressed-column or triplet form */
{
int nzmax ; /* maximum number of entries */
int m ; /* number of rows */
int n ; /* number of columns */
int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
int *i ; /* row indices, size nzmax */
double *x ; /* numerical values, size nzmax */
int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
} cs_di ;


You can build or read this directly.



The igraph documentation mentions that this may contain either a CSC representation of a triplet matrix. Pay attention to this (see comment on the last entry).



Do look at the memory allocation/deallocation functions in cs.h (cs_di_malloc/cs_di_free/etc.) and use them instead of you standard malloc/free, to ensure that a compatible free is used on memory allocated with a certain malloc.



Note that the MATLAB interface of CSparse (take a look at the sources I linked above) also uses this approach: it manipulates the struct directly.



Finally, do pay attention that igraph interprets this matrix as CSC, not CSR. If you convert to another library's data structure, you might need to transpose. If you do that, you would need to convert to (index, value) pairs anyway.






share|improve this answer


























  • Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

    – ps3lister
    Nov 22 '18 at 10:57











  • I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

    – ps3lister
    Nov 22 '18 at 12:17











  • @ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

    – Szabolcs
    Nov 22 '18 at 12:28











  • @ps3lister Out of curiosity, what other library are you adapting this to?

    – Szabolcs
    Nov 22 '18 at 12:28











  • Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

    – ps3lister
    Nov 22 '18 at 14:17
















0














The igraph documentation mentions that igraph_sparsemat_t is a thin wrapper for the CXSparse library's datatype. The documentation for that library is essentially this book:




  • Timothy A. Davis: Direct Methods for Sparse Linear Systems


But you don't really need the book to solve this. You can dig a bit in the source and find igraph_sparsemat_t just contains a cs_di_sparse, which is



typedef struct cs_di_sparse  /* matrix in compressed-column or triplet form */
{
int nzmax ; /* maximum number of entries */
int m ; /* number of rows */
int n ; /* number of columns */
int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
int *i ; /* row indices, size nzmax */
double *x ; /* numerical values, size nzmax */
int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
} cs_di ;


You can build or read this directly.



The igraph documentation mentions that this may contain either a CSC representation of a triplet matrix. Pay attention to this (see comment on the last entry).



Do look at the memory allocation/deallocation functions in cs.h (cs_di_malloc/cs_di_free/etc.) and use them instead of you standard malloc/free, to ensure that a compatible free is used on memory allocated with a certain malloc.



Note that the MATLAB interface of CSparse (take a look at the sources I linked above) also uses this approach: it manipulates the struct directly.



Finally, do pay attention that igraph interprets this matrix as CSC, not CSR. If you convert to another library's data structure, you might need to transpose. If you do that, you would need to convert to (index, value) pairs anyway.






share|improve this answer


























  • Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

    – ps3lister
    Nov 22 '18 at 10:57











  • I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

    – ps3lister
    Nov 22 '18 at 12:17











  • @ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

    – Szabolcs
    Nov 22 '18 at 12:28











  • @ps3lister Out of curiosity, what other library are you adapting this to?

    – Szabolcs
    Nov 22 '18 at 12:28











  • Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

    – ps3lister
    Nov 22 '18 at 14:17














0












0








0







The igraph documentation mentions that igraph_sparsemat_t is a thin wrapper for the CXSparse library's datatype. The documentation for that library is essentially this book:




  • Timothy A. Davis: Direct Methods for Sparse Linear Systems


But you don't really need the book to solve this. You can dig a bit in the source and find igraph_sparsemat_t just contains a cs_di_sparse, which is



typedef struct cs_di_sparse  /* matrix in compressed-column or triplet form */
{
int nzmax ; /* maximum number of entries */
int m ; /* number of rows */
int n ; /* number of columns */
int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
int *i ; /* row indices, size nzmax */
double *x ; /* numerical values, size nzmax */
int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
} cs_di ;


You can build or read this directly.



The igraph documentation mentions that this may contain either a CSC representation of a triplet matrix. Pay attention to this (see comment on the last entry).



Do look at the memory allocation/deallocation functions in cs.h (cs_di_malloc/cs_di_free/etc.) and use them instead of you standard malloc/free, to ensure that a compatible free is used on memory allocated with a certain malloc.



Note that the MATLAB interface of CSparse (take a look at the sources I linked above) also uses this approach: it manipulates the struct directly.



Finally, do pay attention that igraph interprets this matrix as CSC, not CSR. If you convert to another library's data structure, you might need to transpose. If you do that, you would need to convert to (index, value) pairs anyway.






share|improve this answer















The igraph documentation mentions that igraph_sparsemat_t is a thin wrapper for the CXSparse library's datatype. The documentation for that library is essentially this book:




  • Timothy A. Davis: Direct Methods for Sparse Linear Systems


But you don't really need the book to solve this. You can dig a bit in the source and find igraph_sparsemat_t just contains a cs_di_sparse, which is



typedef struct cs_di_sparse  /* matrix in compressed-column or triplet form */
{
int nzmax ; /* maximum number of entries */
int m ; /* number of rows */
int n ; /* number of columns */
int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
int *i ; /* row indices, size nzmax */
double *x ; /* numerical values, size nzmax */
int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
} cs_di ;


You can build or read this directly.



The igraph documentation mentions that this may contain either a CSC representation of a triplet matrix. Pay attention to this (see comment on the last entry).



Do look at the memory allocation/deallocation functions in cs.h (cs_di_malloc/cs_di_free/etc.) and use them instead of you standard malloc/free, to ensure that a compatible free is used on memory allocated with a certain malloc.



Note that the MATLAB interface of CSparse (take a look at the sources I linked above) also uses this approach: it manipulates the struct directly.



Finally, do pay attention that igraph interprets this matrix as CSC, not CSR. If you convert to another library's data structure, you might need to transpose. If you do that, you would need to convert to (index, value) pairs anyway.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 9:54

























answered Nov 22 '18 at 8:41









SzabolcsSzabolcs

16.1k361143




16.1k361143













  • Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

    – ps3lister
    Nov 22 '18 at 10:57











  • I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

    – ps3lister
    Nov 22 '18 at 12:17











  • @ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

    – Szabolcs
    Nov 22 '18 at 12:28











  • @ps3lister Out of curiosity, what other library are you adapting this to?

    – Szabolcs
    Nov 22 '18 at 12:28











  • Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

    – ps3lister
    Nov 22 '18 at 14:17



















  • Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

    – ps3lister
    Nov 22 '18 at 10:57











  • I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

    – ps3lister
    Nov 22 '18 at 12:17











  • @ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

    – Szabolcs
    Nov 22 '18 at 12:28











  • @ps3lister Out of curiosity, what other library are you adapting this to?

    – Szabolcs
    Nov 22 '18 at 12:28











  • Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

    – ps3lister
    Nov 22 '18 at 14:17

















Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

– ps3lister
Nov 22 '18 at 10:57





Great help! Also thanks for pointing out the cs_di_malloc. I wrote 'column-compressed' and abreviated with 'CSR', guess it was a little late yesterday..

– ps3lister
Nov 22 '18 at 10:57













I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

– ps3lister
Nov 22 '18 at 12:17





I recognized cs uses 32 bit integers, but I need 64 indices for very large matrices.

– ps3lister
Nov 22 '18 at 12:17













@ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

– Szabolcs
Nov 22 '18 at 12:28





@ps3lister This is something you should take up with the igraph developers. I do notice that in the latest version of CSparse the index type is adaptable, so it should be possible to do the same for CXSparse, and eventually for the igraph version of the same. However, since in igraph the main purpose of this type is to store adjacency matrices, this would make sense if igraph graphs can also store more than 2^31-1 nodes. I do not know if this is the case.

– Szabolcs
Nov 22 '18 at 12:28













@ps3lister Out of curiosity, what other library are you adapting this to?

– Szabolcs
Nov 22 '18 at 12:28





@ps3lister Out of curiosity, what other library are you adapting this to?

– Szabolcs
Nov 22 '18 at 12:28













Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

– ps3lister
Nov 22 '18 at 14:17





Thanks for the advice. I'm also using Intel MKL and metis for partitioning.

– ps3lister
Nov 22 '18 at 14:17




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422514%2foperate-on-row-compressed-format-from-igraph-sparsemat-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()