numo-narray 0.9.0.1-x86-mingw32
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.
- checksums.yaml +7 -0
 - data/Gemfile +4 -0
 - data/README.md +47 -0
 - data/Rakefile +41 -0
 - data/ext/numo/narray/SFMT-params.h +97 -0
 - data/ext/numo/narray/SFMT-params19937.h +46 -0
 - data/ext/numo/narray/SFMT.c +620 -0
 - data/ext/numo/narray/SFMT.h +157 -0
 - data/ext/numo/narray/array.c +525 -0
 - data/ext/numo/narray/data.c +901 -0
 - data/ext/numo/narray/depend.erb +33 -0
 - data/ext/numo/narray/extconf.rb +117 -0
 - data/ext/numo/narray/gen/bit.erb.c +811 -0
 - data/ext/numo/narray/gen/cogen.rb +18 -0
 - data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
 - data/ext/numo/narray/gen/def/dfloat.rb +30 -0
 - data/ext/numo/narray/gen/def/int16.rb +29 -0
 - data/ext/numo/narray/gen/def/int32.rb +29 -0
 - data/ext/numo/narray/gen/def/int64.rb +29 -0
 - data/ext/numo/narray/gen/def/int8.rb +29 -0
 - data/ext/numo/narray/gen/def/robject.rb +30 -0
 - data/ext/numo/narray/gen/def/scomplex.rb +32 -0
 - data/ext/numo/narray/gen/def/sfloat.rb +30 -0
 - data/ext/numo/narray/gen/def/uint16.rb +29 -0
 - data/ext/numo/narray/gen/def/uint32.rb +29 -0
 - data/ext/numo/narray/gen/def/uint64.rb +29 -0
 - data/ext/numo/narray/gen/def/uint8.rb +29 -0
 - data/ext/numo/narray/gen/dtype.erb.c +328 -0
 - data/ext/numo/narray/gen/tmpl/accum.c +36 -0
 - data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
 - data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
 - data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
 - data/ext/numo/narray/gen/tmpl/aref.c +51 -0
 - data/ext/numo/narray/gen/tmpl/aset.c +61 -0
 - data/ext/numo/narray/gen/tmpl/binary.c +53 -0
 - data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
 - data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
 - data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
 - data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
 - data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
 - data/ext/numo/narray/gen/tmpl/cast.c +37 -0
 - data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
 - data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
 - data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
 - data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
 - data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
 - data/ext/numo/narray/gen/tmpl/cum.c +42 -0
 - data/ext/numo/narray/gen/tmpl/each.c +43 -0
 - data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
 - data/ext/numo/narray/gen/tmpl/extract.c +23 -0
 - data/ext/numo/narray/gen/tmpl/eye.c +91 -0
 - data/ext/numo/narray/gen/tmpl/fill.c +38 -0
 - data/ext/numo/narray/gen/tmpl/format.c +60 -0
 - data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
 - data/ext/numo/narray/gen/tmpl/head.c +25 -0
 - data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
 - data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
 - data/ext/numo/narray/gen/tmpl/median.c +44 -0
 - data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
 - data/ext/numo/narray/gen/tmpl/poly.c +49 -0
 - data/ext/numo/narray/gen/tmpl/pow.c +74 -0
 - data/ext/numo/narray/gen/tmpl/powint.c +17 -0
 - data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
 - data/ext/numo/narray/gen/tmpl/rand.c +33 -0
 - data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
 - data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
 - data/ext/numo/narray/gen/tmpl/seq.c +61 -0
 - data/ext/numo/narray/gen/tmpl/set2.c +56 -0
 - data/ext/numo/narray/gen/tmpl/sort.c +36 -0
 - data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
 - data/ext/numo/narray/gen/tmpl/store.c +31 -0
 - data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
 - data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
 - data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
 - data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
 - data/ext/numo/narray/gen/tmpl/unary.c +58 -0
 - data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
 - data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
 - data/ext/numo/narray/index.c +822 -0
 - data/ext/numo/narray/kwarg.c +79 -0
 - data/ext/numo/narray/math.c +140 -0
 - data/ext/numo/narray/narray.c +1539 -0
 - data/ext/numo/narray/ndloop.c +1928 -0
 - data/ext/numo/narray/numo/compat.h +23 -0
 - data/ext/numo/narray/numo/intern.h +112 -0
 - data/ext/numo/narray/numo/narray.h +411 -0
 - data/ext/numo/narray/numo/ndloop.h +99 -0
 - data/ext/numo/narray/numo/template.h +140 -0
 - data/ext/numo/narray/numo/types/bit.h +19 -0
 - data/ext/numo/narray/numo/types/complex.h +410 -0
 - data/ext/numo/narray/numo/types/complex_macro.h +205 -0
 - data/ext/numo/narray/numo/types/dcomplex.h +11 -0
 - data/ext/numo/narray/numo/types/dfloat.h +12 -0
 - data/ext/numo/narray/numo/types/float_def.h +34 -0
 - data/ext/numo/narray/numo/types/float_macro.h +277 -0
 - data/ext/numo/narray/numo/types/int16.h +12 -0
 - data/ext/numo/narray/numo/types/int32.h +12 -0
 - data/ext/numo/narray/numo/types/int64.h +12 -0
 - data/ext/numo/narray/numo/types/int8.h +12 -0
 - data/ext/numo/narray/numo/types/int_macro.h +34 -0
 - data/ext/numo/narray/numo/types/robj_macro.h +218 -0
 - data/ext/numo/narray/numo/types/robject.h +21 -0
 - data/ext/numo/narray/numo/types/scomplex.h +11 -0
 - data/ext/numo/narray/numo/types/sfloat.h +13 -0
 - data/ext/numo/narray/numo/types/uint16.h +12 -0
 - data/ext/numo/narray/numo/types/uint32.h +12 -0
 - data/ext/numo/narray/numo/types/uint64.h +12 -0
 - data/ext/numo/narray/numo/types/uint8.h +12 -0
 - data/ext/numo/narray/numo/types/uint_macro.h +31 -0
 - data/ext/numo/narray/numo/types/xint_macro.h +133 -0
 - data/ext/numo/narray/rand.c +87 -0
 - data/ext/numo/narray/step.c +506 -0
 - data/ext/numo/narray/struct.c +872 -0
 - data/lib/2.1/numo/narray.so +0 -0
 - data/lib/2.2/numo/narray.so +0 -0
 - data/lib/2.3/numo/narray.so +0 -0
 - data/lib/erbpp/line_number.rb +126 -0
 - data/lib/erbpp/narray_def.rb +338 -0
 - data/lib/erbpp.rb +286 -0
 - data/lib/numo/narray.rb +6 -0
 - data/numo-narray.gemspec +35 -0
 - data/spec/bit_spec.rb +93 -0
 - data/spec/narray_spec.rb +249 -0
 - metadata +238 -0
 
