Mercurial > octave-nkf
comparison src/data.cc @ 14491:5bd9e47e9277
maint: periodic merge of stable to default
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 22 Mar 2012 11:50:51 -0400 |
parents | eff4a5933e28 3959f3f81e33 |
children | c4ed0fdf2b62 |
comparison
equal
deleted
inserted
replaced
14489:f36301ea650f | 14491:5bd9e47e9277 |
---|---|
1283 octave_value arg0 = args(0); | 1283 octave_value arg0 = args(0); |
1284 if (arg0.ndims () == 2 && (args(0).rows () == 1 || args(0).columns () == 1)) | 1284 if (arg0.ndims () == 2 && (args(0).rows () == 1 || args(0).columns () == 1)) |
1285 { | 1285 { |
1286 octave_idx_type m = args(1).int_value (), n = args(2).int_value (); | 1286 octave_idx_type m = args(1).int_value (), n = args(2).int_value (); |
1287 if (! error_state) | 1287 if (! error_state) |
1288 retval = arg0.diag ().resize (dim_vector (m, n)); | 1288 retval = arg0.diag ().resize (dim_vector (m, n), true); |
1289 else | 1289 else |
1290 error ("diag: invalid dimensions"); | 1290 error ("diag: invalid dimensions"); |
1291 } | 1291 } |
1292 else | 1292 else |
1293 error ("diag: V must be a vector"); | 1293 error ("diag: V must be a vector"); |
1297 | 1297 |
1298 return retval; | 1298 return retval; |
1299 } | 1299 } |
1300 | 1300 |
1301 /* | 1301 /* |
1302 %!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]) | 1302 |
1303 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]) | 1303 %!assert(full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]) |
1304 %!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]) | 1304 %!assert(diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]) |
1305 %!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]) | 1305 %!assert(diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]) |
1306 %!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]) | 1306 %!assert(diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]) |
1307 | 1307 %!assert(diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]) |
1308 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]) | 1308 |
1309 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]) | 1309 %!assert(diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]) |
1310 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]) | 1310 %!assert(diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]) |
1311 %!assert (diag (ones (1, 0), 2), zeros (2)) | 1311 %!assert(diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]) |
1312 %!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0]) | 1312 %!assert(diag (ones(1, 0), 2), zeros (2)) |
1313 | 1313 %!assert(diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0]) |
1314 %!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3])) | 1314 |
1315 %!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) | 1315 %!assert(full (diag (single([1; 2; 3]))), single([1, 0, 0; 0, 2, 0; 0, 0, 3])) |
1316 %!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) | 1316 %!assert(diag (single([1; 2; 3]), 1), single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) |
1317 %!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) | 1317 %!assert(diag (single([1; 2; 3]), 2), single([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) |
1318 %!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) | 1318 %!assert(diag (single([1; 2; 3]),-1), single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) |
1319 | 1319 %!assert(diag (single([1; 2; 3]),-2), single([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) |
1320 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3])) | 1320 |
1321 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3])) | 1321 %!assert(diag (single([1, 0, 0; 0, 2, 0; 0, 0, 3])), single([1; 2; 3])) |
1322 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3])) | 1322 %!assert(diag (single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single([1; 2; 3])) |
1323 | 1323 %!assert(diag (single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single([1; 2; 3])) |
1324 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])) | 1324 |
1325 %!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) | 1325 %!assert(diag (int8([1; 2; 3])), int8([1, 0, 0; 0, 2, 0; 0, 0, 3])) |
1326 %!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) | 1326 %!assert(diag (int8([1; 2; 3]), 1), int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) |
1327 %!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) | 1327 %!assert(diag (int8([1; 2; 3]), 2), int8([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) |
1328 %!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) | 1328 %!assert(diag (int8([1; 2; 3]),-1), int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) |
1329 | 1329 %!assert(diag (int8([1; 2; 3]),-2), int8([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) |
1330 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3])) | 1330 |
1331 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3])) | 1331 %!assert(diag (int8([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8([1; 2; 3])) |
1332 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3])) | 1332 %!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3])) |
1333 | 1333 %!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3])) |
1334 ## Test input validation | 1334 |
1335 %!error diag () | 1335 ## Test non-square size |
1336 %!error diag (1,2,3,4) | 1336 %!assert(diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0]) |
1337 | |
1338 %% Test input validation | |
1339 %!error <Invalid call to diag> diag () | |
1340 %!error <Invalid call to diag> diag (1,2,3,4) | |
1337 %!error diag (ones (2), 3, 3) | 1341 %!error diag (ones (2), 3, 3) |
1338 %!error diag (1:3, -4, 3) | 1342 %!error diag (1:3, -4, 3) |
1339 */ | 1343 |
1344 */ | |
1340 | 1345 |
1341 DEFUN (prod, args, , | 1346 DEFUN (prod, args, , |
1342 "-*- texinfo -*-\n\ | 1347 "-*- texinfo -*-\n\ |
1343 @deftypefn {Built-in Function} {} prod (@var{x})\n\ | 1348 @deftypefn {Built-in Function} {} prod (@var{x})\n\ |
1344 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\ | 1349 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |