Mercurial > octave-nkf
comparison liboctave/fMatrix.cc @ 9653:e087d7c77ff9
improve linspace in liboctave
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 18 Sep 2009 15:27:09 +0200 |
parents | a9b37bae1802 |
children | 3429c956de6f |
comparison
equal
deleted
inserted
replaced
9652:ecdb275bd41b | 9653:e087d7c77ff9 |
---|---|
3392 } | 3392 } |
3393 | 3393 |
3394 return result; | 3394 return result; |
3395 } | 3395 } |
3396 | 3396 |
3397 FloatMatrix linspace (const FloatColumnVector& x1, | |
3398 const FloatColumnVector& x2, | |
3399 octave_idx_type n) | |
3400 | |
3401 { | |
3402 if (n < 1) n = 1; | |
3403 | |
3404 octave_idx_type m = x1.length (); | |
3405 | |
3406 if (x2.length () != m) | |
3407 (*current_liboctave_error_handler) ("linspace: vectors must be of equal length"); | |
3408 | |
3409 NoAlias<FloatMatrix> retval; | |
3410 | |
3411 retval.clear (m, n); | |
3412 for (octave_idx_type i = 0; i < m; i++) | |
3413 retval(i, 0) = x1(i); | |
3414 | |
3415 // The last column is not needed while using delta. | |
3416 float *delta = &retval(0, 1); | |
3417 for (octave_idx_type i = 0; i < m; i++) | |
3418 delta[i] = (x2(i) - x1(i)) / (n - 1); | |
3419 | |
3420 for (octave_idx_type j = 1; j < n-1; j++) | |
3421 for (octave_idx_type i = 0; i < m; i++) | |
3422 retval(i, j) = retval(i, j-1) + delta[i]; | |
3423 | |
3424 for (octave_idx_type i = 0; i < m; i++) | |
3425 retval(i, n-1) = x2(i); | |
3426 | |
3427 return retval; | |
3428 } | |
3429 | |
3397 MS_CMP_OPS (FloatMatrix, float) | 3430 MS_CMP_OPS (FloatMatrix, float) |
3398 MS_BOOL_OPS (FloatMatrix, float) | 3431 MS_BOOL_OPS (FloatMatrix, float) |
3399 | 3432 |
3400 SM_CMP_OPS (float, FloatMatrix) | 3433 SM_CMP_OPS (float, FloatMatrix) |
3401 SM_BOOL_OPS (float, FloatMatrix) | 3434 SM_BOOL_OPS (float, FloatMatrix) |