Skip to content

How to use this library #3

@HaGu6aToP

Description

@HaGu6aToP

Hello, i am trying to find the ref for the following matrix

1 1 0 0 0 
1 0 1 0 0 
0 1 0 1 0 
0 0 0 1 6

Just took your fl_block_sparse_dense function in gbla.c and got this

1 0 0 0 0 
0 1 0 0 0 
0 0 0 0 0 
0 0 0 0 0

When i try to do this with your other functions i get an error
main: src/elimination.c:6232: inverse_val: Assertion "*x" failed.

I assume that i am not filling the matrix M correctly and A, B, C and D turn out to be empty.

What am i doing wrong?

Thanks.

#include "gbla/src/matrix.h"
#include "gbla/src/elimination.h"
#include "gbla/src/mapping.h"
#include "gbla/src/types.h"
#include <stdio.h>

#define GBLA_USE_INT32 1

void reduce_sparse_matrix(sm_t* M){
    sb_fl_t *A      = (sb_fl_t *)malloc(sizeof(sb_fl_t));
    dbm_fl_t *B     = (dbm_fl_t *)malloc(sizeof(dbm_fl_t));
    sb_fl_t *C      = (sb_fl_t *)malloc(sizeof(sb_fl_t));
    dbm_fl_t *D     = (dbm_fl_t *)malloc(sizeof(dbm_fl_t));
    map_fl_t *map   = (map_fl_t *)malloc(sizeof(map_fl_t));

    int nthreads = 1;

    splice_fl_matrix_sparse_dense_2(M, A, B, C, D, map, 0, 1, nthreads);

    ri_t ii;
	for (ii=0; ii < M->nrows; ++ii) {
		if (M->rows[ii] != NULL)
		free(M->rows[ii]);
		if (M->pos[ii] != NULL)
		free(M->pos[ii]);
	}
    free(M->rows);
    free(M->pos);

    if (elim_fl_A_sparse_dense_block(&A, B, M->mod, nthreads)) {
        printf("Error while reducing A.\n");
        return;
    }
    if (elim_fl_C_sparse_dense_block(B, &C, D, M->mod, nthreads)) {
        printf("Error while reducing C.\n");
        return;
    }

    dm_t *D_red = copy_block_to_dense_matrix(&D, nthreads, 1);
    D_red->mod  = M->mod;

    ri_t rank_D = 0;

    if (D_red->nrows > 0) rank_D = elim_fl_dense_D(D_red, nthreads);
    

    reconstruct_matrix_block_no_multiline(M, B, D_red, map, nthreads);
    
}

void main(){
    ri_t i;
    sm_t* M = (sm_t*)malloc(sizeof(sm_t));

    // 1, 0, 1, 0, 0
    // 1, 1, 0, 0, 0
    // 0, 1, 0, 1, 0
    // 0, 0, 0, 6, 1

    ri_t m = 4;
    ci_t n = 5;

    M->ncols  = n;
    M->nrows  = m;
    M->rows   = (re_t**)malloc(m*sizeof(re_t*));
    M->pos    = (ci_t**)malloc(m*sizeof(ci_t*));
    M->rwidth = (ci_t*)malloc(m*sizeof(ci_t));

    M->rwidth[0] = 2;
    M->rwidth[1] = 2;
    M->rwidth[2] = 2;
    M->rwidth[3] = 2;

    for(i = 0; i < m; i++){
        M->rows[i] = (re_t*)malloc(M->rwidth[i] * sizeof(re_t));
        M->pos[i]  = (ci_t *)malloc(M->rwidth[i] * sizeof(ci_t));
    }

    M->rows[0][0] = 1;
    M->rows[0][1] = 1;
    M->rows[1][0] = 1;
    M->rows[1][1] = 1;
    M->rows[2][0] = 1;
    M->rows[2][1] = 1;
    M->rows[3][0] = 6;
    M->rows[3][1] = 1;

    M->pos[0][0] = 0;
    M->pos[0][1] = 2;
    M->pos[1][0] = 0;
    M->pos[1][1] = 1;
    M->pos[2][0] = 1;
    M->pos[2][1] = 3;
    M->pos[3][0] = 3;
    M->pos[3][1] = 4;

    M->nnz = 8;
    M->density = compute_density(M->nnz, M->nrows, M->ncols);
    M->mod = 7;

  //  M = load_schreyer_matrix("1.txt", 1);
  // M = sort_schreyer_matrix(M);
  //  normalize_schreyer_input_rows(M);

    print_sparse_matrix(M);
    print_sparse_matrix_info(M);

    reduce_sparse_matrix(M);
    print_sparse_matrix_info(M);
    print_sparse_matrix(M);
}

Output:

1 1 0 0 0 
1 0 1 0 0 
0 1 0 1 0 
0 0 0 1 6 
----
1 1 
1 1 
1 1 
1 6 
----
0 1 
0 2 
1 3 
3 4 
nrows=4 ncols=5 nnz=8 density=40.000000
rwidth: 2 2 2 2 
nrows=4 ncols=5 nnz=8 density=40.000000
rwidth: 2 2 2 2 
1 0 0 0 0 
0 1 0 0 0 
0 0 0 0 0 
0 0 0 0 0 
----
1 6 
1 1 
1 6 
1 1 
----
0 -1 
1 -1 
-1 -1 
-1 -1 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions