gpu/test.ipynb
2025-04-13 00:43:03 +03:00

158 KiB

In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [2]:
a = np.fromfile("input_file.bin", dtype=np.float32)
b = np.fromfile("filter_coefs.bin", dtype=np.float32)
In [3]:
conv = np.convolve(a, b, mode="valid")
plt.plot(conv)
Out[3]:
[<matplotlib.lines.Line2D at 0x7f78d691d810>]
No description has been provided for this image
In [4]:
l = len(a) - len(b) + 1
out = np.ndarray((l,), dtype=np.float32)

for i in range(l):
    s = np.float32(0)

    for j in range(len(b)):
        a_pos = i - j + len(b) - 1
        s += a[a_pos] * b[j]

    out[i] = s
In [5]:
plt.plot(out)
Out[5]:
[<matplotlib.lines.Line2D at 0x7f78d68ae210>]
No description has been provided for this image
In [6]:
c = np.fromfile("./output_file.bin", dtype=np.float32)

plt.plot(c)
Out[6]:
[<matplotlib.lines.Line2D at 0x7f78d6731310>]
No description has been provided for this image
In [7]:
plt.plot(np.isclose(c, conv))
Out[7]:
[<matplotlib.lines.Line2D at 0x7f78d678f890>]
No description has been provided for this image