Re: [sage-devel] Representation of LinearLayers in the crypto module

2018-07-06 Thread Friedrich Wiemer
Well, this seems to be due to another part of the file, I got a MWE to 
work, so I guess I will figure it out.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Representation of LinearLayers in the crypto module

2018-07-06 Thread Friedrich Wiemer
Ah, this looks good!

Interestingly, while this works in the sage notebook, changing it in the 
module results in an
sage: from sage.crypto.linearlayer import LinearLayerFactory
sage: LinearLayerFactory(GF(2))(MatrixSpace(GF(2), 2, 2), [1,0,0,1])
---
TypeError Traceback (most recent call last)
 in ()
> 1 LinearLayerFactory(GF(Integer(2)))(MatrixSpace(GF(Integer(2)), 
Integer(2), Integer(2)), [Integer(1),Integer(0),Integer(0),Integer(1)])

/home/asante/werkstatt/werkbank/sage/local/lib/python2.7/site-packages/sage/
crypto/linearlayer.pyc in LinearLayerFactory(K)
 53 def LinearLayerFactory(K):
 54 if K.characteristic() == 2 and K.degree() == 1:
---> 55 return type("LinearLayerGF2", (LinearLayer, 
Matrix_mod2_dense), {})
 56 if K.characteristic() == 2 and K.degree() >= 1:
 57 return type("LinearLayerGF2E", (LinearLayer, 
Matrix_gf2e_dense), {})

TypeError: metaclass conflict: the metaclass of a derived class must be a (
non-strict) subclass of the metaclasses of all its bases

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Representation of LinearLayers in the crypto module

2018-07-06 Thread 'Martin R. Albrecht' via sage-devel
Hi Friedrich,

I was thinking maybe something like this:

from sage.matrix.matrix_mod2_dense import Matrix_mod2_dense, 
from sage.matrix.matrix_gf2e_dense import Matrix_gf2e_dense

class LinearLayer:
def foo(self):
return self[0, 1]

def LinearLayerFactory(K):
if K.characteristic() == 2 and K.degree() == 1:
return type("LinearLayerGF2", (Matrix_mod2_dense, LinearLayer), {})
if K.characteristic() == 2 and K.degree() == 1:
return type("LinearLayerGF2E", (Matrix_gf2e_dense, LinearLayer), {})
else:
raise NotImplementedError

T = LinearLayerFactory(GF(2))

T(MatrixSpace(GF(2), 2, 2), [0, 1, 2, 3], False, False).foo()

Cheers,
Martin


Friedrich Wiemer  writes:
> Hi,
>
> I worked on an implementation of linear layers (basically a matrix over
> GF(2) or GF(2^n) with some special methods) in the crypto module during
> the sage days 94 and came up with this: #25735.
>
> Martin commented that it might make sense to just inherit from an
> appropriate matrix class, to avoid another layer of indirection. Seems a
> totally valid point for me, so I'm now trying to find out, what would be
> the appropriate inheritance. As we only need matrices over GF(2) or
> GF(2^n), I assume the correct super class would be their common super
> class Matrix_dense. But when I implement it, e.g. like this:
>
> %%cython
> cimport sage.matrix.matrix_dense as matrix_dense
> from sage.matrix.constructor import matrix
> cdef class LinearLayer(matrix_dense.Matrix_dense):
>   cdef public object _m
>  
>   def __init__(self, parent, entries=None):
> m = matrix(parent, entries)
> self._m = m
>
> the matrix self._m "forgets" that it was a Matrix_mod2_dense or
> Matrix_gf2e_dense before:
>
> test_m = random_matrix(GF(2**4), 4, 4)
> test_m.__class__.__mro__
> (,
> ,
> ,
> ,
> ,
> ,
> ,
> ,
> ,
> )
> LinearLayer(test_m.parent(), test_m)
> test1._m.__class__.__mro__
> (,
> ,
> ,
> ,
> ,
> ,
> ,
> ,
> ,
> )
>
> Thus operations which are specialised in Matrix_mod2_dense or 
> Matrix_gf2e_dense are not available anymore.
> Am I misunderstanding some concept here?
>
> Thanks in advance for your help,
> Friedrich


-- 

_pgp: https://keybase.io/martinralbrecht
_www: https://martinralbrecht.wordpress.com
_jab: martinralbre...@jabber.ccc.de
_otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Representation of LinearLayers in the crypto module

2018-07-06 Thread Friedrich Wiemer
Hi,

I worked on an implementation of linear layers (basically a matrix over 
GF(2) or GF(2^n) with some special methods) in the crypto module during the 
sage days 94 and came up with this: #25735.

Martin commented that it might make sense to just inherit from an 
appropriate matrix class, to avoid another layer of indirection. Seems a 
totally valid point for me, so I'm now trying to find out, what would be 
the appropriate inheritance. As we only need matrices over GF(2) or 
GF(2^n), I assume the correct super class would be their common super class 
Matrix_dense. But when I implement it, e.g. like this:

%%cython
cimport sage.matrix.matrix_dense as matrix_dense
from sage.matrix.constructor import matrix

cdef class LinearLayer(matrix_dense.Matrix_dense):
cdef public object _m

def __init__(self, parent, entries=None):
m = matrix(parent, entries)
self._m = m

the matrix self._m "forgets" that it was a Matrix_mod2_dense or 
Matrix_gf2e_dense before:

test_m = random_matrix(GF(2**4), 4, 4)
test_m.__class__.__mro__
(,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 )

LinearLayer(test_m.parent(), test_m)
test1._m.__class__.__mro__
(,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 )


Thus operations which are specialised in Matrix_mod2_dense or Matrix_gf2e_dense 
are not available anymore.
Am I misunderstanding some concept here?

Thanks in advance for your help,
Friedrich

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.