| 
         @@ -0,0 +1,149 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /*
         
     | 
| 
      
 2 
     | 
    
         
            +
              qsort.c
         
     | 
| 
      
 3 
     | 
    
         
            +
              Numerical Array Extension for Ruby
         
     | 
| 
      
 4 
     | 
    
         
            +
                (C) Copyright 2007-2011 by Masahiro TANAKA
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              This program is free software.
         
     | 
| 
      
 7 
     | 
    
         
            +
              You can distribute/modify this program
         
     | 
| 
      
 8 
     | 
    
         
            +
              under the same terms as Ruby itself.
         
     | 
| 
      
 9 
     | 
    
         
            +
              NO WARRANTY.
         
     | 
| 
      
 10 
     | 
    
         
            +
            */
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            /*
         
     | 
| 
      
 13 
     | 
    
         
            +
             *      qsort.c: standard quicksort algorithm
         
     | 
| 
      
 14 
     | 
    
         
            +
             *
         
     | 
| 
      
 15 
     | 
    
         
            +
             *      Modifications from vanilla NetBSD source:
         
     | 
| 
      
 16 
     | 
    
         
            +
             *        Add do ... while() macro fix
         
     | 
| 
      
 17 
     | 
    
         
            +
             *        Remove __inline, _DIAGASSERTs, __P
         
     | 
| 
      
 18 
     | 
    
         
            +
             *        Remove ill-considered "swap_cnt" switch to insertion sort,
         
     | 
| 
      
 19 
     | 
    
         
            +
             *        in favor of a simple check for presorted input.
         
     | 
| 
      
 20 
     | 
    
         
            +
             *
         
     | 
| 
      
 21 
     | 
    
         
            +
             *      CAUTION: if you change this file, see also qsort_arg.c
         
     | 
| 
      
 22 
     | 
    
         
            +
             *
         
     | 
| 
      
 23 
     | 
    
         
            +
             *      $PostgreSQL: pgsql/src/port/qsort.c,v 1.12 2006/10/19 20:56:22 tgl Exp $
         
     | 
| 
      
 24 
     | 
    
         
            +
             */
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            /*      $NetBSD: qsort.c,v 1.13 2003/08/07 16:43:42 agc Exp $   */
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            /*-
         
     | 
| 
      
 29 
     | 
    
         
            +
             * Copyright (c) 1992, 1993
         
     | 
| 
      
 30 
     | 
    
         
            +
             *      The Regents of the University of California.  All rights reserved.
         
     | 
| 
      
 31 
     | 
    
         
            +
             *
         
     | 
| 
      
 32 
     | 
    
         
            +
             * Redistribution and use in source and binary forms, with or without
         
     | 
| 
      
 33 
     | 
    
         
            +
             * modification, are permitted provided that the following conditions
         
     | 
| 
      
 34 
     | 
    
         
            +
             * are met:
         
     | 
| 
      
 35 
     | 
    
         
            +
             * 1. Redistributions of source code must retain the above copyright
         
     | 
| 
      
 36 
     | 
    
         
            +
             *        notice, this list of conditions and the following disclaimer.
         
     | 
| 
      
 37 
     | 
    
         
            +
             * 2. Redistributions in binary form must reproduce the above copyright
         
     | 
| 
      
 38 
     | 
    
         
            +
             *        notice, this list of conditions and the following disclaimer in the
         
     | 
| 
      
 39 
     | 
    
         
            +
             *        documentation and/or other materials provided with the distribution.
         
     | 
| 
      
 40 
     | 
    
         
            +
             * 3. Neither the name of the University nor the names of its contributors
         
     | 
| 
      
 41 
     | 
    
         
            +
             *        may be used to endorse or promote products derived from this software
         
     | 
| 
      
 42 
     | 
    
         
            +
             *        without specific prior written permission.
         
     | 
| 
      
 43 
     | 
    
         
            +
             *
         
     | 
| 
      
 44 
     | 
    
         
            +
             * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
         
     | 
| 
      
 45 
     | 
    
         
            +
             * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
         
     | 
| 
      
 46 
     | 
    
         
            +
             * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
         
     | 
| 
      
 47 
     | 
    
         
            +
             * ARE DISCLAIMED.      IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
         
     | 
| 
      
 48 
     | 
    
         
            +
             * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
         
     | 
| 
      
 49 
     | 
    
         
            +
             * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
         
     | 
| 
      
 50 
     | 
    
         
            +
             * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
         
     | 
| 
      
 51 
     | 
    
         
            +
             * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
         
     | 
| 
      
 52 
     | 
    
         
            +
             * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
         
     | 
| 
      
 53 
     | 
    
         
            +
             * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
         
     | 
| 
      
 54 
     | 
    
         
            +
             * SUCH DAMAGE.
         
     | 
| 
      
 55 
     | 
    
         
            +
             */
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            #ifndef QSORT_INCL
         
     | 
| 
      
 58 
     | 
    
         
            +
            #define QSORT_INCL
         
     | 
| 
      
 59 
     | 
    
         
            +
            #define Min(x, y)               ((x) < (y) ? (x) : (y))
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            #define swap(type,a,b) \
         
     | 
| 
      
 62 
     | 
    
         
            +
                do {type tmp=*(type*)(a); *(type*)(a)=*(type*)(b); *(type*)(b)=tmp;} while(0)
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            #define vecswap(type, a, b, n) if ((n)>0) swap(type,(a),(b))
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            #define MED3(a,b,c)                                     \
         
     | 
| 
      
 67 
     | 
    
         
            +
                (cmpgt(b,a) ?                                       \
         
     | 
| 
      
 68 
     | 
    
         
            +
                 (cmpgt(c,b) ? b : (cmpgt(c,a) ? c : a))            \
         
     | 
| 
      
 69 
     | 
    
         
            +
                 : (cmpgt(b,c) ? b : (cmpgt(c,a) ? a : c)))
         
     | 
| 
      
 70 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            #undef qsort_dtype
         
     | 
| 
      
 73 
     | 
    
         
            +
            #define qsort_dtype <%=dtype%>
         
     | 
| 
      
 74 
     | 
    
         
            +
            #undef qsort_cast
         
     | 
| 
      
 75 
     | 
    
         
            +
            #define qsort_cast <%=dcast%>
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            void
         
     | 
| 
      
 78 
     | 
    
         
            +
            <%=tp%>_qsort(void *a, size_t n, ssize_t es)
         
     | 
