include/tenzr/apiutils/apiutils.h
Namespaces
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_APIUTILS_APIUTILS_H_
#define TENZR_APIUTILS_APIUTILS_H_
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include "tenzr/common/export.h"
#include "tenzr/frontend/dtype.h"
#include "tenzr/frontend/shape.h"
namespace tenzr::apiutils {
[[nodiscard]] TENZR_API int64_t CanonicalizeAxis(int64_t axis, size_t rank);
[[nodiscard]] TENZR_API std::vector<int64_t> CanonicalizeAxes(const std::vector<int64_t>& axes, size_t rank);
[[nodiscard]] TENZR_API std::vector<int64_t> ComputeContiguousStrides(const Shape& shape);
[[nodiscard]] TENZR_API int64_t ComputeElementOffset(const std::vector<int64_t>& indices, const std::vector<int64_t>& strides, int64_t base_offset = 0);
[[nodiscard]] TENZR_API bool AreBroadcastCompatible(const Shape& a, const Shape& b) noexcept;
[[nodiscard]] TENZR_API Shape BroadcastShapes(const Shape& a, const Shape& b);
[[nodiscard]] TENZR_API Shape BroadcastShapes(const std::vector<Shape>& shapes);
[[nodiscard]] TENZR_API Shape SqueezeShape(const Shape& shape, const std::vector<int64_t>& axes);
[[nodiscard]] TENZR_API Shape SqueezeAllUnitDims(const Shape& shape);
[[nodiscard]] TENZR_API Shape ExpandDimsShape(const Shape& shape, int64_t axis);
[[nodiscard]] TENZR_API Shape FlattenShape(const Shape& shape);
} // namespace tenzr::apiutils
#endif // TENZR_APIUTILS_APIUTILS_H_