Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
71aa1b49
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
71aa1b49
编写于
12月 09, 2019
作者:
Y
yiicy
提交者:
GitHub
12月 09, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[JAVA API]java tensor api setData and getData support Int type, test=develop (#2583)
上级
a2f981a4
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
69 addition
and
3 deletion
+69
-3
lite/api/android/jni/native/tensor_jni.cc
lite/api/android/jni/native/tensor_jni.cc
+30
-0
lite/api/android/jni/native/tensor_jni.h
lite/api/android/jni/native/tensor_jni.h
+19
-3
lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java
lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java
+20
-0
未找到文件。
lite/api/android/jni/native/tensor_jni.cc
浏览文件 @
71aa1b49
...
...
@@ -120,6 +120,22 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_lite_Tensor_nativeSetData___3B(
return
JNI_TRUE
;
}
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_nativeSetData___3I
(
JNIEnv
*
env
,
jobject
jtensor
,
jintArray
buf
)
{
std
::
unique_ptr
<
Tensor
>
*
tensor
=
get_writable_tensor_pointer
(
env
,
jtensor
);
if
(
tensor
==
nullptr
||
(
*
tensor
==
nullptr
))
{
return
JNI_FALSE
;
}
int64_t
buf_size
=
(
int64_t
)
env
->
GetArrayLength
(
buf
);
if
(
buf_size
!=
product
((
*
tensor
)
->
shape
()))
{
return
JNI_FALSE
;
}
int32_t
*
input
=
(
*
tensor
)
->
mutable_data
<
int32_t
>
();
env
->
GetIntArrayRegion
(
buf
,
0
,
buf_size
,
input
);
return
JNI_TRUE
;
}
JNIEXPORT
jfloatArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getFloatData
(
JNIEnv
*
env
,
jobject
jtensor
)
{
if
(
is_const_tensor
(
env
,
jtensor
))
{
...
...
@@ -148,6 +164,20 @@ Java_com_baidu_paddle_lite_Tensor_getByteData(JNIEnv *env, jobject jtensor) {
}
}
JNIEXPORT
jintArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getIntData
(
JNIEnv
*
env
,
jobject
jtensor
)
{
if
(
is_const_tensor
(
env
,
jtensor
))
{
std
::
unique_ptr
<
const
Tensor
>
*
tensor
=
get_read_only_tensor_pointer
(
env
,
jtensor
);
return
cpp_array_to_jintarray
(
env
,
(
*
tensor
)
->
data
<
int32_t
>
(),
product
((
*
tensor
)
->
shape
()));
}
else
{
std
::
unique_ptr
<
Tensor
>
*
tensor
=
get_writable_tensor_pointer
(
env
,
jtensor
);
return
cpp_array_to_jintarray
(
env
,
(
*
tensor
)
->
data
<
int32_t
>
(),
product
((
*
tensor
)
->
shape
()));
}
}
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_deleteCppTensor
(
JNIEnv
*
env
,
jobject
jtensor
,
jlong
java_pointer
)
{
if
(
java_pointer
==
0
)
{
...
...
lite/api/android/jni/native/tensor_jni.h
浏览文件 @
71aa1b49
...
...
@@ -16,8 +16,8 @@
#include <jni.h>
/* Header for class com_baidu_paddle_lite_Tensor */
#ifndef
PADDLE_FLUID_
LITE_API_ANDROID_JNI_NATIVE_TENSOR_JNI_H_
#define
PADDLE_FLUID_
LITE_API_ANDROID_JNI_NATIVE_TENSOR_JNI_H_
#ifndef LITE_API_ANDROID_JNI_NATIVE_TENSOR_JNI_H_
#define LITE_API_ANDROID_JNI_NATIVE_TENSOR_JNI_H_
#ifdef __cplusplus
extern
"C"
{
#endif
...
...
@@ -49,6 +49,14 @@ Java_com_baidu_paddle_lite_Tensor_getFloatData(JNIEnv *, jobject);
JNIEXPORT
jbyteArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getByteData
(
JNIEnv
*
,
jobject
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: getIntData
* Signature: ()[I
*/
JNIEXPORT
jintArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getIntData
(
JNIEnv
*
,
jobject
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: nativeResize
...
...
@@ -73,6 +81,14 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_lite_Tensor_nativeSetData___3F(
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_nativeSetData___3B
(
JNIEnv
*
,
jobject
,
jbyteArray
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: nativeSetData
* Signature: ([I)Z
*/
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_nativeSetData___3I
(
JNIEnv
*
,
jobject
,
jintArray
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: deleteCppTensor
...
...
@@ -87,4 +103,4 @@ Java_com_baidu_paddle_lite_Tensor_deleteCppTensor(JNIEnv *, jobject, jlong);
#ifdef __cplusplus
}
#endif
#endif //
PADDLE_FLUID_
LITE_API_ANDROID_JNI_NATIVE_TENSOR_JNI_H_
#endif // LITE_API_ANDROID_JNI_NATIVE_TENSOR_JNI_H_
lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java
浏览文件 @
71aa1b49
...
...
@@ -108,6 +108,19 @@ public class Tensor {
return
nativeSetData
(
buf
);
}
/**
* Set the tensor int data.
*
* @param buf the int array buffer which will be copied into tensor.
* @return true if set data successfully.
*/
public
boolean
setData
(
int
[]
buf
)
{
if
(
readOnly
)
{
return
false
;
}
return
nativeSetData
(
buf
);
}
/**
* @return shape of the tensor as long array.
*/
...
...
@@ -123,12 +136,19 @@ public class Tensor {
*/
public
native
byte
[]
getByteData
();
/**
* @return the tensor data as int array.
*/
public
native
int
[]
getIntData
();
private
native
boolean
nativeResize
(
long
[]
dims
);
private
native
boolean
nativeSetData
(
float
[]
buf
);
private
native
boolean
nativeSetData
(
byte
[]
buf
);
private
native
boolean
nativeSetData
(
int
[]
buf
);
/**
* Delete C++ Tenor object pointed by the input pointer, which is presented by a
* long value.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录