# CLI giving error with higher dimensional arrays

**URL:** <https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366>\
**Category:** Development\
**Created:** [September 10, 2019, 2:40pm UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366 "2019-09-10T14:40:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 2:40pm UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366/1 "2019-09-10T14:40:25Z")

</div>

Hello Developers,

I am creating a CLI module for performing computationally expensive tasks. @lassoan already helped me with parsing an arguments and all.

There is some weird problem. If I initiate 2 or more high dimensional array like (128x128x49) in my CLI module, it is ending with a fault.

```
const int slices= 96;
const int x=127;
const int y=127;

float array1[slices][x][y]={};
float array2[slices][x][y]={};  

```

The error message I am getting is  
CLI\_test terminated with a fault

However, if I use low dimensional array. My module runs perfectly. Is there any memory issue or something else?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2019, 3:17pm UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366/2 "2019-09-10T15:17:37Z")

</div>

These arrays are way too big to be stored on the stack, but allocating them on the heap should be no problem. The easiest way is to let STL containers or VTK or ITK objects manage the memory for you. Most CLI modules use ITK, so you can find lots of examples how to do it.

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 4:25pm UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366/3 "2019-09-10T16:25:13Z")

</div>

Thank you for your response @lassoan. I have seen several examples but most of the examples are manipulating image. Like taking input as an image , apply itk filter and return an image.

I need to work on these 3 dimensional large arrays. Is there any basic example in in ITK to work on these which can return a 3 dimensional array as well.

Maybe a simple example to parse these higher dimensional arrays from scripting module and return as well.

Thank you so much for all your guidance throughout this development process

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2019, 5:19pm UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366/4 "2019-09-10T17:19:12Z")

</div>

Images are 3D arrays. VTK supports up to 4-dimensional images, ITK can handle arbitrary number of dimensions.

What would you like to achieve? What programming language do you prefer: C++ or Python?

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 5:33pm UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366/5 "2019-09-10T17:33:11Z")

</div>

Thank you for your response. I have some higher dimensional arrays and I want to perform some numerical manipulation on them. Doing this in python is very time consuming, so I am planning to parse my arrays to CLI module in C++ and perform these computationally expensive tasks in CLI module thn return the output array.

I mostly have to use simple operations like dot product and vector additions …

Thank you

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 11, 2019, 1:05am UTC](https://discourse.slicer.org/t/cli-giving-error-with-higher-dimensional-arrays/8366/6 "2019-09-11T01:05:57Z")

</div>

> [@fpsiddiqui91](#):
>
> I have some higher dimensional arrays and I want to perform some numerical manipulation on them. Doing this in python is very time consuming

You cannot iterate through each voxel of an image in Python, but there are hundreds of Python packages that implement efficient processing operations on higher-dimensional arrays. See numpy, scipy, SimpleITK, VTK, scikitimage, OpenCV, etc.

In C++ you _can_ implement pixel-by-pixel processing, but nowadays this is rarely needed, since most common low-level operations are already have nice, robust, performance-optimized implementations.

> [@fpsiddiqui91](#):
>
> I mostly have to use simple operations like dot product and vector additions …

You certainly don’t need to implement such basic operations from scratch, in C++. You can add two n-dimensional numpy arrays like this: `c = a + b`.
