Skip to content

Commit

Permalink
Use -1 for dynamic dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelosthege committed Feb 19, 2023
1 parent d660e7b commit dbcf744
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mcbackend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
pass


__version__ = "0.3.0"
__version__ = "0.4.0"
4 changes: 2 additions & 2 deletions mcbackend/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def is_rigid(nshape: Optional[Shape]):
This "nullable shape" is interpreted as follows:
- ``[]`` indicates scalar shape (rigid: True).
- ``[2, 3]`` indicates a matrix with 2 rows and 3 columns (rigid: True).
- ``[2, 0]`` indicates a matrix with 2 rows and dynamic number of columns (rigid: False).
- ``[2, -1]`` indicates a matrix with 2 rows and dynamic number of columns (rigid: False).
- ``None`` indicates dynamic dimensionality (rigid: False).
"""
if nshape is None:
return False
if any(s == 0 for s in nshape):
if any(s == -1 for s in nshape):
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion mcbackend/meta.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mcbackend/test_backend_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_targets(self):
variables=[
Variable("tensor", "int8", (3, 4, 5)),
Variable("scalar", "float64", ()),
Variable("changeling", "uint16", (3, 0)),
Variable("changeling", "uint16", (3, -1)),
],
)
run = imb.init_run(rm)
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_growing(self):
Variable(
"B",
"float32",
(0,),
(-1,),
),
],
)
Expand Down
6 changes: 3 additions & 3 deletions mcbackend/test_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime, timezone

import numpy
import pytest

from mcbackend.meta import ChainMeta, RunMeta, Variable
from mcbackend.test_utils import make_runmeta
Expand All @@ -12,9 +11,10 @@
def test_is_rigid():
assert core.is_rigid([])
assert core.is_rigid([1, 2])
assert core.is_rigid([1, 0])
assert not core.is_rigid(None)
assert not core.is_rigid((0,))
assert not core.is_rigid([1, 0, 2])
assert not core.is_rigid((-1,))
assert not core.is_rigid([1, -1, 2])
pass


Expand Down
4 changes: 2 additions & 2 deletions mcbackend/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def make_draw(variables: Sequence[Variable]):
for var in variables:
dshape = tuple(
# A pre-registered dim length of 0 means that it's random!
s or random.randint(0, 10)
(random.randint(0, 10) if s == -1 else s)
for s in var.shape
)
if "float" in var.dtype:
Expand Down Expand Up @@ -215,7 +215,7 @@ def test__get_slicing(self, slc: slice):
# "B" are dynamically shaped to cover the edge cases.
rmeta = RunMeta(
variables=[Variable("A", "uint8"), Variable("M", "str", [2, 3])],
sample_stats=[Variable("B", "uint8", [2, 0])],
sample_stats=[Variable("B", "uint8", [2, -1])],
data=[],
)
run = self.backend.init_run(rmeta)
Expand Down
2 changes: 1 addition & 1 deletion protobufs/meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ message Variable {
// The default value, an empty sequence, corresponds to scalar shape.
// Note that for variables of dynamic dimensionality, ``undefined_ndim=True``
// can be set to render ``shape`` and ``dims`` meaningless.
repeated uint64 shape = 3;
repeated int64 shape = 3;
// Names of the variable's dimensions.
// The default value, an empty sequence, corresponds to undefined dimension names
// and applies to scalar variables, and variables where ``undefined_ndim=True``.
Expand Down

0 comments on commit dbcf744

Please sign in to comment.