forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ParameterExpression.numeric
to cast to number
This is largely a wrap-up of the `if ParameterExpression.is_real(): ...` logic present in a few places across the library, but a bit more efficient for Symengine because it can re-use cases where it needed to force an evaluation to produce accurate results. Mostly, though, it simplifies a few call sites.
- Loading branch information
1 parent
594ae55
commit b3b0a4d
Showing
5 changed files
with
93 additions
and
41 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
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
10 changes: 10 additions & 0 deletions
10
releasenotes/notes/parameterexpression.numeric-958d365dadabfb81.yaml
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,10 @@ | ||
--- | ||
features: | ||
- | | ||
A new method :meth:`.ParameterExpression.numeric` is added, which converts a fully bound | ||
parameter expression into the most restrictive builtin Python numeric type that accurately | ||
describes the result of the symbolic evaluation. For example, a symbolic integer will become an | ||
:class:`int`, while a symbolic real number will become a :class:`float` and a complex number | ||
will become a :class:`complex`. This method includes several workarounds for peculiarities of | ||
the evaluation contexts of ``symengine``, which can sometimes lead to spurious results when | ||
calling :class:`complex` or :class:`float` on an expression directly. |
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