| 
      
 79 
     | 
    
         
            +
            {
         
     | 
| 
      
 80 
     | 
    
         
            +
                char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
         
     | 
| 
      
 81 
     | 
    
         
            +
                int  d, r, presorted;
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
             loop:
         
     | 
| 
      
 84 
     | 
    
         
            +
                if (n < 7) {
         
     | 
| 
      
 85 
     | 
    
         
            +
                    for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es)
         
     | 
| 
      
 86 
     | 
    
         
            +
                        for (pl = pm; pl > (char *) a && cmpgt(pl - es, pl);
         
     | 
| 
      
 87 
     | 
    
         
            +
                             pl -= es)
         
     | 
| 
      
 88 
     | 
    
         
            +
                            swap(qsort_dtype, pl, pl - es);
         
     | 
| 
      
 89 
     | 
    
         
            +
                    return;
         
     | 
| 
      
 90 
     | 
    
         
            +
                }
         
     | 
| 
      
 91 
     | 
    
         
            +
                presorted = 1;
         
     | 
| 
      
 92 
     | 
    
         
            +
                for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) {
         
     | 
| 
      
 93 
     | 
    
         
            +
                    if (cmpgt(pm - es, pm)) {
         
     | 
| 
      
 94 
     | 
    
         
            +
                        presorted = 0;
         
     | 
| 
      
 95 
     | 
    
         
            +
                        break;
         
     | 
| 
      
 96 
     | 
    
         
            +
                    }
         
     | 
| 
      
 97 
     | 
    
         
            +
                }
         
     | 
| 
      
 98 
     | 
    
         
            +
                if (presorted)
         
     | 
| 
      
 99 
     | 
    
         
            +
                    return;
         
     | 
| 
      
 100 
     | 
    
         
            +
                pm = (char *) a + (n / 2) * es;
         
     | 
| 
      
 101 
     | 
    
         
            +
                if (n > 7) {
         
     | 
| 
      
 102 
     | 
    
         
            +
                    pl = (char *) a;
         
     | 
| 
      
 103 
     | 
    
         
            +
                    pn = (char *) a + (n - 1) * es;
         
     | 
| 
      
 104 
     | 
    
         
            +
                    if (n > 40) {
         
     | 
| 
      
 105 
     | 
    
         
            +
                        d = (n / 8) * es;
         
     | 
| 
      
 106 
     | 
    
         
            +
                        pl = MED3(pl, pl + d, pl + 2 * d);
         
     | 
| 
      
 107 
     | 
    
         
            +
                        pm = MED3(pm - d, pm, pm + d);
         
     | 
| 
      
 108 
     | 
    
         
            +
                        pn = MED3(pn - 2 * d, pn - d, pn);
         
     | 
| 
      
 109 
     | 
    
         
            +
                    }
         
     | 
| 
      
 110 
     | 
    
         
            +
                    pm = MED3(pl, pm, pn);
         
     | 
| 
      
 111 
     | 
    
         
            +
                }
         
     | 
| 
      
 112 
     | 
    
         
            +
                swap(qsort_dtype, a, pm);
         
     | 
| 
      
 113 
     | 
    
         
            +
                pa = pb = (char *) a + es;
         
     | 
| 
      
 114 
     | 
    
         
            +
                pc = pd = (char *) a + (n - 1) * es;
         
     | 
| 
      
 115 
     | 
    
         
            +
                for (;;) {
         
     | 
| 
      
 116 
     | 
    
         
            +
                    while (pb <= pc && (r = cmp(pb, a)) <= 0) {
         
     | 
| 
      
 117 
     | 
    
         
            +
                        if (r == 0) {
         
     | 
| 
      
 118 
     | 
    
         
            +
                            swap(qsort_dtype, pa, pb);
         
     | 
| 
      
 119 
     | 
    
         
            +
                            pa += es;
         
     | 
| 
      
 120 
     | 
    
         
            +
                        }
         
     | 
| 
      
 121 
     | 
    
         
            +
                        pb += es;
         
     | 
| 
      
 122 
     | 
    
         
            +
                    }
         
     | 
| 
      
 123 
     | 
    
         
            +
                    while (pb <= pc && (r = cmp(pc, a)) >= 0) {
         
     | 
| 
      
 124 
     | 
    
         
            +
                        if (r == 0) {
         
     | 
| 
      
 125 
     | 
    
         
            +
                            swap(qsort_dtype, pc, pd);
         
     | 
| 
      
 126 
     | 
    
         
            +
                            pd -= es;
         
     | 
| 
      
 127 
     | 
    
         
            +
                        }
         
     | 
| 
      
 128 
     | 
    
         
            +
                        pc -= es;
         
     | 
| 
      
 129 
     | 
    
         
            +
                    }
         
     | 
| 
      
 130 
     | 
    
         
            +
                    if (pb > pc)
         
     | 
| 
      
 131 
     | 
    
         
            +
                        break;
         
     | 
| 
      
 132 
     | 
    
         
            +
                    swap(qsort_dtype, pb, pc);
         
     | 
| 
      
 133 
     | 
    
         
            +
                    pb += es;
         
     | 
| 
      
 134 
     | 
    
         
            +
                    pc -= es;
         
     | 
| 
      
 135 
     | 
    
         
            +
                }
         
     | 
| 
      
 136 
     | 
    
         
            +
                pn = (char *) a + n * es;
         
     | 
| 
      
 137 
     | 
    
         
            +
                r = Min(pa - (char *) a, pb - pa);
         
     | 
| 
      
 138 
     | 
    
         
            +
                vecswap(qsort_dtype, a, pb - r, r);
         
     | 
| 
      
 139 
     | 
    
         
            +
                r = Min(pd - pc, pn - pd - es);
         
     | 
| 
      
 140 
     | 
    
         
            +
                vecswap(qsort_dtype, pb, pn - r, r);
         
     | 
| 
      
 141 
     | 
    
         
            +
                if ((r = pb - pa) > es)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    <%=tp%>_qsort(a, r / es, es);
         
     | 
| 
      
 143 
     | 
    
         
            +
                if ((r = pd - pc) > es) {
         
     | 
| 
      
 144 
     | 
    
         
            +
                    a = pn - r;
         
     | 
| 
      
 145 
     | 
    
         
            +
                    n = r / es;
         
     | 
| 
      
 146 
     | 
    
         
            +
                    goto loop;
         
     | 
| 
      
 147 
     | 
    
         
            +
                }
         
     | 
| 
      
 148 
     | 
    
         
            +
            }
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t   i;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char    *p1;
         
     | 
| 
      
 6 
     | 
    
         
            +
                ssize_t  s1;
         
     | 
| 
      
 7 
     | 
    
         
            +
                size_t  *idx1;
         
     | 
| 
      
 8 
     | 
    
         
            +
                dtype    x;
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                INIT_COUNTER(lp, i);
         
     | 
| 
      
 11 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 0, p1, s1, idx1);
         
     | 
