Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge c82eaca into be69dbf
Browse files Browse the repository at this point in the history
  • Loading branch information
shssf committed Aug 3, 2019
2 parents be69dbf + c82eaca commit 17b2f61
Show file tree
Hide file tree
Showing 40 changed files with 3,578 additions and 2,991 deletions.
10 changes: 4 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.githubpages']
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.githubpages']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -158,7 +158,5 @@
]




# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
23 changes: 13 additions & 10 deletions docs/gh-pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
something like 'current' as a stable URL for the most current version of the """
from __future__ import print_function, division, absolute_import

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
import os
import re
import shutil
Expand All @@ -27,18 +27,20 @@

from subprocess import Popen, PIPE, CalledProcessError, check_call

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

pages_dir = 'gh-pages'
html_dir = '_build/html'
pdf_dir = '_build/latex'
pages_repo = 'https://github.com/IntelLabs/hpat-doc.git'

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------


def sub_environment():
"""Return an environment dict for executing subcommands in."""
env = os.environ.copy()
Expand Down Expand Up @@ -81,15 +83,16 @@ def sh3(cmd):

def init_repo(path):
"""clone the gh-pages repo if we haven't already."""
sh("git clone %s %s"%(pages_repo, path))
sh("git clone %s %s" % (pages_repo, path))
here = os.getcwd()
cd(path)
sh('git checkout gh-pages')
cd(here)

#-----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Script starts
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
if __name__ == '__main__':
# The tag can be given as a positional argument
try:
Expand Down Expand Up @@ -132,7 +135,7 @@ def init_repo(path):
try:
cd(pages_dir)
status = sh2('git status | head -1').decode()
branch = re.match('\#?\s*On branch (.*)$', status).group(1)
branch = re.match(r'\#?\s*On branch (.*)$', status).group(1)
if branch != 'gh-pages':
e = 'On %r, git branch is %r, MUST be "gh-pages"' % (pages_dir,
branch)
Expand Down
3 changes: 3 additions & 0 deletions generate_data/gen_kde.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import hpat


@hpat.jit
def gen_kde(N, file_name):
# np.random.seed(0)
Expand All @@ -13,6 +14,7 @@ def gen_kde(N, file_name):
dset1[:] = points
f.close()


def main():
parser = argparse.ArgumentParser(description='Gen KDE.')
parser.add_argument('--size', dest='size', type=int, default=2000)
Expand All @@ -23,5 +25,6 @@ def main():

gen_kde(N, file_name)


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions generate_data/gen_kde_pq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import time
import hpat


def gen_kde(N, file_name):
# np.random.seed(0)
df = pd.DataFrame({'points': np.random.random(N)})
table = pa.Table.from_pandas(df)
row_group_size = 128
pq.write_table(table, 'kde.parquet', row_group_size)


def main():
parser = argparse.ArgumentParser(description='Gen KDE.')
parser.add_argument('--size', dest='size', type=int, default=2000)
Expand All @@ -23,5 +25,6 @@ def main():

gen_kde(N, file_name)


if __name__ == '__main__':
main()
11 changes: 7 additions & 4 deletions generate_data/gen_linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import time
import hpat


@hpat.jit
def gen_lir(N, D, p, file_name):
# np.random.seed(0)
points = np.random.random((N,D))
responses = np.random.random((N,p))
points = np.random.random((N, D))
responses = np.random.random((N, p))
f = h5py.File(file_name, "w")
dset1 = f.create_dataset("points", (N,D), dtype='f8')
dset1 = f.create_dataset("points", (N, D), dtype='f8')
dset1[:] = points
dset2 = f.create_dataset("responses", (N,p), dtype='f8')
dset2 = f.create_dataset("responses", (N, p), dtype='f8')
dset2[:] = responses
f.close()


def main():
parser = argparse.ArgumentParser(description='Gen Linear Regression.')
parser.add_argument('--samples', dest='samples', type=int, default=2000)
Expand All @@ -30,5 +32,6 @@ def main():

