Added function to also expose params
This commit is contained in:
parent
a04dabc22c
commit
d801793286
3 changed files with 121 additions and 12 deletions
|
|
@ -88,4 +88,27 @@ Java_com_ethicalml_kompute_KomputeJni_kompute(
|
|||
|
||||
return vectorToJFloatArray(env, pred);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloatArray JNICALL
|
||||
Java_com_ethicalml_kompute_KomputeJni_komputeParams(
|
||||
JNIEnv *env,
|
||||
jobject thiz,
|
||||
jfloatArray xiJFloatArr,
|
||||
jfloatArray xjJFloatArr,
|
||||
jfloatArray yJFloatArr) {
|
||||
|
||||
SPDLOG_INFO("Creating manager");
|
||||
|
||||
std::vector<float> xiVector = jfloatArrayToVector(env, xiJFloatArr);
|
||||
std::vector<float> xjVector = jfloatArrayToVector(env, xjJFloatArr);
|
||||
std::vector<float> yVector = jfloatArrayToVector(env, yJFloatArr);
|
||||
|
||||
KomputeModelML kml;
|
||||
kml.train(yVector, xiVector, xjVector);
|
||||
|
||||
std::vector<float> params = kml.get_params();
|
||||
|
||||
return vectorToJFloatArray(env, params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class KomputeJni : AppCompatActivity() {
|
|||
}
|
||||
Log.i("KomputeJni", "Vulkan Result: " + successVulkanInit)
|
||||
|
||||
binding.komputeJniTextview.text = "N/A"
|
||||
binding.predictionTextView.text = "N/A"
|
||||
}
|
||||
|
||||
fun KomputeButtonOnClick(v: View) {
|
||||
|
|
@ -54,7 +54,12 @@ class KomputeJni : AppCompatActivity() {
|
|||
val xiEditText = findViewById<EditText>(R.id.XIEditText)
|
||||
val xjEditText = findViewById<EditText>(R.id.XJEditText)
|
||||
val yEditText = findViewById<EditText>(R.id.YEditText)
|
||||
val komputeJniTextview = findViewById<TextView>(R.id.kompute_jni_textview)
|
||||
|
||||
val wOneEditText = findViewById<TextView>(R.id.wOneTextView)
|
||||
val wTwoEditText = findViewById<TextView>(R.id.wTwoTextView)
|
||||
val biasEditText = findViewById<TextView>(R.id.biasTextView)
|
||||
|
||||
val komputeJniTextview = findViewById<TextView>(R.id.predictionTextView)
|
||||
|
||||
val xi = xiEditText.text.removeSurrounding("[", "]").split(",").map { it.toFloat() }.toFloatArray()
|
||||
val xj = xjEditText.text.removeSurrounding("[", "]").split(",").map { it.toFloat() }.toFloatArray()
|
||||
|
|
@ -66,12 +71,23 @@ class KomputeJni : AppCompatActivity() {
|
|||
Log.i("KomputeJni", out.contentToString())
|
||||
|
||||
komputeJniTextview.text = out.contentToString()
|
||||
|
||||
val params = komputeParams(xi, xj, y)
|
||||
|
||||
Log.i("KomputeJni", "Params:")
|
||||
Log.i("KomputeJni", params.contentToString())
|
||||
|
||||
wOneEditText.text = params[0].toString()
|
||||
wTwoEditText.text = params[1].toString()
|
||||
biasEditText.text = params[2].toString()
|
||||
}
|
||||
|
||||
external fun initVulkan(): Boolean
|
||||
|
||||
external fun kompute(xi: FloatArray, xj: FloatArray, y: FloatArray): FloatArray
|
||||
|
||||
external fun komputeParams(xi: FloatArray, xj: FloatArray, y: FloatArray): FloatArray
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("kompute-jni")
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="409dp"
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/KomputeButton"
|
||||
|
|
@ -137,11 +137,79 @@
|
|||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="W 1: "
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/wOneTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="N/A"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Space
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="W 2: "
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/wTwoTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="N/A"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Space
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="B : "
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/biasTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="N/A"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="30dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
|
|
@ -152,11 +220,13 @@
|
|||
android:textSize="24sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/kompute_jni_textview"
|
||||
android:id="@+id/predictionTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Input Xi"
|
||||
android:textSize="24sp" />
|
||||
android:layout_weight="1"
|
||||
android:text="TextView"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue