Skip to main content

TensorSpec.h File

Tensor constraints and matching helpers. More...

Included Headers

#include "pipeline/TensorCore.h" #include <optional> #include <string> #include <vector>

Namespaces Index

namespacesimaai
namespaceneat

Classes Index

structTensorConstraint

Description

Tensor constraints and matching helpers.

File Listing

The file content with the documentation metadata removed is:

1
6#pragma once
7
9
10#include <optional>
11#include <string>
12#include <vector>
13
14namespace simaai::neat {
15
17 std::vector<simaai::neat::TensorDType> dtypes;
18 int rank = -1;
19 std::vector<int64_t> shape; // use -1 for dynamic dims
20 std::optional<Device> device;
21 std::vector<Device> allowed_devices;
22 std::optional<Device> preferred_device;
23
24 std::optional<ImageSpec::PixelFormat> image_format;
25 std::vector<Segment> required_segments;
26 std::vector<std::string> required_segment_names;
27 bool allow_composite = true;
28
29 bool matches(const Tensor& t) const {
30 if (rank >= 0 && static_cast<int>(t.shape.size()) != rank)
31 return false;
32 if (!shape.empty() && shape.size() == t.shape.size()) {
33 for (size_t i = 0; i < shape.size(); ++i) {
34 if (shape[i] >= 0 && t.shape[i] != shape[i])
35 return false;
36 }
37 }
38 if (!dtypes.empty()) {
39 bool ok = false;
40 for (auto dt : dtypes) {
41 if (dt == t.dtype) {
42 ok = true;
43 break;
44 }
45 }
46 if (!ok)
47 return false;
48 }
49 if (device.has_value()) {
50 if (t.device.type != device->type || t.device.id != device->id)
51 return false;
52 }
53 if (!allowed_devices.empty()) {
54 bool ok = false;
55 for (const auto& allowed : allowed_devices) {
56 if (t.device.type == allowed.type && t.device.id == allowed.id) {
57 ok = true;
58 break;
59 }
60 }
61 if (!ok)
62 return false;
63 }
64 if (image_format.has_value()) {
65 if (!t.semantic.image.has_value())
66 return false;
67 if (t.semantic.image->format != *image_format)
68 return false;
69 }
70 if (!required_segments.empty()) {
71 if (!t.storage || t.storage->sima_segments.empty())
72 return false;
73 if (t.storage->sima_segments.size() != required_segments.size())
74 return false;
75 for (size_t i = 0; i < required_segments.size(); ++i) {
76 if (t.storage->sima_segments[i].name != required_segments[i].name)
77 return false;
78 if (t.storage->sima_segments[i].size_bytes != required_segments[i].size_bytes) {
79 return false;
80 }
81 }
82 }
83 if (!required_segment_names.empty()) {
84 if (!t.storage || t.storage->sima_segments.empty())
85 return false;
86 for (const auto& name : required_segment_names) {
87 bool found = false;
88 for (const auto& seg : t.storage->sima_segments) {
89 if (seg.name == name) {
90 found = true;
91 break;
92 }
93 }
94 if (!found)
95 return false;
96 }
97 }
99 return false;
100 return true;
101 }
102};
103
104} // namespace simaai::neat

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.