Class: Linalg::XData::DData

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/linalg/ddata.c

Direct Known Subclasses

DReal

Instance Method Summary collapse

Methods included from Enumerable

#map_with_index

Constructor Details

#new(size) ⇒ Object #new(size) {|i| ... } ⇒ Object

Create a contiguous array of LAPACK type doublereal of the given size, assigning elements to the block. If no block is given, the data is left uninitialized.

Overloads:

  • #new(size) {|i| ... } ⇒ Object

    Yields:

    • (i)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/linalg/ddata.c', line 52

VALUE rb_ddata_initialize(VALUE self, VALUE size)
{
    DData* a ;
    get_ddata(a, self) ;
    a->size = NUM2INT(size) ;
    a->data = (doublereal*)ALLOC_N(doublereal, a->size) ;

    if( rb_block_given_p() )
    {
        int i ;
        for( i = 0 ; i != a->size ; ++i )
        {
            VALUE rval = rb_yield(INT2FIX(i)) ;
            a->data[i] = NUM2DBL(rval) ;
        }
    }
    
    return self ;
}

Instance Method Details

#[](*args) ⇒ Object

Array element read



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'ext/linalg/ddata.c', line 76

VALUE rb_ddata_aref(int argc, VALUE* argv, VALUE self)
{
    DData* a ;
    VALUE rpos ;
    int pos ;

    rb_scan_args(argc, argv, "1", &rpos) ;
    pos = NUM2INT(rpos) ;
    get_ddata(a, self) ;

    if( pos < 0 || pos >= a->size )
    {
        rb_raise(rb_eIndexError, "") ;
    }

    return rb_float_new((double)a->data[pos]) ;
}

#[]=(*args) ⇒ Object

Array element write



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/linalg/ddata.c', line 98

VALUE rb_ddata_aset(int argc, VALUE* argv, VALUE self)
{
    DData* a ;
    VALUE rpos ;
    VALUE rval ;
    int pos ;

    rb_scan_args(argc, argv, "2", &rpos, &rval) ;
    pos = NUM2INT(rpos) ;
    get_ddata(a, self) ;

    if( pos < 0 || pos >= a->size )
    {
        rb_raise(rb_eIndexError, "") ;
    }

    a->data[pos] = NUM2DBL(rval) ;

    return rval ;
}

#eachObject

For Enumerable



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'ext/linalg/ddata.c', line 158

VALUE rb_ddata_each( VALUE self )
{
    DData* a ;
    get_ddata(a, self) ;
    
    {
        doublereal* p = a->data ;
        doublereal* end = p + a->size ;

        for( ; p != end ; ++p )
        {
            rb_yield(rb_float_new((double)*p)) ;
        }
    }

    return self ;
}

#fill(rval) ⇒ Object

Fill the array with this value.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/linalg/ddata.c', line 135

VALUE rb_ddata_fill( VALUE self, VALUE rval )
{
    DData* a ;
    get_ddata(a, self) ;
    
    {
        doublereal val = NUM2DBL(rval) ;
        doublereal* p = a->data ;
        doublereal* end = p + a->size ;
        
        for( ; p != end ; ++p )
        {
            *p = val ;
        }
    }

    return self ;
}

#to_doublereal_ptrObject

The entry point into the Lapack module. Returns actual pointer value of the data.



124
125
126
127
128
129
# File 'ext/linalg/ddata.c', line 124

VALUE rb_ddata_to_doublereal_ptr( VALUE self )
{
    DData* a ;
    get_ddata(a, self) ;
    return ULONG2NUM((unsigned long)a->data) ;
}