Consider following code implementing the same business logic as procVector.cpp
(.env) [boris@fedora33server NEWFORWARD]$ cat procVector2.cpp
#include <iostream>
#include <vector>
#include <cstddef>
#include <cmath>
#pragma GCC diagnostic ignored "-Wsign-compare"
namespace abc {
std::vector<std::vector<int> > resultList(int m, int n)
{
std::vector<std::vector<int> > vec;
std::vector<int> v1;
int j,cCount,cntDiv;
for (int i = m; i <= n ; i++) {
cCount = 0 ;
cntDiv = 0 ;
j = 2 ;
while (cCount <= 1 && j <= int(sqrt(i)))
{
if (i%j == 0)
{
cntDiv = j;
cCount +=1;
}
j += 1;
}
if (cCount == 1 && cntDiv != i/cntDiv)
{
v1.push_back(cntDiv);
v1.push_back(i/cntDiv);
vec.push_back(v1);
while (!v1.empty())
{
v1.pop_back();
}
}
}
return vec;
};
} //namespace
import sysconfig
language = 'c++'
std = 'c++20'
default_compile_args = sysconfig.get_config_var('CFLAGS').split()
extra_compile_args = [f"-std={std}", "-Wall", "-Wextra", "-Werror", "-DNDEBUG", "-O3"]
setup(name = 'myModule', version = '1.0', \
ext_modules = [Extension('myModule', ['mainVector.cpp','procVector2.cpp'])])
Now update MyProg.py
(.env) [boris@fedora33server NEWFORWARD]$ cat MyProg.py
import myModule
# a = int(input("Input start number : "))
# b = int(input("Input finish number : "))
# a = 174457
# b = 174505
b = 3044505
myModule.resList(a,b)
lines = []
with open('./outvector.dat') as f:
lines = f.readlines()
Run with new version
for line in lines:
print(line)
No comments:
Post a Comment