Module: Numo::Linalg::Lapack

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

Constant Summary collapse

FIXNAME =
{
 corgqr: :cungqr,
 zorgqr: :zungqr,
}

Class Method Summary collapse

Class Method Details

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

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

Examples:

s = Numo::Linalg::Lapack.call(:gesv, a)

Parameters:

  • func (Symbol, String)

    function name without BLAS char.

  • args

    arguments passed to Lapack function.

  • kwargs

    keyword arguments passed to Lapack function.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/numo/linalg/function.rb', line 47

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



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'ext/numo/linalg/lapack/lapack.c', line 353

static VALUE
lapack_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
    lapack_handle = handle;
    return Qnil;
}

.prefix=(prefix) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'ext/numo/linalg/lapack/lapack.c', line 385

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

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