ICplxTrans' `to_bytes` and `from_bytes` use different primitive data types (int on write, float on read)

オープン 初心者向け
#2,554 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, python
領域
backend

調査の方向性

バグは src/db/db/dbBinarySerialize.h の446~463行目付近のリーダーにあり、ICplxTrans の変位が R (double) として読み込まれる一方で D (int) として書き込まれています。まず issue にある Python のラウンドトリップを再現し、from_bytes の後の変位を確認してください。ICplxTrans(Trans(x=10000, y=-2000)) が to_bytes/from_bytes を経ても変わらず、既存のバイナリ形式も引き続き動作すれば完了です。

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

説明

Hi Matthias,

I found an asymmetry in ICplxTrans.to_bytes() and ICPlxTrans.from_bytes (a clanker helped me analyze the precise error which seems to come from klayout).

Small clanker analysis bleow:

In KLayout 0.30.13, an ICplxTrans with a displacement does not survive a to_bytes() / from_bytes() round trip.

import klayout.db as kdb

original = kdb.ICplxTrans(kdb.Trans(x=10000, y=-2000))
restored = kdb.ICplxTrans.from_bytes(original.to_bytes())

print(original)  # r0 *1 10000,-2000
print(restored)  # r0 *1 0,nan
assert restored == original  # fails

The displacement is present in the serialized bytes. In dbBinarySerialize.h (https://github.com/KLayout/klayout/blob/v0.30.13/src/db/db/dbBinarySerialize.h#L446-L463), the writer stores it using the output coordinate type D, but the reader reads it using the internal representation type R. For ICplxTrans, those are integer and double respectively, so the coordinate bytes are interpreted as floating point values.

Suggested minimal fix for the reader:

-  db::vector<R> d;
+  db::vector<D> d;
   read_binary (s, d);

   double asin, acos, mag;
   s >> asin >> acos >> mag;

-  t = db::complex_trans<C, D, R> (d, asin, acos, mag);
+  t = db::complex_trans<C, D, R> (db::vector<R> (d), asin, acos, mag);

This keeps the existing binary format and reads its displacement using the type with which it was written.

主要言語
C++
スター
1.2k
フォーク
305
平均マージ
3日 2時間
マージ済み PR(30日)
11

環境構築

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

はじめの一歩

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

KLayout/klayout のほかの issue

KLayout/klayout の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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