| 
      
 12 
     | 
    
         
            +
                if (idx1) {
         
     | 
| 
      
 13 
     | 
    
         
            +
                    for (; i--;) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                        x = m_rand;
         
     | 
| 
      
 15 
     | 
    
         
            +
                        SET_DATA_INDEX(p1,idx1,dtype,x);
         
     | 
| 
      
 16 
     | 
    
         
            +
                    }
         
     | 
| 
      
 17 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 18 
     | 
    
         
            +
                    for (; i--;) {
         
     | 
| 
      
 19 
     | 
    
         
            +
                        x = m_rand;
         
     | 
| 
      
 20 
     | 
    
         
            +
                        SET_DATA_STRIDE(p1,s1,dtype,x);
         
     | 
| 
      
 21 
     | 
    
         
            +
                    }
         
     | 
| 
      
 22 
     | 
    
         
            +
                }
         
     | 
| 
      
 23 
     | 
    
         
            +
            }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 26 
     | 
    
         
            +
            <%=c_func%>(VALUE self)
         
     | 
| 
      
 27 
     | 
    
         
            +
            {
         
     | 
| 
      
 28 
     | 
    
         
            +
                ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
         
     | 
| 
      
 29 
     | 
    
         
            +
                ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                na_ndloop(&ndf, 1, self);
         
     | 
| 
      
 32 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 33 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t   i;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char    *p1;
         
     | 
| 
      
 6 
     | 
    
         
            +
                ssize_t  s1;
         
     | 
| 
      
 7 
     | 
    
         
            +
                size_t  *idx1;
         
     | 
| 
      
 8 
     | 
    
         
            +
                dtype    y;
         
     | 
| 
      
 9 
     | 
    
         
            +
                dtype    a[2];
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                INIT_COUNTER(lp, i);
         
     | 
| 
      
 12 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 0, p1, s1, idx1);
         
     | 
| 
      
 13 
     | 
    
         
            +
                if (idx1) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                    for (; i>1; i-=2) {
         
     | 
| 
      
 15 
     | 
    
         
            +
                        m_rand_norm(a);
         
     | 
| 
      
 16 
     | 
    
         
            +
                        *(dtype*)(p1+*idx1)     = a[0];
         
     | 
| 
      
 17 
     | 
    
         
            +
                        *(dtype*)(p1+*(idx1+1)) = a[1];
         
     | 
| 
      
 18 
     | 
    
         
            +
                        idx1 += 2;
         
     | 
| 
      
 19 
     | 
    
         
            +
                    }
         
     | 
| 
      
 20 
     | 
    
         
            +
                    if (i>0) {
         
     | 
| 
      
 21 
     | 
    
         
            +
                        m_rand_norm(a);
         
     | 
| 
      
 22 
     | 
    
         
            +
                        *(dtype*)(p1+*idx1) = a[0];
         
     | 
| 
      
 23 
     | 
    
         
            +
                    }
         
     | 
| 
      
 24 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 25 
     | 
    
         
            +
                    for (; i>1; i-=2) {
         
     | 
| 
      
 26 
     | 
    
         
            +
                        m_rand_norm(a);
         
     | 
| 
      
 27 
     | 
    
         
            +
                        *(dtype*)(p1)    = a[0];
         
     | 
| 
      
 28 
     | 
    
         
            +
                        *(dtype*)(p1+s1) = a[1];
         
     | 
| 
      
 29 
     | 
    
         
            +
                        p1 += s1*2;
         
     | 
| 
      
 30 
     | 
    
         
            +
                    }
         
     | 
| 
      
 31 
     | 
    
         
            +
                    if (i>0) {
         
     | 
| 
      
 32 
     | 
    
         
            +
                        m_rand_norm(a);
         
     | 
| 
      
 33 
     | 
    
         
            +
                        *(dtype*)(p1) = a[0];
         
     | 
| 
      
 34 
     | 
    
         
            +
                    }
         
     | 
| 
      
 35 
     | 
    
         
            +
                }
         
     | 
| 
      
 36 
     | 
    
         
            +
            }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 39 
     | 
    
         
            +
            <%=c_func%>(VALUE self)
         
     | 
| 
      
 40 
     | 
    
         
            +
            {
         
     | 
| 
      
 41 
     | 
    
         
            +
                ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
         
     | 
| 
      
 42 
     | 
    
         
            +
                ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                na_ndloop(&ndf, 1, self);
         
     | 
| 
      
 45 
     | 
    
         
            +
                return self
         
     | 
| 
      
 46 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            na_gc_mark_robj(narray_data_t* na)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t n, i;
         
     | 
| 
      
 5 
     | 
    
         
            +
                VALUE *a;
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                if (na->ptr) {
         
     | 
| 
      
 8 
     | 
    
         
            +
                    a = (VALUE*)(na->ptr);
         
     | 
| 
      
 9 
     | 
    
         
            +
                    n = na->base.size;
         
     | 
| 
      
 10 
     | 
    
         
            +
                    for (i=0; i<n; i++) {
         
     | 
| 
      
 11 
     | 
    
         
            +
                        rb_gc_mark(a[i]);
         
     | 
| 
      
 12 
     | 
    
         
            +
                    }
         
     | 
| 
      
 13 
     | 
    
         
            +
                }
         
     | 
| 
      
 14 
     | 
    
         
            +
            }
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            void na_free(narray_data_t* na);
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            VALUE
         
     | 
| 
      
 19 
     | 
    
         
            +
            <%=c_func%>(VALUE klass)
         
     | 
| 
      
 20 
     | 
    
         
            +
            {
         
     | 
| 
      
 21 
     | 
    
         
            +
                narray_data_t *na = ALLOC(narray_data_t);
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                na->base.ndim = 0;
         
     | 
| 
      
 24 
     | 
    
         
            +
                na->base.type = NARRAY_DATA_T;
         
     | 
| 
      
 25 
     | 
    
         
            +
                na->base.flag[0] = 0;
         
     | 
| 
      
 26 
     | 
    
         
            +
                na->base.flag[1] = 0;
         
     | 
| 
      
 27 
     | 
    
         
            +
                na->base.size = 0;
         
     | 
| 
      
 28 
     | 
    
         
            +
                na->base.shape = NULL;
         
     | 
| 
      
 29 
     | 
    
         
            +
                na->base.reduce = INT2FIX(0);
         
     | 
| 
      
 30 
     | 
    
         
            +
                na->ptr = NULL;
         
     | 
| 
      
 31 
     | 
    
         
            +
                return Data_Wrap_Struct(klass, na_gc_mark_robj, na_free, na);
         
     | 
| 
      
 32 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t  i;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char   *p1;
         
     | 
| 
      
 6 
     | 
    
         
            +
                ssize_t s1;
         
     | 
| 
      
 7 
     | 
    
         
            +
                size_t *idx1;
         
     | 
| 
      
 8 
     | 
    
         
            +
                double  x, beg, step, c;
         
     | 
| 
      
 9 
     | 
    
         
            +
                dtype   y;
         
     | 
| 
      
 10 
     | 
    
         
            +
                seq_opt_t *g;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                INIT_COUNTER(lp, i);
         
     | 
| 
      
 13 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 0, p1, s1, idx1);
         
     | 
| 
      
 14 
     | 
    
         
            +
                g = (seq_opt_t*)(lp->opt_ptr);
         
     | 
| 
      
 15 
     | 
    
         
            +
                beg  = g->beg;
         
     | 
| 
      
 16 
     | 
    
         
            +
                step = g->step;
         
     | 
| 
      
 17 
     | 
    
         
            +
                c    = g->count;
         
     | 
| 
      
 18 
     | 
    
         
            +
                if (idx1) {
         
     | 
| 
      
 19 
     | 
    
         
            +
                    for (; i--;) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                        x = beg + step * c++;
         
     | 
| 
      
 21 
     | 
    
         
            +
                        y = m_from_double(x);
         
     | 
| 
      
 22 
     | 
    
         
            +
                        *(dtype*)(p1+*idx1) = y;
         
     | 
| 
      
 23 
     | 
    
         
            +
                        idx1++;
         
     | 
| 
      
 24 
     | 
    
         
            +
                    }
         
     | 
| 
      
 25 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 26 
     | 
    
         
            +
                    for (; i--;) {
         
     | 
| 
      
 27 
     | 
    
         
            +
                        x = beg + step * c++;
         
     | 
| 
      
 28 
     | 
    
         
            +
                        y = m_from_double(x);
         
     | 
| 
      
 29 
     | 
    
         
            +
                        *(dtype*)(p1) = y;
         
     | 
| 
      
 30 
     | 
    
         
            +
                        p1 += s1;
         
     | 
| 
      
 31 
     | 
    
         
            +
                    }
         
     | 
| 
      
 32 
     | 
    
         
            +
                }
         
     | 
| 
      
 33 
     | 
    
         
            +
                g->count = c;
         
     | 
| 
      
 34 
     | 
    
         
            +
            }
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            /*
         
     | 
| 
      
 37 
     | 
    
         
            +
              Set Sequence of numbers to self NArray.
         
     | 
| 
      
 38 
     | 
    
         
            +
              @overload seq([beg,[step]])
         
     | 
| 
      
 39 
     | 
    
         
            +
              @param [Numeric] beg  begining of sequence. (default=0)
         
     | 
| 
      
 40 
     | 
    
         
            +
              @param [Numeric] step  step of sequence. (default=1)
         
     | 
| 
      
 41 
     | 
    
         
            +
              @return [Numo::<%=class_name%>] self.
         
     | 
| 
      
 42 
     | 
    
         
            +
            */
         
     | 
| 
      
 43 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 44 
     | 
    
         
            +
            <%=c_func%>(int argc, VALUE *args, VALUE self)
         
     | 
| 
      
 45 
     | 
    
         
            +
            {
         
     | 
| 
      
 46 
     | 
    
         
            +
                seq_opt_t *g;
         
     | 
| 
      
 47 
     | 
    
         
            +
                VALUE vbeg=Qnil, vstep=Qnil;
         
     | 
| 
      
 48 
     | 
    
         
            +
                ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
         
     | 
| 
      
 49 
     | 
    
         
            +
                ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                g = ALLOCA_N(seq_opt_t,1);
         
     | 
| 
      
 52 
     | 
    
         
            +
                g->beg = 0;
         
     | 
| 
      
 53 
     | 
    
         
            +
                g->step = 1;
         
     | 
| 
      
 54 
     | 
    
         
            +
                g->count = 0;
         
     | 
| 
      
 55 
     | 
    
         
            +
                rb_scan_args(argc, args, "02", &vbeg, &vstep);
         
     | 
| 
      
 56 
     | 
    
         
            +
                if (vbeg!=Qnil) {g->beg = NUM2DBL(vbeg);}
         
     | 
| 
      
 57 
     | 
    
         
            +
                if (vstep!=Qnil) {g->step = NUM2DBL(vstep);}
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                na_ndloop3(&ndf, g, 1, self);
         
     | 
| 
      
 60 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 61 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t  i;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char   *p1, *p2;
         
     | 
| 
      
 6 
     | 
    
         
            +
                ssize_t s1, s2;
         
     | 
| 
      
 7 
     | 
    
         
            +
                size_t *idx1, *idx2;
         
     | 
| 
      
 8 
     | 
    
         
            +
                dtype   x;
         
     | 
| 
      
 9 
     | 
    
         
            +
                <%=dtype%> y;
         
     | 
| 
      
 10 
     | 
    
         
            +
                INIT_COUNTER(lp, i);
         
     | 
| 
      
 11 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 0, p1, s1, idx1);
         
     | 
| 
      
 12 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 1, p2, s2, idx2);
         
     | 
| 
      
 13 
     | 
    
         
            +
                if (idx1) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                    if (idx2) {
         
     | 
| 
      
 15 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 16 
     | 
    
         
            +
                            GET_DATA_INDEX(p1,idx1,dtype,x);
         
     | 
| 
      
 17 
     | 
    
         
            +
                            GET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
         
     | 
| 
      
 18 
     | 
    
         
            +
                            x = m_<%=method%>(x,y);
         
     | 
| 
      
 19 
     | 
    
         
            +
                            SET_DATA_INDEX(p1,idx1,dtype,x);
         
     | 
| 
      
 20 
     | 
    
         
            +
                        }
         
     | 
| 
      
 21 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 22 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 23 
     | 
    
         
            +
                            GET_DATA_INDEX(p1,idx1,dtype,x);
         
     | 
| 
      
 24 
     | 
    
         
            +
                            GET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
         
     | 
| 
      
 25 
     | 
    
         
            +
                            x = m_<%=method%>(x,y);
         
     | 
| 
      
 26 
     | 
    
         
            +
                            SET_DATA_INDEX(p1,idx1,dtype,x);
         
     | 
| 
      
 27 
     | 
    
         
            +
                        }
         
     | 
| 
      
 28 
     | 
    
         
            +
                    }
         
     | 
| 
      
 29 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    if (idx2) {
         
     | 
| 
      
 31 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 32 
     | 
    
         
            +
                            GET_DATA(p1,dtype,x);
         
     | 
| 
      
 33 
     | 
    
         
            +
                            GET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
         
     | 
| 
      
 34 
     | 
    
         
            +
                            x = m_<%=method%>(x,y);
         
     | 
| 
      
 35 
     | 
    
         
            +
                            SET_DATA_STRIDE(p1,s1,dtype,x);
         
     | 
| 
      
 36 
     | 
    
         
            +
                        }
         
     | 
