octave-maintainers
[Top][All Lists]
Advanced

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

Bug Fix: datenum with Mixed Input


From: Bill Denney
Subject: Bug Fix: datenum with Mixed Input
Date: Sun, 18 May 2008 00:12:32 -0400
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

Attached is a changeset that allows for mixed scalar and vector/matrix input for datenum. I view this as a bug fix because datenum could handle mixed scalar and vector input in some variables before this, but not in the month and day variables.

Have a good day,

Bill
# HG changeset patch
# User address@hidden
# Date 1211083748 14400
# Node ID e671d5e18e4aaea7b64449b9d021fe0d3db600a7
# Parent  a4f25bf9443fc61a9b13dfc48e4288a1ed828ad4
datenum\: fixed combination of scalar and vector/matrix input bug

diff -r a4f25bf9443f -r e671d5e18e4a scripts/ChangeLog
--- a/scripts/ChangeLog Sun May 18 00:01:09 2008 -0400
+++ b/scripts/ChangeLog Sun May 18 00:09:08 2008 -0400
@@ -1,3 +1,8 @@
+2008-05-17  Bill Denney  <address@hidden>
+
+       * time/datenum.m: Allow mixed scalar and vector/matrix input 
+       (and add tests for such)
+
 2008-05-13  Bill Denney  <address@hidden>
 
        * general/isa.m: Use persistent cell arrays to hold class names
diff -r a4f25bf9443f -r e671d5e18e4a scripts/time/datenum.m
--- a/scripts/time/datenum.m    Sun May 18 00:01:09 2008 -0400
+++ b/scripts/time/datenum.m    Sun May 18 00:09:08 2008 -0400
@@ -99,7 +99,16 @@
   Y += fix ((M-14)/12);
 
   ## Lookup number of days since start of the current year.
-  D += reshape (monthstart (mod (M-1,12) + 1), size (D)) + 60;
+  if numel (M) == 1 || numel (D) == 1
+    ## Allow M or D to be scalar while other values may be vectors or
+    ## matrices.
+    D += monthstart (mod (M-1,12) + 1) + 60;
+    if numel (M) > 1
+      D = reshape (D, size (M));
+    endif
+  else
+    D += reshape (monthstart (mod (M-1,12) + 1), size (D)) + 60;
+  endif
 
   ## Add number of days to the start of the current year. Correct
   ## for leap year every 4 years except centuries not divisible by 400.
@@ -130,3 +139,18 @@
 %! t = [2001,5,19,12,21,3.5; 1417,6,12,12,21,3.5]';
 %! n = [730990 517712] + part;
 %! assert(datenum(t(1,:), t(2,:), t(3,:), t(4,:), t(5,:), t(6,:)), n, 2*eps);
+
+## Test mixed vectors and scalars
+%!assert (datenum([2008;2009], 1, 1), [datenum(2008, 1, 1);datenum(2009, 1, 
1)]);
+%!assert (datenum(2008, [1;2], 1), [datenum(2008, 1, 1);datenum(2008, 2, 1)]);
+%!assert (datenum(2008, 1, [1;2]), [datenum(2008, 1, 1);datenum(2008, 1, 2)]);
+%!assert (datenum([2008;2009], [1;2], 1), [datenum(2008, 1, 1);datenum(2009, 
2, 1)]);
+%!assert (datenum([2008;2009], 1, [1;2]), [datenum(2008, 1, 1);datenum(2009, 
1, 2)]);
+%!assert (datenum(2008, [1;2], [1;2]), [datenum(2008, 1, 1);datenum(2008, 2, 
2)]);
+## And the other orientation
+%!assert (datenum([2008 2009], 1, 1), [datenum(2008, 1, 1) datenum(2009, 1, 
1)]);
+%!assert (datenum(2008, [1 2], 1), [datenum(2008, 1, 1) datenum(2008, 2, 1)]);
+%!assert (datenum(2008, 1, [1 2]), [datenum(2008, 1, 1) datenum(2008, 1, 2)]);
+%!assert (datenum([2008 2009], [1 2], 1), [datenum(2008, 1, 1) datenum(2009, 
2, 1)]);
+%!assert (datenum([2008 2009], 1, [1 2]), [datenum(2008, 1, 1) datenum(2009, 
1, 2)]);
+%!assert (datenum(2008, [1 2], [1 2]), [datenum(2008, 1, 1) datenum(2008, 2, 
2)]);

reply via email to

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