Numpy-like library in swift. (Multi-dimensional Array, ndarray, matrix and vector library)

Overview

Matft

SwiftPM compatible CocoaPods compatible Carthage compatible license

Matft is Numpy-like library in Swift. Function name and usage is similar to Numpy.

Note: You can use Protocol version(beta version) too.

Feature & Usage

  • Many types

  • Pretty print

  • Indexing

    • Positive
    • Negative
    • Boolean
    • Fancy
  • Slicing

    • Start / To / By
    • New Axis
  • View

    • Assignment
  • Conversion

    • Broadcast
    • Transpose
    • Reshape
    • Astype
  • Univarsal function reduction

  • Mathematic

    • Arithmetic
    • Statistic
    • Linear Algebra

...etc.

See Function List for all functions.

Declaration

MfArray

  • The MfArray such like a numpy.ndarray

    let a = MfArray([[[ -8,  -7,  -6,  -5],
                      [ -4,  -3,  -2,  -1]],
            
                     [[ 0,  1,  2,  3],
                      [ 4,  5,  6,  7]]])
    let aa = Matft.arange(start: -8, to: 8, by: 1, shape: [2,2,4])
    print(a)
    print(aa)
    /*
    mfarray = 
    [[[	-8,		-7,		-6,		-5],
    [	-4,		-3,		-2,		-1]],
    
    [[	0,		1,		2,		3],
    [	4,		5,		6,		7]]], type=Int, shape=[2, 2, 4]
    mfarray = 
    [[[	-8,		-7,		-6,		-5],
    [	-4,		-3,		-2,		-1]],
    
    [[	0,		1,		2,		3],
    [	4,		5,		6,		7]]], type=Int, shape=[2, 2, 4]
    */

MfType

  • You can pass MfType as MfArray's argument mftype: .Hoge . It is similar to dtype.

    ※Note that stored data type will be Float or Double only even if you set MfType.Int. So, if you input big number to MfArray, it may be cause to overflow or strange results in any calculation (+, -, *, /,... etc.). But I believe this is not problem in practical use.

  • MfType's list is below

      public enum MfType: Int{
        case None // Unsupportted
        case Bool
        case UInt8
        case UInt16
        case UInt32
        case UInt64
        case UInt
        case Int8
        case Int16
        case Int32
        case Int64
        case Int
        case Float
        case Double
        case Object // Unsupported
    }
  • Also, you can convert MfType easily using astype

    let a = MfArray([[[ -8,  -7,  -6,  -5],
                      [ -4,  -3,  -2,  -1]],
            
                     [[ 0,  1,  2,  3],
                      [ 4,  5,  6,  7]]])
    print(a)//See above. if mftype is not passed, MfArray infer MfType. In this example, it's MfType.Int
    
    let a = MfArray([[[ -8,  -7,  -6,  -5],
                      [ -4,  -3,  -2,  -1]],
                
                     [[ 0,  1,  2,  3],
                      [ 4,  5,  6,  7]]], mftype: .Float)
    print(a)
    /*
    mfarray = 
    [[[	-8.0,		-7.0,		-6.0,		-5.0],
    [	-4.0,		-3.0,		-2.0,		-1.0]],
    
    [[	0.0,		1.0,		2.0,		3.0],
    [	4.0,		5.0,		6.0,		7.0]]], type=Float, shape=[2, 2, 4]
    */
    let aa = MfArray([[[ -8,  -7,  -6,  -5],
                      [ -4,  -3,  -2,  -1]],
                
                     [[ 0,  1,  2,  3],
                      [ 4,  5,  6,  7]]], mftype: .UInt)
    print(aa)
    /*
    mfarray = 
    [[[	4294967288,		4294967289,		4294967290,		4294967291],
    [	4294967292,		4294967293,		4294967294,		4294967295]],
    
    [[	0,		1,		2,		3],
    [	4,		5,		6,		7]]], type=UInt, shape=[2, 2, 4]
    */
    //Above output is same as numpy!
    /*
    >>> np.arange(-8, 8, dtype=np.uint32).reshape(2,2,4)
    array([[[4294967288, 4294967289, 4294967290, 4294967291],
            [4294967292, 4294967293, 4294967294, 4294967295]],
    
           [[         0,          1,          2,          3],
            [         4,          5,          6,          7]]], dtype=uint32)
    */
    
    print(aa.astype(.Float))
    /*
    mfarray = 
    [[[	-8.0,		-7.0,		-6.0,		-5.0],
    [	-4.0,		-3.0,		-2.0,		-1.0]],
    
    [[	0.0,		1.0,		2.0,		3.0],
    [	4.0,		5.0,		6.0,		7.0]]], type=Float, shape=[2, 2, 4]
    */

