/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef FIND_H
#define FIND_H
#include
#include
namespace Matfun {
using Eigen::ArrayXi;
using Eigen::Dynamic;
using Eigen::Index;
using Eigen::Vector;
using Eigen::SparseVector;
//! Find indices of 1-elements in vector
[[nodiscard, maybe_unused]] static ArrayXi
find( const Vector & cond)
{
ArrayXi idx( cond.count() );
for (int i=0, k=0; i
[[nodiscard]] static Vector
find( const SparseVector & v)
{
Vector idx( v.nonZeros() );
Index i=0;
for ( typename SparseVector::InnerIterator it(v); it; ++it) {
idx(i++) = it.index();
}
return idx;
}
} // namespace Matfun
// //! Matlab's find(x,1,'first')
// template
// [[nodiscard]] static Index indexOf(const Eigen::Vector &v, const T x)
// {
// for ( Index i=0; i