def cmktest_inputs3(self): from pysnptools.pstreader import PstData np.random.seed(0) row_property=None col_property=None pstdata = PstData(row=[[1.0,2.0],[3,4],[6,7]], col=np.array([]), val = [[],[],[]], row_property=row_property, col_property=col_property, name="test_read") assert pstdata.row_to_index([[3,4]])[0] == 1 assert np.array_equal(pstdata[1:,:2].row_property,pstdata.row_property[1:]) assert np.array_equal(pstdata[1:,:2].col_property,pstdata.col_property[:2]) logging.info("done with test")
def test_inputs3(self): from pysnptools.pstreader import PstData np.random.seed(0) row_property=None col_property=None pstdata = PstData(row=[[1.0,2.0],[3,4],[6,7]], col=np.array([]), val = [[],[],[]], row_property=row_property, col_property=col_property, name="test_read") assert pstdata.row_to_index([[3,4]])[0] == 1 assert np.array_equal(pstdata[1:,:2].row_property,pstdata.row_property[1:]) assert np.array_equal(pstdata[1:,:2].col_property,pstdata.col_property[:2]) logging.info("done with test")
def cmktest_inputs2(self): from pysnptools.pstreader import PstData np.random.seed(0) row_property=None col_property=None pstdata = PstData(row=np.array([1.0,3,6]), col=np.array(["Aa","Bb"]), val = np.random.normal(.5,2,size=(3,2)), row_property=row_property, col_property=col_property, name="test_read") assert pstdata.row_to_index([3])[0] == 1 assert pstdata.col_to_index(["Aa"])[0] == 0 assert np.array_equal(pstdata[1:,:2].row_property,pstdata.row_property[1:]) assert np.array_equal(pstdata[1:,:2].col_property,pstdata.col_property[:2]) logging.info("done with test")
def test_inputs2(self): from pysnptools.pstreader import PstData np.random.seed(0) row_property=None col_property=None pstdata = PstData(row=np.array([1.0,3,6]), col=np.array(["Aa","Bb"]), val = np.random.normal(.5,2,size=(3,2)), row_property=row_property, col_property=col_property, name="test_read") assert pstdata.row_to_index([3])[0] == 1 assert pstdata.col_to_index(["Aa"])[0] == 0 assert np.array_equal(pstdata[1:,:2].row_property,pstdata.row_property[1:]) assert np.array_equal(pstdata[1:,:2].col_property,pstdata.col_property[:2]) logging.info("done with test")
def test_read(self): np.random.seed(0) row_property=np.array([[1.0,2,2.5],[3,4,4.5],[5,6,6.5]]) col_property=np.array([[1.0,2,2.5,1],[3,4,4.5,3]]) pstdata = PstData(row=np.array([[1.0,2],[3,4],[5,6]]), col=np.array([["A","a"],["B","b"]]), val = np.random.normal(.5,2,size=(3,2)), row_property=row_property, col_property=col_property, name="test_read") assert pstdata.row_to_index([np.array([3.0,4])])[0] == 1 assert pstdata.col_to_index([np.array(["A","a"])])[0] == 0 assert np.array_equal(pstdata[1:,:2].row_property,row_property[1:]) assert np.array_equal(pstdata[1:,:2].col_property,col_property[:2]) pstdata2 = pstdata[:2,:2].read() from pysnptools.kernelreader.test import _fortesting_JustCheckExists _fortesting_JustCheckExists().input(pstdata) _fortesting_JustCheckExists().input(pstdata2) np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata3 = pstdata[[],:].read() assert pstdata3.val.shape[0] == 0 and pstdata3.val.shape[1]==2 pstdata.val = pstdata.val.copy(order='F') pstdata2 = pstdata[:2,:2].read() np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(order='F') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(order='A') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype=None,order='C') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype='float32',order='C') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2].astype(dtype='float32'), decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype='float32',order=None) np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2].astype(dtype='float32'), decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype=None,order='F') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata4 = pstdata[::,::].read(force_python_only=True) np.testing.assert_array_almost_equal(pstdata4.val, pstdata.val, decimal=10) logging.info("done with test")
def test_read(self): np.random.seed(0) row_property=np.array([[1.0,2,2.5],[3,4,4.5],[5,6,6.5]]) col_property=np.array([[1.0,2,2.5,1],[3,4,4.5,3]]) pstdata = PstData(row=np.array([[1.0,2],[3,4],[5,6]]), col=np.array([["A","a"],["B","b"]]), val = np.random.normal(.5,2,size=(3,2)), row_property=row_property, col_property=col_property, name="test_read") assert pstdata.row_to_index([np.array([3.0,4])])[0] == 1 assert pstdata.col_to_index([np.array(["A","a"])])[0] == 0 assert np.array_equal(pstdata[1:,:2].row_property,row_property[1:]) assert np.array_equal(pstdata[1:,:2].col_property,col_property[:2]) pstdata2 = pstdata[:2,:2].read() from pysnptools.kernelreader.test import _fortesting_JustCheckExists _fortesting_JustCheckExists().input(pstdata) _fortesting_JustCheckExists().input(pstdata2) np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata3 = pstdata[[],:].read() assert pstdata3.val.shape[0] == 0 and pstdata3.val.shape[1]==2 pstdata.val = pstdata.val.copy(order='F') pstdata2 = pstdata[:2,:2].read() np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(order='F') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(order='A') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype=None,order='C') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype='float32',order='C') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2].astype(dtype='float32'), decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype='float32',order=None) np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2].astype(dtype='float32'), decimal=10) pstdata2 = pstdata[:2,:2].read(force_python_only=True,dtype=None,order='F') np.testing.assert_array_almost_equal(pstdata2.val, pstdata.val[:2,:2], decimal=10) pstdata4 = pstdata[::,::].read(force_python_only=True) np.testing.assert_array_almost_equal(pstdata4.val, pstdata.val, decimal=10) logging.info("done with test")