Skip to content

Use -1 to indicate dynamically sized dimensions #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ docker run --detach --rm --name mcbackend-db -p 9000:9000 --ulimit nofile=262144
If you don't already have it, first install the protobuf compiler:
```bash
conda install protobuf
pip install --pre "betterproto[compiler]"
```

To compile the `*.proto` files for languages other than Python, check the [ProtocolBuffers documentation](https://developers.google.com/protocol-buffers/docs/tutorials).
Expand Down
10 changes: 1 addition & 9 deletions mcbackend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,4 @@
except ModuleNotFoundError:
pass

# Adapters
try:
from .adapters import pymc
from .adapters.pymc import TraceBackend
except ModuleNotFoundError:
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