Event : Visual Studio Users Community Japan #1
Date : 2019/09/14
ソフトウェア/サービス開発において最も後回しにされるものの代表が「パフォーマンスの向上」です。C#/.NET の最大の武器は開発生産性ですが、C# 7.0 以降はパフォーマンス向上のための機能追加が多数行われています。いくつかのポイントを押さえることで実装時からより高速なコードを書くことができるようになります。
このドキュメントでは、そんなポイントとなる箇所をふんだんにお届けします。
Event : Visual Studio Users Community Japan #1
Date : 2019/09/14
ソフトウェア/サービス開発において最も後回しにされるものの代表が「パフォーマンスの向上」です。C#/.NET の最大の武器は開発生産性ですが、C# 7.0 以降はパフォーマンス向上のための機能追加が多数行われています。いくつかのポイントを押さえることで実装時からより高速なコードを書くことができるようになります。
このドキュメントでは、そんなポイントとなる箇所をふんだんにお届けします。
【DLゼミ】XFeat: Accelerated Features for Lightweight Image Matchingharmonylab
公開URL:https://arxiv.org/pdf/2404.19174
出典:Guilherme Potje, Felipe Cadar, Andre Araujo, Renato Martins, Erickson R. ascimento: XFeat: Accelerated Features for Lightweight Image Matching, Proceedings of the 2024 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (2023)
概要:リソース効率に優れた特徴点マッチングのための軽量なアーキテクチャ「XFeat(Accelerated Features)」を提案します。手法は、局所的な特徴点の検出、抽出、マッチングのための畳み込みニューラルネットワークの基本的な設計を再検討します。特に、リソースが限られたデバイス向けに迅速かつ堅牢なアルゴリズムが必要とされるため、解像度を可能な限り高く保ちながら、ネットワークのチャネル数を制限します。さらに、スパース下でのマッチングを選択できる設計となっており、ナビゲーションやARなどのアプリケーションに適しています。XFeatは、高速かつ同等以上の精度を実現し、一般的なラップトップのCPU上でリアルタイムで動作します。
セル生産方式におけるロボットの活用には様々な問題があるが,その一つとして 3 体以上の物体の組み立てが挙げられる.一般に,複数物体を同時に組み立てる際は,対象の部品をそれぞれロボットアームまたは治具でそれぞれ独立に保持することで組み立てを遂行すると考えられる.ただし,この方法ではロボットアームや治具を部品数と同じ数だけ必要とし,部品数が多いほどコスト面や設置スペースの関係で無駄が多くなる.この課題に対して音𣷓らは組み立て対象物に働く接触力等の解析により,治具等で固定されていない対象物が組み立て作業中に運動しにくい状態となる条件を求めた.すなわち,環境中の非把持対象物のロバスト性を考慮して,組み立て作業条件を検討している.本研究ではこの方策に基づいて,複数物体の組み立て作業を単腕マニピュレータで実行することを目的とする.このとき,対象物のロバスト性を考慮することで,仮組状態の複数物体を同時に扱う手法を提案する.作業対象としてパイプジョイントの組み立てを挙げ,簡易な道具を用いることで単腕マニピュレータで複数物体を同時に把持できることを示す.さらに,作業成功率の向上のために RGB-D カメラを用いた物体の位置検出に基づくロボット制御及び動作計画を実装する.
This paper discusses assembly operations using a single manipulator and a parallel gripper to simultaneously
grasp multiple objects and hold the group of temporarily assembled objects. Multiple robots and jigs generally operate
assembly tasks by constraining the target objects mechanically or geometrically to prevent them from moving. It is
necessary to analyze the physical interaction between the objects for such constraints to achieve the tasks with a single
gripper. In this paper, we focus on assembling pipe joints as an example and discuss constraining the motion of the
objects. Our demonstration shows that a simple tool can facilitate holding multiple objects with a single gripper.
11. Parameterless Constructors
• Design Notes 8/27†
• The meeting focused on rounding out the feature
set around structs.
1. Allowing parameterless constructors in structs <allow,
but some unresolved details>
2. Definite assignment for imported structs <revert to
Dev12 behavior>
† https://roslyn.codeplex.com/discussions/562559
12. 背景: 既定値
• 値型の既定値は0クリア
var points = new Point[1000];
• Pointが構造体のとき、コンストラクターを1000回呼ぶのか
• 呼びたくないので、memset(0)にしたい
13. 背景: new T()
• 現状、new T()で既定値を作る
var p = new Point(); 0クリア
• 構造体はパラメーターなしのコンストラクターを持
てない
14. 背景: default(T)
• .NET 2.0以降には、既定値用のdefault(T)がある
var p = default(Point); 0クリア
var p = new Point(); これで0クリアする必要まだある?
• ちなみに
コンストラクター呼んでもよくない?
• .NET IL仕様上は構造体がパラメーターなしのコンス
トラクター持てる
• C#のコンパイラーレベルでエラーにしてる
15. 問題: genericsのnew T()制約
• new T() == default(T) 前提の最適化
T M<T>()
where T : new()
{
return new T();
}
Tが構造体の時、0クリアに
最適化してしまう
• new T() がコンストラクターを呼ぶようにするには
ここも仕様変更に
20. Declaration Expressions
• Design Notes 9/3†
• The meeting focused on rounding out the design of
declaration expressions
1. Removing “spill out” from declaration expressions in
simple statements <yes, remove>
2. Same name declared in subsequent else-if’s <condition
decls out of scope in else-branch>
3. Add semicolon expressions <not in this version>
4. Make variables in declaration expressions readonly
<no>
† http://roslyn.codeplex.com/discussions/565640
21. 背景
• declaration expressions自体はCTP 2で入ってる
• 式の途中で変数宣言
var n = int.TryParse(s, out var x) ? x : 0;
if ((var x = obj as C) != null) { }
else { }
var y = (var x = GetValue()) * x;
p.GetCoordinates(out var x, out var y);
• 問題は、この変数xのスコープがどこまで続くか
22. 検討: 宣言した変数のスコープ
• 現仕様
• 宣言後、ブロックの終わりまで
{
var p = new Point();
p.GetCoordinates(out var x, out var y);
var p = x * y; // OK
Console.WriteLine("{0} = {1} × {2}", p, x, y);
}
// ここから先、x, y 使えない
• 検討事項
• ステートメント内に限るべきではないか
• if-elseの場合、else句ではどうするか
23. 検討: ステートメント内に限る
• ほんとうにステートメントの外で使う?
ステートメント内
var n = int.TryParse(s, out var x) ? x : 0;
var y = (var x = GetValue()) * x;
p.GetCoordinates(out var x, out var y);
var p = x * y;
Console.WriteLine("{0} = {1} × {2}", p, x, y);
xを使いたい範囲
ステートメント内
こいつ、要る?
• C#だと、多値戻り値自体あまり推奨されてない
• = 利用場面少ない
• =レアケースのためにxのスコープ広げる?
• ステートメント内に限った方がよくない?
24. 検討: if-else
• else句で使いたい?
• →使いたい方がレアケース
else句で意味ある値持ってない
if (int.TryParse(s, out var x)) { }
if ((var x = obj as A) != null) { }
else if ((var x = obj as B) != null) { }
else { }
else句にスコープが漏れると
むしろ使いにくい
26. Pattern Matching
• Draft spec for records and pattern-matching in
C#†
• C#にも型のパターンマッチングが入りそう
• 現在はdraft
• 実装もあり(まだmasterブランチには入ってない)
† http://roslyn.codeplex.com/discussions/560339
27. パターンマッチング式
• isを拡張
if (exp is Add(Expression left, Expression right) { … }
• switchも拡張
switch (exp)
{
case Add(Const(0), var x): return x;
case Mul(Const(0), var x): return Const(0);
}
28. operator is
• 型判定+is演算子に展開
static bool operator is(Cartesian c, out double x, out double y)
{
x = c.X;
y = c.Y;
return true;
}
29. record型
• is, Equals, GetHashCode, ToStringの自動生成
• プライマリコンストラクターの引数から
プロパティを自動生成
record class Point(int X, int Y) { }
class Point(int x, int y)
{
public int X { get; } = x;
public int Y { get; } = y;
public static bool operator is(…) { … }
override public bool Equals(object obj) { … }
override public int GetHashCode() { … }
override public string ToString() { … }
}