Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Build and install STARE e.g. with:
git clone https://github.com/SpatioTemporal/STARE
cd STARE
mkdir build
cd build
cmake ../
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/stare -DSTARE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=NO ..
make
sudo make install

Expand Down
36 changes: 36 additions & 0 deletions examples/joins.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
146 changes: 109 additions & 37 deletions pystare/PySTARE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,52 @@ StareResult _expand_intervals(int64_t* indices, int len, int resolution, bool mu
result.add_indexValues(expandIntervalsMultiRes(si,resolution, multi_resolution));
return result;
}
StareResult _convert_Join_Result(std::list<list<STARE_ENCODE>>* temp){
StareResult result;
STARE_ArrayIndexSpatialValues listValues;
STARE_ArrayIndexes listIndexes;
int index = 0;
std::list<list<STARE_ENCODE>>::iterator it;
for(it = temp->begin(); it != temp->end(); ++it){
listIndexes.push_back(index);
std::list<STARE_ENCODE>::iterator it_j;
for(it_j = it->begin(); it_j != it->end(); ++it_j){
listValues.push_back(*it_j);
index += 1;
}
}
result.addJoinResults(listValues, listIndexes);
return result;

}
StareResult _left_join(srange& one, srange& other){
std::list<list<STARE_ENCODE>>* temp = one.range.leftJoin(&(other.range));
return _convert_Join_Result(temp);
}
StareResult _inner_join(srange& one, srange& other){
std::list<list<STARE_ENCODE>>* temp = one.range.innerJoin(&(other.range));
return _convert_Join_Result(temp);
}
StareResult _full_join(srange& one, srange& other){
std::list<list<STARE_ENCODE>>* temp = one.range.fullJoin(&(other.range));
return _convert_Join_Result(temp);
}

StareResult _merge_list(int64_t* indices1, int len1, int64_t* indices2, int len2){
STARE_ArrayIndexSpatialValues a(indices1, len1 + indices1);
STARE_ArrayIndexSpatialValues b(indices2, len2 + indices2);
STARE_ArrayIndexSpatialValues res;
StareResult result;
int index = 0;
std::list<STARE_ENCODE> *temp = mergeList(a, b);
std::list<STARE_ENCODE>::iterator it;
for(it = temp->begin(); it != temp->end(); ++it)
res.push_back(*it);
temp->clear();
delete temp;
result.add_indexValues(res);
return result;
}

