This commit is contained in:
madrocketsci
2025-05-11 12:01:45 -04:00
parent 89210c99cb
commit 8a9f679a6c
8 changed files with 954 additions and 5 deletions

View File

@ -5,12 +5,97 @@ namespace ams
namespace narray
{
void test_narray1()
{
int I;
narray<float> a;
narray<float> *b = NULL;
narray<float> tmp;
b = new(std::nothrow) narray<float>();
a.resize(100);
b->resize(100000);
a.setall(2.5f);
b->setall(3.0f);
for(I=0;I<100000;I++)
{
if(b->at(I)!=3.0f)
{
printf("Error: b[%d]=%1.3f, not %1.3f\n",I,b->at(I),3.0f);
break;
}
}
a.resize(100000);
tmp = a;
a = *b;
*b = tmp;
*b = tmp+a;
for(I=0;I<b->length;I++)
{
if(b->at(I) != tmp[I] + a[I])
{
printf("addition error in index %d",I);
}
}
printf("threaded boolean test: %d\n", (*b==(a+tmp)));
delete b;
return;
}
void test_narray2()
{
int I;
narray<float> a,b,c,d;
a.resize(100000); a.setall(1.0f);
b.resize(100000); for(I=0;I<b.length;I++) b[I] = 0.5f*I;
c.resize(100000); c.setall(2.0f);
d = -a*(b+c);
for(I=0;I<5;I++)
{
printf("d[%d]=%1.3f\n",I,d[I]);
}
printf("d==-a*(b+c):%d\n",d==(-a*(b+c)));
d[50000] = 0.0f;
printf("d==-a*(b+c):%d\n",d==(-a*(b+c)));
}
void test_narray3()
{
int I;
narray<float> a,b,c,d;
a.resize(5); a.setall(1.0f);
b = {0,0.25,0.5,0.675,0.8675};
c.resize(5); c.setall(2.0f);
d = -a*(b+c);
for(I=0;I<5;I++)
{
printf("d[%d]=%1.3f\n",I,d[I]);
}
printf("d==-a*(b+c):%d\n",d==(-a*(b+c)));
d[4] = 0.0f;
printf("d==-a*(b+c):%d\n",d==(-a*(b+c)));
}
}; //end namespace narray
}; //end namespace ams

View File

@ -4,7 +4,9 @@ int main(int argc, char* argv[])
{
int ret = 0;
printf("ams c++ numeric array library tests.\n");
ams::narray::test_narray1();
//ams::narray::test_narray1();
//ams::narray::test_narray2();
ams::narray::test_narray3();
return ret;
}