/usr/include/vigra/random_forest/splices.hxx is in libvigraimpex-dev 1.10.0+dfsg-3ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | #ifndef SPLICES_HXX
#define SPLICES_HXX
#include <vigra/multi_array.hxx>
#include <iterator>
namespace vigra
{
/** Idea for a class to use for easy splicing
*
* usage (with factory function _spl)
*
* // copy every even indexed element to a 5 x 5
* // sized matrix
* Matrix<double> a(10, 10)
* MultiArrayView<2,double> b(_spl_shp(_spl(0,2,10),
* _spl(0,2,10)));
* copy_splice(_spl(0,2,10),_spl(0,2,10), a, b);
*
* it is also possible to supply iterator ranges
* std::vector<int> indices;
* indices.push_back(3) (...)
*
* copy_splice(_spl(indices.begin(), indices.end()),
* _spl(a.shape(1)),
* a, b)
*
* if you only have a forward iterator then you must
* specify the size of the splice with
* _spl(set.begin(), set.end(), set.size());
*
* ok.. what we actually need is a decent iota iterator
* or something like xrange but for now it should suffice.
*/
template<class T>
class Splice
{
int size_;
T begin_;
T end_;
public:
Splice(T &begin, T &end)
: size_(std::distance(begin, end)),
begin_(begin),
end_(end)
{}
int operator[](int index)
{
T ii = begin_;
std::advance(ii, index);
return *ii;
}
int size()
{
return size_;
}
};
template<>
class Splice<int>
{
int begin_;
int interval_;
int end_;
int size_;
public:
Splice(int begin, int end)
: begin_(begin),
interval_(1),
end_(end),
size_(end - begin)
{}
Splice(int begin, int interval, int end)
: begin_(begin),
interval_(interval),
end_(end),
size_(int(std::floor((double(end) -double(begin))/interval)))
{}
int operator[](int index)
{
int ii = begin_ + index * interval_;
return ii;
}
int size()
{
return size_;
}
};
template<class T>
Splice<T> _spl(T b, T e)
{
return Splice<T>(b, e);
}
template<class T>
Splice<T> _spl(T b, int size, T e)
{
return Splice<T>(b, size, e);
}
inline Splice<int> _spl(int size)
{
return Splice<int>(0, size);
}
template<class T, class G>
inline MultiArrayShape<2>::type _spl_shp(Splice<T> f,
Splice<G> h)
{
return MultiArrayShape<2>::type(f.size(), h.size());
}
template< class R, class F,
class T, class C,
class T2, class C2 >
void copy_splice( Splice<R> _first,
Splice<F> _second,
MultiArrayView<2, T, C> src,
MultiArrayView<2, T2, C2> dest)
{
for(int jj = 0 ; jj < _second.size(); ++jj)
{
for(int ii = 0 ; ii < _first.size(); ++ii)
{
dest(ii, jj) = src(_first[ii], _second[jj]);
}
}
}
};
#endif //SPLICES_HXX
|