Infer order from
@param shape the shape to infer by
@param stride the stride to infer by
@param elementStride the element stride to start at
@return the storage order given shape and element stride
519800
public static char getOrder(int[] shape, int[] stride, int elementStride) {
        int sd;
        int dim;
        int i;
        boolean cContiguous = true;
        boolean isFortran = true;

        sd = 1;
        for (i = shape.length - 1; i >= 0; --i) {
            dim = shape[i];

            if (stride[i] != sd) {
                cContiguous = false;
                break;
            }
            /* contiguous, if it got this far */
            if (dim == 0) {
                break;
            }
            sd *= dim;

        }


        /* check if fortran contiguous */
        sd = elementStride;
        for (i = 0; i < shape.length; ++i) {
            dim = shape[i];
            if (stride[i] != sd) {
                isFortran = false;
            }
            if (dim == 0) {
                break;
            }
            sd *= dim;

        }

        if (isFortran && cContiguous)
            return 'a';
        else if (isFortran && !cContiguous)
            return 'f';
        else if (!isFortran && !cContiguous)
            return 'c';
        else
            return 'c';

    }
253801
protected static DefaultProcessDiagramCanvas.SHAPE_TYPE getShapeType(BaseElement baseElement) {
        if (baseElement instanceof Task || baseElement instanceof Activity || baseElement instanceof TextAnnotation) {
            return DefaultProcessDiagramCanvas.SHAPE_TYPE.Rectangle;
        } else if (baseElement instanceof Gateway) {
            return DefaultProcessDiagramCanvas.SHAPE_TYPE.Rhombus;
        } else if (baseElement instanceof Event) {
            return DefaultProcessDiagramCanvas.SHAPE_TYPE.Ellipse;
        }
        // unknown source element, just do not correct coordinates
        return null;
    }
283434
public static long getOffsetUnsafe(DataBuffer shapeInformation, int row, int col) {
        long offset = 0;
        int size_0 = sizeUnsafe(shapeInformation, 0);
        int size_1 = sizeUnsafe(shapeInformation, 1);
        if (row >= size_0 || col >= size_1)
            throw new IllegalArgumentException("Invalid indices: cannot get [" + row + "," + col + "] from a "
                    + Arrays.toString(shape(shapeInformation)) + " NDArray");

        if (size_0 != 1)
            offset += row * strideUnsafe(shapeInformation, 0, 2);
        if (size_1 != 1)
            offset += col * strideUnsafe(shapeInformation, 1, 2);

        return offset;
    }
1254448
public static long[] shape(IntBuffer buffer) {
        val ret = new long[rank(buffer)];
        for (int i = 0; i < ret.length; i++)
            ret[i] = buffer.get(1 + i);
        return ret;
    }
71403
@Pure
	public static ShapeElementType toESRI(Class<? extends MapElement> type) {
		if (MapPolyline.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYLINE;
		}
		if (MapPolygon.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYGON;
		}
		if (MapMultiPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.MULTIPOINT;
		}
		if (MapPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.POINT;
		}
		throw new IllegalArgumentException();
	}
1106385
public static List<? extends Element> getEnclosedElementsDeclarationOrder(TypeElement type) {
        List<? extends Element> result = null;
        try {
            Object binding = field(type, "_binding");

            Class<?> sourceTypeBinding = null;
            {
                Class<?> c = binding.getClass();
                do {
                    if (c.getCanonicalName().equals(
                            "org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding")) {
                        sourceTypeBinding = c;
                        break;
                    }
                } while ((c = c.getSuperclass()) != null);
            }

            final List<Object> declarationOrder;
            if (sourceTypeBinding != null) {
                declarationOrder = findSourceOrder(binding);

                List<Element> enclosedElements = new ArrayList<Element>(type.getEnclosedElements());
                Collections.sort(enclosedElements, new Comparator<Element>() {

                    public int compare(Element o1, Element o2) {
                        try {
                            Object o1Binding = field(o1, "_binding");
                            Object o2Binding = field(o2, "_binding");

                            int i1 = declarationOrder.indexOf(o1Binding);
                            int i2 = declarationOrder.indexOf(o2Binding);

                            return i1 - i2;
                        } catch (Exception e) {
                            return 0;
                        }
                    }

                });
                result = enclosedElements;
            }
        } catch (Exception e) {
            // ignore
        }
        return (result != null) ? result : type.getEnclosedElements();
    }
1037809
@Override
  public Set<FlowEdge> getEdges(DataNode node) {
    try {
      rwLock.readLock().lock();
      return (node != null) ? this.nodesToEdges.getOrDefault(node, null) : null;
    } finally {
      rwLock.readLock().unlock();
    }
  }
783115
public static int elementWiseStride(IntBuffer buffer) {
        int length2 = shapeInfoLength(buffer.get(0));
        return buffer.get(length2 - 2);
    }
570241
public BlockOrder setBlockOrder(BlockOrder order) {
		verifyTrue(order != null, "block order cannot be null");

		if (order == layout.blockOrder) {
			return order; // quick exit, already same
		}

		BlockMatrixLayout newLayout = new BlockMatrixLayout(layout.rows, layout.columns,
				layout.blockStripe, order);

		// swap order of each block
		for (int r = 0; r < layout.rows; r += layout.blockStripe) {
			for (int c = 0; c < layout.columns; c += layout.blockStripe) {

				int blockNumber = layout.getBlockNumber(r, c);
				if (data[blockNumber] == null) {
					continue;
				} else if (order == BlockOrder.ROWMAJOR) {
					data[blockNumber] = layout.toRowMajorBlock(data[blockNumber], r, c);
				} else {
					data[blockNumber] = layout.toColMajorBlock(data[blockNumber], r, c);
				}

			}
		}

		BlockOrder oldLayout = this.layout.blockOrder;
		this.layout = newLayout;
		return oldLayout;

	}
