Skip to content

Commit

Permalink
Trac #19240: Rename matrix_mod2e_dense to matrix_gf2e_dense
Browse files Browse the repository at this point in the history
The name `matrix_mod2e_dense` suggests that it's about matrices in
`ZZ/(2^e)ZZ`, while it's really for matrices in `GF(2^e)`.

Since the module and class names are non-public implementation details,
there is no need for deprecation.

URL: http://trac.sagemath.org/19240
Reported by: jdemeyer
Ticket author(s): Jeroen Demeyer
Reviewer(s): Simon King
  • Loading branch information
Release Manager authored and vbraun committed Sep 20, 2015
2 parents 4cc6f80 + 1e47929 commit 1b32539
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/doc/en/reference/matrices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ objects like operation tables (e.g. the multiplication table of a group).
sage/matrix/matrix_integer_dense_saturation
sage/matrix/matrix_integer_sparse
sage/matrix/matrix_mod2_dense
sage/matrix/matrix_mod2e_dense
sage/matrix/matrix_gf2e_dense
sage/matrix/matrix_modn_dense_double
sage/matrix/matrix_modn_dense_float
sage/matrix/matrix_rational_sparse
Expand Down
4 changes: 2 additions & 2 deletions src/module_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,8 @@ def uname_specific(name, value, alternative):
extra_compile_args = m4ri_extra_compile_args,
depends = [SAGE_INC + "/png.h", SAGE_INC + "/m4ri/m4ri.h"]),

Extension('sage.matrix.matrix_mod2e_dense',
sources = ['sage/matrix/matrix_mod2e_dense.pyx'],
Extension('sage.matrix.matrix_gf2e_dense',
sources = ['sage/matrix/matrix_gf2e_dense.pyx'],
libraries = ['m4rie', 'm4ri', 'm'],
depends = [SAGE_INC + "/m4rie/m4rie.h"],
extra_compile_args = m4ri_extra_compile_args),
Expand Down
12 changes: 12 additions & 0 deletions src/sage/matrix/matrix_gf2e_dense.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from sage.libs.m4rie cimport mzed_t

cimport matrix_dense

cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
cdef mzed_t *_entries
cdef object _one
cdef object _zero

cpdef Matrix_gf2e_dense _multiply_newton_john(Matrix_gf2e_dense self, Matrix_gf2e_dense right)
cpdef Matrix_gf2e_dense _multiply_karatsuba(Matrix_gf2e_dense self, Matrix_gf2e_dense right)
cpdef Matrix_gf2e_dense _multiply_strassen(Matrix_gf2e_dense self, Matrix_gf2e_dense right, cutoff=*)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The M4RIE library offers two matrix representations:
words such that each element is filled with zeroes until the next
power of two. Thus, for example, elements of `\GF{2^3}` are
represented as ``[0xxx|0xxx|0xxx|0xxx|...]``. This representation is
wrapped as :class:`Matrix_mod2e_dense` in Sage.
wrapped as :class:`Matrix_gf2e_dense` in Sage.
Multiplication and elimination both use "Newton-John" tables. These
tables are simply all possible multiples of a given row in a matrix
Expand Down Expand Up @@ -50,7 +50,7 @@ AUTHOR:
TESTS::
sage: TestSuite(sage.matrix.matrix_mod2e_dense.Matrix_mod2e_dense).run(verbose=True)
sage: TestSuite(sage.matrix.matrix_gf2e_dense.Matrix_gf2e_dense).run(verbose=True)
running ._test_pickling() . . . pass
TODO:
Expand All @@ -66,6 +66,16 @@ REFERENCES:
http://arxiv.org/abs/0901.1413
"""

#*****************************************************************************
# Copyright (C) 2010 Martin Albrecht <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************

include "sage/ext/interrupt.pxi"

cimport matrix_dense
Expand Down Expand Up @@ -100,17 +110,17 @@ cdef class M4RIE_finite_field:
"""
EXAMPLE::
sage: from sage.matrix.matrix_mod2e_dense import M4RIE_finite_field
sage: from sage.matrix.matrix_gf2e_dense import M4RIE_finite_field
sage: K = M4RIE_finite_field(); K
<sage.matrix.matrix_mod2e_dense.M4RIE_finite_field object at 0x...>
<sage.matrix.matrix_gf2e_dense.M4RIE_finite_field object at 0x...>
"""
pass

def __dealloc__(self):
"""
EXAMPLE::
sage: from sage.matrix.matrix_mod2e_dense import M4RIE_finite_field
sage: from sage.matrix.matrix_gf2e_dense import M4RIE_finite_field
sage: K = M4RIE_finite_field()
sage: del K
"""
Expand All @@ -123,7 +133,7 @@ cdef m4ri_word poly_to_word(f):
cdef object word_to_poly(w, F):
return F.fetch_int(w)

cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
########################################################################
# LEVEL 1 functionality
########################################################################
Expand Down Expand Up @@ -336,19 +346,19 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
[a^3 + a^2 + 1 a^3 + a^2 + a a^3 + a^2 + a a^3 + 1]
[a^3 + a^2 + 1 a^3 + a^2 a^3 + a^2 a^2]
"""
cdef Matrix_mod2e_dense A
A = Matrix_mod2e_dense.__new__(Matrix_mod2e_dense, self._parent, 0, 0, 0, alloc=False)
cdef Matrix_gf2e_dense A
A = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, self._parent, 0, 0, 0, alloc=False)
if self._nrows == 0 or self._ncols == 0:
return A
A._entries = mzed_add(NULL, self._entries, (<Matrix_mod2e_dense>right)._entries)
A._entries = mzed_add(NULL, self._entries, (<Matrix_gf2e_dense>right)._entries)