Subscription

MfSlice

  • You can access specific data using subscript.

You can set MfSlice (see below's list) to subscript.

  • MfSlice(start: Int? = nil, to: Int? = nil, by: Int = 1)
  • Matft.newaxis
  • ~< //this is prefix, postfix and infix operator. same as python's slice, ":"

(Positive) Indexing

  • Normal indexing

    let a = Matft.arange(start: 0, to: 27, by: 1, shape: [3,3,3])
    print(a)
    /*
    mfarray = 
    [[[	0,		1,		2],
    [	3,		4,		5],
    [	6,		7,		8]],
    
    [[	9,		10,		11],
    [	12,		13,		14],
    [	15,		16,		17]],
    
    [[	18,		19,		20],
    [	21,		22,		23],
    [	24,		25,		26]]], type=Int, shape=[3, 3, 3]
    */
    print(a[2,1,0])
    // 21

    Slicing

  • If you replace : with ~<, you can get sliced mfarray. Note that use a[0~<] instead of a[:] to get all elements along axis.

    print(a[~<1])  //same as a[:1] for numpy
    /*
    mfarray = 
    [[[	9,		10,		11],
    [	12,		13,		14],
    [	15,		16,		17]]], type=Int, shape=[1, 3, 3]
    */
    print(a[1~<3]) //same as a[1:3] for numpy
    /*
    mfarray = 
    [[[	9,		10,		11],
    [	12,		13,		14],
    [	15,		16,		17]],
    
    [[	18,		19,		20],
    [	21,		22,		23],
    [	24,		25,		26]]], type=Int, shape=[2, 3, 3]
    */
    print(a[~<~<2]) //same as a[::2] for numpy
    //print(a[~<<2]) //alias
    /*
    mfarray = 
    [[[	0,		1,		2],
    [	3,		4,		5],
    [	6,		7,		8]],
    
    [[	18,		19,		20],
    [	21,		22,		23],
    [	24,		25,		26]]], type=Int, shape=[2, 3, 3]
    */

Negative Indexing

  • Negative indexing is also available That's implementation was hardest for me...

    print(a[~<-1])
    /*
    mfarray = 
    [[[	0,		1,		2],
    [	3,		4,		5],
    [	6,		7,		8]],
    
    [[	9,		10,		11],
    [	12,		13,		14],
    [	15,		16,		17]]], type=Int, shape=[2, 3, 3]
    */
    print(a[-1~<-3])
    /*
    mfarray = 
    	[], type=Int, shape=[0, 3, 3]
    */
    print(a[~<~<-1])
    //print(a[~<<-1]) //alias
    /*
    mfarray = 
    [[[	18,		19,		20],
    [	21,		22,		23],
    [	24,		25,		26]],
    
    [[	9,		10,		11],
    [	12,		13,		14],
    [	15,		16,		17]],
    
    [[	0,		1,		2],
    [	3,		4,		5],
    [	6,		7,		8]]], type=Int, shape=[3, 3, 3]*/

Boolean Indexing

  • You can use boolean indexing.

    Caution! I don't check performance, so this boolean indexing may be slow

    Unfortunately, Matft is too slower than numpy...

    (numpy is 1ms, Matft is 7ms...)

    let img = MfArray([[1, 2, 3],
                                   [4, 5, 6],
                                   [7, 8, 9]], mftype: .UInt8)
    img[img > 3] = MfArray([10], mftype: .UInt8)
    print(img)
    /*
    mfarray = 
    [[	1,		2,		3],
    [	10,		10,		10],
    [	10,		10,		10]], type=UInt8, shape=[3, 3]
    */

Fancy Indexing

  • You can use fancy indexing!!!

    let a = MfArray([[1, 2], [3, 4], [5, 6]])
                
    a[MfArray([0, 1, 2]), MfArray([0, -1, 0])] = MfArray([999,888,777])
    print(a)
    /*
    mfarray = 
    [[	999,		2],
    [	3,		888],
    [	777,		6]], type=Int, shape=[3, 2]
    */
                
    a.T[MfArray([0, 1, -1]), MfArray([0, 1, 0])] = MfArray([-999,-888,-777])
    print(a)
    /*
    mfarray = 
    [[	-999,		-777],
    [	3,		-888],
    [	777,		6]], type=Int, shape=[3, 2]
    */

View

  • Note that returned subscripted mfarray will have base property (is similar to view in Numpy). See numpy doc in detail.

    let a = Matft.arange(start: 0, to: 4*4*2, by: 1, shape: [4,4,2])
                
    let b = a[0~<, 1]
    b[~<<-1] = MfArray([9999]) // cannot pass Int directly such like 9999
    
    print(a)
    /*
    mfarray = 
    [[[	0,		1],
    [	9999,		9999],
    [	4,		5],
    [	6,		7]],
    
    [[	8,		9],
    [	9999,		9999],
    [	12,		13],
    [	14,		15]],
    
    [[	16,		17],
    [	9999,		9999],
    [	20,		21],
    [	22,		23]],
    
    [[	24,		25],
    [	9999,		9999],
    [	28,		29],
    [	30,		31]]], type=Int, shape=[4, 4, 2]
    */

Function List

Below is Matft's function list. As I mentioned above, almost functions are similar to Numpy. Also, these function use Accelerate framework inside, the perfomance may keep high.

* means method function exists too. Shortly, you can use a.shallowcopy() where a is MfArray.

^ means method function only. Shortly, you can use a.tolist() not Matft.tolist where a is MfArray.

  • Creation
Matft Numpy
*Matft.shallowcopy *numpy.copy
*Matft.deepcopy copy.deepcopy
Matft.nums numpy.ones * N
Matft.nums_like numpy.ones_like * N
Matft.arange numpy.arange
Matft.eye numpy.eye
Matft.diag numpy.diag
Matft.vstack numpy.vstack
Matft.hstack numpy.hstack
Matft.concatenate numpy.concatenate
*Matft.append numpy.append
*Matft.insert numpy.insert
*Matft.take numpy.take
  • Conversion
Matft Numpy
*Matft.astype *numpy.astype
*Matft.transpose *numpy.transpose
*Matft.expand_dims *numpy.expand_dims
*Matft.squeeze *numpy.squeeze
*Matft.broadcast_to *numpy.broadcast_to
*Matft.conv_order *numpy.ascontiguousarray
*Matft.flatten *numpy.flatten
*Matft.flip *numpy.flip
*Matft.clip *numpy.clip
*Matft.swapaxes *numpy.swapaxes
*Matft.moveaxis *numpy.moveaxis
*Matft.sort *numpy.sort
*Matft.argsort *numpy.argsort
^MfArray.toArray ^numpy.ndarray.tolist
  • File

    save function has not developed yet.

Matft Numpy
Matft.file.loadtxt numpy.loadtxt
Matft.file.genfromtxt numpy.genfromtxt
  • Operation

    Line 2 is infix (prefix) operator.

Matft Numpy
Matft.add
+
numpy.add
+
Matft.sub
-
numpy.sub
-
Matft.div
/
numpy.div
.
Matft.mul
*
numpy.multiply
*
Matft.inner
*+
numpy.inner
n/a
Matft.cross
*^
numpy.cross
n/a
Matft.matmul
*&   
numpy.matmul
@ 
Matft.equal
===
numpy.equal
==
Matft.not_equal
!==
numpy.not_equal
!=
Matft.less
<
numpy.less
<
Matft.less_equal
<=
numpy.less_equal
<=
Matft.greater
>
numpy.greater
>
Matft.greater_equal
>=
numpy.greater_equal
>=
Matft.allEqual
==
numpy.array_equal
n/a
Matft.neg
-
numpy.negative
-
  • Universal Fucntion Reduction
Matft Numpy
*Matft.ufuncReduce
e.g.) Matft.ufuncReduce(a, Matft.add)
numpy.add.reduce
e.g.) numpy.add.reduce(a)
*Matft.ufuncAccumulate
e.g.) Matft.ufuncAccumulate(a, Matft.add)
numpy.add.accumulate
e.g.) numpy.add.accumulate(a)
  • Math function
