File: matmul_perftest.py

package info (click to toggle)
pysparse 1.1-1.3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,792 kB
  • ctags: 3,499
  • sloc: ansic: 45,867; python: 2,734; makefile: 102
file content (26 lines) | stat: -rw-r--r-- 475 bytes parent folder | download | duplicates (5)
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
import time
from pysparse import spmatrix


n = 1000000

# create 2 nxn tridiag matrices
A = spmatrix.ll_mat(n, n)
B = spmatrix.ll_mat(n, n)

for i in xrange(n):
    A[i,i] = i
    B[i,i] = i
    if i > 0:
        A[i,i-1] = 1
        B[i,i-1] = 1
    if i < n-1:
        A[i,i+1] = 1
        B[i,i-1] = 1


t1 = time.clock()
C = spmatrix.matrixmultiply(A, B)
t_mult = time.clock() - t1
print 'time for multiplying %dx%d matrices: %.2f sec' % (n, n, t_mult)
print C[:10,:10]