Java Code Examples for com.google.common.primitives.Ints#concat()

The following examples show how to use com.google.common.primitives.Ints#concat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedirectInjector.java    From Mixin with MIT License 6 votes vote down vote up
/**
 * Redirect a method invocation
 */
@Override
protected void injectAtInvoke(Target target, InjectionNode node) {
    RedirectedInvokeData invoke = new RedirectedInvokeData(target, (MethodInsnNode)node.getCurrentTarget());
    
    this.validateParams(invoke, invoke.returnType, invoke.handlerArgs);
    
    InsnList insns = new InsnList();
    Extension extraLocals = target.extendLocals().add(invoke.handlerArgs).add(1);
    Extension extraStack = target.extendStack().add(1); // Normally only need 1 extra stack pos to store target ref 
    int[] argMap = this.storeArgs(target, invoke.handlerArgs, insns, 0);
    if (invoke.captureTargetArgs > 0) {
        int argSize = Bytecode.getArgsSize(target.arguments, 0, invoke.captureTargetArgs);
        extraLocals.add(argSize);
        extraStack.add(argSize);
        // No need to truncate target arg indices, pushArgs ignores args which don't exist
        argMap = Ints.concat(argMap, target.getArgIndices());
    }
    AbstractInsnNode champion = this.invokeHandlerWithArgs(this.methodArgs, insns, argMap);
    if (invoke.coerceReturnType && invoke.returnType.getSort() >= Type.ARRAY) {
        insns.add(new TypeInsnNode(Opcodes.CHECKCAST, invoke.returnType.getInternalName()));
    }
    target.replaceNode(invoke.node, champion, insns);
    extraLocals.apply();
    extraStack.apply();
}
 
Example 2
Source File: ArrayUtil.java    From opc-ua-stack with Apache License 2.0 5 votes vote down vote up
public static int[] getDimensions(Object array) {
    int[] dimensions = new int[0];
    Class<?> type = array.getClass();

    while (type.isArray()) {
        int length = array != null ? Array.getLength(array) : 0;
        dimensions = Ints.concat(dimensions, new int[]{length});

        array = length > 0 ? Array.get(array, 0) : null;
        type = type.getComponentType();
    }

    return dimensions;
}
 
Example 3
Source File: CombineTwoArrays.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void join_two_primitive_arrays_in_java_with_guava() {

	int[] allStateCapitalsByIndex = Ints.concat(
			firstHalfStateCapitalByIndex, secondHalfStateCapitalByIndex);

	Arrays.toString(allStateCapitalsByIndex);
	assertEquals(50, allStateCapitalsByIndex.length);
}
 
Example 4
Source File: ScalarsRegistryTest.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
TInputSet createOverloadWithPriority(int priority, int... priorities) {
    priorities = Ints.concat(new int[] { priority }, priorities);
    TScalar result = new DummyScalar(FUNC_NAME, priorities);
    instanceFinder.put(TScalar.class, result);
    return onlyInputSet(result);
}
 
