2525#include < core/library.hpp>
2626#include < core/error.hpp>
2727#include < core/matrix.hpp>
28+ #include < core/vector.hpp>
2829#include < backend/backend_base.hpp>
2930#include < backend/matrix_base.hpp>
3031#include < io/logger.hpp>
4445
4546namespace cubool {
4647
47- std::unordered_set<class Matrix *> Library::mAllocated ;
48+ std::unordered_set<class Matrix *> Library::mAllocMatrices ;
4849 std::shared_ptr<class BackendBase > Library::mBackend = nullptr ;
4950 std::shared_ptr<class Logger > Library::mLogger = std::make_shared<DummyLogger>();
5051 bool Library::mRelaxedRelease = false ;
@@ -95,16 +96,22 @@ namespace cubool {
9596 LogStream stream (*getLogger ());
9697 stream << Logger::Level::Info << " Enabled relaxed library finalize" << LogStream::cmt;
9798
98- for (auto m: mAllocated ) {
99+ for (auto m: mAllocMatrices ) {
99100 stream << Logger::Level::Warning << " Implicitly release matrix " << m->getDebugMarker () << LogStream::cmt;
100101 delete m;
101102 }
102103
103- mAllocated .clear ();
104+ for (auto v: mAllocVectors ) {
105+ stream << Logger::Level::Warning << " Implicitly release vector " << v->getDebugMarker () << LogStream::cmt;
106+ delete v;
107+ }
108+
109+ mAllocMatrices .clear ();
110+ mAllocVectors .clear ();
104111 }
105112
106113 // Some final message
107- mLogger ->logInfo (" ** cuBool:Finalize backend **" );
114+ mLogger ->logInfo (" *** cuBool:Finalize backend * **" );
108115
109116 // Remember to finalize backend
110117 mBackend ->finalize ();
@@ -184,7 +191,7 @@ namespace cubool {
184191 CHECK_RAISE_ERROR (ncols > 0 , InvalidArgument, " Cannot create matrix with zero dimension" );
185192
186193 auto m = new Matrix (nrows, ncols, *mBackend );
187- mAllocated .emplace (m);
194+ mAllocMatrices .emplace (m);
188195
189196 LogStream stream (*getLogger ());
190197 stream << Logger::Level::Info << " Create Matrix " << m->getDebugMarker ()
@@ -193,18 +200,43 @@ namespace cubool {
193200 return m;
194201 }
195202
203+ class Vector * Library::createVector (size_t nrows) {
204+ CHECK_RAISE_ERROR (nrows > 0 , InvalidArgument, " Cannot create vector with zero dimension" );
205+
206+ auto v = new Vector (nrows, *mBackend );
207+ mAllocVectors .emplace (v);
208+
209+ LogStream stream (*getLogger ());
210+ stream << Logger::Level::Info << " Create Vector " << v->getDebugMarker ()
211+ << " (" << nrows << " )" << LogStream::cmt;
212+
213+ return v;
214+ }
215+
196216 void Library::releaseMatrix (Matrix *matrix) {
197217 if (mRelaxedRelease && !mBackend ) return ;
198218
199- CHECK_RAISE_ERROR (mAllocated .find (matrix) != mAllocated .end (), InvalidArgument, " No such matrix was allocated" );
219+ CHECK_RAISE_ERROR (mAllocMatrices .find (matrix) != mAllocMatrices .end (), InvalidArgument, " No such matrix was allocated" );
200220
201221 LogStream stream (*getLogger ());
202222 stream << Logger::Level::Info << " Release Matrix " << matrix->getDebugMarker () << LogStream::cmt;
203223
204- mAllocated .erase (matrix);
224+ mAllocMatrices .erase (matrix);
205225 delete matrix;
206226 }
207227
228+ void Library::releaseVector (class Vector *vector) {
229+ if (mRelaxedRelease && !mBackend ) return ;
230+
231+ CHECK_RAISE_ERROR (mAllocVectors .find (vector) != mAllocVectors .end (), InvalidArgument, " No such vector was allocated" );
232+
233+ LogStream stream (*getLogger ());
234+ stream << Logger::Level::Info << " Release Vector " << vector->getDebugMarker () << LogStream::cmt;
235+
236+ mAllocVectors .erase (vector);
237+ delete vector;
238+ }
239+
208240 void Library::handleError (const std::exception& error) {
209241 mLogger ->log (Logger::Level::Error, error.what ());
210242 }
0 commit comments