Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
noshu committed May 20, 2016
0 parents commit 5e2a27b
Show file tree
Hide file tree
Showing 10 changed files with 1,371 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "cg-sys"
version = "0.1.0"
authors = ["noshu <naushad1290@gmail.com>"]
build = "build.rs"
[features]
static = []
[dependencies]
libc = "*"
43 changes: 43 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// build.rs

use std::process::Command;
use std::env::{var};
use std::path::PathBuf;

macro_rules! feature(
($name:expr) => (var(concat!("CARGO_FEATURE_", $name)).is_ok());
);

macro_rules! variable(
($name:expr) => (var($name).unwrap());
);

fn main() {
let kind = if feature!("STATIC") { "static" } else { "dylib" };
let source = PathBuf::from("fortran");
let output = PathBuf::from(variable!("OUT_DIR").replace(r"\", "/"));
let os = if cfg!(target_os = "macos"){"Macos"}
else if cfg!(target_os = "windows"){"Windows"}
else {"Linux"};
let com = if os=="Windows" {"mingw32-make"}else{"make"};
run(Command::new(com)
.arg(kind)
.arg(format!("OUTPUT={}",output.display()))
.arg(format!("OSNAME={}",os))
.current_dir(&source));

println!("cargo:rustc-link-search={}", output.display());
println!("cargo:rustc-link-lib={}=cgfam",kind);
println!("cargo:rustc-link-lib=dylib=gfortran");
}
fn run(command: &mut Command) {
println!("Running: {:?}", command);
match command.status() {
Ok(status) => if !status.success() {
panic!("`{:?}` failed: {}", command, status);
},
Err(error) => {
panic!("failed to execute `{:?}`: {}", command, error);
},
}
}
261 changes: 261 additions & 0 deletions fortran/blas.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
c
c L-BFGS-B is released under the “New BSD License” (aka “Modified BSD License”
c or “3-clause license”)
c Please read attached file License.txt
c

double precision function dnrm2(n,x,incx)
integer n,incx
double precision x(n)
c **********
c
c Function dnrm2
c
c Given a vector x of length n, this function calculates the
c Euclidean norm of x with stride incx.
c
c The function statement is
c
c double precision function dnrm2(n,x,incx)
c
c where
c
c n is a positive integer input variable.
c
c x is an input array of length n.
c
c incx is a positive integer variable that specifies the
c stride of the vector.
c
c Subprograms called
c
c FORTRAN-supplied ... abs, max, sqrt
c
c MINPACK-2 Project. February 1991.
c Argonne National Laboratory.
c Brett M. Averick.
c
c **********
integer i
double precision scale

dnrm2 = 0.0d0
scale = 0.0d0

do 10 i = 1, n, incx
scale = max(scale, abs(x(i)))
10 continue

if (scale .eq. 0.0d0) return

do 20 i = 1, n, incx
dnrm2 = dnrm2 + (x(i)/scale)**2
20 continue

dnrm2 = scale*sqrt(dnrm2)


return

end

c====================== The end of dnrm2 ===============================

subroutine daxpy(n,da,dx,incx,dy,incy)
c
c constant times a vector plus a vector.
c uses unrolled loops for increments equal to one.
c jack dongarra, linpack, 3/11/78.
c
double precision dx(*),dy(*),da
integer i,incx,incy,ix,iy,m,mp1,n
c
if(n.le.0)return
if (da .eq. 0.0d0) return
if(incx.eq.1.and.incy.eq.1)go to 20
c
c code for unequal increments or equal increments
c not equal to 1
c
ix = 1
iy = 1
if(incx.lt.0)ix = (-n+1)*incx + 1
if(incy.lt.0)iy = (-n+1)*incy + 1
do 10 i = 1,n
dy(iy) = dy(iy) + da*dx(ix)
ix = ix + incx
iy = iy + incy
10 continue
return
c
c code for both increments equal to 1
c
c
c clean-up loop
c
20 m = mod(n,4)
if( m .eq. 0 ) go to 40
do 30 i = 1,m
dy(i) = dy(i) + da*dx(i)
30 continue
if( n .lt. 4 ) return
40 mp1 = m + 1
do 50 i = mp1,n,4
dy(i) = dy(i) + da*dx(i)
dy(i + 1) = dy(i + 1) + da*dx(i + 1)
dy(i + 2) = dy(i + 2) + da*dx(i + 2)
dy(i + 3) = dy(i + 3) + da*dx(i + 3)
50 continue
return
end

c====================== The end of daxpy ===============================

subroutine dcopy(n,dx,incx,dy,incy)
c
c copies a vector, x, to a vector, y.
c uses unrolled loops for increments equal to one.
c jack dongarra, linpack, 3/11/78.
c
double precision dx(*),dy(*)
integer i,incx,incy,ix,iy,m,mp1,n
c
if(n.le.0)return
if(incx.eq.1.and.incy.eq.1)go to 20
c
c code for unequal increments or equal increments
c not equal to 1
c
ix = 1
iy = 1
if(incx.lt.0)ix = (-n+1)*incx + 1
if(incy.lt.0)iy = (-n+1)*incy + 1
do 10 i = 1,n
dy(iy) = dx(ix)
ix = ix + incx
iy = iy + incy
10 continue
return
c
c code for both increments equal to 1
c
c
c clean-up loop
c
20 m = mod(n,7)
if( m .eq. 0 ) go to 40
do 30 i = 1,m
dy(i) = dx(i)
30 continue
if( n .lt. 7 ) return
40 mp1 = m + 1
do 50 i = mp1,n,7
dy(i) = dx(i)
dy(i + 1) = dx(i + 1)
dy(i + 2) = dx(i + 2)
dy(i + 3) = dx(i + 3)
dy(i + 4) = dx(i + 4)
dy(i + 5) = dx(i + 5)
dy(i + 6) = dx(i + 6)
50 continue
return
end

c====================== The end of dcopy ===============================

double precision function ddot(n,dx,incx,dy,incy)
c
c forms the dot product of two vectors.
c uses unrolled loops for increments equal to one.
c jack dongarra, linpack, 3/11/78.
c
double precision dx(*),dy(*),dtemp
integer i,incx,incy,ix,iy,m,mp1,n
c
ddot = 0.0d0
dtemp = 0.0d0
if(n.le.0)return
if(incx.eq.1.and.incy.eq.1)go to 20
c
c code for unequal increments or equal increments
c not equal to 1
c
ix = 1
iy = 1
if(incx.lt.0)ix = (-n+1)*incx + 1
if(incy.lt.0)iy = (-n+1)*incy + 1
do 10 i = 1,n
dtemp = dtemp + dx(ix)*dy(iy)
ix = ix + incx
iy = iy + incy
10 continue
ddot = dtemp
return
c
c code for both increments equal to 1
c
c
c clean-up loop
c
20 m = mod(n,5)
if( m .eq. 0 ) go to 40
do 30 i = 1,m
dtemp = dtemp + dx(i)*dy(i)
30 continue
if( n .lt. 5 ) go to 60
40 mp1 = m + 1
do 50 i = mp1,n,5
dtemp = dtemp + dx(i)*dy(i) + dx(i + 1)*dy(i + 1) +
* dx(i + 2)*dy(i + 2) + dx(i + 3)*dy(i + 3) + dx(i + 4)*dy(i + 4)
50 continue
60 ddot = dtemp
return
end

c====================== The end of ddot ================================

subroutine dscal(n,da,dx,incx)
c
c scales a vector by a constant.
c uses unrolled loops for increment equal to one.
c jack dongarra, linpack, 3/11/78.
c modified 3/93 to return if incx .le. 0.
c
double precision da,dx(*)
integer i,incx,m,mp1,n,nincx
c
if( n.le.0 .or. incx.le.0 )return
if(incx.eq.1)go to 20
c
c code for increment not equal to 1
c
nincx = n*incx
do 10 i = 1,nincx,incx
dx(i) = da*dx(i)
10 continue
return
c
c code for increment equal to 1
c
c
c clean-up loop
c
20 m = mod(n,5)
if( m .eq. 0 ) go to 40
do 30 i = 1,m
dx(i) = da*dx(i)
30 continue
if( n .lt. 5 ) return
40 mp1 = m + 1
do 50 i = mp1,n,5
dx(i) = da*dx(i)
dx(i + 1) = da*dx(i + 1)
dx(i + 2) = da*dx(i + 2)
dx(i + 3) = da*dx(i + 3)
dx(i + 4) = da*dx(i + 4)
50 continue
return
end

c====================== The end of dscal ===============================

Loading

0 comments on commit 5e2a27b

Please sign in to comment.