Example 5
Source File: TensorMmul.java    From nd4j with Apache License 2.0 4 votes vote down vote up
private SDVariable doTensorMmul(SDVariable a,
                                SDVariable b,
                                int[][] axes) {

    int validationLength = Math.min(axes[0].length, axes[1].length);
    for (int i = 0; i < validationLength; i++) {
        if (a.getShape()[axes[0][i]] != b.getShape()[axes[1][i]])
            throw new IllegalArgumentException("Size of the given axes at each dimension must be the same size.");
        if (axes[0][i] < 0)
            axes[0][i] += a.getShape().length;
        if (axes[1][i] < 0)
            axes[1][i] += b.getShape().length;

    }

    List<Integer> listA = new ArrayList<>();
    for (int i = 0; i < a.getShape().length; i++) {
        if (!Ints.contains(axes[0], i))
            listA.add(i);
    }

    int[] newAxesA = Ints.concat(Ints.toArray(listA), axes[0]);


    List<Integer> listB = new ArrayList<>();
    for (int i = 0; i < b.getShape().length; i++) {
        if (!Ints.contains(axes[1], i))
            listB.add(i);
    }

    int[] newAxesB = Ints.concat(axes[1], Ints.toArray(listB));

    int n2 = 1;
    int aLength = Math.min(a.getShape().length, axes[0].length);
    for (int i = 0; i < aLength; i++) {
        n2 *= a.getShape()[axes[0][i]];
    }

    //if listA and listB are empty these do not initialize.
    //so initializing with {1} which will then get overridden if not empty
    long[] newShapeA = {-1, n2};
    long[] oldShapeA;
    if (listA.size() == 0) {
        oldShapeA = new long[] {1};
    } else {
        oldShapeA = Longs.toArray(listA);
        for (int i = 0; i < oldShapeA.length; i++)
            oldShapeA[i] = a.getShape()[(int) oldShapeA[i]];
    }

    int n3 = 1;
    int bNax = Math.min(b.getShape().length, axes[1].length);
    for (int i = 0; i < bNax; i++) {
        n3 *= b.getShape()[axes[1][i]];
    }


    int[] newShapeB = {n3, -1};
    long[] oldShapeB;
    if (listB.size() == 0) {
        oldShapeB = new long[] {1};
    } else {
        oldShapeB = Longs.toArray(listB);
        for (int i = 0; i < oldShapeB.length; i++)
            oldShapeB[i] = b.getShape()[(int) oldShapeB[i]];
    }


    SDVariable at = f()
            .reshape(f().permute
                    (a,newAxesA),newShapeA);
    SDVariable bt = f()
            .reshape(f()
                    .permute(b,newAxesB),newShapeB);

    SDVariable ret = f().mmul(at,bt);
    long[] aPlusB = Longs.concat(oldShapeA, oldShapeB);
    return f().reshape(ret, aPlusB);
}
 
Example 6
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray get(List<List<Integer>> indices) {
    INDArrayIndex[] indArrayIndices = new INDArrayIndex[indices.size()];
    for(int i = 0; i < indArrayIndices.length; i++) {
        indArrayIndices[i] = new SpecifiedIndex(Ints.toArray(indices.get(i)));
    }

    boolean hasNext = true;
    Generator<List<List<Long>>> iterate = SpecifiedIndex.iterate(indArrayIndices);
    List<INDArray> resultList = new ArrayList<>();
    while(hasNext) {
        try {
            List<List<Long>> next = iterate.next();
            int[][] nextArr = new int[next.size()][];
            for(int i = 0; i < next.size(); i++) {
                nextArr[i] = Ints.toArray(next.get(i));
            }

            int[] curr = Ints.concat(nextArr);
            INDArray currSlice = this;
            for(int j = 0; j < curr.length; j++) {
                currSlice = currSlice.slice(curr[j]);
            }

            //slice drops the first dimension, this adds a 1 to match normal numpy behavior
            currSlice = currSlice.reshape(Longs.concat(new long[]{1},currSlice.shape()));

            resultList.add(currSlice);


        }
        catch(NoSuchElementException e) {
            hasNext = false;
        }
    }




    return Nd4j.concat(0,resultList.toArray(new INDArray[resultList.size()]));
}
 
Example 7
Source File: GuavaTutorial.java    From maven-framework-project with MIT License 3 votes vote down vote up
@Test
public void example20(){
	
	int[] array1 = { 1, 2, 3, 4, 5 };
	int a = 4;
	
	boolean contains = Ints.contains(array1, a);//判断数组中是否存在a元素
	
	System.out.println(contains);
	
	int indexOf = Ints.indexOf(array1, a); //获取该元素在数组中的下标
	
	System.out.println(indexOf);
	
	int max = Ints.max(array1);//求数组中的最大值
	
	System.out.println(max);
	
	int min = Ints.min(array1);//求数组中的最小值
	
	System.out.println(min);
	
	int[] array2 = {6, 7, 8, 9, 10};
	
	int[] concat = Ints.concat(array1, array2 );//合并数组
	
	System.out.println(Arrays.toString(concat));
	
}