Skip to main content

TensorConstraint Struct

Declarative tensor contract — describes the shape/dtype/device/format a tensor must satisfy. More...

Declaration

struct simaai::neat::TensorConstraint { ... }

Included Headers

#include <TensorSpec.h>

Public Member Functions Index

boolmatches (const Tensor &t) const

Returns true if t satisfies every non-empty constraint in this spec. More...

Public Member Attributes Index

std::vector< simaai::neat::TensorDType >dtypes

Acceptable dtypes (empty = any). More...

intrank = -1

Required rank (-1 = any). More...

std::vector< int64_t >shape

Required shape; -1 in any position means dynamic. More...

std::optional< Device >device

Required device (empty = any). More...

std::vector< Device >allowed_devices

Acceptable devices (empty = any). More...

std::optional< Device >preferred_device

Preferred device for placement (informational). More...

std::optional< ImageSpec::PixelFormat >image_format

Required image pixel format (only meaningful for image tensors). More...

std::vector< Segment >required_segments

Exact required memory-segment layout (advanced). More...

std::vector< std::string >required_segment_names

Required memory-segment names (must all be present). More...

boolallow_composite = true

If false, reject composite (multi-plane) tensors like NV12. More...

Description

Declarative tensor contract — describes the shape/dtype/device/format a tensor must satisfy.

Used by Model::input_spec()/output_spec() to advertise what the model expects/produces, and by validation code to verify a tensor meets the contract via matches(). Empty fields mean "no constraint on this dimension." Use -1 in shape for dynamic axes.

 sima::TensorConstraint c;
 c.dtypes = { sima::TensorDType::Float32, sima::TensorDType::BFloat16 };
 c.rank = 4;
 c.shape = { 1, 3, -1, -1 }; // batch=1, channels=3, H/W dynamic
 if (!c.matches(my_tensor)) { ... }

Definition at line 44 of file TensorSpec.h.

Public Member Functions

matches()

bool simaai::neat::TensorConstraint::matches (const Tensor & t)
inline

Returns true if t satisfies every non-empty constraint in this spec.

Empty fields are skipped (treated as "no constraint"). Useful for inline validation in application code and as the underlying check used by built-in contracts.

Definition at line 65 of file TensorSpec.h.

65 bool matches(const Tensor& t) const {
66 if (rank >= 0 && static_cast<int>(t.shape.size()) != rank)
67 return false;
68 if (!shape.empty() && shape.size() == t.shape.size()) {
69 for (size_t i = 0; i < shape.size(); ++i) {
70 if (shape[i] >= 0 && t.shape[i] != shape[i])
71 return false;
72 }
73 }
74 if (!dtypes.empty()) {
75 bool ok = false;
76 for (auto dt : dtypes) {
77 if (dt == t.dtype) {
78 ok = true;
79 break;
80 }
81 }
82 if (!ok)
83 return false;
84 }
85 if (device.has_value()) {
86 if (t.device.type != device->type || t.device.id != device->id)
87 return false;
88 }
89 if (!allowed_devices.empty()) {
90 bool ok = false;
91 for (const auto& allowed : allowed_devices) {
92 if (t.device.type == allowed.type && t.device.id == allowed.id) {
93 ok = true;
94 break;
95 }
96 }
97 if (!ok)
98 return false;
99 }
100 if (image_format.has_value()) {
101 if (!t.semantic.image.has_value())
102 return false;
103 if (t.semantic.image->format != *image_format)
104 return false;
105 }
106 if (!required_segments.empty()) {
107 if (!t.storage || t.storage->sima_segments.empty())
108 return false;
109 if (t.storage->sima_segments.size() != required_segments.size())
110 return false;
111 for (size_t i = 0; i < required_segments.size(); ++i) {
112 if (t.storage->sima_segments[i].name != required_segments[i].name)
113 return false;
114 if (t.storage->sima_segments[i].size_bytes != required_segments[i].size_bytes) {
115 return false;
116 }
117 }
118 }
119 if (!required_segment_names.empty()) {
120 if (!t.storage || t.storage->sima_segments.empty())
121 return false;
122 for (const auto& name : required_segment_names) {
123 bool found = false;
124 for (const auto& seg : t.storage->sima_segments) {
125 if (seg.name == name) {
126 found = true;
127 break;
128 }
129 }
130 if (!found)
131 return false;
132 }
133 }
134 if (!allow_composite && t.is_composite())
135 return false;
136 return true;
137 }

Public Member Attributes

allow_composite

bool simaai::neat::TensorConstraint::allow_composite = true

If false, reject composite (multi-plane) tensors like NV12.

Definition at line 57 of file TensorSpec.h.

57 bool allow_composite = true;

allowed_devices

std::vector<Device> simaai::neat::TensorConstraint::allowed_devices

Acceptable devices (empty = any).

Definition at line 49 of file TensorSpec.h.

49 std::vector<Device> allowed_devices;

device

std::optional<Device> simaai::neat::TensorConstraint::device

Required device (empty = any).

Definition at line 48 of file TensorSpec.h.

48 std::optional<Device> device;

dtypes

std::vector<simaai::neat::TensorDType> simaai::neat::TensorConstraint::dtypes

Acceptable dtypes (empty = any).

Definition at line 45 of file TensorSpec.h.

45 std::vector<simaai::neat::TensorDType> dtypes;

image_format

std::optional<ImageSpec::PixelFormat> simaai::neat::TensorConstraint::image_format

Required image pixel format (only meaningful for image tensors).

Definition at line 53 of file TensorSpec.h.

preferred_device

std::optional<Device> simaai::neat::TensorConstraint::preferred_device

Preferred device for placement (informational).

Definition at line 50 of file TensorSpec.h.

50 std::optional<Device> preferred_device;

rank

int simaai::neat::TensorConstraint::rank = -1

Required rank (-1 = any).

Definition at line 46 of file TensorSpec.h.

46 int rank = -1;

required_segment_names

std::vector<std::string> simaai::neat::TensorConstraint::required_segment_names

Required memory-segment names (must all be present).

Definition at line 56 of file TensorSpec.h.

required_segments

std::vector<Segment> simaai::neat::TensorConstraint::required_segments

Exact required memory-segment layout (advanced).

Definition at line 54 of file TensorSpec.h.

54 std::vector<Segment> required_segments;

shape

std::vector<int64_t> simaai::neat::TensorConstraint::shape

Required shape; -1 in any position means dynamic.

Definition at line 47 of file TensorSpec.h.

47 std::vector<int64_t> shape;

The documentation for this struct was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.