Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Replace use of asExternalTypedData with asTypedList. #31

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.3.1-dev.2

* Replaced uses of deprecated `asExternalTypedData` with `asTypedList`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change the min. Dart SDK requirements for this package? If so, we should update the pubspec as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think asTypedList has been published in a dev release yet, but we needed to make the change to ship D26, since this package is used in the SDK and we want to remove deprecated methods before shipping.

After shipping we should update the minimum constraint to D26 /cc @dcharkes @mkustermann


# 0.3.0

* Update to new tflite C API

# 0.3.0

* Update to new tflite C API
Expand Down
11 changes: 5 additions & 6 deletions lib/src/tensor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Tensor {
Uint8List get data {
final data = cast<Uint8>(TfLiteTensorData(_tensor));
checkState(isNotNull(data), message: 'Tensor data is null.');
return UnmodifiableUint8ListView(data.asExternalTypedData(
count: TfLiteTensorByteSize(_tensor)) as Uint8List);
return UnmodifiableUint8ListView(
data.asTypedList(TfLiteTensorByteSize(_tensor)));
}

/// Updates the underlying data buffer with new bytes.
Expand All @@ -48,8 +48,7 @@ class Tensor {
checkArgument(tensorByteSize == bytes.length);
final data = cast<Uint8>(TfLiteTensorData(_tensor));
checkState(isNotNull(data), message: 'Tensor data is null.');
final externalTypedData =
data.asExternalTypedData(count: tensorByteSize) as Uint8List;
final externalTypedData = data.asTypedList(tensorByteSize);
externalTypedData.setRange(0, tensorByteSize, bytes);
}

Expand All @@ -58,7 +57,7 @@ class Tensor {
void copyFrom(Uint8List bytes) {
var size = bytes.length;
final ptr = allocate<Uint8>(count: size);
final externalTypedData = ptr.asExternalTypedData(count: size) as Uint8List;
final externalTypedData = ptr.asTypedList(size);
externalTypedData.setRange(0, bytes.length, bytes);
checkState(TfLiteTensorCopyFromBuffer(_tensor, ptr.cast(), bytes.length) ==
TfLiteStatus.ok);
Expand All @@ -70,7 +69,7 @@ class Tensor {
Uint8List copyTo() {
var size = TfLiteTensorByteSize(_tensor);
final ptr = allocate<Uint8>(count: size);
final externalTypedData = ptr.asExternalTypedData(count: size) as Uint8List;
final externalTypedData = ptr.asTypedList(size);
checkState(
TfLiteTensorCopyToBuffer(_tensor, ptr.cast(), 4) == TfLiteStatus.ok);
// Clone the data, because once `free(ptr)`, `externalTypedData` will be
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tflite_native
version: 0.3.1-dev
version: 0.3.1-dev.2
author: Dart Team <[email protected]>
description: >-
A Dart interface to TensorFlow Lite through Dart FFI. This library wraps the
Expand All @@ -12,7 +12,7 @@ environment:
dependencies:
path: ^1.6.2
quiver: ^2.0.3
ffi: ^0.1.3-dev.1
ffi: ^0.1.3-dev.3

dev_dependencies:
pedantic: ^1.0.0
Expand Down