# HG changeset patch # User jwe # Date 1109828995 0 # Node ID 41cd70503c72597ed8c8b0c5181b1d0d3e624af9 # Parent e7438487c8574778f8715fb259abdafaaf4015b3 [project @ 2005-03-03 05:49:55 by jwe] diff -r e7438487c857 -r 41cd70503c72 scripts/ChangeLog --- a/scripts/ChangeLog Thu Mar 03 05:33:45 2005 +0000 +++ b/scripts/ChangeLog Thu Mar 03 05:49:55 2005 +0000 @@ -1,3 +1,8 @@ +2005-03-03 Paul Kienzle + + * statistics/distributions/binomial_pdf.m: Extend the feasible + computation range. + 2005-02-25 John W. Eaton Sparse merge. diff -r e7438487c857 -r 41cd70503c72 scripts/general/isequal.m --- a/scripts/general/isequal.m Thu Mar 03 05:33:45 2005 +0000 +++ b/scripts/general/isequal.m Thu Mar 03 05:49:55 2005 +0000 @@ -1,58 +1,78 @@ ## Copyright (C) 2000 Paul Kienzle ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +## This file is part of Octave. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA. ## isequal(x1, x2, ...) ## true if all parts of x1, x2, ... are equal -function t = isequal(x,varargin) - if nargin != 2 - usage("isequal(x,y,...)"); +## Author: Paul Kienzle +## Adapted-by: jwe + +function t = isequal (x, varargin) + + if (nargin != 2) + usage ("isequal (x, y, ...)"); endif - for arg = 1:length(varargin) + for arg = 1:length (varargin) y = varargin{arg}; - if isstruct(x) + if (isstruct (x)) t = isstruct (y); for [v, k] = x - t = t && struct_contains (y, k) && isequal (getfield(x,k), getfield(y,k)); + t = (t + && struct_contains (y, k) + && isequal (getfield (x, k), getfield (y, k))); endfor - for [v,k] = y + for [v, k] = y t = t && struct_contains (x, k); endfor - elseif islist(x) + elseif (islist (x)) t = islist(y) && length(x) == length(y); - if !t, return; endif - for i = 1:length(x) + if (! t) + return; + endif + for i = 1:length (x) t = isequal (x{i}, y{i}); - if !t, return; endif + if (! t) + return; + endif endfor - elseif any (size (x) != size (y)) + elseif (any (size (x) != size (y))) t = false; - elseif iscell(x) || islist(x) - t = iscell (y) || islist(y); - if !t, return; endif - x = x (:); - y = y (:); - for i = 1:length(x) + elseif (iscell (x) || islist (x)) + t = iscell (y) || islist (y); + if (! t) + return; + endif + x = x(:); + y = y(:); + for i = 1:length (x) t = isequal (x{i}, y{i}); - if !t, return; endif + if (! t) + return; + endif endfor else - t = all (x (:) == y (:)); + t = all (x(:) == y(:)); endif - if !t, return; endif + if (! t) + return; + endif endfor + endfunction diff -r e7438487c857 -r 41cd70503c72 scripts/general/sortrows.m --- a/scripts/general/sortrows.m Thu Mar 03 05:33:45 2005 +0000 +++ b/scripts/general/sortrows.m Thu Mar 03 05:49:55 2005 +0000 @@ -1,18 +1,21 @@ ## Copyright (C) 2000 Daniel Calvelo ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +## This file is part of Octave. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA. ## B = sortrows (A) ## returns matrix with rows sorted "lexicographically" @@ -24,38 +27,37 @@ ## Set implicit_str_to_num_ok and implicit_num_to_str_ok to 1 if you ## use this for string sorting and octave 2.1.50 or earlier. -## Author: Daniel Calvelo -## 2001-02-24 Paul Kienzle -## * cleanup according to Octave conventions -## * return reverse index -## * handle string arguments +## Author: Daniel Calvelo, Paul Kienzle +## Adapted-by: jwe function [s, i] = sortrows (m, c) - if nargin < 2 - indices = [ 1 : size(m,2) ]'; + if (nargin < 2) + indices = [1:size(m,2)]'; else - indices = c (:); + indices = c(:); endif - if (isstr (m)) + if (isstr (m)) s = toascii (m); else s = m; endif - ## since sort is 'stable' the order of identical elements will be - ## preserved, so by traversing the sort indices in reverse order - ## we will make sure that identical elements in index i are subsorted - ## by index j. + ## Since sort is 'stable' the order of identical elements will be + ## preserved, so by traversing the sort indices in reverse order we + ## will make sure that identical elements in index i are subsorted by + ## index j. indices = flipud (indices); - i = [1 : size(m,1)]'; - for ii = 1 : length (indices); - [ trash, idx ] = sort ( s ( : , indices (ii) ) ); - s = s ( idx, : ); - i = i (idx ); + i = [1:size(m,1)]'; + for ii = 1:length (indices); + [trash, idx] = sort (s(:,indices(ii))); + s = s(idx,:); + i = i(idx); endfor + if (isstr (m)) - s = setstr(s); + s = setstr (s); endif + endfunction diff -r e7438487c857 -r 41cd70503c72 scripts/set/ismember.m --- a/scripts/set/ismember.m Thu Mar 03 05:33:45 2005 +0000 +++ b/scripts/set/ismember.m Thu Mar 03 05:49:55 2005 +0000 @@ -1,18 +1,21 @@ ## Copyright (C) 2000 Paul Kienzle ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +## This file is part of Octave. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} ismember(@var{A}, @var{S}) @@ -23,23 +26,27 @@ ## @end deftypefn ## @seealso{unique, union, intersect, setxor, setdiff} -function c = ismember(a,S) - if nargin != 2 - usage("ismember(A,S)"); +## Author: Paul Kienzle +## Adapted-by: jwe + +function c = ismember (a, S) + + if (nargin != 2) + usage ("ismember (A, S)"); endif - [ra, ca] = size(a); - if isempty(a) || isempty(S) - c = zeros(ra, ca); + [ra, ca] = size (a); + if (isempty (a) || isempty (S)) + c = zeros (ra, ca); else - S = unique(S(:)); - lt = length(S); - if lt == 1 - c = ( a == S ); - elseif ra*ca == 1 + S = unique (S(:)); + lt = length (S); + if (lt == 1) + c = (a == S); + elseif (ra*ca == 1) c = any (a == S); else - ## Magic : the following code determines for each a, the index i + ## Magic: the following code determines for each a, the index i ## such that S(i)<= a < S(i+1). It does this by sorting the a ## into S and remembering the source index where each element came ## from. Since all the a's originally came after all the S's, if @@ -68,11 +75,12 @@ ## easy to now check membership by comparing S(a_idx) == a. This ## magic works because S starts out sorted, and because sort ## preserves the relative order of identical elements. - [v, p] = sort ( [ S(2:lt) ; a(:) ] ); + [v, p] = sort ([S(2:lt); a(:)]); idx(p) = cumsum (p <= lt-1) + 1; - idx = idx (lt : lt+ra*ca-1); - c = ( a == reshape (S (idx), size (a)) ); + idx = idx(lt:lt+ra*ca-1); + c = (a == reshape (S(idx), size (a))); endif endif + endfunction \ No newline at end of file diff -r e7438487c857 -r 41cd70503c72 scripts/set/setdiff.m --- a/scripts/set/setdiff.m Thu Mar 03 05:33:45 2005 +0000 +++ b/scripts/set/setdiff.m Thu Mar 03 05:49:55 2005 +0000 @@ -1,18 +1,21 @@ ## Copyright (C) 2000 Paul Kienzle ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +## This file is part of Octave. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} setdiff(@var{a}, @var{b}) @@ -24,23 +27,28 @@ ## @end deftypefn ## @seealso{unique, union, intersect, setxor, ismember} -function c = setdiff(a,b) - if nargin != 2 - usage("setdiff(a,b)"); +## Author: Paul Kienzle +## Adapted-by: jwe + +function c = setdiff (a, b) + + if (nargin != 2) + usage ("setdiff (a, b)"); endif - c = unique(a); - if !isempty(c) && !isempty(b) + c = unique (a); + if (! isempty (c) && ! isempty (b)) ## form a and b into combined set - b = unique(b); - [dummy, idx] = sort([ c(:) ; b(:)]); + b = unique (b); + [dummy, idx] = sort ([c(:); b(:)]); ## eliminate those elements of a that are the same as in b - n = length(dummy); - c(idx(find(dummy(1:n-1) == dummy(2:n)))) = []; + n = length (dummy); + c(idx(find (dummy(1:n-1) == dummy(2:n)))) = []; ## reshape if necessary - if ( size(c,1) != 1 && size(b,1) == 1 ) + if (size (c, 1) != 1 && size (b, 1) == 1) c = c.'; endif endif + endfunction \ No newline at end of file diff -r e7438487c857 -r 41cd70503c72 scripts/strings/strmatch.m --- a/scripts/strings/strmatch.m Thu Mar 03 05:33:45 2005 +0000 +++ b/scripts/strings/strmatch.m Thu Mar 03 05:49:55 2005 +0000 @@ -1,80 +1,66 @@ +## Copyright (C) 2000 Paul Kienzle ## Copyright (C) 2003 Alois Schloegl ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +## This file is part of Octave. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## Copyright (C) 2000 Paul Kienzle +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA. ## usage: strmatch(s, A [, 'exact']) ## Determines which entries of A match string s. A can be a string matrix ## or a cell array of strings. If 'exact' is not given, then s only needs ## to match A up to the length of s. Null characters match blanks. ## Results are returned as a column vector. -function idx = strmatch(s,A,exact) + +## Author: Paul Kienzle, Alois Schloegl +## Adapted-by: jwe + +function idx = strmatch (s, A, exact) + if (nargin < 2 || nargin > 3) - usage("strmatch(s,A,'exact')"); + usage ("strmatch (s, A, \"exact\")"); endif - try istno = implicit_str_to_num_ok; - catch istno = 0; - end - try wstno = warn_str_to_num; - catch wstno = 0; - end - try dfi = do_fortran_indexing; - catch dfi = 0; - end - try wfi = warn_fortran_indexing; - catch wfi = 0; - end - unwind_protect - implicit_str_to_num_ok = 1; - warn_str_to_num = 0; - do_fortran_indexing = 1; - warn_fortran_indexing = 0; - - [nr, nc] = size (A); - if iscell(A) - match = zeros(prod(size(A)),1); - if nargin>2, - for k = 1:prod(size(A)), - match(k) = strcmp(s,A{k}); - end - else - for k = 1:prod(size(A)), - match(k) = strncmp(s,A{k},length(s)); - end + [nr, nc] = size (A); + nel = numel (A); + if (iscell (A)) + match = zeros (nel, 1); + if (nargin > 2) + for k = 1:nel + match(k) = strcmp (s, A{k}); + end + else + for k = 1:nel + match(k) = strncmp (s, A{k}, length (s)); end - idx = find(match); - elseif (length (s) > nc) - idx = []; + end + idx = find (match); + elseif (length (s) > nc) + idx = []; + else + if (nargin == 3 && length(s) < nc) + s(1,nc) = " "; + endif + s(s == 0) = " "; + A(A == 0) = " "; + match = s(ones(size(A,1),1),:) == A(:,1:length(s)); + if (length(s) == 1) + idx = find (match); else - if (nargin == 3 && length(s) < nc) s(1,nc) = ' '; endif - s (s==0) = ' '; - A (A==0) = ' '; - match = s(ones(size(A,1),1),:) == A(:,1:length(s)); - if (length(s) == 1) - idx = find(match); - else - idx = find(all(match')'); - endif + idx = find (all (match')'); endif + endif - unwind_protect_cleanup - implicit_str_to_num_ok = istno; - warn_str_to_num = wstno; - do_fortran_indexing = dfi; - warn_fortran_indexing = wfi; - end_unwind_protect endfunction