include/tenzr/frontend/shape.h
Namespaces
Classes
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_FRONTEND_SHAPE_H_
#define TENZR_FRONTEND_SHAPE_H_
#include <cstdint>
#include <initializer_list>
#include <string>
#include <vector>
#include "tenzr/frontend/dtype.h"
namespace tenzr {
class Shape {
public:
Shape() = default;
Shape(std::initializer_list<int64_t> dims);
explicit Shape(std::vector<int64_t> dims);
size_t Rank() const { return dims_.size(); }
int64_t Dim(size_t index) const;
int64_t operator[](size_t index) const { return Dim(index); }
const std::vector<int64_t>& Dims() const { return dims_; }
int64_t NumElements() const;
std::vector<int64_t> ComputeContiguousStrides() const;
bool operator==(const Shape& other) const { return dims_ == other.dims_; }
bool operator!=(const Shape& other) const { return dims_ != other.dims_; }
std::string ToString() const;
std::string ToMlirTensorType(DType dtype) const;
static Shape Broadcast(const Shape& a, const Shape& b);
static bool CanBroadcast(const Shape& a, const Shape& b) noexcept;
private:
std::vector<int64_t> dims_;
};
} // namespace tenzr
#endif // TENZR_FRONTEND_SHAPE_H_