Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/license.m @ 17691:8a54a481ecb5
Massive speed improvement in sparse min/max functions for calls like
'max(s,[],2)' (bug #40268)
* dSparse.cc (SparseMatrix SparseMatrix::max (Array<octave_idx-type>&, int)) :
Remove triple loop by using a local buffer
(SparseMatrix SparseMatrix::min (Array<octave_idx-type>&, int)) : ditto
* CSparse.cc (SparseComplexMatrix SparseComplexMatrix::max (
Array<octave_idx-type>&, int)) : Remove triple loop by using a local buffer
(SparseComplexMatrix SparseComplexMatrix::min (Array<octave_idx-type>&,
int)) : ditto
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 18 Oct 2013 23:44:44 +0200 |
parents | bc924baa2c4e |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13825
diff
changeset
|
1 ## Copyright (C) 2005-2012 William Poetra Yoga Hadisoeseno |
5546 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5546 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5546 | 18 |
19 ## -*- texinfo -*- | |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
20 ## @deftypefn {Command} {} license |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
21 ## @deftypefnx {Function File} {} license ("inuse") |
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{retval} =} license ("inuse") |
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{retval} =} license ("test", @var{feature}) |
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
24 ## @deftypefnx {Function File} {} license ("test", @var{feature}, @var{toggle}) |
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
25 ## @deftypefnx {Function File} {@var{retval} =} license ("checkout", @var{feature}) |
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
26 ## |
5546 | 27 ## Display the license of Octave. |
28 ## | |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
29 ## @code{license ("inuse")} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
30 ## |
5548 | 31 ## Display a list of packages currently being used. |
5546 | 32 ## |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
33 ## @code{@var{retval} = license ("inuse")} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
34 ## |
5548 | 35 ## Return a structure containing the fields @code{feature} and @code{user}. |
5546 | 36 ## |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
37 ## @code{@var{retval} = license ("test", @var{feature})} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
38 ## |
5548 | 39 ## Return 1 if a license exists for the product identified by the string |
40 ## @var{feature} and 0 otherwise. The argument @var{feature} is case | |
41 ## insensitive and only the first 27 characters are checked. | |
5546 | 42 ## |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
43 ## @code{license ("test", @var{feature}, @var{toggle})} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
44 ## |
5548 | 45 ## Enable or disable license testing for @var{feature}, depending on |
46 ## @var{toggle}, which may be one of: | |
5546 | 47 ## |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
48 ## @table @asis |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16491
diff
changeset
|
49 ## @item @qcode{"enable"} |
5546 | 50 ## Future tests for the specified license of @var{feature} are conducted |
51 ## as usual. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
52 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16491
diff
changeset
|
53 ## @item @qcode{"disable"} |
5546 | 54 ## Future tests for the specified license of @var{feature} return 0. |
55 ## @end table | |
56 ## | |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
15466
diff
changeset
|
57 ## @code{@var{retval} = license ("checkout", @var{feature})} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
58 ## |
5548 | 59 ## Check out a license for @var{feature}, returning 1 on success and 0 |
60 ## on failure. | |
5546 | 61 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
62 ## This function is provided for compatibility with @sc{matlab}. |
5642 | 63 ## @seealso{ver, version} |
5546 | 64 ## @end deftypefn |
65 | |
66 ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | |
67 | |
68 function retval = license (varargin) | |
69 | |
5548 | 70 persistent __octave_licenses__; |
5546 | 71 |
72 if (isempty (__octave_licenses__)) | |
73 __octave_licenses__ = cell (); | |
74 __octave_licenses__{1,1} = "Octave"; | |
6555 | 75 __octave_licenses__{1,2} = "GNU General Public License"; |
5546 | 76 __octave_licenses__{1,3} = true; |
77 if (exist ("OCTAVE_FORGE_VERSION")) | |
78 __octave_licenses__{2,1} = "octave-forge"; | |
79 __octave_licenses__{2,2} = "<various licenses>"; | |
80 __octave_licenses__{2,3} = true; | |
81 endif | |
82 endif | |
83 | |
84 nout = nargout; | |
85 nin = nargin; | |
86 nr_licenses = rows (__octave_licenses__); | |
87 | |
88 if (nout > 1 || nin > 3) | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
89 print_usage (); |
5546 | 90 endif |
91 | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
92 if (nin == 0) |
5546 | 93 |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
94 found = find (strcmp (__octave_licenses__(:,1), "Octave"), 1); |
5546 | 95 |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
96 if (! isempty (found)) |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
97 result = __octave_licenses__{found,2}; |
5548 | 98 else |
99 result = "unknown"; | |
100 endif | |
5546 | 101 |
5548 | 102 if (nout == 0) |
103 printf ("%s\n", result); | |
5546 | 104 else |
5548 | 105 retval = result; |
5546 | 106 endif |
107 | |
108 elseif (nin == 1) | |
109 | |
110 if (nout == 0) | |
111 | |
112 if (! strcmp (varargin{1}, "inuse")) | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
113 usage ('license ("inuse")'); |
5546 | 114 endif |
115 | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
116 printf ("%s\n", __octave_licenses__{:,1}); |
5546 | 117 |
118 else | |
119 | |
120 if (! strcmp (varargin{1}, "inuse")) | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
121 usage ('retval = license ("inuse")'); |
5546 | 122 endif |
123 | |
5548 | 124 pw = getpwuid (getuid ()); |
125 if (isstruct (pw)) | |
10549 | 126 username = pw.name; |
5546 | 127 else |
10549 | 128 username = "octave_user"; |
5546 | 129 endif |
130 | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
131 retval = struct ("feature", __octave_licenses__(:,1), "user", username); |
5546 | 132 |
133 endif | |
134 | |
135 else | |
136 | |
137 feature = varargin{2}(1:(min ([(length (varargin{2})), 27]))); | |
138 | |
139 if (strcmp (varargin{1}, "test")) | |
140 | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
141 found = find (strcmpi (__octave_licenses__(:,1), feature), 1); |
5546 | 142 |
143 if (nin == 2) | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
144 retval = ! isempty (found) && __octave_licenses__{found,3}; |
5546 | 145 else |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
146 if (! isempty (found)) |
5546 | 147 if (strcmp (varargin{3}, "enable")) |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
148 __octave_licenses__{found,3} = true; |
5546 | 149 elseif (strcmp (varargin{3}, "disable")) |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
150 __octave_licenses__{found,3} = false; |
5546 | 151 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
152 error ("license: TOGGLE must be either 'enable' or 'disable'"); |
5546 | 153 endif |
154 else | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
155 error ("license: FEATURE '%s' not found", feature); |
5546 | 156 endif |
157 endif | |
158 | |
159 elseif (strcmp (varargin{1}, "checkout")) | |
160 | |
161 if (nin != 2) | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
162 usage ('retval = license ("checkout", feature)'); |
5546 | 163 endif |
164 | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
165 found = find (strcmpi (__octave_licenses__(:,1), feature), 1); |
5546 | 166 |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
167 retval = ! isempty (found) && __octave_licenses__{found,3}; |
5546 | 168 |
169 else | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
170 print_usage (); |
5546 | 171 endif |
172 | |
173 endif | |
174 | |
175 endfunction | |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
176 |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
177 |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
178 %!assert (license(), "GNU General Public License") |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
179 %!assert ((license ("inuse")).feature, "Octave") |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
180 |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
181 %!test |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
182 %! lstate = license ("test", "Octave"); |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
183 %! license ("test", "Octave", "disable"); |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
184 %! assert (license ("test", "Octave"), false); |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
185 %! license ("test", "Octave", "enable"); |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
186 %! assert (license ("test", "Octave"), true); |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
187 %! if (lstate == false) |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
188 %! license ("test", "Octave", "disable"); |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
189 %! endif |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
190 |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
191 %!assert (license ("checkout", "Octave"), true) |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
192 |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
193 %% Test input validation |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
194 %!error license ("not_inuse") |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
195 %!error <TOGGLE must be either> license ("test", "Octave", "not_enable") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
196 %!error <FEATURE 'INVALID' not found> license ("test", "INVALID", "enable") |
13825
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
197 %!error license ("not_test", "Octave", "enable") |
45f4ff9a6247
license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12480
diff
changeset
|
198 |