File: spconv.f.src

package info (click to toggle)
python-scipy 0.5.2-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 33,888 kB
  • ctags: 44,231
  • sloc: ansic: 156,256; cpp: 90,347; python: 89,604; fortran: 73,083; sh: 1,318; objc: 424; makefile: 342
file content (354 lines) | stat: -rw-r--r-- 8,639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
c    -*- fortran -*-
c    convert csc matrix a to csr matrix b
c    convert csr matrix a to csc matrix b
c    transpose csc matrix
c    transpose csr matrix
c    all depends on how you interpret the results
         
      subroutine <_c>transp(m,n,a,rowa,ptra,nnzamax,b,colb,ptrb)
      <_t> a(0:nnzamax-1), b(0:nnzamax-1)
      integer rowa(0:nnzamax-1), colb(0:nnzamax-1)
      integer ptra(0:n), ptrb(0:m)
      integer j, bnum, cola, ia, ra

      ptrb(0) = 0
      bnum = 0
      do j = 0, m-1
         do cola = 0, n-1
            do ia = ptra(cola), ptra(cola+1)-1
               ra = rowa(ia)
               if (ra.eq.j) then
                  b(bnum) = a(ia)
                  colb(bnum) = cola
                  bnum = bnum+1
               end if
            end do
         end do
         ptrb(j+1) = bnum
      end do

      return
      end subroutine <_c>transp

c      returns the index into the data array
c      and the value
      subroutine <_c>cscgetel(a,rowa,ptra,nnzamax,n,row,col,ind,val)
      
      <_t> a(0:nnzamax-1), val
      integer rowa(0:nnzamax-1), ptra(0:n)
      integer nnzamax, row, col, ind

      integer ia

      ind = -1
      val = 0.0
      do ia = ptra(col), ptra(col+1)-1
         if (rowa(ia).eq.row) then
            ind = ia
            val = a(ia)
            goto 10
         end if
      end do

 10   continue
      return 

      end subroutine <_c>cscgetel

      
c      set an element into the data array (assumes there is room)
c
      subroutine <_c>cscsetel(a,rowa,ptra,nnzamax,n,row,col,val)

      <_t> a(0:nnzamax-1), val
      integer rowa(0:nnzamax-1), ptra(0:n)
      integer nnza, n, row, col, nnzamax

      integer ra, newia

      nnza = ptra(n)
      newia = ptra(col)
      do ia = newia, ptra(col+1)-1
         ra = rowa(ia)
         if (ra.eq.row) then
c     just replace and be done
            a(ia) = val
            goto 10
         else if (ra.gt.row) then 
            newia = ia
            goto 5
         end if
      end do

c     we are past where it should be stored
c         (assumes sorted) so make room for this new element
c     here so that it will run if this is the first entry in the
c         column
 5    continue
      ia = newia
      do iia = nnza, ia+1, -1
         a(iia) = a(iia-1)
         rowa(iia) = rowa(iia-1)
      end do
      a(ia) = val
      rowa(ia) = row
      do iia = col+1, n
         ptra(iia) = ptra(iia)+1
      end do

      return

 10   continue
      
      return
      end subroutine <_c>cscsetel

c     assumes sorted by column and then row 

      subroutine <_c>cootocsc(n,vals,row,col,nnz,a,rowa,ptra,nnzamax,
     $     ierr)
      
      <_t> vals(0:nnz-1), a(0:nnzamax-1)
      integer rowa(0:nnzamax-1), ptra(0:n)
      integer row(0:nnz-1), col(0:nnz-1)
      integer n, nnzamax, nnz, ierr

      <_t> val
      integer j, k, cumsum

      if (nnz.gt.nnzamax) goto 999
      ierr=0
      nnza=0
      do k = 0, n-1
         ptra(k) = 0
      end do
      do ia = 0, nnzamax-1
         a(ia) = 0.0
         rowa(ia) = 0
      end do      
      do k = 0, nnz-1
         j = col(k)
         val = vals(k)
         if (val.ne.0.0) then
            a(nnza) = val
            rowa(nnza) = row(k)
            ptra(j+1) = ptra(j+1) + 1
            nnza = nnza + 1
         end if
      end do

c   successful completion (fix the ptr array)
      cumsum = 0
      do k = 1, n
         cumsum = cumsum + ptra(k)
         ptra(k) = cumsum         
      end do
      return      

      return

 999  continue
      ierr=1
      return
      end subroutine <_c>cootocsc

      subroutine <_c>csctocoo(n, vals, row, col, a, rowa, ptra, nnzamax)
      <_t> vals(0:nnzamax-1), a(0:nnzamax-1)
      integer rowa(0:nnzamax-1), ptra(0:n)
      integer row(0:nnzamax-1), col(0:nnzamax-1)
      integer n, nnzamax

      integer i, j, k

      j = 0
      do k = 0, n-1
         do i = ptra(k), ptra(k+1)-1
            row(j) = rowa(i)
            col(j) = k
            vals(j) = a(i)
            j = j + 1
         end do
      end do

      return
      end subroutine <_c>csctocoo

