@@ -4123,10 +4123,10 @@ def matmul(x1: "ArrayLike", x2: "ArrayLike", dtype: Optional["DTypeLike"] = None
4123
4123
4124
4124
4125
4125
def vecdot (
4126
- x1 : " TensorLike" ,
4127
- x2 : " TensorLike" ,
4126
+ x1 : TensorLike ,
4127
+ x2 : TensorLike ,
4128
4128
dtype : Optional ["DTypeLike" ] = None ,
4129
- ) -> " TensorVariable" :
4129
+ ) -> TensorVariable :
4130
4130
"""Compute the vector dot product of two arrays.
4131
4131
4132
4132
Parameters
@@ -4153,21 +4153,20 @@ def vecdot(
4153
4153
--------
4154
4154
>>> import pytensor.tensor as pt
4155
4155
>>> # Vector dot product with shape (5,) inputs
4156
- >>> x = pt.vector("x") # shape (5,)
4157
- >>> y = pt.vector("y") # shape (5,)
4156
+ >>> x = pt.vector("x", shape=(5,) ) # shape (5,)
4157
+ >>> y = pt.vector("y", shape=(5,) ) # shape (5,)
4158
4158
>>> z = pt.vecdot(x, y) # scalar output
4159
- >>> # Equivalent to numpy.vecdot(x, y) or numpy.sum(x * y)
4159
+ >>> # Equivalent to numpy.vecdot(x, y)
4160
4160
>>>
4161
4161
>>> # With batched inputs of shape (3, 5)
4162
- >>> x_batch = pt.matrix("x") # shape (3, 5)
4163
- >>> y_batch = pt.matrix("y") # shape (3, 5)
4162
+ >>> x_batch = pt.matrix("x", shape=(3, 5) ) # shape (3, 5)
4163
+ >>> y_batch = pt.matrix("y", shape=(3, 5) ) # shape (3, 5)
4164
4164
>>> z_batch = pt.vecdot(x_batch, y_batch) # shape (3,)
4165
- >>> # Equivalent to numpy.sum (x_batch * y_batch, axis=-1 )
4165
+ >>> # Equivalent to numpy.vecdot (x_batch, y_batch )
4166
4166
"""
4167
4167
x1 = as_tensor_variable (x1 )
4168
4168
x2 = as_tensor_variable (x2 )
4169
4169
4170
- # Use the inner product operation along the last axis
4171
4170
out = _inner_prod (x1 , x2 )
4172
4171
4173
4172
if dtype is not None :
@@ -4177,8 +4176,8 @@ def vecdot(
4177
4176
4178
4177
4179
4178
def matvec (
4180
- x1 : " TensorLike" , x2 : " TensorLike" , dtype : Optional ["DTypeLike" ] = None
4181
- ) -> " TensorVariable" :
4179
+ x1 : TensorLike , x2 : TensorLike , dtype : Optional ["DTypeLike" ] = None
4180
+ ) -> TensorVariable :
4182
4181
"""Compute the matrix-vector product.
4183
4182
4184
4183
Parameters
@@ -4199,23 +4198,23 @@ def matvec(
4199
4198
4200
4199
Notes
4201
4200
-----
4202
- This is equivalent to `numpy.matmul` where the second argument is a vector,
4203
- but with more intuitive broadcasting rules. Broadcasting happens over all but
4204
- the last two dimensions of x1 and all dimensions of x2 except the last.
4201
+ This is equivalent to `numpy.matvec` and computes the matrix-vector product
4202
+ with broadcasting over batch dimensions.
4205
4203
4206
4204
Examples
4207
4205
--------
4208
4206
>>> import pytensor.tensor as pt
4209
4207
>>> # Matrix-vector product
4210
- >>> A = pt.matrix("A") # shape (3, 4)
4211
- >>> v = pt.vector("v") # shape (4,)
4208
+ >>> A = pt.matrix("A", shape=(3, 4) ) # shape (3, 4)
4209
+ >>> v = pt.vector("v", shape=(4,) ) # shape (4,)
4212
4210
>>> result = pt.matvec(A, v) # shape (3,)
4213
- >>> # Equivalent to numpy.matmul (A, v)
4211
+ >>> # Equivalent to numpy.matvec (A, v)
4214
4212
>>>
4215
4213
>>> # Batched matrix-vector product
4216
- >>> batched_A = pt.tensor3("A") # shape (2, 3, 4)
4217
- >>> batched_v = pt.matrix("v") # shape (2, 4)
4214
+ >>> batched_A = pt.tensor3("A", shape=(2, 3, 4) ) # shape (2, 3, 4)
4215
+ >>> batched_v = pt.matrix("v", shape=(2, 4) ) # shape (2, 4)
4218
4216
>>> result = pt.matvec(batched_A, batched_v) # shape (2, 3)
4217
+ >>> # Equivalent to numpy.matvec(batched_A, batched_v)
4219
4218
"""
4220
4219
x1 = as_tensor_variable (x1 )
4221
4220
x2 = as_tensor_variable (x2 )
@@ -4229,8 +4228,8 @@ def matvec(
4229
4228
4230
4229
4231
4230
def vecmat (
4232
- x1 : " TensorLike" , x2 : " TensorLike" , dtype : Optional ["DTypeLike" ] = None
4233
- ) -> " TensorVariable" :
4231
+ x1 : TensorLike , x2 : TensorLike , dtype : Optional ["DTypeLike" ] = None
4232
+ ) -> TensorVariable :
4234
4233
"""Compute the vector-matrix product.
4235
4234
4236
4235
Parameters
@@ -4251,23 +4250,23 @@ def vecmat(
4251
4250
4252
4251
Notes
4253
4252
-----
4254
- This is equivalent to `numpy.matmul` where the first argument is a vector,
4255
- but with more intuitive broadcasting rules. Broadcasting happens over all but
4256
- the last dimension of x1 and all but the last two dimensions of x2.
4253
+ This is equivalent to `numpy.vecmat` and computes the vector-matrix product
4254
+ with broadcasting over batch dimensions.
4257
4255
4258
4256
Examples
4259
4257
--------
4260
4258
>>> import pytensor.tensor as pt
4261
4259
>>> # Vector-matrix product
4262
- >>> v = pt.vector("v") # shape (3,)
4263
- >>> A = pt.matrix("A") # shape (3, 4)
4260
+ >>> v = pt.vector("v", shape=(3,) ) # shape (3,)
4261
+ >>> A = pt.matrix("A", shape=(3, 4) ) # shape (3, 4)
4264
4262
>>> result = pt.vecmat(v, A) # shape (4,)
4265
- >>> # Equivalent to numpy.matmul (v, A)
4263
+ >>> # Equivalent to numpy.vecmat (v, A)
4266
4264
>>>
4267
4265
>>> # Batched vector-matrix product
4268
- >>> batched_v = pt.matrix("v") # shape (2, 3)
4269
- >>> batched_A = pt.tensor3("A") # shape (2, 3, 4)
4266
+ >>> batched_v = pt.matrix("v", shape=(2, 3) ) # shape (2, 3)
4267
+ >>> batched_A = pt.tensor3("A", shape=(2, 3, 4) ) # shape (2, 3, 4)
4270
4268
>>> result = pt.vecmat(batched_v, batched_A) # shape (2, 4)
4269
+ >>> # Equivalent to numpy.vecmat(batched_v, batched_A)
4271
4270
"""
4272
4271
x1 = as_tensor_variable (x1 )
4273
4272
x2 = as_tensor_variable (x2 )
0 commit comments