comparison src/utils.cc @ 4481:cfbaee1f562f

[project @ 2003-08-06 13:56:07 by jwe]
author jwe
date Wed, 06 Aug 2003 13:56:07 +0000
parents 7afd4bf05aa8
children 1fa73cab40a0
comparison
equal deleted inserted replaced
4480:b96f2c55d5a3 4481:cfbaee1f562f
764 nc = (nc < 0) ? 0 : nc; 764 nc = (nc < 0) ? 0 : nc;
765 } 765 }
766 } 766 }
767 767
768 void 768 void
769 check_dimensions (Array<int>& dim, const char *warnfor)
770 {
771 bool neg = false;
772
773 int n = dim.length ();
774 for (int i = 0; i < dim.length (); i++)
775 {
776 if (dim(i) < 0)
777 {
778 dim(i) = 0;
779 neg = true;
780 }
781 }
782
783 if (neg && Vwarn_neg_dim_as_zero)
784 {
785 warning ("%s: converting negative dimension to zero", warnfor);
786 }
787 }
788
789
790 void
791 get_dimensions (const octave_value& a, const char *warn_for,
792 Array<int>& dim)
793 {
794 if (a.is_scalar_type ())
795 {
796 dim.resize (2);
797 dim(0) = a.nint_value ();
798 dim(1) = dim(0);
799 }
800 else
801 {
802 int nr = a.rows ();
803 int nc = a.columns ();
804
805 if (nr == 1 || nc == 1)
806 {
807 Array<double> v = a.vector_value ();
808
809 if (error_state)
810 return;
811
812 int n = v.length ();
813 dim.resize (n);
814 for (int i = 0; i < n; i++)
815 dim(i) = NINT (v(i));
816 }
817 else
818 warning ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
819 }
820
821 check_dimensions (dim, warn_for); // May set error_state.
822 }
823
824
825 void
769 get_dimensions (const octave_value& a, const char *warn_for, 826 get_dimensions (const octave_value& a, const char *warn_for,
770 int& nr, int& nc) 827 int& nr, int& nc)
771 { 828 {
772 if (a.is_scalar_type ()) 829 if (a.is_scalar_type ())
773 { 830 {