[erlang-questions] Generating a list of lists containing random numbers
Hugo Mills
<>
Wed Jul 4 15:19:27 CEST 2018
On Wed, Jul 04, 2018 at 02:03:42PM +0200, wrote:
> Are lists not collections of varying size, that tend to grow
> or shrink? (there is a tuple_size/1 but no lists:size/1)
> and to contain things of not necessarily the same type? (e.
> g. proplists)?
>
> Are vectors and matrices not of rather fixed dimensions and
> tend to contain similar things (e. g. R^3, or in this thread
> R^1000, or Z^1000, or N^1000)?
>
> When I think "matrix", things that come to mind are:
>
> * {...} (tuple) and element(3, element(2, M)) and
> setelement/3, ...,
>
> * stdlib's array:get(3, array:get(2, A)),
>
> * and in this case especially: array:map(Fun, A).
>
> But these are just some stranger's thoughts ...
Most numerics libraries use single-dimensional lists for storage,
and turn the (i, j) locations of the matrix into (i*width+j) to look
it up in the list, because it's generally more efficient to do so with
random-access data.
If you look at the numerics libraries, the general assumption is
that you have linear random-access storage of the data, and then a
thin translation layer on top of that which converts (i, j)
coordinates to the linear location.
Note also that there are generalisations to matrices which have
more than two indices (and are hence written as n*m*p*q*... objects),
which are used in some things like general relativity. These are
handled in exactly the same way, with a slightly different, but
generalisable, translation function.
There are definitely algorithms which require taking slices out of
matrices, for example, building the (n-1)*(n-1) matrix consisting of
every row that isn't row i, and every column that isn't column j of
some n*n matrix. Similarly, there are some algorithms which use block
decompositions of matrices (say, the four n/2*n/2 square matrices
making up the whole n*n). Both of these can be done quite easily by,
again, generating specific translation functions to map to the
underlying linear matrix.
So, as long as you can do a linear random-access storage unit
(probably what erlang's array module was designed for in the first
place), you can build all fo the useful things on top of that with
appropriate [stacks of] coordinate translation functions.
Hugo.
--
Hugo Mills | Stick them with the pointy end.
carfax.org.uk |
http://carfax.org.uk/ |
PGP: E2AB1DE4 | Jon Snow
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180704/2af58de0/attachment.bin>
More information about the erlang-questions
mailing list