Skip to content

Commit

Permalink
Vector: extracting values from cache for 'exp' and 'prod' methods fix…
Browse files Browse the repository at this point in the history
…ed (#172)
  • Loading branch information
gyrdym committed Dec 26, 2023
1 parent 8b30c13 commit 6960270
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 13.12.1
- `Vector`:
- Extracting values from cache for `exp` and `prod` methods fixed

## 13.12.0
- `Matrix`:
- add `solve` method for solving a system of linear equations
Expand Down
4 changes: 2 additions & 2 deletions lib/src/vector/float32x4_vector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class Float32x4Vector with IterableMixin<double> implements Vector {
Vector pow(num exponent) => _elementWisePow(exponent);

@override
Vector exp({bool skipCaching = false}) => _cache.get(vectorLogKey, () {
Vector exp({bool skipCaching = false}) => _cache.get(vectorExpKey, () {
final source = Float32List(length);
final list = _getTypedList();

Expand Down Expand Up @@ -503,7 +503,7 @@ class Float32x4Vector with IterableMixin<double> implements Vector {

@override
double prod({bool skipCaching = false}) =>
_cache.get(vectorSumKey, _findProduct, skipCaching: skipCaching);
_cache.get(vectorProdKey, _findProduct, skipCaching: skipCaching);

@override
double distanceTo(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/vector/float64x2_vector.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class Float64x2Vector with IterableMixin<double> implements Vector {
Vector pow(num exponent) => _elementWisePow(exponent);

@override
Vector exp({bool skipCaching = false}) => _cache.get(vectorLogKey, () {
Vector exp({bool skipCaching = false}) => _cache.get(vectorExpKey, () {
final source = Float64List(length);
final list = _getTypedList();

Expand Down Expand Up @@ -506,7 +506,7 @@ class Float64x2Vector with IterableMixin<double> implements Vector {

@override
double prod({bool skipCaching = false}) =>
_cache.get(vectorSumKey, _findProduct, skipCaching: skipCaching);
_cache.get(vectorProdKey, _findProduct, skipCaching: skipCaching);

@override
double distanceTo(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ml_linalg
description: SIMD-based linear algebra and statistics, efficient manipulation with numeric data
version: 13.12.0
version: 13.12.1
homepage: https://github.com/gyrdym/ml_linalg

environment:
Expand Down
12 changes: 12 additions & 0 deletions test/vector/methods/exp/exp_test_group_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@ void vectorExpTestGroupFactory(DType dtype) =>
iterableAlmostEqualTo(
[2.7182, 7.3890, 20.08553, 54.5981, 148.4131], 1e-3));
});

test('should extract value from cache', () {
final vector =
Vector.fromList([1.0, 2.0, 3.0, 4.0, 5.0], dtype: dtype);

final log = vector.log();
final exp = vector.exp();
final exp2 = vector.exp();

expect(exp, exp2);
expect(exp, isNot(log));
});
});
});
12 changes: 12 additions & 0 deletions test/vector/methods/prod/prod_test_group_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,17 @@ void vectorProdTestGroupFactory(DType dtype) =>
final vector = Vector.fromList([], dtype: dtype);
expect(vector.prod(), isNaN);
});

test('should extract value from cache', () {
final vector =
Vector.fromList([1.0, 2.0, 3.0, 4.0, 5.0], dtype: dtype);

final sum = vector.sum();
final prod = vector.prod();
final prod2 = vector.prod();

expect(prod, prod2);
expect(prod, isNot(sum));
});
});
});

0 comments on commit 6960270

Please sign in to comment.