rust – How to write a slice into a file?

I have code which interracts with C via bindings. In it I have this:

let a1: *const i8 = get_data();
let size1 = get_size_of_data();

let a2 = ::std::slice::from_raw_parts(a2, size1);

I need to write a2 or a1 into a binary file. The size or length of the data is known.

I tried:

  let mut f1 = File::create("my_file.data").unwrap();
  // ??? f1.write_all(a2).expect("unable to write binary data to file");
  // ??? f1.write_all(a2.as_bytes).expect("unable to write binary data to file");

and nothing has compiled.

How to do it?

sprites – How can I use .txt or .xml reference file to slice up spritesheets in Lua?

I’ve been learning to code games in Lua, and I’ve recently started on my own project. I wanted to use the following spritesheet from Kenney.nl, as well as a few other spritesheets from them

enter image description here

but I’m a little confused as to how to cut it up. Some of the sprites are irregularly sized from the normal 70×70, and there’s a 2px gap between each one, so my current understanding of how to generate quads from a spritesheet doesn’t seem to apply

Thankfully, the spritesheets each come with an associated .txt or .xml file (it varies, not sure why) that gives the top left x/y coordinates, as well as the width and height of each sprite. This seems like it would make the job of creating a reference table of sprites really easy, but I can’t figure out how to include something like

<SubTexture name="box.png" x="0" y="864" width="70" height="70"/>
<SubTexture name="boxAlt.png" x="0" y="792" width="70" height="70"/>
<SubTexture name="boxCoin.png" x="0" y="720" width="70" height="70"/>
<SubTexture name="boxCoinAlt.png" x="0" y="576" width="70" height="70"/>

or

fishSwim1 = 76 0 66 42
fishSwim2 = 73 43 62 43
flyDead = 143 0 59 33
flyFly1 = 0 32 72 36
flyFly2 = 0 0 75 31

as a reference file in my Lua code. Everything I’ve seen online has been guides on chopping up spritesheets with uniform width and height, or using some website or service to create a spritesheet/reference file, which I don’t need to do (and I’d rather do as much as possible within my code)

Category Theory – Slice categories and dependent types

How are slice categories related to dependent types? Here is a quote from Mclarty's book Elementary categories, elementary toposes that surprised me:

High level programming languages ​​have dependent types, data types that themselves depend on parameters in other data types.

So I wonder what the general connection is. An example in Idris would be great, but not necessary.

Recursion – Max. Integers in slice

Each go routine receives a 2K stack. GoLang by Design has no problems with batch overflow for long lists because the batch size is increased if necessary

So I'm using a recursive approach

package expressions

func Max(list ()int) int {

    length := len(list)
    if length > 1 {

        if list(0) > list(length-1) {

            return Max(list(:length))
        } else {

            return Max(list(1:length))
        }
    }
    return list(0)
}

package main

import (
    "fmt"

    "github.com/myhub/cs61a/expressions"
)

var list = ()int{4, 4, 4, 4, 6, 7, 8}

func main() {
    var value = expressions.Max(list)
    fmt.Println(value)
}

Can work Max() be improved in terms of health check?

Algorithms – Generate a slice that contains an element

Suppose I have the array:

[2, 3, 4, 5, 6, 7, 8, 9]

Now based on a few parameters:

  1. current_item – currently selected item.
  2. select_size – Selection size, always odd.

I would like to receive a sublist of the list that meets the conditions:

  1. current item should be in the middle of the sublist if possible.
  2. If there are not enough items left / right in the list, use the items from right / left.

Examples:

list: [2, 3, 4, 5, 6, 7, 8, 9]
current_item: 5
select_size: 3

result: [4, 5, 6]


list: [2, 3, 4, 5, 6, 7, 8, 9]
current_item: 2
select_size: 5

result: [2, 3, 4, 5, 6]

list: [2, 3, 4, 5, 6, 7, 8, 9]
current_item: 8
select_size: 5

result: [5, 6, 7, 8, 9]

Post-processing – refocusing of light field images using the Fourier Slice Photograph set

I am trying to refocus images from a microlens array light field using Renier's Fourier Slice photo set, which can be found in his thesis, Chapter 5, Equation 5.7. You can find this at https://stanford.edu/class/ee367/reading/Ren%20Ng -thesis% 20Lytro.pdf

In other words, the Fourier slice photography set means that a photograph is the inverse 2D Fourier transform of an extended 2D layer in the 4D Fourier transform of the light field.

Part of my confusion is the notation and applying in Python to a captured light field image. At first I understand what the Fourier transform is, but when Ng says 4D Fourier transform the light field, I'm not sure how to interpret it. I currently have my light field as a NumPy array, so my values ​​for u = i, v = j index on the different images with subaperture, each pixel in the image with subaperture having an x ​​and y coordinate, which gives me a 4D Light field array.

        lf_img = cv2.imread(lf_img, -cv2.IMREAD_ANYDEPTH)
        row_lens = lf_img.shape(0)/14 #14 is pixels under a microlens in this direction
        col_lens = lf_img.shape(1)/14 # 14 is pixels under a microlens in this direction
        vp_imgs = np.zeros((14,14,int(row_lens),int(col_lens),3))
        for i in range(14):
            for j in range(14):
                vp_imgs(i, j, :, :, :) = lf_img(i::14, j::14, 0:3) ##U,V,X,Y,(RGB)

Then I see pictures like this http://graphics.stanford.edu/papers/fourierphoto/ in Ng's thesis, where it looks to me like he just took the 2D Fourier transform of each lenslet and arranged it in a grid . So I'm not entirely sure how to interpret this 4D Fourier transform and how to cut. Thank you so much!

Example of what type of light field image I work with:
light_field_data

Slice a Val and attach it to the end

I am trying to create a code that intersects a value and appends it to the end to create encryption.

So far I've got this:

def rotate(s: String, os: Int): String =
  (s + s).slice(os, os + s.length)

However, I am tasked with this & # 39; rotation & # 39; to output as a Map(Int, String) =
Ideas for the best ways to do this.
Thank you very much

What's the big o-notation for this problem when creating sub-arrays with .slice and while-loop in Javascript?

Problem: Given a given array and sub-array size (chunk size), write a function to create many sub-arrays for storing the array elements, where each sub-array has the specified sub-array size .

The data provided are, for example:
(1,3,2,3) and subarray size: 2

Expected performance, ((1.3), (2.3))

For this solution, can I say below that the Big O-time complexity is O (log N)?

const createSubArrays = (arr, subArraySize) => {
  let index = 0
  const resultArr = ()
  while(index < arr.length){
    resultArr.push(arr.slice(index,index+subArraySize))
    index = index + subArraySize
  }
  return resultArr
};

console.log(createSubArrays((1, 3, 2, 3), 2));

Algorithm – Faster way to count the number of discrete values ​​in a slice?

I am currently using this to count the number of discrete values ​​in a particular one ()string. Is there a faster way to do this?

func CountDiscrete(x ()string) int {
    discrete := 0

    for i,xi := range x {
        is_discrete := true
        for j,xj := range x {
            if i != j {
                if xi == xj {
                    is_discrete = false
                    break
                }
            }
        }

        if is_discrete {
            discrete = discrete + 1
        }
    }

    return discrete
}