StareResult _to_neighbors(int64_t* indices, int len) {
STARE_ArrayIndexSpatialValues sivs(indices, indices+len);
Expand Down Expand Up @@ -291,10 +337,11 @@ void _intersects(int64_t* indices1, int len1, int64_t* indices2, int len2, int*
intersects[i] = 0;
int istat = r1.intersects(indices2[i]);
if( istat != 0 ) {
intersects[i] = 1;
intersects[i] = 1;
}
}
} else if( method == 1 ) {
}
else if( method == 1 ) {
// Binary sort and search
sort(indices1,indices1+len1);
for(int i=0; i<len2; ++i) {
Expand All @@ -305,47 +352,49 @@ void _intersects(int64_t* indices1, int len1, int64_t* indices2, int len2, int*
int m = (start+end)/2;
bool done = false;
while( !done ) {
m = (start+end)/2;
if(indices1[m] < test_siv) {
start = m+1;
done = start > end;
} else if(indices1[m] > test_siv) {
end = m-1;
done = start > end;
} else {
intersects[i] = 1; done = true;
}
m = (start+end)/2;
if(indices1[m] < test_siv) {
start = m+1;
done = start > end;
}
else if(indices1[m] > test_siv) {
end = m-1;
done = start > end;
}
else {
intersects[i] = 1; done = true;
}
}
if( intersects[i] == 0 ) {
if( (end >= 0) || (start < len1) ) {
if( 0 <= m-1 ) {
if( cmpSpatial(indices1[m-1],test_siv) != 0 ) {
intersects[i] = 1;
}
}
if( (0 <= m) && (m < len1) ) {
if( cmpSpatial(indices1[m],test_siv) != 0 ) {
intersects[i] = 1;
}
}
if( m+1 < len1 ) {
if( cmpSpatial(indices1[m+1],test_siv) != 0 ) {
intersects[i] = 1;
}
}
}
if( (end >= 0) || (start < len1) ) {
if( 0 <= m-1 ) {
if( cmpSpatial(indices1[m-1],test_siv) != 0 ) {
intersects[i] = 1;
}
}
if( (0 <= m) && (m < len1) ) {
if( cmpSpatial(indices1[m],test_siv) != 0 ) {
intersects[i] = 1;
}
}
if( m+1 < len1 ) {
if( cmpSpatial(indices1[m+1],test_siv) != 0 ) {
intersects[i] = 1;
}
}
}
}
}
} else {
}
else {
// Fall-through

for(int i=0; i<len2; ++i) {
intersects[i] = 0;
for(int j=0; j<len1; ++j) {
if (cmpSpatial(indices2[i], indices1[j]) != 0) {
intersects[i] = 1;
break;
}
if (cmpSpatial(indices2[i], indices1[j]) != 0) {
intersects[i] = 1;
break;
}
}
}
}
Expand Down Expand Up @@ -700,7 +749,12 @@ void _coarsen(int64_t* indices, int len,

////////////////////////////////////////////////////////////////////////////////
//
StareResult::~StareResult() {}
StareResult::~StareResult() {
listValues.clear();
listIndexes.clear();
sis.clear();
sisvs.clear();
}
int StareResult::get_size() {
switch( sCase ) {
case ArrayIndexSpatialValues : return get_size_as_values();
Expand Down Expand Up @@ -733,6 +787,14 @@ void StareResult::copy (int64_t* indices, int len) {
; break;
}
}
void StareResult::copy_as_list_list(int64_t* indices1, int len1, int64_t* indices2, int len2){
for(int i = 0; i < min(len1,(int)listValues.size()); ++i) {
indices1[i] = listValues[i];
}
for(int i = 0; i < min(len2,(int)listIndexes.size()); ++i) {
indices2[i] = listIndexes[i];
}
}
void StareResult::copy_as_values (int64_t* indices, int len) {
switch( sCase ) {
case SpatialIntervals :
Expand Down Expand Up @@ -778,13 +840,23 @@ void StareResult::convert() {
//

srange::srange() {}
srange::srange(bool _isGroupLeaves) {
range.tree->isGroupLeaves = _isGroupLeaves;
}

srange::srange(int64_t* indices, int len) {
STARE_ArrayIndexSpatialValues sis(indices, indices+len);
range.addSpatialIntervals(sis);
}
srange::srange(int64_t* indices, int len, bool isGroupLeaves) {
STARE_ArrayIndexSpatialValues sis(indices, indices+len);
range.addSpatialIntervals(sis, isGroupLeaves);
}

srange::~srange() {}
srange::~srange() {
sis.clear();
sivs.clear();
}

void srange::add_intervals(int64_t* indices, int len) {
STARE_SpatialIntervals sis(indices, indices+len);
Expand Down
76 changes: 41 additions & 35 deletions pystare/PySTARE.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ void _set_temporal_resolutions_from_sorted_inplace (int64_t* indices_inplace, in

/****/

enum StareResultCase { SpatialIntervals, ArrayIndexSpatialValues };
typedef std::vector<int> STARE_ArrayIndexes;
enum StareResultCase { SpatialIntervals, ArrayIndexSpatialValues, ArrayIndexes };

class StareResult {
public:
Expand All @@ -135,8 +136,20 @@ class StareResult {
void copy (int64_t* indices, int len);
void copy_as_values (int64_t* indices, int len);
void copy_as_intervals(int64_t* indices, int len);
void copy_as_list_list(int64_t* indices1, int len1, int64_t* indices2, int len2);
void convert();
bool converted = false;
//For join
void addJoinResults(STARE_ArrayIndexSpatialValues values, std::vector<int> indexes){
this->listValues = values;
this->listIndexes = indexes;
this->sCase = ArrayIndexes;
}
int get_listValues_size(){ return listValues.size();}
int get_listIndexes_size(){ return listIndexes.size();}
STARE_ArrayIndexSpatialValues listValues;
STARE_ArrayIndexes listIndexes;
//
STARE_SpatialIntervals sis;
STARE_ArrayIndexSpatialValues sisvs;
StareResultCase sCase;
Expand Down Expand Up @@ -168,11 +181,15 @@ void _adapt_resolution_to_proximity(int64_t* indices, int len, int64_t* range_in
class srange {
public:
srange();
srange(bool isGroupLeaves);
srange(int64_t* indices, int len);
srange(int64_t* indices, int len, bool isGroupLeaves);
virtual ~srange();

void add_intervals(int64_t* indices, int len);
void add_range(const SpatialRange& r) { range.addSpatialRange(r); }
void add_range(const srange& r) {
range.addSpatialRange(r.range);
}

// bool contains(int64_t siv);
bool contains(long long siv);
Expand Down Expand Up @@ -200,42 +217,31 @@ class srange {
STARE_ArrayIndexSpatialValues sivs;

void add_intersect(const srange& one, const srange& other,bool compress) {
// cout << " compress " << compress << endl << flush;

// HstmRange *range1 = new HstmRange(range.range->range->RangeFromIntersection(other.range.range->range,compress)); // NOTE mlr Probably about the safest way to inst. SpatialRange.
// // #define DIAG
// #ifdef DIAG
// KeyPair kp;
// range1->reset();
// range1->getNext(kp);
// cout << "sr_i range1,r->r,nr " << range1 << " " << range1->range << " " << range1->range->nranges() << " : "
// << setw(16) << setfill('0') << hex << kp.lo << " "
// << setw(16) << setfill('0') << hex << kp.hi << " "
// << dec
// << endl << flush;
// EmbeddedLevelNameEncoding leftJustified;
// leftJustified.setId(kp.lo);
// cout << "kp.lo lj " << setw(16) << setfill('0') << hex << leftJustified.getSciDBLeftJustifiedFormat() << endl << flush;
// leftJustified.setId(kp.hi); cout << "kp.hi lj " << setw(16) << setfill('0') << hex << leftJustified.getSciDBLeftJustifiedFormat() << endl << flush;
// cout << " r-r-my_los " << hex << range1->range->my_los << endl << flush;
// cout << dec;
// #endif
// cout << 1000 << endl << flush;
// SpatialRange *res = new SpatialRange(range1);
// Yay! Works: SpatialRange *res = (one.range & other.range);
SpatialRange *res = sr_intersect(one.range,other.range,compress);
// cout << 1100 << " 11 nr = " << res->range->range->nranges() << endl << flush;
// srange result; result.set_tag(999);
range.addSpatialRange(*res);
// STARE_SpatialIntervals sis_res = res->toSpatialIntervals();
// cout << 1150 << endl << flush;
// range.addSpatialIntervals(sis_res);
// cout << 1200 << " 12 nr = " << range.range->range->nranges() << endl << flush;
// res->purge();
// delete res;
// cout << 1300 << endl << flush;
if(res != NULL){
range.addSpatialRange(*res);
//res->print();
//range.purge();
delete res;
}
}
void add_intersect(const srange& one, const srange& other,bool compress, bool isGroupLeaves) {
SpatialRange *res = sr_intersect(one.range,other.range,compress, isGroupLeaves);
if(res != NULL){
range.addSpatialRange(*res);
//res->print();
//range.purge();
delete res;
}
}
void print(){
//range.print();
}
};

StareResult _left_join(srange& one, srange& other);
StareResult _inner_join(srange& one, srange& other);
StareResult _full_join(srange& one, srange& other);
StareResult _merge_list(int64_t* indices1, int len1, int64_t* indices2, int len2);
#endif

2 changes: 2 additions & 0 deletions pystare/PySTARE.i
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ namespace std {
%}
*/


%pythoncode %{%}


%include "PySTARE.h"
Loading