Complex Differentiation
まだ誰も着手していません。
評価
調査の方向性
まず、言及されている ForwardDiff derivative、can_dual、Partials のエントリーポイントと既存のテストケースを確認します。Real の制約を Number に置き換えることで、非解析的な演算を拒否しつつ解析的な複素関数をサポートできるか調査します。既存のテストがパスし、追加した複素関数のテストで導関数の成功と想定されるエラーの両方がカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I'd really like to be able to differentiate complex functions with ForwardDiff. For almost all analytic functions, the derivative can be taken in the same way as in the real case, so Julia's dynamic type system should make complex diferentiation work out of the box. It seems to me that the only reason it doesn't is because many functions in ForwardDiff accept Real arguments, but if we simply changed these to accept Numbers then we should be most of the way there. Functions that are not analytic such as real, imag, abs, conj, abs2, reim should all return errors when their derivatives are taken at a complex input. For example, consider these two functions:
f(z) = z^2
g(z) = Complex(real(z)^2 - imag(z)^2, 2 * real(z) * imag(z))
These functions are equal and both analytic, but it is not obvious by looking at g that it is analytic. In my opinion, it would be acceptable if derivative(f, im) worked while derivative(g, im) threw an error.
I already started experimenting with this. I copied the definitions of several functions in ForwardDiff and just replaced Real with Complex, like so:
ForwardDiff.can_dual(::Type{Complex{T}}) where {T<:Real} = true
@inline function ForwardDiff.derivative(f::F, x::R) where {F,R<:Complex}
T = typeof(Tag(f, R))
return extract_derivative(T, f(Dual{T}(x, one(x))))
end
@inline function Base.:*(partials::Partials, x::Complex)
return Partials(scale_tuple(partials.values, x))
end
@inline function Base.:/(partials::Partials, x::Complex)
return Partials(div_tuple_by_scalar(partials.values, x))
end
@inline Base.:*(x::Complex, partials::Partials) = partials * x
@inline Base.:*(partials::Partials{0,V}, x::Complex) where {V} = Partials{0,promote_type(V, typeof(x))}(tuple())
@inline Base.:*(x::Complex, partials::Partials{0,V}) where {V} = Partials{0,promote_type(V, typeof(x))}(tuple())
@inline Base.:/(partials::Partials{0,V}, x::Complex) where {V} = Partials{0,promote_type(V, typeof(x))}(tuple())
This was enough for me to correctly differentiate sin. I expect that if we just do this throughout ForwardDiff (and replace the Real definitions with Number, instead of adding Complex definitions like I did here), then we'll be most of the way there. Here's my plan:
- Find and replace
RealwithNumberthroughout the repository - Tweak things until all the test cases pass
- Add test cases for complex functions
I'm tempted to actually do this and make a pull request as soon as I have some time to do so.
- 主要言語
- Julia
- スター
- 80
- フォーク
- 27
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaDiff/DualNumbers.jl のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
JuliaDiff/DualNumbers.jl#94 · コメント 2 件 ·
-
div() and rem()オープン
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
JuliaDiff/DualNumbers.jl#93 ·
-
bitmix not definedオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
JuliaDiff/DualNumbers.jl#88 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
JuliaDiff/DualNumbers.jl#87 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
JuliaDiff/DualNumbers.jl#81 ·
JuliaDiff/DualNumbers.jl の issue をすべて見る
似ている issue
-
Add project: Typst_jll.jl対応中かも @github-actions が今日担当しました。 オープンadd-project
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
YDX-2147483647/best-of-typst#590 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100