其他
Mojo编程语言开放下载,声称比Python快68000倍
mojo 驱动:提供 shell 用于 read-eval-print-loop 或 REPL 的 shell,支持构建和运行 Mojo 程序、打包 Mojo 模块(包括对 🔥 扩展的支持)、生成文档和格式化代码
VS Code 扩展:支持多项生产力功能,例如语法高亮显示、自动补全代码等
Jupyter kernel:支持构建和运行 Mojo notebooks,包括 Python 代码
调试工具(即将推出):进入并检查正在运行的 Mojo 程序,甚至包括混合 C++ 和 Mojo 代码的框架
$ mojo
Welcome to Mojo! 🔥
Expressions are delimited by a blank line.
Type `:mojo help` for further assistance.
1> %%python
2. import numpy as np
3. n = 10000000
4. anp = np.random.rand(n)
5. bnp = np.random.rand(n)
6> from tensor import Tensor
7. let n: Int = 10000000
8. var a = Tensor[DType.float64](n)
9. var b = Tensor[DType.float64](n)
10. for i in range(n):
11. a[i] = anp[i].to_float64()
12. b[i] = bnp[i].to_float64()
13> from math import sqrt
14. def mojo_naive_dist(a: Tensor[DType.float64], b: Tensor[DType.float64]) -> Float64:
15. var s: Float64 = 0.0
16. n = a.num_elements()
17. for i in range(n):
18. dist = a[i] - b[i]
19. s += dist*dist
20. return sqrt(s)
23> fn mojo_fn_dist(a: Tensor[DType.float64], b: Tensor[DType.float64]) -> Float64:
24. var s: Float64 = 0.0
25. let n = a.num_elements()
26. for i in range(n):
27. let dist = a[i] - b[i]
28. s += dist*dist
29. return sqrt(s)
30.
31> let naive_dist = mojo_naive_dist(a, b)
32. let fn_dist = mojo_fn_dist(a, b)
33. print(fn_dist)
34.
1290.8521425092235
35. print(naive_dist)
36.
1290.8521425092235
$ mojo build hello.🔥
$ ./hello
Hello Mojo 🔥!
9
6
3
$ ls -lGtranh hello*
-rw-r--r-- 1 0 817 Sep 3 23:59 hello.🔥
相关链接:
https://www.modular.com/blog/mojo-its-finally-here
往期推荐
点这里 ↓↓↓ 记得 关注✔ 标星⭐ 哦