MLX
 
Loading...
Searching...
No Matches
indexing.h
Go to the documentation of this file.
1// Copyright © 2023-2024 Apple Inc.
2
3#pragma once
4
5#include <metal_stdlib>
6
7template <typename IdxT, int NIDX>
8struct Indices {
9 const array<const device IdxT*, NIDX> buffers;
10 const constant int* shapes;
11 const constant int64_t* strides;
12 const constant bool* row_contiguous;
13 const int ndim;
14};
15
16template <typename IdxT>
17METAL_FUNC size_t offset_neg_idx(IdxT idx, int size) {
18 if (is_unsigned_v<IdxT>) {
19 return idx;
20 } else {
21 return (idx < 0) ? idx + size : idx;
22 }
23}
METAL_FUNC size_t offset_neg_idx(IdxT idx, int size)
Definition indexing.h:17
Definition indexing.h:8
const constant bool * row_contiguous
Definition indexing.h:12
const constant int64_t * strides
Definition indexing.h:11
const constant int * shapes
Definition indexing.h:10
const int ndim
Definition indexing.h:13
const array< const device IdxT *, NIDX > buffers
Definition indexing.h:9