Matft Numpy
Matft.math.sin numpy.sin
Matft.math.asin numpy.asin
Matft.math.sinh numpy.sinh
Matft.math.asinh numpy.asinh
Matft.math.sin numpy.cos
Matft.math.acos numpy.acos
Matft.math.cosh numpy.cosh
Matft.math.acosh numpy.acosh
Matft.math.tan numpy.tan
Matft.math.atan numpy.atan
Matft.math.tanh numpy.tanh
Matft.math.atanh numpy.atanh
Matft.math.sqrt numpy.sqrt
Matft.math.rsqrt numpy.rsqrt
Matft.math.exp numpy.exp
Matft.math.log numpy.log
Matft.math.log2 numpy.log2
Matft.math.log10 numpy.log10
*Matft.math.ceil numpy.ceil
*Matft.math.floor numpy.floor
*Matft.math.trunc numpy.trunc
*Matft.math.nearest numpy.nearest
*Matft.math.round numpy.round
Matft.math.abs numpy.abs
Matft.math.reciprocal numpy.reciprocal
Matft.math.power numpy.power
Matft.math.square numpy.square
Matft.math.sign numpy.sign
  • Statistics function
Matft Numpy
*Matft.stats.mean *numpy.mean
*Matft.stats.max *numpy.max
*Matft.stats.argmax *numpy.argmax
*Matft.stats.min *numpy.min
*Matft.stats.argmin *numpy.argmin
*Matft.stats.sum *numpy.sum
Matft.stats.maximum numpy.maximum
Matft.stats.minimum numpy.minimum
*Matft.stats.sumsqrt n/a
*Matft.stats.squaresum n/a
*Matft.stats.cumsum *numpy.cumsum
  • Linear algebra
