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 https://bitbucket.org/blaze-lib/blaze/issues/34/support-for-ndarrays but it's not sufficient for my use case. I would like to implement filters (etc) on N-D arrays.

Comments (5)

  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,

    Klaus!

  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: https://github.com/dmlc/mshadow/blob/master/mshadow/tensor.h
    
    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. Log in to comment