Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we have addmul! for MatrixSpace #1177

Open
zhaoli-IHEP opened this issue Sep 17, 2021 · 6 comments
Open

Do we have addmul! for MatrixSpace #1177

zhaoli-IHEP opened this issue Sep 17, 2021 · 6 comments

Comments

@zhaoli-IHEP
Copy link

In our code, there are lots of operations like mat1 += mat2*mat3 for the objects MatrixSpace.
For example

using Nemo

const precision_digits = 256
const precision_bits =  round(Int64, precision_digits*log(10)/log(2) )

const RR = RealField(precision_bits)
const CC = ComplexField(precision_bits)

const ep_len = 5
const LSF, ep = LaurentSeriesField(CC, ep_len, "ep")

const lsfe = Generic.LaurentSeriesFieldElem{acb}
const mse = Generic.MatSpaceElem{lsfe}
const ms = Generic.MatSpace{lsfe}
const ms_acb = Generic.MatSpace{acb}


function test()

  mat1 = (zero∘ms)( LSF, 3, 3 )
  mat2 = (zero∘ms)( LSF, 3, 3 )
  mat3 = (zero∘ms)( LSF, 3, 3 )

  addmul!( mat1, mat2, mat3 )

  return nothing

end # function test

test()

But the error message told us there is no definition of addmul! for MatrixSpace.
Do we have any other approach for this? Or the code mat1 += mat2*mat3 has been the best for now?
Thank you!

@wbhart
Copy link
Contributor

wbhart commented Sep 17, 2021

If your matrices are square you can use MatrixAlgebras instead of MatrixSpaces and then in theory there should be something like addmul (I didn't check if it is actually there). But having said that, there really isn't much it can do. The main cost is in multiplying the matrices, not in allocating the result, I would have thought.

@zhaoli-IHEP
Copy link
Author

If your matrices are square you can use MatrixAlgebras instead of MatrixSpaces and then in theory there should be something like addmul (I didn't check if it is actually there). But having said that, there really isn't much it can do. The main cost is in multiplying the matrices, not in allocating the result, I would have thought.

Unfortunately, most of our matrices are not square. We were just wondering if there could be any improvement on the performance of matrix multiplication, since we found the matrix multiplication is the heaviest burden in our code.

@wbhart
Copy link
Contributor

wbhart commented Sep 17, 2021

I don't think we can save much. You can't actually mutate the entries in a matrix, according to our aliasing rules, so the only saving would be the allocation of the actual matrix itself, which is probably a trivial cost in comparison to the cost of the arithmetic.

Are your matrices 3x3 or larger? It should be easy enough for you to wrap the Arb matrix mul function to see if it makes any difference to you. But I doubt it. The larger the matrices, the more negligible the improvement would be.

@zhaoli-IHEP
Copy link
Author

I don't think we can save much. You can't actually mutate the entries in a matrix, according to our aliasing rules, so the only saving would be the allocation of the actual matrix itself, which is probably a trivial cost in comparison to the cost of the arithmetic.

Are your matrices 3x3 or larger? It should be easy enough for you to wrap the Arb matrix mul function to see if it makes any difference to you. But I doubt it. The larger the matrices, the more negligible the improvement would be.

The matrix could be much larger than this demo code. What do you mean by the "wrap"? We may have a trial on this.

@wbhart
Copy link
Contributor

wbhart commented Sep 17, 2021

I mean that you could add your own addmul! function to Nemo, making use of the acb_mat_mul and acb_mat_add functions (or addmul if it exists). If it turns out to be a big win for you, we could consider adding it to Nemo officially.

@zhaoli-IHEP
Copy link
Author

I mean that you could add your own addmul! function to Nemo, making use of the acb_mat_mul and acb_mat_add functions (or addmul if it exists). If it turns out to be a big win for you, we could consider adding it to Nemo officially.

Thank you! We will definitely share it if it indeed works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants