forked from openvinotoolkit/openvino_contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JAVA_API] Wrapper for ov::PartialShape (openvinotoolkit#883)
* Get partial shape from output * Update PartialShape getDimension to align with C++ API * Use pointer arithmetic to access Partial Shape dimension Co-authored-by: Nesterov Alexander <[email protected]> * Remove redundant delete method * Revert "Use pointer arithmetic to access Partial Shape dimension" --------- Co-authored-by: Nesterov Alexander <[email protected]> Co-authored-by: Anna Likholat <[email protected]>
- Loading branch information
1 parent
ec67eed
commit 66557de
Showing
8 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2020-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <jni.h> // JNI header provided by JDK | ||
#include "openvino/openvino.hpp" | ||
|
||
#include "openvino_java.hpp" | ||
#include "jni_common.hpp" | ||
|
||
using namespace ov; | ||
|
||
JNIEXPORT jlong JNICALL Java_org_intel_openvino_PartialShape_GetDimension(JNIEnv *env, jobject obj, jlong addr, jint index) { | ||
JNI_METHOD("GetDimension", | ||
PartialShape* partial_shape = (PartialShape *)addr; | ||
return (jlong) &(*partial_shape)[index]; | ||
) | ||
return 0; | ||
} | ||
|
||
JNIEXPORT jintArray JNICALL Java_org_intel_openvino_PartialShape_GetMaxShape(JNIEnv *env, jobject obj, jlong addr) { | ||
JNI_METHOD("GetMaxShape", | ||
PartialShape* partial_shape = (PartialShape *)addr; | ||
Shape max_shape = partial_shape->get_max_shape(); | ||
|
||
jintArray result = env->NewIntArray(max_shape.size()); | ||
if (!result) { | ||
throw std::runtime_error("Out of memory!"); | ||
} jint *arr = env->GetIntArrayElements(result, nullptr); | ||
|
||
for (int i = 0; i < max_shape.size(); ++i) | ||
arr[i] = max_shape[i]; | ||
|
||
env->ReleaseIntArrayElements(result, arr, 0); | ||
return result; | ||
) | ||
return 0; | ||
} | ||
|
||
JNIEXPORT jintArray JNICALL Java_org_intel_openvino_PartialShape_GetMinShape(JNIEnv *env, jobject obj, jlong addr) { | ||
JNI_METHOD("GetMinShape", | ||
PartialShape* partial_shape = (PartialShape *)addr; | ||
Shape min_shape = partial_shape->get_min_shape(); | ||
|
||
jintArray result = env->NewIntArray(min_shape.size()); | ||
if (!result) { | ||
throw std::runtime_error("Out of memory!"); | ||
} jint *arr = env->GetIntArrayElements(result, nullptr); | ||
|
||
for (int i = 0; i < min_shape.size(); ++i) | ||
arr[i] = min_shape[i]; | ||
|
||
env->ReleaseIntArrayElements(result, arr, 0); | ||
return result; | ||
) | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
modules/java_api/src/main/java/org/intel/openvino/PartialShape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) 2020-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.intel.openvino; | ||
|
||
/** This class represents the definitions and operations about partial shape. */ | ||
public class PartialShape extends Wrapper { | ||
|
||
public PartialShape(long addr) { | ||
super(addr); | ||
} | ||
|
||
/** | ||
* Get the dimension at specified index of a partial shape. | ||
* | ||
* @param index The index of dimension. | ||
* @return The particular dimension of partial shape. | ||
*/ | ||
public Dimension get_dimension(int index) { | ||
return new Dimension(GetDimension(nativeObj, index)); | ||
} | ||
|
||
/** Returns the max bounding shape. */ | ||
public int[] get_max_shape() { | ||
return GetMaxShape(nativeObj); | ||
} | ||
|
||
/** Returns the min bounding shape. */ | ||
public int[] get_min_shape() { | ||
return GetMinShape(nativeObj); | ||
} | ||
|
||
/*----------------------------------- native methods -----------------------------------*/ | ||
private static native long GetDimension(long addr, int index); | ||
|
||
private static native int[] GetMaxShape(long addr); | ||
|
||
private static native int[] GetMinShape(long addr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters