Skip to content

Commit 7825dc2

Browse files
committed
fix some tests
1 parent a6f9ba4 commit 7825dc2

File tree

8 files changed

+137
-167
lines changed

8 files changed

+137
-167
lines changed

lib/src/expr/op.dart

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,23 +1373,23 @@ VARP reshape(VARP x, List<int> shape, {DimensionFormat format = DimensionFormat.
13731373
return rval;
13741374
}
13751375

1376-
VARP scale(VARP x, int channels, List<double> scales, List<double> biases) {
1377-
final (scalesPtr, scalesSize) = scales.toNativeArrayF32();
1378-
final (biasesPtr, biasesSize) = biases.toNativeArrayF32();
1379-
final rval = VARP.fromPointer(
1380-
C.mnn_expr_Scale(
1381-
x.ptr,
1382-
channels,
1383-
scalesPtr.cast(),
1384-
scalesSize,
1385-
biasesPtr.cast(),
1386-
biasesSize,
1387-
),
1388-
);
1389-
calloc.free(scalesPtr);
1390-
calloc.free(biasesPtr);
1391-
return rval;
1392-
}
1376+
// VARP scale(VARP x, int channels, List<double> scales, List<double> biases) {
1377+
// final (scalesPtr, scalesSize) = scales.toNativeArrayF32();
1378+
// final (biasesPtr, biasesSize) = biases.toNativeArrayF32();
1379+
// final rval = VARP.fromPointer(
1380+
// C.mnn_expr_Scale(
1381+
// x.ptr,
1382+
// channels,
1383+
// scalesPtr.cast(),
1384+
// scalesSize,
1385+
// biasesPtr.cast(),
1386+
// biasesSize,
1387+
// ),
1388+
// );
1389+
// calloc.free(scalesPtr);
1390+
// calloc.free(biasesPtr);
1391+
// return rval;
1392+
// }
13931393

13941394
/// Given an input value x, it computes the output as x if x > 0 and slope * x if x <= 0.
13951395
///
@@ -2091,11 +2091,12 @@ VARP GridSample(
20912091
}) =>
20922092
VARP.fromPointer(C.mnn_expr_GridSample(input.ptr, grid.ptr, mode.value, paddingMode.value, alignCorners));
20932093

2094-
VARP floatToInt8(VARP x, VARP scale, int minvalue, int maxValue, {int? zeroPoint}) => VARP.fromPointer(
2095-
zeroPoint == null
2096-
? C.mnn_expr_FloatToInt8(x.ptr, scale.ptr, minvalue, maxValue)
2097-
: C.mnn_expr_FloatToInt8_1(x.ptr, scale.ptr, minvalue, maxValue, zeroPoint),
2098-
);
2094+
VARP floatToInt8(VARP x, VARP scale, {int minvalue = -127, int maxValue = 127, int? zeroPoint}) =>
2095+
VARP.fromPointer(
2096+
zeroPoint == null
2097+
? C.mnn_expr_FloatToInt8(x.ptr, scale.ptr, minvalue, maxValue)
2098+
: C.mnn_expr_FloatToInt8_1(x.ptr, scale.ptr, minvalue, maxValue, zeroPoint),
2099+
);
20992100

