chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:47:05 +08:00
commit 4f3b7da785
7394 changed files with 2005594 additions and 0 deletions
@@ -0,0 +1,45 @@
/* ******************************************************************************
*
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
//
// @author raver119@gmail.com
//
#include <indexing/IndicesList.h>
using namespace sd;
IndicesList::IndicesList(std::initializer_list<NDIndex*> list) {
for (auto v : list) _indices.emplace_back(v);
}
IndicesList::~IndicesList() {
}
int IndicesList::size() { return (int)_indices.size(); }
bool IndicesList::isScalar() {
if (_indices.size() == 1) {
return _indices.at(0)->isPoint();
}
return false;
}
NDIndex* IndicesList::at(int idx) { return _indices.at(idx); }
void IndicesList::push_back(NDIndex* idx) { _indices.emplace_back(idx); }
+58
View File
@@ -0,0 +1,58 @@
/* ******************************************************************************
*
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
//
// @author raver119@gmail.com
//
#include <indexing/NDIndex.h>
namespace sd {
bool NDIndex::isInterval() { return false; }
LongType NDIndex::stride() { return _stride; }
NDIndexAll::NDIndexAll() : NDIndex() { _indices.push_back(-1); }
NDIndexPoint::NDIndexPoint(LongType point) : NDIndex() { this->_indices.push_back(point); }
bool NDIndexAll::isInterval() { return false; }
bool NDIndexPoint::isInterval() { return false; }
bool NDIndexInterval::isInterval() { return true; }
NDIndexInterval::NDIndexInterval(LongType start, LongType end, LongType stride) : NDIndex() {
this->_stride = stride;
for (int e = start; e < end; e += stride) this->_indices.push_back(e);
}
bool NDIndex::isAll() { return _indices.size() == 1 && _indices.at(0) == -1; }
bool NDIndex::isPoint() { return _indices.size() == 1 && _indices.at(0) >= 0; }
std::vector<LongType> &NDIndex::getIndices() { return _indices; }
NDIndex *NDIndex::all() { return new NDIndexAll(); }
NDIndex *NDIndex::point(LongType pt) { return new NDIndexPoint(pt); }
NDIndex *NDIndex::interval(LongType start, LongType end, LongType stride) {
return new NDIndexInterval(start, end, stride);
}
} // namespace sd
@@ -0,0 +1,38 @@
//
// Created by agibsonccc on 4/26/22.
//
#include <indexing/NDIndexUtils.h>
namespace sd {
NDArray NDIndexUtils::createInterval(LongType start, LongType end, LongType stride, bool inclusive) {
// index type, num indices,stride, indices (length num indices), inclusive
auto indexFirstPoint =
NDArrayFactory::create<LongType>('c', {7}, {INTERVAL_TYPE, 2, 1, start, end, stride, inclusive ? 1 : 0});
return indexFirstPoint;
}
NDArray NDIndexUtils::createInterval(LongType start, LongType end, LongType stride, LongType inclusive) {
// index type, num indices,stride, indices (length num indices), inclusive
auto indexFirstPoint =
NDArrayFactory::create<LongType>('c', {7}, {INTERVAL_TYPE, 2, 1, start, end, stride, inclusive});
return indexFirstPoint;
}
NDArray NDIndexUtils::createPoint(LongType offset) {
// index type, num indices,stride, indices (length num indices), inclusive
auto indexFirstPoint = NDArrayFactory::create<LongType>('c', {5}, {POINT_TYPE, 1, 1, offset, DEFAULT_INCLUSIVE});
return indexFirstPoint;
}
NDArray NDIndexUtils::createNewAxis() {
// index type, num indices,stride, indices (length num indices), inclusive
auto indexFirstPoint = NDArrayFactory::create<LongType>('c', {5}, {NEW_AXIS, 1, 1, 0, DEFAULT_INCLUSIVE});
return indexFirstPoint;
}
NDArray NDIndexUtils::createAll() {
// index type, num indices,stride, indices (length num indices), inclusive
auto indexFirstPoint = NDArrayFactory::create<LongType>('c',{4},{ALL_TYPE,0,1,DEFAULT_INCLUSIVE});
return indexFirstPoint;
}
}