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 (8)

  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. Dysis Aurora

    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>
  5. 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

  6. 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,


  7. Log in to comment