Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
abd8b1ea
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
abd8b1ea
编写于
6月 07, 2020
作者:
Z
zhupengyang
提交者:
GitHub
6月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add java api: getLongData (#3750)
上级
1c415218
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
6 deletion
+68
-6
lite/api/android/jni/native/convert_util_jni.h
lite/api/android/jni/native/convert_util_jni.h
+14
-6
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
+16
-0
lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java
lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java
+7
-0
lite/utils/io.h
lite/utils/io.h
+1
-0
未找到文件。
lite/api/android/jni/native/convert_util_jni.h
浏览文件 @
abd8b1ea
...
...
@@ -14,8 +14,8 @@ limitations under the License. */
#pragma once
#include <jni.h>
#include <string>
#include <vector>
#include <string>
// NOLINT
#include <vector>
// NOLINT
#include "lite/api/light_api.h"
#include "lite/api/paddle_api.h"
...
...
@@ -78,6 +78,14 @@ inline jfloatArray cpp_array_to_jfloatarray(JNIEnv *env,
return
result
;
}
inline
jbyteArray
cpp_array_to_jbytearray
(
JNIEnv
*
env
,
const
int8_t
*
buf
,
int64_t
len
)
{
jbyteArray
result
=
env
->
NewByteArray
(
len
);
env
->
SetByteArrayRegion
(
result
,
0
,
len
,
buf
);
return
result
;
}
inline
jintArray
cpp_array_to_jintarray
(
JNIEnv
*
env
,
const
int
*
buf
,
int64_t
len
)
{
...
...
@@ -86,11 +94,11 @@ inline jintArray cpp_array_to_jintarray(JNIEnv *env,
return
result
;
}
inline
j
byteArray
cpp_array_to_jbyte
array
(
JNIEnv
*
env
,
const
int
8
_t
*
buf
,
inline
j
longArray
cpp_array_to_jlong
array
(
JNIEnv
*
env
,
const
int
64
_t
*
buf
,
int64_t
len
)
{
j
byteArray
result
=
env
->
NewByte
Array
(
len
);
env
->
Set
Byte
ArrayRegion
(
result
,
0
,
len
,
buf
);
j
longArray
result
=
env
->
NewLong
Array
(
len
);
env
->
Set
Long
ArrayRegion
(
result
,
0
,
len
,
buf
);
return
result
;
}
...
...
lite/api/android/jni/native/tensor_jni.cc
浏览文件 @
abd8b1ea
...
...
@@ -136,6 +136,22 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_lite_Tensor_nativeSetData___3I(
return
JNI_TRUE
;
}
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_nativeSetData___3L
(
JNIEnv
*
env
,
jobject
jtensor
,
jlongArray
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
;
}
int64_t
*
input
=
(
*
tensor
)
->
mutable_data
<
int64_t
>
();
env
->
GetLongArrayRegion
(
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
))
{
...
...
@@ -178,6 +194,20 @@ Java_com_baidu_paddle_lite_Tensor_getIntData(JNIEnv *env, jobject jtensor) {
}
}
JNIEXPORT
jlongArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getLongData
(
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_jlongarray
(
env
,
(
*
tensor
)
->
data
<
int64_t
>
(),
product
((
*
tensor
)
->
shape
()));
}
else
{
std
::
unique_ptr
<
Tensor
>
*
tensor
=
get_writable_tensor_pointer
(
env
,
jtensor
);
return
cpp_array_to_jlongarray
(
env
,
(
*
tensor
)
->
data
<
int64_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
浏览文件 @
abd8b1ea
...
...
@@ -57,6 +57,14 @@ Java_com_baidu_paddle_lite_Tensor_getByteData(JNIEnv *, jobject);
JNIEXPORT
jintArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getIntData
(
JNIEnv
*
,
jobject
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: getLongData
* Signature: ()[L
*/
JNIEXPORT
jlongArray
JNICALL
Java_com_baidu_paddle_lite_Tensor_getLongData
(
JNIEnv
*
,
jobject
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: nativeResize
...
...
@@ -89,6 +97,14 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_lite_Tensor_nativeSetData___3B(
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_nativeSetData___3I
(
JNIEnv
*
,
jobject
,
jintArray
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: nativeSetData
* Signature: ([L)Z
*/
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_Tensor_nativeSetData___3L
(
JNIEnv
*
,
jobject
,
jlongArray
);
/*
* Class: com_baidu_paddle_lite_Tensor
* Method: deleteCppTensor
...
...
lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java
浏览文件 @
abd8b1ea
...
...
@@ -141,6 +141,11 @@ public class Tensor {
*/
public
native
int
[]
getIntData
();
/**
* @return the tensor data as long array.
*/
public
native
long
[]
getLongData
();
private
native
boolean
nativeResize
(
long
[]
dims
);
private
native
boolean
nativeSetData
(
float
[]
buf
);
...
...
@@ -149,6 +154,8 @@ public class Tensor {
private
native
boolean
nativeSetData
(
int
[]
buf
);
private
native
boolean
nativeSetData
(
long
[]
buf
);
/**
* Delete C++ Tenor object pointed by the input pointer, which is presented by a
* long value.
...
...
lite/utils/io.h
浏览文件 @
abd8b1ea
...
...
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "lite/utils/cp_logging.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录