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

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

[Octave-patch-tracker] [patch #10314] matlab compatible std, var, mean,


From: Rik
Subject: [Octave-patch-tracker] [patch #10314] matlab compatible std, var, mean, median to core from statistics package
Date: Thu, 2 Mar 2023 13:28:17 -0500 (EST)

Follow-up Comment #4, patch #10314 (project octave):

On question 1, I found it easier to understand the reshape process if the
dimensions were at the end.  When indexing, you can use the magic colon ':' to
collapse all remaining dimensions and this is what the code reminded me of. 
For example,


x = reshape (1:24, 2,3,4)
x =

ans(:,:,1) =

   1   3   5
   2   4   6

ans(:,:,2) =

    7    9   11
    8   10   12

ans(:,:,3) =

   13   15   17
   14   16   18

ans(:,:,4) =

   19   21   23
   20   22   24

# Now preserve index 1 (rows) and collapse dimensions 2 and 3 into final
dimension (2 = columns)
x([1 2], :)
ans =

    1    3    5    7    9   11   13   15   17   19   21   23
    2    4    6    8   10   12   14   16   18   20   22   24

# Equivalently, use reshape
reshape (x, 2, 3*4)
ans =

    1    3    5    7    9   11   13   15   17   19   21   23
    2    4    6    8   10   12   14   16   18   20   22   24


When the dimensions are not at the end the reshape vector looks a bit awkward.
 From median, the code is


      ## Reshape all vecdims into dim1
      num_dim = prod (szx(dim));
      szx(dim) = [];
      szx = [num_dim, ones(1, numel(dim)-1), szx];
      x = reshape (x, szx);


I find the need to insert a vector of ones awkward.  But, it isn't a super big
deal and that's why I left it alone in median because it looked like it was
going to involve a fair number of changes to calls to sum() etc. where the
dimension would no longer be 1 but a variable 'dim'.  I'm okay, though, if we
want to rationalize this.

On question 2, that's weird that there is a performance penalty for using
true/false.  Was the performance penalty in the assignment 'flag = true' or
was it in the evaluation of 'if (flag)'?  I can kind of see that 'flag = true'
might be slower because true() is a function, whereas a number like 0 or 1 is
directly understood by the parser.  Still, I'm surprised it makes that much of
a difference.  


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/patch/?10314>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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