11 #ifndef ROL_VECTORWORKSPACE_HPP
12 #define ROL_VECTORWORKSPACE_HPP
66 template<
typename Real>
80 hash_code(typeid(x).hash_code()),
81 dimension( x.dimension() ) {}
88 ss <<
"VectorKey(" << hex << key.
hash_code <<
","
122 for(
auto v : vectors_ ) count += ( getCount(v) > 3 );
132 ROL_TEST_FOR_EXCEPTION( key_.hash_code != x_key.
hash_code, logic_error,
133 "VectorWorkspace::VectorStack tried to clone a vector of type " <<
134 hex << key_.hash_code <<
", but it can only clone vectors of type " <<
137 ROL_TEST_FOR_EXCEPTION( key_.dimension != x_key.
dimension, logic_error,
138 "VectorWorkspace::VectorStack tried to clone a vector of dimension " <<
139 hex << key_.dimension <<
", but it can only clone vectors of dimension " <<
142 for(
auto e : vectors_ ) {
143 if( getCount(e) <= 2 ) {
149 vectors_.push_back( v );
155 vector<size_type> counts;
156 for(
auto e: vectors_ ) counts.push_back( getCount(e) );
170 Ptr<VectorStack> vstack{nullPtr};
172 for(
auto e :
workspace_ ) key_count += (key == e.first);
174 if( key_count == 0 ) {
175 vstack = makePtr<VectorStack>(x);
176 workspace_.insert( make_pair(key,vstack) );
178 else vstack = workspace_[key];
180 return vstack->clone(x);
192 Ptr<V>
copy(
const Ptr<const V>& x ) {
return copy(*x); }
195 os <<
"\n\n" << string(80,
'-') << std::endl;
196 os <<
"VectorWorkspace contains the following VectorStack(hash_code,dim) entries:\n\n";
198 os <<
" VectorStack(" << hex << entry.first.hash_code <<
","
199 << dec << entry.first.dimension <<
")";
200 os <<
"\n Reference Counts per element" << std::endl;
201 for(
auto e : entry.second->vectors_ ) {
202 os <<
" " << getCount( e ) << std::endl;
205 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