Mercurial > octave-nkf
comparison src/utils.cc @ 10033:f349847c4541
optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 27 Dec 2009 21:56:53 +0100 |
parents | 10519b4d6507 |
children | 2cd940306a06 |
comparison
equal
deleted
inserted
replaced
10032:691b4ba32425 | 10033:f349847c4541 |
---|---|
1043 } | 1043 } |
1044 | 1044 |
1045 return retval; | 1045 return retval; |
1046 } | 1046 } |
1047 | 1047 |
1048 void | |
1049 decode_subscripts (const char* name, const octave_value& arg, | |
1050 std::string& type_string, | |
1051 std::list<octave_value_list>& idx) | |
1052 { | |
1053 Octave_map m = arg.map_value (); | |
1054 | |
1055 if (! error_state | |
1056 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) | |
1057 { | |
1058 Cell& type = m.contents ("type"); | |
1059 Cell& subs = m.contents ("subs"); | |
1060 | |
1061 type_string = std::string (type.length(), '\0'); | |
1062 | |
1063 for (int k = 0; k < type.length (); k++) | |
1064 { | |
1065 std::string item = type(k).string_value (); | |
1066 | |
1067 if (! error_state) | |
1068 { | |
1069 if (item == "{}") | |
1070 type_string[k] = '{'; | |
1071 else if (item == "()") | |
1072 type_string[k] = '('; | |
1073 else if (item == ".") | |
1074 type_string[k] = '.'; | |
1075 else | |
1076 { | |
1077 error("%s: invalid indexing type `%s'", name, item.c_str ()); | |
1078 return; | |
1079 } | |
1080 } | |
1081 else | |
1082 { | |
1083 error ("%s: expecting type(%d) to be a character string", | |
1084 name, k+1); | |
1085 return; | |
1086 } | |
1087 | |
1088 octave_value_list idx_item; | |
1089 | |
1090 if (subs(k).is_string ()) | |
1091 idx_item(0) = subs(k); | |
1092 else if (subs(k).is_cell ()) | |
1093 { | |
1094 Cell subs_cell = subs(k).cell_value (); | |
1095 | |
1096 for (int n = 0; n < subs_cell.length (); n++) | |
1097 { | |
1098 if (subs_cell(n).is_string () | |
1099 && subs_cell(n).string_value () == ":") | |
1100 idx_item(n) = octave_value(octave_value::magic_colon_t); | |
1101 else | |
1102 idx_item(n) = subs_cell(n); | |
1103 } | |
1104 } | |
1105 else | |
1106 { | |
1107 error ("%s: expecting subs(%d) to be a character string or cell array", | |
1108 name, k+1); | |
1109 return; | |
1110 } | |
1111 | |
1112 idx.push_back (idx_item); | |
1113 } | |
1114 } | |
1115 else | |
1116 error ("%s: second argument must be a structure with fields `type' and `subs'", name); | |
1117 } | |
1118 | |
1048 Matrix | 1119 Matrix |
1049 identity_matrix (octave_idx_type nr, octave_idx_type nc) | 1120 identity_matrix (octave_idx_type nr, octave_idx_type nc) |
1050 { | 1121 { |
1051 Matrix m (nr, nc, 0.0); | 1122 Matrix m (nr, nc, 0.0); |
1052 | 1123 |