Skip to content

Commit

Permalink
Speed up Vector.randomFilled
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Jun 7, 2024
1 parent 8e28c32 commit 86e032d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/src/vector/float32x4_vector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import 'package:ml_linalg/src/vector/serialization/vector_to_json.dart';
import 'package:ml_linalg/src/vector/vector_cache_keys.dart';
import 'package:ml_linalg/vector.dart';

const _bytesPerElement = Float32List.bytesPerElement;
const _bytesPerSimdElement = Float32x4List.bytesPerElement;
const _bucketSize =
Float32x4List.bytesPerElement ~/ Float32List.bytesPerElement;
Expand Down
5 changes: 4 additions & 1 deletion lib/src/vector/float64x2_vector.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:ml_linalg/src/vector/serialization/vector_to_json.dart';
import 'package:ml_linalg/src/vector/vector_cache_keys.dart';
import 'package:ml_linalg/vector.dart';

const _bytesPerElement = Float64List.bytesPerElement;
const _bytesPerSimdElement = Float64x2List.bytesPerElement;
const _bucketSize =
Float64x2List.bytesPerElement ~/ Float64List.bytesPerElement;
Expand Down Expand Up @@ -57,6 +56,10 @@ class Float64x2Vector with IterableMixin<double> implements Vector {
'Argument `min` should be less than `max`, min: $min, max: $max');
}

if (length < 0) {
throw ArgumentError('Length cannot be negative');
}

_numOfBuckets = _getNumOfBuckets(length, _bucketSize);

final list = Float64List(_numOfBuckets * _bucketSize);
Expand Down

0 comments on commit 86e032d

Please sign in to comment.