Mercurial > hg > octave-nkf
annotate examples/code/paramdemo.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 2f8500ca91d3 |
children |
rev | line source |
---|---|
6580 | 1 #include <octave/oct.h> |
2 | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3 DEFUN_DLD (paramdemo, args, nargout, "Parameter Check Demo") |
6580 | 4 { |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
5 if (args.length () != 1) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
6 print_usage (); |
6580 | 7 |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
8 if (nargout != 0) |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
9 error ("paramdemo: OUTPUT argument required"); |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
10 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
11 NDArray m = args(0).array_value (); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
12 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
13 double min_val = -10.0; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
14 double max_val = 10.0; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
15 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
16 octave_stdout << "Properties of input array:\n"; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
17 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
18 if (m.any_element_is_negative ()) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
19 octave_stdout << " includes negative values\n"; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
20 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
21 if (m.any_element_is_inf_or_nan ()) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
22 octave_stdout << " includes Inf or NaN values\n"; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
23 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
24 if (m.any_element_not_one_or_zero ()) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
25 octave_stdout << " includes other values than 1 and 0\n"; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
26 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
27 if (m.all_elements_are_int_or_inf_or_nan ()) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
28 octave_stdout << " includes only int, Inf or NaN values\n"; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
29 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
30 if (m.all_integers (min_val, max_val)) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
31 octave_stdout << " includes only integers in [-10,10]\n"; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
32 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
33 return octave_value (); |
6580 | 34 } |