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 以降はパフォーマンス向上のための機能追加が多数行われています。いくつかのポイントを押さえることで実装時からより高速なコードを書くことができるようになります。
このドキュメントでは、そんなポイントとなる箇所をふんだんにお届けします。
Pin-point rebuildable and non-rebuild custom widgetcch-robo
I will introduce my custom widgets that 'RebuildableWidget' and 'ConstantWidget'.
RebuildableWidget specifies the tree that you want the builder property to display and update.
ConstantWidget specifies a tree that the builder property does not display and update.
GDG meetup in Kyoto 2019/02/10 at Furyu
https://gdgkyoto.connpass.com/event/115000/
【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.
7. JavaScript の困ったところは、バッサリ切り捨て
7
Dart FAQ
Q. What does Google think of TypeScript?
https://dart.dev/faq#q-what-does-google-think-of-typescript
TypeScript maintains backwards compatability with JavaScript,
whereas Dart purposely made a break from certain parts of JavaScript’s syntax
and semantics in order to eradicate large classes of bugs and to improve performance.
TypeScriptは、JavaScriptとの後方互換性を維持しますが、
Dartは意図的にJavaScriptの特定の構文とセマンティクス(意味解釈)を壊し、
バグの大元を取り去り、パフォーマンスを向上させています。
9. Dart 2 から大規模変革開始
型システムが強化され 静的型付言語 となりました。
Webだけでなく、モバイルを含めたクライアント開発の
(現在ではデスクトップ含むマルチプラットフォーム開発の)
言語に強化されています。
9
Announcing Dart 2: Optimized for Client-Side Development (2018/02/23)
https://medium.com/dartlang/announcing-dart-2-80ba01f43b6
The Dart type system
https://dart.dev/guides/language/type-system
Announcing Dart 2 Stable and the Dart Web Platform (2018/08/08)
https://medium.com/dartlang/dart-2-stable-and-the-dart-web-platform-3775d5f8eac7
10. Dart 言語 公式資料
● Tutorials
https://dart.dev/tutorials
● Effective Dart
https://dart.dev/guides/language/effective-dart
● A tour of the Dart language
https://dart.dev/guides/language/language-tour
● API Reference
https://api.dart.dev/stable/2.9.0/index.html
10
15. 15
Dart スプレッド演算子
var list = [1, 2, 3];
var list2 = [0, ...list];
assert(list2.length == 4);
Dart スプレッド演算子(null認識表記)
var list;
var list2 = [0, ...?list];
assert(list2.length == 1);
spread operator ⇒ スプレッド演算子は、
コレクションへの操作を 各要素への操作に展開します。
spread operator
https://dart.dev/guides/language/language-tour#spread-operator
スプレッド演算子⇒ … は、
... 右辺のコレクションに対する操作を、
その各要素への操作として展開します。
これによりリスト全要素の別リストへの挿入も手軽に記述できます。
16. 16
Dart コレクション if
var nav = [
'Home',
'Furniture',
'Plants',
if (promoActive) 'Outlet' // true 時のみ挿入
];
Dart コレクション for
var listOfInts = [1, 2, 3];
var listOfStrings = [
'#0',
for (var i in listOfInts) '#$i'
];
// listOfStrings ⇒ ['#0','#1','#2','#3']
collection if / collection for は、
コレクションへの 条件 / 繰返 指定付きの要素挿入です。
collection if / collection for
https://dart.dev/guides/language/language-tour#collection-operators
コレクション if と コレクション for により、、
コレクションへの要素挿入処理の記述が手軽になります。
19. 19
Dart の Null 安全 : DartPad with null safety での実行結果
void main() {
String? nullableStr = null; // OK! (null 許容型の String として宣言)
int nonNullNum = 100; // OK! (null 不可型の int として宣言)
int? nullableNum = null; // OK! (null 許容型の int として宣言)
nonNullNum = nullableNum; // Type mismatch: inferred type is Int? but Int was expected
String nonNullStr = null; // Null can not be a value of a non-null type String
}
DartPad with null safety
https://nullsafety.dartpad.dev/
null safety ⇒ null 安全では、
型宣言? で null 許容型、なければ常に null 不可型になる。
20. 20
class Sample {
// 初回アクセスされるまでに初期化されていれば良い、 null 不可型宣言フィールド
late String lateStr;
void init() { print("late -> "); lateStr = "Hello"; }
}
void main() {
Sample sample = Sample();
sample.init();
print("lateStr=${sample.lateStr}"); // late -> lateStr=Hello
}
null safety ⇒ null 不可なフィールドは、
late 型宣言で 遅延設定フィールド に修正する。
late を付けて宣言しないとエラーになる。
Error: Field 'lateStr' should be initialized
because its type 'String' doesn't allow null.
String lateStr;
^^^^^^^
21. 21
null safety ⇒ null 安全では、
null 不可なオプション引数に、初期値が必須になる。
void present(
String name, {String color}) {
print('I send you a $color $name.');
}
Error: Optional parameter 'color' should
have a default value because its type
'String' doesn't allow null.
String name, {String color}) {
^^^^^
void main() {
present('rose', color:'red');
}
void present(
String name, {String color='white'}) {
print('I send you a $color $name.');
// I send you a red rose. が表示される。
}
オプション引数に、初期値があるとき。 オプション引数に、初期値がないとき。
22. 22
Flutter Day Livestream | Session 3: Dart
https://www.youtube.com/watch?v=ZxSyZHq8gUg&feature=youtu.be&t=1618
null safety ⇒ null 安全に移行するには、
既存ソースからの移行作業が必須になります。
nnbd_migration 0.1.0
https://pub.dev/packages/nnbd_migration
null 安全は、魅力的ですが、
既存のコードやライブラリは、
移行作業(コード修正)が必須です
このため Dart チームは、
移行ツールを提供しています。
Note: the null safety migration tooling is in an early
state and may have bugs and other issues.
For best results, use SDK version 2.9.0-10.0.dev or higher.
23. 23
Kotlin Playground
https://play.kotlinlang.org/
【参考】Kotlin の Null 安全 : Kotln Playground での実行結果
fun main() {
var nullableNum : Int? = null // OK! (Null 許容型の Int として宣言)
var nonNullNum : Int = 100 // OK! (Null 不可型の Int として宣言)
var nullableStr : String? = null // OK! (Null 許容型の String として宣言)
nonNullNum = nullableNum // Type mismatch: inferred type is Int? but Int was expected
var nonNullStr : String = null // Null can not be a value of a non-null type String
}
【参考】 Kotlin の Null Safety ⇒ Null 安全も、
型宣言? であれば Null 許容型、なければ常に Null 不可型
24. 24
class Sample {
// 初回アクセスされるまでに初期化されていれば良い、 Null 不可型宣言フィールド
lateinit var lateStr : String
// 初回アクセス時に初期化の移譲関数が実行される、 Null 不可型宣言フィールド
val lazyNum : Int by lazy { print("lazy -> "); 100 }
fun init() { print("late -> "); lateStr = "Hello" }
}
fun main(args: Array<String>) {
val sample = Sample(); sample.init()
println("lateStr=${sample.lateStr}") // late -> lateStr=Hello
println("lazyNum=${sample.lazyNum}") // lazy -> lazyNum=100
}
【参考】 Kotlin の Null 安全な、遅延設定フィールドは、
lateinit か lazy 移譲関数を指定する。
26. 26
Are there any sealed classes alternatives in Dart 2.0?
https://stackoverflow.com/questions/54317000/are-there-any-sealed-classes-alternatives-in-dart-2-0
【補足】 Sealed Class は、
完全ではありませんが擬似コードは作れます。
【参考】Kotlin シールドクラス例
sealed class MyState {
data class Success(val data: List<MyObject>) : MyState()
data class Error(val error: String) : MyState()
}
シールドクラスは、継承可能な範囲(派生先)を制限するクラス
これにより派生物ごとの処理制御が保証可能になります。
stack overflow に Dartでの擬似コードの回答例がありました。
27. 27
Algebraic Data Types (ADTs, Sealed Classes, Enum with associated values)
https://github.com/dart-lang/language/issues/349
Dart での擬似コード回答例
class MyState {
MyState._();
factory MyState.success(String foo) = MySuccessState;
factory MyState.error(String foo) = MyErrorState;
}
class MyErrorState extends MyState {
MyErrorState(this.msg): super._();
final String msg;
}
class MySuccessState extends MyState {
MySuccessState(this.value): super._();
final String value;
}
擬似コードでも、
想定を満たしますが、
Kotlin の
シールドクラスは、
定義されたファイル以外
に、指定されたクラスの
他の実装がないことまで
保証できます。
dart-lang に ISSUE は立ってます。
29. むすび
Dart FAQ からの2つの回答をもとに、
私は、ゆっくりですが着実に進んでいくと思います。
29
Q. Why isn’t Dart syntax more exciting?
https://dart.dev/faq#q-why-isnt-dart-syntax-more-exciting
> but we’d agree that Dart chooses familiarity over excitement.
Dart言語は、エキサイトメントよりも親しみやすさを選択します。
30. 30
Q. Can Dart add tuples, pattern matching, non-nullable types,
partial evaluation, optional semicolons, …?
https://dart.dev/faq#q-can-dart-add-tuples-pattern-matching-non-nullable-types-partial-evaluation-optional-semicolons-
> Some features don’t fit the basic nature of the language,
> and some don’t play well with other features.
> Simplicity is the single most important gift we can give to future programmers.
> It’s far more painful to remove a language feature than to add it,
> so Dart is likely to add the most obvious features first, and then revisit the next tier later.
一部の機能は言語の基本的な性質に適合しませんし、
他の機能とうまく連携しません。
シンプルさこそが、
将来のプログラマーに与えることができる最も重要な贈り物です。