www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Example of append & rectangualar arrays?

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
Does anyone has an example using Appender with a rectangual array?

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
May 25 2019
parent reply 9il <ilyayaroshenko gmail.com> writes:
On Saturday, 25 May 2019 at 14:17:43 UTC, Robert M. Münch wrote:
 Does anyone has an example using Appender with a rectangual 
 array?
Appender!(T[][]) can append rows of type T[]. It does not check their lengths, the T[][] is an array of arrays, not a matrix. To append columns one needs an array of Appenders, Appenders!(T[])[]. T[][] can be converted to Slice!(T*, 2) (ndslice matrix) using the mir.ndslice.fuse module [1]. Then the matrix can be transposed. Zero cost transposition can be found in the second example at [1]. `ndarray` function can be used [2] to convert matrix back to an array of array. http://mir-algorithm.libmir.org/mir_ndslice_allocation.html#ndarray
May 27 2019
parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
On 2019-05-27 13:14:47 +0000, 9il said:

 Appender!(T[][]) can append rows of type T[]. It does not check their 
 lengths, the T[][] is an array of arrays, not a matrix.
 
 To append columns one needs an array of Appenders, Appenders!(T[])[].
And to have appenders on both dimensions? Appenders!(T[])Appenders!(T[]) --- not tested. I'm using dynamic arrays at the moment which works. As the amount of data is not very high, the overhead shouldn't be critical. My idea to use an appender instead of dynamic arrays was efficency.
 T[][] can be converted to Slice!(T*, 2) (ndslice matrix) using the 
 mir.ndslice.fuse module [1].
I took a look at mir, but as I understands it, it needs known dimension sizes (matrix). I don't have these, it's all dynamic.
 Then the matrix can be transposed. Zero cost transposition can be found 
 in the second example at [1].
 `ndarray` function can be used [2] to convert matrix back to an array of array.
Yes, as said I don't have a matrix more a collection of differently sized dynamic arrays. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
May 27 2019