Timeline for I need to multiply a series of matrices
Current License: CC BY-SA 3.0
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 6, 2017 at 16:32 | comment | added | Jens | @L.K. I found this by experimentation - so unfortunately I don't have a general rule for the best choice right now. It might be interesting to do a series of experiments, but then I wouldn't necessarily trust if that remains true in the next version... | |
Apr 6, 2017 at 16:20 | comment | added | L.K. |
@Jens A small query UpTo why 4 ? How to decide this? Does this depend on matrix size(choice)?
|
|
Mar 31, 2016 at 14:17 | comment | added | Jens |
@Lukas I agree that some more experimentation is needed to find the optimal partition. You suggestion using $ProcessorCount sounds like a good guess - and I can't think of anything better if you can't hard-code the approximate dimensions.
|
|
Mar 31, 2016 at 10:52 | comment | added | Lukas |
@Jens Regarding the RecursionLimit , it might be worth mentioning that one could just use a minimum partition size of m=Ceiling[num/$RecursionLimit] where n is the total number of matrices. What I am actually interested in: do you (or someone else) have any intuition about how partition size has to be chosen such that it is at least somehow time-efficient? If this multiplication is part of a function and the number of matrices may vary dramatically from call to call, it is a NoGo for me to benchmark the partition size every time :( Might it be something like Max[m,$ProcessorCount] ?
|
|
Jan 14, 2016 at 20:21 | comment | added | lucian |
I completely missed UpTo ! I will give this a try definitely!
|
|
Jan 14, 2016 at 19:39 | history | edited | Jens | CC BY-SA 3.0 |
Speed up the method
|
Jan 14, 2016 at 19:28 | comment | added | Jens |
@lucian You can use the new UpTo to fix that problem. I'll add something to my answer shortly.
|
|
Jan 14, 2016 at 18:23 | comment | added | lucian |
I tried that and unfortunately it only works if the number of matrices is a power of 2. If not, Partition will drop the elements that it cannot pair and you end up with the wrong result...
|
|
Jan 14, 2016 at 17:54 | comment | added | Jens |
Maybe you can try to use Partition on your list, then ParallelEvaluate to use my answer on each sublist, then combine the results.
|
|
Jan 14, 2016 at 17:28 | comment | added | lucian | I know what you mean. I don't want to hijack this thread thou. I was just curious if parallelization was possible. | |
Jan 14, 2016 at 17:26 | comment | added | Jens | I think that won't be an issue in typical applications. But I'm only guessing. Problems tend to appear only at very specific wavelengths but those isolated points could be dropped. That's just my blind guess, not knowing anything about your case. | |
Jan 14, 2016 at 17:21 | comment | added | lucian | doesn't that mean that there is some truncating going on? i need this product to calculate the transmission coefficient through multi layers and I might end up with artefacts. | |
Jan 14, 2016 at 17:18 | comment | added | Jens |
If your matrices are numerical, you could try to speed things up by using machine-precision arithmetic, e.g. by wrapping the list in N before doing the product. That would be much more of a gain than trying to parallelize the product.
|
|
Jan 14, 2016 at 12:20 | comment | added | lucian | is there a way to parallelize this? I have a similar problem where I need to multiply a lot of 2x2 matrices in a list. I used your method and there doesn't seem to be a difference between that and using a Do loop to multiply them. This method is more elegant but not faster. | |
Dec 2, 2012 at 7:51 | comment | added | Jens | @NasserM.Abbasi lol, it's too late at night here... | |
Dec 2, 2012 at 7:18 | comment | added | Jens |
Yes, you could also take a List and change its head to Times if you want to get the normal multiplication of all elements in a list. But just to clarify: Dot is really very different from Times because conventional matrix multiplication is not commutative, whereas Times doesn't care about the order of the factors. BTW - strange that @NasserM.Abbasi appears here as your name. That's not you, right?
|
|
Dec 2, 2012 at 7:01 | history | answered | Jens | CC BY-SA 3.0 |