Matft Numpy
Matft.linalg.solve numpy.linalg.solve
Matft.linalg.inv numpy.linalg.inv
Matft.linalg.det numpy.linalg.det
Matft.linalg.eigen numpy.linalg.eig
Matft.linalg.svd numpy.linalg.svd
Matft.linalg.pinv numpy.linalg.pinv
Matft.linalg.polar_left scipy.linalg.polar
Matft.linalg.polar_right scipy.linalg.polar
Matft.linalg.normlp_vec scipy.linalg.norm
Matft.linalg.normfro_mat scipy.linalg.norm
Matft.linalg.normnuc_mat scipy.linalg.norm
  • Interpolation

Matft supports only natural cubic spline. I'll implement other boundary condition later.

Matft Numpy
Matft.interp1d.cubicSpline scipy.interpolation.CubicSpline

Performance

I use Accelerate, so all of MfArray operation may keep high performance.

func testPefAdd1() {
        do{
            let a = Matft.arange(start: 0, to: 10*10*10*10*10*10, by: 1, shape: [10,10,10,10,10,10])
            let b = Matft.arange(start: 0, to: -10*10*10*10*10*10, by: -1, shape: [10,10,10,10,10,10])
            
            self.measure {
                let _ = a+b
            }
            /*
             '-[MatftTests.ArithmeticPefTests testPefAdd1]' measured [Time, seconds] average: 0.001, relative standard deviation: 23.418%, values: [0.001707, 0.001141, 0.000999, 0.000969, 0.001029, 0.000979, 0.001031, 0.000986, 0.000963, 0.001631]
            1.14ms
             */
        }
    }
    
    func testPefAdd2(){
        do{
            let a = Matft.arange(start: 0, to: 10*10*10*10*10*10, by: 1, shape: [10,10,10,10,10,10])
            let b = a.transpose(axes: [0,3,4,2,1,5])
            let c = a.T
            
            self.measure {
                let _ = b+c
            }
            /*
             '-[MatftTests.ArithmeticPefTests testPefAdd2]' measured [Time, seconds] average: 0.004, relative standard deviation: 5.842%, values: [0.004680, 0.003993, 0.004159, 0.004564, 0.003955, 0.004200, 0.003998, 0.004317, 0.003919, 0.004248]
            4.20ms
             */
        }
    }

    func testPefAdd3(){
        do{
            let a = Matft.arange(start: 0, to: 10*10*10*10*10*10, by: 1, shape: [10,10,10,10,10,10])
            let b = a.transpose(axes: [1,2,3,4,5,0])
            let c = a.T
            
            self.measure {
                let _ = b+c
            }
            /*
             '-[MatftTests.ArithmeticPefTests testPefAdd3]' measured [Time, seconds] average: 0.004, relative standard deviation: 16.815%, values: [0.004906, 0.003785, 0.003702, 0.005981, 0.004261, 0.003665, 0.004083, 0.003654, 0.003836, 0.003874]
            4.17ms
             */
        }

Matft achieved almost same performance as Numpy!!!

※Swift's performance test was conducted in release mode

My codes have several overhead and redundant part so this performance could be better than now.

import numpy as np
#import timeit

a = np.arange(10**6).reshape((10,10,10,10,10,10))
b = np.arange(0, -10**6, -1).reshape((10,10,10,10,10,10))

#timeit.timeit("b+c", repeat=10, globals=globals())
%timeit -n 10 a+b
"""
962 µs ± 273 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
"""

a = np.arange(10**6).reshape((10,10,10,10,10,10))
b = a.transpose((0,3,4,2,1,5))
c = a.T
#timeit.timeit("b+c", repeat=10, globals=globals())
%timeit -n 10 b+c
"""
5.68 ms ± 1.45 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
"""

a = np.arange(10**6).reshape((10,10,10,10,10,10))
b = a.transpose((1,2,3,4,5,0))
c = a.T
#timeit.timeit("b+c", repeat=10, globals=globals())
%timeit -n 10 b+c
"""
3.92 ms ± 897 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
"""

Installation

SwiftPM

  • Import
    • Project > Build Setting > + Build Setting
    • Select Rules select
  • Update
    • File >Swift Packages >Update to Latest Package versions update

Carthage

  • Set Cartfile

    echo 'github "jjjkkkjjj/Matft"' > Cartfile
     carthage update ###or append '--platform ios'
    
  • Import Matft.framework made by above process to your project

CocoaPods

  • Create Podfile (Skip if you have already done)

    pod init
  • Write pod 'Matft' in Podfile such like below

    target 'your project' do
      pod 'Matft'
    end
  • Install Matft

    pod install
Comments
  • Add fancy indexing

    Add fancy indexing

    Hey, I'm just curious if there are any plans to implement "fancy indexing", where you can pass a list of indeces to an MfArray, and return the items at those indeces, like in numpy. Thanks, its a great library so far.

    enhancement 
    opened by ALMerrill 10
  • memory leak...

    memory leak...

    I wrote pointer's value without initializing, too many many many memory leaks were occurred :)

    See ref Use move or initialize first.

    Bad code eg. here, here, here #

    bug 
    opened by jjjkkkjjj 9
  • Complex support

    Complex support

    To use vdsp, DSPSplitComplex seems to be needed according to documents

    To use blas package, DSPComplex will be needed according to this discussion

    to achieve to support complex type, using DSPComplex is ideal? I must check the difference between DSPComplex and DSPSplitComplex at first.

    DSPComplex is the consecutive float values.

    Complex data are stored as ordered pairs of floating-point numbers. Because they are stored as ordered pairs, complex vectors require address strides that are multiples of two.

    by document

    On the other hand, DSPSplitComplex is stored in different memories

    A structure that represents a single-precision complex vector with the real and imaginary parts stored in separate arrays.

    by document

    So I need to implement the function to connect this difference of memory layout

    enhancement 
    opened by jjjkkkjjj 8
  • Wrong Shape after

    Wrong Shape after "ufuncReduce add"

    Hello,

    I think there is a bug in ufuncReduce. This code

    Matft.ufuncReduce(mfarray: MfArray([1,2,3,4,5,6,7,8,9,10] as [Double]), ufunc: Matft.add)
    

    returns

    MfArray([55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    

    I would expect that I would get scalar or array of shape [1]. What am I doing wrong please?

    bug 
    opened by mlajtos 5
  • Boolean Indexing support ?

    Boolean Indexing support ?

    Hi ! Thanks for open sourcing your code.

    Would you mind suggesting the best way to do boolean indexing like numpy ? for example, I can do this in numpy easily

    import numpy as np
    
    img = np.array([
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]
    ], dtype=np.uint8)
    img[img > 3] = 10
    print(img)
    
    # [[ 1  2  3]
    # [10 10 10]
    # [10 10 10]]
    

    I tried to do it element-wise but I found the performance is significantly slower than using Swift Array

    var testing = Array(repeating: 1, count: 160000)
    var bar = MfArray(testing, shape: [400,400])
    var start = Date()
    for i in 0..<400 {
        for j in 0..<400 {
            bar[i,j] = bar[i,j] as! Int + 1
        }
    }
    print("\(start.timeIntervalSinceNow * -1) seconds elapsed")
    //3.706043004989624 seconds elapsed
    
    
    start = Date()
    for i in 0..<400 {
        for j in 0..<400 {
            let index1D = i*400+j
            testing[index1D] = testing[index1D] + 1
        }
    }
    print("\(start.timeIntervalSinceNow * -1) seconds elapsed")
    //0.05165994167327881 seconds elapsed
    

    Thanks !

    enhancement 
    opened by Ykid 4
  • Support for atan2

    Support for atan2

    Thanks for great library!

    Is there any way to get atan2 from combining 2 MfArrays? Like this:

    let R = MfArray([a, b ,c])
    
    let x = atan2((R[2, 1], R[2, 2])
    

    The issue for us is that we're porting the code from numpy logic, and functionality like that is supported there. E.g. we can retrieve single Double from the expression like R[2, 1] so we're struggling now on how to get similar behaviour.

    Thanks in advance!

    enhancement 
    opened by kkaun 3
  • Adding demo for image processing

    Adding demo for image processing

    Hi jjjkkkjjj,

    Great work on bring Numpy to Swift!!!

    I am learning how to do inference within CoreML using Swift.

    So far I have gotten the UIImage from an image picker and I need to do preprocessing e.g. resize, transpose, normalize(mean=(0,0,0), std=(1,1,1))

    And after hours and hours searching, Swift just proofed that it is not a language which is friendly for image processing. And I found your Repo here which has all the amazing feature I need.

    So I think it is very helpful if you could add a demo for this.

    Cheers

    opened by franva 3
  • Convert MfArray back to regular Swift's Array with a specific type

    Convert MfArray back to regular Swift's Array with a specific type

    Hi @jjjkkkjjj . After I did some math transformations in a MfArray, I want to convert it back to a Swift's Array. What's the most efficient way to do it using your library?

    For example, I want to convert the MfArray back to [Int]. Right now I'm doing it this way:

    let swiftArrayAny = Array(someMfArray).data)
    
    guard let swiftArrayInt32 = swiftArrayAny as? [Int32] else {
        fatalError()
    }
    
    let swiftArrayInt = swiftArrayInt32.map { Int($0) }
    
    enhancement 
    opened by alwc 3
  • Multidimensional MfArray with different length Arrays in axis 1

    Multidimensional MfArray with different length Arrays in axis 1

    Hello, I need to write a lot of python (numpy) code in swift and there I found your library. It would be a great help. Is it possible to create MfArrays that have different lengths at axis=1. Here is an example of what I mean:

    [
        [1, 2, 3, 4],
        [1, 2, 3],
        [1, 2, 3, 4, 5]
    ]
    

    If so, how would I need to instantiate the array?

    opened by sthuettr 2
  • Passing strange arguments in subscription

    Passing strange arguments in subscription

    let a = try! Matft.mfarray.broadcast_to(MfArray([[2, 5, -1],
                                                                 [3, 1, 0]]), shape: [2,2,2,3])
    let b = a[0~, ~1, ~~2]
    
    b[0, ~1] = MfArray([222]) >>>>>>> Precondition failed: -2 is out of bounds for axis 1 with 1: file
    

    subscription arguments [0, ~1] was passed as Int of Array [0, -2]...

    It's strange

    bug invalid 
    opened by jjjkkkjjj 2
  • Subscript’s getter and setter

    Subscript’s getter and setter

    If I don’t use generics in MfArray, subscript’s getter and setter must be handled as Any. However, using Any type causes unexpected error or performance loss.

    
    MfArray<MfType: MfTypable>{
        Hoge
    }
    
    //Initialization 
    let a = MfArray<Int>([1,2,3])
    
    //Getter and setter
    //Note that scalar will be handled only
    subscript(indices: Int...) -> MfType{
        hoge
    }
    
    //Note that MfArray will be handled only
    subscript(mfslices: MfSlice...) -> MfArray{
        fuga
    }
    
    opened by jjjkkkjjj 2
  • Copy On Write implementation

    Copy On Write implementation

    I think it is easier for Matft to implement COW than I expected. Because MfArray has a data class, which is MfData, all we have to do are 2 points. First add “mutating” keyword into conversion method and subscript function. Second check the _isView property in those “mutating” function and then replace the referenced MfData into the new one if the _isView is true.

    enhancement 
    opened by jjjkkkjjj 2
  • Image processing

    Image processing

    Create OpenCV Mat by https://stackoverflow.com/questions/39579398/opencv-how-to-create-mat-from-uint8-t-pointer

    and pass it by “with” statements.

    simple image processing function is vImage Module

    FFFF means float types (8888 means UInt8)

    https://developer.apple.com/documentation/accelerate/1515929-vimageconvolve_argbffff

    opened by jjjkkkjjj 5
  • Other Cubic spline Interpolation

    Other Cubic spline Interpolation

    Now, I just have implemented natural cubic spline only. Other boundary condition(clamped, not a knot, periodic) is not supported Ref: https://github.com/scipy/scipy/blob/v1.5.4/scipy/interpolate/_cubic.py#L464-L847

    enhancement 
    opened by jjjkkkjjj 0
  • Boolean Indexing is slow

    Boolean Indexing is slow

    Regarding #17

    Official boolean indexing code is https://github.com/numpy/numpy/blob/cf1306a842d7b1064270bd06951a485121e60816/numpy/core/src/multiarray/mapping.c#L1010

    SIMD function is https://github.com/numpy/numpy/blob/45bc13e6d922690eea43b9d807d476e0f243f836/numpy/core/src/umath/loops_comparison.dispatch.c.src#L36

    enhancement 
    opened by jjjkkkjjj 9
Releases(0.3.2)
Owner
null
Multi-dimensional Swift math

Upsurge Upsurge implements multi-dimensional data structures and operations. It brings numpy-like operations to Swift. Upsurge no longer supports DSP

Alejandro Isaza 180 Dec 20, 2022
Swift Matrix Library

Swift Matrix and Machine Learning Library Note: tensorflow/swift and apple/swift-numerics/issues/6 have or will have more complete support for NumPy-l

Scott Sievert 591 Sep 5, 2022
Swift Matrix Library

Swift Matrix and Machine Learning Library Note: tensorflow/swift and apple/swift-numerics/issues/6 have or will have more complete support for NumPy-l

Scott Sievert 591 Sep 5, 2022
MRFoundation - A library to complement the Swift Standard Library

MRFoundation MRFoundation is a library to complement the Swift Standard Library.

Roman Mogutnov 2 Feb 12, 2022
A cross-platform Swift library for evaluating mathematical expressions at runtime

Introduction What? Why? How? Usage Installation Integration Symbols Variables Operators Functions Arrays Performance Caching Optimization Standard Lib

Nick Lockwood 738 Jan 7, 2023
Overload +-*/ operator for Swift, make it easier to use (and not so strict)

Easy-Cal-Swift Overview This file is an overloading of +-*/ operator for Swift, to make it easier to use (and not so strict) It can make your life wit

Wei Wang 272 Jun 29, 2022
SwiftMath is a Swift framework providing some useful math constructs and functions

SwiftMath is a Swift framework providing some useful math constructs and functions, like complex numbers, vectors, matrices, quaternions, and polynomials.

Matteo Battaglio 175 Dec 2, 2022
A set of protocols for Arithmetic, Statistics and Logical operations

Arithmosophi - Arithmosoϕ Arithmosophi is a set of missing protocols that simplify arithmetic and statistics on generic objects or functions. As Equat

Eric Marchand 66 Jul 9, 2022
Beautiful math equation rendering on iOS and MacOS

iosMath iosMath is a library for displaying beautifully rendered math equations in iOS and MacOS applications. It typesets formulae written using the

Kostub Deshmukh 1.3k Dec 21, 2022
Metron is a comprehensive collection of geometric functions and types that extend the 2D geometric primitives

Metron Geometry, simplified. Metron is a comprehensive collection of geometric functions and types that extend the 2D geometric primitives provided by

Toine Heuvelmans 1k Dec 5, 2022
Arbitrary-precision arithmetic in pure Swift

Overview API Documentation License Requirements and Integration Implementation Notes Full-width multiplication and division primitives Why is there no

null 707 Dec 19, 2022
A collection of functions for statistical calculation written in Swift.

σ (sigma) - statistics library written in Swift This library is a collection of functions that perform statistical calculations in Swift. It can be us

Evgenii Neumerzhitckii 658 Jan 5, 2023
Swift Custom Operators for Mathematical Notation

Euler Euler uses custom operators in the "Math Symbols" character set to implement functions using traditional mathematical notation. Please keep in m

Mattt 1.1k Jan 4, 2023
Numeric facilities for Swift

NumericAnnex NumericAnnex supplements the numeric facilities provided in the Swift standard library. Features The exponentiation operator ** and the c

Xiaodi Wu 69 Nov 3, 2022
Math expression parser built with Point•Free's swift-parsing package

swift-math-parser Basic math expression parser built with Point•Free's swift-parsing package. NOTE: currently, this uses a fork of that fixes a parsin

Brad Howes 36 Dec 14, 2022
Matft is Numpy-like library in Swift. Function name and usage is similar to Numpy.

Numpy-like library in swift. (Multi-dimensional Array, ndarray, matrix and vector library)

null 80 Dec 21, 2022
VectorMath is a Swift library for Mac and iOS that implements common 2D and 3D vector and matrix functions

Purpose VectorMath is a Swift library for Mac and iOS that implements common 2D and 3D vector and matrix functions, useful for games or vector-based g

Nick Lockwood 341 Dec 31, 2022
Multi-dimensional Swift math

Upsurge Upsurge implements multi-dimensional data structures and operations. It brings numpy-like operations to Swift. Upsurge no longer supports DSP

Alejandro Isaza 180 Dec 20, 2022
Matrix-rust-components-swift - Swift package providing components from the matrix-rust-sdk

Swift package for Matrix Rust components This repository is a Swift Package for

matrix.org 10 Nov 4, 2022
Handling dimensional numbers with physical units in Swift made easy.

Dimensional arithmetics in Swift This package provides an easy and natural way of dealing with physical sizes. Performing complex arithmetics or unit

Niklas Nickel 1 May 27, 2022