21002101
VARP int8ToFloat(VARP x, VARP scale, {int? zeroPoint}) => VARP.fromPointer(
21012102
zeroPoint == null

src/base.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,3 @@
22
// Created by rainy on 2025/9/15.
33
//
44

5-
#include "base.h"
6-
#include <cstdlib>
7-
8-
void *dart_malloc(size_t size) {
9-
#if WIN32
10-
return CoTaskMemAlloc(size);
11-
#else
12-
return malloc(size);
13-
#endif
14-
}
15-
16-
void dart_free(void *ptr) {
17-
#if WIN32
18-
return CoTaskMemFree(ptr);
19-
#else
20-
return free(ptr);
21-
#endif
22-
}

src/base.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
extern "C" {
1818
#endif
1919

20-
MNN_C_API void *dart_malloc(size_t size);
21-
22-
MNN_C_API void dart_free(void *ptr);
23-
2420
#ifdef __cplusplus
2521
}
2622
#endif

src/expr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ MNN_C_API VARMAP_t mnn_expr_VARMAP_create() {
5353
MNN_C_API void mnn_expr_VARMAP_free(void *self) { delete static_cast<VARMAP_t>(self); }
5454
MNN_C_API size_t mnn_expr_VARMAP_size(VARMAP_t self) { return self->size(); }
5555
MNN_C_API char **mnn_expr_VARMAP_keys(VARMAP_t self) {
56-
char **keys = static_cast<char **>(dart_malloc(self->size() * sizeof(char *)));
56+
char **keys = static_cast<char **>(malloc(self->size() * sizeof(char *)));
5757
int idx = 0;
5858
for (const auto &pair : *self) {
5959
keys[idx] = strdup(pair.first.c_str());
@@ -142,7 +142,7 @@ bool mnn_expr_VARP_copyToDevicePtr(VARP_t self, void *devicePtr, int memoryType)
142142

143143
struct Variable_expr_pair *mnn_expr_VARP_getExpr(VARP_t self) {
144144
auto _expr = (*self)->expr();
145-
auto pair = static_cast<Variable_expr_pair *>(dart_malloc(sizeof(Variable_expr_pair)));
145+
auto pair = static_cast<Variable_expr_pair *>(malloc(sizeof(Variable_expr_pair)));
146146
pair->index = _expr.second;
147147
pair->expr = new MNN::Express::EXPRP{_expr.first};
148148
return pair;
@@ -262,10 +262,10 @@ int mnn_expr_Expr_inputType(EXPRP_t self) { return static_cast<int>(self->get()-
262262

263263
struct mnn_expr_Variable_Info *mnn_expr_Expr_outputInfo(EXPRP_t self, int index) {
264264
auto _info = self->get()->outputInfo(index);
265-
auto info = static_cast<mnn_expr_Variable_Info *>(dart_malloc(sizeof(mnn_expr_Variable_Info)));
265+
auto info = new mnn_expr_Variable_Info();
266266
info->order = static_cast<int>(_info->order);
267267
info->ndim = _info->dim.size();
268-
auto pdim = static_cast<int32_t *>(dart_malloc(info->ndim * sizeof(int32_t)));
268+
auto pdim = new int32_t[info->ndim];
269269
for (int i = 0; i < info->ndim; i++) { pdim[i] = _info->dim[i]; }
270270
info->dim = pdim;
271271
info->type = {static_cast<uint8_t>(_info->type.code), _info->type.bits, _info->type.lanes};

test/autotime_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ void main() async {
1111
final end = timer.current();
1212
final duration = end - start;
1313
expect(duration, greaterThan(0));
14+
timer.dispose();
1415
});
1516
}

test/expr/VARP_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:mnn/mnn.dart' as mnn;
44
import 'package:mnn/numpy.dart' as np;
55
import 'package:test/test.dart';
66

7+
import '../list_element_equals.dart';
8+
79
void main() {
810
group('VARP creation', () {
911
test('VARP.create', () {
@@ -266,12 +268,13 @@ void main() {
266268
test('mean, sum instance methods', () {
267269
final data = [1.0, 2.0, 3.0, 4.0];
268270
final x = mnn.VARP.listND<mnn.float32>(data, [2, 2]);
271+
expect(x.data, listCloseTo([1.0, 2.0, 3.0, 4.0], 0.001));
269272

270273
final m = x.mean([0]); // [2, 3]
271-
expect(m.data, [2.0, 3.0]);
274+
expect(m.data, listCloseTo([2.0, 3.0], 0.001));
272275

273276
final s = x.sum([1]); // [3, 7]
274-
expect(s.data, [3.0, 7.0]);
277+
expect(s.data, listCloseTo([3.0, 7.0], 0.001));
275278

276279
x.dispose();
277280
m.dispose();

0 commit comments

Comments
 (0)