comparison src/data.cc @ 4233:ccfdb55c8156

[project @ 2002-12-20 22:43:54 by jwe]
author jwe
date Fri, 20 Dec 2002 22:43:55 +0000
parents b8ec44432831
children e15a96673976
comparison
equal deleted inserted replaced
4232:b032ebd54586 4233:ccfdb55c8156
51 #define ABS(x) (((x) < 0) ? (-x) : (x)) 51 #define ABS(x) (((x) < 0) ? (-x) : (x))
52 #endif 52 #endif
53 53
54 #define ANY_ALL(FCN) \ 54 #define ANY_ALL(FCN) \
55 \ 55 \
56 octave_value_list retval; \ 56 octave_value retval; \
57 \ 57 \
58 int nargin = args.length (); \ 58 int nargin = args.length (); \
59 \ 59 \
60 if (nargin == 1 || nargin == 2) \ 60 if (nargin == 1 || nargin == 2) \
61 { \ 61 { \
186 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ 186 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\
187 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ 187 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\
188 and @var{x}. The result is in range -pi to pi.\n\ 188 and @var{x}. The result is in range -pi to pi.\n\
189 @end deftypefn") 189 @end deftypefn")
190 { 190 {
191 octave_value_list retval; 191 octave_value retval;
192 192
193 int nargin = args.length (); 193 int nargin = args.length ();
194 194
195 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) 195 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ())
196 { 196 {
205 205
206 int arg_y_empty = empty_arg ("atan2", y_nr, y_nc); 206 int arg_y_empty = empty_arg ("atan2", y_nr, y_nc);
207 int arg_x_empty = empty_arg ("atan2", x_nr, x_nc); 207 int arg_x_empty = empty_arg ("atan2", x_nr, x_nc);
208 208
209 if (arg_y_empty > 0 && arg_x_empty > 0) 209 if (arg_y_empty > 0 && arg_x_empty > 0)
210 return Matrix (); 210 return octave_value (Matrix ());
211 else if (arg_y_empty || arg_x_empty) 211 else if (arg_y_empty || arg_x_empty)
212 return retval; 212 return retval;
213 213
214 int y_is_scalar = (y_nr == 1 && y_nc == 1); 214 int y_is_scalar = (y_nr == 1 && y_nc == 1);
215 int x_is_scalar = (x_nr == 1 && x_nc == 1); 215 int x_is_scalar = (x_nr == 1 && x_nc == 1);
271 return retval; 271 return retval;
272 } 272 }
273 273
274 #define DATA_REDUCTION(FCN) \ 274 #define DATA_REDUCTION(FCN) \
275 \ 275 \
276 octave_value_list retval; \ 276 octave_value retval; \
277 \ 277 \
278 int nargin = args.length (); \ 278 int nargin = args.length (); \
279 \ 279 \
280 if (nargin == 1 || nargin == 2) \ 280 if (nargin == 1 || nargin == 2) \
281 { \ 281 { \
290 if (arg.is_real_type ()) \ 290 if (arg.is_real_type ()) \
291 { \ 291 { \
292 Matrix tmp = arg.matrix_value (); \ 292 Matrix tmp = arg.matrix_value (); \
293 \ 293 \
294 if (! error_state) \ 294 if (! error_state) \
295 retval(0) = tmp.FCN (dim); \ 295 retval = tmp.FCN (dim); \
296 } \ 296 } \
297 else if (arg.is_complex_type ()) \ 297 else if (arg.is_complex_type ()) \
298 { \ 298 { \
299 ComplexMatrix tmp = arg.complex_matrix_value (); \ 299 ComplexMatrix tmp = arg.complex_matrix_value (); \
300 \ 300 \
301 if (! error_state) \ 301 if (! error_state) \
302 retval(0) = tmp.FCN (dim); \ 302 retval = tmp.FCN (dim); \
303 } \ 303 } \
304 else \ 304 else \
305 { \ 305 { \
306 gripe_wrong_type_arg (#FCN, arg); \ 306 gripe_wrong_type_arg (#FCN, arg); \
307 return retval; \ 307 return retval; \
366 { 366 {
367 int n = nc + ABS (k); 367 int n = nc + ABS (k);
368 Matrix m (n, n, 0.0); 368 Matrix m (n, n, 0.0);
369 for (int i = 0; i < nc; i++) 369 for (int i = 0; i < nc; i++)
370 m (i+roff, i+coff) = v (0, i); 370 m (i+roff, i+coff) = v (0, i);
371 retval = octave_value (m); 371 retval = m;
372 } 372 }
373 else 373 else
374 { 374 {
375 int n = nr + ABS (k); 375 int n = nr + ABS (k);
376 Matrix m (n, n, 0.0); 376 Matrix m (n, n, 0.0);
377 for (int i = 0; i < nr; i++) 377 for (int i = 0; i < nr; i++)
378 m (i+roff, i+coff) = v (i, 0); 378 m (i+roff, i+coff) = v (i, 0);
379 retval = octave_value (m); 379 retval = m;
380 } 380 }
381 381
382 return retval; 382 return retval;
383 } 383 }
384 384
408 { 408 {
409 int n = nc + ABS (k); 409 int n = nc + ABS (k);
410 ComplexMatrix m (n, n, 0.0); 410 ComplexMatrix m (n, n, 0.0);
411 for (int i = 0; i < nc; i++) 411 for (int i = 0; i < nc; i++)
412 m (i+roff, i+coff) = v (0, i); 412 m (i+roff, i+coff) = v (0, i);
413 retval = octave_value (m); 413 retval = m;
414 } 414 }
415 else 415 else
416 { 416 {
417 int n = nr + ABS (k); 417 int n = nr + ABS (k);
418 ComplexMatrix m (n, n, 0.0); 418 ComplexMatrix m (n, n, 0.0);
419 for (int i = 0; i < nr; i++) 419 for (int i = 0; i < nr; i++)
420 m (i+roff, i+coff) = v (i, 0); 420 m (i+roff, i+coff) = v (i, 0);
421 retval = octave_value (m); 421 retval = m;
422 } 422 }
423 423
424 return retval; 424 return retval;
425 } 425 }
426 426
558 0 0 0 0\n\ 558 0 0 0 0\n\
559 @end group\n\ 559 @end group\n\
560 @end example\n\ 560 @end example\n\
561 @end deftypefn") 561 @end deftypefn")
562 { 562 {
563 octave_value_list retval; 563 octave_value retval;
564 564
565 int nargin = args.length (); 565 int nargin = args.length ();
566 566
567 if (nargin == 1 && args(0).is_defined ()) 567 if (nargin == 1 && args(0).is_defined ())
568 retval = make_diag (args(0)); 568 retval = make_diag (args(0));
597 if (args.length () == 1) 597 if (args.length () == 1)
598 { 598 {
599 int len = args(0).length (); 599 int len = args(0).length ();
600 600
601 if (! error_state) 601 if (! error_state)
602 retval = static_cast<double> (len); 602 retval = len;
603 } 603 }
604 else 604 else
605 print_usage ("length"); 605 print_usage ("length");
606 606
607 return retval; 607 return retval;
652 if (nargout == 0 || nargout == 1) 652 if (nargout == 0 || nargout == 1)
653 { 653 {
654 Matrix m (1, 2); 654 Matrix m (1, 2);
655 m (0, 0) = nr; 655 m (0, 0) = nr;
656 m (0, 1) = nc; 656 m (0, 1) = nc;
657 retval = m; 657 retval(0) = m;
658 } 658 }
659 else if (nargout == 2) 659 else if (nargout == 2)
660 { 660 {
661 retval(1) = static_cast<double> (nc); 661 retval(1) = nc;
662 retval(0) = static_cast<double> (nr); 662 retval(0) = nr;
663 } 663 }
664 } 664 }
665 else if (nargin == 2 && nargout < 2) 665 else if (nargin == 2 && nargout < 2)
666 { 666 {
667 int nd = args(1).nint_value (); 667 int nd = args(1).nint_value ();
669 if (error_state) 669 if (error_state)
670 error ("size: expecting scalar as second argument"); 670 error ("size: expecting scalar as second argument");
671 else 671 else
672 { 672 {
673 if (nd == 1) 673 if (nd == 1)
674 retval(0) = static_cast<double> (args(0).rows ()); 674 retval(0) = args(0).rows ();
675 else if (nd == 2) 675 else if (nd == 2)
676 retval(0) = static_cast<double> (args(0).columns ()); 676 retval(0) = args(0).columns ();
677 else 677 else
678 error ("size: invalid second argument -- expecting 1 or 2"); 678 error ("size: invalid second argument -- expecting 1 or 2");
679 } 679 }
680 } 680 }
681 else 681 else
765 @deftypefn {Built-in Function} {} isempty (@var{a})\n\ 765 @deftypefn {Built-in Function} {} isempty (@var{a})\n\
766 Return 1 if @var{a} is an empty matrix (either the number of rows, or\n\ 766 Return 1 if @var{a} is an empty matrix (either the number of rows, or\n\
767 the number of columns, or both are zero). Otherwise, return 0.\n\ 767 the number of columns, or both are zero). Otherwise, return 0.\n\
768 @end deftypefn") 768 @end deftypefn")
769 { 769 {
770 double retval = 0.0; 770 octave_value retval = false;
771 771
772 if (args.length () == 1) 772 if (args.length () == 1)
773 { 773 {
774 octave_value arg = args(0); 774 octave_value arg = args(0);
775 775
776 if (arg.is_matrix_type ()) 776 if (arg.is_matrix_type ())
777 retval = static_cast<double> (arg.rows () == 0 || arg.columns () == 0); 777 retval = (arg.rows () == 0 || arg.columns () == 0);
778 else if (arg.is_list () || arg.is_string ()) 778 else if (arg.is_list () || arg.is_string ())
779 retval = static_cast<double> (arg.length () == 0); 779 retval = (arg.length () == 0);
780 } 780 }
781 else 781 else
782 print_usage ("isempty"); 782 print_usage ("isempty");
783 783
784 return retval; 784 return retval;
820 "-*- texinfo -*-\n\ 820 "-*- texinfo -*-\n\
821 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ 821 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\
822 Return 1 if @var{a} is a matrix. Otherwise, return 0.\n\ 822 Return 1 if @var{a} is a matrix. Otherwise, return 0.\n\
823 @end deftypefn") 823 @end deftypefn")
824 { 824 {
825 double retval = 0.0; 825 octave_value retval = false;
826 826
827 if (args.length () == 1) 827 if (args.length () == 1)
828 { 828 {
829 octave_value arg = args(0); 829 octave_value arg = args(0);
830 830
831 if (arg.is_scalar_type () || arg.is_range ()) 831 if (arg.is_scalar_type () || arg.is_range ())
832 retval = 1.0; 832 retval = true;
833 else if (arg.is_matrix_type ()) 833 else if (arg.is_matrix_type ())
834 retval = static_cast<double> (arg.rows () >= 1 && arg.columns () >= 1); 834 retval = (arg.rows () >= 1 && arg.columns () >= 1);
835 } 835 }
836 else 836 else
837 print_usage ("ismatrix"); 837 print_usage ("ismatrix");
838 838
839 return retval; 839 return retval;
861 Return a list of strings naming the elements of the structure\n\ 861 Return a list of strings naming the elements of the structure\n\
862 @var{struct}. It is an error to call @code{struct_elements} with an\n\ 862 @var{struct}. It is an error to call @code{struct_elements} with an\n\
863 argument that is not a structure.\n\ 863 argument that is not a structure.\n\
864 @end deftypefn") 864 @end deftypefn")
865 { 865 {
866 octave_value_list retval; 866 octave_value retval;
867 867
868 int nargin = args.length (); 868 int nargin = args.length ();
869 869
870 if (nargin == 1) 870 if (nargin == 1)
871 { 871 {
872 if (args (0).is_map ()) 872 if (args (0).is_map ())
873 { 873 {
874 Octave_map m = args(0).map_value (); 874 Octave_map m = args(0).map_value ();
875 retval(0) = m.keys (); 875 retval = m.keys ();
876 } 876 }
877 else 877 else
878 gripe_wrong_type_arg ("struct_elements", args (0)); 878 gripe_wrong_type_arg ("struct_elements", args (0));
879 } 879 }
880 else 880 else
889 Return 1 if the expression @var{expr} is a structure and it includes an\n\ 889 Return 1 if the expression @var{expr} is a structure and it includes an\n\
890 element named @var{name}. The first argument must be a structure and\n\ 890 element named @var{name}. The first argument must be a structure and\n\
891 the second must be a string.\n\ 891 the second must be a string.\n\
892 @end deftypefn") 892 @end deftypefn")
893 { 893 {
894 octave_value_list retval; 894 octave_value retval;
895 895
896 int nargin = args.length (); 896 int nargin = args.length ();
897 897
898 if (nargin == 2) 898 if (nargin == 2)
899 { 899 {
900 retval = 0.0; 900 retval = false;
901 901
902 // XXX FIXME XXX -- should this work for all types that can do 902 // XXX FIXME XXX -- should this work for all types that can do
903 // structure reference operations? 903 // structure reference operations?
904 904
905 if (args(0).is_map () && args(1).is_string ()) 905 if (args(0).is_map () && args(1).is_string ())
906 { 906 {
907 std::string key = args(1).string_value (); 907 std::string key = args(1).string_value ();
908 908
909 Octave_map m = args(0).map_value (); 909 Octave_map m = args(0).map_value ();
910 910
911 retval = static_cast<double> (m.contains (key)); 911 retval = m.contains (key);
912 } 912 }
913 else 913 else
914 print_usage ("struct_contains"); 914 print_usage ("struct_contains");
915 } 915 }
916 else 916 else