This commit is contained in:
madrocketsci committed 2025-06-22 16:48:23 -04:00
commit cad98f8211
64 files changed
+5157

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
Copyright (c) 2023 Aaron M. Schinder
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+9
View File
@@ -0,0 +1,9 @@
# amscppperm1
Numeric array template class library. A numeric array, in addition to the usual array operations, is expected to have numeric data that can be added, subtracted, multiplied, etc.
This numeric array class implements random number generation, threaded vector operations, threaded math and statistics for fast operations on the arrays.
The primary object is the template class narray<T>
ams::narray::narray<T>
+7
View File
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/bash
tar -czvf ../amscppnarray.tar.gz ./*
scp ../amscppnarray.tar.gz aschinder@amssolarempire.com:~/workspace/projects
Binary file not shown.
Binary file not shown.
Binary file not shown.
+813
View File
@@ -0,0 +1,813 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
"""
Copyright Aaron M. Schinder, 2011 - MIT/BSD License
This script contains a bunch of helper functions for generating simple, imperative, hopefully
transparent build scripts using the python language (and nothing else).
I just want the script to do the compiling and linking operations I want it to do in the order
I want it to do it in, finding every relevant source file.
That's it. That's what I want in a build system.
"""
def flist(pth,**kwargs):
"""
flist - list all files in a given directory pth
optional arguments:
recurse - (T/F): Whether to recursively search for files in directory tree
exts - (list): A list of file extensions to search for, otherwise all files
normpath (T/F): whether to normalize path variables after
filelist = flist(pth,**kwargs):
"""
flst = []
if(not('recurse' in kwargs)):
recurse_ = False
else:
recurse_ = kwargs['recurse']
if(not('exts' in kwargs)):
filterexts_ = False
else:
filterexts_ = True
exts = kwargs['exts']
if(not('normpath' in kwargs)):
normpath_ = True
else:
normpath_ = kwargs['normpath']
if(not('linuxpath' in kwargs)):
linuxpath_ = False
else:
linuxpath_ = kwargs['linuxpath']
if(not('followlinks' in kwargs)):
followlinks_ = False
else:
followlinks_ = kwargs['followlinks']
dirlist = []
rawlist = os.listdir(pth)
for F in rawlist:
F2 = os.path.join(pth,F)
if(os.path.isdir(F2)):
b = (followlinks_) or ((not followlinks_) and not(os.path.islink(F2)))
if(b):
if((F2!=".")&(F2!="..")):
dirlist.append(F2)
elif(os.path.isfile(F2)):
flst.append(F2)
#Recurse through directories
if(recurse_):
for D in dirlist:
lst = flist(D,**kwargs)
for L in lst:
flst.append(L)
#Postprocess:
#Filter out all extensions except the selected ext list
if(filterexts_):
flst = filterexts(flst,exts)
#Normalize filename path according to os
if(normpath_):
flst2 = list(flst)
for I in range(0,len(flst2)):
flst[I] = os.path.normpath(flst2[I])
#If linuxpath, convert all \\ to /
#if(linuxpath_):
# flst2 = list(flst)
# for I in range(0,len(flst2)):
# flst[I] = linuxpath(flst2[I])
return flst
def filterexts(flst,exts):
"""
Filters by extensions in a list of files
flst = def filterexts(flst,exts):
"""
flst2 = []
if(isinstance(exts,str)):
exts = list([exts])
for F in flst:
b = False
for ext in exts:
if(ext[0]!='.'):
ext = '.'+ext
F2 = os.path.splitext(F)
if(len(F2)>=2):
ex = F2[1]
if(len(ex)>0):
if(ex[0]!='.'):
ex = '.'+ex
if(ex==ext):
b = True
if(b):
flst2.append(F)
return flst2
#Find a file fname, starting in pth and recursing
#Used for finding library files to link
def findfile(fname,pth,**kwargs):
fullfname = ""
flst = flist(pth,recurse=True)
for F in flst:
F2 = os.path.split(F)[1]
if(F2 == fname):
fullfname = F
return fullfname
def replaceext(fname,ext):
fname2 = ""
if(len(ext)>0):
if(ext[0]!='.'):
ext = '.'+ext
fname2 = os.path.splitext(fname)[0]+ext
else:
fname2 = os.path.splitext(fname)[0]
return fname2
def replaceexts(fnamelist,ext):
"""Takes a list of filenames and returns a list with the extensions replaced by ext """
fname2list = []
for F in fnamelist:
F2 = replaceext(F,ext)
fname2list.append(F2)
return fname2list
def except_contains(lst1,exc):
"""
Takes a list of file names lst1, and removes filenams that match the
list of exceptions exc. Returns a list without the exceptions.
"""
lst2 = []
for item in lst1:
b = 1
for item2 in exc:
fsplit = os.path.split(item)
fn = fsplit[len(fsplit)-1]
if(fn==item2):
b = 0
break
if(b==1):
lst2.append(item)
return lst2
def list_to_sss(lst):
"""List of strings to space-seperated-string"""
lout = ""
for I in range(0,len(lst)-1):
lout = lout + lst[I] + " "
if(len(lst)>0):
lout = lout + lst[len(lst)-1]
return lout
##########################
##System Call Procedures##
##########################
def callproc(cmd, **kwargs):
if(not('logfile' in kwargs)):
use_lf = False
else:
logfile = kwargs['logfile']
if(logfile!=""):
fp = open(kwargs['logfile'],'a+')
use_lf = True
else:
use_lf = False
if(not('echo' in kwargs)):
echo = True
else:
echo = kwargs['echo']
if(echo):
print(cmd)
#encoding/deconding to/from bytes is necessary to use the subprocess command
#in python3.7
#However, only do this in linux
if(sys.platform!='win32'):
cmd2 = cmd.encode(encoding='utf-8')
else:
cmd2 = cmd
proc = subprocess.Popen(cmd2,stderr = subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
out = out.decode(encoding='utf-8')
if(echo):
print(out)
#print(err);
if(use_lf):
fp.writelines(cmd+'\n')
fp.writelines(out+'\n')
if(use_lf):
fp.close()
#############################################
## Compiler, Archive, and Linker Functions ##
#############################################
#MSVC compiler wrapper
def msvc_compile(compilername, srcfile, **kwargs):
if(not('include' in kwargs)):
include = ''
else:
include = kwargs['include']
if(isinstance(include,list)):
include = list_to_sss(include)
if(not('flags' in kwargs)):
flags = ''
else:
flags = kwargs['flags']
if(isinstance(flags,list)):
flags = list_to_sss(flags)
if(not('objext' in kwargs)):
objext = '.obj'
else:
objext = kwargs['objext']
if(not('srcfileflag' in kwargs)):
srcfileflag = '/c'
else:
srcfileflag = kwargs['srcfileflag']
if(not('outfileflag' in kwargs)):
outfileflag = '/Fo:'
else:
outfileflag = kwargs['outfileflag']
if(not('logfile' in kwargs)):
logfile = ""
else:
logfile = kwargs['logfile']
outfile = replaceext(srcfile,objext)
ln = compilername+" "+flags+" "+" "+srcfileflag+" "+srcfile+" "+outfileflag+'"'+outfile+'"'
ln = ln + " " + include
callproc(ln,echo=True,logfile=logfile)
return
#MSVC compiler wrapper
def msvc_compile_list(compiler,srclist,**kwargs):
for S in srclist:
msvc_compile(compiler,S,**kwargs)
return
#gnu-style compiler compile: Should work with gcc, g++, gfortran
def gs_compile(compiler,srcfile,**kwargs):
if(not('include' in kwargs)):
include = ''
else:
include = kwargs['include']
if(isinstance(include,list)):
include = list_to_sss(include)
if(not('flags' in kwargs)):
flags = ''
else:
flags = kwargs['flags']
if(isinstance(flags,list)):
flags = list_to_sss(flags)
if(not('objext' in kwargs)):
objext = '.o'
else:
objext = kwargs['objext']
if(not('srcfileflag' in kwargs)):
srcfileflag = '-c'
else:
srcfileflag = kwargs['srcfileflag']
if(not('outfileflag' in kwargs)):
outfileflag = '-o'
else:
outfileflag = kwargs['outfileflag']
if(not('logfile' in kwargs)):
logfile = ""
else:
logfile = kwargs['logfile']
if(not('smartcompile' in kwargs)):
_smartcompile = True
else:
_smartcompile = kwargs['smartcompile']
#Do I want to make this thing this general?
# if(not(_smartcompile) or smartcompile(srcfile,objext)):
# outfile = replaceext(srcfile,objext)
# ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
# ln = ln + " " + include
# callproc(ln,echo=True,logfile=logfile)
outfile = replaceext(srcfile,objext)
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
ln = ln + " " + include
callproc(ln,echo=True,logfile=logfile)
return
def gs_compile_list(compiler,srclist,**kwargs):
for S in srclist:
gs_compile(compiler,S,**kwargs)
return
def gs_compile_all(compiler,srcdir,srcexts,**kwargs):
if(not('recurse' in kwargs)):
recurse = True
else:
recurse = kwargs['recurse']
srcfils = flist(srcdir,exts=srcexts,recurse=recurse)
for S in srcfils:
gs_compile(compiler,S,**kwargs)
return
def gs_link_all(linker,srcpath,target,**kwargs):
if(not('objext' in kwargs)):
objext = '.o'
else:
objext = kwargs['objext']
if(not('recurse' in kwargs)):
recurse = True
else:
recurse = kwargs['recurse']
objfils = flist(srcpath,exts=objext,recurse=recurse)
oflst = list_to_sss(objfils)
gs_link_list(linker,oflst,target,**kwargs)
return
def gs_link_list(linker,objlist,target,**kwargs):
if(not('objext' in kwargs)):
objext = '.o'
else:
objext = kwargs['objext']
if(not('libdir' in kwargs)):
libdir = ''
else:
libdir = kwargs['libdir']
if(not('staticlibs' in kwargs)):
staticlibs = ''
else:
staticlibs = kwargs['staticlibs']
if(not('libflags' in kwargs)):
libflags = ''
else:
libflags = kwargs['libflags']
if(not('linkerflags' in kwargs)):
linkerflags = ''
else:
linkerflags = kwargs['linkerflags']
if(not('recurse' in kwargs)):
recurse = True
else:
recurse = kwargs['recurse']
if(not('logfile' in kwargs)):
logfile = ''
else:
logfile = kwargs['logfile']
ln = linker+" -o "+target+" "+libdir
ln = ln+" "+objlist+" "+staticlibs+" "+libflags+" "+linkerflags
callproc(ln,logfile=logfile)
return
def msvc_link_list(objlist,target,**kwargs):
linker = 'link'
if(not('objext' in kwargs)):
objext = '.obj'
else:
objext = kwargs['objext']
if(not('libdir' in kwargs)):
libdir = ''
else:
libdir = kwargs['libdir']
if(not('staticlibs' in kwargs)):
staticlibs = ''
else:
staticlibs = kwargs['staticlibs']
if(not('libflags' in kwargs)):
libflags = ''
else:
libflags = kwargs['libflags']
if(not('linkerflags' in kwargs)):
linkerflags = ''
else:
linkerflags = kwargs['linkerflags']
if(not('recurse' in kwargs)):
recurse = True
else:
recurse = kwargs['recurse']
if(not('logfile' in kwargs)):
logfile = ''
else:
logfile = kwargs['logfile']
ln = linker+" "+libdir
ln = ln+" "+objlist+" "+staticlibs+" "+linkerflags
ln = ln+" /out:"+target+" "+libflags
callproc(ln,logfile=logfile)
return
def ar_all(srcpath,arname,**kwargs):
if(not('recurse' in kwargs)):
recurse = True
else:
recurse = kwargs['recurse']
if(not('objext' in kwargs)):
objext = '.o'
else:
objext = kwargs['objext']
objlist = flist(srcpath,exts=objext,recurse=recurse)
ar_list(objlist,arname,**kwargs)
return
def msvc_lib_list(objlist,arname,**kwargs):
objlist2 = list_to_sss(objlist)
ln = "lib "+objlist2+" /out:"+arname
callproc(ln)
return
def ar_list(objlist,arname,**kwargs):
objlist2 = list_to_sss(objlist)
ln = "ar cr "+ arname+" "+objlist2
callproc(ln)
return
def ar_add_list(objlist,arname,**kwargs):
objlist2 = list_to_sss(objlist)
ln = "ar t "+arname+" "+objlist2
callproc(ln)
return
#####################################
## Incremental Compilation Library ##
#####################################
#silently read lines from a text file if exists
def readtextlines(fname):
txtlns = []
if(not os.path.isfile(fname)):
return txtlns
try:
fp = open(fname,"r")
except:
return txtlns
ln = " "
while(ln!=""):
ln = fp.readline()
txtlns.append(ln)
fp.close()
return txtlns
def getincludefnfrage(includeline):
fnfrag = ""
I1 = -1
I2 = -1
for I in range(0,len(includeline)):
if(I1<0 and (includeline[I]=='<' or includeline[I]=='"')):
I1 = I
if(I1>=0 and (includeline[I]=='>' or includeline[I]=='"')):
I2 = I
break
if(I1>=0 and I2>=0):
fnfrag = includeline[I1+1:I2]
return fnfrag
#Returns the name of the source file fname (if it exists)
#and all included filenames
def getsrcandincludes(fname, incdirs):
flist = []
if(os.path.isfile(fname)):
flist.append(fname)
Ilist = 0
while(Ilist<len(flist)):
#recurse through files
f1 = flist[Ilist]
lns = readtextlines(f1)
for J in range(0,len(lns)):
if(lns[J].find("#include")>=0):
fnfrag = getincludefnfrage(lns[J])
for K in range(0,len(incdirs)):
tfn = os.path.join(incdirs[K],fnfrag)
if(os.path.isfile(tfn)):
flist.append(tfn)
break
Ilist = Ilist + 1
return flist
#Returns the name of the object file associated with the source file
#within the object store folder (if it exists)
def getobjfile(fname,objstore,objext = ".o"):
fret = ""
f1 = os.path.split(fname)[1]
f2 = f1
while(os.path.splitext(f2)[1]!=""):
f2 = os.path.splitext(f2)[0]
objext = objext.strip('.')
f3 = os.path.join(objstore,"{}.{}".format(f2,objext))
if(os.path.exists(f3)):
fret = f3
return fret
def getsrctimes(fname, incdirs):
ftimes = []
flst = getsrcandincludes(fname, incdirs)
for I in range(0,len(flst)):
f = flst[I]
mt = os.path.getmtime(f)
ftimes.append(mt)
return ftimes
def getobjtime(fname,objstore,objext=".o"):
ret = -1
fret = getobjfile(fname,objstore,objext)
if(fret!=""):
ret = os.path.getmtime(fret)
return ret
#Decide whether or not to compile source file
def decidecompile(fname,**kwargs):
ret = True
if(not os.path.isfile(fname)):
ret = False
return ret
##unpack kwargs
if("searchincdirs" in kwargs):
incdirs = kwargs["searchincdirs"]
else:
incdirs = ["./include"]
if("objext" in kwargs):
objext = kwargs["objext"]
else:
objext = ".o"
if("objstore" in kwargs):
objstore = kwargs["objstore"]
else:
objstore = "./objstore"
srclist = getsrcandincludes(fname,incdirs)
srctlist = getsrctimes(fname,incdirs)
obj = getobjfile(fname,objstore,objext)
objt = getobjtime(fname,objstore,objext)
if(obj!=""):
ret = False
for I in range(0,len(srctlist)):
if(srctlist[I]>objt):
ret = True
break
return ret
def gs_incremental_compile(compiler,srcfile,**kwargs):
if(not('include' in kwargs)):
include = ''
else:
include = kwargs['include']
if(isinstance(include,list)):
include = list_to_sss(include)
if(not('flags' in kwargs)):
flags = ''
else:
flags = kwargs['flags']
if(isinstance(flags,list)):
flags = list_to_sss(flags)
if(not('objext' in kwargs)):
objext = '.o'
else:
objext = kwargs['objext']
if(not('srcfileflag' in kwargs)):
srcfileflag = '-c'
else:
srcfileflag = kwargs['srcfileflag']
if(not('outfileflag' in kwargs)):
outfileflag = '-o'
else:
outfileflag = kwargs['outfileflag']
if(not('logfile' in kwargs)):
logfile = ""
else:
logfile = kwargs['logfile']
if(not('smartcompile' in kwargs)):
_smartcompile = True
else:
_smartcompile = kwargs['smartcompile']
#incrementalcompile
if("searchincdirs" in kwargs):
incdirs = kwargs["searchincdirs"]
else:
incdirs = ["./include"]
if("objstore" in kwargs):
objstore = kwargs["objstore"]
else:
objstore = "./objstore"
#Do I want to make this thing this general?
docompile = decidecompile(srcfile,**kwargs)
if(docompile):
f1 = os.path.split(srcfile)[1]
f2 = f1
while(os.path.splitext(f2)[1]!=""):
f2 = os.path.splitext(f2)[0]
outfile = os.path.join(objstore,"{}{}".format(f2,objext))
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
ln = ln + " " + include
callproc(ln,echo=True,logfile=logfile)
return
def msvc_incremental_compile(compiler,srcfile,**kwargs):
if(not('include' in kwargs)):
include = ''
else:
include = kwargs['include']
if(isinstance(include,list)):
include = list_to_sss(include)
if(not('flags' in kwargs)):
flags = ''
else:
flags = kwargs['flags']
if(isinstance(flags,list)):
flags = list_to_sss(flags)
if(not('objext' in kwargs)):
objext = '.obj'
else:
objext = kwargs['objext']
if(not('srcfileflag' in kwargs)):
srcfileflag = '/c'
else:
srcfileflag = kwargs['srcfileflag']
if(not('outfileflag' in kwargs)):
outfileflag = '/Fo'
else:
outfileflag = kwargs['outfileflag']
if(not('logfile' in kwargs)):
logfile = ""
else:
logfile = kwargs['logfile']
#incrementalcompile
if("searchincdirs" in kwargs):
incdirs = kwargs["searchincdirs"]
else:
incdirs = ["./include"]
if("objstore" in kwargs):
objstore = kwargs["objstore"]
else:
objstore = "./objstore"
#Do I want to make this thing this general?
docompile = decidecompile(srcfile,**kwargs)
if(docompile):
f1 = os.path.split(srcfile)[1]
f2 = f1
while(os.path.splitext(f2)[1]!=""):
f2 = os.path.splitext(f2)[0]
outfile = os.path.join(objstore,"{}{}".format(f2,objext))
outfile = os.path.normpath(outfile)
ln = compiler+" "+flags+" "+srcfileflag+" "+srcfile+" "+ outfileflag+'"'+outfile+'"'
ln = ln + " " + include
callproc(ln,echo=True,logfile=logfile)
return
def gs_incremental_compile_list(compiler,srclist,**kwargs):
for s in srclist:
gs_incremental_compile(compiler,s,**kwargs)
return
def msvc_incremental_compile_list(compiler,srclist,**kwargs):
for s in srclist:
msvc_incremental_compile(compiler,s,**kwargs)
return
#######################
## Main Script Tests ##
#######################
def testtimes(args):
if(len(args)>=2):
flist = getsrcandincludes(args[1],["./include"])
ftlist = getsrctimes(args[1],["./include"])
for I in range(0,len(flist)):
print("{}\t\t{}".format(flist[I],ftlist[I]))
print("associated obj file:")
fobj = getobjfile(args[1],"./objstore")
ftobj = getobjtime(args[1],"./objstore")
if(fobj!=""):
print("{}\t\t{}".format(fobj,ftobj))
else:
print("none found")
cflag = decidecompile(args[1])
print("compile? : {}".format(cflag))
return
# if(__name__ == "__main__"):
# args = sys.argv
# testtimes(args)
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
import shutil
from shutil import copytree
from amsbuildlib4 import *
libname = "amscppnarray25.linux64" #static library name to generate
binname = "tests" #create this executable when compiling main.c or main.cpp
commondir = "../../linux64" #common directory to pul libraries and includes from
installdir = "../../linux64" #directory to install to when finished
builddir = "./build_linux64"
doinstall = True #copies the build_output to the install dir when finished
cc = "g++" #compiler
cflags = "-fPIC -O3"
libraries = "-l{}".format(libname)
libdirs = "-L{} -L{}/lib".format(builddir,commondir)
linkerflags = "-static -static-libgcc -Wl,-rpath=."
srcexts = [".c",".cpp"]
binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library
#keyword list to control the compilers/linkers
kwargs = dict()
include = "-I./include -I{}/include".format(commondir)
kwargs["include"] = include
kwargs["flags"] = cflags
kwargs["libdir"] = libdirs
kwargs["libflags"] = libraries
kwargs["linkerflags"] = linkerflags
kwargs["recurse"] = True
kwargs["objstore"] = "{}/objstore".format(builddir)
kwargs["searchincdirs"] = "./include"
#Find all source files, except the main project files
srcfiles = flist('./src',exts = srcexts, recurse=True)
srcfiles = except_contains(srcfiles,binsrc)
#compile all the source files in the list
#gs_compile_list(cc,files,**kwargs)
gs_incremental_compile_list(cc,srcfiles,**kwargs)
#archive all the source files into a static library
objlist = flist(kwargs['objstore'],exts='.o',recurse=True)
ar_list(objlist,'{}/lib{}.a'.format(builddir,libname))
if(doinstall):
#Copy a binary to the common bin folder
#Push any libraries to the common lib folder
shutil.copy('{}/lib{}.a'.format(builddir,libname),"{}/lib".format(commondir))
#Copy include files to the common include folder
copytree('./include/',commondir+'/include/',dirs_exist_ok=True)
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
import shutil
from shutil import copytree
from amsbuildlib4 import *
libname = "amscppnarray25.linux64" #static library name to generate
binname = "tests" #create this executable when compiling main.c or main.cpp
commondir = "../../linux64" #common directory to pul libraries and includes from
installdir = "../../linux64" #directory to install to when finished
builddir = "./build_linux64"
doinstall = True #copies the build_output to the install dir when finished
cc = "g++" #compiler
cflags = "-fPIC"
libraries = "-l{} -lamsmathutil25.linux64".format(libname)
libdirs = "-L{} -L{}/lib".format(builddir,commondir)
linkerflags = "-static -static-libgcc -Wl,-rpath=."
srcexts = [".c",".cpp"]
binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library
#keyword list to control the compilers/linkers
kwargs = dict()
include = "-I./include -I{}/include".format(commondir)
kwargs["include"] = include
kwargs["flags"] = cflags
kwargs["libdir"] = libdirs
kwargs["libflags"] = libraries
kwargs["linkerflags"] = linkerflags
kwargs["recurse"] = True
kwargs["objstore"] = "{}/objstore".format(builddir)
kwargs["searchincdirs"] = "./include"
#Pull required binary dynamic libraries to the bin folder
#shutil.copy('{}/lib/libcamsimg3.linux64.so'.format(commondir),builddir);
#shutil.copy('{}/lib/libamsimg.dll'.format(commondir),builddir);
#shutil.copy('{}/lib/glew32.dll','./bin_winx64');
#Designate source files for main test program
fsrc = ['./src/main.cpp']
fobj = replaceexts(fsrc,'.o')
#Compile test programs
gs_compile_list(cc,fsrc,**kwargs)
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(builddir,binname),**kwargs)
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
import shutil
from shutil import copytree
from amsbuildlib4 import *
libname = "amscppnarray25.mingw64" #static library name to generate
binname = "tests" #create this executable when compiling main.c or main.cpp
commondir = "../../winx64" #common directory to pul libraries and includes from
depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and their includes
installdir = "../../winx64" #directory to install to when finished
builddir = "./build_mingw64"
doinstall = True #copies the build_output to the install dir when finished
cc = "x86_64-w64-mingw32-g++" #compiler
cflags = "-fPIC -O3"
libraries = "-l{}".format(libname)
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
linkerflags = "-static -static-libgcc -Wl,-rpath=."
srcexts = [".c",".cpp"]
binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library
#keyword list to control the compilers/linkers
kwargs = dict()
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
kwargs["include"] = include
kwargs["flags"] = cflags
kwargs["libdir"] = libdirs
kwargs["libflags"] = libraries
kwargs["linkerflags"] = linkerflags
kwargs["recurse"] = True
kwargs["objstore"] = "{}/objstore".format(builddir)
kwargs["searchincdirs"] = "./include"
#Find all source files, except the main project files
srcfiles = flist('./src',exts = srcexts, recurse=True)
srcfiles = except_contains(srcfiles,binsrc)
#compile all the source files in the list
#gs_compile_list(cc,files,**kwargs)
gs_incremental_compile_list(cc,srcfiles,**kwargs)
#archive all the source files into a static library
objlist = flist(kwargs['objstore'],exts='.o',recurse=True)
ar_list(objlist,'{}/lib{}.a'.format(builddir,libname))
if(doinstall):
#Copy a binary to the common bin folder
#Push any libraries to the common lib folder
shutil.copy('{}/lib{}.a'.format(builddir,libname),"{}/lib".format(commondir))
#Copy include files to the common include folder
copytree('./include/',commondir+'/include/',dirs_exist_ok=True)
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
import shutil
from shutil import copytree
from amsbuildlib4 import *
libname = "amscppnarray25.mingw64" #static library name to generate
binname = "tests" #create this executable when compiling main.c or main.cpp
commondir = "../../winx64" #common directory to pul libraries and includes from
depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and their includes
installdir = "../../winx64" #directory to install to when finished
builddir = "./build_mingw64"
doinstall = False #copies the build_output to the install dir when finished
cc = "x86_64-w64-mingw32-g++" #compiler
cflags = "-fPIC -O3"
libraries = "-l{} -lamsmathutil25.mingw64".format(libname)
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
linkerflags = "-static -static-libgcc -Wl,-rpath=."
srcexts = [".c",".cpp"]
binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library
#keyword list to control the compilers/linkers
kwargs = dict()
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
kwargs["include"] = include
kwargs["flags"] = cflags
kwargs["libdir"] = libdirs
kwargs["libflags"] = libraries
kwargs["linkerflags"] = linkerflags
kwargs["recurse"] = True
kwargs["objstore"] = "{}/objstore".format(builddir)
kwargs["searchincdirs"] = "./include"
#Pull required binary dynamic libraries to the bin folder
#shutil.copy('{}/lib/libcamsimg3.linux64.so'.format(commondir),builddir);
#shutil.copy('{}/lib/libamsimg.dll'.format(commondir),builddir);
#shutil.copy('{}/lib/glew32.dll','./bin_winx64');
#Designate source files for main test program
fsrc = ['./src/main.cpp']
fobj = replaceexts(fsrc,'.o')
#Compile test programs
gs_compile_list(cc,fsrc,**kwargs)
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(builddir,binname),**kwargs)
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
import shutil
from shutil import copytree
from amsbuildlib4 import *
libname = "amscppnarray25.msvc64" #static library name to generate
binname = "tests.exe" #create this executable when compiling main.c or main.cpp
commondir = "../../winx64" #common directory to pul libraries and includes from
depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and their includes
installdir = "../../winx64" #directory to install to when finished
builddir = "./build_msvc64"
doinstall = True #copies the build_output to the install dir when finished
cc = "cl" #compiler
cflags = "/O2 /EHsc"
libraries = "lib{}.lib libamsmathutil2.msvc64.lib".format(libname)
libdirs = "/LIBPATH:{} /LIBPATH:{}/lib /LIBPATH:{}/lib".format(builddir,commondir,depdir)
linkerflags = "-static -static-libgcc -Wl,-rpath=."
srcexts = [".c",".cpp"]
binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library
#keyword list to control the compilers/linkers
kwargs = dict()
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
kwargs["include"] = include
kwargs["flags"] = cflags
kwargs["libdir"] = libdirs
kwargs["libflags"] = libraries
kwargs["linkerflags"] = linkerflags
kwargs["recurse"] = True
kwargs["objstore"] = "{}/objstore".format(builddir)
kwargs["searchincdirs"] = "./include"
kwargs["objext"] = ".obj"
#Find all source files, except the main project files
srcfiles = flist('./src',exts = srcexts, recurse=True)
srcfiles = except_contains(srcfiles,binsrc)
#compile all the source files in the list
#gs_compile_list(cc,files,**kwargs)
msvc_incremental_compile_list(cc,srcfiles,**kwargs)
#archive all the source files into a static library
objlist = flist(kwargs['objstore'],exts='.obj',recurse=True)
msvc_lib_list(objlist,'{}/lib{}.lib'.format(builddir,libname))
if(doinstall):
#Copy a binary to the common bin folder
#Push any libraries to the common lib folder
shutil.copy('{}/lib{}.lib'.format(builddir,libname),"{}/lib".format(commondir))
#Copy include files to the common include folder
copytree('./include/',commondir+'/include/',dirs_exist_ok=True)
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/python3
import os,sys,math
import subprocess
import shutil
from shutil import copytree
from amsbuildlib4 import *
libname = "amscppnarray25.msvc64" #static library name to generate
binname = "tests.exe" #create this executable when compiling main.c or main.cpp
commondir = "../../winx64" #common directory to pul libraries and includes from
depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and their includes
installdir = "../../winx64" #directory to install to when finished
builddir = "./build_msvc64"
doinstall = True #copies the build_output to the install dir when finished
cc = "cl" #compiler
cflags = "/O2 /EHsc"
libraries = "lib{}.lib libamsmathutil2.msvc64.lib".format(libname)
libdirs = "/LIBPATH:{} /LIBPATH:{}/lib /LIBPATH:{}/lib".format(builddir,commondir,depdir)
linkerflags = "-static -static-libgcc -Wl,-rpath=."
srcexts = [".c",".cpp"]
binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library
#keyword list to control the compilers/linkers
kwargs = dict()
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
kwargs["include"] = include
kwargs["flags"] = cflags
kwargs["libdir"] = libdirs
kwargs["libflags"] = libraries
kwargs["linkerflags"] = linkerflags
kwargs["recurse"] = True
kwargs["objstore"] = "{}/objstore".format(builddir)
kwargs["searchincdirs"] = "./include"
#Pull required binary dynamic libraries to the bin folder
#shutil.copy('{}/lib/libcamsimg3.linux64.so'.format(commondir),builddir);
#shutil.copy('{}/lib/libamsimg.dll'.format(commondir),builddir);
#shutil.copy('{}/lib/glew32.dll','./bin_winx64');
#Designate source files for main test program
fsrc = ['./src/main.cpp']
fobj = replaceexts(fsrc,'.obj')
#Compile test programs
msvc_compile_list(cc,fsrc,**kwargs)
msvc_link_list(list_to_sss(fobj),'{}/{}'.format(builddir,binname),**kwargs)
Binary file not shown.
Binary file not shown.
View File
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View File
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View File
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+170
View File
@@ -0,0 +1,170 @@
#ifndef __AMSCPPNARRAY_HPP__
#define __AMSCPPNARRAY_HPP__
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <stdint.h>
#include <vector>
#include <new>
#include <initializer_list>
#include <thread>
#include <algorithm>
#include <amsmathutil25/amsmathutil25.hpp>
namespace ams
{
namespace narray
{
// Forward declaration of the operator- template function
//template<typename T> class narray;
//template<typename T> narray<T> operator-(const narray<T> &n);
typedef int64_t narray_size_t;
static const int narray_success = 1;
static const int narray_failure = -1;
//problem size at which to begin using threaded operations
static const narray_size_t narray_thread_sz = 5000;
//maximum number of threads to use
static const int narray_max_threads = 50;
template<typename T> class narray
{
public:
narray_size_t length;
T *data;
narray();
narray(const narray<T>& other);
narray(narray<T>&& other) noexcept;
narray<T>& operator=(const narray<T>& other);
narray<T>& operator=(narray<T>&& other) noexcept;
narray<T>& operator=(const std::vector<T>& other);
narray(const std::initializer_list<T> initlist);
narray<T>& operator=(const std::initializer_list<T> initlist);
~narray();
template<typename T2> operator narray<T2>() const; //casting datatypes
int resize(const narray_size_t newlength);
const narray_size_t size() const;
T& operator[](const narray_size_t ind);
const T& operator[](const narray_size_t ind) const;
T& at(const narray_size_t ind);
const T& at(const narray_size_t ind) const;
void clear(); //erases all elements, sets size to 0
void setall(const T& val); //sets all elements to val
//Comparators
bool operator==(const narray<T>& other) const;
bool operator!=(const narray<T>& other) const;
//Operations
narray<T> operator+(const narray<T>& other) const;
narray<T> operator-(const narray<T>& other) const;
narray<T> operator*(const narray<T>& other) const;
narray<T> operator/(const narray<T>& other) const;
narray<T> operator+(const T val) const;
narray<T> operator-(const T val) const;
narray<T> operator*(const T val) const;
narray<T> operator/(const T val) const;
template<class U> friend narray<U> operator-(const narray<U> &n);
narray<T> applyfn(T (*fnptr)(T)) const;
//min,max
T min() const;
T max() const;
//insertions and deletions
// naive, assumes no ordering to the array
//inserts a value at (before) index ind
//insert(0,val) would give {val, oldval0, oldval1, ...}
//insert(N,val)
int insert(const narray_size_t ind, const T val);
//removes the value at index ind, and reduces array size by 1
int erase(const narray_size_t ind);
//finds the first instance of val in the array
narray_size_t find(const T val);
//finds the next instance of val, starting consideration at indstart
narray_size_t findnext(const narray_size_t indstart, const T val);
//finds where to insert a particular value such that the list remains ordered
narray_size_t find_insert_ordered(const T val);
//subarray operations
narray<T> subarray(const narray_size_t ind1, const narray_size_t ind2) const;
//permutations and sorting
//C++11 iterators
typedef T* iterator;
typedef const T* const_iterator;
iterator begin() {return data;}
iterator end() {return data + length;}
const_iterator begin() const {return data;}
const_iterator end() const {return data + length;}
const_iterator cbegin() const { return data; }
const_iterator cend() const { return data+length;}
//printf (must be template specialized)
void print(int printstyle = 0);
};
//Initializers
template<typename T> narray<T> arange(const T low, const T high, const T incr);
template<typename T> narray<T> zeros(const narray_size_t N);
template<typename T> narray<T> ones(const narray_size_t N);
narray<float> linspacef(const float low, const float high, narray_size_t N);
narray<double> linspace(const double low, const double high, narray_size_t N);
//cast/conversion
/////////
//Tests//
/////////
void test_narray1();
void test_narray2();
void test_narray3();
void test_insertdelete1();
}; //end namespace narray
}; //end namespace ams
#include <amscppnarray/amscppnarray_llbops.hpp>
#include <amscppnarray/amscppnarray_impl.hpp>
#include <amscppnarray/amscppnarray_imploper.hpp>
#include <amscppnarray/amscppnarray_implsubarray.hpp>
#include <amscppnarray/amscppnarray_implinits.hpp>
#include <amscppnarray/amscppnarray_random.hpp>
#include <amscppnarray/amscppnarray_math.hpp>
#include <amscppnarray/amscppnarray_binrw.hpp>
#endif
@@ -0,0 +1,21 @@
#ifndef __AMSCPPNARRAY_BINRW_HPP__
#define __AMSCPPNARRAY_BINRW_HPP__
namespace ams
{
namespace narray
{
//binary array read/write operations
template<typename T> int fwrite_ndarray(FILE *fp, narray<T> *data, narray<int32_t> *shape);
template<typename T> int fread_ndarray(FILE *fp, narray<T> *data, narray<int32_t> *shape);
};
};
#include <amscppnarray/amscppnarray_binrwimpl.hpp>
#endif
@@ -0,0 +1,153 @@
#ifndef __AMSCPPNARRAY_BINRWIMPL_HPP__
#define __AMSCPPNARRAY_BINRWIMPL_HPP__
namespace ams
{
namespace narray
{
//binary array read/write operations
template<typename T> int fwrite_ndarray(FILE *fp, narray<T> *data, narray<int32_t> *shape)
{
int ret = narray_success;
narray_size_t piprod;
narray_size_t I;
int32_t Nd;
narray<int32_t> *lshape=NULL;
if(fp==NULL)
{
ret = narray_failure;
printf("fwrite_ndarray: fp=NULL\n");
return ret;
}
if(shape==NULL)
{
lshape = new(std::nothrow) narray<int32_t>();
lshape->resize(1);
lshape->data[0] = data->length;
}
else
{
lshape = shape;
}
piprod = 1;
for(I=0;I<lshape->length;I++)
{
if(lshape->data[I]>0)
{
piprod = piprod*lshape->data[I];
}
else
{
piprod = 0; break;
}
}
if(piprod!=data->length)
{
ret = narray_failure;
printf("fwrite_ndarray: buffer is size %ld, while shape is size %ld\n",(long) data->length,(long) piprod);
return ret;
}
Nd = lshape->length;
fwrite(&Nd,sizeof(int32_t),1,fp);
if(Nd>0)
{
fwrite(lshape->data,sizeof(int32_t),Nd,fp);
if(piprod>0)
{
fwrite(data->data,sizeof(T),data->length,fp);
}
}
if(shape==NULL)
{
if(lshape!=NULL) {delete lshape; lshape=NULL;}
}
return ret;
}
template<typename T> int fread_ndarray(FILE *fp, narray<T> *data, narray<int32_t> *shape)
{
int ret = narray_success;
narray_size_t piprod;
narray_size_t I;
int32_t Nd;
narray<int32_t> *lshape=NULL;
if(fp==NULL)
{
ret = narray_failure;
printf("fread_ndarray: fp=NULL\n");
return ret;
}
if(shape==NULL)
{
lshape = new(std::nothrow) narray<int32_t>();
}
else
{
lshape = shape;
}
fread(&Nd,sizeof(int32_t),1,fp);
if(Nd<=0)
{
data->resize(0);
lshape->resize(0);
ret = narray_failure;
return ret;
}
lshape->resize(Nd);
fread(lshape->data,sizeof(int32_t),Nd,fp);
piprod = 1;
for(I=0;I<lshape->length;I++)
{
if(lshape->data[I]>0)
{
piprod = piprod*lshape->data[I];
}
else
{
piprod = 0; break;
}
}
if(piprod<=0)
{
data->resize(0);
lshape->resize(0);
ret = narray_failure;
return ret;
}
data->resize(piprod);
fread(data->data,sizeof(T),data->length,fp);
if(shape==NULL)
{
if(lshape!=NULL) {delete lshape; lshape=NULL;}
}
return ret;
}
};
};
#endif
+524
View File
@@ -0,0 +1,524 @@
#ifndef __AMSCPPNARRAY_IMPL_HPP__
#define __AMSCPPNARRAY_IMPL_HPP__
namespace ams
{
namespace narray
{
template<typename T> narray<T>::narray()
{
//printf("debug: constructor called for %p.\n",this);
length = 0;
data = NULL;
return;
}
template<typename T> int narray<T>::resize(const narray_size_t newlength)
{
int ret = narray_failure;
narray_size_t I;
T *newdata = NULL;
narray_size_t ml;
if(newlength<=0)
{
if(data!=NULL) {delete[] data; data=NULL;}
length = 0;
ret = narray_success;
return ret;
}
newdata = new(std::nothrow) T[newlength];
if(newdata==NULL)
{
ret = narray_failure;
return ret;
}
//threaded initialization for speed
ml = (length<newlength) ? length : newlength;
buffer_copycast<T,T>(newdata,data,ml);
buffer_set<T>(newdata,T(),length,newlength);
// for(I=0;I<length&I<newlength;I++)
// {
// newdata[I] = data[I];
// }
// for(I=length;I<newlength;I++)
// {
// newdata[I] = T();
// }
if(data!=NULL) {delete[] data; data=NULL;}
data = newdata;
length = newlength;
ret = narray_success;
return ret;
}
template<typename T> narray<T>::narray(const narray<T>& other)
{
narray_size_t I;
int res;
length = 0;
data = NULL;
narray_size_t ml;
//printf("debug: copy constructor called for\n\t%p\n\t%p\n", this, &other);
if(this!=&other)
{
res = this->resize(other.length);
if(res!=narray_success)
{
return;
}
else
{
//threaded copy for speed
ml = (length<other.length) ? length : other.length;
buffer_copycast<T,T>(data,other.data,ml);
// for(I=0;I<length && I<other.length;I++)
// {
// data[I] = other.data[I];
// }
}
}
}
template<typename T> narray<T>::narray(narray<T>&& other) noexcept
{
//this is a move operator
//I still need to understand when these are called.
//printf("debug: move constructor called for\n\t%p\n\t%p\n", this, &other);
//steal the resources from other and reset other to prevent double deletion
length = other.length;
data = other.data;
other.length = 0;
other.data = NULL;
return;
}
template<typename T> narray<T>& narray<T>::operator=(narray<T>&& other) noexcept
{
//printf("debug: move= called for\n\t%p\n\t%p\n", this, &other);
if(this!=&other)
{
if(data!=NULL) {delete[] data; data=NULL;}
length = other.length;
data = other.data;
other.length = 0;
other.data = NULL;
}
return *this;
}
template<typename T> narray<T>& narray<T>::operator=(const narray<T>& other)
{
narray_size_t I;
int res;
narray_size_t ml;
//printf("debug: operator= called for\n\t%p\n\t%p\n", this, &other);
if(this!=&other)
{
res = this->resize(other.length);
if(res!=narray_success)
{
return *this;
}
else
{
//threaded copy for speed
ml = (length<other.length) ? length : other.length;
buffer_copycast<T,T>(data,other.data,ml);
// for(I=0;I<length && I<other.length;I++)
// {
// data[I] = other.data[I];
// }
}
}
return *this;
}
template<typename T> narray<T>& narray<T>::operator=(const std::vector<T>& other)
{
narray_size_t I;
int res;
if(this!=&other)
{
res = this->resize(other.size());
if(res!=narray_success)
{
return *this;
}
else
{
for(I=0;I<length && I<other.size();I++)
{
data[I] = other[I];
}
}
}
return *this;
}
template<typename T> narray<T>::narray(const std::initializer_list<T> initlist)
{
narray_size_t I;
int res;
length = 0;
data = NULL;
res = this->resize(initlist.size());
if(res!=narray_success)
{
return;
}
else
{
I = 0;
for(T elem : initlist)
{
data[I] = elem;
if(I<length) I++;
}
}
}
template<typename T> narray<T>& narray<T>::operator=(const std::initializer_list<T> initlist)
{
narray_size_t I;
int res;
res = this->resize(initlist.size());
if(res!=narray_success)
{
this->length = 0;
if(this->data != NULL) {delete[] this->data; this->data=NULL;}
return *this;
}
else
{
I = 0;
for(T elem : initlist)
{
data[I] = elem;
if(I<length) I++;
}
}
return *this;
}
template<class T> template<class T2> narray<T>::operator narray<T2>() const
{
//casting datatypes
narray<T2> ret;
int res;
res = ret.resize(this->length);
if(res!=narray_success)
{
ret.resize(0);
return ret;
}
else
{
buffer_copycast<T2,T>(ret.data,data,length);
}
return ret;
}
template<typename T> narray<T>::~narray()
{
//printf("debug: destructor called for %p\n",this);
length = 0;
if(data!=NULL) {delete[] data; data=NULL;}
return;
}
template<typename T> T& narray<T>::operator[](const narray_size_t ind)
{
return data[ind];
}
template<typename T> const T& narray<T>::operator[](const narray_size_t ind) const
{
return data[ind];
}
template<typename T> T& narray<T>::at(const narray_size_t ind)
{
return data[ind];
}
template<typename T> const T& narray<T>::at(const narray_size_t ind) const
{
return data[ind];
}
template<typename T> void narray<T>::clear()
{
this->resize(0);
return;
}
template<typename T> void narray_setall_tf(narray<T> *q, const T& val, int threadnum, int nthreads)
{
int I0,I1,Is,I;
Is = q->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? q->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
q->data[I] = val;
}
return;
}
template<typename T> void narray<T>::setall(const T& val)
{
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(length<narray_thread_sz)
{
for(I=0;I<length;I++) data[I] = val;
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
if(nthreads<1) nthreads=1;
if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_setall_tf<T>,this,val,J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return;
}
template<typename T> const narray_size_t narray<T>::size() const
{
return length;
}
//inserts a value at (before) index ind
//insert(0,val) would give {val, oldval0, oldval1, ...}
//insert(N,val)
template<typename T> int narray<T>::insert(const narray_size_t ind, const T val)
{
int ret = narray_success;
int res;
narray<T> narr;
narray_size_t I;
if(ind<0)
{
ret = narray_failure;
return ret;
}
else if(ind<=this->length)
{
res = narr.resize(this->length+1);
if(res!=narray_success)
{
ret = narray_failure;
return ret;
}
if(this->data!=NULL)
{
for(I=0;I<ind && I<this->length;I++)
{
narr.data[I] = this->data[I];
}
}
narr.data[ind] = val;
if(this->data!=NULL)
{
for(I=ind+1;I<narr.length;I++)
{
narr.data[I] = this->data[I-1];
}
}
//steal data from narr
if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
this->length = narr.length;
this->data = narr.data;
narr.length = 0;
narr.data = NULL;
}
else
{
//inserting past the end of the array
res = narr.resize(ind+1);
if(res!=narray_success)
{
ret = narray_failure;
return ret;
}
if(this->data!=NULL)
{
for(I=0;I<this->length;I++)
{
narr.data[I] = this->data[I];
}
}
narr.data[ind] = val;
//steal data from narr
if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
this->length = narr.length;
this->data = narr.data;
narr.length = 0;
narr.data = NULL;
}
return ret;
}
//removes the value at index ind, and reduces array size by 1
template<typename T> int narray<T>::erase(const narray_size_t ind)
{
int ret = narray_success;
int res;
narray<T> narr;
narray_size_t I;
if(ind<0 || ind>=this->length)
{
ret = narray_failure;
return ret;
}
res = narr.resize(this->length-1);
if(res!=narray_success)
{
ret = narray_failure;
return ret;
}
if(this->data!=NULL)
{
for(I=0;I<ind && I<this->length && I<narr.length;I++)
{
narr.data[I] = this->data[I];
}
for(I=ind+1;I<this->length && (I-1)<narr.length;I++)
{
narr.data[I-1] = this->data[I];
}
}
//steal data from narr (should be similar to what std::move would do?)
if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
this->length = narr.length;
this->data = narr.data;
narr.length = 0;
narr.data = NULL;
return ret;
}
//finds the first instance of val in the array
template<typename T> narray_size_t narray<T>::find(const T val)
{
narray_size_t ret = -1;
narray_size_t I;
for(I=0;I<this->length;I++)
{
if(this->data[I]==val)
{
ret = I;
break;
}
}
return ret;
}
//finds the next instance of val, starting consideration at indstart
template<typename T> narray_size_t narray<T>::findnext(const narray_size_t indstart, const T val)
{
narray_size_t ret = -1;
narray_size_t I;
for(I=indstart;I<this->length;I++)
{
if(this->data[I]==val)
{
ret = I;
break;
}
}
return ret;
}
//finds where to insert a particular value such that the list remains ordered
template<typename T> narray_size_t narray<T>::find_insert_ordered(const T val)
{
narray_size_t ret = -1;
narray_size_t I;
ret = 0;
for(I=0;I<this->length;I++)
{
ret = I+1;
if(this->data[I]>val)
{
ret = I;
break;
}
}
ret = (ret<0) ? 0 : ret;
ret = (ret>this->length) ? this->length : ret;
return ret;
}
}; //end namespace narray
}; //end namespace ams
#endif
@@ -0,0 +1,108 @@
#ifndef __AMSCPPNARRAY_IMPLINITS_HPP__
#define __AMSCPPNARRAY_IMPLINITS_HPP__
namespace ams
{
namespace narray
{
template<typename T> void narray_arange_tf(
narray<T> *in,
const T low, const T high, const T incr,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
in->data[I] = low + incr*I;
}
}
template<typename T> narray<T> arange(const T low, const T high, const T incr)
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
narray_size_t N = (narray_size_t)((high-low)/incr);
if(N<=0)
{
N = 0;
}
ret.resize(N);
if(ret.length==0)
{
return ret;
}
if(ret.length<narray_thread_sz)
{
for(I=0;I<ret.length;I++)
{
ret.data[I] = low + incr*I;
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_arange_tf<T>,
&ret,
low,high,incr,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> narray<T> zeros(const narray_size_t N)
{
narray<T> ret;
ret.resize(N);
ret.setall(0);
return ret;
}
template<typename T> narray<T> ones(const narray_size_t N)
{
narray<T> ret;
ret.resize(N);
ret.setall(1);
return ret;
}
};
};
#endif
@@ -0,0 +1,977 @@
#ifndef __AMSCPPNARRAY_IMPLOPER_HPP__
#define __AMSCPPNARRAY_IMPLOPER_HPP__
namespace ams
{
namespace narray
{
template<typename T> void narray_operator_comp_tf(
const narray<T> *a,
const narray<T> *b,
narray<bool> *cmp,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = (nthreads<=1) ? a->length : a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
cmp->data[threadnum] = 1;
for(I=I0;I<I1;I++)
{
if(a->data[I]!=b->data[I])
{
cmp->data[threadnum] = 0;
break;
}
}
return;
}
template<typename T> bool narray<T>::operator==(const narray<T>& other) const
{
bool ret = 1;
narray<bool> cmp;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length != other.length)
{
ret = 0;
return ret;
}
if(this->length == 0)
{
ret = 1;
return ret;
}
if(this->length < narray_thread_sz)
{
for(I=0;I<this->length;I++)
{
if(this->data[I]!=other.data[I])
{
ret = 0;
break;
}
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
cmp.resize(nthreads);
for(J=0;J<nthreads;J++)
{
//printf("debug: launching thread %d\n",J);
threads[J] = new(std::nothrow) std::thread(
&narray_operator_comp_tf<T>,
this,
&other,
&cmp,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
ret = 1;
for(J=0;J<nthreads;J++)
{
if(cmp[J]==0)
{
ret = 0;
break;
}
}
cmp.resize(0);
}
return ret;
}
template<typename T> bool narray<T>::operator!=(const narray<T>& other) const
{
return !(*this==other);
}
template<typename T> void narray_operator_add_tf(
const narray<T> *a,
const narray<T> *b,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] + b->data[I];
}
return;
}
template<typename T> narray<T> narray<T>::operator+(const narray<T>& other) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length!=other.length)
{
ret.resize(0);
printf("narray<T>::operator+:: error - array sizes %ld and %ld are not the same.\n",(long)this->length,(long)other.length);
}
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] + other.data[I];
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
//printf("debug: launching thread %d\n",J);
threads[J] = new(std::nothrow) std::thread(
&narray_operator_add_tf<T>,
this,
&other,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_sub_tf(
const narray<T> *a,
const narray<T> *b,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] - b->data[I];
}
return;
}
template<typename T> narray<T> narray<T>::operator-(const narray<T>& other) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length!=other.length)
{
ret.resize(0);
printf("narray<T>::operator-:: error - array sizes %ld and %ld are not the same.\n",(long)this->length,(long)other.length);
}
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] - other.data[I];
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_sub_tf<T>,
this,
&other,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_mult_tf(
const narray<T> *a,
const narray<T> *b,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] * b->data[I];
}
return;
}
template<typename T> narray<T> narray<T>::operator*(const narray<T>& other) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length!=other.length)
{
ret.resize(0);
printf("narray<T>::operator*:: error - array sizes %ld and %ld are not the same.\n",(long)this->length,(long)other.length);
}
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] * other.data[I];
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_mult_tf<T>,
this,
&other,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_div_tf(
const narray<T> *a,
const narray<T> *b,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] / b->data[I];
}
return;
}
template<typename T> narray<T> narray<T>::operator/(const narray<T>& other) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length!=other.length)
{
ret.resize(0);
printf("narray<T>::operator/:: error - array sizes %ld and %ld are not the same.\n",(long)this->length,(long)other.length);
}
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] / other.data[I];
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_div_tf<T>,
this,
&other,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_add2_tf(
const narray<T> *a,
const T val,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] + val;
}
return;
}
template<typename T> narray<T> narray<T>::operator+(const T val) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] + val;
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_add2_tf<T>,
this,
val,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_sub2_tf(
const narray<T> *a,
const T val,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] - val;
}
return;
}
template<typename T> narray<T> narray<T>::operator-(const T val) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] - val;
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_sub2_tf<T>,
this,
val,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_mult2_tf(
const narray<T> *a,
const T val,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] * val;
}
return;
}
template<typename T> narray<T> narray<T>::operator*(const T val) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] * val;
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_mult2_tf<T>,
this,
val,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_div2_tf(
const narray<T> *a,
const T val,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = a->data[I] / val;
}
return;
}
template<typename T> narray<T> narray<T>::operator/(const T val) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = this->data[I] / val;
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_div2_tf<T>,
this,
val,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_operator_negative_tf(
const narray<T> *a,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = -a->data[I];
}
return;
}
template<class T> narray<T> operator-(const narray<T> &n)
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
ret.resize(n.length);
if(n.length<narray_thread_sz)
{
for(I=0;I<n.length;I++) ret.data[I] = -n.data[I];
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_operator_negative_tf<T>,
&n,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_applyfn_tf(
const narray<T> *a,
T (*fnptr)(T),
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = a->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? a->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = fnptr(a->data[I]);
}
return;
}
template<typename T> narray<T> narray<T>::applyfn(T (*fnptr)(T)) const
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
ret.resize(this->length);
if(this->length<narray_thread_sz)
{
for(I=0;I<this->length;I++) ret.data[I] = fnptr(this->data[I]);
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_applyfn_tf<T>,
this,
fnptr,
&ret,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
template<typename T> void narray_min_tf(
const narray<T> *in,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
if(in->data[I]<out->data[threadnum])
out->data[threadnum] = in->data[I];
}
return;
}
template<typename T> T narray<T>::min() const
{
T ret = T();
narray<T> minarr;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length<=0)
{
return ret;
}
if(this->length<narray_thread_sz)
{
ret = this->data[0];
for(I=0;I<this->length;I++)
{
if(this->data[I]<ret)
{
ret = this->data[I];
}
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
minarr.resize(nthreads);
minarr.setall(this->data[0]);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_min_tf<T>,
this,
&minarr,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
ret = this->data[0];
for(J=0;J<nthreads;J++)
{
if(minarr[J]<ret)
{
ret = minarr[J];
}
}
}
return ret;
}
template<typename T> void narray_max_tf(
const narray<T> *in,
narray<T> *out,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
if(in->data[I]>out->data[threadnum])
out->data[threadnum] = in->data[I];
}
return;
}
template<typename T> T narray<T>::max() const
{
T ret = T();
narray<T> maxarr;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(this->length<=0)
{
return ret;
}
if(this->length<narray_thread_sz)
{
ret = this->data[0];
for(I=0;I<this->length;I++)
{
if(this->data[I]>ret)
{
ret = this->data[I];
}
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
maxarr.resize(nthreads);
maxarr.setall(this->data[0]);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_max_tf<T>,
this,
&maxarr,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
ret = this->data[0];
for(J=0;J<nthreads;J++)
{
if(maxarr[J]>ret)
{
ret = maxarr[J];
}
}
}
return ret;
}
}; //end namespace narray
}; //end namespace ams
#endif
@@ -0,0 +1,44 @@
#ifndef __AMSCPPNARRAY_IMPLSUBARRAY_HPP__
#define __AMSCPPNARRAY_IMPLSUBARRAY_HPP__
namespace ams
{
namespace narray
{
template<typename T> narray<T> narray<T>::subarray(const narray_size_t ind1, const narray_size_t ind2) const
{
int res;
narray<T> ret;
T defval = T();
narray_size_t I,J;
int nl = ind2-ind1;
if(nl<=0)
{
ret.resize(0);
return ret;
}
ret.resize(nl);
for(I=0;I<nl;I++)
{
J = I + ind1;
if(J<0 || J>=this->length)
{
ret.data[I] = defval;
}
else
{
ret.data[I] = this->data[J];
}
}
return ret;
}
};
};
#endif
@@ -0,0 +1,23 @@
#ifndef __AMSCPPNARRAY_LLBOPS_HPP__
#define __AMSCPPNARRAY_LLBOPS_HPP__
//Low level threaded buffer operations
namespace ams
{
namespace narray
{
template<typename T1, typename T2> void buffer_copycast(T1 *bufferto, const T2 *bufferfrom, const narray_size_t N);
template<typename T> void buffer_set(T *buffer, const T val, const narray_size_t ind1, const narray_size_t ind2);
};
};
#include <amscppnarray/amscppnarray_llbopsimpl.hpp>
#endif
@@ -0,0 +1,166 @@
#ifndef __AMSCPPNARRAY_LLBOPSIMPL_HPP__
#define __AMSCPPNARRAY_LLBOPSIMPL_HPP__
namespace ams
{
namespace narray
{
template<typename T1, typename T2> void buffer_copycast_tf(
T1 *bufferto,
const T2 *bufferfrom,
const narray_size_t N,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = N/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? N: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
bufferto[I] = (T1) bufferfrom[I];
}
return;
}
template<typename T1, typename T2> void buffer_copycast(T1 *bufferto, const T2 *bufferfrom, const narray_size_t N)
{
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(N<=0) return;
if(N<narray_thread_sz)
{
for(I=0;I<N;I++)
{
bufferto[I] = (T1) bufferfrom[I];
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&buffer_copycast_tf<T1,T2>,
bufferto,
bufferfrom,
N,
J,nthreads
);
if(threads[J]==NULL)
{
printf("buffer_copy_cast: warning, thread %d failed to launch.\n",J);
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return;
}
template<typename T> void buffer_set_tf(
T *bufferto,
const T val,
const narray_size_t ind1,
const narray_size_t ind2,
const narray_size_t N,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
Is = N/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? N: Is*(threadnum+1);
I0 = I0 + ind1;
I1 = I1 + ind1;
for(I=I0;I<I1;I++)
{
bufferto[I] = val;
}
return;
}
template<typename T> void buffer_set(T *buffer, const T val, const narray_size_t ind1, const narray_size_t ind2)
{
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
narray_size_t N = ind2-ind1;
if(N<=0) return;
if(N<narray_thread_sz)
{
for(I=ind1;I<ind2;I++)
{
buffer[I] = val;
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&buffer_set_tf<T>,
buffer,
val,
ind1,ind2,N,
J,nthreads
);
if(threads[J]==NULL)
{
printf("buffer_copy_cast: warning, thread %d failed to launch.\n",J);
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return;
}
};
};
#endif
@@ -0,0 +1,29 @@
#ifndef __AMSCPPNARRAY_MATH_HPP__
#define __AMSCPPNARRAY_MATH_HPP__
namespace ams
{
namespace narray
{
template<typename T> T narray_max(const narray<T> &q);
template<typename T> T narray_min(const narray<T> &q);
template<typename T> double narray_mean(const narray<T> &q);
template<typename T> double narray_var(const narray<T> &q);
template<typename T> double narray_stdev(const narray<T> &q);
template<typename T> double narray_L2norm(const narray<T> &q);
template<typename T> T narray_sum(const narray<T> &q);
template<typename T> narray<T> narray_abs(narray<T> &q);
void narray_testmath1();
void narray_testmath2();
void narray_testmath3();
}; //end namespaces
};
#include <amscppnarray/amscppnarray_mathimpl.hpp>
#endif
@@ -0,0 +1,388 @@
#ifndef __AMSCPPNARRAY_MATHIMPL_HPP__
#define __AMSCPPNARRAY_MATHIMPL_HPP__
namespace ams
{
namespace narray
{
template<typename T> T narray_max(const narray<T> &q)
{
return q.max();
}
template<typename T> T narray_min(const narray<T> &q)
{
return q.min();
}
template<typename T> void narray_sum_tf(
const narray<T> *in,
narray<T> *sums,
int threadnum,
int nthreads
)
{
int I0,I1,Is,I;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
sums->data[threadnum] = sums->data[threadnum] + in->data[I];
}
}
template<typename T> T narray_sum(const narray<T> &q)
{
T ret = T();
narray<T> sums;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(q.length<=0)
{
return ret;
}
if(q.length<narray_thread_sz)
{
ret = T();
for(I=0;I<q.length;I++)
{
ret = ret + q.data[I];
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
sums.resize(nthreads);
sums.setall(T());
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_sum_tf<T>,
&q,
&sums,
J,nthreads
);
if(threads[J]==NULL)
{
printf("narray_sum: warning: thread %d failed to initialize.\n",J);
//handle errors
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
ret = T();
for(J=0;J<nthreads;J++)
{
ret = ret + sums.data[J];
}
}
return ret;
}
template<typename T> double narray_mean(const narray<T> &q)
{
double ret = 0.0;
if(q.length>0)
{
T sum = narray_sum(q);
ret = (double)sum/((double)q.length);
}
return ret;
}
template<typename T> void narray_variance_tf(
const narray<T> *in,
narray<double> *sums,
double mean,
int threadnum,
int nthreads
)
{
int I0,I1,Is,I;
double q2;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
q2 = in->data[I]-mean;
sums->data[threadnum] = sums->data[threadnum] + q2*q2/((double)in->length);
}
}
template<typename T> double narray_var(const narray<T> &q)
{
double ret = 0.0;
narray<double> sums;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
double mn = ams::narray::narray_mean(q);
double q2;
if(q.length<=0)
{
return ret;
}
if(q.length<narray_thread_sz)
{
ret = 0.0;
for(I=0;I<q.length;I++)
{
q2 = (double)q.data[I]-mn;
ret = ret + q2*q2/((double)q.length);
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
sums.resize(nthreads);
sums.setall(T());
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_variance_tf<T>,
&q,
&sums,
mn,
J,nthreads
);
if(threads[J]==NULL)
{
printf("narray_var: warning: thread %d failed to initialize.\n",J);
//handle errors
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
ret = T();
for(J=0;J<nthreads;J++)
{
ret = ret + sums.data[J];
}
}
return ret;
}
template<typename T> double narray_stdev(const narray<T> &q)
{
double ret = 0.0;
if(q.length>0)
{
ret = narray_var(q);
ret = ::sqrt(ret);
}
return ret;
}
template<typename T> void narray_L2norm_tf(
const narray<T> *in,
narray<double> *sums,
int threadnum,
int nthreads
)
{
int I0,I1,Is,I;
double q2;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
q2 = in->data[I];
sums->data[threadnum] = sums->data[threadnum] + q2*q2;
}
}
template<typename T> double narray_L2norm(const narray<T> &q)
{
double ret = 0.0;
narray<double> sums;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
double q2;
if(q.length<=0)
{
return ret;
}
if(q.length<narray_thread_sz)
{
ret = 0.0;
for(I=0;I<q.length;I++)
{
q2 = (double)q.data[I];
ret = ret + q2*q2;
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
sums.resize(nthreads);
sums.setall(T());
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_L2norm_tf<T>,
&q,
&sums,
J,nthreads
);
if(threads[J]==NULL)
{
printf("narray_L2norm: warning: thread %d failed to initialize.\n",J);
//handle errors
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
ret = T();
for(J=0;J<nthreads;J++)
{
ret = ret + sums.data[J];
}
}
ret = ::sqrt(ret);
return ret;
}
template<typename T> void narray_abs_tf(
const narray<T> *in,
narray<T> *out,
int threadnum,
int nthreads
)
{
int I0,I1,Is,I;
double q2;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
out->data[I] = (in->data[I]<T(0)) ? -in->data[I] : in->data[I];
}
}
template<typename T> narray<T> narray_abs(narray<T> &q)
{
narray<T> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
if(q.length<=0)
{
ret.resize(0);
return ret;
}
ret.resize(q.length);
if(ret.length!=q.length)
{
printf("narray_abs: error - could not allocate return array.\n");
ret.resize(0);
return ret;
}
if(q.length<narray_thread_sz)
{
for(I=0;I<q.length;I++)
{
ret.data[I] = (q.data[I]<T(0)) ? -q.data[I] : q.data[I];
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_abs_tf<T>,
&q,
&ret,
J,nthreads
);
if(threads[J]==NULL)
{
printf("narray_abs: warning: thread %d failed to initialize.\n",J);
//handle errors
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
}; //end namespaces
};
#endif
@@ -0,0 +1,79 @@
#ifndef __AMSCPPNARRAY_RANDOM_HPP__
#define __AMSCPPNARRAY_RANDOM_HPP__
namespace ams
{
namespace narray
{
namespace rand
{
//Random functions for numeric array class
////////////////////////////////////////////////////////////////////////
//Simple Deterministic Psuedorandom Number Generator (32 bit version) //
////////////////////////////////////////////////////////////////////////
typedef int32_t narray_rands_t;
static const narray_rands_t dpr32_mod = ( ((narray_rands_t)1) << ((narray_rands_t)30) ) - (narray_rands_t)1;
static const narray_rands_t dpr32_mult1 = ( (narray_rands_t) 1201633 );
static const narray_rands_t dpr32_add1 = ( (narray_rands_t) 293482 );
extern narray_rands_t dpr32_rseed; // global random number seed for numeric array class
narray_rands_t dpr32_nextseed(narray_rands_t seed);
double dpr32_randd(narray_rands_t *seed = &(ams::narray::rand::dpr32_rseed));
float dpr32_randf(narray_rands_t *seed = &(ams::narray::rand::dpr32_rseed));
double dpr32_gaussian(narray_rands_t *seed = &(ams::narray::rand::dpr32_rseed));
float dpr32_gaussianf(narray_rands_t *seed = &(ams::narray::rand::dpr32_rseed));
int dpr32_randint(int low, int high, narray_rands_t *seed = &(ams::narray::rand::dpr32_rseed));
ams::vec2 dpr32_randuvec2(narray_rands_t *seed);
ams::vec3 dpr32_randuvec3(narray_rands_t *seed);
ams::vec4 dpr32_randuvec4(narray_rands_t *seed);
ams::vec2f dpr32_randuvec2f(narray_rands_t *seed);
ams::vec3f dpr32_randuvec3f(narray_rands_t *seed);
ams::vec4f dpr32_randuvec4f(narray_rands_t *seed);
////////////////////////////////////////////
//Numeric array threaded random generators//
////////////////////////////////////////////
narray_rands_t get_rseed();
void set_rseed(narray_rands_t seed);
void set_rseed_withtimer();
narray<double> narray_rand(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<float> narray_randf(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<double> narray_randgauss(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<float> narray_randgaussf(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<int> narray_randint(narray_size_t N, int low, int highexcl,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<vec2> narray_randuvec2(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<vec3> narray_randuvec3(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<vec4> narray_randuvec4(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<vec2f> narray_randuvec2f(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<vec3f> narray_randuvec3f(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
narray<vec4f> narray_randuvec4f(narray_size_t N,
narray_rands_t *rseed = &(ams::narray::rand::dpr32_rseed));
void test_random1();
};
};
};
#endif
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/python3
import os,sys,math
from build.amsbuildlib4 import *
if(len(sys.argv)>=2):
if(sys.argv[1]=="clean"):
obj_list = flist('./build_linux64',recurse=True,exts=['.o'])
for o in obj_list:
os.remove('{}'.format(o))
exit()
os.system('python3 ./build/make.linux64.lib.py')
os.system('python3 ./build/make.linux64.test.py')
obj_list = flist('./src',recurse=True,exts=['.o'])
for o in obj_list:
os.remove('{}'.format(o))
os.chdir('./build_linux64')
callproc('./tests')
os.chdir('..')
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/python3
#!/usr/bin/python3
import os,sys,math
from build.amsbuildlib4 import *
if(len(sys.argv)>=2):
if(sys.argv[1]=="clean"):
obj_list = flist('./build_mingw64',recurse=True,exts=['.o'])
for o in obj_list:
os.remove('{}'.format(o))
exit()
os.system('python3 ./build/make.mingw64.lib.py')
os.system('python3 ./build/make.mingw64.test.py')
obj_list = flist('./src',recurse=True,exts=['.o'])
for o in obj_list:
os.remove('{}'.format(o))
if(sys.platform!="win32"):
os.chdir('./build_mingw64')
callproc('wine ./tests.exe')
os.chdir('..')
else:
os.chdir('./build_mingw64')
callproc('tests.exe')
os.chdir('..')
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/python3
#!/usr/bin/python3
import os,sys,math
from build.amsbuildlib4 import *
if(len(sys.argv)>=2):
if(sys.argv[1]=="clean"):
obj_list = flist('./build_msvc64',recurse=True,exts=['.o','.obj'])
for o in obj_list:
os.remove('{}'.format(o))
exit()
os.system('python3 ./build/make.msvc64.lib.py')
os.system('python3 ./build/make.msvc64.test.py')
obj_list = flist('./src',recurse=True,exts=['.o','.obj'])
for o in obj_list:
os.remove('{}'.format(o))
os.chdir('./build_msvc64')
callproc('tests.exe')
os.chdir('..')
View File
Whitespace-only changes.
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/bash
scp aschinder@amssolarempire.com:workspace/projects/amscppnarray.tar.gz ../
tar xzvf ../amscppnarray.tar.gz ./
Binary file not shown.
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/python3
import os,sys,math
import numpy as np
#Write double ndarray
def fwrite_dndarray(fp,array):
array = np.array(array,dtype=np.float64,order='F')
Ndim = np.int32(len(array.shape))
shp = np.int32(array.shape)
q = Ndim.tobytes()
fp.write(q)
if(Ndim>0):
q = shp.tobytes()
fp.write(q)
q = array.tobytes()
fp.write(q)
return
#Read double ndarray
def fread_dndarray(fp):
array = np.zeros((),dtype=np.float64,order='F')
q = fp.read(4)
Ndim = np.frombuffer(q,dtype=np.int32,count=1)[0]
if(Ndim>0):
q = fp.read(4*Ndim)
shp = np.frombuffer(q,dtype=np.int32,count=Ndim)
piprod = 1
for i in range(0,len(shp)):
piprod = piprod*shp[i]
q = fp.read(8*piprod)
array = np.frombuffer(q,dtype=np.float64,count=piprod)
array = array.reshape(shp,order='F')
return array
#Write float ndarray
def fwrite_fndarray(fp,array):
array = np.array(array,dtype=np.float32,order='F')
Ndim = np.int32(len(array.shape))
shp = np.int32(array.shape)
q = Ndim.tobytes()
fp.write(q)
if(Ndim>0):
q = shp.tobytes()
fp.write(q)
q = array.tobytes()
fp.write(q)
return
#Read float ndarray
def fread_fndarray(fp):
array = np.zeros((),dtype=np.float32,order='F')
q = fp.read(4)
Ndim = np.frombuffer(q,dtype=np.int32,count=1)[0]
if(Ndim>0):
q = fp.read(4*Ndim)
shp = np.frombuffer(q,dtype=np.int32,count=Ndim)
piprod = 1
for i in range(0,len(shp)):
piprod = piprod*shp[i]
q = fp.read(4*piprod)
array = np.frombuffer(q,dtype=np.float32,count=piprod)
array = array.reshape(shp,order='F')
return array
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/bash
import os,sys,math
import numpy as np
import matplotlib.pyplot as plt
from amsbinarrayrw import *
def plot_random1():
fp = open("./build_linux64/tmp_testrand.bin","r+b")
data = fread_dndarray(fp)
N1 = data.shape[0]
N2 = int(math.sqrt(N1))
N3 = N2*N2
data = data[0:N3]
data = data.reshape([N2,N2])
q = np.zeros([N2,N2,3])
q[:,:,0] = data[:,:]
q[:,:,1] = data[:,:]
q[:,:,2] = data[:,:]
hf = plt.figure(1)
plt.imshow(q)
plt.show()
fp.close()
if(__name__=="__main__"):
plot_random1()
pass
+230
View File
@@ -0,0 +1,230 @@
#include <amscppnarray/amscppnarray.hpp>
namespace ams
{
namespace narray
{
template<> void narray<float>::print(const int printstyle)
{
narray_size_t I;
printf("{");
for(I=0;I<this->length-1;I++)
{
printf("%1.3f,",this->data[I]);
}
if(this->length>=1) printf("%1.3f",this->data[this->length-1]);
printf("}");
return;
}
template<> void narray<double>::print(const int printstyle)
{
narray_size_t I;
printf("{");
for(I=0;I<this->length-1;I++)
{
printf("%1.3f,",this->data[I]);
}
if(this->length>=1) printf("%1.3f",this->data[this->length-1]);
printf("}");
return;
}
template<> void narray<int>::print(const int printstyle)
{
narray_size_t I;
printf("{");
for(I=0;I<this->length-1;I++)
{
printf("%d,",this->data[I]);
}
if(this->length>=1) printf("%d",this->data[this->length-1]);
printf("}");
return;
}
template<> void narray<long>::print(const int printstyle)
{
narray_size_t I;
printf("{");
for(I=0;I<this->length-1;I++)
{
printf("%ld,",this->data[I]);
}
if(this->length>=1) printf("%ld",this->data[this->length-1]);
printf("}");
return;
}
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*2+2);
for(I=0;I<5;I++)
{
printf("d[%d]=%1.3f\n",I,d[I]);
}
printf("d==-a*(b+c*2+2):%d\n",d==(-a*(b+c*2+2)));
d[4] = 0.0f;
printf("d==-a*(b+c*2+2):%d\n",d==(-a*(b+c*2+2)));
d = d.applyfn(::sinf);
for(I=0;I<5;I++)
{
printf("d[%d]=%1.3f\n",I,d[I]);
}
d = d.subarray(0,1);
for(I=0;I<d.length;I++)
{
printf("d[%d]=%1.3f\n",I,d[I]);
}
}
void test_insertdelete1()
{
narray<int> q;
int I,J,K;
q.insert(0,1);
q.print(); printf("\n");
q.insert(0,2);
q.print(); printf("\n");
q.insert(0,3);
q.print(); printf("\n");
q.insert(-1,1);
q.print(); printf("\n");
q.insert(10,99);
q.print(); printf("\n");
I = 3;
printf("q.find(%d)=%d\n",I,(int)q.find(I));
I = 1;
printf("q.find(%d)=%d\n",I,(int)q.find(I));
I = 5;
printf("q.find(%d)=%d\n",I,(int)q.find(I));
I = 99;
printf("q.find(%d)=%d\n",I,(int)q.find(I));
I = 1;
printf("q.findinsert(%d)=%d\n",I,(int)q.find_insert_ordered(I));
I = -1;
printf("q.findinsert(%d)=%d\n",I,(int)q.find_insert_ordered(I));
I = 5;
printf("q.findinsert(%d)=%d\n",I,(int)q.find_insert_ordered(I));
I = 99;
printf("q.findinsert(%d)=%d\n",I,(int)q.find_insert_ordered(I));
I = 100;
printf("q.findinsert(%d)=%d\n",I,(int)q.find_insert_ordered(I));
q.erase(0);
q.print(); printf("\n");
q.erase(-1);
q.print(); printf("\n");
q.erase(q.length);
q.print(); printf("\n");
q.erase(q.length-1);
q.print(); printf("\n");
q.resize(0);
for(I=0;I<25;I++)
{
J = rand::dpr32_randint(5,25);
K = q.find_insert_ordered(J);
q.insert(K,J);
q.print(); printf("\n");
}
return;
}
}; //end namespace narray
}; //end namespace ams
+173
View File
@@ -0,0 +1,173 @@
#include <amscppnarray/amscppnarray.hpp>
namespace ams
{
namespace narray
{
void narray_linspacef_tf(
narray<float> *in,
const float low, const float high, const narray_size_t N,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
float g;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
g = ((float)I)/((float)(N-1));
in->data[I] = low*(1.0f-g) + high*g;
}
}
narray<float> linspacef(const float low, const float high, narray_size_t N)
{
narray<float> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
float g;
if(N<=0)
{
N = 0;
}
ret.resize(N);
if(ret.length==0)
{
return ret;
}
if(ret.length<narray_thread_sz)
{
for(I=0;I<ret.length;I++)
{
g = ((float)I)/((float)(N-1));
ret.data[I] = low*(1.0f-g) + high*g;
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_linspacef_tf,
&ret,
low,high,N,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
void narray_linspace_tf(
narray<double> *in,
const double low, const double high, const narray_size_t N,
int threadnum, int nthreads
)
{
int I0,I1,Is,I;
double g;
Is = in->length/nthreads;
I0 = Is*threadnum;
I1 = (threadnum>=(nthreads-1))? in->length: Is*(threadnum+1);
for(I=I0;I<I1;I++)
{
g = ((double)I)/((double)(N-1));
in->data[I] = low*(1.0-g) + high*g;
}
}
narray<double> linspace(const double low, const double high, narray_size_t N)
{
narray<double> ret;
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
double g;
if(N<=0)
{
N = 0;
}
ret.resize(N);
if(ret.length==0)
{
return ret;
}
if(ret.length<narray_thread_sz)
{
for(I=0;I<ret.length;I++)
{
g = ((double)I)/((double)(N-1));
ret.data[I] = low*(1.0-g) + high*g;
}
}
else
{
//threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
//if(nthreads<1) nthreads=1;
//if(nthreads>narray_max_threads) nthreads = narray_max_threads;
threads.resize(nthreads);
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_linspace_tf,
&ret,
low,high,N,
J,nthreads
);
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return ret;
}
}; //end namespaces
};
+110
View File
@@ -0,0 +1,110 @@
#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::narray_rands_t rs = 1943981;
rand::set_rseed_withtimer();
printf("rseed: %d\n",(int)rand::get_rseed());
printf("rseed: %d\n",(int)rand::dpr32_rseed); //< -- this is different than the line above
narray<double> unif = ams::narray::rand::narray_rand(10000*10000);
printf("rseed: %d\n",(int)rand::get_rseed());
double mn1 = narray_mean(unif);
double std1 = narray_stdev(unif);
double mn2,std2;
//_intl_printarr(unif); printf("\n");
unif = unif*2.0-1.0;
//unif.setall(3.5);
//_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;
}
void narray_testmath3()
{
narray<double> rb;
const char *fout = "./tmp_testrand.bin";
FILE *fp = NULL;
fp = fopen(fout,"w+b");
rb = rand::narray_rand(500*500);
fwrite_ndarray<double>(fp,&rb,NULL);
fclose(fp);
}
};
};
+592
View File
@@ -0,0 +1,592 @@
#include <amscppnarray/amscppnarray.hpp>
namespace ams
{
namespace narray
{
namespace rand
{
//defining global random number seed for numeric array random routines
narray_rands_t dpr32_rseed = 0;
narray_rands_t dpr32_nextseed(narray_rands_t seed)
{
narray_rands_t sret = seed;
sret = ams::mod(sret*dpr32_mult1+dpr32_add1,dpr32_mod);
return sret;
}
double dpr32_randd(narray_rands_t *seed)
{
double ret;
//printf("debug: seed: %d\n",(int)*seed);
*seed = ams::narray::rand::dpr32_nextseed(*seed);
//printf("debug: seed: %d\n",(int)*seed);
ret = (double)*seed/(double)(dpr32_mod-1);
return ret;
}
float dpr32_randf(narray_rands_t *seed)
{
float ret;
*seed = ams::narray::rand::dpr32_nextseed(*seed);
ret = (float)*seed/(float)(dpr32_mod-1);
return ret;
}
double dpr32_gaussian(narray_rands_t *seed)
{
double ret = 0.0;
double u1,u2;
u1 = ams::narray::rand::dpr32_randd(seed);
u2 = ams::narray::rand::dpr32_randd(seed);
if(u1>0.0)
{
ret = ::sqrt(-2.0*::log(u1))*::cos(2.0*pi*u2);
}
return ret;
}
float dpr32_gaussianf(narray_rands_t *seed)
{
float ret = 0.0f;
float u1,u2;
u1 = ams::narray::rand::dpr32_randf(seed);
u2 = ams::narray::rand::dpr32_randf(seed);
if(u1>0.0)
{
ret = ::sqrt(-2.0f*::log(u1))*::cos(2.0f*pif*u2);
}
return ret;
}
vec2 dpr32_randuvec2(narray_rands_t *seed)
{
vec2 ret = vec2(0,0);
double th = ams::narray::rand::dpr32_randd(seed)*2.0*pi;
ret = vec2(cos(th),sin(th));
return ret;
}
vec3 dpr32_randuvec3(narray_rands_t *seed)
{
vec3 ret;
double az,el;
el = ::acos(2.0*dpr32_randd(seed)-1.0)-pi/2.0;
az = ams::narray::rand::dpr32_randd(seed)*2.0*pi;
ret = vec3(cos(az)*cos(el),sin(az)*cos(el),sin(el));
return ret;
}
vec4 dpr32_randuvec4(narray_rands_t *seed)
{
vec4 ret;
double x,y,z,w;
x = ams::narray::rand::dpr32_gaussian(seed);
y = ams::narray::rand::dpr32_gaussian(seed);
z = ams::narray::rand::dpr32_gaussian(seed);
w = ams::narray::rand::dpr32_gaussian(seed);
ret = vec4(x,y,z,w);
ret = vnormalize(ret);
return ret;
}
vec2f dpr32_randuvec2f(narray_rands_t *seed)
{
vec2f ret = vec2f(0,0);
float th = ams::narray::rand::dpr32_randf(seed)*2.0*pi;
ret = vec2f(cos(th),sin(th));
return ret;
}
vec3f dpr32_randuvec3f(narray_rands_t *seed)
{
vec3f ret;
float az,el;
el = ::acos(2.0f*dpr32_randf(seed)-1.0)-pif/2.0;
az = ams::narray::rand::dpr32_randf(seed)*2.0f*pif;
ret = vec3f(cos(az)*cos(el),sin(az)*cos(el),sin(el));
return ret;
}
vec4f dpr32_randuvec4f(narray_rands_t *seed)
{
vec4f ret;
float x,y,z,w;
x = ams::narray::rand::dpr32_gaussianf(seed);
y = ams::narray::rand::dpr32_gaussianf(seed);
z = ams::narray::rand::dpr32_gaussianf(seed);
w = ams::narray::rand::dpr32_gaussianf(seed);
ret = vec4f(x,y,z,w);
ret = vnormalize(ret);
return ret;
}
narray_rands_t get_rseed()
{
return ams::narray::rand::dpr32_rseed;
}
void set_rseed(narray_rands_t seed)
{
ams::narray::rand::dpr32_rseed = seed;
}
void set_rseed_withtimer()
{
narray_rands_t t1 = (narray_rands_t)time(NULL);
narray_rands_t t2 = (narray_rands_t)(::fmod((double)clock()/((double)CLOCKS_PER_SEC)*1000.0f,36000.0f));
ams::narray::rand::dpr32_rseed = (narray_rands_t)t1 + (narray_rands_t)t2;
}
template<typename T> void narray_rand_threadf1(
narray<T> *out,
narray<narray_rands_t> *rseeds,
T (*randfunc)(narray_rands_t *),
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;I<I1;I++)
{
out->data[I] = randfunc(&(rseeds->data[threadnum]));
}
return;
}
template<typename T> void narray_random_threadexec1(
narray<T> *out,
narray_size_t N,
T (*randfunc)(narray_rands_t *),
narray_rands_t *rseed
)
{
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
narray<narray_rands_t> rseeds;
int res;
res = out->resize(N);
if(res!=narray_success)
{
out->resize(0);
return;
}
if(N<narray_thread_sz)
{
//single threaded
for(I=0;I<N;I++)
{
out->data[I] = randfunc(rseed);
}
}
else
{
//multi-threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
rseeds.resize(nthreads);
for(J=0;J<nthreads;J++)
{
*rseed = dpr32_nextseed(*rseed);
rseeds.data[J] = *rseed + 13*J;
}
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_rand_threadf1<T>,
out,
&rseeds,
randfunc,
J,nthreads
);
if(threads[J]==NULL)
{
//handle thread allocation error
printf("warning: narray_random_threadexec1:: thread %d failed to allocate.\n",J);
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return;
}
narray<double> narray_rand(narray_size_t N,
narray_rands_t *rseed)
{
narray<double> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randd),
rseed
);
return ret;
}
narray<float> narray_randf(narray_size_t N,
narray_rands_t *rseed)
{
narray<float> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randf),
rseed
);
return ret;
}
narray<double> narray_randgauss(narray_size_t N,
narray_rands_t *rseed)
{
narray<double> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_gaussian),
rseed
);
return ret;
}
narray<float> narray_randgaussf(narray_size_t N,
narray_rands_t *rseed)
{
narray<float> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_gaussianf),
rseed
);
return ret;
}
narray<vec2> narray_randuvec2(narray_size_t N,
narray_rands_t *rseed)
{
narray<vec2> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randuvec2),
rseed
);
return ret;
}
narray<vec3> narray_randuvec3(narray_size_t N,
narray_rands_t *rseed)
{
narray<vec3> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randuvec3),
rseed
);
return ret;
}
narray<vec4> narray_randuvec4(narray_size_t N,
narray_rands_t *rseed)
{
narray<vec4> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randuvec4),
rseed
);
return ret;
}
narray<vec2f> narray_randuvec2f(narray_size_t N,
narray_rands_t *rseed)
{
narray<vec2f> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randuvec2f),
rseed
);
return ret;
}
narray<vec3f> narray_randuvec3f(narray_size_t N,
narray_rands_t *rseed)
{
narray<vec3f> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randuvec3f),
rseed
);
return ret;
}
narray<vec4f> narray_randuvec4f(narray_size_t N,
narray_rands_t *rseed)
{
narray<vec4f> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec1(
&ret,
N,
&(ams::narray::rand::dpr32_randuvec4f),
rseed
);
return ret;
}
int dpr32_randint(int low, int high, narray_rands_t *seed)
{
int ret = 0;
if(high-low>0)
{
*seed = dpr32_nextseed(*seed);
ret = low + (int)((*seed)%(high-low));
}
return ret;
}
template<typename T> void narray_rand_threadf2(
narray<T> *out,
narray<narray_rands_t> *rseeds,
T (*randfunc)(T, T, narray_rands_t*),
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;I<I1;I++)
{
out->data[I] = randfunc(low,highexcl,&(rseeds->data[threadnum]));
}
return;
}
template<typename T> void narray_random_threadexec2(
narray<T> *out,
narray_size_t N,
T (*randfunc)(T, T, narray_rands_t *),
T low,
T highexcl,
narray_rands_t *rseed
)
{
narray_size_t I;
int J;
int nthreads;
std::vector<std::thread*> threads;
narray<narray_rands_t> rseeds;
int res;
res = out->resize(N);
if(res!=narray_success)
{
out->resize(0);
return;
}
if(N<narray_thread_sz)
{
//single threaded
for(I=0;I<N;I++)
{
out->data[I] = randfunc(low,highexcl,rseed);
}
}
else
{
//multi-threaded operation
nthreads = std::thread::hardware_concurrency();
nthreads = (nthreads<1) ? 1 : nthreads;
nthreads = (nthreads>narray_max_threads) ? narray_max_threads : nthreads;
threads.resize(nthreads);
rseeds.resize(nthreads);
for(J=0;J<nthreads;J++)
{
*rseed = dpr32_nextseed(*rseed);
rseeds.data[J] = *rseed + 13*J;
}
for(J=0;J<nthreads;J++)
{
threads[J] = new(std::nothrow) std::thread(
&narray_rand_threadf2<T>,
out,
&rseeds,
randfunc,
low,highexcl,
J,nthreads
);
if(threads[J]==NULL)
{
//handle thread allocation error
printf("warning: narray_random_threadexec1:: thread %d failed to allocate.\n",J);
}
}
for(J=0;J<nthreads;J++)
{
if(threads[J]!=NULL)
{
threads[J]->join();
delete threads[J];
threads[J]= NULL;
}
}
}
return;
}
narray<int> narray_randint(narray_size_t N, int low, int highexcl,
narray_rands_t *rseed)
{
narray<int> ret;
if(N<=0)
{
ret.resize(0);
return ret;
}
narray_random_threadexec2(
&ret,
N,
&(ams::narray::rand::dpr32_randint),
low,highexcl,
rseed
);
return ret;
}
}; //end namespace rand
}; //end namespaces
};
+16
View File
@@ -0,0 +1,16 @@
#include <amscppnarray/amscppnarray.hpp>
int main(int argc, char* argv[])
{
int ret = 0;
printf("ams c++ numeric array library tests.\n");
ams::narray::test_narray1();
ams::narray::test_narray2();
ams::narray::test_narray3();
ams::narray::narray_testmath1();
ams::narray::narray_testmath2();
ams::narray::narray_testmath3();
ams::narray::test_insertdelete1();
return ret;
}