Changeset 879 for trunk/yat/utility


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

Location:
trunk/yat/utility
Files:
2 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
  • trunk/yat/utility/vector.h

    r878 r879  
    547547  void sort_index(std::vector<size_t>& sort_index, const vector& invec);
    548548
     549  /** Similar to sort_index but creates a vector with indices to the \a k
     550  smallest elements in \a invec. 
     551  */
     552  void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, const
     553  vector& invec);
     554
     555  /** Similar to sort_index but creates a vector with indices to the \a k
     556  largest elements in \a invec. 
     557  */
     558  void sort_largest_index(std::vector<size_t>& sort_index, size_t k, const
     559  vector& invec);
     560
     561 
    549562
    550563  /**
Note: See TracChangeset for help on using the changeset viewer.