physics The goal of
this package is to make typesetting equations for physics simpler,
faster, and more human readable. To that end, the commands included in
this package have names that make the purpose of each command
immediately obvious and remove any ambiguity while reading and editing
physics code. From a practical standpoint, it is handy to have a
well-defined set of shortcuts for accessing the long-form of each of
these commands. The commands listed below are therefore defined in terms
of their long-form names and then shown explicitly in terms of the
default shorthand command sequences. These shorthand commands are meant
make it easy to remember both the shorthand names and what each one
represents.
physconst This
package consists of several macros that are shorthand for a variety of
physical constants, e.g. the speed of light. The package developed out
of physics and astronomy classes that I have taught and wanted to ensure
that I had correct values for each constant and did not wish to retype
them every time I use them. The constants can be used in two forms, the
most accurate available values, or versions that are rounded to 3
significant digits for use in typical classroom settings, homework
assignments, etc.
physunits This
package consists of several macros that are shorthand for a variety of
physical units that are commonly used in introductory level physics and
astronomy classes. At present, this package provides some similar units
to those in siunitx, but is uses slightly different macro names for
each. This package also provides a number of non-SI units (e.g. erg, cm,
BTU).
# NumPy and CPU Runtime s = time.time() x_cpu = np.ones((1000, 100, 1000)) np_result = np.sqrt(np.sum(x_cpu**2, axis=-1)) e = time.time() np_time = e - s print("Time consumed by NumPy: ", np_time)
Time consumed by NumPy: 0.5474584102630615
同样,创建一个 3D CuPy 数组,执行数学运算,并为其计时以提高性能。
1 2 3 4 5 6 7 8 9
# CuPy and GPU Runtime s = time.time() x_gpu = cp.ones((1000, 100, 1000)) cp_result = cp.sqrt(cp.sum(x_gpu**2, axis=-1)) e = time.time() cp_time = e - s print("\nTime consumed by CuPy: ", cp_time)
Time consumed by CuPy: 0.001028299331665039
为了计算差异,我们将 NumPy 时间除以 CuPy 时间
1 2 3 4
diff = np_time/cp_time print(f'\nCuPy is {diff: .2f} X time faster than NumPy')
from cupy.core.dlpack import toDlpack from cupy.core.dlpack import fromDlpack from torch.utils.dlpack import to_dlpack from torch.utils.dlpack import from_dlpack import torch
注意:对于clone下来的项目,push和pull和普通的git操作没有区别。如果不像上面这样编辑默认的默认的仓库及分支,则网络上的教程在U盘上建立git仓库,移动的“私有云”完成的配置的话应当使用命令pull usb master拉取,使用push usb master推送,其显然不如此处的配置便捷。