Esempio n. 1
0
def primes_gen(start=2,stop=None):
    """generate prime numbers from 'start'"""
    if start==1:
        yield 1 #if we asked for it explicitly
    if start<=2:
        yield 2
    if stop is None:
        candidates=itertools.count(max(start,3),2)
    elif stop>start:
        candidates=itertools2.arange(max(start,3),stop+1,2)
    else: #
        candidates=itertools2.arange(start if start%2 else start-1,stop-1,-2)
    for n in candidates:
        if is_prime(n):
            yield n
Esempio n. 2
0
File: expr.py Progetto: goulu/Goulib
 def points(self, xmin=-1, xmax=1, step=0.1):
     ''':return: x,y lists of float : points for a line plot'''
     if self.isconstant:
         return [xmin, xmax], [self(xmin), self(xmax)]
     x = list(itertools2.arange(xmin, xmax, step))
     y = self(x)
     return x, y
Esempio n. 3
0
    def test_blackbody2color(self):
        from Goulib.table import Table, Cell
        from Goulib.itertools2 import arange

        Table([
            Cell(str(t), style={'background-color': blackBody2Color(t).hex})
            for t in arange(500, 12000, 500)
        ]).save(path + '\\results\\colors.blackbody.html')
Esempio n. 4
0
def primes_gen(start=2, stop=None):
    """generate prime numbers from 'start'"""
    if start == 1:
        yield 1  #if we asked for it explicitly
    if start <= 2:
        yield 2
    elif start % 2 == 0:
        start += 1

    if stop is None:
        candidates = itertools.count(max(start, 3), 2)
    elif stop > start:
        candidates = itertools2.arange(max(start, 3), stop + 1, 2)
    else:  #
        candidates = itertools2.arange(start if start % 2 else start - 1,
                                       stop - 1, -2)
    for n in candidates:
        if is_prime(n):
            yield n
Esempio n. 5
0
    def test___call__(self):
        y = [self.p1(x) for x in range(6)]
        assert_equal(y, [0, 1, 1, 3, 4, 0])

        #periodic function
        assert_equal(self.pb(.5), self.pb(10.5))

        return  # below does'nt work yet...

        #test function of Expr
        y = self.f(arange(0., 2., .1))
        assert_equal(y, [0, 1, 1, 3, 4, 0])
Esempio n. 6
0
    def test___call__(self):
        y=[self.p1(x) for x in range(6)]
        assert_equal(y,[0,1,1,3,4,0])


        #periodic function
        assert_equal(self.pb(.5),self.pb(10.5))

        return # below does'nt work yet...

        #test function of Expr
        y=self.f(arange(0.,2.,.1))
        assert_equal(y,[0,1,1,3,4,0])
 def test___call__(self):
     y=[self.p1(x) for x in range(6)]
     assert_equal(y,[0,1,1,3,4,0])
     return #below doesn't work yet
     y=self.f(arange(0.,2.,.1))
     assert_equal(y,[0,1,1,3,4,0])