From 1d6db10387439d1de4d1d9d842f4f4d03749c219 Mon Sep 17 00:00:00 2001 From: Kwan-Yuet Ho Date: Mon, 20 Dec 2021 21:02:41 -0500 Subject: [PATCH 1/4] removing fortran --- graphflow/pagerank/GooglePageRank.py | 11 +----- graphflow/pagerank/f90pagerank.f90 | 57 ---------------------------- graphflow/pagerank/f90pagerank.pyf | 25 ------------ setup.py | 14 ++----- test/test_pagerank.py | 13 ++++--- 5 files changed, 12 insertions(+), 108 deletions(-) delete mode 100644 graphflow/pagerank/f90pagerank.f90 delete mode 100644 graphflow/pagerank/f90pagerank.pyf diff --git a/graphflow/pagerank/GooglePageRank.py b/graphflow/pagerank/GooglePageRank.py index b415ae6..82a6f9a 100644 --- a/graphflow/pagerank/GooglePageRank.py +++ b/graphflow/pagerank/GooglePageRank.py @@ -2,7 +2,6 @@ import numpy as np -from .f90pagerank import f90pagerank as fpr from .cpagerank import pagerank_cython from .. import L1norm, PageRankLanguage @@ -15,12 +14,6 @@ def GoogleMatrix(digraph, beta): return A, nodedict -def CalculatePageRankFromAdjacencyMatrix_Fortran(adjMatrix, nodes, eps=1e-4, maxstep=1000): - r = fpr.compute_pagerank(adjMatrix, eps, maxstep) - nodepr = {node: r[nodes[node]] for node in nodes} - return nodepr - - def CalculatePageRankFromAdjacencyMatrix_Cython(adjMatrix, nodes, eps=1e-4, maxstep=1000): return pagerank_cython(adjMatrix, nodes, eps, maxstep) @@ -40,12 +33,12 @@ def CalculatePageRankFromAdjacencyMatrix_Python(adjMatrix, nodes, eps=1e-4, maxs def CalculatePageRankFromAdjacencyMatrix(adjMatrix, nodes, eps=1e-4, maxstep=1000, - language=PageRankLanguage.FORTRAN, + language=PageRankLanguage.CYTHON, fortran=True): if not fortran: warnings.warn('The boolean variable "fortran" is deprecated.') if language == PageRankLanguage.FORTRAN: - return CalculatePageRankFromAdjacencyMatrix_Fortran(adjMatrix, nodes, eps=eps, maxstep=maxstep) + raise ValueError('Fortran is no longer supported.') elif language == PageRankLanguage.CYTHON: return CalculatePageRankFromAdjacencyMatrix_Cython(adjMatrix, nodes, eps=eps, maxstep=maxstep) else: diff --git a/graphflow/pagerank/f90pagerank.f90 b/graphflow/pagerank/f90pagerank.f90 deleted file mode 100644 index 681e752..0000000 --- a/graphflow/pagerank/f90pagerank.f90 +++ /dev/null @@ -1,57 +0,0 @@ -module f90pagerank - implicit none - private - public l1norm, compute_pagerank - -contains - - function l1norm(length, vec1, vec2) result(l1dist) - integer, intent(in) :: length - real, dimension(length), intent(in) :: vec1, vec2 - real :: l1dist - integer :: i - - l1dist = 0. - do i=1, length - l1dist = l1dist + abs(vec1(i)-vec2(i)) - end do - end function l1norm - - - function compute_pagerank(n, A, eps, maxstep) result(r) - integer, intent(in) :: n - real, dimension(n, n), intent(in) :: A - real, intent(in) :: eps - integer, intent(in) :: maxstep - real, dimension(n) :: r, newr - logical :: converged - integer :: stepid, i - - converged = .false. - do i=1, n - r(i) = 1./n - end do - stepid = 0 - - do - if ((converged) .or. (stepid >= maxstep)) then - exit - end if - - newr = matmul(A, r) - converged = (l1norm(n, newr, r) < eps) - r(:) = newr(:) - stepid = stepid + 1 - end do - end function compute_pagerank - -end module f90pagerank - - -! compiling -! > f2py -h f90pagerank.pyf -m f90pagerank f90pagerank.f90 -! > f2py -c f90pagerank.pyf f90pagerank.f90 - - - - diff --git a/graphflow/pagerank/f90pagerank.pyf b/graphflow/pagerank/f90pagerank.pyf deleted file mode 100644 index 82acdcb..0000000 --- a/graphflow/pagerank/f90pagerank.pyf +++ /dev/null @@ -1,25 +0,0 @@ -! -*- f90 -*- -! Note: the context of this file is case sensitive. - -python module f90pagerank ! in - interface ! in :f90pagerank - module f90pagerank ! in :f90pagerank:f90pagerank.f90 - function l1norm(length,vec1,vec2) result (l1dist) ! in :f90pagerank:f90pagerank.f90:f90pagerank - integer, optional,intent(in),check(len(vec1)>=length),depend(vec1) :: length=len(vec1) - real dimension(length),intent(in) :: vec1 - real dimension(length),intent(in),depend(length) :: vec2 - real :: l1dist - end function l1norm - function compute_pagerank(n,a,eps,maxstep) result (r) ! in :f90pagerank:f90pagerank.f90:f90pagerank - integer, optional,intent(in),check(shape(a,0)==n),depend(a) :: n=shape(a,0) - real dimension(n,n),intent(in) :: a - real intent(in) :: eps - integer intent(in) :: maxstep - real dimension(n) :: r - end function compute_pagerank - end module f90pagerank - end interface -end python module f90pagerank - -! This file was auto-generated with f2py (version:2). -! See http://cens.ioc.ee/projects/f2py2e/ diff --git a/setup.py b/setup.py index 5d84ede..5c84e0f 100644 --- a/setup.py +++ b/setup.py @@ -14,14 +14,6 @@ dynprog_ext_modules = [Extension('graphflow.pagerank.cpagerank', sources=['graphflow/pagerank/cpagerank.c'])] -import numpy as np -from numpy.distutils.core import setup -from numpy.distutils.core import Extension as fortranExtension - -fortran_ext_modules = [fortranExtension('graphflow.pagerank.f90pagerank', - sources=['graphflow/pagerank/f90pagerank.f90', - 'graphflow/pagerank/f90pagerank.pyf'])] - def readme(): with open('README.md') as f: @@ -33,7 +25,7 @@ def install_requirements(): setup(name='graphflow', - version="0.4.2", + version="0.5.0a1", description="Algorithms for Graph Flow Analysis", long_description="Numerical routines for analyzing data represented by graphs", classifiers=[ @@ -66,8 +58,8 @@ def install_requirements(): tests_require=[ 'pandas', ], - include_dirs=[np.get_include()], - ext_modules=fortran_ext_modules+dynprog_ext_modules, + # include_dirs=[np.get_include()], + ext_modules=dynprog_ext_modules, include_package_data=True, test_suite="test", zip_safe=False) diff --git a/test/test_pagerank.py b/test/test_pagerank.py index 9b0f758..e4e3b4b 100644 --- a/test/test_pagerank.py +++ b/test/test_pagerank.py @@ -73,12 +73,13 @@ def setUp(self): self.googlematrix, self.nodedict = graphflow.pagerank.GooglePageRank.GoogleMatrix(graph, 0.15) def testNetwork_fortran(self): - pagerank = graphflow.pagerank.GooglePageRank.CalculatePageRankFromAdjacencyMatrix(self.googlematrix, self.nodedict, language=PageRankLanguage.FORTRAN) - - self.assertEqual(len(pagerank), len(pagerank_answer)) - self.assertEqual(len(set(pagerank.keys()).intersection(set(pagerank_answer.keys()))), len(pagerank)) - for name in pagerank: - self.assertAlmostEqual(pagerank[name], pagerank_answer[name], places=5) + self.assertRaises( + ValueError, + graphflow.pagerank.GooglePageRank.CalculatePageRankFromAdjacencyMatri, + adjMatrix=self.googlematrix, + nodes=self.nodedict, + language=PageRankLanguage.FORTRAN + ) def testNetwork_python(self): pagerank = graphflow.pagerank.GooglePageRank.CalculatePageRankFromAdjacencyMatrix(self.googlematrix, self.nodedict, language=PageRankLanguage.PYTHON) From 494cb97725d7bbeef78eb5bd90a23059f82cf614 Mon Sep 17 00:00:00 2001 From: Kwan-Yuet Ho Date: Mon, 20 Dec 2021 21:09:12 -0500 Subject: [PATCH 2/4] added back numpy in setup.py --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5c84e0f..f22e670 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ # https://stackoverflow.com/questions/7932028/setup-py-for-packages-that-depend-on-both-cython-and-f2py from setuptools import setup +import numpy as np try: from Cython.Build import cythonize @@ -58,7 +59,7 @@ def install_requirements(): tests_require=[ 'pandas', ], - # include_dirs=[np.get_include()], + include_dirs=[np.get_include()], ext_modules=dynprog_ext_modules, include_package_data=True, test_suite="test", From acbf08e1e1dacd8eaf9eff3019baf5a3dfaef682 Mon Sep 17 00:00:00 2001 From: Kwan-Yuet Ho Date: Mon, 20 Dec 2021 21:10:35 -0500 Subject: [PATCH 3/4] typo --- test/test_pagerank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_pagerank.py b/test/test_pagerank.py index e4e3b4b..bbfe328 100644 --- a/test/test_pagerank.py +++ b/test/test_pagerank.py @@ -75,7 +75,7 @@ def setUp(self): def testNetwork_fortran(self): self.assertRaises( ValueError, - graphflow.pagerank.GooglePageRank.CalculatePageRankFromAdjacencyMatri, + graphflow.pagerank.GooglePageRank.CalculatePageRankFromAdjacencyMatrix, adjMatrix=self.googlematrix, nodes=self.nodedict, language=PageRankLanguage.FORTRAN From c33bae69d492458eb08e9fa3cefc4da1de0f9646 Mon Sep 17 00:00:00 2001 From: Kwan-Yuet Ho Date: Fri, 31 Dec 2021 18:01:27 -0500 Subject: [PATCH 4/4] back to 0.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f22e670..f8e200f 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def install_requirements(): setup(name='graphflow', - version="0.5.0a1", + version="0.4.3a1", description="Algorithms for Graph Flow Analysis", long_description="Numerical routines for analyzing data represented by graphs", classifiers=[