Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
10 changes: 10 additions & 0 deletions core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading