 ## Blender

1038 Members
Unofficial help & discussion | Blender Community: #Blender.org:matrix.org87 Servers

SenderMessageTime
15 May 2022 0.Eth3rnal_ 21:25:44 0.Eth3rnal_ * Eg. haskell, too:21:25:48 0.Eth3rnal_I wrote this by writing a bit, testing, adding a bit, testing...21:26:28 0.Eth3rnal_Which is slightly diff than I write most things21:26:37 0.Eth3rnal_This method tends to end up with sphagetti code21:26:54 0.Eth3rnal_ * This method tends to end up with spaghetti code21:26:57 0.Eth3rnal_If I actually think tho21:27:43 0.Eth3rnal_ 21:27:46 0.Eth3rnal_The readability here sucks cuz this is not how you write haskell normally, but much better than one-liners21:28:13 0.Eth3rnal_ Well, it is readable but not pretty 21:28:41 0.Eth3rnal_Anyway21:29:26 nodespaghetti
This method tends to end up with spaghetti code
Guess I can't really criticize spaghetti code lol
22:29:21
16 May 2022 0.Eth3rnal_
Guess I can't really criticize spaghetti code lol
:P
01:07:35 0.Eth3rnal_For good measure, here's some spaghetti python01:07:59 0.Eth3rnal_
``````    def __mul__(self, other):
if type(other) == Fraction:
res = (self.val * other.val, self.exp * other.exp)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)
elif type(other) == Float:
ofrac = other.get_fraction()
res = (self.val * ofrac.val, self.exp * ofrac.exp)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)

def __truediv__(self, other):
if type(other) == Fraction:
return self.__mul__(other.invert())
elif type(other) == Float:
return self.__mul__(other.get_fraction().invert())

if type(other) == Fraction:
flcm = math.lcm(self.exp, other.exp)
sv = self.val * (flcm//self.exp)
ov = other.val * (flcm//other.exp)
res = (sv + ov, flcm)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)
elif type(other) == Float:
ofrac = other.get_fraction()
flcm = math.lcm(self.exp, ofrac.exp)
sv = self.val * (flcm//self.exp)
ov = ofrac.val * (flcm//ofrac.exp)
res = (sv + ov, flcm)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)
``````
01:08:18 0.Eth3rnal_ *
``````class Fraction:
def __init__(self, val, exp):
self.val, self.exp = simplify(val, exp)

def invert(self):
val = self.val
self.val = self.exp
self.exp = val
return self

def sign_flip(self):
self.val = -self.val
return self

def __mul__(self, other):
if type(other) == Fraction:
res = (self.val * other.val, self.exp * other.exp)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)
elif type(other) == Float:
ofrac = other.get_fraction()
res = (self.val * ofrac.val, self.exp * ofrac.exp)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)

def __truediv__(self, other):
if type(other) == Fraction:
return self.__mul__(other.invert())
elif type(other) == Float:
return self.__mul__(other.get_fraction().invert())

if type(other) == Fraction:
flcm = math.lcm(self.exp, other.exp)
sv = self.val * (flcm//self.exp)
ov = other.val * (flcm//other.exp)
res = (sv + ov, flcm)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)
elif type(other) == Float:
ofrac = other.get_fraction()
flcm = math.lcm(self.exp, ofrac.exp)
sv = self.val * (flcm//self.exp)
ov = ofrac.val * (flcm//ofrac.exp)
res = (sv + ov, flcm)
v, e, i = get_float(res, res)
if i: return Float(v, e)
else: return Fraction(res, res)

def __sub__(self, other):
if type(other) == Fraction:
return self.__mul__(other.sign_flip())
elif type(other) == Float:
return self.__mul__(other.get_fraction().sign_flip())

def __eq__(self, other):
if type(other) == Float:
othfr = other.get_fraction()
return self.val == othfr.val and self.exp == othfr.exp
elif type(other) == Fraction:
return self.val == other.val and self.exp == other.exp

def __gt__(self, other):
if type(other) == Fraction:
flcm = math.lcm(self.exp, other.exp)
sv = self.val * (flcm//self.exp)
ov = other.val * (flcm//other.exp)
return sv > ov
elif type(other) == Float:
othfr = other.get_fraction()
flcm = math.lcm(self.exp, othfr.exp)
sv = self.val * (flcm//self.exp)
ov = othfr.val * (flcm//othfr.exp)
return sv > ov

def __ge__(self, other):
if self == other: return True
else: return self > other

def __lt__(self, other):
if type(other) == Fraction:
flcm = math.lcm(self.exp, other.exp)
sv = self.val * (flcm//self.exp)
ov = other.val * (flcm//other.exp)
return sv < ov
elif type(other) == Float:
othfr = other.get_fraction()
flcm = math.lcm(self.exp, othfr.exp)
sv = self.val * (flcm//self.exp)
ov = othfr.val * (flcm//othfr.exp)
return sv < ov

def __le__(self, other):
if self == other: return True
else: return self < other

def __str__(self):
return f'{self.val}/{self.exp}'

def __repr__(self):
return self.__str__()

``````
01:09:00 0.Eth3rnal_It's from my infloats lib, for infinite precision mathematics 01:09:17 0.Eth3rnal_Lol01:09:18 0.Eth3rnal_Single letter variables 👌01:09:57 0.Eth3rnal_And this is ontopic, since it's a python library for math stuff which might be useful in blender :)01:10:31 0.Eth3rnal_ I haven't tested it in blender, I originally made it for my shell, but it should work fine 01:10:58 Akawama joined the room.02:34:17 AkawamaWhen I run blender with prime-run it says my gpu is not supported but when I run it with dri_prime=1 it runs fine. Why is that so?02:35:44 neuroblossomthanks for the ideas everyone i'm using the camera shifting method and it's way, way faster03:22:05 neuroblossomactually what i mean is, it's not crashing like it was03:22:20 Marisvaldo Amaral changed their profile picture.12:55:24 nurpu changed their display name from nurpu to k0r0va.13:55:12 nurpu changed their display name from k0r0va to nurpu.13:55:37 @maxicarlos08:matrix.org left the room.16:35:56 Akawama * My GPU is incompatible with blender, only has 2.1 compute capability while blender requires 3.0+ so when I run blender with Nvidia prime render offload prime-run, it says my gpu is not supported but when I run it with Nouveau prime dri_prime=1, it runs fine. Why is that so?17:25:18

#### There are no newer messages yet.

Back to Room List