def test_ctor(env): if np.double not in detail.scalars(): pytest.skip("unsupported configuration") for dist_vector_t in [ dt.ElDistColumnVector_Double_ElSTAR_ElSTAR_ElELEMENT, dt.ElDistRowVector_Double_ElSTAR_ElSTAR_ElELEMENT, dt.ElDistColumnVector_Double_ElMC_ElMR_ElELEMENT, dt.ElDistRowVector_Double_ElMC_ElMR_ElELEMENT ]: v = dist_vector_t(env.grid, env.n) assert v.length() == env.n
def test_make(env): for dtype in detail.scalars() + detail.complex_scalars(): for vector_t, dist_vector_t in [(dt.ElColumnVector, dt.ElDistColumnVector), (dt.ElRowVector, dt.ElDistRowVector)]: vec_np = np.asarray(np.arange(env.n), order='F', dtype=dtype) vec_el = vector_t.view_from_numpy(vec_np) dvec_el = dist_vector_t.make_view(env.grid, vec_el) assert isinstance(dvec_el, dist_vector_t) assert dvec_el.length() == env.n
def test_make_view(env): for dtype in detail.scalars() + detail.complex_scalars(): mat_np = np.asarray(np.arange(env.m*env.n).reshape(env.m, env.n), order='F', dtype=dtype) mat_el = dt.ElMatrix.view_from_numpy(mat_np) dist_el = dt.MatrixDistribution.make( dt.ElDist.STAR, dt.ElDist.STAR, dt.ElDistWrap.ELEMENT) dmat_el = dt.ElDistMatrix.make_view(env.grid, mat_el, dist_el) assert isinstance(dmat_el, dt.ElDistMatrix) assert dmat_el.size().m == env.m assert dmat_el.size().n == env.n
def test_local(env): for dtype in detail.scalars(): # TODO: Add detail.complex_scalars() for vector_t, dist_vector_t in [(dt.ElColumnVector, dt.ElDistColumnVector), (dt.ElRowVector, dt.ElDistRowVector)]: vec_np = np.asarray(np.arange(env.n), order='F', dtype=dtype) assert vec_np[3] == 3 vec_el = vector_t.view_from_numpy(vec_np) dvec_el = dist_vector_t.make_view(env.grid, vec_el) lcl_el = dvec_el.local() lcl_np = lcl_el.view_to_numpy() lcl_np[3] = -1337 assert vec_np[3] == -1337
def test_local(env): for dtype in detail.scalars(): # TODO: Add detail.complex_scalars() mat_np = np.asarray(np.arange(env.m*env.n).reshape(env.m, env.n), order='F', dtype=dtype) assert mat_np[1, 3] == 2*env.m+3 mat_el = dt.ElMatrix.view_from_numpy(mat_np) dist_el = dt.MatrixDistribution.make( dt.ElDist.STAR, dt.ElDist.STAR, dt.ElDistWrap.ELEMENT) dmat_el = dt.ElDistMatrix.make_view(env.grid, mat_el, dist_el) lcl_el = dmat_el.local() lcl_np = lcl_el.view_to_numpy() lcl_np[1, 3] = -1337 assert mat_np[1, 3] == -1337
def test_ctor_view(env): for dtype in detail.scalars(): for vector_t in [dt.ElColumnVector, dt.ElRowVector]: vec_np = np.asarray(np.arange(env.n), order='F', dtype=dtype) assert vec_np[3] == 3 vec_el = vector_t.view_from_numpy(vec_np) assert isinstance(vec_el, vector_t) assert vec_el.length() == vec_np.size vec_np2 = vec_el.view_to_numpy() assert vec_np.size == vec_np2.size assert not vec_np2.flags.owndata assert np.array_equal(vec_np, vec_np2) vec_np2[3] = 1337 assert vec_np[3] == 1337
def test_copy_redist(env): for dtype in detail.scalars() + detail.complex_scalars(): mat_np = np.asarray(np.arange(env.m*env.n).reshape(env.m, env.n), order='F', dtype=dtype) assert mat_np[1, 3] == 2*env.m+3 mat_el = dt.ElMatrix.view_from_numpy(mat_np) dist_star_star_el = dt.MatrixDistribution.make(dt.ElDist.STAR, dt.ElDist.STAR, dt.ElDistWrap.ELEMENT) dist_mc_mr_el = dt.MatrixDistribution.make(dt.ElDist.MC, dt.ElDist.MR, dt.ElDistWrap.ELEMENT) dist_circ_circ_el = dt.MatrixDistribution.make(dt.ElDist.CIRC, dt.ElDist.CIRC, dt.ElDistWrap.ELEMENT) dist_vc_star_el = dt.MatrixDistribution.make(dt.ElDist.VC, dt.ElDist.STAR, dt.ElDistWrap.ELEMENT) dmat_star_star_el = dt.ElDistMatrix.make_view(env.grid, mat_el, dist_star_star_el) dmat_mc_mr_el = dmat_star_star_el.copy(dist_mc_mr_el) dmat_vc_star_el = dmat_mc_mr_el.copy(dist_vc_star_el) dmat_circ_circ_el = dmat_vc_star_el.copy(dist_circ_circ_el) lcl_star_star_el = dmat_star_star_el.local() lcl_mc_mr_el = dmat_mc_mr_el.local() lcl_vc_star_el = dmat_vc_star_el.local() lcl_circ_circ_el = dmat_circ_circ_el.local() assert dmat_star_star_el.size().m == env.m assert dmat_star_star_el.size().n == env.n assert dmat_mc_mr_el.size().m == env.m assert dmat_mc_mr_el.size().n == env.n assert dmat_vc_star_el.size().m == env.m assert dmat_vc_star_el.size().n == env.n assert dmat_circ_circ_el.size().m == env.m assert dmat_circ_circ_el.size().n == env.n if env.size > 1: assert lcl_vc_star_el.size().m < lcl_star_star_el.size().m assert lcl_vc_star_el.size().n == lcl_star_star_el.size().n lcl_star_star_np = lcl_star_star_el.view_to_numpy() lcl_mc_mr_np = lcl_mc_mr_el.view_to_numpy() # noqa F841 # TODO: Add assert lcl_vc_star_np = lcl_vc_star_el.view_to_numpy() # noqa F841 # TODO: Add assert lcl_circ_circ_np = lcl_circ_circ_el.view_to_numpy() if env.rank == 0: # If this assertion fails due to zeros in the upper matrix indices, then you may try # to use a different MPI point-to-point management layer, e.g. ob1 instead of ucx. # To do so, set and export the OMPI_MCA_pml variable before executing the unit tests: # export OMPI_MCA_pml=ob1 assert np.array_equal(lcl_star_star_np, lcl_circ_circ_np)
def test_ctor_view(env): for dtype in detail.scalars(): mat_np = np.asarray(np.arange(env.m*env.n).reshape(env.m, env.n), order='F', dtype=dtype) assert mat_np[3, 5] == (4-1)*env.n+5 logging.debug(mat_np.flags) logging.debug(mat_np.dtype) logging.debug(str(mat_np)) mat_el = dt.ElMatrix.view_from_numpy(mat_np) assert isinstance(mat_el, dt.ElMatrix) assert mat_el.size().m, mat_el.size().n == mat_np.size mat_np2 = mat_el.view_to_numpy() assert not mat_np2.flags.owndata logging.debug(mat_np2.flags) logging.debug(str(mat_np2)) assert np.array_equal(mat_np, mat_np2) mat_np2[3, 5] = 1337 assert mat_np[3, 5] == 1337 logging.debug(str(mat_np))
def test_copy_redist(env): for dtype in detail.scalars() + detail.complex_scalars(): for vector_t, dist_vector_t in [(dt.ElColumnVector, dt.ElDistColumnVector), (dt.ElRowVector, dt.ElDistRowVector)]: vec_np = np.asarray(np.arange(env.n), order='F', dtype=dtype) assert vec_np[3] == 3 vec_el = vector_t.view_from_numpy(vec_np) dist_star_star_el = dt.MatrixDistribution.make( dt.ElDist.STAR, dt.ElDist.STAR, dt.ElDistWrap.ELEMENT) dist_mc_mr_el = dt.MatrixDistribution.make(dt.ElDist.MC, dt.ElDist.MR, dt.ElDistWrap.ELEMENT) dist_circ_circ_el = dt.MatrixDistribution.make( dt.ElDist.CIRC, dt.ElDist.CIRC, dt.ElDistWrap.ELEMENT) dist_vc_star_el = dt.MatrixDistribution.make( dt.ElDist.VC, dt.ElDist.STAR, dt.ElDistWrap.ELEMENT) dvec_star_star_el = dist_vector_t.make_view( env.grid, vec_el, dist_star_star_el) dvec_mc_mr_el = dvec_star_star_el.copy(dist_mc_mr_el) dvec_vc_star_el = dvec_mc_mr_el.copy(dist_vc_star_el) dvec_circ_circ_el = dvec_vc_star_el.copy(dist_circ_circ_el) dvec_star_star_el2 = dvec_circ_circ_el.copy(dist_star_star_el) lcl_star_star_el = dvec_star_star_el.local() lcl_star_star_el2 = dvec_star_star_el2.local() assert dvec_star_star_el.length() == env.n assert dvec_mc_mr_el.length() == env.n assert dvec_vc_star_el.length() == env.n assert dvec_circ_circ_el.length() == env.n assert dvec_star_star_el2.length() == env.n lcl_star_star_np = lcl_star_star_el.view_to_numpy() lcl_star_star_np2 = lcl_star_star_el2.view_to_numpy() assert np.array_equal(lcl_star_star_np, lcl_star_star_np2)
def test_ctor(env): if np.double not in detail.scalars(): pytest.skip("unsupported configuration") dt.ElDistMatrix_Double_ElSTAR_ElSTAR_ElELEMENT(env.grid, 2, 3).size().n