Sha256: 64e74a871a5de6b2ee7ae866a6d01bd1b8088db2647d44219d95db5e8be4152a

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

#pragma once

#include <rice/Symbol.hpp>

// keep THP prefix for now to make it easier to compare code

extern VALUE THPVariableClass;

inline VALUE THPUtils_internSymbol(const std::string& str) {
  return Symbol(str);
}

inline std::string THPUtils_unpackSymbol(VALUE obj) {
  Check_Type(obj, T_SYMBOL);
  obj = rb_funcall(obj, rb_intern("to_s"), 0);
  return std::string(RSTRING_PTR(obj), RSTRING_LEN(obj));
}

inline std::string THPUtils_unpackString(VALUE obj) {
  Check_Type(obj, T_STRING);
  return std::string(RSTRING_PTR(obj), RSTRING_LEN(obj));
}

inline bool THPUtils_checkSymbol(VALUE obj) {
  return SYMBOL_P(obj);
}

inline bool THPUtils_checkIndex(VALUE obj) {
  return FIXNUM_P(obj);
}

inline bool THPUtils_checkScalar(VALUE obj) {
  return FIXNUM_P(obj) || RB_FLOAT_TYPE_P(obj) || RB_TYPE_P(obj, T_COMPLEX);
}

inline bool THPVariable_Check(VALUE obj) {
  return rb_obj_is_kind_of(obj, THPVariableClass);
}

inline bool THPVariable_CheckExact(VALUE obj) {
  return rb_obj_is_instance_of(obj, THPVariableClass);
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
torch-rb-0.5.3 ext/torch/utils.h
torch-rb-0.5.2 ext/torch/utils.h
torch-rb-0.5.1 ext/torch/utils.h
torch-rb-0.5.0 ext/torch/utils.h
torch-rb-0.4.2 ext/torch/utils.h
torch-rb-0.4.1 ext/torch/utils.h
torch-rb-0.4.0 ext/torch/utils.h