Skip to content
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
9 changes: 8 additions & 1 deletion dali/operators/generic/reshape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@
namespace dali {

inline std::optional<int> ReshapeNDimFunc(const OpSpec &spec) {
// run-time shape is no-go
if (spec.NumRegularInput() > 1)
return std::nullopt;
if (spec.HasTensorArgument("shape") || spec.HasTensorArgument("rel_shape"))
return std::nullopt;

std::vector<int> shape;
if (spec.TryGetRepeatedArgument(shape, "shape"))
return shape.size();
std::vector<float> rel_shape;
if (spec.TryGetRepeatedArgument(rel_shape, "rel_shape"))
return rel_shape.size();
return std::nullopt;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bit too pessimistic.


return spec.InputDesc(0).ndim;
}

DALI_SCHEMA(Reshape)
Expand Down
6 changes: 4 additions & 2 deletions dali/python/nvidia/dali/experimental/dynamic/_invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def dtype(self, result_index: int) -> DType:
self.run(self._eval_context)
return self._results[result_index].dtype

def layout(self, result_index: int) -> str:
def layout(self, result_index: int) -> str | None:
if self._results is None:
if init_spec := getattr(self._operator, "_init_spec", None):
init_spec(self._inputs, self._args)
Expand All @@ -160,7 +160,9 @@ def layout(self, result_index: int) -> str:
layout = str(layout)
return None if layout == "" else layout
self.run(self._eval_context)
return self._results[result_index].layout()
Comment thread
mzient marked this conversation as resolved.

layout = self._results[result_index].layout()
return layout or None # this will override "" with None

def __iter__(self):
for index in range(len(self)):
Expand Down
13 changes: 13 additions & 0 deletions dali/test/python/experimental_mode/test_output_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def assert_correct_metadata(
(ndd.brightness_contrast, dict(brightness=1.2)),
(ndd.crop_mirror_normalize, dict(crop=(2, 2))),
(ndd.crop_mirror_normalize, dict(crop=(2, 2), dtype=ndd.float32)),
(ndd.reshape, dict(layout="")),
)
def test_image_ops(func, kwargs):
tensor = ndd.zeros(shape=(4, 4, 3), dtype=ndd.uint8, layout="HWC")
Expand Down Expand Up @@ -206,3 +207,15 @@ def test_gaussian_blur_fchw():
sigmas = ndd.per_frame(sigmas)

assert_correct_metadata(ndd.gaussian_blur(input, sigma=sigmas))


# --- Empty layout handling ---


@eval_modes(ndd.EvalMode.deferred)
def test_empty_layout():
input = ndd.as_batch([ndd.zeros(shape=(3, 3)), ndd.zeros(shape=(4, 4))])
reshaped = ndd.reshape(input, layout="")
assert reshaped._invocation_result.layout is None
reshaped.evaluate()
assert reshaped._invocation_result.layout is None
Loading