Align the labels for a label query.

@param l1 List of reference labels
@param d1 Probabilities for these labels
@param l2 List of requested labels
@return Probabilities in desired output order
962751
protected double[] alignLabels(List<ClassLabel> l1, double[] d1, Collection<ClassLabel> l2) {
    assert (l1.size() == d1.length);
    if(l1 == l2) {
      return d1.clone();
    }
    double[] d2 = new double[l2.size()];
    Iterator<ClassLabel> i2 = l2.iterator();
    for(int i = 0; i2.hasNext();) {
      ClassLabel l = i2.next();
      int idx = l1.indexOf(l);
      if(idx < 0 && getLogger().isDebuggingFiner()) {
        getLogger().debugFiner("Label not found: " + l);
      }
      d2[i] = (idx >= 0) ? d1[idx] : 0.; // Default to 0 for unknown labels!
    }
    return d2;
  }
902273
def intersection(L1, L2):
    
    D = L1[0] * L2[1] - L1[1] * L2[0]
    Dx = L1[2] * L2[1] - L1[1] * L2[2]
    Dy = L1[0] * L2[2] - L1[2] * L2[0]
    if D != 0:
        x = Dx / D
        y = Dy / D
        return x, y
    else:
        return False
566586
public static double cosineSim(@NonNull INDArray d1, @NonNull INDArray d2) {
        return Nd4j.getExecutioner().exec(new CosineSimilarity(d1, d2)).getDouble(0);
    }
1061954
public double alignOrientation(double baseOrientation, double orientation) {
        double resultOrientation;
        if (baseOrientation >= 0) {
            if (orientation < -Math.PI + baseOrientation)
                resultOrientation = orientation + 2 * Math.PI;
            else
                resultOrientation = orientation;

        } else if (orientation > +Math.PI + baseOrientation)
            resultOrientation = orientation - 2 * Math.PI;
        else
            resultOrientation = orientation;
        return resultOrientation;
    }
519147
public static <S extends Sequence<S>> Alignment<S> alignLocal(AlignmentScoring<S> alignmentScoring,
                                                                  S seq1, S seq2) {
        if (alignmentScoring instanceof AffineGapAlignmentScoring)
            return alignLocalAffine((AffineGapAlignmentScoring<S>) alignmentScoring, seq1, seq2);
        if (alignmentScoring instanceof LinearGapAlignmentScoring)
            return alignLocalLinear((LinearGapAlignmentScoring<S>) alignmentScoring, seq1, seq2);
        throw new RuntimeException("Unknown scoring type.");
    }
113384
public int getAlignPos(int[][] alignList)
	{
		int     i = B1;
		int     j = B2;
		int     s = 0;
		int     a = 0;
		int     op;
		while(i <= E1 && j <= E2)       {
			op = sapp0[s ++];

			if (op == 0)    {
				alignList[0][a] = i - 1; //i - 1
				alignList[1][a] = j - 1;
				a ++;
				i ++;
				j ++;
			}
			else if (op > 0) {
				j += op;
			}
			else {
				i -= op;
			}
		}
		return a;
	}
769393
def outline(labels):
    
    
    output = numpy.zeros(labels.shape, labels.dtype)
    lr_different = labels[1:,:]!=labels[:-1,:]
    ud_different = labels[:,1:]!=labels[:,:-1]
    d1_different = labels[1:,1:]!=labels[:-1,:-1]
    d2_different = labels[1:,:-1]!=labels[:-1,1:]
    different = numpy.zeros(labels.shape, bool)
    different[1:,:][lr_different]  = True
    different[:-1,:][lr_different] = True
    different[:,1:][ud_different]  = True
    different[:,:-1][ud_different] = True
    different[1:,1:][d1_different] = True
    different[:-1,:-1][d1_different] = True
    different[1:,:-1][d2_different] = True
    different[:-1,1:][d2_different] = True
    #
    # Labels on edges need outlines
    #
    different[0,:] = True
    different[:,0] = True
    different[-1,:] = True
    different[:,-1] = True
    
    output[different] = labels[different]
    return output
