Class: Dyndoc::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndoc/common/dynArray.rb

Constant Summary collapse

@@all =

global stuff

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(langs = [:r], first = [], lang = :rb, vname = nil) ⇒ Vector

ary is a String when lang is not :rb



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 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

Instance Attribute Details

#aryObject

object stuff



103
104
105
# File 'lib/dyndoc/common/dynArray.rb', line 103

def ary
  @ary
end

#idObject

object stuff



103
104
105
# File 'lib/dyndoc/common/dynArray.rb', line 103

def id
  @id
end

#vectorsObject

object stuff



103
104
105
# File 'lib/dyndoc/common/dynArray.rb', line 103

def vectors
  @vectors
end

Class Method Details

.[](key) ⇒ Object



93
94
95
# File 'lib/dyndoc/common/dynArray.rb', line 93

def Vector.[](key)
	@@all[key.to_s]
end

.[]=(key, value) ⇒ Object



97
98
99
100
# 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

.getObject



89
90
91
# File 'lib/dyndoc/common/dynArray.rb', line 89

def Vector.get
	@@all
end

Instance Method Details

#[](key) ⇒ Object



213
214
215
# File 'lib/dyndoc/common/dynArray.rb', line 213

def [](key)
	@ary[key]
end

#[]=(key, val) ⇒ Object

when modified from ruby, other languages are updated



218
219
220
221
222
# File 'lib/dyndoc/common/dynArray.rb', line 218

def []=(key,val)
	@ary[key]=val #super
	sync
	self
end

#ids(lang) ⇒ Object



146
147
148
149
150
151
152
153
154
155
# 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

#inspectObject



142
143
144
# File 'lib/dyndoc/common/dynArray.rb', line 142

def inspect
	@ary.inspect
end

#replace(ary) ⇒ Object



225
226
227
228
229
# File 'lib/dyndoc/common/dynArray.rb', line 225

def replace(ary)
	@ary.replace ary #super ary
	sync
	self
end

#sync(from = :rb) ⇒ Object

from is :rb, :jl or :r



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# 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) ⇒ Object



157
158
159
160
161
162
163
164
165
166
# 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