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

Revision 384285f1e4152e7b962f0081e629c268bb50d8d7 authored by Jonas on 04 October 2023, 08:33:42 UTC, committed by Jonas on 04 October 2023, 08:33:42 UTC
Add link vide youtube
1 parent ad43f9c
  • Files
  • Changes
  • 1dc96b4
  • /
  • common.py
Raw File Download

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.

  • revision
  • directory
  • content
revision badge
swh:1:rev:384285f1e4152e7b962f0081e629c268bb50d8d7
directory badge
swh:1:dir:1dc96b42fa35ea1865d5fcfe7ecfd14cb2e50ad9
content badge
swh:1:cnt:07d138c36fdfcdc5ac73aec81decef76afb686e0

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.

  • revision
  • directory
  • content
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 ...
common.py
from numba import njit
from numpy import empty
from math import sqrt
from random import uniform

@njit
def vec2(x,y):
	'''Convert two numbers to a 2D numpy array '''
	v = empty((2,),dtype=float)
	v[0] = x
	v[1] = y
	return v

@njit
def vec3(x,y,z):
	'''Convert three numbers to a 2D numpy array '''
	v = empty((3,),dtype=float)
	v[0] = x
	v[1] = y
	v[2] = z
	return v

@njit
def vec4(x,y,z,w):
	'''Convert four numbers to a 2D numpy array '''
	v = empty((4,),dtype=float)
	v[0] = x
	v[1] = y
	v[2] = z
	v[3] = w
	return v

# @njit	
# def V(x, inv_noise_scale, offset):
# 	''' V returns a curl noise vector field'''
# 	p = empty(3)
# 	p[0:2] = x*inv_noise_scale+offset
# 	return scnoise_curl(p)[0:2]

@njit	
def V(x, inv_noise_scale, offset, noise_grad):
	''' V returns a curl noise vector field'''
	p = empty(3)
	p[0:2] = x*inv_noise_scale+offset
	p[2] = 98.45
	g = noise_grad(p)
	gh = vec2(-g[1], g[0])
	return gh

@njit
def Euler(x, dt, inv_noise_scale, offset, noise_grad):
	'''Perform one Euler step of length dt from x along the curl noise vector field'''
	return x + dt * V(x, inv_noise_scale, offset, noise_grad)

@njit
def RK4(x, dt, inv_noise_scale, offset, noise_grad):
	'''Perform one Runge-Kutta 4th order step of length dt from x along the curl noise vector field'''
	a = dt * V(x, inv_noise_scale, offset, noise_grad)
	b = dt * V(x+a/2, inv_noise_scale, offset, noise_grad)
	c = dt * V(x+b/2, inv_noise_scale, offset, noise_grad)
	d = dt * V(x+c, inv_noise_scale, offset, noise_grad)
	return x + (a+2*b+2*c+d)/6



@njit
def rand_vec2():
	'''Convert two numbers to a 2D numpy array '''
	v = empty((2,),dtype=float)
	v[0] = uniform(0,1)
	v[1] = uniform(0,1)
	return v

## UNUSED

@njit
def smoothstep(a,b,x):
	t = x-a/b-a
	if t < 0: return 0
	if 1 < t: return 1
	return 3*t**2-2*t**3

@njit
def Rand(x, dt, inv_noise_scale, offset):
	'''Perform a step of length dt from x in a random direction.'''
	return x + dt * rand_vec2() 

@njit
def NoiseV(x, dt, inv_noise_scale, offset, noise_grad):
	'''Perform a step of length dt from x in a noise vector direction.'''
	p = vec3(0,0,offset)
	p[0:2] = x*inv_noise_scale
	g = noise_grad(p)
	return x + dt * g[0:2]

def L2_star_disc(P):
	n = P.shape[0]
	l2sd = (1/3)**2 
	l2sd -= (2/n) * sum([ 0.25 * (1 - x[0]**2) * (1 - x[1]**2) for x in P])
	s = 0
	for xi in P:
		for xk in P:
			s += (1-max(xi[0], xk[0]))*(1-max(xi[1], xk[1]))
	l2sd += s/(n**2)
	return sqrt(l2sd)
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

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— Content policy— Contact— JavaScript license information— Web API