Skip to content

Commit

Permalink
WIP: all unit tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Apr 7, 2019
1 parent ac6d292 commit 0c88322
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/src/matrix/byte_data_storage/float32_data_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Float32DataManager implements DataManager {
columnsCache = List<Vector>(source.first.length),
_data = ByteData(source.length * source.first.length *
Float32List.bytesPerElement) {
final flattened = flatten2dimList(source, (i, j) => columnsNum + i);
final flattened = flatten2dimList(source, (i, j) => i * columnsNum + j);
updateAll(0, flattened);
}

Expand All @@ -23,18 +23,18 @@ class Float32DataManager implements DataManager {
columnsCache = List<Vector>(source.first.length),
_data = ByteData(source.length * source.first.length *
Float32List.bytesPerElement) {
final flattened = flatten2dimList(source, (i, j) => columnsNum + i);
final flattened = flatten2dimList(source, (i, j) => i * columnsNum + j);
updateAll(0, flattened);
}

Float32DataManager.fromColumns(Iterable<Vector> source) :
rowsNum = source.length,
columnsNum = source.first.length,
rowsCache = List<Vector>(source.length),
rowsNum = source.first.length,
columnsNum = source.length,
rowsCache = List<Vector>(source.first.length),
columnsCache = source.toList(growable: false),
_data = ByteData(source.length * source.first.length *
Float32List.bytesPerElement) {
final flattened = flatten2dimList(source, (i, j) => columnsNum + i);
final flattened = flatten2dimList(source, (i, j) => j * columnsNum + i);
updateAll(0, flattened);
}

Expand All @@ -45,6 +45,11 @@ class Float32DataManager implements DataManager {
rowsCache = List<Vector>(rowsNum),
columnsCache = List<Vector>(colsNum),
_data = ByteData(rowsNum * colsNum * Float32List.bytesPerElement) {
if (source.length != rowsNum * colsNum) {
throw Exception('Invalid matrix dimension has been provided - '
'$rowsNum x $colsNum, but given a collection of length '
'${source.length}');
}
updateAll(0, source);
}

Expand Down Expand Up @@ -85,10 +90,11 @@ class Float32DataManager implements DataManager {
Iterable<Iterable<double>> rows, int accessor(int i, int j)) {
int i = 0;
int j = 0;
final flattened = List<double>(rows.length * rows.first.length);
final flattened = List<double>(columnsNum * rowsNum);
for (final row in rows) {
for (final value in row) {
flattened[accessor(i, j++)] = value;
flattened[accessor(i, j)] = value;
j++;
}
j = 0;
i++;
Expand Down

0 comments on commit 0c88322

Please sign in to comment.