11// *****************************************************************************
2- // Copyright (c) 2016-2023 , Intel Corporation
2+ // Copyright (c) 2016-2024 , Intel Corporation
33// All rights reserved.
44//
55// Redistribution and use in source and binary forms, with or without
@@ -233,18 +233,14 @@ DPCTLSyclEventRef dpnp_diagonal_c(DPCTLSyclQueueRef q_ref,
233233 continue ;
234234 }
235235 else {
236- size_t ind_input_size = ind_list.size () + 2 ;
237- size_t ind_input_[ind_input_size];
238- ind_input_[0 ] = i;
239- ind_input_[1 ] = i + offset;
240- size_t ind_output_size = ind_list.size () + 1 ;
241- size_t ind_output_[ind_output_size];
242- for (size_t k = 0 ; k < ind_list.size (); k++) {
243- ind_input_[k + 2 ] = ind_list.at (k);
244- ind_output_[k] = ind_list.at (k);
245- }
246- ind_output_[ind_list.size ()] = i;
236+ std::vector<size_t > ind_input_{i, i + offset};
237+ ind_input_.insert (ind_input_.end (), ind_list.begin (),
238+ ind_list.end ());
239+
240+ std::vector<size_t > ind_output_ = ind_list;
241+ ind_output_.push_back (i);
247242
243+ const size_t ind_output_size = ind_output_.size ();
248244 size_t ind_output = 0 ;
249245 size_t n = 1 ;
250246 for (size_t k = 0 ; k < ind_output_size; k++) {
@@ -253,6 +249,7 @@ DPCTLSyclEventRef dpnp_diagonal_c(DPCTLSyclQueueRef q_ref,
253249 n *= res_shape[ind];
254250 }
255251
252+ const size_t ind_input_size = ind_input_.size ();
256253 size_t ind_input = 0 ;
257254 size_t m = 1 ;
258255 for (size_t k = 0 ; k < ind_input_size; k++) {
@@ -423,11 +420,13 @@ DPCTLSyclEventRef dpnp_nonzero_c(DPCTLSyclQueueRef q_ref,
423420 long *result = result_ptr.get_ptr ();
424421
425422 size_t idx = 0 ;
423+ size_t *ids = new size_t [ndim];
424+
426425 for (size_t i = 0 ; i < input1_size; ++i) {
427426 if (arr[i] != 0 ) {
428- size_t ids[ndim];
429427 size_t ind1 = input1_size;
430428 size_t ind2 = i;
429+
431430 for (size_t k = 0 ; k < ndim; ++k) {
432431 ind1 = ind1 / shape[k];
433432 ids[k] = ind2 / ind1;
@@ -438,6 +437,7 @@ DPCTLSyclEventRef dpnp_nonzero_c(DPCTLSyclQueueRef q_ref,
438437 idx += 1 ;
439438 }
440439 }
440+ delete[] ids;
441441
442442 return event_ref;
443443}
@@ -621,8 +621,6 @@ DPCTLSyclEventRef
621621 DPCTLSyclEventRef event_ref = nullptr ;
622622 sycl::queue q = *(reinterpret_cast <sycl::queue *>(q_ref));
623623
624- size_t res_ndim = ndim - 1 ;
625- size_t res_shape[res_ndim];
626624 const size_t size_arr = std::accumulate (shape, shape + ndim, 1 ,
627625 std::multiplies<shape_elem_type>());
628626
@@ -635,14 +633,14 @@ DPCTLSyclEventRef
635633 _DataType *values = input2_ptr.get_ptr ();
636634 _DataType *arr = result_ptr.get_ptr ();
637635
638- if (axis != res_ndim ) {
639- int ind = 0 ;
636+ if (axis != (ndim - 1 ) ) {
637+ std::vector< size_t > res_shape ;
640638 for (size_t i = 0 ; i < ndim; i++) {
641639 if (axis != i) {
642- res_shape[ind] = shape[i];
643- ind++;
640+ res_shape.push_back (shape[i]);
644641 }
645642 }
643+ size_t res_ndim = res_shape.size ();
646644
647645 size_t prod = 1 ;
648646 for (size_t i = 0 ; i < res_ndim; ++i) {
@@ -651,20 +649,21 @@ DPCTLSyclEventRef
651649 }
652650 }
653651
654- size_t ind_array[prod];
655- bool bool_ind_array[prod];
652+ size_t * ind_array = new size_t [prod];
653+ bool * bool_ind_array = new bool [prod];
656654 for (size_t i = 0 ; i < prod; ++i) {
657655 bool_ind_array[i] = true ;
658656 }
659- size_t arr_shape_offsets[ndim];
657+
658+ size_t *arr_shape_offsets = new size_t [ndim];
660659 size_t acc = 1 ;
661660 for (size_t i = ndim - 1 ; i > 0 ; --i) {
662661 arr_shape_offsets[i] = acc;
663662 acc *= shape[i];
664663 }
665664 arr_shape_offsets[0 ] = acc;
666665
667- size_t output_shape_offsets[res_ndim];
666+ size_t * output_shape_offsets = new size_t [res_ndim];
668667 acc = 1 ;
669668 if (res_ndim > 0 ) {
670669 for (size_t i = res_ndim - 1 ; i > 0 ; --i) {
@@ -680,31 +679,31 @@ DPCTLSyclEventRef
680679 }
681680
682681 // init result array
682+ size_t *xyz = new size_t [res_ndim];
683683 for (size_t result_idx = 0 ; result_idx < size_result; ++result_idx) {
684- size_t xyz[res_ndim];
685684 size_t remainder = result_idx;
686685 for (size_t i = 0 ; i < res_ndim; ++i) {
687686 xyz[i] = remainder / output_shape_offsets[i];
688687 remainder = remainder - xyz[i] * output_shape_offsets[i];
689688 }
690689
691- size_t source_axis[ndim];
692- size_t result_axis_idx = 0 ;
693- for (size_t idx = 0 ; idx < ndim; ++idx) {
694- bool found = false ;
695- if (axis == idx) {
696- found = true ;
697- }
698- if (found) {
699- source_axis[idx] = 0 ;
700- }
701- else {
702- source_axis[idx] = xyz[result_axis_idx];
703- result_axis_idx++;
704- }
705- }
690+ // FIXME: computed and unused. Commented out per compiler warning
691+ // size_t source_axis[ndim];
692+ // size_t result_axis_idx = 0;
693+ // for (size_t idx = 0; idx < ndim; ++idx) {
694+ // bool found = false;
695+ // if (axis == idx) {
696+ // found = true;
697+ // }
698+ // if (found) {
699+ // source_axis[idx] = 0;
700+ // }
701+ // else {
702+ // source_axis[idx] = xyz[result_axis_idx];
703+ // result_axis_idx++;
704+ // }
705+ // }
706706
707- // FIXME: computed, but unused. Commented out per compiler warning
708707 // size_t source_idx = 0;
709708 // for (size_t i = 0; i < static_cast<size_t>(ndim); ++i)
710709 // {
@@ -714,25 +713,18 @@ DPCTLSyclEventRef
714713
715714 for (size_t source_idx = 0 ; source_idx < size_arr; ++source_idx) {
716715 // reconstruct x,y,z from linear source_idx
717- size_t xyz[ndim];
718716 size_t remainder = source_idx;
719717 for (size_t i = 0 ; i < ndim; ++i) {
720718 xyz[i] = remainder / arr_shape_offsets[i];
721719 remainder = remainder - xyz[i] * arr_shape_offsets[i];
722720 }
723721
724722 // extract result axis
725- size_t result_axis[res_ndim];
726- size_t result_idx = 0 ;
723+ std::vector<size_t > result_axis;
727724 for (size_t idx = 0 ; idx < ndim; ++idx) {
728725 // try to find current idx in axis array
729- bool found = false ;
730- if (axis == idx) {
731- found = true ;
732- }
733- if (!found) {
734- result_axis[result_idx] = xyz[idx];
735- result_idx++;
726+ if (axis != idx) {
727+ result_axis.push_back (xyz[idx]);
736728 }
737729 }
738730
@@ -756,6 +748,12 @@ DPCTLSyclEventRef
756748 arr[source_idx] = values[source_idx % values_size];
757749 }
758750 }
751+
752+ delete[] ind_array;
753+ delete[] bool_ind_array;
754+ delete[] arr_shape_offsets;
755+ delete[] output_shape_offsets;
756+ delete[] xyz;
759757 }
760758 else {
761759 for (size_t i = 0 ; i < size_arr; ++i) {
0 commit comments