return A

cpdef ModuleElement _sub_(self, ModuleElement right):
"""
EXAMPLE::
sage: from sage.matrix.matrix_mod2e_dense import Matrix_mod2e_dense
sage: from sage.matrix.matrix_gf2e_dense import Matrix_gf2e_dense
sage: K.<a> = GF(2^4)
sage: m,n = 3, 4
sage: MS = MatrixSpace(K,m,n)
Expand Down Expand Up @@ -406,13 +416,13 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
if self._ncols != right._nrows:
raise ArithmeticError("left ncols must match right nrows")

cdef Matrix_mod2e_dense ans
cdef Matrix_gf2e_dense ans

ans = self.new_matrix(nrows = self.nrows(), ncols = right.ncols())
if self._nrows == 0 or self._ncols == 0 or right._ncols == 0:
return ans
sig_on()
ans._entries = mzed_mul_naive(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries)
ans._entries = mzed_mul_naive(ans._entries, self._entries, (<Matrix_gf2e_dense>right)._entries)
sig_off()
return ans

Expand Down Expand Up @@ -449,17 +459,17 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
if self._ncols != right._nrows:
raise ArithmeticError("left ncols must match right nrows")

cdef Matrix_mod2e_dense ans
cdef Matrix_gf2e_dense ans

ans = self.new_matrix(nrows = self.nrows(), ncols = right.ncols())
if self._nrows == 0 or self._ncols == 0 or right._ncols == 0:
return ans
sig_on()
ans._entries = mzed_mul(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries)
ans._entries = mzed_mul(ans._entries, self._entries, (<Matrix_gf2e_dense>right)._entries)
sig_off()
return ans

cpdef Matrix_mod2e_dense _multiply_newton_john(Matrix_mod2e_dense self, Matrix_mod2e_dense right):
cpdef Matrix_gf2e_dense _multiply_newton_john(Matrix_gf2e_dense self, Matrix_gf2e_dense right):
"""
Return A*B using Newton-John tables.
Expand Down Expand Up @@ -510,18 +520,18 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
if self._ncols != right._nrows:
raise ArithmeticError("left ncols must match right nrows")

cdef Matrix_mod2e_dense ans
cdef Matrix_gf2e_dense ans

ans = self.new_matrix(nrows = self.nrows(), ncols = right.ncols())
if self._nrows == 0 or self._ncols == 0 or right._ncols == 0:
return ans

sig_on()
ans._entries = mzed_mul_newton_john(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries)
ans._entries = mzed_mul_newton_john(ans._entries, self._entries, (<Matrix_gf2e_dense>right)._entries)
sig_off()
return ans

cpdef Matrix_mod2e_dense _multiply_karatsuba(Matrix_mod2e_dense self, Matrix_mod2e_dense right):
cpdef Matrix_gf2e_dense _multiply_karatsuba(Matrix_gf2e_dense self, Matrix_gf2e_dense right):
"""
Matrix multiplication using Karatsuba over polynomials with
matrix coefficients over GF(2).
Expand Down Expand Up @@ -558,18 +568,18 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
if self._ncols != right._nrows:
raise ArithmeticError("left ncols must match right nrows")

cdef Matrix_mod2e_dense ans
cdef Matrix_gf2e_dense ans

ans = self.new_matrix(nrows = self.nrows(), ncols = right.ncols())
if self._nrows == 0 or self._ncols == 0 or right._ncols == 0:
return ans

sig_on()
ans._entries = mzed_mul_karatsuba(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries)
ans._entries = mzed_mul_karatsuba(ans._entries, self._entries, (<Matrix_gf2e_dense>right)._entries)
sig_off()
return ans

cpdef Matrix_mod2e_dense _multiply_strassen(Matrix_mod2e_dense self, Matrix_mod2e_dense right, cutoff=0):
cpdef Matrix_gf2e_dense _multiply_strassen(Matrix_gf2e_dense self, Matrix_gf2e_dense right, cutoff=0):
"""
Winograd-Strassen matrix multiplication with Newton-John
multiplication as base case.
Expand Down Expand Up @@ -609,17 +619,17 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
if self._ncols != right._nrows:
raise ArithmeticError("left ncols must match right nrows")

