#include <amscppnarray/amscppnarray.hpp>

namespace ams
{
namespace narray
{

    static void _intl_printarr(narray<int> &q)
    {
        int I;
        if(q.length>0)
        {
            printf("{");
            for(I=0;I<q.length-1;I++) printf("%d,",q[I]);
            printf("%d}",q[q.length-1]);
        }
        else
        {
            printf("{}");
        }
    }

    static void _intl_printarr(narray<double> &q)
    {
        int I;
        if(q.length>0)
        {
            printf("{");
            for(I=0;I<q.length-1;I++) printf("%1.3f,",q[I]);
            printf("%1.3f}",q[q.length-1]);
        }
        else
        {
            printf("{}");
        }
    }

    void narray_testmath1()
    {
        narray<int> a = {-4,-3,-2,-1,0,1,2,3,4,5};
        narray<int> b;
        int asum = narray_sum(a);
        double amean = narray_mean(a);

        printf("sum(a)=%d\n",asum);
        printf("mean(a)=%1.3f\n",amean);
        printf("stdev(a)=%1.3f\n",narray_stdev(a));
        printf("L2norm(a)=%1.3f\n",narray_L2norm(a));
        printf("min(a)=%d\n",narray_min(a));
        printf("max(a)=%d\n",narray_max(a));

        b = narray_abs(a);
        _intl_printarr(b); printf("\n");

        return;
    }

    void narray_testmath2()
    {
        rand::set_rseed_withtimer();

        narray<double> unif = ams::narray::rand::narray_rand(10000);
        double mn1 = narray_mean(unif);
        double std1 = narray_stdev(unif);
        double mn2,std2;
        
        

        //_intl_printarr(unif); printf("\n");

        unif = unif*2.0-1.0;
        //_intl_printarr(unif); printf("\n");
        mn2 = narray_mean(unif);
        std2 = narray_stdev(unif);


        printf("mn1=%1.3f std1=%1.3f\n",mn1,std1);
        printf("mn2=%1.3f std2=%1.3f\n",mn2,std2);
        

        return;
    }

};
};