45 #ifndef ROL_VECTORWORKSPACE_HPP
46 #define ROL_VECTORWORKSPACE_HPP
100 template<
typename Real>
114 hash_code(typeid(x).hash_code()),
115 dimension( x.dimension() ) {}
122 ss <<
"VectorKey(" << hex << key.
hash_code <<
","
156 for(
auto v : vectors_ ) count += ( getCount(v) > 3 );
166 ROL_TEST_FOR_EXCEPTION( key_.hash_code != x_key.
hash_code, logic_error,
167 "VectorWorkspace::VectorStack tried to clone a vector of type " <<
168 hex << key_.hash_code <<
", but it can only clone vectors of type " <<
171 ROL_TEST_FOR_EXCEPTION( key_.dimension != x_key.
dimension, logic_error,
172 "VectorWorkspace::VectorStack tried to clone a vector of dimension " <<
173 hex << key_.dimension <<
", but it can only clone vectors of dimension " <<
176 for(
auto e : vectors_ ) {
177 if( getCount(e) <= 2 ) {
183 vectors_.push_back( v );
189 vector<size_type> counts;
190 for(
auto e: vectors_ ) counts.push_back( getCount(e) );
204 Ptr<VectorStack> vstack{nullPtr};
206 for(
auto e :
workspace_ ) key_count += (key == e.first);
208 if( key_count == 0 ) {
209 vstack = makePtr<VectorStack>(x);
210 workspace_.insert( make_pair(key,vstack) );
212 else vstack = workspace_[key];
214 return vstack->clone(x);
226 Ptr<V>
copy(
const Ptr<const V>& x ) {
return copy(*x); }
229 os <<
"\n\n" << string(80,
'-') << std::endl;
230 os <<
"VectorWorkspace contains the following VectorStack(hash_code,dim) entries:\n\n";
232 os <<
" VectorStack(" << hex << entry.first.hash_code <<
","
233 << dec << entry.first.dimension <<
")";
234 os <<
"\n Reference Counts per element" << std::endl;
235 for(
auto e : entry.second->vectors_ ) {
236 os <<
" " << getCount( e ) << std::endl;
239 os << string(80,
'-') << std::endl;
typename vector< Real >::size_type size_type
typename PV< Real >::size_type size_type
VectorWorkspace< Real > workspace_
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
vector< size_type > getRefCounts(void) const
Ptr< V > clone(const V &x)
Ptr< V > copy(const Ptr< const V > &x)
static string to_string(const VectorKey &key)
Defines the linear algebra or vector space interface.
const VectorKey & getKey() const
Provides a "smart" cloning manager to be used a member variable in a class and called in the member f...
Ptr< V > copy(const V &x)
vector< Ptr< V > > vectors_
VectorKey(const Ptr< V > &x)
Ptr< V > clone(const Ptr< const V > &x)
size_type number_assigned() const
Ptr< V > clone(const V &x)
map< VectorKey, Ptr< VectorStack > > workspace_
void status(ostream &os) const