class Dyndoc::Vector

Attributes

ary[RW]

object stuff

id[RW]

object stuff

vectors[RW]

object stuff

Public Class Methods

[](key) click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 93
def Vector.[](key)
        @@all[key.to_s]
end
[]=(key,value) click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 97
def Vector.[]=(key,value)
        @@all[key.to_s].replace(value) if value.is_a? Array
        @@all[key.to_s]
end
get() click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 89
def Vector.get
        @@all
end
new(langs=[:r],first=[],lang=:rb,vname=nil) click to toggle source

ary is a String when lang is not :rb

# File lib/dyndoc/common/dynArray.rb, line 106
def initialize(langs=[:r],first=[],lang=:rb,vname=nil)
        @ary=(first.is_a? String) ? [] : first
        @vectors={} 
        #@to_update={}
        @vname,@id=vname,vname #+"@"+self.object_id.abs.to_s
        if langs.include? :r
                Array.initR 
                @vectors[:r]=R4rb::RVector.new ""
                @vectors[:r] << ids(:r)
                @vectors[:r] < @ary unless @ary.empty?
                ##@to_update[:r]=nil
        end
        if langs.include? :jl
                Julia.init 
                @vectors[:jl]=Julia::Vector.new ""
                @vectors[:jl] << ids(:jl)
                Julia << wrapper(:jl)+"=Any[]"
                @vectors[:jl] < @ary unless @ary.empty?
                #@to_update[:jl]=nil
        end
        # global register => callable for update
        @@all[ids(:rb)]=self
        # first init
        @unlock=true
        case lang
        when :jl
                Julia << ids(:jl)+"="+first
                sync(:jl)
                ## Julia << "println("+wrapper(:jl)+")"
        when :r,:R
                R4rb << ids(:r)+"<-"+first
                sync(:r)
                ## R4rb << "print("+wrapper(:r)+")"
        end
end

Public Instance Methods

[](key) click to toggle source

# to is :jl or :r (:rb is always up to date) def sync_to(to=:r)

if @unlock and @to_update[to]
        @unlock=nil #to avoid the same update several times
        ## Dyndoc.warn "sync to #{to}",[@ary,@vectors[to].name]
        @vectors[to] < @ary
        ## Dyndoc.warn "done", [@vectors[to].name,@vectors[to].value]
        @to_update[to]=nil
        @unlock=true
end

end

# File lib/dyndoc/common/dynArray.rb, line 213
def [](key)
        @ary[key]
end
[]=(key,val) click to toggle source

when modified from ruby, other languages are updated

# File lib/dyndoc/common/dynArray.rb, line 218
def []=(key,val)
        @ary[key]=val #super
        sync
        self
end
ids(lang) click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 146
def ids(lang)
        case lang
        when :rb
                 @id
        when :jl
                "Dyndoc.Vec[\""+@id+"\"].ary"
        when :r
                "Dyndoc.Vec[\""+@id+"\"]"
        end
end
inspect() click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 142
def inspect
        @ary.inspect
end
replace(ary) click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 225
def replace(ary)
        @ary.replace ary #super ary
        sync
        self
end
sync(from=:rb) click to toggle source

from is :rb, :jl or :r

# File lib/dyndoc/common/dynArray.rb, line 169
def sync(from=:rb)
        if @unlock
                @unlock=nil #to avoid the same update several times
                ## Dyndoc.warn "rb sync (from #{from}):",ids(:rb)
                @vectors[from] > @ary unless from==:rb
                ## Dyndoc.warn "new ary",[@vectors[from].name,@vectors[from].value,@ary]
                ([:jl,:r]-[from]).each do |to|
                        ## Dyndoc.warn "rb sync (to #{to})"
                        @vectors[to] < @ary
                        ## Dyndoc.warn "@vectors[#{to}].value", @vectors[to].value
                end
                @unlock=true
        end
end
wrapper(lang) click to toggle source
# File lib/dyndoc/common/dynArray.rb, line 157
def wrapper(lang)
        case lang
        when :rb
                 "Dyndoc.Vec[:"+@id+"]"
        when :jl
                "Dyndoc.Vec[\""+@id+"\"]"
        when :r
                "Dyndoc.Vec[\""+@id+"\"]"
        end
end