1
1
// *****************************************************************************
2
- // Copyright (c) 2016-2023 , Intel Corporation
2
+ // Copyright (c) 2016-2024 , Intel Corporation
3
3
// All rights reserved.
4
4
//
5
5
// Redistribution and use in source and binary forms, with or without
@@ -233,18 +233,14 @@ DPCTLSyclEventRef dpnp_diagonal_c(DPCTLSyclQueueRef q_ref,
233
233
continue ;
234
234
}
235
235
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);
247
242
243
+ const size_t ind_output_size = ind_output_.size ();
248
244
size_t ind_output = 0 ;
249
245
size_t n = 1 ;
250
246
for (size_t k = 0 ; k < ind_output_size; k++) {
@@ -253,6 +249,7 @@ DPCTLSyclEventRef dpnp_diagonal_c(DPCTLSyclQueueRef q_ref,
253
249
n *= res_shape[ind];
254
250
}
255
251
252
+ const size_t ind_input_size = ind_input_.size ();
256
253
size_t ind_input = 0 ;
257
254
size_t m = 1 ;
258
255
for (size_t k = 0 ; k < ind_input_size; k++) {
@@ -423,11 +420,13 @@ DPCTLSyclEventRef dpnp_nonzero_c(DPCTLSyclQueueRef q_ref,
423
420
long *result = result_ptr.get_ptr ();
424
421
425
422
size_t idx = 0 ;
423
+ size_t *ids = new size_t [ndim];
424
+
426
425
for (size_t i = 0 ; i < input1_size; ++i) {
427
426
if (arr[i] != 0 ) {
428
- size_t ids[ndim];
429
427
size_t ind1 = input1_size;
430
428
size_t ind2 = i;
429
+
431
430
for (size_t k = 0 ; k < ndim; ++k) {
432
431
ind1 = ind1 / shape[k];
433
432
ids[k] = ind2 / ind1;
@@ -438,6 +437,7 @@ DPCTLSyclEventRef dpnp_nonzero_c(DPCTLSyclQueueRef q_ref,
438
437
idx += 1 ;
439
438
}
440
439
}
440
+ delete[] ids;
441
441
442
442
return event_ref;
443
443
}
@@ -621,8 +621,6 @@ DPCTLSyclEventRef
621
621
DPCTLSyclEventRef event_ref = nullptr ;
622
622
sycl::queue q = *(reinterpret_cast <sycl::queue *>(q_ref));
623
623
624
- size_t res_ndim = ndim - 1 ;
625
- size_t res_shape[res_ndim];
626
624
const size_t size_arr = std::accumulate (shape, shape + ndim, 1 ,
627
625
std::multiplies<shape_elem_type>());
628
626
@@ -635,14 +633,14 @@ DPCTLSyclEventRef
635
633
_DataType *values = input2_ptr.get_ptr ();
636
634
_DataType *arr = result_ptr.get_ptr ();
637
635
638
- if (axis != res_ndim ) {
639
- int ind = 0 ;
636
+ if (axis != (ndim - 1 ) ) {
637
+ std::vector< size_t > res_shape ;
640
638
for (size_t i = 0 ; i < ndim; i++) {
641
639
if (axis != i) {
642
- res_shape[ind] = shape[i];
643
- ind++;
640
+ res_shape.push_back (shape[i]);
644
641
}
645
642
}
643
+ size_t res_ndim = res_shape.size ();
646
644
647
645
size_t prod = 1 ;
648
646
for (size_t i = 0 ; i < res_ndim; ++i) {
@@ -651,20 +649,21 @@ DPCTLSyclEventRef
651
649
}
652
650
}
653
651
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];
656
654
for (size_t i = 0 ; i < prod; ++i) {
657
655
bool_ind_array[i] = true ;
658
656
}
659
- size_t arr_shape_offsets[ndim];
657
+
658
+ size_t *arr_shape_offsets = new size_t [ndim];
660
659
size_t acc = 1 ;
661
660
for (size_t i = ndim - 1 ; i > 0 ; --i) {
662
661
arr_shape_offsets[i] = acc;
663
662
acc *= shape[i];
664
663
}
665
664
arr_shape_offsets[0 ] = acc;
666
665
667
- size_t output_shape_offsets[res_ndim];
666
+ size_t * output_shape_offsets = new size_t [res_ndim];
668
667
acc = 1 ;
669
668
if (res_ndim > 0 ) {
670
669
for (size_t i = res_ndim - 1 ; i > 0 ; --i) {
@@ -680,31 +679,31 @@ DPCTLSyclEventRef
680
679
}
681
680
682
681
// init result array
682
+ size_t *xyz = new size_t [res_ndim];
683
683
for (size_t result_idx = 0 ; result_idx < size_result; ++result_idx) {
684
- size_t xyz[res_ndim];
685
684
size_t remainder = result_idx;
686
685
for (size_t i = 0 ; i < res_ndim; ++i) {
687
686
xyz[i] = remainder / output_shape_offsets[i];
688
687
remainder = remainder - xyz[i] * output_shape_offsets[i];
689
688
}
690
689
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
+ // }
706
706
707
- // FIXME: computed, but unused. Commented out per compiler warning
708
707
// size_t source_idx = 0;
709
708
// for (size_t i = 0; i < static_cast<size_t>(ndim); ++i)
710
709
// {
@@ -714,25 +713,18 @@ DPCTLSyclEventRef
714
713
715
714
for (size_t source_idx = 0 ; source_idx < size_arr; ++source_idx) {
716
715
// reconstruct x,y,z from linear source_idx
717
- size_t xyz[ndim];
718
716
size_t remainder = source_idx;
719
717
for (size_t i = 0 ; i < ndim; ++i) {
720
718
xyz[i] = remainder / arr_shape_offsets[i];
721
719
remainder = remainder - xyz[i] * arr_shape_offsets[i];
722
720
}
723
721
724
722
// extract result axis
725
- size_t result_axis[res_ndim];
726
- size_t result_idx = 0 ;
723
+ std::vector<size_t > result_axis;
727
724
for (size_t idx = 0 ; idx < ndim; ++idx) {
728
725
// 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]);
736
728
}
737
729
}
738
730
@@ -756,6 +748,12 @@ DPCTLSyclEventRef
756
748
arr[source_idx] = values[source_idx % values_size];
757
749
}
758
750
}
751
+
752
+ delete[] ind_array;
753
+ delete[] bool_ind_array;
754
+ delete[] arr_shape_offsets;
755
+ delete[] output_shape_offsets;
756
+ delete[] xyz;
759
757
}
760
758
else {
761
759
for (size_t i = 0 ; i < size_arr; ++i) {
0 commit comments