Пример #1
0
    def setUp(self):
        self.half = frac(1, 2)
        self.div3 = frac(1, 3)
        self.fds = frac(4, 8)
        self.opf = frac(1.5, 3)

        self.x = frac(3, 2)
Пример #2
0
def ridgequantity(w,fs):

	"""RIDGEQUANTITY  The ``ridge quantity'' associated with a wavelet transform.

   WARNING: Type of ridge is here imposed to be "amplitude" (see the matlab version for extra choices).

   RQ,FW = RIDGEQUANTITY(W,FS) returns the ridge quantity RQ associated with the analytic wavelet transform W computed at frequencies FS. RQ is the same size as W. It also returns the transform frequency matrix FW. FW has the radian instantaneous frequency at each scale and is the same size as W.
 
   For details see

       Lilly and Olhede (2010).  On the analytic wavelet transform.
           IEEE Trans. Info. Theory.
   _____________________________________________________________________

   RIDGEQUANTITY is a low-level function called by RIDGEWALK.

   See also RIDGEWALK

   Usage: rq, fw = ridgequantity(w,fs)
   __________________________________________________________________
   This is part of JLAB
   (C) 2009 J.M. Lilly
   Rewritten in python 2.X by G. Lenoir, October 2016"""
	
	from vdiff import vdiff
	from frac import frac
 
	om=np.zeros(w.shape)
	for k in range(w.shape[0]):
		om[k,:]=fs[:]

	#This is dw/ds
	rq=om**2*frac(vdiff(w,2),vdiff(om,2))*frac(np.ones(w.shape),w)
	
	return rq, om
Пример #3
0
 def test_error_init(self):
     try:
         b = False
         x = frac('hello', 'world')
     except:
         b = True
     self.assertEqual(b, True)
Пример #4
0
	def testrecipClosure ( self ):
		"""recip() should give known `ORIGINAL` value with known input"""
		r = re.compile ( 'frac' )
		for fracTup1 in self.knownReciprocalTwiceValues:
			frac1 = eval ( r.sub ( 'frac.frac', fracTup1 ) )
			frac2 = frac.frac ( frac1.numerator, frac1.den () )
			frac1.recip ()
			frac1.recip ()			
			self.assertEqual ( frac1.toString (),  frac2.toString ())
Пример #5
0
	def testpowInvalidInput ( self ):
		"""pow() should raise exceptions with bad input"""
		self.assertRaises ( ValueError, pow, -3, frac.frac ( 1,4 ))
		r = re.compile ( 'frac' )
		for fracBase, fracPow, in self.knownPowBadInputValues:
			frac1 = eval ( r.sub ( 'frac.frac', fracBase ) )
			frac2 = eval ( r.sub ( 'frac.frac', fracPow ) )
#			print frac1, frac2, type ( frac1), type ( frac2) 	
			self.assertRaises ( frac.fracNoneError, pow, frac1, frac2 )
		for fracBase, fracPow, in self.knownrPowBadInputValues:
			frac1 = eval ( r.sub ( 'frac.frac', fracBase ) )
			frac2 = eval ( r.sub ( 'frac.frac', fracPow ) )
#			print frac1, frac2, type ( frac1), type ( frac2) 	
			self.assertRaises ( frac.fracNoneError, pow, frac1, frac2 )
Пример #6
0
 def test_bug_add(self):
     self.assertEqual(self.half + frac(1, 2), frac(1, 1))
Пример #7
0
 def test_reversed(self):
     self.assertEqual(reversed(self.half), frac(2, 1))
Пример #8
0
 def test_mod(self):
     self.assertEqual(self.x % (4, 3), frac(4, 3))
Пример #9
0
 def test_div(self):
     self.assertEqual(1 / self.div3, frac(3, 1))
Пример #10
0
 def test_mul(self):
     self.assertEqual(self.half * self.div3, frac(1, 6))
Пример #11
0
 def test_sub2(self):
     self.assertEqual(frac(11, 2) - 5, frac(1, 2))
Пример #12
0
 def test_sub(self):
     self.assertEqual(1 - self.div3, frac(2, 3))
Пример #13
0
 def test_add(self):
     self.assertEqual(self.half + self.div3, frac(5, 6))
Пример #14
0
import frac

print('A Few Fractions')
f1 = frac.frac(12, 15)  # Reduce to 4/5
f2 = frac.frac(27, 8)  # Irreducible
f3 = frac.frac(5, -2)  # Neg fraction is always neg numer over pos denom
f4 = frac.frac(-5, -2)  # Represent as 5/2
f5 = frac.frac(42)  # Represent as 42/1
f6 = frac.frac(0) # Represent as 0/1
print(f1, f2, f3, f4, f5, f6)
print(type(f1), type(f5))
print()

print("Negation and Absolute Value")
print("Negative of", f1, "=", -f1)
print("Absolute value of", f3, "=", abs(f3))
print()

print('Two-Frac Operations')
f1 = frac.frac(1, 2)
f2 = frac.frac(-2, 3)
print(f1, '+', f2, '=', f1 + f2)
print(f1, '-', f2, '=', f1 - f2)
print(f1, '*', f2, '=', f1 * f2)
print(f1, '/', f2, '=', f1 / f2)
print(f1, '** 3 =', f1 ** 3)
print(f1, '** -3 = ', f1 ** -3)
print()

print('Chained Operations')
f3 = frac.frac(5, 4)
import frac, cnum

f1 = frac.frac(1, 2)
f2 = frac.frac(2, 3)
f3 = frac.frac(1, 3)
f4 = frac.frac(3, 4)
c1 = cnum.cnum(f1, f2)
c2 = cnum.cnum(f3, f4)

print("Comp Nums with Frac Parts")
print(c1, c2)
print()

print("Addition")
print(c1 + c2)
print()

print("Subtraction")
print(c1 - c2)
print()

print("Multiplication")
print(c1 * c2)
print()

print("Division")
print(c1 / c2)
print()

print("Negation")
print(-c1)