what-the-bank/sources/o/C15516gsl.java

207 lines
8.4 KiB
Java

package o;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.tensorflow.lite.NativeInterpreterWrapper;
import org.tensorflow.lite.Tensor;
/* renamed from: o.gsl, reason: case insensitive filesystem */
/* loaded from: classes6.dex */
public final class C15516gsl implements AutoCloseable {
private NativeInterpreterWrapper c;
/* renamed from: o.gsl$HBt */
/* loaded from: classes6.dex */
public static class HBt {
public int c = -1;
public boolean d = false;
public boolean b = false;
}
public C15516gsl(File file) {
this(file, (byte) 0);
}
private C15516gsl(File file, byte b) {
this.c = new NativeInterpreterWrapper(file.getAbsolutePath());
}
@Deprecated
public C15516gsl(MappedByteBuffer mappedByteBuffer) {
this((ByteBuffer) mappedByteBuffer);
}
private C15516gsl(ByteBuffer byteBuffer) {
this.c = new NativeInterpreterWrapper(byteBuffer);
}
public final void d(Object[] objArr, Map<Integer, Object> map) {
NativeInterpreterWrapper nativeInterpreterWrapper = this.c;
if (nativeInterpreterWrapper != null) {
nativeInterpreterWrapper.b = -1L;
if (objArr == null || objArr.length == 0) {
throw new IllegalArgumentException("Input error: Inputs should not be null or empty.");
}
if (map == null || map.isEmpty()) {
throw new IllegalArgumentException("Input error: Outputs should not be null or empty.");
}
int i = 0;
for (int i2 = 0; i2 < objArr.length; i2++) {
Tensor a = nativeInterpreterWrapper.a(i2);
Object obj = objArr[i2];
int[] iArr = null;
if (!Tensor.a(obj)) {
int[] d = Tensor.d(obj);
if (!Arrays.equals(a.b, d)) {
iArr = d;
}
}
if (iArr != null) {
nativeInterpreterWrapper.b(i2, iArr);
}
}
boolean z = !nativeInterpreterWrapper.a;
if (z) {
NativeInterpreterWrapper.allocateTensors(nativeInterpreterWrapper.c, nativeInterpreterWrapper.e);
nativeInterpreterWrapper.a = true;
}
for (int i3 = 0; i3 < objArr.length; i3++) {
Tensor a2 = nativeInterpreterWrapper.a(i3);
Object obj2 = objArr[i3];
a2.e(obj2);
if (Tensor.a(obj2)) {
ByteBuffer byteBuffer = (ByteBuffer) obj2;
if (byteBuffer.isDirect() && byteBuffer.order() == ByteOrder.nativeOrder()) {
Tensor.writeDirectBuffer(a2.d, byteBuffer);
} else {
Tensor.buffer(a2.d).order(ByteOrder.nativeOrder()).put(byteBuffer);
}
} else {
Tensor.writeMultiDimensionalArray(a2.d, obj2);
}
}
long nanoTime = System.nanoTime();
NativeInterpreterWrapper.run(nativeInterpreterWrapper.c, nativeInterpreterWrapper.e);
long nanoTime2 = System.nanoTime();
if (z) {
while (true) {
Tensor[] tensorArr = nativeInterpreterWrapper.j;
if (i >= tensorArr.length) {
break;
}
Tensor tensor = tensorArr[i];
if (tensor != null) {
tensor.b = Tensor.shape(tensor.d);
}
i++;
}
}
for (Map.Entry<Integer, Object> entry : map.entrySet()) {
int intValue = entry.getKey().intValue();
if (intValue >= 0) {
Tensor[] tensorArr2 = nativeInterpreterWrapper.j;
if (intValue < tensorArr2.length) {
Tensor tensor2 = tensorArr2[intValue];
if (tensor2 == null) {
long j = nativeInterpreterWrapper.c;
tensor2 = Tensor.b(j, NativeInterpreterWrapper.getOutputTensorIndex(j, intValue));
tensorArr2[intValue] = tensor2;
}
Object value = entry.getValue();
tensor2.e(value);
if (value instanceof ByteBuffer) {
((ByteBuffer) value).put(Tensor.buffer(tensor2.d).order(ByteOrder.nativeOrder()));
} else {
Tensor.readMultiDimensionalArray(tensor2.d, value);
}
}
}
throw new IllegalArgumentException("Invalid output Tensor index: ".concat(String.valueOf(intValue)));
}
nativeInterpreterWrapper.b = nanoTime2 - nanoTime;
return;
}
throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
}
public final void b(int i, int[] iArr) {
NativeInterpreterWrapper nativeInterpreterWrapper = this.c;
if (nativeInterpreterWrapper != null) {
nativeInterpreterWrapper.b(i, iArr);
return;
}
throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
}
public final int d(String str) {
NativeInterpreterWrapper nativeInterpreterWrapper = this.c;
if (nativeInterpreterWrapper != null) {
if (nativeInterpreterWrapper.d == null) {
String[] inputNames = NativeInterpreterWrapper.getInputNames(nativeInterpreterWrapper.c);
nativeInterpreterWrapper.d = new HashMap();
if (inputNames != null) {
for (int i = 0; i < inputNames.length; i++) {
nativeInterpreterWrapper.d.put(inputNames[i], Integer.valueOf(i));
}
}
}
if (nativeInterpreterWrapper.d.containsKey(str)) {
return nativeInterpreterWrapper.d.get(str).intValue();
}
throw new IllegalArgumentException(String.format("Input error: '%s' is not a valid name for any input. Names of inputs and their indexes are %s", str, nativeInterpreterWrapper.d.toString()));
}
throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
}
public final int a(String str) {
NativeInterpreterWrapper nativeInterpreterWrapper = this.c;
if (nativeInterpreterWrapper != null) {
if (nativeInterpreterWrapper.h == null) {
String[] outputNames = NativeInterpreterWrapper.getOutputNames(nativeInterpreterWrapper.c);
nativeInterpreterWrapper.h = new HashMap();
if (outputNames != null) {
for (int i = 0; i < outputNames.length; i++) {
nativeInterpreterWrapper.h.put(outputNames[i], Integer.valueOf(i));
}
}
}
if (nativeInterpreterWrapper.h.containsKey(str)) {
return nativeInterpreterWrapper.h.get(str).intValue();
}
throw new IllegalArgumentException(String.format("Input error: '%s' is not a valid name for any output. Names of outputs and their indexes are %s", str, nativeInterpreterWrapper.h.toString()));
}
throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
}
@Deprecated
public final void b(boolean z) {
NativeInterpreterWrapper nativeInterpreterWrapper = this.c;
if (nativeInterpreterWrapper == null) {
throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
}
NativeInterpreterWrapper.useNNAPI(nativeInterpreterWrapper.c, z);
}
@Override // java.lang.AutoCloseable
public final void close() {
NativeInterpreterWrapper nativeInterpreterWrapper = this.c;
if (nativeInterpreterWrapper != null) {
nativeInterpreterWrapper.close();
this.c = null;
}
}
protected final void finalize() throws Throwable {
try {
close();
} finally {
super.finalize();
}
}
}