[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: data structure for simulation
From: |
Francesco Potorti` |
Subject: |
Re: data structure for simulation |
Date: |
Tue, 17 Mar 2009 23:12:40 +0100 |
>> This is an issue with cell arrays, in fact. I realise that my question
>> can be reformulated more simply like this:
>>
>> octave> a=cell(1e6,1);
>> octave> a(1e6)=1;
>> octave> whos a
>> Variables in the current scope:
>>
>> Attr Name Size Bytes Class
>> ==== ==== ==== ===== =====
>> a 1000000x1 8 cell
>>
>> Total is 1000000 elements using 8 bytes
>>
>> So Octave internally knows that only an element in the cell array is
>> nonempty and does not allocate memory for the whole array.
>
>No, that assumption is wrong. The whos output apparently does not
>include memory for array and octave_value internals.
>What you have in memory is indeed an array of million octave_value objects.
I see. Maybe whos should be more realistic? I normally use it to know
how much memory my variables need, so I think it is not useful if whos
tells me much less than the real memory usage.
>> But if I want to know the index of the nonempty cell, doing
>>
>> find (! cellfun (@isempty, a))
>>
>> needs a non-negligible computing time, because cellfun goes through all
>> elements, be they empty or not. I hoped there was an efficient way of
>> knowing indexes of nonempty elements.
>
>Well, you really need to go through all the elements, there's no way
>avoiding it. This expression
>is slow because you pass in a function handle, even though it's a
>built-in function.
I see.
>Cellfun allows also specifying certain mappers as special string, so you may
>try
>
>find (cellfun ("prodofsize", a))
>
>which seems to be specialized and thus significantly faster.
Yes, it is *much* faster, indeed, thanks!
This is undocumented, right?
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/
- data structure for simulation, Francesco Potorti`, 2009/03/17
- Re: data structure for simulation, Jaroslav Hajek, 2009/03/17
- Re: data structure for simulation, Francesco Potorti`, 2009/03/17
- Re: data structure for simulation, Francesco Potorti`, 2009/03/18
- Re: data structure for simulation, Michael Creel, 2009/03/18
- Re: data structure for simulation, Francesco Potorti`, 2009/03/18
- Re: data structure for simulation, Michael Creel, 2009/03/18
- Re: data structure for simulation, Francesco Potorti`, 2009/03/19
- Re: data structure for simulation, Michael Creel, 2009/03/20
- Re: data structure for simulation, Jaroslav Hajek, 2009/03/18
- Re: data structure for simulation, Francesco Potorti`, 2009/03/19
- Re: data structure for simulation, Jaroslav Hajek, 2009/03/19