Module: Numo::Linalg::Blas

Defined in:
lib/numo/linalg/function.rb,
ext/numo/linalg/blas/blas.c

Constant Summary collapse

FIXNAME =
{
 cnrm2: :csnrm2,
 znrm2: :dznrm2,
}

Class Method Summary collapse

Class Method Details

.call(func, *args, **kwargs) ⇒ Object

Call BLAS function prefixed with BLAS char ([sdcz]) defined from data-types of arguments.

Examples:

c = Numo::Linalg::Blas.call(:gemm, a, b)

Parameters:

  • func (Symbol)

    function name without BLAS char.

  • args

    arguments passed to Blas function.

  • kwargs

    keyword arguments passed to Blas function.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/numo/linalg/function.rb', line 18

def self.call(func, *args, **kwargs)
  fn = (Linalg.blas_char(*args) + func.to_s).to_sym
  fn = FIXNAME[fn] || fn
  if kwargs.empty?
    # This conditional branch is necessary to prevent ArgumentError
    # that occurs in Ruby 2.6 or earlier.
    send(fn, *args)
  else
    send(fn, *args, **kwargs)
  end
end

.dlopen(*args) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'ext/numo/linalg/blas/blas.c', line 288

static VALUE
blas_s_dlopen(int argc, VALUE *argv, VALUE mod)
{
    int i, f;
    VALUE lib, flag;
    char *error;
    void *handle;

    i = rb_scan_args(argc, argv, "11", &lib, &flag);
    if (i==2) {
        f = NUM2INT(flag);
    } else {
        f = RTLD_LAZY;
    }
#if defined(HAVE_DLFCN_H)
    dlerror();
#endif
    handle = dlopen(StringValueCStr(lib), f);
#if defined(HAVE_DLFCN_H)
    if ( !handle && (error = dlerror()) ) {
        rb_raise(rb_eRuntimeError, "%s", error);
    }
#else
    if ( !handle ) {
        error = dlerror();
        rb_raise(rb_eRuntimeError, "%s", error);
    }
#endif
    blas_handle = handle;
    return Qnil;
}

.prefix=(prefix) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'ext/numo/linalg/blas/blas.c', line 321

static VALUE
blas_s_prefix_set(VALUE mod, VALUE prefix)
{
    long len;

    if (TYPE(prefix) != T_STRING) {
        rb_raise(rb_eTypeError,"argument must be string");
    }
    if (blas_prefix) {
        free(blas_prefix);
    }
    len = RSTRING_LEN(prefix);
    blas_prefix = malloc(len+1);
    strcpy(blas_prefix, StringValueCStr(prefix));
    return prefix;
}