bug-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gsl] [bug #51951] sparse add function gives wrong result (shorter t


From: Alfredo Correa
Subject: [Bug-gsl] [bug #51951] sparse add function gives wrong result (shorter than expected)
Date: Wed, 6 Sep 2017 03:17:22 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

URL:
  <http://savannah.gnu.org/bugs/?51951>

                 Summary: sparse add function gives wrong result (shorter than
expected)
                 Project: GNU Scientific Library
            Submitted by: alfc
            Submitted on: Wed 06 Sep 2017 07:17:21 AM UTC
                Category: Runtime error
                Severity: 3 - Normal
        Operating System: linux fedora 26
                  Status: None
             Assigned to: None
             Open/Closed: Open
                 Release: 2.3
         Discussion Lock: Any

    _______________________________________________________

Details:

This program produces the wrong sum D = C + C:

C is
```
matrix in compressed row format:
i = [ 2, 3, 0, 2, 0, 1, 3, 0, ]
p = [ 0, 2, 4, 4, 7, 8, ]
d = [ 3.1, 4.6, 1, 7.2, 2.1, 2.9, 8.5, 4.1, ]
```
while D (erroneously) results in 
```
D matrix in compressed row format:
i = [ 2, 3, 0, 1, ]
p = [ 0, 2, 3, 3, 4, 4, ]
d = [ 6.2, 9.2, 2, 5.8, ]
```




```
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");

  gsl_spmatrix_free(A);
  gsl_spmatrix_free(B);
  gsl_spmatrix_free(C);
```




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51951>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]