From 2483da2d9837268df88d74c56f210f9479b370f1 Mon Sep 17 00:00:00 2001 From: Marcel Luethi Date: Tue, 25 Aug 2026 09:31:41 +0200 Subject: [PATCH 1/2] allow tensors in binary zipvmap to have different vtype --- .../main/scala/dimwit/tensor/tensorops/FunctionalOps.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/dimwit/tensor/tensorops/FunctionalOps.scala b/core/src/main/scala/dimwit/tensor/tensorops/FunctionalOps.scala index 925d9ca..49c6058 100644 --- a/core/src/main/scala/dimwit/tensor/tensorops/FunctionalOps.scala +++ b/core/src/main/scala/dimwit/tensor/tensorops/FunctionalOps.scala @@ -130,12 +130,12 @@ object FunctionalOps: * @param f A function that takes a tuple of tensors (with the specified axis removed) and returns a new tensor. * @return A new tensor resulting from applying `f` to the zipped tensors. */ - def zipvmap[L: Label, T2 <: Tuple, FOut](axis: Axis[L])( - other: Tensor[T2, V] + def zipvmap[L: Label, T2 <: Tuple, V2, FOut](axis: Axis[L])( + other: Tensor[T2, V2] )(using ev: SharedAxisRemover[(T, T2), L] )( - f: TensorsOf[ev.RemainingAxes, (V, V)] => FOut + f: TensorsOf[ev.RemainingAxes, (V, V2)] => FOut )(using prependAxis: PrependAxis[L, FOut], toPyTree: TensorTree[FOut], From 4ca1312ec21c64bc9d0bef8841aa2be997f36d3c Mon Sep 17 00:00:00 2001 From: Marcel Luethi Date: Wed, 26 Aug 2026 19:49:09 +0200 Subject: [PATCH 2/2] add test for zipvmap for two tensors with different vtype --- .../scala/dimwit/tensor/TensorOpsFunctionalSuite.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala b/core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala index 09bceb5..0672eb0 100644 --- a/core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala +++ b/core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala @@ -88,6 +88,16 @@ class TensorOpsFunctionalSuite extends DimwitTest: // Each row of ta sums to 3.0, each row of tc sums to 8.0 => 11.0 per row res.shouldEqual(Tensor1(Axis[A]).fromArray(Array(11.0f, 11.0f))) + it("extension zipvmap with two different-vtype tensors"): + val floats = Tensor(Shape(Axis[A] -> 2, Axis[B] -> 3)).fill(2.0f) + val ints = Tensor(Shape(Axis[A] -> 2, Axis[C] -> 4)).fill(3) + val res = floats.zipvmap(Axis[A])(ints) { + case (rowFloat, rowInt) => + rowFloat.sum + rowInt.asFloat32.sum + } + // Each row of floats sums to 6.0, each row of ints sums to 12 => 18.0 per row + res shouldEqual Tensor1(Axis[A]).fromArray(Array(18.0f, 18.0f)) + it("zipvmap2 return tuple"): val t1 = Tensor(Shape(Axis[A] -> 2, Axis[B] -> 3)).fill(0f) val t2 = Tensor(Shape(Axis[A] -> 2, Axis[B] -> 3)).fill(1f)