Support for 3d arrays (or ndarrays if possible)

Issue #53 new
Mario Emmenlauer created an issue

It would be great if blaze could support image analysis in multiple dimensions, like blitz++ does. Its already very well suitable for 2D image analysis, but nowadays 3D would be essential. In the long run, possibly 4D would be great (3D multi-channel image or 3D time series), but this might be supported using a vector of 3D arrays.

I've already seen but it's not sufficient for my use case. I would like to implement filters (etc) on N-D arrays.

Comments (13)

  1. Klaus Iglberger

    Hi Mario!

    Thanks a lot for the suggestion. We agree that this is an important feature and therefore will address the issue in the near future.

    Since you have a specific application in mind, could you please sketch which operations you would require for 3D arrays?

    Best regards,


  2. Mario Emmenlauer reporter

    I was a long-term blitz++ user, so I'm used to having some basic algebra on N-dimensional arrays and vectors. In principle 3D is sufficient for my image analysis tasks. This might generally be the case because higher dimensions usually resemble time, color, viewing angles or the like, and often require to be handled separately anyways. Of course in the long run, N-D would be great :-)

    For my use case, I only require basic linear algebra (add, subtract, element-wise multiplication) involving two or more dense arrays or a dense array and one or more constant(s).

  3. Fabien Péan

    Hi, to state it explicitly so that it is written down, nD-arrays could also be useful for multilinear algebra, like for tensor arithmetics.

    Best regards, Fabien

  4. Zhen Zhong
    1. the basic operations like eigen3 unsupported tensor module and Armadillo, for example, contraction and so on
    2. Einstein notation I can help more if you need it
  5. Zhen Zhong

    Some proposal

    A presentation Towards a High-Performance Tensor Algebra Package for Accelerators

    like this

    //from mshadow:
    struct cpu {
        /*! \brief whether this device is CPU or not */
        static const bool kDevCPU = true;
        /*! \brief device flag number, identifies this device */
        static const int kDevMask = 1 << 0;
    /*! \brief device name GPU */
    struct gpu {
        /*! \brief whether this device is CPU or not */
        static const bool kDevCPU = false;
        /*! \brief device flag number, identifies this device */
        static const int kDevMask = 1 << 1;
    template<size_t dimension>
    struct Shape {
        /*! \brief dimension of current shape */
        static const size_t kDimension = dimension;
        /*! \brief dimension of current shape minus one */
        static const size_t kSubdim = dimension - 1;
        /*! \brief storing the dimension information */
        size_t shape_[kDimension];
        /*! \brief default constructor, do nothing */
        BLAZE_ALWAYS_INLINE Shape(void) {}
        /*! \brief constuctor */
        BLAZE_ALWAYS_INLINE Shape(const Shape<kDimension> &s) {
    #pragma unroll
            for (int i = 0; i < kDimension; ++i) {
                this->shape_[i] = s[i];
    BLAZE_ALWAYS_INLINE size_t &operator[](size_t idx) {
        return shape_[idx];
    template<typename TT // Tensor Type
            , size_t DIM // Tensor Dimension
            , typename Device>
    struct Tensor
        using TensorType = TT;
        Shape<DIM> shape;
        BLAZE_ALWAYS_INLINE TensorType & operator~() noexcept {
            return *static_cast<TensorType*>( this );
        BLAZE_ALWAYS_INLINE const TensorType& operator~() const noexcept {
            return *static_cast<const TensorType*>( this );
    template< typename MT  // Type of the matrix
            , bool SO >    // Storage order
    struct Matrix
        : Tensor<MT, 2, cpu>
  6. Mario Emmenlauer reporter

    Hi Klaus, blaze is evolving nicely, great work. I'm just checking in again if there is progress on the 3D (or nD) support? How difficult would it be to add 3D-support in your eyes? All the best, Mario

  7. Klaus Iglberger

    Hi Mario!

    Unfortunately there is no progress yet, but the topic is pretty high on our priority list. The problem is not the difficulty of the task, but rather the amount of work associated with it (new data structures, new algorithms, new views, ...). I cannot give any ETA, but I can promise that we will address this issue within the next couple of releases.

    Best regards,


  8. Ray Kim

    Hi Klaus, Love your amazing work. I have one thing to suggest.

    One of my colleagues use n-dim(n > 2) arrays a lot for his signal processing research. A thing to note though, is that instead of generic n-dim arrays in numpy, arrayfire sense, He uses n-dim arrays as 'batches' in order to process N concurrent matrix multiplications and such. I propose something like batch<DynamicVector>, batch<DynamicMatrix> would signify obviously parallelizable types and operations. Generic N-dim arrays would obviously be a lot useful, However something like the batch type would have clear semantics, and hopefully less work. What do you think?

    Your work is much appreciated, Ray

  9. Klaus Iglberger

    Hi Ray!

    Thanks for sharing the idea and for creating this issue. We believe that your idea of batch processing is orthogonal to the idea of n-dimensional data structures. Therefore we have created issue #185 to preserve the idea and to make it possible to track the progress. Thanks again for sharing,

    Best regards,


  10. Klaus Iglberger

    Thanks Hartmut for this great addition to Blaze. Since coordinating our efforts will definitely take some time, I will initially add this as a Blaze project to the main page to make it known to as many Blaze users as possible. Thanks a lot!

  11. Mario Emmenlauer reporter

    Dear Hartmut, we are still quite interested but its currently unclear if we have spare resources. In the meantime I'll keep an eye on your work and send you lots of good karma :)

  12. Log in to comment