Mercurial > hg > octave-lyh
comparison liboctave/Array.cc @ 9058:2da105bf2507
remove redundant checks from Array<T>::index
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 29 Mar 2009 18:09:44 +0200 |
parents | 88bf56bbccca |
children | 1a8bbfb2f7cf |
comparison
equal
deleted
inserted
replaced
9057:8b263623d0f3 | 9058:2da105bf2507 |
---|---|
1270 | 1270 |
1271 resize_fill (nx, rfv); | 1271 resize_fill (nx, rfv); |
1272 n = numel (); | 1272 n = numel (); |
1273 } | 1273 } |
1274 | 1274 |
1275 // If the resizing was ambiguous, resize has already griped. | 1275 if (i.is_colon ()) |
1276 if (nx == n) | 1276 { |
1277 { | 1277 // A(:) = X makes a full fill or a shallow copy. |
1278 if (i.is_colon ()) | 1278 if (rhl == 1) |
1279 { | 1279 fill (rhs(0)); |
1280 // A(:) = X makes a full fill or a shallow copy. | |
1281 if (rhl == 1) | |
1282 fill (rhs(0)); | |
1283 else | |
1284 *this = rhs.reshape (dimensions); | |
1285 } | |
1286 else | 1280 else |
1287 { | 1281 *this = rhs.reshape (dimensions); |
1288 if (rhl == 1) | 1282 } |
1289 i.fill (rhs(0), n, fortran_vec ()); | 1283 else |
1290 else | 1284 { |
1291 i.assign (rhs.data (), n, fortran_vec ()); | 1285 if (rhl == 1) |
1292 } | 1286 i.fill (rhs(0), n, fortran_vec ()); |
1287 else | |
1288 i.assign (rhs.data (), n, fortran_vec ()); | |
1293 } | 1289 } |
1294 } | 1290 } |
1295 else | 1291 else |
1296 gripe_invalid_assignment_size (); | 1292 gripe_invalid_assignment_size (); |
1297 } | 1293 } |
1343 | 1339 |
1344 resize (rdv, rfv); | 1340 resize (rdv, rfv); |
1345 dv = dimensions; | 1341 dv = dimensions; |
1346 } | 1342 } |
1347 | 1343 |
1348 // If the resizing was invalid, resize has already griped. | 1344 if (i.is_colon () && j.is_colon ()) |
1349 if (dv == rdv) | 1345 { |
1350 { | 1346 // A(:,:) = X makes a full fill or a shallow copy |
1351 if (i.is_colon () && j.is_colon ()) | 1347 if (isfill) |
1352 { | 1348 fill (rhs(0)); |
1353 // A(:,:) = X makes a full fill or a shallow copy | 1349 else |
1350 *this = rhs.reshape (dimensions); | |
1351 } | |
1352 else | |
1353 { | |
1354 // The actual work. | |
1355 octave_idx_type n = numel (), r = dv (0), c = dv (1); | |
1356 idx_vector ii (i); | |
1357 | |
1358 const T* src = rhs.data (); | |
1359 T *dest = fortran_vec (); | |
1360 | |
1361 // Try reduction first. | |
1362 if (ii.maybe_reduce (r, j, c)) | |
1363 { | |
1354 if (isfill) | 1364 if (isfill) |
1355 fill (rhs(0)); | 1365 ii.fill (*src, n, dest); |
1356 else | 1366 else |
1357 *this = rhs.reshape (dimensions); | 1367 ii.assign (src, n, dest); |
1358 } | 1368 } |
1359 else | 1369 else |
1360 { | 1370 { |
1361 // The actual work. | 1371 if (isfill) |
1362 octave_idx_type n = numel (), r = dv (0), c = dv (1); | |
1363 idx_vector ii (i); | |
1364 | |
1365 const T* src = rhs.data (); | |
1366 T *dest = fortran_vec (); | |
1367 | |
1368 // Try reduction first. | |
1369 if (ii.maybe_reduce (r, j, c)) | |
1370 { | 1372 { |
1371 if (isfill) | 1373 for (octave_idx_type k = 0; k < jl; k++) |
1372 ii.fill (*src, n, dest); | 1374 i.fill (*src, r, dest + r * j.xelem (k)); |
1373 else | |
1374 ii.assign (src, n, dest); | |
1375 } | 1375 } |
1376 else | 1376 else |
1377 { | 1377 { |
1378 if (isfill) | 1378 for (octave_idx_type k = 0; k < jl; k++) |
1379 { | 1379 src += i.assign (src, r, dest + r * j.xelem (k)); |
1380 for (octave_idx_type k = 0; k < jl; k++) | |
1381 i.fill (*src, r, dest + r * j.xelem (k)); | |
1382 } | |
1383 else | |
1384 { | |
1385 for (octave_idx_type k = 0; k < jl; k++) | |
1386 src += i.assign (src, r, dest + r * j.xelem (k)); | |
1387 } | |
1388 } | 1380 } |
1389 } | 1381 } |
1390 | 1382 } |
1391 } | |
1392 | |
1393 } | 1383 } |
1394 else | 1384 else |
1395 gripe_assignment_dimension_mismatch (); | 1385 gripe_assignment_dimension_mismatch (); |
1396 } | 1386 } |
1397 | 1387 |
1454 resize_fill (rdv, rfv); | 1444 resize_fill (rdv, rfv); |
1455 dv = dimensions; | 1445 dv = dimensions; |
1456 chop_trailing_singletons (); | 1446 chop_trailing_singletons (); |
1457 } | 1447 } |
1458 | 1448 |
1459 // If the resizing was invalid, resize has already griped. | 1449 if (all_colons) |
1460 if (dv == rdv) | 1450 { |
1461 { | 1451 // A(:,:,...,:) = X makes a full fill or a shallow copy. |
1462 if (all_colons) | 1452 if (isfill) |
1463 { | 1453 fill (rhs(0)); |
1464 // A(:,:,...,:) = X makes a full fill or a shallow copy. | |
1465 if (isfill) | |
1466 fill (rhs(0)); | |
1467 else | |
1468 *this = rhs.reshape (dimensions); | |
1469 } | |
1470 else | 1454 else |
1471 { | 1455 *this = rhs.reshape (dimensions); |
1472 // Do the actual work. | 1456 } |
1473 | 1457 else |
1474 // Prepare for recursive indexing | 1458 { |
1475 rec_index_helper rh (dv, ia); | 1459 // Do the actual work. |
1476 | 1460 |
1477 // Do it. | 1461 // Prepare for recursive indexing |
1478 if (isfill) | 1462 rec_index_helper rh (dv, ia); |
1479 rh.fill (rhs(0), fortran_vec ()); | 1463 |
1480 else | 1464 // Do it. |
1481 rh.assign (rhs.data (), fortran_vec ()); | 1465 if (isfill) |
1482 } | 1466 rh.fill (rhs(0), fortran_vec ()); |
1467 else | |
1468 rh.assign (rhs.data (), fortran_vec ()); | |
1483 } | 1469 } |
1484 } | 1470 } |
1485 else | 1471 else |
1486 gripe_assignment_dimension_mismatch (); | 1472 gripe_assignment_dimension_mismatch (); |
1487 } | 1473 } |