为 Matlab 编写 Astropy Units / 软件架构是什么?

Writing Astropy Units for Matlab / What is the software architecture?

Matlab 没有 Astropy Units 这样的功能。此功能允许将单位附加到 Python 中的数值数据。单位可以因式分解、乘法、除法、简化。当带有单位的数值数据添加到带有错误单位或根本没有单位的数值数据时,它会提供错误。

可以使用 NumPy 在线性代数、FFT 等中处理带有单位的数据。单位也显示在 LaTex 和图形轴上。

虽然我了解 OOP 概念,但我不明白 Astropy 是如何在没有大量重写 NumPy(等)的情况下编写的。

NumPy 如何在不重写 NumPy 中的每个方法的情况下接受 Astopy 单位标记对象?

Astropy Quantity 是 numpy ndarray class 的子class。它提供了 __array_function__ 方法(https://numpy.org/neps/nep-0018-array-function-protocol.html),它允许覆盖 numpy 函数的行为。

如果您对软件架构感兴趣,您应该继续查看源代码:

https://github.com/astropy/astropy/blob/master/astropy/units/quantity.py