How to use Shuffle.c index mode for complex numbers
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sharon Yakim
il 14 Apr 2020
Commentato: James Tursa
il 15 Apr 2020
I want to shuffle a 3d array within the third dimension using Shuffle.c. Till now I have used Shuffle(arr,3) with great performance. Now I try to do the same, but with array of Complex numbers and get this Error:
*** Shuffle[mex]: Use index mode for complex input!
I haven't found the proper way to use index mode.
Thank you.
5 Commenti
James Tursa
il 15 Apr 2020
Shuffling the new interleaved complex data directly in R2018a or later will require code changes. Fairly easy to do, but I don't know if Jan plans on these updates. If not, I could probably do it.
Risposta accettata
Walter Roberson
il 14 Apr 2020
From the source code:
// 2. INDEX MODE: Index = Shuffle(N, 'index', NOut) --------------------------
// A vector of shuffled indices is created as by RANDPERM, but faster and using
// the smallest possible integer type to save memory. The number of output
// elements can be limited. This method works for cells, structs or complex
// arrays also.
// INPUT:
// N: Numeric scalar >= 0.
// String: 'index'.
// NOut: Optional, number of outputs, NOut <= N. Default: N.
// OUTPUT:
// Index: [1 x nOut] vector containing the shuffled elements of the vector
// [1:N] vector. To limit the memory usage the smallest possible type
// is used: UINT8/16/32 or INT64.
So you need to call Shuffle() with the 'index' option. In that mode you cannot use the dim option.
A complex example is given in the comments:
// M = rand(3) + i * rand(3); SM = M(:, Shuffle(size(C, 2), 'index'))
You would use
Sarr = arr(:,:,Shuffle(size(arr,3), 'index'));
Più risposte (1)
James Tursa
il 14 Apr 2020
Modificato: James Tursa
il 14 Apr 2020
Note: Compiling mex code in R2018a or later with the '-R2017b' option will cause the mex routine to make deep copies of all complex inputs & outputs. This may greatly negate any speed advantage that the mex routine may have had for these arguments. To gain that speed advantage back the mex source code may have to be rewritten to be compiled with '-R2018a' option.
3 Commenti
Walter Roberson
il 15 Apr 2020
in this case, Jan's code is detecting complex and refusing to run, so any complex support would be an enhancement.
James Tursa
il 15 Apr 2020
I took a look at the code and yes it will need source code changes to operate properly in R2018a+. The changes would not be difficult to do, simply adding routines for 16-byte data types and some minor up-front changes. I dropped a note to Jan on the FEX to see if there are any update plans for this.
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!