cdef Matrix_mod2e_dense ans
cdef Matrix_gf2e_dense ans

ans = self.new_matrix(nrows = self.nrows(), ncols = right.ncols())
if self._nrows == 0 or self._ncols == 0 or right._ncols == 0:
return ans

if cutoff == 0:
cutoff = _mzed_strassen_cutoff(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries)
cutoff = _mzed_strassen_cutoff(ans._entries, self._entries, (<Matrix_gf2e_dense>right)._entries)

sig_on()
ans._entries = mzed_mul_strassen(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries, cutoff)
ans._entries = mzed_mul_strassen(ans._entries, self._entries, (<Matrix_gf2e_dense>right)._entries, cutoff)
sig_off()
return ans

Expand Down Expand Up @@ -660,7 +670,7 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
[ a 1 0 a a + 1 0 0 a + 1 1 a + 1]
"""
cdef m4ri_word a = poly_to_word(right)
cdef Matrix_mod2e_dense C = Matrix_mod2e_dense.__new__(Matrix_mod2e_dense, self._parent, 0, 0, 0)
cdef Matrix_gf2e_dense C = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, self._parent, 0, 0, 0)
mzed_mul_scalar(C._entries, a, self._entries)
return C

Expand Down Expand Up @@ -696,7 +706,7 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
"""
if self._nrows == 0 or self._ncols == 0:
return 0
return mzed_cmp(self._entries, (<Matrix_mod2e_dense>right)._entries)
return mzed_cmp(self._entries, (<Matrix_gf2e_dense>right)._entries)

def __copy__(self):
"""
Expand All @@ -718,8 +728,8 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
sage: A2[0,0]
a^2
"""
cdef Matrix_mod2e_dense A
A = Matrix_mod2e_dense.__new__(Matrix_mod2e_dense, self._parent, 0, 0, 0)
cdef Matrix_gf2e_dense A
A = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, self._parent, 0, 0, 0)

if self._nrows and self._ncols:
mzed_copy(A._entries, <const_mzed_t *>self._entries)
Expand Down Expand Up @@ -997,8 +1007,8 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
[0 1 0]
[0 0 1]
"""
cdef Matrix_mod2e_dense A
A = Matrix_mod2e_dense.__new__(Matrix_mod2e_dense, self._parent, 0, 0, 0)
cdef Matrix_gf2e_dense A
A = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, self._parent, 0, 0, 0)

if self._nrows and self._nrows == self._ncols:
mzed_invert_newton_john(A._entries, self._entries)
Expand Down Expand Up @@ -1132,7 +1142,7 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
"""
mzed_col_swap(self._entries, col1, col2)

def augment(self, Matrix_mod2e_dense right):
def augment(self, Matrix_gf2e_dense right):
"""
Augments ``self`` with ``right``.
Expand Down Expand Up @@ -1190,10 +1200,10 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
sage: M.augment(N)
[]
"""
cdef Matrix_mod2e_dense A
cdef Matrix_gf2e_dense A

if self._nrows != right._nrows:
raise TypeError, "Both numbers of rows must match."
raise TypeError("Both numbers of rows must match.")

if self._ncols == 0:
return right.__copy__()
Expand All @@ -1206,7 +1216,7 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
A._entries = mzed_concat(A._entries, self._entries, right._entries)
return A

def stack(self, Matrix_mod2e_dense other):
def stack(self, Matrix_gf2e_dense other):
"""
Stack ``self`` on top of ``other``.
Expand Down Expand Up @@ -1262,14 +1272,14 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
[]
"""
if self._ncols != other._ncols:
raise TypeError, "Both numbers of columns must match."
raise TypeError("Both numbers of columns must match.")

if self._nrows == 0:
return other.__copy__()
if other._nrows == 0:
return self.__copy__()

cdef Matrix_mod2e_dense A
cdef Matrix_gf2e_dense A
A = self.new_matrix(nrows = self._nrows + other._nrows)
if self._ncols == 0:
return A
Expand Down Expand Up @@ -1335,7 +1345,7 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
if highr > self._entries.nrows:
raise TypeError("Expected highr <= self.nrows(), but got %d > %d instead."%(highr, self._entries.nrows))