| 
      
 37 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 38 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 39 
     | 
    
         
            +
                            GET_DATA(p1,dtype,x);
         
     | 
| 
      
 40 
     | 
    
         
            +
                            GET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
         
     | 
| 
      
 41 
     | 
    
         
            +
                            x = m_<%=method%>(x,y);
         
     | 
| 
      
 42 
     | 
    
         
            +
                            SET_DATA_STRIDE(p1,s1,dtype,x);
         
     | 
| 
      
 43 
     | 
    
         
            +
                        }
         
     | 
| 
      
 44 
     | 
    
         
            +
                    }
         
     | 
| 
      
 45 
     | 
    
         
            +
                }
         
     | 
| 
      
 46 
     | 
    
         
            +
            }
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 49 
     | 
    
         
            +
            <%=c_func%>(VALUE self, VALUE a1)
         
     | 
| 
      
 50 
     | 
    
         
            +
            {
         
     | 
| 
      
 51 
     | 
    
         
            +
                ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{<%=tpclass%>,0}};
         
     | 
| 
      
 52 
     | 
    
         
            +
                ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                na_ndloop(&ndf, 2, self, a1);
         
     | 
| 
      
 55 
     | 
    
         
            +
                return a1;
         
     | 
| 
      
 56 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,36 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t n;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char *ptr;
         
     | 
| 
      
 6 
     | 
    
         
            +
                ssize_t step;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                INIT_COUNTER(lp, n);
         
     | 
| 
      
 9 
     | 
    
         
            +
                INIT_PTR(lp, 0, ptr, step);
         
     | 
| 
      
 10 
     | 
    
         
            +
                <%=tp%>_qsort(ptr, n, step);
         
     | 
| 
      
 11 
     | 
    
         
            +
            }
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            /*
         
     | 
| 
      
 14 
     | 
    
         
            +
             *  call-seq:
         
     | 
| 
      
 15 
     | 
    
         
            +
             *     narray.sort() => narray
         
     | 
| 
      
 16 
     | 
    
         
            +
             *     narray.sort(dim0,dim1,...) => narray
         
     | 
| 
      
 17 
     | 
    
         
            +
             *
         
     | 
| 
      
 18 
     | 
    
         
            +
             *  Return an index array of sort result.
         
     | 
| 
      
 19 
     | 
    
         
            +
             *
         
     | 
| 
      
 20 
     | 
    
         
            +
             *     Numo::DFloat[3,4,1,2].sort => Numo::DFloat[1,2,3,4]
         
     | 
| 
      
 21 
     | 
    
         
            +
             */
         
     | 
| 
      
 22 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 23 
     | 
    
         
            +
            <%=c_func%>(int argc, VALUE *argv, VALUE self)
         
     | 
| 
      
 24 
     | 
    
         
            +
            {
         
     | 
| 
      
 25 
     | 
    
         
            +
                VALUE reduce;
         
     | 
| 
      
 26 
     | 
    
         
            +
                ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_reduce,0}};
         
     | 
