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,44 @@
/* ******************************************************************************
*
*
* 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 <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_clone_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(clone_list, 1, 1, 0, 0) {
auto list = INPUT_LIST(0);
auto newList = list->clone();
// OVERWRITE_RESULT(newList);
setupResultList(newList, block);
return Status::OK;
}
DECLARE_SYN(TensorArrayIdentityV3, clone_list);
DECLARE_SYN(tensorarrayidentityv3, clone_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,66 @@
/* ******************************************************************************
*
*
* 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
******************************************************************************/
//
// Created by raver119 on 06.11.2017.
//
#include <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_create_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(create_list, -2, 2, 0, -2) {
int height = 0;
bool expandable = false;
if (block.numI() == 2) {
height = INT_ARG(0);
expandable = (bool)INT_ARG(1);
} else if (block.numI() == 1) {
height = INT_ARG(0);
} else if (block.width() == 1) {
height = INPUT_VARIABLE(0)->e<int>(0);
expandable = true;
} else {
height = 0;
expandable = true;
}
auto list = new NDArrayList(height, expandable);
// we receive input array for graph integrity purposes only
//mainly a marker for now, representing the fixed shape the elements can be
setupResultList(list, block);
auto scalar = NDArrayFactory::create_(list->counter());
block.pushNDArrayToVariableSpace(block.getNodeId(), 1, scalar);
return Status::OK;
}
DECLARE_SYN(TensorArrayV3, create_list);
DECLARE_SYN(tensorarrayv3, create_list);
DECLARE_SYN(TensorArrayCreateV3, create_list);
DECLARE_SYN(tensorarraycreatev3, create_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,60 @@
/* ******************************************************************************
*
*
* 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 <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_delete_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(delete_list, -2, 1, 0, -2) {
auto list = INPUT_LIST(0);
auto output = OUTPUT_VARIABLE(0);
int idx = -1;
// nd4j mode
if (block.width() >= 2) {
auto idxArr = INPUT_VARIABLE(block.width() - 1);
REQUIRE_TRUE(idxArr->isScalar(), 0, "Index should be Scalar");
idx = idxArr->e<int>(0);
}
//allow negative indexing from the end
if(idx < 0) {
idx += list->elements();
}
list->remove(idx);
auto result = list->remove(idx);
output->assign(result);
return Status::OK;
}
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,76 @@
/* ******************************************************************************
*
*
* 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 <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_gather_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(gather_list, 2, 1, 0, -2) {
auto list = INPUT_LIST(0);
auto indices = INPUT_VARIABLE(1);
REQUIRE_TRUE(indices->isVector() || indices->rankOf() == 1, 0, "Indices for Gather operation should be a vector");
REQUIRE_TRUE(list->height() > 0, 0, "Number of elements in list should be positive prior to Gather call");
REQUIRE_TRUE(list->height() == indices->lengthOf(), 1,
"Number of indicies should be equal to number of elements in list, but got [%i] indices instead",
indices->lengthOf());
// first of all we need to get shapes
std::vector<LongType> shape({0});
shape[0] = indices->lengthOf();
for (int e = 0; e < list->height(); e++) {
auto array = list->readRaw(e);
// now we should fill other dimensions
if (e == 0) {
for (int d = 0; d < array->rankOf(); d++) shape.emplace_back(array->sizeAt(d));
}
}
auto result = NDArrayFactory::create_('c', shape, list->dataType());
std::vector<LongType> indicesList((list->readRaw(0)->rankOf() + 1) * 2, 0);
int skipPosition = 0;
for (int e = 0; e < indices->lengthOf(); e++) {
auto idx = indices->e<int>(e);
auto array = list->readRaw(idx);
// first dimension
indicesList[0] = skipPosition;
indicesList[1] = skipPosition++ + 1;
auto subarray = (*result)(indicesList, true);
subarray->assign(array);
delete subarray;
}
setupResult(result, block);
return Status::OK;
}
DECLARE_SYN(TensorArrayGatherV3, gather_list);
DECLARE_SYN(tensorarraygatherv3, gather_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,57 @@
/* ******************************************************************************
*
*
* 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
******************************************************************************/
//
// Created by raver119 on 06.11.2017.
//
#include <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_pick_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(pick_list, 1, 1, 0, -2) {
auto list = INPUT_LIST(0);
std::vector<LongType> indices;
if (block.width() > 1 && block.getVariable(1)->getNDArray()->isVector()) {
auto ia = INPUT_VARIABLE(1);
for (int e = 0; e < ia->lengthOf(); e++) indices.emplace_back(ia->e<int>(e));
} else if (block.getIArguments()->size() > 0) {
indices = *(block.getIArguments());
} else
return Status::BAD_ARGUMENTS;
for (auto& v : indices) {
if (v >= list->height()) {
sd_printf("Requested index [%i] is higher (or equal) then ArrayList height: [%i]", v, list->height());
return Status::BAD_ARGUMENTS;
}
}
auto result = list->pick(indices);
// OVERWRITE_RESULT(result);
setupResult(result, block);
return Status::OK;
}
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,65 @@
/* ******************************************************************************
*
*
* 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
******************************************************************************/
//
// Created by raver119 on 06.11.2017.
//
#include <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_read_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(read_list, 1, 1, 0, 0) {
auto list = INPUT_LIST(0);
NDArray *result = nullptr;
REQUIRE_TRUE(list->height() > 0, 0, "ReadList: number of elements in list should be positive prior to Read call");
if (block.numI() > 0) {
auto index = INT_ARG(0);
REQUIRE_TRUE(list->isWritten(index), 0, "ReadList: requested index [%i] wasn't written yet", index);
result = list->read(index);
} else if (block.width() > 0) {
auto vec = INPUT_VARIABLE(1);
REQUIRE_TRUE(vec->isScalar(), 0, "ReadList: index operand should be a scalar");
auto index = vec->e<int>(0);
REQUIRE_TRUE(list->isWritten(index), 0, "ReadList: requested index [%i] wasn't written yet", index);
result = list->read(index);
} else {
REQUIRE_TRUE(false, 0, "ReadList: index value should be set either via IntArgs or via second operand");
}
// OVERWRITE_RESULT(result);
setupResult(result, block);
return Status::OK;
}
DECLARE_SYN(TensorArrayReadV3, read_list);
DECLARE_SYN(tensorarrayreadv3, read_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,89 @@
/* ******************************************************************************
*
*
* 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
******************************************************************************/
//
// Created by raver119 on 06.11.2017.
//
#include <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_scatter_list)
#include <helpers/ShapeUtils.h>
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(scatter_list, 1, 1, 0, -2) {
NDArrayList *list = nullptr;
NDArray *array = nullptr;
NDArray *indices = nullptr;
bool hasList = false;
auto w = block.width();
if (w >= 3) {
list = INPUT_LIST(0);
indices = INPUT_VARIABLE(1);
array = INPUT_VARIABLE(2);
hasList = true;
} else {
array = INPUT_VARIABLE(1);
indices = INPUT_VARIABLE(2);
list = new NDArrayList(indices->lengthOf(), false);
block.trackList(list);
}
REQUIRE_TRUE(indices->isVector() || indices->rankOf() == 1, 0, "ScatterList: Indices for Scatter should be a vector")
REQUIRE_TRUE(indices->lengthOf() == array->sizeAt(0), 0,
"ScatterList: Indices length should be equal number of TADs along dim0, but got %i instead",
indices->lengthOf());
std::vector<LongType> zero;
zero.push_back(0);
std::vector<LongType> *axis = ShapeUtils::evalDimsToExclude(array->rankOf(),1,zero.data());
auto tads = array->allTensorsAlongDimension(*axis);
for (LongType e = 0; e < tads.size(); e++) {
auto idx = indices->e<LongType>(e);
if (idx >= tads.size()) return Status::BAD_ARGUMENTS;
auto arr = tads.at(e)->dup(array->ordering(), false); // dup() already returns NDArray*
auto res = list->write(idx, arr);
if (res != Status::OK) {
delete axis;
return res;
}
}
if (!hasList)
setupResultList(list, block);
delete axis;
return Status::OK;
}
DECLARE_SYN(TensorArrayScatterV3, scatter_list);
DECLARE_SYN(tensorarrayscatterv3, scatter_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,46 @@
/* ******************************************************************************
*
*
* 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
******************************************************************************/
//
// Created by raver119 on 06.11.2017.
//
#include <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_size_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(size_list, 1, 1, 0, 0) {
auto list = INPUT_LIST(0);
auto result = NDArrayFactory::create_<int>(list->height(), block.launchContext());
// OVERWRITE_RESULT(result);
setupResult(result, block);
return Status::OK;
}
DECLARE_SYN(TensorArraySizeV3, size_list);
DECLARE_SYN(tensorarraysizev3, size_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,92 @@
/* ******************************************************************************
*
*
* 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
******************************************************************************/
//
// Created by raver119 on 06.11.2017.
//
#include <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_split_list)
#include <helpers/ShapeUtils.h>
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(split_list, 2, 1, 0, -2) {
NDArrayList *list = nullptr;
NDArray *array = nullptr;
NDArray *sizes = nullptr;
bool hasList = false;
if (block.width() >= 3) {
list = INPUT_LIST(0);
array = INPUT_VARIABLE(1);
sizes = INPUT_VARIABLE(2);
hasList = true;
} else {
array = INPUT_VARIABLE(0);
sizes = INPUT_VARIABLE(1);
list = new NDArrayList(sizes->lengthOf(), false);
block.trackList(list);
}
REQUIRE_TRUE(sizes->isZ(), 0, "split_list: sizes array must have one of integer types");
REQUIRE_TRUE(sizes->rankOf() == 1, 0, "split_list: sizes array must be 1D")
auto* arrayShape = array->getShapeAsVector();
list->shape() = *arrayShape;
delete arrayShape;
// now let's build subarrays
int cnt = 0;
std::vector<LongType> indices(2 * array->rankOf(), 0);
for (LongType e = 0; e < sizes->lengthOf(); e++) {
int c_size = sizes->e<int>(e);
REQUIRE_TRUE(c_size > 0, 0, "Slice size should have postive value, but got %i instead", c_size);
REQUIRE_TRUE(cnt < array->sizeAt(0) && cnt + c_size <= array->sizeAt(0), 0,
"Slices size should NOT be higher then number of TADs of source array. Source size: [%i]; Slice "
"start: [%i]; Slice size: [%i]",
array->sizeAt(0), cnt, c_size);
// we're adding our interval along zeroth dimension
indices[0] = cnt;
indices[1] = cnt + c_size;
cnt += c_size;
auto subarray = (*array)(indices);
auto status = list->write(e, subarray->dup(array->ordering(), false)); // dup() already returns NDArray*
delete subarray;
if (status != Status::OK) return status;
}
if (!hasList) {
setupResultList(list, block);
}
return Status::OK;
}
DECLARE_SYN(TensorArraySplitV3, split_list);
DECLARE_SYN(tensorarraysplitv3, split_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,47 @@
/* ******************************************************************************
*
*
* 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 <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_stack_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(stack_list, 1, 1, 0, 0) {
auto list = INPUT_LIST(0);
// auto z = OUTPUT_VARIABLE(0);
// FIXME: this is obviously bad
auto result = list->stack();
// OVERWRITE_RESULT(result);
setupResult(result, block);
return Status::OK;
}
DECLARE_SYN(TensorArrayConcatV3, stack_list);
DECLARE_SYN(tensorarrayconcatv3, stack_list);
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,49 @@
/* ******************************************************************************
*
*
* 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 <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_unstack_list)
#include <ops/declarable/headers/list.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(unstack_list, 1, 1, 0, 0) {
auto outputList = INPUT_LIST(0);
auto input = INPUT_VARIABLE(int(outputList != nullptr));
if (outputList == nullptr) {
outputList = new NDArrayList(0, true);
// block.trackList(outputList);
setupResultList(outputList, block);
}
outputList->unstack(input, INT_ARG(0));
// OVERWRITE_RESULT(list);
//
return Status::OK;
}
} // namespace ops
} // namespace sd
#endif
@@ -0,0 +1,64 @@
/* ******************************************************************************
*
*
* 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 <system/op_boilerplate.h>
#if NOT_EXCLUDED(OP_write_list)
#include <ops/declarable/CustomOperations.h>
namespace sd {
namespace ops {
LIST_OP_IMPL(write_list, 2, 1, 0, -2) {
auto list = INPUT_LIST(0);
auto output = OUTPUT_VARIABLE(0);
// nd4j mode
if (block.width() >= 3) {
auto input = INPUT_VARIABLE(block.width() - 2);
auto idx = INPUT_VARIABLE(block.width() - 1);
REQUIRE_TRUE(idx->isScalar(), 0, "Index should be Scalar");
Status result = list->write(idx->e<int>(0), input->dup(input->ordering())); // dup() already returns NDArray*
auto res = NDArrayFactory::create_(list->counter(), block.launchContext());
setupResult(res, block);
return result;
} else if (block.getIArguments()->size() == 1) {
auto input = INPUT_VARIABLE(1);
auto idx = INT_ARG(0);
Status result = list->write(idx, input->dup(input->ordering())); // dup() already returns NDArray*
auto res = NDArrayFactory::create_(list->counter(), block.launchContext());
setupResult(res, block);
return result;
} else
return Status::BAD_INPUT;
}
DECLARE_SYN(TensorArrayWriteV3, write_list);
DECLARE_SYN(tensorarraywritev3, write_list);
} // namespace ops
} // namespace sd
#endif