File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -283,10 +283,25 @@ namespace htm {
283283 NTA_ASSERT ( dimensions == sdr.dimensions );
284284
285285 UInt ovlp = 0u ;
286- const auto a = this ->getDense ();
287- const auto b = sdr.getDense ();
288- for ( UInt i = 0u ; i < size; i++ )
289- ovlp += a[i] && b[i];
286+ const auto a_sparse = this ->getSparse ();
287+ const auto b_sparse = sdr.getSparse ();
288+ long unsigned int a_idx = 0u ;
289+ long unsigned int b_idx = 0u ;
290+ while ( a_idx < a_sparse.size () && b_idx < b_sparse.size () ) {
291+ auto a = a_sparse[a_idx];
292+ auto b = b_sparse[b_idx];
293+ if ( a == b ) {
294+ ovlp += 1u ;
295+ a_idx += 1u ;
296+ b_idx += 1u ;
297+ }
298+ else if ( a > b ) {
299+ b_idx += 1u ;
300+ }
301+ else {
302+ a_idx += 1u ;
303+ }
304+ }
290305 return ovlp;
291306 }
292307
You can’t perform that action at this time.
0 commit comments