cdef Matrix_mod2e_dense A = self.new_matrix(nrows = nrows, ncols = ncols)
cdef Matrix_gf2e_dense A = self.new_matrix(nrows = nrows, ncols = ncols)
if ncols == 0 or nrows == 0:
return A
A._entries = mzed_submatrix(A._entries, self._entries, row, col, highr, highc)
Expand Down Expand Up @@ -1388,8 +1398,8 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
sage: K.<a> = GF(2^8)
sage: A = random_matrix(K,70,70)
sage: f, s= A.__reduce__()
sage: from sage.matrix.matrix_mod2e_dense import unpickle_matrix_mod2e_dense_v0
sage: f == unpickle_matrix_mod2e_dense_v0
sage: from sage.matrix.matrix_gf2e_dense import unpickle_matrix_gf2e_dense_v0
sage: f == unpickle_matrix_gf2e_dense_v0
True
sage: f(*s) == A
True
Expand All @@ -1400,7 +1410,7 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
MS = MatrixSpace(GF(2), self._entries.x.nrows, self._entries.x.ncols)
A = Matrix_mod2_dense.__new__(Matrix_mod2_dense, MS, 0, 0, 0, alloc = False)
A._entries = mzd_copy( NULL, self._entries.x)
return unpickle_matrix_mod2e_dense_v0, (A, self.base_ring(), self.nrows(), self.ncols())
return unpickle_matrix_gf2e_dense_v0, (A, self.base_ring(), self.nrows(), self.ncols())

def slice(self):
r"""
Expand Down Expand Up @@ -1587,22 +1597,29 @@ cdef class Matrix_mod2e_dense(matrix_dense.Matrix_dense):
mzed_cling(self._entries, v)
mzd_slice_free(v)

def unpickle_matrix_mod2e_dense_v0(Matrix_mod2_dense a, base_ring, nrows, ncols):
"""
def unpickle_matrix_gf2e_dense_v0(Matrix_mod2_dense a, base_ring, nrows, ncols):
r"""
EXAMPLE::
sage: K.<a> = GF(2^2)
sage: A = random_matrix(K,10,10)
sage: f, s= A.__reduce__()
sage: from sage.matrix.matrix_mod2e_dense import unpickle_matrix_mod2e_dense_v0
sage: f == unpickle_matrix_mod2e_dense_v0
sage: from sage.matrix.matrix_gf2e_dense import unpickle_matrix_gf2e_dense_v0
sage: f == unpickle_matrix_gf2e_dense_v0
True
sage: f(*s) == A
True
We can still unpickle pickles from before :trac:`19240`::
sage: old_pickle = 'x\x9c\x85RKo\xd3@\x10\xae\xdd$$\xdb&\xe5U\x1e-\x8f\xc2\xc9\x12RD#$\xce\xa0\xb4\x80\x07\xa2\xca\xc2\x07\x0e\xd5\xe2:\x1b\xdb\x8acg\x1c\xa7J\x85*!\xa4\x90\xe6\x07p\xe0\xc4\x01q\xe5\xc4\x19\xf5\xd0?\xc1\x81\xdf\x80\xb8q\x0b\xb3\x8eMS\xa1\x82V;;\xb3\xdf\xce\xf7\xcd\x8e\xe6\xb5j\xf7,GT;V\x1cy\x83\xf4\xe0\x9d\xb0Y\x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xf9\xc4\x8f[Iw\xf8\x89\xef\xcbQf\xcfh\xe3\x95\x8c\xebj&\xb9\xe2.\x8f\x0c\\ui\x89\xf1x\xf4\xd6\xc0kf\xc1\xf1v\xad(\xc4\xeb\x89~\xfa\xf0\x06\xa8\xa4\x7f\x93\xf4\xd7\x0c\xbcE#\xad\x92\xfc\xed\xeao\xefX\\\x03'
sage: loads(old_pickle)
[ 0 a]
[a + 1 1]
"""
from sage.matrix.matrix_space import MatrixSpace

MS = MatrixSpace(base_ring, nrows, ncols)
cdef Matrix_mod2e_dense A = Matrix_mod2e_dense.__new__(Matrix_mod2e_dense, MS, 0, 0, 0)
cdef Matrix_gf2e_dense A = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, MS, 0, 0, 0)
mzd_copy(A._entries.x, a._entries)
return A
14 changes: 0 additions & 14 deletions src/sage/matrix/matrix_mod2e_dense.pxd

This file was deleted.

Loading

0 comments on commit 1b32539

Please sign in to comment.