File: tri_check_itemsize.patch

package info (click to toggle)
libgpuarray 0.7.6-13
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,176 kB
  • sloc: ansic: 19,235; python: 4,591; makefile: 208; javascript: 71; sh: 15
file content (34 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Description: Fail unsupported tril/u instead of returning nonsense

The extract_tri kernel assumes 4 bytes per entry when deciding which
memory addresses to zero out: if the actual data type is another size,
it will "succeed" but produce nonsense.

There are real fixes for this upstream (
https://github.com/Theano/libgpuarray/commit/07cd4ad56054c279442ee28413b26939f4c03632
plus https://github.com/Theano/libgpuarray/pull/584), but I am not sure
whether those are appropriate as a Debian patch.

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: not-needed

--- a/pygpu/basic.py
+++ b/pygpu/basic.py
@@ -32,6 +32,8 @@ def triu(A, inplace=True):
         raise ValueError("triu only works for 2d arrays")
     if A.flags.c_contiguous is A.flags.f_contiguous is False:
         raise ValueError("triu only works for contiguous arrays")
+    if A.dtype.itemsize != 4:
+        raise TypeError("triu only works on 4 byte dtypes (usually np.float32) - use upstream libgpuarray if you need it on other types")
 
     if not inplace:
         A = A.copy()
@@ -51,6 +53,8 @@ def tril(A, inplace=True):
         raise ValueError("tril only works for 2d arrays")
     if A.flags.c_contiguous is A.flags.f_contiguous is False:
         raise ValueError("tril only works for contiguous arrays")
+    if A.dtype.itemsize != 4:
+        raise TypeError("tril only works on 4 byte dtypes (usually np.float32) - use upstream libgpuarray if you need it on other types")
 
     if not inplace:
         A = A.copy()