diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a40f29d..dbdc28d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/vector/float32x4_vector.dart b/lib/src/vector/float32x4_vector.dart index 15eab365..7d460a95 100644 --- a/lib/src/vector/float32x4_vector.dart +++ b/lib/src/vector/float32x4_vector.dart @@ -434,7 +434,7 @@ class Float32x4Vector with IterableMixin 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(); @@ -503,7 +503,7 @@ class Float32x4Vector with IterableMixin implements Vector { @override double prod({bool skipCaching = false}) => - _cache.get(vectorSumKey, _findProduct, skipCaching: skipCaching); + _cache.get(vectorProdKey, _findProduct, skipCaching: skipCaching); @override double distanceTo( diff --git a/lib/src/vector/float64x2_vector.g.dart b/lib/src/vector/float64x2_vector.g.dart index 5ca15dad..a523f1d2 100644 --- a/lib/src/vector/float64x2_vector.g.dart +++ b/lib/src/vector/float64x2_vector.g.dart @@ -437,7 +437,7 @@ class Float64x2Vector with IterableMixin 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(); @@ -506,7 +506,7 @@ class Float64x2Vector with IterableMixin implements Vector { @override double prod({bool skipCaching = false}) => - _cache.get(vectorSumKey, _findProduct, skipCaching: skipCaching); + _cache.get(vectorProdKey, _findProduct, skipCaching: skipCaching); @override double distanceTo( diff --git a/pubspec.yaml b/pubspec.yaml index e56e2870..d7881e6c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: diff --git a/test/vector/methods/exp/exp_test_group_factory.dart b/test/vector/methods/exp/exp_test_group_factory.dart index 08241f27..5ca098d4 100644 --- a/test/vector/methods/exp/exp_test_group_factory.dart +++ b/test/vector/methods/exp/exp_test_group_factory.dart @@ -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)); + }); }); }); diff --git a/test/vector/methods/prod/prod_test_group_factory.dart b/test/vector/methods/prod/prod_test_group_factory.dart index fa584d8a..2e3229e2 100644 --- a/test/vector/methods/prod/prod_test_group_factory.dart +++ b/test/vector/methods/prod/prod_test_group_factory.dart @@ -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)); + }); }); });