nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/executioner/OpExecutionerUtil.java
public static boolean canDoOpDirectly(INDArray x, INDArray y) {
        if (x.isVector())
            return true;
        if (x.ordering() != y.ordering())
            return false; //other than vectors, elements in f vs. c NDArrays will never line up
        if (x.elementWiseStride() < 1 || y.elementWiseStride() < 1)
            return false;
        //Full buffer + matching strides -> implies all elements are contiguous (and match)
        //Need strides to match, otherwise elements in buffer won't line up (i.e., c vs. f order arrays)
        long l1 = x.lengthLong();
        long dl1 = x.data().length();
        long l2 = y.lengthLong();
        long dl2 = y.data().length();
        long[] strides1 = x.stride();
        long[] strides2 = y.stride();
        boolean equalStrides = Arrays.equals(strides1, strides2);
        if (l1 == dl1 && l2 == dl2 && equalStrides)
            return true;

        //Strides match + are same as a zero offset NDArray -> all elements are contiguous (and match)
        if (equalStrides) {
            long[] shape1 = x.shape();
            long[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1)
                            : ArrayUtil.calcStridesFortran(shape1));
            boolean stridesSameAsInit = Arrays.equals(strides1, stridesAsInit);
            return stridesSameAsInit;
        }

        return false;
    }
public static boolean canDoOpDirectly(INDArray x, INDArray y) {
        if (x.isVector())
            return true;
        if (x.ordering() != y.ordering())
            return false; //other than vectors, elements in f vs. c NDArrays will never line up
        if (x.elementWiseStride() < 1 || y.elementWiseStride() < 1)
            return false;
        //Full buffer + matching strides -> implies all elements are contiguous (and match)
        //Need strides to match, otherwise elements in buffer won't line up (i.e., c vs. f order arrays)
        long l1 = x.lengthLong();
        long dl1 = x.data().length();
        long l2 = y.lengthLong();
        long dl2 = y.data().length();
        long[] strides1 = x.stride();
        long[] strides2 = y.stride();
        boolean equalStrides = Arrays.equals(strides1, strides2);
        if (l1 == dl1 && l2 == dl2 && equalStrides)
            return true;

        //Strides match + are same as a zero offset NDArray -> all elements are contiguous (and match)
        if (equalStrides) {
            long[] shape1 = x.shape();
            long[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1)
                            : ArrayUtil.calcStridesFortran(shape1));
            boolean stridesSameAsInit = Arrays.equals(strides1, stridesAsInit);
            return stridesSameAsInit;
        }

        return false;
    }
public static boolean canDoOpDirectly ( INDArray x , INDArray y ) { if ( x . isVector ( ) ) return true ; if ( x . ordering ( ) != y . ordering ( ) ) return false ; //other than vectors, elements in f vs. c NDArrays will never line up if ( x . elementWiseStride ( ) < 1 || y . elementWiseStride ( ) < 1 ) return false ; //Full buffer + matching strides -> implies all elements are contiguous (and match) //Need strides to match, otherwise elements in buffer won't line up (i.e., c vs. f order arrays) long l1 = x . lengthLong ( ) ; long dl1 = x . data ( ) . length ( ) ; long l2 = y . lengthLong ( ) ; long dl2 = y . data ( ) . length ( ) ; long [ ] strides1 = x . stride ( ) ; long [ ] strides2 = y . stride ( ) ; boolean equalStrides = Arrays . equals ( strides1 , strides2 ) ; if ( l1 == dl1 && l2 == dl2 && equalStrides ) return true ; //Strides match + are same as a zero offset NDArray -> all elements are contiguous (and match) if ( equalStrides ) { long [ ] shape1 = x . shape ( ) ; long [ ] stridesAsInit = ( x . ordering ( ) == ' ' ? ArrayUtil . calcStrides ( shape1 ) : ArrayUtil . calcStridesFortran ( shape1 ) ) ; boolean stridesSameAsInit = Arrays . equals ( strides1 , stridesAsInit ) ; return stridesSameAsInit ; } return false ; }
Can we do the transform op (X = Op(X,Y)) directly on the arrays without breaking them up into 1d tensors first?
Can we do the transform op ( X = Op ( X Y )) directly on the arrays without breaking them up into 1d tensors first?