/usr/include/ITK-4.5/vnl/vnl_power.h is in libinsighttoolkit4-dev 4.5.0-3.
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 | // This is core/vnl/vnl_power.h
#ifndef vnl_power_h_
#define vnl_power_h_
//:
// \file
// \brief Calculates nth power of a small vnl_matrix_fixed (not using svd)
// \author Peter Vanroose
// \date 21 July 2009
//
// \verbatim
// Modifications
// <none yet>
// \endverbatim
#include <vnl/vnl_matrix_fixed.h>
#include <vnl/vnl_matrix.h>
#include <vnl/vnl_inverse.h> // used for negative powers
#include <vcl_cassert.h>
//: Calculates nth power of a vnl_matrix_fixed (not using svd)
// This allows you to write e.g.
//
// x = vnl_power(A,7) * vnl_power(B,-4) * b;
//
// Note that this function is inlined (except for the call to vnl_inverse()),
// which makes it much faster than a full-fledged square matrix power
// implementation using svd, which belongs in vnl/algo.
//
// \relatesalso vnl_matrix_fixed
template <class T, unsigned int d>
vnl_matrix_fixed<T,d,d> vnl_power(vnl_matrix_fixed<T,d,d> const& m, int n)
{
assert(n >= 0 || d <= 4); // to allow the use of vnl_inverse()
if (n == 0)
return vnl_matrix_fixed<T,d,d>().set_identity();
else if (n == 1 || m.is_identity())
return m;
else if (n < 0)
return vnl_inverse(vnl_power(m, -n));
else {
vnl_matrix_fixed<T,d,d> r = vnl_power(m, n/2);
return n%2==0 ? r * r : r * r * m;
}
}
//: Calculates nth power of a square vnl_matrix (not using svd)
// This allows you to write e.g.
//
// x = vnl_power(A,7) * vnl_power(B,-4) * b;
//
// Note that this function is inlined (except for the call to vnl_inverse()),
// which makes it much faster than a full-fledged square matrix power
// implementation using svd, which belongs in vnl/algo.
//
// \relatesalso vnl_matrix
template <class T>
vnl_matrix<T> vnl_power(vnl_matrix<T> const& m, int n)
{
assert(m.rows() == m.columns());
assert(n >= 0 || m.rows() <= 4);
if (n == 0)
return vnl_matrix<T>(m.rows(),m.columns()).set_identity();
else if (n == 1 || m.is_identity())
return m;
else if (n < 0 && m.rows() == 1)
return vnl_power(vnl_matrix_fixed<T,1,1>(m),n).as_ref();
else if (n < 0 && m.rows() == 2)
return vnl_power(vnl_matrix_fixed<T,2,2>(m),n).as_ref();
else if (n < 0 && m.rows() == 3)
return vnl_power(vnl_matrix_fixed<T,3,3>(m),n).as_ref();
else if (n < 0 && m.rows() == 4)
return vnl_power(vnl_matrix_fixed<T,4,4>(m),n).as_ref();
else {
vnl_matrix<T> r = vnl_power(m, n/2);
return n%2==0 ? r * r : r * r * m;
}
}
#endif // vnl_power_h_
|