Opened 7 years ago
Closed 7 years ago
#19492 closed enhancement (fixed)
Optimize linear codes: __eq__, dual_code and commented debug lines
Reported by:  David Lucas  Owned by:  

Priority:  major  Milestone:  sage7.0 
Component:  coding theory  Keywords:  
Cc:  Merged in:  
Authors:  David Lucas  Reviewers:  Vincent Delecroix 
Report Upstream:  N/A  Work issues:  
Branch:  b869837 (Commits, GitHub, GitLab)  Commit:  b869837b6732e6c0d9458e18c48abb4957e63387 
Dependencies:  Stopgaps: 
Description
Some code in LinearCode.py
is quite old and/or slow, and could be optimized.
This tickets proposes a faster implementation for __eq__
and dual_code
methods.
It also removes a lot of commented debug lines.
Change History (12)
comment:1 Changed 7 years ago by
Branch:  → u/dlucas/clean_linear_code 

comment:2 Changed 7 years ago by
Authors:  → David Lucas 

Commit:  → d64c3603f5f870f4d35cfd85ce74c01c5fd6a4f9 
Status:  new → needs_review 
comment:3 Changed 7 years ago by
Summary:  Cleaning linear codes: __eq__, dual_code and commented debug lines → Optimize linear codes: __eq__, dual_code and commented debug lines 

comment:4 Changed 7 years ago by
Milestone:  sage6.10 → sage7.0 

Status:  needs_review → needs_work 
The following would be cleaner on two lines.
+ Ks, rbas = self.parity_check_matrix().right_kernel(), right.gens()
Otherwise it looks good.
comment:5 Changed 7 years ago by
Commit:  d64c3603f5f870f4d35cfd85ce74c01c5fd6a4f9 → f3a7f0790113ce41b9822ea7722796afbaa8342d 

Branch pushed to git repo; I updated commit sha1. New commits:
f3a7f07  Integrated reviewer's comment

comment:6 Changed 7 years ago by
Status:  needs_work → needs_review 

Thanks for your input.
I changed the code to what you suggested. I also fixed a silly copypaste mistake two lines below the one you mentioned.
David
comment:7 Changed 7 years ago by
While you are at it, the print statements like
print " t = ",t," , v = ",n," , k = ",w," , lambda = ",wts[w]*binomial(w,t)/binomial(n,t)
are really ugly. Could you do something cleaner like
print "t={} v={} k={} lambda={}".format(t, n, w, wts[w]*binomial(w,t)/binomial(n,t))
comment:8 Changed 7 years ago by
Even better would be
print("t={} v={} k={} lambda={}".format(t, n, w, wts[w]*binomial(w,t)/binomial(n,t)))
since that's compatible with Python 2 and 3.
comment:9 Changed 7 years ago by
Commit:  f3a7f0790113ce41b9822ea7722796afbaa8342d → b869837b6732e6c0d9458e18c48abb4957e63387 

Branch pushed to git repo; I updated commit sha1. New commits:
b869837  Changed some print statements to something cleaner

comment:11 Changed 7 years ago by
Reviewers:  → Vincent Delecroix 

Status:  needs_review → positive_review 
comment:12 Changed 7 years ago by
Branch:  u/dlucas/clean_linear_code → b869837b6732e6c0d9458e18c48abb4957e63387 

Resolution:  → fixed 
Status:  positive_review → closed 
Let
C
be a linear code withH
a parity check matrix ofC
. The generator matrix ofC
's dual isH
. I made changes inAbstractLinearCode
'sdual_code
method to use that property instead of the old implementation and got something faster.I also rewrote
AbstractLinearCode
's__eq__
which is now less heavy and a bit faster.Finally, I removed a lot of old debug prints that were still present in this file as commented lines.
This is now ready for review.
New commits:
Changes in dual_code method
Changes in __eq__ method, removed commented debug lines