On Thu, 25 May 2006, Alex P. wrote:
end
def marshal_load(array)
@narray = NArray.to_narray(array)
end
end
But then I’d have to write a whole bunch of accessor methods and stuff.
I bet there’s some C/ruby/narray wizardry that will replicate replace.
are you sure need it? you can write/read narrays from file quite
easily:
harp:~ > cat a.rb
require 'narray'
na = NArray.int 2, 3
na[0, true] = 42
p na
open('dat', 'w'){|f| f.write na.to_s}
buf = IO.read('dat')
na = NArray.to_na buf, NArray::INT, 2, 3
p na
harp:~ > ruby a.rb
NArray.int(2,3):
[ [ 42, 0 ],
[ 42, 0 ],
[ 42, 0 ] ]
NArray.int(2,3):
[ [ 42, 0 ],
[ 42, 0 ],
[ 42, 0 ] ]
so, assuming that you do, it’s easy enough:
harp:~ > cat a.rb
require 'narray'
class NArray
def _dump *ignored
Marshal.dump :typecode => typecode, :shape => shape, :data =>
to_s
end
def self._load buf
h = Marshal.load buf
typecode = h[:typecode]
shape = h[:shape]
data = h[:data]
to_na data, typecode, *shape
end
end
na = NArray.int 2, 3
na[0, true] = 42
dumped = Marshal.dump na
na = Marshal.load dumped
p na
harp:~ > ruby a.rb
NArray.int(2,3):
[ [ 42, 0 ],
[ 42, 0 ],
[ 42, 0 ] ]
regards.
-a