Caffe2 - Python API
A deep learning, cross platform ML framework
Packages
Classes
Files
C++ API
Python API
GitHub
File List
test
error_messages
storage.py
1
import
torch
2
3
4
def
check_error(desc, fn, *required_substrings):
5
try
:
6
fn()
7
except
Exception
as
e:
8
error_message = e.args[0]
9
print(
'='
* 80)
10
print(desc)
11
print(
'-'
* 80)
12
print(error_message)
13
print(
''
)
14
for
sub
in
required_substrings:
15
assert
sub
in
error_message
16
return
17
assert
False
,
"given function ({}) didn't raise an error"
.format(desc)
18
19
check_error(
20
'Wrong argument types'
,
21
lambda
:
torch.FloatStorage
(object()),
22
'object'
)
23
24
check_error(
'Unknown keyword argument'
,
25
lambda
:
torch.FloatStorage
(content=1234.),
26
'keyword'
)
27
28
check_error(
'Invalid types inside a sequence'
,
29
lambda
:
torch.FloatStorage
([
'a'
,
'b'
]),
30
'list'
,
'str'
)
31
32
check_error(
'Invalid size type'
,
33
lambda
:
torch.FloatStorage
(1.5),
34
'float'
)
35
36
check_error(
'Invalid offset'
,
37
lambda
:
torch.FloatStorage
(
torch.FloatStorage
(2), 4),
38
'2'
,
'4'
)
39
40
check_error(
'Negative offset'
,
41
lambda
:
torch.FloatStorage
(
torch.FloatStorage
(2), -1),
42
'2'
,
'-1'
)
43
44
check_error(
'Invalid size'
,
45
lambda
:
torch.FloatStorage
(
torch.FloatStorage
(3), 1, 5),
46
'2'
,
'1'
,
'5'
)
47
48
check_error(
'Negative size'
,
49
lambda
:
torch.FloatStorage
(
torch.FloatStorage
(3), 1, -5),
50
'2'
,
'1'
,
'-5'
)
51
52
check_error(
'Invalid index type'
,
53
lambda
:
torch.FloatStorage
(10)[
'first item'
],
54
'str'
)
55
56
57
def
assign():
58
torch.FloatStorage
(10)[1:-1] =
'1'
59
check_error(
'Invalid value type'
,
60
assign,
61
'str'
)
62
63
check_error(
'resize_ with invalid type'
,
64
lambda
:
torch.FloatStorage
(10).resize_(1.5),
65
'float'
)
66
67
check_error(
'fill_ with invalid type'
,
68
lambda
:
torch.IntStorage
(10).fill_(
'asdf'
),
69
'str'
)
70
71
# TODO: frombuffer
torch.IntStorage
Definition:
__init__.py:206
torch.FloatStorage
Definition:
__init__.py:194
Generated on Thu Mar 21 2019 13:06:36 for Caffe2 - Python API by
1.8.11