comparison src/utils.cc @ 5275:23b37da9fd5b

[project @ 2005-04-08 16:07:35 by jwe]
author jwe
date Fri, 08 Apr 2005 16:07:37 +0000
parents 60999c752276
children 41273fff034d
comparison
equal deleted inserted replaced
5274:eae7b40388e9 5275:23b37da9fd5b
227 227
228 // Return non-zero if either NR or NC is zero. Return -1 if this 228 // Return non-zero if either NR or NC is zero. Return -1 if this
229 // should be considered fatal; return 1 if this is ok. 229 // should be considered fatal; return 1 if this is ok.
230 230
231 int 231 int
232 empty_arg (const char * /* name */, int nr, int nc) 232 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
233 { 233 {
234 return (nr == 0 || nc == 0); 234 return (nr == 0 || nc == 0);
235 } 235 }
236 236
237 // See if the given file is in the path. 237 // See if the given file is in the path.
753 753
754 return pref; 754 return pref;
755 } 755 }
756 756
757 static void 757 static void
758 check_dimensions (int& nr, int& nc, const char *warnfor) 758 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
759 { 759 {
760 if (nr < 0 || nc < 0) 760 if (nr < 0 || nc < 0)
761 { 761 {
762 if (Vwarn_neg_dim_as_zero) 762 if (Vwarn_neg_dim_as_zero)
763 warning ("%s: converting negative dimension to zero", warnfor); 763 warning ("%s: converting negative dimension to zero", warnfor);
796 dim(0) = a.int_value (); 796 dim(0) = a.int_value ();
797 dim(1) = dim(0); 797 dim(1) = dim(0);
798 } 798 }
799 else 799 else
800 { 800 {
801 int nr = a.rows (); 801 octave_idx_type nr = a.rows ();
802 int nc = a.columns (); 802 octave_idx_type nc = a.columns ();
803 803
804 if (nr == 1 || nc == 1) 804 if (nr == 1 || nc == 1)
805 { 805 {
806 Array<double> v = a.vector_value (); 806 Array<double> v = a.vector_value ();
807 807
808 if (error_state) 808 if (error_state)
809 return; 809 return;
810 810
811 int n = v.length (); 811 octave_idx_type n = v.length ();
812 dim.resize (n); 812 dim.resize (n);
813 for (int i = 0; i < n; i++) 813 for (octave_idx_type i = 0; i < n; i++)
814 dim(i) = static_cast<int> (fix (v(i))); 814 dim(i) = static_cast<int> (fix (v(i)));
815 } 815 }
816 else 816 else
817 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); 817 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
818 } 818 }
822 } 822 }
823 823
824 824
825 void 825 void
826 get_dimensions (const octave_value& a, const char *warn_for, 826 get_dimensions (const octave_value& a, const char *warn_for,
827 int& nr, int& nc) 827 octave_idx_type& nr, octave_idx_type& nc)
828 { 828 {
829 if (a.is_scalar_type ()) 829 if (a.is_scalar_type ())
830 { 830 {
831 nr = nc = a.int_value (); 831 nr = nc = a.int_value ();
832 } 832 }
840 Array<double> v = a.vector_value (); 840 Array<double> v = a.vector_value ();
841 841
842 if (error_state) 842 if (error_state)
843 return; 843 return;
844 844
845 nr = static_cast<int> (fix (v (0))); 845 nr = static_cast<octave_idx_type> (fix (v (0)));
846 nc = static_cast<int> (fix (v (1))); 846 nc = static_cast<octave_idx_type> (fix (v (1)));
847 } 847 }
848 else 848 else
849 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); 849 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
850 } 850 }
851 851
853 check_dimensions (nr, nc, warn_for); // May set error_state. 853 check_dimensions (nr, nc, warn_for); // May set error_state.
854 } 854 }
855 855
856 void 856 void
857 get_dimensions (const octave_value& a, const octave_value& b, 857 get_dimensions (const octave_value& a, const octave_value& b,
858 const char *warn_for, int& nr, int& nc) 858 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
859 { 859 {
860 nr = a.is_empty () ? 0 : a.int_value (); 860 nr = a.is_empty () ? 0 : a.int_value ();
861 nc = b.is_empty () ? 0 : b.int_value (); 861 nc = b.is_empty () ? 0 : b.int_value ();
862 862
863 if (error_state) 863 if (error_state)
865 else 865 else
866 check_dimensions (nr, nc, warn_for); // May set error_state. 866 check_dimensions (nr, nc, warn_for); // May set error_state.
867 } 867 }
868 868
869 Matrix 869 Matrix
870 identity_matrix (int nr, int nc) 870 identity_matrix (octave_idx_type nr, octave_idx_type nc)
871 { 871 {
872 Matrix m (nr, nc, 0.0); 872 Matrix m (nr, nc, 0.0);
873 873
874 if (nr > 0 && nc > 0) 874 if (nr > 0 && nc > 0)
875 { 875 {
876 int n = std::min (nr, nc); 876 octave_idx_type n = std::min (nr, nc);
877 877
878 for (int i = 0; i < n; i++) 878 for (octave_idx_type i = 0; i < n; i++)
879 m (i, i) = 1.0; 879 m (i, i) = 1.0;
880 } 880 }
881 881
882 return m; 882 return m;
883 } 883 }