dastrobu / ndarray Goto Github PK
View Code? Open in Web Editor NEWN dimensional array package for numeric computing in swift.
Home Page: https://dastrobu.github.io/NdArray/documentation/ndarray/
License: MIT License
N dimensional array package for numeric computing in swift.
Home Page: https://dastrobu.github.io/NdArray/documentation/ndarray/
License: MIT License
The README is lacking docs on conversion from and to normal swift arrays.
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
Thanks !
@EliaCereda I saw you deleted Matrix.swift in you fork. So I expect there are some issues with the matrix type for you. Would appreciate it if you could share them.
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])
}
Following example is broken
let a = ndarray<double>.range(to: 12)
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!
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
}
}
Singular value decomposition would be quite useful as well.
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.
only deep links work: https://dastrobu.github.io/NdArray/documentation/ndarray/
the top link does not work: https://dastrobu.github.io/NdArray/
relates to apple/swift-docc-plugin#70
compute the transpose with vDSP_mtransD
.
Url in the installation section didn't work, but https://github.com/dastrobu/NdArray worked for me.
var a = NdArray<Double>.range(to: 3 * 4)
a.reshape([3, 4])
a = NdArray(a[...][...,3])
let b = a.flattened()
fails.
Compute eigenvalues and/or eigenvectors on a Matrix
.
provide LU factorization as linear algebra method on Matrix.
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)
}
}
the following slices should be equivalent.
let a = NdArray<Double>.range(to: 4)
print(a[1..<2]) // [1.0]
print(a[1]) // []
Vector is conform to the Sequence protocol, as should matrix be.
This would enable to iterate matrices as sequence of vectors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.