473,625 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

transfer undefined class methods to attribute's method [Numeric array]

I am constructing a "placeholde r array" to mimick Numeric arrays. I have a
3D regular structured domain, so I can describe the axis with 3 1D arrays
x[], y[] and z[]. All the variables defined on this field (temperature,
velocity) are 3D-fields, and to treat everything the same, I want to have
x,y and z also as a 3d-array. However, as one field is typically 100 Mb, I
do not want to create these arrays, but instead define a class that mimicks
this.

I have succeeded in doing this (see code below), but now I want to transfer
any unknown class methods to the in-line created variable, something like:

def process_unknown method(self, method, args)
exec(self[:].method(args))

How do I do this in python?

TIA, Maarten
Here's the class (sorry for the long class)

from Numeric import *

class PlaceHolder:
def __init__(self, axis, dims, arr):
self.axis = axis
self.arr = arr
self.dims = dims

def __interpretkey( self, axis, key):
if type(key) == int:
sl = slice(key, key+1,1)
else:
# interpret the slice object
start = key.start
if (start == None):
if not (key.stop == None):
start = key.stop
else:
start == 0
if start < 0:
if start > - self.dims[axis]:
start = self.dims[axis] + start
else:
start = 0

stop = key.stop
if stop == None or stop == sys.maxint:
stop = self.dims[axis]
if stop < 0:
if stop > - self.dims[axis]:
stop = self.dims[axis] + stop
else:
stop = 0

step = key.step
if not step: step = 1

sl = slice(start, stop, step)

return sl

def __getitem__(sel f, key):
sl = []

# if it's only one argument, make it into a tuple
if not ((type(key) == tuple) or (type(key) == list)):
key = (key,)

# determine ranges
for i, rng in enumerate(key):
sl.append(self. __interpretkey( i, rng))

# extend for missing dimensions
for i in range(len(key), len(self.dims)) :
sl.append(slice (0, self.dims[i], 1))

# swap values for indices
sl[0], sl[self.axis] = sl[self.axis], sl[0]
base = self.arr[sl[0]]

# create an array
for n, i in enumerate(sl):
l = int(abs(float(i .stop - i.start)) / abs(i.step)+0.5 )
if n > 0:
base = add.outer(base, zeros(l))

base = swapaxes(base, 0, self.axis)

# remove the dimensions of length 1

rdims = []
for i in range(rank(base )):
if base.shape[i] <= 1:
rdims.append(i)

rdims.sort()
rdims.reverse()

for i in rdims:
base = add.reduce(base , i)

return base
# example starts here

a = arange(10.)
y = PlaceHolder(1, [10, 10, 10], a)

print y[1, :, 10]
print y[1, 3]

--
=============== =============== =============== =============== =======
Maarten van Reeuwijk Thermal and Fluids Sciences
Phd student dept. of Multiscale Physics
www.ws.tn.tudelft.nl Delft University of Technology
Jul 18 '05 #1
0 1626

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9591
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
4
1863
by: Maarten van Reeuwijk | last post by:
Hello, Maybe I was a little too detailed in my previous post . I can boil down my problem to this: say I have a class A that I encapsulate with a class Proxy. Now I just want to override and add some functionality (see my other post why). All functionality not defined in the Proxy class should be delegated (I can't use inheritance, see other post). It should be possible to achieve this using Python's great introspection possibilities,...
2
3209
by: Owen Woo | last post by:
My activeX control developped in VC++ has following method: void AppendData(double* databuf) How can I call this method in C# and transfer the databuf parameter to it?
8
6004
by: Joe | last post by:
I have several classes which I need serialized. Here is their class definitions: public class TopContainer { private LevelTwoType m_levelTwo; public LevelTwoType LevelTwo { get {
4
1854
by: Terry Olsen | last post by:
Since both methods seem to produce the same results, in which cases would you prefer one over the other? The only thing I would think is using Server.Transfer because of some browsers blocking redirects. *** Sent via Developersdex http://www.developersdex.com ***
22
7951
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I am using getElelementsByName since these are radio buttons, but it seems that the dynamic element is not seen!!! This is my code... please let me know if there is anything that I am doing wrong! - thanks ---- ....
45
4823
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to "new Array() vs " question or to the array performance, I dared to move it to a new thread. Gecko takes undefined value strictly as per Book 4, Chapter 3, Song 9 of Books of ECMA :-)
0
2820
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
6
1854
by: Lee | last post by:
I'd like to implement a generic class that takes as its Type-parameter a numeric type (e.g. (U)Int16/32/64, float, double, decimal, etc.). The problem is that, having validated the Type-parameter, I cannot do any arithmetic operations (+, -, *, /) on variables of that type. I tried creating wrapper-classes for the numeric types I will support and tried to derive them from a custom interface that specified the above 4 operators -- but...
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.