Git Product home page Git Product logo

ndarray's People

Contributors

dastrobu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ndarray's Issues

Float Matrix Vector Multiplication

Hello! I started using this library from your comment on Untouched Wilderness (Swift Numerics).
This library is really really great!!!

I have a question. when I ran the following code with reference to the README,

import NdArray
let A = Matrix<Float>.ones([2, 2])
let x = Vector<Float>.ones(2)
print(A * x)

I got the following error.

 BLAS error: Parameter number 7 passed to cblas_sgemv had an invalid value
Program ended with exit code: 255

Does this library currently not support operations other than Double?

For your information, my execution environment is as follows

  • macOS Big Sur v11.1
  • Apple M1
  • Swift v5.3.2

Thanks !

better debug support

When debugging, it is quite hard to look into data:

image

a property which allows looking into the data would be helpful.

optimize matrix multiplicaton for C and F matrix

currently both matrices are always transformed to the same memory layout before multiplying. C and F contiguous matrices could be handled as is:

    if A.isFContiguous {
        order = CblasColMajor
        a = Matrix(A, order: .F)
        b = Matrix(B, order: .F)
        c = Matrix<Float>(empty: [Int(m), Int(n)], order: .F)
        lda = Int32(a.strides[1])
        ldb = Int32(b.strides[1])
        ldc = Int32(c.strides[1])
    } else {
        order = CblasRowMajor
        a = Matrix(A, order: .C)
        b = Matrix(B, order: .C)
        c = Matrix<Float>(empty: [Int(m), Int(n)], order: .C)
        lda = Int32(a.strides[0])
        ldb = Int32(b.strides[0])
        ldc = Int32(c.strides[0])
    }

License

Hi, I used your library in a proof-of-concept project and I had a very good first impression.

I'd like to ask if you could clarify the licensing terms you're releasing it under. Thanks!

support varargs on subscripts

when the old style index API is removed, varargs can be added:

    /**
     slice access
     */
    public subscript(slices: Slice...) -> NdArray<T> {
        get {
            self[slices]
        }
        set {
            self[slices] = newValue
        }
    }

    /**
     index access
     */
    public subscript(index: Int...) -> T {
        get {
            self[index]
        }
        set {
            self[index] = newValue
        }
    }

SVD

Singular value decomposition would be quite useful as well.

Subscript of NdArray should be of type NdArray

As it is, it's not possible to copy the contents of an NdArray to a slice of another array using the subscript, since the subscript expects an NdArraySlice.

For example, the following pattern cannot be implemented using the subscript:

// Say you want to perform some computation a number of times and store
// all the results in a single array.

let n = 10
let array = NdArray<Float>.empty(shape: [n, 128])

for i in 0 ..< n {
    // The result of the computation.
    let result = NdArray<Float>.zeros(128)
    
    // ERROR: Cannot assign value of type 'NdArray<Float>' to type 'NdArraySlice<Float>'
    array[i] = result
    
    // This works on the other hand:
    result.copyTo(array[i])
}

If the subscripts had a public type of NdArray (while still returning an NdArraySlice) this issue would be fixed, but now the API wouldn't explicitly convey that the subscript returns a slice as opposed to a standalone array.

Also, I tried changing the types and found that apply.swift and possibly other files depend on the subscripts returning a NdArraySlice, so it's not entirely straightforward what the solution should be.

Eigenvalues

Compute eigenvalues and/or eigenvectors on a Matrix.

Make index slices ExpressibleByIntegerLiteral

To remove the need to convert to a slice expliclty a[Slice(1)] one can make Slice conform to ExpressibleByIntegerLiteral.
This should not be done before the old index API is removed, since old slices with strides:

let a = A[0..., 2]

would be interpreted as

let a = A[0..., Slice(2)]

leading to unexpected behaviour.

/**
 Auto convert integer literals to an index slice.

       let s = a[..., 1]

 */
extension Slice: ExpressibleByIntegerLiteral {
    public typealias IntegerLiteralType = Int

    public init(integerLiteral i: Int) {
        self.init(i)
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.