Ask Your Question

M. H. M.'s profile - activity

2018-02-08 03:30:45 +0200 received badge  Famous Question (source)
2015-11-30 00:24:58 +0200 received badge  Notable Question (source)
2015-11-30 00:24:58 +0200 received badge  Popular Question (source)
2014-05-08 11:01:40 +0200 received badge  Supporter (source)
2013-07-11 08:42:41 +0200 answered a question maximum element of a matrix

I tried to do this a while ago but couldn't do it in one step. I just went through all the columns and got their maximum. I also needed to find the location of the maximum.

Example for a matrix M with type 'sage.matrix.matrix_real_double_dense.Matrix_real_double_dense'

MAX_val=0
for i in range(len(M.columns())):
  if (MAX_val< max(M.column(i))):
    MAX_val=max(M.column(i))

MAX_val is then the maximum value in the matrix. I hope it was helpful. I ll follow to see if there is a better way.

2013-07-09 10:10:12 +0200 commented answer How to prevent memory leak when solving a linear system of equations using left_kernel ?

I added my code in the question. I tried to upload the matrix for you but I do not have enough karma

2013-07-09 06:48:28 +0200 commented answer How to prevent memory leak when solving a linear system of equations using left_kernel ?

I am new to this system. How can I paste a code in the comment part. In the answer part I can just click on "Insert code" icon.

2013-07-08 12:17:33 +0200 commented answer How to prevent memory leak when solving a linear system of equations using left_kernel ?

I start with a list of vectors and then transform it to a matrix. So I write mat=matrix(W,mat) instead of mat=matrix(mat). where: m=6 q=2^m P=GF(q,'a') W.<x> = PolynomialRing(P)

2013-07-08 12:16:19 +0200 answered a question How to prevent memory leak when solving a linear system of equations using left_kernel ?

I solved my problem by changing the type of the elements from Symbolic ring to Univariate Polynomial Ring in x over Finite Field in a of size 2^6.

However, if it remained as a matrix with elements from the Symbolic ring. The leak would still exist.

2013-07-08 12:09:49 +0200 commented answer How to prevent memory leak when solving a linear system of equations using left_kernel ?

I changed the type of the elements inside the matrix from Symbolic ring to Univariate Polynomial Ring in x over Finite Field in a of size 2^6. Now it works fine without a leak. I do not know why. Thanks for the help. You gave me the idea to change it. What should I do now that I have my problem solved. Also I would like to point out the problem when it was Symbolic?

2013-07-08 11:50:39 +0200 received badge  Editor (source)
2013-07-08 11:33:34 +0200 commented answer How to prevent memory leak when solving a linear system of equations using left_kernel ?

I tried it before but it didnt help. This is the result I get when I use your code: (using my mat of course) 1133.46875 1153.5234375 1174.0078125 1178.21875 1198.9296875 .....

2013-07-08 11:33:02 +0200 received badge  Nice Question (source)
2013-07-08 11:16:18 +0200 received badge  Student (source)
2013-07-08 09:00:19 +0200 asked a question How to prevent memory leak when solving a linear system of equations using left_kernel ?

I am having a problem when running the left_kernel function multiple times. Every time I call the function It takes a new part of the memory although I do not create new variables. I tried finding out where does the memory disappear, but without any luck. here is an example code:

    sage: mat
    69 x 70 dense matrix over Symbolic Ring (type 'print mat.str()' to see all of the entries)
    sage: get_memory_usage() #memory check before call
    1170.34765625
    sage: Inter_mat=mat.transpose() 
    sage: Solution=Inter_mat.left_kernel()
    sage: get_memory_usage() #memory check after 1st call
    1190.5390625
    sage: Inter_mat=mat.transpose()
    sage: Solution=Inter_mat.left_kernel()
    sage: get_memory_usage()  #memory check after 2nd call
    1194.73828125
    sage: Inter_mat=mat.transpose()
    sage: Solution=Inter_mat.left_kernel()
    sage: get_memory_usage()  #memory check after 3rd call
    1217.76953125

As you can see every time I call the function, the memory usage increases. Is there a way to release the memory that was used in a previous call ? My program stops after a few iterations because of lack of memory.

Update: (Creating the matrix "mat")

mat=[]
for Coord in range(len(M_col)):
  if(M[M_row[Coord],M_col[Coord]]!=0):
    s=M[M_row[Coord],M_col[Coord]]
    if(s==1):
      temp_v=vector(Poly)(x=a^M_col[Coord],y=FIELDinfoBook[M_row[Coord]])
      mat.append(vector(W,temp_v))
    else:
      up=[i for i in range(s)]
      down=list(up)
      down.reverse()
      for Cup in range(s):
        for Cdown in range(s):
          if(up[Cup]+down[Cdown]<s):
            temp_v=list(zero_vector(sum(Len_Poly)))
            for j in range(down[Cdown],l+1):
              for i in range(up[Cup],Len_Poly[j]):
            comb1=len(Combinations(j,down[Cdown]).list())
            comb2=len(Combinations(i,up[Cup]).list())
            temp=comb1*comb2*x^(i-up[Cup])*y^(j-down[Cdown])
            temp=temp(x=a^M_col[Coord],y=FIELDinfoBook[M_row[Coord]])
            temp_v[Len_Poly_inc[j]+i]=(temp)
              mat.append(vector(temp_v))

The matrix M is a sparse matrix with integers (mostly ones) at certain positions. M_col and M_row are lists with the locations of nonzero elements.

sage: M
64 x 63 dense matrix over Integer Ring (type 'print M.str()' to see all of the entries)

Poly is a list of bivariate polynomials created like this:

Poly=[]
    for j in range(l+1):
      for i in range(Len_Poly[j]):
        Poly.append(x^i*y^j)

And l=1 , Len_poly=[63, 7] and Len_poly_inc=[0, 63, 70]