Changeset 877
 Timestamp:
 Sep 20, 2007, 9:01:57 PM (15 years ago)
 Location:
 trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/vector_test.cc
r865 r877 267 267 ok &= this_ok; 268 268 269 std::string data3("data/vector3.data"); 270 std::ifstream data_stream3(data3.c_str()); 271 utility::vector vec3(data_stream3); 272 std::vector<size_t> dummy; 273 utility::sort_index(dummy,vec3); 274 for(size_t i=0;i<dummy.size();i++) { 275 *message << "dummy: " << dummy[i] << std::endl; 276 } 277 269 278 if (!ok) 270 279 *message << "vector test failed" << std::endl; 
trunk/yat/utility/vector.cc
r865 r877 513 513 514 514 515 void sort_index(std::vector<size_t>& sort_index, const vector& invec) 516 { 517 assert(invec.gsl_vector_p()); 518 gsl_permutation* p = gsl_permutation_alloc(invec.size()); 519 int status=gsl_sort_vector_index(p,invec.gsl_vector_p()); 520 if (status) { 521 gsl_permutation_free(p); 522 throw utility::GSL_error(std::string("sort_index(vector&,const vector&)",status)); 523 } 524 for(size_t i=0;i<p>size;i++) { 525 sort_index.resize(0); 526 sort_index.push_back(gsl_permutation_get(p,i)); 527 } 528 gsl_permutation_free(p); 529 } 530 531 532 515 533 double sum(const vector& v) 516 534 { 
trunk/yat/utility/vector.h
r865 r877 536 536 537 537 /** 538 Create a vector \a sort_index containing the indeces of 539 elements in a another vector \a invec. The elements of \a 540 sort_index give the index of the vector element which would 541 have been stored in that position if the vector had been sorted 542 in place. The first element of \a sort_index gives the index of the least 543 element in \a invec, and the last element of \a sort_index gives the index of the 544 greatest element in \a invec . The vector \a invec is not changed. 545 546 */ 547 void sort_index(std::vector<size_t>& sort_index, vector& invec); 548 549 550 /** 538 551 \brief Calculate the sum of all vector elements. 539 552
Note: See TracChangeset
for help on using the changeset viewer.