mverzilli / crystalla

Crystal library for Numerical Methods. It binds to LAPACK and is unashamedly inspired by Numpy.
MIT License
45 stars 7 forks source link

Implemented sum #5

Closed spalladino closed 8 years ago

spalladino commented 8 years ago

Manually sums all values.

Note that the following implementation using BLAS dgemm is roughly 5 times slower (tested with matrices of 1000 x 1000).

    def +(other : self)
      c = other.clone
      eye = Matrix.eye(number_of_cols)
      LibBlas.dgemm(
        LibBlas::Order::ColMajor,                                 # order
        LibBlas::Transpose::NoTrans, LibBlas::Transpose::NoTrans, # transa, transb
        number_of_rows, number_of_cols, number_of_cols,           # m, n, k
        1.0, self, ld,                                            # alpha, a, lda
        eye, eye.ld,                                              # b, ldb
        1.0, c, c.ld                                              # beta, c, ldc
      )
      c
    end