This file is indexed.

/usr/include/roboptim/core/filter/cached-function.hxx is in libroboptim-core-dev 2.0-7.

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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright (C) 2010 by Thomas Moulard, AIST, CNRS, INRIA.
//
// This file is part of the roboptim.
//
// roboptim is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// roboptim 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with roboptim.  If not, see <http://www.gnu.org/licenses/>.

#ifndef ROBOPTIM_CORE_FILTER_CACHED_FUNCTION_HXX
# define ROBOPTIM_CORE_FILTER_CACHED_FUNCTION_HXX
# include <boost/format.hpp>

# include <roboptim/core/derivative-size.hh>

namespace roboptim
{
  namespace
  {
    template <typename T>
    std::string cachedFunctionName (const T& fct);

    template <typename T>
    std::string cachedFunctionName (const T& fct)
    {
      boost::format fmt ("%1% (cached)");
      fmt % fct.getName ();
      return fmt.str ();
    }

  } // end of anonymous namespace.

  template <typename T>
  CachedFunction<T>::CachedFunction (boost::shared_ptr<const T> fct) throw ()
    : T (fct->inputSize (), fct->outputSize (), cachedFunctionName (*fct)),
      function_ (fct),
      cache_ (derivativeSize<T>::value),
      gradientCache_ (static_cast<std::size_t> (fct->outputSize ())),
      hessianCache_ (static_cast<std::size_t> (fct->outputSize ()))
  {
  }

  template <typename T>
  CachedFunction<T>::~CachedFunction () throw ()
  {
  }

  template <typename T>
  void
  CachedFunction<T>::reset () throw ()
  {
    cache_.clear ();
    gradientCache_.clear ();
    hessianCache_.clear ();
  }


  template <typename T>
  void
  CachedFunction<T>::impl_compute (result_t& result,
				   const argument_t& argument)
    const throw ()
  {
    functionCache_t::const_iterator it = cache_[0].find (argument);
    if (it != cache_[0].end ())
      {
	result = it->second;
	return;
      }
    (*function_) (result, argument);
    cache_[0][argument] = result;
  }


  template <>
  void
  CachedFunction<Function>::impl_gradient (gradient_t&, const argument_t&, size_type)
    const throw ()
  {
    assert (0);
  }

  template <typename T>
  void
  CachedFunction<T>::impl_gradient (gradient_t& gradient,
				    const argument_t& argument,
				    size_type functionId)
    const throw ()
  {
    functionCache_t::const_iterator it =
      gradientCache_[static_cast<std::size_t> (functionId)].find (argument);
    if (it != gradientCache_[static_cast<std::size_t> (functionId)].end ())
      {
	gradient = it->second;
	return;
      }
    function_->gradient (gradient, argument, functionId);
    gradientCache_[static_cast<std::size_t> (functionId)][argument] = gradient;
  }




  template <>
  void
  CachedFunction<Function>::impl_hessian
  (hessian_t&, const argument_t&, size_type) const throw ()
  {
    assert (0);
  }

  template <>
  void
  CachedFunction<DifferentiableFunction>::impl_hessian
  (hessian_t&, const argument_t&, size_type) const throw ()
  {
    assert (0);
  }



  template <typename T>
  void
  CachedFunction<T>::impl_hessian (hessian_t& hessian,
  				   const argument_t& argument,
  				   size_type functionId)
    const throw ()
  {
    //FIXME: bug detected by Clang. To be fixed.
#ifdef ROBOPTIM_CORE_THIS_DOES_NOT_WORK
    functionCache_t::const_iterator it =
      hessianCache_[static_cast<std::size_t> (functionId)].find (argument);
    if (it != hessianCache_[functionId].end ())
      {
	hessian = it->second;
	return;
      }
#endif
    function_->hessian (hessian, argument, functionId);
    hessianCache_[static_cast<std::size_t> (functionId)][argument] = hessian;
  }


  template <>
  void
  CachedFunction<Function>::impl_derivative
  (gradient_t&, double, size_type) const throw ()
  {
    assert (0);
  }

  template <>
  void
  CachedFunction<DifferentiableFunction>::impl_derivative
  (gradient_t&, double, size_type) const throw ()
  {
    assert (0);
  }

  template <>
  void
  CachedFunction<TwiceDifferentiableFunction>::impl_derivative
  (gradient_t&, double, size_type) const throw ()
  {
    assert (0);
  }

  template <typename T>
  void
  CachedFunction<T>::impl_derivative (gradient_t& derivative,
  				      double argument,
  				      size_type order)
    const throw ()
  {
    vector_t x (1);
    x[0] = argument;
    functionCache_t::const_iterator it = cache_[order].find (x);
    if (it != cache_[order].end ())
      {
	derivative = it->second;
	return;
      }
    function_->derivative (derivative, x, order);
    cache_[order][x] = derivative;
  }

} // end of namespace roboptim

#endif //! ROBOPTIM_CORE_FILTER_CACHED_FUNCTION_HXX