Handling structs without the default constructor via `Expr(:new,...` ?

オープン
#406 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
julia

調査の方向性

CustomType MWE から始めて、src/differentials/composite.jl の read 構文、特にリンク先のセクションを読みます。次に、FiniteDifferences を介して型を構築する CRTU テストを調べ、その動作を issue で説明されているカスタムコンストラクターの処理と比較します。このコンストラクターパターンで、関連する CRTU のケースが失敗しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

In FiniteDifferences, this PR allowed custom constructors to be handled as part of to_vec: https://github.com/JuliaDiff/FiniteDifferences.jl/pull/181 here

However iiuc construct in CRC here doesn't handle this. In this case however, the constructor requirements are mentioned in the docstring.

However, tests in CRTU will construct the new type as part of the call to FiniteDifferences but then fail later as the constructor is not found in the call to construct.

Allowing this here, or otherwise, it would be easier if these behaviours were consistent in terms of custom types as part of the CTRU testing pipeline.

EDIT: MWE:

struct CustomType{T}
           x
           function CustomType(X::T) where {T}
               new{T}(X)
           end
end

# This misses the constructor:
CustomType{Int64}(5) # ERROR: MethodError: no method matching CustomType{Int64}(::Int64)

val = CustomType(5) # CustomType{Int64}(5)
diff = Tangent{typeof(val)}(x = 5) # Tangent{CustomType{Int64}}(x = 5,)

val + diff #ERROR: MethodError: no method matching CustomType{Int64}(::Int64)

# FiniteDifferences handles this in the vec to x:

to_vec(CustomType(5))[2]([6.0]) #CustomType{Int64}(6.0)

Defining CustomType{T}(x) where {T} = CustomType(x) allows this pass.

cc @mzgubic

主要言語
Julia
スター
267
フォーク
66
平均マージ
1日 1時間
マージ済み PR(30日)
9

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JuliaDiff/ChainRulesCore.jl のほかの issue

JuliaDiff/ChainRulesCore.jl の issue をすべて見る

似ている issue

Julia の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。