87 integer,
dimension(:),
allocatable :: row
92 integer,
dimension(:),
allocatable :: col
98 logical :: sorted = .false.
189 integer,
dimension(nl),
intent(in) :: nnz
190 integer ,
intent(in) :: nl, nc
192 integer :: nz, ii, jj, wdt, length
194 if ( nc < 0 )
call quit( &
195 &
"graph_mod: graph_create: number of columns nc < 0")
197 if ( nl <= 0 )
call quit( &
198 &
"graph_mod: graph_create: number of lines nl <= 0")
200 if (
size(nnz,1) /= nl )
call quit( &
201 &
"graph_mod: graph_create: 'nnz'wrong size")
203 if ( .NOT. all( nnz >=0 ) )
call quit( &
204 &
"graph_mod: graph_create: 'nnz(ii)' must be >=0 ")
206 if ( sum( nnz ) == 0 )
call quit( &
207 &
"graph_mod: graph_create: one line at least must be non-empty'")
226 if (length>wdt) wdt = length
246 integer :: ii, wdt, length
250 if ( .NOT. (
allocated(g%row)) ) info = -1
251 if ( .NOT. (
allocated(g%col)) ) info = -2
254 if ( g%nl <= 0 ) info = -3
255 if ( g%nc <= 0 ) info = -4
256 if ( g%nnz <= 0 ) info = -5
257 if ( minval(g%row) <= 0 ) info = -6
258 if ( minval(g%col) < 0 ) info = -7
262 if ( maxval(g%row) /= g%nnz+1 ) info = -8
263 if ( maxval(g%col) > g%nc ) info = -9
264 if (
size(g%row,1) /= g%nl+1 ) info = -10
265 if (
size(g%col,1) /= g%nnz ) info = -11
269 if ( g%row(g%nl+1) /=
size(g%col)+1 ) info = -12
275 length = g%row(ii+1) - g%row(ii)
276 if (length>wdt) wdt = length
278 if ( wdt /= g%width ) info = -13
282 write(*,*)
"graph_mod : valid, info =", int(info, 1)
293 write(*,*)
'graph_mod : print' 295 write(*,*)
' Valid =', int(
valid(g), 1)
296 write(*,*)
' Nb lines =', g%nl
297 write(*,*)
' Nb columns =', g%nc
298 write(*,*)
' Nb non-zero entries =', g%nnz
299 write(*,*)
' Maximal line width =', g%width
300 write(*,*)
' Sorted lines = ', g%sorted
308 type(
graph),
intent(in) :: g0
317 call allocmem(g%row,
size(g0%row,1) )
318 call allocmem(g%col,
size(g0%col,1) )
332 type(
graph),
intent(in):: g1, g2
334 integer,
dimension(:),
allocatable :: p1, p2
335 integer :: ii, wdt, sz
340 b = b .AND. ( g1%nl == g2%nl ) .AND. ( g1%nnz == g2%nnz )
341 b = b .AND. ( g1%nc == g2%nc )
342 b = b .AND. ( g1%width == g2%width )
345 b = b .AND. (all( g1%row == g2%row ) )
353 call getrow(sz, p1, wdt, g1, ii)
356 call getrow(sz, p2, wdt, g2, ii)
358 call sort( p1(1:sz), sz )
359 call sort( p2(1:sz), sz )
361 b = b .AND. (all( p1(1:sz) == p2(1:sz) ) )
380 integer ,
dimension(n),
intent(out):: p
381 integer ,
intent(out):: sz
382 type(
graph) ,
intent(in) :: g
383 integer ,
intent(in) :: ii, n
389 &
"graph_mod: graph_getRow_1: graph 'g' not valid")
391 if ( (11<=0) .OR. (ii>g%nl) )
call quit( &
392 &
"graph_mod: graph_getRow_1: wrong line index 'ii'")
400 if (sz>n )
call quit( &
401 &
"graph_mod: graph_getRow_1: unsufficient size& 402 & for the array 'p'")
405 p(1:sz) = g%col(j1:j2-1)
421 integer ,
dimension(n),
intent(out):: p
422 type(
graph) ,
intent(in) :: g
423 integer ,
intent(in) :: ii, n
429 &
"graph_mod: graph_getRow_2: graph 'g' not valid")
431 if ( (11<=0) .OR. (ii>g%nl) )
call quit( &
432 &
"graph_mod: graph_getRow_2: wrong line index 'ii'")
439 if ( (j2-j1) /= n )
call quit( &
440 &
'graph_mod: graph_getRow: 3')
451 integer ,
intent(in) :: p, ii
452 integer ,
dimension(p),
intent(in) :: col
461 write(*,*)
"graph_mod: graph_setRow: graph 'g' not valid, info = ", j1
464 if ( (11<=0) .OR. (ii>g%nl) )
call quit( &
465 &
"graph_mod: graph_setRow: wrong line index 'ii'")
467 j1 = g%row(ii+1) - g%row(ii)
468 if (j1 /= p )
call quit(
'graph_mod: graph_setRow: 3')
473 g%col(j1:j1+p-1) = col
486 type(
graph),
intent(in) :: g1
488 integer,
dimension(:),
allocatable :: nnz
489 integer :: jj, ii, j1, j2, col, kk, nc
492 &
"graph_mod: graph_transpose: graph 'g' not valid")
509 nnz(jj) = nnz(jj) + 1
511 g2 =
graph(nnz, g1%nc, g1%nl)
523 kk = g2%row(col) + nnz(col)
525 nnz(col) = nnz(col) + 1
557 subroutine union(sz, tab, bf1, n, bf2, p, g, rows, m)
558 integer ,
intent(out):: sz
559 integer ,
intent(in) :: m, n, p
560 integer,
dimension(n),
intent(out):: tab, bf1
561 integer,
dimension(p),
intent(out):: bf2
562 type(
graph) ,
intent(in) :: g
563 integer,
dimension(m),
intent(in) :: rows
565 integer :: ii, s1, s2
568 if( maxval(rows) > g%nl )
call quit(
'graph_mod: union: 1')
569 if( minval(rows) <= 0 )
call quit(
'graph_mod: union: 2')
572 call getrow(sz, tab, n, g, rows(1))
576 call getrow(s2, bf2, p, g, rows(ii))
581 if( s1 > n )
call quit(
'graph_mod: union: 3')
585 tab(1:s1) = bf1(1:s1)
599 type(
graph) ,
intent(in) :: g1
600 logical,
dimension(:),
intent(in) :: line
602 integer,
dimension(g1%nl) :: nnz
603 integer :: ii, j1_1, j1_2, j2_1, j2_2
606 &
'graph_mod: graph_extract: 1')
608 if (
size(line,1)/=g1%nl)
call quit( &
609 &
'graph_mod: graph_extract: 2')
614 nnz(ii) = g1%row(ii+1)-g1%row(ii)
619 g2 =
graph(nnz, g1%nl, g1%nc)
624 if (nnz(ii)==0) cycle
632 g2%col(j2_1:j2_2-1) = g1%col(j1_1:j1_2-1)
639 &
'graph_mod: graph_extract: 3')
650 integer :: ii, j1, j2, ll
653 &
'graph_mod: graph_sortRows: 1')
664 call sort(g%col(j1:j2-1), ll)
680 type(
graph),
intent(in) :: A, B
683 integer :: wA, wB, wC, nl
686 &
'graph_mod: graph_prod: 1')
689 &
'graph_mod: graph_prod: 2')
691 if ( maxval(a%col) > b%nl )
call quit( &
692 &
'graph_mod: graph_prod: 3')
696 if (.NOT. b2%sorted)
call sortrows(b2)
715 integer,
dimension(wc,nl) :: list
716 integer,
dimension(nl) :: nnz
717 integer,
dimension(wA) :: row_A
718 integer,
dimension(wB) :: bf2
719 integer,
dimension(wC) :: tab, bf1
721 integer :: ii, jj, szA, sz
730 call getrow(sza, row_a, wa, a, ii)
736 call union(sz, tab, bf1, wc, bf2, wb, b2, row_a(1:sza), sza)
739 list(1:sz,ii) = tab(1:sz)
751 g =
graph(nnz, a%nl, b%nc)
759 call setrow(g, list(1:jj,ii), jj, ii)
775 type(
graph),
intent(in) :: A, B
780 &
'graph_mod: prod_tAB: 1')
subroutine graph_sortrows(g)
Sort all rows of the graph g.
DERIVED TYPE graph: sparse matrices of boolean in CSR format
subroutine graph_copy(g, g0)
g := g0
deallocate memory for real(RP) arrays
type(graph) function graph_create(nnz, nl, nc)
Constructor for the type graph
subroutine graph_transpose(g2, g1)
Transpose graph.
subroutine graph_print(g)
Print a short description of the graph 'g'.
print a short description
subroutine, public graph_prod(g, A, B)
Matrix product g = A*B.
subroutine, public graph_extract(g2, g1, line)
line i of g2 = line i of g1 if line(i) = .TRUE. = void otherwise
subroutine graph_setrow(g, col, p, ii)
subroutine graph_getrow_1(sz, p, n, g, ii)
Extract row ii of the graph g.
subroutine graph_clear(g)
Destructor for the type graph.
integer function graph_valid(g)
Check if the graph structure 'g' is valid.
subroutine, public merge_sorted_set(cpt, t, n, t1, n1, t2, n2)
t(1:cpt) = merge of the two arrays t1 and t2 of size n1 and n2
ALGEBRAIC OPERATIONS ON SETS
subroutine, public union(sz, tab, bf1, n, bf2, p, g, rows, m)
graph row union
allocate memory for real(RP) arrays
subroutine graph_getrow_2(p, n, g, ii)
Extract row ii of the graph g.
logical function graph_equal(g2, g1)
test equality Two graph are equal if the underlying boolean matrices are equal independently of the c...
integer choral_verb
Verbosity level.
subroutine, public sort(t, n)
Sorts the array t of length N in ascending order by the straight insertion method.
DEFINITION OF GLOBAL VARIABLES FOR THE LIBRARY CHORAL
sort graph rows in ascending order
The type graph stores sparse matrices of boolean in CSR format.
subroutine, public prod_tab(g, A, B)
graph product