Alfredo, thanks for reporting this, the issue was related to the
duplicate input argument (C). It should now be fixed on the git
repository, can you check out the latest git and retest?
Thanks,
Patrick
On 09/07/2017 09:39 AM, Alfredo Correa wrote:
> Follow-up Comment #2, bug #51951 (project gsl):
>
> Hi Patrick, sorry, for some reason the code posted removed the '*' symbols. (I
> am also attaching the file this time)
>
> This should compile with `gcc sparse.c -Wfatal-errors -lgsl -lgslcblas -lm`
>
> ```
> #include <stdio.h>
> #include <stdlib.h>
>
> #include <gsl/gsl_spmatrix.h>
>
> int main(){
>
> gsl_spmatrix* A = gsl_spmatrix_alloc(5, 4); /* triplet format */
> gsl_spmatrix* B, *C, *D;
> size_t i, j;
>
> /* build the sparse matrix */
> gsl_spmatrix_set(A, 0, 2, 3.1);
> gsl_spmatrix_set(A, 0, 3, 4.6);
> gsl_spmatrix_set(A, 1, 0, 1.0);
> gsl_spmatrix_set(A, 1, 2, 7.2);
> gsl_spmatrix_set(A, 3, 0, 2.1);
> gsl_spmatrix_set(A, 3, 1, 2.9);
> gsl_spmatrix_set(A, 3, 3, 8.5);
> gsl_spmatrix_set(A, 4, 0, 4.1);
>
> printf("printing all matrix elements:\n");
> for (i = 0; i < 5; ++i)
> for (j = 0; j < 4; ++j)
> printf("A(%zu,%zu) = %g\n", i, j,
> gsl_spmatrix_get(A, i, j));
>
> /* print out elements in triplet format */
> printf("matrix in triplet format (i,j,Aij):\n");
> gsl_spmatrix_fprintf(stdout, A, "%.1f");
>
> /* convert to compressed row format */
> C = gsl_spmatrix_crs(A);
> D = gsl_spmatrix_crs(A);
>
> gsl_spmatrix_add(D, C, C);
>
> printf("matrix in compressed row format:\n");
> printf("i = [ ");
> for (i = 0; i < C->nz; ++i)
> printf("%zu, ", C->i[i]);
> printf("]\n");
>
> printf("p = [ ");
> for (i = 0; i < C->size1 + 1; ++i)
> printf("%zu, ", C->p[i]);
> printf("]\n");
>
> printf("d = [ ");
> for (i = 0; i < C->nz; ++i)
> printf("%g, ", C->data[i]);
> printf("]\n");
>
> printf("D matrix in compressed row format:\n");
> printf("i = [ ");
> for (i = 0; i < D->nz; ++i)
> printf("%zu, ", D->i[i]);
> printf("]\n");
>
> printf("p = [ ");
> for (i = 0; i < D->size1 + 1; ++i)
> printf("%zu, ", D->p[i]);
> printf("]\n");
>
> printf("d = [ ");
> for (i = 0; i < D->nz; ++i)
> printf("%g, ", D->data[i]);
> printf("]\n");
>
> printf("end");
> gsl_spmatrix_free(A);
> gsl_spmatrix_free(B);
> gsl_spmatrix_free(C);
> gsl_spmatrix_free(D);
> return 0;
> }
> ```
>
> (file #41753)
> _______________________________________________________
>
> Additional Item Attachment:
>
> File name: sparse.c Size:1 KB
>
>
> _______________________________________________________
>
> Reply to this item at:
>
> <http://savannah.gnu.org/bugs/?51951>
>
> _______________________________________________
> Message sent via/by Savannah
> http://savannah.gnu.org/
>