| 
      
 27 
     | 
    
         
            +
                ndfunc_t ndf = {<%=c_iter%>, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE, 2,0, ain,0};
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                if (!TEST_INPLACE(self)) {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    self = na_copy(self);
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
      
 32 
     | 
    
         
            +
                reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                na_ndloop(&ndf, 2, self, reduce);
         
     | 
| 
      
 35 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 36 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,86 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            <% [64,32].each do |i| %>
         
     | 
| 
      
 3 
     | 
    
         
            +
            #define idx_t int<%=i%>_t
         
     | 
| 
      
 4 
     | 
    
         
            +
            static void
         
     | 
| 
      
 5 
     | 
    
         
            +
            <%=tp%>_index<%=i%>_qsort(na_loop_t *const lp)
         
     | 
| 
      
 6 
     | 
    
         
            +
            {
         
     | 
| 
      
 7 
     | 
    
         
            +
                size_t   i, n, idx;
         
     | 
| 
      
 8 
     | 
    
         
            +
                char    *d_ptr, *i_ptr, *o_ptr;
         
     | 
| 
      
 9 
     | 
    
         
            +
                ssize_t  d_step, i_step, o_step;
         
     | 
| 
      
 10 
     | 
    
         
            +
                char   **ptr;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                INIT_COUNTER(lp, n);
         
     | 
| 
      
 13 
     | 
    
         
            +
                INIT_PTR(lp, 0, d_ptr, d_step);
         
     | 
| 
      
 14 
     | 
    
         
            +
                INIT_PTR(lp, 1, i_ptr, i_step);
         
     | 
| 
      
 15 
     | 
    
         
            +
                INIT_PTR(lp, 2, o_ptr, o_step);
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                ptr = (char**)(lp->opt_ptr);
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                //printf("(ptr=%lx, d_ptr=%lx,d_step=%ld, i_ptr=%lx,i_step=%ld, o_ptr=%lx,o_step=%ld)\n",(size_t)ptr,(size_t)d_ptr,(ssize_t)d_step,(size_t)i_ptr,(ssize_t)i_step,(size_t)o_ptr,(ssize_t)o_step);
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                for (i=0; i<n; i++) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    ptr[i] = d_ptr + d_step * i;
         
     | 
| 
      
 23 
     | 
    
         
            +
                    //printf("(%ld,%.3f)",i,*(double*)ptr[i]);
         
     | 
| 
      
 24 
     | 
    
         
            +
                }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                <%=tp%>_index_qsort(ptr, n, sizeof(dtype*));
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                //d_ptr = lp->args[0].ptr;
         
     | 
| 
      
 29 
     | 
    
         
            +
                //printf("(d_ptr=%lx)\n",(size_t)d_ptr);
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                for (i=0; i<n; i++) {
         
     | 
| 
      
 32 
     | 
    
         
            +
                    idx = (ptr[i] - d_ptr) / d_step;
         
     | 
| 
      
 33 
     | 
    
         
            +
                    *(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
         
     | 
| 
      
 34 
     | 
    
         
            +
                    //printf("(idx[%ld]=%ld,%d)",i,idx,*(idx_t*)o_ptr);
         
     | 
| 
      
 35 
     | 
    
         
            +
                    o_ptr += o_step;
         
     | 
| 
      
 36 
     | 
    
         
            +
                }
         
     | 
| 
      
 37 
     | 
    
         
            +
                //printf("\n");
         
     | 
| 
      
 38 
     | 
    
         
            +
            }
         
     | 
| 
      
 39 
     | 
    
         
            +
            #undef idx_t
         
     | 
| 
      
 40 
     | 
    
         
            +
            <% end %>
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            /*
         
     | 
| 
      
 43 
     | 
    
         
            +
             *  call-seq:
         
     | 
| 
      
 44 
     | 
    
         
            +
             *     narray.sort_index() => narray
         
     | 
| 
      
 45 
     | 
    
         
            +
             *     narray.sort_index(dim0,dim1,..) => narray
         
     | 
| 
      
 46 
     | 
    
         
            +
             *
         
     | 
| 
      
 47 
     | 
    
         
            +
             *  Return an index array of sort result.
         
     | 
| 
      
 48 
     | 
    
         
            +
             *
         
     | 
| 
      
 49 
     | 
    
         
            +
             *     Numo::NArray[3,4,1,2].sort_index => Numo::Int32[2,3,0,1]
         
     | 
| 
      
 50 
     | 
    
         
            +
             */
         
     | 
| 
      
 51 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 52 
     | 
    
         
            +
            <%=c_func%>(int argc, VALUE *argv, VALUE self)
         
     | 
| 
      
 53 
     | 
    
         
            +
            {
         
     | 
| 
      
 54 
     | 
    
         
            +
                size_t size;
         
     | 
| 
      
 55 
     | 
    
         
            +
                narray_t *na;
         
     | 
| 
      
 56 
     | 
    
         
            +
                VALUE idx, tmp, reduce, res;
         
     | 
| 
      
 57 
     | 
    
         
            +
                char *buf;
         
     | 
| 
      
 58 
     | 
    
         
            +
                ndfunc_arg_in_t ain[3] = {{cT,0},{0,0},{sym_reduce,0}};
         
     | 
| 
      
 59 
     | 
    
         
            +
                ndfunc_arg_out_t aout[1] = {{0,0,0}};
         
     | 
| 
      
 60 
     | 
    
         
            +
                ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_CUM, 3,1, ain,aout};
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                GetNArray(self,na);
         
     | 
| 
      
 63 
     | 
    
         
            +
                if (na->ndim==0) {
         
     | 
| 
      
 64 
     | 
    
         
            +
                    return INT2FIX(0);
         
     | 
| 
      
 65 
     | 
    
         
            +
                }
         
     | 
| 
      
 66 
     | 
    
         
            +
                if (na->size > (~(u_int32_t)0)) {
         
     | 
| 
      
 67 
     | 
    
         
            +
                    ain[1].type =
         
     | 
| 
      
 68 
     | 
    
         
            +
                    aout[0].type = numo_cInt64;
         
     | 
| 
      
 69 
     | 
    
         
            +
                    idx = rb_narray_new(numo_cInt64, na->ndim, na->shape);
         
     | 
| 
      
 70 
     | 
    
         
            +
                    ndf.func = <%=tp%>_index64_qsort;
         
     | 
| 
      
 71 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 72 
     | 
    
         
            +
                    ain[1].type =
         
     | 
| 
      
 73 
     | 
    
         
            +
                    aout[0].type = numo_cInt32;
         
     | 
| 
      
 74 
     | 
    
         
            +
                    idx = rb_narray_new(numo_cInt32, na->ndim, na->shape);
         
     | 
| 
      
 75 
     | 
    
         
            +
                    ndf.func = <%=tp%>_index32_qsort;
         
     | 
| 
      
 76 
     | 
    
         
            +
                }
         
     | 
| 
      
 77 
     | 
    
         
            +
                rb_funcall(idx, rb_intern("seq"), 0);
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                size = na->size*sizeof(void*);
         
     | 
| 
      
 82 
     | 
    
         
            +
                buf = rb_alloc_tmp_buffer(&tmp, size);
         
     | 
| 
      
 83 
     | 
    
         
            +
                res = na_ndloop3(&ndf, buf, 3, self, idx, reduce);
         
     | 
| 
      
 84 
     | 
    
         
            +
                rb_free_tmp_buffer(&tmp);
         
     | 
| 
      
 85 
     | 
    
         
            +
                return res;
         
     | 
| 
      
 86 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /*
         
     | 
| 
      
 2 
     | 
    
         
            +
              Store elements to Numo::<%=class_name%> from other.
         
     | 
| 
      
 3 
     | 
    
         
            +
              @overload store(other)
         
     | 
| 
      
 4 
     | 
    
         
            +
              @param [Object] other
         
     | 
| 
      
 5 
     | 
    
         
            +
              @return [Numo::<%=class_name%>] self
         
     | 
| 
      
 6 
     | 
    
         
            +
            */
         
     | 
| 
      
 7 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 8 
     | 
    
         
            +
            <%=c_func%>(VALUE self, VALUE obj)
         
     | 
| 
      
 9 
     | 
    
         
            +
            {
         
     | 
| 
      
 10 
     | 
    
         
            +
                VALUE r;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                <% Store.definitions.each do |x| %>
         
     | 
| 
      
 13 
     | 
    
         
            +
                if (<%=x.condition%>) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                    <%=x.c_func%>(self,obj);
         
     | 
| 
      
 15 
     | 
    
         
            +
                    return self;
         
     | 
| 
      
 16 
     | 
    
         
            +
                }
         
     | 
| 
      
 17 
     | 
    
         
            +
                <% end %>
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                if (IsNArray(obj)) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
         
     | 
| 
      
 21 
     | 
    
         
            +
                    if (CLASS_OF(r)==cT) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                        <%=c_func%>(self,r);
         
     | 
| 
      
 23 
     | 
    
         
            +
                        return self;
         
     | 
| 
      
 24 
     | 
    
         
            +
                    }
         
     | 
| 
      
 25 
     | 
    
         
            +
                }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                rb_raise(nary_eCastError, "unknown conversion from %s to %s",
         
     | 
| 
      
 28 
     | 
    
         
            +
                         rb_class2name(CLASS_OF(obj)),
         
     | 
| 
      
 29 
     | 
    
         
            +
                         rb_class2name(CLASS_OF(self)));
         
     | 
| 
      
 30 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 31 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,53 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t  i, s1, s2;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char   *p1, *p2;
         
     | 
| 
      
 6 
     | 
    
         
            +
                size_t *idx1, *idx2;
         
     | 
| 
      
 7 
     | 
    
         
            +
                <%=dtype%> x;
         
     | 
| 
      
 8 
     | 
    
         
            +
                dtype y;
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                INIT_COUNTER(lp, i);
         
     | 
| 
      
 11 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 0, p1, s1, idx1);
         
     | 
| 
      
 12 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 1, p2, s2, idx2);
         
     | 
| 
      
 13 
     | 
    
         
            +
                if (idx2) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                    if (idx1) {
         
     | 
| 
      
 15 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 16 
     | 
    
         
            +
                            GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
         
     | 
| 
      
 17 
     | 
    
         
            +
                            y = <%=macro%>(x);
         
     | 
| 
      
 18 
     | 
    
         
            +
                            SET_DATA_INDEX(p1,idx1,dtype,y);
         
     | 
| 
      
 19 
     | 
    
         
            +
                        }
         
     | 
