test.py 577 B

123456789101112131415161718192021222324252627
  1. import mlx.core as mx
  2. import numpy as np
  3. # Create some test arrays
  4. a = mx.array([[1, 2, 3], [4, 5, 6]], dtype=mx.float32)
  5. b = mx.array([[7, 8, 9], [10, 11, 12]], dtype=mx.float32)
  6. # Test basic operations
  7. print("Array a:")
  8. print(a)
  9. print("\nArray b:")
  10. print(b)
  11. # Test multiplication
  12. c = mx.multiply(a, b)
  13. print("\nElement-wise multiplication (a * b):")
  14. print(c)
  15. # Test matrix multiplication
  16. d = a @ b.transpose()
  17. print("\nMatrix multiplication (a @ b.T):")
  18. print(d)
  19. # Test converting to numpy
  20. print("\nConvert to numpy array:")
  21. numpy_array = np.array(c)
  22. print(numpy_array)