Create a sparse matrix plot canvas.
@param sparse a sparse matrix.
198872
public static PlotCanvas plot(SparseMatrix sparse) {
        double[] lowerBound = {0, 0};
        double[] upperBound = {sparse.ncols(), sparse.nrows()};
        PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound, false);
        canvas.add(new SparseMatrixPlot(sparse));

        canvas.getAxis(0).setLabelVisible(false);
        canvas.getAxis(0).setGridVisible(false);
        canvas.getAxis(1).setLabelVisible(false);
        canvas.getAxis(1).setGridVisible(false);

        return canvas;
    }
1134610
public static SparseMatrix zero(int rows, int columns, int capacity) {
        return CRSMatrix.zero(rows, columns, capacity);
    }
1047021
public static SparseTensor empty(List<Integer> dimensionNumbers, List<Integer> dimensionSizes) {
    return empty(Ints.toArray(dimensionNumbers), Ints.toArray(dimensionSizes));
  }
723542
public SparseMatrix parse(InputStream stream) throws IOException, ParseException {
        int nrows = 0, ncols = 0, n = 0;
        int[] colIndex;
        int[] rowIndex;
        double[] data;

        try (Scanner scanner = new Scanner(stream)) {
            String line = scanner.nextLine();
            String[] tokens = line.split("\\s+");
            if (tokens.length == 3) {
                try {
                    nrows = Integer.parseInt(tokens[0]);
                    ncols = Integer.parseInt(tokens[1]);
                    n = Integer.parseInt(tokens[2]);
                } catch (Exception ex) {
                }
            }
            
            if (n == 0) {
                // Harwell-Boeing Exchange Format. We ignore first two lines.
                line = scanner.nextLine().trim();
                tokens = line.split("\\s+");
                int RHSCRD = Integer.parseInt(tokens[4]);

                line = scanner.nextLine().trim();
                if (!line.startsWith("R")) {
                    throw new UnsupportedOperationException("SparseMatrixParser supports only real-valued matrix.");
                }

                tokens = line.split("\\s+");
                nrows = Integer.parseInt(tokens[1]);
                ncols = Integer.parseInt(tokens[2]);
                n = Integer.parseInt(tokens[3]);

                line = scanner.nextLine();
                if (RHSCRD > 0) {
                    line = scanner.nextLine();
                }            
            }
            
            colIndex = new int[ncols + 1];
            rowIndex = new int[n];
            data = new double[n];
            for (int i = 0; i <= ncols; i++) {
                colIndex[i] = scanner.nextInt() - 1;
            }
            for (int i = 0; i < n; i++) {
                rowIndex[i] = scanner.nextInt() - 1;
            }
            for (int i = 0; i < n; i++) {
                data[i] = scanner.nextDouble();
            }
        }
        
        SparseMatrix matrix = new SparseMatrix(nrows, ncols, data, rowIndex, colIndex);
        return matrix;
    }
789497
public static SparseVector fromMatrixMarket(InputStream is) throws IOException {
        return Vector.fromMatrixMarket(is).to(Vectors.SPARSE);
    }
1367427
@Override protected void initGraphics() {
        super.initGraphics();

        matrix = PixelMatrixBuilder.create()
                                   .pixelShape(PixelShape.SQUARE)
                                   .useSpacer(true)
                                   .squarePixels(false)
                                   .colsAndRows(tile.getMatrixSize())
                                   .pixelOnColor(tile.getBarColor())
                                   .pixelOffColor(Helper.isDark(tile.getBackgroundColor()) ? tile.getBackgroundColor().brighter() : tile.getBackgroundColor().darker())
                                   .build();

        if (!tile.getChartData().isEmpty() && tile.getChartData().size() > 2) {
            matrix.setColsAndRows(tile.getChartData().size(), matrix.getRows());
        }

        chartEventListener = e -> updateMatrixWithChartData();
        tile.getChartData().forEach(chartData -> chartData.addChartDataEventListener(chartEventListener));

        chartDataListener = c -> {
            while (c.next()) {
                if (c.wasAdded()) {
                    c.getAddedSubList().forEach(addedItem -> addedItem.addChartDataEventListener(chartEventListener));
                    if (!tile.getChartData().isEmpty() && tile.getChartData().size() > 2) {
                        matrix.setColsAndRows(tile.getChartData().size(), matrix.getRows());
                    }
                } else if (c.wasRemoved()) {
                    c.getRemoved().forEach(removedItem -> removedItem.removeChartDataEventListener(chartEventListener));
                    if (!tile.getChartData().isEmpty() && tile.getChartData().size() > 2) {
                        matrix.setColsAndRows(tile.getChartData().size(), matrix.getRows());
                    }
                }
            }
            updateMatrixWithChartData();
        };
        matrixListener    = e -> {
            if (tile.getChartData().isEmpty()) { return; }
            int       column      = e.getX();
            ChartData data        = tile.getChartData().get(column);
            String    tooltipText = new StringBuilder(data.getName()).append("\n").append(String.format(locale, formatString, data.getValue())).toString();
            Point2D popupLocation = new Point2D(e.getMouseScreenX() - selectionTooltip.getWidth() * 0.5, e.getMouseScreenY() - size * 0.025 - selectionTooltip.getHeight());

            selectionTooltip.setText(tooltipText);
            selectionTooltip.setX(popupLocation.getX());
            selectionTooltip.setY(popupLocation.getY());
            selectionTooltip.show(tile.getScene().getWindow());

            tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, data));
        };
        mouseHandler = e -> {
            final javafx.event.EventType<? extends MouseEvent> TYPE = e.getEventType();
            if (MouseEvent.MOUSE_CLICKED.equals(TYPE)) {
                matrix.checkForClick(e);
            } else if (MouseEvent.MOUSE_MOVED.equals(TYPE)) {
                selectionTooltip.hide();
            } else if (MouseEvent.MOUSE_EXITED.equals(TYPE)) {
                selectionTooltip.hide();
            }
        };

        titleText = new Text();
        titleText.setFill(tile.getTitleColor());
        Helper.enableNode(titleText, !tile.getTitle().isEmpty());

        text = new Text(tile.getText());
        text.setFill(tile.getTextColor());
        Helper.enableNode(text, tile.isTextVisible());

        selectionTooltip = new Tooltip("");
        selectionTooltip.setWidth(60);
        selectionTooltip.setHeight(48);
        Tooltip.install(matrix, selectionTooltip);

        getPane().getChildren().addAll(titleText, matrix, text);
    }
112564
private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts,
            float[] textGridWidths, float[] textGridHeights) {
        mPaint.setTextSize(textSize);
        mPaint.setTypeface(typeface);
        Paint[] textPaints = assignTextColors(texts);
        canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], textPaints[0]);
        canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], textPaints[1]);
        canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], textPaints[2]);
        canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], textPaints[3]);
        canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], textPaints[4]);
        canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], textPaints[5]);
        canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], textPaints[6]);
        canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], textPaints[7]);
        canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], textPaints[8]);
        canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], textPaints[9]);
        canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], textPaints[10]);
        canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], textPaints[11]);
    }
96937
private static SparseTensor resizeIntoTable(int[] dimensions, int[] dimensionSizes,
      long[] keyNums, double[] values, int size) {
    if (values.length == size) {
      return new SparseTensor(dimensions, dimensionSizes, keyNums, values);
    } else {
      // Resize the result array to fit the actual number of result
      // keyNums.
      long[] shrunkResultKeyInts = ArrayUtils.copyOf(keyNums, size);
      double[] shrunkResultValues = ArrayUtils.copyOf(values, size);
      return new SparseTensor(dimensions, dimensionSizes, shrunkResultKeyInts, shrunkResultValues);
    }
  }
109773
def _construct_sparse_features(self, x):
        
        I, J, K = x.shape
        new_array_height = (x != 0).sum(axis=2).max()
        index_array = -np.ones((I, J, new_array_height), dtype='int64')
        value_array = -np.ones((I, J, new_array_height), dtype='float64')
        populate_sparse_features(x, index_array, value_array, I, J, K)
        return index_array, value_array
561731
public void add(Plot p) {
        shapes.add(p);

        JComponent[] tb = p.getToolBar();
        if (tb != null) {
            toolbar.addSeparator();
            for (JComponent comp : tb) {
                toolbar.add(comp);
            }
        }

        repaint();
    }
633384
public void drawLine(double[]... coord) {
        int[][] sc = new int[coord.length][];
        for (int i = 0; i < sc.length; i++) {
            sc[i] = projection.screenProjection(coord[i]);
        }

        drawLine(sc);
    }
1077786
public SparseBitmap and(SparseBitmap o) {
		SparseBitmap a = new SparseBitmap();
		and2by2(a, this, o);
		return a;
	}
538809
public static PlotCanvas plot(String id, double[][][] data) {
        double[] lowerBound = {data[0][0][0], data[0][0][1]};
        double[] upperBound = {data[0][0][0], data[0][0][1]};
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[i].length; j++) {
                if (data[i][j][0] < lowerBound[0]) {
                    lowerBound[0] = data[i][j][0];
                }
                if (data[i][j][0] > upperBound[0]) {
                    upperBound[0] = data[i][j][0];
                }
                if (data[i][j][1] < lowerBound[1]) {
                    lowerBound[1] = data[i][j][1];
                }
                if (data[i][j][1] > upperBound[1]) {
                    upperBound[1] = data[i][j][1];
                }
            }
        }

        PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound);

        Grid grid = new Grid(data);
        if (id != null) grid.setID(id);
        canvas.add(grid);

        return canvas;
    }
1353781
public void setColumn(int i, SparseVector x) {
        if (x.size() != numRows)
            throw new IllegalArgumentException(
                    "New column must be of the same size as existing column");
        colD[i] = x;
    }
1166320
@Override
    public void draw(Canvas canvas) {
        drawSpacings(canvas);
        drawBaselineGrid(canvas);
        drawKeylines(canvas);
    }
1371147
public static SparseBitmap and(SparseBitmap... bitmaps) {
		if (bitmaps.length == 0)
			return new SparseBitmap();
		else if (bitmaps.length == 1)
			return bitmaps[0];
		else if (bitmaps.length == 2)
			return bitmaps[0].and(bitmaps[1]);
		// for "and" a priority queue is not needed, but
		// overhead ought to be small
		PriorityQueue<SparseBitmap> pq = new PriorityQueue<SparseBitmap>(
				bitmaps.length, smallfirst);
		for (SparseBitmap x : bitmaps)
			pq.add(x);
		while (pq.size() > 1) {
			SparseBitmap x1 = pq.poll();
			SparseBitmap x2 = pq.poll();
			pq.add(x1.and(x2));
		}
		return pq.poll();
	}
378912
ShadowCompatOperation createShadowCompatOperation(final Matrix transform) {
        // If the shadowCompatOperations don't end on the desired endShadowAngle, add an arc to do so.
        addConnectingShadowIfNecessary(endShadowAngle);
        final List<ShadowCompatOperation> operations = new ArrayList<>(shadowCompatOperations);
        return new ShadowCompatOperation() {
            @Override
            public void draw(
                    Matrix matrix, ShadowRenderer shadowRenderer, int shadowElevation, Canvas canvas) {
                for (ShadowCompatOperation op : operations) {
                    op.draw(transform, shadowRenderer, shadowElevation, canvas);
                }
            }
        };
    }