| 
      
 20 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 21 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                            GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
         
     | 
| 
      
 23 
     | 
    
         
            +
                            y = <%=macro%>(x);
         
     | 
| 
      
 24 
     | 
    
         
            +
                            SET_DATA_STRIDE(p1,s1,dtype,y);
         
     | 
| 
      
 25 
     | 
    
         
            +
                        }
         
     | 
| 
      
 26 
     | 
    
         
            +
                    }
         
     | 
| 
      
 27 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 28 
     | 
    
         
            +
                    if (idx1) {
         
     | 
| 
      
 29 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 30 
     | 
    
         
            +
                            GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
         
     | 
| 
      
 31 
     | 
    
         
            +
                            y = <%=macro%>(x);
         
     | 
| 
      
 32 
     | 
    
         
            +
                            SET_DATA_INDEX(p1,idx1,dtype,y);
         
     | 
| 
      
 33 
     | 
    
         
            +
                        }
         
     | 
| 
      
 34 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 35 
     | 
    
         
            +
                        for (; i--;) {
         
     | 
| 
      
 36 
     | 
    
         
            +
                            GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
         
     | 
| 
      
 37 
     | 
    
         
            +
                            y = <%=macro%>(x);
         
     | 
| 
      
 38 
     | 
    
         
            +
                            SET_DATA_STRIDE(p1,s1,dtype,y);
         
     | 
| 
      
 39 
     | 
    
         
            +
                        }
         
     | 
| 
      
 40 
     | 
    
         
            +
                    }
         
     | 
| 
      
 41 
     | 
    
         
            +
                }
         
     | 
| 
      
 42 
     | 
    
         
            +
            }
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 46 
     | 
    
         
            +
            <%=c_func%>(VALUE self, VALUE obj)
         
     | 
| 
      
 47 
     | 
    
         
            +
            {
         
     | 
| 
      
 48 
     | 
    
         
            +
                ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{Qnil,0}};
         
     | 
| 
      
 49 
     | 
    
         
            +
                ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                na_ndloop(&ndf, 2, self, obj);
         
     | 
| 
      
 52 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 53 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 2 
     | 
    
         
            +
            numo_<%=tp%>_new_dim0(dtype x)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                VALUE v;
         
     | 
| 
      
 5 
     | 
    
         
            +
                dtype *ptr;
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                v = rb_narray_new(cT, 0, NULL);
         
     | 
| 
      
 8 
     | 
    
         
            +
                ptr = (dtype*)(char*)na_get_pointer_for_write(v);
         
     | 
| 
      
 9 
     | 
    
         
            +
                *ptr = x;
         
     | 
| 
      
 10 
     | 
    
         
            +
                na_release_lock(v);
         
     | 
| 
      
 11 
     | 
    
         
            +
                return v;
         
     | 
| 
      
 12 
     | 
    
         
            +
            }
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 15 
     | 
    
         
            +
            <%=c_func%>(VALUE self, VALUE obj)
         
     | 
| 
      
 16 
     | 
    
         
            +
            {
         
     | 
| 
      
 17 
     | 
    
         
            +
                dtype x;
         
     | 
| 
      
 18 
     | 
    
         
            +
                x = m_num_to_data(obj);
         
     | 
| 
      
 19 
     | 
    
         
            +
                obj = numo_<%=tp%>_new_dim0(x);
         
     | 
| 
      
 20 
     | 
    
         
            +
                <%=find_tmpl("store").c_func%>(self,obj);
         
     | 
| 
      
 21 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 22 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,41 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            void
         
     | 
| 
      
 2 
     | 
    
         
            +
            <%=c_iter%>(na_loop_t *const lp)
         
     | 
| 
      
 3 
     | 
    
         
            +
            {
         
     | 
| 
      
 4 
     | 
    
         
            +
                size_t i, s1;
         
     | 
| 
      
 5 
     | 
    
         
            +
                char *p1;
         
     | 
| 
      
 6 
     | 
    
         
            +
                size_t *idx1;
         
     | 
| 
      
 7 
     | 
    
         
            +
                dtype x;
         
     | 
| 
      
 8 
     | 
    
         
            +
                volatile VALUE a, y;
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                INIT_COUNTER(lp, i);
         
     | 
| 
      
 11 
     | 
    
         
            +
                INIT_PTR_IDX(lp, 0, p1, s1, idx1);
         
     | 
| 
      
 12 
     | 
    
         
            +
                a = rb_ary_new2(i);
         
     | 
| 
      
 13 
     | 
    
         
            +
                rb_ary_push(lp->args[1].value, a);
         
     | 
| 
      
 14 
     | 
    
         
            +
                if (idx1) {
         
     | 
| 
      
 15 
     | 
    
         
            +
                    for (; i--;) {
         
     | 
| 
      
 16 
     | 
    
         
            +
                        GET_DATA_INDEX(p1,idx1,dtype,x);
         
     | 
| 
      
 17 
     | 
    
         
            +
                        y = m_data_to_num(x);
         
     | 
| 
      
 18 
     | 
    
         
            +
                        rb_ary_push(a,y);
         
     | 
| 
      
 19 
     | 
    
         
            +
                    }
         
     | 
| 
      
 20 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 21 
     | 
    
         
            +
                    for (; i--;) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                        GET_DATA_STRIDE(p1,s1,dtype,x);
         
     | 
| 
      
 23 
     | 
    
         
            +
                        y = m_data_to_num(x);
         
     | 
| 
      
 24 
     | 
    
         
            +
                        rb_ary_push(a,y);
         
     | 
| 
      
 25 
     | 
    
         
            +
                    }
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
      
 27 
     | 
    
         
            +
            }
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            /*
         
     | 
| 
      
 30 
     | 
    
         
            +
              Convert self to Array.
         
     | 
| 
      
 31 
     | 
    
         
            +
              @overload <%=method%>
         
     | 
| 
      
 32 
     | 
    
         
            +
              @return [Array]
         
     | 
| 
      
 33 
     | 
    
         
            +
            */
         
     | 
| 
      
 34 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 35 
     | 
    
         
            +
            <%=c_func%>(VALUE self)
         
     | 
| 
      
 36 
     | 
    
         
            +
            {
         
     | 
| 
      
 37 
     | 
    
         
            +
                ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
         
     | 
| 
      
 38 
     | 
    
         
            +
                ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
         
     | 
| 
      
 39 
     | 
    
         
            +
                ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP_NIP, 3, 1, ain, aout };
         
     | 
| 
      
 40 
     | 
    
         
            +
                return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
         
     | 
| 
      
 41 
     | 
    
         
            +
            }
         
     |