"js/node/package-lock.json" did not exist on "cf1acfd2990a25052481bc7a64b5bbadbbdd3676"
ai_onnxruntime_OnnxMap.c 5.95 KB
Newer Older
gaoqiong's avatar
gaoqiong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
 * Licensed under the MIT License.
 */
#include <jni.h>
#include "onnxruntime/core/session/onnxruntime_c_api.h"
#include "OrtJniUtil.h"
#include "ai_onnxruntime_OnnxMap.h"

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    getStringKeys
 * Signature: (J)[Ljava/lang/String;
 */
JNIEXPORT jobjectArray JNICALL Java_ai_onnxruntime_OnnxMap_getStringKeys(JNIEnv* jniEnv, jobject jobj, jlong apiHandle,
                                                                         jlong handle, jlong allocatorHandle) {
  (void)jobj;  // Required JNI parameter not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  OrtAllocator* allocator = (OrtAllocator*)allocatorHandle;
  // Extract key
  OrtValue* keys;
  OrtErrorCode code = checkOrtStatus(jniEnv, api, api->GetValue((OrtValue*)handle, 0, allocator, &keys));
  if (code == ORT_OK) {
    // Convert to Java String array
    jobjectArray output = createStringArrayFromTensor(jniEnv, api, keys);

    api->ReleaseValue(keys);

    return output;
  } else {
    return NULL;
  }
}

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    getLongKeys
 * Signature: (JJ)[J
 */
JNIEXPORT jlongArray JNICALL Java_ai_onnxruntime_OnnxMap_getLongKeys(JNIEnv* jniEnv, jobject jobj, jlong apiHandle,
                                                                     jlong handle, jlong allocatorHandle) {
  (void)jobj;  // Required JNI parameter not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  OrtAllocator* allocator = (OrtAllocator*)allocatorHandle;
  // Extract key
  OrtValue* keys;
  OrtErrorCode code = checkOrtStatus(jniEnv, api, api->GetValue((OrtValue*)handle, 0, allocator, &keys));
  if (code == ORT_OK) {
    jlongArray output = createLongArrayFromTensor(jniEnv, api, keys);

    api->ReleaseValue(keys);

    return output;
  } else {
    return NULL;
  }
}

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    getStringValues
 * Signature: (JJ)[Ljava/lang/String;
 */
JNIEXPORT jobjectArray JNICALL Java_ai_onnxruntime_OnnxMap_getStringValues(JNIEnv* jniEnv, jobject jobj,
                                                                           jlong apiHandle, jlong handle,
                                                                           jlong allocatorHandle) {
  (void)jobj;  // Required JNI parameter not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  OrtAllocator* allocator = (OrtAllocator*)allocatorHandle;
  // Extract value
  OrtValue* values;
  OrtErrorCode code = checkOrtStatus(jniEnv, api, api->GetValue((OrtValue*)handle, 1, allocator, &values));
  if (code == ORT_OK) {
    // Convert to Java String array
    jobjectArray output = createStringArrayFromTensor(jniEnv, api, values);

    api->ReleaseValue(values);

    return output;
  } else {
    return NULL;
  }
}

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    getLongValues
 * Signature: (JJ)[J
 */
JNIEXPORT jlongArray JNICALL Java_ai_onnxruntime_OnnxMap_getLongValues(JNIEnv* jniEnv, jobject jobj, jlong apiHandle,
                                                                       jlong handle, jlong allocatorHandle) {
  (void)jobj;  // Required JNI parameter not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  OrtAllocator* allocator = (OrtAllocator*)allocatorHandle;
  // Extract value
  OrtValue* values;
  OrtErrorCode code = checkOrtStatus(jniEnv, api, api->GetValue((OrtValue*)handle, 1, allocator, &values));
  if (code == ORT_OK) {
    jlongArray output = createLongArrayFromTensor(jniEnv, api, values);

    api->ReleaseValue(values);

    return output;
  } else {
    return NULL;
  }
}

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    getFloatValues
 * Signature: (JJ)[F
 */
JNIEXPORT jfloatArray JNICALL Java_ai_onnxruntime_OnnxMap_getFloatValues(JNIEnv* jniEnv, jobject jobj, jlong apiHandle,
                                                                         jlong handle, jlong allocatorHandle) {
  (void)jobj;  // Required JNI parameter not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  OrtAllocator* allocator = (OrtAllocator*)allocatorHandle;
  // Extract value
  OrtValue* values;
  OrtErrorCode code = checkOrtStatus(jniEnv, api, api->GetValue((OrtValue*)handle, 1, allocator, &values));
  if (code == ORT_OK) {
    jfloatArray output = createFloatArrayFromTensor(jniEnv, api, values);

    api->ReleaseValue(values);

    return output;
  } else {
    return NULL;
  }
}

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    getDoubleValues
 * Signature: (JJ)[D
 */
JNIEXPORT jdoubleArray JNICALL Java_ai_onnxruntime_OnnxMap_getDoubleValues(JNIEnv* jniEnv, jobject jobj,
                                                                           jlong apiHandle, jlong handle,
                                                                           jlong allocatorHandle) {
  (void)jobj;  // Required JNI parameter not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  OrtAllocator* allocator = (OrtAllocator*)allocatorHandle;
  // Extract value
  OrtValue* values;
  OrtErrorCode code = checkOrtStatus(jniEnv, api, api->GetValue((OrtValue*)handle, 1, allocator, &values));
  if (code == ORT_OK) {
    jdoubleArray output = createDoubleArrayFromTensor(jniEnv, api, values);

    api->ReleaseValue(values);

    return output;
  } else {
    return NULL;
  }
}

/*
 * Class:     ai_onnxruntime_OnnxMap
 * Method:    close
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_ai_onnxruntime_OnnxMap_close(JNIEnv* jniEnv, jobject jobj, jlong apiHandle, jlong handle) {
  (void)jniEnv; (void)jobj;  // Required JNI parameters not used by functions which don't access their host object.
  const OrtApi* api = (const OrtApi*)apiHandle;
  api->ReleaseValue((OrtValue*)handle);
}