package com.facebook.appevents.ml; import androidx.annotation.RestrictTo; import com.facebook.appevents.ml.ModelManager; import com.facebook.internal.instrument.crashshield.CrashShieldHandler; import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.Set; import kotlin.TuplesKt; import kotlin.collections.MapsKt__MapsKt; import kotlin.collections.SetsKt__SetsKt; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) /* loaded from: classes2.dex */ public final class Model { public static final Companion Companion = new Companion(null); private static final int SEQ_LEN = 128; private static final Map mapping; private final MTensor convs0Bias; private final MTensor convs0Weight; private final MTensor convs1Bias; private final MTensor convs1Weight; private final MTensor convs2Bias; private final MTensor convs2Weight; private final MTensor embedding; private final MTensor fc1Bias; private final MTensor fc1Weight; private final MTensor fc2Bias; private final MTensor fc2Weight; private final Map finalWeights; public /* synthetic */ Model(Map map, DefaultConstructorMarker defaultConstructorMarker) { this(map); } private Model(Map map) { Set of; MTensor mTensor = map.get("embed.weight"); if (mTensor == null) { throw new IllegalStateException("Required value was null.".toString()); } this.embedding = mTensor; Operator operator = Operator.INSTANCE; MTensor mTensor2 = map.get("convs.0.weight"); if (mTensor2 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.convs0Weight = Operator.transpose3D(mTensor2); MTensor mTensor3 = map.get("convs.1.weight"); if (mTensor3 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.convs1Weight = Operator.transpose3D(mTensor3); MTensor mTensor4 = map.get("convs.2.weight"); if (mTensor4 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.convs2Weight = Operator.transpose3D(mTensor4); MTensor mTensor5 = map.get("convs.0.bias"); if (mTensor5 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.convs0Bias = mTensor5; MTensor mTensor6 = map.get("convs.1.bias"); if (mTensor6 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.convs1Bias = mTensor6; MTensor mTensor7 = map.get("convs.2.bias"); if (mTensor7 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.convs2Bias = mTensor7; MTensor mTensor8 = map.get("fc1.weight"); if (mTensor8 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.fc1Weight = Operator.transpose2D(mTensor8); MTensor mTensor9 = map.get("fc2.weight"); if (mTensor9 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.fc2Weight = Operator.transpose2D(mTensor9); MTensor mTensor10 = map.get("fc1.bias"); if (mTensor10 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.fc1Bias = mTensor10; MTensor mTensor11 = map.get("fc2.bias"); if (mTensor11 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.fc2Bias = mTensor11; this.finalWeights = new HashMap(); of = SetsKt__SetsKt.setOf((Object[]) new String[]{ModelManager.Task.MTML_INTEGRITY_DETECT.toKey(), ModelManager.Task.MTML_APP_EVENT_PREDICTION.toKey()}); for (String str : of) { String stringPlus = Intrinsics.stringPlus(str, ".weight"); String stringPlus2 = Intrinsics.stringPlus(str, ".bias"); MTensor mTensor12 = map.get(stringPlus); MTensor mTensor13 = map.get(stringPlus2); if (mTensor12 != null) { this.finalWeights.put(stringPlus, Operator.transpose2D(mTensor12)); } if (mTensor13 != null) { this.finalWeights.put(stringPlus2, mTensor13); } } } public static final /* synthetic */ Map access$getMapping$cp() { if (CrashShieldHandler.isObjectCrashing(Model.class)) { return null; } try { return mapping; } catch (Throwable th) { CrashShieldHandler.handleThrowable(th, Model.class); return null; } } public final MTensor predictOnMTML(MTensor dense, String[] texts, String task) { if (CrashShieldHandler.isObjectCrashing(this)) { return null; } try { Intrinsics.checkNotNullParameter(dense, "dense"); Intrinsics.checkNotNullParameter(texts, "texts"); Intrinsics.checkNotNullParameter(task, "task"); Operator operator = Operator.INSTANCE; MTensor conv1D = Operator.conv1D(Operator.embedding(texts, 128, this.embedding), this.convs0Weight); Operator.addmv(conv1D, this.convs0Bias); Operator.relu(conv1D); MTensor conv1D2 = Operator.conv1D(conv1D, this.convs1Weight); Operator.addmv(conv1D2, this.convs1Bias); Operator.relu(conv1D2); MTensor maxPool1D = Operator.maxPool1D(conv1D2, 2); MTensor conv1D3 = Operator.conv1D(maxPool1D, this.convs2Weight); Operator.addmv(conv1D3, this.convs2Bias); Operator.relu(conv1D3); MTensor maxPool1D2 = Operator.maxPool1D(conv1D, conv1D.getShape(1)); MTensor maxPool1D3 = Operator.maxPool1D(maxPool1D, maxPool1D.getShape(1)); MTensor maxPool1D4 = Operator.maxPool1D(conv1D3, conv1D3.getShape(1)); Operator.flatten(maxPool1D2, 1); Operator.flatten(maxPool1D3, 1); Operator.flatten(maxPool1D4, 1); MTensor dense2 = Operator.dense(Operator.concatenate(new MTensor[]{maxPool1D2, maxPool1D3, maxPool1D4, dense}), this.fc1Weight, this.fc1Bias); Operator.relu(dense2); MTensor dense3 = Operator.dense(dense2, this.fc2Weight, this.fc2Bias); Operator.relu(dense3); MTensor mTensor = this.finalWeights.get(Intrinsics.stringPlus(task, ".weight")); MTensor mTensor2 = this.finalWeights.get(Intrinsics.stringPlus(task, ".bias")); if (mTensor != null && mTensor2 != null) { MTensor dense4 = Operator.dense(dense3, mTensor, mTensor2); Operator.softmax(dense4); return dense4; } return null; } catch (Throwable th) { CrashShieldHandler.handleThrowable(th, this); return null; } } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } public final Model build(File file) { Intrinsics.checkNotNullParameter(file, "file"); Map parse = parse(file); DefaultConstructorMarker defaultConstructorMarker = null; if (parse == null) { return null; } try { return new Model(parse, defaultConstructorMarker); } catch (Exception unused) { return null; } } private final Map parse(File file) { Map parseModelWeights = Utils.parseModelWeights(file); if (parseModelWeights == null) { return null; } HashMap hashMap = new HashMap(); Map access$getMapping$cp = Model.access$getMapping$cp(); for (Map.Entry entry : parseModelWeights.entrySet()) { String key = entry.getKey(); if (access$getMapping$cp.containsKey(entry.getKey()) && (key = (String) access$getMapping$cp.get(entry.getKey())) == null) { return null; } hashMap.put(key, entry.getValue()); } return hashMap; } } static { HashMap hashMapOf; hashMapOf = MapsKt__MapsKt.hashMapOf(TuplesKt.to("embedding.weight", "embed.weight"), TuplesKt.to("dense1.weight", "fc1.weight"), TuplesKt.to("dense2.weight", "fc2.weight"), TuplesKt.to("dense3.weight", "fc3.weight"), TuplesKt.to("dense1.bias", "fc1.bias"), TuplesKt.to("dense2.bias", "fc2.bias"), TuplesKt.to("dense3.bias", "fc3.bias")); mapping = hashMapOf; } }