@@ -69,6 +69,13 @@ namespace cubool {
6969 CHECK_RAISE_ERROR (cols != nullptr || nvals == 0 , InvalidArgument, " Null ptr cols array" );
7070
7171 this ->releaseCache ();
72+
73+ LogStream stream (*Library::getLogger ());
74+ stream << Logger::Level::Info
75+ << " Matrix:build:" << this ->getDebugMarker () << " "
76+ << " isSorted=" << isSorted << " , "
77+ << " noDuplicates=" << noDuplicates << LogStream::cmt;
78+
7279 mHnd ->build (rows, cols, nvals, isSorted, noDuplicates);
7380 }
7481
@@ -98,7 +105,8 @@ namespace cubool {
98105 CHECK_RAISE_ERROR (nrows == this ->getNrows (), InvalidArgument, " Result matrix has incompatible size for extracted sub-matrix range" );
99106 CHECK_RAISE_ERROR (ncols == this ->getNcols (), InvalidArgument, " Result matrix has incompatible size for extracted sub-matrix range" );
100107
101- this ->commitCache ();
108+ other->commitCache ();
109+ this ->releaseCache (); // Values of this matrix won't be used any more
102110
103111 if (checkTime) {
104112 TIMER_ACTION (timer, mHnd ->extractSubMatrix (*other->mHnd , i, j, nrows, ncols, false ));
@@ -122,13 +130,18 @@ namespace cubool {
122130
123131 CHECK_RAISE_ERROR (other != nullptr , InvalidArgument, " Passed matrix does not belong to core matrix class" );
124132
133+ if (this == other)
134+ return ;
135+
125136 auto M = other->getNrows ();
126137 auto N = other->getNcols ();
127138
128139 CHECK_RAISE_ERROR (M == this ->getNrows (), InvalidArgument, " Cloned matrix has incompatible size" );
129140 CHECK_RAISE_ERROR (N == this ->getNcols (), InvalidArgument, " Cloned matrix has incompatible size" );
130141
131- this ->commitCache ();
142+ other->commitCache ();
143+ this ->releaseCache (); // Values of this matrix won't be used any more
144+
132145 mHnd ->clone (*other->mHnd );
133146 }
134147
@@ -144,6 +157,7 @@ namespace cubool {
144157 CHECK_RAISE_ERROR (N == this ->getNrows (), InvalidArgument, " Transposed matrix has incompatible size" );
145158
146159 this ->commitCache ();
160+ this ->releaseCache (); // Values of this matrix won't be used any more
147161
148162 if (checkTime) {
149163 TIMER_ACTION (timer, mHnd ->transpose (*other->mHnd , false ));
@@ -171,7 +185,8 @@ namespace cubool {
171185 CHECK_RAISE_ERROR (M == this ->getNrows (), InvalidArgument, " Matrix has incompatible size" );
172186 CHECK_RAISE_ERROR (1 == this ->getNcols (), InvalidArgument, " Matrix has incompatible size" );
173187
174- this ->commitCache ();
188+ other->commitCache ();
189+ this ->releaseCache (); // Values of this matrix won't be used any more
175190
176191 if (checkTime) {
177192 TIMER_ACTION (timer, mHnd ->reduce (*other->mHnd , false ));
@@ -204,7 +219,13 @@ namespace cubool {
204219 CHECK_RAISE_ERROR (N == this ->getNcols (), InvalidArgument, " Matrix has incompatible size for operation result" );
205220 CHECK_RAISE_ERROR (T == b->getNrows (), InvalidArgument, " Cannot multiply passed matrices" );
206221
207- this ->commitCache ();
222+ a->commitCache ();
223+ b->commitCache ();
224+
225+ if (accumulate)
226+ this ->commitCache ();
227+ else
228+ this ->releaseCache ();
208229
209230 if (checkTime) {
210231 TIMER_ACTION (timer, mHnd ->multiply (*a->mHnd , *b->mHnd , accumulate, false ));
@@ -238,7 +259,9 @@ namespace cubool {
238259 CHECK_RAISE_ERROR (M * K == this ->getNrows (), InvalidArgument, " Matrix has incompatible size for operation result" );
239260 CHECK_RAISE_ERROR (N * T == this ->getNcols (), InvalidArgument, " Matrix has incompatible size for operation result" );
240261
241- this ->commitCache ();
262+ a->commitCache ();
263+ b->commitCache ();
264+ this ->releaseCache ();
242265
243266 if (checkTime) {
244267 TIMER_ACTION (timer, mHnd ->kronecker (*a->mHnd , *b->mHnd , false ));
@@ -273,7 +296,9 @@ namespace cubool {
273296 CHECK_RAISE_ERROR (M == this ->getNrows (), InvalidArgument, " Matrix has incompatible size for operation result" );
274297 CHECK_RAISE_ERROR (N == this ->getNcols (), InvalidArgument, " Matrix has incompatible size for operation result" );
275298
276- this ->commitCache ();
299+ a->commitCache ();
300+ b->commitCache ();
301+ this ->releaseCache ();
277302
278303 if (checkTime) {
279304 TIMER_ACTION (timer, mHnd ->eWiseAdd (*a->mHnd , *b->mHnd , false ));
@@ -339,17 +364,17 @@ namespace cubool {
339364 bool isSorted = false ;
340365 bool noDuplicates = false ;
341366
342- // We will have to join old and new values
343367 if (mHnd ->getNvals () > 0 ) {
344- // Build tmp matrix with new values
368+ // We will have to join old and new values
369+ // Create tmp matrix and merge values
370+
345371 MatrixBase* tmp = mProvider ->createMatrix (getNrows (), getNcols ());
346372 tmp->build (mCachedI .data (), mCachedJ .data (), cachedNvals, isSorted, noDuplicates);
347-
348- // Add new values to current matrix content
349373 mHnd ->eWiseAdd (*mHnd , *tmp, false );
374+ mProvider ->releaseMatrix (tmp);
350375 }
351- // Otherwise, new values are used to build matrix content
352376 else {
377+ // Otherwise, new values are used to build matrix content
353378 mHnd ->build (mCachedI .data (), mCachedJ .data (), cachedNvals, isSorted, noDuplicates);
354379 }
355380
0 commit comments