Mercurial > jwe > octave
comparison libinterp/octave-value/ov-range.cc @ 30840:2989202f92f8 stable
only allow range<FLOAT> to be instantiated
* Range.h, Range.cc: Limit range<T> to floating point values.
* range-fwd.h: Update forward declaration of range<T>.
* ov-base.h, ov-base.cc, ov-range.h, ov-range.cc, ov.h, ov.cc,
pt-eval.cc: Temporarily comment out code that uses range<INT>
objects.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 17 Mar 2022 02:44:19 -0400 |
parents | 796f54d4ddbf |
children | 97504d2edcc7 95725e6ad9c1 |
comparison
equal
deleted
inserted
replaced
30839:f1a9e55d850c | 30840:2989202f92f8 |
---|---|
65 #include "ls-utils.h" | 65 #include "ls-utils.h" |
66 | 66 |
67 #if defined (HAVE_HDF5) | 67 #if defined (HAVE_HDF5) |
68 | 68 |
69 template <> | 69 template <> |
70 octave_hdf5_id ov_range<double>::hdf5_save_type = H5T_NATIVE_DOUBLE; | |
71 | |
72 // For now, disable all but ov_range<double>. | |
73 | |
74 # if 0 | |
75 | |
76 template <> | |
70 octave_hdf5_id ov_range<float>::hdf5_save_type = H5T_NATIVE_FLOAT; | 77 octave_hdf5_id ov_range<float>::hdf5_save_type = H5T_NATIVE_FLOAT; |
71 | 78 |
72 template <> | 79 template <> |
73 octave_hdf5_id ov_range<double>::hdf5_save_type = H5T_NATIVE_DOUBLE; | |
74 | |
75 template <> | |
76 octave_hdf5_id ov_range<octave_int8>::hdf5_save_type = H5T_NATIVE_INT8; | 80 octave_hdf5_id ov_range<octave_int8>::hdf5_save_type = H5T_NATIVE_INT8; |
77 | 81 |
78 template <> | 82 template <> |
79 octave_hdf5_id ov_range<octave_int16>::hdf5_save_type = H5T_NATIVE_INT16; | 83 octave_hdf5_id ov_range<octave_int16>::hdf5_save_type = H5T_NATIVE_INT16; |
80 | 84 |
94 octave_hdf5_id ov_range<octave_uint32>::hdf5_save_type = H5T_NATIVE_UINT32; | 98 octave_hdf5_id ov_range<octave_uint32>::hdf5_save_type = H5T_NATIVE_UINT32; |
95 | 99 |
96 template <> | 100 template <> |
97 octave_hdf5_id ov_range<octave_uint64>::hdf5_save_type = H5T_NATIVE_UINT64; | 101 octave_hdf5_id ov_range<octave_uint64>::hdf5_save_type = H5T_NATIVE_UINT64; |
98 | 102 |
103 # endif | |
104 | |
99 #else | 105 #else |
100 | 106 |
101 template <> | 107 template <> |
108 octave_hdf5_id ov_range<double>::hdf5_save_type = 0; | |
109 | |
110 // For now, disable all but ov_range<double>. | |
111 | |
112 #if 0 | |
113 | |
114 template <> | |
102 octave_hdf5_id ov_range<float>::hdf5_save_type = 0; | 115 octave_hdf5_id ov_range<float>::hdf5_save_type = 0; |
103 | 116 |
104 template <> | 117 template <> |
105 octave_hdf5_id ov_range<double>::hdf5_save_type = 0; | |
106 | |
107 template <> | |
108 octave_hdf5_id ov_range<octave_int8>::hdf5_save_type = 0; | 118 octave_hdf5_id ov_range<octave_int8>::hdf5_save_type = 0; |
109 | 119 |
110 template <> | 120 template <> |
111 octave_hdf5_id ov_range<octave_int16>::hdf5_save_type = 0; | 121 octave_hdf5_id ov_range<octave_int16>::hdf5_save_type = 0; |
112 | 122 |
126 octave_hdf5_id ov_range<octave_uint32>::hdf5_save_type = 0; | 136 octave_hdf5_id ov_range<octave_uint32>::hdf5_save_type = 0; |
127 | 137 |
128 template <> | 138 template <> |
129 octave_hdf5_id ov_range<octave_uint64>::hdf5_save_type = 0; | 139 octave_hdf5_id ov_range<octave_uint64>::hdf5_save_type = 0; |
130 | 140 |
131 #endif | 141 # endif |
142 | |
143 #endif | |
144 | |
145 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<double>, | |
146 "range", "double"); | |
147 | |
148 // For now, disable all but ov_range<double>. | |
149 | |
150 #if 0 | |
132 | 151 |
133 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<float>, | 152 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<float>, |
134 "float_range", "single"); | 153 "float_range", "single"); |
135 | 154 |
136 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<double>, | |
137 "range", "double"); | |
138 | |
139 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_int8>, | 155 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_int8>, |
140 "int8_range", "int8"); | 156 "int8_range", "int8"); |
141 | 157 |
142 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_int16>, | 158 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_int16>, |
143 "int16_range", "int16"); | 159 "int16_range", "int16"); |
157 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_uint32>, | 173 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_uint32>, |
158 "uint32_range", "uint32"); | 174 "uint32_range", "uint32"); |
159 | 175 |
160 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_uint64>, | 176 DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA (ov_range<octave_uint64>, |
161 "uint64_range", "uint64"); | 177 "uint64_range", "uint64"); |
178 | |
179 #endif | |
162 | 180 |
163 template <typename T> | 181 template <typename T> |
164 static octave_base_value * | 182 static octave_base_value * |
165 default_numeric_conversion_function (const octave_base_value& a) | 183 default_numeric_conversion_function (const octave_base_value& a) |
166 { | 184 { |
393 retval.resize (dv); | 411 retval.resize (dv); |
394 return retval; | 412 return retval; |
395 } | 413 } |
396 | 414 |
397 template <typename T> | 415 template <typename T> |
416 octave::range<double> | |
417 ov_range<T>::range_value (void) const | |
418 { | |
419 err_wrong_type_arg ("ov_range<T>::range_value()", type_name ()); | |
420 } | |
421 | |
422 // For now, disable all but ov_range<double>. | |
423 | |
424 #if 0 | |
425 | |
426 template <typename T> | |
398 octave::range<float> | 427 octave::range<float> |
399 ov_range<T>::float_range_value (void) const | 428 ov_range<T>::float_range_value (void) const |
400 { | 429 { |
401 err_wrong_type_arg ("ov_range<T>::float_range_value ()", type_name ()); | 430 err_wrong_type_arg ("ov_range<T>::float_range_value ()", type_name ()); |
402 } | 431 } |
403 | 432 |
404 template <typename T> | 433 template <typename T> |
405 octave::range<double> | |
406 ov_range<T>::range_value (void) const | |
407 { | |
408 err_wrong_type_arg ("ov_range<T>::range_value()", type_name ()); | |
409 } | |
410 | |
411 template <typename T> | |
412 octave::range<octave_int8> | 434 octave::range<octave_int8> |
413 ov_range<T>::int8_range_value (void) const | 435 ov_range<T>::int8_range_value (void) const |
414 { | 436 { |
415 err_wrong_type_arg ("ov_range<T>::int8_range_value ()", type_name ()); | 437 err_wrong_type_arg ("ov_range<T>::int8_range_value ()", type_name ()); |
416 } | 438 } |
461 octave::range<octave_uint64> | 483 octave::range<octave_uint64> |
462 ov_range<T>::uint64_range_value (void) const | 484 ov_range<T>::uint64_range_value (void) const |
463 { | 485 { |
464 err_wrong_type_arg ("ov_range<T>::uint64_range_value ()", type_name ()); | 486 err_wrong_type_arg ("ov_range<T>::uint64_range_value ()", type_name ()); |
465 } | 487 } |
488 | |
489 #endif | |
466 | 490 |
467 template <typename T> | 491 template <typename T> |
468 octave_value | 492 octave_value |
469 ov_range<T>::convert_to_str_internal (bool pad, bool force, char type) const | 493 ov_range<T>::convert_to_str_internal (bool pad, bool force, char type) const |
470 { | 494 { |
689 return xsave_ascii (os, m_range, false); | 713 return xsave_ascii (os, m_range, false); |
690 } | 714 } |
691 | 715 |
692 // specialize for saving with "reverse" flag | 716 // specialize for saving with "reverse" flag |
693 | 717 |
718 // For now, disable all but ov_range<double>. | |
719 | |
720 #if 0 | |
721 | |
694 template <> | 722 template <> |
695 bool | 723 bool |
696 ov_range<octave_uint8>::save_ascii (std::ostream& os) | 724 ov_range<octave_uint8>::save_ascii (std::ostream& os) |
697 { | 725 { |
698 return xsave_ascii (os, m_range, true); | 726 return xsave_ascii (os, m_range, true); |
716 bool | 744 bool |
717 ov_range<octave_uint64>::save_ascii (std::ostream& os) | 745 ov_range<octave_uint64>::save_ascii (std::ostream& os) |
718 { | 746 { |
719 return xsave_ascii (os, m_range, true); | 747 return xsave_ascii (os, m_range, true); |
720 } | 748 } |
749 | |
750 #endif | |
721 | 751 |
722 template <typename T> | 752 template <typename T> |
723 bool | 753 bool |
724 xload_ascii (std::istream& is, octave::range<T>& r, const bool with_reverse) | 754 xload_ascii (std::istream& is, octave::range<T>& r, const bool with_reverse) |
725 { | 755 { |
754 return xload_ascii (is, m_range, false); | 784 return xload_ascii (is, m_range, false); |
755 } | 785 } |
756 | 786 |
757 // specialize for loading with "reverse" flag | 787 // specialize for loading with "reverse" flag |
758 | 788 |
789 // For now, disable all but ov_range<double>. | |
790 | |
791 #if 0 | |
792 | |
759 template <> | 793 template <> |
760 bool | 794 bool |
761 ov_range<octave_uint8>::load_ascii (std::istream& is) | 795 ov_range<octave_uint8>::load_ascii (std::istream& is) |
762 { | 796 { |
763 return xload_ascii (is, m_range, true); | 797 return xload_ascii (is, m_range, true); |
781 bool | 815 bool |
782 ov_range<octave_uint64>::load_ascii (std::istream& is) | 816 ov_range<octave_uint64>::load_ascii (std::istream& is) |
783 { | 817 { |
784 return xload_ascii (is, m_range, true); | 818 return xload_ascii (is, m_range, true); |
785 } | 819 } |
820 | |
821 #endif | |
786 | 822 |
787 /* | 823 /* |
788 %!test | 824 %!test |
789 %! a = b = 1:4; | 825 %! a = b = 1:4; |
790 %! sv_file = [tempname(), ".sav"]; | 826 %! sv_file = [tempname(), ".sav"]; |
842 ov_range<T>::save_binary (std::ostream& os, bool save_as_floats) | 878 ov_range<T>::save_binary (std::ostream& os, bool save_as_floats) |
843 { | 879 { |
844 return xsave_binary (os, save_as_floats, m_range, false); | 880 return xsave_binary (os, save_as_floats, m_range, false); |
845 } | 881 } |
846 | 882 |
883 // For now, disable all but ov_range<double>. | |
884 | |
885 #if 0 | |
886 | |
847 template <> | 887 template <> |
848 bool | 888 bool |
849 ov_range<octave_uint8>::save_binary (std::ostream& os, bool save_as_floats) | 889 ov_range<octave_uint8>::save_binary (std::ostream& os, bool save_as_floats) |
850 { | 890 { |
851 return xsave_binary (os, save_as_floats, m_range, true); | 891 return xsave_binary (os, save_as_floats, m_range, true); |
869 bool | 909 bool |
870 ov_range<octave_uint64>::save_binary (std::ostream& os, bool save_as_floats) | 910 ov_range<octave_uint64>::save_binary (std::ostream& os, bool save_as_floats) |
871 { | 911 { |
872 return xsave_binary (os, save_as_floats, m_range, true); | 912 return xsave_binary (os, save_as_floats, m_range, true); |
873 } | 913 } |
914 | |
915 #endif | |
874 | 916 |
875 template <typename T> | 917 template <typename T> |
876 bool | 918 bool |
877 xload_binary (std::istream& is, bool swap, | 919 xload_binary (std::istream& is, bool swap, |
878 octave::mach_info::float_format /* fmt */, | 920 octave::mach_info::float_format /* fmt */, |
921 octave::mach_info::float_format fmt) | 963 octave::mach_info::float_format fmt) |
922 { | 964 { |
923 return xload_binary (is, swap, fmt, m_range, false); | 965 return xload_binary (is, swap, fmt, m_range, false); |
924 } | 966 } |
925 | 967 |
968 // For now, disable all but ov_range<double>. | |
969 | |
970 #if 0 | |
971 | |
926 template <> | 972 template <> |
927 bool | 973 bool |
928 ov_range<octave_uint8>::load_binary (std::istream& is, bool swap, | 974 ov_range<octave_uint8>::load_binary (std::istream& is, bool swap, |
929 octave::mach_info::float_format fmt) | 975 octave::mach_info::float_format fmt) |
930 { | 976 { |
952 ov_range<octave_uint64>::load_binary (std::istream& is, bool swap, | 998 ov_range<octave_uint64>::load_binary (std::istream& is, bool swap, |
953 octave::mach_info::float_format fmt) | 999 octave::mach_info::float_format fmt) |
954 { | 1000 { |
955 return xload_binary (is, swap, fmt, m_range, true); | 1001 return xload_binary (is, swap, fmt, m_range, true); |
956 } | 1002 } |
1003 | |
1004 #endif | |
957 | 1005 |
958 /* | 1006 /* |
959 %!test | 1007 %!test |
960 %! a = b = 1:4; | 1008 %! a = b = 1:4; |
961 %! sv_file = [tempname(), ".dat"]; | 1009 %! sv_file = [tempname(), ".dat"]; |
1099 | 1147 |
1100 return false; | 1148 return false; |
1101 #endif | 1149 #endif |
1102 } | 1150 } |
1103 | 1151 |
1152 // For now, disable all but ov_range<double>. | |
1153 | |
1154 #if 0 | |
1155 | |
1104 template <> | 1156 template <> |
1105 bool | 1157 bool |
1106 ov_range<octave_uint8>::save_hdf5 (octave_hdf5_id loc_id, const char *name, | 1158 ov_range<octave_uint8>::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
1107 bool save_as_floats) | 1159 bool save_as_floats) |
1108 { | 1160 { |
1175 | 1227 |
1176 return false; | 1228 return false; |
1177 #endif | 1229 #endif |
1178 } | 1230 } |
1179 | 1231 |
1232 #endif | |
1233 | |
1180 #if defined (HAVE_HDF5) | 1234 #if defined (HAVE_HDF5) |
1181 | 1235 |
1182 template <typename T> | 1236 template <typename T> |
1183 bool | 1237 bool |
1184 xload_hdf5 (octave_hdf5_id loc_id, const char *name, octave::range<T>& r, | 1238 xload_hdf5 (octave_hdf5_id loc_id, const char *name, octave::range<T>& r, |
1258 | 1312 |
1259 return false; | 1313 return false; |
1260 #endif | 1314 #endif |
1261 } | 1315 } |
1262 | 1316 |
1317 // For now, disable all but ov_range<double>. | |
1318 | |
1319 #if 0 | |
1320 | |
1263 template <> | 1321 template <> |
1264 bool | 1322 bool |
1265 ov_range<octave_uint8>::load_hdf5 (octave_hdf5_id loc_id, const char *name) | 1323 ov_range<octave_uint8>::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
1266 { | 1324 { |
1267 #if defined (HAVE_HDF5) | 1325 #if defined (HAVE_HDF5) |
1321 warn_load ("hdf5"); | 1379 warn_load ("hdf5"); |
1322 | 1380 |
1323 return false; | 1381 return false; |
1324 #endif | 1382 #endif |
1325 } | 1383 } |
1384 | |
1385 #endif | |
1326 | 1386 |
1327 /* | 1387 /* |
1328 %!testif HAVE_HDF5 | 1388 %!testif HAVE_HDF5 |
1329 %! a = b = 1:4; | 1389 %! a = b = 1:4; |
1330 %! sv_file = [tempname(), ".h5"]; | 1390 %! sv_file = [tempname(), ".h5"]; |
1381 } | 1441 } |
1382 | 1442 |
1383 // Specializations. | 1443 // Specializations. |
1384 | 1444 |
1385 template <> | 1445 template <> |
1446 octave::range<double> | |
1447 ov_range<double>::range_value (void) const | |
1448 { | |
1449 return m_range; | |
1450 } | |
1451 | |
1452 // For now, disable all but ov_range<double>. | |
1453 | |
1454 #if 0 | |
1455 | |
1456 template <> | |
1386 octave::range<float> | 1457 octave::range<float> |
1387 ov_range<float>::float_range_value (void) const | 1458 ov_range<float>::float_range_value (void) const |
1388 { | 1459 { |
1389 return m_range; | 1460 return m_range; |
1390 } | 1461 } |
1391 | 1462 |
1392 template <> | 1463 template <> |
1393 octave::range<double> | |
1394 ov_range<double>::range_value (void) const | |
1395 { | |
1396 return m_range; | |
1397 } | |
1398 | |
1399 template <> | |
1400 octave::range<octave_int8> | 1464 octave::range<octave_int8> |
1401 ov_range<octave_int8>::int8_range_value (void) const | 1465 ov_range<octave_int8>::int8_range_value (void) const |
1402 { | 1466 { |
1403 return m_range; | 1467 return m_range; |
1404 } | 1468 } |
1449 octave::range<octave_uint64> | 1513 octave::range<octave_uint64> |
1450 ov_range<octave_uint64>::uint64_range_value (void) const | 1514 ov_range<octave_uint64>::uint64_range_value (void) const |
1451 { | 1515 { |
1452 return m_range; | 1516 return m_range; |
1453 } | 1517 } |
1518 | |
1519 #endif | |
1454 | 1520 |
1455 template <> | 1521 template <> |
1456 octave::idx_vector | 1522 octave::idx_vector |
1457 ov_range<double>::index_vector (bool require_integers) const | 1523 ov_range<double>::index_vector (bool require_integers) const |
1458 { | 1524 { |