Ejemplo n.º 1
0
    def test_sqrt(self):
        import math
        from numpypy import sqrt

        nan, inf = float("nan"), float("inf")
        data = [1, 2, 3, inf]
        results = [math.sqrt(1), math.sqrt(2), math.sqrt(3), inf]
        assert (sqrt(data) == results).all()
        assert math.isnan(sqrt(-1))
        assert math.isnan(sqrt(nan))
Ejemplo n.º 2
0
def RR_histogram(X,Y,Xr,Yr,distance,th_min,th_max,theta_bins,cat_number=3):
    
    n_points=len(X)
    #Xmin=1.0*np.floor( np.amin(X) )
    #Xmax=1.0*np.ceil( np.amax(X) )
    #Ymin=1.0*np.floor( np.amin(Y) )
    #Ymax=1.0*np.ceil( np.amax(Y) )
    

    #Xr= Xmin +  ( Xmax - Xmin )*np.random.random_sample(n_points*cat_number)
    #Yr=Ymin +   ( Ymax - Ymin )*np.random.random_sample(n_points*cat_number)
    d_arr=[]

    for m in range(cat_number):
        print "random cat=",m
        for i in range(n_points):
            for j in range(i+1,n_points):
                
                d=(Xr[i + n_points*m ] - Xr[j + n_points*m ])*(Xr[i + n_points*m ] - Xr[j + n_points*m ]) + (Yr[i + n_points*m ] - Yr[j + n_points*m ])*(Yr[i + n_points*m ] - Yr[j + n_points*m ])
                d=np.sqrt(d)/distance
                d_arr=np.append(d_arr,d)
                
    theta=206265*d_arr 
    
    RR,bins=np.histogram(theta,bins=theta_bins, range=(th_min,th_max))
    
    N=1.0*n_points*(1.0*n_points-1.0)/2.0
    N=N*cat_number
    RR=RR/N            
    
    return RR,bins
Ejemplo n.º 3
0
def DR_histogram(X,Y,Xr,Yr,distance,th_min,th_max,theta_bins,cat_number=3):
    n_points=len(X)
    #Xmin=1.0*np.floor( np.amin(X) )
    #Xmax=1.0*np.ceil( np.amax(X) )
    #Ymin=1.0*np.floor( np.amin(Y) )
    #Ymax=1.0*np.ceil( np.amax(Y) )
    

    #Xr= Xmin +  ( Xmax - Xmin )*np.random.random_sample(n_points*cat_number)
    #Yr=Ymin +   ( Ymax - Ymin )*np.random.random_sample(n_points*cat_number)
    d_arr=[]
    print "number of LAEs=" + str(n_points)
    for m in range(cat_number): 
        for i in range(n_points):
	    if(i%100==0):
            	print "LAE_"+str(i)
            for j in range(n_points):
                d=( X[i] - Xr[j + n_points*m] )*( X[i] - Xr[j + n_points*m] ) + ( Y[i] - Yr[j + n_points*m] )*( Y[i] - Yr[j + n_points*m] )
                d=np.sqrt(d)/distance
                d_arr=np.append(d_arr,d)
    theta=206265*d_arr 
    
    DR,bins=np.histogram(theta,bins=theta_bins, range=(th_min,th_max))
    
    N=1.0*n_points*(n_points)
    N=(N*cat_number)            
    DR=DR/N
    
    return DR,bins
Ejemplo n.º 4
0
def only_first_factor(n):
    primes = []
    candidates = np.arange(2, int(np.sqrt(n)))
    for candidate in candidates:
        if n % candidate == 0:
            primes.append(candidate)
            break
    return primes
Ejemplo n.º 5
0
def only_first_factor(n):
  primes = []
  candidates = np.arange(2, int(np.sqrt(n)))
  for candidate in candidates:
    if n % candidate == 0:
      primes.append(candidate)
      break      
  return primes
Ejemplo n.º 6
0
def DD_histogram(X,Y,distance,th_min,th_max,theta_bins):

    n_points=len(X)
    d_arr=[]
    print "number of LAEs=" + str(n_points)
    for i in range(n_points):
        
        if(i%100==0):
            print "LAE_"+str(i)
        for j in range(i+1,n_points):
            d=(X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j])
            d=np.sqrt(d)/distance
            d_arr=np.append(d_arr,d)
            
            
    theta=206265.0*d_arr         
    
    
    DD,bins=np.histogram(theta,bins=theta_bins, range=(th_min,th_max))
    
    N=1.0*n_points*(1.0*n_points-1.0)/2.0
    DD=DD/N
    
    return DD,bins
Ejemplo n.º 7
0
def isPrime(n):
    for x in np.arange(2, int(np.sqrt(n))):
        if n % x == 0:
            return False
    return True
Ejemplo n.º 8
0
 def test_sub_call1(self):
     from numpypy import array, sqrt
     a = array(range(12)).view(self.NoNew)
     b = sqrt(a)
     assert b.called_finalize == True
Ejemplo n.º 9
0
def isPrime(n):
  for x in np.arange(2, int(np.sqrt(n))):
    if n % x == 0:
      return False
  return True
Ejemplo n.º 10
0
Archivo: tsp.py Proyecto: M4573R/algo2
def get_dist(data,i,j):
    return np.sqrt((data[i][0]-data[j][0])*(data[i][0]-data[j][0])+
(data[i][1]-data[j][1])*(data[i][1]-data[j][1]))
Ejemplo n.º 11
0
import random
import math
import numpypy as np

a = np.arange(2, int(np.sqrt(10000000)))
def MillerRabin(n):
    if np.any(n % a == 0):
        return False
    return True

def keygen(bits):
    p = q = 3
    while p == q:
        p = random.randint(2**(bits/2-2),2**(bits/2))
        q = random.randint(2**(bits/2-2),2**(bits/2))
        p += not(p&1)                             # changes the values from 
        q += not(q&1)                             # even to odd

        while MillerRabin(p) == False:            # checks for primality
            p -= 2
        while MillerRabin(q) == False:
            q -= 2
    n = p * q   
    tot = (p-1) * (q-1)
    e = tot
    return e

print keygen(200)