vhalli

Cython - M1RI

Mar 19th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. struct vec3{
  2.     long s;     # What are s and u for?
  3.     long u;
  4. };
  5.  
  6. -----------------------------------------------------------------------
  7.  
  8.  
  9. cdef vec3 * matrix_to_m1ri(M):
  10.     cdef vec3 t
  11.     cdef vec3 *R = <vec3 *>sage_malloc(M1RI_BITS * sizeof(vec3))
  12.     cdef long ptr, i
  13.  
  14.     i = 0
  15.     for row in M:
  16.     t.u = 0
  17.     t.s = 0
  18.     ptr = 1
  19.     j = 0
  20.     for x in row:
  21.         if x != 0:
  22.         t.u |= ptr 
  23.         if x == 2:      # Why check x!=0 and x==2? I think this will make sense if I know
  24.             t.s |= ptr  # what long s and long u are.
  25.         ptr += ptr
  26.     R[i] = t
  27.     i+=1
  28.     return R
  29.  
  30. -------------------------------------------------------------------------
  31.  
  32. cdef vec3 * print_m1ri(vec3 *M):
  33.     cdef long i, j, ptr
  34.     global D
  35.     for i from 0 <= i < M1RI_BITS:
  36.     ptr = 1
  37.     s = ''
  38.     for j from 0 <= j < M1RI_BITS:
  39.         if M[i].u&ptr:
  40.         if M[i].s&ptr:
  41.             s += ':'                # We printing the matrix using only
  42.         else:                   # : . ? and the space characters?
  43.             s += '.'                # What sort of output is this?
  44.         elif M[i].s & ptr:
  45.         s += '?'
  46.         else:
  47.         s += ' '
  48.         ptr += ptr
  49.     print s
Advertisement
Add Comment
Please, Sign In to add comment