2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
bool NDIndex::isInterval() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Nd4jLong NDIndex::stride() {
|
|
|
|
return _stride;
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::NDIndexAll::NDIndexAll() : sd::NDIndex() {
|
2019-06-06 14:21:15 +02:00
|
|
|
_indices.push_back(-1);
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::NDIndexPoint::NDIndexPoint(Nd4jLong point) : sd::NDIndex() {
|
2019-06-06 14:21:15 +02:00
|
|
|
this->_indices.push_back(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NDIndexAll::isInterval() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NDIndexPoint::isInterval() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NDIndexInterval::isInterval() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::NDIndexInterval::NDIndexInterval(Nd4jLong start, Nd4jLong end, Nd4jLong stride) : sd::NDIndex() {
|
2019-06-06 14:21:15 +02:00
|
|
|
this->_stride = stride;
|
|
|
|
for (int e = start; e < end; e+= stride)
|
|
|
|
this->_indices.push_back(e);
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
bool sd::NDIndex::isAll() {
|
2019-06-06 14:21:15 +02:00
|
|
|
return _indices.size() == 1 && _indices.at(0) == -1;
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
bool sd::NDIndex::isPoint() {
|
2019-06-06 14:21:15 +02:00
|
|
|
return _indices.size() == 1 && _indices.at(0) >= 0;
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
std::vector<Nd4jLong> &sd::NDIndex::getIndices() {
|
2019-06-06 14:21:15 +02:00
|
|
|
return _indices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::NDIndex *sd::NDIndex::all() {
|
2019-06-06 14:21:15 +02:00
|
|
|
return new NDIndexAll();
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::NDIndex *sd::NDIndex::point(Nd4jLong pt) {
|
2019-06-06 14:21:15 +02:00
|
|
|
return new NDIndexPoint(pt);
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::NDIndex *sd::NDIndex::interval(Nd4jLong start, Nd4jLong end, Nd4jLong stride) {
|
2019-06-06 14:21:15 +02:00
|
|
|
return new NDIndexInterval(start, end, stride);
|
|
|
|
}
|
|
|
|
}
|