c     intended for re-entry in case a is too small

      subroutine <_c>fulltocsc(m,n,fulla,a,rowa,ptra,nnzamax,
     $     irow,jcol,ierr)
      
      <_t> fulla(0:m-1,0:n-1), a(0:nnzamax-1)
      integer rowa(0:nnzamax-1), ptra(0:n)
      integer m, n, nnzamax, irow, jcol, ierr

      <_t> val
      integer nnza, i, j, k, cumsum

      ierr=0
      nnza = ierr
      do j = jcol, n-1
         do i = irow, m-1
            val = fulla(i,j)
            if (val.ne.0.0) then
               if (nnza.ge.nnzamax) goto 999
               a(nnza) = val
               rowa(nnza) = i
               ptra(j+1) = ptra(j+1) + 1
               nnza = nnza + 1
            end if
         end do
      end do      

c   successful completion (fix the ptr array)
      cumsum = 0
      do k = 1, n
         cumsum = cumsum + ptra(k)
         ptra(k) = cumsum         
      end do
      return

 999  continue
      ierr=nnza
      irow = i
      jcol = j
      return
      end subroutine <_c>fulltocsc


      subroutine <_c>csctofull(m, n, fulla, a, rowa, ptra, nnzamax)

      <_t> fulla(0:m-1, 0:n-1), a(0:nnzamax-1)
      integer rowa(0:nnzamax-1), ptra(0:n)
      integer m, n, nnzamax

      integer ia, k
c      integer i, j

c      do j = 0, n-1
c         do i = 0, m-1
c            fulla(i,j) = 0.0
c         end do
c      end do

      do k = 0, n-1
         do ia = ptra(k), ptra(k+1)-1
            fulla(rowa(ia),k) = a(ia)
         end do
      end do
      
      return
      end subroutine <_c>csctofull


c  extract a sub-matrix from a sparse matrix
c     c = a(ibeg:iend, jbeg:jend)  (inclusive of end-points)
c
c     intended for re-entry if nnzcmax is not big enough 
c      irow and jcol should initially be 0 and 0

      subroutine <_c>cscextract(n,a,rowa,ptra,nnzamax,ibeg,iend,jbeg,
     $     jend, c, rowc, ptrc, nnzcmax, irow, jcol, ierr)

      <_t> a(0:nnzamax-1), c(0:nnzcmax-1)
      integer rowa(0:nnzamax-1), rowc(0:nnzamax-1)
      integer ptra(0:n), ptrc(0:jend-jbeg+1)
      integer ibeg, iend, jbeg, jend
      integer nnzamax, nnzcmax, irow, jcol, ierr

      integer nnza, nc, j, iabeg, ia, k, cumsum

      nc = jend-jbeg+1

      nnza = ptra(n)
      nnzc = ierr

      if (jcol .lt. jbeg) jcol = jbeg

      do j = jcol, jend
         jc = j - jbeg
c   look through row indices in this column, copy all those that are
c      in required range.
         iabeg = max(irow,ptra(j))
         do ia = iabeg, ptra(j+1)-1
            ra = rowa(ia)
            if ((ra.le.iend).and.(ra.ge.ibeg)) then
               if (nnzc.ge.nnzcmax) goto 999
               c(nnzc) = a(ia)
               rowc(nnzc) = ra-ibeg
               ptrc(jc+1) = ptrc(jc+1) + 1
               nnzc = nnzc + 1
            end if
         end do
      end do

c   successful completion (fix the ptr array)
      cumsum = 0
      do k = 1, n
         cumsum = cumsum + ptrc(k)
         ptrc(k) = cumsum         
      end do
      return


      return

 999  continue
      ierr = nnzc
      irow = ia
      jcol = j
      return
      end subroutine <_c>cscextract


      
      subroutine <_c>diatocsc(m,n,diags,numdia,diasize,offsets,
     $     a,rowa,ptra,nzmax, ierr)
      
      integer n, numdia, diasize, nzmax, ierr
      <_t> diags(0:numdia-1, 0:diasize-1), a(0:nzmax-1)
      <_t> val
      integer offsets(0:numdia-1), rowa(0:nzmax-1)
      integer ptra(0:n)

      integer col, nnza, jj, row, idiag, ia

      nnza = 0
      ierr = 0
c      write (*,*) "SDSD", m, n, numdia, diasize, nzmax
      do col = 0, n-1
c   Loop through the offsets 
         do jj = 0, numdia-1
            row = col - offsets(jj)
            if ((row.ge.0).and.(row.lt.m)) then
               idiag = min(row, col)
               val = diags(jj, idiag)
               if (val.ne.0.0) then
                  if (nnza.ge.nzmax) goto 999
c   find place to insert this row (inserted in sorted order)
                  ia = ptra(col)
 10               if ((ia.lt.ptra(col+1)).and.(rowa(ia).lt.row)) then
                     ia = ia + 1
                     goto 10
                  end if
                  do iia = nnza, ia+1, -1
                     a(iia) = a(iia-1)
                     rowa(iia) = rowa(iia-1)
                  end do
                  a(ia) = val
                  rowa(ia) = row
                  nnza = nnza + 1
               end if
            end if
         end do
         ptra(col+1) = nnza
      end do

      return 

 999  continue
      ierr = 1
      return
      

      end subroutine <_c>diatocsc