Sha256: 9ebc51f5063aa49cfbceb56235a0e996aeaa9082dc3fb7606624586286a08fcb

Contents?: true

Size: 773 Bytes

Versions: 44

Compression:

Stored size: 773 Bytes

Contents

#include "xint_macro.h"

#define m_sign(x)    (((x)==0) ? 0 : (((x)>0) ? 1 : -1))

static inline dtype m_abs(dtype x) {
    if (x==DATA_MIN) {
        rb_raise(nary_eValueError, "cannot convert the minimum integer");
    }
    return (x<0)?-x:x;
}

static inline dtype int_reciprocal(dtype x) {
    switch (x) {
    case 1:
        return 1;
    case -1:
        return -1;
    case 0:
        rb_raise(rb_eZeroDivError, "divided by 0");
    default:
        return 0;
    }
}

static dtype pow_int(dtype x, int p)
{
    dtype r = m_one;
    switch(p) {
    case 0: return 1;
    case 1: return x;
    case 2: return x*x;
    case 3: return x*x*x;
    }
    if (p<0) return 0;
    while (p) {
        if (p&1) r *= x;
        x *= x;
        p >>= 1;
    }
    return r;
}

Version data entries

44 entries across 21 versions & 2 rubygems

Version Path
ruby-dnn-0.1.6 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.5 lib/dnn/ext/mnist/numo/types/int_macro.h
ruby-dnn-0.1.5 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.5 lib/dnn/ext/image_io/numo/types/int_macro.h
ruby-dnn-0.1.4 lib/dnn/ext/mnist/numo/types/int_macro.h
ruby-dnn-0.1.4 lib/dnn/ext/image_io/numo/types/int_macro.h
ruby-dnn-0.1.4 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.3 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.3 lib/dnn/ext/mnist/numo/types/int_macro.h
ruby-dnn-0.1.3 lib/dnn/ext/image_io/numo/types/int_macro.h
ruby-dnn-0.1.2 lib/dnn/ext/image_io/numo/types/int_macro.h
ruby-dnn-0.1.2 lib/dnn/ext/mnist/numo/types/int_macro.h
ruby-dnn-0.1.2 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.1 lib/dnn/ext/image_io/numo/types/int_macro.h
ruby-dnn-0.1.1 lib/dnn/ext/mnist/numo/types/int_macro.h
ruby-dnn-0.1.1 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.0 lib/dnn/ext/cifar10/numo/types/int_macro.h
ruby-dnn-0.1.0 lib/dnn/ext/mnist/numo/types/int_macro.h
ruby-dnn-0.1.0 lib/dnn/ext/image_io/numo/types/int_macro.h
numo-narray-0.9.1.2 ext/numo/narray/numo/types/int_macro.h