Skip to content

Commit d533f39

Browse files
committed
better print and negtive dim with size()
1 parent b491ed0 commit d533f39

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

python/jittor/__init__.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This file is subject to the terms and conditions defined in
88
# file 'LICENSE.txt', which is part of this source code package.
99
# ***************************************************************
10-
__version__ = '1.1.7.19'
10+
__version__ = '1.1.7.20'
1111
from . import lock
1212
with lock.lock_scope():
1313
from . import compiler
@@ -818,10 +818,19 @@ def jittor_exit():
818818
core.cleanup()
819819
atexit.register(jittor_exit)
820820

821-
Var.__str__ = lambda x: str(x.data)
822-
Var.__repr__ = lambda x: str(x.data)
821+
def vtos(v):
822+
return f"jt.Var({v.data}, dtype={v.dtype})"
823+
824+
Var.__str__ = vtos
825+
Var.__repr__ = vtos
823826
Var.peek = lambda x: f"{x.dtype}{x.shape}"
824827

828+
def size(v, dim=None):
829+
if dim is None:
830+
return v.shape
831+
return v.shape[dim]
832+
Var.size = size
833+
825834
def item(v):
826835
return v.data.item()
827836

src/var_holder.h

-13
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@ struct VarHolder {
7272
return var->name.c_str();
7373
}
7474

75-
// @pyjt(size)
76-
inline NanoVector size() {
77-
if (var->num<0) sync();
78-
return var->shape;
79-
}
80-
81-
// @pyjt(size)
82-
inline int64 size(int64 dim) {
83-
if (var->num<0) sync();
84-
ASSERT(dim>=0 && dim<var->shape.size()) << "dim is out of index";
85-
return var->shape[dim];
86-
}
87-
8875
// @pyjt(numel)
8976
inline int64 numel() {
9077
if (var->num<0) sync();

0 commit comments

Comments
 (0)