[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek fo
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility |
Date: |
Thu, 23 Sep 2021 14:38:19 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 |
Follow-up Comment #11, bug #61199 (project octave):
here are a handful of matlab-compatibility BISTs if we're trying to hit most
things discussed here (chars, cells, structs), with output based on Matlab
2021a (ignoring char and string differentiation. it sees "abc" as a single
string element, but 'abc' as a 3-element char array.)
##char inputs
%!assert (nchoosek ("A", 0), char (ones (1,0)))
%!assert (class (nchoosek ("A", 0)), "char")
%!assert (nchoosek ("A", 2), char (ones (0,2)))
%!assert (class (nchoosek ("A", 2)), "char")
%!assert (nchoosek ("A", 1), "A")
%!assert (class (nchoosek ("A", 1)), "char")
%!assert (nchoosek (["AB"], 1), ["A"; "B"])
%!assert (nchoosek (["A"; "B"], 1), ["A"; "B"])
%!assert (nchoosek (["AB"], 2), "AB")
%!assert (nchoosek (["A"; "B"], 2), "AB")
%!assert (sort (nchoosek (["A"; "B"; "C"], 2)),["AB"; "AC"; "BC"])
##cell inputs (undocumented)
%!assert (nchoosek ({1,2,3}, 1), {[1]; [2]; [3]})
%!assert (nchoosek ({1,2,3}, 3), {[1], [2], [3]})
%!assert (nchoosek ({1,2,3}, 2), {[1], [2]; [1], [3]; [2], [3]})
%!assert (nchoosek ({[1 4], 2, 3}, 1), {[1 4]; [2]; [3]})
%!assert (nchoosek ({[1 4], 2, "Ab"}, 1), {[1 4]; [2]; "Ab"})
%!assert (nchoosek ({{1}, {2}, {3}}, 1), {{1}; {2}; {3}})
%!assert (nchoosek ({{1}, {2}, {3}}, 3), {{1}, {2}, {3}})
%!test ##struct/ struct array inputs (undocumented)
%! A.a = [1 2 3];
%! A.b = [4 5 6];
%! assert (nchoosek (A, 1), A)
%! assert (nchoosek (A, 2), struct("a",[],"b",[]))
## not quite right, should be 0x2 struct array with
## empty fields a and b (not [] or "", just 'empty')
## but can't recreate that in Octave (or Matlab with struct.empty)
%! A(2).a = [7 8 9];
%! A(2).b = [10 11 12];
%! assert (size (A), [1 2]);
%! B = nchoosek (A, 1);
%! assert (size (B), [2 1]);
%! assert ({A(1),A(2)}, {B(1),B(2)});
%! C = nchoosek (A, 2);
%! assert (size (B), [1 2]);
%! assert ({A(1),A(2)}, {C(1),C(2)});
%! A(3).a = [13 14 15];
%! A(3).b = [16 17 18];
%! D = nchoosek (A, 1);
%! assert (size (D), [3 1]);
%! assert ({A(1),A(2),A(3)}, {D(1),D(2),D(3)});
%! E = nchoosek (A, 3);
%! assert (size (E), [1 3]);
%! assert ({A(1),A(2),A(3)}, {E(1),E(2),E(3)});
%! F = nchoosek (A, 2);
%! assert (size (F), [3 2]);
%! assert ({E(1),E(2),E(3),E(4),E(5),E(6)}, {A(1),A(1),A(2),A(2),A(3),A(3)});
%!error (nchoosek (["Ab"; "Cd"], 1)) ##only scalars or vectors
most of these don't run through the current nchoosek, so couldn't test all
those for syntax, etc., but verified 'intent' over in matlab.
based on the empty outputs, I'm guessing matlab preallocates an array with
size (m, k), m is calculated from n and k, and if zero it just results in
size(0,k) when k>n. Then k=0 gives size(m,0), and m is either calculated or
set to 1 in that case.
I've had a heck of a time trying to get empty outputs matlab compatible in a
couple of cases. Seems it usually shouldn't matter, but its always possible
someone will expect it to be for later empty math consistency.
https://octave.org/doc/v6.3.0/Empty-Matrices.html#Empty-Matrices
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?61199>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #61199] Input validation for nchoosek, (continued)
- [Octave-bug-tracker] [bug #61199] Input validation for nchoosek, anonymous, 2021/09/21
- [Octave-bug-tracker] [bug #61199] Input validation for nchoosek, anonymous, 2021/09/21
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Rik, 2021/09/22
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, John W. Eaton, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, anonymous, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, anonymous, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Rik, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, John W. Eaton, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Rik, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, John W. Eaton, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility,
Nicholas Jankowski <=
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Rik, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Nicholas Jankowski, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, John W. Eaton, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Rik, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Nicholas Jankowski, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Nicholas Jankowski, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, John W. Eaton, 2021/09/23
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, anonymous, 2021/09/24
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, Philip Nienhuis, 2021/09/24
- [Octave-bug-tracker] [bug #61199] Allow 'char' input sets to nchoosek for Matlab compatibility, anonymous, 2021/09/24