comparison src/xpow.cc @ 8979:a7c00773a089

optimize also .^-1 case
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 13 Mar 2009 22:54:37 +0100
parents 0a58c4cd1405
children 10bed8fbec99
comparison
equal deleted inserted replaced
8978:0a58c4cd1405 8979:a7c00773a089
1121 if (ib == 2) 1121 if (ib == 2)
1122 { 1122 {
1123 for (octave_idx_type i = 0; i < a.length (); i++) 1123 for (octave_idx_type i = 0; i < a.length (); i++)
1124 result.xelem (i) = a(i) * a(i); 1124 result.xelem (i) = a(i) * a(i);
1125 } 1125 }
1126 else if (ib == -1)
1127 {
1128 for (octave_idx_type i = 0; i < a.length (); i++)
1129 result.xelem (i) = 1.0 / a(i);
1130 }
1126 else 1131 else
1127 { 1132 {
1128 for (octave_idx_type i = 0; i < a.length (); i++) 1133 for (octave_idx_type i = 0; i < a.length (); i++)
1129 { 1134 {
1130 OCTAVE_QUIT; 1135 OCTAVE_QUIT;
1280 { 1285 {
1281 ComplexNDArray result (a.dims ()); 1286 ComplexNDArray result (a.dims ());
1282 1287
1283 if (xisint (b)) 1288 if (xisint (b))
1284 { 1289 {
1285 for (octave_idx_type i = 0; i < a.length (); i++) 1290 if (b == -1)
1286 { 1291 {
1287 OCTAVE_QUIT; 1292 for (octave_idx_type i = 0; i < a.length (); i++)
1288 result(i) = std::pow (a(i), static_cast<int> (b)); 1293 result.xelem (i) = std::conj (a(i)) / std::norm (a(i));
1289 } 1294 }
1295 else
1296 {
1297 for (octave_idx_type i = 0; i < a.length (); i++)
1298 {
1299 OCTAVE_QUIT;
1300 result(i) = std::pow (a(i), static_cast<int> (b));
1301 }
1302 }
1290 } 1303 }
1291 else 1304 else
1292 { 1305 {
1293 for (octave_idx_type i = 0; i < a.length (); i++) 1306 for (octave_idx_type i = 0; i < a.length (); i++)
1294 { 1307 {
2423 if (ib == 2) 2436 if (ib == 2)
2424 { 2437 {
2425 for (octave_idx_type i = 0; i < a.length (); i++) 2438 for (octave_idx_type i = 0; i < a.length (); i++)
2426 result.xelem (i) = a(i) * a(i); 2439 result.xelem (i) = a(i) * a(i);
2427 } 2440 }
2441 else if (ib == -1)
2442 {
2443 for (octave_idx_type i = 0; i < a.length (); i++)
2444 result.xelem (i) = 1.0f / a(i);
2445 }
2428 else 2446 else
2429 { 2447 {
2430 for (octave_idx_type i = 0; i < a.length (); i++) 2448 for (octave_idx_type i = 0; i < a.length (); i++)
2431 { 2449 {
2432 OCTAVE_QUIT; 2450 OCTAVE_QUIT;
2582 { 2600 {
2583 FloatComplexNDArray result (a.dims ()); 2601 FloatComplexNDArray result (a.dims ());
2584 2602
2585 if (xisint (b)) 2603 if (xisint (b))
2586 { 2604 {
2587 for (octave_idx_type i = 0; i < a.length (); i++) 2605 if (b == -1)
2588 { 2606 {
2589 OCTAVE_QUIT; 2607 for (octave_idx_type i = 0; i < a.length (); i++)
2590 result(i) = std::pow (a(i), static_cast<int> (b)); 2608 result.xelem (i) = std::conj (a(i)) / std::norm (a(i));
2591 } 2609 }
2610 else
2611 {
2612 for (octave_idx_type i = 0; i < a.length (); i++)
2613 {
2614 OCTAVE_QUIT;
2615 result(i) = std::pow (a(i), static_cast<int> (b));
2616 }
2617 }
2592 } 2618 }
2593 else 2619 else
2594 { 2620 {
2595 for (octave_idx_type i = 0; i < a.length (); i++) 2621 for (octave_idx_type i = 0; i < a.length (); i++)
2596 { 2622 {