gen_lir(N, D, p, file_name)


if __name__ == '__main__':
main()
7 changes: 5 additions & 2 deletions generate_data/gen_logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import time
import hpat


@hpat.jit
def gen_lir(N, D, file_name):
# np.random.seed(0)
points = np.random.random((N,D))
points = np.random.random((N, D))
responses = np.random.random(N)
f = h5py.File(file_name, "w")
dset1 = f.create_dataset("points", (N,D), dtype='f8')
dset1 = f.create_dataset("points", (N, D), dtype='f8')
dset1[:] = points
dset2 = f.create_dataset("responses", (N,), dtype='f8')
dset2[:] = responses
f.close()


def main():
parser = argparse.ArgumentParser(description='Gen Logistic Regression.')
parser.add_argument('--samples', dest='samples', type=int, default=2000)
Expand All @@ -28,5 +30,6 @@ def main():

gen_lir(N, D, file_name)


if __name__ == '__main__':
main()
4 changes: 3 additions & 1 deletion generate_data/stock_data_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pandas_datareader import data
import h5py


def main():
stocks = pd.read_csv('all_syms.csv')
file_name = "stock_data_all_google.hdf5"
Expand All @@ -11,7 +12,7 @@ def main():
for symbol in stocks.Symbol:
try:
df = data.DataReader(symbol, 'google', start='1/1/2000')
except:
except BaseException:
continue
N = len(df)
grp = f.create_group(symbol)
Expand All @@ -24,5 +25,6 @@ def main():

f.close()


if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions hpat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from ._version import get_versions
import numba

# re-export from Numba
from numba import (typeof, prange, pndindex, gdb, gdb_breakpoint, gdb_init,
stencil, threading_layer, jitclass, objmode)
stencil, threading_layer, jitclass, objmode)
from numba.types import *

import hpat.dict_ext
Expand All @@ -12,7 +13,7 @@
from hpat.distributed_api import dist_time
# legacy for STAC A3, TODO: remove
from hpat.dict_ext import (DictIntInt, DictInt32Int32, dict_int_int_type,
dict_int32_int32_type)
dict_int32_int32_type)
from hpat.str_ext import string_type
from hpat.str_arr_ext import string_array_type
from numba.types import List
Expand All @@ -32,6 +33,5 @@
multithread_mode = False


from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
71 changes: 35 additions & 36 deletions hpat/_cv.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <Python.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <string>

using namespace cv;

void* cv_imread(int64_t *shapes, uint8_t **data, char* file_name);
void cv_resize(int64_t new_rows, int64_t new_cols, uint8_t *data,
uint8_t *in_data, int64_t rows, int64_t cols);
void cv_mat_release(cv::Mat *img);
void cv_delete_buf(void *data);
void* cv_imdecode(int64_t *out_shapes, void* in_data, int64_t in_size, int64_t flags);
void* cv_imread(int64_t* shapes, uint8_t** data, char* file_name);
void cv_resize(int64_t new_rows, int64_t new_cols, uint8_t* data, uint8_t* in_data, int64_t rows, int64_t cols);
void cv_mat_release(cv::Mat* img);
void cv_delete_buf(void* data);
void* cv_imdecode(int64_t* out_shapes, void* in_data, int64_t in_size, int64_t flags);

PyMODINIT_FUNC PyInit_cv_wrapper(void) {
PyObject *m;
PyMODINIT_FUNC PyInit_cv_wrapper(void)
{
PyObject* m;
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT, "cv_wrapper", "No docs", -1, NULL, };
PyModuleDef_HEAD_INIT,
"cv_wrapper",
"No docs",
-1,
NULL,
};
m = PyModule_Create(&moduledef);
if (m == NULL)
{
return NULL;
}

