Skip to content

Commit

Permalink
Vector: randomFilled constructor default parameters fixed, unit tests…
Browse files Browse the repository at this point in the history
… for Vector factory added
  • Loading branch information
gyrdym committed Jun 23, 2019
1 parent 87cc84f commit d20bcfa
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 10.3.6
- `Vector`: `randomFilled` default parameters fixed
- Tests for `Vector`'s constructors added

## 10.3.5
- readme updated: explanation images added

Expand Down
1 change: 1 addition & 0 deletions lib/linalg.dart
Expand Up @@ -2,6 +2,7 @@ export 'package:ml_linalg/axis.dart';
export 'package:ml_linalg/distance.dart';
export 'package:ml_linalg/dtype.dart';
export 'package:ml_linalg/matrix.dart';
export 'package:ml_linalg/matrix_norm.dart';
export 'package:ml_linalg/norm.dart';
export 'package:ml_linalg/sort_direction.dart';
export 'package:ml_linalg/vector.dart';
2 changes: 1 addition & 1 deletion lib/vector.dart
Expand Up @@ -59,7 +59,7 @@ abstract class Vector implements Iterable<double> {
/// If [min] greater than [max] when [min] becomes [max]
/// generated from randomizer with seed, equal to [seed].
factory Vector.randomFilled(int length,
{int seed, double min, double max, DType dtype = DType.float32}) {
{int seed, double min = 0, double max = 1, DType dtype = DType.float32}) {
switch (dtype) {
case DType.float32:
return Float32Vector.randomFilled(length, seed: seed,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: ml_linalg
description: SIMD-based linear algebra (1 operation on 4 float32 values, 1 operation on 2 float64 values)
version: 10.3.5
version: 10.3.6
author: Ilia Gyrdymov <ilgyrd@gmail.com>
homepage: https://github.com/gyrdym/ml_linalg

Expand Down
2 changes: 2 additions & 0 deletions test/test_all.dart
@@ -1,9 +1,11 @@
import 'float32_matrix_test.dart' as float32x4_matrix_test;
import 'matrix_iterator_test.dart' as matrix_iterator_test;
import 'float32_vector_test.dart' as float32x4_vector_test;
import 'vector_test.dart' as vector_test;

void main() {
float32x4_matrix_test.main();
matrix_iterator_test.main();
float32x4_vector_test.main();
vector_test.main();
}
42 changes: 42 additions & 0 deletions test/vector_test.dart
@@ -0,0 +1,42 @@
import 'dart:typed_data';

import 'package:ml_linalg/src/vector/float32/float32_vector.dart';
import 'package:ml_linalg/vector.dart';
import 'package:test/test.dart';

void main() {
group('Vector', () {
group('float32', () {
test('should create vector instance via `fromList` constructor', () {
expect(Vector.fromList([1, 2, 3]), isA<Float32Vector>());
expect(Vector.fromList([1, 2, 3]), hasLength(3));
});

test('should create vector instance via `zero` constructor', () {
expect(Vector.zero(5), isA<Float32Vector>());
expect(Vector.zero(5), hasLength(5));
});

test('should create vector instance via `fromSimdList` constructor', () {
expect(Vector.fromSimdList(
Float32x4List.fromList([Float32x4.zero()]),
3
), isA<Float32Vector>());
expect(Vector.fromSimdList(
Float32x4List.fromList([Float32x4.zero()]),
3
), hasLength(3));
});

test('should create vector instance via `filled` constructor', () {
expect(Vector.filled(7, 3), isA<Float32Vector>());
expect(Vector.filled(7, 3), hasLength(7));
});

test('should create vector instance via `randomFilled` constructor', () {
expect(Vector.randomFilled(11), isA<Float32Vector>());
expect(Vector.randomFilled(11), hasLength(11));
});
});
});
}

0 comments on commit d20bcfa

Please sign in to comment.