Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Define functions before calling them
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Apr 21, 2017
1 parent 89e6ef4 commit 841676d
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 118 deletions.
138 changes: 71 additions & 67 deletions src/sage/matrix/matrix_modn_dense_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,77 @@ cdef inline linbox_charpoly(celement modulus, Py_ssize_t nrows, celement* entrie
del F
return l


cpdef __matrix_from_rows_of_matrices(X):
"""
Return a matrix whose row ``i`` is constructed from the entries of
matrix ``X[i]``.
INPUT:
- ``X`` - a nonempty list of matrices of the same size mod a
single modulus `n`
EXAMPLES::
sage: X = [random_matrix(GF(17), 4, 4) for _ in range(10)]; X
[
[ 2 14 0 15] [12 14 3 13] [ 9 15 8 1] [ 2 12 6 10]
[11 10 16 2] [10 1 14 6] [ 5 8 10 11] [12 0 6 9]
[ 9 4 10 14] [ 2 14 13 7] [ 5 12 4 9] [ 7 7 3 8]
[ 1 14 3 14], [ 6 14 10 3], [15 2 6 11], [ 2 9 1 5],
<BLANKLINE>
[12 13 7 16] [ 5 3 16 2] [14 15 16 4] [ 1 15 11 0]
[ 7 11 11 1] [11 10 12 14] [14 1 12 13] [16 13 8 14]
[ 0 2 0 4] [ 0 7 16 4] [ 5 5 16 13] [13 14 16 4]
[ 7 9 8 15], [ 6 5 2 3], [10 12 1 7], [15 6 6 6],
<BLANKLINE>
[ 4 10 11 15] [13 12 5 1]
[11 2 9 14] [16 13 16 7]
[12 5 4 4] [12 2 0 11]
[ 2 0 12 8], [13 11 6 15]
]
sage: X[0]._matrix_from_rows_of_matrices(X) # indirect doctest
[ 2 14 0 15 11 10 16 2 9 4 10 14 1 14 3 14]
[12 14 3 13 10 1 14 6 2 14 13 7 6 14 10 3]
[ 9 15 8 1 5 8 10 11 5 12 4 9 15 2 6 11]
[ 2 12 6 10 12 0 6 9 7 7 3 8 2 9 1 5]
[12 13 7 16 7 11 11 1 0 2 0 4 7 9 8 15]
[ 5 3 16 2 11 10 12 14 0 7 16 4 6 5 2 3]
[14 15 16 4 14 1 12 13 5 5 16 13 10 12 1 7]
[ 1 15 11 0 16 13 8 14 13 14 16 4 15 6 6 6]
[ 4 10 11 15 11 2 9 14 12 5 4 4 2 0 12 8]
[13 12 5 1 16 13 16 7 12 2 0 11 13 11 6 15]
OUTPUT: A single matrix mod ``p`` whose ``i``-th row is ``X[i].list()``.
.. note::
Do not call this function directly but use the static method
``Matrix_modn_dense_float/double._matrix_from_rows_of_matrices``
"""
# The code below is just a fast version of the following:
## from constructor import matrix
## K = X[0].base_ring()
## v = sum([y.list() for y in X],[])
## return matrix(K, len(X), X[0].nrows()*X[0].ncols(), v)

from matrix_space import MatrixSpace
cdef Matrix_modn_dense_template A, T
cdef Py_ssize_t i, n, m
n = len(X)

T = X[0]
m = T._nrows * T._ncols
A = T.__class__.__new__(T.__class__, MatrixSpace(X[0].base_ring(), n, m), 0, 0, 0)
A.p = T.p

for i from 0 <= i < n:
T = X[i]
memcpy(A._entries + i*m, T._entries, sizeof(celement)*m)
return A


cdef class Matrix_modn_dense_template(Matrix_dense):
def __cinit__(self, parent, entries, copy, coerce):
"""
Expand Down Expand Up @@ -2994,72 +3065,5 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
for j in range(self._ncols):
to[j] = <mod_int>_from[j]

cpdef __matrix_from_rows_of_matrices(X):
"""
Return a matrix whose row ``i`` is constructed from the entries of
matrix ``X[i]``.
INPUT:
- ``X`` - a nonempty list of matrices of the same size mod a
single modulus `n`

EXAMPLES::
sage: X = [random_matrix(GF(17), 4, 4) for _ in range(10)]; X
[
[ 2 14 0 15] [12 14 3 13] [ 9 15 8 1] [ 2 12 6 10]
[11 10 16 2] [10 1 14 6] [ 5 8 10 11] [12 0 6 9]
[ 9 4 10 14] [ 2 14 13 7] [ 5 12 4 9] [ 7 7 3 8]
[ 1 14 3 14], [ 6 14 10 3], [15 2 6 11], [ 2 9 1 5],
<BLANKLINE>
[12 13 7 16] [ 5 3 16 2] [14 15 16 4] [ 1 15 11 0]
[ 7 11 11 1] [11 10 12 14] [14 1 12 13] [16 13 8 14]
[ 0 2 0 4] [ 0 7 16 4] [ 5 5 16 13] [13 14 16 4]
[ 7 9 8 15], [ 6 5 2 3], [10 12 1 7], [15 6 6 6],
<BLANKLINE>
[ 4 10 11 15] [13 12 5 1]
[11 2 9 14] [16 13 16 7]
[12 5 4 4] [12 2 0 11]
[ 2 0 12 8], [13 11 6 15]
]
sage: X[0]._matrix_from_rows_of_matrices(X) # indirect doctest
[ 2 14 0 15 11 10 16 2 9 4 10 14 1 14 3 14]
[12 14 3 13 10 1 14 6 2 14 13 7 6 14 10 3]
[ 9 15 8 1 5 8 10 11 5 12 4 9 15 2 6 11]
[ 2 12 6 10 12 0 6 9 7 7 3 8 2 9 1 5]
[12 13 7 16 7 11 11 1 0 2 0 4 7 9 8 15]
[ 5 3 16 2 11 10 12 14 0 7 16 4 6 5 2 3]
[14 15 16 4 14 1 12 13 5 5 16 13 10 12 1 7]
[ 1 15 11 0 16 13 8 14 13 14 16 4 15 6 6 6]
[ 4 10 11 15 11 2 9 14 12 5 4 4 2 0 12 8]
[13 12 5 1 16 13 16 7 12 2 0 11 13 11 6 15]
OUTPUT: A single matrix mod ``p`` whose ``i``-th row is ``X[i].list()``.
.. note::
Do not call this function directly but use the static method
``Matrix_modn_dense_float/double._matrix_from_rows_of_matrices``
"""
# The code below is just a fast version of the following:
## from constructor import matrix
## K = X[0].base_ring()
## v = sum([y.list() for y in X],[])
## return matrix(K, len(X), X[0].nrows()*X[0].ncols(), v)

from matrix_space import MatrixSpace
cdef Matrix_modn_dense_template A, T
cdef Py_ssize_t i, n, m
n = len(X)

T = X[0]
m = T._nrows * T._ncols
A = T.__class__.__new__(T.__class__, MatrixSpace(X[0].base_ring(), n, m), 0, 0, 0)
A.p = T.p

for i from 0 <= i < n:
T = X[i]
memcpy(A._entries + i*m, T._entries, sizeof(celement)*m)
return A

1 change: 0 additions & 1 deletion src/sage/rings/multi_power_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@

from sage.rings.ring import CommutativeRing
from sage.rings.polynomial.all import PolynomialRing
from sage.rings.polynomial.polynomial_element import is_Polynomial
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.rings.polynomial.multi_polynomial import is_MPolynomial
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
Expand Down
2 changes: 0 additions & 2 deletions src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ from sage.rings.polynomial.polynomial_element cimport Polynomial
from sage.structure.element cimport ModuleElement, RingElement
from sage.structure.element import coerce_binop

from sage.rings.polynomial.polynomial_element cimport is_Polynomial

from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX

from sage.rings.integer_ring import ZZ
Expand Down
1 change: 0 additions & 1 deletion src/sage/rings/polynomial/polynomial_rational_flint.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ from sage.rings.fraction_field_element import FractionFieldElement
from sage.rings.rational cimport Rational
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_element cimport Polynomial
from sage.rings.polynomial.polynomial_element import is_Polynomial
from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint

from sage.structure.parent cimport Parent
Expand Down
94 changes: 47 additions & 47 deletions src/sage/sets/finite_set_map_cy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,53 @@ cdef class FiniteSetMap_MN(ClonableIntArray):
return res


cpdef FiniteSetMap_Set FiniteSetMap_Set_from_list(t, parent, lst):
"""
Creates a ``FiniteSetMap`` from a list
.. warning:: no check is performed !
TESTS::
sage: from sage.sets.finite_set_map_cy import FiniteSetMap_Set_from_list as from_list
sage: F = FiniteSetMaps(["a", "b"], [3, 4, 5])
sage: f = from_list(F.element_class, F, [0,2]); f.check(); f
map: a -> 3, b -> 5
sage: f.parent() is F
True
sage: f.is_immutable()
True
"""
cdef FiniteSetMap_MN res
cdef type cls = <type>t
res = cls.__new__(cls)
super(FiniteSetMap_MN, res).__init__(parent, lst)
return res

cpdef FiniteSetMap_Set FiniteSetMap_Set_from_dict(t, parent, d):
"""
Creates a ``FiniteSetMap`` from a dictionary
.. warning:: no check is performed !
TESTS::
sage: from sage.sets.finite_set_map_cy import FiniteSetMap_Set_from_dict as from_dict
sage: F = FiniteSetMaps(["a", "b"], [3, 4, 5])
sage: f = from_dict(F.element_class, F, {"a": 3, "b": 5}); f.check(); f
map: a -> 3, b -> 5
sage: f.parent() is F
True
sage: f.is_immutable()
True
"""
cdef FiniteSetMap_Set res
cdef type cls = <type>t
res = cls.__new__(cls)
res.__init__(parent, d.__getitem__)
return res


cdef class FiniteSetMap_Set(FiniteSetMap_MN):
"""
Data structure for maps
Expand Down Expand Up @@ -554,53 +601,6 @@ cdef class FiniteSetMap_Set(FiniteSetMap_MN):
return "map: "+", ".join([("%s -> %s"%(i, self(i))) for i in self.domain()])


cpdef FiniteSetMap_Set FiniteSetMap_Set_from_list(t, parent, lst):
"""
Creates a ``FiniteSetMap`` from a list
.. warning:: no check is performed !
TESTS::
sage: from sage.sets.finite_set_map_cy import FiniteSetMap_Set_from_list as from_list
sage: F = FiniteSetMaps(["a", "b"], [3, 4, 5])
sage: f = from_list(F.element_class, F, [0,2]); f.check(); f
map: a -> 3, b -> 5
sage: f.parent() is F
True
sage: f.is_immutable()
True
"""
cdef FiniteSetMap_MN res
cdef type cls = <type>t
res = cls.__new__(cls)
super(FiniteSetMap_MN, res).__init__(parent, lst)
return res

cpdef FiniteSetMap_Set FiniteSetMap_Set_from_dict(t, parent, d):
"""
Creates a ``FiniteSetMap`` from a dictionary
.. warning:: no check is performed !
TESTS::
sage: from sage.sets.finite_set_map_cy import FiniteSetMap_Set_from_dict as from_dict
sage: F = FiniteSetMaps(["a", "b"], [3, 4, 5])
sage: f = from_dict(F.element_class, F, {"a": 3, "b": 5}); f.check(); f
map: a -> 3, b -> 5
sage: f.parent() is F
True
sage: f.is_immutable()
True
"""
cdef FiniteSetMap_Set res
cdef type cls = <type>t
res = cls.__new__(cls)
res.__init__(parent, d.__getitem__)
return res


cdef class FiniteSetEndoMap_N(FiniteSetMap_MN):
"""
Maps from ``range(n)`` to itself.
Expand Down

0 comments on commit 841676d

Please sign in to comment.