Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Added minimum and maximum of STL-vector
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Jul 16, 2018
1 parent 2bce108 commit f0c69c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cppmat/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ template<typename X> std::string to_string(const std::vector<X> &A, std::string
// linearly spaced array
template <typename T = double> std::vector<T> linspace(T a, T b, size_t N);

// minimum/maximum
template<typename X> X min(const std::vector<X> &A);
template<typename X> X max(const std::vector<X> &A);

// minimum/maximum of each entry
template<typename X> std::vector<X> min(const std::vector<X> &A, const std::vector<X> &B);
template<typename X> std::vector<X> max(const std::vector<X> &A, const std::vector<X> &B);
Expand Down
18 changes: 17 additions & 1 deletion src/cppmat/stl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,23 @@ std::vector<T> linspace(T a, T b, size_t N)
}

// =================================================================================================
// minimum/maximum from two vector of equal size
// minimum/maximum from a vector
// =================================================================================================

template<typename X> X min(const std::vector<X> &A)
{
return *std::min_element(A.begin(),A.end());
}

// -------------------------------------------------------------------------------------------------

template<typename X> X max(const std::vector<X> &A)
{
return *std::max_element(A.begin(),A.end());
}

// =================================================================================================
// minimum/maximum from two vectors of equal size
// =================================================================================================

template<typename X> std::vector<X> min(const std::vector<X> &A, const std::vector<X> &B)
Expand Down

0 comments on commit f0c69c3

Please sign in to comment.