672442
static List<Point2D> pointsOf(final Shape shape) {
        final List<Point2D> points = new ArrayList<Point2D>();
        final double[] coordinates = new double[6];
        for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) {
            switch (i.currentSegment(coordinates)) {
                case PathIterator.SEG_CLOSE:
                    break;
                case PathIterator.SEG_MOVETO:
                case PathIterator.SEG_LINETO:
                    points.add(new Point2D.Double(coordinates[0], coordinates[1]));
                    break;
                case PathIterator.SEG_QUADTO:
                    points.add(new Point2D.Double(coordinates[0], coordinates[1]));
                    points.add(new Point2D.Double(coordinates[2], coordinates[3]));
                    break;
                case PathIterator.SEG_CUBICTO:
                    points.add(new Point2D.Double(coordinates[0], coordinates[1]));
                    points.add(new Point2D.Double(coordinates[2], coordinates[3]));
                    points.add(new Point2D.Double(coordinates[4], coordinates[5]));
                    break;
            }
        }

        if (!points.isEmpty() && points.get(points.size() - 1).equals(points.get(0))) {
            points.remove(points.size() - 1);
        }
        return points;
    }
426581
@Override
    public INDArray arange(double begin, double end, double step) {
        return Nd4j.create(ArrayUtil.toDoubles(ArrayUtil.range((int) begin, (int) end,  (int)step)));
    }
123593
@SuppressWarnings("unchecked")
    static <T> Node<T> emptyNode(StreamShape shape) {
        switch (shape) {
            case REFERENCE:    return (Node<T>) EMPTY_NODE;
            case INT_VALUE:    return (Node<T>) EMPTY_INT_NODE;
            case LONG_VALUE:   return (Node<T>) EMPTY_LONG_NODE;
            case DOUBLE_VALUE: return (Node<T>) EMPTY_DOUBLE_NODE;
            default:
                throw new IllegalStateException("Unknown shape " + shape);
        }
    }
932961
private static Point getShapeIntersection(Shape shape,
                                              Line2D.Double line) {
        PathIterator it = shape.getPathIterator(null);
        double[] coords = new double[6];
        double[] pos = new double[2];
        Line2D.Double l = new Line2D.Double();
        while (!it.isDone()) {
            int type = it.currentSegment(coords);
            switch (type) {
                case PathIterator.SEG_MOVETO:
                    pos[0] = coords[0];
                    pos[1] = coords[1];
                    break;
                case PathIterator.SEG_LINETO:
                    l = new Line2D.Double(pos[0],
                                          pos[1],
                                          coords[0],
                                          coords[1]);
                    if (line.intersectsLine(l)) {
                        return getLinesIntersection(line,
                                                    l);
                    }
                    pos[0] = coords[0];
                    pos[1] = coords[1];
                    break;
                case PathIterator.SEG_CLOSE:
                    break;
                default:
                    // whatever
            }
            it.next();
        }
        return null;
    }
240960
@Pure
	@SuppressWarnings("checkstyle:cyclomaticcomplexity")
	public static Class<? extends MapElement> fromESRI(ShapeElementType type) {
		switch (type) {
		case MULTIPOINT:
		case MULTIPOINT_M:
		case MULTIPOINT_Z:
			return MapMultiPoint.class;
		case POINT:
		case POINT_M:
		case POINT_Z:
			return MapPoint.class;
		case POLYGON:
		case POLYGON_M:
		case POLYGON_Z:
			return MapPolygon.class;
		case POLYLINE:
		case POLYLINE_M:
		case POLYLINE_Z:
			return MapPolyline.class;
			//$CASES-OMITTED$
		default:
		}
		throw new IllegalArgumentException();
	}
1303891
public static <T extends TypeDefinition> ElementMatcher.Junction<T> ofSort(TypeDefinition.Sort sort) {
        return ofSort(is(sort));
    }
217995
@Pure
	public static ShapeElementType classifiesElement(MapElement element) {
		final Class<? extends MapElement> type = element.getClass();
		if (MapMultiPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.MULTIPOINT;
		}
		if (MapPolygon.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYGON;
		}
		if (MapPolyline.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYLINE;
		}
		if (MapPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.POINT;
		}
		return ShapeElementType.UNSUPPORTED;
	}
1188187
public static long getOffsetUnsafe(DataBuffer shapeInformation, int dim0, int dim1, int dim2) {
        long offset = 0;
        int size_0 = sizeUnsafe(shapeInformation, 0);
        int size_1 = sizeUnsafe(shapeInformation, 1);
        int size_2 = sizeUnsafe(shapeInformation, 2);
        if (dim0 >= size_0 || dim1 >= size_1 || dim2 >= size_2)
            throw new IllegalArgumentException("Invalid indices: cannot get [" + dim0 + "," + dim1 + "," + dim2
                    + "] from a " + Arrays.toString(shape(shapeInformation)) + " NDArray");

        if (size_0 != 1)
            offset += dim0 * strideUnsafe(shapeInformation, 0, 3);
        if (size_1 != 1)
            offset += dim1 * strideUnsafe(shapeInformation, 1, 3);
        if (size_2 != 1)
            offset += dim2 * strideUnsafe(shapeInformation, 2, 3);

        return offset;
    }