PyObject_SetAttrString(m, "cv_imread",
PyLong_FromVoidPtr((void*)(&cv_imread)));
PyObject_SetAttrString(m, "cv_mat_release",
PyLong_FromVoidPtr((void*)(&cv_mat_release)));
PyObject_SetAttrString(m, "cv_delete_buf",
PyLong_FromVoidPtr((void*)(&cv_delete_buf)));
PyObject_SetAttrString(m, "cv_resize",
PyLong_FromVoidPtr((void*)(&cv_resize)));
PyObject_SetAttrString(m, "cv_imdecode",
PyLong_FromVoidPtr((void*)(&cv_imdecode)));
PyObject_SetAttrString(m, "cv_imread", PyLong_FromVoidPtr((void*)(&cv_imread)));
PyObject_SetAttrString(m, "cv_mat_release", PyLong_FromVoidPtr((void*)(&cv_mat_release)));
PyObject_SetAttrString(m, "cv_delete_buf", PyLong_FromVoidPtr((void*)(&cv_delete_buf)));
PyObject_SetAttrString(m, "cv_resize", PyLong_FromVoidPtr((void*)(&cv_resize)));
PyObject_SetAttrString(m, "cv_imdecode", PyLong_FromVoidPtr((void*)(&cv_imdecode)));
return m;
}


void* cv_imread(int64_t *shapes, uint8_t **data, char* file_name)
void* cv_imread(int64_t* shapes, uint8_t** data, char* file_name)
{

cv::Mat image;
image = cv::imread(std::string(file_name));
if(!image.data )
if (!image.data)
{
std::cerr << "no image found" << '\n';
return 0;
}
if (image.type()!=CV_8UC3)
if (image.type() != CV_8UC3)
{
std::cerr << "image is not uint8 (CV_8UC3)" << '\n';
return 0;
Expand All @@ -54,23 +54,22 @@ void* cv_imread(int64_t *shapes, uint8_t **data, char* file_name)
std::cerr << "image is not continuous" << '\n';
return 0;
}
if (image.channels()!=3)
if (image.channels() != 3)
{
std::cerr << "image is not 3 channels" << '\n';
return 0;
}
// printf("size %d %d\n", image.size[0], image.size[1]);
// image.size is MatSize, returns rows (height) first!
shapes[0] = (int64_t) image.size[0];
shapes[1] = (int64_t) image.size[1];
shapes[0] = (int64_t)image.size[0];
shapes[1] = (int64_t)image.size[1];
shapes[2] = 3; // XXX: assuming 3 channels

*data = image.data;
return new cv::Mat(image);
}

void cv_resize(int64_t new_rows, int64_t new_cols, uint8_t *data,
uint8_t *in_data, int64_t rows, int64_t cols)
void cv_resize(int64_t new_rows, int64_t new_cols, uint8_t* data, uint8_t* in_data, int64_t rows, int64_t cols)
{
// printf("%lld %lld %lld %lld\n", rows, cols, new_rows, new_cols);
// cv::Size takes columns (width) first!
Expand All @@ -82,25 +81,25 @@ void cv_resize(int64_t new_rows, int64_t new_cols, uint8_t *data,
return;
}

void cv_mat_release(cv::Mat *img)
void cv_mat_release(cv::Mat* img)
{
delete img;
return;
}

void* cv_imdecode(int64_t *out_shapes, void* in_data, int64_t in_size, int64_t flags)
void* cv_imdecode(int64_t* out_shapes, void* in_data, int64_t in_size, int64_t flags)
{
//
cv::Mat in_mat = cv::Mat(1, (int)in_size, CV_8UC1, in_data);
cv::Mat image;
image = cv::imdecode(in_mat, (int)flags);
out_shapes[0] = (int64_t) image.size[0];
out_shapes[1] = (int64_t) image.size[1];
out_shapes[0] = (int64_t)image.size[0];
out_shapes[1] = (int64_t)image.size[1];
image.addref();
return image.data;
}

void cv_delete_buf(void *data)
void cv_delete_buf(void* data)
{
delete data;
return;
Expand Down
Loading

0 comments on commit 17b2f61

Please sign in to comment.