Skip to content

Commit bd52e32

Browse files
author
Dag Sverre Seljebotn
committed
Merge pull request #4 from dagss/legtrans
Legendre transforms
2 parents 9a839b8 + 765831e commit bd52e32

21 files changed

Lines changed: 1883 additions & 3 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
*.o
2+
*.so
23
#*
34
*~
5+
*.pyc
6+
*.pyo
47

58
/auto
69
/autom4te.cache
@@ -9,3 +12,5 @@
912
/config/config.auto
1013
/configure
1114
/sharp_oracle.inc
15+
16+
/python/libsharp/libsharp.c

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,18 @@ perftest: compile_all
5353
$(BINDIR)/sharp_testsuite test gauss 2047 -1 -1 4096 0 1 && \
5454
$(BINDIR)/sharp_testsuite test gauss 4095 -1 -1 8192 0 1 && \
5555
$(BINDIR)/sharp_testsuite test gauss 8191 -1 -1 16384 0 1
56+
57+
%.c: %.c.in
58+
# Only do this if the md5sum changed, in order to avoid Python and Jinja
59+
# dependency when not modifying the c.in file
60+
grep `md5sum $< | cut -d ' ' -f 1` $@ || ./runjinja.py < $< > $@
61+
62+
genclean:
63+
rm libsharp/sharp_legendre.c || exit 0
64+
65+
pytest:
66+
rm python/libsharp/libsharp.so || exit 0
67+
cd python && LIBSHARP_INCLUDE=$(INCDIR) LIBSHARP_LIB=$(LIBDIR) python setup.py build_ext --inplace
68+
cd python && nosetests libsharp
69+
70+

fortran/sharp.f90

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,32 @@ subroutine c_sharp_execute_mpi(comm, type, spin, alm, map, geom_info, alm_info,
103103
type(c_ptr), intent(in) :: alm(*), map(*)
104104
end subroutine c_sharp_execute_mpi
105105

106+
! Legendre transforms
107+
subroutine c_sharp_legendre_transform(bl, recfac, lmax, x, out, nx) &
108+
bind(c, name='sharp_legendre_transform')
109+
use iso_c_binding
110+
integer(c_ptrdiff_t), value :: lmax, nx
111+
real(c_double) :: bl(lmax + 1), x(nx), out(nx)
112+
real(c_double), optional :: recfac(lmax + 1)
113+
end subroutine c_sharp_legendre_transform
114+
115+
subroutine c_sharp_legendre_transform_s(bl, recfac, lmax, x, out, nx) &
116+
bind(c, name='sharp_legendre_transform_s')
117+
use iso_c_binding
118+
integer(c_ptrdiff_t), value :: lmax, nx
119+
real(c_float) :: bl(lmax + 1), x(nx), out(nx)
120+
real(c_float), optional :: recfac(lmax + 1)
121+
end subroutine c_sharp_legendre_transform_s
106122
end interface
107123

108124
interface sharp_execute
109125
module procedure sharp_execute_d
110126
end interface
111127

128+
interface sharp_legendre_transform
129+
module procedure sharp_legendre_transform_d, sharp_legendre_transform_s
130+
end interface sharp_legendre_transform
131+
112132
contains
113133
! alm info
114134

@@ -240,6 +260,25 @@ subroutine sharp_execute_d(type, spin, nmaps, alm, alm_info, map, geom_info, &
240260
end if
241261
end subroutine sharp_execute_d
242262

263+
subroutine sharp_legendre_transform_d(bl, x, out)
264+
use iso_c_binding
265+
real(c_double) :: bl(:)
266+
real(c_double) :: x(:), out(size(x))
267+
!--
268+
integer(c_ptrdiff_t) :: lmax, nx
269+
call c_sharp_legendre_transform(bl, lmax=int(size(bl) - 1, c_ptrdiff_t), &
270+
x=x, out=out, nx=int(size(x), c_ptrdiff_t))
271+
end subroutine sharp_legendre_transform_d
272+
273+
subroutine sharp_legendre_transform_s(bl, x, out)
274+
use iso_c_binding
275+
real(c_float) :: bl(:)
276+
real(c_float) :: x(:), out(size(x))
277+
!--
278+
integer(c_ptrdiff_t) :: lmax, nx
279+
call c_sharp_legendre_transform_s(bl, lmax=int(size(bl) - 1, c_ptrdiff_t), &
280+
x=x, out=out, nx=int(size(x), c_ptrdiff_t))
281+
end subroutine sharp_legendre_transform_s
243282

244283

245284
end module

fortran/test_sharp.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,31 @@ program test_sharp
5454
print *, 'DONE'
5555
call MPI_Finalize(ierr)
5656

57+
print *, 'LEGENDRE TRANSFORMS'
58+
59+
call test_legendre_transforms()
60+
61+
contains
62+
subroutine test_legendre_transforms()
63+
integer, parameter :: lmax = 20, nx=10
64+
real(c_double) :: bl(0:lmax)
65+
real(c_double) :: x(nx), out(nx)
66+
real(c_float) :: out_s(nx)
67+
!--
68+
integer :: l, i
69+
70+
do l = 0, lmax
71+
bl(l) = 1.0 / real(l + 1, c_double)
72+
end do
73+
do i = 1, nx
74+
x(i) = 1 / real(i, c_double)
75+
end do
76+
out = 0
77+
call sharp_legendre_transform(bl, x, out)
78+
print *, out
79+
call sharp_legendre_transform(real(bl, c_float), real(x, c_float), out_s)
80+
print *, out_s
81+
end subroutine test_legendre_transforms
82+
83+
5784
end program test_sharp

libsharp/planck.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FULL_INCLUDE+= -I$(SD)
88
HDR_$(PKG):=$(SD)/*.h
99
LIB_$(PKG):=$(LIBDIR)/libsharp.a
1010
BIN:=sharp_testsuite
11-
LIBOBJ:=sharp_ylmgen_c.o sharp.o sharp_announce.o sharp_geomhelpers.o sharp_almhelpers.o sharp_core.o
11+
LIBOBJ:=sharp_ylmgen_c.o sharp.o sharp_announce.o sharp_geomhelpers.o sharp_almhelpers.o sharp_core.o sharp_legendre.o
1212
ALLOBJ:=$(LIBOBJ) sharp_testsuite.o
1313
LIBOBJ:=$(LIBOBJ:%=$(OD)/%)
1414
ALLOBJ:=$(ALLOBJ:%=$(OD)/%)

libsharp/sharp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
#include <complex.h>
4040

4141
#include "sharp_lowlevel.h"
42+
#include "sharp_legendre.h"
4243

4344
#endif

0 commit comments

Comments
 (0)