halildurmus / dartwinrt

Idiomatic Dart projection of the modern Windows Runtime (WinRT) APIs.
BSD 3-Clause "New" or "Revised" License
49 stars 3 forks source link

windows_ai: float and double tensor's getAsVectorView() throws exception #261

Closed harshitmahapatra closed 1 year ago

harshitmahapatra commented 1 year ago

Is there an existing issue for this?

On which packages did you experience this issue?

windows_ai

What version are you using?

windows_ai: 0.0.2

What happened?

Creating a tensor of type float or double (using the TensorFloat or TensorDouble class) and calling getAsVectorView() throws exception.

Steps to reproduce

1. Run the following dart code:

import 'package:windows_ai/windows_ai.dart';

void main() {
  final tensor =
      TensorFloat.createFromShapeArrayAndDataArray([1, 4], [1, 2, 3, 4]);
  print(tensor?.getAsVectorView());
}

Expected Output: `[1, 2, 3, 4]`
Current Output:
Unhandled exception:
Invalid argument (T): Unsupported type: double
#0      new IVectorView.fromPtr (package:windows_foundation/src/collections/ivectorview.dart:133:5)
#1      ITensorFloat.getAsVectorView (package:windows_ai/src/machinelearning/itensorfloat.dart:48:24)
#2      TensorFloat.getAsVectorView (package:windows_ai/src/machinelearning/tensorfloat.dart:73:51)
#3      main (package:iamhear_app/services/windows_ai.dart:6:17)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
#5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

Supporting info to reproduce

Upon looking at the IVectorView.fromPtr factory in ivectorview.dart in windows_foundation, it seems that the error happens because the factory can handle bool, Guid, int, String and Uri, but has no method for double.

This is also seems to be the case when looking at the ivectorview_part.dart in the same package, as the said file does not ivectorview class for double type.

Relevant log output

Unhandled exception:
Invalid argument (T): Unsupported type: double
#0      new IVectorView.fromPtr (package:windows_foundation/src/collections/ivectorview.dart:133:5)
#1      ITensorFloat.getAsVectorView (package:windows_ai/src/machinelearning/itensorfloat.dart:48:24)
#2      TensorFloat.getAsVectorView (package:windows_ai/src/machinelearning/tensorfloat.dart:73:51)
#3      main (package:iamhear_app/services/windows_ai.dart:6:17)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
#5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

Flutter analyze output

Analyzing services...                                                   

   info - Don't invoke 'print' in production code - windows_ai.dart:6:3 - avoid_print

1 issue found. (ran in 0.4s)

Flutter doctor output

[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1848], locale en-US)
    • Flutter version 3.10.5 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (9 days ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\harsh\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.2)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.6.33723.286
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.79.2)
    • VS Code at C:\Users\harsh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.66.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.1848]
    • Chrome (web)      • chrome  • web-javascript • unknown
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 112.0.1722.58

[√] Network resources
    • All expected network resources are available.

• No issues found!
[√] Network resources

• No issues found!

Code of Conduct

halildurmus commented 1 year ago

Oops! Thanks for catching this. I'll fix this shortly.

harshitmahapatra commented 1 year ago

No worries! Thanks a lot for the really nice project :).

halildurmus commented 1 year ago

Just published windows_ai v0.0.2+1.

harshitmahapatra commented 1 year ago

Thanks a lot, I just tested it and can confirm it works!