def test_prediction_copies(): "prediction properties should be copies" p = testing.micro_prediction() ok_(testing.shares_memory(p, p), "looks like shares_memory failed") ok_(testing.shares_memory(p, p.ids), "p.ids should be a view") ok_(testing.shares_memory(p, p.y), "p.y should be a view") ok_(not testing.shares_memory(p, p.copy()), "should be a copy")
def test_prediction_copies(): "prediction properties should be copies" d = play_data() p = Prediction() p.append(d.ids, d.y) ok_(shares_memory(p, p), "looks like shares_memory failed") ok_(shares_memory(p, p.ids), "p.ids should be a view") ok_(shares_memory(p, p.yhat), "p.yhat should be a view") ok_(not shares_memory(p, p.copy()), "should be a copy")
def test_data_xnew(): "test data.xnew" d = nx.testing.micro_data() x = d.x.copy() x = x[:, -2:] d2 = d.xnew(x) ok_(not shares_memory(d, d2), "data.xnew should return a copy") ok_(d2.xshape[1] == 2, "x should have two columns") assert_array_equal(d2.x, x, "data.xnew corrupted the values") assert_raises(ValueError, d.xnew, x[:4])
def test_data_copies(): "data properties should be copies or views" d = micro_data() ok_(shares_memory(d, d), "looks like shares_memory failed") # copies ok_(not shares_memory(d, d.copy()), "should be a copy") ok_(not shares_memory(d, d.era), "d.era should be a copy") ok_(not shares_memory(d, d.region), "d.region should be a copy") ok_(not shares_memory(d, d.ids), "d.ids should be a copy") # views ok_(shares_memory(d, d.era_float), "d.era_float should be a view") ok_(shares_memory(d, d.region_float), "d.region_float should be a view") ok_(shares_memory(d, d.x), "d.x should be a view") ok_(shares_memory(d, d.y[:]), "d.y[:] should be a view")
def test_data_pca(): "test data.pca" d = nx.play_data() nfactors = (None, 3, 0.5) for nfactor in nfactors: d2 = d.pca(nfactor=nfactor) msg = "data.pca should return a copy" ok_(not shares_memory(d, d2), msg) if nfactor is None: ok_(d.shape == d2.shape, "shape should not change") corr = np.corrcoef(d2.x.T) corr.flat[::corr.shape[0] + 1] = 0 corr = np.abs(corr).max() ok_(corr < 1e-5, "features are not orthogonal")
def test_data_copies(): "data properties should be copies" d = micro_data() ok_(shares_memory(d, d), "looks like shares_memory failed") ok_(~shares_memory(d, d.copy()), "should be a copy") ok_(~shares_memory(d, d.ids), "d.ids should be a copy") ok_(~shares_memory(d, d.era), "d.era should be a copy") ok_(~shares_memory(d, d.region), "d.region should be a copy") ok_(~shares_memory(d, d.x), "d.x should be a copy") ok_(~shares_memory(d, d.y), "d.y should be a copy")