Skip to content

Commit

Permalink
Add another datatype to check if it's easy to add another datatype (#4)
Browse files Browse the repository at this point in the history
# Objective

This PR adds a new datatype for **BBox** to ensure that everything work
well and it's easy to add a new datatype.

# Datatypes & Usage

- [x] Image

```Rust
use crate::image::Image;

let flat_image = (0..27).collect::<Vec<u8>>();
let image = Image::new_rgb8(flat_image, 3, 3, Some("camera.test")).unwrap();

let final_image = image.into_bgr8().unwrap();
let final_image_data = final_image.data.as_u8().unwrap();

let expected_image = vec![
    2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21,
    26, 25, 24,
];

assert_eq!(&expected_image, final_image_data);

use crate::image::Image;

let flat_image = vec![0; 27];
let original_buffer_address = flat_image.as_ptr();

let bgr8_image = Image::new_bgr8(flat_image, 3, 3, None).unwrap();
let image_buffer_address = bgr8_image.as_ptr();

let arrow_image = bgr8_image.into_arrow().unwrap();

let new_image = Image::from_arrow(arrow_image).unwrap();
let final_image_buffer = new_image.as_ptr();

assert_eq!(original_buffer_address, image_buffer_address);
assert_eq!(image_buffer_address, final_image_buffer);
```

- [x] BBox

```Rust
use crate::bbox::BBox;

let flat_bbox = vec![1.0, 1.0, 2.0, 2.0];
let confidence = vec![0.98];
let label = vec!["cat".to_string()];

let bbox = BBox::new_xyxy(flat_bbox, confidence, label).unwrap();
let final_bbox = bbox.into_xywh().unwrap();
let final_bbox_data = final_bbox.data;

let expected_bbox = vec![1.0, 1.0, 1.0, 1.0];

assert_eq!(expected_bbox, final_bbox_data);

use crate::bbox::BBox;

let flat_bbox = vec![1.0, 1.0, 2.0, 2.0];
let original_buffer_address = flat_bbox.as_ptr();

let confidence = vec![0.98];
let label = vec!["cat".to_string()];

let xyxy_bbox = BBox::new_xyxy(flat_bbox, confidence, label).unwrap();
let bbox_buffer_address = xyxy_bbox.data.as_ptr();

let arrow_bbox = xyxy_bbox.into_arrow().unwrap();

let new_bbox = BBox::from_arrow(arrow_bbox).unwrap();
let final_bbox_buffer = new_bbox.data.as_ptr();

assert_eq!(original_buffer_address, bbox_buffer_address);
assert_eq!(bbox_buffer_address, final_bbox_buffer);
```

# Quick Fixes

- I also improved readability and consistency with Rust formatting,
following the guidelines mentioned in [this
comment](#1 (comment)).
- Fix Arrow Array extraction from Union inside #3 
- Fix Dora compatibility (by viewing objects when it's not possible to
own them) inside #5
- I improved the structure of the library, with separated packages and
with some `features` as one might want to use `fastformat` only with
ndarray/arrow. #6
  • Loading branch information
Hennzau authored Sep 9, 2024
2 parents 0827e04 + 7b6a2d7 commit bf356e0
Show file tree
Hide file tree
Showing 44 changed files with 4,283 additions and 1,684 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ jobs:
cache-directories: ${{ env.CARGO_TARGET_DIR }}

- name: "Check"
run: cargo check --all
- name: "Build (Without Python node as it is build with maturin)"
run: cargo build --all --exclude dora-node-api-python
- name: "Test"
run: cargo test --all --exclude dora-ros2-bridge-python
run: cargo check --all --all-features

clippy:
name: "Clippy"
Expand All @@ -48,14 +44,7 @@ jobs:
- run: cargo --version --verbose

- name: "Clippy"
run: cargo clippy --all
- name: "Clippy (tracing feature)"
run: cargo clippy --all --features tracing
if: false # only the dora-runtime has this feature, but it is currently commented out
- name: "Clippy (metrics feature)"
run: cargo clippy --all --features metrics
if: false # only the dora-runtime has this feature, but it is currently commented out

run: cargo clippy --all --all-features
rustfmt:
name: "Formatting"
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pip_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --manifest-path libraries/fastformat/Cargo.toml --all-features
sccache: "true"
manylinux: auto
- name: Upload wheels
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --manifest-path libraries/fastformat/Cargo.toml --all-features
sccache: "true"
manylinux: musllinux_1_2
- name: Upload wheels
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
target: ${{ matrix.platform.target }}
manylinux: auto
container: off
args: --release -o dist -i 3.8
args: --release -o dist -i 3.8 --manifest-path libraries/fastformat/Cargo.toml --all-features
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand All @@ -134,7 +134,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --manifest-path libraries/fastformat/Cargo.toml --all-features
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand All @@ -160,7 +160,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --manifest-path libraries/fastformat/Cargo.toml --all-features
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand All @@ -176,7 +176,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
args: --out dist --manifest-path libraries/fastformat/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
Expand Down
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __pycache__/
.pytest_cache/
*.py[cod]

# C extensions
# C extensionst
*.so

# Distribution / packaging
Expand Down Expand Up @@ -70,3 +70,15 @@ docs/_build/

# Pyenv
.python-version

# PyO3 config
.pyo3_config

# UV
uv.lock

# Dora
dora-coordinator.txt
dora-daemon.txt

out/
Loading

0 comments on commit bf356e0

Please sign in to comment.