diff --git a/amsmathutil25.code-workspace b/amsmathutil25.code-workspace index a39253d..d691644 100644 --- a/amsmathutil25.code-workspace +++ b/amsmathutil25.code-workspace @@ -8,6 +8,9 @@ }, { "path": "../amscppnarray" + }, + { + "path": "../../sourceprojs23/amscpptimelib" } ] } diff --git a/build_linux64/libamsmathutil25.linux64.a b/build_linux64/libamsmathutil25.linux64.a index cd61525..ddeb585 100644 Binary files a/build_linux64/libamsmathutil25.linux64.a and b/build_linux64/libamsmathutil25.linux64.a differ diff --git a/build_linux64/objstore/amsmathtuil25_test1.o b/build_linux64/objstore/amsmathtuil25_test1.o index 2ab5e26..fff9d60 100644 Binary files a/build_linux64/objstore/amsmathtuil25_test1.o and b/build_linux64/objstore/amsmathtuil25_test1.o differ diff --git a/build_linux64/objstore/amsmathutiil25_random.o b/build_linux64/objstore/amsmathutiil25_random.o index 4a28951..ddb5f35 100644 Binary files a/build_linux64/objstore/amsmathutiil25_random.o and b/build_linux64/objstore/amsmathutiil25_random.o differ diff --git a/build_linux64/objstore/amsmathutil25_amsarray.o b/build_linux64/objstore/amsmathutil25_amsarray.o index df8dc90..3d4d64a 100644 Binary files a/build_linux64/objstore/amsmathutil25_amsarray.o and b/build_linux64/objstore/amsmathutil25_amsarray.o differ diff --git a/build_linux64/objstore/amsmathutil25_amsarray_sort.o b/build_linux64/objstore/amsmathutil25_amsarray_sort.o index b876810..69c66ef 100644 Binary files a/build_linux64/objstore/amsmathutil25_amsarray_sort.o and b/build_linux64/objstore/amsmathutil25_amsarray_sort.o differ diff --git a/build_linux64/objstore/amsmathutil25_mathfns1.o b/build_linux64/objstore/amsmathutil25_mathfns1.o index 13bd9c9..7def272 100644 Binary files a/build_linux64/objstore/amsmathutil25_mathfns1.o and b/build_linux64/objstore/amsmathutil25_mathfns1.o differ diff --git a/build_linux64/objstore/amsmathutil25_utils1.o b/build_linux64/objstore/amsmathutil25_utils1.o new file mode 100644 index 0000000..9232ac3 Binary files /dev/null and b/build_linux64/objstore/amsmathutil25_utils1.o differ diff --git a/build_linux64/tests b/build_linux64/tests index aed5fd0..5db147b 100644 Binary files a/build_linux64/tests and b/build_linux64/tests differ diff --git a/include/amsmathutil25/math/amsmathutil25_complex128.hpp b/include/amsmathutil25/math/amsmathutil25_complex128.hpp index f700ac8..d97f8bc 100644 --- a/include/amsmathutil25/math/amsmathutil25_complex128.hpp +++ b/include/amsmathutil25/math/amsmathutil25_complex128.hpp @@ -13,7 +13,7 @@ namespace cmp complex(); complex(double _r, double _i); - complex(double _r); + explicit complex(double _r); complex(const complex &other); complex& operator=(const complex& other); complex& operator=(const double other); diff --git a/include/amsmathutil25/math/amsmathutil25_complex64.hpp b/include/amsmathutil25/math/amsmathutil25_complex64.hpp index 40c275f..bc1d8db 100644 --- a/include/amsmathutil25/math/amsmathutil25_complex64.hpp +++ b/include/amsmathutil25/math/amsmathutil25_complex64.hpp @@ -13,7 +13,7 @@ namespace cmp complex64(); complex64(float _r, float _i); - complex64(float _r); + explicit complex64(float _r); complex64(const complex64 &other); complex64& operator=(const complex64& other); complex64& operator=(const float other); diff --git a/include/amsmathutil25/random/amsmathutil25_random.hpp b/include/amsmathutil25/random/amsmathutil25_random.hpp index 24dddcb..04f59d6 100644 --- a/include/amsmathutil25/random/amsmathutil25_random.hpp +++ b/include/amsmathutil25/random/amsmathutil25_random.hpp @@ -11,17 +11,36 @@ typedef ::int64_t amsmu_randt2; static const amsmu_randt1 dpr32_mod = ( ((amsmu_randt1)1) << ((amsmu_randt1)30) ) - (amsmu_randt1)1; static const amsmu_randt1 dpr32_mult1 = ( (amsmu_randt1) 1201633 ); -static const amsmu_randt1 dpr32_add1 = ( (amsmu_randt1) 293482 ); +static const amsmu_randt1 dpr32_add1 = ( (amsmu_randt1) 293487 ); static const amsmu_randt2 dpr64_mod = ( ((amsmu_randt2)1) << ((amsmu_randt2)62) ) - (amsmu_randt2)1; static const amsmu_randt2 dpr64_mult1 = ( (amsmu_randt2) 1201633L ); -static const amsmu_randt2 dpr64_add1 = ( (amsmu_randt2) 293482L ); +static const amsmu_randt2 dpr64_add1 = ( (amsmu_randt2) 293487L ); extern amsmu_randt1 dpr32_rseed; extern amsmu_randt2 dpr64_rseed; -amsmu_randt1 dpr32_nextseed(amsmu_randt1 seed); -amsmu_randt2 dpr64_nextseed(amsmu_randt2 seed); +amsmu_randt1 seed32_next(amsmu_randt1 seed); +amsmu_randt2 seed64_next(amsmu_randt2 seed); + +double rand(amsmu_randt1 *seed = &dpr32_rseed); +float randf(amsmu_randt1 *seed = &dpr32_rseed); +double randgaussian(amsmu_randt1 *seed = &dpr32_rseed); +float randgaussianf(amsmu_randt1 *seed = &dpr32_rseed); +int randint(int low, int highexcl, amsmu_randt1 *seed = &dpr32_rseed); +int64_t randintl(int64_t low, int64_t highexcl, amsmu_randt2 *seed = &dpr64_rseed); + +void seed32_set(amsmu_randt1 _seed); +void seed64_set(amsmu_randt2 _seed); +void seed_init_timer(); + +//Threaded generation of random amsarrays + +amsarray amsarray_rand(amsarray_size_t N, amsmu_randt1 *seed = &dpr32_rseed); +amsarray amsarray_randf(amsarray_size_t N, amsmu_randt1 *seed = &dpr32_rseed); + +amsarray amsarray_randint(amsarray_size_t N, int low, int highexcl, amsmu_randt1 *seed = &dpr32_rseed); +amsarray amsarray_randintl(amsarray_size_t N, int64_t low, int64_t highexcl, amsmu_randt2 *seed = &dpr64_rseed); diff --git a/include/amsmathutil25/testing/amsmathutil25_testing.hpp b/include/amsmathutil25/testing/amsmathutil25_testing.hpp index af2311b..488b96d 100644 --- a/include/amsmathutil25/testing/amsmathutil25_testing.hpp +++ b/include/amsmathutil25/testing/amsmathutil25_testing.hpp @@ -8,9 +8,11 @@ namespace amsmathutil25 void test_amsarray1(); void test_amsarray2(); - - void test_select(); void test_amsarray_sort(); + void test_amsarray_select(); + void test_amsarray_sort1(); + + }; //end namespace amsmathutil25 }; //end namespace ams diff --git a/include/amsmathutil25/util/amsmathutil25_amsarray.hpp b/include/amsmathutil25/util/amsmathutil25_amsarray.hpp index 2a5f11b..d0a696b 100644 --- a/include/amsmathutil25/util/amsmathutil25_amsarray.hpp +++ b/include/amsmathutil25/util/amsmathutil25_amsarray.hpp @@ -7,6 +7,8 @@ namespace ams static const int amsarray_success = amsmathutil25_success; static const int amsarray_failure = amsmathutil25_failure; + static const int amsarray_sortthreadpsize = 5000; + template class amsarray { public: @@ -109,6 +111,9 @@ namespace ams // {0, 1, 2, .... N} amsarray permutation_identity(amsarray_size_t _length); +void _debug_amsarray_print(amsarray *array, bool newline=1,int printstyle=0); +void _debug_amsarray_print(amsarray *array, bool newline=1,int printstyle=0); + }; //end namespace ams diff --git a/include/amsmathutil25/util/amsmathutil25_amsarray_sortimpl.hpp b/include/amsmathutil25/util/amsmathutil25_amsarray_sortimpl.hpp index dce9ec5..7aabd83 100644 --- a/include/amsmathutil25/util/amsmathutil25_amsarray_sortimpl.hpp +++ b/include/amsmathutil25/util/amsmathutil25_amsarray_sortimpl.hpp @@ -41,9 +41,10 @@ template int amsarray_quicksort_round( if(v2data[range.a]; - permarray->data[range.a] = permarray->data[range.b-1]; - permarray->data[range.b-1] = tmp; + amsarray_permutation_swap(permarray,range.a,range.b-1); + // tmp = permarray->data[range.a]; + // permarray->data[range.a] = permarray->data[range.b-1]; + // permarray->data[range.b-1] = tmp; } //there is no more work to be done within this range *leftrange = ams::pair(-1,-1); @@ -63,18 +64,28 @@ template int amsarray_quicksort_round( amsarray_permutation_swap(permarray,P,range.b-1); P = range.b-1; + // amsarray_permutation_swap(permarray,P,range.a); + // P = range.a; + + J = range.a; for(I=range.a;Idata[permarray->data[I]],(double)array->data[permarray->data[P]]); + if(array->data[permarray->data[I]]data[permarray->data[P]]) { if(J!=I) { + //printf("debug: swap\n"); amsarray_permutation_swap(permarray,I,J); J++; } else { + //printf("debug: skip\n"); J++; } } @@ -82,7 +93,7 @@ template int amsarray_quicksort_round( if(array->data[permarray->data[J]]data[permarray->data[P]]) { - J++; + J++; amsarray_permutation_swap(permarray,P,J); } @@ -119,6 +130,42 @@ template int amsarray_quicksort_round( return ret; } +template int amsarray_quicksort_subrange( + amsarray *array, //size N - array to sort + amsarray *permarray, //size N - permutation of sorting + ams::pair _range +) +{ + int ret = amsarray_success; + int res; + + amsarray> ranges; + amsarray_size_t rangeptr = 0; + ams::pair range,rangeleft,rangeright; + + ranges.append(_range); + rangeptr = 0; + while(rangeptr=0 && rangeleft.b>rangeleft.a) + { + ranges.append(rangeleft); + } + if(rangeright.a>=0 && rangeright.b>rangeright.a) + { + ranges.append(rangeright); + } + } + + + return ret; +} + template int amsarray_quicksort_unthreaded( amsarray *array, //size N - array to sort amsarray *permarray //size N - permutation of sorting @@ -145,8 +192,10 @@ template int amsarray_quicksort_unthreaded( rangeptr = 0; while(rangeptr=0 && rangeleft.b>rangeleft.a) { @@ -173,31 +222,48 @@ template void amsarray_quicksort_tf( ams::pair rangeleft,rangeright; - res = amsarray_quicksort_round( - array, - permarray, - range, - &rangeleft, - &rangeright - ); - - { //scope wrapper for std::lock_guard - std::lock_guard lock(*threadlock); - //critical section - if(rangeleft.a>=0 && rangeleft.b>rangeleft.a) - { - ranges->append(rangeleft); - } - if(rangeright.a>=0 && rangeright.b>rangeright.a) - { - ranges->append(rangeright); + if(range.b-range.a < amsarray_sortthreadpsize) + { + res = amsarray_quicksort_subrange( + array, + permarray, + range + ); + //there should be no work to be done after this + } + else + { + //range is too big, quicksort the pivot and supply subranges + res = amsarray_quicksort_round( + array, + permarray, + range, + &rangeleft, + &rangeright + ); + + { //scope wrapper for std::lock_guard + std::lock_guard lock(*threadlock); + //critical section + if(rangeleft.a>=0 && rangeleft.b>rangeleft.a) + { + ranges->append(rangeleft); + } + if(rangeright.a>=0 && rangeright.b>rangeright.a) + { + ranges->append(rangeright); + } } + //end critical section (end of function) } - //end critical section (end of function) return; } +//TODO - if the range falls below a specified size, I want to be able to run through +// quicksorting the entire range within a thread before returning + + template int amsarray_quicksort_threaded( amsarray *array, //size N - array to sort amsarray *permarray //size N - permutation of sorting @@ -240,9 +306,13 @@ template int amsarray_quicksort_threaded( nthreads = ranges.length-rangeptr; nthreads = (nthreads>maxthreads) ? maxthreads : nthreads; + //printf("debug: %d %d %ld %ld\n",nthreads,maxthreads,rangeptr,ranges.length); for(I=0;I, array,permarray, @@ -259,6 +329,7 @@ template int amsarray_quicksort_threaded( ret = amsarray_failure; } } + //printf("debug3\n"); for(I=0;I int amsarray_quicksort_threaded( delete threads[I]; threads[I] = NULL; } - rangeptr++; + //rangeptr++; } } @@ -292,7 +363,7 @@ template int amsarray_quicksort( } } - if(array->lengthlength diff --git a/src/amsmathutil25/math/amsmathutil25_mathfns1.cpp b/src/amsmathutil25/math/amsmathutil25_mathfns1.cpp index 5930127..7f5252c 100644 --- a/src/amsmathutil25/math/amsmathutil25_mathfns1.cpp +++ b/src/amsmathutil25/math/amsmathutil25_mathfns1.cpp @@ -2,8 +2,6 @@ namespace ams { -namespace amsmathutil25 -{ bool isnan(double d) { @@ -210,5 +208,4 @@ int64_t abs(int64_t a) return ret; } -}; -}; \ No newline at end of file +}; //end namespace ams \ No newline at end of file diff --git a/src/amsmathutil25/random/amsmathutiil25_random.cpp b/src/amsmathutil25/random/amsmathutiil25_random.cpp index de8a401..fb196bd 100644 --- a/src/amsmathutil25/random/amsmathutiil25_random.cpp +++ b/src/amsmathutil25/random/amsmathutiil25_random.cpp @@ -8,22 +8,387 @@ namespace rand amsmu_randt1 dpr32_rseed; amsmu_randt2 dpr64_rseed; -amsmu_randt1 dpr32_nextseed(amsmu_randt1 seed) +amsmu_randt1 seed32_next(amsmu_randt1 seed) { amsmu_randt1 sret = seed; sret = ams::mod(sret*dpr32_mult1+dpr32_add1,dpr32_mod); return sret; } -amsmu_randt2 dpr64_nextseed(amsmu_randt2 seed) +amsmu_randt2 seed64_next(amsmu_randt2 seed) { amsmu_randt2 sret = seed; sret = ams::mod(sret*dpr64_mult1+dpr64_add1,dpr64_mod); return sret; } +double rand(amsmu_randt1 *seed) +{ + double ret = 0.0; + *seed = seed32_next(*seed); + ret = ((double) *seed) / ((double)(dpr32_mod-1)); + return ret; +} + +float randf(amsmu_randt1 *seed) +{ + float ret = 0.0; + *seed = seed32_next(*seed); + ret = ((float) *seed) / ((float)(dpr32_mod-1)); + return ret; +} + +double randgaussian(amsmu_randt1 *seed) +{ + double ret = 0.0; + double u1,u2; + u1 = rand(seed); + u2 = rand(seed); + if(u1>0.0) + { + ret = ::sqrt(-2.0*::log(u1))*::cos(2.0*ams::pi*u2); + } + return ret; +} + +float randgaussianf(amsmu_randt1 *seed) +{ + float ret = 0.0; + float u1,u2; + u1 = randf(seed); + u2 = randf(seed); + if(u1>0.0f) + { + ret = ::sqrtf(-2.0*::logf(u1))*::cosf(2.0f*ams::pif*u2); + } + return ret; +} + +int randint(int low, int highexcl, amsmu_randt1 *seed) +{ + int ret = 0; + + if(highexcl-low>0) + { + *seed = seed32_next(*seed); + ret = low + (int)((*seed)%(highexcl-low)); + } + + return ret; +} + +int64_t randintl(int64_t low, int64_t highexcl, amsmu_randt2 *seed) +{ + int64_t ret = 0; + + if(highexcl-low>0) + { + *seed = seed64_next(*seed); + ret = low + (int)((*seed)%(highexcl-low)); + } + + return ret; +} + +void seed32_set(amsmu_randt1 _seed) +{ + dpr32_rseed = _seed; + return; +} + +void seed64_set(amsmu_randt2 _seed) +{ + dpr64_rseed = _seed; + return; +} + +void seed_init_timer() +{ + amsmu_randt1 t1 = (amsmu_randt1)time(NULL); + amsmu_randt1 t2 = (amsmu_randt1)(::fmod((double)clock()/((double)CLOCKS_PER_SEC)*1000.0f,36000.0f)); + dpr32_rseed = (amsmu_randt1)t1 + (amsmu_randt1)t2; + + amsmu_randt2 t3 = (amsmu_randt2)time(NULL); + amsmu_randt2 t4 = (amsmu_randt2)(::fmod((double)clock()/((double)CLOCKS_PER_SEC)*1000.0f,36000.0f)); + dpr64_rseed = (amsmu_randt2)t3 + (amsmu_randt2)t4; + + return; +} + +//Threaded generation of random amsarrays + +template void amsarray_rand_threadf1( + amsarray *out, + amsarray *rseeds, + T (*randfunc)(amsmu_randt1 *), + int threadnum, + int nthreads +) +{ + int I0,I1,Is,I; + Is = out->length/nthreads; + I0 = Is*threadnum; + I1 = (threadnum>=(nthreads-1)) ? out->length : Is*(threadnum+1); + for(I=I0;Idata[I] = randfunc(&(rseeds->data[threadnum])); + } + return; +} + +template void amsarray_random_threadexec1( + amsarray *out, + amsarray_size_t N, + T (*randfunc)(amsmu_randt1 *), + amsmu_randt1 *rseed +) +{ + amsarray_size_t I; + int J; + int nthreads; + std::vector threads; + ams::amsarray rseeds; + int res; + + res = out->resize(N); + if(res!=amsarray_success) + { + out->resize(0); + return; + } + + if(Ndata[I] = randfunc(rseed); + } + } + else + { + //multi-threaded operation + nthreads = std::thread::hardware_concurrency(); + nthreads = (nthreads<1) ? 1 : nthreads; + nthreads = (nthreads>amsmathutil25_maxthreads) ? amsmathutil25_maxthreads : nthreads; + threads.resize(nthreads); + rseeds.resize(nthreads); + + for(J=0;J, + out, + &rseeds, + randfunc, + J,nthreads + ); + if(threads[J]==NULL) + { + //handle thread allocation error + printf("warning: amsarray_random_threadexec1:: thread %d failed to allocate.\n",J); + } + } + for(J=0;Jjoin(); + delete threads[J]; + threads[J]= NULL; + } + } + } + + return; +} +amsarray amsarray_rand(amsarray_size_t N, amsmu_randt1 *seed) +{ + amsarray ret; + + if(N<=0) + { + ret.resize(0); + return ret; + } + + amsarray_random_threadexec1( + &ret, + N, + &(rand), + seed + ); + + return ret; +} + +amsarray amsarray_randf(amsarray_size_t N, amsmu_randt1 *seed) +{ + amsarray ret; + + if(N<=0) + { + ret.resize(0); + return ret; + } + + amsarray_random_threadexec1( + &ret, + N, + &(randf), + seed + ); + + return ret; +} + +template void amsarray_rand_threadf2( + amsarray *out, + amsarray *rseeds, + T (*randfunc)(T, T, T2*), + T low, + T highexcl, + int threadnum, + int nthreads +) +{ + int I0,I1,Is,I; + Is = out->length/nthreads; + I0 = Is*threadnum; + I1 = (threadnum>=(nthreads-1)) ? out->length : Is*(threadnum+1); + for(I=I0;Idata[I] = randfunc(low,highexcl,&(rseeds->data[threadnum])); + } + return; +} + +template void amsarray_random_threadexec2( + amsarray *out, + amsarray_size_t N, + T (*randfunc)(T, T, T2*), + T2 (*nextfunc)(T2), + T low, + T highexcl, + T2 *rseed +) +{ + amsarray_size_t I; + int J; + int nthreads; + std::vector threads; + amsarray rseeds; + int res; + + res = out->resize(N); + if(res!=amsarray_success) + { + out->resize(0); + return; + } + + if(Ndata[I] = randfunc(low,highexcl,rseed); + } + } + else + { + //multi-threaded operation + nthreads = std::thread::hardware_concurrency(); + nthreads = (nthreads<1) ? 1 : nthreads; + nthreads = (nthreads>amsmathutil25_maxthreads) ? amsmathutil25_maxthreads : nthreads; + threads.resize(nthreads); + rseeds.resize(nthreads); + for(J=0;J, + out, + &rseeds, + randfunc, + low,highexcl, + J,nthreads + ); + if(threads[J]==NULL) + { + //handle thread allocation error + printf("warning: amsarray_random_threadexec2:: thread %d failed to allocate.\n",J); + } + } + for(J=0;Jjoin(); + delete threads[J]; + threads[J]= NULL; + } + } + } + + return; +} + +amsarray amsarray_randint(amsarray_size_t N, int low, int highexcl, + amsmu_randt1 *rseed) +{ + amsarray ret; + + if(N<=0) + { + ret.resize(0); + return ret; + } + + amsarray_random_threadexec2( + &ret, + N, + &(randint), + &(seed32_next), + low,highexcl, + rseed + ); + + return ret; +} + +amsarray amsarray_randintl(amsarray_size_t N, int64_t low, int64_t highexcl, amsmu_randt2 *rseed) +{ + amsarray ret; + + if(N<=0) + { + ret.resize(0); + return ret; + } + + amsarray_random_threadexec2( + &ret, + N, + &(randintl), + &(seed64_next), + low,highexcl, + rseed + ); + + return ret; +} -}; -}; \ No newline at end of file +}; //end namespace rand +}; //end namespace ams \ No newline at end of file diff --git a/src/amsmathutil25/testing/amsmathtuil25_test1.cpp b/src/amsmathutil25/testing/amsmathtuil25_test1.cpp index ea9a350..48ebb25 100644 --- a/src/amsmathutil25/testing/amsmathtuil25_test1.cpp +++ b/src/amsmathutil25/testing/amsmathtuil25_test1.cpp @@ -87,6 +87,104 @@ void test_amsarray2() { printf("q[%ld]=%1.3f\n",I,q[I]); } +} + +void test_amsarray_select() +{ + int I; + amsarray a; + amsarray b; + amsarray c; + + a = ams::rand::amsarray_rand(100); + + for(I=0;I<10;I++) + { + printf("a[%d]=%1.3f\n",I,a[I]); + } + + b = amsarray({1,3,5,7}); + + c = a.select(b); + + for(I=0;I)ams::rand::amsarray_randintl(10000,0,a.length); + c = a.select(b); + + for(I=b.length/2;I a,b; + amsarray q; + int K; + //int J; + amsarray_size_t bs; + double t0,t1; + + ams::rand::seed_init_timer(); + + + for(K=0;K<10;K++) + { + a = ams::rand::amsarray_rand(10000); + //_debug_amsarray_print(&a,1); + a.sort(); + //_debug_amsarray_print(&a,1); + + bool ordertest = 1; + for(I=0;Ia[I+1]) + { + ordertest = 0; + break; + } + } + if(ordertest==1) + printf("ordering test: passed.\n"); + else + printf("ordering test: failed.\n"); + } + + bs = 100; + for(K=0;K<10;K++) + { + b = ams::rand::amsarray_rand(bs); + t0 = time_msec(); + b.sort(); + t1 = time_msec(); + printf("sorted %ld in %1.3f msec.\n",bs,t1-t0); + bs*=2; + }; + //a.print(); + + // q = permutation_identity(10000); + + + for(I=0;I void amsarray::print(bool newline,int printstyle) { amsarray_size_t I; - printf("{"); if(data!=NULL) { @@ -44,7 +43,6 @@ template<> void amsarray::print(bool newline,int printstyle) template<> void amsarray::print(bool newline,int printstyle) { amsarray_size_t I; - printf("{"); if(data!=NULL) { @@ -63,7 +61,6 @@ template<> void amsarray::print(bool newline,int printstyle) template<> void amsarray::print(bool newline,int printstyle) { amsarray_size_t I; - printf("{"); if(data!=NULL) { @@ -79,10 +76,49 @@ template<> void amsarray::print(bool newline,int printstyle) return; } +void _debug_amsarray_print(amsarray *array, bool newline,int printstyle) +{ + amsarray_size_t I; + + printf("{"); + if(array->data!=NULL) + { + for(I=0;Ilength-1;I++) + { + printf("%ld,",array->data[I]); + } + if(array->length>0) printf("%ld",array->data[array->length-1]); + } + printf("}"); + if(newline==1) printf("\n"); + + return; +} + + +void _debug_amsarray_print(amsarray *array, bool newline,int printstyle) +{ + amsarray_size_t I; + + printf("{"); + if(array->data!=NULL) + { + for(I=0;Ilength-1;I++) + { + printf("%1.4f,",array->data[I]); + } + if(array->length>0) printf("%1.4f",array->data[array->length-1]); + } + printf("}"); + if(newline==1) printf("\n"); + + return; +} + // Explicit Class Instantiations? -template class amsarray; -template class amsarray; -template class amsarray; -template class amsarray; +// template class amsarray; +// template class amsarray; +// template class amsarray; +// template class amsarray; }; \ No newline at end of file diff --git a/src/amsmathutil25/util/amsmathutil25_amsarray_sort.cpp b/src/amsmathutil25/util/amsmathutil25_amsarray_sort.cpp index ed5add2..1c993bd 100644 --- a/src/amsmathutil25/util/amsmathutil25_amsarray_sort.cpp +++ b/src/amsmathutil25/util/amsmathutil25_amsarray_sort.cpp @@ -63,8 +63,8 @@ void amsarray_permutation_swap(amsarray *permutation, amsarray_ { amsarray_size_t tmp; tmp = permutation->data[I]; - permutation->data[J] = permutation->data[I]; - permutation->data[I] = tmp; + permutation->data[I] = permutation->data[J]; + permutation->data[J] = tmp; return; } diff --git a/src/amsmathutil25/util/amsmathutil25_utils1.cpp b/src/amsmathutil25/util/amsmathutil25_utils1.cpp new file mode 100644 index 0000000..8924dcc --- /dev/null +++ b/src/amsmathutil25/util/amsmathutil25_utils1.cpp @@ -0,0 +1,16 @@ +#include + + +namespace ams +{ + +//returns time in msec +double time_msec() +{ + double msec = 0.0; + clock_t c = clock(); + msec = (double)c/(double) CLOCKS_PER_SEC * 1000.0; + return msec; +} + +}; //end namespace ams \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 97ae37e..a774b1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,5 +7,8 @@ int main(int argc, char* argv[]) //ams::amsmathutil25::test_amsarray1(); //ams::amsmathutil25::test_amsarray2(); + //ams::amsmathutil25::test_amsarray_select(); + ams::amsmathutil25::test_amsarray_sort1(); + return ret; } \ No newline at end of file