-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prepare `pyconstant` variable and export it from SciPy * collect constant-like objects and store them in d["constant"] * implement `constants` module * mv docstring * fix * write comment because the implenentation of `constants` module is more complicated than other submodules of SciPy.jl * add type checking test * write more tests * fix docstring * add comment * Revert "add comment" This reverts commit 939e506. * Revert "collect constant-like objects and store them in d["constant"]" This reverts commit 1a7b6c9. * rewrite constants.jl * add test
- Loading branch information
1 parent
3caf6d2
commit 4610d78
Showing
3 changed files
with
88 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
scipy.constants module | ||
- [Constants (scipy.constants) Reference Guide](https://docs.scipy.org/doc/scipy/reference/constants.html) | ||
# Examples | ||
You can access each constants: | ||
```julia-repl | ||
julia> SciPy.constants.golden | ||
1.618033988749895 | ||
julia> SciPy.constants.physical_constants["electron mass"] | ||
(9.10938356e-31, "kg", 1.1e-38) | ||
julia> SciPy.constants.convert_temperature([-40, 40.0], "Celsius", "Kelvin") | ||
2-element Vector{Float64}: | ||
233.14999999999998 | ||
313.15 | ||
``` | ||
""" | ||
module constants | ||
|
||
using PyCall | ||
|
||
pyimport_conda("scipy", "scipy") | ||
@pyinclude(joinpath(pkgdir(@__MODULE__), "src", "scipy_api_list.py")) | ||
apis = py"generate_scipy_apis"("constants") | ||
|
||
all_properties = [apis["function"]; apis["class"]] | ||
|
||
import ..pyconstants | ||
|
||
import ..LazyHelp | ||
|
||
const _ignore_funcs = ["constants"] | ||
|
||
for f in [apis["function"]; apis["class"]] | ||
f in _ignore_funcs && continue | ||
|
||
sf = Symbol(f) | ||
@eval @doc LazyHelp(pyconstants, $f) $sf(args...; kws...) = | ||
pycall(pyconstants.$f, PyAny, args...; kws...) | ||
end | ||
|
||
function __init__() | ||
copy!(pyconstants, pyimport_conda("scipy.constants", "scipy")) | ||
|
||
#= | ||
The following metaprogramming will generate expressions like: | ||
const zero_Celsius = 273.15 | ||
const golden = 1.618033988749895 | ||
const centi = 0.01 | ||
=# | ||
for f in pyconstants.__all__ |> unique |> sort | ||
f in _ignore_funcs && continue # just in case | ||
a = pybuiltin("getattr")(pyconstants, f) | ||
if a isa PyObject | ||
# The variable `a` should be python function, class or module | ||
continue | ||
else | ||
# The variable `a` is converted in a Julia's native type. We assume this is a constant value. | ||
sf = Symbol(f) | ||
@eval @doc LazyHelp(pyconstants, $f) const $sf = $a | ||
end | ||
end | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters