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/matanatz/pcnn
05 April 2024, 19:58:56 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • f652ea2
  • /
  • unit_tests
  • /
  • test_pooling.py
Raw File Download Save again
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 ...

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
swh:1:cnt:f9b7b2db8c4ff1a1ede3c476fc71ab2e7c01d60c
origin badgedirectory badge
swh:1:dir:56ad103d4437a671a9a91d9742a91ee87eff36e3
origin badgerevision badge
swh:1:rev:69a739b61e6e5cb32a666e2531bcd39f623936ce
origin badgesnapshot badge
swh:1:snp:67b7691ccc3b4f83512c5ed685a234a29e8aaf7f

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
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 69a739b61e6e5cb32a666e2531bcd39f623936ce authored by matanatz on 17 December 2019, 13:43:05 UTC
Update train.py
Tip revision: 69a739b
test_pooling.py
import tensorflow as tf
import numpy as np
import sys
from scipy.spatial import distance_matrix

sys.path.append('../layers')
from pooling import PoolingLayer
from convlayer_elements import ConvElements


class TestPooling(tf.test.TestCase):

    def run_test(self):
        with self.test_session():

            B = 2
            I = 8
            I_tag = int(I / 2)
            J = 3

            X = np.random.rand(B,I, 3)

            F = np.random.rand(B,I, J)

            idx, startidx = self.fps(X, B, I_tag, I)

            X_tag = X[[[[x] for x in list(range(B))]] + [idx.tolist()]]

            poolOut = np.zeros([B,I_tag, J])
            for b in range(B):
                dist = np.power(distance_matrix(X[b], X[b]), 2)


                for ii in range(I_tag):
                    for jj  in range(J):

                        vals = []
                        for kk in range(I):
                            a = idx[b]

                            minidx = np.argmin(dist[kk, a])
                            if (minidx == ii):
                                vals = vals + [F[b,kk, jj]]

                        poolOut[b,ii, jj] = np.max(vals)

            print(poolOut.shape)
            print (poolOut)

            elm = ConvElements(tf.constant(X,dtype=tf.float32),np.sqrt(I,dtype=np.float32),np.float32(1),np.float32(1))
            m = PoolingLayer(elm,J,J,I_tag).get_layer(tf.constant(F,dtype=tf.float32),use_fps=tf.constant(True,dtype=tf.bool),startidx=startidx)

            self.assertLess (np.linalg.norm(m[1].eval() - poolOut),1.0e-6)
            self.assertLess (np.linalg.norm(m[0].eval() - X_tag),1.0e-6)

    def fps(self,points,B,I_tag,I):
        r = np.sum(points * points, 2)
        r = np.expand_dims(r, axis=2)
        distance = r - 2 * np.matmul(points, np.transpose(points, [0, 2, 1])) + np.transpose(r, [0, 2, 1])
        temp = [[x] for x in list(range(B))]
        idx = np.random.randint(0, I)
        startidx = idx

        if (I_tag > 1):
            gather = np.argmax(distance[:, idx, :], axis=1)
            idx = np.stack([np.array(B * [idx]), gather], axis=1)

            for step in range(2, max(I_tag, 2)):
                gather = distance[[temp] + [idx.tolist()]]

                idx = np.concatenate([idx, np.expand_dims(np.argmax(np.min(gather, 1), 1), 1)], 1)
        else:
            idx = np.array(B * [idx])
        return idx,startidx


TestPooling().run_test()

back to top

Software Heritage — Copyright (C) 2015–2026, 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— Content policy— Contact— JavaScript license information— Web API