Skip to content

Commit

Permalink
Added toList method to SparseVector
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 10, 2024
1 parent 381afd5 commit a24142d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/sparsevec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class SparseVector {
return SparseVector._(dimensions, indices, values);
}

List<double> toList() {
var vec = List<double>.filled(this.dimensions, 0.0);
for (var i = 0; i < indices.length; i++) {
vec[indices[i]] = values[i];
}
return vec;
}

@override
String toString() {
var elements = [
Expand Down

0 comments on commit a24142d

Please sign in to comment.