Ignore:
Timestamp:
Sep 21, 2007, 4:10:07 PM (14 years ago)
Author:
Markus Ringnér
Message:

Added support to utility::vector for gsl-functions that finds indices to the k largest/smallest elements in a vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/vector.cc

    r877 r879  
    522522      throw utility::GSL_error(std::string("sort_index(vector&,const vector&)",status));     
    523523    }
    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     }
     524    sort_index=std::vector<size_t>(p->data,p->data+p->size);
    528525    gsl_permutation_free(p);
    529526  }
    530527
     528
     529  void sort_smallest_index(std::vector<size_t>& sort_index, size_t k,
     530                            const vector& invec)
     531  {
     532    assert(invec.gsl_vector_p());
     533    assert(k<=invec.size());
     534    sort_index.resize(k);
     535    gsl_sort_vector_smallest_index(&sort_index[0],k,invec.gsl_vector_p());
     536  }
     537 
     538  void sort_largest_index(std::vector<size_t>& sort_index, size_t k,
     539                            const vector& invec)
     540  {
     541    assert(invec.gsl_vector_p());
     542    assert(k<=invec.size());
     543    sort_index.resize(k);
     544    gsl_sort_vector_largest_index(&sort_index[0],k,invec.gsl_vector_p());
     545  }
    531546
    532547
Note: See TracChangeset for help on using the changeset viewer.