This repository has been archived by the owner on Jul 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svd, matrix+*double sped up, pointerToMatrix fixed
- Loading branch information
scottsievert
committed
Jul 15, 2014
1 parent
eb82f4f
commit e1e5f87
Showing
10 changed files
with
153 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// svd.m | ||
// swix | ||
// | ||
// Created by Scott Sievert on 7/15/14. | ||
// Copyright (c) 2014 com.scott. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <Accelerate/Accelerate.h> | ||
#import <stdint.h> | ||
#import "swix-Bridging-Header.h" // for copy_objc | ||
|
||
void svd_objc(double * xx, int m, int n, double* sigma, double* vt, double* u){ | ||
// adapted from http://stackoverflow.com/questions/5047503/lapack-svd-singular-value-decomposition | ||
// Setup a buffer to hold the singular values: | ||
int lda = m; | ||
int numberOfSingularValues = m < n ? m : n; | ||
|
||
// Workspace and status variables: | ||
double workSize; | ||
double *work = &workSize; | ||
int lwork = -1; | ||
int *iwork = malloc(8*numberOfSingularValues); | ||
int info = 0; | ||
|
||
// Call dgesdd_ with lwork = -1 to query optimal workspace size: | ||
dgesdd_("A", &m, &n, xx, &lda, sigma, u, &m, vt, &n, work, &lwork, iwork, &info); | ||
|
||
// Optimal workspace size is returned in work[0]. | ||
lwork = workSize; | ||
work = malloc(lwork * sizeof *work); | ||
|
||
// Call dgesdd_ to do the actual computation: | ||
dgesdd_("A", &m, &n, xx, &lda, sigma, u, &m, vt, &n, work, &lwork, iwork, &info); | ||
free(work); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// twoD-complex-math.swift | ||
// swix | ||
// | ||
// Created by Scott Sievert on 7/15/14. | ||
// Copyright (c) 2014 com.scott. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
func svd(x: matrix2d) -> (matrix2d, matrix, matrix2d){ | ||
// 2014-7-15: almost have this working. to change by tomorrow. | ||
var (m, n) = x.shape | ||
var nS = m < n ? m : n | ||
var sigma = zeros(nS) | ||
var vt = zeros((n,n)) | ||
var u = zeros((m,m)) | ||
|
||
var xx = zeros_like(x) | ||
xx.flat = x.flat | ||
xx = transpose(xx) | ||
var xP = matrixToPointer(xx.flat) | ||
var sP = matrixToPointer(sigma) | ||
var vP = matrixToPointer(vt.flat) | ||
var uP = matrixToPointer(u.flat) | ||
|
||
println(x) | ||
svd_objc(xP, m.cint, n.cint, sP, vP, uP); | ||
if m > n {vt = transpose(vt)} | ||
|
||
println(sigma) | ||
println(vt) | ||
println(u) | ||
|
||
return (zeros((2,2)), zeros(2), zeros((2,2))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters