Variation in prefix sum

2022-12-05 Thread Soham Mukherjee via Digitalmars-d-learn
I'm attempting to parallelize some program that solves recursive 
linear equations. Some of these, I believe, might be modified 
into prefix sums. Here are a handful of examples of the equations 
I'm dealing with.

The conventional prefix sum is as follows:
```
y[i] = y[i-1] + x[i]
```
One equation that interests me is similar to prefix sum but with 
a multiplication:

```
y[i] = A*y[i-1] + x[i]
```
Another feature is deeper recursion:
```
y[i] = y[i-1] + y[i-2] + x[i]
```
Aside from these two versions, I'm wondering whether there are 
any resources that discuss how to convert situations like the one 
above into prefix sum form. Alternatively, ways for 
adopting/adapting prefix sum in order to make it more flexible. I 
read this [blog](https://www.scaler.com/topics/prefix-sum/), but 
I need more information about my situation.


RDBMS internal operation

2022-11-07 Thread Soham Mukherjee via Digitalmars-d-learn
I have a table with ten columns and would want to choose column 1 
and column 9 from it. How many columns should be selected 
internally in RDBMS? Also, I'm not an expert in 3-Level 
Architecture of DBMS to understand [data 
independence](https://www.scaler.com/topics/data-independence-in-dbms/) but I've read several resources.


I'm asking about Oracle, but I'm also learning hbase, so I'm a 
little confused. I'm not a database guy; I'm a java guy who is 
now into Hadoop and hasn't touched a database in over a year. 
There are other reasons for this, but we will not go into them. I 
am very aware of what I am doing. I'm a newbie MR coder, but I'm 
doing okay with my part of the code.


Re: Need Help with Encapsulation in Python!

2022-06-17 Thread Soham Mukherjee via Digitalmars-d-learn

[Here](https://www.scaler.com/topics/python/encapsulation-in-python/), they 
mentioned a way of simulating encapsulation of class level like this:
```
def private(*values):
def decorator(cls):
class Proxy:
def __init__(self, *args, **kwargs):
self.inst = cls(*args, **kwargs)
def __call__(self, cls, *args, **kwargs):
return self.inst
def __getattr__(self, attr):
if attr in values:
raise AttributeError("Private valueiables are 
not accessible!")

else: return getattr(self.inst, attr)
def __setattr__(self, attr, val):
# Allow access inside the class
if attr == 'inst': self.__dict__[attr] = val
elif attr in values:
raise AttributeError("Private valueiables are 
not accessible!")

else: setattr(self.inst, attr, val)
def __str__(self):
return self.inst.__str__()
return Proxy
return decorator
```
this can be used for class-level encapsulation (e.g.limiting the 
access of a variable or method in a class).


For module-level encapsulation, however, the only way that I can 
think of is that you create a file and write the init.py. However 
if those who writes the client program knows the structure of 
your file / package, this can still not stop them from importing 
stuff.




Need Help with Encapsulation in Python!

2022-06-17 Thread Soham Mukherjee via Digitalmars-d-learn

```
   self.a = 1
self.b = 2
self.c = 3
pass

  def __getattribute__(self, name):
if sys._getframe(1).f_code.co_argcount == 0:
  if name in self.privates:
raise Exception("Access to private attribute \"%s\" is 
not allowed" % name)

  else:
return object.__getattribute__(self, name)
else:
  return object.__getattribute__(self, name)

  def __setattr__(self, name, value):
if sys._getframe(1).f_code.co_argcount == 0:
  if name in self.privates:
raise Exception("Setting private attribute \"%s\" is not 
allowed" % name)

  elif name in self.protected:
raise Exception("Setting protected attribute \"%s\" is 
not allowed" % name)

  else:
return object.__setattr__(self, name, value)
else:
  return object.__setattr__(self, name, value)


example = EncapsulationClass()

example.a = 10 # Exception: Setting private attribute "a" is not 
allowed
example.b = 10 # Exception: Setting protected attribute "b" is 
not allowed

example.c = 10 # example.c == 10

example.__dict__["privates"] # Exception: Setting protected 
attribute "b" is not allowed

```

What would actually be wrong with doing something like this?

Is there any better way to achieve encapsulation in Python? 
Please rectify my code if possible.