`ProjectTo{SparseMatrixCSC}` can incorrectly assume `eltype` of projected value

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

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

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

評価

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

調査の方向性

src/projection.jl の575-583行目から開始し、Unitful.Quantity の微分と Float64 のスパース配列を使った SparseMatrixCSC 射影を再現してください。project_type と提案された mapreduce アプローチが射影された値および異種の値をどのように処理するかを調査してください。完了条件は、射影で報告された次元エラーが発生しなくなり、正しい型の挙動が維持されることです。

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

説明

ProjectTo

The example below attempts to project a Unitful.Quantity differential onto a sparse array of Float64

using SparseArrays
using ChainRulesCore

using Unitful
using UnitfulChainRules # defines projection of quantities onto Floats/Complex{<:Float}

A = sprandn(5,5, 0.5)
pA = ProjectTo(A)

dx = randn((5,5)) * u"m"

pA(dx)
# Unitful error:
# ERROR: DimensionError:  and m are not dimensionally compatible.

The error occurs here because we pre-allocate the nzvals vector using project_type(project.element). However, project_type doesn't take into account the value we are projecting, which, in the case of a Unitful.Quantity, can mean that project_type(ProjectTo(A)) != eltype(A).

In the case of SparseMatrixCSC, we can rewrite the projection without preallocating nzvals using mapreduce to get a type-stable pullback that doesn't use project_type. In general, would it be better to get away without project_type and write projections which infer the type based on the input types?

E- On closer inspection the mapreduce solution runs into issues if the differential isn't a homogeneous type, project_type may be a necessary solution here

主要言語
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 を短くまとめたダイジェスト。