Ich brauche Matrix-Operationen in Android auszuführen, so dass ich über die render gesucht, und ich habe useful information hereVerwenden von RenderScript Intrinsic BLAS Matrix Operationen in Android durchführen, aber ich habe ein falsches Ergebnis?
ich das Programm in der Antwort oben wie folgt versucht:
private void compute(){
mRs = RenderScript.create(this);
Type.Builder builder = new Type.Builder(mRs, Element.U8(mRs));
Type a_type = builder.setX(3).setY(2).create();
Type b_type = builder.setX(3).setY(2).create();
Type c_type = builder.setX(2).setY(2).create();
Allocation A = Allocation.createTyped(mRs, a_type);
Allocation B = Allocation.createTyped(mRs, b_type);
Allocation C = Allocation.createTyped(mRs, c_type);
A.copyFrom(new byte[]{1, 2, 3, 1, 2, 3});
B.copyFrom(new byte[]{1, 1, 1, 0, 1, 0});
ScriptIntrinsicBLAS BLAS = ScriptIntrinsicBLAS.create(mRs);
BLAS.BNNM(A, 0, B, 0, C, 0, 1);
byte[] result = new byte[]{1,2,3,4};
C.copyTo(result);
for(int i = 0; i < result.length; ++i){
Log.i(TAG, i + " " + result[i]);
}
}
Meine gradle Datei wie folgt ist folgende:
targetSdkVersion 25
renderscriptTargetApi 25
renderscriptSupportModeEnabled true
renderscriptSupportModeBlasEnabled true
Aber ich habe die falschen Ergebnisse, die alle Elemente in der Matrix C gleich Null ist:
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 0 0
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 1 0
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 2 0
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 3 0
Jemand weiß, wie man das löst?
Außerdem habe ich gerade festgestellt, dass es scheint, dass die Begrenzung der Dimensionen der Matrix, die mit ScriptIntrinsicBLAS behandelt werden kann, zu sein scheint? here is a question about this Wer kennt diese Einschränkung? Wenn die Beschränkung echt ist, muss ich leider eine andere Möglichkeit finden, die Matrixoperation auf Android zu handhaben.
Sie können nicht 3x2 mit einem anderen 3x2 multiplizieren, 2. Matrix muss 2x3 sein. – sakridge
@sakridge Vielen Dank für Ihre Antwort. Aber die Funktion BNNM führt eine Matrixoperation wie folgt aus: C = A * Transpose (B), [API-Dokument hier] (https://developer.android.com/reference/android/renderscript/ScriptIntrinsicBLAS.html). Die Dimensionen jeder Matrix sind also korrekt. Andernfalls wird eine Ausnahme ausgelöst, wenn die Operation nicht ausgeführt werden kann. – Yuan