Skip to content

Commit

Permalink
Merge pull request #39 from gyrdym/coveralls-integration
Browse files Browse the repository at this point in the history
Coveralls integration
  • Loading branch information
gyrdym committed Feb 11, 2019
2 parents e5e120d + 4777acf commit def14a9
Show file tree
Hide file tree
Showing 34 changed files with 498 additions and 244 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
@@ -1,6 +1,8 @@
language: dart
dart:
- "2.0.0"
- "2.1.0"
dart_task:
- test: --platform vm
- dartanalyzer: true
- dartfmt: true
script: ./tool/coverage.sh
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 5.0.1
- Travis integration added
- `dartfmt` task added

## 5.0.0
- MLVector and MLMatrix now don't have generic type parameters

Expand Down
1 change: 1 addition & 0 deletions README.md
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.com/gyrdym/ml_linalg.svg?branch=master)](https://travis-ci.com/gyrdym/ml_linalg)
[![Coverage Status](https://coveralls.io/repos/github/gyrdym/ml_linalg/badge.svg)](https://coveralls.io/github/gyrdym/ml_linalg)
[![pub package](https://img.shields.io/pub/v/ml_linalg.svg)](https://pub.dartlang.org/packages/ml_linalg)
[![Gitter Chat](https://badges.gitter.im/gyrdym/gyrdym.svg)](https://gitter.im/gyrdym/)

Expand Down
2 changes: 1 addition & 1 deletion benchmark/main.dart
Expand Up @@ -8,4 +8,4 @@ void main() {
VectorUniqueBenchmark.main();
VectorMulBenchmark.main();
VectorAdditionBenchmark.main();
}
}
4 changes: 3 additions & 1 deletion benchmark/vector_initializing/float32x4_from_iterable.dart
Expand Up @@ -9,7 +9,9 @@ const amountOfElements = 10000000;
Float32x4Vector vector;

class VectorInitializationBenchmark extends BenchmarkBase {
const VectorInitializationBenchmark() : super('Vector initialization (from simple iterable), $amountOfElements elements');
const VectorInitializationBenchmark()
: super(
'Vector initialization (from simple iterable), $amountOfElements elements');

static void main() {
const VectorInitializationBenchmark().report();
Expand Down
8 changes: 5 additions & 3 deletions benchmark/vector_operations/float32x4_unique.dart
Expand Up @@ -11,7 +11,8 @@ const amountOfElements = 10000;
Float32x4Vector vector;

class VectorUniqueBenchmark extends BenchmarkBase {
const VectorUniqueBenchmark() : super('Vector unnique elements obtaining, $amountOfElements elements');
const VectorUniqueBenchmark()
: super('Vector unnique elements obtaining, $amountOfElements elements');

static void main() {
const VectorUniqueBenchmark().report();
Expand All @@ -25,7 +26,8 @@ class VectorUniqueBenchmark extends BenchmarkBase {
@override
void setup() {
final generator = math.Random(DateTime.now().millisecondsSinceEpoch);
vector = Float32x4Vector.from(List<double>.generate(amountOfElements, (int idx) => generator.nextDouble()));
vector = Float32x4Vector.from(List<double>.generate(
amountOfElements, (int idx) => generator.nextDouble()));
}

void tearDown() {
Expand All @@ -35,4 +37,4 @@ class VectorUniqueBenchmark extends BenchmarkBase {

void main() {
VectorUniqueBenchmark.main();
}
}
Expand Up @@ -12,7 +12,8 @@ Float32x4Vector vector1;
Float32x4Vector vector2;

class VectorMulBenchmark extends BenchmarkBase {
const VectorMulBenchmark() : super('Vectors multiplication, $amountOfElements elements');
const VectorMulBenchmark()
: super('Vectors multiplication, $amountOfElements elements');

static void main() {
const VectorMulBenchmark().report();
Expand All @@ -27,8 +28,10 @@ class VectorMulBenchmark extends BenchmarkBase {
@override
void setup() {
final generator = math.Random(DateTime.now().millisecondsSinceEpoch);
vector1 = Float32x4Vector.from(List<double>.generate(amountOfElements, (int idx) => generator.nextDouble()));
vector2 = Float32x4Vector.from(List<double>.generate(amountOfElements, (int idx) => generator.nextDouble()));
vector1 = Float32x4Vector.from(List<double>.generate(
amountOfElements, (int idx) => generator.nextDouble()));
vector2 = Float32x4Vector.from(List<double>.generate(
amountOfElements, (int idx) => generator.nextDouble()));
}

void tearDown() {
Expand All @@ -39,4 +42,4 @@ class VectorMulBenchmark extends BenchmarkBase {

void main() {
VectorMulBenchmark.main();
}
}
5 changes: 3 additions & 2 deletions benchmark/vector_operations/float32x4_vectors_sum.dart
Expand Up @@ -10,7 +10,8 @@ Float32x4Vector vector1;
Float32x4Vector vector2;

class VectorAdditionBenchmark extends BenchmarkBase {
const VectorAdditionBenchmark() : super('Vectors addition, $amountOfElements elements');
const VectorAdditionBenchmark()
: super('Vectors addition, $amountOfElements elements');

static void main() {
const VectorAdditionBenchmark().report();
Expand All @@ -36,4 +37,4 @@ class VectorAdditionBenchmark extends BenchmarkBase {

void main() {
VectorAdditionBenchmark.main();
}
}
3 changes: 2 additions & 1 deletion example/main.dart
Expand Up @@ -74,7 +74,8 @@ void dot() {
final vector1 = Float32x4Vector.from([1.0, 2.0, 3.0, 4.0, 5.0]);
final vector2 = Float32x4Vector.from([2.0, 3.0, 4.0, 5.0, 6.0]);
final result = vector1.dot(vector2);
print(result); // 1.0 * 2.0 + 2.0 * 3.0 + 3.0 * 4.0 + 4.0 * 5.0 + 5.0 * 6.0 = 70.0
print(
result); // 1.0 * 2.0 + 2.0 * 3.0 + 3.0 * 4.0 + 4.0 * 5.0 + 5.0 * 6.0 = 70.0
}

void scalarAddition() {
Expand Down
6 changes: 4 additions & 2 deletions lib/matrix.dart
Expand Up @@ -70,10 +70,12 @@ abstract class MLMatrix {
MLVector getRow(int index, {bool tryCache = true, bool mutable = false});

/// Reduces all the matrix columns to only column, using [combiner] function
MLVector reduceColumns(MLVector combiner(MLVector combine, MLVector vector), {MLVector initValue});
MLVector reduceColumns(MLVector combiner(MLVector combine, MLVector vector),
{MLVector initValue});

/// Reduces all the matrix rows to only row, using [combiner] function
MLVector reduceRows(MLVector combiner(MLVector combine, MLVector vector), {MLVector initValue});
MLVector reduceRows(MLVector combiner(MLVector combine, MLVector vector),
{MLVector initValue});

/// Creates a new matrix, efficiently iterating through all the matrix elements (several floating point elements in a
/// time) and applying the [mapper] function
Expand Down
6 changes: 4 additions & 2 deletions lib/src/matrix/float32x4/float32_matrix_iterator.dart
Expand Up @@ -18,10 +18,12 @@ class Float32MatrixIterator implements Iterator<Iterable<double>> {
if (byteOffset >= _data.buffer.lengthInBytes) {
_current = null;
} else {
final totalSizeInBytes = byteOffset + (_columns * Float32List.bytesPerElement);
final totalSizeInBytes =
byteOffset + (_columns * Float32List.bytesPerElement);
final length = _data.buffer.lengthInBytes >= totalSizeInBytes
? _columns
: (totalSizeInBytes - _data.buffer.lengthInBytes) ~/ Float32List.bytesPerElement;
: (totalSizeInBytes - _data.buffer.lengthInBytes) ~/
Float32List.bytesPerElement;
_current = _data.buffer.asFloat32List(byteOffset, length);
}
_currentRow++;
Expand Down
31 changes: 18 additions & 13 deletions lib/src/matrix/float32x4/float32x4_matrix.dart
Expand Up @@ -12,15 +12,15 @@ import 'package:ml_linalg/src/matrix/ml_matrix_validator_mixin.dart';
import 'package:ml_linalg/src/vector/float32x4/float32x4_vector_factory_mixin.dart';
import 'package:ml_linalg/vector.dart';

class Float32x4Matrix extends Object with
IterableMixin<Iterable<double>>,
MLMatrixValidatorMixin<Float32x4>,
Float32x4MatrixFactoryMixin,
Float32x4VectorFactoryMixin,
MLMatrixFastIterableMixin,
MLMatrixMixin<Float32x4, Float32x4List>
class Float32x4Matrix extends Object
with
IterableMixin<Iterable<double>>,
MLMatrixValidatorMixin<Float32x4>,
Float32x4MatrixFactoryMixin,
Float32x4VectorFactoryMixin,
MLMatrixFastIterableMixin,
MLMatrixMixin<Float32x4, Float32x4List>
implements MLMatrixDataStore, MLMatrix {

@override
final int rowsNum;

Expand All @@ -39,7 +39,8 @@ class Float32x4Matrix extends Object with
Float32x4Matrix.from(Iterable<Iterable<double>> source)
: rowsNum = source.length,
columnsNum = source.first.length,
data = ByteData(source.length * source.first.length * Float32List.bytesPerElement),
data = ByteData(
source.length * source.first.length * Float32List.bytesPerElement),
rowsCache = List<MLVector>(source.length),
columnsCache = List<MLVector>(source.first.length) {
final flattened = flatten2dimList(source, (i, j) => i * columnsNum + j);
Expand All @@ -61,7 +62,8 @@ class Float32x4Matrix extends Object with
Float32x4Matrix.columns(Iterable<MLVector> source)
: rowsNum = source.first.length,
columnsNum = source.length,
data = ByteData(source.length * source.first.length * Float32List.bytesPerElement),
data = ByteData(
source.length * source.first.length * Float32List.bytesPerElement),
rowsCache = List<MLVector>(source.first.length),
columnsCache = source.toList(growable: false) {
final flattened = flatten2dimList(source, (i, j) => j * columnsNum + i);
Expand All @@ -72,14 +74,16 @@ class Float32x4Matrix extends Object with
Float32x4Matrix.rows(Iterable<MLVector> source)
: rowsNum = source.length,
columnsNum = source.first.length,
data = ByteData(source.length * source.first.length * Float32List.bytesPerElement),
data = ByteData(
source.length * source.first.length * Float32List.bytesPerElement),
rowsCache = source.toList(growable: false),
columnsCache = List<MLVector>(source.first.length) {
final flattened = flatten2dimList(source, (i, j) => i * columnsNum + j);
data.buffer.asFloat32List().setAll(0, flattened);
}

Float32x4Matrix.flattened(Iterable<double> source, this.rowsNum, this.columnsNum)
Float32x4Matrix.flattened(
Iterable<double> source, this.rowsNum, this.columnsNum)
: data = ByteData(rowsNum * columnsNum * Float32List.bytesPerElement),
rowsCache = List<MLVector>(rowsNum),
columnsCache = List<MLVector>(columnsNum) {
Expand All @@ -90,5 +94,6 @@ class Float32x4Matrix extends Object with
}

@override
Iterator<Iterable<double>> get iterator => Float32MatrixIterator(data, columnsNum);
Iterator<Iterable<double>> get iterator =>
Float32MatrixIterator(data, columnsNum);
}
5 changes: 3 additions & 2 deletions lib/src/matrix/float32x4/float32x4_matrix_factory_mixin.dart
Expand Up @@ -9,7 +9,8 @@ abstract class Float32x4MatrixFactoryMixin implements MLMatrixFactory {
Float32x4Matrix.from(source);

@override
MLMatrix createMatrixFromFlattened(Iterable<double> source, int rowsNum, int columnsNum) =>
MLMatrix createMatrixFromFlattened(
Iterable<double> source, int rowsNum, int columnsNum) =>
Float32x4Matrix.flattened(source, rowsNum, columnsNum);

@override
Expand All @@ -19,4 +20,4 @@ abstract class Float32x4MatrixFactoryMixin implements MLMatrixFactory {
@override
MLMatrix createMatrixFromColumns(Iterable<MLVector> source) =>
Float32x4Matrix.columns(source);
}
}
5 changes: 3 additions & 2 deletions lib/src/matrix/ml_matrix_factory.dart
Expand Up @@ -3,7 +3,8 @@ import 'package:ml_linalg/vector.dart';

abstract class MLMatrixFactory {
MLMatrix createMatrixFrom(Iterable<Iterable<double>> source);
MLMatrix createMatrixFromFlattened(Iterable<double> source, int rowsNum, int columnsNum);
MLMatrix createMatrixFromFlattened(
Iterable<double> source, int rowsNum, int columnsNum);
MLMatrix createMatrixFromRows(Iterable<MLVector> source);
MLMatrix createMatrixFromColumns(Iterable<MLVector> source);
}
}
8 changes: 5 additions & 3 deletions lib/src/matrix/ml_matrix_fast_iterable_mixin.dart
Expand Up @@ -5,8 +5,10 @@ import 'package:ml_linalg/vector.dart';
abstract class MLMatrixFastIterableMixin implements MLMatrixFactory, MLMatrix {
@override
MLMatrix fastMap<T>(T mapper(T element)) {
final source = List<MLVector>.generate(rowsNum, (int i) => (getRow(i))
.fastMap((T element, int startOffset, int endOffset) => mapper(element)));
final source = List<MLVector>.generate(
rowsNum,
(int i) => (getRow(i)).fastMap(
(T element, int startOffset, int endOffset) => mapper(element)));
return createMatrixFromRows(source);
}
}
}

0 comments on commit def14a9

Please sign in to comment.