octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50854] zeros: like keyword


From: Rik
Subject: [Octave-bug-tracker] [bug #50854] zeros: like keyword
Date: Sun, 23 Apr 2017 10:19:43 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

Update of bug #50854 (project octave):

                Category:                    None => Octave Function        
                Severity:              3 - Normal => 1 - Wish               
                Priority:              5 - Normal => 2                      
                  Status:                    None => Confirmed              

    _______________________________________________________

Follow-up Comment #1:

Yeah.  Matlab has been this way for a while.  I happen to think it clutters
the interface to the matrix-producing functions like zeros, ones, etc., but
maybe it will get implemented.

A pretty easy hack, if one *really* needs this functionality, is to use
class().


A = single (1+i);
B = zeros (1, class (A));
whos ('B')
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  ===== 
        B           1x1                          4  single

Total is 1 element using 4 bytes


The complex attribute isn't really necessary to copy because Octave adjusts
matrices automatically as necessary to save memory.  If a matrix has all zero
imaginary parts t is automatically reduced to real to save memory. 
Conversely, if you assign a complex variable to a real matrix Octave will
conver the matrix to complex.  Using the example above.



octave:4> B(1) = 1+i
B =  1 + 1i
whos ('B')
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  ===== 
   c    B           1x1                          8  single

Total is 1 element using 8 bytes


Now B is taking up 8 bytes just as the Matlab variable does.


B(1) = 1
B =  1
octave:7> whos ('B')
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  ===== 
        B           1x1                          4  single

Total is 1 element using 4 bytes


And now it is back to requiring only 4 bytes.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50854>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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