gumath 0.2.0dev5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +61 -0
  3. data/Gemfile +5 -0
  4. data/History.md +0 -0
  5. data/README.md +5 -0
  6. data/Rakefile +105 -0
  7. data/ext/ruby_gumath/examples.c +126 -0
  8. data/ext/ruby_gumath/extconf.rb +97 -0
  9. data/ext/ruby_gumath/functions.c +106 -0
  10. data/ext/ruby_gumath/gufunc_object.c +79 -0
  11. data/ext/ruby_gumath/gufunc_object.h +55 -0
  12. data/ext/ruby_gumath/gumath/AUTHORS.txt +5 -0
  13. data/ext/ruby_gumath/gumath/INSTALL.txt +42 -0
  14. data/ext/ruby_gumath/gumath/LICENSE.txt +29 -0
  15. data/ext/ruby_gumath/gumath/MANIFEST.in +3 -0
  16. data/ext/ruby_gumath/gumath/Makefile.in +62 -0
  17. data/ext/ruby_gumath/gumath/README.rst +20 -0
  18. data/ext/ruby_gumath/gumath/config.guess +1530 -0
  19. data/ext/ruby_gumath/gumath/config.h.in +52 -0
  20. data/ext/ruby_gumath/gumath/config.sub +1782 -0
  21. data/ext/ruby_gumath/gumath/configure +5049 -0
  22. data/ext/ruby_gumath/gumath/configure.ac +167 -0
  23. data/ext/ruby_gumath/gumath/doc/_static/copybutton.js +66 -0
  24. data/ext/ruby_gumath/gumath/doc/conf.py +26 -0
  25. data/ext/ruby_gumath/gumath/doc/gumath/functions.rst +62 -0
  26. data/ext/ruby_gumath/gumath/doc/gumath/index.rst +26 -0
  27. data/ext/ruby_gumath/gumath/doc/index.rst +45 -0
  28. data/ext/ruby_gumath/gumath/doc/libgumath/data-structures.rst +130 -0
  29. data/ext/ruby_gumath/gumath/doc/libgumath/functions.rst +78 -0
  30. data/ext/ruby_gumath/gumath/doc/libgumath/index.rst +25 -0
  31. data/ext/ruby_gumath/gumath/doc/libgumath/kernels.rst +41 -0
  32. data/ext/ruby_gumath/gumath/doc/releases/index.rst +11 -0
  33. data/ext/ruby_gumath/gumath/install-sh +527 -0
  34. data/ext/ruby_gumath/gumath/libgumath/Makefile.in +170 -0
  35. data/ext/ruby_gumath/gumath/libgumath/Makefile.vc +160 -0
  36. data/ext/ruby_gumath/gumath/libgumath/apply.c +201 -0
  37. data/ext/ruby_gumath/gumath/libgumath/extending/bfloat16.c +130 -0
  38. data/ext/ruby_gumath/gumath/libgumath/extending/examples.c +176 -0
  39. data/ext/ruby_gumath/gumath/libgumath/extending/graph.c +393 -0
  40. data/ext/ruby_gumath/gumath/libgumath/extending/pdist.c +140 -0
  41. data/ext/ruby_gumath/gumath/libgumath/extending/quaternion.c +156 -0
  42. data/ext/ruby_gumath/gumath/libgumath/func.c +177 -0
  43. data/ext/ruby_gumath/gumath/libgumath/gumath.h +205 -0
  44. data/ext/ruby_gumath/gumath/libgumath/kernels/binary.c +547 -0
  45. data/ext/ruby_gumath/gumath/libgumath/kernels/unary.c +449 -0
  46. data/ext/ruby_gumath/gumath/libgumath/nploops.c +219 -0
  47. data/ext/ruby_gumath/gumath/libgumath/tbl.c +223 -0
  48. data/ext/ruby_gumath/gumath/libgumath/thread.c +175 -0
  49. data/ext/ruby_gumath/gumath/libgumath/xndloops.c +130 -0
  50. data/ext/ruby_gumath/gumath/python/extending.py +24 -0
  51. data/ext/ruby_gumath/gumath/python/gumath/__init__.py +74 -0
  52. data/ext/ruby_gumath/gumath/python/gumath/_gumath.c +577 -0
  53. data/ext/ruby_gumath/gumath/python/gumath/examples.c +93 -0
  54. data/ext/ruby_gumath/gumath/python/gumath/functions.c +77 -0
  55. data/ext/ruby_gumath/gumath/python/gumath/pygumath.h +95 -0
  56. data/ext/ruby_gumath/gumath/python/test_gumath.py +405 -0
  57. data/ext/ruby_gumath/gumath/setup.py +298 -0
  58. data/ext/ruby_gumath/gumath/vcbuild/INSTALL.txt +36 -0
  59. data/ext/ruby_gumath/gumath/vcbuild/vcbuild32.bat +21 -0
  60. data/ext/ruby_gumath/gumath/vcbuild/vcbuild64.bat +21 -0
  61. data/ext/ruby_gumath/gumath/vcbuild/vcclean.bat +10 -0
  62. data/ext/ruby_gumath/gumath/vcbuild/vcdistclean.bat +11 -0
  63. data/ext/ruby_gumath/include/gumath.h +205 -0
  64. data/ext/ruby_gumath/include/ruby_gumath.h +41 -0
  65. data/ext/ruby_gumath/lib/libgumath.a +0 -0
  66. data/ext/ruby_gumath/lib/libgumath.so +1 -0
  67. data/ext/ruby_gumath/lib/libgumath.so.0 +1 -0
  68. data/ext/ruby_gumath/lib/libgumath.so.0.2.0dev3 +0 -0
  69. data/ext/ruby_gumath/ruby_gumath.c +295 -0
  70. data/ext/ruby_gumath/ruby_gumath.h +41 -0
  71. data/ext/ruby_gumath/ruby_gumath_internal.h +45 -0
  72. data/ext/ruby_gumath/util.c +68 -0
  73. data/ext/ruby_gumath/util.h +48 -0
  74. data/gumath.gemspec +47 -0
  75. data/lib/gumath.rb +7 -0
  76. data/lib/gumath/version.rb +5 -0
  77. data/lib/ruby_gumath.so +0 -0
  78. metadata +206 -0
