-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
30 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
cimport c_library | ||
|
||
|
||
def timestwo(int x): | ||
return c_library.timestwo(x) | ||
|
||
|
||
def square(int x): | ||
return c_library.square(x) | ||
|
||
|
||
cdef copy_to_GL2RMatrix(M, c_library.GL2RMatrix* N): | ||
cdef int i, j | ||
for i in range(2): | ||
for j in range(2): | ||
N.entries[i][j] = M[i][j] | ||
|
||
|
||
cdef class TwoByTwoMatrix(): | ||
# C attributes that are defined in the "pxd" header file. | ||
# | ||
# cdef c_library.GL2RMatrix matrix | ||
|
||
def __cinit__(self, matrix=None): | ||
if matrix is None: | ||
matrix = [[0,0],[0,0]] | ||
matrix = [[0, 0], [0, 0]] | ||
copy_to_GL2RMatrix(matrix, &self.matrix) | ||
|
||
def __mul__(TwoByTwoMatrix self, TwoByTwoMatrix other): | ||
cdef TwoByTwoMatrix ans | ||
ans = TwoByTwoMatrix() | ||
c_library.multiply_GL2R(&self.matrix, &other.matrix, &ans.matrix) | ||
return ans | ||
|
||
def __repr__(self): | ||
a, b = self.matrix.entries[0][0], self.matrix.entries[0][1] | ||
c, d = self.matrix.entries[1][0], self.matrix.entries[1][1] | ||
return "TwoByTwoMatrix([(%d, %d), (%d, %d)])" % (a, b, c, d) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters