Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/pierre-guillou/pdiags_bench
13 February 2023, 11:53:21 UTC
  • Code
  • Branches (5)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • refs/heads/mesu
    • refs/heads/mesu_bench
    • refs/heads/saddle_pairs
    • refs/heads/zomo_variants
    No releases to show
  • 95e447f
  • /
  • jplex_persistence.java
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:713eb780cd0f4abfe25283a8cdc74f8f86797084
origin badgedirectory badge Iframe embedding
swh:1:dir:95e447fd05b7bb9564fba216a8957d42fbdb26ff
origin badgerevision badge
swh:1:rev:8a2de479abf7bcbf2002b4f8f620c635217cc088
origin badgesnapshot badge
swh:1:snp:49df835a23e1f2a8e7b91973ed24143919372067
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 8a2de479abf7bcbf2002b4f8f620c635217cc088 authored by Julien J Tierny on 30 January 2023, 16:30:54 UTC
added reference to the arxiv repo
Tip revision: 8a2de47
jplex_persistence.java
import edu.stanford.math.plex4.api.Plex4;
import edu.stanford.math.plex4.homology.barcodes.*;
import edu.stanford.math.plex4.homology.interfaces.AbstractPersistenceAlgorithm;
import edu.stanford.math.plex4.homology.chain_basis.Simplex;
import edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream;

import java.io.*;
import java.nio.*;

public class jplex_persistence {
    static void writePairs(String outputFile, BarcodeCollection<Double> intervals)
        throws IOException {
        FileWriter wr = new FileWriter(outputFile);
        for(int i = 0; i < 3; ++i) {
            for(Interval<Double> pair: intervals.getIntervalsAtDimension(i)) {
                if(pair.isRightInfinite()) {
                    wr.write(i + " " + pair.getStart() + " inf\n");
                } else {
                    wr.write(i + " " + pair.getStart() + " " + pair.getEnd() + "\n");
                }
            }
        }
        wr.close();
    }

    public static void main(String[] args) throws IOException {
        if (args.length < 2) {
            System.out.println("Please provide input and output files");
            System.exit(0);
        }
        SimplicialComplex cpx = new SimplicialComplex(args[0]);
        ExplicitSimplexStream s = cpx.fillStream();
        AbstractPersistenceAlgorithm<Simplex> algo = Plex4.getDefaultSimplicialAlgorithm(3);
        long startTime = System.nanoTime();
        BarcodeCollection<Double> intervals = algo.computeIntervals(s);
        long endTime = System.nanoTime();
        double duration = (endTime - startTime) / 10e9;
        System.out.println("Computed diagram in " + duration + " seconds");
        writePairs(args[1], intervals);
    }
}

class SimplicialComplex {
    public int[] dims;
    public double[] values;
    public int[] edges;
    public int[] triangles;
    public int[] tetras;

    int readInt(InputStream is) throws IOException {
        byte[] ints = new byte[4];
        ByteBuffer buff = ByteBuffer.wrap(ints);
        buff.order(ByteOrder.LITTLE_ENDIAN);
        is.read(ints);
        return buff.getInt();
    }

    double[] readDoubleArray(InputStream is, int size) throws IOException {
        byte[] doubles = new byte[size * 8];
        ByteBuffer buff = ByteBuffer.wrap(doubles);
        buff.order(ByteOrder.LITTLE_ENDIAN);
        is.read(doubles);
        double[] res = new double[size];
        for(int i = 0; i < res.length; i++) {
            res[i] = buff.getDouble();
        }
        return res;
    }

    int[] readIntArray(InputStream is, int size) throws IOException {
        byte[] ints = new byte[size * 4];
        ByteBuffer buff = ByteBuffer.wrap(ints);
        buff.order(ByteOrder.LITTLE_ENDIAN);
        is.read(ints);
        int[] res = new int[size];
        for(int i = 0; i < res.length; i++) {
            res[i] = buff.getInt();
        }
        return res;
    }

    public SimplicialComplex(String inputFile) throws IOException {
        InputStream is = new FileInputStream(inputFile);
        byte[] magic = new byte[20];
        is.read(magic);
        String magic_str = new String(magic);
        if (!magic_str.equals("TTKSimplicialComplex")) {
            System.out.println("Not a TTK Simplicial Complex file");
            return;
        }
        int ncells = readInt(is);
        System.out.println("Number of cells: " + ncells);

        int dim = readInt(is);
        System.out.println("Global dataset dimension: " + dim);

        this.dims = new int[4];
        for(int i = 0; i < dims.length; ++i) {
            this.dims[i] = readInt(is);
            System.out.println("  " + this.dims[i] + " cells of dimension " + i);
        }

        this.values = readDoubleArray(is, ncells);

        int num_entries = readInt(is);
        System.out.println("Number of entries in boundary matrix: " + num_entries);

        this.edges = readIntArray(is, 2 * dims[1]);
        this.triangles = readIntArray(is, 3 * dims[2]);
        this.tetras = readIntArray(is, 4 * dims[3]);
        is.close();
    }

    ExplicitSimplexStream fillStream() {
        ExplicitSimplexStream s = new ExplicitSimplexStream();
        for(int i = 0; i < this.dims[0]; ++i) {
            s.addVertex(i, this.values[i]);
        }
        for(int i = 0; i < this.dims[1]; ++i) {
            int[] a = new int[]{
                this.edges[2 * i + 0],
                this.edges[2 * i + 1],
            };
            s.addElement(a, this.values[this.dims[0] + i]);
        }
        for(int i = 0; i < this.dims[2]; ++i) {
            int[] a = new int[]{
                this.triangles[3 * i + 0],
                this.triangles[3 * i + 1],
                this.triangles[3 * i + 2],
            };
            s.addElement(a, this.values[this.dims[0] + this.dims[1] + i]);
        }
        for(int i = 0; i < this.dims[3]; ++i) {
            int[] a = new int[]{
                this.tetras[4 * i + 0],
                this.tetras[4 * i + 1],
                this.tetras[4 * i + 2],
                this.tetras[4 * i + 3],
            };
            s.addElement(a, this.values[this.dims[0] + this.dims[1] + this.dims[2] + i]);
        }
        s.finalizeStream();
        return s;
    }

}

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top