Skip to content

Commit

Permalink
dart format
Browse files Browse the repository at this point in the history
  • Loading branch information
jpohhhh committed Dec 12, 2023
1 parent 8da8918 commit 1936595
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 30 deletions.
1 change: 0 additions & 1 deletion example/integration_test/plugin_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// For more information about Flutter integration tests, please see
// https://docs.flutter.dev/cookbook/testing/integration/introduction


import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand Down
2 changes: 1 addition & 1 deletion example/lib/padding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const heightPadding = SizedBox(
);
const widthPadding = SizedBox(
width: padding,
);
);
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data!.startsWith('Running on:'),
(Widget widget) =>
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
5 changes: 2 additions & 3 deletions lib/extensions/vector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ extension Average on Iterable<Vector> {
if (isEmpty) {
return null;
}

final length = this.length;
final sum =
fold(Vector.zero(first.length), (previousValue, element) {
final sum = fold(Vector.zero(first.length), (previousValue, element) {
return previousValue + element;
});

Expand Down
2 changes: 1 addition & 1 deletion lib/fonnx_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class FonnxPlatform extends PlatformInterface {
Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
}

Future<Float32List?> miniLm({
required String modelPath,
required List<int> inputs,
Expand Down
4 changes: 2 additions & 2 deletions lib/fonnx_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class FonnxWeb extends FonnxPlatform {
/// Returns a [String] containing the version of the platform.
@override
Future<String?> getPlatformVersion() async {
throw UnimplementedError();
throw UnimplementedError();
}

@override
Future<Float32List?> miniLm({
required String modelPath,
required List<int> inputs,
}) async {
throw UnimplementedError();
throw UnimplementedError();
}
}
2 changes: 1 addition & 1 deletion lib/models/minilml6v2/mini_lm_l6_v2_abstract.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'mini_lm_l6_v2.dart';

MiniLmL6V2 getMiniLmL6V2(String path) =>
throw UnsupportedError('Cannot create a MiniLmL6V2');
throw UnsupportedError('Cannot create a MiniLmL6V2');
3 changes: 1 addition & 2 deletions lib/models/minilml6v2/mini_lm_l6_v2_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class MiniLmL6V2Native implements MiniLmL6V2 {
return vector;
}

Future<Float32List> getEmbedding(
List<int> tokens) async {
Future<Float32List> getEmbedding(List<int> tokens) async {
await _onnxIsolateManager.start();
if (!kIsWeb && Platform.environment['FLUTTER_TEST'] == 'true') {
return _onnxIsolateManager.sendInference(modelPath, tokens);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'msmarco_mini_lm_l6_v3.dart';

MsmarcoMiniLmL6V3 getMsmarcoMiniLmL6V3(String path) =>
throw UnsupportedError('Cannot create a MsmarcoMiniLmL6V3');
throw UnsupportedError('Cannot create a MsmarcoMiniLmL6V3');
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MsmarcoMiniLmL6V3Native implements MsmarcoMiniLmL6V3 {
final OnnxIsolateManager _onnxIsolateManager = OnnxIsolateManager();

MsmarcoMiniLmL6V3Native(this.modelPath);

Fonnx? _fonnx;

@override
Expand All @@ -26,8 +26,7 @@ class MsmarcoMiniLmL6V3Native implements MsmarcoMiniLmL6V3 {
return vector;
}

Future<Float32List> getEmbedding(
List<int> tokens) async {
Future<Float32List> getEmbedding(List<int> tokens) async {
await _onnxIsolateManager.start();
if (!kIsWeb && Platform.environment['FLUTTER_TEST'] == 'true') {
return _onnxIsolateManager.sendInference(modelPath, tokens);
Expand Down
5 changes: 2 additions & 3 deletions lib/models/whisper/whisper_native.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:ffi';


import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.dart';

Expand All @@ -22,7 +21,8 @@ class WhisperNative implements Whisper {
}

OrtSessionObjects get _session {
_sessionObjects ??= createOrtSession(modelPath, includeOnnxExtensionsOps: true);
_sessionObjects ??=
createOrtSession(modelPath, includeOnnxExtensionsOps: true);

return _sessionObjects!;
}
Expand Down Expand Up @@ -140,7 +140,6 @@ class WhisperNative implements Whisper {
outputValues.value, stringLength, 0, stringPtr.cast<Void>());
final string = stringPtr.cast<Utf8>().toDartString(length: stringLength);


sw.stop();
sw.reset();
sw.start();
Expand Down
2 changes: 1 addition & 1 deletion lib/models/whisper/whisper_none.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fonnx/models/whisper/whisper.dart';

Whisper getWhisper(String path) =>
throw UnsupportedError('Cannot create a Whisper');
throw UnsupportedError('Cannot create a Whisper');
3 changes: 1 addition & 2 deletions lib/ort_minilm_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class OnnxIsolateManager {
Isolate? _isolate;
Future<void>? _starting;


// Start the isolate and store its SendPort.
Future<void> start() async {
if (_starting != null) {
Expand All @@ -90,7 +89,7 @@ class OnnxIsolateManager {
// Wait for the SendPort from the new isolate.
final sendPort = await receivePort.first as SendPort;
_sendPort = sendPort;

// Mark the start process as complete.
completer.complete();
_starting = null;
Expand Down
1 change: 0 additions & 1 deletion lib/tokenizers/bert_vocab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30523,7 +30523,6 @@ const Map<String, int> bertEncoder = {
r"""##~""": 30521,
};


const List<String> bertDecoder = [
r"""[PAD]""",
r"""[unused0]""",
Expand Down
6 changes: 4 additions & 2 deletions test/fonnx_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ void main() {
const MethodChannel channel = MethodChannel('fonnx');

setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(MethodCall methodCall) async {
return '42';
Expand All @@ -18,7 +19,8 @@ void main() {
});

tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});

test('getPlatformVersion', () async {
Expand Down
1 change: 0 additions & 1 deletion test/fonnx_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockFonnxPlatform
with MockPlatformInterfaceMixin
implements FonnxPlatform {

@override
Future<String?> getPlatformVersion() => throw UnimplementedError();

Expand Down
6 changes: 4 additions & 2 deletions test/models/msmarco_mini_lm_l6_v3_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ void main() {
});

test('Performance test', () async {
final List<List<int>> tokens =
MsmarcoMiniLmL6V3.tokenizer.tokenize(data).map((e) => e.tokens).toList();
final List<List<int>> tokens = MsmarcoMiniLmL6V3.tokenizer
.tokenize(data)
.map((e) => e.tokens)
.toList();
const count = 100;
List<Future> futures = [];
final sw = Stopwatch()..start();
Expand Down
4 changes: 3 additions & 1 deletion test/models/whisper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void main() {
const modelPath = 'example/assets/models/whisper/whisper_tiny.onnx';
final whisper = WhisperNative(modelPath);
final shouldSkip = !Platform.isMacOS && !Platform.isLinux;
final skipReason = shouldSkip ? 'Whisper only works on ARM64 Mac and X64 Linux currently' : null;
final skipReason = shouldSkip
? 'Whisper only works on ARM64 Mac and X64 Linux currently'
: null;

test('Whisper works', skip: skipReason, () async {
String testFilePath = 'test/data/rain_in_spain.wav';
Expand Down

0 comments on commit 1936595

Please sign in to comment.