Skip to content
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

Use "N-dimensional" instead of "rank-N" in docstrings and error messages #6797

Merged
merged 4 commits into from
Jul 8, 2024
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
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/archetypes/bar_chart.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ table BarChart (
) {
// --- Required ---

/// The values. Should always be a rank-1 tensor.
/// The values. Should always be a 1-dimensional tensor (i.e. a vector).
values: rerun.components.TensorData ("attr.rerun.component_required", required, order: 1000);

// --- Optional ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ table DepthImage (
) {
// --- Required ---

/// The depth-image data. Should always be a rank-2 tensor.
/// The depth-image data. Should always be a 2-dimensional tensor.
data: rerun.components.TensorData ("attr.rerun.component_required", order: 1000);

// --- Optional ---
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/archetypes/image.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ table Image (
) {
// --- Required ---

/// The image data. Should always be a rank-2 or rank-3 tensor.
/// The image data. Should always be a 2- or 3-dimensional tensor.
data: rerun.components.TensorData ("attr.rerun.component_required", order: 1000);

// --- Optional ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ table SegmentationImage (
) {
// --- Required ---

/// The image data. Should always be a rank-2 tensor.
/// The image data. Should always be a 2-dimensional tensor.
data: rerun.components.TensorData ("attr.rerun.component_required", order: 1000);

// --- Optional ---
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/src/archetypes/bar_chart.rs

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

2 changes: 1 addition & 1 deletion crates/re_types/src/archetypes/depth_image.rs

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

2 changes: 1 addition & 1 deletion crates/re_types/src/archetypes/image.rs

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

2 changes: 1 addition & 1 deletion crates/re_types/src/archetypes/segmentation_image.rs

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

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/bar_chart.hpp

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

8 changes: 4 additions & 4 deletions rerun_cpp/src/rerun/archetypes/depth_image.hpp

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

12 changes: 8 additions & 4 deletions rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "../collection_adapter_builtins.hpp"

#include <sstream>

namespace rerun::archetypes {

#ifdef EDIT_EXTENSION
Expand All @@ -11,7 +13,7 @@ namespace rerun::archetypes {
/// New depth image from height/width and tensor buffer.
///
/// \param shape
/// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
/// Shape of the image. Calls `Error::handle()` if the tensor is not 2-dimensional
/// Sets the dimension names to "height" and "width" if they are not specified.
/// \param buffer
/// The tensor buffer containing the depth image data.
Expand All @@ -23,14 +25,14 @@ namespace rerun::archetypes {
/// \param data_
/// The tensor buffer containing the depth image data.
/// Sets the dimension names to "height" and "width" if they are not specified.
/// Calls `Error::handle()` if the shape is not rank 2.
/// Calls `Error::handle()` if the tensor is not 2-dimensional
explicit DepthImage(components::TensorData data_);

/// New depth image from dimensions and pointer to depth image data.
///
/// Type must be one of the types supported by `rerun::datatypes::TensorData`.
/// \param shape
/// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
/// Shape of the image. Calls `Error::handle()` if the tensor is not 2-dimensional
/// Sets the dimension names to "height", "width" and "channel" if they are not specified.
/// Determines the number of elements expected to be in `data`.
/// \param data_
Expand All @@ -45,7 +47,9 @@ namespace rerun::archetypes {
DepthImage::DepthImage(components::TensorData data_) : data(std::move(data_)) {
auto& shape = data.data.shape;
if (shape.size() != 2) {
Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle();
std::stringstream ss;
ss << "Expected 2-dimensional tensor, got " << shape.size() << " dimensions.";
Error(ErrorCode::InvalidTensorDimension, ss.str()).handle();
return;
}

Expand Down
8 changes: 4 additions & 4 deletions rerun_cpp/src/rerun/archetypes/image.hpp

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

16 changes: 8 additions & 8 deletions rerun_cpp/src/rerun/archetypes/image_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "../collection_adapter_builtins.hpp"

#include <sstream>

// Uncomment for better auto-complete while editing the extension.
// #define EDIT_EXTENSION

Expand All @@ -14,7 +16,7 @@ namespace rerun::archetypes {
/// New Image from height/width/channel and tensor buffer.
///
/// \param shape
/// Shape of the image. Calls `Error::handle()` if the shape is not rank 2 or 3.
/// Shape of the image. Calls `Error::handle()` if the tensor is not 2- or 3-dimensional.
/// Sets the dimension names to "height", "width" and "channel" if they are not specified.
/// \param buffer
/// The tensor buffer containing the image data.
Expand All @@ -26,14 +28,14 @@ namespace rerun::archetypes {
/// \param data_
/// The tensor buffer containing the image data.
/// Sets the dimension names to "height", "width" and "channel" if they are not specified.
/// Calls `Error::handle()` if the shape is not rank 2 or 3.
/// Calls `Error::handle()` if the tensor is not 2- or 3-dimensional.
explicit Image(rerun::components::TensorData data_);

/// New image from dimensions and pointer to image data.
///
/// Type must be one of the types supported by `rerun::datatypes::TensorData`.
/// \param shape
/// Shape of the image. Calls `Error::handle()` if the shape is not rank 2 or 3.
/// Shape of the image. Calls `Error::handle()` if the tensor is not 2- or 3-dimensional.
/// Sets the dimension names to "height", "width" and "channel" if they are not specified.
/// Determines the number of elements expected to be in `data`.
/// \param data_
Expand All @@ -48,11 +50,9 @@ namespace rerun::archetypes {
Image::Image(rerun::components::TensorData data_) : data(std::move(data_)) {
auto& shape = data.data.shape;
if (shape.size() != 2 && shape.size() != 3) {
Error(
ErrorCode::InvalidTensorDimension,
"Image shape is expected to be either rank 2 or 3."
)
.handle();
std::stringstream ss;
ss << "Expected 2- or 3-dimensional tensor, got " << shape.size() << " dimensions.";
Error(ErrorCode::InvalidTensorDimension, ss.str()).handle();
return;
}
if (shape.size() == 3 && shape[2].size != 1 && shape[2].size != 3 && shape[2].size != 4) {
Expand Down
8 changes: 4 additions & 4 deletions rerun_cpp/src/rerun/archetypes/segmentation_image.hpp

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

12 changes: 8 additions & 4 deletions rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "../collection_adapter_builtins.hpp"
#include "../error.hpp"

#include <sstream>

namespace rerun::archetypes {

#if 0
Expand All @@ -11,7 +13,7 @@ namespace rerun::archetypes {
/// New segmentation image from height/width and tensor buffer.
///
/// \param shape
/// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
/// Shape of the image. Calls `Error::handle()` if the tensor is not 2-dimensional
/// Sets the dimension names to "height" and "width" if they are not specified.
/// \param buffer
/// The tensor buffer containing the segmentation image data.
Expand All @@ -23,14 +25,14 @@ namespace rerun::archetypes {
/// \param data_
/// The tensor buffer containing the segmentation image data.
/// Sets the dimension names to "height" and "width" if they are not specified.
/// Calls `Error::handle()` if the shape is not rank 2.
/// Calls `Error::handle()` if the tensor is not 2-dimensional
explicit SegmentationImage(components::TensorData data_);

/// New segmentation image from dimensions and pointer to segmentation image data.
///
/// Type must be one of the types supported by `rerun::datatypes::TensorData`.
/// \param shape
/// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
/// Shape of the image. Calls `Error::handle()` if the tensor is not 2-dimensional
/// Sets the dimension names to "height", "width" and "channel" if they are not specified.
/// Determines the number of elements expected to be in `data`.
/// \param data_
Expand All @@ -45,7 +47,9 @@ namespace rerun::archetypes {
SegmentationImage::SegmentationImage(components::TensorData data_) : data(std::move(data_)) {
auto& shape = data.data.shape;
if (shape.size() != 2) {
Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle();
std::stringstream ss;
ss << "Expected 2-dimensional tensor, got " << shape.size() << " dimensions.";
Error(ErrorCode::InvalidTensorDimension, ss.str()).handle();
return;
}

Expand Down
10 changes: 5 additions & 5 deletions rerun_cpp/tests/archetypes/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace rerun::archetypes;
#define TEST_TAG "[image][archetypes]"

SCENARIO("Image archetype can be created from tensor data." TEST_TAG) {
GIVEN("tensor data with correct rank 2 shape") {
GIVEN("tensor data with correct 2-dimensional shape") {
rerun::datatypes::TensorData data({3, 7}, std::vector<uint8_t>(3 * 7, 0));
THEN("no error occurs on image construction") {
auto image = check_logged_error([&] { return Image(std::move(data)); });
Expand All @@ -22,7 +22,7 @@ SCENARIO("Image archetype can be created from tensor data." TEST_TAG) {
}
}
}
GIVEN("tensor data with correct rank 3 shape") {
GIVEN("tensor data with correct 3-dimensional shape") {
rerun::datatypes::TensorData data({3, 7, 3}, std::vector<uint8_t>(3 * 7 * 3, 0));
THEN("no error occurs on image construction") {
auto image = check_logged_error([&] { return Image(std::move(data)); });
Expand All @@ -38,7 +38,7 @@ SCENARIO("Image archetype can be created from tensor data." TEST_TAG) {
}
}
}
GIVEN("tensor data with incorrect rank 3 shape") {
GIVEN("tensor data with incorrect 3-dimensional shape") {
rerun::datatypes::TensorData data({3, 7, 2}, std::vector<uint8_t>(3 * 7 * 2, 0));
THEN("a warning occurs on image construction") {
auto image = check_logged_error(
Expand Down Expand Up @@ -72,7 +72,7 @@ SCENARIO("Image archetype can be created from tensor data." TEST_TAG) {
}
}

GIVEN("tensor data with too high rank") {
GIVEN("tensor data with too high dimensionality") {
rerun::datatypes::TensorData data(
{
{
Expand Down Expand Up @@ -103,7 +103,7 @@ SCENARIO("Image archetype can be created from tensor data." TEST_TAG) {
}
}

GIVEN("tensor data with too low rank") {
GIVEN("tensor data with too low dimensionality") {
rerun::datatypes::TensorData data(
{
rerun::datatypes::TensorDimension(1, "dr robotnik"),
Expand Down
4 changes: 2 additions & 2 deletions rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void run_image_tests() {
}
}

GIVEN("tensor data with too high rank") {
GIVEN("tensor data with too high dimensionality") {
rerun::datatypes::TensorData data(
{
{
Expand Down Expand Up @@ -75,7 +75,7 @@ void run_image_tests() {
}
}

GIVEN("tensor data with too low rank") {
GIVEN("tensor data with too low dimensionality") {
rerun::datatypes::TensorData data(
{
rerun::datatypes::TensorDimension(1, "dr robotnik"),
Expand Down
Loading
Loading