import random
import sys
+##
+# @brief Convert given data to bytes
+# @param[in] data The data to be converted to bytes array
+# @return bytes converted from the data
+
+def convert_to_bytes(data):
+ """
+ Convert given data to bytes
+
+ @param data: The data to be converted to bytes
+ @rtype : bytes
+ @return : bytes converted from the data
+ """
+
+ if isinstance(data, bytes):
+ return data
+ else:
+ return pack("<B", data)
##
# @brief Save bitmap "data" to "filename"
for h in range(height-1, -1, -1):
for w in range(0, width):
pos = 3 * (w + width * h)
- graphics += data[pos+2]
- graphics += data[pos+1]
- graphics += data[pos]
+ graphics += convert_to_bytes(data[pos + 2])
+ graphics += convert_to_bytes(data[pos + 1])
+ graphics += convert_to_bytes(data[pos])
for x in range(0, (width * 3) % 4):
graphics += pack('<B', 0)
elif colorspace == 'BGRx':
for h in range(height-1, -1, -1):
for w in range(0, width):
pos = bytes_per_px * (w + width * h)
- graphics += data[pos]
- graphics += data[pos+1]
- graphics += data[pos+2]
+ graphics += convert_to_bytes(data[pos])
+ graphics += convert_to_bytes(data[pos + 1])
+ graphics += convert_to_bytes(data[pos + 2])
for x in range(0, (width * 3) % 4):
graphics += pack('<B', 0)
elif colorspace == 'GRAY8':
for h in range(height-1, -1, -1):
for w in range(0, width):
pos = bytes_per_px * (w + width * h)
- graphics += data[pos]
+ graphics += convert_to_bytes(data[pos])
for x in range(0, (width * 3) % 4):
graphics += pack('<B', 0)
else:
file.write(s[i])
for i in range(0,10):
- sink_1 = i/3;
+ sink_1 = i // 3;
with open("testsynch03_"+str(i)+".golden",'wb') as file:
file.write(s[i])
file.write(s[sink_1])
id=[0,1,1,2,3,3,4,5,5,6]
for i in range(0,10):
sink_0 = id[i]
- sink_1 = i/3
+ sink_1 = i // 3
with open("testsynch05_"+str(i)+".golden",'wb') as file:
file.write(s[i])
file.write(s[sink_0])
s=b''
for y in range(0,100):
for x in range(0,100):
- s+=buf[y*100+x];
+ s += bmp.convert_to_bytes(buf[y * 100 + x])
bmp.write('testcase_1_0.golden', s);
s = b''
for i in range(1, 3):
for y in range(0,100):
for x in range(0,100):
- s+=buf[y*100+x + i*100*100];
+ s += bmp.convert_to_bytes(buf[y*100+x + i*100*100]);
bmp.write('testcase_1_1.golden', s);
for i in range(0,3):
s = b''
for y in range(0,100):
for x in range(0,100):
- s += buf[y*100+x + i*100*100]
+ s += bmp.convert_to_bytes(buf[y*100+x + i*100*100])
bmp.write('testcase_2_'+str(i)+'.golden', s)
string = bmp.gen_BMP_stream('testsequence', 'testcase_stream.golden', 1)
for i in range (0,10):
for y in range(0,16):
for x in range(0,16):
- s += string[i][y*16+x]
+ s += bmp.convert_to_bytes(string[i][y*16+x])
bmp.write('testcase_stream_1_0.golden',s)
s=b''
for j in range (1,3):
for y in range(0,16):
for x in range(0,16):
- s += string[i][j*16*16+ y*16+x]
+ s += bmp.convert_to_bytes(string[i][j*16*16+ y*16+x])
bmp.write('testcase_stream_1_1.golden',s)
for j in range (0,3):
for i in range (0,10):
for y in range(0,16):
for x in range(0,16):
- s += string[i][j*16*16+ y*16+x]
+ s += bmp.convert_to_bytes(string[i][j*16*16+ y*16+x])
bmp.write('testcase_stream_2_'+str(j)+'.golden',s)
if target == -1 or target == 12:
# @author HyoungJoo Ahn <hello.ahn@samsung.com>
import sys
+import os
import struct
import string
+sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+from gen24bBMP import convert_to_bytes
+
+if sys.version_info < (3,):
+ range = xrange
def readbyte (filename):
- F = open(filename, 'r')
- readbyte = F.read()
- F.close()
- return readbyte
+ F = open(filename, 'rb')
+ readbyte = F.read()
+ F.close()
+ return readbyte
+
bytearr = readbyte(sys.argv[1])
softmax = []
-for i in xrange(10):
- byte = bytearr[i * 4] + bytearr[i * 4 + 1] + bytearr[i * 4 + 2] + bytearr[i * 4 + 3]
- softmax.append(struct.unpack('f', byte))
+for i in range(10):
+ byte = b''
+ byte += convert_to_bytes(bytearr[i * 4])
+ byte += convert_to_bytes(bytearr[i * 4 + 1])
+ byte += convert_to_bytes(bytearr[i * 4 + 2])
+ byte += convert_to_bytes(bytearr[i * 4 + 3])
+ softmax.append(struct.unpack('f', byte))
pred = softmax.index(max(softmax))
-answer = string.atoi(sys.argv[2].strip())
+answer = int(sys.argv[2].strip())
exit(pred != answer)
for y in range(0, height2):
for x in range(0, width2):
for c in range(0, innerdim):
- ix = x * width1 / width2
- iy = y * height1 / height2
+ ix = x * width1 // width2
+ iy = y * height1 // height2
if data1[count + c + ix * innerdim + iy * width1 * innerdim] != data2[count2 + c + x * innerdim + y * width2 * innerdim]:
print("At "+str(x)+","+str(y))
return 5
return 0
def readfile (filename):
- F = open(filename, 'r')
+ F = open(filename, 'rb')
readfile = F.read()
F.close()
return readfile
for y in range(0, height2):
for x in range(0, width2):
for c in range(0, innerdim):
- ix = x * width1 / width2
- iy = y * height1 / height2
+ ix = x * width1 // width2
+ iy = y * height1 // height2
if data1[count + c + ix * innerdim + iy * width1 * innerdim] != data2[count2 + c + x * innerdim + y * width2 * innerdim]:
print("At "+str(x)+","+str(y))
return 5
## @brief Read file and return its content
def readfile (filename):
- F = open(filename, 'r')
+ F = open(filename, 'rb')
readfile = F.read()
F.close()
return readfile
# @author Parichay Kapoor <pk.kapoor@samsung.com>
import sys
+import os
+import struct
+import string
+sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+from gen24bBMP import convert_to_bytes
# Read the bytes from the file
def readbyte (filename):
- with open(filename, 'r') as f:
- readbyte = f.read()
- return readbyte
+ with open(filename, 'rb') as f:
+ readbyte = f.read()
+ return readbyte
# Verify that the output of test case verifies the filename of the input
onehot = readbyte(sys.argv[1])
-onehot = [str(ord(x)) for x in onehot]
+onehot = [convert_to_bytes(x) for x in onehot]
idx = onehot.index(max(onehot))
label = str(idx)
# @author HyoungJoo Ahn <hello.ahn@samsung.com>
import sys
+import os
import struct
import string
+sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+from gen24bBMP import convert_to_bytes
+
+if sys.version_info < (3,):
+ range = xrange
def readbyte (filename):
- F = open(filename, 'r')
- readbyte = F.read()
- F.close()
- return readbyte
+ F = open(filename, 'rb')
+ readbyte = F.read()
+ F.close()
+ return readbyte
def readlabel (filename):
- F = open(filename, 'r')
- line = F.readlines()
- F.close()
- return line
+ F = open(filename, 'r')
+ line = F.readlines()
+ F.close()
+ return line
bytearr = readbyte(sys.argv[1])
softmax = []
-for i in xrange(10):
- byte = bytearr[i * 4] + bytearr[i * 4 + 1] + bytearr[i * 4 + 2] + bytearr[i * 4 + 3]
- softmax.append(struct.unpack('f', byte))
+for i in range(10):
+ byte = b''
+ byte += convert_to_bytes(bytearr[i * 4])
+ byte += convert_to_bytes(bytearr[i * 4 + 1])
+ byte += convert_to_bytes(bytearr[i * 4 + 2])
+ byte += convert_to_bytes(bytearr[i * 4 + 3])
+ softmax.append(struct.unpack('f', byte))
pred = softmax.index(max(softmax))
-answer = string.atoi(sys.argv[2].strip())
+answer = int(sys.argv[2].strip())
exit(pred != answer)
# @author HyoungJoo Ahn <hello.ahn@samsung.com>
import sys
+import os
+import struct
+import string
+sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+from gen24bBMP import convert_to_bytes
def readbyte (filename):
- F = open(filename, 'r')
+ F = open(filename, 'rb')
readbyte = F.read()
F.close()
return readbyte
return line
onehot = readbyte(sys.argv[1])
-onehot = [str(ord(x)) for x in onehot]
+onehot = [convert_to_bytes(x) for x in onehot]
idx = onehot.index(max(onehot))
label_list = readlabel(sys.argv[2])
import sys
import os
import array as arr
+import struct
+import string
+sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+from gen24bBMP import convert_to_bytes
def location(c, w, h):
return c+4*(w+4*h)
for h in range(0,4):
w=0
for i in range(0,4):
- out[location(i,w,h)]=frame[location(i,w,h)]
+ out[location(i,w,h)] = frame[location(i,w,h)]
for w in range(1,3):
for c in range(0,4):
sum = frame[location(0,w,h)]
sum += out[location(0,w,h)]
- out[location(0,w,h)] = sum/2
+ out[location(0,w,h)] = sum // 2
w=3
for i in range(0,4):
out[location(i,w,h)] = out[location(i,w,h)]
- return frame.tostring(), out
+ return frame, out
filename = "video_4x4xBGRx.xraw"
-f = open(filename, "w")
+f = open(filename, "wb")
out = arr.array('B',[0]*64)
for seq in range(0, 10):
outfilename = "rnn.golden"
- string, out=genFrame(seq,out)
+ frame, out = genFrame(seq,out)
+
if(seq == 9):
with open(outfilename,'wb') as file:
file.write(out.tostring())
- f.write(string)
+ f.write(frame)
f.close()
def testDimchgFirstDimGoHigher(dataA, dataB, dim1, repeatblocksize, elementsize):
if (len(dataA) != len(dataB)):
return 1
- loop = len(dataA) / repeatblocksize
+ loop = len(dataA) // repeatblocksize
if ((loop * repeatblocksize) != len(dataA)):
return 2
- ncpy = repeatblocksize / dim1 / elementsize
+ ncpy = repeatblocksize // dim1 // elementsize
if ((ncpy * dim1 * elementsize) != repeatblocksize):
return 3
for x in range(0, loop):
return 4
def readfile (filename):
- F = open(filename, 'r')
+ F = open(filename, 'rb')
readfile = F.read()
F.close
return readfile
if (0 < (lena % typeasize)) or (0 < (lenb % typebsize)):
return 10
- num = lena / typeasize
- if num != (lenb / typebsize):
+ num = lena // typeasize
+ if num != (lenb // typebsize):
return 11
limitb = 2 ** (8 * typebsize)
maskb = limitb - 1
return 0
def readfile (filename):
- F = open(filename, 'r')
+ F = open(filename, 'rb')
readfile = F.read()
F.close
return readfile
if (0 < (lena % typeasize)) or (0 < (lenb % typebsize)):
return 10
- num = lena / typeasize
- if num != (lenb / typebsize):
+ num = lena // typeasize
+ if num != (lenb // typebsize):
return 11
limitb = 2 ** (8 * typebsize)
maskb = limitb - 1
return 0
def readfile (filename):
- F = open(filename, 'r')
+ F = open(filename, 'rb')
readfile = F.read()
F.close
return readfile