include/tenzr/check/check.h¶
Namespaces¶
| Name |
|---|
| tenzr |
| tenzr::check |
Classes¶
| Name | |
|---|---|
| struct | tenzr::check::DeviceTestTarget A test device target pairing its name with whether it is available on this machine. |
| class | tenzr::check::HardwareHarness Test helper that discovers available device targets and runs a test body once per target. |
Defines¶
| Name | |
|---|---|
| TENZR_ASSERT_SHAPE(tensor, expected_shape) Assertion macros calling the matching tenzr::check routine with the caller's file and line. |
|
| TENZR_ASSERT_DTYPE(tensor, expected_dtype) | |
| TENZR_ASSERT_DEVICE(tensor, expected_dev) | |
| TENZR_ASSERT_CLOSE_TOL(actual, expected, rtol, atol) | |
| TENZR_ASSERT_CLOSE(actual, expected) |
Macros Documentation¶
define TENZR_ASSERT_SHAPE¶
#define TENZR_ASSERT_SHAPE(
tensor,
expected_shape
)
::tenzr::check::AssertShape((tensor), (expected_shape), __FILE__, __LINE__)
Assertion macros calling the matching tenzr::check routine with the caller's file and line.
define TENZR_ASSERT_DTYPE¶
#define TENZR_ASSERT_DTYPE(
tensor,
expected_dtype
)
::tenzr::check::AssertDtype((tensor), (expected_dtype), __FILE__, __LINE__)
define TENZR_ASSERT_DEVICE¶
#define TENZR_ASSERT_DEVICE(
tensor,
expected_dev
)
::tenzr::check::AssertDevice((tensor), (expected_dev), __FILE__, __LINE__)
define TENZR_ASSERT_CLOSE_TOL¶
#define TENZR_ASSERT_CLOSE_TOL(
actual,
expected,
rtol,
atol
)
::tenzr::check::AssertClose((actual), (expected), (rtol), (atol), __FILE__, __LINE__)
define TENZR_ASSERT_CLOSE¶
#define TENZR_ASSERT_CLOSE(
actual,
expected
)
::tenzr::check::AssertClose((actual), (expected), __FILE__, __LINE__)
Source code¶
// Copyright 2026 The Tenzr Project Authors
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef TENZR_CHECK_CHECK_H_
#define TENZR_CHECK_CHECK_H_
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include "tenzr/frontend/dtype.h"
#include "tenzr/frontend/shape.h"
#include "tenzr/frontend/tensor.h"
namespace tenzr::check {
void AssertShape(const Tensor& t, const Shape& expected, const char* file, int line);
void AssertDtype(const Tensor& t, DType expected, const char* file, int line);
void AssertDevice(const Tensor& t, const std::string& expected_device, const char* file, int line);
void AssertClose(const Tensor& actual, const Tensor& expected, double rtol, double atol, const char* file, int line);
void AssertClose(const Tensor& actual, const Tensor& expected, const char* file, int line);
struct DeviceTestTarget {
std::string name;
bool is_available{false};
};
class HardwareHarness {
public:
static std::vector<DeviceTestTarget> AvailableTargets();
static void RunOnAllAvailableDevices(const std::function<void(const std::string& target_name)>& test_fn);
};
} // namespace tenzr::check
#define TENZR_ASSERT_SHAPE(tensor, expected_shape) ::tenzr::check::AssertShape((tensor), (expected_shape), __FILE__, __LINE__)
#define TENZR_ASSERT_DTYPE(tensor, expected_dtype) ::tenzr::check::AssertDtype((tensor), (expected_dtype), __FILE__, __LINE__)
#define TENZR_ASSERT_DEVICE(tensor, expected_dev) ::tenzr::check::AssertDevice((tensor), (expected_dev), __FILE__, __LINE__)
#define TENZR_ASSERT_CLOSE_TOL(actual, expected, rtol, atol) ::tenzr::check::AssertClose((actual), (expected), (rtol), (atol), __FILE__, __LINE__)
#define TENZR_ASSERT_CLOSE(actual, expected) ::tenzr::check::AssertClose((actual), (expected), __FILE__, __LINE__)
#endif // TENZR_CHECK_CHECK_H_