List of usage examples for com.google.common.primitives Ints indexOf
public static int indexOf(int[] array, int[] target)
From source file:org.mb459.easy.premca.sim.ctrnn.GMCTRNN.java
@Override public void EulerStep(float stepSize, int[] inputs) { for (int i = 0; i < n; i++) { float input; int sensInd = sensNeurIndices.indexOf(i); if (sensInd != -1) input = inputs[sensInd];/*from w w w.j a v a2 s. com*/ else { int predInd = Ints.indexOf(predPair1, i); if (predInd != -1) { float predError = (outputs[predPair1[predInd]] - outputs[predPair2[predInd]]); input = predError; } else input = 0; } for (int j = 0; j < n; j++) input += weights[j][i] * outputs[j]; states[i] += stepSize * taus[i] * (input - states[i]); outputs[i] = sigmoid(gains[i] * (states[i] + biases[i])); } }
From source file:suneido.database.immudb.ReadWriteTransaction.java
void updateAll(int tblnum, int[] colNums, Record oldkey, Record newkey) { IndexIter iter = getIndex(tblnum, colNums).iterator(oldkey); for (iter.next(); !iter.eof(); iter.next()) { Record oldrec = input(iter.keyadr()); RecordBuilder rb = new RecordBuilder(); for (int i = 0; i < oldrec.size(); ++i) { int j = Ints.indexOf(colNums, i); rb.add(j == -1 ? oldrec.get(i) : newkey.get(j)); }/*from w w w . jav a 2 s . co m*/ updateRecord(tblnum, oldrec, rb.build(), Blocking.NO_BLOCK); } }
From source file:suneido.database.immudb.UpdateTransaction.java
@Override void updateAll(int tblnum, int[] colNums, Record oldkey, Record newkey) { Index index = index(tblnum, colNums); IndexIter iter = getIndex(index).iterator(oldkey); trackReads(index, iter);/*from ww w . ja va 2 s . co m*/ for (iter.next(); !iter.eof(); iter.next()) { Record oldrec = input(iter.keyadr()); RecordBuilder rb = new RecordBuilder(); for (int i = 0; i < oldrec.size(); ++i) { int j = Ints.indexOf(colNums, i); rb.add(j == -1 ? oldrec.get(i) : newkey.get(j)); } updateRecord(tblnum, oldrec, rb.build(), Blocking.NO_BLOCK); } }
From source file:edu.mit.streamjit.impl.compiler2.CompositionAllocationStrategy.java
@Override public void allocateGroup(ActorGroup group, Range<Integer> iterations, List<Core> cores, Configuration config) { if (group.isStateful()) { int minStatefulId = Integer.MAX_VALUE; for (Actor a : group.actors()) if (a instanceof WorkerActor && ((WorkerActor) a).archetype().isStateful()) minStatefulId = Math.min(minStatefulId, a.id()); Configuration.SwitchParameter<Integer> param = config.getParameter("Group" + minStatefulId + "Core", Configuration.SwitchParameter.class, Integer.class); cores.get(param.getValue() % cores.size()).allocate(group, iterations); return;//from w w w .j a v a 2 s .c o m } Configuration.CompositionParameter param = config.getParameter("Group" + group.id() + "Cores", Configuration.CompositionParameter.class); assert iterations.lowerBoundType() == BoundType.CLOSED && iterations.upperBoundType() == BoundType.OPEN; int totalAvailable = iterations.upperEndpoint() - iterations.lowerEndpoint(); int[] allocations = new int[cores.size()]; int totalAllocated = 0; for (int i = 0; i < param.getLength() && i < allocations.length; ++i) { int allocation = DoubleMath.roundToInt(param.getValue(i) * totalAvailable, RoundingMode.HALF_EVEN); allocations[i] = allocation; totalAllocated += allocation; } //If we allocated more than we have, remove from the cores with the least. //Need a loop here because we might not have enough on the least core. while (totalAllocated > totalAvailable) { int least = Ints.indexOf(allocations, Ints.max(allocations)); for (int i = 0; i < allocations.length; ++i) if (allocations[i] > 0 && allocations[i] < allocations[least]) least = i; int toRemove = Math.min(allocations[least], totalAllocated - totalAvailable); allocations[least] -= toRemove; totalAllocated -= toRemove; } //If we didn't allocate enough, allocate on the cores with the most. if (totalAllocated < totalAvailable) { int most = Ints.indexOf(allocations, Ints.min(allocations)); for (int i = 0; i < allocations.length; ++i) if (allocations[i] > allocations[most]) most = i; allocations[most] += totalAvailable - totalAllocated; totalAllocated += totalAvailable - totalAllocated; } assert totalAllocated == totalAvailable : totalAllocated + " " + totalAvailable; int lower = iterations.lowerEndpoint(); for (int i = 0; i < allocations.length; ++i) if (allocations[i] > 0) { cores.get(i).allocate(group, Range.closedOpen(lower, lower + allocations[i])); lower += allocations[i]; } }
From source file:org.hyperledger.fabric.sdk.idemix.IdemixSignature.java
/** * Create a new IdemixSignature by proving knowledge of a credential * * @param c the credential used to create an idemix signature * @param sk the signer's secret key * @param pseudonym a pseudonym of the signer * @param ipk the issuer public key * @param disclosure a bool-array that steers the disclosure of attributes * @param msg the message to be signed * @param rhIndex the index of the attribute that represents the revocation handle * @param cri the credential revocation information that allows the signer to prove non-revocation *///from www. j a va 2 s . c om public IdemixSignature(IdemixCredential c, BIG sk, IdemixPseudonym pseudonym, IdemixIssuerPublicKey ipk, boolean[] disclosure, byte[] msg, int rhIndex, Idemix.CredentialRevocationInformation cri) { if (c == null || sk == null || pseudonym == null || pseudonym.getNym() == null || pseudonym.getRandNym() == null || ipk == null || disclosure == null || msg == null || cri == null) { throw new IllegalArgumentException("Cannot construct idemix signature from null input"); } if (disclosure.length != c.getAttrs().length) { throw new IllegalArgumentException("Disclosure length must be the same as the number of attributes"); } if (cri.getRevocationAlg() >= RevocationAlgorithm.values().length) { throw new IllegalArgumentException("CRI specifies unknown revocation algorithm"); } if (cri.getRevocationAlg() != RevocationAlgorithm.ALG_NO_REVOCATION.ordinal() && disclosure[rhIndex]) { throw new IllegalArgumentException("Attribute " + rhIndex + " is disclosed but also used a revocation handle attribute, which should remain hidden"); } RevocationAlgorithm revocationAlgorithm = RevocationAlgorithm.values()[cri.getRevocationAlg()]; int[] hiddenIndices = hiddenIndices(disclosure); final RAND rng = IdemixUtils.getRand(); // Start signature BIG r1 = IdemixUtils.randModOrder(rng); BIG r2 = IdemixUtils.randModOrder(rng); BIG r3 = new BIG(r1); r3.invmodp(IdemixUtils.GROUP_ORDER); nonce = IdemixUtils.randModOrder(rng); aPrime = PAIR.G1mul(c.getA(), r1); aBar = PAIR.G1mul(c.getB(), r1); aBar.sub(PAIR.G1mul(aPrime, c.getE())); bPrime = PAIR.G1mul(c.getB(), r1); bPrime.sub(PAIR.G1mul(ipk.getHRand(), r2)); BIG sPrime = new BIG(c.getS()); sPrime.add(BIG.modneg(BIG.modmul(r2, r3, IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER)); sPrime.mod(IdemixUtils.GROUP_ORDER); //Construct Zero Knowledge Proof BIG rsk = IdemixUtils.randModOrder(rng); BIG re = IdemixUtils.randModOrder(rng); BIG rR2 = IdemixUtils.randModOrder(rng); BIG rR3 = IdemixUtils.randModOrder(rng); BIG rSPrime = IdemixUtils.randModOrder(rng); BIG rRNym = IdemixUtils.randModOrder(rng); BIG[] rAttrs = new BIG[hiddenIndices.length]; for (int i = 0; i < hiddenIndices.length; i++) { rAttrs[i] = IdemixUtils.randModOrder(rng); } // Compute non-revoked proof NonRevocationProver prover = NonRevocationProver.getNonRevocationProver(revocationAlgorithm); int hiddenRHIndex = Ints.indexOf(hiddenIndices, rhIndex); if (hiddenRHIndex < 0) { // rhIndex is not present, set to last index position hiddenRHIndex = hiddenIndices.length; } byte[] nonRevokedProofHashData = prover.getFSContribution(BIG.fromBytes(c.getAttrs()[rhIndex]), rAttrs[hiddenRHIndex], cri); if (nonRevokedProofHashData == null) { throw new RuntimeException("Failed to compute non-revoked proof"); } ECP t1 = aPrime.mul2(re, ipk.getHRand(), rR2); ECP t2 = PAIR.G1mul(ipk.getHRand(), rSPrime); t2.add(bPrime.mul2(rR3, ipk.getHsk(), rsk)); for (int i = 0; i < hiddenIndices.length / 2; i++) { t2.add(ipk.getHAttrs()[hiddenIndices[2 * i]].mul2(rAttrs[2 * i], ipk.getHAttrs()[hiddenIndices[2 * i + 1]], rAttrs[2 * i + 1])); } if (hiddenIndices.length % 2 != 0) { t2.add(PAIR.G1mul(ipk.getHAttrs()[hiddenIndices[hiddenIndices.length - 1]], rAttrs[hiddenIndices.length - 1])); } ECP t3 = ipk.getHsk().mul2(rsk, ipk.getHRand(), rRNym); // create proofData such that it can contain the sign label, 7 elements in G1 (each of size 2*FIELD_BYTES+1), // the ipk hash, the disclosure array, and the message byte[] proofData = new byte[0]; proofData = IdemixUtils.append(proofData, SIGN_LABEL.getBytes()); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t1)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t2)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t3)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(aPrime)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(aBar)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(bPrime)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(pseudonym.getNym())); proofData = IdemixUtils.append(proofData, ipk.getHash()); proofData = IdemixUtils.append(proofData, disclosure); proofData = IdemixUtils.append(proofData, msg); BIG cvalue = IdemixUtils.hashModOrder(proofData); byte[] finalProofData = new byte[0]; finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(cvalue)); finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(nonce)); proofC = IdemixUtils.hashModOrder(finalProofData); proofSSk = IdemixUtils.modAdd(rsk, BIG.modmul(proofC, sk, IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER); proofSE = IdemixUtils.modSub(re, BIG.modmul(proofC, c.getE(), IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER); proofSR2 = IdemixUtils.modAdd(rR2, BIG.modmul(proofC, r2, IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER); proofSR3 = IdemixUtils.modSub(rR3, BIG.modmul(proofC, r3, IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER); proofSSPrime = IdemixUtils.modAdd(rSPrime, BIG.modmul(proofC, sPrime, IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER); proofSRNym = IdemixUtils.modAdd(rRNym, BIG.modmul(proofC, pseudonym.getRandNym(), IdemixUtils.GROUP_ORDER), IdemixUtils.GROUP_ORDER); nym = new ECP(); nym.copy(pseudonym.getNym()); proofSAttrs = new BIG[hiddenIndices.length]; for (int i = 0; i < hiddenIndices.length; i++) { proofSAttrs[i] = new BIG(rAttrs[i]); proofSAttrs[i].add( BIG.modmul(proofC, BIG.fromBytes(c.getAttrs()[hiddenIndices[i]]), IdemixUtils.GROUP_ORDER)); proofSAttrs[i].mod(IdemixUtils.GROUP_ORDER); } // include non-revocation proof in signature this.revocationPk = cri.getEpochPk(); this.revocationPKSig = cri.getEpochPkSig().toByteArray(); this.epoch = cri.getEpoch(); this.nonRevocationProof = prover.getNonRevocationProof(this.proofC); }
From source file:org.eclipse.recommenders.jayes.transformation.AbstractDecomposition.java
private double[] undoReordering(double[] latentProb, AbstractFactor originalFactor, AbstractFactor newFactor, int originalId) { AbstractFactor o2 = originalFactor.clone(); AbstractFactor n2 = newFactor.clone(); n2.getDimensionIDs()[n2.getDimensionIDs().length - 1] = originalId; int oInd = Ints.indexOf(o2.getDimensionIDs(), originalId); n2.getDimensions()[n2.getDimensions().length - 1] = o2.getDimensions()[oInd]; n2.setValues(new DoubleArrayWrapper(latentProb)); o2.setValues(new DoubleArrayWrapper(new double[MathUtils.product(o2.getDimensions())])); o2.fill(1);/*from w w w. j ava 2 s .co m*/ o2.multiplyCompatible(n2); return o2.getValues().toDoubleArray(); }
From source file:com.google.android.apps.forscience.whistlepunk.metadata.SensorTrigger.java
public boolean hasAlertType(int alertType) { int[] alertTypes = mTriggerInfo.triggerAlertTypes; return Ints.indexOf(alertTypes, alertType) != -1; }
From source file:org.totschnig.myexpenses.task.CsvImportTask.java
private int findColumnIndex(int field) { return Ints.indexOf(column2FieldMap, field); }
From source file:com.opengamma.strata.collect.array.IntArray.java
/** * Find the index of the first occurrence of the specified value. * //ww w . j a va2s. co m * @param value the value to find * @return the index of the value, -1 if not found */ public int indexOf(int value) { return Ints.indexOf(array, value); }
From source file:org.hyperledger.fabric.sdk.idemix.IdemixSignature.java
/** * Verify this signature/*from www . j a v a 2 s .c o m*/ * * @param disclosure an array indicating which attributes it expects to be disclosed * @param ipk the issuer public key * @param msg the message that should be signed in this signature * @param attributeValues BIG array where attributeValues[i] contains the desired attribute value for the i-th attribute if its disclosed * @param rhIndex index of the attribute that represents the revocation-handle * @param revPk the long term public key used to authenticate CRIs * @param epoch monotonically increasing counter representing a time window * @return true iff valid */ public boolean verify(boolean[] disclosure, IdemixIssuerPublicKey ipk, byte[] msg, BIG[] attributeValues, int rhIndex, PublicKey revPk, int epoch) throws CryptoException { if (disclosure == null || ipk == null || msg == null || attributeValues == null || attributeValues.length != ipk.getAttributeNames().length || disclosure.length != ipk.getAttributeNames().length) { return false; } for (int i = 0; i < ipk.getAttributeNames().length; i++) { if (disclosure[i] && attributeValues[i] == null) { return false; } } int[] hiddenIndices = hiddenIndices(disclosure); if (proofSAttrs.length != hiddenIndices.length) { return false; } if (aPrime.is_infinity()) { return false; } if (nonRevocationProof.getRevocationAlg() >= RevocationAlgorithm.values().length) { throw new IllegalArgumentException("CRI specifies unknown revocation algorithm"); } RevocationAlgorithm revocationAlgorithm = RevocationAlgorithm.values()[nonRevocationProof .getRevocationAlg()]; if (disclosure[rhIndex]) { throw new IllegalArgumentException("Attribute " + rhIndex + " is disclosed but also used a revocation handle attribute, which should remain hidden"); } // Verify EpochPK if (!RevocationAuthority.verifyEpochPK(revPk, this.revocationPk, this.revocationPKSig, epoch, revocationAlgorithm)) { // Signature is based on an invalid revocation epoch public key return false; } FP12 temp1 = PAIR.ate(ipk.getW(), aPrime); FP12 temp2 = PAIR.ate(IdemixUtils.genG2, aBar); temp2.inverse(); temp1.mul(temp2); if (!PAIR.fexp(temp1).isunity()) { return false; } ECP t1 = aPrime.mul2(proofSE, ipk.getHRand(), proofSR2); ECP temp = new ECP(); temp.copy(aBar); temp.sub(bPrime); t1.sub(PAIR.G1mul(temp, proofC)); ECP t2 = PAIR.G1mul(ipk.getHRand(), proofSSPrime); t2.add(bPrime.mul2(proofSR3, ipk.getHsk(), proofSSk)); for (int i = 0; i < hiddenIndices.length / 2; i++) { t2.add(ipk.getHAttrs()[hiddenIndices[2 * i]].mul2(proofSAttrs[2 * i], ipk.getHAttrs()[hiddenIndices[2 * i + 1]], proofSAttrs[2 * i + 1])); } if (hiddenIndices.length % 2 != 0) { t2.add(PAIR.G1mul(ipk.getHAttrs()[hiddenIndices[hiddenIndices.length - 1]], proofSAttrs[hiddenIndices.length - 1])); } temp = new ECP(); temp.copy(IdemixUtils.genG1); for (int i = 0; i < disclosure.length; i++) { if (disclosure[i]) { temp.add(PAIR.G1mul(ipk.getHAttrs()[i], attributeValues[i])); } } t2.add(PAIR.G1mul(temp, proofC)); ECP t3 = ipk.getHsk().mul2(proofSSk, ipk.getHRand(), proofSRNym); t3.sub(nym.mul(proofC)); // Check with non-revoked-verifier NonRevocationVerifier nonRevokedVerifier = NonRevocationVerifier .getNonRevocationVerifier(revocationAlgorithm); int hiddenRHIndex = Ints.indexOf(hiddenIndices, rhIndex); if (hiddenRHIndex < 0) { // rhIndex is not present, set to last index position hiddenRHIndex = hiddenIndices.length; } BIG proofSRh = proofSAttrs[hiddenRHIndex]; byte[] nonRevokedProofBytes = nonRevokedVerifier.recomputeFSContribution(this.nonRevocationProof, proofC, IdemixUtils.transformFromProto(this.revocationPk), proofSRh); if (nonRevokedProofBytes == null) { return false; } // create proofData such that it can contain the sign label, 7 elements in G1 (each of size 2*FIELD_BYTES+1), // the ipk hash, the disclosure array, and the message byte[] proofData = new byte[0]; proofData = IdemixUtils.append(proofData, SIGN_LABEL.getBytes()); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t1)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t2)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t3)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(aPrime)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(aBar)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(bPrime)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(nym)); proofData = IdemixUtils.append(proofData, ipk.getHash()); proofData = IdemixUtils.append(proofData, disclosure); proofData = IdemixUtils.append(proofData, msg); BIG cvalue = IdemixUtils.hashModOrder(proofData); byte[] finalProofData = new byte[0]; finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(cvalue)); finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(nonce)); byte[] hashedProofData = IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(finalProofData)); return Arrays.equals(IdemixUtils.bigToBytes(proofC), hashedProofData); }