@@ -0,0 +1,170 @@
1
+
2
+ # ==============================================================================
3
+ # Unix Makefile for libxnd
4
+ # ==============================================================================
5
+
6
+
7
+ LIBSTATIC = @LIBSTATIC@
8
+ LIBNAME = @LIBNAME@
9
+ LIBSONAME = @LIBSONAME@
10
+ LIBSHARED = @LIBSHARED@
11
+
12
+ CC = @CC@
13
+ LD = @LD@
14
+ AR = @AR@
15
+ RANLIB = @RANLIB@
16
+
17
+ GM_INCLUDES = @CONFIGURE_INCLUDES@
18
+
19
+ CONFIGURE_CFLAGS = @CONFIGURE_CFLAGS@
20
+ GM_CFLAGS = $(strip -I.. -I$(GM_INCLUDES) $(CONFIGURE_CFLAGS) $(CFLAGS))
21
+ GM_CFLAGS_SHARED = $(GM_CFLAGS) -fPIC
22
+
23
+ CONFIGURE_LDFLAGS = @CONFIGURE_LDFLAGS@
24
+ GM_LDFLAGS = $(strip $(CONFIGURE_LDFLAGS) $(LDFLAGS))
25
+
26
+
27
+ default: $(LIBSTATIC) $(LIBSHARED)
28
+
29
+
30
+ OBJS = apply.o func.o nploops.o tbl.o thread.o xndloops.o unary.o binary.o \
31
+ examples.o bfloat16.o graph.o quaternion.o pdist.o
32
+
33
+ SHARED_OBJS = .objs/apply.o .objs/func.o .objs/nploops.o .objs/tbl.o .objs/thread.o .objs/xndloops.o \
34
+ .objs/unary.o .objs/binary.o .objs/examples.o .objs/bfloat16.o .objs/graph.o \
35
+ .objs/quaternion.o .objs/pdist.o
36
+
37
+
38
+ $(LIBSTATIC): Makefile $(OBJS)
39
+ $(AR) rc $(LIBSTATIC) $(OBJS)
40
+ $(RANLIB) $(LIBSTATIC)
41
+
42
+ $(LIBSHARED): Makefile $(SHARED_OBJS)
43
+ $(LD) $(GM_LDFLAGS) -o $(LIBSHARED) $(SHARED_OBJS)
44
+ ln -sf $(LIBSHARED) $(LIBNAME)
45
+ ln -sf $(LIBSHARED) $(LIBSONAME)
46
+
47
+
48
+ apply.o:\
49
+ Makefile apply.c gumath.h
50
+ $(CC) $(GM_CFLAGS) -c apply.c
51
+
52
+ .objs/apply.o:\
53
+ Makefile apply.c gumath.h
54
+ $(CC) $(GM_CFLAGS_SHARED) -c apply.c -o .objs/apply.o
55
+
56
+ func.o:\
57
+ Makefile func.c gumath.h
58
+ $(CC) $(GM_CFLAGS) -c func.c
59
+
60
+ .objs/func.o:\
61
+ Makefile func.c gumath.h
62
+ $(CC) $(GM_CFLAGS_SHARED) -c func.c -o .objs/func.o
63
+
64
+ nploops.o:\
65
+ Makefile nploops.c gumath.h
66
+ $(CC) $(GM_CFLAGS) -c nploops.c
67
+
68
+ .objs/nploops.o:\
69
+ Makefile nploops.c gumath.h
70
+ $(CC) $(GM_CFLAGS_SHARED) -c nploops.c -o .objs/nploops.o
71
+
72
+ tbl.o:\
73
+ Makefile tbl.c gumath.h
74
+ $(CC) $(GM_CFLAGS) -c tbl.c
75
+
76
+ .objs/tbl.o:\
77
+ Makefile tbl.c gumath.h
78
+ $(CC) $(GM_CFLAGS_SHARED) -c tbl.c -o .objs/tbl.o
79
+
80
+ thread.o:\
81
+ Makefile thread.c gumath.h
82
+ $(CC) $(GM_CFLAGS) -c thread.c
83
+
84
+ .objs/thread.o:\
85
+ Makefile thread.c gumath.h
86
+ $(CC) $(GM_CFLAGS_SHARED) -c thread.c -o .objs/thread.o
87
+
88
+ xndloops.o:\
89
+ Makefile xndloops.c gumath.h
90
+ $(CC) $(GM_CFLAGS) -c xndloops.c
91
+
92
+ .objs/xndloops.o:\
93
+ Makefile xndloops.c gumath.h
94
+ $(CC) $(GM_CFLAGS_SHARED) -c xndloops.c -o .objs/xndloops.o
95
+
96
+ unary.o:\
97
+ Makefile kernels/unary.c gumath.h
98
+ $(CC) -I. $(GM_CFLAGS) -Wno-absolute-value -c kernels/unary.c
99
+
100
+ .objs/unary.o:\
101
+ Makefile kernels/unary.c gumath.h
102
+ $(CC) -I. $(GM_CFLAGS_SHARED) -Wno-absolute-value -c kernels/unary.c -o .objs/unary.o
103
+
104
+ binary.o:\
105
+ Makefile kernels/binary.c gumath.h
106
+ $(CC) -I. $(GM_CFLAGS) -c kernels/binary.c
107
+
108
+ .objs/binary.o:\
109
+ Makefile kernels/binary.c gumath.h
110
+ $(CC) -I. $(GM_CFLAGS_SHARED) -c kernels/binary.c -o .objs/binary.o
111
+
112
+ examples.o:\
113
+ Makefile extending/examples.c gumath.h
114
+ $(CC) -I. $(GM_CFLAGS) -c extending/examples.c -o examples.o
115
+
116
+ .objs/examples.o:\
117
+ Makefile extending/examples.c gumath.h
118
+ $(CC) -I. $(GM_CFLAGS_SHARED) -c extending/examples.c -o .objs/examples.o
119
+
120
+ bfloat16.o:\
121
+ Makefile extending/bfloat16.c gumath.h
122
+ $(CC) -I. $(GM_CFLAGS) -c extending/bfloat16.c -o bfloat16.o
123
+
124
+ .objs/bfloat16.o:\
125
+ Makefile extending/bfloat16.c gumath.h
126
+ $(CC) -I. $(GM_CFLAGS_SHARED) -c extending/bfloat16.c -o .objs/bfloat16.o
127
+
128
+ graph.o:\
129
+ Makefile extending/graph.c gumath.h
130
+ $(CC) -I. $(GM_CFLAGS) -c extending/graph.c -o graph.o
131
+
132
+ .objs/graph.o:\
133
+ Makefile extending/graph.c gumath.h
134
+ $(CC) -I. $(GM_CFLAGS_SHARED) -c extending/graph.c -o .objs/graph.o
135
+
136
+ quaternion.o:\
137
+ Makefile extending/quaternion.c gumath.h
138
+ $(CC) -I. $(GM_CFLAGS) -c extending/quaternion.c -o quaternion.o
139
+
140
+ .objs/quaternion.o:\
141
+ Makefile extending/quaternion.c gumath.h
142
+ $(CC) -I. $(GM_CFLAGS_SHARED) -c extending/quaternion.c -o .objs/quaternion.o
143
+
144
+ pdist.o:\
145
+ Makefile extending/pdist.c gumath.h
146
+ $(CC) -I. $(GM_CFLAGS) -c extending/pdist.c -o pdist.o
147
+
148
+ .objs/pdist.o:\
149
+ Makefile extending/pdist.c gumath.h
150
+ $(CC) -I. $(GM_CFLAGS_SHARED) -c extending/pdist.c -o .objs/pdist.o
151
+
152
+
153
+ # Coverage
154
+ coverage:\
155
+ Makefile clean runtest
156
+ ./tests/runtest
157
+ for file in *.c; do gcov -l "$$file" > /dev/null 2>&1; done
158
+
159
+ FORCE:
160
+
161
+ clean: FORCE
162
+ rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock
163
+ rm -f $(LIBSTATIC) $(LIBSHARED) $(LIBSONAME) $(LIBNAME)
164
+ cd .objs && rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock
165
+
166
+ distclean: clean
167
+ rm -f Makefile
168
+
169
+
170
+
@@ -0,0 +1,160 @@
1
+
2
+ # ======================================================================
3
+ # Visual C (nmake) Makefile for libgumath
4
+ # ======================================================================
5
+
6
+ LIBSTATIC = libgumath-0.2.0dev3.lib
7
+ LIBIMPORT = libgumath-0.2.0dev3.dll.lib
8
+ LIBSHARED = libgumath-0.2.0dev3.dll
9
+ LIBNDTYPESIMPORT = libndtypes-0.2.0dev3.dll.lib
10
+ LIBXNDIMPORT = libxnd-0.2.0dev3.dll.lib
11
+
12
+ !ifndef LIBNDTYPESINCLUDE
13
+ LIBNDTYPESINCLUDE = ..\ndtypes\libndtypes
14
+ !endif
15
+
16
+ !ifndef LIBNDTYPESDIR
17
+ LIBNDTYPESDIR = ..\ndtypes\libndtypes
18
+ !endif
19
+
20
+ !ifndef LIBXNDINCLUDE
21
+ LIBXNDINCLUDE = ..\xnd\libxnd
22
+ !endif
23
+
24
+ !ifndef LIBXNDDIR
25
+ LIBXNDDIR = ..\xnd\libxnd
26
+ !endif
27
+
28
+ OPT = /MT /Ox /GS /EHsc /fp:strict
29
+ OPT_SHARED = /DGM_EXPORT /DNDT_IMPORT /DXND_IMPORT /MD /Ox /GS /EHsc /fp:strict /Fo.objs^\
30
+
31
+ COMMON_CFLAGS = /nologo /W4 /wd4200 /wd4201 /wd4204
32
+ CFLAGS = $(COMMON_CFLAGS) $(OPT)
33
+ CFLAGS_SHARED = $(COMMON_CFLAGS) $(OPT_SHARED)
34
+
35
+
36
+ default: $(LIBSTATIC) $(LIBSHARED)
37
+ copy /y gumath.h ..\python\gumath
38
+ copy /y $(LIBSTATIC) ..\python\gumath
39
+ copy /y $(LIBIMPORT) ..\python\gumath
40
+ copy /y $(LIBSHARED) ..\python\gumath
41
+
42
+
43
+ OBJS = apply.obj func.obj nploops.obj tbl.obj xndloops.obj \
44
+ unary.obj binary.obj examples.obj graph.obj pdist.obj
45
+
46
+ SHARED_OBJS = .objs/apply.obj .objs/func.obj .objs/nploops.obj .objs/tbl.obj .objs/xndloops.obj \
47
+ .objs/unary.obj .objs/binary.obj .objs/examples.obj .objs/graph.obj .objs/pdist.obj
48
+
49
+
50
+ $(LIBSTATIC):\
51
+ Makefile $(OBJS)
52
+ -@if exist $@ del $(LIBSTATIC)
53
+ lib /nologo /out:$(LIBSTATIC) $(OBJS)
54
+
55
+ $(LIBSHARED):\
56
+ Makefile $(SHARED_OBJS)
57
+ -@if exist $@ del $(LIBSHARED)
58
+ link /nologo /DLL /MANIFEST /out:$(LIBSHARED) /implib:$(LIBIMPORT) $(SHARED_OBJS) \
59
+ "/LIBPATH:$(LIBNDTYPESDIR)" $(LIBNDTYPESIMPORT) \
60
+ "/LIBPATH:$(LIBXNDDIR)" $(LIBXNDIMPORT)
61
+ mt /nologo -manifest $(LIBSHARED).manifest -outputresource:$(LIBSHARED);2
62
+
63
+
64
+ apply.obj:\
65
+ Makefile apply.c gumath.h
66
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c apply.c
67
+
68
+ .objs\apply.obj:\
69
+ Makefile apply.c gumath.h
70
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c apply.c
71
+
72
+ func.obj:\
73
+ Makefile func.c gumath.h
74
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c func.c
75
+
76
+ .objs\func.obj:\
77
+ Makefile func.c gumath.h
78
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c func.c
79
+
80
+ nploops.obj:\
81
+ Makefile nploops.c gumath.h
82
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c nploops.c
83
+
84
+ .objs\nploops.obj:\
85
+ Makefile nploops.c gumath.h
86
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c nploops.c
87
+
88
+ tbl.obj:\
89
+ Makefile tbl.c gumath.h
90
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c tbl.c
91
+
92
+ .objs\tbl.obj:\
93
+ Makefile tbl.c gumath.h
94
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c tbl.c
95
+
96
+ xndloops.obj:\
97
+ Makefile xndloops.c gumath.h
98
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c xndloops.c
99
+
100
+ .objs\xndloops.obj:\
101
+ Makefile xndloops.c gumath.h
102
+ $(CC) "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c xndloops.c
103
+
104
+ unary.obj:\
105
+ Makefile kernels\unary.c gumath.h
106
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c kernels\unary.c
107
+
108
+ .objs\unary.obj:\
109
+ Makefile kernels\unary.c gumath.h
110
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c kernels\unary.c
111
+
112
+ binary.obj:\
113
+ Makefile kernels\binary.c gumath.h
114
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c kernels\binary.c
115
+
116
+ .objs\binary.obj:\
117
+ Makefile kernels\binary.c gumath.h
118
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c kernels\binary.c
119
+
120
+ examples.obj:\
121
+ Makefile extending\examples.c gumath.h
122
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c extending\examples.c
123
+
124
+ .objs\examples.obj:\
125
+ Makefile extending\examples.c gumath.h
126
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c extending\examples.c
127
+
128
+ graph.obj:\
129
+ Makefile extending\graph.c gumath.h
130
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c extending\graph.c
131
+
132
+ .objs\graph.obj:\
133
+ Makefile extending\graph.c gumath.h
134
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c extending\graph.c
135
+
136
+ pdist.obj:\
137
+ Makefile extending\pdist.c gumath.h
138
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS) -c extending\pdist.c
139
+
140
+ .objs\pdist.obj:\
141
+ Makefile extending\pdist.c gumath.h
142
+ $(CC) -I. "-I$(LIBNDTYPESINCLUDE)" "-I$(LIBXNDINCLUDE)" $(CFLAGS_SHARED) -c extending\pdist.c
143
+
144
+
145
+ FORCE:
146
+
147
+ clean: FORCE
148
+ del /q /f *.exe *.obj *.lib *.dll *.exp *.manifest 2>NUL
149
+ cd .objs && del /q /f *.obj 2>NUL
150
+ if exist "..\build\" rd /q /s "..\build\"
151
+ if exist "..\dist\" rd /q /s "..\dist\"
152
+ if exist "..\MANIFEST" del "..\MANIFEST"
153
+ if exist "..\record.txt" del "..\record.txt"
154
+ cd ..\python\gumath && del *.lib *.dll *.pyd gumath.h 2>NUL
155
+
156
+ distclean: clean
157
+ del Makefile 2>NUL
158
+
159
+
160
+
@@ -0,0 +1,201 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2017-2018, plures
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ #include <stdlib.h>
35
+ #include <stdint.h>
36
+ #include <string.h>
37
+ #include <inttypes.h>
38
+ #include "ndtypes.h"
39
+ #include "xnd.h"
40
+ #include "gumath.h"
41
+
42
+
43
+ static int
44
+ sum_inner_dimensions(const xnd_t stack[], int nargs, int outer_dims)
45
+ {
46
+ int sum = 0, n;
47
+ int i;
48
+
49
+ for (i = 0; i < nargs; i++) {
50
+ const ndt_t *t = stack[i].type;
51
+ n = t->ndim - outer_dims;
52
+ sum += n == 0 ? 1 : n;
53
+ }
54
+
55
+ return sum;
56
+ }
57
+
58
+ int
59
+ gm_apply(const gm_kernel_t *kernel, xnd_t stack[], int outer_dims,
60
+ ndt_context_t *ctx)
61
+ {
62
+ const int nargs = (int)kernel->set->sig->Function.nargs;
63
+
64
+ switch (kernel->flag) {
65
+ case NDT_ELEMWISE_1D: {
66
+ if (outer_dims == 0) {
67
+ ndt_err_format(ctx, NDT_RuntimeError,
68
+ "gm_xnd_map: optimized elementwise kernel called with "
69
+ "outer_dims==0");
70
+ return -1;
71
+ }
72
+
73
+ return gm_xnd_map(kernel->set->Opt, stack, nargs, outer_dims-1, ctx);
74
+ }
75
+
76
+ case NDT_C: {
77
+ return gm_xnd_map(kernel->set->C, stack, nargs, outer_dims, ctx);
78
+ }
79
+
80
+ case NDT_FORTRAN: {
81
+ return gm_xnd_map(kernel->set->Fortran, stack, nargs, outer_dims, ctx);
82
+ }
83
+
84
+ case NDT_XND: {
85
+ return gm_xnd_map(kernel->set->Xnd, stack, nargs, outer_dims, ctx);
86
+ }
87
+
88
+ case NDT_STRIDED: {
89
+ const int sum_inner = sum_inner_dimensions(stack, nargs, outer_dims);
90
+ const int dims_size = outer_dims + sum_inner;
91
+ const int steps_size = nargs * outer_dims + sum_inner;
92
+ ALLOCA(char *, args, nargs);
93
+ ALLOCA(intptr_t, dimensions, dims_size);
94
+ ALLOCA(intptr_t, steps, steps_size);
95
+
96
+ if (gm_np_convert_xnd(args, nargs,
97
+ dimensions, dims_size,
98
+ steps, steps_size,
99
+ stack, outer_dims, ctx) < 0) {
100
+ return -1;
101
+ }
102
+
103
+ return gm_np_map(kernel->set->Strided, args, nargs,
104
+ dimensions, steps, NULL, outer_dims);
105
+ }
106
+ }
107
+
108
+ /* NOT REACHED: tags should be exhaustive. */
109
+ ndt_internal_error("invalid tag");
110
+ }
111
+
112
+ static gm_kernel_t
113
+ select_kernel(const ndt_apply_spec_t *spec, const gm_kernel_set_t *set,
114
+ ndt_context_t *ctx)
115
+ {
116
+ gm_kernel_t kernel = {0U, NULL};
117
+
118
+ kernel.set = set;
119
+
120
+ if (set->Opt != NULL && (spec->flags&NDT_ELEMWISE_1D)) {
121
+ kernel.flag = NDT_ELEMWISE_1D;
122
+ return kernel;
123
+ }
124
+
125
+ if (set->C != NULL && (spec->flags&NDT_C)) {
126
+ kernel.flag = NDT_C;
127
+ return kernel;
128
+ }
129
+
130
+ if (set->Fortran != NULL && (spec->flags&NDT_FORTRAN)) {
131
+ kernel.flag = NDT_FORTRAN;
132
+ return kernel;
133
+ }
134
+
135
+ if (set->Strided != NULL && (spec->flags&NDT_STRIDED)) {
136
+ kernel.flag = NDT_STRIDED;
137
+ return kernel;
138
+ }
139
+
140
+ if (set->Xnd != NULL && (spec->flags&NDT_XND)) {
141
+ kernel.flag = NDT_XND;
142
+ return kernel;
143
+ }
144
+
145
+ kernel.set = NULL;
146
+ ndt_err_format(ctx, NDT_RuntimeError,
147
+ "could not find specialized kernel for '%s' input (available: %s, %s, %s, %s)",
148
+ ndt_apply_flags_as_string(spec),
149
+ set->C ? "C" : "_",
150
+ set->Fortran ? "Fortran" : "_",
151
+ set->Xnd ? "Xnd" : "_",
152
+ set->Strided ? "Strided" : "_");
153
+
154
+ return kernel;
155
+ }
156
+
157
+ /* Look up a multimethod by name and select a kernel. */
158
+ gm_kernel_t
159
+ gm_select(ndt_apply_spec_t *spec, const gm_tbl_t *tbl, const char *name,
160
+ const ndt_t *in_types[], int nin, const xnd_t args[],
161
+ ndt_context_t *ctx)
162
+ {
163
+ gm_kernel_t empty_kernel = {0U, NULL};
164
+ const gm_func_t *f;
165
+ char *s;
166
+ int i;
167
+
168
+ f = gm_tbl_find(tbl, name, ctx);
169
+ if (f == NULL) {
170
+ return empty_kernel;
171
+ }
172
+
173
+ if (f->typecheck != NULL) {
174
+ const gm_kernel_set_t *set = f->typecheck(spec, f, in_types, nin, ctx);
175
+ if (set == NULL) {
176
+ return empty_kernel;
177
+ }
178
+ return select_kernel(spec, set, ctx);
179
+ }
180
+
181
+ for (i = 0; i < f->nkernels; i++) {
182
+ const gm_kernel_set_t *set = &f->kernels[i];
183
+ if (ndt_typecheck(spec, set->sig, in_types, nin, set->constraint, args,
184
+ ctx) < 0) {
185
+ ndt_err_clear(ctx);
186
+ continue;
187
+ }
188
+ return select_kernel(spec, set, ctx);
189
+ }
190
+
191
+ s = ndt_list_as_string(in_types, nin, ctx);
192
+ if (s == NULL) {
193
+ return empty_kernel;
194
+ }
195
+
196
+ ndt_err_format(ctx, NDT_TypeError,
197
+ "could not find '%s' kernel for input types '%s'", name, s);
198
+ ndt_free(s);
199
+
200
+ return empty_kernel;
201
+ }