help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make a matrix with all combinations of digits efficiently


From: Francesco Potortì
Subject: Re: how to make a matrix with all combinations of digits efficiently
Date: Fri, 29 Dec 2017 14:51:53 +0100

>2017-12-29 0:07 GMT+01:00 Juan Pablo Carbajal <address@hidden>:
>> On Thu, Dec 28, 2017 at 9:25 PM, Jean Dubois <address@hidden> wrote:
>>> I'd like to generate a matrix like this (small version to give you the 
>>> idea):
>>>
>>> 0 0 0 (three columns in this example)
>>> 0 0 1
>>> 0 0 2
>>> 0 0 3
>>> .
>>> .
>>> .
>>> 9 9 8
>>> 9 9 9
>>>
>>> Could anyone here show me how to do this efficiently?

[...]

>Dear Juan,
>I bumped into the following problem. I changed your code to a function
>like this:
>
>function [counter] = decomp (base, nc)
>i            = (0:(base^nc-1)).'; # row index - 1
>counter = mod( floor (i ./ base.^[(nc-1):-1:0]), base);
>endfunction
>
>It works fine for a lot of cases but the case I want to use is
>problematic as you can see here:
>result=decomp(10,9);
>error: out of memory or dimension too large for Octave's index type

decomp(B,C) creates a matrix with B^C rows and C columns.  In the case
you tested this means 9e9 elements.  Each element is a double needing 8
bytes, which means that you need 72GB of memory only for hosting the
final result.  In practice, you need additional space for hosting
intermediate variables.

This is the only problem if Octave has been specially compiled for using
64-bit indexes, which is not the general case, and most probably not
your case.

For the general case, have a look at
https://wiki.octave.org/Enable_large_arrays:_Build_octave_such_that_it_can_use_arrays_larger_than_2Gb.

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it




reply via email to

[Prev in Thread] Current Thread [Next in Thread]