574629
def create_labels(da, labels, locations, direction):
    
    # The box dimensions are determined by the size of
    # the text objects. We put two dummy children at
    # either end to gaurantee that when center packed
    # the labels in the labels_box matchup with the ticks.
    fontsize = 9
    aux_transform = mtransforms.IdentityTransform()
    labels_box = MyAuxTransformBox(aux_transform)
    xs, ys = [0]*len(labels), locations
    ha, va = 'left', 'center'

    x1, y1 = 0, 0
    x2, y2 = 0, da.height
    if direction == 'horizontal':
        xs, ys = ys, xs
        ha, va = 'center', 'top'
        x2, y2 = da.width, 0
    txt1 = mtext.Text(x1, y1, '',
                      horizontalalignment=ha,
                      verticalalignment=va)
    txt2 = mtext.Text(x2, y2, '',
                      horizontalalignment=ha,
                      verticalalignment=va)
    labels_box.add_artist(txt1)
    labels_box.add_artist(txt2)

    legend_text = []
    for i, (x, y, text) in enumerate(zip(xs, ys, labels)):
        txt = mtext.Text(x, y, text,
                         size=fontsize,
                         horizontalalignment=ha,
                         verticalalignment=va)
        labels_box.add_artist(txt)
        legend_text.append(txt)
    return labels_box, legend_text
1083956
protected Set<Integer> getLabelIndices(Set<L> labels) {
    Set<Integer> iLabels = new HashSet<Integer>();
    for (L label:labels) {
      int iLabel = labelIndex.indexOf(label);
      iLabels.add(iLabel);
      if (iLabel < 0) throw new IllegalArgumentException("Unknown label " + label);
    }
    return iLabels;
  }
218408
def kld(d1, d2):
    
    d1, d2 = flatten(d1), flatten(d2)
    return entropy(d1, d2, 2.0)
322544
public static final @BetterImageSpanAlignment
  int normalizeAlignment(int alignment) {
    switch (alignment) {
      case DynamicDrawableSpan.ALIGN_BOTTOM:
        return ALIGN_BOTTOM;
      case ALIGN_CENTER:
        return ALIGN_CENTER;
      case DynamicDrawableSpan.ALIGN_BASELINE:
      default:
        return ALIGN_BASELINE;
    }
  }
573226
def same_label_mask(y, y2):
    
    return tf.cast(tf.squeeze(tf.equal(y, tf.expand_dims(y2, 1))), tf.float32)
549958
def dist_point_line(p, l1, l2):
    '''
    '''
    cross_prod = np.cross(l2 - l1, p - l1)
    return np.linalg.norm(cross_prod) / np.linalg.norm(l2 - l1)
750339
@Pure
	public static Point2d L2_L1(double x, double y) {
		final Point2d ntfLambdaPhi = NTFLambert_NTFLambdaPhi(x, y,
				LAMBERT_2_N,
				LAMBERT_2_C,
				LAMBERT_2_XS,
				LAMBERT_2_YS);
		return NTFLambdaPhi_NTFLambert(
				ntfLambdaPhi.getX(), ntfLambdaPhi.getY(),
				LAMBERT_1_N,
				LAMBERT_1_C,
				LAMBERT_1_XS,
				LAMBERT_1_YS);
	}
443274
public PatternElementMatch getFirstLabeledMatch(String label) {
        PatternElementMatch cur = this, result = null;
        while (cur != null) {
            String elementLabel = cur.patternElement.getLabel();
            if (elementLabel != null && elementLabel.equals(label)) {
                result = cur;
            }
            cur = cur.prev;
        }
        return result;
    }
231128
def overlap1d(l1,l2,PAx,PBx,gamma):
    
    total = 0
    for i in range(1+int(floor(0.5*(l1+l2)))):
        total += binomial_prefactor(2*i,l1,l2,PAx,PBx)* \
                 fact2(2*i-1)/pow(2*gamma,i)
    return total
590645
public static <E> List<E> unionList(List<E> l1, List<E> l2) {
	return new UList<E>(l1, l2);
    }