Maybe small improvement for accuracy for cos for regular angles

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

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

評価

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

調査の方向性

npsr/trig/high-inl.h の 35–43 行目から始め、SIMD ルーチン内のコサインの前処理パスを追跡します。既存の変換と、提案されている cos(x) = sin(π/2 - |x|) のアプローチを比較し、-pi から pi の間の入力に焦点を当てます。コサインのパスが精度を維持する変換を使用し、周辺のサイン/コサイン処理にリグレッションを生じさせないことが完了の条件です。

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

説明

@seiko2plus - Came here out of curiosity from https://github.com/numpy/numpy/pull/29699#issuecomment-3630501457, to see how things get done. For cos, the following transformation is done before any real calculation:
https://github.com/numpy/numpy-simd-routines/blob/1acd14571b9f58072d1f7f17886945000d78b56a/npsr/trig/high-inl.h#L35-L43

This would seem to loose some precision for the common case where angle input will be between -pi and pi, by moving those angles to pi/2 to 3*pi/2. Instead, one can move those angles to near zero and thus get optimal precision near both crossings by using that cos(x) = sin(pi/2 - |x|) , i.e. do something like,

  // Transform cosine to sine using identity cos(x) = sin(π/2 - |x|)
  // where |x| ensures optimal precision near both -pi/2 and pi/2.
  const V half_pi = Set(d, data::kHalfPi<T>);
  V x_trans = x;
  if constexpr (OP == Operation::kCos) {
    x_trans = And(abs_mask, x);
    x_trans = Sub(half_pi, x_trans);
  }
  const V x_abs = And(abs_mask, x_trans);
  const V x_sign = AndNot(x_abs, x_trans);
主要言語
C++
スター
10
フォーク
3
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

numpy/numpy-simd-routines のほかの issue

numpy/numpy-simd-routines の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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