permute.c (1106B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2021 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "stdlib/ndarray/base/unary/internal/permute.h" 20 #include <stdint.h> 21 22 /** 23 * Permutes an input array according to a provided index array. 24 * 25 * @private 26 * @param n number of elements to permute 27 * @param arr input array 28 * @param idx permutation indices 29 * @param out output array 30 */ 31 void stdlib_ndarray_base_unary_internal_permute( const int64_t n, const int64_t *arr, const int64_t *idx, int64_t *out ) { 32 int64_t i; 33 for ( i = 0; i < n; i++ ) { 34 out[ i ] = arr[ idx[i] ]; 35 } 36 }