# Last edited on 2021-07-31 15:39:40 by jstolfi from ixdiff import ixdiff def basis_sampled_write(wr, s, B, w, grid): # Assumes that {s} is a list of {ns} sampling points in {d}-space ({d}-tuples of floats) # and {B} is a list of {nb} vectors (lists) of {ns} floats, which are the # values of {nb} basis functions at those sampling points. Writes that data # to {wr}. # # The parameter {w}, if not {None}, is a vector of {ns} non-negative floats # that specify the weight of each sampling point. If {None}, all # weights are assumed to be 1. # # Each line has the format # # "{k} {w[k]} {s[k][0]} ... {s[k][d-1]} {B[0][k]} ... {B[nb-1][k]}" # # for {k} in {0..ns-1}. # # If {grid} is true, the procedure assumes that the samples come from # a regular grid and are sorted in lex or reverse lex order. Then # blank lines are inserted between slices of the grid. THus, if {d} is # 2, the file can be used with {gnumplot}'s {splot} command. # nb = len(B) assert nb > 0, "empty basis" ns = len(s) sprev = None for ks in range(ns): sk = s[ks] if grid: for j in range(ixdiff(sprev, sk) - 1): wr.write("\n"); wr.write("%5d" % ks) ws = 1 if w == None else w[ks] wr.write(" %12.10f " % ws) for skj in sk: wr.write(" %12.8f" % skj) wr.write(" ") for kb in range(nb): wr.write(" %+16.10f" % B[kb][ks]) wr.write("\n") sprev = s[ks] wr.flush() return # ----------------------------------------------------------------------