| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193 |
- import os.path
- import struct
- import numpy as np
- def normalize(a):
- return(a/np.max(np.abs(a)))
- TAILONLY = 1
- BODYONLY = 2
- BODYANDTAIL = 3
- # Datatype formats
- F64 = 64
- F32 = 0
- F16 = 16
- Q63 = 63
- Q31 = 31
- Q15 = 15
- Q7 = 7
- def loopnb(format,loopkind):
- nb = 0
- if loopkind == TAILONLY:
- if format == 64 or format == Tools.Q63:
- nb = 2
- if format == 0 or format == 31:
- nb = 3
- if format == 15 or format == 16:
- nb = 7
- if format == 7:
- nb = 15
- if loopkind == BODYONLY:
- if format == 64 or format == Tools.Q63:
- nb = 4
- if format == 0 or format == 31:
- nb = 8
- if format == 15 or format == 16:
- nb = 16
- if format == 7:
- nb = 32
- if loopkind == BODYANDTAIL:
- if format == 64 or format == Tools.Q63:
- nb = 5
- if format == 0 or format == 31:
- nb = 11 # 9
- if format == 15 or format == 16:
- nb = 23 # 17
- if format == 7:
- nb = 47 # 33
- return(nb)
- # Tools to generate pattern files
- def createMissingDir(destPath):
- theDir=os.path.normpath(destPath)
- if not os.path.exists(theDir):
- os.makedirs(theDir)
- # Pack an array of boolean into uint32
- def packset(a):
- b = np.packbits(a)
- newSize = int(np.ceil(b.shape[0] / 4.0)) * 4
- c = np.copy(b)
- c.resize(newSize)
- #print(c)
- vecSize = round(newSize/4)
- c=c.reshape(vecSize,4)
- #print(c)
- r = np.zeros(vecSize)
- result = []
- for i in range(0,vecSize):
- #print(c[i,:])
- #print("%X %X %X %X" % (c[i,0],c[i,1],c[i,2],c[i,3]))
- d = (c[i,0] << 24) | (c[i,1] << 16) | (c[i,2] << 8) | c[i,3]
- result.append(np.uint32(d))
- return(result)
- def float_to_hex(f):
- """ Convert and x86 float to an ARM unsigned long int.
-
- Args:
- f (float): value to be converted
- Raises:
- Nothing
- Returns:
- str : representation of the hex value
- """
- return hex(struct.unpack('<I', struct.pack('<f', f))[0])
- def float16_to_hex(f):
- """ Convert and x86 float to an ARM unsigned long int.
-
- Args:
- f (float): value to be converted
- Raises:
- Nothing
- Returns:
- str : representation of the hex value
- """
- return hex(struct.unpack('<H', struct.pack('<e', f))[0])
- def float64_to_hex(f):
- """ Convert and x86 float to an ARM unsigned long int.
-
- Args:
- f (float): value to be converted
- Raises:
- Nothing
- Returns:
- str : representation of the hex value
- """
- return hex(struct.unpack('<Q', struct.pack('<d', f))[0])
- def to_q63(v):
- r = int(round(v * 2**63))
- if (r > 0x07FFFFFFFFFFFFFFF):
- r = 0x07FFFFFFFFFFFFFFF
- if (r < -0x08000000000000000):
- r = -0x08000000000000000
- return ("0x%s" % format(struct.unpack('<Q', struct.pack('<q', r))[0],'016X'))
- def to_q31(v):
- r = int(round(v * 2**31))
- if (r > 0x07FFFFFFF):
- r = 0x07FFFFFFF
- if (r < -0x080000000):
- r = -0x080000000
- return ("0x%s" % format(struct.unpack('<I', struct.pack('<i', r))[0],'08X'))
- def to_q15(v):
- r = int(round(v * 2**15))
- if (r > 0x07FFF):
- r = 0x07FFF
- if (r < -0x08000):
- r = -0x08000
- return ("0x%s" % format(struct.unpack('<H', struct.pack('<h', r))[0],'04X'))
- def to_q7(v):
- r = int(round(v * 2**7))
- if (r > 0x07F):
- r = 0x07F
- if (r < -0x080):
- r = -0x080
- return ("0x%s" % format(struct.unpack('<B', struct.pack('<b', r))[0],'02X'))
- def s8(r):
- return ("0x%s" % format(struct.unpack('<B', struct.pack('<b', r))[0],'02X'))
- def u8(r):
- return ("0x%s" % format(struct.unpack('<B', struct.pack('<B', r))[0],'02X'))
- def s16(r):
- return ("0x%s" % format(struct.unpack('<H', struct.pack('<h', r))[0],'04X'))
- def u16(r):
- return ("0x%s" % format(struct.unpack('<H', struct.pack('<H', r))[0],'04X'))
- def s32(r):
- return ("0x%s" % format(struct.unpack('<I', struct.pack('<i', r))[0],'08X'))
- def u32(r):
- return ("0x%s" % format(struct.unpack('<I', struct.pack('<I', r))[0],'08X'))
- def s64(r):
- return ("0x%s" % format(struct.unpack('<Q', struct.pack('<q', r))[0],'016X'))
- def u32(r):
- return ("0x%s" % format(struct.unpack('<I', struct.pack('<I', r))[0],'08X'))
- def u64(r):
- return ("0x%s" % format(struct.unpack('<Q', struct.pack('<Q', r))[0],'016X'))
- class Config:
- def __init__(self,patternDir,paramDir,ext):
- self._patternDir = "%s%s" % (patternDir,ext.upper())
- self._paramDir = "%s%s" % (paramDir,ext.upper())
- self._ext = ext
- self._overwrite=True
- createMissingDir(self._patternDir)
- createMissingDir(self._paramDir)
- def setOverwrite(self,v):
- self._overwrite=v
- def canOverwrite(self,path):
- return(self._overwrite or not os.path.exists(path))
- def inputP(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,self._ext)))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,self._ext)))
- def inputS64P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s64")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s64")))
- def inputS32P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s32")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s32")))
- def inputS16P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s16")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s16")))
- def inputS8P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s8")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s8")))
- def inputF32P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"f32")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"f32")))
- def inputF16P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"f16")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"f16")))
- def inputQ63P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q63")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q63")))
- def inputQ31P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q31")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q31")))
- def inputQ15P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q15")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q15")))
- def inputQ7P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q7")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q7")))
- def inputU64P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u64")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"u64")))
- def inputU32P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u32")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"u32")))
- def inputU16P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u16")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"u16")))
- def inputU8P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u8")))
- else:
- return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"u8")))
-
- def refP(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,self._ext)))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,self._ext)))
- def refS8P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s8")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s8")))
- def refU8P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u8")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"u8")))
- def refS16P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s16")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s16")))
- def refU16P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u16")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"u16")))
- def refS32P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s32")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s32")))
- def refU32P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u32")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"u32")))
- def refS64P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s64")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s64")))
- def refU64P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u64")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"u64")))
- def refQ63P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q63")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"q63")))
- def refQ31P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q31")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"q31")))
- def refF32P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"f32")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"f32")))
- def refF16P(self,i,name=None):
- """ Path to a reference pattern from the ID
-
- Args:
- i (int): ID to the reference pattern
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"f16")))
- else:
- return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"f16")))
- def paramP(self,i,name=None):
- """ Path to a parameters from the ID
-
- Args:
- i (int): ID to the params
- Raises:
- Nothing
- Returns:
- str : path to the file where to generate the pattern data
- """
- if name:
- return(os.path.join(self._paramDir,"%s%d.txt" % (name,i)))
- else:
- return(os.path.join(self._paramDir,"Params%d.txt" % i))
- def _writeVectorF64(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W,D for 8,16,32 or 64 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("D\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % float64_to_hex(v))
- def _writeVectorF32(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("W\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % float_to_hex(v))
- def _writeVectorF16(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("H\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % float16_to_hex(v))
- def _writeVectorQ63(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("D\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % to_q63(v))
- def _writeVectorQ31(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("W\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % to_q31(v))
- def _writeVectorQ15(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("H\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % to_q15(v))
- def _writeVectorS16(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("H\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % s16(v))
- def _writeVectorU16(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("H\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % u16(v))
- def _writeVectorS64(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("D\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % s64(v))
- def _writeVectorU64(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("D\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % u64(v))
- def _writeVectorS32(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("W\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % s32(v))
- def _writeVectorU32(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("W\n%d\n" % len(data))
- for v in data:
- f.write("// %s\n" % v)
- f.write("%s\n" % u32(v))
- def _writeVectorQ7(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("B\n%d\n" % len(data))
- for v in data:
- f.write("// %f\n" % v)
- f.write("%s\n" % to_q7(v))
- def _writeVectorS8(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("B\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % s8(v))
- def _writeVectorU8(self,i,data):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of pattern file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("B\n%d\n" % len(data))
- for v in data:
- f.write("// %d\n" % v)
- f.write("%s\n" % u8(v))
- def writeReference(self,j,data,name=None):
- if (self._ext == "f64"):
- self._writeVectorF64(self.refP(j,name),data)
- if (self._ext == "f32"):
- self._writeVectorF32(self.refP(j,name),data)
- if (self._ext == "f16"):
- self._writeVectorF16(self.refP(j,name),data)
- if (self._ext == "q63"):
- self._writeVectorQ63(self.refP(j,name),data)
- if (self._ext == "q31"):
- self._writeVectorQ31(self.refP(j,name),data)
- if (self._ext == "q15"):
- self._writeVectorQ15(self.refP(j,name),data)
- if (self._ext == "q7"):
- self._writeVectorQ7(self.refP(j,name),data)
- if (self._ext == "s64"):
- self._writeVectorS64(self.refP(j,name),data)
- if (self._ext == "u64"):
- self._writeVectorU64(self.refP(j,name),data)
- if (self._ext == "s32"):
- self._writeVectorS32(self.refP(j,name),data)
- if (self._ext == "u32"):
- self._writeVectorU32(self.refP(j,name),data)
- if (self._ext == "s16"):
- self._writeVectorS16(self.refP(j,name),data)
- if (self._ext == "u16"):
- self._writeVectorU16(self.refP(j,name),data)
- if (self._ext == "s8"):
- self._writeVectorS8(self.refP(j,name),data)
- if (self._ext == "u8"):
- self._writeVectorU8(self.refP(j,name),data)
- def writeReferenceQ63(self,j,data,name=None):
- self._writeVectorQ63(self.refQ63P(j,name),data)
- def writeReferenceQ31(self,j,data,name=None):
- self._writeVectorQ31(self.refQ31P(j,name),data)
- def writeReferenceS8(self,j,data,name=None):
- self._writeVectorS8(self.refS8P(j,name),data)
- def writeReferenceS16(self,j,data,name=None):
- self._writeVectorS16(self.refS16P(j,name),data)
-
- def writeReferenceS32(self,j,data,name=None):
- self._writeVectorS32(self.refS32P(j,name),data)
- def writeReferenceS64(self,j,data,name=None):
- self._writeVectorS64(self.refS64P(j,name),data)
- def writeReferenceU8(self,j,data,name=None):
- self._writeVectorU8(self.refU8P(j,name),data)
- def writeReferenceU16(self,j,data,name=None):
- self._writeVectorU16(self.refU16P(j,name),data)
-
- def writeReferenceU32(self,j,data,name=None):
- self._writeVectorU32(self.refU32P(j,name),data)
- def writeReferenceU64(self,j,data,name=None):
- self._writeVectorU64(self.refU64P(j,name),data)
- def writeReferenceF32(self,j,data,name=None):
- self._writeVectorF32(self.refF32P(j,name),data)
- def writeReferenceF16(self,j,data,name=None):
- self._writeVectorF16(self.refF16P(j,name),data)
- def writeInput(self,j,data,name=None):
- if (self._ext == "f64"):
- self._writeVectorF64(self.inputP(j,name),data)
- if (self._ext == "f32"):
- self._writeVectorF32(self.inputP(j,name),data)
- if (self._ext == "f16"):
- self._writeVectorF16(self.inputP(j,name),data)
- if (self._ext == "q63"):
- self._writeVectorQ63(self.inputP(j,name),data)
- if (self._ext == "q31"):
- self._writeVectorQ31(self.inputP(j,name),data)
- if (self._ext == "q15"):
- self._writeVectorQ15(self.inputP(j,name),data)
- if (self._ext == "q7"):
- self._writeVectorQ7(self.inputP(j,name),data)
- if (self._ext == "s64"):
- self._writeVectorS64(self.inputP(j,name),data)
- if (self._ext == "u64"):
- self._writeVectorU64(self.inputP(j,name),data)
- if (self._ext == "s32"):
- self._writeVectorS32(self.inputP(j,name),data)
- if (self._ext == "u32"):
- self._writeVectorU32(self.inputP(j,name),data)
- if (self._ext == "s8"):
- self._writeVectorS8(self.inputP(j,name),data)
- if (self._ext == "u8"):
- self._writeVectorU8(self.inputP(j,name),data)
- def writeInputF32(self,j,data,name=None):
- self._writeVectorF32(self.inputF32P(j,name),data)
- def writeInputF16(self,j,data,name=None):
- self._writeVectorF16(self.inputF16P(j,name),data)
- def writeInputQ63(self,j,data,name=None):
- self._writeVectorQ63(self.inputQ63P(j,name),data)
- def writeInputQ31(self,j,data,name=None):
- self._writeVectorQ31(self.inputQ31P(j,name),data)
- def writeInputQ15(self,j,data,name=None):
- self._writeVectorQ15(self.inputQ15P(j,name),data)
- def writeInputQ7(self,j,data,name=None):
- self._writeVectorQ7(self.inputQ7P(j,name),data)
- def writeInputS64(self,j,data,name=None):
- self._writeVectorS64(self.inputS64P(j,name),data)
- def writeInputS32(self,j,data,name=None):
- self._writeVectorS32(self.inputS32P(j,name),data)
- def writeInputS16(self,j,data,name=None):
- self._writeVectorS16(self.inputS16P(j,name),data)
- def writeInputS8(self,j,data,name=None):
- self._writeVectorS8(self.inputS8P(j,name),data)
- def writeInputU64(self,j,data,name=None):
- self._writeVectorU64(self.inputU64P(j,name),data)
- def writeInputU32(self,j,data,name=None):
- self._writeVectorU32(self.inputU32P(j,name),data)
- def writeInputU16(self,j,data,name=None):
- self._writeVectorU16(self.inputU16P(j,name),data)
- def writeInputU8(self,j,data,name=None):
- self._writeVectorU8(self.inputU8P(j,name),data)
- def writeParam(self,j,data,name=None):
- """ Write pattern data
-
- The format is recognized by the text framework script.
- First line is the sample width (B,H or W for 8,16 or 32 bits)
- Second line is number of samples
- Other lines are hexadecimal representation of the samples in format
- which can be read on big endian ARM.
-
- Args:
- j (int): ID of parameter file
- data (array): Vector containing the data
- Raises:
- Nothing
- Returns:
- Nothing
- """
- i=self.paramP(j,name)
- if self.canOverwrite(i):
- with open(i,"w") as f:
- # Write sample dimension nb sample header
- #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
- f.write("%d\n" % len(data))
- for v in data:
- f.write("%d\n" % v)
|