Advertisement
Dmitrey15

Untitled

Jan 24th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
  2.  
  3. class AppTestNumeric(BaseNumpyAppTest):
  4.     def test_zeros_like(self):
  5.         import numpypy as np
  6.         for a in [
  7.                   np.array(1), np.array([1, 2, 3]), np.array([[2.0, 4.0],[3,6]]), np.ones((3, 4, 5)), np.int16(1),
  8.                   np.float32(1), np.zeros((3, 4, 5, 6)), np.array([1, 2], 'int16'), np.array([1, 2], 'float32')
  9.                   ]:
  10.                     b = np.zeros_like(a)
  11.                     assert b.shape == a.shape and a.dtype == b.dtype
  12.                    
  13.         for a in [1, 1.0]:
  14.             b = np.zeros_like(a)
  15.             assert b.shape == ()  and b.size == 1
  16.    
  17.     def test_ones_like(self):
  18.         import numpypy as np
  19.         for a in [
  20.                   np.array(1), np.array([1, 2, 3]), np.array([[2.0, 4.0],[3,6]]), np.ones((3, 4, 5)), np.int16(1),
  21.                   np.float32(1), np.zeros((3, 4, 5, 6)), np.array([1, 2], 'int16'), np.array([1, 2], 'float32')
  22.                   ]:
  23.                     b = np.ones_like(a)
  24.                     assert b.shape == a.shape and a.dtype == b.dtype
  25.                    
  26.         for a in [1, 1.0]:
  27.             b = np.ones_like(a)
  28.             assert b.shape == ()  and b.size == 1
  29.    
  30.     def test_empty_like(self):
  31.         import numpypy as np
  32.         for a in [
  33.                   np.array(1), np.array([1, 2, 3]), np.array([[2.0, 4.0],[3,6]]), np.ones((3, 4, 5)), np.int16(1),
  34.                   np.float32(1), np.zeros((3, 4, 5, 6)), np.array([1, 2], 'int16'), np.array([1, 2], 'float32')
  35.                   ]:
  36.                     b = np.empty_like(a)
  37.                     assert b.shape == a.shape and a.dtype == b.dtype
  38.                    
  39.         for a in [1, 1.0]:
  40.             b = np.empty_like(a)
  41.             assert b.shape == ()  and b.size == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement