Class: CNTK::NDArrayView

Inherits:
Object
  • Object
show all
Defined in:
lib/cntk/ndarrayview.rb,
ext/cntk/cntk_wrap.cxx

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, self) ⇒ Object



22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
# File 'ext/cntk/cntk_wrap.cxx', line 22091

SWIGINTERN VALUE _wrap_new_NDArrayView(int nargs, VALUE *args, VALUE self) {
  int argc;
  VALUE argv[5];
  int ii;
  
  argc = nargs;
  if (argc > 5) SWIG_fail;
  for (ii = 0; (ii < argc); ++ii) {
    argv[ii] = args[ii];
  }
  if (argc == 1) {
    int _v;
    {
      int res = SWIG_AsVal_double(argv[0], NULL);
      _v = SWIG_CheckState(res);
    }
    if (_v) {
      return _wrap_new_NDArrayView__SWIG_1(nargs, args, self);
    }
  }
  if (argc == 4) {
    int _v;
    {
      int res = SWIG_AsVal_int(argv[0], NULL);
      _v = SWIG_CheckState(res);
    }
    if (_v) {
      {
        int res = SWIG_AsVal_int(argv[1], NULL);
        _v = SWIG_CheckState(res);
      }
      if (_v) {
        {
          // '1000' is the typecheck precedence code. It means: check after basic
          // types, but before arrays. See: http://www.swig.org/Doc3.0/Typemaps.html#Typemaps_overloading
          _v = NIL_P(rb_check_array_type(argv[2])) ? 0 : 1;
        }
        if (_v) {
          void *vptr = 0;
          int res = SWIG_ConvertPtr(argv[3], &vptr, SWIGTYPE_p_CNTK__DeviceDescriptor, 0);
          _v = SWIG_CheckState(res);
          if (_v) {
            return _wrap_new_NDArrayView__SWIG_0(nargs, args, self);
          }
        }
      }
    }
  }
  if (argc == 5) {
    int _v;
    {
      int res = SWIG_AsVal_int(argv[0], NULL);
      _v = SWIG_CheckState(res);
    }
    if (_v) {
      {
        // '1000' is the typecheck precedence code. It means: check after basic
        // types, but before arrays. See: http://www.swig.org/Doc3.0/Typemaps.html#Typemaps_overloading
        _v = NIL_P(rb_check_array_type(argv[1])) ? 0 : 1;
      }
      if (_v) {
        int res = swig::asptr(argv[2], (std::vector< double,std::allocator< double > >**)(0));
        _v = SWIG_CheckState(res);
        if (_v) {
          void *vptr = 0;
          int res = SWIG_ConvertPtr(argv[3], &vptr, SWIGTYPE_p_CNTK__DeviceDescriptor, 0);
          _v = SWIG_CheckState(res);
          if (_v) {
            {
              int res = SWIG_AsVal_bool(argv[4], NULL);
              _v = SWIG_CheckState(res);
            }
            if (_v) {
              return _wrap_new_NDArrayView__SWIG_2(nargs, args, self);
            }
          }
        }
      }
    }
  }
  
fail:
  Ruby_Format_OverloadedError( argc, 5, "NDArrayView.new", 
    "    NDArrayView.new(enum CNTK::DataType, enum CNTK::StorageFormat, CNTK::NDShape const &, CNTK::DeviceDescriptor const &)\n"
    "    NDArrayView.new(double)\n"
    "    NDArrayView.new(enum CNTK::DataType dataType, CNTK::NDShape const &shape, std::vector< double,std::allocator< double > > v, CNTK::DeviceDescriptor const &device, bool readOnly)\n");
  
  return Qnil;
}

Class Method Details

.create(a) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cntk/ndarrayview.rb', line 4

def self.create(a)
  if a.respond_to?(:shape)
    case a
    when NDArrayView
      return a
    when Numo::DFloat
      dtype = DataType_Double
    when Numo::SFloat
      dtype = DataType_Float
    else
      raise ArgumentError, "Numo::NArray or NDArrayView expected"
    end
    return self.new(dtype, a.shape, a.flatten.to_a,
                    CNTK::DeviceDescriptor.use_default_device(), false)
  else
    raise ArgumentError, "not responds to :shape"
  end
end

Instance Method Details

#alias(*args, self) ⇒ Object



21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
# File 'ext/cntk/cntk_wrap.cxx', line 21810

SWIGINTERN VALUE _wrap_NDArrayView_alias(int nargs, VALUE *args, VALUE self) {
  int argc;
  VALUE argv[3];
  int ii;
  
  argc = nargs + 1;
  argv[0] = self;
  if (argc > 3) SWIG_fail;
  for (ii = 1; (ii < argc); ++ii) {
    argv[ii] = args[ii-1];
  }
  if (argc == 1) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      return _wrap_NDArrayView_alias__SWIG_1(nargs, args, self);
    }
  }
  if (argc == 2) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      {
        int res = SWIG_AsVal_bool(argv[1], NULL);
        _v = SWIG_CheckState(res);
      }
      if (_v) {
        return _wrap_NDArrayView_alias__SWIG_0(nargs, args, self);
      }
    }
  }
  
fail:
  Ruby_Format_OverloadedError( argc, 3, "NDArrayView.alias", 
    "    CNTK::NDArrayViewPtr NDArrayView.alias(bool readOnly)\n"
    "    CNTK::NDArrayViewPtr NDArrayView.alias()\n");
  
  return Qnil;
}

#change_device(*args) ⇒ Object



21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
# File 'ext/cntk/cntk_wrap.cxx', line 21927

SWIGINTERN VALUE
_wrap_NDArrayView_change_device(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  CNTK::DeviceDescriptor *arg2 = 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  void *argp2 ;
  int res2 = 0 ;
  
  if ((argc < 1) || (argc > 1)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","ChangeDevice", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_CNTK__DeviceDescriptor,  0 );
  if (!SWIG_IsOK(res2)) {
    SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "CNTK::DeviceDescriptor const &","ChangeDevice", 2, argv[0] )); 
  }
  if (!argp2) {
    SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "CNTK::DeviceDescriptor const &","ChangeDevice", 2, argv[0])); 
  }
  arg2 = reinterpret_cast< CNTK::DeviceDescriptor * >(argp2);
  {
    try {
      (arg1)->ChangeDevice((CNTK::DeviceDescriptor const &)*arg2); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  return Qnil;
fail:
  return Qnil;
}

#copy_from(*args) ⇒ Object



21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
# File 'ext/cntk/cntk_wrap.cxx', line 21853

SWIGINTERN VALUE
_wrap_NDArrayView_copy_from(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  CNTK::NDArrayView *arg2 = 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  void *argp2 = 0 ;
  int res2 = 0 ;
  std::shared_ptr< CNTK::NDArrayView const > tempshared2 ;
  
  if ((argc < 1) || (argc > 1)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","CopyFrom", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res2 = SWIG_ConvertPtrAndOwn(argv[0], &argp2, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t,  0 , &newmem);
    if (!SWIG_IsOK(res2)) {
      SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "CNTK::NDArrayView const &","CopyFrom", 2, argv[0] ));
    }
    if (!argp2) {
      SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "CNTK::NDArrayView const &","CopyFrom", 2, argv[0])); 
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared2 = *reinterpret_cast< std::shared_ptr< const CNTK::NDArrayView > * >(argp2);
      delete reinterpret_cast< std::shared_ptr< const CNTK::NDArrayView > * >(argp2);
      arg2 = const_cast< CNTK::NDArrayView * >(tempshared2.get());
    } else {
      arg2 = const_cast< CNTK::NDArrayView * >(reinterpret_cast< std::shared_ptr< const CNTK::NDArrayView > * >(argp2)->get());
    }
  }
  {
    try {
      (arg1)->CopyFrom((CNTK::NDArrayView const &)*arg2); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  return Qnil;
fail:
  return Qnil;
}

#deep_clone(*args, self) ⇒ Object



21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
# File 'ext/cntk/cntk_wrap.cxx', line 21611

SWIGINTERN VALUE _wrap_NDArrayView_deep_clone(int nargs, VALUE *args, VALUE self) {
  int argc;
  VALUE argv[4];
  int ii;
  
  argc = nargs + 1;
  argv[0] = self;
  if (argc > 4) SWIG_fail;
  for (ii = 1; (ii < argc); ++ii) {
    argv[ii] = args[ii-1];
  }
  if (argc == 1) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      return _wrap_NDArrayView_deep_clone__SWIG_3(nargs, args, self);
    }
  }
  if (argc == 2) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      void *vptr = 0;
      int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_CNTK__DeviceDescriptor, 0);
      _v = SWIG_CheckState(res);
      if (_v) {
        return _wrap_NDArrayView_deep_clone__SWIG_1(nargs, args, self);
      }
    }
  }
  if (argc == 2) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      {
        int res = SWIG_AsVal_bool(argv[1], NULL);
        _v = SWIG_CheckState(res);
      }
      if (_v) {
        return _wrap_NDArrayView_deep_clone__SWIG_2(nargs, args, self);
      }
    }
  }
  if (argc == 3) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      void *vptr = 0;
      int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_CNTK__DeviceDescriptor, 0);
      _v = SWIG_CheckState(res);
      if (_v) {
        {
          int res = SWIG_AsVal_bool(argv[2], NULL);
          _v = SWIG_CheckState(res);
        }
        if (_v) {
          return _wrap_NDArrayView_deep_clone__SWIG_0(nargs, args, self);
        }
      }
    }
  }
  
fail:
  Ruby_Format_OverloadedError( argc, 4, "NDArrayView.deep_clone", 
    "    CNTK::NDArrayViewPtr NDArrayView.deep_clone(CNTK::DeviceDescriptor const &device, bool readOnly)\n"
    "    CNTK::NDArrayViewPtr NDArrayView.deep_clone(CNTK::DeviceDescriptor const &device)\n"
    "    CNTK::NDArrayViewPtr NDArrayView.deep_clone(bool readOnly)\n"
    "    CNTK::NDArrayViewPtr NDArrayView.deep_clone()\n");
  
  return Qnil;
}

#get_data_type(*args) ⇒ Object



20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
# File 'ext/cntk/cntk_wrap.cxx', line 20908

SWIGINTERN VALUE
_wrap_NDArrayView_get_data_type(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  enum CNTK::DataType result;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","GetDataType", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    try {
      result = (enum CNTK::DataType)(arg1)->GetDataType(); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  vresult = SWIG_From_int(static_cast< int >(result));
  return vresult;
fail:
  return Qnil;
}

#get_storage_format(*args) ⇒ Object



20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
# File 'ext/cntk/cntk_wrap.cxx', line 20962

SWIGINTERN VALUE
_wrap_NDArrayView_get_storage_format(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  enum CNTK::StorageFormat result;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","GetStorageFormat", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    try {
      result = (enum CNTK::StorageFormat)(arg1)->GetStorageFormat(); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  vresult = SWIG_From_int(static_cast< int >(result));
  return vresult;
fail:
  return Qnil;
}

#is_read_only(*args) ⇒ Object



21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
# File 'ext/cntk/cntk_wrap.cxx', line 21124

SWIGINTERN VALUE
_wrap_NDArrayView_is_read_only(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  bool result;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","IsReadOnly", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    try {
      result = (bool)(arg1)->IsReadOnly(); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  vresult = SWIG_From_bool(static_cast< bool >(result));
  return vresult;
fail:
  return Qnil;
}

#is_sparse(*args) ⇒ Object



21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
# File 'ext/cntk/cntk_wrap.cxx', line 21070

SWIGINTERN VALUE
_wrap_NDArrayView_is_sparse(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  bool result;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","IsSparse", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    try {
      result = (bool)(arg1)->IsSparse(); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  vresult = SWIG_From_bool(static_cast< bool >(result));
  return vresult;
fail:
  return Qnil;
}

