mirror of
https://github.com/ml-explore/mlx.git
synced 2025-08-07 04:06:42 +08:00
fix
This commit is contained in:
parent
bc3357e6ad
commit
4e4ec88152
@ -4330,6 +4330,10 @@ array addmm(
|
|||||||
|
|
||||||
c = reshape(c, c_reshape, s);
|
c = reshape(c, c_reshape, s);
|
||||||
}
|
}
|
||||||
|
if (c.shape() != out_shape) {
|
||||||
|
throw std::invalid_argument(
|
||||||
|
"[addmm] input c must broadcast to the output shape");
|
||||||
|
}
|
||||||
|
|
||||||
auto out = array(
|
auto out = array(
|
||||||
std::move(out_shape),
|
std::move(out_shape),
|
||||||
|
@ -589,6 +589,10 @@ class TestBlas(mlx_tests.MLXTestCase):
|
|||||||
alpha = 0.5
|
alpha = 0.5
|
||||||
beta = 2.0
|
beta = 2.0
|
||||||
|
|
||||||
|
# c must broadcast to the output shape
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
mx.addmm(mx.zeros((2, 2, 2)), mx.zeros((2, 2)), mx.zeros((2, 2)))
|
||||||
|
|
||||||
# Regular batched case
|
# Regular batched case
|
||||||
a_npy = np.random.normal(0.0, 1.0 / 128, (32, 128, 16)).astype(np.float32)
|
a_npy = np.random.normal(0.0, 1.0 / 128, (32, 128, 16)).astype(np.float32)
|
||||||
b_npy = np.random.normal(0.0, 1.0 / 128, (32, 16, 16)).astype(np.float32)
|
b_npy = np.random.normal(0.0, 1.0 / 128, (32, 16, 16)).astype(np.float32)
|
||||||
@ -745,11 +749,11 @@ class TestBlas(mlx_tests.MLXTestCase):
|
|||||||
mx.eval(c)
|
mx.eval(c)
|
||||||
self.assertEqual(c.shape, (0, 0))
|
self.assertEqual(c.shape, (0, 0))
|
||||||
|
|
||||||
c = mx.array([], dtype=mx.float32)
|
c = mx.array(1.0, dtype=mx.float32)
|
||||||
a = mx.array([], dtype=mx.float32)
|
a = mx.array([], dtype=mx.float32)
|
||||||
b = mx.array([], dtype=mx.float32)
|
b = mx.array([], dtype=mx.float32)
|
||||||
out = mx.addmm(a, b, c)
|
out = mx.addmm(c, a, b)
|
||||||
mx.eval(out)
|
self.assertEqual(out.item(), 1.0)
|
||||||
self.assertEqual(out.shape, ())
|
self.assertEqual(out.shape, ())
|
||||||
|
|
||||||
a = mx.zeros(shape=(5, 0))
|
a = mx.zeros(shape=(5, 0))
|
||||||
|
Loading…
Reference in New Issue
Block a user