From 859f540f4a5d8f489362fc471e59912692195f3c Mon Sep 17 00:00:00 2001 From: Jordan Hewitt Date: Fri, 13 Dec 2024 09:45:59 -0800 Subject: [PATCH] rethinking design of tensor. --- lib/src/splat/tensor.dart | 4 ++++ lib/src/test/splat/tensor_test.dart | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/src/splat/tensor.dart b/lib/src/splat/tensor.dart index 583f625..e02efc8 100644 --- a/lib/src/splat/tensor.dart +++ b/lib/src/splat/tensor.dart @@ -5,6 +5,10 @@ import 'package:collection/collection.dart'; class Tensor extends DelegatingList> { Tensor(super.base); + factory Tensor.fromList(List> lst) { + return Tensor(DelegatingList(lst.map((e) => DelegatingList(e)).toList())); + } + Tensor each(Function(double, int, int) f) { Tensor other = Tensor([]); for (int j = 0; j < length; ++j) { diff --git a/lib/src/test/splat/tensor_test.dart b/lib/src/test/splat/tensor_test.dart index 84e849f..d83952f 100644 --- a/lib/src/test/splat/tensor_test.dart +++ b/lib/src/test/splat/tensor_test.dart @@ -17,6 +17,20 @@ void main() { ])); expect(Tensor.stack(x)[0], equals(x)); + expect( + Tensor.stack(x), + equals(Tensor.fromList([ + [ + [ + [0.3367, 0.1288, 0.2345], + [0.3367, 0.1288, 0.2345], + ], + [ + [0.2303, -1.1229, -0.1863], + [0.2303, -1.1229, -0.1863] + ] + ] + ]))); }); }); }