Mercurial > octave-nkf
comparison src/ov.cc @ 4563:742993a501b9
[project @ 2003-10-29 06:25:12 by jwe]
author | jwe |
---|---|
date | Wed, 29 Oct 2003 06:25:12 +0000 |
parents | 01ee68d18069 |
children | fc30061d01da |
comparison
equal
deleted
inserted
replaced
4562:4699bdb4c362 | 4563:742993a501b9 |
---|---|
815 } | 815 } |
816 | 816 |
817 return *this; | 817 return *this; |
818 } | 818 } |
819 | 819 |
820 int | |
821 octave_value::rows (void) const | |
822 { | |
823 dim_vector dv = dims (); | |
824 | |
825 return (dv.length () > 0) ? dv(0) : -1; | |
826 } | |
827 | |
828 int | |
829 octave_value::columns (void) const | |
830 { | |
831 dim_vector dv = dims (); | |
832 | |
833 return (dv.length () > 1) ? dv(1) : -1; | |
834 } | |
835 | |
836 int | |
837 octave_value::length (void) const | |
838 { | |
839 int retval = 0; | |
840 | |
841 dim_vector dv = dims (); | |
842 | |
843 for (int i = 0; i < dv.length (); i++) | |
844 { | |
845 if (dv(i) < 0) | |
846 { | |
847 retval = -1; | |
848 break; | |
849 } | |
850 | |
851 if (dv(i) > retval) | |
852 retval = dv(i); | |
853 } | |
854 | |
855 return retval; | |
856 } | |
857 | |
858 int | |
859 octave_value::ndims (void) const | |
860 { | |
861 dim_vector dv = dims (); | |
862 | |
863 int n_dims = dv.length (); | |
864 | |
865 // Remove trailing singleton dimensions. | |
866 | |
867 for (int i = n_dims; i > 2; i--) | |
868 { | |
869 if (dv(i-1) == 1) | |
870 n_dims--; | |
871 else | |
872 break; | |
873 } | |
874 | |
875 // The result is always >= 2. | |
876 | |
877 if (n_dims < 2) | |
878 n_dims = 2; | |
879 | |
880 return n_dims; | |
881 } | |
882 | |
883 int | |
884 octave_value::numel (void) const | |
885 { | |
886 dim_vector dv = dims (); | |
887 | |
888 int n_dims = dv.length (); | |
889 | |
890 int retval = n_dims > 0 ? dv(0) : 0; | |
891 | |
892 for (int i = 1; i < n_dims; i++) | |
893 retval *= dv(i); | |
894 | |
895 return retval; | |
896 } | |
897 | |
820 Cell | 898 Cell |
821 octave_value::cell_value (void) const | 899 octave_value::cell_value (void) const |
822 { | 900 { |
823 return rep->cell_value (); | 901 return rep->cell_value (); |
824 } | 902 } |