#set_value(*args, self) ⇒ Object



21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
# File 'ext/cntk/cntk_wrap.cxx', line 21296

SWIGINTERN VALUE _wrap_NDArrayView_set_value(int nargs, VALUE *args, VALUE self) {
  int argc;
  VALUE argv[3];
  int ii;
  
  argc = nargs + 1;
  argv[0] = self;
  if (argc > 3) SWIG_fail;
  for (ii = 1; (ii < argc); ++ii) {
    argv[ii] = args[ii-1];
  }
  if (argc == 2) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      {
        int res = SWIG_AsVal_float(argv[1], NULL);
        _v = SWIG_CheckState(res);
      }
      if (_v) {
        return _wrap_NDArrayView_set_value__SWIG_0(nargs, args, self);
      }
    }
  }
  if (argc == 2) {
    int _v;
    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0);
    _v = SWIG_CheckState(res);
    if (_v) {
      {
        int res = SWIG_AsVal_double(argv[1], NULL);
        _v = SWIG_CheckState(res);
      }
      if (_v) {
        return _wrap_NDArrayView_set_value__SWIG_1(nargs, args, self);
      }
    }
  }
  
fail:
  Ruby_Format_OverloadedError( argc, 3, "NDArrayView.set_value", 
    "    void NDArrayView.set_value(float value)\n"
    "    void NDArrayView.set_value(double value)\n");
  
  return Qnil;
}

#shape(*args) ⇒ Object



21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
# File 'ext/cntk/cntk_wrap.cxx', line 21016

SWIGINTERN VALUE
_wrap_NDArrayView_shape(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  CNTK::NDShape *result = 0 ;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","Shape", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    try {
      result = (CNTK::NDShape *) &(arg1)->Shape(); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_CNTK__NDShape, 0 |  0 );
  return vresult;
fail:
  return Qnil;
}

#to_narrayObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cntk/ndarrayview.rb', line 23

def to_narray
  case get_data_type
  when DataType_Float
    klass = Numo::SFloat
  when DataType_Double
    klass = Numo::DFloat
  else
    raise "unknown data type"
  end
  ret = klass[*to_vec()]
  ret = ret.reshape(*shape().to_a)
  return ret
end

#to_vec(*args) ⇒ Object



22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
# File 'ext/cntk/cntk_wrap.cxx', line 22182

SWIGINTERN VALUE
_wrap_NDArrayView_to_vec(int argc, VALUE *argv, VALUE self) {
  CNTK::NDArrayView *arg1 = (CNTK::NDArrayView *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  std::shared_ptr< CNTK::NDArrayView > tempshared1 ;
  std::shared_ptr< CNTK::NDArrayView > *smartarg1 = 0 ;
  std::vector< double,std::allocator< double > > result;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  {
    swig_ruby_owntype newmem = {
      0, 0
    };
    res1 = SWIG_ConvertPtrAndOwn(self, &argp1, SWIGTYPE_p_std__shared_ptrT_CNTK__NDArrayView_t, 0 |  0 , &newmem);
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "CNTK::NDArrayView *","to_vec", 1, self ));
    }
    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
      tempshared1 = *reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      delete reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >(tempshared1.get());
    } else {
      smartarg1 = reinterpret_cast< std::shared_ptr<  CNTK::NDArrayView > * >(argp1);
      arg1 = const_cast< CNTK::NDArrayView * >((smartarg1 ? smartarg1->get() : 0));
    }
  }
  {
    try {
      result = CNTK_NDArrayView_to_vec(arg1); 
    }
    catch (const std::runtime_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (const std::invalid_argument &e) {
      SWIG_exception(SWIG_ValueError,e.what()); 
    }
    catch (const std::logic_error &e) {
      SWIG_exception(SWIG_RuntimeError,e.what()); 
    }
    catch (...) {
      SWIG_exception(SWIG_UnknownError,"Runtime exception"); 
    }
  }
  vresult = swig::from(static_cast< std::vector< double,std::allocator< double > > >(result));
  return vresult;
fail:
  return Qnil;
}